1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-07-29 21:01:13 +03:00

Regorganized directories to make them more intuitive

This commit is contained in:
Thomas Davis
2013-08-23 19:36:42 -04:00
parent 1bef635908
commit b2aee90d14
149 changed files with 836 additions and 669 deletions

View File

@ -0,0 +1,36 @@
#
# Copyright (c) 2013 No Face Press, LLC
# License http://opensource.org/licenses/mit-license.php MIT License
#
#This makefile is used to test the other Makefiles
PROG = embedded_cpp
SRC = embedded_cpp.cpp
TOP = ../..
CIVETWEB_LIB = libcivetweb.a
CFLAGS = -I$(TOP)/include $(COPT)
LIBS = -lpthread
include $(TOP)/resources/Makefile.in-os
ifeq ($(TARGET_OS),LINUX)
LIBS += -ldl
endif
all: $(PROG)
$(PROG): $(CIVETWEB_LIB) $(SRC)
$(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS)
$(CIVETWEB_LIB):
$(MAKE) -C $(TOP) clean lib WITH_CPP=1
cp $(TOP)/$(CIVETWEB_LIB) .
clean:
rm -f $(CIVETWEB_LIB) $(PROG)
.PHONY: all clean

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 2013 No Face Press, LLC
* License http://opensource.org/licenses/mit-license.php MIT License
*/
// Simple example program on how to use Embedded C++ interface.
#include "CivetServer.h"
#ifdef _WIN32
#include <Windows.h>
#endif
#define DOCUMENT_ROOT "."
#define PORT "8888"
#define EXAMPLE_URI "/example"
#define EXIT_URI "/exit"
bool exitNow = false;
class ExampleHandler: public CivetHandler {
public:
bool handleGet(CivetServer *server, struct mg_connection *conn) {
mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
mg_printf(conn, "<html><body>");
mg_printf(conn, "<h2>This is example text!!!</h2>");
mg_printf(conn, "<p>To exit <a href=\"%s\">click here</a></p>",
EXIT_URI);
mg_printf(conn, "</body></html>\n");
return true;
}
};
class ExitHandler: public CivetHandler {
public:
bool handleGet(CivetServer *server, struct mg_connection *conn) {
mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n");
mg_printf(conn, "Bye!\n");
exitNow = true;
return true;
}
};
int main(int argc, char *argv[]) {
const char * options[] = { "document_root", DOCUMENT_ROOT,
"listening_ports", PORT, 0 };
CivetServer server(options);
server.addHandler(EXAMPLE_URI, new ExampleHandler());
server.addHandler(EXIT_URI, new ExitHandler());
printf("Browse files at http://localhost:%s/\n", PORT);
printf("Run example at http://localhost:%s%s\n", PORT, EXIT_URI);
printf("Exit at http://localhost:%s%s\n", PORT, EXIT_URI);
while (!exitNow) {
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
}
printf("Bye!\n");
return 0;
}