File: wwwoffle.c

package info (click to toggle)
wwwoffle 2.3a-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,452 kB
  • ctags: 1,064
  • sloc: ansic: 10,102; lex: 1,395; sh: 510; makefile: 263; perl: 78
file content (760 lines) | stat: -rw-r--r-- 23,104 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
/***************************************
  $Header: /home/amb/wwwoffle/RCS/wwwoffle.c 2.21 1998/08/22 12:15:17 amb Exp $

  WWWOFFLE - World Wide Web Offline Explorer - Version 2.3.
  A user level program to interact with the server.
  ******************/ /******************
  Written by Andrew M. Bishop

  This file Copyright 1996,97,98 Andrew M. Bishop
  It may be distributed under the GNU Public License, version 2, or
  any higher version.  See section COPYING of the GNU Public license
  for conditions under which this file may be redistributed.
  ***************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "version.h"
#include "wwwoffle.h"
#include "misc.h"
#include "config.h"
#include "sockets.h"
#include "errors.h"


static void usage(int verbose);


/*+ The action to perform. +*/
typedef enum _Action
{
 None,                          /*+ Undecided. +*/
 Online,                        /*+ Tell the server that we are online. +*/
 Autodial,                      /*+ Tell the server that we are in autodial mode. +*/
 Offline,                       /*+ Tell the server that we are offline. +*/
 Fetch,                         /*+ Tell the server to fetch the requested pages. +*/
 Config,                        /*+ Tell the server to re-read the configuration file. +*/
 Purge,                         /*+ Tell the server to purge pages. +*/
 Kill,                          /*+ Tell the server to exit. +*/
 Get,                           /*+ Tell the server to get pages. +*/
 Output,                        /*+ Get a page from the server and output it. +*/
 OutputWithHeader               /*+ Get a page and the headers from the server and output it. +*/
}
Action;


static void add_url_file(char *url_file);

/*+ The list of URLs or files. +*/
char **url_file_list=NULL;
/*+ The number of URLs or files. +*/
int n_url_file_list=0;


/*++++++++++++++++++++++++++++++++++++++
  The main program.
  ++++++++++++++++++++++++++++++++++++++*/

int main(int argc, char** argv)
{
 int i;
 int recursive_depth=0,recursive_mode=0,force=0;
 int stylesheets=0,images=0,frames=0,scripts=0,objects=0;

 Action action=None;

 char *env=NULL;
 char *host=NULL;
 int port=0;

 /* Parse the command line options */

 ConfigFile=NULL;

 if(argc==1)
    usage(0);

 for(i=1;i<argc;i++)
   {
    if(!strcmp(argv[i],"-h"))
       usage(1);

    if(!strcmp(argv[i],"-o"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Output;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-O"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=OutputWithHeader;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-F"))
      {
       if(action!=None && action!=Get)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Get;
       if(force)
         {fprintf(stderr,"wwwoffle: Only one '-F' argument may be given.\n"); exit(1);}
       force=1;
       argv[i]=NULL;
       continue;
      }

    if(!strncmp(argv[i],"-g",2))
      {
       if(action!=None && action!=Get)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Get;
       if(strchr(argv[i]+2,'S'))
         {
          if(stylesheets)
            {fprintf(stderr,"wwwoffle: Only one '-gS' argument may be given.\n"); exit(1);}
          stylesheets=1;
         }
       if(strchr(argv[i]+2,'i'))
         {
          if(images)
            {fprintf(stderr,"wwwoffle: Only one '-gi' argument may be given.\n"); exit(1);}
          images=1;
         }
       if(strchr(argv[i]+2,'f'))
         {
          if(frames)
            {fprintf(stderr,"wwwoffle: Only one '-gf' argument may be given.\n"); exit(1);}
          frames=1;
         }
       if(strchr(argv[i]+2,'s'))
         {
          if(scripts)
            {fprintf(stderr,"wwwoffle: Only one '-gs' argument may be given.\n"); exit(1);}
          scripts=1;
         }
       if(strchr(argv[i]+2,'o'))
         {
          if(objects)
            {fprintf(stderr,"wwwoffle: Only one '-go' argument may be given.\n"); exit(1);}
          objects=1;
         }
       if(argv[i][2]==0)
          fprintf(stderr,"wwwoffle: The '-g' option does nothing on its own.\n");

       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-i"))
      {
       fprintf(stderr,"wwwoffle: The '-i' option is being replaced by '-gi'.\n");

       if(action!=None && action!=Get)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Get;
       if(images)
         {fprintf(stderr,"wwwoffle: Only one '-i' argument may be given.\n"); exit(1);}
       images=1;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-f"))
      {
       fprintf(stderr,"wwwoffle: The '-f' option is being replaced by '-gf'.\n");

       if(action!=None && action!=Get)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Get;
       if(frames)
         {fprintf(stderr,"wwwoffle: Only one '-f' argument may be given.\n"); exit(1);}
       frames=1;
       argv[i]=NULL;
       continue;
      }

    if(!strncmp(argv[i],"-R",2) || !strncmp(argv[i],"-r",2) || !strncmp(argv[i],"-d",2))
      {
       if(action!=None && action!=Get)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Get;

       if(recursive_depth)
         {fprintf(stderr,"wwwoffle: Only one '-d', '-r' or '-R' argument may be given.\n"); exit(1);}

       if(argv[i][1]=='d')
          recursive_mode=1;
       else if(argv[i][1]=='r')
          recursive_mode=2;
       else /* argv[i][1]=='R' */
          recursive_mode=3;

       if(argv[i][2])
          recursive_depth=atoi(&argv[i][2]);
       else
          recursive_depth=1;
       if(recursive_depth<=0)
         {fprintf(stderr,"wwwoffle: The '-%c' argument may only be followed by a positive integer.\n",argv[i][1]); exit(1);}

       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-p"))
      {
       char *colon;

       if(++i>=argc)
         {fprintf(stderr,"wwwoffle: The '-p' argument requires a hostname and optionally a port number.\n"); exit(1);}

       if(ConfigFile)
         {fprintf(stderr,"wwwoffle: The '-p' and '-c' options cannot be used together.\n"); exit(1);}

       if((colon=strchr(argv[i],':')))
         {
          *colon++=0;

          port=atoi(colon);

          if(port<=0 || port>=65536)
            {fprintf(stderr,"wwwoffle: The port number %d '%s' is invalid.\n",port,argv[i]); exit(1);}
         }

       host=argv[i];

       argv[i-1]=NULL;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-c"))
      {
       if(++i>=argc)
         {fprintf(stderr,"wwwoffle: The '-c' argument requires a configuration file name.\n"); exit(1);}

       if(host)
         {fprintf(stderr,"wwwoffle: The '-p' and '-c' options cannot be used together.\n"); exit(1);}

       ConfigFile=argv[i];

       argv[i-1]=NULL;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-on") || !strcmp(argv[i],"-online"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Online;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-auto") || !strcmp(argv[i],"-autodial"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Autodial;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-off") || !strcmp(argv[i],"-offline"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Offline;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-fetch"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Fetch;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-config"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Config;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-purge"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Purge;
       argv[i]=NULL;
       continue;
      }

    if(!strcmp(argv[i],"-kill"))
      {
       if(action!=None)
         {fprintf(stderr,"wwwoffle: Only one command at a time.\n\n");usage(0);}
       action=Kill;
       argv[i]=NULL;
       continue;
      }

    if(argv[i][0]=='-' && argv[i][1])
      {
       fprintf(stderr,"wwwoffle: Unknown option '%s'.\n\n",argv[i]);
       usage(0);
      }

    add_url_file(argv[i]);
   }

 if(action==None)
    action=Get;

 /* Initialise things. */

 if(!ConfigFile && !host && (env=getenv("WWWOFFLE_PROXY")))
   {
    if(*env=='/')
       ConfigFile=env;
    else
      {
       char *colon1,*colon2;

       host=(char*)malloc(strlen(env)+1);
       strcpy(host,env);

       if((colon1=strchr(host,':')))
         {
          *colon1=0;
          if((colon2=strchr(colon1+1,':')))
            {
             *colon2=0;
             if(action==Get || action==Output || action==OutputWithHeader)
                port=atoi(colon1+1);
             else
                port=atoi(colon2+1);
            }
          else
             port=atoi(colon1+1);

          if(port<=0 || port>=65536)
            {fprintf(stderr,"wwwoffle: The port number %d '%s' is invalid.\n",port,env); exit(1);}
         }
      }
   }

 InitErrorHandler("wwwoffle",0,1);

 if(ConfigFile)
   {
    if(ReadConfigFile(2))
       PrintMessage(Fatal,"Error in configuration file '%s'.",ConfigFile);

    host=GetLocalHost(0);
   }

 /* The connections to the WWWOFFLE server. */

 if(action!=Get && action!=Output && action!=OutputWithHeader)
   {
    int socket;
    char *buffer=NULL;

    socket=OpenClientSocket(host?host:"localhost",port?port:WWWOFFLE_Port);
    init_buffer(socket);

    if(socket==-1)
       PrintMessage(Fatal,"Cannot open connection to wwwoffle server %s port %d.",host?host:"localhost",port?port:WWWOFFLE_Port);

    /* Send the message. */

    if(PassWord)
       write_formatted(socket,"WWWOFFLE PASSWORD %s\r\n",PassWord);

    if(action==Online)
       write_string(socket,"WWWOFFLE ONLINE\r\n");
    else if(action==Autodial)
       write_string(socket,"WWWOFFLE AUTODIAL\r\n");
    else if(action==Offline)
       write_string(socket,"WWWOFFLE OFFLINE\r\n");
    else if(action==Fetch)
       write_string(socket,"WWWOFFLE FETCH\r\n");
    else if(action==Config)
       write_string(socket,"WWWOFFLE CONFIG\r\n");
    else if(action==Purge)
       write_string(socket,"WWWOFFLE PURGE\r\n");
    else if(action==Kill)
       write_string(socket,"WWWOFFLE KILL\r\n");
    else
       write_string(socket,"WWWOFFLE BOGUS\r\n");

    while((buffer=read_line(socket,buffer)))
      {
       fputs(buffer,stdout);
       fflush(stdout);
      }

    CloseSocket(socket);
   }

 /* The connections to the http proxy. */

 else if(action==Get)
   {
    URL *Url;
    struct stat buf;
    char *refresh;

    refresh=CreateRefreshPath(recursive_depth,recursive_mode,force,
                              stylesheets,images,frames,scripts,objects);

    for(i=0;i<n_url_file_list;i++)
       if(strcmp(url_file_list[i],"-") && stat(url_file_list[i],&buf))
         {
          int socket;
          char buffer256[257];

          socket=OpenClientSocket(host?host:"localhost",port?port:HTTP_Port);
          init_buffer(socket);

          if(socket==-1)
             PrintMessage(Fatal,"Cannot open connection to wwwoffle server %s port %d.",host?host:"localhost",port?port:HTTP_Port);

          Url=SplitURL(url_file_list[i]);

          printf("Getting: %s\n",Url->name);

          if(Url->user)
            {
             char *userpass1=(char*)(malloc(strlen(Url->user)+(Url->pass?strlen(Url->pass):1)+3)),*userpass2;

             sprintf(userpass1,"%s:%s",Url->user,Url->pass?Url->pass:"");
             userpass2=Base64Encode(userpass1,strlen(userpass1));

             write_formatted(socket,"GET %s/?%s HTTP/1.0\r\n"
                                    "Pragma: wwwoffle\r\n"
                                    "Accept: */*\r\n"
                                    "Authorization: Basic %s\r\n"
                                    "\r\n",
                             refresh,Url->name,userpass2);

             free(userpass1);
             free(userpass2);
            }
          else
             write_formatted(socket,"GET %s/?%s HTTP/1.0\r\n"
                                    "Pragma: wwwoffle\r\n"
                                    "Accept: */*\r\n"
                                    "\r\n",
                             refresh,Url->name);

          while(read_data(socket,buffer256,256)>0)
             ;

          CloseSocket(socket);

          FreeURL(Url);
         }
       else if(!strcmp(url_file_list[i],"-") || S_ISREG(buf.st_mode))
         {
          int file;
          char *buffer=(char*)malloc(strlen(url_file_list[i])+256);
          char **links;
          int j;

          if(strcmp(url_file_list[i],"-"))
            {
             file=open(url_file_list[i],O_RDONLY);
             if(file==-1)
               {PrintMessage(Warning,"Cannot open file '%s' for reading.",url_file_list[i]);continue;}

             printf("Reading: %s\n",url_file_list[i]);
            }
          else
            {
             file=fileno(stdin);

             printf("Reading: <stdin>\n");
            }

          init_buffer(file);

          strcpy(buffer,"file://localhost");
          if(*url_file_list[i]=='/')
             strcat(buffer,url_file_list[i]);
          else
            {
             char cwd[256];

             if(!getcwd(cwd,255))
             cwd[0]=0;

             strcat(buffer,cwd);
             strcat(buffer,"/");
             strcat(buffer,url_file_list[i]);
            }

          Url=SplitURL(buffer);
          ParseHTML(file,Url,1);

          if(images && (links=ListImages()))
             for(j=0;links[j];j++)
               {
                URL *linkUrl=SplitURL(links[j]);

                if(strcmp(linkUrl->proto,"file"))
                   add_url_file(linkUrl->name);

                FreeURL(linkUrl);
               }

          if((links=ListLinks()))
             for(j=0;links[j];j++)
               {
                URL *linkUrl=SplitURL(links[j]);

                if(strcmp(linkUrl->proto,"file"))
                   add_url_file(linkUrl->name);

                FreeURL(linkUrl);
               }

          if(frames && (links=ListFrames()))
             for(j=0;links[j];j++)
               {
                URL *linkUrl=SplitURL(links[j]);

                if(strcmp(linkUrl->proto,"file"))
                   add_url_file(linkUrl->name);

                FreeURL(linkUrl);
               }

          FreeURL(Url);
          if(file!=0)
             close(file);
         }
       else
          PrintMessage(Warning,"The file '%s' is not a regular file.",url_file_list[i]);
   }
 else /* action==Output or action==OutputWithHeader */
   {
    URL *Url;
    int socket;
    char *buffer=NULL,buffer256[257];
    int nbytes;

    if(!n_url_file_list)
       PrintMessage(Fatal,"No URL specified to output");

    socket=OpenClientSocket(host?host:"localhost",port?port:HTTP_Port);
    init_buffer(socket);

    if(socket==-1)
       PrintMessage(Fatal,"Cannot open connection to wwwoffle server %s port %d.",host?host:"localhost",port?port:HTTP_Port);

    Url=SplitURL(url_file_list[0]);

    if(action!=Output && action!=OutputWithHeader)
       fprintf(stderr,"Getting: %s\n",Url->name);

    if(Url->user)
      {
       char *userpass1=(char*)(malloc(strlen(Url->user)+(Url->pass?strlen(Url->pass):1)+3)),*userpass2;

       sprintf(userpass1,"%s:%s",Url->user,Url->pass?Url->pass:"");
       userpass2=Base64Encode(userpass1,strlen(userpass1));

       write_formatted(socket,"GET %s HTTP/1.0\r\n"
                              "Pragma: wwwoffle\r\n"
                              "Accept: */*\r\n"
                              "Authorization: Basic %s\r\n"
                              "\r\n",
                       Url->name,userpass2);

       free(userpass1);
       free(userpass2);
      }
    else
       write_formatted(socket,"GET %s HTTP/1.0\r\n"
                              "Pragma: wwwoffle\r\n"
                              "Accept: */*\r\n"
                              "\r\n",
                       Url->name);

    if((buffer=read_line(socket,buffer)))
      {
       char *willget="HTTP/1.0 404 WWWOFFLE Will Get\r\n";
       int status;

       sscanf(buffer,"%*s %d",&status);

       if(!strcmp(willget,buffer))
          fprintf(stderr,"The URL is not in the cache but has been requested.\n");
       else if((status>=300 && status<400) && action!=OutputWithHeader)
          fprintf(stderr,"The URL has been moved, check with a browser.\n");
       else if(status!=200 && action!=OutputWithHeader)
          fprintf(stderr,"The URL returns an error message, check with a browser.\n");
       else
         {
          if(action==OutputWithHeader)
             fputs(buffer,stdout);

          while((buffer=read_line(socket,buffer)))
            {
             if(action==OutputWithHeader)
                fputs(buffer,stdout);
             if(buffer[0]=='\r' || buffer[0]=='\n')
                break;
            }

          while((nbytes=read_data(socket,buffer256,256))>0)
             fwrite(buffer256,1,nbytes,stdout);
         }
      }
    else
       PrintMessage(Fatal,"Cannot read from wwwoffle server.");

    CloseSocket(socket);

    FreeURL(Url);
   }

 /* exit. */

 return(0);
}


/*++++++++++++++++++++++++++++++++++++++
  Print the program usage in long or short format.

  int verbose True for long format.
  ++++++++++++++++++++++++++++++++++++++*/

static void usage(int verbose)
{
 fprintf(stderr,
         "\n"
         "WWWOFFLE - World Wide Web Offline Explorer - Version %s\n"
         "\n",WWWOFFLE_VERSION);

 if(verbose)
    fprintf(stderr,
            "(c) Andrew M. Bishop 1996,97,98 [       amb@gedanken.demon.co.uk ]\n"
            "                                [http://www.gedanken.demon.co.uk/]\n"
            "\n");

 fprintf(stderr,
         "Usage: wwwoffle -h\n"
         "       wwwoffle -online | -autodial | -offline | -fetch\n"
         "       wwwoffle -config | -purge | -kill\n"
         "       wwwoffle [-o|-O] <url>\n"
         "       wwwoffle [-g[Sisfo]] [-F] [-(d|r|R)[<depth>]] <url> ...\n"
         "       wwwoffle [-g[Sisfo]] [-F] [-(d|r|R)[<depth>]] [<file>|-] ...\n"
         "\n"
         "Any of these can also take:  [-p <host>[:<port>] | -c <config-file>]\n"
         "The environment variable WWWOFFLE_PROXY can be set instead of -p or -c options.\n"
         "\n");

 if(verbose)
    fprintf(stderr,
            "wwwoffle -h          : Display this help.\n"
            "\n"
            "wwwoffle -on[line]   : Indicate to the server that the network is active.\n"
            "                       (Proxy requests will be fetched from remote hosts.)\n"
            "\n"
            "wwwoffle -auto[dial] : Indicate to the server that the network is automatic.\n"
            "                       (Proxy requests will be fetched from remote hosts\n"
            "                        ONLY if they are not already cached.)\n"
            "\n"
            "wwwoffle -off[line]  : Indicate to the server that the network is inactive.\n"
            "                       (Proxy requests will be fetched from cache or recorded.)\n"
            "\n"
            "wwwoffle -fetch      : Force the server to fetch the pages that are recorded.\n"
            "\n"
            "wwwoffle -config     : Force the server to re-read the configuration file.\n"
            "\n"
            "wwwoffle -purge      : Force the server to purge pages from the cache.\n"
            "\n"
            "wwwoffle -kill       : Force the server to exit cleanly.\n"
            "\n"
            "wwwoffle <url> ...   : Fetch the specified URLs.\n"
            "\n"
            "wwwoffle <file> ...  : Fetch the URLs that are links in the specified file.\n"
            "\n"
            " -o                  : Fetch the URL and output it on the standard output.\n"
            " -O                  : As above but include the HTTP header.\n"
            "\n"
            " -g[Sisfo]           : Fetch the items included in the specified URLs.\n"
            "                       (S=stylesheets, i=images, f=frames, s=scripts, o=objects)\n"
            " -F                  : Force the url to be refreshed even if already cached.\n"
            " -(d|r|R)[<depth>]   : Fetch pages linked to the URLs and their links,\n"
            "                       going no more than <depth> steps (default 1).\n"
            "                        (-d => URLs in the same directory or sub-directory)\n"
            "                        (-r => URLs on the same host)\n"
            "                        (-R => URLs on any host)\n"
            "\n"
            " -p <host>[:<port>]  : The host name and port number to talk to the demon on.\n"
            "                       (Defaults to localhost for the server and\n"
            "                        %d for control port, %d for http proxy port).\n"
            "\n"
            " -c <config-file>    : The name of the configuration file with the hostname,\n"
            "                       port number and the password (if any).\n"
            "\n"
            "WWWOFFLE_PROXY       : An environment variable that can be set to either the\n"
            "                       name of the config file (absolute path) or the hostname\n"
            "                       and port number (both proxy and control) for the proxy.\n"
            "                       e.g. \"/var/spool/wwwoffle/wwwoffle.conf\",\n"
            "                       \"localhost:8080:8081\" or \"localhost:8080\" are valid.\n"
            "\n",DEF_WWWOFFLE_PORT,DEF_HTTP_PORT);

 if(verbose)
    exit(0);
 else
    exit(1);
}


/*++++++++++++++++++++++++++++++++++++++
  Add a URL or a file to the list.

  char *url_file The URL or file to add.
  ++++++++++++++++++++++++++++++++++++++*/

static void add_url_file(char *url_file)
{
 if(!(n_url_file_list%16))
   {
    if(n_url_file_list)
       url_file_list=(char**)realloc(url_file_list,(n_url_file_list+16)*sizeof(char*));
    else
       url_file_list=(char**)malloc(16*sizeof(char*));
   }

 url_file_list[n_url_file_list]=(char*)malloc(strlen(url_file)+1);

 strcpy(url_file_list[n_url_file_list],url_file);

 n_url_file_list++;
}