text
stringlengths
0
357
"INSERT INTO msgs (rfc724_mid, chat_id, from_id, to_id, timestamp,"
" type, state, txt, param, hidden,"
" mime_in_reply_to, mime_references, location_id)"
" VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?);");
sqlite3_bind_text (stmt, 1, new_rfc724_mid, -1, SQLITE_STATIC);
sqlite3_bind_int (stmt, 2, chat->id);
sqlite3_bind_int (stmt, 3, DC_CONTACT_ID_SELF);
sqlite3_bind_int (stmt, 4, to_id);
sqlite3_bind_int64(stmt, 5, timestamp);
sqlite3_bind_int (stmt, 6, msg->type);
sqlite3_bind_int (stmt, 7, msg->state);
sqlite3_bind_text (stmt, 8, msg->text? msg->text : "", -1, SQLITE_STATIC);
sqlite3_bind_text (stmt, 9, msg->param->packed, -1, SQLITE_STATIC);
sqlite3_bind_int (stmt, 10, msg->hidden);
sqlite3_bind_text (stmt, 11, new_in_reply_to, -1, SQLITE_STATIC);
sqlite3_bind_text (stmt, 12, new_references, -1, SQLITE_STATIC);
sqlite3_bind_int (stmt, 13, location_id);
if (sqlite3_step(stmt)!=SQLITE_DONE) {
dc_log_error(context, 0, "Cannot send message, cannot insert to database.", chat->id);
goto cleanup;
}
msg_id = dc_sqlite3_get_rowid(context->sql, "msgs", "rfc724_mid", new_rfc724_mid);
cleanup:
free(parent_rfc724_mid);
free(parent_in_reply_to);
free(parent_references);
free(new_rfc724_mid);
free(new_in_reply_to);
free(new_references);
sqlite3_finalize(stmt);
return msg_id;
}
static uint32_t prepare_msg_common(dc_context_t* context, uint32_t chat_id, dc_msg_t* msg)
{
char* pathNfilename = NULL;
dc_chat_t* chat = NULL;
msg->id = 0;
msg->context = context;
if (msg->type==DC_MSG_TEXT)
{
; /* the caller should check if the message text is empty */
}
else if (DC_MSG_NEEDS_ATTACHMENT(msg->type))
{
pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
if (pathNfilename==NULL) {
dc_log_error(context, 0, "Attachment missing for message of type #%i.", (int)msg->type);
goto cleanup;
}
if (msg->state==DC_STATE_OUT_PREPARING && !dc_is_blobdir_path(context, pathNfilename)) {
dc_log_error(context, 0, "Files must be created in the blob-directory.");
goto cleanup;
}
if (!dc_make_rel_and_copy(context, &pathNfilename)) {
goto cleanup;
}
dc_param_set(msg->param, DC_PARAM_FILE, pathNfilename);
if (msg->type==DC_MSG_FILE || msg->type==DC_MSG_IMAGE)
{
/* Correct the type, take care not to correct already very special formats as GIF or VOICE.
Typical conversions:
- from FILE to AUDIO/VIDEO/IMAGE
- from FILE/IMAGE to GIF */
int better_type = 0;
char* better_mime = NULL;
dc_msg_guess_msgtype_from_suffix(pathNfilename, &better_type, &better_mime);
if (better_type) {
msg->type = better_type;
dc_param_set(msg->param, DC_PARAM_MIMETYPE, better_mime);
}
free(better_mime);
}
else if (!dc_param_exists(msg->param, DC_PARAM_MIMETYPE))
{
char* better_mime = NULL;
dc_msg_guess_msgtype_from_suffix(pathNfilename, NULL, &better_mime);
dc_param_set(msg->param, DC_PARAM_MIMETYPE, better_mime);
free(better_mime);
}
dc_log_info(context, 0, "Attaching \"%s\" for message type #%i.", pathNfilename, (int)msg->type);
}
else
{
dc_log_error(context, 0, "Cannot send messages of type #%i.", (int)msg->type); /* should not happen */
goto cleanup;
}
dc_unarchive_chat(context, chat_id);
context->smtp->log_connect_errors = 1;