From 3baf3e36137869fa0fea6cb41aae023733bbfe20 Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Mon, 14 Apr 2008 13:52:35 -0400 Subject: [PATCH] nothing --- sflphone-gtk/src/configwindow.c | 1 - src/Makefile.am | 1 + src/eventthread.cpp | 21 ++++++++++++- src/eventthread.h | 4 +++ src/managerimpl.cpp | 54 +++++++++++++++++++++++++++------ src/managerimpl.h | 6 ++++ src/sipaccount.cpp | 5 ++- src/sipvoiplink.cpp | 41 +++++++++++++++---------- src/sipvoiplink.h | 5 ++- src/voiplink.cpp | 10 ++++-- src/voiplink.h | 5 +++ 11 files changed, 119 insertions(+), 34 deletions(-) diff --git a/sflphone-gtk/src/configwindow.c b/sflphone-gtk/src/configwindow.c index 5f713d9fd0..83111e66f3 100644 --- a/sflphone-gtk/src/configwindow.c +++ b/sflphone-gtk/src/configwindow.c @@ -657,7 +657,6 @@ enable_account(GtkCellRendererToggle *rend , gchar* path, gpointer data ) // Modify account state g_hash_table_replace( acc->properties , g_strdup(ACCOUNT_ENABLED) , g_strdup((enable == 1)? "TRUE":"FALSE")); - //dbus_set_account_details(acc); dbus_send_register( acc->accountID , enable ); } diff --git a/src/Makefile.am b/src/Makefile.am index 98e0a07fb4..a64dc12432 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -44,6 +44,7 @@ sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone sflphoned_LDADD = ./libsflphone.la $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) $(IAX_LIBS) $(EXOSIP_LIBS) $(ALSAFLAG) AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $(libccgnu2_CFLAGS) $(IAX_CFLAGS) $(USER_INCLUDES) $(libdbuscpp_CFLAGS) \ -DCODECS_DIR=\""$(sflcodecdir)"\" + -DENABLE_TRACE # libsflphone_la_LDFLAGS= -version-info 0:1:0 diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 05ba81bdda..e8e8905d1b 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -25,6 +25,7 @@ EventThread::EventThread (VoIPLink* link) : Thread () { _linkthread = link; setCancel(cancelDeferred); + stopIt = false; } EventThread::~EventThread (void) @@ -38,9 +39,27 @@ EventThread::~EventThread (void) void EventThread::run (void) { - while(!testCancel()) { + stopIt = false; + while(!stopIt) { _linkthread->getEvent(); } } +void +EventThread::stop( void ) +{ + stopIt = true; +} +void +EventThread::startLoop( void ) +{ + stopIt = false; + //start(); +} + +bool +EventThread::isStopped( void ) +{ + return stopIt; +} diff --git a/src/eventthread.h b/src/eventthread.h index cb812b2c31..65daaf9003 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -36,10 +36,14 @@ public: ~EventThread (void); virtual void run (); + virtual void stop(); + virtual void startLoop(); + bool isStopped(); private: /** VoIPLink is the object being called by getEvents() method */ VoIPLink* _linkthread; + bool stopIt; }; #endif // __EVENT_THREAD_H__ diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 21bf054ced..48612dec24 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -440,7 +440,6 @@ ManagerImpl::initRegisterAccounts() if ( iter->second) { iter->second->loadConfig(); if ( iter->second->isEnabled() ) { - _debug("Init register accounts\n" ); // NOW iter->second->registerVoIPLink(); iter->second->loadContacts(); @@ -789,6 +788,7 @@ ManagerImpl::startVoiceMessageNotification(const AccountID& accountId, const std void ManagerImpl::stopVoiceMessageNotification(const AccountID& accountId) { + // TODO : do not notify when no messages if (_dbus) _dbus->getCallManager()->voiceMailNotify(accountId, 0 ); } @@ -817,12 +817,22 @@ ManagerImpl::registrationFailed(const AccountID& accountid) { Account* acc = getAccount(accountid); if ( acc ) { - //acc->setState(false); _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(); + } +} + /** * Multi Thread */ @@ -2117,26 +2127,36 @@ ManagerImpl::sendRegister( const ::DBus::String& accountID , bool expire ) { // Update the active field setConfig( accountID, CONFIG_ACCOUNT_ENABLE, expire ); + Account* acc = getAccount(accountID); acc->loadConfig(); - if (acc->isEnabled()) { + // Test on the value freshly updated + if ( acc->isEnabled() ) { + // As we don't support multiple SIP account, we have to unregister everything before + AccountMap::iterator iter = _accountMap.begin(); + while ( iter != _accountMap.end() ) { + if ( iter->second ) { + setConfig( iter->first , CONFIG_ACCOUNT_ENABLE , false ); + iter->second->unregisterVoIPLink(); + } + iter++; + } // Verify we aren't already registered, then register - if (acc->getRegistrationState() != VoIPLink::Registered) { - _debug("SET ACCOUNTS DETAILS - non registered - > registered\n"); + //if (acc->getRegistrationState() != VoIPLink::Registered) { + _debug("Send register for account %s\n" , accountID.c_str()); + setConfig( accountID , CONFIG_ACCOUNT_ENABLE , true ); acc->registerVoIPLink(); - } + //} } else { // Verify we are already registered, then unregister if (acc->getRegistrationState() == VoIPLink::Registered) { - _debug("SET ACCOUNTS DETAILS - registered - > non registered\n"); + _debug("Send unregister for account %s\n" , accountID.c_str()); acc->unregisterVoIPLink(); - //unregisterAccount(accountID); } } } - void ManagerImpl::addAccount(const std::map< ::DBus::String, ::DBus::String >& details) { @@ -2288,6 +2308,22 @@ ManagerImpl::associateCallToAccount(const CallID& callID, const AccountID& accou } } + AccountID + ManagerImpl::getAccountFromEvent( std::string authname ) +{ + AccountID id; + AccountMap::iterator iter = _accountMap.begin(); + while( iter != _accountMap.end() ){ + if( iter -> second != NULL ){ + id = iter -> first ; + if(getConfigString( id , SIP_AUTH_NAME ) == authname ) + return id; + } + } + return NULL; +} + + AccountID ManagerImpl::getAccountFromCall(const CallID& callID) { diff --git a/src/managerimpl.h b/src/managerimpl.h index 8a9cb64057..378df59087 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -208,6 +208,8 @@ public: void unregistrationSucceed(const AccountID& accountId); /** Notify the user that registration failed */ void registrationFailed(const AccountID& accountId); + /** Notify the user that registration is trying */ + void registrationTrying(const AccountID& accountId); void sendRegister( const AccountID& accountId , bool expire ); // configuration function requests @@ -498,6 +500,10 @@ public: */ bool isCurrentCall(const CallID& callId); + /** + * Map accounts parameters ( authname - hostname ) to an account ID + */ + AccountID getAccountFromEvent( std::string authname ); private: /** * Create .PROGNAME directory in home user and create diff --git a/src/sipaccount.cpp b/src/sipaccount.cpp index e95cfa6f77..cdd79558d1 100644 --- a/src/sipaccount.cpp +++ b/src/sipaccount.cpp @@ -38,16 +38,17 @@ SIPAccount::~SIPAccount() void SIPAccount::registerVoIPLink() { + _debug("SIPAccount: register account %s\n" , getAccountID().c_str()); _link->setFullName(Manager::instance().getConfigString(_accountID,SIP_FULL_NAME)); _link->setHostName(Manager::instance().getConfigString(_accountID,SIP_HOST_PART)); int useStun = Manager::instance().getConfigInt(_accountID,SIP_USE_STUN); + //_link->setAccountID( getAccountID() ); SIPVoIPLink* thislink = dynamic_cast<SIPVoIPLink*> (_link); thislink->setStunServer(Manager::instance().getConfigString(_accountID,SIP_STUN_SERVER)); thislink->setUseStun( useStun!=0 ? true : false); _link->init(); - // Stuff needed for SIP registration. thislink->setProxy (Manager::instance().getConfigString(_accountID,SIP_PROXY)); thislink->setUserPart(Manager::instance().getConfigString(_accountID,SIP_USER_PART)); @@ -59,7 +60,9 @@ SIPAccount::registerVoIPLink() void SIPAccount::unregisterVoIPLink() { + _debug("SIPAccount: unregister account %s\n" , getAccountID().c_str()); _link->sendUnregister(); + _debug("Terminate SIP account\n"); _link->terminate(); } diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 2a0746e174..7d98ba1a63 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -24,6 +24,7 @@ #include "eventthread.h" #include "sipcall.h" #include <sstream> // for ostringstream +#include "sipaccount.h" #include "manager.h" #include "user_cfg.h" // SIGNALISATION / PULSE #define @@ -56,6 +57,7 @@ SIPVoIPLink::SIPVoIPLink(const AccountID& accountID) : VoIPLink(accountID), _localExternAddress("") { _evThread = new EventThread(this); + _initDone = false; _nMsgVoicemail = 0; _eXosipRegID = EXOSIP_ERROR_STD; @@ -76,6 +78,7 @@ SIPVoIPLink::~SIPVoIPLink() bool SIPVoIPLink::init() { + _debug("INIT DONE : %d\n" , _initDone); if (!_initDone) { if (0 != eXosip_init()) { _debug("! SIP Failure: Could not initialize eXosip\n"); @@ -149,18 +152,18 @@ SIPVoIPLink::init() return true; } - - void SIPVoIPLink::terminate() { + _debug("Terminate before\n"); terminateSIPCall(); + _debug("Terminate after\n"); if (_initDone) { // TODO The next line makes the daemon crash on // account delete if at least one account is registered. // It should called only when the last account // is deleted/unregistered. - //eXosip_quit(); + // eXosip_quit(); _initDone = false; } } @@ -168,6 +171,7 @@ SIPVoIPLink::terminate() void SIPVoIPLink::terminateSIPCall() { + ost::MutexLock m(_callMapMutex); CallMap::iterator iter = _callMap.begin(); SIPCall *call; @@ -213,18 +217,17 @@ void SIPVoIPLink::getEvent() { char* tmp2; + const char* localport = ""+_localPort; eXosip_event_t* event = eXosip_event_wait(0, 50); eXosip_lock(); eXosip_automatic_action(); eXosip_unlock(); - - if (event == NULL) { + + if ( event == NULL ) { return; } - - _debugMid("> SIP Event: [cdt=%4d:%4d:%4d] type=#%03d %s = ", event->cid, event->did, event->tid, event->type, event->textinfo); + switch (event->type) { - /* REGISTER related events */ case EXOSIP_REGISTRATION_NEW: /** 00 < announce new registration. */ _debugMid(" !EXOSIP_REGISTRATION_NEW event is not implemented\n"); @@ -232,18 +235,18 @@ SIPVoIPLink::getEvent() case EXOSIP_REGISTRATION_SUCCESS: /** 01 < user is successfully registred. */ _debugMid(" !EXOSIP_REGISTRATION_SUCCESS \n"); if(_eXosipRegID == EXOSIP_ERROR_STD){ + _debug("Successfully Unregister account ID = %s\n" , getAccountID().c_str()); setRegistrationState(Unregistered); - Manager::instance().unregistrationSucceed(getAccountID()); + if( _evThread ) _evThread->stop(); } else{ + _debug("Successfully Register account ID = %s\n" , getAccountID().c_str()); setRegistrationState(Registered); - Manager::instance().registrationSucceed(getAccountID()); } break; case EXOSIP_REGISTRATION_FAILURE: /** 02 < user is not registred. */ setRegistrationState(Error, "SIP registration failure."); _debugMid(" !EXOSIP_REGISTRATION_FAILURE\n"); - //Manager::instance().registrationFailed(getAccountID()); break; case EXOSIP_REGISTRATION_REFRESHED: /** 03 < registration has been refreshed. */ _debugMid(" !EXOSIP_REGISTRATION_REFRESHED event is not implemented\n"); @@ -448,7 +451,6 @@ SIPVoIPLink::getEvent() bool SIPVoIPLink::sendRegister() { - _debug("SEND REGISTER \n"); if (_eXosipRegID != EXOSIP_ERROR_STD) { Manager::instance().displayError("! SIP Error: Registration already sent. Try to unregister"); @@ -507,9 +509,9 @@ SIPVoIPLink::sendRegister() eXosip_unlock(); return false; } - eXosip_unlock(); setRegistrationState(Trying); + eXosip_unlock(); return true; } @@ -520,6 +522,12 @@ SIPVoIPLink::SIPFromHeader(const std::string& userpart, const std::string& hostp return ("\"" + getFullName() + "\"" + " <sip:" + userpart + "@" + hostpart + ">"); } +std::string +SIPVoIPLink::SIPFromHeaderAlternate(const std::string& userpart, const std::string& hostpart) +{ + return ("<sip:" + userpart + "@" + hostpart + ">"); +} + bool SIPVoIPLink::sendSIPAuthentification() { @@ -547,7 +555,7 @@ SIPVoIPLink::sendSIPAuthentification() bool SIPVoIPLink::sendUnregister() { - _debug("SEND UNREGISTER\n"); + _debug("SEND UNREGISTER for account %s\n" , getAccountID().c_str()); if ( _eXosipRegID == EXOSIP_ERROR_STD) return false; int eXosipErr = EXOSIP_ERROR_NO; osip_message_t *reg = NULL; @@ -572,8 +580,8 @@ SIPVoIPLink::sendUnregister() if (eXosipErr == EXOSIP_ERROR_STD) { _debug("! SIP Failure: Unable to send registration (unregister)\n"); } - eXosip_unlock(); _eXosipRegID = EXOSIP_ERROR_STD; + eXosip_unlock(); return true; } @@ -1517,6 +1525,7 @@ SIPVoIPLink::SIPCallReleased(eXosip_event_t *event) if (!call) { return; } // if we are here.. something when wrong before... + _debug("SIP call release\n"); CallID id = call->getCallId(); Manager::instance().callFailure(id); removeCall(id); @@ -1535,7 +1544,6 @@ SIPVoIPLink::SIPMessageNew(eXosip_event_t *event) } // Voice message else if (MSG_IS_NOTIFY(event->request)){ - _debug(" > NOTIFY Voice message\n"); int ii; osip_body_t *body = NULL; // Get the message body @@ -1565,6 +1573,7 @@ SIPVoIPLink::SIPMessageNew(eXosip_event_t *event) // Set the number of voice-message int msgVoicemail = atoi(nb_msg.data()); + _debug(" > NOTIFY -> %i voice message for account %s\n" , msgVoicemail , getAccountID().c_str()); if (msgVoicemail != 0) { // If there is at least one voice-message, start notification diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h index d25553c7db..0a40e05979 100644 --- a/src/sipvoiplink.h +++ b/src/sipvoiplink.h @@ -24,13 +24,13 @@ #include <string> #include <eXosip2/eXosip.h> #include "audio/audiortp.h" +#include <osip2/osip_mt.h> class EventThread; class SIPCall; /** * Specific VoIPLink for SIP (SIP core for incoming and outgoing events) - * @author Yan Morin <yan.morin@gmail.com> */ class SIPVoIPLink : public VoIPLink @@ -113,6 +113,7 @@ private: * @return SIP URI for from Header */ std::string SIPFromHeader(const std::string& userpart, const std::string& hostpart); + std::string SIPFromHeaderAlternate(const std::string& userpart, const std::string& hostpart); /** * Build a sip address with the number that you want to call @@ -242,8 +243,6 @@ private: /** To build sdp when call is off-hold */ int sdp_off_hold_call (sdp_message_t * sdp); - - /** EventThread get every incoming events */ EventThread* _evThread; /** Tell if eXosip was stared (eXosip_init) */ diff --git a/src/voiplink.cpp b/src/voiplink.cpp index 7da85fa6f5..ad0c07dea7 100644 --- a/src/voiplink.cpp +++ b/src/voiplink.cpp @@ -88,17 +88,21 @@ VoIPLink::setRegistrationState(const enum RegistrationState state, const std::st _registrationState = state; _registrationError = errorMessage; + std::string acc_ID = getAccountID(); + _debug("Set registration state for account %s\n" , acc_ID.c_str()); + switch (state) { case Registered: - Manager::instance().registrationSucceed(getAccountID()); + Manager::instance().registrationSucceed(acc_ID); break; case Trying: - //Manager::instance(). some function to say that + Manager::instance().registrationTrying( acc_ID); break; case Error: - Manager::instance().registrationFailed(getAccountID()); + Manager::instance().registrationFailed(acc_ID); break; case Unregistered: + Manager::instance().unregistrationSucceed(acc_ID); break; } } diff --git a/src/voiplink.h b/src/voiplink.h index 73c16896b5..887ea7973b 100644 --- a/src/voiplink.h +++ b/src/voiplink.h @@ -122,6 +122,11 @@ public: */ AccountID& getAccountID(void) { return _accountID; } + /** + * Set parent Account's ID + */ + void setAccountID( const AccountID& accountID) { _accountID = accountID; } + /** Get the call pointer from the call map (protected by mutex) * @param id A Call ID * @return call pointer or 0 -- GitLab