diff --git a/daemon/src/dbus/networkmanager.cpp b/daemon/src/dbus/networkmanager.cpp index 3bbc15d0043b449f4b2f62c3206beb481b8ac40c..7333066a751f69464c8ce42d8f947560b37665f1 100644 --- a/daemon/src/dbus/networkmanager.cpp +++ b/daemon/src/dbus/networkmanager.cpp @@ -51,7 +51,10 @@ void NetworkManager::StateChanged(const uint32_t &state) void NetworkManager::PropertiesChanged(const std::map<std::string, ::DBus::Variant> &argin0) { - WARN("Properties changed: %s", argin0.begin()->first.c_str()); + WARN("Properties changed: "); + for (std::map<std::string, ::DBus::Variant>::const_iterator iter = argin0.begin(); + iter != argin0.end(); ++iter) + WARN("%s", iter->first.c_str()); Manager::instance().registerAccounts(); } diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 01f7d85be139c143aa66be37a85eac2f24a52195..783dec8268d583de16d90e65f152e98c61b1ec74 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -226,7 +226,6 @@ bool ManagerImpl::outgoingCall(const std::string& account_id, try { Call *call = getAccountLink(account_id)->newOutgoingCall(call_id, to_cleaned); - switchCall(call_id); call->setConfId(conf_id); } catch (const VoipLinkException &e) { diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 3560443fdfb03426c5d22edbb395871381d15583..c676d8ae0eaea421bfd746f344c7cd6bddc1251c 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -98,6 +98,7 @@ SIPAccount::SIPAccount(const std::string& accountID) , registrationStateDetailed_() , keepAliveTimer_() , link_(SIPVoIPLink::instance()) + , receivedParameter_() {} void SIPAccount::serialize(Conf::YamlEmitter &emitter) @@ -419,7 +420,7 @@ void SIPAccount::setAccountDetails(std::map<std::string, std::string> details) publishedIpAddress_ = details[CONFIG_PUBLISHED_ADDRESS]; localPort_ = atoi(details[CONFIG_LOCAL_PORT].c_str()); publishedPort_ = atoi(details[CONFIG_PUBLISHED_PORT].c_str()); - if(stunServer_ != details[CONFIG_STUN_SERVER]) { + if (stunServer_ != details[CONFIG_STUN_SERVER]) { DEBUG("Stun server changed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); link_->sipTransport.destroyStunResolver(stunServer_); // pj_stun_sock_destroy(pj_stun_sock *stun_sock); diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index c116031b84d3ff03be06d3cf9d544dcb3b2b06f8..8fd101d9da304e67960c48cd52b5a6ca96d5debe 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -469,7 +469,7 @@ class SIPAccount : public Account { * @param The public IPV4 address in the standard dot notation. * @return void */ - void setPublishedAddress(const std::string& publishedIpAddress) { + void setPublishedAddress(const std::string &publishedIpAddress) { publishedIpAddress_ = publishedIpAddress; } @@ -497,6 +497,14 @@ class SIPAccount : public Account { return zrtpHelloHash_; } + void setReceivedParameter(const std::string &received) { + receivedParameter_ = received; + } + + std::string getReceivedParameter() const { + return receivedParameter_; + } + /** * Timer used to periodically send re-register request based * on the "Expire" sip header (or the "expire" Contact parameter) @@ -720,6 +728,11 @@ class SIPAccount : public Account { * Voice over IP Link contains a listener thread and calls */ SIPVoIPLink* link_; + + /** + * Received via parameters + */ + std::string receivedParameter_; }; #endif diff --git a/daemon/src/sip/siptransport.cpp b/daemon/src/sip/siptransport.cpp index ece189460152aec6e91facca6c2fd6891f3ddb88..74385255c29f96082824a8bdea5673c829012ef0 100644 --- a/daemon/src/sip/siptransport.cpp +++ b/daemon/src/sip/siptransport.cpp @@ -342,10 +342,14 @@ void SipTransport::createSipTransport(SIPAccount &account) } if (!account.transport_) { - DEBUG("SipTransport: Looking into previously created transport map for %s:%d", - account.getLocalInterface().c_str(), account.getLocalPort()); + std::ostringstream key; + key << account.getLocalInterface(); + key << ":"; + key << account.getLocalPort(); + DEBUG("SipTransport: Looking into previously created transport map for" + " %s", key.str().c_str()); // Could not create new transport, this transport may already exists - pjsip_transport *cachedTransport = transportMap_[account.getLocalPort()]; + pjsip_transport *cachedTransport = transportMap_[key.str()]; if (cachedTransport) { account.transport_ = cachedTransport; @@ -418,7 +422,8 @@ SipTransport::createUdpTransport(const std::string &interface, unsigned int port std::ostringstream fullAddress; fullAddress << listeningAddress << ":" << listeningPort; pj_str_t udpString; - pj_cstr(&udpString, fullAddress.str().c_str()); + std::string fullAddressStr(fullAddress.str()); + pj_cstr(&udpString, fullAddressStr.c_str()); pj_sockaddr boundAddr; pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &udpString, &boundAddr); pj_status_t status; @@ -435,10 +440,10 @@ SipTransport::createUdpTransport(const std::string &interface, unsigned int port } } - DEBUG("SipTransport: Listening address %s, listening port %d", listeningAddress.c_str(), listeningPort); + DEBUG("SipTransport: Listening address %s", fullAddressStr.c_str()); // dump debug information to stdout pjsip_tpmgr_dump_transports(pjsip_endpt_get_tpmgr(endpt_)); - transportMap_[listeningPort] = transport; + transportMap_[fullAddressStr] = transport; return transport; } diff --git a/daemon/src/sip/siptransport.h b/daemon/src/sip/siptransport.h index 79b874b705844ff30190454a6286b19f0bd21a87..cbbad8c7ec4997fa0dc9f287a62e33ca559575ff 100644 --- a/daemon/src/sip/siptransport.h +++ b/daemon/src/sip/siptransport.h @@ -169,7 +169,7 @@ class SipTransport { * UDP Transports are stored in this map in order to retreive them in case * several accounts would share the same port number. */ - std::map<pj_uint16_t, pjsip_transport*> transportMap_; + std::map<std::string, pjsip_transport*> transportMap_; /** * Stun resolver array diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 79328eda1eb4f8c3e13ebb3de9686f2284e182c4..5cad7f68c403d0ff4a5252b908b0dededf333d75 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -524,6 +524,9 @@ void SIPVoIPLink::sendRegister(Account *a) std::string contact(account->getContactHeader()); pj_str_t pjContact = pj_str((char*) contact.c_str()); + std::string received(account->getReceivedParameter()); + pj_str_t pjReceived = pj_str((char *) received.c_str()); + if (pjsip_regc_init(regc, &pjSrv, &pjFrom, &pjFrom, 1, &pjContact, account->getRegistrationExpire()) != PJ_SUCCESS) throw VoipLinkException("Unable to initialize account registration structure"); @@ -1632,6 +1635,17 @@ void update_contact_header(pjsip_regc_cbparam *param, SIPAccount *account) pj_pool_release(pool); } +void lookForReceivedParameter(pjsip_regc_cbparam *param, SIPAccount *account) +{ + pj_str_t receivedValue = param->rdata->msg_info.via->recvd_param; + + if (receivedValue.slen) { + std::string publicIpFromReceived(receivedValue.ptr, receivedValue.slen); + DEBUG("Cool received received parameter... uhhh?, the value is %s", publicIpFromReceived.c_str()); + account->setReceivedParameter(publicIpFromReceived); + } +} + void registration_cb(pjsip_regc_cbparam *param) { if (param == NULL) { @@ -1670,22 +1684,23 @@ void registration_cb(pjsip_regc_cbparam *param) if (param->code < 0 || param->code >= 300) { switch (param->code) { - case 606: + case PJSIP_SC_NOT_ACCEPTABLE_ANYWHERE: + lookForReceivedParameter(param, account); account->setRegistrationState(ErrorNotAcceptable); break; - case 503: - case 408: + case PJSIP_SC_SERVICE_UNAVAILABLE: + case PJSIP_SC_REQUEST_TIMEOUT: account->setRegistrationState(ErrorHost); break; - case 401: - case 403: - case 404: + case PJSIP_SC_UNAUTHORIZED: + case PJSIP_SC_FORBIDDEN: + case PJSIP_SC_NOT_FOUND: account->setRegistrationState(ErrorAuth); break; - case 423: + case PJSIP_SC_INTERVAL_TOO_BRIEF: // Expiration Interval Too Brief account->doubleRegistrationExpire(); account->registerVoIPLink(); diff --git a/gnome/src/actions.c b/gnome/src/actions.c index fc938d035ddf9be7568053e9dcbb6d4ff4afad4e..bbbddc23989e59ff8ad26dbb6d49af019a6c6e9a 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -740,15 +740,12 @@ sflphone_keypad(guint keyval, gchar * key) sflphone_new_call(); } -static void place_direct_call(const callable_obj_t * c) +int +sflphone_place_call(callable_obj_t * c) { - g_assert(c->_state == CALL_STATE_DIALING); - dbus_place_call(c); -} + account_t * account = NULL; -static int place_registered_call(callable_obj_t * c) -{ - account_t * current = NULL; + DEBUG("Actions: Placing call with %s @ %s and accountid %s", c->_display_name, c->_peer_number, c->_accountID); if (c->_state != CALL_STATE_DIALING) return -1; @@ -756,51 +753,38 @@ static int place_registered_call(callable_obj_t * c) if (!*c->_peer_number) return -1; - if (account_list_get_size() == 0) { - notify_no_accounts(); - sflphone_fail(c); - return -1; - } - - if (account_list_get_by_state(ACCOUNT_STATE_REGISTERED) == NULL) { - DEBUG("Actions: No registered account, cannot make a call"); - notify_no_registered_accounts(); - sflphone_fail(c); - return -1; - } - DEBUG("Actions: Get account for this call"); if (strlen(c->_accountID) != 0) { DEBUG("Actions: Account %s already set for this call", c->_accountID); - current = account_list_get_by_id(c->_accountID); + account = account_list_get_by_id(c->_accountID); } else { DEBUG("Actions: No account set for this call, use first of the list"); - current = account_list_get_current(); + account = account_list_get_current(); } - if (current == NULL) { + if (account == NULL) { DEBUG("Actions: Unexpected condition: account_t is NULL in %s at %d for accountID %s", __FILE__, __LINE__, c->_accountID); return -1; } - gpointer status = g_hash_table_lookup(current->properties, "Status"); + gpointer status = g_hash_table_lookup(account->properties, "Status"); if (utf8_case_equal(status, "REGISTERED")) { /* The call is made with the current account */ // free memory for previous account id and get a new one g_free(c->_accountID); - c->_accountID = g_strdup(current->accountID); + c->_accountID = g_strdup(account->accountID); dbus_place_call(c); } else { /* Place the call with the first registered account * and switch the current account. * If we are here, we can be sure that there is at least one. */ - current = account_list_get_by_state(ACCOUNT_STATE_REGISTERED); + account = account_list_get_by_state(ACCOUNT_STATE_REGISTERED); g_free(c->_accountID); - c->_accountID = g_strdup(current->accountID); + c->_accountID = g_strdup(account->accountID); dbus_place_call(c); - notify_current_account(current); + notify_current_account(account); } c->_history_state = g_strdup(OUTGOING_STRING); @@ -808,26 +792,6 @@ static int place_registered_call(callable_obj_t * c) return 0; } -void -sflphone_place_call(callable_obj_t * c) -{ - DEBUG("Actions: Placing call with %s @ %s and accountid %s", c->_display_name, c->_peer_number, c->_accountID); - if (place_registered_call(c) < 0) - DEBUG("An error occured while placing registered call in %s at %d", __FILE__, __LINE__); -/* - if (is_direct_call(c)) { - gchar *msg = g_markup_printf_escaped(_("Direct SIP call")); - statusbar_pop_message(__MSG_ACCOUNT_DEFAULT); - statusbar_push_message(msg , NULL, __MSG_ACCOUNT_DEFAULT); - g_free(msg); - - place_direct_call(c); - } else if (place_registered_call(c) < 0) - DEBUG("An error occured while placing registered call in %s at %d", __FILE__, __LINE__); -*/ -} - - void sflphone_detach_participant(const gchar* callID) { diff --git a/gnome/src/actions.h b/gnome/src/actions.h index 5dc304885850c2dcccf9772b2a6f6ed27753111a..6349c4cb8be4d410f2b833d0a173496906fb1b49 100644 --- a/gnome/src/actions.h +++ b/gnome/src/actions.h @@ -157,7 +157,7 @@ void sflphone_keypad(guint keyval, gchar * key); * Place a call with a filled callable_obj_t.to * @param c A call in CALL_STATE_DIALING state */ -void sflphone_place_call(callable_obj_t * c); +int sflphone_place_call(callable_obj_t * c); /** * Fetch the ip2ip profile through dbus and fill diff --git a/gnome/src/config/accountconfigdialog.c b/gnome/src/config/accountconfigdialog.c index fc456f63619eb86ab9764705c280066829c4ca38..f253d8fb6a5024ba15c562c1ed729eada520aecf 100644 --- a/gnome/src/config/accountconfigdialog.c +++ b/gnome/src/config/accountconfigdialog.c @@ -539,7 +539,7 @@ static void use_sip_tls_cb(GtkWidget *widget, gpointer data) static gchar * get_interface_addr_from_name(const gchar * const iface_name) { -#define UC(b) (((int)b)&0xff) +#define UC(b) (((int)b)&0xff) int fd;