void display_history_message(GtkWidget *chat_view,MSList *messages,const LinphoneAddress *with){ if(messages != NULL){ MSList *it; char *from_str; char *with_str; gchar *tmp; for(it=messages;it!=NULL;it=it->next){ LinphoneChatMessage *msg=(LinphoneChatMessage *)it->data; from_str=linphone_address_as_string_uri_only(linphone_chat_message_get_from(msg)); with_str=linphone_address_as_string_uri_only(with); linphone_gtk_push_text(chat_view,strcmp(from_str,with_str)==0? with : linphone_chat_message_get_from(msg), strcmp(from_str,with_str)==0? FALSE : TRUE, linphone_chat_message_get_chat_room(msg),msg,TRUE); } tmp=g_object_get_data(G_OBJECT(chat_view),"from_message"); if (tmp){ g_object_set_data(G_OBJECT(chat_view),"from_message",NULL); g_free(tmp); } ms_free(from_str); ms_free(with_str); linphone_gtk_free_list(messages); } }
void linphone_gtk_load_chatroom(LinphoneChatRoom *cr,const LinphoneAddress *uri,GtkWidget *chat_view){ GtkWidget *main_window=linphone_gtk_get_main_window (); LinphoneChatRoom *cr2=(LinphoneChatRoom *)g_object_get_data(G_OBJECT(chat_view),"cr"); const LinphoneAddress *from=linphone_chat_room_get_peer_address(cr2); char *from_str=linphone_address_as_string_uri_only(from); char *uri_str=linphone_address_as_string(uri); char *uri_only=linphone_address_as_string_uri_only(uri); MSList *messages=NULL; if(g_strcmp0(from_str,uri_only)!=0){ GtkTextView *text_view=GTK_TEXT_VIEW(linphone_gtk_get_widget(chat_view,"textview")); GtkTextIter start; GtkTextIter end; GtkTextBuffer *text_buffer; text_buffer=gtk_text_view_get_buffer(text_view); gtk_text_buffer_get_bounds(text_buffer, &start, &end); gtk_text_buffer_delete (text_buffer, &start, &end); udpate_tab_chat_header(chat_view,uri,cr); g_object_set_data(G_OBJECT(chat_view),"cr",cr); g_object_set_data(G_OBJECT(linphone_gtk_get_widget(main_window,"contact_list")),"chatview",(gpointer)chat_view); messages=linphone_chat_room_get_history(cr,NB_MSG_HIST); g_object_set_data(G_OBJECT(chat_view),"from_message",g_strdup(uri_str)); display_history_message(chat_view,messages,uri); gtk_text_buffer_get_end_iter(text_buffer,&end); gtk_text_view_scroll_to_iter(text_view,&end,0,FALSE,1.0,0); } ms_free(from_str); ms_free(uri_str); ms_free(uri_only); }
void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message){ GtkWidget *w=(GtkWidget*)linphone_chat_room_get_user_data(room); if (w==NULL){ w=linphone_gtk_init_chatroom(room,linphone_address_as_string_uri_only(from)); } linphone_gtk_push_text(GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textlog")), linphone_address_as_string_uri_only(from), message,FALSE); gtk_window_present(GTK_WINDOW(w)); /*gtk_window_set_urgency_hint(GTK_WINDOW(w),TRUE);*/ }
void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) { ChatRoom *w=(ChatRoom*)linphone_chat_room_get_user_data(room); if (w==NULL){ w=linphone_qt_init_chatroom(room,linphone_address_as_string_uri_only(from)); } QString msgid; w->push_text(linphone_address_as_string_uri_only(from), message, msgid, false); w->activateWindow(); w->show(); }
static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t unread_only){ LinphoneCore *lc=linphone_chat_room_get_core(cr); int numrows=0; char *peer; char *buf; sqlite3_stmt *selectStatement; int returnValue; if (lc->db==NULL) return 0; // optimization: do not read database if the count is already available in memory if(unread_only && cr->unread_count >= 0) return cr->unread_count; 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); /* no need to test the sign of cr->unread_count here * because it has been tested above */ if(unread_only) cr->unread_count = numrows; return numrows; }
static void subscribe_failure_handle_by_app(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new("pauline_rc"); LinphoneProxyConfig* config; LinphoneFriend* lf; char* lf_identity=linphone_address_as_string_uri_only(pauline->identity); linphone_core_get_default_proxy(marie->lc,&config); CU_ASSERT_TRUE(subscribe_to_callee_presence(marie,pauline)); wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,1); /*just to wait for unsubscription even if not notified*/ sal_set_recv_error(marie->lc->sal, 0); /*simulate an error*/ CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphoneRegistrationProgress,2)); CU_ASSERT_EQUAL(linphone_proxy_config_get_error(config),LinphoneReasonIOError); sal_set_recv_error(marie->lc->sal, 1); lf = linphone_core_get_friend_by_address(marie->lc,lf_identity); linphone_friend_edit(lf); linphone_friend_enable_subscribes(lf,FALSE); /*disable subscription*/ linphone_friend_done(lf); CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphoneRegistrationOk,2)); /*wait for register ok*/ linphone_friend_edit(lf); linphone_friend_enable_subscribes(lf,TRUE); linphone_friend_done(lf); CU_ASSERT_FALSE(wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,2)); /*just to wait for unsubscription even if not notified*/ linphone_core_manager_destroy(marie); CU_ASSERT_FALSE(wait_for(NULL,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,3)); /*just to wait for unsubscription even if not notified*/ linphone_core_manager_destroy(pauline); }
static bool_t subscribe_to_callee_presence(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr) { stats initial_caller=caller_mgr->stat; stats initial_callee=callee_mgr->stat; bool_t result=FALSE; char* identity=linphone_address_as_string_uri_only(callee_mgr->identity); LinphoneFriend* friend=linphone_friend_new_with_address(identity); linphone_friend_edit(friend); linphone_friend_enable_subscribes(friend,TRUE); linphone_friend_done(friend); linphone_core_add_friend(caller_mgr->lc,friend); result=wait_for(caller_mgr->lc,callee_mgr->lc,&caller_mgr->stat.number_of_LinphonePresenceActivityOnline,initial_caller.number_of_LinphonePresenceActivityOnline+1); /*without proxy, callee cannot subscribe to caller result&=wait_for(caller_mgr->lc,callee_mgr->lc,&callee_mgr->stat.number_of_LinphonePresenceActivityOnline,initial_callee.number_of_LinphonePresenceActivityOnline+1); */ CU_ASSERT_EQUAL(callee_mgr->stat.number_of_NewSubscriptionRequest,initial_callee.number_of_NewSubscriptionRequest+1); /*without proxy, callee cannot subscribe to caller CU_ASSERT_EQUAL(callee_mgr->stat.number_of_NotifyReceived,initial_callee.number_of_NotifyReceived+1); */ CU_ASSERT_EQUAL(caller_mgr->stat.number_of_NotifyReceived,initial_caller.number_of_NotifyReceived+1); ms_free(identity); return result; }
void linphone_gtk_set_in_conference(LinphoneCall *call){ GtkWidget *mw=linphone_gtk_get_main_window(); GtkWidget *participant=find_conferencee_from_call(call); if (participant==NULL){ GtkWidget *tab=get_conference_tab(mw); const LinphoneAddress *addr=linphone_call_get_remote_address(call); participant=linphone_gtk_create_widget("main","callee_frame"); GtkWidget *sound_meter; GtkWidget *viewswitch=linphone_gtk_get_widget(mw,"viewswitch"); gchar *markup; if (linphone_address_get_display_name(addr)!=NULL){ markup=g_strdup_printf("<b>%s</b>",linphone_address_get_display_name(addr)); }else{ char *tmp=linphone_address_as_string_uri_only(addr); markup=g_strdup_printf("%s",tmp); ms_free(tmp); } gtk_label_set_markup(GTK_LABEL(linphone_gtk_get_widget(participant,"callee_name_label")),markup); g_free(markup); sound_meter=linphone_gtk_get_widget(participant,"sound_indicator"); linphone_gtk_init_audio_meter(sound_meter, (get_volume_t) linphone_call_get_play_volume, call); gtk_box_pack_start(GTK_BOX(tab),participant,FALSE,FALSE,PADDING_PIXELS); g_object_set_data_full(G_OBJECT(participant),"call",linphone_call_ref(call),(GDestroyNotify)linphone_call_unref); gtk_widget_show(participant); gtk_notebook_set_current_page(GTK_NOTEBOOK(viewswitch), gtk_notebook_page_num(GTK_NOTEBOOK(viewswitch),tab)); } }
int linphone_friend_set_name(LinphoneFriend *lf, const char *name){ LinphoneAddress *fr = lf->uri; LinphoneVcard *vcard = NULL; bool_t vcard_created = FALSE; vcard = lf->vcard; if (!vcard) { linphone_friend_create_vcard(lf, name); vcard = lf->vcard; vcard_created = TRUE; } if (vcard) { linphone_vcard_set_full_name(vcard, name); if (fr && vcard_created) { // SIP address wasn't set yet, let's do it char *address = linphone_address_as_string_uri_only(fr); linphone_vcard_edit_main_sip_address(vcard, address); ms_free(address); } } if (!fr && !vcard) { ms_warning("linphone_friend_set_address() must be called before linphone_friend_set_name() to be able to set display name."); return -1; } else if (fr) { linphone_address_set_display_name(fr, name); } return 0; }
GtkWidget* linphone_gtk_init_chatroom(LinphoneChatRoom *cr, const LinphoneAddress *with){ GtkWidget *chat_view=linphone_gtk_create_widget("main","chatroom_frame"); GtkWidget *main_window=linphone_gtk_get_main_window(); GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch"); GtkWidget *text=linphone_gtk_get_widget(chat_view,"textview"); GdkColor color; GdkColor colorb; int idx; GtkWidget *button; GtkWidget *entry; MSList *messages; GHashTable *table; char *with_str; color.red = 32512; color.green = 32512; color.blue = 32512; colorb.red = 56832; colorb.green = 60928; colorb.blue = 61952; with_str=linphone_address_as_string_uri_only(with); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text),GTK_WRAP_WORD_CHAR); gtk_text_view_set_editable(GTK_TEXT_VIEW(text),FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text),FALSE); gtk_notebook_append_page(notebook,chat_view,create_tab_chat_header(cr,with)); idx = gtk_notebook_page_num(notebook, chat_view); gtk_notebook_set_current_page(notebook, idx); gtk_widget_show(chat_view); table=g_hash_table_new_full(g_direct_hash,g_direct_equal,NULL,NULL); g_object_set_data(G_OBJECT(chat_view),"cr",cr); g_object_set_data(G_OBJECT(chat_view),"from_message",NULL); g_object_set_data(G_OBJECT(chat_view),"table",table); gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), "right","justification", GTK_JUSTIFY_RIGHT,NULL); gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), "left","justification", GTK_JUSTIFY_LEFT,NULL); gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), "bold","weight", PANGO_WEIGHT_BOLD,NULL); gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), "italic","style", PANGO_STYLE_ITALIC,NULL); gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), "small","size",9*PANGO_SCALE,NULL); gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), "font_grey","foreground-gdk",&color,NULL); gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), "margin","indent",10,NULL); gtk_text_buffer_create_tag(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), "bg","paragraph-background-gdk",&colorb,NULL); messages = linphone_chat_room_get_history(cr,NB_MSG_HIST); display_history_message(chat_view,messages,with); button = linphone_gtk_get_widget(chat_view,"send"); g_signal_connect_swapped(G_OBJECT(button),"clicked",(GCallback)linphone_gtk_send_text,NULL); entry = linphone_gtk_get_widget(chat_view,"text_entry"); g_signal_connect_swapped(G_OBJECT(entry),"activate",(GCallback)linphone_gtk_send_text,NULL); g_signal_connect_swapped(G_OBJECT(entry),"changed",(GCallback)linphone_gtk_compose_text,NULL); g_signal_connect(G_OBJECT(notebook),"switch_page",(GCallback)linphone_gtk_notebook_tab_select,NULL); ms_free(with_str); return chat_view; }
/** * Sets the proxy address * * Examples of valid sip proxy address are: * - IP address: sip:87.98.157.38 * - IP address with port: sip:87.98.157.38:5062 * - hostnames : sip:sip.example.net **/ int linphone_proxy_config_set_server_addr(LinphoneProxyConfig *obj, const char *server_addr){ LinphoneAddress *addr=NULL; char *modified=NULL; if (obj->reg_proxy!=NULL) ms_free(obj->reg_proxy); obj->reg_proxy=NULL; if (server_addr!=NULL && strlen(server_addr)>0){ if (strstr(server_addr,"sip:")==NULL){ modified=ms_strdup_printf("sip:%s",server_addr); addr=linphone_address_new(modified); ms_free(modified); } if (addr==NULL) addr=linphone_address_new(server_addr); if (addr){ obj->reg_proxy=linphone_address_as_string_uri_only(addr); linphone_address_destroy(addr); }else{ ms_warning("Could not parse %s",server_addr); return -1; } } return 0; }
MSList * linphone_core_get_call_history_for_address(LinphoneCore *lc, const LinphoneAddress *addr) { char *buf; char *sipAddress; uint64_t begin,end; MSList *result = NULL; if (!lc || lc->logs_db == NULL || addr == NULL) return NULL; /*since we want to append query parameters depending on arguments given, we use malloc instead of sqlite3_mprintf*/ sipAddress = linphone_address_as_string_uri_only(addr); buf = sqlite3_mprintf("SELECT * FROM call_history WHERE caller LIKE '%%%q%%' OR callee LIKE '%%%q%%' ORDER BY id DESC", sipAddress, sipAddress); // The '%%%q%%' takes care of the eventual presence of a display name begin = ortp_get_cur_time_ms(); linphone_sql_request_call_log(lc->logs_db, buf, &result); end = ortp_get_cur_time_ms(); ms_message("%s(): completed in %i ms",__FUNCTION__, (int)(end-begin)); sqlite3_free(buf); ms_free(sipAddress); if (lc->call_logs) { copy_user_data_from_existing_logs(lc->call_logs, result); } return result; }
static void simple_subscribe_with_early_notify(void) { LinphoneCoreManager* marie = presence_linphone_core_manager_new("marie"); LinphoneCoreManager* pauline = presence_linphone_core_manager_new("pauline"); LinphoneAddress *marie_identity_addr = linphone_address_clone(marie->identity); LpConfig *pauline_lp; char* pauline_identity=linphone_address_as_string_uri_only(pauline->identity); char* marie_identity; LinphoneFriend* pauline_s_friend; LinphoneFriend* marie_s_friend=linphone_core_create_friend_with_address(marie->lc,pauline_identity); pauline_lp = linphone_core_get_config(pauline->lc); lp_config_set_int(pauline_lp,"sip","notify_pending_state",1); linphone_friend_edit(marie_s_friend); linphone_friend_enable_subscribes(marie_s_friend,TRUE); linphone_friend_done(marie_s_friend); linphone_core_add_friend(marie->lc,marie_s_friend); ms_free(pauline_identity); /*to simulate pending state.*/ linphone_address_set_port(marie_identity_addr,0); marie_identity=linphone_address_as_string_uri_only(marie_identity_addr); pauline_s_friend=linphone_core_create_friend_with_address(pauline->lc,marie_identity); linphone_core_add_friend(pauline->lc,pauline_s_friend); ms_free(marie_identity); BC_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_NotifyPresenceReceived,1)); BC_ASSERT_EQUAL(linphone_friend_get_subscription_state(marie_s_friend), LinphoneSubscriptionPending,int, "%d"); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityOnline,marie->stat.number_of_LinphonePresenceActivityOnline+1); BC_ASSERT_EQUAL(marie->stat.number_of_NotifyPresenceReceived,2, int, "%d"); linphone_friend_unref(marie_s_friend); linphone_friend_unref(pauline_s_friend); linphone_address_unref(marie_identity_addr); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) { LpConfig *lpc = NULL; LinphoneFriend *lf = NULL; LinphoneFriendList *lfl = linphone_core_get_default_friend_list(lc); int i; #ifndef FRIENDS_SQL_STORAGE_ENABLED ms_warning("linphone has been compiled without sqlite, can't migrate friends"); return; #endif if (!lc) { return; } lpc = linphone_core_get_config(lc); if (!lpc) { ms_warning("this core has been started without a rc file, nothing to migrate"); return; } if (lp_config_get_int(lpc, "misc", "friends_migration_done", 0) == 1) { ms_warning("the friends migration has already been done, skipping..."); return; } if (ms_list_size(linphone_friend_list_get_friends(lfl)) > 0 && lfl->storage_id == 0) { linphone_core_remove_friend_list(lc, lfl); lfl = linphone_core_create_friend_list(lc); linphone_core_add_friend_list(lc, lfl); linphone_friend_list_unref(lfl); } for (i = 0; (lf = linphone_friend_new_from_config_file(lc, i)) != NULL; i++) { char friend_section[32]; const LinphoneAddress *addr = linphone_friend_get_address(lf); if (addr) { const char *displayName = linphone_address_get_display_name(addr); if (!displayName) { displayName = linphone_address_get_username(addr); } if (!linphone_friend_create_vcard(lf, displayName)) { ms_warning("Couldn't create vCard for friend %s", linphone_address_as_string(addr)); } else { linphone_vcard_add_sip_address(linphone_friend_get_vcard(lf), linphone_address_as_string_uri_only(addr)); } linphone_friend_list_add_friend(lfl, lf); linphone_friend_unref(lf); snprintf(friend_section, sizeof(friend_section), "friend_%i", i); lp_config_clean_section(lpc, friend_section); } } ms_debug("friends migration successful: %i friends migrated", i); lp_config_set_int(lpc, "misc", "friends_migration_done", 1); }
const char* GetDisplayNameFromLinphoneAddress(const LinphoneAddress *address) { if (!address) return NULL; const char *displayName = linphone_address_get_display_name(address); if (!displayName) displayName = linphone_address_get_username(address); if (!displayName) displayName = linphone_address_as_string_uri_only(address); return displayName; }
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); }
void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; if (!lf || !addr) { return; } vcard = linphone_friend_get_vcard(lf); if (!vcard) { return; } linphone_vcard_remove_sip_address(vcard, linphone_address_as_string_uri_only(addr)); }
static void test_subscribe_notify_publish(void) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); LinphoneProxyConfig* proxy; LinphonePresenceModel* presence; LpConfig *pauline_lp = linphone_core_get_config(pauline->lc); char* lf_identity=linphone_address_as_string_uri_only(marie->identity); LinphoneFriend *lf = linphone_core_create_friend_with_address(pauline->lc,lf_identity); lp_config_set_int(pauline_lp,"sip","subscribe_expires",5); linphone_core_add_friend(pauline->lc,lf); /*wait for subscribe acknowledgment*/ wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,1,2000); CU_ASSERT_EQUAL(LinphoneStatusOffline,linphone_friend_get_status(lf)); /*enable publish*/ linphone_core_get_default_proxy(marie->lc,&proxy); linphone_proxy_config_edit(proxy); linphone_proxy_config_enable_publish(proxy,TRUE); linphone_proxy_config_set_publish_expires(proxy,3); linphone_proxy_config_done(proxy); /*wait for marie status*/ wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,2,2000); CU_ASSERT_EQUAL(LinphoneStatusOnline,linphone_friend_get_status(lf)); presence =linphone_presence_model_new_with_activity(LinphonePresenceActivityBusy,NULL); linphone_core_set_presence_model(marie->lc,presence); /*wait for new status*/ wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,3,2000); CU_ASSERT_EQUAL(LinphoneStatusBusy,linphone_friend_get_status(lf)); /*wait for refresh*/ wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,4,5000); CU_ASSERT_EQUAL(LinphoneStatusBusy,linphone_friend_get_status(lf)); /*linphone_core_remove_friend(pauline->lc,lf);*/ /*wait for final notify*/ /*wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,4,5000); CU_ASSERT_EQUAL(LinphonePresenceActivityOffline,linphone_friend_get_status(lf)); */ linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
MSList *linphone_chat_room_get_history_range(LinphoneChatRoom *cr, int startm, int endm){ LinphoneCore *lc=linphone_chat_room_get_core(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) || (startm == 0 && endm == 0) ){ 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(); if (endm+1-startm > 1) { //display message only if at least 2 messages are loaded 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; }
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); }
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; }
int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr){ LinphoneAddress *fr = linphone_address_clone(addr); LinphoneVcard *vcard = NULL; linphone_address_clean(fr); if (lf->uri != NULL) linphone_address_unref(lf->uri); lf->uri = fr; vcard = linphone_friend_get_vcard(lf); if (vcard) { linphone_vcard_edit_main_sip_address(vcard, linphone_address_as_string_uri_only(fr)); } return 0; }
static void display_peer_name_in_label(GtkWidget *label, const LinphoneAddress *from){ const char *displayname=NULL; const char *id; char *uri_label; displayname=linphone_address_get_display_name(from); id=linphone_address_as_string_uri_only(from); if (displayname!=NULL){ uri_label=g_markup_printf_escaped("<span size=\"large\">%s</span>\n<i>%s</i>", displayname,id); }else uri_label=g_markup_printf_escaped("<span size=\"large\"><i>%s</i></span>\n",id); gtk_label_set_markup(GTK_LABEL(label),uri_label); g_free(uri_label); }
void linphone_friend_remove_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; char * address = NULL; if (!lf || !addr) { return; } vcard = lf->vcard; if (!vcard) { return; } address = linphone_address_as_string_uri_only(addr); linphone_vcard_remove_sip_address(vcard, address); ms_free(address); }
static void linphone_conference_server_refer_received(LinphoneCore *core, const char *refer_to) { char method[20]; LinphoneAddress *refer_to_addr = linphone_address_new(refer_to); char *uri; LinphoneCall *call; if(refer_to_addr == NULL) return; strncpy(method, linphone_address_get_method_param(refer_to_addr), sizeof(method)); if(strcmp(method, "BYE") == 0) { linphone_address_clean(refer_to_addr); uri = linphone_address_as_string_uri_only(refer_to_addr); call = linphone_core_find_call_from_uri(core, uri); if(call) linphone_core_terminate_call(core, call); ms_free(uri); } linphone_address_destroy(refer_to_addr); }
void conferenceframe::set_in_conference(LinphoneCall *call) { const LinphoneAddress *addr; QProgressBar *progressBar_speaker=NULL; QLabel *urilabel=NULL; sound_indicator* si; char *tmp; QString markup; int call_count=0; if(!call) return; if(_conferencealls.value(call)) return; call_count = _conferencealls.count(); addr=linphone_call_get_remote_address(call); if (linphone_address_get_display_name(addr)!=NULL){ markup.sprintf("<b>%s</b>",linphone_address_get_display_name(addr)); }else{ tmp=linphone_address_as_string_uri_only(addr); markup.sprintf("%s",tmp); ms_free(tmp); } si = new sound_indicator; /* 创建界面 */ progressBar_speaker = new QProgressBar(this); progressBar_speaker->setStyleSheet("QProgressBar::chunk {background-color: grey;} QProgressBar{text-align: center;}"); progressBar_speaker->setTextVisible(false); progressBar_speaker->setEnabled(true); progressBar_speaker->setValue(0); progressBar_speaker->setRange(0,100); QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Fixed); sizePolicy3.setHorizontalStretch(0); sizePolicy3.setVerticalStretch(0); sizePolicy3.setHeightForWidth(progressBar_speaker->sizePolicy().hasHeightForWidth()); progressBar_speaker->setSizePolicy(sizePolicy3); progressBar_speaker->setAutoFillBackground(false); progressBar_speaker->setOrientation(Qt::Horizontal); progressBar_speaker->setInvertedAppearance(false); urilabel = new QLabel(this); urilabel->setText(markup); ui->gridLayout->addWidget(progressBar_speaker, call_count+1, 3, 1, 1); ui->gridLayout->addWidget(urilabel, call_count+1, 2, 1, 1); si->sound_meter = progressBar_speaker; si->speaker_last_value = 0; si->urilabel = urilabel; _conferencealls.insert(call, si); }
void linphone_friend_add_address(LinphoneFriend *lf, const LinphoneAddress *addr) { LinphoneVcard *vcard = NULL; if (!lf || !addr) { return; } if (lf->uri == NULL) { LinphoneAddress *fr = linphone_address_clone(addr); linphone_address_clean(fr); lf->uri = fr; } vcard = linphone_friend_get_vcard(lf); if (!vcard) { return; } linphone_vcard_add_sip_address(vcard, linphone_address_as_string_uri_only(addr)); }
static void text_message_compatibility_mode(void) { char route[256]; LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); LinphoneProxyConfig* proxy; LinphoneAddress* proxy_address; char*tmp; LCSipTransports transport; char* to = linphone_address_as_string(pauline->identity); LinphoneChatRoom* chat_room; linphone_core_get_default_proxy(marie->lc,&proxy); CU_ASSERT_PTR_NOT_NULL (proxy); proxy_address=linphone_address_new(linphone_proxy_config_get_addr(proxy)); linphone_address_clean(proxy_address); tmp=linphone_address_as_string_uri_only(proxy_address); linphone_proxy_config_set_server_addr(proxy,tmp); sprintf(route,"sip:%s",test_route); linphone_proxy_config_set_route(proxy,route); ms_free(tmp); linphone_address_destroy(proxy_address); linphone_core_get_sip_transports(marie->lc,&transport); transport.udp_port=0; transport.tls_port=0; transport.dtls_port=0; /*only keep tcp*/ linphone_core_set_sip_transports(marie->lc,&transport); marie->stat.number_of_LinphoneRegistrationOk=0; CU_ASSERT_TRUE (wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphoneRegistrationOk,1)); chat_room = linphone_core_create_chat_room(marie->lc,to); { int dummy=0; wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } linphone_chat_room_send_message(chat_room,"Bla bla bla bla"); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageReceived,1)); CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceivedLegacy,1); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
void linphone_gtk_call_log_update(GtkWidget *w){ GtkTreeView *v=GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view")); GtkListStore *store; const MSList *logs; store=(GtkListStore*)gtk_tree_view_get_model(v); if (store==NULL){ store=gtk_list_store_new(3,G_TYPE_STRING,G_TYPE_STRING, G_TYPE_POINTER); gtk_tree_view_set_model(v,GTK_TREE_MODEL(store)); g_object_unref(G_OBJECT(store)); } gtk_list_store_clear (store); for (logs=linphone_core_get_call_logs(linphone_gtk_get_core());logs!=NULL;logs=logs->next){ LinphoneCallLog *cl=(LinphoneCallLog*)logs->data; GtkTreeIter iter; LinphoneAddress *la=cl->dir==LinphoneCallIncoming ? cl->from : cl->to; char *addr= linphone_address_as_string_uri_only (la); const char *display; gchar *logtxt; gchar quality[20]; display=linphone_address_get_display_name (la); if (display==NULL){ display=linphone_address_get_username (la); if (display==NULL) display=linphone_address_get_domain (la); } if (cl->quality!=-1){ snprintf(quality,sizeof(quality),"%.1f",cl->quality); } logtxt=g_markup_printf_escaped("<big><b>%s</b></big>\t<small><i>%s</i>\t<i>Quality: %s</i></small>\n" "%s\t%i minutes %i seconds\t",display, addr, cl->quality!=-1 ? quality : _("n/a"), cl->start_date, cl->duration/60,cl->duration%60); gtk_list_store_append (store,&iter); gtk_list_store_set (store,&iter, 0, cl->dir==LinphoneCallOutgoing ? GTK_STOCK_GO_UP : GTK_STOCK_GO_DOWN, 1, logtxt,2,la,-1); ms_free(addr); g_free(logtxt); } }
void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg){ LinphoneChatRoom *cr=NULL; LinphoneAddress *addr; char *cleanfrom; char *from; LinphoneChatMessage* msg; const SalCustomHeader *ch; addr=linphone_address_new(sal_msg->from); linphone_address_clean(addr); cr=linphone_core_get_chat_room(lc,addr); cleanfrom=linphone_address_as_string(addr); from=linphone_address_as_string_uri_only(addr); if (cr==NULL){ /* create a new chat room */ cr=linphone_core_create_chat_room(lc,cleanfrom); } msg = linphone_chat_room_create_message(cr, sal_msg->text); linphone_chat_message_set_from(msg, cr->peer_url); { LinphoneAddress *to; to=sal_op_get_to(op) ? linphone_address_new(sal_op_get_to(op)) : linphone_address_new(linphone_core_get_identity(lc)); msg->to=to; } msg->time=sal_msg->time; msg->state=LinphoneChatMessageStateDelivered; msg->is_read=FALSE; msg->dir=LinphoneChatMessageIncoming; ch=sal_op_get_recv_custom_header(op); if (ch) msg->custom_headers=sal_custom_header_clone(ch); if (sal_msg->url) { linphone_chat_message_set_external_body_url(msg, sal_msg->url); } linphone_address_destroy(addr); msg->storage_id=linphone_chat_message_store(msg); linphone_chat_room_message_received(cr,lc,msg); ms_free(cleanfrom); ms_free(from); }