1#ifndef __HTTP_H
2#define __HTTP_H
3
4/***************************************************************************
5 *                                  _   _ ____  _
6 *  Project                     ___| | | |  _ \| |
7 *                             / __| | | | |_) | |
8 *                            | (__| |_| |  _ <| |___
9 *                             \___|\___/|_| \_\_____|
10 *
11 * Copyright (C) 1998 - 2011, 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
27extern const struct Curl_handler Curl_handler_http;
28
29#ifdef USE_SSL
30extern const struct Curl_handler Curl_handler_https;
31#endif
32
33bool 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
37char *Curl_checkheaders(struct SessionHandle *data, const char *thisheader);
38
39/* ------------------------------------------------------------------------- */
40/*
41 * The add_buffer series of functions are used to build one large memory chunk
42 * from repeated function invokes. Used so that the entire HTTP request can
43 * be sent in one go.
44 */
45struct Curl_send_buffer {
46  char *buffer;
47  size_t size_max;
48  size_t size_used;
49};
50typedef struct Curl_send_buffer Curl_send_buffer;
51
52Curl_send_buffer *Curl_add_buffer_init(void);
53CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...);
54CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size);
55CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
56                              struct connectdata *conn,
57                              long *bytes_written,
58                              size_t included_body_bytes,
59                              int socketindex);
60
61CURLcode Curl_add_timecondition(struct SessionHandle *data,
62                                Curl_send_buffer *buf);
63CURLcode Curl_add_custom_headers(struct connectdata *conn,
64                                   Curl_send_buffer *req_buffer);
65
66/* protocol-specific functions set up to be called by the main engine */
67CURLcode Curl_http(struct connectdata *conn, bool *done);
68CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature);
69CURLcode Curl_http_connect(struct connectdata *conn, bool *done);
70
71/* The following functions are defined in http_chunks.c */
72void Curl_httpchunk_init(struct connectdata *conn);
73CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap,
74                              ssize_t length, ssize_t *wrote);
75
76/* These functions are in http.c */
77void Curl_http_auth_stage(struct SessionHandle *data, int stage);
78CURLcode Curl_http_input_auth(struct connectdata *conn,
79                              int httpcode, const char *header);
80CURLcode Curl_http_auth_act(struct connectdata *conn);
81CURLcode Curl_http_perhapsrewind(struct connectdata *conn);
82
83/* If only the PICKNONE bit is set, there has been a round-trip and we
84   selected to use no auth at all. Ie, we actively select no auth, as opposed
85   to not having one selected. The other CURLAUTH_* defines are present in the
86   public curl/curl.h header. */
87#define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
88
89/* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
90   data get included in the initial data chunk sent to the server. If the
91   data is larger than this, it will automatically get split up in multiple
92   system calls.
93
94   This value used to be fairly big (100K), but we must take into account that
95   if the server rejects the POST due for authentication reasons, this data
96   will always be uncondtionally sent and thus it may not be larger than can
97   always be afforded to send twice.
98
99   It must not be greater than 64K to work on VMS.
100*/
101#ifndef MAX_INITIAL_POST_SIZE
102#define MAX_INITIAL_POST_SIZE (64*1024)
103#endif
104
105#ifndef TINY_INITIAL_POST_SIZE
106#define TINY_INITIAL_POST_SIZE 1024
107#endif
108
109#endif /* CURL_DISABLE_HTTP */
110
111/****************************************************************************
112 * HTTP unique setup
113 ***************************************************************************/
114struct HTTP {
115  struct FormData *sendit;
116  curl_off_t postsize; /* off_t to handle large file sizes */
117  const char *postdata;
118
119  const char *p_pragma;      /* Pragma: string */
120  const char *p_accept;      /* Accept: string */
121  curl_off_t readbytecount;
122  curl_off_t writebytecount;
123
124  /* For FORM posting */
125  struct Form form;
126
127  struct back {
128    curl_read_callback fread_func; /* backup storage for fread pointer */
129    void *fread_in;           /* backup storage for fread_in pointer */
130    const char *postdata;
131    curl_off_t postsize;
132  } backup;
133
134  enum {
135    HTTPSEND_NADA,    /* init */
136    HTTPSEND_REQUEST, /* sending a request */
137    HTTPSEND_BODY,    /* sending body */
138    HTTPSEND_LAST     /* never use this */
139  } sending;
140
141  void *send_buffer; /* used if the request couldn't be sent in one chunk,
142                        points to an allocated send_buffer struct */
143};
144
145CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
146                                     struct connectdata *conn,
147                                     ssize_t *nread,
148                                     bool *stop_reading);
149
150/**
151 * Curl_http_output_auth() setups the authentication headers for the
152 * host/proxy and the correct authentication
153 * method. conn->data->state.authdone is set to TRUE when authentication is
154 * done.
155 *
156 * @param conn all information about the current connection
157 * @param request pointer to the request keyword
158 * @param path pointer to the requested path
159 * @param proxytunnel boolean if this is the request setting up a "proxy
160 * tunnel"
161 *
162 * @returns CURLcode
163 */
164CURLcode
165Curl_http_output_auth(struct connectdata *conn,
166                      const char *request,
167                      const char *path,
168                      bool proxytunnel); /* TRUE if this is the request setting
169                                            up the proxy tunnel */
170
171#endif
172