From: Frank Lahm Date: Thu, 7 Jun 2012 14:18:27 +0000 (+0200) Subject: Give the baby the name dalloc, haha X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=b17741f6a9e2121454bd8d6159c86cdd44087648 Give the baby the name dalloc, haha --- diff --git a/etc/afpd/Makefile.am b/etc/afpd/Makefile.am index c839fc78..e74157ea 100644 --- a/etc/afpd/Makefile.am +++ b/etc/afpd/Makefile.am @@ -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 index 1bb95896..00000000 --- a/etc/afpd/dd.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - Copyright (c) 2012 Frank Lahm - - 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 -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#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 - -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 index e072e067..00000000 --- a/etc/afpd/dd.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2012 Frank Lahm - - 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 index 00000000..d9a5ad9f --- /dev/null +++ b/etc/afpd/spotlight.c @@ -0,0 +1,142 @@ +/* + Copyright (c) 2012 Frank Lahm + + 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#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 + +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 index 00000000..671ac8d6 --- /dev/null +++ b/etc/afpd/spotlight.h @@ -0,0 +1,30 @@ +/* + Copyright (c) 2012 Frank Lahm + + 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 + +typedef struct { + uint16_t ca_unkn1; + uint32_t ca_unkn2; + DALLOC_CTX *ca_cnids; +} cnid_array_t; + +#endif /* SPOTLIGHT_H */ diff --git a/include/atalk/Makefile.am b/include/atalk/Makefile.am index b328d802..8ad9c7fb 100644 --- a/include/atalk/Makefile.am +++ b/include/atalk/Makefile.am @@ -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 index 00000000..96d10289 --- /dev/null +++ b/include/atalk/dalloc.h @@ -0,0 +1,37 @@ +/* + Copyright (c) 2012 Frank Lahm + + 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 + +/* 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 */ diff --git a/libatalk/talloc/Makefile.am b/libatalk/talloc/Makefile.am index 4fd3252d..8616eac0 100644 --- a/libatalk/talloc/Makefile.am +++ b/libatalk/talloc/Makefile.am @@ -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 index 00000000..562755d9 --- /dev/null +++ b/libatalk/talloc/dalloc.c @@ -0,0 +1,44 @@ +/* + Copyright (c) 2012 Frank Lahm + + 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* 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; +}