[ekiga/gnome-2-26] Fixed potential crash due to threads.



commit 46aa37f9dc9ff63eb08a37789891e3deacb2d62f
Author: Damien Sandras <dsandras seconix com>
Date:   Tue Sep 8 17:10:11 2009 +0200

    Fixed potential crash due to threads.
    
    The account stack is not thread-safe.

 lib/engine/components/opal/sip-endpoint.cpp |   51 ++++++++++++++++++--------
 lib/engine/components/opal/sip-endpoint.h   |    7 ++++
 2 files changed, 42 insertions(+), 16 deletions(-)
---
diff --git a/lib/engine/components/opal/sip-endpoint.cpp b/lib/engine/components/opal/sip-endpoint.cpp
index db7cce7..8358fe0 100644
--- a/lib/engine/components/opal/sip-endpoint.cpp
+++ b/lib/engine/components/opal/sip-endpoint.cpp
@@ -123,6 +123,10 @@ Opal::Sip::EndPoint::EndPoint (Opal::CallManager & _manager,
   dialect = gmref_ptr<SIP::Dialect>(new SIP::Dialect (core, sigc::mem_fun (this, &Opal::Sip::EndPoint::send_message)));
   chat_core->add_dialect (dialect);
 
+  bank->account_added.connect (sigc::mem_fun (this, &Opal::Sip::EndPoint::on_bank_updated));
+  bank->account_removed.connect (sigc::mem_fun (this, &Opal::Sip::EndPoint::on_bank_updated));
+  bank->account_updated.connect (sigc::mem_fun (this, &Opal::Sip::EndPoint::on_bank_updated));
+
   /* Timeouts */
   SetAckTimeout (PTimeInterval (0, 32));
   SetPduCleanUpTimeout (PTimeInterval (0, 1));
@@ -178,7 +182,7 @@ Opal::Sip::EndPoint::menu_builder_add_actions (const std::string& fullname,
   bool populated = false;
 
   std::list<std::string> uris;
-  std::list<std::string> accounts;
+  std::list<std::string> accounts_list;
 
   if (!(uri.find ("sip:") == 0 || uri.find (":") == string::npos))
     return false;
@@ -210,15 +214,15 @@ Opal::Sip::EndPoint::menu_builder_add_actions (const std::string& fullname,
 	uristr << "@" << (*it)->get_host ();
 
 	uris.push_back (uristr.str ());
-	accounts.push_back ((*it)->get_name ());
+	accounts_list.push_back ((*it)->get_name ());
       }
     }
   } else {
     uris.push_back (uri);
-    accounts.push_back ("");
+    accounts_list.push_back ("");
   }
 
-  std::list<std::string>::iterator ita = accounts.begin ();
+  std::list<std::string>::iterator ita = accounts_list.begin ();
   for (std::list<std::string>::iterator it = uris.begin ();
        it != uris.end ();
        it++) {
@@ -244,7 +248,7 @@ Opal::Sip::EndPoint::menu_builder_add_actions (const std::string& fullname,
     ita++;
   }
 
-  ita = accounts.begin ();
+  ita = accounts_list.begin ();
   for (std::list<std::string>::iterator it = uris.begin ();
        it != uris.end ();
        it++) {
@@ -951,14 +955,11 @@ SIPURL
 Opal::Sip::EndPoint::GetRegisteredPartyName (const SIPURL & aor,
 					     const OpalTransport & transport)
 {
-  /*
-   * Do we have an account?
-   */
-  for (Opal::Bank::iterator it = bank->begin ();
-       it != bank->end ();
-       it++) 
-    if ((*it)->get_host () == (const char*) aor.GetHostName ())
-      return (*it)->get_aor ().c_str ();
+  PWaitAndSignal m(aorMutex);
+  std::string local_aor = accounts[(const char*) aor.GetHostName ()];
+
+  if (!local_aor.empty ())
+    return local_aor.c_str ();
 
   /* As a last resort, use the local address
    */
@@ -1092,6 +1093,26 @@ void Opal::Sip::EndPoint::on_transfer (std::string uri)
       connection->TransferConnection (uri);
 }
 
+
+void
+Opal::Sip::EndPoint::on_bank_updated (Ekiga::AccountPtr /*account*/)
+{
+  bank->visit_accounts (sigc::mem_fun (this, &Opal::Sip::EndPoint::visit_accounts));
+}
+
+
+bool
+Opal::Sip::EndPoint::visit_accounts (Ekiga::AccountPtr account_)
+{
+  Opal::AccountPtr account = account_;
+
+  PWaitAndSignal m(aorMutex);
+  accounts[account->get_host ()] = account->get_aor ();
+
+  return true;
+}
+
+
 void
 Opal::Sip::EndPoint::registration_event_in_main (const std::string aor,
 						 Ekiga::Account::RegistrationState state,
@@ -1099,10 +1120,8 @@ Opal::Sip::EndPoint::registration_event_in_main (const std::string aor,
 {
   AccountPtr account = bank->find_account (aor);
 
-  if (account) {
-
+  if (account) 
     account->registration_event.emit (state, msg);
-  }
 }
 
 
diff --git a/lib/engine/components/opal/sip-endpoint.h b/lib/engine/components/opal/sip-endpoint.h
index 7a25f69..6c08bd4 100644
--- a/lib/engine/components/opal/sip-endpoint.h
+++ b/lib/engine/components/opal/sip-endpoint.h
@@ -193,6 +193,10 @@ namespace Opal {
 		       std::string name);
       void on_transfer (std::string uri);
 
+      void on_bank_updated (Ekiga::AccountPtr account);
+
+      bool visit_accounts (Ekiga::AccountPtr account);
+
       void registration_event_in_main (const std::string aor,
 				       Ekiga::Account::RegistrationState state,
 				       const std::string msg);
@@ -215,6 +219,9 @@ namespace Opal {
       PMutex msgDataMutex;
       msgDict msgData;
 
+      PMutex aorMutex;
+      std::map<std::string, std::string> accounts;
+
       CallManager & manager;
 
       Ekiga::ServiceCore & core;



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