home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Magazine / wwwoffle-2.1.tar.gz / wwwoffle-2.1 / wwwoffle.c < prev    next >
C/C++ Source or Header  |  1998-03-02  |  20KB  |  675 lines

  1. /***************************************
  2.   $Header: /home/amb/wwwoffle/RCS/wwwoffle.c 2.13 1998/03/02 15:05:59 amb Exp $
  3.  
  4.   WWWOFFLE - World Wide Web Offline Explorer - Version 2.1.
  5.   A user level program to interact with the server.
  6.   ******************/ /******************
  7.   Written by Andrew M. Bishop
  8.  
  9.   This file Copyright 1996,97,98 Andrew M. Bishop
  10.   It may be distributed under the GNU Public License, version 2, or
  11.   any higher version.  See section COPYING of the GNU Public license
  12.   for conditions under which this file may be redistributed.
  13.   ***************************************/
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. #include <unistd.h>
  21. #include <sys/stat.h>
  22. #include <fcntl.h>
  23.  
  24. #include "version.h"
  25. #include "wwwoffle.h"
  26. #include "misc.h"
  27. #include "config.h"
  28. #include "sockets.h"
  29. #include "errors.h"
  30.  
  31.  
  32. static void usage(int verbose);
  33.  
  34.  
  35. /*+ The action to perform. +*/
  36. typedef enum _Action
  37. {
  38.  None,                          /*+ Undecided. +*/
  39.  Online,                        /*+ Tell the server that we are online. +*/
  40.  Autodial,                      /*+ Tell the server that we are in autodial mode. +*/
  41.  Offline,                       /*+ Tell the server that we are offline. +*/
  42.  Fetch,                         /*+ Tell the server to fetch the requested pages. +*/
  43.  Config,                        /*+ Tell the server to re-read the configuration file. +*/
  44.  Purge,                         /*+ Tell the server to purge pages. +*/
  45.  Kill,                          /*+ Tell the server to exit. +*/
  46.  Get,                           /*+ Tell the server to get pages. +*/
  47.  Output                         /*+ Get a page from the server and output it. +*/
  48. }
  49. Action;
  50.  
  51.  
  52. static void add_url_file(char *url_file);
  53.  
  54. /*+ The list of URLs or files. +*/
  55. char **url_file_list=NULL;
  56. /*+ The number of URLs or files. +*/
  57. int n_url_file_list=0;
  58.  
  59.  
  60. /*++++++++++++++++++++++++++++++++++++++
  61.   The main program.
  62.   ++++++++++++++++++++++++++++++++++++++*/
  63.  
  64. int main(int argc, char** argv)
  65. {
  66.  int i;
  67.  int force=0,images=0,frames=0,recursive_depth=0,recursive_mode=0;
  68.  
  69.  Action action=None;
  70.  
  71.  char *env=NULL;
  72.  char *host=NULL;
  73.  int port=0;
  74.  
  75.  /* Parse the command line options */
  76.  
  77.  ConfigFile=NULL;
  78.  
  79.  if(argc==1)
  80.     usage(0);
  81.  
  82.  for(i=1;i<argc;i++)
  83.    {
  84.     if(!strcmp(argv[i],"-h"))
  85.        usage(1);
  86.  
  87.     if(!strcmp(argv[i],"-o"))
  88.       {
  89.        if(action!=None)
  90.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  91.        action=Output;
  92.        argv[i]=NULL;
  93.        continue;
  94.       }
  95.  
  96.     if(!strcmp(argv[i],"-F"))
  97.       {
  98.        if(action!=None && action!=Get)
  99.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  100.        action=Get;
  101.        if(force)
  102.          {fprintf(stderr,"wwwoffle: Only one '-F' argument may be given.\n"); exit(1);}
  103.        force=1;
  104.        argv[i]=NULL;
  105.        continue;
  106.       }
  107.  
  108.     if(!strcmp(argv[i],"-i"))
  109.       {
  110.        if(action!=None && action!=Get)
  111.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  112.        action=Get;
  113.        if(images)
  114.          {fprintf(stderr,"wwwoffle: Only one '-i' argument may be given.\n"); exit(1);}
  115.        images=1;
  116.        argv[i]=NULL;
  117.        continue;
  118.       }
  119.  
  120.     if(!strcmp(argv[i],"-f"))
  121.       {
  122.        if(action!=None && action!=Get)
  123.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  124.        action=Get;
  125.        if(frames)
  126.          {fprintf(stderr,"wwwoffle: Only one '-f' argument may be given.\n"); exit(1);}
  127.        frames=1;
  128.        argv[i]=NULL;
  129.        continue;
  130.       }
  131.  
  132.     if(!strncmp(argv[i],"-R",2) || !strncmp(argv[i],"-r",2) || !strncmp(argv[i],"-d",2))
  133.       {
  134.        if(action!=None && action!=Get)
  135.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  136.        action=Get;
  137.  
  138.        if(recursive_depth)
  139.          {fprintf(stderr,"wwwoffle: Only one '-d', '-r' or '-R' argument may be given.\n"); exit(1);}
  140.  
  141.        if(argv[i][1]=='d')
  142.           recursive_mode=1;
  143.        else if(argv[i][1]=='r')
  144.           recursive_mode=2;
  145.        else /* argv[i][1]=='R' */
  146.           recursive_mode=3;
  147.  
  148.        if(argv[i][2])
  149.           recursive_depth=atoi(&argv[i][2]);
  150.        else
  151.           recursive_depth=1;
  152.        if(recursive_depth<=0)
  153.          {fprintf(stderr,"wwwoffle: The '-%c' argument may only be followed by a positive integer.\n",argv[i][1]); exit(1);}
  154.  
  155.        argv[i]=NULL;
  156.        continue;
  157.       }
  158.  
  159.     if(!strcmp(argv[i],"-p"))
  160.       {
  161.        char *colon;
  162.  
  163.        if(++i>=argc)
  164.          {fprintf(stderr,"wwwoffle: The '-p' argument requires a hostname and optionally a port number.\n"); exit(1);}
  165.  
  166.        if(ConfigFile)
  167.          {fprintf(stderr,"wwwoffle: The '-p' and '-c' options cannot be used together.\n"); exit(1);}
  168.  
  169.        if((colon=strchr(argv[i],':')))
  170.          {
  171.           *colon++=0;
  172.  
  173.           port=atoi(colon);
  174.  
  175.           if(port<=0 || port>=65536)
  176.             {fprintf(stderr,"wwwoffle: The port number %d '%s' is invalid.\n",port,argv[i]); exit(1);}
  177.          }
  178.  
  179.        host=argv[i];
  180.  
  181.        argv[i-1]=NULL;
  182.        argv[i]=NULL;
  183.        continue;
  184.       }
  185.  
  186.     if(!strcmp(argv[i],"-c"))
  187.       {
  188.        if(++i>=argc)
  189.          {fprintf(stderr,"wwwoffle: The '-c' argument requires a configuration file name.\n"); exit(1);}
  190.  
  191.        if(host)
  192.          {fprintf(stderr,"wwwoffle: The '-p' and '-c' options cannot be used together.\n"); exit(1);}
  193.  
  194.        ConfigFile=argv[i];
  195.  
  196.        argv[i-1]=NULL;
  197.        argv[i]=NULL;
  198.        continue;
  199.       }
  200.  
  201.     if(!strcmp(argv[i],"-on") || !strcmp(argv[i],"-online"))
  202.       {
  203.        if(action!=None)
  204.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  205.        action=Online;
  206.        argv[i]=NULL;
  207.        continue;
  208.       }
  209.  
  210.     if(!strcmp(argv[i],"-auto") || !strcmp(argv[i],"-autodial"))
  211.       {
  212.        if(action!=None)
  213.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  214.        action=Autodial;
  215.        argv[i]=NULL;
  216.        continue;
  217.       }
  218.  
  219.     if(!strcmp(argv[i],"-off") || !strcmp(argv[i],"-offline"))
  220.       {
  221.        if(action!=None)
  222.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  223.        action=Offline;
  224.        argv[i]=NULL;
  225.        continue;
  226.       }
  227.  
  228.     if(!strcmp(argv[i],"-fetch"))
  229.       {
  230.        if(action!=None)
  231.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  232.        action=Fetch;
  233.        argv[i]=NULL;
  234.        continue;
  235.       }
  236.  
  237.     if(!strcmp(argv[i],"-config"))
  238.       {
  239.        if(action!=None)
  240.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  241.        action=Config;
  242.        argv[i]=NULL;
  243.        continue;
  244.       }
  245.  
  246.     if(!strcmp(argv[i],"-purge"))
  247.       {
  248.        if(action!=None)
  249.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  250.        action=Purge;
  251.        argv[i]=NULL;
  252.        continue;
  253.       }
  254.  
  255.     if(!strcmp(argv[i],"-kill"))
  256.       {
  257.        if(action!=None)
  258.          {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
  259.        action=Kill;
  260.        argv[i]=NULL;
  261.        continue;
  262.       }
  263.  
  264.     if(argv[i][0]=='-' && argv[i][1])
  265.       {
  266.        fprintf(stderr,"wwwoffle: Unknown option '%s'.\n\n",argv[i]);
  267.        usage(0);
  268.       }
  269.  
  270.     add_url_file(argv[i]);
  271.    }
  272.  
  273.  if(action==None)
  274.     action=Get;
  275.  
  276.  /* Initialise things. */
  277.  
  278.  if(!ConfigFile && !host && (env=getenv("WWWOFFLE_PROXY")))
  279.    {
  280.     if(*env=='/')
  281.        ConfigFile=env;
  282.     else
  283.       {
  284.        char *colon1,*colon2;
  285.  
  286.        host=(char*)malloc(strlen(env)+1);
  287.        strcpy(host,env);
  288.  
  289.        if((colon1=strchr(host,':')))
  290.          {
  291.           *colon1=0;
  292.           if((colon2=strchr(colon1+1,':')))
  293.             {
  294.              *colon2=0;
  295.              if(action==Get || action==Output)
  296.                 port=atoi(colon1+1);
  297.              else
  298.                 port=atoi(colon2+1);
  299.             }
  300.           else
  301.              port=atoi(colon1+1);
  302.  
  303.           if(port<=0 || port>=65536)
  304.             {fprintf(stderr,"wwwoffle: The port number %d '%s' is invalid.\n",port,env); exit(1);}
  305.          }
  306.       }
  307.    }
  308.  
  309.  InitErrorHandler("wwwoffle",0,1);
  310.  
  311.  if(ConfigFile)
  312.    {
  313.     if(ReadConfigFile(2))
  314.        PrintMessage(Fatal,"Error in configuration file '%s'.",ConfigFile);
  315.  
  316.     host=GetLocalHost(0);
  317.    }
  318.  
  319.  /* The connections to the WWWOFFLE server. */
  320.  
  321.  if(action!=Get && action!=Output)
  322.    {
  323.     int socket;
  324.     char *buffer=NULL;
  325.  
  326.     socket=OpenClientSocket(host?host:"localhost",port?port:WWWOFFLE_Port);
  327.     init_buffer(socket);
  328.  
  329.     if(socket==-1)
  330.        PrintMessage(Fatal,"Cannot open connection to wwwoffle server %s port %d.",host?host:"localhost",port?port:WWWOFFLE_Port);
  331.  
  332.     /* Send the message. */
  333.  
  334.     if(PassWord)
  335.        write_formatted(socket,"WWWOFFLE PASSWORD %s\r\n",PassWord);
  336.  
  337.     if(action==Online)
  338.        write_string(socket,"WWWOFFLE ONLINE\r\n");
  339.     else if(action==Autodial)
  340.        write_string(socket,"WWWOFFLE AUTODIAL\r\n");
  341.     else if(action==Offline)
  342.        write_string(socket,"WWWOFFLE OFFLINE\r\n");
  343.     else if(action==Fetch)
  344.        write_string(socket,"WWWOFFLE FETCH\r\n");
  345.     else if(action==Config)
  346.        write_string(socket,"WWWOFFLE CONFIG\r\n");
  347.     else if(action==Purge)
  348.        write_string(socket,"WWWOFFLE PURGE\r\n");
  349.     else if(action==Kill)
  350.        write_string(socket,"WWWOFFLE KILL\r\n");
  351.     else
  352.        write_string(socket,"WWWOFFLE BOGUS\r\n");
  353.  
  354.     while((buffer=read_line(socket,buffer)))
  355.       {
  356.        fputs(buffer,stdout);
  357.        fflush(stdout);
  358.       }
  359.  
  360.     CloseSocket(socket);
  361.    }
  362.  
  363.  /* The connections to the http proxy. */
  364.  
  365.  else if(action==Get)
  366.    {
  367.     URL *Url;
  368.     struct stat buf;
  369.     char refresh[32];
  370.  
  371.     strcpy(refresh,"refresh");
  372.     if(images)
  373.        strcat(refresh,"-images");
  374.     if(frames)
  375.        strcat(refresh,"-frames");
  376.     if(force)
  377.        strcat(refresh,"-force");
  378.     if(recursive_depth)
  379.       {
  380.        if(recursive_mode==1)
  381.           strcat(refresh,"-dir");
  382.        else if(recursive_mode==2)
  383.           strcat(refresh,"-host");
  384.        else /* recursive_mode==3 */
  385.           strcat(refresh,"-any");
  386.        sprintf(&refresh[strlen(refresh)],"-%d",recursive_depth);
  387.       }
  388.     if(!images && !frames && !recursive_depth && !force)
  389.        strcat(refresh,"-none");
  390.  
  391.     for(i=0;i<n_url_file_list;i++)
  392.        if(strcmp(url_file_list[i],"-") && stat(url_file_list[i],&buf))
  393.          {
  394.           int socket;
  395.           char *buffer=NULL;
  396.  
  397.           socket=OpenClientSocket(host?host:"localhost",port?port:HTTP_Port);
  398.           init_buffer(socket);
  399.  
  400.           if(socket==-1)
  401.              PrintMessage(Fatal,"Cannot open connection to wwwoffle server %s port %d.",host?host:"localhost",port?port:HTTP_Port);
  402.  
  403.           Url=SplitURL(url_file_list[i]);
  404.  
  405.           printf("Getting: %s\n",Url->name);
  406.  
  407.           write_formatted(socket,"GET /%s/%s/%s HTTP/1.0\r\n"
  408.                                  "Accept: */*\r\n"
  409.                                  "\r\n",
  410.                           refresh,Url->proto,Url->hostp);
  411.  
  412.           while((buffer=read_line(socket,buffer)))
  413.             {
  414.              fputs(buffer,stdout);
  415.              fflush(stdout);
  416.             }
  417.  
  418.           CloseSocket(socket);
  419.  
  420.           FreeURL(Url);
  421.          }
  422.        else if(!strcmp(url_file_list[i],"-") || S_ISREG(buf.st_mode))
  423.          {
  424.           int file;
  425.           char *buffer=(char*)malloc(strlen(url_file_list[i])+256);
  426.           char **links;
  427.           int j;
  428.  
  429.           if(strcmp(url_file_list[i],"-"))
  430.             {
  431.              file=open(url_file_list[i],O_RDONLY);
  432.              if(file==-1)
  433.                {PrintMessage(Warning,"Cannot open file '%s' for reading.",url_file_list[i]);continue;}
  434.              init_buffer(file);
  435.  
  436.              printf("Reading: %s\n",url_file_list[i]);
  437.             }
  438.           else
  439.             {
  440.              file=fileno(stdin);
  441.  
  442.              printf("Reading: <stdin>\n");
  443.             }
  444.  
  445.           strcpy(buffer,"file://localhost");
  446.           if(*url_file_list[i]=='/')
  447.              strcat(buffer,url_file_list[i]);
  448.           else
  449.             {
  450.              char cwd[256];
  451.  
  452.              if(!getcwd(cwd,255))
  453.              cwd[0]=0;
  454.  
  455.              strcat(buffer,cwd);
  456.              strcat(buffer,"/");
  457.              strcat(buffer,url_file_list[i]);
  458.             }
  459.  
  460.           Url=SplitURL(buffer);
  461.           ParseHTML(file,Url,1);
  462.  
  463.           if(images && (links=ListImages()))
  464.              for(j=0;links[j];j++)
  465.                {
  466.                 URL *linkUrl=SplitURL(links[j]);
  467.  
  468.                 if(strcmp(linkUrl->proto,"file"))
  469.                    add_url_file(linkUrl->name);
  470.  
  471.                 FreeURL(linkUrl);
  472.                }
  473.  
  474.           if((links=ListLinks()))
  475.              for(j=0;links[j];j++)
  476.                {
  477.                 URL *linkUrl=SplitURL(links[j]);
  478.  
  479.                 if(strcmp(linkUrl->proto,"file"))
  480.                    add_url_file(linkUrl->name);
  481.  
  482.                 FreeURL(linkUrl);
  483.                }
  484.  
  485.           if(frames && (links=ListFrames()))
  486.              for(j=0;links[j];j++)
  487.                {
  488.                 URL *linkUrl=SplitURL(links[j]);
  489.  
  490.                 if(strcmp(linkUrl->proto,"file"))
  491.                    add_url_file(linkUrl->name);
  492.  
  493.                 FreeURL(linkUrl);
  494.                }
  495.  
  496.           FreeURL(Url);
  497.           if(file!=0)
  498.              close(file);
  499.          }
  500.        else
  501.           PrintMessage(Warning,"The file '%s' is not a regular file.",url_file_list[i]);
  502.    }
  503.  else /* action==Output */
  504.    {
  505.     URL *Url;
  506.     int socket;
  507.     char *buffer=NULL,buffer256[257];
  508.     int nbytes;
  509.  
  510.     if(!n_url_file_list)
  511.        PrintMessage(Fatal,"No URL specified to output");
  512.  
  513.     socket=OpenClientSocket(host?host:"localhost",port?port:HTTP_Port);
  514.     init_buffer(socket);
  515.  
  516.     if(socket==-1)
  517.        PrintMessage(Fatal,"Cannot open connection to wwwoffle server %s port %d.",host?host:"localhost",port?port:HTTP_Port);
  518.  
  519.     Url=SplitURL(url_file_list[0]);
  520.  
  521.     fprintf(stderr,"Getting: %s\n",Url->name);
  522.  
  523.     write_formatted(socket,"GET %s HTTP/1.0\r\n"
  524.                            "Accept: */*\r\n"
  525.                            "\r\n",
  526.                     Url->name);
  527.  
  528.     if((buffer=read_line(socket,buffer)))
  529.       {
  530.        char *willget="HTTP/1.0 404 WWWOFFLE Will Get\r\n"; /* This line must not be changed (see messages.c). */
  531.        int status;
  532.  
  533.        sscanf(buffer,"%*s %d",&status);
  534.  
  535.        if(!strcmp(willget,buffer))
  536.           fprintf(stderr,"The URL is not in the cache but has been requested.\n");
  537.        else if(status>=300 && status<400)
  538.           fprintf(stderr,"The URL has been moved, check with a browser.\n");
  539.        else if(status!=200)
  540.           fprintf(stderr,"The URL returns an error message, check with a browser.\n");
  541.        else
  542.          {
  543.           while((buffer=read_line(socket,buffer)) && buffer[0]!='\r' && buffer[0]!='\n')
  544.              ;
  545.  
  546.           while((nbytes=read_data(socket,buffer256,256))>0)
  547.              fwrite(buffer256,1,nbytes,stdout);
  548.          }
  549.       }
  550.     else
  551.        PrintMessage(Fatal,"Cannot read from wwwoffle server.");
  552.  
  553.     CloseSocket(socket);
  554.  
  555.     FreeURL(Url);
  556.    }
  557.  
  558.  /* exit. */
  559.  
  560.  return(0);
  561. }
  562.  
  563.  
  564. /*++++++++++++++++++++++++++++++++++++++
  565.   Print the program usage in long or short format.
  566.  
  567.   int verbose True for long format.
  568.   ++++++++++++++++++++++++++++++++++++++*/
  569.  
  570. static void usage(int verbose)
  571. {
  572.  fprintf(stderr,
  573.          "\n"
  574.          "WWWOFFLE - World Wide Web Offline Explorer - Version %s\n"
  575.          "\n",WWWOFFLE_VERSION);
  576.  
  577.  if(verbose)
  578.     fprintf(stderr,
  579.             "(c) Andrew M. Bishop 1996,97,98 [       amb@gedanken.demon.co.uk ]\n"
  580.             "                                [http://www.gedanken.demon.co.uk/]\n"
  581.             "\n");
  582.  
  583.  fprintf(stderr,
  584.          "Usage: wwwoffle -h\n"
  585.          "       wwwoffle -online | -autodial | -offline | -fetch\n"
  586.          "       wwwoffle -config | -purge | -kill\n"
  587.          "       wwwoffle -o <url>\n"
  588.          "       wwwoffle [-i] [-f] [-F] [-(d|r|R)[<depth>]] <url> ...\n"
  589.          "       wwwoffle [-i] [-f] [-F] [-(d|r|R)[<depth>]] [<file>|-] ...\n"
  590.          "\n"
  591.          "Any of these can also take:  [-p <host>[:<port>] | -c <config-file>]\n"
  592.          "The environment variable WWWOFFLE_PROXY can be set instead of -p or -c options.\n"
  593.          "\n");
  594.  
  595.  if(verbose)
  596.     fprintf(stderr,
  597.             "wwwoffle -h          : Display this help.\n"
  598.             "\n"
  599.             "wwwoffle -on[line]   : Indicate to the server that the network is active.\n"
  600.             "                       (Proxy requests will be fetched from remote hosts.)\n"
  601.             "\n"
  602.             "wwwoffle -auto[dial] : Indicate to the server that the network is automatic.\n"
  603.             "                       (Proxy requests will be fetched from remote hosts\n"
  604.             "                        ONLY if they are not already cached.)\n"
  605.             "\n"
  606.             "wwwoffle -off[line]  : Indicate to the server that the network is inactive.\n"
  607.             "                       (Proxy requests will be fetched from cache or recorded.)\n"
  608.             "\n"
  609.             "wwwoffle -fetch      : Force the server to fetch the pages that are recorded.\n"
  610.             "\n"
  611.             "wwwoffle -config     : Force the server to re-read the configuration file.\n"
  612.             "\n"
  613.             "wwwoffle -purge      : Force the server to purge pages from the cache.\n"
  614.             "\n"
  615.             "wwwoffle -kill       : Force the server to exit cleanly.\n"
  616.             "\n"
  617.             "wwwoffle <url> ...   : Fetch the specified URLs.\n"
  618.             "\n"
  619.             "wwwoffle <file> ...  : Fetch the URLs that are links in the specified file.\n"
  620.             "\n"
  621.             " -o                  : Fetch the URL and output it on the standard output.\n"
  622.             "\n"
  623.             " -i                  : Fetch the images included in the specified URLs.\n"
  624.             " -f                  : Fetch the frames included in the specified URLs.\n"
  625.             " -F                  : Force the url to be refreshed even if already cached.\n"
  626.             " -(d|r|R)[<depth>]   : Fetch pages linked to the URLs and their links,\n"
  627.             "                       going no more than <depth> steps (default 1).\n"
  628.             "                        (-d => URLs in the same directory or sub-directory)\n"
  629.             "                        (-r => URLs on the same host)\n"
  630.             "                        (-R => URLs on any host)\n"
  631.             "\n"
  632.             " -p <host>[:<port>]  : The host name and port number to talk to the demon on.\n"
  633.             "                       (Defaults to localhost for the server and\n"
  634.             "                        %d for control port, %d for http proxy port).\n"
  635.             "\n"
  636.             " -c <config-file>    : The name of the configuration file with the hostname,\n"
  637.             "                       port number and the password (if any).\n"
  638.             "\n"
  639.             "WWWOFFLE_PROXY       : An environment variable that can be set to either the\n"
  640.             "                       name of the config file (absolute path) or the hostname\n"
  641.             "                       and port number (both proxy and control) for the proxy.\n"
  642.             "                       e.g. \"/var/spool/wwwoffle/wwwoffle.conf\",\n"
  643.             "                       \"localhost:8080:8081\" or \"localhost:8080\" are valid.\n"
  644.             "\n",DEF_WWWOFFLE_PORT,DEF_HTTP_PORT);
  645.  
  646.  if(verbose)
  647.     exit(0);
  648.  else
  649.     exit(1);
  650. }
  651.  
  652.  
  653. /*++++++++++++++++++++++++++++++++++++++
  654.   Add a URL or a file to the list.
  655.  
  656.   char *url_file The URL or file to add.
  657.   ++++++++++++++++++++++++++++++++++++++*/
  658.  
  659. static void add_url_file(char *url_file)
  660. {
  661.  if(!(n_url_file_list%16))
  662.    {
  663.     if(n_url_file_list)
  664.        url_file_list=(char**)realloc(url_file_list,(n_url_file_list+16)*sizeof(char*));
  665.     else
  666.        url_file_list=(char**)malloc(16*sizeof(char*));
  667.    }
  668.  
  669.  url_file_list[n_url_file_list]=(char*)malloc(strlen(url_file)+1);
  670.  
  671.  strcpy(url_file_list[n_url_file_list],url_file);
  672.  
  673.  n_url_file_list++;
  674. }
  675.