httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@covalent.net
Subject patch - Config file reading change
Date Sun, 21 Jul 2002 06:43:22 GMT

A minor itch - we're currently unable to allow partially quoted strings
(which can be useful when doing m4 substititutions). Given the
ramfications - I'd like to see at least some positive humming from someone
who encounteres similar requirements in 'the real world(tm)'.

Attached is a patch for 1.3 which parses the lines below all
in the same way.

	ServerDirectory	/tmp/foo
	ServerDirectory	"/tmp/foo"
	ServerDirectory	/tmp/"foo"
	ServerDirectory	/tm"p/f"oo
	ServerDirectory	/tm\
	p/foo
	ServerDirectory	/tm\
		p/foo

Note the whitespace on the last one. Which is debatable. I like eating the
whitespace after a line-continuation as it allows me to construct nice
things like

	ServerDirectory /www/tmp/\
		foo

or some other alignment fun and games to please the eye. However it also
means that:

	ServerDirectory "C:/My Documents/www"
	ServerDirectory C:/"My Documents"/www
	ServerDirectory "C:/My \
	Documents/www"

are not equivament with:

	ServerDirectory "C:/My\
	 Documents/www"

but need to be done as

	ServerDirectory "C:/My"\
	" Documents/www"

I.e. the space needs to be escaped or "-ed.

The patch below is for 1.3 - I've done the same for 2.0 - except that
there is one section which seems windows specific and hen merging it into
2.0 - I came across this line which I do not quite get:

util.c
   if (c == EOF || c == 0x4 || c == LF || i >= (bufsize - 2)) {

what does it do - what is 0x4 ?

Dw
-- 
Dirk-Willem van Gulik

Index: util.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/util.c,v
retrieving revision 1.206
diff -u -r1.206 util.c
--- util.c	18 Jun 2002 00:59:58 -0000	1.206
+++ util.c	21 Jul 2002 06:37:34 -0000
@@ -756,28 +756,6 @@
     return res;
 }

-/* Get a word, (new) config-file style --- quoted strings and backslashes
- * all honored
- */
-
-static char *substring_conf(pool *p, const char *start, int len, char quote)
-{
-    char *result = ap_palloc(p, len + 2);
-    char *resp = result;
-    int i;
-
-    for (i = 0; i < len; ++i) {
-	if (start[i] == '\\' && (start[i + 1] == '\\'
-				 || (quote && start[i + 1] == quote)))
-	    *resp++ = start[++i];
-	else
-	    *resp++ = start[i];
-    }
-
-    *resp++ = '\0';
-    return result;
-}
-
 API_EXPORT(char *) ap_getword_conf_nc(pool *p, char **line)
 {
     return ap_getword_conf(p, (const char **) line);
@@ -785,9 +763,10 @@

 API_EXPORT(char *) ap_getword_conf(pool *p, const char **line)
 {
-    const char *str = *line, *strend;
-    char *res;
-    char quote;
+    char out_buff[MAX_STRING_LEN];
+    const char *str = *line;
+    char * out = out_buff;
+    char quote = '\0';

     while (*str && ap_isspace(*str))
 	++str;
@@ -797,34 +776,54 @@
 	return "";
     }

-    if ((quote = *str) == '"' || quote == '\'') {
-	strend = str + 1;
-	while (*strend && *strend != quote) {
-	    if (*strend == '\\' && strend[1] && strend[1] == quote)
-		strend += 2;
-	    else
-		++strend;
+    while (*str && (quote || !ap_isspace(*str)))
+    {
+	switch (*str) {
+	case '"':
+	case '\'':
+		if (quote == *str)
+			quote = '\0';
+		else
+			quote = *str;
+		break;
+	case '\\':
+		/* XX We are quite anal about quoting. I.e.
+	         *    we only accept the escaped \ and the
+	         *    actual quote you are using as escaped.
+		 *    and note the interaction with the _get_line_cfg
+	         */
+		if ((str[1] == '\\') || (quote && str[1] == quote))
+			*(out++) = *(++str);
+		else
+			*out++ = *str++;
+		break;
+	default:
+		if ((*str == '#') && (!quote)) {
+	    		ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, NULL,
+			 	"Apache does not support line-end comments. Consider "
+				"using quotes around argument: \"%s\"", str);
+			/* Actually it propably would if we broke out
+                         * of the loop at this point.
+	 		 */
+		}
+		*out++ = *str;
+		break;
 	}
-	res = substring_conf(p, str + 1, strend - str - 1, quote);
+	str++;
+    };
+    *out ='\0';

-	if (*strend == quote)
-	    ++strend;
-    }
-    else {
-	if (*str == '#')
-	    ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, NULL,
-			 "Apache does not support line-end comments. Consider using quotes around argument: \"%s\"",
str);
-	strend = str;
-	while (*strend && !ap_isspace(*strend))
-	    ++strend;
+    while (*str && ap_isspace(*str))
+	++str;

-	res = substring_conf(p, str, strend - str, 0);
-    }
+    *line = str;

-    while (*strend && ap_isspace(*strend))
-	++strend;
-    *line = strend;
-    return res;
+
+    return ap_pstrdup(p,out_buff);
 }

 API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp)
@@ -971,17 +970,29 @@
 	char *cp;
 	char *cbuf = buf;
 	size_t cbufsize = bufsize;
+	int lcont = 0;

 	while (1) {
 	    ++cfp->line_number;
 	    if (cfp->getstr(cbuf, cbufsize, cfp->param) == NULL)
 		return 1;

+	    cp = cbuf;
+
+	    /* After line continuation strip the initial
+	     * whitespace by shifting the read buffer.
+	     */
+	    if (lcont) {
+	    	while (cp < cbuf+cbufsize && ap_isspace(*cp))
+			cp++;
+		if (cp != cbuf)
+			ap_cpystrn(cbuf,cp,cbufsize-(cp-cbuf));
+	    }
+            lcont = 0;
 	    /*
 	     *  check for line continuation,
 	     *  i.e. match [^\\]\\[\r]\n only
 	     */
-	    cp = cbuf;
 	    while (cp < cbuf+cbufsize && *cp != '\0')
 		cp++;
 	    if (cp > cbuf && cp[-1] == LF) {
@@ -995,6 +1006,7 @@
 			 * line continuation requested -
 			 * then remove backslash and continue
 			 */
+			lcont = 1;
 			cbufsize -= (cp-cbuf);
 			cbuf = cp;
 			continue;


Mime
View raw message