[phodav: 6/18] wip: move more of get method



commit d380a4cdf3f9b6a1d911d1967f2ab867e397f74f
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Thu Apr 10 17:23:45 2014 +0200

    wip: move more of get method

 libphodav/phodav-method-get.c |   20 +++++++++++++++++---
 libphodav/phodav-method-get.h |    5 +++--
 libphodav/phodav-priv.h       |   11 ++++++++---
 libphodav/phodav-server.c     |   30 +++++++++++++-----------------
 4 files changed, 41 insertions(+), 25 deletions(-)
---
diff --git a/libphodav/phodav-method-get.c b/libphodav/phodav-method-get.c
index 604b0df..4582d0c 100644
--- a/libphodav/phodav-method-get.c
+++ b/libphodav/phodav-method-get.c
@@ -82,9 +82,9 @@ get_directory_listing (GFile *file, GCancellable *cancellable, GError **err)
   return listing;
 }
 
-gint
-phodav_method_get (SoupMessage *msg, GFile *file,
-                   GCancellable *cancellable, GError **err)
+static gint
+method_get (SoupMessage *msg, GFile *file,
+            GCancellable *cancellable, GError **err)
 {
   GError *error = NULL;
   gint status = SOUP_STATUS_NOT_FOUND;
@@ -175,3 +175,17 @@ end:
   g_clear_object (&info);
   return status;
 }
+
+gint
+phodav_method_get (PathHandler *handler, SoupMessage *msg, const char *path, GError **err)
+{
+  GFile *file;
+  GCancellable *cancellable = handler_get_cancellable (handler);
+  gint status;
+
+  file = g_file_get_child (handler_get_file (handler), path + 1);
+  status = method_get (msg, file, cancellable, err);
+  g_object_unref (file);
+
+  return status;
+}
diff --git a/libphodav/phodav-method-get.h b/libphodav/phodav-method-get.h
index 95f59fb..1c198ff 100644
--- a/libphodav/phodav-method-get.h
+++ b/libphodav/phodav-method-get.h
@@ -23,8 +23,9 @@
 
 G_BEGIN_DECLS
 
-gint                  phodav_method_get         (SoupMessage *msg, GFile *file,
-                                                 GCancellable *cancellable, GError **err);
+gint                  phodav_method_get         (PathHandler *handler, SoupMessage *msg,
+                                                 const char *path, GError **err);
+
 G_END_DECLS
 
 #endif /* __PHODAV_METHOD_GET_H__ */
diff --git a/libphodav/phodav-priv.h b/libphodav/phodav-priv.h
index 1a4adbf..aa7d598 100644
--- a/libphodav/phodav-priv.h
+++ b/libphodav/phodav-priv.h
@@ -22,6 +22,7 @@
 
 #include <glib/gi18n.h>
 #include <glib-object.h>
+#include <gio/gio.h>
 
 #include <libxml/parser.h>
 #include <libxml/tree.h>
@@ -32,6 +33,7 @@ G_BEGIN_DECLS
 
 typedef struct _DAVLock DAVLock;
 typedef struct _Path    Path;
+typedef struct _PathHandler PathHandler;
 
 typedef enum _LockScopeType {
   LOCK_SCOPE_NONE,
@@ -63,11 +65,14 @@ struct _DAVLock
 
 struct _Path
 {
-  gchar  *path;
-  GList  *locks;
-  guint32 refs;
+  gchar         *path;
+  GList         *locks;
+  guint32        refs;
 };
 
+GFile *                 handler_get_file                     (PathHandler *handler);
+GCancellable *          handler_get_cancellable              (PathHandler *handler);
+
 G_END_DECLS
 
 #endif /* __PHODAV_PRIV_H__ */
diff --git a/libphodav/phodav-server.c b/libphodav/phodav-server.c
index a8a91eb..83c665b 100644
--- a/libphodav/phodav-server.c
+++ b/libphodav/phodav-server.c
@@ -42,8 +42,6 @@
  * PhodavServer implements a simple WebDAV server.
  */
 
-typedef struct _PathHandler PathHandler;
-
 struct _PhodavServer
 {
   GObject       parent;
@@ -120,6 +118,18 @@ struct _PathHandler
   GFile       *file;
 };
 
+GFile * G_GNUC_PURE
+handler_get_file (PathHandler *handler)
+{
+  return handler->file;
+}
+
+GCancellable * G_GNUC_PURE
+handler_get_cancellable (PathHandler *handler)
+{
+  return handler->self->cancellable;
+}
+
 static PathHandler*
 path_handler_new (PhodavServer *self, GFile *file)
 {
@@ -1358,20 +1368,6 @@ prop_set (PhodavServer *self, SoupMessage *msg,
 }
 
 static gint
-method_get (PathHandler *handler, SoupMessage *msg, const char *path, GError **err)
-{
-  GFile *file;
-  PhodavServer *self = handler->self;
-  gint status;
-
-  file = g_file_get_child (handler->file, path + 1);
-  status = phodav_method_get (msg, file, self->cancellable, err);
-  g_object_unref (file);
-
-  return status;
-}
-
-static gint
 put_start (SoupMessage *msg, GFile *file,
            GFileOutputStream **output, GCancellable *cancellable,
            GError **err)
@@ -2503,7 +2499,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
     }
   else if (msg->method == SOUP_METHOD_GET ||
            msg->method == SOUP_METHOD_HEAD)
-    status = method_get (handler, msg, path, &err);
+    status = phodav_method_get (handler, msg, path, &err);
   else if (msg->method == SOUP_METHOD_PROPFIND)
     status = method_propfind (handler, msg, path, &err);
   else if (msg->method == SOUP_METHOD_PROPPATCH)


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