12c593315Sopenharmony_ci/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
22c593315Sopenharmony_ci *
32c593315Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
42c593315Sopenharmony_ci * of this software and associated documentation files (the "Software"), to
52c593315Sopenharmony_ci * deal in the Software without restriction, including without limitation the
62c593315Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
72c593315Sopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is
82c593315Sopenharmony_ci * furnished to do so, subject to the following conditions:
92c593315Sopenharmony_ci *
102c593315Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
112c593315Sopenharmony_ci * all copies or substantial portions of the Software.
122c593315Sopenharmony_ci *
132c593315Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
142c593315Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
152c593315Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
162c593315Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
172c593315Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
182c593315Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
192c593315Sopenharmony_ci * IN THE SOFTWARE.
202c593315Sopenharmony_ci */
212c593315Sopenharmony_ci#ifndef url_parser_h
222c593315Sopenharmony_ci#define url_parser_h
232c593315Sopenharmony_ci#ifdef __cplusplus
242c593315Sopenharmony_ciextern "C" {
252c593315Sopenharmony_ci#endif
262c593315Sopenharmony_ci
272c593315Sopenharmony_ci/* Also update SONAME in the Makefile whenever you change these. */
282c593315Sopenharmony_ci#define HTTP_PARSER_VERSION_MAJOR 2
292c593315Sopenharmony_ci#define HTTP_PARSER_VERSION_MINOR 9
302c593315Sopenharmony_ci#define HTTP_PARSER_VERSION_PATCH 1
312c593315Sopenharmony_ci
322c593315Sopenharmony_ci#include <stddef.h>
332c593315Sopenharmony_ci#if defined(_WIN32) && !defined(__MINGW32__) && \
342c593315Sopenharmony_ci  (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
352c593315Sopenharmony_ci#include <BaseTsd.h>
362c593315Sopenharmony_citypedef __int8 int8_t;
372c593315Sopenharmony_citypedef unsigned __int8 uint8_t;
382c593315Sopenharmony_citypedef __int16 int16_t;
392c593315Sopenharmony_citypedef unsigned __int16 uint16_t;
402c593315Sopenharmony_citypedef __int32 int32_t;
412c593315Sopenharmony_citypedef unsigned __int32 uint32_t;
422c593315Sopenharmony_citypedef __int64 int64_t;
432c593315Sopenharmony_citypedef unsigned __int64 uint64_t;
442c593315Sopenharmony_ci#else
452c593315Sopenharmony_ci#include <stdint.h>
462c593315Sopenharmony_ci#endif
472c593315Sopenharmony_ci
482c593315Sopenharmony_ci/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
492c593315Sopenharmony_ci * faster
502c593315Sopenharmony_ci */
512c593315Sopenharmony_ci#ifndef HTTP_PARSER_STRICT
522c593315Sopenharmony_ci# define HTTP_PARSER_STRICT 1
532c593315Sopenharmony_ci#endif
542c593315Sopenharmony_ci
552c593315Sopenharmony_cienum http_parser_url_fields
562c593315Sopenharmony_ci  { UF_SCHEMA           = 0
572c593315Sopenharmony_ci  , UF_HOST             = 1
582c593315Sopenharmony_ci  , UF_PORT             = 2
592c593315Sopenharmony_ci  , UF_PATH             = 3
602c593315Sopenharmony_ci  , UF_QUERY            = 4
612c593315Sopenharmony_ci  , UF_FRAGMENT         = 5
622c593315Sopenharmony_ci  , UF_USERINFO         = 6
632c593315Sopenharmony_ci  , UF_MAX              = 7
642c593315Sopenharmony_ci  };
652c593315Sopenharmony_ci
662c593315Sopenharmony_ci
672c593315Sopenharmony_ci/* Result structure for http_parser_parse_url().
682c593315Sopenharmony_ci *
692c593315Sopenharmony_ci * Callers should index into field_data[] with UF_* values iff field_set
702c593315Sopenharmony_ci * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
712c593315Sopenharmony_ci * because we probably have padding left over), we convert any port to
722c593315Sopenharmony_ci * a uint16_t.
732c593315Sopenharmony_ci */
742c593315Sopenharmony_cistruct http_parser_url {
752c593315Sopenharmony_ci  uint16_t field_set;           /* Bitmask of (1 << UF_*) values */
762c593315Sopenharmony_ci  uint16_t port;                /* Converted UF_PORT string */
772c593315Sopenharmony_ci
782c593315Sopenharmony_ci  struct {
792c593315Sopenharmony_ci    uint16_t off;               /* Offset into buffer in which field starts */
802c593315Sopenharmony_ci    uint16_t len;               /* Length of run in buffer */
812c593315Sopenharmony_ci  } field_data[UF_MAX];
822c593315Sopenharmony_ci};
832c593315Sopenharmony_ci
842c593315Sopenharmony_ci/* Initialize all http_parser_url members to 0 */
852c593315Sopenharmony_civoid http_parser_url_init(struct http_parser_url *u);
862c593315Sopenharmony_ci
872c593315Sopenharmony_ci/* Parse a URL; return nonzero on failure */
882c593315Sopenharmony_ciint http_parser_parse_url(const char *buf, size_t buflen,
892c593315Sopenharmony_ci                          int is_connect,
902c593315Sopenharmony_ci                          struct http_parser_url *u);
912c593315Sopenharmony_ci#ifdef __cplusplus
922c593315Sopenharmony_ci}
932c593315Sopenharmony_ci#endif
942c593315Sopenharmony_ci#endif
95