Skip to content

Commit

Permalink
Merge pull request #67 from risoflora/upgrade-mhd-library
Browse files Browse the repository at this point in the history
Upgrade MHD library
  • Loading branch information
silvioprog authored Feb 27, 2024
2 parents 08dc0da + bd8304e commit 4605b6a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 71 deletions.
4 changes: 2 additions & 2 deletions cmake/SgMHD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ if(CMAKE_VERSION VERSION_GREATER "3.23")
endif()

set(MHD_NAME "libmicrohttpd")
set(MHD_VER "0.9.77")
set(MHD_VER "1.0.1")
set(MHD_FULL_NAME "${MHD_NAME}-${MHD_VER}")
set(MHD_URL "https://ftp.gnu.org/gnu/libmicrohttpd/${MHD_FULL_NAME}.tar.gz")
set(MHD_URL_MIRROR "https://ftp.gnu.org/gnu/libmicrohttpd/${MHD_FULL_NAME}.tar.gz")
set(MHD_SHA256 "9e7023a151120060d2806a6ea4c13ca9933ece4eacfc5c9464d20edddb76b0a0")
set(MHD_SHA256 "a89e09fc9b4de34dde19f4fcb4faaa1ce10299b9908db1132bbfa1de47882b94")
set(_libdir ${CMAKE_BINARY_DIR}/${MHD_FULL_NAME}/lib)
if(${CMAKE_VERSION} VERSION_LESS "3.7")
unset(MHD_URL_MIRROR)
Expand Down
2 changes: 1 addition & 1 deletion include/sagui.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extern "C" {

#define SG_VERSION_MAJOR 3
#define SG_VERSION_MINOR 5
#define SG_VERSION_PATCH 0
#define SG_VERSION_PATCH 1
#define SG_VERSION_HEX \
((SG_VERSION_MAJOR << 16) | (SG_VERSION_MINOR << 8) | (SG_VERSION_PATCH))

Expand Down
8 changes: 0 additions & 8 deletions src/sg_httpsrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,12 @@ static enum MHD_Result sg__httpsrv_ahc(void *cls, struct MHD_Connection *con,
struct sg_httpsrv *srv = cls;
struct sg_httpreq *req = *con_cls;
const union MHD_ConnectionInfo *info;
#ifdef SG_TESTING
if (con) {
#endif /* SG_TESTING */
info =
MHD_get_connection_info(con, MHD_CONNECTION_INFO_SOCKET_CONTEXT, NULL);
if (info && info->socket_context)
return MHD_NO;
#ifdef SG_TESTING
}
#endif /* SG_TESTING */
if (!req) {
req = sg__httpreq_new(srv, con, version, method, url);
if (!req)
Expand All @@ -92,15 +88,11 @@ static enum MHD_Result sg__httpsrv_ahc(void *cls, struct MHD_Connection *con,
if (!req->isolated)
srv->req_cb(srv->cls, req, req->res);
}
#ifdef SG_TESTING
if (con) {
#endif /* SG_TESTING */
info = MHD_get_connection_info(
con, MHD_CONNECTION_INFO_CONNECTION_SUSPENDED, NULL);
#ifdef SG_TESTING
} else
info = NULL;
#endif /* SG_TESTING */
return info && info->suspended ? MHD_YES : sg__httpres_dispatch(req->res);
}

Expand Down
11 changes: 7 additions & 4 deletions test/test_httpauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Cross-platform library which helps to develop web servers or frameworks.
*
* Copyright (C) 2016-2019 Silvio Clecio <[email protected]>
* Copyright (C) 2016-2024 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
Expand All @@ -32,8 +32,8 @@
#include "sg_httpres.h"
#include "sg_httpauth.h"

static void test__httpauth_new(void) {
struct sg_httpres *res = sg__httpres_new(NULL);
static void test__httpauth_new(struct MHD_Connection *con) {
struct sg_httpres *res = sg__httpres_new(con);
struct sg_httpauth *auth = sg__httpauth_new(res);
ASSERT(auth);
sg__httpauth_free(auth);
Expand Down Expand Up @@ -173,8 +173,10 @@ int main(void) {
struct sg_httpauth *auth = sg_alloc(sizeof(struct sg_httpauth));
ASSERT(auth);
auth->res = sg_alloc(sizeof(struct sg_httpres));
auth->res->con = sg_alloc(256);
ASSERT(auth->res);
test__httpauth_new();
ASSERT(auth->res->con);
test__httpauth_new(auth->res->con);
test__httpauth_free();
test__httpauth_dispatch(auth);
test_httpauth_set_realm(auth);
Expand All @@ -184,6 +186,7 @@ int main(void) {
test_httpauth_cancel(auth);
test_httpauth_usr(auth);
test_httpauth_pwd(auth);
sg_free(auth->res->con);
sg_free(auth->res);
sg_free(auth);
return EXIT_SUCCESS;
Expand Down
13 changes: 7 additions & 6 deletions test/test_httpreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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-2024 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
Expand All @@ -31,15 +31,14 @@
#include "sg_httpreq.h"
#include <sagui.h>

static void test__httpreq_new(struct sg_httpsrv *srv) {
struct MHD_Connection *con = sg_alloc(64);
static void test__httpreq_new(struct MHD_Connection *con,
struct sg_httpsrv *srv) {
struct sg_httpreq *req = sg__httpreq_new(srv, con, "abc", "def", "ghi");
ASSERT(req);
ASSERT(req->srv == srv);
ASSERT(strcmp(req->version, "abc") == 0);
ASSERT(strcmp(req->method, "def") == 0);
ASSERT(strcmp(req->path, "ghi") == 0);
sg_free(con);
sg__httpreq_free(req);
}

Expand Down Expand Up @@ -308,8 +307,9 @@ static void test_httpreq_user_data(struct sg_httpreq *req) {

int main(void) {
struct sg_httpsrv *srv = sg_httpsrv_new(dummy_httpreq_cb, NULL);
struct sg_httpreq *req = sg__httpreq_new(srv, NULL, NULL, NULL, NULL);
test__httpreq_new(srv);
struct MHD_Connection *con = sg_alloc(256);
struct sg_httpreq *req = sg__httpreq_new(srv, con, NULL, NULL, NULL);
test__httpreq_new(con, srv);
test__httpreq_free();
test_httpreq_srv(req);
test_httpreq_headers(req);
Expand All @@ -331,5 +331,6 @@ int main(void) {
test_httpreq_user_data(req);
sg__httpreq_free(req);
sg_httpsrv_free(srv);
sg_free(con);
return EXIT_SUCCESS;
}
43 changes: 8 additions & 35 deletions test/test_httpsrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,17 @@ static void test__httpsrv_oel(const char *fmt, ...) {
sg_httpsrv_free(srv);
}

static void test__httpsrv_ahc(struct sg_httpsrv *srv) {
static void test__httpsrv_ahc(struct MHD_Connection *con,
struct sg_httpsrv *srv) {
struct sg_httpreq *req = NULL;
size_t size = 0;
ASSERT(sg__httpsrv_ahc(srv, NULL, "abc", "def", "ghi", NULL, &size,
(void **) &req) == MHD_YES);
ASSERT(sg__httpsrv_ahc(srv, NULL, "abc", "def", "ghi", NULL, &size,
ASSERT(sg__httpsrv_ahc(srv, con, "abc", "def", "ghi", NULL, &size,
(void **) &req) == MHD_NO);
ASSERT(req);
sg__httpreq_free(req);
}

static void test__httpsrv_rcc(void) {
static void test__httpsrv_rcc(struct MHD_Connection *con) {
struct sg_httpsrv *srv = sg_httpsrv_new(dummy_httpreq_cb, NULL);
struct sg_httpreq *req = sg__httpreq_new(srv, NULL, NULL, NULL, NULL);
struct sg_httpreq *req = sg__httpreq_new(srv, con, NULL, NULL, NULL);
sg_httpsrv_free(srv);
sg__httpsrv_rcc(NULL, NULL, (void **) &req,
MHD_REQUEST_TERMINATED_COMPLETED_OK);
Expand Down Expand Up @@ -398,14 +395,6 @@ static void test_httpsrv_listen(struct sg_httpsrv *srv) {
MHD_USE_AUTO_INTERNAL_THREAD);
ASSERT(MHD_get_daemon_info(srv->handle, MHD_DAEMON_INFO_FLAGS)->flags &
MHD_USE_THREAD_PER_CONNECTION);
#ifdef __linux__
dummy_srv =
sg_httpsrv_new2(NULL, dummy_httpreq_cb, dummy_httpreq_err_cb, NULL);
errno = 0;
ASSERT(!sg_httpsrv_listen(dummy_srv, TEST_HTTPSRV_PORT, true));
ASSERT(errno == EADDRINUSE);
sg_httpsrv_free(dummy_srv);
#endif /* __linux__ */
ASSERT(sg_httpsrv_shutdown(srv) == 0);
}

Expand Down Expand Up @@ -475,14 +464,6 @@ static void test_httpsrv_listen2(struct sg_httpsrv *srv) {
MHD_USE_AUTO_INTERNAL_THREAD);
ASSERT(MHD_get_daemon_info(srv->handle, MHD_DAEMON_INFO_FLAGS)->flags &
MHD_USE_THREAD_PER_CONNECTION);
#ifdef __linux__
dummy_srv =
sg_httpsrv_new2(NULL, dummy_httpreq_cb, dummy_httpreq_err_cb, NULL);
errno = 0;
ASSERT(!sg_httpsrv_listen2(dummy_srv, NULL, TEST_HTTPSRV_PORT, 0, true));
ASSERT(errno == EADDRINUSE);
sg_httpsrv_free(dummy_srv);
#endif /* __linux__ */
ASSERT(sg_httpsrv_shutdown(srv) == 0);
}

Expand Down Expand Up @@ -575,15 +556,6 @@ static void test_httpsrv_tls_listen(struct sg_httpsrv *srv) {
MHD_USE_THREAD_PER_CONNECTION);
ASSERT(MHD_get_daemon_info(srv->handle, MHD_DAEMON_INFO_FLAGS)->flags &
MHD_USE_TLS);
#ifdef __linux__
dummy_srv =
sg_httpsrv_new2(NULL, dummy_httpreq_cb, dummy_httpreq_err_cb, NULL);
errno = 0;
ASSERT(!sg_httpsrv_tls_listen(dummy_srv, private_key, certificate,
TEST_HTTPSRV_PORT, true));
ASSERT(errno == EADDRINUSE);
sg_httpsrv_free(dummy_srv);
#endif /* __linux__ */
ASSERT(sg_httpsrv_shutdown(srv) == 0);
ASSERT(sg_httpsrv_listen(srv, 0, false));
ASSERT(sg_httpsrv_shutdown(srv) == 0);
Expand Down Expand Up @@ -867,11 +839,12 @@ static void test_httpsrv_handle(struct sg_httpsrv *srv) {
}

int main(void) {
struct MHD_Connection *con = sg_alloc(256);
struct sg_httpsrv *srv = sg_httpsrv_new(dummy_httpreq_cb, NULL);
/* test__httperr_cb() */
test__httpsrv_oel("%s%d", "abc", 123);
test__httpsrv_ahc(srv);
test__httpsrv_rcc();
test__httpsrv_ahc(con, srv);
test__httpsrv_rcc(con);
test__httpsrv_addopt();
test__httpsrv_eprintf();
test_httpsrv_new2();
Expand Down
30 changes: 15 additions & 15 deletions test/test_httpuplds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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-2024 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
Expand Down Expand Up @@ -111,11 +111,11 @@ static ssize_t empty_httpupld_write_cb(void *handle, uint64_t offset,
return -1;
}

static void test__httpuplds_add(void) {
static void test__httpuplds_add(struct MHD_Connection *con) {
char err[256];
struct sg_httpsrv *srv =
sg_httpsrv_new2(NULL, dummy_httpreq_cb, dummy_err_cb, err);
struct sg_httpreq *req = sg__httpreq_new(srv, NULL, "", "", "");
struct sg_httpreq *req = sg__httpreq_new(srv, con, "", "", "");
ASSERT(sg_httpuplds_count(sg_httpreq_uploads(req)) == 0);
sg__httpuplds_add(srv, req, "abc", "def", "ghi", "jkl");
ASSERT(strcmp(sg_httpupld_field(req->curr_upld), "abc") == 0);
Expand All @@ -132,13 +132,13 @@ static void test__httpuplds_free(void) {
sg__httpuplds_free(NULL, NULL);
}

static void test__httpuplds_iter(void) {
static void test__httpuplds_iter(struct MHD_Connection *con) {
const char *filename = "foo.txt";
const size_t len = 3;
char err[256], str[256];
struct sg_httpsrv *srv =
sg_httpsrv_new2(NULL, dummy_httpreq_cb, dummy_err_cb, err);
struct sg_httpreq *req = sg__httpreq_new(srv, NULL, "", "", "");
struct sg_httpreq *req = sg__httpreq_new(srv, con, "", "", "");
struct sg__httpupld_holder holder = {srv, req};
struct sg_strmap **fields;
sg_httpupld_cb saved_upld_cb;
Expand Down Expand Up @@ -200,13 +200,12 @@ static void test__httpuplds_iter(void) {
sg_httpsrv_free(srv);
}

static void test__httpuplds_process(void) {
static void test__httpuplds_process(struct MHD_Connection *con) {
const size_t len = 3;
char err[256], str[256];
struct MHD_Connection *con = sg_alloc(64);
struct sg_httpsrv *srv =
sg_httpsrv_new2(NULL, dummy_httpreq_cb, dummy_err_cb, err);
struct sg_httpreq *req = sg__httpreq_new(srv, NULL, "", "", "");
struct sg_httpreq *req = sg__httpreq_new(srv, con, "", "", "");
int ret = 0;
size_t size = 0;

Expand All @@ -230,12 +229,11 @@ static void test__httpuplds_process(void) {

sg__httpreq_free(req);
sg_httpsrv_free(srv);
sg_free(con);
}

static void test__httpuplds_cleanup(void) {
static void test__httpuplds_cleanup(struct MHD_Connection *con) {
struct sg_httpsrv *srv = sg_httpsrv_new(dummy_httpreq_cb, NULL);
struct sg_httpreq *req = sg__httpreq_new(srv, NULL, "", "", "");
struct sg_httpreq *req = sg__httpreq_new(srv, con, "", "", "");
struct sg_httpupld *tmp;
size_t count = 0;
ASSERT(srv);
Expand Down Expand Up @@ -679,11 +677,12 @@ static void test_httpupld_save_as(struct sg_httpupld *upld) {

int main(void) {
struct sg_httpupld *upld = sg_alloc(sizeof(struct sg_httpupld));
test__httpuplds_add();
struct MHD_Connection *con = sg_alloc(256);
test__httpuplds_add(con);
test__httpuplds_free();
test__httpuplds_iter();
test__httpuplds_process();
test__httpuplds_cleanup();
test__httpuplds_iter(con);
test__httpuplds_process(con);
test__httpuplds_cleanup(con);
test__httpupld_cb();
test__httpupld_write_cb();
test__httpupld_free_cb();
Expand All @@ -702,5 +701,6 @@ int main(void) {
test_httpupld_save(upld);
test_httpupld_save_as(upld);
sg_free(upld);
sg_free(con);
return EXIT_SUCCESS;
}

0 comments on commit 4605b6a

Please sign in to comment.