Git init
[external/curl.git] / lib / http.h
1 #ifndef __HTTP_H
2 #define __HTTP_H
3
4 /***************************************************************************
5  *                                  _   _ ____  _
6  *  Project                     ___| | | |  _ \| |
7  *                             / __| | | | |_) | |
8  *                            | (__| |_| |  _ <| |___
9  *                             \___|\___/|_| \_\_____|
10  *
11  * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
12  *
13  * This software is licensed as described in the file COPYING, which
14  * you should have received as part of this distribution. The terms
15  * are also available at http://curl.haxx.se/docs/copyright.html.
16  *
17  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
18  * copies of the Software, and permit persons to whom the Software is
19  * furnished to do so, under the terms of the COPYING file.
20  *
21  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22  * KIND, either express or implied.
23  *
24  ***************************************************************************/
25 #ifndef CURL_DISABLE_HTTP
26
27 extern const struct Curl_handler Curl_handler_http;
28
29 #ifdef USE_SSL
30 extern const struct Curl_handler Curl_handler_https;
31 #endif
32
33 bool Curl_compareheader(const char *headerline,  /* line to check */
34                         const char *header,   /* header keyword _with_ colon */
35                         const char *content); /* content string to find */
36
37 char *Curl_checkheaders(struct SessionHandle *data, const char *thisheader);
38
39 char *Curl_copy_header_value(const char *h);
40
41
42 /* ------------------------------------------------------------------------- */
43 /*
44  * The add_buffer series of functions are used to build one large memory chunk
45  * from repeated function invokes. Used so that the entire HTTP request can
46  * be sent in one go.
47  */
48 struct Curl_send_buffer {
49   char *buffer;
50   size_t size_max;
51   size_t size_used;
52 };
53 typedef struct Curl_send_buffer Curl_send_buffer;
54
55 Curl_send_buffer *Curl_add_buffer_init(void);
56 CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...);
57 CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size);
58 CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
59                               struct connectdata *conn,
60                               long *bytes_written,
61                               size_t included_body_bytes,
62                               int socketindex);
63
64 CURLcode Curl_add_timecondition(struct SessionHandle *data,
65                                 Curl_send_buffer *buf);
66 CURLcode Curl_add_custom_headers(struct connectdata *conn,
67                                    Curl_send_buffer *req_buffer);
68
69
70 /* ftp can use this as well */
71 CURLcode Curl_proxyCONNECT(struct connectdata *conn,
72                            int tunnelsocket,
73                            const char *hostname, unsigned short remote_port);
74
75 /* protocol-specific functions set up to be called by the main engine */
76 CURLcode Curl_http(struct connectdata *conn, bool *done);
77 CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature);
78 CURLcode Curl_http_connect(struct connectdata *conn, bool *done);
79
80 /* The following functions are defined in http_chunks.c */
81 void Curl_httpchunk_init(struct connectdata *conn);
82 CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap,
83                               ssize_t length, ssize_t *wrote);
84
85 /* These functions are in http.c */
86 void Curl_http_auth_stage(struct SessionHandle *data, int stage);
87 CURLcode Curl_http_input_auth(struct connectdata *conn,
88                               int httpcode, const char *header);
89 CURLcode Curl_http_auth_act(struct connectdata *conn);
90 CURLcode Curl_http_perhapsrewind(struct connectdata *conn);
91
92 int Curl_http_should_fail(struct connectdata *conn);
93
94 /* If only the PICKNONE bit is set, there has been a round-trip and we
95    selected to use no auth at all. Ie, we actively select no auth, as opposed
96    to not having one selected. The other CURLAUTH_* defines are present in the
97    public curl/curl.h header. */
98 #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
99
100 /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
101    data get included in the initial data chunk sent to the server. If the
102    data is larger than this, it will automatically get split up in multiple
103    system calls.
104
105    This value used to be fairly big (100K), but we must take into account that
106    if the server rejects the POST due for authentication reasons, this data
107    will always be uncondtionally sent and thus it may not be larger than can
108    always be afforded to send twice.
109
110    It must not be greater than 64K to work on VMS.
111 */
112 #ifndef MAX_INITIAL_POST_SIZE
113 #define MAX_INITIAL_POST_SIZE (64*1024)
114 #endif
115
116 #ifndef TINY_INITIAL_POST_SIZE
117 #define TINY_INITIAL_POST_SIZE 1024
118 #endif
119
120 #endif /* CURL_DISABLE_HTTP */
121
122 /****************************************************************************
123  * HTTP unique setup
124  ***************************************************************************/
125 struct HTTP {
126   struct FormData *sendit;
127   curl_off_t postsize; /* off_t to handle large file sizes */
128   const char *postdata;
129
130   const char *p_pragma;      /* Pragma: string */
131   const char *p_accept;      /* Accept: string */
132   curl_off_t readbytecount;
133   curl_off_t writebytecount;
134
135   /* For FORM posting */
136   struct Form form;
137
138   struct back {
139     curl_read_callback fread_func; /* backup storage for fread pointer */
140     void *fread_in;           /* backup storage for fread_in pointer */
141     const char *postdata;
142     curl_off_t postsize;
143   } backup;
144
145   enum {
146     HTTPSEND_NADA,    /* init */
147     HTTPSEND_REQUEST, /* sending a request */
148     HTTPSEND_BODY,    /* sending body */
149     HTTPSEND_LAST     /* never use this */
150   } sending;
151
152   void *send_buffer; /* used if the request couldn't be sent in one chunk,
153                         points to an allocated send_buffer struct */
154 };
155
156 CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
157                                      struct connectdata *conn,
158                                      ssize_t *nread,
159                                      bool *stop_reading);
160
161 #endif