ekiga r7581 - in trunk: . lib/engine/components/opal



Author: dsandras
Date: Wed Jan 21 21:05:20 2009
New Revision: 7581
URL: http://svn.gnome.org/viewvc/ekiga?rev=7581&view=rev

Log:
Do not force the SIP listen port to be in the udp port range.
Optimized dialog info notifications handling.


Modified:
   trunk/ChangeLog
   trunk/lib/engine/components/opal/opal-call-manager.cpp
   trunk/lib/engine/components/opal/opal-main.cpp
   trunk/lib/engine/components/opal/sip-endpoint.cpp
   trunk/lib/engine/components/opal/sip-endpoint.h

Modified: trunk/lib/engine/components/opal/opal-call-manager.cpp
==============================================================================
--- trunk/lib/engine/components/opal/opal-call-manager.cpp	(original)
+++ trunk/lib/engine/components/opal/opal-call-manager.cpp	Wed Jan 21 21:05:20 2009
@@ -727,12 +727,13 @@
 			 " still use it, but you need to configure your network settings manually.\n\n"
 			 "Please see http://wiki.ekiga.org/index.php/Enable_port_forwarding_manually for"
 			 " instructions"));
-    } else {
+    } 
+    else {
 
-    for (Ekiga::CallManager::iterator iter = begin ();
-	 iter != end ();
-	 ++iter) 
-      (*iter)->set_listen_port ((*iter)->get_listen_interface ().port);
+      for (Ekiga::CallManager::iterator iter = begin ();
+           iter != end ();
+           ++iter) 
+        (*iter)->set_listen_port ((*iter)->get_listen_interface ().port);
     }
 
     ready.emit ();
@@ -740,7 +741,8 @@
     if (result != NULL)
       g_free (result);
 
-  } else {
+  } 
+  else {
 
       patience--;
       runtime->run_in_main (sigc::mem_fun (this,

Modified: trunk/lib/engine/components/opal/opal-main.cpp
==============================================================================
--- trunk/lib/engine/components/opal/opal-main.cpp	(original)
+++ trunk/lib/engine/components/opal/opal-main.cpp	Wed Jan 21 21:05:20 2009
@@ -88,15 +88,49 @@
 using namespace Opal;
 
 void 
-on_call_manager_ready_cb (Ekiga::ServiceCore *core)
+on_call_manager_ready_cb (Ekiga::ServiceCore *core,
+                          gmref_ptr<CallManager> call_manager)
 {
   gmref_ptr<Ekiga::AccountCore> account_core = core->get ("account-core");
+  gmref_ptr<Ekiga::ContactCore> contact_core = core->get ("contact-core");
+  gmref_ptr<Ekiga::PresenceCore> presence_core = core->get ("presence-core");
   gmref_ptr<Opal::Bank> bank (new Bank (*core));
 
+#ifdef HAVE_SIP
+  gmref_ptr<Sip::EndPoint> sip_manager = call_manager->get_protocol_manager ("sip");  
+#endif
+#ifdef HAVE_H323
+  gmref_ptr<H323::EndPoint> h323_manager = call_manager->get_protocol_manager ("h323");  
+#endif
+
   account_core->add_bank (*bank);
   core->add (bank);
+
+  if (contact_core) { 
+
+#ifdef HAVE_SIP
+    contact_core->add_contact_decorator (sip_manager);
+#endif
+#ifdef HAVE_H323
+    contact_core->add_contact_decorator (h323_manager);
+#endif
+  }
+
+  if (presence_core) {
+
+#ifdef HAVE_SIP
+    presence_core->add_presentity_decorator (sip_manager);
+    presence_core->add_presence_fetcher (sip_manager);
+    presence_core->add_presence_publisher (sip_manager);
+#endif
+#ifdef HAVE_H323
+    presence_core->add_presentity_decorator (h323_manager);
+#endif
+    presence_core->add_supported_uri (sigc::ptr_fun (is_supported_address)); //FIXME
+  }
 }
 
+
 bool
 opal_init (Ekiga::ServiceCore &core,
            int * /*argc*/,
@@ -108,8 +142,6 @@
   gmref_ptr<Ekiga::ChatCore> chat_core = core.get ("chat-core");
   gmref_ptr<Ekiga::AccountCore> account_core = core.get ("account-core");
 
-  bool result = true;
-
   gmref_ptr<CallManager> call_manager (new CallManager (core));
 
 #ifdef HAVE_SIP
@@ -131,41 +163,14 @@
   new ConfBridge (*call_manager); // FIXME: isn't that leaked!?
 
   // Add the bank of accounts when the CallManager is ready
-  call_manager->ready.connect (sigc::bind (sigc::ptr_fun (on_call_manager_ready_cb), &core));
+  call_manager->ready.connect (sigc::bind (sigc::ptr_fun (on_call_manager_ready_cb), &core, call_manager));
   call_manager->start ();
 
-  if (contact_core) { 
-
-#ifdef HAVE_SIP
-    contact_core->add_contact_decorator (sip_manager);
-#endif
-#ifdef HAVE_H323
-    contact_core->add_contact_decorator (h323_manager);
-#endif
-  }
-  else
-    return false;
-
-  if (presence_core) {
-
-#ifdef HAVE_SIP
-    presence_core->add_presentity_decorator (sip_manager);
-    presence_core->add_presence_fetcher (sip_manager);
-    presence_core->add_presence_publisher (sip_manager);
-#endif
-#ifdef HAVE_H323
-    presence_core->add_presentity_decorator (h323_manager);
-#endif
-    presence_core->add_supported_uri (sigc::ptr_fun (is_supported_address)); //FIXME
-  }
-  else
-    return false;
-
   OpalLinkerHacks::loadOpalVideoInput = 1;
   OpalLinkerHacks::loadOpalVideoOutput = 1;
   OpalLinkerHacks::loadOpalAudio = 1;
 
   core.add (call_manager);
 
-  return result;
+  return true;
 }

Modified: trunk/lib/engine/components/opal/sip-endpoint.cpp
==============================================================================
--- trunk/lib/engine/components/opal/sip-endpoint.cpp	(original)
+++ trunk/lib/engine/components/opal/sip-endpoint.cpp	Wed Jan 21 21:05:20 2009
@@ -304,8 +304,8 @@
   // It is not in the list of uris for which a subscribe is active
   if (std::find (subscribed_uris.begin (), subscribed_uris.end (), _uri) == subscribed_uris.end ()) {
 
-    // We are registered yet
-    if (std::find (domains.begin (), domains.end (), domain) != domains.end ()) {
+    // The account is active 
+    if (std::find (active_domains.begin (), active_domains.end (), domain) != active_domains.end ()) {
 
       Subscribe (SIPSubscribe::Presence, 300, PString (_uri.c_str ()));
       Subscribe (SIPSubscribe::Dialog, 300, PString (_uri.c_str ()));
@@ -463,7 +463,7 @@
 
   manager.get_udp_ports (udp_min, udp_max);
 
-  if (port > 0 && port >= udp_min && port <= udp_max) {
+  if (port > 0) {
 
     std::stringstream str;
     RemoveListener (NULL);
@@ -484,8 +484,10 @@
         port++;
       }
     }
-    else
+    else {
       listen_iface.port = port;
+      return true;
+    }
   }
 
   return false;
@@ -537,6 +539,18 @@
 }
 
 
+std::string Opal::Sip::EndPoint::get_aor_domain (const std::string & aor)
+{
+  std::string domain;
+  std::string::size_type loc = aor.find ("@", 0);
+
+  if (loc != string::npos) 
+    domain = aor.substr (loc+1);
+
+  return domain;
+}
+
+
 bool Opal::Sip::EndPoint::subscribe (const Opal::Account & account)
 {
   if (account.get_protocol_name () != "SIP" || account.is_active ())
@@ -579,7 +593,16 @@
   params.m_expire = (account.is_enabled () ? account.get_timeout () : 0);
   params.m_minRetryTime = 0;
   params.m_maxRetryTime = 0;
+  
+  // Update the list of active domains
+  std::string domain = Opal::Sip::EndPoint::get_aor_domain (aor.str ());
+  bool found = (std::find (active_domains.begin (), active_domains.end (), domain) != active_domains.end ());
+  if (account.is_enabled () && !found)
+    active_domains.push_back (domain);
+  else if (!account.is_enabled () && found)
+    active_domains.remove (domain);
 
+  // Register the given aor to the give registrar
   if (!SIPEndPoint::Register (params, _aor))
     OnRegistrationFailed (aor.str (), SIP_PDU::MaxStatusCode, account.is_enabled ());
 }
@@ -614,17 +637,10 @@
 
   if (loc != string::npos) {
 
-    server = aor.substr (loc+1);
-
+    server = get_aor_domain (aor);
     if (server.empty ())
       return;
 
-    if (was_registering && std::find (domains.begin (), domains.end (), server) == domains.end ()) 
-      domains.push_back (server);
-
-    if (!was_registering && std::find (domains.begin (), domains.end (), server) != domains.end ()) 
-      domains.remove (server);
-
     if (was_registering) {
       for (std::list<std::string>::const_iterator iter = to_subscribe_uris.begin (); 
            iter != to_subscribe_uris.end () ; ) { 
@@ -1078,8 +1094,8 @@
   SIPURL sip_uri = SIPURL (user);
   sip_uri.Sanitise (SIPURL::ExternalURI);
   std::string _uri = sip_uri.AsString ();
-  std::string old_presence = uri_presences[_uri].first;
-  std::string old_status = uri_presences[_uri].second;
+  std::string old_presence = presence_infos[_uri].presence;
+  std::string old_status = presence_infos[_uri].status;
 
   // If first notification, and no information, then we are offline
   if (presence == "unknown" && old_presence.empty ())
@@ -1090,8 +1106,9 @@
   // first notification, and we can conclude it is a ping back from the server 
   // to indicate the presence status did not change, hence we do nothing.
   if (presence != "unknown" && (old_presence != presence || old_status != status)) {
-    uri_presences[_uri] = std::pair<std::string, std::string> (presence, status);
-    runtime->run_in_main (sigc::bind (sigc::ptr_fun (presence_status_in_main), this, _uri, presence, status));
+    presence_infos[_uri].presence = presence;
+    presence_infos[_uri].status = status;
+    runtime->run_in_main (sigc::bind (sigc::ptr_fun (presence_status_in_main), this, _uri, presence_infos[_uri].presence, presence_infos[_uri].status));
   }
 }
 
@@ -1099,9 +1116,10 @@
 void 
 Opal::Sip::EndPoint::OnDialogInfoReceived (const SIPDialogNotification & info)
 {
-  gchar* status = NULL;
+  gchar* _status = NULL;
+  std::string status;
   std::string presence;
-  PString uri = info.m_entity;
+  std::string uri = (const char *) info.m_entity;
   PString remote_uri = info.m_remote.m_identity;
   PString remote_display_name = info.m_remote.m_display.IsEmpty () ? remote_uri : info.m_remote.m_display;
 
@@ -1109,17 +1127,19 @@
     case SIPDialogNotification::Proceeding:
     case SIPDialogNotification::Early:
       if (!remote_display_name.IsEmpty ())
-        status = g_strdup_printf (_("Incoming call from %s"), (const char *) remote_display_name);
+        _status = g_strdup_printf (_("Incoming call from %s"), (const char *) remote_display_name);
       else
-        status = g_strdup_printf (_("Incoming call"));
+        _status = g_strdup_printf (_("Incoming call"));
+      status = _status;
       presence = "ringing";
       break;
     case SIPDialogNotification::Confirmed:
       if (!remote_display_name.IsEmpty ())
-        status = g_strdup_printf (_("In a call with %s"), (const char *) remote_display_name);
+        _status = g_strdup_printf (_("In a call with %s"), (const char *) remote_display_name);
       else
-        status = g_strdup_printf (_("In a call"));
+        _status = g_strdup_printf (_("In a call"));
       presence = "inacall";
+      status = _status;
       break;
     default:
     case SIPDialogNotification::Trying:
@@ -1127,10 +1147,13 @@
       break;
   }
 
-  if (status)
-    runtime->run_in_main (sigc::bind (sigc::ptr_fun (presence_status_in_main), this, uri, presence, status));
+  dialog_infos[uri].presence = presence;
+  dialog_infos[uri].status = status;
+
+  if (_status)
+    runtime->run_in_main (sigc::bind (sigc::ptr_fun (presence_status_in_main), this, uri, dialog_infos[uri].presence, dialog_infos[uri].status));
   else
-    runtime->run_in_main (sigc::bind (sigc::ptr_fun (presence_status_in_main), this, uri, uri_presences[uri].first, uri_presences[uri].second));
+    runtime->run_in_main (sigc::bind (sigc::ptr_fun (presence_status_in_main), this, uri, presence_infos[uri].presence, presence_infos[uri].status));
 }
 
 

Modified: trunk/lib/engine/components/opal/sip-endpoint.h
==============================================================================
--- trunk/lib/engine/components/opal/sip-endpoint.h	(original)
+++ trunk/lib/engine/components/opal/sip-endpoint.h	Wed Jan 21 21:05:20 2009
@@ -73,6 +73,15 @@
 
   public:
 
+      typedef std::list<std::string> domain_list;
+      typedef std::list<std::string>::iterator domain_list_iterator;
+      typedef struct {
+        std::string presence;
+        std::string status;
+        bool requested;
+      } uri_info;
+      typedef std::map<std::string, uri_info> uri_info_map; 
+
       EndPoint (CallManager &ep, Ekiga::ServiceCore & core, unsigned listen_port);
 
       ~EndPoint ();
@@ -132,6 +141,10 @@
       bool subscribe (const Opal::Account & account);
       bool unsubscribe (const Opal::Account & account);
 
+      
+      /* Helper */
+      static std::string get_aor_domain (const std::string & aor);
+
 
       /* OPAL Methods */
       void Register (const Opal::Account & account);
@@ -180,7 +193,6 @@
 
       std::list<std::string> to_subscribe_uris;  // List of uris to subscribe
       std::list<std::string> subscribed_uris;    // List of subscribed uris
-      std::list<std::string> domains;            // List of registered domains
       std::list<std::string> aors;               // List of registered aor
       Ekiga::ServiceCore & core;
       Ekiga::Runtime* runtime;
@@ -197,7 +209,9 @@
 
       SIP::Dialect* dialect;
 
-      std::map<std::string, std::pair <std::string, std::string> > uri_presences;
+      domain_list active_domains;   // List of active domains
+      uri_info_map presence_infos;  // List of uri presences
+      uri_info_map dialog_infos;    // List of uri dialog informations
     };
   };
 };



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]