Browse Source

Split uri_find_param out of uri_get_param_bool

Luke Dashjr 11 years ago
parent
commit
0c34bb2e42
1 changed files with 21 additions and 7 deletions
  1. 21 7
      util.c

+ 21 - 7
util.c

@@ -2132,29 +2132,43 @@ bool bfg_strtobool(const char * const s, char ** const endptr, __maybe_unused co
 	return false;
 	return false;
 }
 }
 
 
-bool uri_get_param_bool(const char * const uri, const char * const param, const bool defval)
+#define URI_FIND_PARAM_FOUND ((const char *)uri_find_param)
+
+const char *uri_find_param(const char * const uri, const char * const param, bool * const invert_p)
 {
 {
 	const char *start = strchr(uri, '#');
 	const char *start = strchr(uri, '#');
-	bool invert = false, foundval = true;
+	if (invert_p)
+		*invert_p = false;
 	if (!start)
 	if (!start)
-		return defval;
+		return NULL;
 	const char *p = start;
 	const char *p = start;
 	++start;
 	++start;
 nextmatch:
 nextmatch:
 	p = strstr(&p[1], param);
 	p = strstr(&p[1], param);
 	if (!p)
 	if (!p)
-		return defval;
+		return NULL;
 	const char *q = &p[strlen(param)];
 	const char *q = &p[strlen(param)];
 	if (isCalpha(q[0]))
 	if (isCalpha(q[0]))
 		goto nextmatch;
 		goto nextmatch;
-	if (p - start >= 2 && (!strncasecmp(&p[-2], "no", 2)) && !isCalpha(p[-3]))
-		invert = true;
+	if (invert_p && p - start >= 2 && (!strncasecmp(&p[-2], "no", 2)) && !isCalpha(p[-3]))
+		*invert_p = true;
 	else
 	else
 	if (isCalpha(p[-1]))
 	if (isCalpha(p[-1]))
 		goto nextmatch;
 		goto nextmatch;
 	if (q[0] == '=')
 	if (q[0] == '=')
+		return &q[1];
+	return URI_FIND_PARAM_FOUND;
+}
+
+bool uri_get_param_bool(const char * const uri, const char * const param, const bool defval)
+{
+	bool invert, foundval = true;
+	const char *q = uri_find_param(uri, param, &invert);
+	if (!q)
+		return defval;
+	else
+	if (q != URI_FIND_PARAM_FOUND)
 	{
 	{
-		++q;
 		char *end;
 		char *end;
 		bool v = bfg_strtobool(q, &end, 0);
 		bool v = bfg_strtobool(q, &end, 0);
 		if (end > q && !isCalpha(end[0]))
 		if (end > q && !isCalpha(end[0]))