- FILE *fp;
-
- struct forward_spec *b, *bl;
- char buf[BUFSIZ];
- char *p, *tmp;
- char *vec[4];
- int n;
- struct file_list *fs;
- const struct gateway *gw;
-
- if (!check_file_changed(current_forwardfile, csp->config->forwardfile, &fs))
- {
- /* No need to load */
- if (csp)
- {
- csp->flist = current_forwardfile;
- }
- return(0);
- }
- if (!fs)
- {
- goto load_forwardfile_error;
- }
-
- fs->f = bl = (struct forward_spec *)zalloc(sizeof(*bl));
-
- if ((fs == NULL) || (bl == NULL))
- {
- goto load_forwardfile_error;
- }
-
- if ((fp = fopen(csp->config->forwardfile, "r")) == NULL)
- {
- goto load_forwardfile_error;
- }
-
- tmp = NULL;
-
- while (read_config_line(buf, sizeof(buf), fp, fs) != NULL)
- {
- freez(tmp);
-
- tmp = strdup(buf);
-
- n = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
-
- if (n != 4)
- {
- log_error(LOG_LEVEL_ERROR, "error in forwardfile: %s", buf);
- continue;
- }
-
- strcpy(buf, vec[0]);
-
- /* skip lines containing only ~ */
- if (*buf == '\0')
- {
- continue;
- }
-
- /* allocate a new node */
- if (((b = zalloc(sizeof(*b))) == NULL)
- )
- {
- fclose(fp);
- goto load_forwardfile_error;
- }
-
- /* add it to the list */
- b->next = bl->next;
- bl->next = b;
-
- /* Save the URL pattern */
- if (create_url_spec(b->url, buf))
- {
- fclose(fp);
- goto load_forwardfile_error;
- }
-
- /* now parse the gateway specs */
-
- p = vec[2];
-
- for (gw = gateways; gw->name; gw++)
- {
- if (strcmp(gw->name, p) == 0)
- {
- break;
- }
- }
-
- if (gw->name == NULL)
- {
- goto load_forwardfile_error;
- }
-
- /* save this as the gateway type */
- *b->gw = *gw;
-
- /* now parse the gateway host[:port] spec */
- p = vec[3];
-
- if (strcmp(p, ".") != 0)
- {
- b->gw->gateway_host = strdup(p);
-
- if ((p = strchr(b->gw->gateway_host, ':')))
- {
- *p++ = '\0';
- b->gw->gateway_port = atoi(p);
- }
-
- if (b->gw->gateway_port <= 0)
- {
- goto load_forwardfile_error;
- }
- }
-
- /* now parse the forwarding spec */
- p = vec[1];
-
- if (strcmp(p, ".") != 0)
- {
- b->gw->forward_host = strdup(p);
-
- if ((p = strchr(b->gw->forward_host, ':')))
- {
- *p++ = '\0';
- b->gw->forward_port = atoi(p);
- }
-
- if (b->gw->forward_port <= 0)
- {
- b->gw->forward_port = 8000;
- }
- }
- }
-
- freez(tmp);
-
- fclose(fp);
-
-#ifndef SPLIT_PROXY_ARGS
- if (!suppress_blocklists)
- {
- fs->proxy_args = strsav(fs->proxy_args, "</pre>");
- }
-#endif /* ndef SPLIT_PROXY_ARGS */