text stringlengths 0 357 |
|---|
dc_msg_t* dc_msg_new(dc_context_t* context, int viewtype) |
{ |
dc_msg_t* msg = NULL; |
if ((msg=calloc(1, sizeof(dc_msg_t)))==NULL) { |
exit(15); /* cannot allocate little memory, unrecoverable error */ |
} |
msg->context = context; |
msg->magic = DC_MSG_MAGIC; |
msg->type = viewtype; |
msg->state = DC_STATE_UNDEFINED; |
msg->param = dc_param_new(); |
return msg; |
} |
dc_msg_t* dc_msg_new_untyped(dc_context_t* context) |
{ |
return dc_msg_new(context, 0); |
} |
dc_msg_t* dc_msg_new_load(dc_context_t* context, uint32_t msg_id) |
{ |
dc_msg_t* msg = dc_msg_new_untyped(context); |
dc_msg_load_from_db(msg, context, msg_id); |
return msg; |
} |
/** |
* Free a message object. Message objects are created eg. by dc_get_msg(). |
* |
* @memberof dc_msg_t |
* @param msg The message object to free. |
* If NULL is given, nothing is done. |
* @return None. |
*/ |
void dc_msg_unref(dc_msg_t* msg) |
{ |
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) { |
return; |
} |
dc_msg_empty(msg); |
dc_param_unref(msg->param); |
msg->magic = 0; |
free(msg); |
} |
/** |
* Empty a message object. |
* |
* @private @memberof dc_msg_t |
* @param msg The message object to empty. |
* @return None. |
*/ |
void dc_msg_empty(dc_msg_t* msg) |
{ |
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) { |
return; |
} |
free(msg->text); |
msg->text = NULL; |
free(msg->rfc724_mid); |
msg->rfc724_mid = NULL; |
free(msg->in_reply_to); |
msg->in_reply_to = NULL; |
free(msg->server_folder); |
msg->server_folder = NULL; |
dc_param_set_packed(msg->param, NULL); |
msg->hidden = 0; |
} |
/** |
* Get the ID of the message. |
* |
* @memberof dc_msg_t |
* @param msg The message object. |
* @return The ID of the message. |
* 0 if the given message object is invalid. |
*/ |
uint32_t dc_msg_get_id(const dc_msg_t* msg) |
{ |
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) { |
return 0; |
} |
return msg->id; |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.