[ekiga] Canonise address introduced when editing a contact in roster



commit 0c0c97980f195c1dea76532fc50eac22fc3550dc
Author: Eugen Dedu <Eugen Dedu pu-pm univ-fcomte fr>
Date:   Mon Dec 5 16:48:26 2011 +0100

    Canonise address introduced when editing a contact in roster

 lib/engine/components/local-roster/local-heap.cpp  |   13 +--------
 .../components/local-roster/local-presentity.cpp   |   25 +++++++++++++++++--
 .../components/local-roster/local-presentity.h     |    5 ++++
 3 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/lib/engine/components/local-roster/local-heap.cpp b/lib/engine/components/local-roster/local-heap.cpp
index b0389ea..571c40c 100644
--- a/lib/engine/components/local-roster/local-heap.cpp
+++ b/lib/engine/components/local-roster/local-heap.cpp
@@ -43,6 +43,7 @@
 #include "form-request-simple.h"
 
 #include "local-heap.h"
+#include "local-presentity.h"
 
 #define KEY "/apps/" PACKAGE_NAME "/contacts/roster"
 
@@ -395,17 +396,7 @@ Local::Heap::new_presentity_form_submitted (bool submitted,
   else
     uri = result.text ("uri");
 
-  // remove leading and trailing spaces (useful for copy/paste)
-  const size_t begin_str = uri.find_first_not_of (" \t");
-  if (begin_str != std::string::npos) {  // there is content
-    const size_t end_str = uri.find_last_not_of (" \t");
-    const size_t range = end_str - begin_str + 1;
-    uri = uri.substr (begin_str, range);
-    const size_t pos = uri.find (":");
-    // if no protocol specified, add leading "sip:"
-    if (pos == std::string::npos)
-      uri = uri.insert (0, "sip:");
-  }
+  uri = canonise_uri (uri);
 
   if (presence_core->is_supported_uri (uri)
       && !has_presentity_with_uri (uri)) {
diff --git a/lib/engine/components/local-roster/local-presentity.cpp b/lib/engine/components/local-roster/local-presentity.cpp
index 88f4afd..b154b11 100644
--- a/lib/engine/components/local-roster/local-presentity.cpp
+++ b/lib/engine/components/local-roster/local-presentity.cpp
@@ -42,6 +42,26 @@
 #include "robust-xml.h"
 #include "local-presentity.h"
 
+
+// remove leading and trailing spaces and tabs (useful for copy/paste)
+// also, if no protocol specified, add leading "sip:"
+std::string
+canonise_uri (std::string uri)
+{
+  const size_t begin_str = uri.find_first_not_of (" \t");
+  if (begin_str == std::string::npos)  // there is no content
+    return "";
+
+  const size_t end_str = uri.find_last_not_of (" \t");
+  const size_t range = end_str - begin_str + 1;
+  uri = uri.substr (begin_str, range);
+  const size_t pos = uri.find (":");
+  if (pos == std::string::npos)
+    uri = uri.insert (0, "sip:");
+  return uri;
+}
+
+
 /* at one point we will return a smart pointer on this... and if we don't use
  * a false smart pointer, we will crash : the reference count isn't embedded!
  */
@@ -272,9 +292,8 @@ Local::Presentity::edit_presentity_form_submitted (bool submitted,
   const std::string uri = get_uri ();
   bool preferred = result.boolean ("preferred");
   std::set<xmlNodePtr> nodes_to_remove;
-  size_t pos = new_uri.find_first_of (' ');
-  if (pos != std::string::npos)
-    new_uri = new_uri.substr (0, pos);
+
+  new_uri = canonise_uri (new_uri);
 
   for (xmlNodePtr child = node->children ;
        child != NULL ;
diff --git a/lib/engine/components/local-roster/local-presentity.h b/lib/engine/components/local-roster/local-presentity.h
index fcba57e..8f5824d 100644
--- a/lib/engine/components/local-roster/local-presentity.h
+++ b/lib/engine/components/local-roster/local-presentity.h
@@ -47,6 +47,11 @@
 #include "presence-core.h"
 #include "presentity.h"
 
+// remove leading and trailing spaces (useful for copy/paste)
+// also, if no protocol specified, add leading "sip:"
+std::string
+canonise_uri (std::string uri);
+
 namespace Local
 {
 



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