summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util_array.c57
1 files changed, 42 insertions, 15 deletions
diff --git a/source3/lib/util_array.c b/source3/lib/util_array.c
index 5edb6ebf32..71f7046d62 100644
--- a/source3/lib/util_array.c
+++ b/source3/lib/util_array.c
@@ -39,26 +39,40 @@ void free_void_array(uint32 num_entries, void **entries,
}
}
-void* add_item_to_array(uint32 *len, void ***array, const void *item,
+void* add_copy_to_array(uint32 *len, void ***array, const void *item,
void*(item_dup)(const void*), BOOL alloc_anyway)
{
- if (len == NULL || array == NULL || item_dup == NULL)
+ if (len == NULL || array == NULL)
{
return NULL;
}
- (*array) = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0]));
-
- if ((*array) != NULL)
+ if (item != NULL || alloc_anyway)
{
void* copy = NULL;
if (item != NULL || alloc_anyway)
{
copy = item_dup(item);
}
- (*array)[(*len)] = copy;
+ add_item_to_array(len, array, copy);
+ }
+ return NULL;
+}
+
+void* add_item_to_array(uint32 *len, void ***array, void *item)
+{
+ if (len == NULL || array == NULL)
+ {
+ return NULL;
+ }
+
+ (*array) = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0]));
+
+ if ((*array) != NULL)
+ {
+ (*array)[(*len)] = item;
(*len)++;
- return copy;
+ return item;
}
return NULL;
}
@@ -72,11 +86,24 @@ void free_char_array(uint32 num_entries, char **entries)
char* add_chars_to_array(uint32 *len, char ***array, const char *name)
{
void*(*fn)(const void*) = (void*(*)(const void*))&strdup;
- return (char*)add_item_to_array(len,
+ return (char*)add_copy_to_array(len,
(void***)array, (const void*)name, *fn, False);
}
+void free_con_array(uint32 num_entries, struct cli_connection **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&cli_connection_free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+struct cli_connection* add_con_to_array(uint32 *len, struct cli_connection ***array, struct cli_connection *con)
+{
+ return (struct cli_connection*)add_item_to_array(len,
+ (void***)array, (void*)con);
+
+}
+
static uint32 *uint32_dup(const uint32* from)
{
if (from != NULL)
@@ -100,7 +127,7 @@ void free_uint32_array(uint32 num_entries, uint32 **entries)
uint32* add_uint32s_to_array(uint32 *len, uint32 ***array, const uint32 *name)
{
void*(*fn)(const void*) = (void*(*)(const void*))&uint32_dup;
- return (uint32*)add_item_to_array(len,
+ return (uint32*)add_copy_to_array(len,
(void***)array, (const void*)name, *fn, False);
}
@@ -114,7 +141,7 @@ void free_unistr_array(uint32 num_entries, UNISTR2 **entries)
UNISTR2* add_unistr_to_array(uint32 *len, UNISTR2 ***array, UNISTR2 *name)
{
void*(*fn)(const void*) = (void*(*)(const void*))&unistr2_dup;
- return (UNISTR2*)add_item_to_array(len,
+ return (UNISTR2*)add_copy_to_array(len,
(void***)array, (const void*)name, *fn, False);
}
@@ -127,7 +154,7 @@ void free_sid_array(uint32 num_entries, DOM_SID **entries)
DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid)
{
void*(*fn)(const void*) = (void*(*)(const void*))&sid_dup;
- return (DOM_SID*)add_item_to_array(len,
+ return (DOM_SID*)add_copy_to_array(len,
(void***)array, (const void*)sid, *fn, False);
}
@@ -177,7 +204,7 @@ PRINTER_INFO_2 *add_print2_to_array(uint32 *len, PRINTER_INFO_2 ***array,
const PRINTER_INFO_2 *prt)
{
void*(*fn)(const void*) = (void*(*)(const void*))&prt2_dup;
- return (PRINTER_INFO_2*)add_item_to_array(len,
+ return (PRINTER_INFO_2*)add_copy_to_array(len,
(void***)array, (const void*)prt, *fn, True);
}
@@ -208,7 +235,7 @@ PRINTER_INFO_1 *add_print1_to_array(uint32 *len, PRINTER_INFO_1 ***array,
const PRINTER_INFO_1 *prt)
{
void*(*fn)(const void*) = (void*(*)(const void*))&prt1_dup;
- return (PRINTER_INFO_1*)add_item_to_array(len,
+ return (PRINTER_INFO_1*)add_copy_to_array(len,
(void***)array, (const void*)prt, *fn, True);
}
@@ -239,7 +266,7 @@ JOB_INFO_1 *add_job1_to_array(uint32 *len, JOB_INFO_1 ***array,
const JOB_INFO_1 *job)
{
void*(*fn)(const void*) = (void*(*)(const void*))&job1_dup;
- return (JOB_INFO_1*)add_item_to_array(len,
+ return (JOB_INFO_1*)add_copy_to_array(len,
(void***)array, (const void*)job, *fn, True);
}
@@ -270,7 +297,7 @@ JOB_INFO_2 *add_job2_to_array(uint32 *len, JOB_INFO_2 ***array,
const JOB_INFO_2 *job)
{
void*(*fn)(const void*) = (void*(*)(const void*))&job2_dup;
- return (JOB_INFO_2*)add_item_to_array(len,
+ return (JOB_INFO_2*)add_copy_to_array(len,
(void***)array, (const void*)job, *fn, True);
}