Annotation of embedaddon/curl/lib/http.h, revision 1.1.1.1

1.1       misho       1: #ifndef HEADER_CURL_HTTP_H
                      2: #define HEADER_CURL_HTTP_H
                      3: /***************************************************************************
                      4:  *                                  _   _ ____  _
                      5:  *  Project                     ___| | | |  _ \| |
                      6:  *                             / __| | | | |_) | |
                      7:  *                            | (__| |_| |  _ <| |___
                      8:  *                             \___|\___/|_| \_\_____|
                      9:  *
                     10:  * Copyright (C) 1998 - 2020, 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: #include "curl_setup.h"
                     25: 
                     26: #ifndef CURL_DISABLE_HTTP
                     27: 
                     28: #ifdef USE_NGHTTP2
                     29: #include <nghttp2/nghttp2.h>
                     30: #endif
                     31: 
                     32: extern const struct Curl_handler Curl_handler_http;
                     33: 
                     34: #ifdef USE_SSL
                     35: extern const struct Curl_handler Curl_handler_https;
                     36: #endif
                     37: 
                     38: /* Header specific functions */
                     39: bool Curl_compareheader(const char *headerline,  /* line to check */
                     40:                         const char *header,   /* header keyword _with_ colon */
                     41:                         const char *content); /* content string to find */
                     42: 
                     43: char *Curl_copy_header_value(const char *header);
                     44: 
                     45: char *Curl_checkProxyheaders(const struct connectdata *conn,
                     46:                              const char *thisheader);
                     47: /* ------------------------------------------------------------------------- */
                     48: /*
                     49:  * The add_buffer series of functions are used to build one large memory chunk
                     50:  * from repeated function invokes. Used so that the entire HTTP request can
                     51:  * be sent in one go.
                     52:  */
                     53: struct Curl_send_buffer {
                     54:   char *buffer;
                     55:   size_t size_max;
                     56:   size_t size_used;
                     57: };
                     58: typedef struct Curl_send_buffer Curl_send_buffer;
                     59: 
                     60: Curl_send_buffer *Curl_add_buffer_init(void);
                     61: void Curl_add_buffer_free(Curl_send_buffer **inp);
                     62: CURLcode Curl_add_bufferf(Curl_send_buffer **inp, const char *fmt, ...)
                     63:   WARN_UNUSED_RESULT;
                     64: CURLcode Curl_add_buffer(Curl_send_buffer **inp, const void *inptr,
                     65:                          size_t size) WARN_UNUSED_RESULT;
                     66: CURLcode Curl_add_buffer_send(Curl_send_buffer **inp,
                     67:                               struct connectdata *conn,
                     68:                               curl_off_t *bytes_written,
                     69:                               size_t included_body_bytes,
                     70:                               int socketindex);
                     71: 
                     72: CURLcode Curl_add_timecondition(const struct connectdata *conn,
                     73:                                 Curl_send_buffer *buf);
                     74: CURLcode Curl_add_custom_headers(struct connectdata *conn,
                     75:                                  bool is_connect,
                     76:                                  Curl_send_buffer *req_buffer);
                     77: CURLcode Curl_http_compile_trailers(struct curl_slist *trailers,
                     78:                                     Curl_send_buffer **buffer,
                     79:                                     struct Curl_easy *handle);
                     80: 
                     81: /* protocol-specific functions set up to be called by the main engine */
                     82: CURLcode Curl_http(struct connectdata *conn, bool *done);
                     83: CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature);
                     84: CURLcode Curl_http_connect(struct connectdata *conn, bool *done);
                     85: 
                     86: /* These functions are in http.c */
                     87: CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
                     88:                               const char *auth);
                     89: CURLcode Curl_http_auth_act(struct connectdata *conn);
                     90: 
                     91: /* If only the PICKNONE bit is set, there has been a round-trip and we
                     92:    selected to use no auth at all. Ie, we actively select no auth, as opposed
                     93:    to not having one selected. The other CURLAUTH_* defines are present in the
                     94:    public curl/curl.h header. */
                     95: #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
                     96: 
                     97: /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
                     98:    data get included in the initial data chunk sent to the server. If the
                     99:    data is larger than this, it will automatically get split up in multiple
                    100:    system calls.
                    101: 
                    102:    This value used to be fairly big (100K), but we must take into account that
                    103:    if the server rejects the POST due for authentication reasons, this data
                    104:    will always be unconditionally sent and thus it may not be larger than can
                    105:    always be afforded to send twice.
                    106: 
                    107:    It must not be greater than 64K to work on VMS.
                    108: */
                    109: #ifndef MAX_INITIAL_POST_SIZE
                    110: #define MAX_INITIAL_POST_SIZE (64*1024)
                    111: #endif
                    112: 
                    113: /* EXPECT_100_THRESHOLD is the request body size limit for when libcurl will
                    114:  * automatically add an "Expect: 100-continue" header in HTTP requests. When
                    115:  * the size is unknown, it will always add it.
                    116:  *
                    117:  */
                    118: #ifndef EXPECT_100_THRESHOLD
                    119: #define EXPECT_100_THRESHOLD (1024*1024)
                    120: #endif
                    121: 
                    122: #endif /* CURL_DISABLE_HTTP */
                    123: 
                    124: #ifdef USE_NGHTTP3
                    125: struct h3out; /* see ngtcp2 */
                    126: #endif
                    127: 
                    128: /****************************************************************************
                    129:  * HTTP unique setup
                    130:  ***************************************************************************/
                    131: struct HTTP {
                    132:   curl_mimepart *sendit;
                    133:   curl_off_t postsize; /* off_t to handle large file sizes */
                    134:   const char *postdata;
                    135: 
                    136:   const char *p_pragma;      /* Pragma: string */
                    137:   const char *p_accept;      /* Accept: string */
                    138: 
                    139:   /* For FORM posting */
                    140:   curl_mimepart form;
                    141: 
                    142:   struct back {
                    143:     curl_read_callback fread_func; /* backup storage for fread pointer */
                    144:     void *fread_in;           /* backup storage for fread_in pointer */
                    145:     const char *postdata;
                    146:     curl_off_t postsize;
                    147:   } backup;
                    148: 
                    149:   enum {
                    150:     HTTPSEND_NADA,    /* init */
                    151:     HTTPSEND_REQUEST, /* sending a request */
                    152:     HTTPSEND_BODY,    /* sending body */
                    153:     HTTPSEND_LAST     /* never use this */
                    154:   } sending;
                    155: 
                    156: #ifndef CURL_DISABLE_HTTP
                    157:   Curl_send_buffer *send_buffer; /* used if the request couldn't be sent in
                    158:                                     one chunk, points to an allocated
                    159:                                     send_buffer struct */
                    160: #endif
                    161: #ifdef USE_NGHTTP2
                    162:   /*********** for HTTP/2 we store stream-local data here *************/
                    163:   int32_t stream_id; /* stream we are interested in */
                    164: 
                    165:   bool bodystarted;
                    166:   /* We store non-final and final response headers here, per-stream */
                    167:   Curl_send_buffer *header_recvbuf;
                    168:   size_t nread_header_recvbuf; /* number of bytes in header_recvbuf fed into
                    169:                                   upper layer */
                    170:   Curl_send_buffer *trailer_recvbuf;
                    171:   int status_code; /* HTTP status code */
                    172:   const uint8_t *pausedata; /* pointer to data received in on_data_chunk */
                    173:   size_t pauselen; /* the number of bytes left in data */
                    174:   bool close_handled; /* TRUE if stream closure is handled by libcurl */
                    175: 
                    176:   char **push_headers;       /* allocated array */
                    177:   size_t push_headers_used;  /* number of entries filled in */
                    178:   size_t push_headers_alloc; /* number of entries allocated */
                    179: #endif
                    180: #if defined(USE_NGHTTP2) || defined(USE_NGHTTP3)
                    181:   bool closed; /* TRUE on HTTP2 stream close */
                    182:   char *mem;     /* points to a buffer in memory to store received data */
                    183:   size_t len;    /* size of the buffer 'mem' points to */
                    184:   size_t memlen; /* size of data copied to mem */
                    185: #endif
                    186: #if defined(USE_NGHTTP2) || defined(ENABLE_QUIC)
                    187:   /* fields used by both HTTP/2 and HTTP/3 */
                    188:   const uint8_t *upload_mem; /* points to a buffer to read from */
                    189:   size_t upload_len; /* size of the buffer 'upload_mem' points to */
                    190:   curl_off_t upload_left; /* number of bytes left to upload */
                    191: #endif
                    192: 
                    193: #ifdef ENABLE_QUIC
                    194:   /*********** for HTTP/3 we store stream-local data here *************/
                    195:   int64_t stream3_id; /* stream we are interested in */
                    196:   bool firstheader;  /* FALSE until headers arrive */
                    197:   bool firstbody;  /* FALSE until body arrives */
                    198:   bool h3req;    /* FALSE until request is issued */
                    199:   bool upload_done;
                    200: #endif
                    201: #ifdef USE_NGHTTP3
                    202:   size_t unacked_window;
                    203:   struct h3out *h3out; /* per-stream buffers for upload */
                    204:   char *overflow_buf; /* excess data received during a single Curl_read */
                    205:   size_t overflow_buflen; /* amount of data currently in overflow_buf */
                    206:   size_t overflow_bufsize; /* size of the overflow_buf allocation */
                    207: #endif
                    208: };
                    209: 
                    210: #ifdef USE_NGHTTP2
                    211: /* h2 settings for this connection */
                    212: struct h2settings {
                    213:   uint32_t max_concurrent_streams;
                    214:   bool enable_push;
                    215: };
                    216: #endif
                    217: 
                    218: struct http_conn {
                    219: #ifdef USE_NGHTTP2
                    220: #define H2_BINSETTINGS_LEN 80
                    221:   nghttp2_session *h2;
                    222:   uint8_t binsettings[H2_BINSETTINGS_LEN];
                    223:   size_t  binlen; /* length of the binsettings data */
                    224:   Curl_send *send_underlying; /* underlying send Curl_send callback */
                    225:   Curl_recv *recv_underlying; /* underlying recv Curl_recv callback */
                    226:   char *inbuf; /* buffer to receive data from underlying socket */
                    227:   size_t inbuflen; /* number of bytes filled in inbuf */
                    228:   size_t nread_inbuf; /* number of bytes read from in inbuf */
                    229:   /* We need separate buffer for transmission and reception because we
                    230:      may call nghttp2_session_send() after the
                    231:      nghttp2_session_mem_recv() but mem buffer is still not full. In
                    232:      this case, we wrongly sends the content of mem buffer if we share
                    233:      them for both cases. */
                    234:   int32_t pause_stream_id; /* stream ID which paused
                    235:                               nghttp2_session_mem_recv */
                    236:   size_t drain_total; /* sum of all stream's UrlState.drain */
                    237: 
                    238:   /* this is a hash of all individual streams (Curl_easy structs) */
                    239:   struct h2settings settings;
                    240: 
                    241:   /* list of settings that will be sent */
                    242:   nghttp2_settings_entry local_settings[3];
                    243:   size_t local_settings_num;
                    244:   uint32_t error_code; /* HTTP/2 error code */
                    245: #else
                    246:   int unused; /* prevent a compiler warning */
                    247: #endif
                    248: };
                    249: 
                    250: CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
                    251:                                      struct connectdata *conn,
                    252:                                      ssize_t *nread,
                    253:                                      bool *stop_reading);
                    254: 
                    255: /**
                    256:  * Curl_http_output_auth() setups the authentication headers for the
                    257:  * host/proxy and the correct authentication
                    258:  * method. conn->data->state.authdone is set to TRUE when authentication is
                    259:  * done.
                    260:  *
                    261:  * @param conn all information about the current connection
                    262:  * @param request pointer to the request keyword
                    263:  * @param path pointer to the requested path
                    264:  * @param proxytunnel boolean if this is the request setting up a "proxy
                    265:  * tunnel"
                    266:  *
                    267:  * @returns CURLcode
                    268:  */
                    269: CURLcode
                    270: Curl_http_output_auth(struct connectdata *conn,
                    271:                       const char *request,
                    272:                       const char *path,
                    273:                       bool proxytunnel); /* TRUE if this is the request setting
                    274:                                             up the proxy tunnel */
                    275: 
                    276: #endif /* HEADER_CURL_HTTP_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>