void linphone_chat_room_update_url(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { LinphoneCore *lc=linphone_chat_room_get_lc(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_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); }
MSList *linphone_chat_room_get_history_range(LinphoneChatRoom *cr, int startm, int endm){ LinphoneCore *lc=linphone_chat_room_get_lc(cr); MSList *ret; char *buf,*buf2; char *peer; uint64_t begin,end; int buf_max_size = 512; if (lc->db==NULL) return NULL; peer = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr)); cr->messages_hist = NULL; /*since we want to append query parameters depending on arguments given, we use malloc instead of sqlite3_mprintf*/ buf=ms_malloc(buf_max_size); buf=sqlite3_snprintf(buf_max_size-1,buf,"SELECT * FROM history WHERE remoteContact = %Q ORDER BY id DESC",peer); if (startm<0) startm=0; if (endm>0&&endm>=startm){ buf2=ms_strdup_printf("%s LIMIT %i ",buf,endm+1-startm); ms_free(buf); buf = buf2; }else if(startm>0){ ms_message("%s(): end is lower than start (%d < %d). Assuming no end limit.",__FUNCTION__,endm,startm); buf2=ms_strdup_printf("%s LIMIT -1",buf); ms_free(buf); buf = buf2; } if (startm>0){ buf2=ms_strdup_printf("%s OFFSET %i ",buf,startm); ms_free(buf); buf = buf2; } begin=ortp_get_cur_time_ms(); linphone_sql_request_message(lc->db,buf,cr); end=ortp_get_cur_time_ms(); ms_message("%s(): completed in %i ms",__FUNCTION__, (int)(end-begin)); ms_free(buf); ret=cr->messages_hist; cr->messages_hist=NULL; ms_free(peer); return ret; }
static int linphone_chat_message_store_content(LinphoneChatMessage *msg) { LinphoneCore *lc = linphone_chat_room_get_lc(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);", content->type, content->subtype, content->name, content->encoding, content->size, NULL ); linphone_sql_request(lc->db, buf); sqlite3_free(buf); id = (unsigned int) sqlite3_last_insert_rowid (lc->db); } return id; }
/** * Create a message attached to a dedicated chat room; * @param cr the chat room. * @param message text message, NULL if absent. * @param external_body_url the URL given in external body or NULL. * @param state the LinphoneChatMessage.State of the message. * @param time the time_t at which the message has been received/sent. * @param is_read TRUE if the message should be flagged as read, FALSE otherwise. * @param is_incoming TRUE if the message has been received, FALSE otherwise. * @return a new #LinphoneChatMessage */ LinphoneChatMessage* linphone_chat_room_create_message_2( LinphoneChatRoom *cr, const char* message, const char* external_body_url, LinphoneChatMessageState state, time_t time, bool_t is_read, bool_t is_incoming) { LinphoneCore *lc=linphone_chat_room_get_lc(cr); LinphoneChatMessage* msg = ms_new0(LinphoneChatMessage,1); msg->chat_room=(LinphoneChatRoom*)cr; msg->message=message?ms_strdup(message):NULL; msg->external_body_url=external_body_url?ms_strdup(external_body_url):NULL; msg->time=time; msg->state=state; msg->is_read=is_read; if (is_incoming) { msg->dir=LinphoneChatMessageIncoming; linphone_chat_message_set_from(msg, linphone_chat_room_get_peer_address(cr)); linphone_chat_message_set_to(msg, linphone_address_new(linphone_core_get_identity(lc))); } else { msg->dir=LinphoneChatMessageOutgoing; linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr)); linphone_chat_message_set_from(msg, linphone_address_new(linphone_core_get_identity(lc))); } return msg; }
static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t unread_only){ LinphoneCore *lc=linphone_chat_room_get_lc(cr); int numrows=0; char *peer; char *buf; sqlite3_stmt *selectStatement; int returnValue; if (lc->db==NULL) return 0; peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr)); buf=sqlite3_mprintf("SELECT count(*) FROM history WHERE remoteContact = %Q %s;",peer,unread_only?"AND read = 0":""); returnValue = sqlite3_prepare_v2(lc->db,buf,-1,&selectStatement,NULL); if (returnValue == SQLITE_OK){ if(sqlite3_step(selectStatement) == SQLITE_ROW){ numrows= sqlite3_column_int(selectStatement, 0); } } sqlite3_finalize(selectStatement); sqlite3_free(buf); ms_free(peer); return numrows; }
unsigned int linphone_chat_message_store(LinphoneChatMessage *msg){ LinphoneCore *lc=linphone_chat_room_get_lc(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; }