diff --git a/sflphone-client-gnome/src/accountlist.c b/sflphone-client-gnome/src/accountlist.c index 8a4187df746b60a0cc3f7f0223b20a1cf48d5e35..bd8621c6949230ee0534ba3f6a8f2ef9e1ef530b 100644 --- a/sflphone-client-gnome/src/accountlist.c +++ b/sflphone-client-gnome/src/accountlist.c @@ -298,9 +298,13 @@ gchar * account_list_get_ordered_list (void) { gchar *order=""; guint i; - for( i=0; i<account_list_get_size(); i++ ) + for( i=0; i < account_list_get_size(); i++ ) { - order = g_strconcat (order, account_list_get_nth (i)->accountID, "/", NULL); + account_t * account = NULL; + account = account_list_get_nth(i); + if (account != NULL) { + order = g_strconcat (order, account->accountID, "/", NULL); + } } return order; } diff --git a/sflphone-client-gnome/src/config/accountwindow.c b/sflphone-client-gnome/src/config/accountwindow.c index 30a2c27761dd29d94535458f4c15eb2bf699d261..455b43aa117b978e1416a1246064d9741322cb40 100644 --- a/sflphone-client-gnome/src/config/accountwindow.c +++ b/sflphone-client-gnome/src/config/accountwindow.c @@ -57,7 +57,7 @@ GtkWidget * entryHostname; GtkWidget * entryPassword; GtkWidget * entryMailbox; GtkWidget * entryResolveNameOnlyOnce; -GtkWidget * entryExpire; +GtkWidget * expireSpinBox; GtkListStore * credentialStore; GtkWidget * deleteCredButton; GtkWidget * treeViewCredential; @@ -68,9 +68,15 @@ GtkWidget * useSipTlsCheckBox; GtkWidget * publishedAddressEntry; GtkWidget * localAddressCombo; -GtkWidget * sameAsLocalCheckBox; +GtkWidget * useStunRadioButton; +GtkWidget * sameAsLocalRadioButton; +GtkWidget * publishedAddrRadioButton; GtkWidget * publishedPortSpinBox; GtkWidget * localPortSpinBox; +GtkWidget * publishedAddressLabel; +GtkWidget * publishedPortLabel; +GtkWidget * stunServerLabel; +GtkWidget * stunServerEntry; GtkWidget * displayNameEntry; @@ -604,6 +610,19 @@ GtkWidget * create_security_tab(account_t **a) return ret; } +static use_stun_cb(GtkWidget * widget, gpointer data UNUSED) +{ + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { + DEBUG("Showing stun options"); + gtk_widget_show(stunServerLabel); + gtk_widget_show(stunServerEntry); + } else { + gtk_widget_hide(stunServerLabel); + gtk_widget_hide(stunServerEntry); + } + +} + static same_as_local_cb(GtkWidget * widget, gpointer data UNUSED) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { @@ -613,12 +632,22 @@ static same_as_local_cb(GtkWidget * widget, gpointer data UNUSED) gchar * local_port = (gchar *) gtk_entry_get_text(GTK_ENTRY(localPortSpinBox)); gtk_spin_button_set_value(GTK_SPIN_BUTTON(publishedPortSpinBox), g_ascii_strtod(local_port, NULL)); - - gtk_widget_set_sensitive(publishedPortSpinBox, FALSE); - gtk_widget_set_sensitive(publishedAddressEntry, FALSE); + } +} + +static set_published_addr_manually_cb(GtkWidget * widget, gpointer data UNUSED) +{ + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { + DEBUG("Showing manual options"); + gtk_widget_show(publishedPortLabel); + gtk_widget_show(publishedPortSpinBox); + gtk_widget_show(publishedAddressLabel); + gtk_widget_show(publishedAddressEntry); } else { - gtk_widget_set_sensitive(publishedPortSpinBox, TRUE); - gtk_widget_set_sensitive(publishedAddressEntry, TRUE); + gtk_widget_hide(publishedPortLabel); + gtk_widget_hide(publishedPortSpinBox); + gtk_widget_hide(publishedAddressLabel); + gtk_widget_hide(publishedAddressEntry); } } @@ -638,32 +667,40 @@ GtkWidget * create_advanced_tab(account_t **a) gchar * resolve_once = NULL; gchar * account_expire = NULL; + gchar * use_tls; gchar * published_address; gchar * published_port; gchar * local_address; gchar * local_port; + gchar * stun_enable; + gchar * stun_server; // Load from SIP/IAX/Unknown ? if(currentAccount) { resolve_once = g_hash_table_lookup(currentAccount->properties, ACCOUNT_RESOLVE_ONCE); account_expire = g_hash_table_lookup(currentAccount->properties, ACCOUNT_REGISTRATION_EXPIRE); + use_tls = g_hash_table_lookup(currentAccount->properties, TLS_ENABLE); local_port = g_hash_table_lookup(currentAccount->properties, LOCAL_PORT); local_address = g_hash_table_lookup(currentAccount->properties, LOCAL_ADDRESS); published_address = g_hash_table_lookup(currentAccount->properties, PUBLISHED_ADDRESS); - published_port = g_hash_table_lookup(currentAccount->properties, PUBLISHED_PORT); + published_port = g_hash_table_lookup(currentAccount->properties, PUBLISHED_PORT); + published_port = g_hash_table_lookup(currentAccount->properties, PUBLISHED_PORT); + stun_enable = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_STUN_ENABLED); + stun_server = g_hash_table_lookup(currentAccount->properties, ACCOUNT_SIP_STUN_SERVER); } gnome_main_section_new_with_table (_("Registration"), &frame, &table, 2, 3); gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(table), 10); - - label = gtk_label_new_with_mnemonic (_("Registration _expire")); - gtk_table_attach_defaults( GTK_TABLE( table ), label, 0, 1, 0, 1); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - entryExpire = gtk_entry_new(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entryExpire); - gtk_entry_set_text(GTK_ENTRY(entryExpire), account_expire); - gtk_table_attach_defaults( GTK_TABLE( table ), entryExpire, 1, 2, 0, 1); + gtk_table_set_row_spacings( GTK_TABLE(table), 5); + + label = gtk_label_new_with_mnemonic (_("Local port")); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + expireSpinBox = gtk_spin_button_new_with_range(1, 65535, 1); + gtk_label_set_mnemonic_widget(GTK_LABEL(label), expireSpinBox); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(expireSpinBox), g_ascii_strtod(account_expire, NULL)); + gtk_table_attach_defaults(GTK_TABLE(table), expireSpinBox, 1, 2, 0, 1); entryResolveNameOnlyOnce = gtk_check_button_new_with_mnemonic(_("_Comply with RFC 3263")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(entryResolveNameOnlyOnce), @@ -674,7 +711,8 @@ GtkWidget * create_advanced_tab(account_t **a) gnome_main_section_new_with_table (_("Network"), &frame, &table, 2, 3); gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(table), 10); - + gtk_table_set_row_spacings( GTK_TABLE(table), 5); + /** * Retreive the list of IP interface from the * the daemon and build the combo box. @@ -729,29 +767,62 @@ GtkWidget * create_advanced_tab(account_t **a) gtk_spin_button_set_value(GTK_SPIN_BUTTON(localPortSpinBox), g_ascii_strtod(local_port, NULL)); gtk_table_attach_defaults(GTK_TABLE(table), localPortSpinBox, 1, 2, 1, 2); - sameAsLocalCheckBox = gtk_check_button_new_with_mnemonic(_("Published address and port same as local")); - g_signal_connect(sameAsLocalCheckBox, "toggled", G_CALLBACK(same_as_local_cb), sameAsLocalCheckBox); - gtk_table_attach_defaults(GTK_TABLE(table), sameAsLocalCheckBox, 0, 2, 2, 3); - gtk_widget_set_sensitive(GTK_WIDGET(sameAsLocalCheckBox), TRUE ); - - label = gtk_label_new_with_mnemonic (_("Published address")); - gtk_table_attach_defaults( GTK_TABLE( table ), label, 0, 1, 3, 4); + label = gtk_label_new_with_mnemonic (_("Set published address and port:")); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 2, 3); gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + + useStunRadioButton = gtk_radio_button_new_with_mnemonic(NULL,_("Using STUN ")); + gtk_table_attach_defaults(GTK_TABLE(table), useStunRadioButton, 0, 2, 3, 4); + gtk_widget_set_sensitive(GTK_TOGGLE_BUTTON(useStunRadioButton), + g_strcasecmp(use_tls,"false") == 0 ? TRUE: FALSE); + + sameAsLocalRadioButton = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(useStunRadioButton), _("Same as local parameters")); + gtk_table_attach_defaults(GTK_TABLE(table), sameAsLocalRadioButton, 0, 2, 4, 5); + + publishedAddrRadioButton = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(useStunRadioButton), _("Manually")); + gtk_table_attach_defaults(GTK_TABLE(table), publishedAddrRadioButton, 0, 2, 5, 6); + + gtk_widget_show_all(ret); + + publishedAddressLabel = gtk_label_new_with_mnemonic (_("Published address")); + gtk_table_attach_defaults( GTK_TABLE(table), publishedAddressLabel, 0, 1, 6, 7); + gtk_misc_set_alignment(GTK_MISC (publishedAddressLabel), 0, 0.5); publishedAddressEntry = gtk_entry_new(); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), publishedAddressEntry); + gtk_label_set_mnemonic_widget (GTK_LABEL (publishedAddressLabel), publishedAddressEntry); gtk_entry_set_text(GTK_ENTRY(publishedAddressEntry), published_address); - gtk_table_attach_defaults( GTK_TABLE(table), publishedAddressEntry, 1, 2, 3, 4); + gtk_table_attach_defaults( GTK_TABLE(table), publishedAddressEntry, 1, 2, 6, 7); - label = gtk_label_new_with_mnemonic (_("Published port")); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + publishedPortLabel = gtk_label_new_with_mnemonic(_("Published port")); + gtk_table_attach_defaults(GTK_TABLE(table), publishedPortLabel, 0, 1, 7, 8); + gtk_misc_set_alignment(GTK_MISC(publishedPortLabel), 0, 0.5); publishedPortSpinBox = gtk_spin_button_new_with_range(1, 65535, 1); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), publishedPortSpinBox); + gtk_label_set_mnemonic_widget(GTK_LABEL (publishedPortLabel), publishedPortSpinBox); gtk_spin_button_set_value(GTK_SPIN_BUTTON(publishedPortSpinBox), g_ascii_strtod(published_port, NULL)); - gtk_table_attach_defaults(GTK_TABLE(table), publishedPortSpinBox, 1, 2, 4, 5); - - gtk_widget_show_all(ret); - + gtk_table_attach_defaults(GTK_TABLE(table), publishedPortSpinBox, 1, 2, 7, 8); + + stunServerLabel = gtk_label_new_with_mnemonic (_("STUN server URL")); + gtk_table_attach_defaults(GTK_TABLE(table), stunServerLabel, 0, 1, 8, 9); + gtk_misc_set_alignment(GTK_MISC(stunServerLabel), 0, 0.5); + stunServerEntry = gtk_entry_new(); + gtk_label_set_mnemonic_widget(GTK_LABEL(stunServerLabel), stunServerEntry); + gtk_entry_set_text(GTK_ENTRY(stunServerEntry), stun_server); + gtk_table_attach_defaults(GTK_TABLE(table), stunServerEntry, 1, 2, 8, 9); + + // This will trigger a signal, and the above two + // widgets need to be instanciated before that. + g_signal_connect(useStunRadioButton, "toggled", G_CALLBACK(use_stun_cb), useStunRadioButton); + g_signal_connect(sameAsLocalRadioButton, "toggled", G_CALLBACK(same_as_local_cb), sameAsLocalRadioButton); + g_signal_connect(publishedAddrRadioButton, "toggled", G_CALLBACK(set_published_addr_manually_cb), publishedAddrRadioButton); + + if (g_strcasecmp(stun_enable,"true") == 0) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useStunRadioButton), TRUE); + } else if ((g_strcasecmp(published_address, local_address) == 0) + && (g_strcasecmp(published_port, local_port) == 0)) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton), TRUE); + } else { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(publishedAddrRadioButton), TRUE); + } + return ret; } @@ -890,7 +961,7 @@ show_account_window (account_t * a) g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryMailbox)))); g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_REGISTRATION_EXPIRE), - g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryExpire)))); + g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(expireSpinBox)))); if (strcmp(proto, "SIP") == 0) { guint i, size; @@ -976,7 +1047,7 @@ show_account_window (account_t * a) } /** @todo Verify if it's the best condition to check */ - if (currentAccount->accountID == NULL) { + if (g_strcasecmp(currentAccount->accountID, "new") == 0) { dbus_add_account(currentAccount); } else { diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index 240419f640405b84e80c2b64bddc93c333922297..0e978649a4e7c4900b84e9dbc3e149f60365b60f 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -1236,15 +1236,11 @@ ManagerImpl::getStunInfo (StunAddress4& stunSvrAddr, int port) struct in_addr in; char* addr; - //int fd3, fd4; - // bool ok = stunOpenSocketPair(stunSvrAddr, &mappedAddr, &fd3, &fd4, port); int fd1 = stunOpenSocket (stunSvrAddr, &mappedAddr, port); bool ok = (fd1 == -1 || fd1 == INVALID_SOCKET) ? false : true; if (ok) { closesocket (fd1); - //closesocket(fd3); - //closesocket(fd4); _firewallPort = mappedAddr.port; // Convert ipv4 address to host byte ordering in.s_addr = ntohl (mappedAddr.addr); @@ -1374,9 +1370,7 @@ ManagerImpl::initConfigFile (bool load_user_value, std::string alternate) _config.addDefaultValue(std::pair<std::string, std::string> (PLAY_DTMF, TRUE_STR), SIGNALISATION); _config.addDefaultValue(std::pair<std::string, std::string> (PLAY_TONES, TRUE_STR), SIGNALISATION); _config.addDefaultValue(std::pair<std::string, std::string> (PULSE_LENGTH, DFT_PULSE_LENGTH_STR), SIGNALISATION); - _config.addDefaultValue(std::pair<std::string, std::string> (SEND_DTMF_AS, SIP_INFO_STR), SIGNALISATION); - _config.addDefaultValue(std::pair<std::string, std::string> (STUN_ENABLE, DFT_STUN_ENABLE), SIGNALISATION); - _config.addDefaultValue(std::pair<std::string, std::string> (STUN_SERVER, DFT_STUN_SERVER), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string> (SEND_DTMF_AS, SIP_INFO_STR), SIGNALISATION); _config.addDefaultValue(std::pair<std::string, std::string> (ZRTP_ZIDFILE, ZRTP_ZID_FILENAME), SIGNALISATION); // Audio settings @@ -1445,7 +1439,9 @@ ManagerImpl::initConfigFile (bool load_user_value, std::string alternate) _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_ACCOUNT_ENABLE, TRUE_STR)); _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_CREDENTIAL_NUMBER, "0")); _config.addDefaultValue(std::pair<std::string, std::string> (CONFIG_ACCOUNT_TYPE, DEFAULT_ACCOUNT_TYPE)); - + _config.addDefaultValue(std::pair<std::string, std::string> (STUN_ENABLE, DFT_STUN_ENABLE)); + _config.addDefaultValue(std::pair<std::string, std::string> (STUN_SERVER, DFT_STUN_SERVER)); + _setupLoaded = (_exist == 2) ? false : true; } @@ -2560,7 +2556,9 @@ std::map< std::string, std::string > ManagerImpl::getAccountDetails (const Accou a.insert(std::pair<std::string, std::string> (PUBLISHED_ADDRESS, getConfigString(accountID, PUBLISHED_ADDRESS))); a.insert(std::pair<std::string, std::string> (LOCAL_PORT, getConfigString(accountID, LOCAL_PORT))); a.insert(std::pair<std::string, std::string> (PUBLISHED_PORT, getConfigString(accountID, PUBLISHED_PORT))); - a.insert(std::pair<std::string, std::string> (DISPLAY_NAME, getConfigString(accountID, DISPLAY_NAME))); + a.insert(std::pair<std::string, std::string> (DISPLAY_NAME, getConfigString(accountID, DISPLAY_NAME))); + a.insert(std::pair<std::string, std::string> (STUN_ENABLE, getConfigString(accountID, STUN_ENABLE))); + a.insert(std::pair<std::string, std::string> (STUN_SERVER, getConfigString(accountID, STUN_SERVER))); RegistrationState state; if (account != NULL) { @@ -2704,7 +2702,6 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, const std::ma { std::string accountType; - Account *acc; std::map <std::string, std::string> map_cpy; std::map<std::string, std::string>::iterator iter; @@ -2753,7 +2750,9 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, const std::ma std::string localAddress; std::string publishedAddress; std::string localPort; - std::string publishedPort; + std::string publishedPort; + std::string stunEnable; + std::string stunServer; std::string srtpEnable; std::string zrtpDisplaySas; std::string zrtpDisplaySasOnce; @@ -2780,7 +2779,9 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, const std::ma if((iter = map_cpy.find(LOCAL_ADDRESS)) != map_cpy.end()) { localAddress = iter->second; } if((iter = map_cpy.find(PUBLISHED_ADDRESS)) != map_cpy.end()) { publishedAddress = iter->second; } if((iter = map_cpy.find(LOCAL_PORT)) != map_cpy.end()) { localPort = iter->second; } - if((iter = map_cpy.find(PUBLISHED_PORT)) != map_cpy.end()) { publishedPort = iter->second; } + if((iter = map_cpy.find(PUBLISHED_PORT)) != map_cpy.end()) { publishedPort = iter->second; } + if((iter = map_cpy.find(STUN_ENABLE)) != map_cpy.end()) { stunEnable = iter->second; } + if((iter = map_cpy.find(STUN_SERVER)) != map_cpy.end()) { stunServer = iter->second; } if((iter = map_cpy.find(SRTP_ENABLE)) != map_cpy.end()) { srtpEnable = iter->second; } if((iter = map_cpy.find(ZRTP_DISPLAY_SAS)) != map_cpy.end()) { zrtpDisplaySas = iter->second; } if((iter = map_cpy.find(ZRTP_DISPLAY_SAS_ONCE)) != map_cpy.end()) { zrtpDisplaySasOnce = iter->second; } @@ -2846,16 +2847,21 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, const std::ma saveConfig(); + Account * acc = NULL; acc = getAccount (accountID); - acc->loadConfig(); - - if (acc->isEnabled()) { - acc->unregisterVoIPLink(); - acc->registerVoIPLink(); + if (acc != NULL) { + acc->loadConfig(); + + if (acc->isEnabled()) { + acc->unregisterVoIPLink(); + acc->registerVoIPLink(); + } else { + acc->unregisterVoIPLink(); + } } else { - acc->unregisterVoIPLink(); + _debug("ManagerImpl::setAccountDetails: account is NULL\n"); } - + // Update account details to the client side if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); diff --git a/sflphone-common/src/sip/sipaccount.h b/sflphone-common/src/sip/sipaccount.h index 6375f986b84d72a86db089c1070d089b04d73dea..62b2725798400815fd405e4f94ea9658fa933368 100644 --- a/sflphone-common/src/sip/sipaccount.h +++ b/sflphone-common/src/sip/sipaccount.h @@ -220,6 +220,12 @@ class SIPAccount : public Account */ inline void setPublishedAddress(const std::string& publishedIpAddress) { _publishedIpAddress = publishedIpAddress; } + /** + * Get the chosen transport type. + * @return pjsip_transport_type_e Transport type chosen by the user for this account. + */ + inline pjsip_transport_type_e getTransportType(void) { return _transportType; } + private: /* Maps a string description of the SSL method diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 755585d251f2820372d87ee9fa212f5bb775a805..b6fe24488354dad0154bc90bb35b2a93305324de 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -2329,8 +2329,8 @@ void call_on_state_changed (pjsip_inv_session *inv, pjsip_event *e) if (link) link->SIPCallAnswered (call, rdata); } else if (inv->state == PJSIP_INV_STATE_DISCONNECTED) { - _debug ("Invitation falled in state \"disconnected\".\n"); - _debug ("State: %i, Disconnection cause: %i\n", inv->state, inv->cause); + + _debug ("State: %s. Cause: %.*s\n", invitationStateMap[inv->state], (int)inv->cause_text.slen, inv->cause_text.ptr); switch (inv->cause) { /* The call terminates normally - BYE / CANCEL */ @@ -2343,11 +2343,8 @@ void call_on_state_changed (pjsip_inv_session *inv, pjsip_event *e) if (link) { link->SIPCallClosed (call); } - break; - - /* The call connection failed */ - + case PJSIP_SC_NOT_FOUND: /* peer not found */ case PJSIP_SC_DECLINE: case PJSIP_SC_REQUEST_TIMEOUT: /* request timeout */ diff --git a/sflphone-common/src/sip/sipvoiplink.h b/sflphone-common/src/sip/sipvoiplink.h index 723d3240d7bd8d5ca53e96b710db8d23d41162ca..65e91ec3a37b7dfd4618b7ed16196b84544e2a07 100644 --- a/sflphone-common/src/sip/sipvoiplink.h +++ b/sflphone-common/src/sip/sipvoiplink.h @@ -48,7 +48,7 @@ namespace sfl { #define RANDOM_SIP_PORT rand() % 64000 + 1024 // To set the verbosity. From 0 (min) to 6 (max) -#define PJ_LOG_LEVEL 6 +#define PJ_LOG_LEVEL 0 /** * @file sipvoiplink.h