summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2002-06-14 16:02:59 +0000
committerSimo Sorce <idra@samba.org>2002-06-14 16:02:59 +0000
commite69fba09846f9bfd1564c4c684bb5d4fc059b02d (patch)
tree310c7e9a06c443aadb560a62f60809784db48218 /source3/lib
parenta98d2b1e1788d3207278340330052fc09245e8d2 (diff)
downloadsamba-e69fba09846f9bfd1564c4c684bb5d4fc059b02d.tar.gz
samba-e69fba09846f9bfd1564c4c684bb5d4fc059b02d.tar.bz2
samba-e69fba09846f9bfd1564c4c684bb5d4fc059b02d.zip
moved lp_list_* functions away from param/loadparm.c, put int lib/util_str.c
and renamed to str_list_* as it is a better name. Elrond should be satisfied now :) (This used to be commit 4ae260adb9505384fcccfb4c9929cb60a45f2e84)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/debug.c6
-rw-r--r--source3/lib/username.c6
-rw-r--r--source3/lib/util_str.c182
3 files changed, 188 insertions, 6 deletions
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index 255b0568f1..487b4957fe 100644
--- a/source3/lib/debug.c
+++ b/source3/lib/debug.c
@@ -423,16 +423,16 @@ BOOL debug_parse_levels(const char *params_str)
if (AllowDebugChange == False)
return True;
- params = lp_list_make(params_str);
+ params = str_list_make(params_str);
if (debug_parse_params(params, DEBUGLEVEL_CLASS,
DEBUGLEVEL_CLASS_ISSET))
{
debug_dump_status(5);
- lp_list_free(&params);
+ str_list_free(&params);
return True;
} else {
- lp_list_free(&params);
+ str_list_free(&params);
return False;
}
}
diff --git a/source3/lib/username.c b/source3/lib/username.c
index be8acfb4d6..c83b4eea28 100644
--- a/source3/lib/username.c
+++ b/source3/lib/username.c
@@ -197,7 +197,7 @@ BOOL map_username(char *user)
}
}
- dosuserlist = lp_list_make(dosname);
+ dosuserlist = str_list_make(dosname);
if (!dosuserlist) {
DEBUG(0,("Unable to build user list\n"));
return False;
@@ -210,13 +210,13 @@ BOOL map_username(char *user)
sscanf(unixname,"%s",user);
fstrcpy(last_to,user);
if(return_if_mapped) {
- lp_list_free (&dosuserlist);
+ str_list_free (&dosuserlist);
x_fclose(f);
return True;
}
}
- lp_list_free (&dosuserlist);
+ str_list_free (&dosuserlist);
}
x_fclose(f);
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index ff3559ce14..eac3ebe929 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -1013,3 +1013,185 @@ some platforms don't have strnlen
return i;
}
#endif
+
+
+
+/***********************************************************
+ List of Strings manipulation functions
+***********************************************************/
+
+#define S_LIST_ABS 16 /* List Allocation Block Size */
+
+char **str_list_make(const char *string)
+{
+ char **list, **rlist;
+ char *str, *s;
+ int num, lsize;
+ pstring tok;
+
+ if (!string || !*string) return NULL;
+ s = strdup(string);
+ if (!s) {
+ DEBUG(0,("str_list_make: Unable to allocate memory"));
+ return NULL;
+ }
+
+ num = lsize = 0;
+ list = NULL;
+
+ str = s;
+ while (next_token(&str, tok, LIST_SEP, sizeof(tok)))
+ {
+ if (num == lsize) {
+ lsize += S_LIST_ABS;
+ rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+ if (!rlist) {
+ DEBUG(0,("str_list_make: Unable to allocate memory"));
+ str_list_free(&list);
+ SAFE_FREE(s);
+ return NULL;
+ }
+ else list = rlist;
+ memset (&list[num], 0, ((sizeof(char**)) * (S_LIST_ABS +1)));
+ }
+
+ list[num] = strdup(tok);
+ if (!list[num]) {
+ DEBUG(0,("str_list_make: Unable to allocate memory"));
+ str_list_free(&list);
+ SAFE_FREE(s);
+ return NULL;
+ }
+
+ num++;
+ }
+
+ SAFE_FREE(s);
+ return list;
+}
+
+BOOL str_list_copy(char ***dest, char **src)
+{
+ char **list, **rlist;
+ int num, lsize;
+
+ *dest = NULL;
+ if (!src) return False;
+
+ num = lsize = 0;
+ list = NULL;
+
+ while (src[num])
+ {
+ if (num == lsize) {
+ lsize += S_LIST_ABS;
+ rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+ if (!rlist) {
+ DEBUG(0,("str_list_copy: Unable to allocate memory"));
+ str_list_free(&list);
+ return False;
+ }
+ else list = rlist;
+ memset (&list[num], 0, ((sizeof(char **)) * (S_LIST_ABS +1)));
+ }
+
+ list[num] = strdup(src[num]);
+ if (!list[num]) {
+ DEBUG(0,("str_list_copy: Unable to allocate memory"));
+ str_list_free(&list);
+ return False;
+ }
+
+ num++;
+ }
+
+ *dest = list;
+ return True;
+}
+
+/* return true if all the elemnts of the list matches exactly */
+BOOL str_list_compare(char **list1, char **list2)
+{
+ int num;
+
+ if (!list1 || !list2) return (list1 == list2);
+
+ for (num = 0; list1[num]; num++) {
+ if (!list2[num]) return False;
+ if (!strcsequal(list1[num], list2[num])) return False;
+ }
+ if (list2[num]) return False; /* if list2 has more elements than list1 fail */
+
+ return True;
+}
+
+void str_list_free(char ***list)
+{
+ char **tlist;
+
+ if (!list || !*list) return;
+ tlist = *list;
+ for(; *tlist; tlist++) SAFE_FREE(*tlist);
+ SAFE_FREE(*list);
+}
+
+BOOL str_list_substitute(char **list, const char *pattern, const char *insert)
+{
+ char *p, *s, *t;
+ ssize_t ls, lp, li, ld, i, d;
+
+ if (!list) return False;
+ if (!pattern) return False;
+ if (!insert) return False;
+
+ lp = (ssize_t)strlen(pattern);
+ li = (ssize_t)strlen(insert);
+ ld = li -lp;
+
+ while (*list)
+ {
+ s = *list;
+ ls = (ssize_t)strlen(s);
+
+ while ((p = strstr(s, pattern)))
+ {
+ t = *list;
+ d = p -t;
+ if (ld)
+ {
+ t = (char *) malloc(ls +ld +1);
+ if (!t) {
+ DEBUG(0,("str_list_substitute: Unable to allocate memory"));
+ return False;
+ }
+ memcpy(t, *list, d);
+ memcpy(t +d +li, p +lp, ls -d -lp +1);
+ SAFE_FREE(*list);
+ *list = t;
+ ls += ld;
+ s = t +d +li;
+ }
+
+ for (i = 0; i < li; i++) {
+ switch (insert[i]) {
+ case '`':
+ case '"':
+ case '\'':
+ case ';':
+ case '$':
+ case '%':
+ case '\r':
+ case '\n':
+ t[d +i] = '_';
+ break;
+ default:
+ t[d +i] = insert[i];
+ }
+ }
+ }
+
+ list++;
+ }
+
+ return True;
+}