/*
- * $Id: cache_cf.cc,v 1.411 2002/09/01 15:16:33 hno Exp $
+ * $Id: cache_cf.cc,v 1.412 2002/09/07 14:55:24 hno Exp $
*
* DEBUG: section 3 Configuration File Parsing
* AUTHOR: Harvest Derived
static void parseTimeLine(time_t * tptr, const char *units);
static void parse_ushort(u_short * var);
static void parse_string(char **);
-void parse_wordlist(wordlist **);
static void default_all(void);
static void defaults_if_none(void);
static int parse_line(char *);
if (stat(path, &sb) < 0)
fatalf("%s: %s", path, xstrerror());
}
+
+char *
+strtokFile(void)
+{
+ char *t, *fn;
+ LOCAL_ARRAY(char, buf, 256);
+
+ strtok_again:
+ if (!aclFromFile) {
+ t = (strtok(NULL, w_space));
+ if (!t || *t == '#') {
+ return NULL;
+ } else if (*t == '\"' || *t == '\'') {
+ /* quote found, start reading from file */
+ fn = ++t;
+ while (*t && *t != '\"' && *t != '\'')
+ t++;
+ *t = '\0';
+ if ((aclFile = fopen(fn, "r")) == NULL) {
+ debug(28, 0) ("strtokFile: %s not found\n", fn);
+ return (NULL);
+ }
+#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)
+ setmode(fileno(aclFile), O_TEXT);
+#endif
+ aclFromFile = 1;
+ } else {
+ return t;
+ }
+ }
+ /* aclFromFile */
+ if (fgets(buf, 256, aclFile) == NULL) {
+ /* stop reading from file */
+ fclose(aclFile);
+ aclFromFile = 0;
+ goto strtok_again;
+ } else {
+ t = buf;
+ /* skip leading and trailing white space */
+ t += strspn(buf, w_space);
+ t[strcspn(t, w_space)] = '\0';
+ /* skip comments */
+ if (*t == '#')
+ goto strtok_again;
+ /* skip blank lines */
+ if (!*t)
+ goto strtok_again;
+ return t;
+ }
+}
+
/*
- * $Id: external_acl.cc,v 1.12 2002/09/07 14:39:52 hno Exp $
+ * $Id: external_acl.cc,v 1.13 2002/09/07 14:55:24 hno Exp $
*
* DEBUG: section 82 External ACL
* AUTHOR: Henrik Nordstrom, MARA Systems AB
static int external_acl_entry_expired(external_acl * def, external_acl_entry * entry);
static void external_acl_cache_touch(external_acl * def, external_acl_entry * entry);
-extern char *strtokFile(void);
-static void strwordquote(MemBuf * mb, const char *str);
-
/*******************************************************************
* external_acl cache entry
* Used opaqueue in the interface
cbdataReferenceDone(state->def);
}
-/* FIXME: This should be moved to tools.c */
-static char *
-strwordtok(char *buf, char **t)
-{
- unsigned char *word = NULL;
- unsigned char *p = (unsigned char *) buf;
- unsigned char *d;
- unsigned char ch;
- int quoted = 0;
- if (!p)
- p = (unsigned char *) *t;
- if (!p)
- goto error;
- while (*p && isspace(*p))
- p++;
- if (!*p)
- goto error;
- word = d = p;
- while ((ch = *p)) {
- switch (ch) {
- case '\\':
- p++;
- *d++ = ch = *p;
- if (ch)
- p++;
- break;
- case '"':
- quoted = !quoted;
- p++;
- default:
- if (!quoted && isspace(*p)) {
- p++;
- goto done;
- }
- *d++ = *p++;
- break;
- }
- }
- done:
- *d++ = '\0';
- error:
- *t = (char *) p;
- return (char *) word;
-}
-
-static void
-strwordquote(MemBuf * mb, const char *str)
-{
- int quoted = 0;
- if (strchr(str, ' ')) {
- quoted = 1;
- memBufAppend(mb, "\"", 1);
- }
- while (*str) {
- int l = strcspn(str, "\"\\");
- memBufAppend(mb, str, l);
- str += l;
- while (*str == '"' || *str == '\\') {
- memBufAppend(mb, "\\", 1);
- memBufAppend(mb, str, 1);
- str++;
- }
- }
- if (quoted)
- memBufAppend(mb, "\"", 1);
-}
-
/*
* The helper program receives queries on stdin, one
* per line, and must return the result on on stdout as
/*
- * $Id: protos.h,v 1.442 2002/07/20 12:30:04 hno Exp $
+ * $Id: protos.h,v 1.443 2002/09/07 14:55:24 hno Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
extern void parseEtcHosts(void);
extern int getMyPort(void);
+static void strwordquote(MemBuf * mb, const char *str);
+void strwordquote(MemBuf * mb, const char *str);
+
#if USE_HTCP
extern void htcpInit(void);
extern void htcpQuery(StoreEntry * e, request_t * req, peer * p);
extern void externalAclLookup(aclCheck_t * ch, void *acl_data, EAH * handler, void *data);
extern void externalAclInit(void);
extern void externalAclShutdown(void);
+extern char *strtokFile(void);
#endif /* SQUID_PROTOS_H */
/*
- * $Id: tools.cc,v 1.221 2002/09/01 15:16:35 hno Exp $
+ * $Id: tools.cc,v 1.222 2002/09/07 14:55:24 hno Exp $
*
* DEBUG: section 21 Misc Functions
* AUTHOR: Harvest Derived
fatal("No port defined");
return 0; /* NOT REACHED */
}
+
+/*
+ * Similar to strtok, but has some rudimentary knowledge
+ * of quoting
+ */
+static char *
+strwordtok(char *buf, char **t)
+{
+ unsigned char *word = NULL;
+ unsigned char *p = (unsigned char *) buf;
+ unsigned char *d;
+ unsigned char ch;
+ int quoted = 0;
+ if (!p)
+ p = (unsigned char *) *t;
+ if (!p)
+ goto error;
+ while (*p && isspace(*p))
+ p++;
+ if (!*p)
+ goto error;
+ word = d = p;
+ while ((ch = *p)) {
+ switch (ch) {
+ case '\\':
+ p++;
+ *d++ = ch = *p;
+ if (ch)
+ p++;
+ break;
+ case '"':
+ quoted = !quoted;
+ p++;
+ default:
+ if (!quoted && isspace(*p)) {
+ p++;
+ goto done;
+ }
+ *d++ = *p++;
+ break;
+ }
+ }
+ done:
+ *d++ = '\0';
+ error:
+ *t = (char *) p;
+ return (char *) word;
+}
+
+/*
+ * Inverse of strwordtok. Quotes a word if needed
+ */
+static void
+strwordquote(MemBuf * mb, const char *str)
+{
+ int quoted = 0;
+ if (strchr(str, ' ')) {
+ quoted = 1;
+ memBufAppend(mb, "\"", 1);
+ }
+ while (*str) {
+ int l = strcspn(str, "\"\\");
+ memBufAppend(mb, str, l);
+ str += l;
+ while (*str == '"' || *str == '\\') {
+ memBufAppend(mb, "\\", 1);
+ memBufAppend(mb, str, 1);
+ str++;
+ }
+ }
+ if (quoted)
+ memBufAppend(mb, "\"", 1);
+}