]> arthur.barton.de Git - netatalk.git/commitdiff
First checking of Dynamic Datastore
authorFrank Lahm <franklahm@googlemail.com>
Tue, 5 Jun 2012 15:07:43 +0000 (17:07 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 15 Aug 2012 18:12:55 +0000 (20:12 +0200)
etc/afpd/.gitignore
etc/afpd/Makefile.am
etc/afpd/dd.c [new file with mode: 0644]
etc/afpd/dd.h [new file with mode: 0644]

index 5d0c03fa85cb4a199ed3beead2cdc679b820512b..1138fa6bb558238558227316330a64af3a1dc264 100644 (file)
@@ -3,8 +3,9 @@ Makefile.in
 afpd
 fce
 hash
+spot
 test_parse_mtab
 .deps
 .libs
-.gitignore
-afpd-afp_asp.o afpd-afp_config.o afpd-afp_dsi.o afpd-afp_options.o afpd-afprun.o afpd-afp_util.o afpd-afs.o afpd-appl.o afpd-auth.o afpd-catsearch.o afpd-desktop.o afpd-directory.o afpd-enumerate.o afpd-extattrs.o afpd-filedir.o afpd-file.o afpd-fork.o afpd-gettok.o afpd-hash.o afpd-main.o afpd-mangle.o afpd-messages.o afpd-nfsquota.o afpd-ofork.o afpd-quota.o afpd-status.o afpd-switch.o afpd-uam.o afpd-uid.o afpd-unix.o afpd-volume.o hash-hash.o
+*.o
+
index 85b51dc86bdca8971ecb85ce94c66c1273c28e21..c839fc7801fc1dd9d53a1f9a097d4ed007599d08 100644 (file)
@@ -3,7 +3,7 @@
 pkgconfdir = @PKGCONFDIR@
 
 sbin_PROGRAMS = afpd
-noinst_PROGRAMS = hash fce
+noinst_PROGRAMS = hash fce spot
 
 afpd_SOURCES = \
        afp_avahi.c \
@@ -66,7 +66,7 @@ endif
 noinst_HEADERS = auth.h afp_config.h desktop.h directory.h fce_api_internal.h file.h \
         filedir.h fork.h icon.h mangle.h misc.h status.h switch.h \
         uam_auth.h uid.h unix.h volume.h hash.h acls.h acl_mappings.h extattrs.h \
-        dircache.h afp_zeroconf.h afp_avahi.h afp_mdns.h
+        dircache.h afp_zeroconf.h afp_avahi.h afp_mdns.h dd.h
 
 hash_SOURCES = hash.c
 hash_CFLAGS = -DKAZLIB_TEST_MAIN -I$(top_srcdir)/include
@@ -74,3 +74,7 @@ hash_CFLAGS = -DKAZLIB_TEST_MAIN -I$(top_srcdir)/include
 fce_SOURCES = fce_api.c fce_util.c
 fce_CFLAGS = -DFCE_TEST_MAIN -I$(top_srcdir)/include
 fce_LDADD = $(top_builddir)/libatalk/libatalk.la
+
+spot_SOURCES = dd.c
+spot_CFLAGS = -DSPOT_TEST_MAIN
+spot_LDADD = $(top_builddir)/libatalk/libatalk.la
diff --git a/etc/afpd/dd.c b/etc/afpd/dd.c
new file mode 100644 (file)
index 0000000..63be82e
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+  Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU 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 General Public License for more details.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <string.h>
+#include <strings.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdbool.h>
+
+#include <atalk/errchk.h>
+#include <atalk/util.h>
+#include <atalk/logger.h>
+#include <atalk/talloc.h>
+
+#include "dd.h"
+
+static const char *neststrings[] = {
+    "",
+    "    ",
+    "        ",
+    "            "
+};
+
+static int dd_add_elem(dd_t *dd, dde_type_e type, void *val, size_t size)
+{
+    if (dd->dd_count == 0) {
+        dd->dd_elem = talloc_array(dd, dde_t *, 1);
+    } else {
+        dd->dd_elem = talloc_realloc(dd, dd->dd_elem, dde_t *, dd->dd_count + 1);
+    }
+
+    if (dd->dd_elem == NULL) {
+        LOG(logtype_default, log_error, "Allocation error");
+        return -1;
+    }
+
+    dd->dd_elem[dd->dd_count] = talloc(dd->dd_elem, dde_t);
+    dd->dd_elem[dd->dd_count]->dde_type = type;
+    dd->dd_elem[dd->dd_count]->dde_val = talloc_memdup(dd->dd_elem, val, size);
+
+    dd->dd_count++;
+
+    return 0;
+}
+
+static int dd_dump(dd_t *dd, int nestinglevel)
+{
+    printf("%sArray(#%d): {\n", neststrings[nestinglevel], dd->dd_count);
+    for (int n = 0; n < dd->dd_count; n++) {
+        switch (dd->dd_elem[n]->dde_type) {
+        case DDT_INT64: {
+            int i;
+            memcpy(&i, dd->dd_elem[n]->dde_val, sizeof(int));
+            printf("%s%d:\t%d\n", neststrings[nestinglevel + 1], n, i);
+            break;
+        }
+        case DDT_STRING:
+            printf("%s%d:\t%s\n", neststrings[nestinglevel + 1], n, dd->dd_elem[n]->dde_val);
+            break;
+        case DDT_BOOL: {
+            bool b;
+            memcpy(&b, dd->dd_elem[n]->dde_val, sizeof(bool));
+            printf("%s%d:\t%s\n", neststrings[nestinglevel + 1], n, b ? "true" : "false");
+            break;
+        }
+        case DDT_ARRAY:
+            dd_dump(dd->dd_elem[n]->dde_val, nestinglevel + 1);
+            break;
+        default:
+            LOG(logtype_default, log_error, "Unknown type");
+            break;
+        }
+    }
+    printf("%s}\n", neststrings[nestinglevel]);
+}
+
+#ifdef SPOT_TEST_MAIN
+#include <stdarg.h>
+
+int main(int argc, char **argv)
+{
+    TALLOC_CTX *mem_ctx = talloc_new(NULL);
+    dd_t *dd = talloc_zero(mem_ctx, dd_t);
+    int i;
+
+    set_processname("spot");
+    setuplog("default:info", "/dev/tty");
+
+    LOG(logtype_default, log_info, "Start");
+
+    i = 2;
+    dd_add_elem(dd, DDT_INT64, &i, sizeof(int));
+
+    i = 3;
+    dd_add_elem(dd, DDT_INT64, &i, sizeof(int));
+
+    char *str = "hello world";
+    dd_add_elem(dd, DDT_STRING, str, strlen(str) + 1);
+
+    bool b = true;
+    dd_add_elem(dd, DDT_BOOL, &b, sizeof(bool));
+
+    b = false;
+    dd_add_elem(dd, DDT_BOOL, &b, sizeof(bool));
+
+    i = 1;
+    dd_add_elem(dd, DDT_INT64, &i, sizeof(int));
+
+    /* add a nested array */
+    dd_t *nested = talloc_zero(dd, dd_t);
+
+    dd_add_elem(nested, DDT_INT64, &i, sizeof(int));
+
+    dd_add_elem(dd, DDT_ARRAY, nested, sizeof(dd_t));
+
+    dd_dump(dd, 0);
+
+    talloc_free(mem_ctx);
+    return 0;
+}
+#endif
diff --git a/etc/afpd/dd.h b/etc/afpd/dd.h
new file mode 100644 (file)
index 0000000..1e324a5
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+  Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU 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 General Public License for more details.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+/* dynamic datastore element types */
+typedef enum {
+    DDT_INT64,
+    DDT_BOOL,
+    DDT_DATE,
+    DDT_UUID,
+    DDT_FLOAT,
+    DDT_STRING,
+    DDT_UTF16_STRING,
+    DDT_ARRAY,
+    DDT_DICTIONARY
+} dde_type_e;
+
+/* one dynamic datastore element */
+typedef struct {
+    dde_type_e dde_type;    /* type */
+    void       *dde_val;    /* void pointer to value */
+} dde_t;
+
+/* dynamic datastore */
+typedef struct {
+    int   dd_count;         /* number of elements */
+    dde_t **dd_elem;        /* talloc'ed array of elements */
+} dd_t;