text stringlengths 0 357 |
|---|
ret = dc_strdup(buf_setupcodebegin); /* we need to make a copy as buf_setupcodebegin just points inside buf (which will be free()'d on cleanup) */ |
cleanup: |
free(filename); |
free(buf); |
return ret? ret : dc_strdup(NULL); |
} |
#define DC_MSG_FIELDS " m.id,rfc724_mid,m.mime_in_reply_to,m.server_folder,m.server_uid,m.move_state,m.chat_id, " \ |
" m.from_id,m.to_id,m.timestamp,m.timestamp_sent,m.timestamp_rcvd, m.type,m.state,m.msgrmsg,m.txt, " \ |
" m.param,m.starred,m.hidden,m.location_id, c.blocked " |
static int dc_msg_set_from_stmt(dc_msg_t* msg, sqlite3_stmt* row, int row_offset) /* field order must be DC_MSG_FIELDS */ |
{ |
dc_msg_empty(msg); |
msg->id = (uint32_t)sqlite3_column_int (row, row_offset++); |
msg->rfc724_mid = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); |
msg->in_reply_to = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); |
msg->server_folder= dc_strdup((char*)sqlite3_column_text (row, row_offset++)); |
msg->server_uid = (uint32_t)sqlite3_column_int (row, row_offset++); |
msg->move_state = (dc_move_state_t)sqlite3_column_int (row, row_offset++); |
msg->chat_id = (uint32_t)sqlite3_column_int (row, row_offset++); |
msg->from_id = (uint32_t)sqlite3_column_int (row, row_offset++); |
msg->to_id = (uint32_t)sqlite3_column_int (row, row_offset++); |
msg->timestamp_sort = (time_t)sqlite3_column_int64(row, row_offset++); |
msg->timestamp_sent = (time_t)sqlite3_column_int64(row, row_offset++); |
msg->timestamp_rcvd = (time_t)sqlite3_column_int64(row, row_offset++); |
msg->type = sqlite3_column_int (row, row_offset++); |
msg->state = sqlite3_column_int (row, row_offset++); |
msg->is_dc_message= sqlite3_column_int (row, row_offset++); |
msg->text = dc_strdup((char*)sqlite3_column_text (row, row_offset++)); |
dc_param_set_packed( msg->param, (char*)sqlite3_column_text (row, row_offset++)); |
msg->starred = sqlite3_column_int (row, row_offset++); |
msg->hidden = sqlite3_column_int (row, row_offset++); |
msg->location_id = sqlite3_column_int (row, row_offset++); |
msg->chat_blocked = sqlite3_column_int (row, row_offset++); |
if (msg->chat_blocked==2) { |
dc_truncate_n_unwrap_str(msg->text, 256 /* 256 characters is about a half screen on a 5" smartphone display */, |
0/*unwrap*/); |
} |
return 1; |
} |
/** |
* Load a message from the database to the message object. |
* |
* @private @memberof dc_msg_t |
*/ |
int dc_msg_load_from_db(dc_msg_t* msg, dc_context_t* context, uint32_t id) |
{ |
int success = 0; |
sqlite3_stmt* stmt = NULL; |
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || context==NULL || context->sql==NULL) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT " DC_MSG_FIELDS |
" FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id" |
" WHERE m.id=?;"); |
sqlite3_bind_int(stmt, 1, id); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
if (!dc_msg_set_from_stmt(msg, stmt, 0)) { /* also calls dc_msg_empty() */ |
goto cleanup; |
} |
msg->context = context; |
success = 1; |
cleanup: |
sqlite3_finalize(stmt); |
return success; |
} |
/** |
* Guess message type from suffix. |
* |
* @private @memberof dc_msg_t |
* @param pathNfilename Path and filename of the file to guess the type for. |
* @param[out] ret_msgtype Guessed message type is copied here as one of the DC_MSG_* constants. |
* May be NULL if you're not interested in this value. |
* @param[out] ret_mime The pointer to a string buffer is set to the guessed MIME-type. May be NULL. Must be free()'d by the caller. |
* @return None. But there are output parameters. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.