]> arthur.barton.de Git - netatalk.git/commitdiff
Give the baby the name dalloc, haha
authorFrank Lahm <franklahm@googlemail.com>
Thu, 7 Jun 2012 14:18:27 +0000 (16:18 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 15 Aug 2012 18:13:38 +0000 (20:13 +0200)
etc/afpd/Makefile.am
etc/afpd/dd.c [deleted file]
etc/afpd/dd.h [deleted file]
etc/afpd/spotlight.c [new file with mode: 0644]
etc/afpd/spotlight.h [new file with mode: 0644]
include/atalk/Makefile.am
include/atalk/dalloc.h [new file with mode: 0644]
libatalk/talloc/Makefile.am
libatalk/talloc/dalloc.c [new file with mode: 0644]

index c839fc7801fc1dd9d53a1f9a097d4ed007599d08..e74157ea30c19f34d68ec8197567e91e574867e9 100644 (file)
@@ -36,6 +36,7 @@ afpd_SOURCES = \
        nfsquota.c \
        ofork.c \
        quota.c \
+       spotlight.c \
        status.c \
        switch.c \
        uam.c \
@@ -66,7 +67,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 dd.h
+        dircache.h afp_zeroconf.h afp_avahi.h afp_mdns.h
 
 hash_SOURCES = hash.c
 hash_CFLAGS = -DKAZLIB_TEST_MAIN -I$(top_srcdir)/include
@@ -75,6 +76,6 @@ 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_SOURCES = spotlight.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
deleted file mode 100644 (file)
index 1bb9589..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
-  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 <inttypes.h>
-
-#include <atalk/errchk.h>
-#include <atalk/util.h>
-#include <atalk/logger.h>
-#include <atalk/talloc.h>
-#include <atalk/bstrlib.h>
-
-#include "dd.h"
-
-static const char *neststrings[] = {
-    "",
-    "    ",
-    "        ",
-    "            ",
-    "                ",
-    "                    ",
-    "                        "
-};
-
-int _dd_add_obj(dd_t *dd, void *talloc_chunk, void *obj, size_t size, int (*destructor)(void *))
-{
-    AFP_ASSERT(talloc_chunk);
-
-    if (destructor)
-        talloc_set_destructor(talloc_chunk, destructor);
-    if (dd->dd_talloc_array == NULL) {
-        dd->dd_talloc_array = talloc_array(dd, void *, 1);
-    } else {
-        dd->dd_talloc_array = talloc_realloc(dd, dd->dd_talloc_array, void *, talloc_array_length(dd->dd_talloc_array) + 1);
-    }
-
-    memcpy(talloc_chunk, obj, size);
-    dd->dd_talloc_array[talloc_array_length(dd->dd_talloc_array) - 1] = talloc_chunk;
-
-    return 0;
-}
-
-static int dd_dump(dd_t *dd, int nestinglevel)
-{
-    const char *type;
-
-    printf("%sArray(#%d): {\n", neststrings[nestinglevel], talloc_array_length(dd->dd_talloc_array));
-
-    for (int n = 0; n < talloc_array_length(dd->dd_talloc_array); n++) {
-
-        type = talloc_get_name(dd->dd_talloc_array[n]);
-
-        if (STRCMP(type, ==, "int64_t")) {
-            int64_t i;
-            memcpy(&i, dd->dd_talloc_array[n], sizeof(int64_t));
-            printf("%s%d:\t%" PRId64 "\n", neststrings[nestinglevel + 1], n, i);
-        } else if (STRCMP(type, ==, "bstring")) {
-            bstring b;
-            memcpy(&b, dd->dd_talloc_array[n], sizeof(bstring));
-            printf("%s%d:\t%s\n", neststrings[nestinglevel + 1], n, bdata(b));
-        } else if (STRCMP(type, ==, "_Bool")) {
-            bool bl;
-            memcpy(&bl, dd->dd_talloc_array[n], sizeof(bool));
-            printf("%s%d:\t%s\n", neststrings[nestinglevel + 1], n, bl ? "true" : "false");
-        } else if (STRCMP(type, ==, "dd_t")) {
-            dd_t *nested;
-            memcpy(&nested, dd->dd_talloc_array[n], sizeof(dd_t *));
-            dd_dump(nested, nestinglevel + 1);
-        }
-    }
-    printf("%s}\n", neststrings[nestinglevel]);
-}
-
-static int bstring_destructor(void *bstr)
-{
-    bdestroy(*(bstring *)bstr);
-    return 0;
-}
-
-#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_obj(dd, &i, int64_t, NULL);
-
-    bstring str = bfromcstr("hello world");
-    dd_add_obj(dd, &str, bstring, bstring_destructor);
-
-    bool b = true;
-    dd_add_obj(dd, &b, bool, NULL);
-
-    b = false;
-    dd_add_obj(dd, &b, bool, NULL);
-
-    i = 1;
-    dd_add_obj(dd, &i, int64_t, NULL);
-
-    /* add a nested array */
-    dd_t *nested = talloc_zero(dd, dd_t);
-    dd_add_obj(nested, &i, int64_t, NULL);
-    dd_add_obj(nested, &str, bstring, bstring_destructor);
-    dd_add_obj(dd, &nested, dd_t, NULL);
-
-    dd_dump(dd, 0);
-
-    talloc_free(mem_ctx);
-    return 0;
-}
-#endif
diff --git a/etc/afpd/dd.h b/etc/afpd/dd.h
deleted file mode 100644 (file)
index e072e06..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-  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 */
-
-#ifndef DD_H
-#define DD_H
-
-/* dynamic datastore */
-typedef struct {
-    void **dd_talloc_array;
-} dd_t;
-
-#define dd_init(dd) (dd)->dd_talloc_array = NULL;
-
-#define dd_add_obj(dd, obj, type, destructor)                              \
-    _dd_add_obj((dd), talloc((dd), type), (obj), sizeof(type), (destructor));
-
-#define dd_get_count(dd) talloc_array_length(dd->dd_talloc_array)
-
-extern int _dd_add_obj(dd_t *dd, void *talloc_chunk, void *obj, size_t size, int (*destructor)(void *));
-
-#endif  /* DD_H */
diff --git a/etc/afpd/spotlight.c b/etc/afpd/spotlight.c
new file mode 100644 (file)
index 0000000..d9a5ad9
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+  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 <inttypes.h>
+
+#include <atalk/errchk.h>
+#include <atalk/util.h>
+#include <atalk/logger.h>
+#include <atalk/talloc.h>
+#include <atalk/bstrlib.h>
+
+#include "spotlight.h"
+
+#ifdef SPOT_TEST_MAIN
+
+static const char *neststrings[] = {
+    "",
+    "    ",
+    "        ",
+    "            ",
+    "                ",
+    "                    ",
+    "                        "
+};
+
+static int dd_dump(DALLOC_CTX *dd, int nestinglevel)
+{
+    const char *type;
+
+    printf("%sArray(#%d): {\n", neststrings[nestinglevel], talloc_array_length(dd->dd_talloc_array));
+
+    for (int n = 0; n < talloc_array_length(dd->dd_talloc_array); n++) {
+
+        type = talloc_get_name(dd->dd_talloc_array[n]);
+
+        if (STRCMP(type, ==, "int64_t")) {
+            int64_t i;
+            memcpy(&i, dd->dd_talloc_array[n], sizeof(int64_t));
+            printf("%s%d:\t%" PRId64 "\n", neststrings[nestinglevel + 1], n, i);
+        } else if (STRCMP(type, ==, "uint32_t")) {
+            uint32_t i;
+            memcpy(&i, dd->dd_talloc_array[n], sizeof(uint32_t));
+            printf("%s%d:\t%" PRIu32 "\n", neststrings[nestinglevel + 1], n, i);
+        } else if (STRCMP(type, ==, "char *")) {
+            char *s;
+            memcpy(&s, dd->dd_talloc_array[n], sizeof(char *));
+            printf("%s%d:\t%s\n", neststrings[nestinglevel + 1], n, s);
+        } else if (STRCMP(type, ==, "_Bool")) {
+            bool bl;
+            memcpy(&bl, dd->dd_talloc_array[n], sizeof(bool));
+            printf("%s%d:\t%s\n", neststrings[nestinglevel + 1], n, bl ? "true" : "false");
+        } else if (STRCMP(type, ==, "dd_t")) {
+            DALLOC_CTX *nested;
+            memcpy(&nested, dd->dd_talloc_array[n], sizeof(DALLOC_CTX *));
+            dd_dump(nested, nestinglevel + 1);
+        } else if (STRCMP(type, ==, "cnid_array_t")) {
+            cnid_array_t *cnids;
+            memcpy(&cnids, dd->dd_talloc_array[n], sizeof(cnid_array_t *));
+            printf("%s%d:\tunkn1: %" PRIu16 ", unkn2: %" PRIu32,
+                   neststrings[nestinglevel + 1], n, cnids->ca_unkn1, cnids->ca_unkn2);
+            if (cnids->ca_cnids)
+                dd_dump(cnids->ca_cnids, nestinglevel + 1);
+        }
+    }
+    printf("%s}\n", neststrings[nestinglevel]);
+}
+
+#include <stdarg.h>
+
+int main(int argc, char **argv)
+{
+    TALLOC_CTX *mem_ctx = talloc_new(NULL);
+    DALLOC_CTX *dd = talloc_zero(mem_ctx, DALLOC_CTX);
+    int64_t i;
+
+    set_processname("spot");
+    setuplog("default:info", "/dev/tty");
+
+    LOG(logtype_default, log_info, "Start");
+
+    i = 2;
+    dalloc_add(dd, &i, int64_t);
+
+    i = 1;
+    dalloc_add(dd, &i, int64_t);
+
+
+    char *str = talloc_strdup(dd, "hello world");
+    dalloc_add(dd, &str, char *);
+
+    bool b = true;
+    dalloc_add(dd, &b, bool);
+
+    b = false;
+    dalloc_add(dd, &b, bool);
+
+
+    /* add a nested array */
+    DALLOC_CTX *nested = talloc_zero(dd, DALLOC_CTX);
+    i = 3;
+    dalloc_add(nested, &i, int64_t);
+    dalloc_add(dd, &nested, DALLOC_CTX);
+
+    /* test a CNID array */
+    uint32_t id = 16;
+    cnid_array_t *cnids = talloc_zero(dd, cnid_array_t);
+
+    cnids->ca_cnids = talloc_zero(cnids, DALLOC_CTX);
+
+    cnids->ca_unkn1 = 1;
+    cnids->ca_unkn2 = 2;
+
+    dalloc_add(cnids->ca_cnids, &id, uint32_t);
+    dalloc_add(dd, &cnids, cnid_array_t);
+
+    dd_dump(dd, 0);
+
+    talloc_free(mem_ctx);
+    return 0;
+}
+#endif
diff --git a/etc/afpd/spotlight.h b/etc/afpd/spotlight.h
new file mode 100644 (file)
index 0000000..671ac8d
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+  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 */
+
+#ifndef SPOTLIGHT_H
+#define SPOTLIGHT_H
+
+#include <atalk/dalloc.h>
+
+typedef struct {
+    uint16_t   ca_unkn1;
+    uint32_t   ca_unkn2;
+    DALLOC_CTX *ca_cnids;
+} cnid_array_t;
+
+#endif /* SPOTLIGHT_H */
index b328d80210e6bf1e5fa338d0f86d2eb33e7d0fd8..8ad9c7fb11ddb3cb74811239181bede54f3e90dd 100644 (file)
@@ -40,5 +40,6 @@ noinst_HEADERS = \
        ftw.h \
        dsi.h \
        ldapconfig.h \
-       talloc.h
+       talloc.h \
+       dalloc.h
 
diff --git a/include/atalk/dalloc.h b/include/atalk/dalloc.h
new file mode 100644 (file)
index 0000000..96d1028
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+  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 */
+
+#ifndef DALLOC_H
+#define DALLOC_H
+
+#include <atalk/talloc.h>
+
+/* dynamic datastore */
+typedef struct {
+    void **dd_talloc_array;
+} DALLOC_CTX;
+
+#define dalloc_add(dd, obj, type)                                       \
+    dalloc_add_talloc_chunk((dd), talloc((dd), type), (obj), sizeof(type));
+
+#define dd_get_count(dd) talloc_array_length(dd->dd_talloc_array)
+
+extern int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size);
+
+
+#endif  /* DALLOC_H */
index 4fd3252dfaa5d47d8ef5ec2298a355f34f471f7c..8616eac093b446b7798970c7e960310008479778 100644 (file)
@@ -1,4 +1,4 @@
 # Makefile.am for libatalk/talloc/
 
 noinst_LTLIBRARIES = libtalloc.la
-libtalloc_la_SOURCES = talloc.c
+libtalloc_la_SOURCES = talloc.c dalloc.c
diff --git a/libatalk/talloc/dalloc.c b/libatalk/talloc/dalloc.c
new file mode 100644 (file)
index 0000000..562755d
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+  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 <inttypes.h>
+
+#include <atalk/errchk.h>
+#include <atalk/util.h>
+#include <atalk/logger.h>
+#include <atalk/talloc.h>
+#include <atalk/bstrlib.h>
+#include <atalk/dalloc.h>
+
+/* Use dalloc_add_obj() macro, not this function */
+int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size)
+{
+    AFP_ASSERT(talloc_chunk);
+
+    dd->dd_talloc_array = talloc_realloc(dd, dd->dd_talloc_array, void *, talloc_array_length(dd->dd_talloc_array) + 1);
+    memcpy(talloc_chunk, obj, size);
+    dd->dd_talloc_array[talloc_array_length(dd->dd_talloc_array) - 1] = talloc_chunk;
+
+    return 0;
+}