text
stringlengths
0
357
}
/**
* Check if the message is an informational message, created by the
* device or by another users. Such messages are not "typed" by the user but
* created due to other actions, eg. dc_set_chat_name(), dc_set_chat_profile_image()
* or dc_add_contact_to_chat().
*
* These messages are typically shown in the center of the chat view,
* dc_msg_get_text() returns a descriptive text about what is going on.
*
* There is no need to perform any action when seeing such a message - this is already done by the core.
* Typically, these messages are displayed in the center of the chat.
*
* @memberof dc_msg_t
* @param msg The message object.
* @return 1=message is a system command, 0=normal message
*/
int dc_msg_is_info(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
int cmd = dc_param_get_int(msg->param, DC_PARAM_CMD, 0);
if (msg->from_id==DC_CONTACT_ID_DEVICE
|| msg->to_id==DC_CONTACT_ID_DEVICE
|| (cmd && cmd!=DC_CMD_AUTOCRYPT_SETUP_MESSAGE)) {
return 1;
}
return 0;
}
/**
* Check if the message is an Autocrypt Setup Message.
*
* Setup messages should be shown in an unique way eg. using a different text color.
* On a click or another action, the user should be prompted for the setup code
* which is forwarded to dc_continue_key_transfer() then.
*
* Setup message are typically generated by dc_initiate_key_transfer() on another device.
*
* @memberof dc_msg_t
* @param msg The message object.
* @return 1=message is a setup message, 0=no setup message.
* For setup messages, dc_msg_get_viewtype() returns DC_MSG_FILE.
*/
int dc_msg_is_setupmessage(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->type!=DC_MSG_FILE) {
return 0;
}
return dc_param_get_int(msg->param, DC_PARAM_CMD, 0)==DC_CMD_AUTOCRYPT_SETUP_MESSAGE? 1 : 0;
}
/**
* Get the first characters of the setup code.
*
* Typically, this is used to pre-fill the first entry field of the setup code.
* If the user has several setup messages, he can be sure typing in the correct digits.
*
* To check, if a message is a setup message, use dc_msg_is_setupmessage().
* To decrypt a secret key from a setup message, use dc_continue_key_transfer().
*
* @memberof dc_msg_t
* @param msg The message object.
* @return Typically, the first two digits of the setup code or an empty string if unknown.
* NULL is never returned. Must be free()'d when done.
*/
char* dc_msg_get_setupcodebegin(const dc_msg_t* msg)
{
char* filename = NULL;
char* buf = NULL;
size_t buf_bytes = 0;
const char* buf_headerline = NULL; // just a pointer inside buf, MUST NOT be free()'d
const char* buf_setupcodebegin = NULL; // just a pointer inside buf, MUST NOT be free()'d
char* ret = NULL;
if (!dc_msg_is_setupmessage(msg)) {
goto cleanup;
}
if ((filename=dc_msg_get_file(msg))==NULL || filename[0]==0) {
goto cleanup;
}
if (!dc_read_file(msg->context, filename, (void**)&buf, &buf_bytes) || buf==NULL || buf_bytes <= 0) {
goto cleanup;
}
if (!dc_split_armored_data(buf, &buf_headerline, &buf_setupcodebegin, NULL, NULL)
|| strcmp(buf_headerline, "-----BEGIN PGP MESSAGE-----")!=0 || buf_setupcodebegin==NULL) {
goto cleanup;
}