-/*********************************************************************
- *
- * Function : unload_permissions_file
- *
- * Description : Unloads a permissions file.
- *
- * Parameters :
- * 1 : file_data = the data structure associated with the
- * permissions file.
- *
- * Returns : N/A
- *
- *********************************************************************/
-static void unload_permissions_file(void *file_data)
-{
- struct permissions_spec * next;
- struct permissions_spec * cur = (struct permissions_spec *)file_data;
- while (cur != NULL)
- {
- next = cur->next;
- unload_url(cur->url);
- freez(cur);
- cur = next;
- }
-
-}
-
-
-#ifdef TRUST_FILES
-/*********************************************************************
- *
- * Function : unload_trustfile
- *
- * Description : Unloads a trustfile.
- *
- * Parameters :
- * 1 : f = the data structure associated with the trustfile.
- *
- * Returns : N/A
- *
- *********************************************************************/
-static void unload_trustfile(void *f)
-{
- struct block_spec *b = (struct block_spec *)f;
- if (b == NULL) return;
-
- unload_trustfile(b->next);
-
- unload_url(b->url);
-
- freez(b);
-
-}
-#endif /* def TRUST_FILES */
-
-
-/*********************************************************************
- *
- * Function : unload_forwardfile
- *
- * Description : Unloads a forwardfile.
- *
- * Parameters :
- * 1 : f = the data structure associated with the forwardfile.
- *
- * Returns : N/A
- *
- *********************************************************************/
-static void unload_forwardfile(void *f)
-{
- struct forward_spec *b = (struct forward_spec *)f;
- if (b == NULL) return;
-
- unload_forwardfile(b->next);
-
- unload_url(b->url);
-
- freez(b->gw->gateway_host);
- freez(b->gw->forward_host);
-
- freez(b);
-
-}
-
-
-#ifdef PCRS
-/*********************************************************************
- *
- * Function : unload_re_filterfile
- *
- * Description : Unload the re_filter list.
- *
- * Parameters :
- * 1 : f = the data structure associated with the filterfile.
- *
- * Returns : N/A
- *
- *********************************************************************/
-static void unload_re_filterfile(void *f)
-{
- pcrs_job *joblist;
- struct re_filterfile_spec *b = (struct re_filterfile_spec *)f;
-
- if (b == NULL) return;
-
- destroy_list(b->patterns);
-
- joblist = b->joblist;
- while ( NULL != (joblist = pcrs_free_job(joblist)) ) {}
-
- freez(b);
-
-}
-#endif /* def PCRS */
-
-
-/*********************************************************************
- *
- * Function : check_file_changed
- *
- * Description : Helper function to check if a file needs reloading.
- * If "current" is still current, return it. Otherwise
- * allocates a new (zeroed) "struct file_list", fills
- * in the disk file name and timestamp, and returns it.
- *
- * Parameters :
- * 1 : current = The file_list currently being used - will
- * be checked to see if it is out of date.
- * May be NULL (which is treated as out of
- * date).
- * 2 : filename = Name of file to check.
- * 3 : newfl = New file list. [Output only]
- * This will be set to NULL, OR a struct
- * file_list newly allocated on the
- * heap, with the filename and lastmodified
- * fields filled, standard header giving file
- * name in proxy_args, and all others zeroed.
- * (proxy_args is only filled in if !defined
- * SPLIT_PROXY_ARGS and !suppress_blocklists).
- *
- * Returns : If file unchanged: 0 (and sets newfl == NULL)
- * If file changed: 1 and sets newfl != NULL
- * On error: 1 and sets newfl == NULL
- *
- *********************************************************************/
-static int check_file_changed(const struct file_list * current,
- const char * filename,
- struct file_list ** newfl)
-{
- struct file_list *fs;
- struct stat statbuf[1];
-
- *newfl = NULL;
-
- if (stat(filename, statbuf) < 0)
- {
- /* Error, probably file not found. */
- return 1;
- }
-
- if (current
- && (current->lastmodified == statbuf->st_mtime)
- && (0 == strcmp(current->filename, filename)))
- {
- return 0;
- }
-
- fs = (struct file_list *)zalloc(sizeof(struct file_list));
-
- if (fs == NULL)
- {
- /* Out of memory error */
- return 1;
- }
-
- fs->filename = strdup(filename);
- fs->lastmodified = statbuf->st_mtime;
-
- if (fs->filename == NULL)
- {
- /* Out of memory error */
- freez (fs);
- return 1;
- }
-
-#ifndef SPLIT_PROXY_ARGS
- if (!suppress_blocklists)
- {
- char * p = html_encode(filename);
- if (p)
- {
- fs->proxy_args = strsav(fs->proxy_args, "<h2>The file `");
- fs->proxy_args = strsav(fs->proxy_args, p);
- fs->proxy_args = strsav(fs->proxy_args,
- "' contains the following patterns</h2>\n");
- freez(p);
- }
- fs->proxy_args = strsav(fs->proxy_args, "<pre>");
- }
-#endif /* ndef SPLIT_PROXY_ARGS */
-
- *newfl = fs;
- return 1;
-}
-
-
-/*********************************************************************
- *
- * Function : read_config_line
- *
- * Description : Read a single non-empty line from a file and return
- * it. Trims comments, leading and trailing whitespace
- * and respects escaping of newline and comment char.
- * Also writes the file to fs->proxy_args.
- *
- * Parameters :
- * 1 : buf = Buffer to use.
- * 2 : buflen = Size of buffer in bytes.
- * 3 : fp = File to read from
- * 4 : fs = File will be written to fs->proxy_args. May
- * be NULL to disable this feature.
- *
- * Returns : NULL on EOF or error
- * Otherwise, returns buf.
- *
- *********************************************************************/
-char *read_config_line(char *buf, int buflen, FILE *fp, struct file_list *fs)
-{
- char *p, *q;
- char linebuf[BUFSIZ];
- int contflag = 0;
-
- *buf = '\0';
-
- while (fgets(linebuf, sizeof(linebuf), fp))
- {
-#ifndef SPLIT_PROXY_ARGS
- if (fs && !suppress_blocklists)
- {
- char *html_line = html_encode(linebuf);
- if (html_line != NULL)
- {
- fs->proxy_args = strsav(fs->proxy_args, html_line);
- freez(html_line);
- }
- fs->proxy_args = strsav(fs->proxy_args, "<br>");
- }
-#endif /* ndef SPLIT_PROXY_ARGS */
-
- /* Trim off newline */
- if ((p = strpbrk(linebuf, "\r\n")) != NULL)
- {
- *p = '\0';
- }
-
- /* Line continuation? Trim escape and set flag. */
- if ((p != linebuf) && (*--p == '\\'))
- {
- contflag = 1;
- *p = '\0';
- }
-
- /* If there's a comment char.. */
- if ((p = strpbrk(linebuf, "#")) != NULL)
- {
- /* ..and it's escaped, left-shift the line over the escape. */
- if ((p != linebuf) && (*(p-1) == '\\'))
- {
- q = p-1;
- while ((*q++ = *p++) != '\0') /* nop */;
- }
- /* Else, chop off the rest of the line */
- else
- {
- *p = '\0';
- }
- }
-
- /* Trim leading whitespace */
- p = linebuf;
- while (*p && ijb_isspace(*p))