aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/http/http_schemes.c
blob: df8b92081a1627194a46fb07b045e2ee966f2d3c (plain)
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
//
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//

#include <ctype.h>
#include <stdbool.h>
#include <string.h>

#include "core/nng_impl.h"

#include "http_api.h"

static struct {
	const char *upper;
	const char *lower;
} http_schemes[] = {
	{
	    .upper = "http",
	    .lower = "tcp",
	},
	{
	    .upper = "ws",
	    .lower = "tcp",
	},
	{
	    .upper = "https",
	    .lower = "tls+tcp",
	},
	{
	    .upper = "wss",
	    .lower = "tls+tcp",
	},
	{
	    .upper = "http4",
	    .lower = "tcp4",
	},
	{
	    .upper = "ws4",
	    .lower = "tcp4",
	},
	{
	    .upper = "http6",
	    .lower = "tcp6",
	},
	{
	    .upper = "ws6",
	    .lower = "tcp6",
	},
	{
	    .upper = "https4",
	    .lower = "tls+tcp4",
	},
	{
	    .upper = "wss4",
	    .lower = "tls+tcp4",
	},
	{
	    .upper = "https6",
	    .lower = "tls+tcp6",
	},
	{
	    .upper = "wss6",
	    .lower = "tls+tcp6",
	},
	{
	    .upper = NULL,
	    .lower = NULL,
	},
};

const char *
nni_http_stream_scheme(const char *upper)
{
	for (int i = 0; http_schemes[i].upper != NULL; i++) {
		if (strcmp(http_schemes[i].upper, upper) == 0) {
			return (http_schemes[i].lower);
		}
	}
	return (NULL);
}