]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ConfigParser.cc
4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
7 * Squid is the result of efforts by numerous individuals from
8 * the Internet community; see the CONTRIBUTORS file for full
9 * details. Many organizations have provided support for Squid's
10 * development; see the SPONSORS file for full details. Squid is
11 * Copyrighted (C) 2001 by the Regents of the University of
12 * California; see the COPYRIGHT file for full details. Squid
13 * incorporates software developed and/or copyrighted by other
14 * sources; see the CREDITS file for full details.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 #include "ConfigParser.h"
42 ConfigParser::destruct()
45 fatalf("Bungled %s line %d: %s",
46 cfg_filename
, config_lineno
, config_input_line
);
50 ConfigParser::strtokFile(void)
52 static int fromFile
= 0;
53 static FILE *wordFile
= NULL
;
56 LOCAL_ARRAY(char, buf
, CONFIG_LINE_LIMIT
);
61 t
= (strtok(NULL
, w_space
));
63 if (!t
|| *t
== '#') {
65 } else if (*t
== '\"' || *t
== '\'') {
66 /* quote found, start reading from file */
69 while (*t
&& *t
!= '\"' && *t
!= '\'')
74 if ((wordFile
= fopen(fn
, "r")) == NULL
) {
75 debugs(28, DBG_CRITICAL
, "strtokFile: " << fn
<< " not found");
80 setmode(fileno(wordFile
), O_TEXT
);
90 if (fgets(buf
, CONFIG_LINE_LIMIT
, wordFile
) == NULL
) {
91 /* stop reading from file */
99 /* skip leading and trailing white space */
100 t
+= strspn(buf
, w_space
);
101 t2
= t
+ strcspn(t
, w_space
);
102 t3
= t2
+ strspn(t2
, w_space
);
104 while (*t3
&& *t3
!= '#') {
105 t2
= t3
+ strcspn(t3
, w_space
);
106 t3
= t2
+ strspn(t2
, w_space
);
113 /* skip blank lines */
114 } while ( *t
== '#' || !*t
);
120 ConfigParser::ParseQuotedString(char **var
, bool *wasQuoted
)
123 ParseQuotedString(&sVar
, wasQuoted
);
124 *var
= xstrdup(sVar
.termedBuf());
128 ConfigParser::ParseQuotedString(String
*var
, bool *wasQuoted
)
130 // Get all of the remaining string
131 char *token
= strtok(NULL
, "");
136 token
= strtok(token
, w_space
);
141 } else if (wasQuoted
)
145 /* scan until the end of the quoted string, unescaping " and \ */
146 while (*s
&& *s
!= '"') {
148 const char * next
= s
+1; // may point to 0
149 memmove(s
, next
, strlen(next
) + 1);
155 debugs(3, DBG_CRITICAL
, "ParseQuotedString: missing '\"' at the end of quoted string" );
158 strtok(s
-1, "\""); /*Reset the strtok to point after the " */
165 ConfigParser::QuoteString(String
&var
)
167 static String quotedStr
;
168 const char *s
= var
.termedBuf();
169 bool needQuote
= false;
171 for (const char *l
= s
; !needQuote
&& *l
!= '\0'; ++l
)
172 needQuote
= !isalnum(*l
);
178 quotedStr
.append('"');
179 for (; *s
!= '\0'; ++s
) {
180 if (*s
== '"' || *s
== '\\')
181 quotedStr
.append('\\');
182 quotedStr
.append(*s
);
184 quotedStr
.append('"');
185 return quotedStr
.termedBuf();