ekiga r7224 - trunk/lib/engine/components/resource-list



Author: jpuydt
Date: Wed Oct 15 12:48:18 2008
New Revision: 7224
URL: http://svn.gnome.org/viewvc/ekiga?rev=7224&view=rev

Log:
Much improved resource-list code... untested : no working XCAP server...

Modified:
   trunk/lib/engine/components/resource-list/rl-cluster.cpp
   trunk/lib/engine/components/resource-list/rl-cluster.h
   trunk/lib/engine/components/resource-list/rl-entry.cpp
   trunk/lib/engine/components/resource-list/rl-entry.h
   trunk/lib/engine/components/resource-list/rl-heap.cpp
   trunk/lib/engine/components/resource-list/rl-heap.h
   trunk/lib/engine/components/resource-list/rl-list.cpp
   trunk/lib/engine/components/resource-list/rl-list.h

Modified: trunk/lib/engine/components/resource-list/rl-cluster.cpp
==============================================================================
--- trunk/lib/engine/components/resource-list/rl-cluster.cpp	(original)
+++ trunk/lib/engine/components/resource-list/rl-cluster.cpp	Wed Oct 15 12:48:18 2008
@@ -86,7 +86,7 @@
     doc = xmlNewDoc (BAD_CAST "1.0");
     xmlNodePtr root = xmlNewDocNode (doc, NULL, BAD_CAST "list", NULL);
     xmlDocSetRootElement (doc, root);
-    add ("http://localhost/test.rl";, "", "", "XCAP Test"); // FIXME: remove
+    add ("http://localhost:443";, "test", "", "", "XCAP Test"); // FIXME: remove
   }
 }
 
@@ -101,7 +101,7 @@
 {
   builder.add_action ("new", _("New resource list"),
 		      sigc::bind (sigc::mem_fun (this, &RL::Cluster::new_heap),
-				  "", "", "", ""));
+				  "", "", "", "", ""));
   return true;
 }
 
@@ -117,9 +117,10 @@
 RL::Cluster::add (const std::string uri,
 		  const std::string username,
 		  const std::string password,
+		  const std::string user,
 		  const std::string name)
 {
-  Heap* heap = new Heap (core, name, uri, username, password);
+  Heap* heap = new Heap (core, name, uri, username, password, user);
   xmlNodePtr root = xmlDocGetRootElement (doc);
 
   xmlAddChild (root, heap->get_node ());
@@ -155,7 +156,8 @@
 RL::Cluster::new_heap (const std::string name,
 		       const std::string uri,
 		       const std::string username,
-		       const std::string password)
+		       const std::string password,
+		       const std::string user)
 {
   Ekiga::FormRequestSimple request;
 
@@ -166,6 +168,7 @@
   request.text ("uri", _("Address:"), uri);
   request.text ("username", _("Username:"), username);
   request.private_text ("password", _("Password:"), password);
+  request.text ("user", _("User:"), user);
 
   request.submitted.connect (sigc::mem_fun (this, &RL::Cluster::on_new_heap_form_submitted));
 
@@ -188,8 +191,9 @@
     const std::string uri = result.text ("uri");
     const std::string username = result.text ("username");
     const std::string password = result.private_text ("password");
+    const std::string user = result.text ("user");
 
-    add (name, uri, username, password);
+    add (name, uri, username, password, user);
   } catch (Ekiga::Form::not_found) {
 
 #ifdef __GNUC__

Modified: trunk/lib/engine/components/resource-list/rl-cluster.h
==============================================================================
--- trunk/lib/engine/components/resource-list/rl-cluster.h	(original)
+++ trunk/lib/engine/components/resource-list/rl-cluster.h	Wed Oct 15 12:48:18 2008
@@ -71,6 +71,7 @@
     void add (const std::string uri,
 	      const std::string username,
 	      const std::string password,
+	      const std::string user,
 	      const std::string name);
     void common_add (Heap& heap);
     void save () const;
@@ -78,7 +79,8 @@
     void new_heap (const std::string name,
 		   const std::string uri,
 		   const std::string username,
-		   const std::string password);
+		   const std::string password,
+		   const std::string user);
 
     void on_new_heap_form_submitted (Ekiga::Form& result);
 

Modified: trunk/lib/engine/components/resource-list/rl-entry.cpp
==============================================================================
--- trunk/lib/engine/components/resource-list/rl-entry.cpp	(original)
+++ trunk/lib/engine/components/resource-list/rl-entry.cpp	Wed Oct 15 12:48:18 2008
@@ -45,17 +45,33 @@
 #include "presence-core.h"
 
 RL::Entry::Entry (Ekiga::ServiceCore& core_,
-		  const std::string path_,
+		  gmref_ptr<XCAP::Path> path_,
 		  int pos,
 		  const std::string group,
 		  xmlNodePtr node_):
-  core(core_), path(path_), position(pos), doc(NULL),
-  node(node_), name_node(NULL),
+  core(core_), position(pos), doc(NULL), node(node_), name_node(NULL),
   presence("unknown"), status("")
 {
   groups.insert (group);
 
-  refresh ();
+  if (node != NULL) {
+
+    xmlChar* str = xmlGetProp (node, BAD_CAST "name");
+
+    if (str != NULL) {
+
+      path = path_->build_child_with_attribute ("entry", "name",
+						(const char*)str);
+      xmlFree (str);
+    } else {
+
+      path = path_->build_child_with_position ("entry", position);
+    }
+    parse ();
+  } else {
+
+    path = path_;
+  }
 }
 
 RL::Entry::~Entry ()
@@ -137,13 +153,8 @@
 void
 RL::Entry::refresh ()
 {
-  if (node != NULL)
-    parse ();
-  else {
-
-    /* FIXME: here we should fetch the document, then parse it
-     */
-  }
+  /* FIXME: here we should fetch the document, then parse it */
+  std::cout << "Refreshing on " << path << std::endl;
 }
 
 void

Modified: trunk/lib/engine/components/resource-list/rl-entry.h
==============================================================================
--- trunk/lib/engine/components/resource-list/rl-entry.h	(original)
+++ trunk/lib/engine/components/resource-list/rl-entry.h	Wed Oct 15 12:48:18 2008
@@ -38,10 +38,9 @@
 #ifndef __RL_ENTRY_H__
 #define __RL_ENTRY_H__
 
-#include "gmref.h"
-
 #include "services.h"
 #include "presentity.h"
+#include "xcap-path.h"
 
 #include <libxml/tree.h>
 
@@ -54,7 +53,7 @@
   public:
 
     Entry (Ekiga::ServiceCore& core_,
-	   const std::string path_,
+	   gmref_ptr<XCAP::Path> path_,
 	   int pos,
 	   const std::string group,
 	   xmlNodePtr node_);
@@ -94,7 +93,7 @@
   private:
     Ekiga::ServiceCore& core;
 
-    std::string path;
+    gmref_ptr<XCAP::Path> path;
     int position;
 
     std::set<std::string> groups;

Modified: trunk/lib/engine/components/resource-list/rl-heap.cpp
==============================================================================
--- trunk/lib/engine/components/resource-list/rl-heap.cpp	(original)
+++ trunk/lib/engine/components/resource-list/rl-heap.cpp	Wed Oct 15 12:48:18 2008
@@ -38,6 +38,7 @@
 #include "config.h"
 
 #include <glib.h>
+#include <iostream>
 
 #include "robust-xml.h"
 
@@ -45,31 +46,53 @@
 
 RL::Heap::Heap (Ekiga::ServiceCore& core_,
 		xmlNodePtr node_):
-  core(core_), node(node_), uri(NULL),
-  username(NULL), password(NULL), name(NULL), doc(NULL)
+  core(core_),
+  node(node_), name(NULL),
+  root(NULL), user(NULL),
+  username(NULL), password(NULL),
+  doc(NULL)
 {
   for (xmlNodePtr child = node->children; child != NULL; child = child->next) {
 
     if (child->type == XML_ELEMENT_NODE
 	&& child->name != NULL) {
 
-      if (xmlStrEqual (BAD_CAST ("uri"), child->name))
-	uri = child;
-      if (xmlStrEqual (BAD_CAST ("username"), child->name))
+      if (xmlStrEqual (BAD_CAST ("name"), child->name)) {
+
+	name = child;
+	continue;
+      }
+      if (xmlStrEqual (BAD_CAST ("root"), child->name)) {
+
+	root = child;
+	continue;
+      }
+      if (xmlStrEqual (BAD_CAST ("user"), child->name)) {
+
+	user = child;
+	continue;
+      }
+      if (xmlStrEqual (BAD_CAST ("username"), child->name)) {
+
 	username = child;
-      if (xmlStrEqual (BAD_CAST ("password"), child->name))
+	continue;
+      }
+      if (xmlStrEqual (BAD_CAST ("password"), child->name)) {
+
 	password = child;
-      if (xmlStrEqual (BAD_CAST ("name"), child->name))
-	name = child;
+	continue;
+      }
     }
   }
 
-  if (uri == NULL)
-    uri = xmlNewChild (node, NULL, BAD_CAST "uri", BAD_CAST "");
   if (name == NULL)
     name = xmlNewChild (node, NULL, BAD_CAST "name",
 			BAD_CAST robust_xmlEscape(node->doc,
 						  _("Unnamed")).c_str ());
+  if (root == NULL)
+    root = xmlNewChild (node, NULL, BAD_CAST "root", BAD_CAST "");
+  if (user == NULL)
+    user = xmlNewChild (node, NULL, BAD_CAST "user", BAD_CAST "");
   if (username == NULL)
     username = xmlNewChild (node, NULL, BAD_CAST "username", BAD_CAST "");
   if (password == NULL)
@@ -80,24 +103,17 @@
 
 RL::Heap::Heap (Ekiga::ServiceCore& core_,
 		const std::string name_,
-		const std::string uri_,
+		const std::string root_,
+		const std::string user_,
 		const std::string username_,
 		const std::string password_):
-  core(core_), node(NULL), uri(NULL), username(NULL), password(NULL), name(NULL)
+  core(core_),
+  node(NULL), name(NULL),
+  root(NULL), user(NULL),
+  username(NULL), password(NULL),
+  doc(NULL)
 {
   node = xmlNewNode (NULL, BAD_CAST "entry");
-  uri = xmlNewChild (node, NULL,
-		     BAD_CAST "uri",
-		     BAD_CAST robust_xmlEscape (node->doc,
-						uri_).c_str ());
-  username = xmlNewChild (node, NULL,
-			  BAD_CAST "username",
-			  BAD_CAST robust_xmlEscape (node->doc,
-						     username_).c_str ());
-  password = xmlNewChild (node, NULL,
-			  BAD_CAST "password",
-			  BAD_CAST robust_xmlEscape (node->doc,
-						     password_).c_str ());
   if ( !name_.empty ())
     name = xmlNewChild (node, NULL,
 			BAD_CAST "name",
@@ -108,6 +124,22 @@
 			BAD_CAST "name",
 			BAD_CAST robust_xmlEscape (node->doc,
 						   _("Unnamed")).c_str ());
+  root = xmlNewChild (node, NULL,
+		      BAD_CAST "root",
+		      BAD_CAST robust_xmlEscape (node->doc,
+						root_).c_str ());
+  user = xmlNewChild (node, NULL,
+		      BAD_CAST "user",
+		      BAD_CAST robust_xmlEscape (node->doc,
+						 user_).c_str ());
+  username = xmlNewChild (node, NULL,
+			  BAD_CAST "username",
+			  BAD_CAST robust_xmlEscape (node->doc,
+						     username_).c_str ());
+  password = xmlNewChild (node, NULL,
+			  BAD_CAST "password",
+			  BAD_CAST robust_xmlEscape (node->doc,
+						     password_).c_str ());
   refresh ();
 }
 
@@ -132,21 +164,6 @@
   return result;
 }
 
-const std::string
-RL::Heap::get_uri () const
-{
-  std::string result;
-  xmlChar* str = xmlNodeGetContent (uri);
-  if (str != NULL)
-    result = (const char*)str;
-  else
-    result = "";
-
-  xmlFree (str);
-
-  return result;
-}
-
 void
 RL::Heap::visit_presentities (sigc::slot<bool, Ekiga::Presentity&> visitor)
 {
@@ -182,6 +199,35 @@
 {
   XCAP::Core* xcap
     = dynamic_cast<XCAP::Core*>(core.get ("xcap-core"));
+  std::string root_str;
+  std::string username_str;
+  std::string password_str;
+  std::string user_str;
+
+  {
+    xmlChar* str = xmlNodeGetContent (root);
+    if (str != NULL)
+      root_str = (const char*)str;
+  }
+  {
+    xmlChar* str = xmlNodeGetContent (user);
+    if (str != NULL)
+      user_str = (const char*)str;
+  }
+  {
+    xmlChar* str = xmlNodeGetContent (username);
+    if (str != NULL)
+      username_str = (const char*)str;
+  }
+  {
+    xmlChar* str = xmlNodeGetContent (password);
+    if (str != NULL)
+      password_str = (const char*)str;
+  }
+  gmref_ptr<XCAP::Path> path(new XCAP::Path (root_str, "resource-lists",
+					     user_str));
+  path->set_credentials (username_str, password_str);
+  path = path->build_child ("resource-lists");
 
   for (std::list<gmref_ptr<List> >::iterator iter = lists.begin ();
        iter != lists.end ();
@@ -193,8 +239,7 @@
     xmlFreeDoc (doc);
   doc = NULL;
 
-  xcap->read (get_uri (),
-	      sigc::mem_fun (this, &RL::Heap::on_document_received));
+  xcap->read (path, sigc::mem_fun (this, &RL::Heap::on_document_received));
 }
 
 void
@@ -209,6 +254,7 @@
     break;
   case XCAP::Core::ERROR:
 
+    std::cout << "XCAP error: " << value << std::endl;
     // FIXME: do something
     break;
   default:
@@ -222,9 +268,9 @@
 {
   doc = xmlRecoverMemory (raw.c_str (), raw.length ());
 
-  xmlNodePtr root = xmlDocGetRootElement (doc);
+  xmlNodePtr doc_root = xmlDocGetRootElement (doc);
 
-  if (root == NULL) {
+  if (doc_root == NULL) {
 
     // FIXME: warn the user somehow?
     xmlFreeDoc (doc);
@@ -232,12 +278,43 @@
   } else {
 
     int pos = 1;
+    std::string root_str;
+    std::string user_str;
+    std::string username_str;
+    std::string password_str;
+
+    {
+      xmlChar* str = xmlNodeGetContent (root);
+      if (str != NULL)
+	root_str = (const char*)str;
+    }
+    {
+      xmlChar* str = xmlNodeGetContent (user);
+      if (str != NULL)
+	user_str = (const char*)str;
+    }
+    {
+      xmlChar* str = xmlNodeGetContent (username);
+      if (str != NULL)
+	username_str = (const char*)str;
+    }
+    {
+      xmlChar* str = xmlNodeGetContent (password);
+      if (str != NULL)
+	password_str = (const char*)str;
+    }
+
+    gmref_ptr<XCAP::Path> path(new XCAP::Path (root_str, "resource-lists",
+					       user_str));
+    path->set_credentials (username_str, password_str);
+    path = path->build_child ("resource-lists");
+
     for (xmlNodePtr child = root->children; child != NULL; child = child->next)
       if (child->type == XML_ELEMENT_NODE
 	  && child->name != NULL
 	  && xmlStrEqual (BAD_CAST ("list"), child->name)) {
 
-	gmref_ptr<List> list(new List (core, get_uri (), pos, "", child));
+	gmref_ptr<List> list(new List (core, path, pos, "", child));
 	list->entry_added.connect (sigc::mem_fun (this, &RL::Heap::on_entry_added));
 	list->entry_updated.connect (sigc::mem_fun (this, &RL::Heap::on_entry_updated));
 	list->entry_removed.connect (sigc::mem_fun (this, &RL::Heap::on_entry_removed));

Modified: trunk/lib/engine/components/resource-list/rl-heap.h
==============================================================================
--- trunk/lib/engine/components/resource-list/rl-heap.h	(original)
+++ trunk/lib/engine/components/resource-list/rl-heap.h	Wed Oct 15 12:48:18 2008
@@ -41,7 +41,7 @@
 #include "gmref.h"
 
 #include "heap.h"
-#include "xcap.h"
+#include "xcap-core.h"
 
 #include <libxml/tree.h>
 
@@ -56,9 +56,19 @@
     Heap (Ekiga::ServiceCore& core_,
 	  xmlNodePtr node);
 
+    /* name: the name of the Heap in the GUI
+     * root: the XCAP root address
+     * user: the user as XCAP user
+     * username: the username on the HTTP server
+     * password: the password on the HTTP server
+     *
+     * Don't complain to me(Snark) it's complex : read RFC4825 and cry with me
+     *
+     */
     Heap (Ekiga::ServiceCore& core_,
 	  const std::string name_,
-	  const std::string uri_,
+	  const std::string root_,
+	  const std::string user_,
 	  const std::string username_,
 	  const std::string password_);
 
@@ -88,17 +98,16 @@
     Ekiga::ServiceCore& core;
 
     xmlNodePtr node;
-    xmlNodePtr uri;
+    xmlNodePtr name;
+    xmlNodePtr root;
+    xmlNodePtr user;
     xmlNodePtr username;
     xmlNodePtr password;
-    xmlNodePtr name;
 
     xmlDocPtr doc;
 
     std::list<gmref_ptr<List> > lists;
 
-    const std::string get_uri () const;
-
     void refresh ();
 
     void on_document_received (XCAP::Core::ResultType result,

Modified: trunk/lib/engine/components/resource-list/rl-list.cpp
==============================================================================
--- trunk/lib/engine/components/resource-list/rl-list.cpp	(original)
+++ trunk/lib/engine/components/resource-list/rl-list.cpp	Wed Oct 15 12:48:18 2008
@@ -47,7 +47,7 @@
 public: // no need to make anything private
 
   ListImpl (Ekiga::ServiceCore& core_,
-	    const std::string path_,
+	    gmref_ptr<XCAP::Path> path_,
 	    int pos,
 	    const std::string group_,
 	    xmlNodePtr node_);
@@ -78,7 +78,7 @@
 
   Ekiga::ServiceCore& core;
 
-  std::string path;
+  gmref_ptr<XCAP::Path> path;
   int position;
 
   std::string group;
@@ -110,7 +110,7 @@
 /* implementation of the List class */
 
 RL::List::List (Ekiga::ServiceCore& core_,
-		const std::string path_,
+		gmref_ptr<XCAP::Path> path_,
 		int pos,
 		const std::string group_,
 		xmlNodePtr node_)
@@ -119,6 +119,7 @@
   impl->entry_added.connect (entry_added.make_slot ());
   impl->entry_updated.connect (entry_updated.make_slot ());
   impl->entry_removed.connect (entry_removed.make_slot ());
+  impl->parse ();
 }
 
 RL::List::~List ()
@@ -173,11 +174,11 @@
 /* implementation of the ListImpl class */
 
 RL::ListImpl::ListImpl (Ekiga::ServiceCore& core_,
-			const std::string path_,
+			gmref_ptr<XCAP::Path> path_,
 			int pos,
 			const std::string group_,
 			xmlNodePtr node_):
-  core(core_), path(path_), position(pos), group(group_), doc(NULL), node(node_)
+  core(core_), position(pos), group(group_), doc(NULL), node(node_)
 {
   {
     gchar* raw = NULL;
@@ -195,9 +196,26 @@
 
   }
 
-  display_name = position_name; // refresh will set better
+  display_name = position_name; // will be set to better when we get the data
 
-  refresh ();
+  if (node != NULL) {
+
+    xmlChar* str = xmlGetProp (node, BAD_CAST "name");
+
+    if (str != NULL) {
+
+      path = path_->build_child_with_attribute ("list", "name",
+						(const char*)str);
+      xmlFree (str);
+    } else {
+
+      path = path_->build_child_with_position ("list", position);
+    }
+    parse ();
+  } else {
+
+    path = path_;
+  }
 }
 
 RL::ListImpl::~ListImpl ()
@@ -285,21 +303,15 @@
 {
   flush ();
 
-  if (node)
-    parse ();
-  else {
-
-    /* FIXME:
-     * - fetch the document
-     * - call parse
-     */
-  }
+  /* FIXME:
+   * - fetch the document
+   * - call parse
+   */
 }
 
 void
 RL::ListImpl::parse ()
 {
-  std::string my_path = compute_path ();
   int list_pos = 1;
   int entry_pos = 1;
 
@@ -327,7 +339,7 @@
 	&& child->name != NULL
 	&& xmlStrEqual (BAD_CAST "list", child->name)) {
 
-      gmref_ptr<List> list = new List (core, my_path,
+      gmref_ptr<List> list = new List (core, path,
 				       list_pos, display_name, child);
       list->entry_added.connect (entry_added.make_slot ());
       lists.push_back (list);
@@ -340,7 +352,7 @@
 	&& child->name != NULL
 	&& xmlStrEqual (BAD_CAST "entry", child->name)) {
 
-      gmref_ptr<Entry> entry = new Entry (core, my_path,
+      gmref_ptr<Entry> entry = new Entry (core, path,
 					  entry_pos, display_name, child);
       std::list<sigc::connection> conns;
       conns.push_back (entry->updated.connect (sigc::bind (entry_updated.make_slot (), entry)));
@@ -353,30 +365,6 @@
   }
 }
 
-std::string
-RL::ListImpl::compute_path () const
-{
-  std::string result;
-  gchar* raw = NULL;
-  xmlChar* str = xmlGetProp (node, BAD_CAST "name");
-
-  if (str != NULL) {
-
-    raw = g_strdup_printf ("%s/list[ name=\"%s\"]",
-			   path.c_str (), str);
-    xmlFree (str);
-  } else {
-
-    raw = g_strdup_printf ("%s/list[%d]", path.c_str (), position);
-  }
-
-  result = raw;
-
-  g_free (raw);
-
-  return result;
-}
-
 void
 RL::ListImpl::push_presence (const std::string uri_,
 			     const std::string presence)

Modified: trunk/lib/engine/components/resource-list/rl-list.h
==============================================================================
--- trunk/lib/engine/components/resource-list/rl-list.h	(original)
+++ trunk/lib/engine/components/resource-list/rl-list.h	Wed Oct 15 12:48:18 2008
@@ -39,12 +39,6 @@
 #ifndef __RL_LIST_H__
 #define __RL_LIST_H__
 
-#include "gmref.h"
-
-#include "services.h"
-
-#include <libxml/tree.h>
-
 #include "rl-entry.h"
 
 namespace RL
@@ -56,7 +50,7 @@
   public:
 
     List (Ekiga::ServiceCore& core_,
-	  const std::string path_,
+	  gmref_ptr<XCAP::Path> path_,
 	  int pos,
 	  const std::string group_,
 	  xmlNodePtr node_);



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