Home | History | Annotate | Line # | Download | only in isc
      1 /*	$NetBSD: url.h,v 1.6 2026/08/29 14:55:19 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * SPDX-License-Identifier: MPL-2.0 and MIT
      7  *
      8  * This Source Code Form is subject to the terms of the Mozilla Public
      9  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  *
     12  * See the COPYRIGHT file distributed with this work for additional
     13  * information regarding copyright ownership.
     14  */
     15 
     16 /*
     17  * Copyright Joyent, Inc. and other Node contributors. All rights reserved.
     18  *
     19  * Permission is hereby granted, free of charge, to any person obtaining a copy
     20  * of this software and associated documentation files (the "Software"), to
     21  * deal in the Software without restriction, including without limitation the
     22  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
     23  * sell copies of the Software, and to permit persons to whom the Software is
     24  * furnished to do so, subject to the following conditions:
     25  *
     26  * The above copyright notice and this permission notice shall be included in
     27  * all copies or substantial portions of the Software.
     28  *
     29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     30  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     31  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     32  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     33  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     34  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     35  * IN THE SOFTWARE.
     36  */
     37 
     38 #pragma once
     39 
     40 #include <stdbool.h>
     41 #include <stddef.h>
     42 #include <stdint.h>
     43 
     44 #include <isc/result.h>
     45 
     46 /*
     47  * Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
     48  * faster
     49  */
     50 #ifndef HTTP_PARSER_STRICT
     51 #define HTTP_PARSER_STRICT 1
     52 #endif
     53 
     54 #define URL_MAX_LENGTH 8192
     55 
     56 typedef enum {
     57 	ISC_UF_SCHEMA = 0,
     58 	ISC_UF_HOST = 1,
     59 	ISC_UF_PORT = 2,
     60 	ISC_UF_PATH = 3,
     61 	ISC_UF_QUERY = 4,
     62 	ISC_UF_FRAGMENT = 5,
     63 	ISC_UF_USERINFO = 6,
     64 	ISC_UF_MAX = 7
     65 } isc_url_field_t;
     66 
     67 /* Result structure for isc_url_parse().
     68  *
     69  * Callers should index into field_data[] with UF_* values iff field_set
     70  * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
     71  * because we probably have padding left over), we convert any port to
     72  * a uint16_t.
     73  */
     74 typedef struct {
     75 	uint16_t field_set; /* Bitmask of (1 << UF_*) values */
     76 	uint16_t port;	    /* Converted UF_PORT string */
     77 
     78 	struct {
     79 		uint16_t off; /* Offset into buffer in which field starts */
     80 		uint16_t len; /* Length of run in buffer */
     81 	} field_data[ISC_UF_MAX];
     82 } isc_url_parser_t;
     83 
     84 isc_result_t
     85 isc_url_parse(const char *buf, size_t buflen, bool is_connect,
     86 	      isc_url_parser_t *up);
     87 /*%<
     88  * Parse a URL; return nonzero on failure
     89  */
     90