[phodav: 3/18] wip: move davdoc to utils



commit 1691888b7fdef2162fd20ac1ba27ade8d9a903b1
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Thu Apr 10 16:41:56 2014 +0200

    wip: move davdoc to utils

 libphodav/phodav-server.c |   99 +--------------------------------------------
 libphodav/phodav-utils.c  |   78 +++++++++++++++++++++++++++++++++++
 libphodav/phodav-utils.h  |   18 ++++++++
 3 files changed, 97 insertions(+), 98 deletions(-)
---
diff --git a/libphodav/phodav-server.c b/libphodav/phodav-server.c
index fc6dc84..0185f88 100644
--- a/libphodav/phodav-server.c
+++ b/libphodav/phodav-server.c
@@ -28,6 +28,7 @@
 #include "phodav-multistatus.h"
 #include "phodav-path.h"
 #include "phodav-lock.h"
+#include "phodav-utils.h"
 
 /**
  * SECTION:phodav-server
@@ -397,55 +398,6 @@ locktype_to_string (LockType type)
   g_return_val_if_reached (NULL);
 }
 
-static xmlDocPtr
-parse_xml (const gchar  *data,
-           const goffset len,
-           xmlNodePtr   *root,
-           const char   *name)
-{
-  xmlDocPtr doc;
-
-  doc = xmlReadMemory (data, len,
-                       "request.xml",
-                       NULL,
-                       XML_PARSE_NONET |
-                       XML_PARSE_NOWARNING |
-                       XML_PARSE_NOBLANKS |
-                       XML_PARSE_NSCLEAN |
-                       XML_PARSE_NOCDATA |
-                       XML_PARSE_COMPACT);
-  if (doc == NULL)
-    {
-      g_debug ("Could not parse request");
-      return NULL;
-    }
-  if (!(doc->properties & XML_DOC_NSVALID))
-    {
-      g_debug ("Could not parse request, NS errors");
-      xmlFreeDoc (doc);
-      return NULL;
-    }
-
-  *root = xmlDocGetRootElement (doc);
-
-  if (*root == NULL || (*root)->children == NULL)
-    {
-      g_debug ("Empty request");
-      xmlFreeDoc (doc);
-      return NULL;
-    }
-
-  if (g_strcmp0 ((char *) (*root)->name, name))
-    {
-      g_debug ("Unexpected request");
-      xmlFreeDoc (doc);
-      return NULL;
-    }
-
-  return doc;
-}
-
-
 static int
 compare_strings (gconstpointer a, gconstpointer b)
 {
@@ -604,55 +556,6 @@ end:
   return status;
 }
 
-typedef struct _DavDoc     DavDoc;
-typedef struct _DDPropfind DDPropfind;
-
-struct _DavDoc
-{
-  xmlDocPtr  doc;
-  xmlNodePtr root;
-
-  SoupURI   *target;
-  char      *path;
-};
-
-struct _DDPropfind
-{
-  DavDoc    *dd;
-
-  xmlNodePtr prop_node;
-};
-
-static gboolean
-davdoc_parse (DavDoc *dd, SoupMessage *msg, SoupMessageBody *body,
-              const gchar *name)
-{
-  xmlDocPtr doc;
-  xmlNodePtr root;
-  SoupURI *uri;
-
-  doc = parse_xml (body->data, body->length, &root, name);
-  if (!doc)
-    return FALSE;
-
-  uri = soup_message_get_uri (msg);
-
-  dd->doc = doc;
-  dd->root = root;
-  dd->target = uri;
-  dd->path = g_uri_unescape_string (uri->path, "/");
-
-  return TRUE;
-}
-
-static void
-davdoc_free (DavDoc *dd)
-{
-  if (dd->doc)
-    xmlFreeDoc (dd->doc);
-  g_free (dd->path);
-}
-
 typedef enum _PropFindType {
   PROPFIND_ALLPROP,
   PROPFIND_PROPNAME,
diff --git a/libphodav/phodav-utils.c b/libphodav/phodav-utils.c
index afab913..a91e3f3 100644
--- a/libphodav/phodav-utils.c
+++ b/libphodav/phodav-utils.c
@@ -31,3 +31,81 @@ xml_node_to_string (xmlNodePtr root, xmlChar **mem, int *size)
   /*FIXME, pretty print?*/
   xmlFreeDoc (doc);
 }
+
+static xmlDocPtr
+parse_xml (const gchar  *data,
+           const goffset len,
+           xmlNodePtr   *root,
+           const char   *name)
+{
+  xmlDocPtr doc;
+
+  doc = xmlReadMemory (data, len,
+                       "request.xml",
+                       NULL,
+                       XML_PARSE_NONET |
+                       XML_PARSE_NOWARNING |
+                       XML_PARSE_NOBLANKS |
+                       XML_PARSE_NSCLEAN |
+                       XML_PARSE_NOCDATA |
+                       XML_PARSE_COMPACT);
+  if (doc == NULL)
+    {
+      g_debug ("Could not parse request");
+      return NULL;
+    }
+  if (!(doc->properties & XML_DOC_NSVALID))
+    {
+      g_debug ("Could not parse request, NS errors");
+      xmlFreeDoc (doc);
+      return NULL;
+    }
+
+  *root = xmlDocGetRootElement (doc);
+
+  if (*root == NULL || (*root)->children == NULL)
+    {
+      g_debug ("Empty request");
+      xmlFreeDoc (doc);
+      return NULL;
+    }
+
+  if (g_strcmp0 ((char *) (*root)->name, name))
+    {
+      g_debug ("Unexpected request");
+      xmlFreeDoc (doc);
+      return NULL;
+    }
+
+  return doc;
+}
+
+gboolean
+davdoc_parse (DavDoc *dd, SoupMessage *msg, SoupMessageBody *body,
+              const gchar *name)
+{
+  xmlDocPtr doc;
+  xmlNodePtr root;
+  SoupURI *uri;
+
+  doc = parse_xml (body->data, body->length, &root, name);
+  if (!doc)
+    return FALSE;
+
+  uri = soup_message_get_uri (msg);
+
+  dd->doc = doc;
+  dd->root = root;
+  dd->target = uri;
+  dd->path = g_uri_unescape_string (uri->path, "/");
+
+  return TRUE;
+}
+
+void
+davdoc_free (DavDoc *dd)
+{
+  if (dd->doc)
+    xmlFreeDoc (dd->doc);
+  g_free (dd->path);
+}
diff --git a/libphodav/phodav-utils.h b/libphodav/phodav-utils.h
index f9c7c5d..d13d476 100644
--- a/libphodav/phodav-utils.h
+++ b/libphodav/phodav-utils.h
@@ -18,12 +18,30 @@
 #ifndef __PHODAV_UTILS_H__
 #define __PHODAV_UTILS_H__
 
+#include <libsoup/soup.h>
 #include "phodav-priv.h"
 
 G_BEGIN_DECLS
 
 void             xml_node_to_string              (xmlNodePtr root, xmlChar **mem, int *size);
 
+
+typedef struct _DavDoc     DavDoc;
+
+struct _DavDoc
+{
+  xmlDocPtr  doc;
+  xmlNodePtr root;
+
+  SoupURI   *target;
+  char      *path;
+};
+
+gboolean         davdoc_parse                    (DavDoc *dd, SoupMessage *msg,
+                                                  SoupMessageBody *body,
+                                                  const gchar *name);
+void             davdoc_free                     (DavDoc *dd);
+
 G_END_DECLS
 
 #endif /* __PHODAV_UTILS_H__ */


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