This file is indexed.

/usr/include/h2o/url.h is in libh2o-dev-common 2.2.4+dfsg-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * Copyright (c) 2014,2015 DeNA Co., Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */
#ifndef h2o__url_h
#define h2o__url_h

#include <sys/un.h>
#include "h2o/memory.h"

typedef struct st_h2o_url_scheme_t {
    h2o_iovec_t name;
    uint16_t default_port;
} h2o_url_scheme_t;

extern const h2o_url_scheme_t H2O_URL_SCHEME_HTTP, H2O_URL_SCHEME_HTTPS;

typedef struct st_h2o_url_t {
    const h2o_url_scheme_t *scheme;
    h2o_iovec_t authority; /* i.e. host:port */
    h2o_iovec_t host;
    h2o_iovec_t path;
    uint16_t _port;
} h2o_url_t;

/**
 * retrieves the port number from url
 */
static uint16_t h2o_url_get_port(const h2o_url_t *url);
/**
 * removes "..", ".", decodes %xx from a path representation
 * @param pool memory pool to be used in case the path contained references to directories
 * @param path source path
 * @param len source length
 * @param returns offset of '?' within `path` if found, or SIZE_MAX if not
 * @param indexes mapping the normalized version to the input version
 * @return buffer pointing to source, or buffer pointing to an allocated chunk with normalized representation of the given path
 */
h2o_iovec_t h2o_url_normalize_path(h2o_mem_pool_t *pool, const char *path, size_t len, size_t *query_at, size_t **norm_indexes);
/**
 * initializes URL object given scheme, authority, and path
 * @param the output
 * @param scheme scheme
 * @param authority
 * @param path
 * @return 0 if successful
 */
static int h2o_url_init(h2o_url_t *url, const h2o_url_scheme_t *scheme, h2o_iovec_t authority, h2o_iovec_t path);
/**
 * parses absolute URL (either http or https)
 */
int h2o_url_parse(const char *url, size_t url_len, h2o_url_t *result);
/**
 * parses relative URL
 */
int h2o_url_parse_relative(const char *url, size_t url_len, h2o_url_t *result);
/**
 * parses the authority and returns the next position (i.e. start of path)
 * @return pointer to the end of hostport if successful, or NULL if failed.  *port becomes the specified port number or 65535 if not
 */
const char *h2o_url_parse_hostport(const char *s, size_t len, h2o_iovec_t *host, uint16_t *port);
/**
 * resolves the URL (stored to `dest` as well as returning the stringified representation (always allocated using pool)
 */
h2o_iovec_t h2o_url_resolve(h2o_mem_pool_t *pool, const h2o_url_t *base, const h2o_url_t *relative, h2o_url_t *dest);
/**
 * resolves the path part of the URL (both the arguments are modified; the result is h2o_concat(*base, *relative))
 */
void h2o_url_resolve_path(h2o_iovec_t *base, h2o_iovec_t *relative);
/**
 * stringifies the URL
 */
static h2o_iovec_t h2o_url_stringify(h2o_mem_pool_t *pool, const h2o_url_t *url);
/**
 * copies a URL object (null-terminates all the string elements)
 */
void h2o_url_copy(h2o_mem_pool_t *pool, h2o_url_t *dest, const h2o_url_t *src);
/**
 * extracts sockaddr_un from host and returns NULL (or returns an error string if failed)
 */
const char *h2o_url_host_to_sun(h2o_iovec_t host, struct sockaddr_un *sa);
extern const char *h2o_url_host_to_sun_err_is_not_unix_socket;

/* inline definitions */

inline int h2o_url_init(h2o_url_t *url, const h2o_url_scheme_t *scheme, h2o_iovec_t authority, h2o_iovec_t path)
{
    if (h2o_url_parse_hostport(authority.base, authority.len, &url->host, &url->_port) != authority.base + authority.len)
        return -1;
    url->scheme = scheme;
    url->authority = authority;
    url->path = path;
    return 0;
}

inline uint16_t h2o_url_get_port(const h2o_url_t *url)
{
    return url->_port != 65535 ? url->_port : url->scheme->default_port;
}

inline h2o_iovec_t h2o_url_stringify(h2o_mem_pool_t *pool, const h2o_url_t *url)
{
    h2o_url_t tmp;
    return h2o_url_resolve(pool, url, NULL, &tmp);
}

static inline int h2o_url_host_is_unix_path(h2o_iovec_t host)
{
    if (host.len < 5) {
        return 0;
    }
    return h2o_memis(host.base, 5, H2O_STRLIT("unix:"));
}

/**
 * Compares to hostnames, taking into account whether they contain a
 * unix path (the comparison will be case sensitive) or not.
 */
static inline int h2o_url_hosts_are_equal(const h2o_url_t *url_a, const h2o_url_t *url_b)
{
    if (url_a->host.len != url_b->host.len)
        return 0;

    if (h2o_url_host_is_unix_path(url_a->host))
        return h2o_memis(url_a->host.base, url_a->host.len, url_b->host.base, url_b->host.len);
    else
        return h2o_lcstris(url_a->host.base, url_a->host.len, url_b->host.base, url_b->host.len);
}

#endif