Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
236 additions
and
58 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- a/Makefile | ||
+++ b/Makefile | ||
@@ -5,5 +5,5 @@ SRCS = mongoose.c test/unit_test.c test/packed_fs.c | ||
OPTS ?= -O3 -g3 | ||
INCS ?= -Isrc -I. | ||
-CFLAGS ?= $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) $(EXTRA) | ||
+CFLAGS := $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) $(CFLAGS) | ||
SSL ?= MBEDTLS | ||
CWD ?= $(realpath $(CURDIR)) | ||
@@ -10,6 +10,9 @@ CWD ?= $(realpath $(CURDIR)) | ||
DOCKER ?= docker run --rm -e Tmp=. -e WINEDEBUG=-all -v $(CWD):$(CWD) -w $(CWD) | ||
VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS) | ||
IPV6 ?= 1 | ||
+ifneq "$(NO_SANITIZE)" "1" | ||
+SANITIZE = -fsanitize=address,undefined | ||
+endif | ||
ASAN_OPTIONS ?= | ||
EXAMPLES := $(wildcard examples/*) | ||
PREFIX ?= /usr/local | ||
@@ -19,12 +22,12 @@ VERSION ?= $(shell cut -d'"' -f2 src/version.h) | ||
ifeq "$(SSL)" "MBEDTLS" | ||
MBEDTLS ?= /usr | ||
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS)/include -I/usr/include | ||
-LDFLAGS ?= -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509 | ||
+LDFLAGS += -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509 | ||
endif | ||
ifeq "$(SSL)" "OPENSSL" | ||
OPENSSL ?= /usr | ||
CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include | ||
-LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto | ||
+LDFLAGS += -L$(OPENSSL)/lib -lssl -lcrypto | ||
endif | ||
|
||
all: mg_prefix unamalgamated unpacked test test++ arm examples vc98 vc2017 mingw mingw++ linux linux++ fuzz | ||
@@ -59,7 +62,7 @@ fuzz: fuzzer | ||
$(RUN) ./fuzzer | ||
|
||
# make CC=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1 | ||
-test: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6) -fsanitize=address,undefined | ||
+test: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6) $(SANITIZE) | ||
test: mongoose.h Makefile $(SRCS) | ||
$(CC) $(SRCS) $(CFLAGS) -coverage $(LDFLAGS) -g -o unit_test | ||
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test | ||
@@ -108,10 +111,12 @@ linux++: CC = g++ | ||
linux++: WARN += -Wno-missing-field-initializers | ||
linux++: linux | ||
|
||
-linux-libs: CFLAGS += -fPIC | ||
-linux-libs: mongoose.o | ||
- $(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION) | ||
+.PHONY: linux-libs | ||
+linux-libs: libmongoose.a libmongoose.so.$(VERSION) | ||
+libmongoose.a: mongoose.o | ||
$(AR) rcs libmongoose.a mongoose.o | ||
+libmongoose.so.$(VERSION): mongoose.o | ||
+ $(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION) | ||
|
||
install: linux-libs | ||
install -Dm644 libmongoose.a libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib |
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 |
---|---|---|
@@ -0,0 +1,149 @@ | ||
Tests should not need to connect to the internet | ||
|
||
--- a/test/unit_test.c | ||
+++ b/test/unit_test.c | ||
@@ -291,67 +291,6 @@ static void test_sntp(void) { | ||
ASSERT(mg_sntp_parse(NULL, 0) == -1); | ||
} | ||
|
||
-static void mqtt_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { | ||
- char *buf = (char *) fnd; | ||
- if (ev == MG_EV_MQTT_OPEN) { | ||
- buf[0] = *(int *) evd == 0 ? 'X' : 'Y'; | ||
- } else if (ev == MG_EV_MQTT_MSG) { | ||
- struct mg_mqtt_message *mm = (struct mg_mqtt_message *) evd; | ||
- sprintf(buf + 1, "%.*s/%.*s", (int) mm->topic.len, mm->topic.ptr, | ||
- (int) mm->data.len, mm->data.ptr); | ||
- } | ||
- (void) c; | ||
-} | ||
- | ||
-static void test_mqtt(void) { | ||
- char buf[50] = {0}; | ||
- struct mg_mgr mgr; | ||
- struct mg_str topic = mg_str("x/f12"), data = mg_str("hi"); | ||
- struct mg_connection *c; | ||
- struct mg_mqtt_opts opts; | ||
- // const char *url = "mqtt://mqtt.eclipse.org:1883"; | ||
- const char *url = "mqtt://broker.hivemq.com:1883"; | ||
- int i; | ||
- mg_mgr_init(&mgr); | ||
- | ||
- { | ||
- uint8_t bad[] = " \xff\xff\xff\xff "; | ||
- struct mg_mqtt_message mm; | ||
- mg_mqtt_parse(bad, sizeof(bad), &mm); | ||
- } | ||
- | ||
- // Connect with empty client ID | ||
- c = mg_mqtt_connect(&mgr, url, NULL, mqtt_cb, buf); | ||
- for (i = 0; i < 200 && buf[0] == 0; i++) mg_mgr_poll(&mgr, 10); | ||
- ASSERT(buf[0] == 'X'); | ||
- mg_mqtt_sub(c, topic, 1); | ||
- mg_mqtt_pub(c, topic, data, 1, false); | ||
- for (i = 0; i < 300 && buf[1] == 0; i++) mg_mgr_poll(&mgr, 10); | ||
- // LOG(LL_INFO, ("[%s]", buf)); | ||
- ASSERT(strcmp(buf, "Xx/f12/hi") == 0); | ||
- | ||
- // Set params | ||
- memset(buf, 0, sizeof(buf)); | ||
- memset(&opts, 0, sizeof(opts)); | ||
- opts.clean = true; | ||
- opts.will_qos = 1; | ||
- opts.will_retain = true; | ||
- opts.keepalive = 20; | ||
- opts.client_id = mg_str("mg_client"); | ||
- opts.will_topic = mg_str("mg_will_topic"); | ||
- opts.will_message = mg_str("mg_will_messsage"); | ||
- c = mg_mqtt_connect(&mgr, url, &opts, mqtt_cb, buf); | ||
- for (i = 0; i < 300 && buf[0] == 0; i++) mg_mgr_poll(&mgr, 10); | ||
- ASSERT(buf[0] == 'X'); | ||
- mg_mqtt_sub(c, topic, 1); | ||
- mg_mqtt_pub(c, topic, data, 1, false); | ||
- for (i = 0; i < 500 && buf[1] == 0; i++) mg_mgr_poll(&mgr, 10); | ||
- ASSERT(strcmp(buf, "Xx/f12/hi") == 0); | ||
- | ||
- mg_mgr_free(&mgr); | ||
- ASSERT(mgr.conns == NULL); | ||
-} | ||
- | ||
static void eh1(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { | ||
struct mg_tls_opts *topts = (struct mg_tls_opts *) fn_data; | ||
if (ev == MG_EV_ACCEPT && topts != NULL) mg_tls_init(c, topts); | ||
@@ -750,63 +689,6 @@ static void test_tls(void) { | ||
#endif | ||
} | ||
|
||
-static void f3(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { | ||
- int *ok = (int *) fn_data; | ||
- // LOG(LL_INFO, ("%d", ev)); | ||
- if (ev == MG_EV_CONNECT) { | ||
- // c->is_hexdumping = 1; | ||
- mg_printf(c, "GET / HTTP/1.0\r\nHost: %s\r\n\r\n", | ||
- c->peer.is_ip6 ? "ipv6.google.com" : "cesanta.com"); | ||
- } else if (ev == MG_EV_HTTP_MSG) { | ||
- struct mg_http_message *hm = (struct mg_http_message *) ev_data; | ||
- // LOG(LL_INFO, ("-->[%.*s]", (int) hm->message.len, hm->message.ptr)); | ||
- // ASSERT(mg_vcmp(&hm->method, "HTTP/1.1") == 0); | ||
- // ASSERT(mg_vcmp(&hm->uri, "301") == 0); | ||
- *ok = atoi(hm->uri.ptr); | ||
- } else if (ev == MG_EV_CLOSE) { | ||
- if (*ok == 0) *ok = 888; | ||
- } else if (ev == MG_EV_ERROR) { | ||
- if (*ok == 0) *ok = 777; | ||
- } | ||
-} | ||
- | ||
-static void test_http_client(void) { | ||
- struct mg_mgr mgr; | ||
- struct mg_connection *c; | ||
- int i, ok = 0; | ||
- mg_mgr_init(&mgr); | ||
- c = mg_http_connect(&mgr, "http://cesanta.com", f3, &ok); | ||
- ASSERT(c != NULL); | ||
- for (i = 0; i < 500 && ok <= 0; i++) mg_mgr_poll(&mgr, 10); | ||
- ASSERT(ok == 301); | ||
- c->is_closing = 1; | ||
- mg_mgr_poll(&mgr, 0); | ||
- ok = 0; | ||
-#if MG_ENABLE_MBEDTLS || MG_ENABLE_OPENSSL | ||
- { | ||
- struct mg_tls_opts opts = {.ca = "./test/data/ca.pem"}; | ||
- c = mg_http_connect(&mgr, "https://cesanta.com", f3, &ok); | ||
- ASSERT(c != NULL); | ||
- mg_tls_init(c, &opts); | ||
- for (i = 0; i < 500 && ok <= 0; i++) mg_mgr_poll(&mgr, 10); | ||
- ASSERT(ok == 200); | ||
- } | ||
-#endif | ||
- | ||
-#if MG_ENABLE_IPV6 | ||
- ok = 0; | ||
- // ipv6.google.com does not have IPv4 address, only IPv6, therefore | ||
- // it is guaranteed to hit IPv6 resolution path. | ||
- c = mg_http_connect(&mgr, "http://ipv6.google.com", f3, &ok); | ||
- ASSERT(c != NULL); | ||
- for (i = 0; i < 500 && ok <= 0; i++) mg_mgr_poll(&mgr, 10); | ||
- ASSERT(ok == 200); | ||
-#endif | ||
- | ||
- mg_mgr_free(&mgr); | ||
- ASSERT(mgr.conns == NULL); | ||
-} | ||
- | ||
static void f4(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { | ||
if (ev == MG_EV_HTTP_MSG) { | ||
struct mg_http_message *hm = (struct mg_http_message *) ev_data; | ||
@@ -1680,11 +1562,9 @@ int main(void) { | ||
test_ws(); | ||
test_ws_fragmentation(); | ||
test_http_server(); | ||
- test_http_client(); | ||
test_http_no_content_length(); | ||
test_http_pipeline(); | ||
test_http_range(); | ||
- test_mqtt(); | ||
printf("SUCCESS. Total tests: %d\n", s_num_tests); | ||
return EXIT_SUCCESS; | ||
} | ||
|
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 |
---|---|---|
@@ -1,29 +1,49 @@ | ||
# Template file for 'mongoose' | ||
pkgname=mongoose | ||
version=6.18 | ||
revision=4 | ||
version=7.6 | ||
revision=1 | ||
build_style=gnu-makefile | ||
make_use_env=compliant | ||
make_use_env=yes | ||
make_check_target=test | ||
make_build_target=linux-libs | ||
makedepends="openssl-devel" | ||
short_desc="Easy to use Web server" | ||
maintainer="Orphaned <orphan@voidlinux.org>" | ||
checkdepends="openssl-devel" | ||
short_desc="Embedded Networking Library for TCP,UDP,HTTP,MQTT,WebSocket and SSL/TLS" | ||
maintainer="Subhaditya Nath <sn03.general@gmail.com>" | ||
license="GPL-2.0-only" | ||
homepage="https://cesanta.com/" | ||
homepage="https://mongoose.ws/" | ||
distfiles="https://github.com/cesanta/mongoose/archive/${version}.tar.gz" | ||
checksum=f5c10346abc9c72f7cac7885d853ca064fb09aad57580433941a8fd7a3543769 | ||
checksum=1ef09d971b6de1a6317c109980d6fb5a9c19b39efef2506d6b76869644b3dafa | ||
|
||
export SSL=OPENSSL | ||
CFLAGS+=" -fPIC" | ||
|
||
case "$XBPS_TARGET_MACHINE" in | ||
*-musl) make_check_args="NO_SANITIZE=1" # libsanitizer-devel unavailable | ||
CFLAGS+=" -Wno-error" ;; # FD(c_) macro is broken | ||
*) checkdepends+=" libsanitizer-devel" ;; | ||
esac | ||
|
||
# GitHub CI runner doesn't support IPv6, causing tests to fail | ||
if [ "$XBPS_BUILD_ENVIRONMENT" = "void-packages-ci" ]; then | ||
make_check_args="IPV6=0" | ||
fi | ||
|
||
mongoose-devel_package() { | ||
depends="${sourcepkg}>=${version}_${revision}" | ||
short_desc+=" - development files" | ||
pkg_install() { | ||
vmove usr/include | ||
vmove "usr/lib/*.a" | ||
vmove "usr/lib/*.so" | ||
} | ||
} | ||
|
||
mongoose-doc_package() { | ||
short_desc+=" - documentation" | ||
pkg_install() { | ||
vmove usr/share | ||
vmkdir "usr/share/${sourcepkg}/doc" | ||
vcopy examples "usr/share/${sourcepkg}/doc" | ||
vcopy "docs/*" "usr/share/${sourcepkg}/doc" | ||
} | ||
} |