summaryrefslogtreecommitdiffstats
path: root/src/parse_uri.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-12 08:40:57 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-12 08:40:57 +0000
commite2fdf6c58545799d7522fabf7a2999f113bf3541 (patch)
tree4eb7533bf42fa54fcc6a1b2396f1abdfe4102484 /src/parse_uri.c
parentAdding upstream version 2.10.0. (diff)
downloaddnsperf-e2fdf6c58545799d7522fabf7a2999f113bf3541.tar.xz
dnsperf-e2fdf6c58545799d7522fabf7a2999f113bf3541.zip
Adding upstream version 2.11.0.upstream/2.11.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/parse_uri.c')
-rw-r--r--src/parse_uri.c112
1 files changed, 0 insertions, 112 deletions
diff --git a/src/parse_uri.c b/src/parse_uri.c
deleted file mode 100644
index fa74c85..0000000
--- a/src/parse_uri.c
+++ /dev/null
@@ -1,112 +0,0 @@
-#include "parse_uri.h"
-
-#include <string.h>
-
-// From: https://github.com/nghttp2/nghttp2/blob/master/examples/client.c
-/*
- * nghttp2 - HTTP/2 C Library
- *
- * Copyright (c) 2013 Tatsuhiro Tsujikawa
- *
- * 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.
- */
-
-int parse_uri(struct URI* res, const char* uri)
-{
- /* We only interested in https */
- size_t len, i, offset;
- int ipv6addr = 0;
- memset(res, 0, sizeof(struct URI));
- len = strlen(uri);
- if (len < 9 || memcmp("https://", uri, 8) != 0) {
- return -1;
- }
- offset = 8;
- res->host = res->hostport = &uri[offset];
- res->hostlen = 0;
- if (uri[offset] == '[') {
- /* IPv6 literal address */
- ++offset;
- ++res->host;
- ipv6addr = 1;
- for (i = offset; i < len; ++i) {
- if (uri[i] == ']') {
- res->hostlen = i - offset;
- offset = i + 1;
- break;
- }
- }
- } else {
- const char delims[] = ":/?#";
- for (i = offset; i < len; ++i) {
- if (strchr(delims, uri[i]) != NULL) {
- break;
- }
- }
- res->hostlen = i - offset;
- offset = i;
- }
- if (res->hostlen == 0) {
- return -1;
- }
- /* Assuming https */
- res->port = 443;
- if (offset < len) {
- if (uri[offset] == ':') {
- /* port */
- const char delims[] = "/?#";
- int port = 0;
- ++offset;
- for (i = offset; i < len; ++i) {
- if (strchr(delims, uri[i]) != NULL) {
- break;
- }
- if ('0' <= uri[i] && uri[i] <= '9') {
- port *= 10;
- port += uri[i] - '0';
- if (port > 65535) {
- return -1;
- }
- } else {
- return -1;
- }
- }
- if (port == 0) {
- return -1;
- }
- offset = i;
- res->port = (uint16_t)port;
- }
- }
- res->hostportlen = (size_t)(uri + offset + ipv6addr - res->host);
- for (i = offset; i < len; ++i) {
- if (uri[i] == '#') {
- break;
- }
- }
- if (i - offset == 0) {
- res->path = "/";
- res->pathlen = 1;
- } else {
- res->path = &uri[offset];
- res->pathlen = i - offset;
- }
- return 0;
-}