-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new function "sg_httpsrv_tls_listen3()"
- Loading branch information
1 parent
21a27b1
commit 2aff171
Showing
3 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* | ||
* Cross-platform library which helps to develop web servers or frameworks. | ||
* | ||
* Copyright (C) 2016-2020 Silvio Clecio <[email protected]> | ||
* Copyright (C) 2016-2021 Silvio Clecio <[email protected]> | ||
* | ||
* Sagui library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
|
@@ -144,7 +144,8 @@ static void sg__httpsrv_addopt(struct MHD_OptionItem ops[8], unsigned char *pos, | |
static bool sg__httpsrv_listen(struct sg_httpsrv *srv, const char *key, | ||
const char *pwd, const char *cert, | ||
const char *trust, const char *dhparams, | ||
uint16_t port, bool threaded) { | ||
const char *priorities, uint16_t port, | ||
bool threaded) { | ||
struct MHD_OptionItem ops[8]; | ||
unsigned int flags; | ||
unsigned char pos = 0; | ||
|
@@ -186,6 +187,9 @@ static bool sg__httpsrv_listen(struct sg_httpsrv *srv, const char *key, | |
if (dhparams) | ||
sg__httpsrv_addopt(ops, &pos, MHD_OPTION_HTTPS_MEM_DHPARAMS, 0, | ||
(void *) dhparams); | ||
if (priorities) | ||
sg__httpsrv_addopt(ops, &pos, MHD_OPTION_HTTPS_PRIORITIES, 0, | ||
(void *) priorities); | ||
} | ||
sg__httpsrv_addopt(ops, &pos, MHD_OPTION_END, 0, NULL); | ||
srv->handle = MHD_start_daemon(flags, port, NULL, NULL, sg__httpsrv_ahc, srv, | ||
|
@@ -303,12 +307,24 @@ void sg_httpsrv_free(struct sg_httpsrv *srv) { | |
|
||
#ifdef SG_HTTPS_SUPPORT | ||
|
||
bool sg_httpsrv_tls_listen3(struct sg_httpsrv *srv, const char *key, | ||
const char *pwd, const char *cert, | ||
const char *trust, const char *dhparams, | ||
const char *priorities, uint16_t port, | ||
bool threaded) { | ||
if (key && cert) | ||
return sg__httpsrv_listen(srv, key, pwd, cert, trust, dhparams, priorities, | ||
port, threaded); | ||
errno = EINVAL; | ||
return false; | ||
} | ||
|
||
bool sg_httpsrv_tls_listen2(struct sg_httpsrv *srv, const char *key, | ||
const char *pwd, const char *cert, | ||
const char *trust, const char *dhparams, | ||
uint16_t port, bool threaded) { | ||
if (key && cert) | ||
return sg__httpsrv_listen(srv, key, pwd, cert, trust, dhparams, port, | ||
return sg__httpsrv_listen(srv, key, pwd, cert, trust, dhparams, NULL, port, | ||
threaded); | ||
errno = EINVAL; | ||
return false; | ||
|
@@ -317,15 +333,17 @@ bool sg_httpsrv_tls_listen2(struct sg_httpsrv *srv, const char *key, | |
bool sg_httpsrv_tls_listen(struct sg_httpsrv *srv, const char *key, | ||
const char *cert, uint16_t port, bool threaded) { | ||
if (key && cert) | ||
return sg__httpsrv_listen(srv, key, NULL, cert, NULL, NULL, port, threaded); | ||
return sg__httpsrv_listen(srv, key, NULL, cert, NULL, NULL, NULL, port, | ||
threaded); | ||
errno = EINVAL; | ||
return false; | ||
} | ||
|
||
#endif /* SG_HTTPS_SUPPORT */ | ||
|
||
bool sg_httpsrv_listen(struct sg_httpsrv *srv, uint16_t port, bool threaded) { | ||
return sg__httpsrv_listen(srv, NULL, NULL, NULL, NULL, NULL, port, threaded); | ||
return sg__httpsrv_listen(srv, NULL, NULL, NULL, NULL, NULL, NULL, port, | ||
threaded); | ||
} | ||
|
||
int sg_httpsrv_shutdown(struct sg_httpsrv *srv) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* | ||
* Cross-platform library which helps to develop web servers or frameworks. | ||
* | ||
* Copyright (C) 2016-2020 Silvio Clecio <[email protected]> | ||
* Copyright (C) 2016-2021 Silvio Clecio <[email protected]> | ||
* | ||
* Sagui library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
|
@@ -523,6 +523,17 @@ static void test_httpsrv_tls_listen2(struct sg_httpsrv *srv) { | |
ASSERT(errno == EINVAL); | ||
} | ||
|
||
static void test_httpsrv_tls_listen3(struct sg_httpsrv *srv) { | ||
errno = 0; | ||
ASSERT(!sg_httpsrv_tls_listen3(srv, NULL, "", "", "", "", "", | ||
TEST_HTTPSRV_PORT, false)); | ||
ASSERT(errno == EINVAL); | ||
errno = 0; | ||
ASSERT(!sg_httpsrv_tls_listen3(srv, "", "", NULL, "", "", "", | ||
TEST_HTTPSRV_PORT, false)); | ||
ASSERT(errno == EINVAL); | ||
} | ||
|
||
#endif /* SG_HTTPS_SUPPORT */ | ||
|
||
static void test_httpsrv_shutdown(struct sg_httpsrv *srv) { | ||
|
@@ -782,6 +793,7 @@ int main(void) { | |
#ifdef SG_HTTPS_SUPPORT | ||
test_httpsrv_tls_listen(srv); | ||
test_httpsrv_tls_listen2(srv); | ||
test_httpsrv_tls_listen3(srv); | ||
#endif /* SG_HTTPS_SUPPORT */ | ||
test_httpsrv_shutdown(srv); | ||
test_httpsrv_port(srv); | ||
|