Imported Upstream version 7.48.0
[platform/upstream/curl.git] / lib / formdata.h
1 #ifndef HEADER_CURL_FORMDATA_H
2 #define HEADER_CURL_FORMDATA_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@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_DATA,    /* form metadata (convert to network encoding if necessary) */
27   FORM_CONTENT, /* form content  (never convert) */
28   FORM_CALLBACK, /* 'line' points to the custom pointer we pass to the callback
29                   */
30   FORM_FILE     /* 'line' points to a file name we should read from
31                    to create the form data (never convert) */
32 };
33
34 /* plain and simple linked list with lines to send */
35 struct FormData {
36   struct FormData *next;
37   enum formtype type;
38   char *line;
39   size_t length;
40 };
41
42 struct Form {
43   struct FormData *data; /* current form line to send */
44   size_t sent;           /* number of bytes of the current line that has
45                             already been sent in a previous invoke */
46   FILE *fp;              /* file to read from */
47   curl_read_callback fread_func; /* fread callback pointer */
48 };
49
50 /* used by FormAdd for temporary storage */
51 typedef struct FormInfo {
52   char *name;
53   bool name_alloc;
54   size_t namelength;
55   char *value;
56   bool value_alloc;
57   curl_off_t contentslength;
58   char *contenttype;
59   bool contenttype_alloc;
60   long flags;
61   char *buffer;      /* pointer to existing buffer used for file upload */
62   size_t bufferlength;
63   char *showfilename; /* The file name to show. If not set, the actual
64                          file name will be used */
65   bool showfilename_alloc;
66   char *userp;        /* pointer for the read callback */
67   struct curl_slist* contentheader;
68   struct FormInfo *more;
69 } FormInfo;
70
71 int Curl_FormInit(struct Form *form, struct FormData *formdata );
72
73 CURLcode Curl_getformdata(struct SessionHandle *data,
74                           struct FormData **,
75                           struct curl_httppost *post,
76                           const char *custom_contenttype,
77                           curl_off_t *size);
78
79 /* fread() emulation */
80 size_t Curl_FormReader(char *buffer,
81                        size_t size,
82                        size_t nitems,
83                        FILE *mydata);
84
85 /*
86  * Curl_formpostheader() returns the first line of the formpost, the
87  * request-header part (which is not part of the request-body like the rest of
88  * the post).
89  */
90 char *Curl_formpostheader(void *formp, size_t *len);
91
92 char *Curl_FormBoundary(void);
93
94 void Curl_formclean(struct FormData **);
95
96 CURLcode Curl_formconvert(struct SessionHandle *, struct FormData *);
97
98 #endif /* HEADER_CURL_FORMDATA_H */