Home | History | Annotate | Download | only in lib
      1 #ifndef HEADER_CURL_FORMDATA_H
      2 #define HEADER_CURL_FORMDATA_H
      3 /***************************************************************************
      4  *                                  _   _ ____  _
      5  *  Project                     ___| | | |  _ \| |
      6  *                             / __| | | | |_) | |
      7  *                            | (__| |_| |  _ <| |___
      8  *                             \___|\___/|_| \_\_____|
      9  *
     10  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel (at) haxx.se>, et al.
     11  *
     12  * This software is licensed as described in the file COPYING, which
     13  * you should have received as part of this distribution. The terms
     14  * are also available at https://curl.haxx.se/docs/copyright.html.
     15  *
     16  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     17  * copies of the Software, and permit persons to whom the Software is
     18  * furnished to do so, under the terms of the COPYING file.
     19  *
     20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     21  * KIND, either express or implied.
     22  *
     23  ***************************************************************************/
     24 
     25 enum formtype {
     26   FORM_DATAMEM, /* already allocated FORM_DATA memory */
     27   FORM_DATA,    /* form metadata (convert to network encoding if necessary) */
     28   FORM_CONTENT, /* form content  (never convert) */
     29   FORM_CALLBACK, /* 'line' points to the custom pointer we pass to the callback
     30                   */
     31   FORM_FILE     /* 'line' points to a file name we should read from
     32                    to create the form data (never convert) */
     33 };
     34 
     35 /* plain and simple linked list with lines to send */
     36 struct FormData {
     37   struct FormData *next;
     38   enum formtype type;
     39   char *line;
     40   size_t length;
     41 };
     42 
     43 struct Form {
     44   struct FormData *data; /* current form line to send */
     45   size_t sent;           /* number of bytes of the current line that has
     46                             already been sent in a previous invoke */
     47   FILE *fp;              /* file to read from */
     48   curl_read_callback fread_func; /* fread callback pointer */
     49 };
     50 
     51 /* used by FormAdd for temporary storage */
     52 typedef struct FormInfo {
     53   char *name;
     54   bool name_alloc;
     55   size_t namelength;
     56   char *value;
     57   bool value_alloc;
     58   curl_off_t contentslength;
     59   char *contenttype;
     60   bool contenttype_alloc;
     61   long flags;
     62   char *buffer;      /* pointer to existing buffer used for file upload */
     63   size_t bufferlength;
     64   char *showfilename; /* The file name to show. If not set, the actual
     65                          file name will be used */
     66   bool showfilename_alloc;
     67   char *userp;        /* pointer for the read callback */
     68   struct curl_slist *contentheader;
     69   struct FormInfo *more;
     70 } FormInfo;
     71 
     72 int Curl_FormInit(struct Form *form, struct FormData *formdata);
     73 
     74 CURLcode Curl_getformdata(struct Curl_easy *data,
     75                           struct FormData **,
     76                           struct curl_httppost *post,
     77                           const char *custom_contenttype,
     78                           curl_off_t *size);
     79 
     80 /* fread() emulation */
     81 size_t Curl_FormReader(char *buffer,
     82                        size_t size,
     83                        size_t nitems,
     84                        FILE *mydata);
     85 
     86 /*
     87  * Curl_formpostheader() returns the first line of the formpost, the
     88  * request-header part (which is not part of the request-body like the rest of
     89  * the post).
     90  */
     91 char *Curl_formpostheader(void *formp, size_t *len);
     92 
     93 char *Curl_FormBoundary(void);
     94 
     95 void Curl_formclean(struct FormData **);
     96 
     97 CURLcode Curl_formconvert(struct Curl_easy *, struct FormData *);
     98 
     99 #endif /* HEADER_CURL_FORMDATA_H */
    100