]> saetta.ns0.it Git - zakstorage/libzakstorage/commitdiff
Skeleton for raw file system plugin. master
authorAndrea Zagli <azagli@libero.it>
Sun, 6 Sep 2020 08:25:01 +0000 (10:25 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 6 Sep 2020 08:25:01 +0000 (10:25 +0200)
Makefile.am
configure.ac
plugins/Makefile.am [new file with mode: 0644]
plugins/fsraw/Makefile.am [new file with mode: 0644]
plugins/fsraw/fsraw.plugin [new file with mode: 0644]
plugins/fsraw/plgfsraw.c [new file with mode: 0644]
plugins/fsraw/plgfsraw.h [new file with mode: 0644]

index 30774db21c1da0d643812970684dc485912586b2..37b757d63c6f1a00577e07ddfab84262f9747766 100644 (file)
@@ -1,6 +1,6 @@
 DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc --enable-introspection
 
-SUBDIRS = src docs
+SUBDIRS = src plugins docs
 
 EXTRA_DIST = libzakstorage.pc.in
 
index 8eeb85c9294781a8b21f1f9afe40e4e33e9a4122..f86950807b37930e507f5307f0e35bb81fc2b60a 100644 (file)
@@ -58,6 +58,8 @@ AC_CONFIG_FILES([
   libzakstorage.pc
   Makefile
   src/Makefile
+  plugins/Makefile
+  plugins/fsraw/Makefile
   docs/Makefile
   docs/reference/Makefile
   docs/reference/version.xml
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
new file mode 100644 (file)
index 0000000..c8a04c8
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = fsraw
diff --git a/plugins/fsraw/Makefile.am b/plugins/fsraw/Makefile.am
new file mode 100644 (file)
index 0000000..0cf7f6c
--- /dev/null
@@ -0,0 +1,19 @@
+pluginsdir = $(libdir)/$(PACKAGE)/plugins
+
+AM_CPPFLAGS = \
+              -I$(top_srcdir) \
+              $(LIBZAKSTORAGE_CFLAGS) \
+              -DG_LOG_DOMAIN=\"ZakStorageFsRaw\"
+
+plugins_LTLIBRARIES = libfsraw.la
+
+libfsraw_la_SOURCES = \
+                      plgfsraw.h \
+                      plgfsraw.c
+
+libfsraw_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
+libfsraw_la_LIBADD = \
+                     $(top_builddir)/src/libzakstorage.la \
+                     $(LIBZAKSTORAGE_LIBS)
+
+plugins_DATA = fsraw.plugin
diff --git a/plugins/fsraw/fsraw.plugin b/plugins/fsraw/fsraw.plugin
new file mode 100644 (file)
index 0000000..062a18e
--- /dev/null
@@ -0,0 +1,8 @@
+[Plugin]
+Module=fsraw
+Name=File System raw
+Description=Stores files in a raw file system.
+Authors=Andrea Zagli <azagli@libero.it>
+Copyright=Copyright © 2020 Andrea Zagli
+Website=http://saetta.ns0.it/
+Help=http://saetta.ns0.it/
diff --git a/plugins/fsraw/plgfsraw.c b/plugins/fsraw/plgfsraw.c
new file mode 100644 (file)
index 0000000..5380b5d
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * plgfsraw.c
+ * This file is part of libzakstorage
+ *
+ * Copyright (C) 2020 Andrea Zagli <azagli@libero.it>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gmodule.h>
+
+#include <libpeas/peas.h>
+
+#include "../../src/libzakstorage.h"
+#include "../../src/storagepluggable.h"
+
+#include "plgfsraw.h"
+
+static void zak_storage_pluggable_iface_init (ZakStoragePluggableInterface *iface);
+
+gboolean zak_storage_fsraw_plugin_initialize (ZakStoragePluggable *pluggable, const gchar *cnc_string);
+
+static void zak_storage_fsraw_plugin_node_new (ZakStoragePluggable *pluggable, GInputStream *src_stream, const gchar *dest_filename, const gchar *version);
+
+#define ZAK_STORAGE_FSRAW_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_STORAGE_TYPE_FSRAW_PLUGIN, ZakStorageFsRawPluginPrivate))
+
+typedef struct _ZakStorageFsRawPluginPrivate ZakStorageFsRawPluginPrivate;
+struct _ZakStorageFsRawPluginPrivate
+       {
+               gchar *cnc_string;
+
+               gchar *root;
+       };
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (ZakStorageFsRawPlugin,
+                                zak_storage_fsraw_plugin,
+                                PEAS_TYPE_EXTENSION_BASE,
+                                0,
+                                G_IMPLEMENT_INTERFACE_DYNAMIC (ZAK_STORAGE_TYPE_PLUGGABLE,
+                                                               zak_storage_pluggable_iface_init))
+
+enum {
+       PROP_0,
+       PROP_CNC_STRING,
+       PROP_ROOT
+};
+
+static void
+zak_storage_fsraw_plugin_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+       ZakStorageFsRawPlugin *plugin = ZAK_STORAGE_FSRAW_PLUGIN (object);
+       ZakStorageFsRawPluginPrivate *priv = ZAK_STORAGE_FSRAW_PLUGIN_GET_PRIVATE (plugin);
+
+       switch (prop_id)
+               {
+                       case PROP_CNC_STRING:
+                               zak_storage_fsraw_plugin_initialize ((ZakStoragePluggable *)plugin, g_value_get_string (value));
+                               break;
+
+                       case PROP_ROOT:
+                               priv->root = g_value_get_string (value);
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                               break;
+               }
+}
+
+static void
+zak_storage_fsraw_plugin_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+       ZakStorageFsRawPlugin *plugin = ZAK_STORAGE_FSRAW_PLUGIN (object);
+       ZakStorageFsRawPluginPrivate *priv = ZAK_STORAGE_FSRAW_PLUGIN_GET_PRIVATE (plugin);
+
+       switch (prop_id)
+               {
+                       case PROP_CNC_STRING:
+                               g_value_set_string (value, priv->cnc_string);
+                               break;
+
+                       case PROP_ROOT:
+                               g_value_set_string (value, priv->root);
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                               break;
+               }
+}
+
+static void
+zak_storage_fsraw_plugin_init (ZakStorageFsRawPlugin *plugin)
+{
+       ZakStorageFsRawPluginPrivate *priv = ZAK_STORAGE_FSRAW_PLUGIN_GET_PRIVATE (plugin);
+
+       priv->cnc_string = NULL;
+       priv->root = NULL;
+}
+
+static void
+zak_storage_fsraw_plugin_finalize (GObject *object)
+{
+       ZakStorageFsRawPlugin *plugin = ZAK_STORAGE_FSRAW_PLUGIN (object);
+
+       G_OBJECT_CLASS (zak_storage_fsraw_plugin_parent_class)->finalize (object);
+}
+
+gboolean
+zak_storage_fsraw_plugin_initialize (ZakStoragePluggable *pluggable, const gchar *cnc_string)
+{
+       gboolean ret;
+       GError *error;
+       gchar *root;
+
+       ZakStorageFsRawPlugin *plugin = ZAK_STORAGE_FSRAW_PLUGIN (pluggable);
+       ZakStorageFsRawPluginPrivate *priv = ZAK_STORAGE_FSRAW_PLUGIN_GET_PRIVATE (plugin);
+
+       priv->cnc_string = g_strdup (cnc_string);
+
+       root = g_strstr_len (priv->cnc_string, -1, ";ROOT=/");
+       if (root != NULL)
+               {
+                       priv->root = g_strdup (root + 7);
+                       g_free (root);
+               }
+
+       return ret;
+}
+
+static void
+zak_storage_fsraw_plugin_node_new (ZakStoragePluggable *pluggable, GInputStream *src_stream, const gchar *dest_filename, const gchar *version)
+{
+       GError *error;
+
+       ZakStorageFsRawPluginPrivate *priv = ZAK_STORAGE_FSRAW_PLUGIN_GET_PRIVATE (pluggable);
+
+}
+
+static void
+zak_storage_fsraw_plugin_class_init (ZakStorageFsRawPluginClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (ZakStorageFsRawPluginPrivate));
+
+       object_class->set_property = zak_storage_fsraw_plugin_set_property;
+       object_class->get_property = zak_storage_fsraw_plugin_get_property;
+       object_class->finalize = zak_storage_fsraw_plugin_finalize;
+
+       g_object_class_override_property (object_class, PROP_CNC_STRING, "cnc_string");
+       g_object_class_override_property (object_class, PROP_ROOT, "root");
+}
+
+static void
+zak_storage_pluggable_iface_init (ZakStoragePluggableInterface *iface)
+{
+       iface->initialize = zak_storage_fsraw_plugin_initialize;
+       iface->node_new = zak_storage_fsraw_plugin_node_new;
+}
+
+static void
+zak_storage_fsraw_plugin_class_finalize (ZakStorageFsRawPluginClass *klass)
+{
+}
+
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+       zak_storage_fsraw_plugin_register_type (G_TYPE_MODULE (module));
+
+       peas_object_module_register_extension_type (module,
+                                                   ZAK_STORAGE_TYPE_PLUGGABLE,
+                                                   ZAK_STORAGE_TYPE_FSRAW_PLUGIN);
+}
diff --git a/plugins/fsraw/plgfsraw.h b/plugins/fsraw/plgfsraw.h
new file mode 100644 (file)
index 0000000..b7be201
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * plgfsraw.h
+ * This file is part of libzakstorage
+ *
+ * Copyright (C) 2020 Andrea Zagli <azagli@libero.it>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __ZAK_STORAGE_FSRAW_PLUGIN_H__
+#define __ZAK_STORAGE_FSRAW_PLUGIN_H__
+
+#include <libpeas/peas.h>
+
+G_BEGIN_DECLS
+
+#define ZAK_STORAGE_TYPE_FSRAW_PLUGIN         (zak_storage_fsraw_plugin_get_type ())
+#define ZAK_STORAGE_FSRAW_PLUGIN(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), ZAK_STORAGE_TYPE_FSRAW_PLUGIN, ZakStorageFsRawPlugin))
+#define ZAK_STORAGE_FSRAW_PLUGIN_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), ZAK_STORAGE_TYPE_FSRAW_PLUGIN, ZakStorageFsRawPlugin))
+#define ZAK_STORAGE_IS_FSRAW_PLUGIN(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), ZAK_STORAGE_TYPE_FSRAW_PLUGIN))
+#define ZAK_STORAGE_IS_FSRAW_PLUGIN_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), ZAK_STORAGE_TYPE_FSRAW_PLUGIN))
+#define ZAK_STORAGE_FSRAW_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ZAK_STORAGE_TYPE_FSRAW_PLUGIN, ZakStorageFsRawPluginClass))
+
+typedef struct _ZakStorageFsRawPlugin       ZakStorageFsRawPlugin;
+typedef struct _ZakStorageFsRawPluginClass  ZakStorageFsRawPluginClass;
+
+struct _ZakStorageFsRawPlugin {
+       PeasExtensionBase parent_instance;
+};
+
+struct _ZakStorageFsRawPluginClass {
+       PeasExtensionBaseClass parent_class;
+};
+
+GType                 zak_storage_fsraw_plugin_get_type        (void) G_GNUC_CONST;
+G_MODULE_EXPORT void  peas_register_types                         (PeasObjectModule *module);
+
+G_END_DECLS
+
+#endif /* __ZAK_STORAGE_FSRAW_PLUGIN_H__ */