@@ -931,31 +931,15 @@
Loading
931 931
{
932 932
	nni_http_server *s;
933 933
	int              rv;
934 -
	nng_url          myurl;
934 +
	nng_url          my_url;
935 +
	const char *     scheme;
935 936
936 -
	// Rewrite URLs to either TLS or TCP.
937 -
	memcpy(&myurl, url, sizeof(myurl));
938 -
	if ((strcmp(url->u_scheme, "http") == 0) ||
939 -
	    (strcmp(url->u_scheme, "ws") == 0)) {
940 -
		myurl.u_scheme = "tcp";
941 -
	} else if ((strcmp(url->u_scheme, "https") == 0) ||
942 -
	    (strcmp(url->u_scheme, "wss") == 0)) {
943 -
		myurl.u_scheme = "tls+tcp";
944 -
	} else if ((strcmp(url->u_scheme, "ws4") == 0) ||
945 -
	    (strcmp(url->u_scheme, "http4")) == 0) {
946 -
		myurl.u_scheme = "tcp4";
947 -
	} else if ((strcmp(url->u_scheme, "ws6") == 0) ||
948 -
	    (strcmp(url->u_scheme, "http6") == 0)) {
949 -
		myurl.u_scheme = "tcp6";
950 -
	} else if ((strcmp(url->u_scheme, "wss4") == 0) ||
951 -
	    (strcmp(url->u_scheme, "https4") == 0)) {
952 -
		myurl.u_scheme = "tls+tcp4";
953 -
	} else if ((strcmp(url->u_scheme, "wss6") == 0) ||
954 -
	    (strcmp(url->u_scheme, "https6") == 0)) {
955 -
		myurl.u_scheme = "tls+tcp6";
956 -
	} else {
937 +
	if ((scheme = nni_http_stream_scheme(url->u_scheme)) == NULL) {
957 938
		return (NNG_EADDRINVAL);
958 939
	}
940 +
	// Rewrite URLs to either TLS or TCP.
941 +
	memcpy(&my_url, url, sizeof(my_url));
942 +
	my_url.u_scheme = (char *) scheme;
959 943
960 944
	if ((s = NNI_ALLOC_STRUCT(s)) == NULL) {
961 945
		return (NNG_ENOMEM);
@@ -983,7 +967,7 @@
Loading
983 967
		return (NNG_ENOMEM);
984 968
	}
985 969
986 -
	if ((rv = nng_stream_listener_alloc_url(&s->listener, &myurl)) != 0) {
970 +
	if ((rv = nng_stream_listener_alloc_url(&s->listener, &my_url)) != 0) {
987 971
		http_server_fini(s);
988 972
		return (rv);
989 973
	}
@@ -1882,20 +1866,15 @@
Loading
1882 1866
int
1883 1867
nni_http_server_set_tls(nni_http_server *s, nng_tls_config *tls)
1884 1868
{
1885 -
	int rv;
1886 -
	rv = nni_stream_listener_set(s->listener, NNG_OPT_TLS_CONFIG, &tls,
1887 -
	    sizeof(tls), NNI_TYPE_POINTER);
1888 -
	return (rv);
1869 +
	return (
1870 +
	    nng_stream_listener_set_ptr(s->listener, NNG_OPT_TLS_CONFIG, tls));
1889 1871
}
1890 1872
1891 1873
int
1892 1874
nni_http_server_get_tls(nni_http_server *s, nng_tls_config **tlsp)
1893 1875
{
1894 -
	size_t sz = sizeof(*tlsp);
1895 -
	int    rv;
1896 -
	rv = nni_stream_listener_get(
1897 -
	    s->listener, NNG_OPT_TLS_CONFIG, tlsp, &sz, NNI_TYPE_POINTER);
1898 -
	return (rv);
1876 +
	return (nng_stream_listener_get_ptr(
1877 +
	    s->listener, NNG_OPT_TLS_CONFIG, (void **) tlsp));
1899 1878
}
1900 1879
1901 1880
int

@@ -100,30 +100,14 @@
Loading
100 100
	int              rv;
101 101
	nni_http_client *c;
102 102
	nng_url          my_url;
103 +
	const char *     scheme;
103 104
104 -
	// Rewrite URLs to either TLS or TCP.
105 -
	memcpy(&my_url, url, sizeof(my_url));
106 -
	if ((strcmp(url->u_scheme, "http") == 0) ||
107 -
	    (strcmp(url->u_scheme, "ws") == 0)) {
108 -
		my_url.u_scheme = "tcp";
109 -
	} else if ((strcmp(url->u_scheme, "https") == 0) ||
110 -
	    (strcmp(url->u_scheme, "wss") == 0)) {
111 -
		my_url.u_scheme = "tls+tcp";
112 -
	} else if ((strcmp(url->u_scheme, "ws4") == 0) ||
113 -
	    (strcmp(url->u_scheme, "http4") == 0)) {
114 -
		my_url.u_scheme = "tcp4";
115 -
	} else if ((strcmp(url->u_scheme, "ws6") == 0) ||
116 -
	    (strcmp(url->u_scheme, "http6") == 0)) {
117 -
		my_url.u_scheme = "tcp6";
118 -
	} else if ((strcmp(url->u_scheme, "wss4") == 0) ||
119 -
	    (strcmp(url->u_scheme, "https4") == 0)) {
120 -
		my_url.u_scheme = "tls+tcp4";
121 -
	} else if ((strcmp(url->u_scheme, "wss6") == 0) ||
122 -
	    (strcmp(url->u_scheme, "https6") == 0)) {
123 -
		my_url.u_scheme = "tls+tcp6";
124 -
	} else {
105 +
	if ((scheme = nni_http_stream_scheme(url->u_scheme)) == NULL) {
125 106
		return (NNG_EADDRINVAL);
126 107
	}
108 +
	// Rewrite URLs to either TLS or TCP.
109 +
	memcpy(&my_url, url, sizeof(my_url));
110 +
	my_url.u_scheme = (char *) scheme;
127 111
128 112
	if (strlen(url->u_hostname) == 0) {
129 113
		// We require a valid hostname.
@@ -153,20 +137,14 @@
Loading
153 137
int
154 138
nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls)
155 139
{
156 -
	int rv;
157 -
	rv = nni_stream_dialer_set(c->dialer, NNG_OPT_TLS_CONFIG, &tls,
158 -
	    sizeof(tls), NNI_TYPE_POINTER);
159 -
	return (rv);
140 +
	return (nng_stream_dialer_set_ptr(c->dialer, NNG_OPT_TLS_CONFIG, tls));
160 141
}
161 142
162 143
int
163 144
nni_http_client_get_tls(nni_http_client *c, nng_tls_config **tlsp)
164 145
{
165 -
	size_t sz = sizeof(*tlsp);
166 -
	int    rv;
167 -
	rv = nni_stream_dialer_get(
168 -
	    c->dialer, NNG_OPT_TLS_CONFIG, tlsp, &sz, NNI_TYPE_POINTER);
169 -
	return (rv);
146 +
	return (nng_stream_dialer_get_ptr(
147 +
	    c->dialer, NNG_OPT_TLS_CONFIG, (void **) tlsp));
170 148
}
171 149
172 150
int

@@ -0,0 +1,85 @@
Loading
1 +
//
2 +
// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
3 +
//
4 +
// This software is supplied under the terms of the MIT License, a
5 +
// copy of which should be located in the distribution where this
6 +
// file was obtained (LICENSE.txt).  A copy of the license may also be
7 +
// found online at https://opensource.org/licenses/MIT.
8 +
//
9 +
10 +
#include <ctype.h>
11 +
#include <stdbool.h>
12 +
#include <string.h>
13 +
14 +
#include "core/nng_impl.h"
15 +
16 +
#include "http_api.h"
17 +
18 +
static struct {
19 +
	const char *upper;
20 +
	const char *lower;
21 +
} http_schemes[] = {
22 +
	{
23 +
	    .upper = "http",
24 +
	    .lower = "tcp",
25 +
	},
26 +
	{
27 +
	    .upper = "ws",
28 +
	    .lower = "tcp",
29 +
	},
30 +
	{
31 +
	    .upper = "https",
32 +
	    .lower = "tls+tcp",
33 +
	},
34 +
	{
35 +
	    .upper = "wss",
36 +
	    .lower = "tls+tcp",
37 +
	},
38 +
	{
39 +
	    .upper = "http4",
40 +
	    .lower = "tcp4",
41 +
	},
42 +
	{
43 +
	    .upper = "ws4",
44 +
	    .lower = "tcp4",
45 +
	},
46 +
	{
47 +
	    .upper = "http6",
48 +
	    .lower = "tcp6",
49 +
	},
50 +
	{
51 +
	    .upper = "ws6",
52 +
	    .lower = "tcp6",
53 +
	},
54 +
	{
55 +
	    .upper = "https4",
56 +
	    .lower = "tls+tcp4",
57 +
	},
58 +
	{
59 +
	    .upper = "wss4",
60 +
	    .lower = "tls+tcp4",
61 +
	},
62 +
	{
63 +
	    .upper = "https6",
64 +
	    .lower = "tls+tcp6",
65 +
	},
66 +
	{
67 +
	    .upper = "wss6",
68 +
	    .lower = "tls+tcp6",
69 +
	},
70 +
	{
71 +
	    .upper = NULL,
72 +
	    .lower = NULL,
73 +
	},
74 +
};
75 +
76 +
const char *
77 +
nni_http_stream_scheme(const char *upper)
78 +
{
79 +
	for (int i = 0; http_schemes[i].upper != NULL; i++) {
80 +
		if (strcmp(http_schemes[i].upper, upper) == 0) {
81 +
			return (http_schemes[i].lower);
82 +
		}
83 +
	}
84 +
	return (NULL);
85 +
}
Files Coverage
src 80.71%
tools/nngcat/nngcat.c 56.33%
Project Totals (88 files) 79.94%
1
ignore:
2
 - "tests"
3
 - "perf"
4
 - "**/*_test.c"
5
coverage:
6
 range: 50..95
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading