[phodav: 14/18] wip: move method unlock



commit ff760ae4c229f5bcf2a9dbe5433103491076c077
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Thu Apr 10 19:25:22 2014 +0200

    wip: move method unlock

 Makefile.am                      |    1 +
 libphodav/phodav-method-unlock.c |   57 ++++++++++++++++++++++++++++++++++++++
 libphodav/phodav-priv.h          |    3 +-
 libphodav/phodav-server.c        |   40 +--------------------------
 4 files changed, 61 insertions(+), 40 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 51c61b3..a8e1bf0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,6 +41,7 @@ libphodav_1_0_la_SOURCES =                    \
        libphodav/phodav-method-movecopy.c      \
        libphodav/phodav-method-propfind.c      \
        libphodav/phodav-method-proppatch.c     \
+       libphodav/phodav-method-unlock.c        \
        libphodav/phodav-multistatus.c          \
        libphodav/phodav-multistatus.h          \
        libphodav/phodav-server.c               \
diff --git a/libphodav/phodav-method-unlock.c b/libphodav/phodav-method-unlock.c
new file mode 100644
index 0000000..17a7c97
--- /dev/null
+++ b/libphodav/phodav-method-unlock.c
@@ -0,0 +1,57 @@
+/* -*- 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"
+#include "phodav-lock.h"
+
+static gchar *
+remove_brackets (const gchar *str)
+{
+  if (!str)
+    return NULL;
+
+  gint len = strlen (str);
+
+  if (str[0] != '<' || str[len - 1] != '>')
+    return NULL;
+
+  return g_strndup (str + 1, len - 2);
+}
+
+gint
+phodav_method_unlock (PathHandler *handler, SoupMessage *msg,
+                      const char *path, GError **err)
+{
+  DAVLock *lock;
+  gint status = SOUP_STATUS_BAD_REQUEST;
+
+  gchar *token = remove_brackets (
+                                  soup_message_headers_get_one (msg->request_headers, "Lock-Token"));
+
+  g_return_val_if_fail (token != NULL, SOUP_STATUS_BAD_REQUEST);
+
+  lock = server_path_get_lock (handler_get_server (handler), path, token);
+  if (!lock)
+    return SOUP_STATUS_CONFLICT;
+
+  dav_lock_free (lock);
+  status = SOUP_STATUS_NO_CONTENT;
+
+  g_free (token);
+  return status;
+}
diff --git a/libphodav/phodav-priv.h b/libphodav/phodav-priv.h
index c960476..74ee8c9 100644
--- a/libphodav/phodav-priv.h
+++ b/libphodav/phodav-priv.h
@@ -119,7 +119,8 @@ gint                    phodav_method_movecopy               (PathHandler *handl
                                                               const char *path, GError **err);
 gint                    phodav_method_lock                   (PathHandler *handler, SoupMessage *msg,
                                                               const char *path, GError **err);
-
+gint                    phodav_method_unlock                 (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 74bdab4..bf18801 100644
--- a/libphodav/phodav-server.c
+++ b/libphodav/phodav-server.c
@@ -423,44 +423,6 @@ server_path_has_other_locks (PhodavServer *self, const gchar *path, GList *locks
   return !server_foreach_parent_path (self, path, other_lock_exists, locks);
 }
 
-static gchar *
-remove_brackets (const gchar *str)
-{
-  if (!str)
-    return NULL;
-
-  gint len = strlen (str);
-
-  if (str[0] != '<' || str[len - 1] != '>')
-    return NULL;
-
-  return g_strndup (str + 1, len - 2);
-}
-
-static gint
-method_unlock (PathHandler *handler, SoupMessage *msg,
-               const char *path, GError **err)
-{
-  PhodavServer *self = handler->self;
-  DAVLock *lock;
-  gint status = SOUP_STATUS_BAD_REQUEST;
-
-  gchar *token = remove_brackets (
-    soup_message_headers_get_one (msg->request_headers, "Lock-Token"));
-
-  g_return_val_if_fail (token != NULL, SOUP_STATUS_BAD_REQUEST);
-
-  lock = server_path_get_lock (self, path, token);
-  if (!lock)
-    return SOUP_STATUS_CONFLICT;
-
-  dav_lock_free (lock);
-  status = SOUP_STATUS_NO_CONTENT;
-
-  g_free (token);
-  return status;
-}
-
 static void
 method_put_finished (SoupMessage *msg,
                      SoupBuffer  *chunk,
@@ -618,7 +580,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
   else if (msg->method == SOUP_METHOD_LOCK)
     status = phodav_method_lock (handler, msg, path, &err);
   else if (msg->method == SOUP_METHOD_UNLOCK)
-    status = method_unlock (handler, msg, path, &err);
+    status = phodav_method_unlock (handler, msg, path, &err);
   else
     g_warn_if_reached ();
 


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