Annotation of embedaddon/php/sapi/cli/php_http_parser.h, revision 1.1

1.1     ! misho       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
        !            25: extern "C" {
        !            26: #endif
        !            27: 
        !            28: 
        !            29: #include <sys/types.h>
        !            30: #if defined(_WIN32) && !defined(__MINGW32__)
        !            31: # include <windows.h>
        !            32: # include "win32/php_stdint.h"
        !            33: # include "config.w32.h"
        !            34: #else
        !            35: # include <stdint.h>
        !            36: #endif
        !            37: 
        !            38: /* Compile with -DPHP_HTTP_PARSER_STRICT=0 to make less checks, but run
        !            39:  * faster
        !            40:  */
        !            41: #ifndef PHP_HTTP_PARSER_STRICT
        !            42: # define PHP_HTTP_PARSER_STRICT 1
        !            43: #else
        !            44: # define PHP_HTTP_PARSER_STRICT 0
        !            45: #endif
        !            46: 
        !            47: 
        !            48: /* Maximium header size allowed */
        !            49: #define PHP_HTTP_MAX_HEADER_SIZE (80*1024)
        !            50: 
        !            51: 
        !            52: typedef struct php_http_parser php_http_parser;
        !            53: typedef struct php_http_parser_settings php_http_parser_settings;
        !            54: 
        !            55: 
        !            56: /* Callbacks should return non-zero to indicate an error. The parser will
        !            57:  * then halt execution.
        !            58:  *
        !            59:  * The one exception is on_headers_complete. In a PHP_HTTP_RESPONSE parser
        !            60:  * returning '1' from on_headers_complete will tell the parser that it
        !            61:  * should not expect a body. This is used when receiving a response to a
        !            62:  * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
        !            63:  * chunked' headers that indicate the presence of a body.
        !            64:  *
        !            65:  * http_data_cb does not return data chunks. It will be call arbitrarally
        !            66:  * many times for each string. E.G. you might get 10 callbacks for "on_path"
        !            67:  * each providing just a few characters more data.
        !            68:  */
        !            69: typedef int (*php_http_data_cb) (php_http_parser*, const char *at, size_t length);
        !            70: typedef int (*php_http_cb) (php_http_parser*);
        !            71: 
        !            72: 
        !            73: /* Request Methods */
        !            74: enum php_http_method
        !            75:   { PHP_HTTP_DELETE    = 0
        !            76:   , PHP_HTTP_GET
        !            77:   , PHP_HTTP_HEAD
        !            78:   , PHP_HTTP_POST
        !            79:   , PHP_HTTP_PUT
        !            80:   /* pathological */
        !            81:   , PHP_HTTP_CONNECT
        !            82:   , PHP_HTTP_OPTIONS
        !            83:   , PHP_HTTP_TRACE
        !            84:   /* webdav */
        !            85:   , PHP_HTTP_COPY
        !            86:   , PHP_HTTP_LOCK
        !            87:   , PHP_HTTP_MKCOL
        !            88:   , PHP_HTTP_MOVE
        !            89:   , PHP_HTTP_PROPFIND
        !            90:   , PHP_HTTP_PROPPATCH
        !            91:   , PHP_HTTP_UNLOCK
        !            92:   /* subversion */
        !            93:   , PHP_HTTP_REPORT
        !            94:   , PHP_HTTP_MKACTIVITY
        !            95:   , PHP_HTTP_CHECKOUT
        !            96:   , PHP_HTTP_MERGE
        !            97:   /* upnp */
        !            98:   , PHP_HTTP_MSEARCH
        !            99:   , PHP_HTTP_NOTIFY
        !           100:   , PHP_HTTP_SUBSCRIBE
        !           101:   , PHP_HTTP_UNSUBSCRIBE
        !           102:   };
        !           103: 
        !           104: 
        !           105: enum php_http_parser_type { PHP_HTTP_REQUEST, PHP_HTTP_RESPONSE, PHP_HTTP_BOTH };
        !           106: 
        !           107: 
        !           108: struct php_http_parser {
        !           109:   /** PRIVATE **/
        !           110:   unsigned char type : 2;
        !           111:   unsigned char flags : 6;
        !           112:   unsigned char state;
        !           113:   unsigned char header_state;
        !           114:   unsigned char index;
        !           115: 
        !           116:   uint32_t nread;
        !           117:   ssize_t  content_length;
        !           118: 
        !           119:   /** READ-ONLY **/
        !           120:   unsigned short http_major;
        !           121:   unsigned short http_minor;
        !           122:   unsigned short status_code; /* responses only */
        !           123:   unsigned char method;    /* requests only */
        !           124: 
        !           125:   /* 1 = Upgrade header was present and the parser has exited because of that.
        !           126:    * 0 = No upgrade header present.
        !           127:    * Should be checked when http_parser_execute() returns in addition to
        !           128:    * error checking.
        !           129:    */
        !           130:   char upgrade;
        !           131: 
        !           132:   /** PUBLIC **/
        !           133:   void *data; /* A pointer to get hook to the "connection" or "socket" object */
        !           134: };
        !           135: 
        !           136: 
        !           137: struct php_http_parser_settings {
        !           138:   php_http_cb      on_message_begin;
        !           139:   php_http_data_cb on_path;
        !           140:   php_http_data_cb on_query_string;
        !           141:   php_http_data_cb on_url;
        !           142:   php_http_data_cb on_fragment;
        !           143:   php_http_data_cb on_header_field;
        !           144:   php_http_data_cb on_header_value;
        !           145:   php_http_cb      on_headers_complete;
        !           146:   php_http_data_cb on_body;
        !           147:   php_http_cb      on_message_complete;
        !           148: };
        !           149: 
        !           150: 
        !           151: void php_http_parser_init(php_http_parser *parser, enum php_http_parser_type type);
        !           152: 
        !           153: 
        !           154: size_t php_http_parser_execute(php_http_parser *parser,
        !           155:                            const php_http_parser_settings *settings,
        !           156:                            const char *data,
        !           157:                            size_t len);
        !           158: 
        !           159: 
        !           160: /* If php_http_should_keep_alive() in the on_headers_complete or
        !           161:  * on_message_complete callback returns true, then this will be should be
        !           162:  * the last message on the connection.
        !           163:  * If you are the server, respond with the "Connection: close" header.
        !           164:  * If you are the client, close the connection.
        !           165:  */
        !           166: int php_http_should_keep_alive(php_http_parser *parser);
        !           167: 
        !           168: /* Returns a string version of the HTTP method. */
        !           169: const char *php_http_method_str(enum php_http_method);
        !           170: 
        !           171: #ifdef __cplusplus
        !           172: }
        !           173: #endif
        !           174: #endif

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