Added openSSL support

Fixed missing parameter in makefile
Added URI handling
This commit is contained in:
Sergio R. Caprile 2022-06-20 15:27:46 -03:00
parent 46bf79455c
commit 380a50e39b
2 changed files with 15 additions and 12 deletions

View File

@ -1,11 +1,13 @@
PROG ?= example PROG ?= example
ARGS ?= http://www.ladyada.net/ ARGS ?= 167.235.63.238:3128 http://info.cern.ch/
MBEDTLS_DIR ?= SSL = ?
ifeq "$(MBEDTLS_DIR)" "" ifeq "$(SSL)" "MBEDTLS"
else CFLAGS += -DMG_ENABLE_MBEDTLS=1 -lmbedtls -lmbedcrypto -lmbedx509
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS_DIR)/include -I/usr/include endif
CFLAGS += -L$(MBEDTLS_DIR)/lib -lmbedtls -lmbedcrypto -lmbedx509
ifeq "$(SSL)" "OPENSSL"
CFLAGS += -DMG_ENABLE_OPENSSL=1 -lssl -lcrypto
endif endif
all: $(PROG) all: $(PROG)
@ -13,7 +15,7 @@ all: $(PROG)
$(PROG): main.c $(PROG): main.c
$(CC) ../../mongoose.c -I../.. -W -Wall $(CFLAGS) -o $(PROG) main.c $(CC) ../../mongoose.c -I../.. -W -Wall $(CFLAGS) $(EXTRA_CFLAGS) -o $(PROG) main.c
clean: clean:
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb

View File

@ -5,9 +5,8 @@
// make // make
// ./example PROXY:PORT http://www.ladyada.net // ./example PROXY:PORT http://www.ladyada.net
// //
// To enable SSL/TLS for this client, build it like this: // To enable SSL/TLS, make SSL=OPENSSL or make SSL=MBEDTLS
// make MBEDTLS_DIR=/path/to/your/mbedtls/installation //
#include "mongoose.h" #include "mongoose.h"
// Print HTTP response and signal that we're done // Print HTTP response and signal that we're done
@ -41,8 +40,10 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
("Connected to proxy, status: %.*s", (int) hm.uri.len, hm.uri.ptr)); ("Connected to proxy, status: %.*s", (int) hm.uri.len, hm.uri.ptr));
mg_iobuf_del(&c->recv, 0, n); mg_iobuf_del(&c->recv, 0, n);
// Send request to the target server // Send request to the target server
mg_printf(c, "GET / HTTP/1.0\r\nHost: %.*s\r\n\r\n", (int) host.len, mg_printf(c, "GET %s HTTP/1.0\r\n"
host.ptr); "Host: %.*s\r\n"
"\r\n",
mg_url_uri(url), (int) host.len, host.ptr);
} }
} }
} }