void linphone_chat_message_store_appdata(LinphoneChatMessage* msg){ LinphoneCore *lc=msg->chat_room->lc; if (lc->db){ char *buf=sqlite3_mprintf("UPDATE history SET appdata=%Q WHERE id=%i;", msg->appdata,msg->storage_id); linphone_sql_request(lc->db,buf); sqlite3_free(buf); } }
void linphone_chat_message_store_state(LinphoneChatMessage *msg){ LinphoneCore *lc=msg->chat_room->lc; if (lc->db){ char *buf=sqlite3_mprintf("UPDATE history SET status=%i WHERE (id = %i);", msg->state,msg->storage_id); linphone_sql_request(lc->db,buf); sqlite3_free(buf); } }
static void linphone_migrate_timestamps(sqlite3* db){ int ret; char* errmsg = NULL; uint64_t begin=ortp_get_cur_time_ms(); linphone_sql_request(db,"BEGIN TRANSACTION"); ret = sqlite3_exec(db,"SELECT id,time,direction FROM history WHERE time != '-1';", migrate_messages_timestamp, db, &errmsg); if( ret != SQLITE_OK ){ ms_warning("Error migrating outgoing messages: %s.\n", errmsg); sqlite3_free(errmsg); linphone_sql_request(db, "ROLLBACK"); } else { uint64_t end; linphone_sql_request(db, "COMMIT"); end=ortp_get_cur_time_ms(); ms_message("Migrated message timestamps to UTC in %lu ms",(unsigned long)(end-begin)); } }
void linphone_chat_room_update_url(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { LinphoneCore *lc=linphone_chat_room_get_core(cr); char *buf; if (lc->db==NULL) return ; buf=sqlite3_mprintf("UPDATE history SET url=%Q WHERE id=%i;",msg->external_body_url,msg->storage_id); linphone_sql_request(lc->db,buf); sqlite3_free(buf); }
void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { LinphoneCore *lc=cr->lc; char *buf; if (lc->db==NULL) return ; buf=sqlite3_mprintf("DELETE FROM history WHERE id = %i;", msg->storage_id); linphone_sql_request(lc->db,buf); sqlite3_free(buf); }
void linphone_chat_room_delete_history(LinphoneChatRoom *cr){ LinphoneCore *lc=cr->lc; char *peer; char *buf; if (lc->db==NULL) return ; peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr)); buf=sqlite3_mprintf("DELETE FROM history WHERE remoteContact = %Q;",peer); linphone_sql_request(lc->db,buf); sqlite3_free(buf); ms_free(peer); }
static int migrate_messages_timestamp(void* data,int argc, char** argv, char** column_names) { time_t new_time = parse_time_from_db(argv[1]); if( new_time ){ /* replace 'time' by -1 and set 'utc' to the timestamp */ char *buf = sqlite3_mprintf("UPDATE history SET utc=%lld,time='-1' WHERE id=%i;", (int64_t)new_time, atoi(argv[0])); if( buf) { linphone_sql_request((sqlite3*)data, buf); sqlite3_free(buf); } } else { ms_warning("Cannot parse time %s from id %s", argv[1], argv[0]); } return 0; }
void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { LinphoneCore *lc=cr->lc; char *buf; if (lc->db==NULL) return ; buf=sqlite3_mprintf("DELETE FROM history WHERE id = %i;", msg->storage_id); linphone_sql_request(lc->db,buf); sqlite3_free(buf); /* Invalidate unread_count when we modify the database, so that next time we need it it will be recomputed from latest database state */ cr->unread_count = -1; }
void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){ LinphoneCore *lc=linphone_chat_room_get_lc(cr); int read=1; char *peer; char *buf; if (lc->db==NULL) return ; peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr)); buf=sqlite3_mprintf("UPDATE history SET read=%i WHERE remoteContact = %Q;", read,peer); linphone_sql_request(lc->db,buf); sqlite3_free(buf); ms_free(peer); }
void linphone_chat_message_store_state(LinphoneChatMessage *msg){ LinphoneCore *lc=msg->chat_room->lc; if (lc->db){ char *buf=sqlite3_mprintf("UPDATE history SET status=%i WHERE (id = %i);", msg->state,msg->storage_id); linphone_sql_request(lc->db,buf); sqlite3_free(buf); } if( msg->state == LinphoneChatMessageStateDelivered || msg->state == LinphoneChatMessageStateNotDelivered ){ // message is not transient anymore, we can remove it from our transient list: msg->chat_room->transient_messages = ms_list_remove(msg->chat_room->transient_messages, msg); linphone_chat_message_unref(msg); } }
static int linphone_chat_message_store_content(LinphoneChatMessage *msg) { LinphoneCore *lc = linphone_chat_room_get_core(msg->chat_room); int id = -1; if (lc->db) { LinphoneContent *content = msg->file_transfer_information; char *buf = sqlite3_mprintf("INSERT INTO content VALUES(NULL,%Q,%Q,%Q,%Q,%i,%Q);", linphone_content_get_type(content), linphone_content_get_subtype(content), linphone_content_get_name(content), linphone_content_get_encoding(content), linphone_content_get_size(content), NULL ); linphone_sql_request(lc->db, buf); sqlite3_free(buf); id = (unsigned int) sqlite3_last_insert_rowid (lc->db); } return id; }
void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){ LinphoneCore *lc=linphone_chat_room_get_core(cr); int read=1; char *peer; char *buf; if (lc->db==NULL) return ; // optimization: do not modify the database if no message is marked as unread if(linphone_chat_room_get_unread_messages_count(cr) == 0) return; peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr)); buf=sqlite3_mprintf("UPDATE history SET read=%i WHERE remoteContact = %Q;", read,peer); linphone_sql_request(lc->db,buf); sqlite3_free(buf); ms_free(peer); cr->unread_count = 0; }
unsigned int linphone_chat_message_store(LinphoneChatMessage *msg){ LinphoneCore *lc=linphone_chat_room_get_core(msg->chat_room); int id = 0; if (lc->db){ int content_id = -1; char *peer; char *local_contact; char *buf; if (msg->file_transfer_information) { content_id = linphone_chat_message_store_content(msg); } peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(msg->chat_room)); local_contact=linphone_address_as_string_uri_only(linphone_chat_message_get_local_address(msg)); buf = sqlite3_mprintf("INSERT INTO history VALUES(NULL,%Q,%Q,%i,%Q,%Q,%i,%i,%Q,%lld,%Q,%i);", local_contact, peer, msg->dir, msg->message, "-1", /* use UTC field now */ msg->is_read, msg->state, msg->external_body_url, (int64_t)msg->time, msg->appdata, content_id ); linphone_sql_request(lc->db,buf); sqlite3_free(buf); ms_free(local_contact); ms_free(peer); id = (unsigned int) sqlite3_last_insert_rowid (lc->db); } return id; }