~ubuntu-branches/ubuntu/raring/curl/raring-updates

« back to all changes in this revision

Viewing changes to lib/formdata.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: formdata.c,v 1.104 2008-03-31 10:02:25 bagder Exp $
 
21
 * $Id: formdata.c,v 1.116 2008-12-20 22:51:57 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
/*
56
56
vlue for PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE
57
57
(or you might see v^@lue at the start)
58
58
 
59
 
Content-Disposition: form-data; name="FILE1_+_CONTENTTYPE"; filename="inet_ntoa_r.h"
 
59
Content-Disposition: form-data; name="FILE1_+_CONTENTTYPE"; filename="formdata.h"
60
60
Content-Type: text/html
61
61
...
62
62
 
63
63
Content-Disposition: form-data; name="FILE1_+_FILE2"
64
64
Content-Type: multipart/mixed, boundary=curlz1s0dkticx49MV1KGcYP5cvfSsz
65
65
...
66
 
Content-Disposition: attachment; filename="inet_ntoa_r.h"
 
66
Content-Disposition: attachment; filename="formdata.h"
67
67
Content-Type: application/octet-stream
68
68
...
69
69
Content-Disposition: attachment; filename="Makefile.b32"
73
73
Content-Disposition: form-data; name="FILE1_+_FILE2_+_FILE3"
74
74
Content-Type: multipart/mixed, boundary=curlirkYPmPwu6FrJ1vJ1u1BmtIufh1
75
75
...
76
 
Content-Disposition: attachment; filename="inet_ntoa_r.h"
 
76
Content-Disposition: attachment; filename="formdata.h"
77
77
Content-Type: application/octet-stream
78
78
...
79
79
Content-Disposition: attachment; filename="Makefile.b32"
80
80
Content-Type: application/octet-stream
81
81
...
82
 
Content-Disposition: attachment; filename="inet_ntoa_r.h"
 
82
Content-Disposition: attachment; filename="formdata.h"
83
83
Content-Type: application/octet-stream
84
84
...
85
85
 
87
87
Content-Disposition: form-data; name="ARRAY: FILE1_+_FILE2_+_FILE3"
88
88
Content-Type: multipart/mixed, boundary=curlirkYPmPwu6FrJ1vJ1u1BmtIufh1
89
89
...
90
 
Content-Disposition: attachment; filename="inet_ntoa_r.h"
 
90
Content-Disposition: attachment; filename="formdata.h"
91
91
Content-Type: application/octet-stream
92
92
...
93
93
Content-Disposition: attachment; filename="Makefile.b32"
94
94
Content-Type: application/octet-stream
95
95
...
96
 
Content-Disposition: attachment; filename="inet_ntoa_r.h"
 
96
Content-Disposition: attachment; filename="formdata.h"
97
97
Content-Type: application/octet-stream
98
98
...
99
99
 
171
171
            struct curl_httppost **last_post)
172
172
{
173
173
  struct curl_httppost *post;
174
 
  post = (struct curl_httppost *)calloc(sizeof(struct curl_httppost), 1);
 
174
  post = calloc(sizeof(struct curl_httppost), 1);
175
175
  if(post) {
176
176
    post->name = name;
177
177
    post->namelength = (long)(name?(namelength?namelength:strlen(name)):0);
222
222
                              FormInfo *parent_form_info)
223
223
{
224
224
  FormInfo *form_info;
225
 
  form_info = (FormInfo *)malloc(sizeof(FormInfo));
 
225
  form_info = calloc(sizeof(FormInfo), 1);
226
226
  if(form_info) {
227
 
    memset(form_info, 0, sizeof(FormInfo));
228
227
    if(value)
229
228
      form_info->value = value;
230
229
    if(contenttype)
267
266
   * extensions and pick the first we match!
268
267
   */
269
268
  struct ContentType {
270
 
    const char *extension;
 
269
    char extension[6];
271
270
    const char *type;
272
271
  };
273
272
  static const struct ContentType ctts[]={
275
274
    {".jpg",  "image/jpeg"},
276
275
    {".jpeg", "image/jpeg"},
277
276
    {".txt",  "text/plain"},
278
 
    {".html", "text/html"}
 
277
    {".html", "text/html"},
 
278
    {".xml", "application/xml"}
279
279
  };
280
280
 
281
281
  if(prevtype)
325
325
  }
326
326
  else
327
327
    /* no length and a NULL src pointer! */
328
 
    return strdup((char *)"");
 
328
    return strdup("");
329
329
 
330
 
  buffer = (char*)malloc(length+add);
 
330
  buffer = malloc(length+add);
331
331
  if(!buffer)
332
332
    return NULL; /* fail */
333
333
 
410
410
  /*
411
411
   * We need to allocate the first struct to fill in.
412
412
   */
413
 
  first_form = (FormInfo *)calloc(sizeof(struct FormInfo), 1);
 
413
  first_form = calloc(sizeof(struct FormInfo), 1);
414
414
  if(!first_form)
415
415
    return CURL_FORMADD_MEMORY;
416
416
 
705
705
  }
706
706
 
707
707
  if(CURL_FORMADD_OK == return_value) {
708
 
    /* go through the list, check for copleteness and if everything is
 
708
    /* go through the list, check for completeness and if everything is
709
709
     * alright add the HttpPost item otherwise set return_value accordingly */
710
710
 
711
711
    post = NULL;
743
743
        }
744
744
        if( !(form->flags & HTTPPOST_PTRNAME) &&
745
745
             (form == first_form) ) {
746
 
          /* copy name (without strdup; possibly contains null characters) */
747
 
          form->name = memdup(form->name, form->namelength);
 
746
          /* Note that there's small risk that form->name is NULL here if the
 
747
             app passed in a bad combo, so we better check for that first. */
 
748
          if(form->name)
 
749
            /* copy name (without strdup; possibly contains null characters) */
 
750
            form->name = memdup(form->name, form->namelength);
748
751
          if(!form->name) {
749
752
            return_value = CURL_FORMADD_MEMORY;
750
753
            break;
838
841
                            size_t length,
839
842
                            curl_off_t *size)
840
843
{
841
 
  struct FormData *newform = (struct FormData *)
842
 
    malloc(sizeof(struct FormData));
 
844
  struct FormData *newform = malloc(sizeof(struct FormData));
843
845
  if(!newform)
844
846
    return CURLE_OUT_OF_MEMORY;
845
847
  newform->next = NULL;
849
851
    if(!length)
850
852
      length = strlen((char *)line);
851
853
 
852
 
    newform->line = (char *)malloc(length+1);
 
854
    newform->line = malloc(length+1);
853
855
    if(!newform->line) {
854
856
      free(newform);
855
857
      return CURLE_OUT_OF_MEMORY;
1098
1100
 
1099
1101
  free(filename); /* free temporary buffer */
1100
1102
 
1101
 
  return base; /* returns an allocated string! */
 
1103
  return base; /* returns an allocated string or NULL ! */
1102
1104
}
1103
1105
 
1104
1106
/*
1205
1207
 
1206
1208
      if(post->more) {
1207
1209
        /* if multiple-file */
1208
 
        char *filebasename=
1209
 
          (!file->showfilename)?strippath(file->contents):NULL;
 
1210
        char *filebasename= NULL;
 
1211
        if(!file->showfilename) {
 
1212
          filebasename = strippath(file->contents);
 
1213
          if(!filebasename) {
 
1214
            Curl_formclean(&firstform);
 
1215
            free(boundary);
 
1216
            return CURLE_OUT_OF_MEMORY;
 
1217
          }
 
1218
        }
1210
1219
 
1211
1220
        result = AddFormDataf(&form, &size,
1212
1221
                              "\r\n--%s\r\nContent-Disposition: "
1563
1572
  char value4[] = "value for simple PTRCONTENTS";
1564
1573
  char value5[] = "value for PTRCONTENTS + CONTENTSLENGTH";
1565
1574
  char value6[] = "value for PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE";
1566
 
  char value7[] = "inet_ntoa_r.h";
 
1575
  char value7[] = "formdata.h";
1567
1576
  char value8[] = "Makefile.b32";
1568
1577
  char type2[] = "image/gif";
1569
1578
  char type6[] = "text/plain";
1674
1683
  } while(1);
1675
1684
 
1676
1685
  fprintf(stdout, "size: ");
1677
 
  fprintf(stdout, CURL_FORMAT_OFF_T, size);
 
1686
  fprintf(stdout, "%" FORMAT_OFF_T, size);
1678
1687
  fprintf(stdout, "\n");
1679
1688
  if(errors)
1680
1689
    fprintf(stdout, "\n==> %d Test(s) failed!\n", errors);
1727
1736
                              the same form won't be identical */
1728
1737
  size_t i;
1729
1738
 
1730
 
  static const char table16[]="abcdef0123456789";
 
1739
  static const char table16[]="0123456789abcdef";
1731
1740
 
1732
 
  retstring = (char *)malloc(BOUNDARY_LENGTH+1);
 
1741
  retstring = malloc(BOUNDARY_LENGTH+1);
1733
1742
 
1734
1743
  if(!retstring)
1735
1744
    return NULL; /* failed */