Skip to content

Commit

Permalink
Merge pull request civetweb#1318 from DL6ER/new/is_optional
Browse files Browse the repository at this point in the history
Export ports.is_optional
  • Loading branch information
bel2125 authored Jan 13, 2025
2 parents 566f37a + e92dbe1 commit 7f95a26
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/api/mg_server_port.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
|**`port`**|`int`|The port number on which the service listens|
|**`is_ssl`**|`int`|**0** for `HTTP` communication, **1** for `HTTPS`|
|**`is_redirect`**|`int`|**1** if all requests are redirected, otherwise **0**|
|**`_reserved1`**|`int`|Reserved for internal use|
|**`is_optional`**|`int`|**1** if prot is optional, otherwise **0**|
|**`_reserved2`**|`int`|Reserved for internal use|
|**`_reserved3`**|`int`|Reserved for internal use|
|**`_reserved4`**|`int`|Reserved for internal use|
Expand Down
2 changes: 1 addition & 1 deletion include/civetweb.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ struct mg_server_port {
int port; /* port number */
int is_ssl; /* https port: 0 = no, 1 = yes */
int is_redirect; /* redirect all requests: 0 = no, 1 = yes */
int _reserved1;
int is_optional; /* optional: 0 = no, 1 = yes */
int _reserved2;
int _reserved3;
int _reserved4;
Expand Down
1 change: 1 addition & 0 deletions src/civetweb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,7 @@ mg_get_server_ports(const struct mg_context *ctx,
ntohs(USA_IN_PORT_UNSAFE(&(ctx->listening_sockets[i].lsa)));
ports[cnt].is_ssl = ctx->listening_sockets[i].is_ssl;
ports[cnt].is_redirect = ctx->listening_sockets[i].ssl_redir;
ports[cnt].is_optional = ctx->listening_sockets[i].is_optional;

if (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET) {
/* IPv4 */
Expand Down
16 changes: 14 additions & 2 deletions unittest/public_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,12 @@ test_mg_start_stop_http_server_impl(int ipv6, int bound)
ck_assert_int_eq(portinfo[0].port, 0);
ck_assert_int_eq(portinfo[0].is_ssl, 0);
ck_assert_int_eq(portinfo[0].is_redirect, 0);
ck_assert_int_eq(portinfo[0].is_optional, 0);
ck_assert_int_eq(portinfo[1].protocol, 0);
ck_assert_int_eq(portinfo[1].port, 0);
ck_assert_int_eq(portinfo[1].is_ssl, 0);
ck_assert_int_eq(portinfo[1].is_redirect, 0);
ck_assert_int_eq(portinfo[1].is_optional, 0);

ret = mg_get_server_ports(ctx, 4, portinfo);
ck_assert_int_eq(ret, 1);
Expand All @@ -472,10 +474,12 @@ test_mg_start_stop_http_server_impl(int ipv6, int bound)
ck_assert_int_eq(portinfo[0].port, 8080);
ck_assert_int_eq(portinfo[0].is_ssl, 0);
ck_assert_int_eq(portinfo[0].is_redirect, 0);
ck_assert_int_eq(portinfo[0].is_optional, 0);
ck_assert_int_eq(portinfo[1].protocol, 0);
ck_assert_int_eq(portinfo[1].port, 0);
ck_assert_int_eq(portinfo[1].is_ssl, 0);
ck_assert_int_eq(portinfo[1].is_redirect, 0);
ck_assert_int_eq(portinfo[1].is_optional, 0);

test_sleep(1);

Expand Down Expand Up @@ -649,7 +653,7 @@ START_TEST(test_mg_start_stop_https_server)
OPTIONS[opt_idx++] = ".";
#endif
OPTIONS[opt_idx++] = "listening_ports";
OPTIONS[opt_idx++] = "8080r,8443s";
OPTIONS[opt_idx++] = "8080r,8443os";
OPTIONS[opt_idx++] = "ssl_certificate";
OPTIONS[opt_idx++] = ssl_cert;

Expand All @@ -674,25 +678,30 @@ START_TEST(test_mg_start_stop_https_server)
ck_assert_int_eq(portinfo[0].port, 0);
ck_assert_int_eq(portinfo[0].is_ssl, 0);
ck_assert_int_eq(portinfo[0].is_redirect, 0);
ck_assert_int_eq(portinfo[0].is_optional, 0);
ck_assert_int_eq(portinfo[1].protocol, 0);
ck_assert_int_eq(portinfo[1].port, 0);
ck_assert_int_eq(portinfo[1].is_ssl, 0);
ck_assert_int_eq(portinfo[1].is_redirect, 0);
ck_assert_int_eq(portinfo[1].is_optional, 0);

ret = mg_get_server_ports(ctx, 4, portinfo);
ck_assert_int_eq(ret, 2);
ck_assert_int_eq(portinfo[0].protocol, 1);
ck_assert_int_eq(portinfo[0].port, 8080);
ck_assert_int_eq(portinfo[0].is_ssl, 0);
ck_assert_int_eq(portinfo[0].is_redirect, 1);
ck_assert_int_eq(portinfo[0].is_optional, 0);
ck_assert_int_eq(portinfo[1].protocol, 1);
ck_assert_int_eq(portinfo[1].port, 8443);
ck_assert_int_eq(portinfo[1].is_ssl, 1);
ck_assert_int_eq(portinfo[1].is_redirect, 0);
ck_assert_int_eq(portinfo[1].is_optional, 1);
ck_assert_int_eq(portinfo[2].protocol, 0);
ck_assert_int_eq(portinfo[2].port, 0);
ck_assert_int_eq(portinfo[2].is_ssl, 0);
ck_assert_int_eq(portinfo[2].is_redirect, 0);
ck_assert_int_eq(portinfo[2].is_optional, 0);

test_sleep(1);

Expand Down Expand Up @@ -771,7 +780,7 @@ START_TEST(test_mg_server_and_client_tls)
OPTIONS[opt_idx++] = ".";
#endif
OPTIONS[opt_idx++] = "listening_ports";
OPTIONS[opt_idx++] = "8080r,8443s";
OPTIONS[opt_idx++] = "8080r,8443os";
OPTIONS[opt_idx++] = "ssl_certificate";
OPTIONS[opt_idx++] = server_cert;
OPTIONS[opt_idx++] = "ssl_verify_peer";
Expand Down Expand Up @@ -800,14 +809,17 @@ START_TEST(test_mg_server_and_client_tls)
ck_assert_int_eq(ports[0].port, 8080);
ck_assert_int_eq(ports[0].is_ssl, 0);
ck_assert_int_eq(ports[0].is_redirect, 1);
ck_assert_int_eq(ports[0].is_optional, 0);
ck_assert_int_eq(ports[1].protocol, 1);
ck_assert_int_eq(ports[1].port, 8443);
ck_assert_int_eq(ports[1].is_ssl, 1);
ck_assert_int_eq(ports[1].is_redirect, 0);
ck_assert_int_eq(ports[1].is_optional, 1);
ck_assert_int_eq(ports[2].protocol, 0);
ck_assert_int_eq(ports[2].port, 0);
ck_assert_int_eq(ports[2].is_ssl, 0);
ck_assert_int_eq(ports[2].is_redirect, 0);
ck_assert_int_eq(ports[2].is_optional, 0);

test_sleep(1);

Expand Down

0 comments on commit 7f95a26

Please sign in to comment.