aboutsummaryrefslogtreecommitdiff
path: root/src/http.c
blob: 2f08209105b040bb2f5ea4614b89c71bbc979198 (plain)
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
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
 /*@@
   @file      http.c
   @date      Wed Sep 13 20:44:31 2000
   @author    Tom Goodale
   @desc 
   Stuff to parse and deal with HTTP requests.
   @enddesc
   @version $Header$
 @@*/

#include "cctk.h"
#include "cctk_Parameters.h"

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

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <string.h>

#include "util_String.h"

#include "httpd.h"
#include "httpd_Map.h"
#include "SString_Namespace.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusConnect_HTTPD_http_c)

/********************************************************************
 *********************     Local Data Types   ***********************
 ********************************************************************/

typedef struct HTTPArg
{
  /* Public data */
  char *arg;
  char *value;
  
  /* Private data */ 
  struct HTTPArg *next;
  struct HTTPArg *all_next;
} httpArg_PLACEHOLDER;

/* This is the main structure for storing data about a request. */
typedef struct httpRequestTag
{
  /* Public members of the structure. */
  char *body;        /* The body of the request */
  int body_length;   /* How long the body is */

  const char *method;      /* The HTTP method */
  char *uri;         /* The URI */
  const char *residual;    /* What's left of the URI after subtracting the found page */
  
  /* HTTP version numbers */
  int http_major_version;  
  int http_minor_version;

  /* How many arguments there are */
  int n_arguments;

  /* These are all private members of this structure */

  /* The connection data */
  void *connection;

  /* The request header lines */
  uMap headers;

  /* Stuff for arguments */

  /* First a hash table to look the data up quickly */
  uMap arguments;

  /* Now a linked list to allow walking. */
  httpArg *firstarg;
  httpArg *lastarg;
  httpArg *currentarg;

} httpRequest_PLACEHOLDER;

#define BLANK_HTTPREQUEST {NULL, 0, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL } 
  /* Accessors for the httpRequest structure */
unsigned int HTTP_MajorVersion( const httpRequest *request )
{
  return request->http_major_version;
}

unsigned int HTTP_MinorVersion( const httpRequest *request )
{
  return request->http_minor_version;
}

unsigned int HTTP_NumArguments( const httpRequest *request )
{
  return request->n_arguments;
}

const char * HTTP_URI( const httpRequest *request )
{
  return request->uri;
}

const char * HTTP_Residual( const httpRequest *request )
{
  return request->residual;
}

void HTTP_SetResidual( httpRequest *request, const char *residual )
{
  request->residual = residual;
}

const char * HTTP_ArgValue( const httpArg *arg )
{
  return arg->value;
}

const char * HTTP_ArgName( const httpArg *arg )
{
  return arg->arg;
}

httpSocket * HTTP_Connection( const httpRequest *request )
{
  return request->connection;
}

SSBOOL HTTP_GetHeaderValueString(const httpRequest *request,
                const String *header, String *value)
{
  const char * v = HTTP_HeaderValue(request, GetBuffer( header ) );
  if( v )
  {
    SetToCString( value, v );
    return SSTRUE;
  }
  else
    return SSFALSE;
}

struct httpHeader
{
  char *line;
};

/********************************************************************
 ********************* Local Routine Prototypes *********************
 ********************************************************************/

static char *NextLine(char *buffer, int *start, int size);
static int  DealWithRequest(cGH *cctkGH, httpRequest *request, char *buffer, 
                            int bufsize);
static int  AddHeader(httpRequest *request, const char *line);

static int  StripArgs(httpRequest *request, char *request_uri);
static void Decode(char *string);
static int  InitialiseRequest(httpRequest *request);
static int  ClearRequest(httpRequest *request);

static void DestroyHeader(struct httpHeader *header);
static void DestroyArgument(httpArg *argument);

/********************************************************************
 ********************* Other Routine Prototypes *********************
 ********************************************************************/

/********************************************************************
 *********************     Local Data   *****************************
 ********************************************************************/

#define INITIAL_SIZE 16
#define MAXMSG  2048
#define EMPTY_STRING  {'\0'}

/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine    HTTP_ReadFromClient
   @date       Wed Sep 13 20:44:31 2000
   @author     Tom Goodale
   @desc 
   Reads a request from a client socket.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
int HTTP_ReadFromClient(cGH *cctkGH, void *connection)
{
  int retval = -1;
  int keepalive = 0;
  char inbuffer[MAXMSG] = EMPTY_STRING;
  httpRequest request = BLANK_HTTPREQUEST;
  int request_buffer_length = 0;
  char *request_buffer = NULL;
  struct timeval timeout = {1, 0};
  int found_eoh = 0;
  int failure_count = 0;

  InitialiseRequest(&request);

  request.connection = connection;


  while(! found_eoh)
  {
    int nbytes = HTTP_Read(&request, inbuffer, MAXMSG);
   
    if (nbytes < 0)
    {
      /* Read error. */
      perror ("HTTP_Read");
      CCTK_WARN(1, "Error reading from socket");
    }
    else if (nbytes == 0)
    {      
      CCTK_WARN(1, "Got 0 bytes when waiting for end of HTTP request header");
      if(failure_count < 3)
      {
        select (0, NULL, NULL, NULL, &timeout);
        failure_count++;
      }
      else
      {
        /* Give up waiting for this socket */
        CCTK_WARN(1, "Too many failures reading from socket.  Giving up.");
        request_buffer_length = 0;
        break;
      }
    }
    else
    {
      /* Reallocate space for buffer.
       * Add space for one extra char so can null-terminate to allow string search.
       */
      char *tmp = (char *)realloc(request_buffer, (request_buffer_length+nbytes+1)*sizeof(char));
      if(tmp)
      {
        request_buffer = tmp;
      }
      else
      {
        CCTK_WARN(0, "Memory allocation failure.");
      }

      /* Copy the new data into the buffer */
      memcpy(request_buffer+request_buffer_length, inbuffer, nbytes);
      request_buffer_length += nbytes;
      /* Add a null byte in the extra allocated space to allow strstr */
      request_buffer[request_buffer_length] = 0;

      /* Look for end of HTTP header. 
       * Comment out the check for \n\n for strict compliance, but this is
       * useful for debugging with telnet.
       */
      if(strstr(request_buffer, "\r\n\r\n") || strstr(request_buffer, "\n\n"))
      {
        found_eoh = 1;
#ifdef HTTP_DEBUG
        fprintf (stderr, "Found end of HTTP header.\n");
#endif
      }
    }
  }

  if(request_buffer_length > 0)
  {
    /* Data read. */
#ifdef HTTP_DEBUG
    fprintf (stderr, "Server: got message: `%s'\n", request_buffer);
#endif

    keepalive = DealWithRequest(cctkGH, &request, request_buffer, request_buffer_length);
  }

  if(keepalive)
  {
    retval = 0;
  }
  else
  {
    retval = -1;
  }

  if(request_buffer)
  {
    free(request_buffer);
  }

  return retval;
}

 /*@@
   @routine    HTTP_ArgumentValue
   @date       Thu Sep 14 16:40:11 2000
   @author     Tom Goodale
   @desc 
   Returns the value (if any) of an argument.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
const char *HTTP_ArgumentValue(const httpRequest *request, const char *arg)
{
  if(request->arguments)
  {
    const httpArg *value = (httpArg *)Httpd_MapData(request->arguments, strlen(arg), arg);

    if(value)
    {
      return value->value;
    }
  }

  return NULL;
}

 /*@@
   @routine    HTTP_ArgumentWalk
   @date       Sat Sep 16 14:41:01 2000
   @author     Tom Goodale
   @desc 
   Walks the argument list.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
const httpArg *HTTP_ArgumentWalk(httpRequest *request, int first)
{
  if(first || ! (request->currentarg))
  {
    request->currentarg = request->firstarg;
  }
  else
  {
    request->currentarg = request->currentarg->all_next;
  }

  return request->currentarg;
}

 /*@@
   @routine    HTTP_HeaderValue
   @date       Thu Sep 14 19:55:04 2000
   @author     Tom Goodale
   @desc 
   Gets the value of an HTTP header line.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
const char *HTTP_HeaderValue(const httpRequest *request, const char *header)
{
  struct httpHeader *header_line;

  if(request->headers)
  {
    header_line = Httpd_MapData(request->headers, strlen(header), header);

    if(header_line)
    {
      return header_line->line;
    }
  }

  return NULL;
}

/********************************************************************
 *********************     Local Routines   *************************
 ********************************************************************/

 /*@@
   @routine    NextLine
   @date       Wed Sep 13 20:44:31 2000
   @author     Tom Goodale
   @desc 
   Gets the next line from an HTTP header.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static char *NextLine(char *buffer, int *start, int size)
{
  char *line = NULL;
  int found = 0;
  char *pos;

  for(pos = buffer + *start; pos-buffer < size-1; pos++)
  {
    if(*pos == '\r' && *(pos+1) == '\n')
    {
      *pos = 0;
      found = 1;
      break;
    }
  }
   
  if(found)
  {
    line = buffer + *start;
    *start = pos-buffer+2;
  }
  else
  {
    *start = size+1;
  }

  return line;
}

 /*@@
   @routine    DealWithRequest
   @date       Wed Sep 13 20:44:31 2000
   @author     Tom Goodale
   @desc 
   Takes an http request buffer and deals with it.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int DealWithRequest(cGH *cctkGH, httpRequest *request, char *buffer, int bufsize)
{
  char *line;
  char *tmp = buffer;
  int start = 0;
  char *method = NULL;
  char *request_uri = NULL;
  char *http_version = NULL;
  DECLARE_CCTK_PARAMETERS

#ifdef HTTP_DEBUG
  printf("Dealing with request\n");
#endif

  line = NextLine(tmp, &start, bufsize);

  if(line)
  {
    method = line;

    for(; *line; line++)
    {
      if(*line == ' ')
      {
        *line = 0;
        line++;
        if(!request_uri)
        {
          request_uri = line;
        }
        else
        {
          http_version = line;
          break;
        }
      }
    }
  }

  if(method)
  {
#ifdef HTTP_DEBUG
    printf("Method: %s\n", method);
#endif

    request->method = method; 
  }

  if(request_uri)
  {
    if (verbose)
    {
      CCTK_VInfo (CCTK_THORNSTRING, "URI:    %s", request_uri);
    }

    request->uri = request_uri; 
    StripArgs(request, request->uri);
  }

  if(http_version)
  {
#ifdef HTTP_DEBUG
    printf("HTTP:   %s\n", http_version);
#endif
    sscanf(http_version, "%*5s%d%*1[.]%d", &(request->http_major_version),
                                          &(request->http_minor_version));
  }
  else
  {
    request->http_major_version = 0;
    request->http_minor_version = 90;
  }

#ifdef HTTP_DEBUG
  printf("HTTP Major version: %d\n", request->http_major_version);
  printf("HTTP Minor version: %d\n", request->http_minor_version);
#endif

#ifdef HTTP_DEBUG
  printf("Start of request header\n");
#endif

  while((line = NextLine(tmp, &start, bufsize)) != NULL)
  {
    if(! request->body && *line != 0)
    {
      AddHeader(request, line);
    }

#ifdef HTTP_DEBUG
    if(line)
    {
      printf("Line is '%s'\n", line);
    }
#endif

    if(*line == 0)
    {
#ifdef HTTP_DEBUG
      printf("End of request header\n");

      printf("Start of request body\n");
#endif
      request->body = line + 2;
    }
  }

#ifdef HTTP_DEBUG
  printf("End of request body\n");
#endif

  request->body_length = buffer + bufsize - request->body;

#ifdef HTTP_DEBUG
  printf("Replying...\n");
#endif

  if(!strcmp(request->method, "GET"))
  {
    HTTP_RequestGET(cctkGH, request);
  }
  else
  {
    HTTP_RequestUnsupported(cctkGH, request);
  }
  
#ifdef HTTP_DEBUG
  printf("Dealt with.\n");
#endif

  ClearRequest(request);

  return 0;
}



 /*@@
   @routine    AddHeader
   @date       Wed Sep 13 20:44:31 2000
   @author     Tom Goodale
   @desc 
   Stores an HTTP header line on a request.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int AddHeader(httpRequest *request, const char *line)
{
  int keylength = -1;
  struct httpHeader *header_line;
  /* Split the string */
  char *value = strchr(line, ':');

  if(value)
  {
    keylength = value - line;
  
    value++;

    /* Strip off leading whitespace */
    for(; *value && (*value == ' ' || *value == '\t') ; value++);

  }
  else
  {
    CCTK_VWarn(1, __LINE__,__FILE__,CCTK_THORNSTRING,
               "Invalid header line:\n\"%s\"", line );
  }
  
  if(value)
  {
    if(!request->headers)
    {
      /* Need to create the hash table */
      request->headers = Httpd_MapCreate();
    }

    if(request->headers)
    {
      /* Does the line already exist ? */
      header_line = (struct httpHeader *)Httpd_MapData(request->headers, keylength, line);

      if(header_line)
      {
        char *temp = (char *)realloc(header_line->line, strlen(header_line->line)+strlen(value)+2);

        if(temp)
        {
          header_line->line = temp;
          sprintf(header_line->line,"%s,%s", header_line->line,value);
        }
        else
        {
          CCTK_WARN( 0, "Out of memory!\n" );
        }
      }
      else
      {
        /* Ok, must create it */
        header_line = (struct httpHeader *)malloc(sizeof(struct httpHeader));

        if(header_line)
        {
          header_line->line = (char *)malloc(strlen(value)+1);

          if(header_line->line)
          {
            strcpy(header_line->line, value);

            Httpd_MapStore(request->headers, keylength, line, (void *)header_line);
          }
        }
      }
    }
  }

  return 0;
}

 /*@@
   @routine    StripArgs
   @date       Thu Sep 14 16:36:56 2000
   @author     Tom Goodale
   @desc 
   Strips the arguments for a submitted URI from the
   URI and decodes any HTTP encodings.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int StripArgs(httpRequest *request, char *request_uri)
{
  char *position;
  /* Do we have arguments ? */
  if((position = strchr(request_uri, '?')))
  {
    char *token;
    /* Mark the end of the URI */
    *position = 0;

    /* Create the hash table */
    request->arguments = Httpd_MapCreate();

    /* Parse the argument list */
    position++;

    token = strtok(position, "&");

    while(token)
    {
      char *value = strchr(token, '=');
      
      if(value)
      {
        httpArg *argument;

        *value = 0;

        value++;

        /* Remove any encoding in the token and value */
        Decode(token);
        Decode(value);

        argument = (httpArg *)malloc(sizeof(httpArg));

        if(argument)
        {
          httpArg *last = NULL;
          httpArg *stored;

          argument->next      = NULL;
          argument->all_next  = NULL;
          argument->arg   = Util_Strdup(token);
          argument->value = Util_Strdup(value);

          if((stored = (httpArg *)Httpd_MapData(request->arguments, strlen(token), token)))
          {
            /* Argument already exists */

            /* Find the last one on the list */
            for(; stored; stored = stored->next)
            {
              last = stored; 
            }

            /* Append to local list */
              /* SW it isn't perfecty obvious this non NULL */
            last->next = argument;
          }
          else
          {
            Httpd_MapStore(request->arguments, strlen(token), token, (void *)argument);
            request->n_arguments++;
          }
          /* Append to global list. */
          if(request->lastarg)
          {
            request->lastarg->all_next = argument;
          }
          request->lastarg = argument;
          if(!request->firstarg)
          {
            request->firstarg = argument;
          }
        }
        else
        {
          CCTK_WARN( 0, "Out of memory!\n" );
        }
      }
      else
      {
        CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                    "Argument \"%s\" has no value!", token );
      }     
      token=strtok(NULL, "&");  
    }
  }
  else
  {
    request->arguments = NULL;
  }

  /* Finally remove any encoding in the URI */
  Decode(request_uri);

  return 0;
}

 /*@@
   @routine    InitialiseRequest
   @date       Sat Sep 16 14:29:17 2000
   @author     Tom Goodale
   @desc 
   Initialises a request data structure.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int InitialiseRequest(httpRequest *request)
{

  /* Initialise the public data */
  request->body        = NULL;
  request->body_length = 0;
  request->method      = NULL;
  request->uri         = NULL;
  request->residual    = NULL;

  request->http_major_version = -1;
  request->http_minor_version = -1;

  request->n_arguments = 0;

  /* Initialise the private data */

  request->connection  = NULL;
  request->headers     = NULL;
  request->arguments   = NULL;
  
  request->firstarg    = NULL;
  request->lastarg     = NULL;
  request->currentarg  = NULL;

  return 0;
}

 /*@@
   @routine    ClearRequest
   @date       Wed Sep 13 20:44:31 2000
   @author     Tom Goodale
   @desc 
   Frees all memory associated with a request.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int ClearRequest(httpRequest *request)
{
  if(request->arguments)
  {
    Httpd_MapDestroy(request->arguments, (void (*)(void *))DestroyArgument);
  }

  if(request->headers)
  {
    Httpd_MapDestroy(request->headers, (void (*)(void *))DestroyHeader);
  }

  return 0;
}

 /*@@
   @routine    Decode
   @date       Thu Sep 14 16:25:25 2000
   @author     Tom Goodale
   @desc 
   Decode HTTP encodings -
   + -> ' '
   %2-bytehexadecimal -> ascii
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static void Decode(char *string)
{
  char *position;
  char *to;
  char hexadecimal[3] = {0, 0, 0};

  for(position=string, to=position; *position; position++, to++)
  {
    switch(*position)
    {
      case '+' : *to = ' '; break;
      case '%' : hexadecimal[0] = *(position+1);
                 hexadecimal[1] = *(position+2);
                 position += 2;
                 *to = strtol(hexadecimal, NULL, 16);
                 break;
      default :  *to = *position;
    }
  }

  *to = 0;
}

 /*@@
   @routine    DestroyHeader
   @date       Wed Sep 13 20:44:31 2000
   @author     Tom Goodale
   @desc 
   Frees all memory associated with a header structure.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static void DestroyHeader(struct httpHeader *header)
{
  free(header->line);
  free(header);
}

 /*@@
   @routine    DestroyArgument
   @date       Sat Sep 16 14:10:57 2000
   @author     Tom Goodale
   @desc 
   Frees all memory associated with an argument.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static void DestroyArgument(httpArg *argument)
{
  httpArg *next;

  for(; argument; argument = next)
  {
    next = argument->next;
    free(argument->arg);
    free(argument->value);
    free(argument);
  }
}