[phodav: 15/18] wip: move method put
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [phodav: 15/18] wip: move method put
- Date: Thu, 10 Apr 2014 17:52:20 +0000 (UTC)
commit f0b8ebb8587613649d495a9d7251e5aed7dc890d
Author: Marc-André Lureau <marcandre lureau gmail com>
Date: Thu Apr 10 19:37:48 2014 +0200
wip: move method put
Makefile.am | 1 +
libphodav/phodav-method-propfind.c | 1 +
libphodav/phodav-method-put.c | 119 ++++++++++++++++++++++++++++++++++++
libphodav/phodav-priv.h | 2 +
libphodav/phodav-server.c | 103 +------------------------------
5 files changed, 125 insertions(+), 101 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index a8e1bf0..e9ce4a7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,6 +42,7 @@ libphodav_1_0_la_SOURCES = \
libphodav/phodav-method-propfind.c \
libphodav/phodav-method-proppatch.c \
libphodav/phodav-method-unlock.c \
+ libphodav/phodav-method-put.c \
libphodav/phodav-multistatus.c \
libphodav/phodav-multistatus.h \
libphodav/phodav-server.c \
diff --git a/libphodav/phodav-method-propfind.c b/libphodav/phodav-method-propfind.c
index 50243bf..3041a21 100644
--- a/libphodav/phodav-method-propfind.c
+++ b/libphodav/phodav-method-propfind.c
@@ -16,6 +16,7 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
+#include "phodav-priv.h"
#include "phodav-utils.h"
#include "phodav-multistatus.h"
#include "phodav-lock.h"
diff --git a/libphodav/phodav-method-put.c b/libphodav/phodav-method-put.c
new file mode 100644
index 0000000..02bb68b
--- /dev/null
+++ b/libphodav/phodav-method-put.c
@@ -0,0 +1,119 @@
+/* -*- 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-utils.h"
+
+static void
+method_put_finished (SoupMessage *msg,
+ SoupBuffer *chunk,
+ gpointer user_data)
+{
+ GFileOutputStream *output = user_data;
+
+ g_debug ("PUT finished");
+
+ g_object_unref (output);
+}
+
+static void
+method_put_got_chunk (SoupMessage *msg,
+ SoupBuffer *chunk,
+ gpointer user_data)
+{
+ GFileOutputStream *output = user_data;
+ PathHandler *handler = g_object_get_data (user_data, "handler");
+ GCancellable *cancellable = handler_get_cancellable (handler);
+ GError *err = NULL;
+ gsize bytes_written;
+
+ g_debug ("PUT got chunk");
+
+ if (!g_output_stream_write_all (G_OUTPUT_STREAM (output),
+ chunk->data, chunk->length,
+ &bytes_written, cancellable, &err))
+ goto end;
+
+end:
+ if (err)
+ {
+ g_warning ("error: %s", err->message);
+ g_clear_error (&err);
+ soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
+ }
+}
+
+static gint
+put_start (SoupMessage *msg, GFile *file,
+ GFileOutputStream **output, GCancellable *cancellable,
+ GError **err)
+{
+ GFileOutputStream *s = NULL;
+ gchar *etag = NULL;
+ gboolean created = TRUE;
+ SoupMessageHeaders *headers = msg->request_headers;
+ gint status = SOUP_STATUS_INTERNAL_SERVER_ERROR;
+
+ if (g_file_query_exists (file, cancellable))
+ created = FALSE;
+
+ if (soup_message_headers_get_list (headers, "If-Match"))
+ g_warn_if_reached ();
+ else if (soup_message_headers_get_list (headers, "If-None-Match"))
+ g_warn_if_reached ();
+ else if (soup_message_headers_get_list (headers, "Expect"))
+ g_warn_if_reached ();
+
+ s = g_file_replace (file, etag, FALSE, G_FILE_CREATE_PRIVATE, cancellable, err);
+ if (!s)
+ goto end;
+
+ status = created ? SOUP_STATUS_CREATED : SOUP_STATUS_OK;
+
+end:
+ *output = s;
+ return status;
+}
+
+void
+phodav_method_put (PathHandler *handler, SoupMessage *msg, const gchar *path, GError **err)
+{
+ GCancellable *cancellable = handler_get_cancellable (handler);
+ GFile *file = NULL;
+ GList *submitted = NULL;
+ GFileOutputStream *output = NULL;
+ gint status;
+
+ 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 = put_start (msg, file, &output, cancellable, err);
+ if (*err)
+ goto end;
+
+ soup_message_body_set_accumulate (msg->request_body, FALSE);
+ g_object_set_data (G_OBJECT (output), "handler", handler);
+ g_signal_connect (msg, "got-chunk", G_CALLBACK (method_put_got_chunk), output);
+ g_signal_connect (msg, "finished", G_CALLBACK (method_put_finished), output);
+
+end:
+ soup_message_set_status (msg, status);
+ g_clear_object (&file);
+}
diff --git a/libphodav/phodav-priv.h b/libphodav/phodav-priv.h
index 74ee8c9..9a81110 100644
--- a/libphodav/phodav-priv.h
+++ b/libphodav/phodav-priv.h
@@ -121,6 +121,8 @@ gint phodav_method_lock (PathHandler *handl
const char *path, GError **err);
gint phodav_method_unlock (PathHandler *handler, SoupMessage *msg,
const char *path, GError **err);
+void phodav_method_put (PathHandler *handler, SoupMessage *msg,
+ const gchar *path, GError **err);
G_END_DECLS
diff --git a/libphodav/phodav-server.c b/libphodav/phodav-server.c
index bf18801..40737b7 100644
--- a/libphodav/phodav-server.c
+++ b/libphodav/phodav-server.c
@@ -119,7 +119,7 @@ handler_get_cancellable (PathHandler *handler)
return handler->self->cancellable;
}
-static PathHandler*
+static PathHandler *
path_handler_new (PhodavServer *self, GFile *file)
{
PathHandler *h = g_slice_new0 (PathHandler);
@@ -369,38 +369,6 @@ server_path_get_lock (PhodavServer *self, const gchar *path, const gchar *token)
return p.lock;
}
-static gint
-put_start (SoupMessage *msg, GFile *file,
- GFileOutputStream **output, GCancellable *cancellable,
- GError **err)
-{
- GFileOutputStream *s = NULL;
- gchar *etag = NULL;
- gboolean created = TRUE;
- SoupMessageHeaders *headers = msg->request_headers;
- gint status = SOUP_STATUS_INTERNAL_SERVER_ERROR;
-
- if (g_file_query_exists (file, cancellable))
- created = FALSE;
-
- if (soup_message_headers_get_list (headers, "If-Match"))
- g_warn_if_reached ();
- else if (soup_message_headers_get_list (headers, "If-None-Match"))
- g_warn_if_reached ();
- else if (soup_message_headers_get_list (headers, "Expect"))
- g_warn_if_reached ();
-
- s = g_file_replace (file, etag, FALSE, G_FILE_CREATE_PRIVATE, cancellable, err);
- if (!s)
- goto end;
-
- status = created ? SOUP_STATUS_CREATED : SOUP_STATUS_OK;
-
-end:
- *output = s;
- return status;
-}
-
static gboolean
other_lock_exists (const gchar *key, Path *path, gpointer data)
{
@@ -424,73 +392,6 @@ server_path_has_other_locks (PhodavServer *self, const gchar *path, GList *locks
}
static void
-method_put_finished (SoupMessage *msg,
- SoupBuffer *chunk,
- gpointer user_data)
-{
- GFileOutputStream *output = user_data;
-
- g_debug ("PUT finished");
-
- g_object_unref (output);
-}
-
-static void
-method_put_got_chunk (SoupMessage *msg,
- SoupBuffer *chunk,
- gpointer user_data)
-{
- GFileOutputStream *output = user_data;
- PathHandler *handler = g_object_get_data (user_data, "handler");
- PhodavServer *self = handler->self;
- GError *err = NULL;
- gsize bytes_written;
-
- g_debug ("PUT got chunk");
-
- if (!g_output_stream_write_all (G_OUTPUT_STREAM (output),
- chunk->data, chunk->length,
- &bytes_written, self->cancellable, &err))
- goto end;
-
-end:
- if (err)
- {
- g_warning ("error: %s", err->message);
- g_clear_error (&err);
- soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
- }
-}
-
-static void
-method_put (PathHandler *handler, const gchar *path, SoupMessage *msg, GError **err)
-{
- PhodavServer *self = handler->self;
- GFile *file = NULL;
- GList *submitted = NULL;
- GFileOutputStream *output = NULL;
- gint status;
-
- 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 = put_start (msg, file, &output, self->cancellable, err);
- if (*err)
- goto end;
-
- soup_message_body_set_accumulate (msg->request_body, FALSE);
- g_object_set_data (G_OBJECT (output), "handler", handler);
- g_signal_connect (msg, "got-chunk", G_CALLBACK (method_put_got_chunk), output);
- g_signal_connect (msg, "finished", G_CALLBACK (method_put_finished), output);
-
-end:
- soup_message_set_status (msg, status);
- g_clear_object (&file);
-}
-
-static void
got_headers (SoupMessage *msg,
gpointer user_data)
{
@@ -500,7 +401,7 @@ got_headers (SoupMessage *msg,
GError *err = NULL;
if (msg->method == SOUP_METHOD_PUT)
- method_put (self->root_handler, path, msg, &err);
+ phodav_method_put (self->root_handler, msg, path, &err);
if (err)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]