[phodav: 1/18] wip
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [phodav: 1/18] wip
- Date: Thu, 10 Apr 2014 17:51:10 +0000 (UTC)
commit c56f614b40ffc42195a9a1c63795debf329bba90
Author: Marc-André Lureau <marcandre lureau gmail com>
Date: Tue Apr 8 20:40:53 2014 +0200
wip
Makefile.am | 6 ++
libphodav/guuid.h | 2 +-
libphodav/phodav-lock.c | 67 ++++++++++++++++++++++
libphodav/phodav-lock.h | 36 ++++++++++++
libphodav/phodav-path.c | 58 +++++++++++++++++++
libphodav/phodav-path.h | 32 +++++++++++
libphodav/phodav-priv.h | 73 ++++++++++++++++++++++++
libphodav/phodav-server.c | 136 +--------------------------------------------
8 files changed, 275 insertions(+), 135 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 9142a96..0296ab9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,7 +28,13 @@ libphodav_include_HEADERS = \
libphodav_1_0_la_SOURCES = \
libphodav/guuid.c \
libphodav/guuid.h \
+ libphodav/phodav-priv.h \
+ libphodav/phodav-path.c \
+ libphodav/phodav-path.h \
+ libphodav/phodav-lock.c \
+ libphodav/phodav-lock.h \
libphodav/phodav-server.c \
+ libphodav/phodav-server.h \
$(NULL)
libphodav_1_0_la_CFLAGS = \
diff --git a/libphodav/guuid.h b/libphodav/guuid.h
index 7a95283..1cda776 100644
--- a/libphodav/guuid.h
+++ b/libphodav/guuid.h
@@ -23,7 +23,7 @@
#ifndef __G_UUID_H__
#define __G_UUID_H__
-#include <glib/gtypes.h>
+#include <glib.h>
G_BEGIN_DECLS
diff --git a/libphodav/phodav-lock.c b/libphodav/phodav-lock.c
new file mode 100644
index 0000000..21f0214
--- /dev/null
+++ b/libphodav/phodav-lock.c
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2014 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-lock.h"
+#include "phodav-path.h"
+
+void
+dav_lock_refresh_timeout (DAVLock *lock, guint timeout)
+{
+ if (timeout)
+ lock->timeout = g_get_monotonic_time () / G_USEC_PER_SEC + timeout;
+ else
+ lock->timeout = 0;
+}
+
+DAVLock *
+dav_lock_new (Path *path, const gchar *token,
+ LockScopeType scope, LockType type,
+ DepthType depth, const xmlNodePtr owner,
+ guint timeout)
+{
+ DAVLock *lock;
+
+ g_return_val_if_fail (token, NULL);
+ g_return_val_if_fail (strlen (token) == sizeof (lock->token), NULL);
+
+ lock = g_slice_new0 (DAVLock);
+ lock->path = path_ref (path);
+ memcpy (lock->token, token, sizeof (lock->token));
+ lock->scope = scope;
+ lock->type = type;
+ lock->depth = depth;
+ if (owner)
+ lock->owner = xmlCopyNode (owner, 1);
+
+ dav_lock_refresh_timeout (lock, timeout);
+
+ return lock;
+}
+
+void
+dav_lock_free (DAVLock *lock)
+{
+ g_return_if_fail (lock);
+
+ path_remove_lock (lock->path, lock);
+ path_unref (lock->path);
+
+ if (lock->owner)
+ xmlFreeNode (lock->owner);
+
+ g_slice_free (DAVLock, lock);
+}
diff --git a/libphodav/phodav-lock.h b/libphodav/phodav-lock.h
new file mode 100644
index 0000000..fb09903
--- /dev/null
+++ b/libphodav/phodav-lock.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2014 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/>.
+ */
+#ifndef __PHODAV_LOCK_H__
+#define __PHODAV_LOCK_H__
+
+#include "phodav-priv.h"
+
+G_BEGIN_DECLS
+
+DAVLock * dav_lock_new (Path *path, const gchar *token,
+ LockScopeType scope, LockType type,
+ DepthType depth, const xmlNodePtr owner,
+ guint timeout);
+
+void dav_lock_free (DAVLock *lock);
+
+void dav_lock_refresh_timeout (DAVLock *lock, guint timeout);
+
+G_END_DECLS
+
+#endif /* __PHODAV_LOCK_H__ */
diff --git a/libphodav/phodav-path.c b/libphodav/phodav-path.c
new file mode 100644
index 0000000..22b8853
--- /dev/null
+++ b/libphodav/phodav-path.c
@@ -0,0 +1,58 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2014 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-path.h"
+#include "phodav-lock.h"
+
+Path *
+path_ref (Path *path)
+{
+ path->refs++;
+
+ return path;
+}
+
+void
+path_unref (Path *path)
+{
+ path->refs--;
+
+ if (path->refs == 0)
+ {
+ g_list_free_full (path->locks, (GDestroyNotify) dav_lock_free);
+ g_free (path->path);
+ g_slice_free (Path, path);
+ }
+}
+
+void
+path_remove_lock (Path *path, DAVLock *lock)
+{
+ g_return_if_fail (path);
+ g_return_if_fail (lock);
+
+ path->locks = g_list_remove (path->locks, lock);
+}
+
+void
+path_add_lock (Path *path, DAVLock *lock)
+{
+ g_return_if_fail (path);
+ g_return_if_fail (lock);
+
+ path->locks = g_list_append (path->locks, lock);
+}
diff --git a/libphodav/phodav-path.h b/libphodav/phodav-path.h
new file mode 100644
index 0000000..78b1528
--- /dev/null
+++ b/libphodav/phodav-path.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2014 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/>.
+ */
+#ifndef __PHODAV_PATH_H__
+#define __PHODAV_PATH_H__
+
+#include "phodav-priv.h"
+
+G_BEGIN_DECLS
+
+Path * path_ref (Path *path);
+void path_unref (Path *path);
+void path_remove_lock (Path *path, DAVLock *lock);
+void path_add_lock (Path *path, DAVLock *lock);
+
+G_END_DECLS
+
+#endif /* __PHODAV_LOCK_H__ */
diff --git a/libphodav/phodav-priv.h b/libphodav/phodav-priv.h
new file mode 100644
index 0000000..1a4adbf
--- /dev/null
+++ b/libphodav/phodav-priv.h
@@ -0,0 +1,73 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2014 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/>.
+ */
+#ifndef __PHODAV_PRIV_H__
+#define __PHODAV_PRIV_H__
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <glib-object.h>
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+G_BEGIN_DECLS
+
+typedef struct _DAVLock DAVLock;
+typedef struct _Path Path;
+
+typedef enum _LockScopeType {
+ LOCK_SCOPE_NONE,
+ LOCK_SCOPE_EXCLUSIVE,
+ LOCK_SCOPE_SHARED,
+} LockScopeType;
+
+typedef enum _LockType {
+ LOCK_NONE,
+ LOCK_WRITE,
+} LockType;
+
+typedef enum _DepthType {
+ DEPTH_ZERO,
+ DEPTH_ONE,
+ DEPTH_INFINITY
+} DepthType;
+
+struct _DAVLock
+{
+ Path *path;
+ gchar token[45];
+ LockScopeType scope;
+ LockType type;
+ DepthType depth;
+ xmlNodePtr owner;
+ guint64 timeout;
+};
+
+struct _Path
+{
+ gchar *path;
+ GList *locks;
+ guint32 refs;
+};
+
+G_END_DECLS
+
+#endif /* __PHODAV_PRIV_H__ */
diff --git a/libphodav/phodav-server.c b/libphodav/phodav-server.c
index 2d350c5..9bea109 100644
--- a/libphodav/phodav-server.c
+++ b/libphodav/phodav-server.c
@@ -18,13 +18,6 @@
#include "config.h"
-#include <glib/gi18n.h>
-
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-
#include <sys/types.h>
#ifdef HAVE_ATTR_XATTR_H
#include <attr/xattr.h>
@@ -32,6 +25,8 @@
#include "guuid.h"
#include "phodav-server.h"
+#include "phodav-path.h"
+#include "phodav-lock.h"
/**
* SECTION:phodav-server
@@ -65,9 +60,6 @@ struct _PhodavServerClass
GObjectClass parent_class;
};
-typedef struct _DAVLock DAVLock;
-typedef struct _Path Path;
-
G_DEFINE_TYPE (PhodavServer, phodav_server, G_TYPE_OBJECT)
/* Properties */
@@ -90,54 +82,6 @@ static void request_started (SoupServer *server,
SoupClientContext *client,
gpointer user_data);
-static void dav_lock_free (DAVLock *lock);
-
-struct _Path
-{
- gchar *path;
- GList *locks;
- guint32 refs;
-};
-
-static Path *
-path_ref (Path *path)
-{
- path->refs++;
-
- return path;
-}
-
-static void
-path_unref (Path *path)
-{
- path->refs--;
-
- if (path->refs == 0)
- {
- g_list_free_full (path->locks, (GDestroyNotify) dav_lock_free);
- g_free (path->path);
- g_slice_free (Path, path);
- }
-}
-
-static void
-path_remove_lock (Path *path, DAVLock *lock)
-{
- g_return_if_fail (path);
- g_return_if_fail (lock);
-
- path->locks = g_list_remove (path->locks, lock);
-}
-
-static void
-path_add_lock (Path *path, DAVLock *lock)
-{
- g_return_if_fail (path);
- g_return_if_fail (lock);
-
- path->locks = g_list_append (path->locks, lock);
-}
-
static void
remove_trailing (gchar *str, gchar c)
{
@@ -167,82 +111,6 @@ get_path (PhodavServer *self, const gchar *_path)
return p;
}
-typedef enum _LockScopeType {
- LOCK_SCOPE_NONE,
- LOCK_SCOPE_EXCLUSIVE,
- LOCK_SCOPE_SHARED,
-} LockScopeType;
-
-typedef enum _LockType {
- LOCK_NONE,
- LOCK_WRITE,
-} LockType;
-
-typedef enum _DepthType {
- DEPTH_ZERO,
- DEPTH_ONE,
- DEPTH_INFINITY
-} DepthType;
-
-struct _DAVLock
-{
- Path *path;
- gchar token[45];
- LockScopeType scope;
- LockType type;
- DepthType depth;
- xmlNodePtr owner;
- guint64 timeout;
-};
-
-static void
-dav_lock_refresh_timeout (DAVLock *lock, guint timeout)
-{
- if (timeout)
- lock->timeout = g_get_monotonic_time () / G_USEC_PER_SEC + timeout;
- else
- lock->timeout = 0;
-}
-
-static DAVLock *
-dav_lock_new (Path *path, const gchar *token,
- LockScopeType scope, LockType type,
- DepthType depth, const xmlNodePtr owner,
- guint timeout)
-{
- DAVLock *lock;
-
- g_return_val_if_fail (token, NULL);
- g_return_val_if_fail (strlen (token) == sizeof (lock->token), NULL);
-
- lock = g_slice_new0 (DAVLock);
- lock->path = path_ref (path);
- memcpy (lock->token, token, sizeof (lock->token));
- lock->scope = scope;
- lock->type = type;
- lock->depth = depth;
- if (owner)
- lock->owner = xmlCopyNode (owner, 1);
-
- dav_lock_refresh_timeout (lock, timeout);
-
- return lock;
-}
-
-static void
-dav_lock_free (DAVLock *lock)
-{
- g_return_if_fail (lock);
-
- path_remove_lock (lock->path, lock);
- path_unref (lock->path);
-
- if (lock->owner)
- xmlFreeNode (lock->owner);
-
- g_slice_free (DAVLock, lock);
-}
-
struct _PathHandler
{
PhodavServer *self;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]