php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
php_http_parser.h
Go to the documentation of this file.
1/* Copyright 2009,2010 Ryan Dahl <ry@tinyclouds.org>
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21/* modified by Moriyoshi Koizumi <moriyoshi@php.net> to make it fit to PHP source tree. */
22#ifndef php_http_parser_h
23#define php_http_parser_h
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28
29#include <sys/types.h>
30#if defined(_WIN32) && !defined(__MINGW32__)
31# include <windows.h>
32# include "config.w32.h"
33#else
34# include <php_config.h>
35#endif
36
37#include <stdint.h>
38
39/* Compile with -DPHP_HTTP_PARSER_STRICT=0 to make less checks, but run
40 * faster
41 */
42#ifndef PHP_HTTP_PARSER_STRICT
43# define PHP_HTTP_PARSER_STRICT 1
44#else
45# define PHP_HTTP_PARSER_STRICT 0
46#endif
47
48
49/* Maximum header size allowed */
50#define PHP_HTTP_MAX_HEADER_SIZE (80*1024)
51
52
55
56
57/* Callbacks should return non-zero to indicate an error. The parser will
58 * then halt execution.
59 *
60 * The one exception is on_headers_complete. In a PHP_HTTP_RESPONSE parser
61 * returning '1' from on_headers_complete will tell the parser that it
62 * should not expect a body. This is used when receiving a response to a
63 * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
64 * chunked' headers that indicate the presence of a body.
65 *
66 * http_data_cb does not return data chunks. It will be call arbitrarily
67 * many times for each string. E.G. you might get 10 callbacks for "on_path"
68 * each providing just a few characters more data.
69 */
70typedef int (*php_http_data_cb) (php_http_parser*, const char *at, size_t length);
71typedef int (*php_http_cb) (php_http_parser*);
72
73
74/* Request Methods */
109
110
112
114 { s_dead = 1 /* important that this is > 0 */
115
131
133
156
161
163
165 /* Important: 's_headers_almost_done' must be the last 'header' state. All
166 * states beyond this must be 'body' states. It is used for overflow
167 * checking. See the PARSING_HEADER() macro.
168 */
176
179 };
180
183 unsigned char type : 2;
184 unsigned char flags : 6;
185 unsigned char state;
186 unsigned char header_state;
187 unsigned char index;
188
189 uint32_t nread;
191
193 unsigned short http_major;
194 unsigned short http_minor;
195 unsigned short status_code; /* responses only */
196 unsigned char method; /* requests only */
197
198 /* 1 = Upgrade header was present and the parser has exited because of that.
199 * 0 = No upgrade header present.
200 * Should be checked when http_parser_execute() returns in addition to
201 * error checking.
202 */
204
206 void *data; /* A pointer to get hook to the "connection" or "socket" object */
207};
208
209
222
223
225
226
228 const php_http_parser_settings *settings,
229 const char *data,
230 size_t len);
231
232
233/* If php_http_should_keep_alive() in the on_headers_complete or
234 * on_message_complete callback returns true, then this will be should be
235 * the last message on the connection.
236 * If you are the server, respond with the "Connection: close" header.
237 * If you are the client, close the connection.
238 */
240
241/* Returns a string version of the HTTP method. */
242const char *php_http_method_str(enum php_http_method);
243
244#ifdef __cplusplus
245}
246#endif
247#endif
size_t len
Definition apprentice.c:174
zend_ffi_type * type
Definition ffi.c:3812
int(* php_http_data_cb)(php_http_parser *, const char *at, size_t length)
int(* php_http_cb)(php_http_parser *)
php_http_method
@ PHP_HTTP_CONNECT
@ PHP_HTTP_UNSUBSCRIBE
@ PHP_HTTP_NOTIFY
@ PHP_HTTP_OPTIONS
@ PHP_HTTP_MOVE
@ PHP_HTTP_PUT
@ PHP_HTTP_POST
@ PHP_HTTP_PROPFIND
@ PHP_HTTP_GET
@ PHP_HTTP_PROPPATCH
@ PHP_HTTP_NOT_IMPLEMENTED
@ PHP_HTTP_MSEARCH
@ PHP_HTTP_DELETE
@ PHP_HTTP_HEAD
@ PHP_HTTP_SEARCH
@ PHP_HTTP_MKCOL
@ PHP_HTTP_REPORT
@ PHP_HTTP_PATCH
@ PHP_HTTP_LOCK
@ PHP_HTTP_UNLOCK
@ PHP_HTTP_MKCALENDAR
@ PHP_HTTP_SUBSCRIBE
@ PHP_HTTP_COPY
@ PHP_HTTP_MERGE
@ PHP_HTTP_MKACTIVITY
@ PHP_HTTP_TRACE
@ PHP_HTTP_CHECKOUT
int php_http_should_keep_alive(php_http_parser *parser)
void php_http_parser_init(php_http_parser *parser, enum php_http_parser_type type)
php_http_parser_type
@ PHP_HTTP_REQUEST
@ PHP_HTTP_RESPONSE
@ PHP_HTTP_BOTH
@ s_body_identity
@ s_req_port
@ s_chunk_data_done
@ s_chunk_size_almost_done
@ s_start_res
@ s_body_identity_eof
@ s_chunk_data
@ s_res_H
@ s_res_first_status_code
@ s_res_first_http_minor
@ s_res_status
@ s_header_field
@ s_req_query_string
@ s_req_query_string_start
@ s_res_http_major
@ s_req_spaces_before_url
@ s_header_almost_done
@ s_req_path
@ s_res_HTTP
@ s_header_value
@ s_req_host
@ s_start_req_or_res
@ s_req_method
@ s_chunk_size
@ s_req_http_HTTP
@ s_req_http_minor
@ s_chunk_parameters
@ s_start_req
@ s_res_first_http_major
@ s_res_http_minor
@ s_req_schema
@ s_req_http_H
@ s_req_schema_slash_slash
@ s_header_field_start
@ s_req_first_http_major
@ s_res_line_almost_done
@ s_header_value_start
@ s_res_HTT
@ s_req_http_major
@ s_req_line_almost_done
@ s_headers_almost_done
@ s_req_fragment
@ s_req_schema_slash
@ s_res_or_resp_H
@ s_req_fragment_start
@ s_req_http_HT
@ s_dead
@ s_req_http_start
@ s_req_http_HTT
@ s_res_HT
@ s_res_status_code
@ s_req_first_http_minor
@ s_chunk_size_start
@ s_chunk_data_almost_done
size_t php_http_parser_execute(php_http_parser *parser, const php_http_parser_settings *settings, const char *data, size_t len)
const char * php_http_method_str(enum php_http_method)
zend_constant * data
php_http_data_cb on_query_string
php_http_data_cb on_header_value
php_http_data_cb on_header_field
php_http_data_cb on_fragment
unsigned char header_state
unsigned char index
unsigned char flags
unsigned short http_minor
unsigned short status_code
unsigned char state
unsigned char method
unsigned short http_major
unsigned char type