diff --git a/install_deps.sh b/install_deps.sh index c6b8556791ca7493a97fd7cc4d39d2887cf42401..cd7b966bbe0eab152c22ac8d4d95a9d9fd9fa60b 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -1,29 +1,23 @@ #!/bin/sh -sudo apt-get install build-essential -sudo apt-get install gnome-common -sudo apt-get install libalsaplayer0 -sudo apt-get install libalsaplayer-dev -sudo apt-get install libasound2-dev -sudo apt-get install libpulse-dev -sudo apt-get install libcommoncpp2-1.6-0 -sudo apt-get install libcommoncpp2-dev -sudo apt-get install libccrtp1-1.6-1 -sudo apt-get install libccrtp-dev -sudo apt-get install libsamplerate0 -sudo apt-get install libsamplerate0-dev -sudo apt-get install libdbus-1-dev -sudo apt-get install libexpat1-dev -sudo apt-get install ffmpeg -sudo apt-get install libhal1 -sudo apt-get install libhal-dev -sudo apt-get install libcppunit-1.12-1 -sudo apt-get install libcppunit-dev -sudo apt-get install libgtk2.0-dev -sudo apt-get install libdbus-glib-1-dev -sudo apt-get install libnotifymm-dev -sudo apt-get install libnotify1 -sudo apt-get install libsexy-dev +# Daemon side +sudo apt-get install build-essential gnome-common \ + libasound2-dev \ + libpulse-dev \ + libcommoncpp2-dev \ + libccrtp-dev \ + libsamplerate0-dev \ + libdbus-1-dev \ + libexpat1-dev \ + libcppunit-dev \ + libgsm1-dev \ + sflphone-iax2-dev \ + dbus-c++-1-dev \ + libspeex-dev + +# Client side +sudo apt-get install libgtk2.0-dev \ + libdbus-glib-1-dev \ + libnotify-dev \ + libsexy-dev -sudo apt-get install libgsm1-dev -sudo apt-get install libspeex-dev diff --git a/po/fr.po b/po/fr.po index 7914d0ad7915d94fc9b51a729dbd1c3bad19ae50..65ae5c83b326704515107354cb3286518f6eeb33 100644 --- a/po/fr.po +++ b/po/fr.po @@ -51,11 +51,11 @@ msgstr "_Serveur" #: ../sflphone-gtk/src/accountlist.c:179 #, fuzzy msgid "Stun configuration error" -msgstr "" +msgstr "Erreur de configuration Stun" #: ../sflphone-gtk/src/accountlist.c:182 msgid "Stun server invalid" -msgstr "" +msgstr "Serveur Stun invalide" #: ../sflphone-gtk/src/accountlist.c:185 msgid "Invalid" diff --git a/po/ru.po b/po/ru.po index 1353adef1237249b038a1fce21c4a81e4ecf03c0..658ae7c1c4d145b3bf50e2d004e91524649d4f48 100644 --- a/po/ru.po +++ b/po/ru.po @@ -48,11 +48,11 @@ msgstr "Хост недоступен" #: ../sflphone-gtk/src/accountlist.c:179 #, fuzzy msgid "Stun configuration error" -msgstr "" +msgstr "Ошибка настройки Stun" #: ../sflphone-gtk/src/accountlist.c:182 msgid "Stun server invalid" -msgstr "" +msgstr "Недействительный Stun-сервер" #: ../sflphone-gtk/src/accountlist.c:185 msgid "Invalid" diff --git a/sflphone-gtk/src/accountwindow.c b/sflphone-gtk/src/accountwindow.c index e1ceb3cf81e479c5a41780a3c9f1c5c51321371b..d45401a7d8e5afec0ff3a611b0a95e2a9d564ec8 100644 --- a/sflphone-gtk/src/accountwindow.c +++ b/sflphone-gtk/src/accountwindow.c @@ -50,327 +50,302 @@ GtkWidget * stunEnable; GtkWidget * entryMailbox; /* Signal to entryProtocol 'changed' */ - void + void change_protocol (account_t * currentAccount UNUSED) { - gchar* proto = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(entryProtocol)); - //g_print("Protocol changed\n"); - - // toggle sensitivity for: entryUserPart - if (strcmp(proto, "SIP") == 0) { - gtk_widget_set_sensitive( GTK_WIDGET(stunEnable), TRUE); - gtk_widget_set_sensitive( GTK_WIDGET(stunServer), TRUE); - } - else if (strcmp(proto, "IAX") == 0) { - gtk_widget_set_sensitive( GTK_WIDGET(stunEnable), FALSE); - gtk_widget_set_sensitive( GTK_WIDGET(stunServer), FALSE); - } - else { - // Should not get here. - g_print("Unknown protocol: %s\n", proto); - } + gchar* proto = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(entryProtocol)); + //g_print("Protocol changed\n"); + + // toggle sensitivity for: entryUserPart + if (strcmp(proto, "SIP") == 0) { + gtk_widget_set_sensitive( GTK_WIDGET(stunEnable), TRUE); + gtk_widget_set_sensitive( GTK_WIDGET(stunServer), TRUE); + } + else if (strcmp(proto, "IAX") == 0) { + gtk_widget_set_sensitive( GTK_WIDGET(stunEnable), FALSE); + gtk_widget_set_sensitive( GTK_WIDGET(stunServer), FALSE); + } + else { + // Should not get here. + g_print("Unknown protocol: %s\n", proto); + } } - int + int is_iax_enabled(void) { - int res = dbus_is_iax2_enabled(); - if(res == 1) - return TRUE; - else - return FALSE; + int res = dbus_is_iax2_enabled(); + if(res == 1) + return TRUE; + else + return FALSE; } -void + void stun_state( void ) { - gboolean stunActive = (gboolean)gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( stunEnable )); - gtk_widget_set_sensitive( GTK_WIDGET( stunServer ) , stunActive ); + gboolean stunActive = (gboolean)gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( stunEnable )); + gtk_widget_set_sensitive( GTK_WIDGET( stunServer ) , stunActive ); } - void + void show_account_window (account_t * a) { - gint response; - GtkWidget *image; - - currentAccount = a; - - // Default settings - gchar * curAccountID = ""; - gchar * curAccountEnabled = "TRUE"; - gchar * curAccountType = "SIP"; - gchar * curAlias = ""; - gchar * curUsername = ""; - gchar * curHostname = ""; - gchar * curPassword = ""; - /* TODO: add curProxy, and add boxes for Proxy support */ - gchar * stun_enabled = "FALSE"; - gchar * stun_server= "stun.fwdnet.net:3478"; - gchar * curMailbox = "888"; - - // Load from SIP/IAX/Unknown ? - if(a) - { - curAccountID = a->accountID; - curAccountType = g_hash_table_lookup(currentAccount->properties, ACCOUNT_TYPE); - curAccountEnabled = g_hash_table_lookup(currentAccount->properties, ACCOUNT_ENABLED); - curAlias = g_hash_table_lookup(currentAccount->properties, ACCOUNT_ALIAS); - - if (strcmp(curAccountType, "IAX") == 0) { - curHostname = g_hash_table_lookup(currentAccount->properties, ACCOUNT_IAX_HOST); - curPassword = g_hash_table_lookup(currentAccount->properties, ACCOUNT_IAX_PASSWORD); - curUsername = g_hash_table_lookup(currentAccount->properties, ACCOUNT_IAX_USER); - curMailbox = g_hash_table_lookup(currentAccount->properties, ACCOUNT_MAILBOX); + gint response; + GtkWidget *image; + + currentAccount = a; + + // Default settings + gchar * curAccountID = ""; + gchar * curAccountEnabled = "TRUE"; + gchar * curAccountType = "SIP"; + gchar * curAlias = ""; + gchar * curUsername = ""; + gchar * curHostname = ""; + gchar * curPassword = ""; + /* TODO: add curProxy, and add boxes for Proxy support */ + gchar * stun_enabled = "FALSE"; + gchar * stun_server= "stun.fwdnet.net:3478"; + gchar * curMailbox = "888"; + + // Load from SIP/IAX/Unknown ? + if(a) + { + curAccountID = a->accountID; + curAccountType = g_hash_table_lookup(currentAccount->properties, ACCOUNT_TYPE); + curAccountEnabled = g_hash_table_lookup(currentAccount->properties, ACCOUNT_ENABLED); + curAlias = g_hash_table_lookup(currentAccount->properties, ACCOUNT_ALIAS); + curHostname = g_hash_table_lookup(currentAccount->properties, ACCOUNT_HOSTNAME); + curPassword = g_hash_table_lookup(currentAccount->properties, ACCOUNT_PASSWORD); + curUsername = g_hash_table_lookup(currentAccount->properties, ACCOUNT_USERNAME); + curMailbox = g_hash_table_lookup(currentAccount->properties, ACCOUNT_MAILBOX); + + if (strcmp(curAccountType, "SIP") == 0) { + stun_enabled = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_STUN_ENABLED); + stun_server = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_STUN_SERVER); + } } - else if (strcmp(curAccountType, "SIP") == 0) { - curHostname = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_HOST); - curPassword = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_PASSWORD); - curUsername = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_USER); - stun_enabled = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_STUN_ENABLED); - stun_server = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_STUN_SERVER); - curMailbox = g_hash_table_lookup(currentAccount->properties, ACCOUNT_MAILBOX); + else + { + currentAccount = g_new0(account_t, 1); + currentAccount->properties = g_hash_table_new(NULL, g_str_equal); + curAccountID = "test"; } - } - else - { - currentAccount = g_new0(account_t, 1); - currentAccount->properties = g_hash_table_new(NULL, g_str_equal); - curAccountID = "test"; - } - - dialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Account settings"), - GTK_WINDOW(get_main_window()), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_APPLY, - GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - NULL)); - - gtk_dialog_set_has_separator(dialog, TRUE); - gtk_container_set_border_width (GTK_CONTAINER(dialog), 0); - - frame = gtk_frame_new(_("Account parameters")); - gtk_box_pack_start(GTK_BOX(dialog->vbox), frame, FALSE, FALSE, 0); - gtk_widget_show(frame); - - table = gtk_table_new ( 8, 2 , FALSE/* homogeneous */); - gtk_table_set_row_spacings( GTK_TABLE(table), 10); - gtk_table_set_col_spacings( GTK_TABLE(table), 10); - gtk_widget_show(table); - gtk_container_add( GTK_CONTAINER( frame) , table ); + + dialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Account settings"), + GTK_WINDOW(get_main_window()), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_APPLY, + GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + NULL)); + + gtk_dialog_set_has_separator(dialog, TRUE); + gtk_container_set_border_width (GTK_CONTAINER(dialog), 0); + + frame = gtk_frame_new(_("Account parameters")); + gtk_box_pack_start(GTK_BOX(dialog->vbox), frame, FALSE, FALSE, 0); + gtk_widget_show(frame); + + table = gtk_table_new ( 8, 2 , FALSE/* homogeneous */); + gtk_table_set_row_spacings( GTK_TABLE(table), 10); + gtk_table_set_col_spacings( GTK_TABLE(table), 10); + gtk_widget_show(table); + gtk_container_add( GTK_CONTAINER( frame) , table ); #ifdef DEBUG - label = gtk_label_new_with_mnemonic ("ID:"); - gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - entryID = gtk_entry_new(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryID); - gtk_entry_set_text(GTK_ENTRY(entryID), curAccountID); - gtk_widget_set_sensitive( GTK_WIDGET(entryID), FALSE); - gtk_table_attach ( GTK_TABLE( table ), entryID, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + label = gtk_label_new_with_mnemonic ("ID:"); + gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + entryID = gtk_entry_new(); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryID); + gtk_entry_set_text(GTK_ENTRY(entryID), curAccountID); + gtk_widget_set_sensitive( GTK_WIDGET(entryID), FALSE); + gtk_table_attach ( GTK_TABLE( table ), entryID, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); #endif - entryEnabled = gtk_check_button_new_with_mnemonic(_("_Enabled")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(entryEnabled), - g_strcasecmp(curAccountEnabled,"TRUE") == 0 ? TRUE: FALSE); - gtk_table_attach ( GTK_TABLE( table ), entryEnabled, 0, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_set_sensitive( GTK_WIDGET( entryEnabled ) , TRUE ); - - label = gtk_label_new_with_mnemonic (_("_Alias")); - gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - entryAlias = gtk_entry_new(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryAlias); - gtk_entry_set_text(GTK_ENTRY(entryAlias), g_hash_table_lookup(currentAccount->properties, ACCOUNT_ALIAS)); - gtk_table_attach ( GTK_TABLE( table ), entryAlias, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - - label = gtk_label_new_with_mnemonic (_("_Protocol")); - gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - entryProtocol = gtk_combo_box_new_text(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryProtocol); - gtk_combo_box_append_text(GTK_COMBO_BOX(entryProtocol), "SIP"); - if( is_iax_enabled() ) gtk_combo_box_append_text(GTK_COMBO_BOX(entryProtocol), "IAX"); - if(strcmp(curAccountType, "SIP") == 0) - { - gtk_combo_box_set_active(GTK_COMBO_BOX(entryProtocol),0); - } - else if(strcmp(curAccountType, "IAX") == 0) - { - gtk_combo_box_set_active(GTK_COMBO_BOX(entryProtocol),1); - } - else - { - /* Should never come here, add debug message. */ - gtk_combo_box_append_text(GTK_COMBO_BOX(entryProtocol), _("Unknown")); - gtk_combo_box_set_active(GTK_COMBO_BOX(entryProtocol),2); - } - gtk_table_attach ( GTK_TABLE( table ), entryProtocol, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - - /* Link signal 'changed' */ - g_signal_connect (G_OBJECT (GTK_COMBO_BOX(entryProtocol)), "changed", - G_CALLBACK (change_protocol), - currentAccount); - - label = gtk_label_new_with_mnemonic (_("_Host name")); - gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - entryHostname = gtk_entry_new(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryHostname); - gtk_entry_set_text(GTK_ENTRY(entryHostname), curHostname); - gtk_table_attach ( GTK_TABLE( table ), entryHostname, 1, 2, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - - label = gtk_label_new_with_mnemonic (_("_User name")); - gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 6, 7, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - entryUsername = sexy_icon_entry_new(); - //image = gtk_image_new_from_stock( GTK_STOCK_DIALOG_AUTHENTICATION , GTK_ICON_SIZE_SMALL_TOOLBAR ); - image = gtk_image_new_from_file( ICONS_DIR "/stock_person.svg" ); - sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(entryUsername), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) ); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryUsername); - gtk_entry_set_text(GTK_ENTRY(entryUsername), curUsername); - gtk_table_attach ( GTK_TABLE( table ), entryUsername, 1, 2, 6, 7, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - - label = gtk_label_new_with_mnemonic (_("_Password")); - gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 7, 8, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - entryPassword = sexy_icon_entry_new(); - image = gtk_image_new_from_stock( GTK_STOCK_DIALOG_AUTHENTICATION , GTK_ICON_SIZE_SMALL_TOOLBAR ); - sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(entryPassword), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) ); - gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryPassword); - gtk_entry_set_text(GTK_ENTRY(entryPassword), curPassword); - gtk_table_attach ( GTK_TABLE( table ), entryPassword, 1, 2, 7, 8, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - - label = gtk_label_new_with_mnemonic (_("_Voicemail box #")); - gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 8, 9, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - entryMailbox = gtk_entry_new(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryMailbox); - gtk_entry_set_text(GTK_ENTRY(entryMailbox), curMailbox); - gtk_table_attach ( GTK_TABLE( table ), entryMailbox, 1, 2, 8, 9, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - - gtk_widget_show_all( table ); - gtk_container_set_border_width (GTK_CONTAINER(table), 10); - - frameNat = gtk_frame_new( _("Network Address Translation") ); - gtk_box_pack_start(GTK_BOX(dialog->vbox), frameNat, FALSE, FALSE, 0); - gtk_widget_show(frameNat); - - tableNat = gtk_table_new ( 2, 2 , FALSE/* homogeneous */); - gtk_table_set_row_spacings( GTK_TABLE(tableNat), 10); - gtk_table_set_col_spacings( GTK_TABLE(tableNat), 10); - gtk_widget_show(tableNat); - gtk_container_add( GTK_CONTAINER( frameNat) , tableNat ); - - // NAT detection code section - stunEnable = gtk_check_button_new_with_mnemonic(_("E_nable STUN")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stunEnable), strcmp(stun_enabled,"TRUE") == 0 ? TRUE: FALSE); - g_signal_connect( G_OBJECT (GTK_TOGGLE_BUTTON(stunEnable)) , "toggled" , G_CALLBACK( stun_state ), NULL); + entryEnabled = gtk_check_button_new_with_mnemonic(_("_Enabled")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(entryEnabled), + g_strcasecmp(curAccountEnabled,"TRUE") == 0 ? TRUE: FALSE); + gtk_table_attach ( GTK_TABLE( table ), entryEnabled, 0, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_set_sensitive( GTK_WIDGET( entryEnabled ) , TRUE ); + + label = gtk_label_new_with_mnemonic (_("_Alias")); + gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + entryAlias = gtk_entry_new(); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryAlias); + gtk_entry_set_text(GTK_ENTRY(entryAlias), g_hash_table_lookup(currentAccount->properties, ACCOUNT_ALIAS)); + gtk_table_attach ( GTK_TABLE( table ), entryAlias, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + + label = gtk_label_new_with_mnemonic (_("_Protocol")); + gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + entryProtocol = gtk_combo_box_new_text(); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryProtocol); + gtk_combo_box_append_text(GTK_COMBO_BOX(entryProtocol), "SIP"); + if( is_iax_enabled() ) gtk_combo_box_append_text(GTK_COMBO_BOX(entryProtocol), "IAX"); + if(strcmp(curAccountType, "SIP") == 0) + { + gtk_combo_box_set_active(GTK_COMBO_BOX(entryProtocol),0); + } + else if(strcmp(curAccountType, "IAX") == 0) + { + gtk_combo_box_set_active(GTK_COMBO_BOX(entryProtocol),1); + } + else + { + /* Should never come here, add debug message. */ + gtk_combo_box_append_text(GTK_COMBO_BOX(entryProtocol), _("Unknown")); + gtk_combo_box_set_active(GTK_COMBO_BOX(entryProtocol),2); + } + gtk_table_attach ( GTK_TABLE( table ), entryProtocol, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + + /* Link signal 'changed' */ + g_signal_connect (G_OBJECT (GTK_COMBO_BOX(entryProtocol)), "changed", + G_CALLBACK (change_protocol), + currentAccount); + + label = gtk_label_new_with_mnemonic (_("_Host name")); + gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + entryHostname = gtk_entry_new(); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryHostname); + gtk_entry_set_text(GTK_ENTRY(entryHostname), curHostname); + gtk_table_attach ( GTK_TABLE( table ), entryHostname, 1, 2, 5, 6, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + + label = gtk_label_new_with_mnemonic (_("_User name")); + gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 6, 7, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + entryUsername = sexy_icon_entry_new(); + //image = gtk_image_new_from_stock( GTK_STOCK_DIALOG_AUTHENTICATION , GTK_ICON_SIZE_SMALL_TOOLBAR ); + image = gtk_image_new_from_file( ICONS_DIR "/stock_person.svg" ); + sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(entryUsername), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) ); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryUsername); + gtk_entry_set_text(GTK_ENTRY(entryUsername), curUsername); + gtk_table_attach ( GTK_TABLE( table ), entryUsername, 1, 2, 6, 7, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + + label = gtk_label_new_with_mnemonic (_("_Password")); + gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 7, 8, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + entryPassword = sexy_icon_entry_new(); + image = gtk_image_new_from_stock( GTK_STOCK_DIALOG_AUTHENTICATION , GTK_ICON_SIZE_SMALL_TOOLBAR ); + sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(entryPassword), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) ); + gtk_entry_set_visibility(GTK_ENTRY(entryPassword), FALSE); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryPassword); + gtk_entry_set_text(GTK_ENTRY(entryPassword), curPassword); + gtk_table_attach ( GTK_TABLE( table ), entryPassword, 1, 2, 7, 8, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + + label = gtk_label_new_with_mnemonic (_("_Voicemail box #")); + gtk_table_attach ( GTK_TABLE( table ), label, 0, 1, 8, 9, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + entryMailbox = gtk_entry_new(); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryMailbox); + gtk_entry_set_text(GTK_ENTRY(entryMailbox), curMailbox); + gtk_table_attach ( GTK_TABLE( table ), entryMailbox, 1, 2, 8, 9, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + + gtk_widget_show_all( table ); + gtk_container_set_border_width (GTK_CONTAINER(table), 10); + + frameNat = gtk_frame_new( _("Network Address Translation") ); + gtk_box_pack_start(GTK_BOX(dialog->vbox), frameNat, FALSE, FALSE, 0); + gtk_widget_show(frameNat); + + tableNat = gtk_table_new ( 2, 2 , FALSE/* homogeneous */); + gtk_table_set_row_spacings( GTK_TABLE(tableNat), 10); + gtk_table_set_col_spacings( GTK_TABLE(tableNat), 10); + gtk_widget_show(tableNat); + gtk_container_add( GTK_CONTAINER( frameNat) , tableNat ); + + // NAT detection code section + stunEnable = gtk_check_button_new_with_mnemonic(_("E_nable STUN")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stunEnable), strcmp(stun_enabled,"TRUE") == 0 ? TRUE: FALSE); + g_signal_connect( G_OBJECT (GTK_TOGGLE_BUTTON(stunEnable)) , "toggled" , G_CALLBACK( stun_state ), NULL); #if GTK_CHECK_VERSION(2,12,0) - gtk_widget_set_tooltip_text( GTK_WIDGET( stunEnable ) , _("Enable it if you are behind a firewall, then restart SFLphone")); + gtk_widget_set_tooltip_text( GTK_WIDGET( stunEnable ) , _("Enable it if you are behind a firewall, then restart SFLphone")); #endif - gtk_table_attach ( GTK_TABLE( tableNat ), stunEnable, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - - label = gtk_label_new_with_mnemonic(_("_STUN Server")); - gtk_table_attach( GTK_TABLE( tableNat ), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - stunServer = gtk_entry_new(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), stunServer); - gtk_entry_set_text(GTK_ENTRY(stunServer), stun_server); + gtk_table_attach ( GTK_TABLE( tableNat ), stunEnable, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + + label = gtk_label_new_with_mnemonic(_("_STUN Server")); + gtk_table_attach( GTK_TABLE( tableNat ), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + stunServer = gtk_entry_new(); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), stunServer); + gtk_entry_set_text(GTK_ENTRY(stunServer), stun_server); #if GTK_CHECK_VERSION(2,12,0) - gtk_widget_set_tooltip_text( GTK_WIDGET( stunServer ) , _("Format: name.server:port")); + gtk_widget_set_tooltip_text( GTK_WIDGET( stunServer ) , _("Format: name.server:port")); #endif - gtk_table_attach ( GTK_TABLE( tableNat ), stunServer, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_set_sensitive( GTK_WIDGET( stunServer ), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stunEnable))); - - - // Toggle enabled/disabled widgets - if (strcmp(curAccountType, "SIP") == 0) { - //gtk_widget_set_sesitive( GTK_WIDGET(entryUserPart), TRUE);< - } - else if (strcmp(curAccountType, "IAX") == 0) { - gtk_widget_set_sensitive( GTK_WIDGET(stunEnable), FALSE); - gtk_widget_set_sensitive( GTK_WIDGET(stunServer), FALSE); - } - else { - // Disable everything ! ouch! - // Shouldn't get there. - } - - - - gtk_widget_show_all( tableNat ); - gtk_container_set_border_width (GTK_CONTAINER(tableNat), 10); + gtk_table_attach ( GTK_TABLE( tableNat ), stunServer, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_set_sensitive( GTK_WIDGET( stunServer ), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stunEnable))); - response = gtk_dialog_run (GTK_DIALOG (dialog)); - if(response == GTK_RESPONSE_ACCEPT) - { - gchar* proto = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(entryProtocol)); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_ENABLED), - g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(entryEnabled)) ? "TRUE": "FALSE")); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_ALIAS), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryAlias)))); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_TYPE), - g_strdup(proto)); - - - if (strcmp(proto, "SIP") == 0) { - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_SIP_HOST), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryHostname)))); - - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_SIP_USER), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryUsername)))); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_SIP_PASSWORD), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryPassword)))); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_SIP_STUN_SERVER), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(stunServer)))); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_SIP_STUN_ENABLED), - g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stunEnable)) ? "TRUE": "FALSE")); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_MAILBOX), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryMailbox)))); + // Toggle enabled/disabled widgets + if (strcmp(curAccountType, "SIP") == 0) { + //gtk_widget_set_sesitive( GTK_WIDGET(entryUserPart), TRUE);< } - else if (strcmp(proto, "IAX") == 0) { - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_IAX_HOST), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryHostname)))); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_IAX_USER), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryUsername)))); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_IAX_PASSWORD), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryPassword)))); - g_hash_table_replace(currentAccount->properties, - g_strdup(ACCOUNT_MAILBOX), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryMailbox)))); + else if (strcmp(curAccountType, "IAX") == 0) { + gtk_widget_set_sensitive( GTK_WIDGET(stunEnable), FALSE); + gtk_widget_set_sensitive( GTK_WIDGET(stunServer), FALSE); } else { - + // Disable everything ! ouch! + // Shouldn't get there. } - /** @todo Verify if it's the best condition to check */ - if (currentAccount->accountID == NULL) { - dbus_add_account(currentAccount); - account_list_set_current_id( currentAccount->accountID ); - } - else { - dbus_set_account_details(currentAccount); - account_list_set_current_id( currentAccount->accountID); + + + gtk_widget_show_all( tableNat ); + gtk_container_set_border_width (GTK_CONTAINER(tableNat), 10); + + response = gtk_dialog_run (GTK_DIALOG (dialog)); + if(response == GTK_RESPONSE_ACCEPT) + { + gchar* proto = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(entryProtocol)); + + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_ENABLED), + g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(entryEnabled)) ? "TRUE": "FALSE")); + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_ALIAS), + g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryAlias)))); + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_TYPE), + g_strdup(proto)); + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_HOSTNAME), + g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryHostname)))); + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_USERNAME), + g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryUsername)))); + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_PASSWORD), + g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryPassword)))); + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_MAILBOX), + g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryMailbox)))); + + if (strcmp(proto, "SIP") == 0) { + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_SIP_STUN_SERVER), + g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(stunServer)))); + g_hash_table_replace(currentAccount->properties, + g_strdup(ACCOUNT_SIP_STUN_ENABLED), + g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stunEnable)) ? "TRUE": "FALSE")); + } + + /** @todo Verify if it's the best condition to check */ + if (currentAccount->accountID == NULL) { + dbus_add_account(currentAccount); + account_list_set_current_id( currentAccount->accountID ); + } + else { + dbus_set_account_details(currentAccount); + account_list_set_current_id( currentAccount->accountID); + } } - } - gtk_widget_destroy (GTK_WIDGET(dialog)); + gtk_widget_destroy (GTK_WIDGET(dialog)); } diff --git a/sflphone-gtk/src/assistant.c b/sflphone-gtk/src/assistant.c index bd7060e632fb4117902ac607853e9e46d85c9c6b..26694a9ef08d56fdd7535950cfa9d5ddbdd80cef 100644 --- a/sflphone-gtk/src/assistant.c +++ b/sflphone-gtk/src/assistant.c @@ -82,10 +82,9 @@ sip_apply_callback( void ) g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ENABLED), g_strdup("TRUE")); g_hash_table_insert(current->properties, g_strdup(ACCOUNT_MAILBOX), g_strdup("888")); g_hash_table_insert(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("SIP")); - g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_server)))); - //g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_PORT), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_port)))); - g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_password)))); - g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_username)))); + g_hash_table_insert(current->properties, g_strdup(ACCOUNT_HOSTNAME), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_server)))); + g_hash_table_insert(current->properties, g_strdup(ACCOUNT_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_password)))); + g_hash_table_insert(current->properties, g_strdup(ACCOUNT_USERNAME), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->sip_username)))); g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED), g_strdup((gchar *)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wiz->enable))? "TRUE":"FALSE")); g_hash_table_insert(current->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->addr)))); @@ -109,9 +108,9 @@ iax_apply_callback( void ) g_hash_table_insert(current->properties, g_strdup(ACCOUNT_ENABLED), g_strdup("TRUE")); g_hash_table_insert(current->properties, g_strdup(ACCOUNT_MAILBOX), g_strdup("888")); g_hash_table_insert(current->properties, g_strdup(ACCOUNT_TYPE), g_strdup("IAX")); - g_hash_table_insert(current->properties, g_strdup(ACCOUNT_IAX_USER), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username)))); - g_hash_table_insert(current->properties, g_strdup(ACCOUNT_IAX_HOST), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server)))); - g_hash_table_insert(current->properties, g_strdup(ACCOUNT_IAX_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password)))); + g_hash_table_insert(current->properties, g_strdup(ACCOUNT_USERNAME), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_username)))); + g_hash_table_insert(current->properties, g_strdup(ACCOUNT_HOSTNAME), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_server)))); + g_hash_table_insert(current->properties, g_strdup(ACCOUNT_PASSWORD), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(wiz->iax_password)))); dbus_add_account( current ); account_list_set_current_id( current->accountID ); diff --git a/sflphone-gtk/src/errors.c b/sflphone-gtk/src/errors.c index 9f9842720b9d5d443c9fde7148790e4d867ea675..a566ca72d8222c25ba7fd096d6d51f2b7548fc95 100644 --- a/sflphone-gtk/src/errors.c +++ b/sflphone-gtk/src/errors.c @@ -22,7 +22,7 @@ void sflphone_throw_exception( int err ) { - gchar* markup; + gchar* markup=""; switch( err ){ case ALSA_PLAYBACK_DEVICE: markup = g_markup_printf_escaped(_("<b>ALSA notification</b>\n\nError while opening playback device")); diff --git a/sflphone-gtk/src/sflphone_const.h b/sflphone-gtk/src/sflphone_const.h index 34faa3f59d9cdbdffbd0d59ed40cff3ee93217dd..cdd85602d928af95a22ee93580ab8be0885a96db 100644 --- a/sflphone-gtk/src/sflphone_const.h +++ b/sflphone-gtk/src/sflphone_const.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + #ifndef __SFLPHONE_CONST_H #define __SFLPHONE_CONST_H @@ -35,32 +35,15 @@ #define UNUSED __attribute__((__unused__)) -/** Account type : SIP / IAX */ #define ACCOUNT_TYPE "Account.type" -/** Account alias */ #define ACCOUNT_ALIAS "Account.alias" -/** Tells if account is enabled or not */ #define ACCOUNT_ENABLED "Account.enable" -/** Mail box number */ #define ACCOUNT_MAILBOX "Account.mailbox" -/** SIP parameter: host name */ -#define ACCOUNT_SIP_HOST "SIP.hostPart" -/** SIP parameter: authentification name */ -#define ACCOUNT_SIP_USER "SIP.username" -/** SIP parameter: password */ -#define ACCOUNT_SIP_PASSWORD "SIP.password" -/** SIP parameter: proxy address */ -#define ACCOUNT_SIP_PROXY "SIP.proxy" -/** SIP parameter: stun server address */ +#define ACCOUNT_HOSTNAME "hostname" +#define ACCOUNT_USERNAME "username" +#define ACCOUNT_PASSWORD "password" #define ACCOUNT_SIP_STUN_SERVER "STUN.server" -/** SIP parameter: tells if stun is enabled or not */ #define ACCOUNT_SIP_STUN_ENABLED "STUN.enable" -/** IAX2 parameter: host name */ -#define ACCOUNT_IAX_HOST "IAX.host" -/** IAX2 parameter: user name */ -#define ACCOUNT_IAX_USER "IAX.user" -/** IAX2 parameter: password name */ -#define ACCOUNT_IAX_PASSWORD "IAX.password" /** Error while opening capture device */ #define ALSA_CAPTURE_DEVICE 0x0001 diff --git a/src/Makefile.am b/src/Makefile.am index d87ca8153a824bd53485b518592774559a00e603..5be031174cdf639b7967fbb297021f6256af06e5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,17 +27,17 @@ SUBDIRS = audio config dbus $(ZEROCONFDIR) # Add here the cpp files to be build with sflphone sflphoned_SOURCES = \ - eventthread.cpp \ - main.cpp \ voiplink.cpp \ + main.cpp \ managerimpl.cpp \ observer.cpp \ samplerateconverter.cpp \ - account.cpp \ + eventthread.cpp \ sipaccount.cpp \ accountcreator.cpp \ - sipvoiplink.cpp \ + sipvoiplink.cpp \ call.cpp \ + account.cpp \ sipcall.cpp \ $(IAXSOURCES) \ useragent.cpp @@ -65,18 +65,18 @@ sflphoned_LDADD = \ noinst_LTLIBRARIES = libsflphone.la noinst_HEADERS = \ + voiplink.h \ managerimpl.h \ manager.h \ global.h \ observer.h \ eventthread.h \ user_cfg.h \ - voiplink.h \ samplerateconverter.h \ account.h \ sipaccount.h \ accountcreator.h \ - sipvoiplink.h \ + sipvoiplink.h \ call.h \ sipcall.h \ useragent.h diff --git a/src/account.cpp b/src/account.cpp index 88fdf99fda109f291d4d476ff2e830d1a6628edd..5bc6ba36ebb8325da825c8e93d3e1fdfa30dc1a7 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -1,7 +1,8 @@ /* - * Copyright (C) 2006-2007 Savoir-Faire Linux inc. + * Copyright (C) 2006-2009 Savoir-Faire Linux inc. + * + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> - * Author: Yan Morin <yan.morin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,13 +18,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + #include "account.h" -#include "voiplink.h" #include "manager.h" -#include <string> - -Account::Account(const AccountID& accountID) : _accountID(accountID), _link(NULL), _enabled(false) +Account::Account(const AccountID& accountID) : + _accountID(accountID), _link(NULL), _enabled(false) { } @@ -31,62 +31,18 @@ Account::~Account() { } -void -Account::loadConfig() +void Account::loadConfig() { - std::string p = Manager::instance().getConfigString( _accountID , CONFIG_ACCOUNT_TYPE ); + std::string p; + + p = Manager::instance().getConfigString( _accountID , CONFIG_ACCOUNT_TYPE ); #ifdef USE_IAX - _enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false; + _enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false; #else - if( p.c_str() == "IAX" ) - _enabled = false; - else - _enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false; + if( p.c_str() == "IAX" ) + _enabled = false; + else + _enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false; #endif } -// NOW -void -Account::loadContacts() -{ - /* - // TMP - Contact* contact1 = new Contact("1223345", "Guillaume140", "<sip:140@asterix.inside.savoirfairelinux.net>"); - _contacts.push_back(contact1); - Contact* contact2 = new Contact("9876543", "SFLphone131", "<sip:131@asterix.inside.savoirfairelinux.net>"); - _contacts.push_back(contact2); - Contact* contact3 = new Contact("6867823", "Guillaume201", "<sip:201@192.168.1.202:5066>"); - _contacts.push_back(contact3); - Contact* contact4 = new Contact("3417928", "SFLphone203", "<sip:203@192.168.1.202:5066>"); - _contacts.push_back(contact4); - - // TODO Load contact file containing list of contacts - // or a configuration for LDAP contacts -*/ -} - -void -Account::subscribeContactsPresence() -{ - /* - if(_link->isContactPresenceSupported()) - { - // Subscribe to presence for each contact that presence is enabled - std::vector<Contact*>::iterator iter; - - for(iter = _contacts.begin(); iter != _contacts.end(); iter++) - { - _link->subscribePresenceForContact(*iter); - } - } - */ -} - -void -Account::publishPresence(std::string presenceStatus UNUSED) -{ - /* - if(_link->isContactPresenceSupported()) - _link->publishPresenceStatus(presenceStatus); - */ -} diff --git a/src/account.h b/src/account.h index cd070f6ad93ca8aa5ad48ee2c63fd95ec58c9c3a..571f7220315facc986953b1c7a9cc9a2cb2f7b89 100644 --- a/src/account.h +++ b/src/account.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2006-2007 Savoir-Faire Linux inc. + * Copyright (C) 2006-2009 Savoir-Faire Linux inc. + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify @@ -16,11 +17,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <vector> + #include "config/config.h" #include "voiplink.h" @@ -36,132 +39,101 @@ class VoIPLink; typedef std::string AccountID; #define AccountNULL "" -/** Account type: SIP / IAX2 are supported */ -#define CONFIG_ACCOUNT_TYPE "Account.type" -/** Tells if account is enable or not */ -#define CONFIG_ACCOUNT_ENABLE "Account.enable" -/** Account alias */ + +// Common account parameters +#define CONFIG_ACCOUNT_TYPE "Account.type" #define CONFIG_ACCOUNT_ALIAS "Account.alias" -/** Mail box number */ #define CONFIG_ACCOUNT_MAILBOX "Account.mailbox" -/** IAX paramater : host name */ -#define IAX_HOST "IAX.host" -/** IAX paramater : user name */ -#define IAX_USER "IAX.user" -/** IAX paramater : password */ -#define IAX_PASSWORD "IAX.password" -/** SIP parameter : authorization name */ -#define SIP_USER "SIP.username" -/** SIP parameter : password */ -#define SIP_PASSWORD "SIP.password" -/** SIP parameter : host name */ -#define SIP_HOST "SIP.hostPart" -/** SIP parameter : proxy address */ +#define CONFIG_ACCOUNT_ENABLE "Account.enable" +#define HOSTNAME "hostname" +#define USERNAME "username" +#define PASSWORD "password" + +// SIP specific parameters #define SIP_PROXY "SIP.proxy" -/** SIP parameter : stun server address */ #define SIP_STUN_SERVER "STUN.server" -/** SIP parameter : tells if stun is used or not */ #define SIP_USE_STUN "STUN.enable" -/** SIP parameter : stun port */ #define SIP_STUN_PORT "STUN.port" class Account{ - public: - Account(const AccountID& accountID); - - /** - * Virtual destructor - */ - virtual ~Account(); - - - /** - * Load the settings for this account. - */ - virtual void loadConfig(); - - /** - * Get the account ID - * @return constant account id - */ - inline const AccountID& getAccountID() { return _accountID; } - - /** - * Get the voiplink pointer - * @return VoIPLink* the pointer or 0 - */ - inline VoIPLink* getVoIPLink() { return _link; } - - /** - * Register the underlying VoIPLink. Launch the event listener. - * This should update the getRegistrationState() return value. - */ - virtual int registerVoIPLink() = 0; - - /** - * Unregister the underlying VoIPLink. Stop the event listener. - * This should update the getRegistrationState() return value. - */ - virtual int unregisterVoIPLink() = 0; - - /** - * Tell if the account is enable or not. - * @return true if enabled - * false otherwise - */ - bool isEnabled() { return _enabled; } - - /** - * Get the registration state of the specified link - * @return RegistrationState The registration state of underlying VoIPLink - */ - VoIPLink::RegistrationState getRegistrationState() { return _link->getRegistrationState(); } - - /** - * Load all contacts - */ - void loadContacts(); - - /** - * Suscribe presence information for selected contacts if supported - */ - void subscribeContactsPresence(); - - /** - * Publish our presence information to the server - */ - void publishPresence(std::string presenceStatus); - -private: - - // copy constructor - Account(const Account& rh); - - // assignment operator - Account& operator=(const Account& rh); - -protected: - /** - * Account ID are assign in constructor and shall not changed - */ - AccountID _accountID; - - /** - * Voice over IP Link contains a listener thread and calls - */ - VoIPLink* _link; - - /** - * Tells if the link is enabled, active. - * This implies the link will be initialized on startup. - * Modified by the configuration (key: ENABLED) - */ - bool _enabled; - - /** - * Contacts related to account that can have presence information - */ - //std::vector<Contact*> _contacts; + + public: + + Account(const AccountID& accountID); + + /** + * Virtual destructor + */ + virtual ~Account(); + + /** + * Load the settings for this account. + */ + virtual void loadConfig(); + + /** + * Get the account ID + * @return constant account id + */ + inline const AccountID& getAccountID() { return _accountID; } + + /** + * Get the voiplink pointer + * @return VoIPLink* the pointer or 0 + */ + inline VoIPLink* getVoIPLink() { return _link; } + + /** + * Register the underlying VoIPLink. Launch the event listener. + * This should update the getRegistrationState() return value. + */ + virtual int registerVoIPLink() = 0; + + /** + * Unregister the underlying VoIPLink. Stop the event listener. + * This should update the getRegistrationState() return value. + */ + virtual int unregisterVoIPLink() = 0; + + /** + * Tell if the account is enable or not. + * @return true if enabled + * false otherwise + */ + bool isEnabled() { return _enabled; } + + /** + * Get the registration state of the specified link + * @return RegistrationState The registration state of underlying VoIPLink + */ + VoIPLink::RegistrationState getRegistrationState() { return _link->getRegistrationState(); } + + private: + + // copy constructor + Account(const Account& rh); + + // assignment operator + Account& operator=(const Account& rh); + + protected: + /** + * Account ID are assign in constructor and shall not changed + */ + AccountID _accountID; + + /** + * Voice over IP Link contains a listener thread and calls + */ + VoIPLink* _link; + + /** + * Tells if the link is enabled, active. + * This implies the link will be initialized on startup. + * Modified by the configuration (key: ENABLED) + */ + bool _enabled; + }; #endif diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 7f7e0fb7849426767aed36cd79eb987ffc490802..c2f3ec87673b1d73b58029c8215bd0cfc3a24b43 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -142,6 +142,8 @@ AudioRtpRTX::~AudioRtpRTX () { delete [] spkrDataConverted; spkrDataConverted = NULL; delete time; time = NULL; + + delete converter; converter = NULL; } void diff --git a/src/audio/codecDescriptor.h b/src/audio/codecDescriptor.h index 9369117148fe149d5f9a18e076cdcd5bb9a139bb..e23a18509dae5555938deb0b02ec363560097966 100644 --- a/src/audio/codecDescriptor.h +++ b/src/audio/codecDescriptor.h @@ -22,7 +22,6 @@ #ifndef __CODEC_DESCRIPTOR_H__ #define __CODEC_DESCRIPTOR_H__ -#include <string> #include <map> #include <vector> #include <dirent.h> diff --git a/src/audio/pulselayer.cpp b/src/audio/pulselayer.cpp index f13f463719bd5332c8bc3bc094af63794fd6279b..d0f14c36ce03e32bb6be940c152c804d521ac05d 100644 --- a/src/audio/pulselayer.cpp +++ b/src/audio/pulselayer.cpp @@ -117,10 +117,10 @@ void PulseLayer::context_state_callback( pa_context* c, void* user_data ) void PulseLayer::disconnectPulseAudioServer( void ) { if( playback ) - delete playback; + delete playback; playback=NULL; if( record ) - delete record; + delete record; record=NULL; } void diff --git a/src/audio/ringbuffer.cpp b/src/audio/ringbuffer.cpp index f56e8ec0e93e5f85ec0e59d8c1ba7235fcafa66f..12cac26c34e9ed63b1881c9bacf84f05b20ba424 100644 --- a/src/audio/ringbuffer.cpp +++ b/src/audio/ringbuffer.cpp @@ -32,8 +32,9 @@ // Create a ring buffer with 'size' bytes RingBuffer::RingBuffer(int size): mStart( 0 ), mEnd( 0 ) , mBufferSize( size > MIN_BUFFER_SIZE ? size : MIN_BUFFER_SIZE ) - , mBuffer (new unsigned char[mBufferSize]) + , mBuffer(NULL) { + mBuffer = new unsigned char[mBufferSize]; assert (mBuffer != NULL); } diff --git a/src/call.h b/src/call.h index 63b2de4443d93d6a89350e1e7768f597dc1c6380..32ce4f30e7a8c6085228765d9ea7ec1eef4163cf 100644 --- a/src/call.h +++ b/src/call.h @@ -20,8 +20,8 @@ #ifndef CALL_H #define CALL_H -#include <string> #include <cc++/thread.h> // for mutex + #include "audio/codecDescriptor.h" /* diff --git a/src/config/config.cpp b/src/config/config.cpp index c32ea177199f92dfe37646bf60dadd8237840be9..2c26e203172d28075e054901fb3a585e1e6030d3 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -176,6 +176,7 @@ bool ConfigTree::setConfigTreeItem(const std::string& section, const std::string& itemName, const std::string& value) { + SectionMap::iterator iter = _sections.find(section); if ( iter == _sections.end()) { // Not found, create section diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 1ec4363470bf3533683541a56f9dcfbcdc43eddb..66e6d441090be9d70a785ecc7fa0ff44a5256b44 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -21,7 +21,6 @@ #include "eventthread.h" #include "voiplink.h" - EventThread::EventThread (VoIPLink* link) : Thread (), _linkthread(link), stopIt(false) { setCancel(cancelDeferred); diff --git a/src/global.h b/src/global.h index e95d776764d08d4d0935d08bed9890873ae13a27..e752d41b2f5ee4be78392cd0dd67308e19bf2b93 100644 --- a/src/global.h +++ b/src/global.h @@ -27,73 +27,51 @@ #include <libintl.h> #include <locale.h> +#define SFLPHONED_VERSION "0.9.2-4" /** Version number */ + typedef float float32; typedef short int16; - #define SUCCESS 0 #define ASSERT( expected , value) if( value == expected ) return SUCCESS; \ else return 1; #define PIDFILE "sfl.pid" + #ifdef DATAFORMAT_IS_FLOAT #define SFLDataFormat float32 #define SFLDataFormatString "Float32" #define SFLDataAmplitude 0.05 -#define SFLConvertInt16(s) ((float)(s)-16384.0)/16384.0 #else #define SFLDataFormat int16 #define SFLDataFormatString "Int16" #define SFLDataAmplitude (32767 >> 4) -#define SFLConvertInt16(s) (s) #endif #ifdef SFLDEBUG #define _debug(...) fprintf(stderr, "[sfl-debug] " __VA_ARGS__) - #define _debugStart(...) fprintf(stderr, "[sfl-debug] " __VA_ARGS__) - #define _debugMid(...) fprintf(stderr, __VA_ARGS__) - #define _debugEnd(...) fprintf(stderr, __VA_ARGS__) #define _debugException(...) fprintf(stderr, "[sfl-excep] " __VA_ARGS__ "\n") #define _debugInit(...) fprintf(stderr, "[sfl-init] " __VA_ARGS__ "\n") #define _debugAlsa(...) fprintf(stderr, "[alsa-debug] " __VA_ARGS__ ) #else #define _debug(...) - #define _debugStart(...) - #define _debugMid(...) - #define _debugEnd(...) #define _debugException(...) #define _debugInit(...) #define _debugAlsa(...) #endif -#define SFLPHONED_VERSION "0.8.2" /** Version number */ -#define SFLPHONED_VERSIONNUM 0x000802 - #define PROGNAME "sflphoned" /** Binary name */ -#define PROGNAME_GLOBAL "sflphone" /** Program name */ #define PROGDIR "sflphone" /** Program directory */ #define RINGDIR "ringtones" /** Ringtones directory */ #define CODECDIR "codecs" /** Codecs directory */ -#define _(arg) arg -#define MONO 1 -#define CHANNELS 2 #define SIZEBUF 1024*1024 #define ALSA_DFT_CARD_ID 0 /** Index of the default soundcard */ -#define PCM_HW "hw" /** Alsa plugin hardware */ #define PCM_PLUGHW "plughw" /** Alsa plugin */ -#define PCM_PULSE "pulse" /** Alsa plugin for pulse audio */ -#define PCM_FRONT "plug:front" /** Alsa plugin: front PCM */ #define PCM_DEFAULT "default" /** Default ALSA plugin */ #define PCM_DMIX "plug:dmix" /** Alsa plugin for software mixing */ -#define PCM_DSNOOP "plug:dsnoop" /** Alsa plugin for software mixing */ -#define PCM_SURROUND40 "plug:surround40" /** Alsa plugin: surround40 */ -#define PCM_SURROUND41 "plug:surround41" /** Alsa plugin: surround41 */ -#define PCM_SURROUND50 "plug:surround50" /** Alsa plugin: surround50 */ -#define PCM_SURROUND51 "plug:surround51" /** Alsa plugin: surround51 */ -#define PCM_SURROUND71 "plug:surround71" /** Alsa plugin: surround71 */ #define SFL_CODEC_VALID_PREFIX "libcodec_" /** Valid prefix for codecs shared library */ #define SFL_CODEC_VALID_EXTEN ".so" /** Valid extension for codecs shared library */ @@ -134,4 +112,6 @@ typedef short int16; #define UNUSED __attribute__((__unused__)) +#define DEFAULT_SIP_PORT 5060 + #endif // __GLOBAL_H__ diff --git a/src/iaxaccount.cpp b/src/iaxaccount.cpp index d038bab844664cbcb9e92aa9972772c037a9a616..364f0ab31b028944112bc177ce85e2b45e6e3b81 100644 --- a/src/iaxaccount.cpp +++ b/src/iaxaccount.cpp @@ -1,7 +1,8 @@ /* - * Copyright (C) 2006-2007 Savoir-Faire Linux inc. + * Copyright (C) 2006-2009 Savoir-Faire Linux inc. + * + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> - * Author: Yan Morin <yan.morin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,58 +18,55 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + #include "iaxaccount.h" -#include "account.h" #include "iaxvoiplink.h" -#include "manager.h" -IAXAccount::IAXAccount(const AccountID& accountID) - : Account(accountID) + IAXAccount::IAXAccount(const AccountID& accountID) +: Account(accountID) { - _link = new IAXVoIPLink(accountID); + _link = new IAXVoIPLink(accountID); } IAXAccount::~IAXAccount() { - delete _link; - _link = NULL; + delete _link; + _link = NULL; } -int + int IAXAccount::registerVoIPLink() { - _link->init(); + IAXVoIPLink *thislink; + + _link->init(); - //unregisterAccount(); No need to unregister first. - IAXVoIPLink* thislink = dynamic_cast<IAXVoIPLink*> (_link); - if (thislink) { - // Stuff needed for IAX registration - thislink->setHost(Manager::instance().getConfigString(_accountID, IAX_HOST)); - thislink->setUser(Manager::instance().getConfigString(_accountID, IAX_USER)); - thislink->setPass(Manager::instance().getConfigString(_accountID, IAX_PASSWORD)); - } + thislink = dynamic_cast<IAXVoIPLink*> (_link); + if (thislink) { + // Stuff needed for IAX registration + thislink->setHost(Manager::instance().getConfigString(_accountID, HOSTNAME)); + thislink->setUser(Manager::instance().getConfigString(_accountID, USERNAME)); + thislink->setPass(Manager::instance().getConfigString(_accountID, PASSWORD)); + } - _link->sendRegister(); + _link->sendRegister(); - return SUCCESS; + return SUCCESS; } -int + int IAXAccount::unregisterVoIPLink() { - _link->sendUnregister(); - _link->terminate(); + _link->sendUnregister(); + _link->terminate(); - return SUCCESS; + return SUCCESS; } -void + void IAXAccount::loadConfig() { - // Account generic - Account::loadConfig(); - - // IAX specific - //none + // Account generic + Account::loadConfig(); } diff --git a/src/iaxaccount.h b/src/iaxaccount.h index cb7a2c861e1eaac58a4572d281717319535f9fd2..9c40df1194a5625b3e4fc4e6495778ede20a2c4c 100644 --- a/src/iaxaccount.h +++ b/src/iaxaccount.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2007 Savoir-Faire Linux inc. + * Copyright (C) 2006-2009 Savoir-Faire Linux inc. * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> * @@ -22,34 +22,33 @@ #include "account.h" - /** * @file: iaxaccount.h * @brief An IAX Account specify IAX specific functions and objects (IAXCall/IAXVoIPLink) */ class IAXAccount : public Account { -public: - IAXAccount(const AccountID& accountID); + public: + IAXAccount(const AccountID& accountID); - ~IAXAccount(); + ~IAXAccount(); - /** - * Actually unuseful, since config loading is done in init() - */ - void loadConfig(); + /** + * Actually unuseful, since config loading is done in init() + */ + void loadConfig(); - /** - * Register an account - */ - int registerVoIPLink(); + /** + * Register an account + */ + int registerVoIPLink(); - /** - * Unregister an account - */ - int unregisterVoIPLink(); + /** + * Unregister an account + */ + int unregisterVoIPLink(); -private: + private: }; #endif diff --git a/src/iaxvoiplink.cpp b/src/iaxvoiplink.cpp index 730eada2a63587c04bd62bb15a24a780f0f2b829..6d04dffcaeae225d5d75207136262f3a36705b1c 100644 --- a/src/iaxvoiplink.cpp +++ b/src/iaxvoiplink.cpp @@ -173,6 +173,7 @@ IAXVoIPLink::getEvent() // lock iax_ stuff.. _mutexIAX.enterMutex(); iax_event* event = NULL; + while ( (event = iax_get_event(IAX_NONBLOCKING)) != NULL ) { // If we received an 'ACK', libiax2 tells apps to ignore them. if (event->etype == IAX_EVENT_NULL) { @@ -211,6 +212,7 @@ IAXVoIPLink::getEvent() // thread wait 3 millisecond _evThread->sleep(3); + free(event); } void diff --git a/src/iaxvoiplink.h b/src/iaxvoiplink.h index f01ce54dad66c8cca18513b9facb03ecf6df173c..fe8978c1b390724ea8a8d2e172a4e15ee359fc25 100644 --- a/src/iaxvoiplink.h +++ b/src/iaxvoiplink.h @@ -67,13 +67,6 @@ class IAXVoIPLink : public VoIPLink */ bool init (void); - /** - * Check if a local IP can be found - * @return true if pingable - * false otherwise - */ - bool checkNetwork (void) { return false; } - /** * Terminate a voip link by clearing the call list */ diff --git a/src/main.cpp b/src/main.cpp index 88c44d927aa2dbe78225a4c321e3ce0b2e777788..7ae724194b4ae53525d0587e490195b6e7772dc9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,14 +42,14 @@ main (int argc, char **argv) { //bindtextdomain (PACKAGE, LOCALEDIR); //textdomain (PACKAGE); - if (argc == 2 && strcmp(argv[1], _("--help")) == 0) { + if (argc == 2 && strcmp(argv[1], "--help") == 0) { - printf(_("%1$s Daemon %2$s, by Savoir-Faire Linux 2004-2005\n\n"), + printf("%1$s Daemon %2$s, by Savoir-Faire Linux 2004-2009\n\n", PROGNAME, SFLPHONED_VERSION); - printf(_("USAGE: sflphoned [--help]\nParameters: \n --help\tfor this message\n\n --port=3999\tchange the session port\n\n")); - printf(_("See http://www.sflphone.org/ for more information\n")); + printf("USAGE: sflphoned [--help]\nParameters: \n --help\tfor this message\n\n --port=3999\tchange the session port\n\n"); + printf("See http://www.sflphone.org/ for more information\n"); } else { FILE *fp; @@ -76,7 +76,7 @@ main (int argc, char **argv) { // PID file doesn't exists, create and write pid in it if( (fp = fopen(homepid,"w")) == NULL ){ - fprintf(stderr, _("Creating PID file %s failed. Exited.\n"), homepid); + fprintf(stderr, "Creating PID file %s failed. Exited.\n", homepid); exit(-1); } else { fputs(cPid , fp ); @@ -87,11 +87,11 @@ main (int argc, char **argv) { fgets( cOldPid, 64, fp ); fclose(fp); if (kill(atoi(cOldPid), 0) == SUCCESS) { - fprintf(stderr, _("There is already a sflphoned daemon running in the system. Starting Failed.\n")); + fprintf(stderr, "There is already a sflphoned daemon running in the system. Starting Failed.\n"); exit(-1); } else { if( (fp = fopen(homepid,"w")) == NULL ){ - fprintf(stderr, _("Writing to PID file %s failed. Exited.\n"), homepid); + fprintf(stderr, "Writing to PID file %s failed. Exited.\n", homepid); exit(-1); } else { fputs(cPid , fp ); @@ -119,7 +119,7 @@ main (int argc, char **argv) { exit_code = -1; } catch (...) { - fprintf(stderr, _("An exception occured when initializing the system.\n")); + fprintf(stderr, "An exception occured when initializing the system.\n"); exit_code = -1; } if (initOK) { diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 320d81f89c75af7504533c02c3c30468f188599a..c6177f35fc920738250824a767cd0f07635b32f2 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -50,8 +50,6 @@ #include "user_cfg.h" -#define DEFAULT_SIP_PORT 5060 - #ifdef USE_ZEROCONF #include "zeroconf/DNSService.h" #include "zeroconf/DNSServiceTXTRecord.h" @@ -292,16 +290,6 @@ ManagerImpl::answerCall(const CallID& id) return true; } -//THREAD=Main - bool -ManagerImpl::sendTextMessage(const AccountID& accountId, const std::string& to, const std::string& message) -{ - if (accountExists(accountId)) { - return getAccountLink(accountId)->sendMessage(to, message); - } - return false; -} - //THREAD=Main bool ManagerImpl::hangupCall(const CallID& id) @@ -730,45 +718,12 @@ ManagerImpl::startVoiceMessageNotification(const AccountID& accountId, int nb_ms if (_dbus) _dbus->getCallManager()->voiceMailNotify(accountId, nb_msg) ; } -//THREAD=VoIP - void -ManagerImpl::registrationSucceed(const AccountID& accountid) -{ - Account* acc = getAccount(accountid); - if ( acc ) { - _debug("REGISTRATION SUCCEED\n"); - if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); - } -} - -//THREAD=VoIP - void -ManagerImpl::unregistrationSucceed(const AccountID& accountid UNUSED) +void ManagerImpl::connectionStatusNotification( void ) { - _debug("UNREGISTRATION SUCCEED\n"); - if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); -} - -//THREAD=VoIP - void -ManagerImpl::registrationFailed(const AccountID& accountid) -{ - Account* acc = getAccount(accountid); - if ( acc ) { - _debug("REGISTRATION FAILED\n"); - if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); - } -} - -//THREAD=VoIP - void -ManagerImpl::registrationTrying(const AccountID& accountid) -{ - Account* acc = getAccount(accountid); - if ( acc ) { - _debug("REGISTRATION TRYING\n"); - if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); - } + if (_dbus) + _dbus->getConfigurationManager()->accountsChanged(); + else + _debug("Error: DBus connection not found\n"); } /** @@ -2001,29 +1956,19 @@ ManagerImpl::getAccountList() return v; } - std::map< std::string, std::string > -ManagerImpl::getAccountDetails(const AccountID& accountID) +std::map< std::string, std::string > ManagerImpl::getAccountDetails(const AccountID& accountID) { + std::map<std::string, std::string> a; std::string accountType; - enum VoIPLink::RegistrationState state = _accountMap[accountID]->getRegistrationState(); - + enum VoIPLink::RegistrationState state; + + state = _accountMap[accountID]->getRegistrationState(); accountType = getConfigString(accountID, CONFIG_ACCOUNT_TYPE); - a.insert( - std::pair<std::string, std::string>( - CONFIG_ACCOUNT_ALIAS, - getConfigString(accountID, CONFIG_ACCOUNT_ALIAS) - ) - ); - a.insert( - std::pair<std::string, std::string>( - CONFIG_ACCOUNT_ENABLE, - getConfigString(accountID, CONFIG_ACCOUNT_ENABLE) == "1" ? "TRUE": "FALSE" - ) - ); - a.insert( - std::pair<std::string, std::string>( + a.insert( std::pair<std::string, std::string>( CONFIG_ACCOUNT_ALIAS, getConfigString(accountID, CONFIG_ACCOUNT_ALIAS)) ); + a.insert( std::pair<std::string, std::string>( CONFIG_ACCOUNT_ENABLE, getConfigString(accountID, CONFIG_ACCOUNT_ENABLE) == "1" ? "TRUE": "FALSE")); + a.insert( std::pair<std::string, std::string>( "Status", (state == VoIPLink::Registered ? "REGISTERED": (state == VoIPLink::Unregistered ? "UNREGISTERED": @@ -2036,155 +1981,78 @@ ManagerImpl::getAccountDetails(const AccountID& accountID) (state == VoIPLink::Error ? "ERROR": "ERROR"))))))))) ) ); - a.insert( - std::pair<std::string, std::string>( - CONFIG_ACCOUNT_TYPE, accountType - ) - ); - + + a.insert( std::pair<std::string, std::string>( CONFIG_ACCOUNT_TYPE, accountType ) ); + a.insert( std::pair<std::string, std::string>( USERNAME, getConfigString(accountID, USERNAME) ) ); + a.insert( std::pair<std::string, std::string>( PASSWORD, getConfigString(accountID, PASSWORD) ) ); + a.insert( std::pair<std::string, std::string>( HOSTNAME, getConfigString(accountID, HOSTNAME) ) ); + a.insert( std::pair<std::string, std::string>( CONFIG_ACCOUNT_MAILBOX, getConfigString(accountID, CONFIG_ACCOUNT_MAILBOX)) ); + + // SIP SPECIFIC if( accountType == "SIP") { - a.insert( - std::pair<std::string, std::string>( - SIP_USER, - getConfigString(accountID, SIP_USER) - ) - ); - a.insert( - std::pair<std::string, std::string>( - SIP_PASSWORD, - getConfigString(accountID, SIP_PASSWORD) - ) - ); - a.insert( - std::pair<std::string, std::string>( - SIP_HOST, - getConfigString(accountID, SIP_HOST) - ) - ); - a.insert( - std::pair<std::string, std::string>( - SIP_PROXY, - getConfigString(accountID, SIP_PROXY) - ) - ); - a.insert( - std::pair<std::string, std::string>( - SIP_STUN_SERVER, - getConfigString(accountID, SIP_STUN_SERVER) - ) - ); - a.insert( - std::pair<std::string, std::string>( - SIP_USE_STUN, - getConfigString(accountID, SIP_USE_STUN) == "1" ? "TRUE": "FALSE" - ) - ); - a.insert( - std::pair<std::string, std::string>( - CONFIG_ACCOUNT_MAILBOX, - getConfigString(accountID, CONFIG_ACCOUNT_MAILBOX) - ) - ); - } - else if (accountType == "IAX") { - a.insert( - std::pair<std::string, std::string>( - IAX_HOST, - getConfigString(accountID, IAX_HOST) - ) - ); - a.insert( - std::pair<std::string, std::string>( - IAX_USER, - getConfigString(accountID, IAX_USER) - ) - ); - a.insert( - std::pair<std::string, std::string>( - IAX_PASSWORD, - getConfigString(accountID, IAX_PASSWORD) - ) - ); - a.insert( - std::pair<std::string, std::string>( - CONFIG_ACCOUNT_MAILBOX, - getConfigString(accountID, CONFIG_ACCOUNT_MAILBOX) - ) - ); - } - else { - // Unknown type - _debug("Unknown account type in getAccountDetails(): %s", accountType.c_str()); + a.insert( std::pair<std::string, std::string>( SIP_STUN_SERVER, getConfigString(accountID, SIP_STUN_SERVER) ) ); + a.insert( std::pair<std::string, std::string>( SIP_USE_STUN, getConfigString(accountID, SIP_USE_STUN) == "1" ? "TRUE": "FALSE")); } return a; } - void -ManagerImpl::setAccountDetails( const std::string& accountID, - const std::map< std::string, std::string >& details ) +void ManagerImpl::setAccountDetails( const std::string& accountID, const std::map< std::string, std::string >& details ) { - std::string accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second; - - setConfig(accountID, CONFIG_ACCOUNT_ALIAS, (*details.find(CONFIG_ACCOUNT_ALIAS)).second); - setConfig(accountID, CONFIG_ACCOUNT_ENABLE, (*details.find(CONFIG_ACCOUNT_ENABLE)).second == "TRUE" ? "1": "0" ); - setConfig(accountID, CONFIG_ACCOUNT_TYPE, accountType); + std::string accountType; + Account *acc; - if (accountType == "SIP") { - setConfig(accountID, SIP_USER, (*details.find(SIP_USER)).second); - setConfig(accountID, SIP_PASSWORD, (*details.find(SIP_PASSWORD)).second); - setConfig(accountID, SIP_HOST, (*details.find(SIP_HOST)).second); - setConfig(accountID, SIP_STUN_SERVER,(*details.find(SIP_STUN_SERVER)).second); + accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second; + + setConfig(accountID, CONFIG_ACCOUNT_ALIAS, (*details.find(CONFIG_ACCOUNT_ALIAS)).second); + setConfig(accountID, CONFIG_ACCOUNT_ENABLE, (*details.find(CONFIG_ACCOUNT_ENABLE)).second == "TRUE" ? "1": "0" ); + setConfig(accountID, CONFIG_ACCOUNT_TYPE, accountType); + setConfig(accountID, USERNAME, (*details.find(USERNAME)).second); + setConfig(accountID, PASSWORD, (*details.find(PASSWORD)).second); + setConfig(accountID, HOSTNAME, (*details.find(HOSTNAME)).second); setConfig(accountID, CONFIG_ACCOUNT_MAILBOX,(*details.find(CONFIG_ACCOUNT_MAILBOX)).second); - setConfig(accountID, SIP_USE_STUN, - (*details.find(SIP_USE_STUN)).second == "TRUE" ? "1" : "0"); - - if(!_userAgentInitlized) { - _userAgentInitlized = true; - - if((*details.find(SIP_USE_STUN)).second == "TRUE") - _userAgent->setStunServer((*details.find(SIP_STUN_SERVER)).second.data()); - else - _userAgent->setStunServer(NULL); - - _userAgent->sipCreate(); - _userAgent->sipInit(); - } else { - if((*details.find(SIP_USE_STUN)).second == "TRUE") - _userAgent->setStunServer((*details.find(SIP_STUN_SERVER)).second.data()); - else - _userAgent->setStunServer(NULL); - - restartPjsip(); - - } - - } - else if (accountType == "IAX") { - setConfig(accountID, IAX_HOST, (*details.find(IAX_HOST)).second); - setConfig(accountID, IAX_USER, (*details.find(IAX_USER)).second); - setConfig(accountID, IAX_PASSWORD, (*details.find(IAX_PASSWORD)).second); - setConfig(accountID, CONFIG_ACCOUNT_MAILBOX, (*details.find(CONFIG_ACCOUNT_MAILBOX)).second); - } else { - _debug("Unknown account type in setAccountDetails(): %s\n", accountType.c_str()); - } - - saveConfig(); - Account* acc = getAccount(accountID); - acc->loadConfig(); - if (acc->isEnabled()){ - acc->unregisterVoIPLink(); - acc->registerVoIPLink();} - else - acc->unregisterVoIPLink(); + // SIP SPECIFIC + if (accountType == "SIP") { + setConfig(accountID, SIP_STUN_SERVER,(*details.find(SIP_STUN_SERVER)).second); + setConfig(accountID, SIP_USE_STUN, (*details.find(SIP_USE_STUN)).second == "TRUE" ? "1" : "0"); + + if(!_userAgentInitlized) { + _userAgentInitlized = true; + + if((*details.find(SIP_USE_STUN)).second == "TRUE") + _userAgent->setStunServer((*details.find(SIP_STUN_SERVER)).second.data()); + else + _userAgent->setStunServer(NULL); + + _userAgent->sipCreate(); + _userAgent->sipInit(); + } else { + if((*details.find(SIP_USE_STUN)).second == "TRUE") + _userAgent->setStunServer((*details.find(SIP_STUN_SERVER)).second.data()); + else + _userAgent->setStunServer(NULL); + + restartPjsip(); + } + } + + saveConfig(); + + acc = getAccount(accountID); + acc->loadConfig(); + if (acc->isEnabled()){ + acc->unregisterVoIPLink(); + acc->registerVoIPLink(); + } + else + acc->unregisterVoIPLink(); - // Update account details - if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); + // Update account details to the client side + if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); - //restartPjsip(); } void @@ -2338,7 +2206,7 @@ ManagerImpl::restartPjsip() short ManagerImpl::loadAccountMap() { - _debugStart("Load account:"); + _debug("Load account:"); short nbAccount = 0; TokenList sections = _config.getSections(); std::string accountType; @@ -2386,12 +2254,12 @@ ManagerImpl::loadAccountMap() } if (tmpAccount != NULL) { - _debugMid(" %s ", iter->c_str()); + _debug(" %s ", iter->c_str()); _accountMap[iter->c_str()] = tmpAccount; nbAccount++; } - _debugEnd("\n"); + _debug("\n"); iter++; } diff --git a/src/managerimpl.h b/src/managerimpl.h index 1d06bd331fc5f39e3ac2f0220a58921d9cb02cd0..a76987d758b48188f60e853759be06a51d5b75de 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -181,11 +181,6 @@ class ManagerImpl { */ bool _hasTriedToRegister; - /** - * Undocumented - */ - bool sendTextMessage(const AccountID& accountId, const std::string& to, const std::string& message); - /** * Handle choice of the DTMF-send-way * @param id: callid of the line. @@ -257,35 +252,16 @@ class ManagerImpl { void incomingMessage(const AccountID& accountId, const std::string& message); /** - * Notify the user he has voice mails + * Notify the client he has voice mails * @param accountId The account identifier * @param nb_msg The number of messages */ void startVoiceMessageNotification(const AccountID& accountId, int nb_msg); /** - * Notify the user that registration succeeded - * @param accountId The account identifier - */ - void registrationSucceed(const AccountID& accountId); - - /** - * Notify the user that unregistration succeeded - * @param accountId The account identifier - */ - void unregistrationSucceed(const AccountID& accountId); - - /** - * Notify the user that registration failed - * @param accountId The account identifier - */ - void registrationFailed(const AccountID& accountId); - - /** - * Notify the user that registration is trying - * @param accountId The account identifier + * Notify the client through DBus that registration state has been updated */ - void registrationTrying(const AccountID& accountId); + void connectionStatusNotification(void); /** * ConfigurationManager - Send registration request diff --git a/src/sipaccount.cpp b/src/sipaccount.cpp index 8453b1f29bb0a7a39a433a203302bfab48777626..acce1bb66ed5fff56fad4d6a3d20b77c6ba146a0 100644 --- a/src/sipaccount.cpp +++ b/src/sipaccount.cpp @@ -1,8 +1,7 @@ - -#include "voiplink.h" - /* - * Copyright (C) 2006-2007 Savoir-Faire Linux inc. + * Copyright (C) 2006-2009 Savoir-Faire Linux inc. + * + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> * @@ -20,8 +19,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + #include "sipaccount.h" -#include "sipvoiplink.h" #include "manager.h" #include "user_cfg.h" #include "useragent.h" @@ -52,7 +51,7 @@ SIPAccount::registerVoIPLink() int status, useStun; SIPVoIPLink *thislink; - _link->setHostName(Manager::instance().getConfigString(_accountID,SIP_HOST)); + _link->setHostname(Manager::instance().getConfigString(_accountID,HOSTNAME)); useStun = Manager::instance().getConfigInt(_accountID,SIP_USE_STUN); thislink = dynamic_cast<SIPVoIPLink*> (_link); @@ -62,10 +61,9 @@ SIPAccount::registerVoIPLink() _link->init(); // Stuff needed for SIP registration. - thislink->setProxy (Manager::instance().getConfigString(_accountID,SIP_PROXY)); - thislink->setAuthName(Manager::instance().getConfigString(_accountID,SIP_USER)); - thislink->setPassword(Manager::instance().getConfigString(_accountID,SIP_PASSWORD)); - thislink->setSipServer(Manager::instance().getConfigString(_accountID,SIP_HOST)); + thislink->setUsername(Manager::instance().getConfigString(_accountID, USERNAME)); + thislink->setPassword(Manager::instance().getConfigString(_accountID, PASSWORD)); + thislink->setHostname(Manager::instance().getConfigString(_accountID, HOSTNAME)); status = _link->sendRegister(); ASSERT( status , SUCCESS ); @@ -78,7 +76,6 @@ SIPAccount::unregisterVoIPLink() { _debug("SIPAccount: unregister account %s\n" , getAccountID().c_str()); _link->sendUnregister(); - _debug("Terminate SIP account\n"); _link->terminate(); return SUCCESS; @@ -89,9 +86,6 @@ SIPAccount::loadConfig() { // Account generic Account::loadConfig(); - - // SIP specific - //none } bool diff --git a/src/sipaccount.h b/src/sipaccount.h index 40ca2c876d491e096233b9b12ef2d29ac89609db..549d1a6d0d857326720e81b9863df9a4ca045083 100644 --- a/src/sipaccount.h +++ b/src/sipaccount.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2006-2007 Savoir-Faire Linux inc. + * Copyright (C) 2006-2009 Savoir-Faire Linux inc. + * + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> * @@ -17,10 +19,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + #ifndef SIPACCOUNT_H #define SIPACCOUNT_H #include "account.h" +#include "sipvoiplink.h" struct pjsip_cred_info; diff --git a/src/sipcall.cpp b/src/sipcall.cpp index 9efbd661fbbe950f84b6724a4bbadef01855b0d4..0e53bdd013d066744d80db93204ffbf14a46549f 100644 --- a/src/sipcall.cpp +++ b/src/sipcall.cpp @@ -212,6 +212,7 @@ void SIPCall::sdpAddMediaDescription(pj_pool_t* pool) { pjmedia_sdp_media* med; pjmedia_sdp_attr *attr; + pjmedia_sdp_rtpmap rtpMap; //int nbMedia, i; med = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_media); @@ -230,12 +231,12 @@ void SIPCall::sdpAddMediaDescription(pj_pool_t* pool) med->desc.fmt_count = count; int i = 0; + while(itr != _codecMap.getActiveCodecs().end()) { std::ostringstream format; format << *itr; pj_strdup2(pool, &med->desc.fmt[i], format.str().data()); - pjmedia_sdp_rtpmap rtpMap; rtpMap.pt = med->desc.fmt[i]; rtpMap.enc_name = pj_str((char *)_codecMap.getCodecName(*itr).data()); rtpMap.clock_rate = _codecMap.getSampleRate(*itr); diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 061df2f3a106a5733163ab39838dce024129ab5d..cc7e147a8b12f7549173727a6fa01d02d1f934ea 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -1,5 +1,7 @@ /* - * Copyright (C) 2004-2006 Savoir-Faire Linux inc. + * Copyright (C) 2004-2009 Savoir-Faire Linux inc. + * + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> * Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com> * @@ -31,9 +33,6 @@ #include "manager.h" #include "user_cfg.h" // SIGNALISATION / PULSE #define -// for listener -#define DEFAULT_SIP_PORT 5060 -#define RANDOM_SIP_PORT rand() % 64000 + 1024 #define RANDOM_LOCAL_PORT ((rand() % 27250) + 5250)*2 // 1XX responses @@ -51,12 +50,8 @@ SIPVoIPLink::SIPVoIPLink(const AccountID& accountID) , _stunServer("") , _localExternAddress("") , _localExternPort(0) - , _proxy("") - , _authname("") - , _password("") , _audiortp(new AudioRtp()) , _regc() - , _server("") , _bRegister(false) { // to get random number for RANDOM_PORT @@ -100,32 +95,6 @@ SIPVoIPLink::terminateSIPCall() _callMap.clear(); } -bool -SIPVoIPLink::checkNetwork() -{ - // Set IP address - return loadSIPLocalIP(); -} - -bool -SIPVoIPLink::loadSIPLocalIP() -{ - bool returnValue = true; - if (_localIPAddress == "127.0.0.1") { - pj_sockaddr ip_addr; - if (pj_gethostip(pj_AF_INET(), &ip_addr) != PJ_SUCCESS) { - // Update the registration state if no network capabilities found - _debug("Get host ip failed!\n"); - setRegistrationState( ErrorNetwork ); - returnValue = false; - } else { - _localIPAddress = std::string(pj_inet_ntoa(ip_addr.ipv4.sin_addr)); - _debug(" SIP Info: Checking network, setting local IP address to: %s\n", _localIPAddress.data()); - } - } - return returnValue; -} - void SIPVoIPLink::getEvent() { @@ -153,7 +122,7 @@ SIPVoIPLink::sendRegister() setRegistrationState(Trying); - return Manager::instance().getUserAgent()->addAccount(id, &_regc, _server, _authname, _password, expire_value); + return Manager::instance().getUserAgent()->addAccount(id, &_regc, getHostname(), getUsername(), getPassword(), expire_value); } std::string @@ -165,12 +134,11 @@ SIPVoIPLink::SIPFromHeader(const std::string& userpart, const std::string& hostp bool SIPVoIPLink::sendSIPAuthentification() { - std::string login = _authname; - if (login.empty()) { + if (getUsername().empty()) { /** @todo Ajouter ici un call à setRegistrationState(Error, "Fill balh") ? */ return false; } - if (_password.empty()) { + if (getPassword().empty()) { /** @todo Même chose ici ? */ return false; } @@ -323,7 +291,7 @@ SIPVoIPLink::transfer(const CallID& id, const std::string& to) std::string tmp_to = SIPToHeader(to); if (tmp_to.find("@") == std::string::npos) { - tmp_to = tmp_to + "@" + getHostName(); + tmp_to = tmp_to + "@" + getHostname(); } _debug("In transfer, tmp_to is %s\n", tmp_to.data()); @@ -373,40 +341,6 @@ SIPVoIPLink::carryingDTMFdigits(const CallID& id, char code UNUSED) snprintf(dtmf_body, body_len - 1, "Signal=%c\r\nDuration=%d\r\n", code, duration); return Manager::instance().getUserAgent()->carryingDTMFdigits(call, dtmf_body); - - - //int duration = Manager::instance().getConfigInt(SIGNALISATION, PULSE_LENGTH); - - // TODO Add DTMF with pjsip - INFO method - - /* - eXosip_lock(); - // Build info request - i = eXosip_call_build_info(call->getDid(), &info); - if (i == 0) { - snprintf(dtmf_body, body_len - 1, "Signal=%c\r\nDuration=%d\r\n", code, duration); - osip_message_set_content_type (info, "application/dtmf-relay"); - osip_message_set_body (info, dtmf_body, strlen (dtmf_body)); - // Send info request - i = eXosip_call_send_request(call->getDid(), info); - } - eXosip_unlock(); - */ - - return true; -} - -bool -SIPVoIPLink::sendMessage(const std::string& to UNUSED, const std::string& body UNUSED) -{ - return true; -} - -// NOW -bool -SIPVoIPLink::isContactPresenceSupported() -{ - return true; } bool @@ -423,36 +357,29 @@ SIPVoIPLink::SIPOutgoingInvite(SIPCall* call) bool SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject UNUSED) { - if (!call) return false; - - std::string to = getSipTo(call->getPeerNumber()); - std::string route = getSipRoute(); - _debug(" To: %s\n", to.data()); - _debug(" Route: %s\n", route.data()); + std::string to; - /*if (!SIPCheckUrl(from)) { - _debug("! SIP Error: Source address is invalid %s\n", from.data()); - return false; - } - if (!SIPCheckUrl(to)) { - return false; - }*/ + if (!call) + return false; - //setCallAudioLocal(call); - AccountID accId = getAccountID(); + to = getSipTo(call->getPeerNumber()); + _debug(" To: %s\n", to.data()); - return Manager::instance().getUserAgent()->makeOutgoingCall(to, call, accId); + return Manager::instance().getUserAgent()->makeOutgoingCall(to, call, getAccountID()); } std::string SIPVoIPLink::getSipFrom() { // Form the From header field basis on configuration panel - std::string host = getHostName(); - if ( host.empty() ) { - host = _localIPAddress; + std::string hostname; + + hostname = getHostname(); + + if ( hostname.empty() ) { + hostname = _localIPAddress; } - return SIPFromHeader(_authname, host); + return SIPFromHeader(getUsername(), hostname); } std::string @@ -462,7 +389,7 @@ SIPVoIPLink::getSipTo(const std::string& to_url) { // add a @host if we are registered and there is no one inside the url if (to_url.find("@") == std::string::npos) {// && isRegistered) { - std::string host = getHostName(); + std::string host = getHostname(); if(!host.empty()) { return SIPToHeader(to_url + "@" + host); } @@ -470,15 +397,6 @@ SIPVoIPLink::getSipTo(const std::string& to_url) { return SIPToHeader(to_url); } -std::string -SIPVoIPLink::getSipRoute() { - std::string proxy = _proxy; - if ( !proxy.empty() ) { - proxy = "<sip:" + proxy + ";lr>"; - } - return proxy; // return empty -} - std::string SIPVoIPLink::SIPToHeader(const std::string& to) { @@ -712,31 +630,6 @@ SIPVoIPLink::handleDtmfRelay(eXosip_event_t* event) { // Private functions /////////////////////////////////////////////////////////////////////////////// -void SIPVoIPLink::setAuthName(const std::string& authname) -{ - _authname = authname; - //_cred.username = pj_str((char *)authname.data()); -} - -void SIPVoIPLink::setPassword(const std::string& password) -{ - _password = password; - /*_cred.data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; - _cred.data = pj_str((char *)password.data()); - _cred.realm = pj_str("*"); - _cred.scheme = pj_str("digest");*/ -} - -void SIPVoIPLink::setSipServer(const std::string& sipServer) -{ - //std::string tmp; - _debug("Set sip server %s\n", sipServer.data()); - _server = sipServer; - //_registrar = pj_str((char *)tmp.data()); - //_user = "<sip:" + _authname + "@" + sipServer + ">"; - //_user = pj_str((char *)tmp.data()); -} - pj_str_t SIPVoIPLink::string2PJStr(const std::string &value) { char tmp[256]; diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h index f29ceb9e589354f109c888a5542dc35e95fa2332..fb863c491ab20b61e5034cff70460240a1835503 100644 --- a/src/sipvoiplink.h +++ b/src/sipvoiplink.h @@ -1,8 +1,8 @@ /* - * Copyright (C) 2004-2008 Savoir-Faire Linux inc. - * Author: Yan Morin <yan.morin@savoirfairelinux.com> - * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> + * Copyright (C) 2004-2009 Savoir-Faire Linux inc. + * * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> + * Author: Yan Morin <yan.morin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,24 +16,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + #ifndef SIPVOIPLINK_H #define SIPVOIPLINK_H #include "voiplink.h" -#include <string> -#include <pjsip.h> -#include <pjlib-util.h> -#include <pjlib.h> -#include <pjnath/stun_config.h> - -//TODO Remove this include if we don't need anything from it -#include <pjsip_simple.h> - -#include <pjsip_ua.h> -#include <pjmedia/sdp.h> -#include <pjmedia/sdp_neg.h> +#include "useragent.h" class EventThread; class SIPCall; @@ -76,12 +66,6 @@ class SIPVoIPLink : public VoIPLink */ void terminate(void); - /** - * Check if a local IP can be found - * @return bool True if network is reachable - */ - bool checkNetwork(void); - /** * Event listener. Each event send by the call manager is received and handled from here */ @@ -170,13 +154,6 @@ class SIPVoIPLink : public VoIPLink */ bool carryingDTMFdigits(const CallID& id, char code); - bool sendMessage(const std::string& to, const std::string& body); - - bool isContactPresenceSupported(); - - // TODO Not used yet - void sendMessageToContact(const CallID& id, const std::string& message); - /** * If set to true, we check for a firewall * @param use true if we use STUN @@ -189,26 +166,6 @@ class SIPVoIPLink : public VoIPLink */ void setStunServer(const std::string& server) { _stunServer = server; } - /** - * Set the SIP proxy - * @param proxy Proxy FQDN/IP - */ - void setProxy(const std::string& proxy) { _proxy = proxy; } - - /** - * Set the authentification name - * @param authname The authentification name - */ - void setAuthName(const std::string& authname); //{ _authname = authname; } - - /** - * Set the password - * @param password Password - */ - void setPassword(const std::string& password); //{ _password = password; } - - void setSipServer(const std::string& sipServer); - bool isRegister() {return _bRegister;} void setRegister(bool result) {_bRegister = result;} @@ -219,15 +176,7 @@ class SIPVoIPLink : public VoIPLink * Terminate every call not hangup | brutal | Protected by mutex */ void terminateSIPCall(); - - /** - * Get the local Ip - * only if the local ip address is to his default value: 127.0.0.1 - * setLocalIpAdress - * @return bool false if not found - */ - bool loadSIPLocalIP(); - + /** * send SIP authentification * @return bool true if sending succeed @@ -279,12 +228,6 @@ class SIPVoIPLink : public VoIPLink */ std::string getSipFrom(); - /** - * Get the sip proxy (add sip: if there is one) - * @return std::string Empty string or <sip:proxy;lr> url - */ - std::string getSipRoute(); - /** * Get the Sip TO url (add sip:, add @host, etc...) * @param to_url The To url @@ -366,22 +309,13 @@ class SIPVoIPLink : public VoIPLink /** Local Extern Port is the port seen by peers for SIP listener */ unsigned int _localExternPort; - /** SIP Proxy URL */ - std::string _proxy; - - /** SIP Authenfication name */ - std::string _authname; - - /** SIP Authenfication password */ - std::string _password; - /** Starting sound */ AudioRtp* _audiortp; pj_str_t string2PJStr(const std::string &value); + private: pjsip_regc *_regc; - std::string _server; bool _bRegister; }; diff --git a/src/useragent.cpp b/src/useragent.cpp index ec4453809f5a9913b0cd3a5db8c7ad3734d8ea0e..cb39635f05d2593c5090cd43e6c501a683aa9db1 100644 --- a/src/useragent.cpp +++ b/src/useragent.cpp @@ -18,8 +18,6 @@ */ #include <string> - - #include <iostream> #include "manager.h" @@ -28,13 +26,12 @@ #include "sipvoiplink.h" #include "sipaccount.h" -#define DEFAULT_SIP_PORT 5060 #define RANDOM_SIP_PORT rand() % 64000 + 1024 #define RANDOM_LOCAL_PORT ((rand() % 27250) + 5250)*2 UserAgent *UserAgent::_current; -UserAgent::UserAgent():_endpt(NULL) ,_sock(NULL), _cp(), _pool(NULL), _mutex(NULL), _mod(), _options_handler(), _useStun(false), _stunHost(), +UserAgent::UserAgent():_endpt(NULL) ,_sock(NULL), _cp(), _pool(NULL), _mutex(NULL), _mod(), _useStun(false), _stunHost(), _stunServer(""), _localExternAddress(""), _localIPAddress("127.0.0.1"), _localExternPort(0), _localPort(0), _regPort(DEFAULT_SIP_PORT), _thread(NULL) { //_useStun = false; //_localIPAddress = "127.0.0.1"; @@ -91,6 +88,9 @@ pj_status_t UserAgent::sipCreate() { pj_status_t UserAgent::sipInit() { pj_status_t status; + int errPjsip = 0; + int port; + validStunServer = true; /* Init SIP UA: */ @@ -103,8 +103,8 @@ pj_status_t UserAgent::sipInit() { _debug("UserAgent: Unable to determine network capabilities\n"); return false; } - int errPjsip = 0; - int port = _regPort; + errPjsip = 0; + port = _regPort; //_debug("stun host is %s\n", _stunHost.ptr); if (_useStun && !Manager::instance().behindNat(_stunServer, port)) { @@ -206,38 +206,6 @@ pj_status_t UserAgent::sipInit() { status = pjsip_xfer_init_module(_endpt); PJ_ASSERT_RETURN( status == PJ_SUCCESS, 1 ); - /*{ - const pjsip_module handler ={ - NULL, NULL, // prev, next. - { (char*)"mod-sflphone-options", 20},//9}, // Name. - -1, // Id - PJSIP_MOD_PRIORITY_APPLICATION, // Priority - NULL, // load() - NULL, // start() - NULL, // stop() - NULL, // unload() - &options_on_rx_request, // on_rx_request() - NULL, // on_tx_request. - NULL, // on_tx_response() - NULL, // on_tsx_state() - }; - - _options_handler = handler; - } - - // Register the OPTIONS module - status = pjsip_endpt_register_module(_endpt, &_options_handler); - PJ_ASSERT_RETURN( status == PJ_SUCCESS, 1 ); - - // Add OPTIONS in Allow header - status = pjsip_endpt_add_capability(_endpt, - NULL, - PJSIP_H_ALLOW, - NULL, 1, - &STR_OPTIONS); - PJ_ASSERT_RETURN( status == PJ_SUCCESS, 1 );*/ - - // Initialize invite session module // These callbacks will be called on incoming requests, media session state, etc. { @@ -274,7 +242,7 @@ pj_status_t UserAgent::sipInit() { pjsip_endpt_add_capability(_endpt, &_mod, PJSIP_H_ACCEPT, NULL, 1, &accepted); } - _debug("UserAgent: sflphone version %s for %s initialized\n", pj_get_version(), PJ_OS_NAME); + _debug("UserAgent: pjsip version %s for %s initialized\n", pj_get_version(), PJ_OS_NAME); Manager::instance().setSipThreadStatus(false); @@ -359,8 +327,8 @@ void UserAgent::busy_sleep(unsigned msec) #endif } -bool UserAgent::addAccount(AccountID id, pjsip_regc **regc2, const std::string& server, const std::string& user, const std::string& passwd, - const int& timeout UNUSED) { +bool UserAgent::addAccount(AccountID id, pjsip_regc **regc2, const std::string& server, const std::string& user, const std::string& passwd, const int& timeout UNUSED) { + pj_status_t status; AccountID *currentId = new AccountID(id); char contactTmp[256]; @@ -368,6 +336,7 @@ bool UserAgent::addAccount(AccountID id, pjsip_regc **regc2, const std::string& pj_str_t svr; pj_str_t aor; pj_str_t contact; + pjsip_tx_data *tdata; //pj_mutex_lock(_mutex); std::string tmp; @@ -401,7 +370,6 @@ bool UserAgent::addAccount(AccountID id, pjsip_regc **regc2, const std::string& pj_strdup2(_pool, &contact, contactTmp); //_debug("UserAgent: Get in %s %d %s\n", svr.ptr, svr.slen, aor.ptr); - _debug("UserAgent: Contact is %s\n", contact.ptr); status = pjsip_regc_init(regc, &svr, &aor, &aor, 1, &contact, 600); //timeout); if (status != PJ_SUCCESS) { _debug("UserAgent: Unable to initialize regc. %d\n", status); //, regc->str_srv_url.ptr); @@ -426,7 +394,6 @@ bool UserAgent::addAccount(AccountID id, pjsip_regc **regc2, const std::string& account->setCredInfo(cred); - pjsip_tx_data *tdata; status = pjsip_regc_register(regc, PJ_TRUE, &tdata); if (status != PJ_SUCCESS) { _debug("UserAgent: Unable to register regc.\n"); diff --git a/src/voiplink.cpp b/src/voiplink.cpp index 8ef4661fc33b2ea820b504fe48bb23f523349f1f..fe62b20467a1047fa2a1965618de1bff4abeea79 100644 --- a/src/voiplink.cpp +++ b/src/voiplink.cpp @@ -1,8 +1,9 @@ /* - * Copyright (C) 2005-2007 Savoir-Faire Linux inc. + * Copyright (C) 2005-2009 Savoir-Faire Linux inc. + * + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> - * Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,46 +20,41 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <string> - #include "user_cfg.h" #include "voiplink.h" #include "manager.h" VoIPLink::VoIPLink(const AccountID& accountID) : _accountID(accountID), _localIPAddress("127.0.0.1"), _localPort(0), _initDone(false) { - _registrationError = NO_ERROR; + setRegistrationState(VoIPLink::Unregistered); } VoIPLink::~VoIPLink (void) { - clearCallMap(); + clearCallMap(); } -bool -VoIPLink::addCall(Call* call) +bool VoIPLink::addCall(Call* call) { - if (call) { - if (getCall(call->getCallId()) == 0) { - ost::MutexLock m(_callMapMutex); - _callMap[call->getCallId()] = call; - } - } - return false; + if (call) { + if (getCall(call->getCallId()) == 0) { + ost::MutexLock m(_callMapMutex); + _callMap[call->getCallId()] = call; + } + } + return false; } -bool -VoIPLink::removeCall(const CallID& id) +bool VoIPLink::removeCall(const CallID& id) { - ost::MutexLock m(_callMapMutex); - if (_callMap.erase(id)) { - return true; - } - return false; + ost::MutexLock m(_callMapMutex); + if (_callMap.erase(id)) { + return true; + } + return false; } -Call* -VoIPLink::getCall(const CallID& id) +Call* VoIPLink::getCall(const CallID& id) { ost::MutexLock m(_callMapMutex); CallMap::iterator iter = _callMap.find(id); @@ -82,68 +78,9 @@ VoIPLink::clearCallMap() return true; } -void -VoIPLink::setRegistrationState(const enum RegistrationState state, const int& errorCode) -{ - _registrationState = state; - _registrationError = errorCode; - - std::string acc_ID = getAccountID(); - - /** Push to the GUI when state changes */ - switch (state) { - case Registered: - Manager::instance().registrationSucceed(acc_ID); - break; - case Trying: - Manager::instance().registrationTrying( acc_ID); - break; - case Error: - Manager::instance().registrationFailed(acc_ID); - // Notify the error to the client - if( _registrationError != NO_ERROR ) - Manager::instance().notifyErrClient( errorCode ); - break; - case ErrorAuth: - Manager::instance().registrationFailed(acc_ID); - break; - case ErrorNetwork: - Manager::instance().registrationFailed(acc_ID); - break; - case Unregistered: - Manager::instance().unregistrationSucceed(acc_ID); - break; - case ErrorHost: - Manager::instance().registrationFailed(acc_ID); - break; - case ErrorExistStun: - Manager::instance().registrationFailed(acc_ID); - break; - case ErrorConfStun: - Manager::instance().registrationFailed(acc_ID); - break; - } -} - -void -VoIPLink::setRegistrationState(const enum RegistrationState state) -{ - setRegistrationState(state, NO_ERROR); -} - -// NOW -/*void -VoIPLink::subscribePresenceForContact(Contact* contact) -{ - // Nothing to do if presence is not supported - // or the function will be overidden - _debug("Presence subscription not supported for account\n"); -}*/ - -void -VoIPLink::publishPresenceStatus(std::string status UNUSED) +void VoIPLink::setRegistrationState(const RegistrationState state) { - // Nothing to do if presence is not supported - // or the function will be overidden - _debug("Presence publication not supported for account\n"); + _registrationState = state; + // Notify the client + Manager::instance().connectionStatusNotification( ); } diff --git a/src/voiplink.h b/src/voiplink.h index d9cb6bcabb35f573e2eef01fc83fe6d53fd8dd29..e095c1922ccc24af99754eddd5ed79b1d2ebc83a 100644 --- a/src/voiplink.h +++ b/src/voiplink.h @@ -1,8 +1,9 @@ /* - * Copyright (C) 2005-2007 Savoir-Faire Linux inc. + * Copyright (C) 2005-2009 Savoir-Faire Linux inc. + * + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> - * Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,15 +23,10 @@ #ifndef __VOIP_LINK_H__ #define __VOIP_LINK_H__ -#include <string> #include "call.h" -#include <map> -#include <cc++/thread.h> // for mutex class AudioCodec; -struct pjsip_rx_data; - /** Define AccountID type */ typedef std::string AccountID; @@ -57,6 +53,7 @@ class VoIPLink { /** Contains all the state an Voip can be in */ enum RegistrationState {Unregistered, Trying, Registered, Error, ErrorAuth , ErrorNetwork , ErrorHost, ErrorExistStun, ErrorConfStun}; + typedef enum RegistrationState RegistrationState; /** * Virtual method @@ -71,13 +68,6 @@ class VoIPLink { */ virtual bool init (void) = 0; - /** - * Virtual method - * Check if a local IP can be found - * @return bool True if network is reachable - */ - virtual bool checkNetwork (void) = 0; - /** * Virtual method * Delete link-related stuuf like calls @@ -165,50 +155,18 @@ class VoIPLink { */ virtual bool carryingDTMFdigits(const CallID& id, char code) = 0; - /** - * Send text message - */ - virtual bool sendMessage(const std::string& to, const std::string& body) = 0; - - // NOW - /** - * Determine if link supports presence information - */ - virtual bool isContactPresenceSupported() = 0; - - /** - * Register contacts for presence information if supported - */ - //virtual void subscribePresenceForContact(Contact* contact); - - /** - * Publish presence status to server - */ - virtual void publishPresenceStatus(std::string status); - - /** - * Set the account full name - * @param fullname The full name - */ + /* Accessors */ + std::string& getFullName (void) { return _fullname; } void setFullName (const std::string& fullname) { _fullname = fullname; } - /** - * Get the account full name - * @return std::string The full name - */ - std::string& getFullName (void) { return _fullname; } + std::string& getHostname (void) { return _hostname; } + void setHostname (const std::string& hostname) { _hostname = hostname; } - /** - * Set the account host name - * @param hostname The host name - */ - void setHostName (const std::string& hostname) { _hostname = hostname; } - - /** - * Get the account host name - * @return std::string The host name - */ - std::string& getHostName (void) { return _hostname; } + std::string& getUsername (void) { return _username; } + void setUsername (const std::string& username) { _username = username; } + + std::string& getPassword (void) { return _password; } + void setPassword (const std::string& password) { _password = password; } /** * @return AccountID parent Account's ID @@ -227,42 +185,22 @@ class VoIPLink { Call* getCall(const CallID& id); /** - * Get registration state - * @return RegistrationState - */ - enum RegistrationState getRegistrationState() { return _registrationState; } - - /** - * Get registration error message, if set. - */ - int getRegistrationError() { return _registrationError; } - - /** - * Set new registration state - * We use this function, in case the server needs to PUSH to the - * GUI when the state changes. - * @param state The registration state - * @param errorCode The error code + * Get connection status + * @return Connection status */ - void setRegistrationState(const enum RegistrationState state, - const int& errorCode); + RegistrationState getRegistrationState() { return _registrationState; } /** * Set new registration state * @param state The registration state */ - void setRegistrationState(const enum RegistrationState state); + void setRegistrationState(const RegistrationState state); private: - /** - * Full name used as outgoing Caller ID - */ - std::string _fullname; - - /** - * Host name used for authentication - */ std::string _hostname; + std::string _username; + std::string _password; + std::string _fullname; /** * ID of parent's Account @@ -272,14 +210,8 @@ class VoIPLink { /** * State of registration */ - enum RegistrationState _registrationState; - - /** - * Registration error code -> refers to global.h - */ - int _registrationError; + RegistrationState _registrationState; - //protected: public: /** Add a call to the call map (protected by mutex) * @param call A call pointer with a unique pointer