]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/talloc/dalloc.c
Spotlight module
[netatalk.git] / libatalk / talloc / dalloc.c
index 562755d9e0d3ae9214bda5e2c43db3f600ea0e9e..70c75e3b53e0a23f5ab1fde019c31a3e78f33137 100644 (file)
@@ -31,7 +31,7 @@
 #include <atalk/bstrlib.h>
 #include <atalk/dalloc.h>
 
-/* Use dalloc_add_obj() macro, not this function */
+/* Use dalloc_add() macro, not this function */
 int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size)
 {
     AFP_ASSERT(talloc_chunk);
@@ -42,3 +42,76 @@ int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_
 
     return 0;
 }
+
+void *dalloc_get(const DALLOC_CTX *d, ...)
+{
+    EC_INIT;
+    void *p = NULL;
+    va_list args;
+    const char *type;
+    int elem;
+    const char *elemtype;
+
+    va_start(args, d);
+    type = va_arg(args, const char *);
+
+    if (STRCMP(type, !=, "DALLOC_CTX"))
+        EC_FAIL;
+
+    while (STRCMP(type, ==, "DALLOC_CTX")) {
+        elem = va_arg(args, int);
+        AFP_ASSERT(elem < talloc_array_length(d->dd_talloc_array));
+        d = d->dd_talloc_array[elem];
+        type = va_arg(args, const char *);
+    }
+
+    elem = va_arg(args, int);
+    AFP_ASSERT(elem < talloc_array_length(d->dd_talloc_array));
+
+    p = talloc_check_name(d->dd_talloc_array[elem], type);
+
+    va_end(args);
+
+EC_CLEANUP:
+    if (ret != 0)
+        p = NULL;
+    return p;
+}
+
+void *dalloc_value_for_key(const DALLOC_CTX *d, ...)
+{
+    EC_INIT;
+    void *p = NULL;
+    va_list args;
+    const char *type;
+    int elem;
+    const char *elemtype;
+    char *s;
+
+    va_start(args, d);
+    type = va_arg(args, const char *);
+
+    if (STRCMP(type, !=, "DALLOC_CTX"))
+        EC_FAIL;
+
+    while (STRCMP(type, ==, "DALLOC_CTX")) {
+        elem = va_arg(args, int);
+        AFP_ASSERT(elem < talloc_array_length(d->dd_talloc_array));
+        d = d->dd_talloc_array[elem];
+        type = va_arg(args, const char *);
+    }
+
+    for (elem = 0; elem + 1 < talloc_array_length(d->dd_talloc_array); elem += 2) {
+        memcpy(&s, d->dd_talloc_array[elem], sizeof(char *));
+        if (STRCMP(s, ==, type)) {
+            p = d->dd_talloc_array[elem + 1];
+            break;
+        }            
+    }
+    va_end(args);
+
+EC_CLEANUP:
+    if (ret != 0)
+        p = NULL;
+    return p;
+}