summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-03-09 00:17:14 +0000
committerJeremy Allison <jra@samba.org>2004-03-09 00:17:14 +0000
commitc9b7cbbfa572512cd0348817965b99fd1df01285 (patch)
tree9705a925b947e8a354250b8538c6a1be440aa5bf /source3/lib
parent3f14e8eb9dd9893ed195853dd7cf46ee5c2d5133 (diff)
downloadsamba-c9b7cbbfa572512cd0348817965b99fd1df01285.tar.gz
samba-c9b7cbbfa572512cd0348817965b99fd1df01285.tar.bz2
samba-c9b7cbbfa572512cd0348817965b99fd1df01285.zip
Added strstr_m() function. Use in all places where we might run into mb
(should fix the mb service name problem, can't remember the bugid). Jeremy. (This used to be commit 94a272b9a881ec0004c5da2a7242b0a818da5630)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util.c4
-rw-r--r--source3/lib/util_str.c78
2 files changed, 76 insertions, 6 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index f169a3103e..3a8d627ee9 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -551,7 +551,7 @@ void dos_clean_name(char *s)
/* remove any double slashes */
all_string_sub(s, "\\\\", "\\", 0);
- while ((p = strstr(s,"\\..\\")) != NULL) {
+ while ((p = strstr_m(s,"\\..\\")) != NULL) {
pstring s1;
*p = 0;
@@ -589,7 +589,7 @@ void unix_clean_name(char *s)
pstrcpy(s,"./");
}
- while ((p = strstr(s,"/../")) != NULL) {
+ while ((p = strstr_m(s,"/../")) != NULL) {
pstring s1;
*p = 0;
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 71c8d56e40..cad0df48a4 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -919,7 +919,7 @@ void string_sub(char *s,const char *pattern, const char *insert, size_t len)
if (len == 0)
len = ls + 1; /* len is number of *bytes* */
- while (lp <= ls && (p = strstr(s,pattern))) {
+ while (lp <= ls && (p = strstr_m(s,pattern))) {
if (ls + (li-lp) >= len) {
DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n",
(int)(ls + (li-lp) - len),
@@ -1004,7 +1004,7 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert)
}
}
- while ((p = strstr(s,pattern))) {
+ while ((p = strstr_m(s,pattern))) {
if (ld > 0) {
int offset = PTR_DIFF(s,string);
char *t = Realloc(string, ls + ld + 1);
@@ -1052,7 +1052,7 @@ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len)
if (len == 0)
len = ls + 1; /* len is number of *bytes* */
- while (lp <= ls && (p = strstr(s,pattern))) {
+ while (lp <= ls && (p = strstr_m(s,pattern))) {
if (ls + (li-lp) >= len) {
DEBUG(0,("ERROR: string overflow by %d in all_string_sub(%.50s, %d)\n",
(int)(ls + (li-lp) - len),
@@ -1294,6 +1294,76 @@ char *strnrchr_m(const char *s, char c, unsigned int n)
return (char *)(s+strlen(s2));
}
+/***********************************************************************
+ strstr_m - We convert via ucs2 for now.
+***********************************************************************/
+
+char *strstr_m(const char *src, const char *findstr)
+{
+ smb_ucs2_t *p;
+ smb_ucs2_t *src_w, *find_w;
+ const char *s;
+ char *s2;
+ char *retp;
+
+ /* Samba does single character findstr calls a *lot*. */
+ if (findstr[1] == '\0')
+ return strchr_m(src, *findstr);
+
+ /* We optimise for the ascii case, knowing that all our
+ supported multi-byte character sets are ascii-compatible
+ (ie. they match for the first 128 chars) */
+
+ for (s = src; *s && !(((unsigned char)s[0]) & 0x80); s++) {
+ if (*s == *findstr) {
+ if (strcmp(s, findstr) == 0) {
+ return (char *)s;
+ }
+ }
+ }
+
+ if (!*s)
+ return NULL;
+
+#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
+ /* With compose characters we must restart from the beginning. JRA. */
+ s = src;
+#endif
+
+ if (push_ucs2_allocate(&src_w, src) == (size_t)-1) {
+ DEBUG(0,("strstr_m: src malloc fail\n"));
+ return NULL;
+ }
+
+ if (push_ucs2_allocate(&find_w, findstr) == (size_t)-1) {
+ SAFE_FREE(src_w);
+ DEBUG(0,("strstr_m: find malloc fail\n"));
+ return NULL;
+ }
+
+ for (p = src_w; (p = strchr_w(p, *find_w)) != NULL; p++) {
+ if (strcmp_w(p, find_w) == 0)
+ break;
+ }
+ if (!p) {
+ SAFE_FREE(src_w);
+ SAFE_FREE(find_w);
+ return NULL;
+ }
+ *p = 0;
+ if (pull_ucs2_allocate(&s2, src_w) == (size_t)-1) {
+ SAFE_FREE(src_w);
+ SAFE_FREE(find_w);
+ DEBUG(0,("strstr_m: dest malloc fail\n"));
+ return NULL;
+ }
+ retp = (char *)(s+strlen(s2));
+ SAFE_FREE(src_w);
+ SAFE_FREE(find_w);
+ SAFE_FREE(s2);
+ return retp;
+}
+
/**
Convert a string to lower case.
**/
@@ -1624,7 +1694,7 @@ BOOL str_list_substitute(char **list, const char *pattern, const char *insert)
s = *list;
ls = (ssize_t)strlen(s);
- while ((p = strstr(s, pattern))) {
+ while ((p = strstr_m(s, pattern))) {
t = *list;
d = p -t;
if (ld) {