[phodav: 10/18] wip: move mkcol



commit 1d405cf7c37fea7b8cb5e70ced7f4c9b882e6a83
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Thu Apr 10 18:55:26 2014 +0200

    wip: move mkcol

 Makefile.am                     |    1 +
 libphodav/phodav-method-mkcol.c |   72 +++++++++++++++++++++++++++++++++++++++
 libphodav/phodav-priv.h         |    2 +
 libphodav/phodav-server.c       |   55 +-----------------------------
 4 files changed, 76 insertions(+), 54 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ae64b53..07fd6ad 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,6 +35,7 @@ libphodav_1_0_la_SOURCES =                    \
        libphodav/phodav-lock.h                 \
        libphodav/phodav-if.c                   \
        libphodav/phodav-method-get.c           \
+       libphodav/phodav-method-mkcol.c \
        libphodav/phodav-method-propfind.c      \
        libphodav/phodav-method-proppatch.c     \
        libphodav/phodav-multistatus.c          \
diff --git a/libphodav/phodav-method-mkcol.c b/libphodav/phodav-method-mkcol.c
new file mode 100644
index 0000000..b1bef4b
--- /dev/null
+++ b/libphodav/phodav-method-mkcol.c
@@ -0,0 +1,72 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "phodav-priv.h"
+
+static gint
+do_mkcol_file (SoupMessage *msg, GFile *file,
+               GCancellable *cancellable, GError **err)
+{
+  GError *error = NULL;
+  gint status = SOUP_STATUS_CREATED;
+
+  if (!g_file_make_directory (file, cancellable, &error))
+    {
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+        status = SOUP_STATUS_CONFLICT;
+      else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+        status = SOUP_STATUS_METHOD_NOT_ALLOWED;
+      else
+        {
+          status = SOUP_STATUS_FORBIDDEN;
+          g_propagate_error (err, error);
+          error = NULL;
+        }
+
+      g_clear_error (&error);
+    }
+
+  return status;
+}
+
+gint
+phodav_method_mkcol (PathHandler *handler, SoupMessage *msg,
+                     const char *path, GError **err)
+{
+  GFile *file = NULL;
+  GCancellable *cancellable = handler_get_cancellable (handler);
+  gint status;
+  GList *submitted = NULL;
+
+  if (msg->request_body && msg->request_body->length)
+    {
+      status = SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE;
+      goto end;
+    }
+
+  status = phodav_check_if (handler, msg, path, &submitted);
+  if (status != SOUP_STATUS_OK)
+    goto end;
+
+  file = g_file_get_child (handler_get_file (handler), path + 1);
+  status = do_mkcol_file (msg, file, cancellable, err);
+
+end:
+  g_clear_object (&file);
+  return status;
+}
diff --git a/libphodav/phodav-priv.h b/libphodav/phodav-priv.h
index 8a5ea0c..11e3a40 100644
--- a/libphodav/phodav-priv.h
+++ b/libphodav/phodav-priv.h
@@ -105,6 +105,8 @@ gint                    phodav_method_propfind               (PathHandler *handl
                                                               const char *path, GError **err);
 gint                    phodav_method_proppatch              (PathHandler *handler, SoupMessage *msg,
                                                               const char *path, GError **err);
+gint                    phodav_method_mkcol                  (PathHandler *handler, SoupMessage *msg,
+                                                              const char *path, GError **err);
 
 
 G_END_DECLS
diff --git a/libphodav/phodav-server.c b/libphodav/phodav-server.c
index 69b29e5..1fc19ed 100644
--- a/libphodav/phodav-server.c
+++ b/libphodav/phodav-server.c
@@ -462,59 +462,6 @@ server_path_has_other_locks (PhodavServer *self, const gchar *path, GList *locks
 }
 
 static gint
-do_mkcol_file (SoupMessage *msg, GFile *file,
-               GCancellable *cancellable, GError **err)
-{
-  GError *error = NULL;
-  gint status = SOUP_STATUS_CREATED;
-
-  if (!g_file_make_directory (file, cancellable, &error))
-    {
-      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
-        status = SOUP_STATUS_CONFLICT;
-      else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
-        status = SOUP_STATUS_METHOD_NOT_ALLOWED;
-      else
-        {
-          status = SOUP_STATUS_FORBIDDEN;
-          g_propagate_error (err, error);
-          error = NULL;
-        }
-
-      g_clear_error (&error);
-    }
-
-  return status;
-}
-
-static gint
-method_mkcol (PathHandler *handler, SoupMessage *msg,
-              const char *path, GError **err)
-{
-  GFile *file = NULL;
-  PhodavServer *self = handler->self;
-  gint status;
-  GList *submitted = NULL;
-
-  if (msg->request_body && msg->request_body->length)
-    {
-      status = SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE;
-      goto end;
-    }
-
-  status = phodav_check_if (handler, msg, path, &submitted);
-  if (status != SOUP_STATUS_OK)
-    goto end;
-
-  file = g_file_get_child (handler->file, path + 1);
-  status = do_mkcol_file (msg, file, self->cancellable, err);
-
-end:
-  g_clear_object (&file);
-  return status;
-}
-
-static gint
 error_to_status (GError *err)
 {
   if (g_error_matches (err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
@@ -1153,7 +1100,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
   else if (msg->method == SOUP_METHOD_PROPPATCH)
     status = phodav_method_proppatch (handler, msg, path, &err);
   else if (msg->method == SOUP_METHOD_MKCOL)
-    status = method_mkcol (handler, msg, path, &err);
+    status = phodav_method_mkcol (handler, msg, path, &err);
   else if (msg->method == SOUP_METHOD_DELETE)
     status = method_delete (handler, msg, path, &err);
   else if (msg->method == SOUP_METHOD_MOVE ||


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