diff --git a/doc/Embedding.md b/doc/Embedding.md
index 70947831..be61e19e 100644
--- a/doc/Embedding.md
+++ b/doc/Embedding.md
@@ -55,11 +55,11 @@ By default, the server will automatically serve up files like a normal HTTP serv
### C
- Include the C interface ```libhttp.h```.
- - Use `mg_start()` to start the server.
+ - Use `httplib_start()` to start the server.
- Use *options* to select the port and document root among other things.
- Use *callbacks* to add your own hooks.
- - Use `mg_set_request_handler()` to easily add your own request handlers.
- - Use `mg_stop()` to stop the server.
+ - Use `httplib_set_request_handler()` to easily add your own request handlers.
+ - Use `httplib_stop()` to stop the server.
### C++
- Note that LibHTTP is Clean C, and C++ interface ```LibHTTPServer.h``` is only a wrapper layer around the C interface.
@@ -136,8 +136,8 @@ LibHTTP can be built with server side JavaScript support by including the Duktap
LibHTTP internals
------
-LibHTTP is multithreaded web server. `mg_start()` function allocates
-web server context (`struct mg_context`), which holds all information
+LibHTTP is multithreaded web server. `httplib_start()` function allocates
+web server context (`struct httplib_context`), which holds all information
about web server instance:
- configuration options. Note that LibHTTP makes internal copies of
@@ -148,14 +148,14 @@ about web server instance:
- a queue for accepted sockets
- mutexes and condition variables for inter-thread synchronization
-When `mg_start()` returns, all initialization is guaranteed to be complete
-(e.g. listening ports are opened, SSL is initialized, etc). `mg_start()` starts
+When `httplib_start()` returns, all initialization is guaranteed to be complete
+(e.g. listening ports are opened, SSL is initialized, etc). `httplib_start()` starts
some threads: a master thread, that accepts new connections, and several
worker threads, that process accepted connections. The number of worker threads
is configurable via `num_threads` configuration option. That number puts a
limit on number of simultaneous requests that can be handled by LibHTTP.
If you embed LibHTTP into a program that uses SSL outside LibHTTP as well,
-you may need to initialize SSL before calling `mg_start()`, and set the pre-
+you may need to initialize SSL before calling `httplib_start()`, and set the pre-
processor define SSL_ALREADY_INITIALIZED. This is not required if SSL is used
only within LibHTTP.
diff --git a/doc/UserManual.md b/doc/UserManual.md
index 9f594ac2..aa9547f2 100644
--- a/doc/UserManual.md
+++ b/doc/UserManual.md
@@ -531,7 +531,7 @@ is an example for a plain Lua script.
is an example for a Lua Server Page.
Both examples show the content of the `mg.request_info` object as the page
-content. Please refer to `struct mg_request_info` definition in
+content. Please refer to `struct httplib_request_info` definition in
[libhttp.h](https://github.com/lammertb/libhttp/blob/master/include/libhttp.h)
to see additional information on the elements of the `mg.request_info` object.
diff --git a/examples/chat/chat.c b/examples/chat/chat.c
index ad146183..23ba77d4 100644
--- a/examples/chat/chat.c
+++ b/examples/chat/chat.c
@@ -54,13 +54,13 @@ static long last_message_id;
static pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
// Get session object for the connection. Caller must hold the lock.
-static struct session *get_session(const struct mg_connection *conn)
+static struct session *get_session(const struct httplib_connection *conn)
{
int i;
- const char *cookie = mg_get_header(conn, "Cookie");
+ const char *cookie = httplib_get_header(conn, "Cookie");
char session_id[33];
time_t now = time(NULL);
- mg_get_cookie(cookie, "session", session_id, sizeof(session_id));
+ httplib_get_cookie(cookie, "session", session_id, sizeof(session_id));
for (i = 0; i < MAX_SESSIONS; i++) {
if (sessions[i].expire != 0 &&
sessions[i].expire > now &&
@@ -71,11 +71,10 @@ static struct session *get_session(const struct mg_connection *conn)
return i == MAX_SESSIONS ? NULL : &sessions[i];
}
-static void get_qsvar(const struct mg_request_info *request_info,
- const char *name, char *dst, size_t dst_len)
+static void get_qsvar(const struct httplib_request_info *request_info, const char *name, char *dst, size_t dst_len)
{
const char *qs = request_info->query_string;
- mg_get_var(qs, strlen(qs == NULL ? "" : qs), name, dst, dst_len);
+ httplib_get_var(qs, strlen(qs == NULL ? "" : qs), name, dst, dst_len);
}
// Get a get of messages with IDs greater than last_id and transform them
@@ -118,14 +117,14 @@ static char *messages_to_json(long last_id)
// If "callback" param is present in query string, this is JSONP call.
// Return 1 in this case, or 0 if "callback" is not specified.
// Wrap an output in Javascript function call.
-static int handle_jsonp(struct mg_connection *conn,
- const struct mg_request_info *request_info)
+static int handle_jsonp(struct httplib_connection *conn,
+ const struct httplib_request_info *request_info)
{
char cb[64];
get_qsvar(request_info, "callback", cb, sizeof(cb));
if (cb[0] != '\0') {
- mg_printf(conn, "%s(", cb);
+ httplib_printf(conn, "%s(", cb);
}
return cb[0] == '\0' ? 0 : 1;
@@ -133,23 +132,23 @@ static int handle_jsonp(struct mg_connection *conn,
// A handler for the /ajax/get_messages endpoint.
// Return a list of messages with ID greater than requested.
-static void ajax_get_messages(struct mg_connection *conn,
- const struct mg_request_info *request_info)
+static void ajax_get_messages(struct httplib_connection *conn,
+ const struct httplib_request_info *request_info)
{
char last_id[32], *json;
int is_jsonp;
- mg_printf(conn, "%s", ajax_reply_start);
+ httplib_printf(conn, "%s", ajax_reply_start);
is_jsonp = handle_jsonp(conn, request_info);
get_qsvar(request_info, "last_id", last_id, sizeof(last_id));
if ((json = messages_to_json(strtoul(last_id, NULL, 10))) != NULL) {
- mg_printf(conn, "[%s]", json);
+ httplib_printf(conn, "[%s]", json);
free(json);
}
if (is_jsonp) {
- mg_printf(conn, "%s", ")");
+ httplib_printf(conn, "%s", ")");
}
}
@@ -170,15 +169,15 @@ static void my_strlcpy(char *dst, const char *src, size_t len)
}
// A handler for the /ajax/send_message endpoint.
-static void ajax_send_message(struct mg_connection *conn,
- const struct mg_request_info *request_info)
+static void ajax_send_message(struct httplib_connection *conn,
+ const struct httplib_request_info *request_info)
{
struct message *message;
struct session *session;
char text[sizeof(message->text) - 1];
int is_jsonp;
- mg_printf(conn, "%s", ajax_reply_start);
+ httplib_printf(conn, "%s", ajax_reply_start);
is_jsonp = handle_jsonp(conn, request_info);
get_qsvar(request_info, "text", text, sizeof(text));
@@ -195,19 +194,19 @@ static void ajax_send_message(struct mg_connection *conn,
pthread_rwlock_unlock(&rwlock);
}
- mg_printf(conn, "%s", text[0] == '\0' ? "false" : "true");
+ httplib_printf(conn, "%s", text[0] == '\0' ? "false" : "true");
if (is_jsonp) {
- mg_printf(conn, "%s", ")");
+ httplib_printf(conn, "%s", ")");
}
}
// Redirect user to the login form. In the cookie, store the original URL
// we came from, so that after the authorization we could redirect back.
-static void redirect_to_login(struct mg_connection *conn,
- const struct mg_request_info *request_info)
+static void redirect_to_login(struct httplib_connection *conn,
+ const struct httplib_request_info *request_info)
{
- mg_printf(conn, "HTTP/1.1 302 Found\r\n"
+ httplib_printf(conn, "HTTP/1.1 302 Found\r\n"
"Set-Cookie: original_url=%s\r\n"
"Location: %s\r\n\r\n",
request_info->uri, login_url);
@@ -244,7 +243,7 @@ static struct session *new_session(void)
static void generate_session_id(char *buf, const char *random,
const char *user)
{
- mg_md5(buf, random, user, NULL);
+ httplib_md5(buf, random, user, NULL);
}
static void send_server_message(const char *fmt, ...)
@@ -264,8 +263,8 @@ static void send_server_message(const char *fmt, ...)
// A handler for the /authorize endpoint.
// Login page form sends user name and password to this endpoint.
-static void authorize(struct mg_connection *conn,
- const struct mg_request_info *request_info)
+static void authorize(struct httplib_connection *conn,
+ const struct httplib_request_info *request_info)
{
char user[MAX_USER_LEN], password[MAX_USER_LEN];
struct session *session;
@@ -290,7 +289,7 @@ static void authorize(struct mg_connection *conn,
snprintf(session->random, sizeof(session->random), "%d", rand());
generate_session_id(session->session_id, session->random, session->user);
send_server_message("<%s> joined", session->user);
- mg_printf(conn, "HTTP/1.1 302 Found\r\n"
+ httplib_printf(conn, "HTTP/1.1 302 Found\r\n"
"Set-Cookie: session=%s; max-age=3600; http-only\r\n" // Session ID
"Set-Cookie: user=%s\r\n" // Set user, needed by Javascript code
"Set-Cookie: original_url=/; max-age=0\r\n" // Delete original_url
@@ -303,8 +302,8 @@ static void authorize(struct mg_connection *conn,
}
// Return 1 if request is authorized, 0 otherwise.
-static int is_authorized(const struct mg_connection *conn,
- const struct mg_request_info *request_info)
+static int is_authorized(const struct httplib_connection *conn,
+ const struct httplib_request_info *request_info)
{
struct session *session;
char valid_id[33];
@@ -329,22 +328,22 @@ static int is_authorized(const struct mg_connection *conn,
return authorized;
}
-static void redirect_to_ssl(struct mg_connection *conn,
- const struct mg_request_info *request_info)
+static void redirect_to_ssl(struct httplib_connection *conn,
+ const struct httplib_request_info *request_info)
{
- const char *p, *host = mg_get_header(conn, "Host");
+ const char *p, *host = httplib_get_header(conn, "Host");
if (host != NULL && (p = strchr(host, ':')) != NULL) {
- mg_printf(conn, "HTTP/1.1 302 Found\r\n"
+ httplib_printf(conn, "HTTP/1.1 302 Found\r\n"
"Location: https://%.*s:8082/%s:8082\r\n\r\n",
(int) (p - host), host, request_info->uri);
} else {
- mg_printf(conn, "%s", "HTTP/1.1 500 Error\r\n\r\nHost: header is not set");
+ httplib_printf(conn, "%s", "HTTP/1.1 500 Error\r\n\r\nHost: header is not set");
}
}
-static int begin_request_handler(struct mg_connection *conn)
+static int begin_request_handler(struct httplib_connection *conn)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
int processed = 1;
if (!request_info->is_ssl) {
@@ -375,8 +374,8 @@ static const char *options[] = {
int main(void)
{
- struct mg_callbacks callbacks;
- struct mg_context *ctx;
+ struct httplib_callbacks callbacks;
+ struct httplib_context *ctx;
// Initialize random number generator. It will be used later on for
// the session identifier creation.
@@ -385,16 +384,16 @@ int main(void)
// Setup and start Civetweb
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = begin_request_handler;
- if ((ctx = mg_start(&callbacks, NULL, options)) == NULL) {
+ if ((ctx = httplib_start(&callbacks, NULL, options)) == NULL) {
printf("%s\n", "Cannot start chat server, fatal exit");
exit(EXIT_FAILURE);
}
// Wait until enter is pressed, then exit
printf("Chat server started on ports %s, press enter to quit.\n",
- mg_get_option(ctx, "listening_ports"));
+ httplib_get_option(ctx, "listening_ports"));
getchar();
- mg_stop(ctx);
+ httplib_stop(ctx);
printf("%s\n", "Chat server stopped.");
return EXIT_SUCCESS;
diff --git a/examples/embedded_c/embedded_c.c b/examples/embedded_c/embedded_c.c
index ca542c61..8bb5d3bc 100644
--- a/examples/embedded_c/embedded_c.c
+++ b/examples/embedded_c/embedded_c.c
@@ -38,157 +38,157 @@ int exitNow = 0;
int
-ExampleHandler(struct mg_connection *conn, void *cbdata)
+ExampleHandler(struct httplib_connection *conn, void *cbdata)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
"close\r\n\r\n");
- mg_printf(conn, "
");
- mg_printf(conn, "This is an example text from a C handler ");
- mg_printf(
+ httplib_printf(conn, "");
+ httplib_printf(conn, "This is an example text from a C handler ");
+ httplib_printf(
conn,
"To see a page from the A handler click A
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the A handler click "
"A/A
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the A/B handler click A/B
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the B handler (0) click B
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the B handler (1) click B/A
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the B handler (2) click B/B
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the *.foo handler click xy.foo
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the close handler click close
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the FileHandler handler click form (the starting point of the "
"form test)
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the CookieHandler handler click cookie
");
- mg_printf(conn,
+ httplib_printf(conn,
"To see an example for parsing files on the fly click form (form for "
"uploading files)
");
#ifdef USE_WEBSOCKET
- mg_printf(conn,
+ httplib_printf(conn,
"To test websocket handler click "
"websocket
");
#endif
- mg_printf(conn, "To exit click exit
", EXIT_URI);
- mg_printf(conn, "\n");
+ httplib_printf(conn, "To exit click exit
", EXIT_URI);
+ httplib_printf(conn, "\n");
return 1;
}
int
-ExitHandler(struct mg_connection *conn, void *cbdata)
+ExitHandler(struct httplib_connection *conn, void *cbdata)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: "
"text/plain\r\nConnection: close\r\n\r\n");
- mg_printf(conn, "Server will shut down.\n");
- mg_printf(conn, "Bye!\n");
+ httplib_printf(conn, "Server will shut down.\n");
+ httplib_printf(conn, "Bye!\n");
exitNow = 1;
return 1;
}
int
-AHandler(struct mg_connection *conn, void *cbdata)
+AHandler(struct httplib_connection *conn, void *cbdata)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
"close\r\n\r\n");
- mg_printf(conn, "");
- mg_printf(conn, "This is the A handler!!! ");
- mg_printf(conn, "\n");
+ httplib_printf(conn, "");
+ httplib_printf(conn, "This is the A handler!!! ");
+ httplib_printf(conn, "\n");
return 1;
}
int
-ABHandler(struct mg_connection *conn, void *cbdata)
+ABHandler(struct httplib_connection *conn, void *cbdata)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
"close\r\n\r\n");
- mg_printf(conn, "");
- mg_printf(conn, "This is the AB handler!!! ");
- mg_printf(conn, "\n");
+ httplib_printf(conn, "");
+ httplib_printf(conn, "This is the AB handler!!! ");
+ httplib_printf(conn, "\n");
return 1;
}
int
-BXHandler(struct mg_connection *conn, void *cbdata)
+BXHandler(struct httplib_connection *conn, void *cbdata)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
"close\r\n\r\n");
- mg_printf(conn, "");
- mg_printf(conn, "This is the BX handler %p!!! ", cbdata);
- mg_printf(conn, "The actual uri is %s
", req_info->uri);
- mg_printf(conn, "\n");
+ httplib_printf(conn, "");
+ httplib_printf(conn, "This is the BX handler %p!!! ", cbdata);
+ httplib_printf(conn, "The actual uri is %s
", req_info->uri);
+ httplib_printf(conn, "\n");
return 1;
}
int
-FooHandler(struct mg_connection *conn, void *cbdata)
+FooHandler(struct httplib_connection *conn, void *cbdata)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
"close\r\n\r\n");
- mg_printf(conn, "");
- mg_printf(conn, "This is the Foo handler!!! ");
- mg_printf(conn,
+ httplib_printf(conn, "");
+ httplib_printf(conn, "This is the Foo handler!!! ");
+ httplib_printf(conn,
"The request was:
%s %s HTTP/%s ",
req_info->request_method,
req_info->uri,
req_info->http_version);
- mg_printf(conn, "\n");
+ httplib_printf(conn, "\n");
return 1;
}
int
-CloseHandler(struct mg_connection *conn, void *cbdata)
+CloseHandler(struct httplib_connection *conn, void *cbdata)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
"close\r\n\r\n");
- mg_printf(conn, "");
- mg_printf(conn,
+ httplib_printf(conn, "");
+ httplib_printf(conn,
"This handler will close the connection in a second ");
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
- mg_printf(conn, "bye");
+ httplib_printf(conn, "bye");
printf("CloseHandler: close connection\n");
- mg_close_connection(conn);
+ httplib_close_connection(conn);
printf("CloseHandler: wait 10 sec\n");
#ifdef _WIN32
Sleep(10000);
@@ -201,12 +201,12 @@ CloseHandler(struct mg_connection *conn, void *cbdata)
int
-FileHandler(struct mg_connection *conn, void *cbdata)
+FileHandler(struct httplib_connection *conn, void *cbdata)
{
/* In this handler, we ignore the req_info and send the file "fileName". */
const char *fileName = (const char *)cbdata;
- mg_send_file(conn, fileName);
+ httplib_send_file(conn, fileName);
return 1;
}
@@ -218,9 +218,9 @@ field_found(const char *key,
size_t pathlen,
void *user_data)
{
- struct mg_connection *conn = (struct mg_connection *)user_data;
+ struct httplib_connection *conn = (struct httplib_connection *)user_data;
- mg_printf(conn, "\r\n\r\n%s:\r\n", key);
+ httplib_printf(conn, "\r\n\r\n%s:\r\n", key);
if (filename && *filename) {
#ifdef _WIN32
@@ -237,12 +237,12 @@ field_found(const char *key,
int
field_get(const char *key, const char *value, size_t valuelen, void *user_data)
{
- struct mg_connection *conn = (struct mg_connection *)user_data;
+ struct httplib_connection *conn = (struct httplib_connection *)user_data;
if (key[0]) {
- mg_printf(conn, "%s = ", key);
+ httplib_printf(conn, "%s = ", key);
}
- mg_write(conn, value, valuelen);
+ httplib_write(conn, value, valuelen);
return 0;
}
@@ -251,62 +251,59 @@ field_get(const char *key, const char *value, size_t valuelen, void *user_data)
int
field_stored(const char *path, long long file_size, void *user_data)
{
- struct mg_connection *conn = (struct mg_connection *)user_data;
+ struct httplib_connection *conn = (struct httplib_connection *)user_data;
- mg_printf(conn,
- "stored as %s (%lu bytes)\r\n\r\n",
- path,
- (unsigned long)file_size);
+ httplib_printf(conn, "stored as %s (%lu bytes)\r\n\r\n", path, (unsigned long)file_size);
return 0;
}
int
-FormHandler(struct mg_connection *conn, void *cbdata)
+FormHandler(struct httplib_connection *conn, void *cbdata)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
int ret;
- struct mg_form_data_handler fdh = {field_found, field_get, field_stored, 0};
+ struct httplib_form_data_handler fdh = {field_found, field_get, field_stored, 0};
/* It would be possible to check the request info here before calling
- * mg_handle_form_request. */
+ * httplib_handle_form_request. */
(void)req_info;
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: "
"text/plain\r\nConnection: close\r\n\r\n");
fdh.user_data = (void *)conn;
/* Call the form handler */
- mg_printf(conn, "Form data:");
- ret = mg_handle_form_request(conn, &fdh);
- mg_printf(conn, "\r\n%i fields found", ret);
+ httplib_printf(conn, "Form data:");
+ ret = httplib_handle_form_request(conn, &fdh);
+ httplib_printf(conn, "\r\n%i fields found", ret);
return 1;
}
int
-FileUploadForm(struct mg_connection *conn, void *cbdata)
+FileUploadForm(struct httplib_connection *conn, void *cbdata)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
"close\r\n\r\n");
- mg_printf(conn, "\n");
- mg_printf(conn, "\n\n");
- mg_printf(conn, " \n");
- mg_printf(conn, "File upload \n");
- mg_printf(conn, "\n\n");
- mg_printf(conn,
+ httplib_printf(conn, "\n");
+ httplib_printf(conn, "\n\n");
+ httplib_printf(conn, " \n");
+ httplib_printf(conn, "File upload \n");
+ httplib_printf(conn, "\n\n");
+ httplib_printf(conn,
"\n\n\n");
+ httplib_printf(conn, " \n");
+ httplib_printf(conn, " \n");
+ httplib_printf(conn, "\n\n\n");
return 1;
}
@@ -371,66 +368,63 @@ field_get_checksum(const char *key,
int
-CheckSumHandler(struct mg_connection *conn, void *cbdata)
+CheckSumHandler(struct httplib_connection *conn, void *cbdata)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
int i, j, ret;
struct tfiles_checksums chksums;
md5_byte_t digest[16];
- struct mg_form_data_handler fdh = {field_disp_read_on_the_fly,
- field_get_checksum,
- 0,
- (void *)&chksums};
+ struct httplib_form_data_handler fdh = {field_disp_read_on_the_fly, field_get_checksum, 0,(void *)&chksums};
/* It would be possible to check the request info here before calling
- * mg_handle_form_request. */
+ * httplib_handle_form_request. */
(void)req_info;
memset(&chksums, 0, sizeof(chksums));
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Connection: close\r\n\r\n");
/* Call the form handler */
- mg_printf(conn, "File checksums:");
- ret = mg_handle_form_request(conn, &fdh);
+ httplib_printf(conn, "File checksums:");
+ ret = httplib_handle_form_request(conn, &fdh);
for (i = 0; i < chksums.index; i++) {
md5_finish(&(chksums.file[i].chksum), digest);
/* Visual Studio 2010+ support llu */
- mg_printf(conn,
+ httplib_printf(conn,
"\r\n%s %llu ",
chksums.file[i].name,
chksums.file[i].length);
for (j = 0; j < 16; j++) {
- mg_printf(conn, "%02x", (unsigned int)digest[j]);
+ httplib_printf(conn, "%02x", (unsigned int)digest[j]);
}
}
- mg_printf(conn, "\r\n%i files\r\n", ret);
+ httplib_printf(conn, "\r\n%i files\r\n", ret);
return 1;
}
int
-CookieHandler(struct mg_connection *conn, void *cbdata)
+CookieHandler(struct httplib_connection *conn, void *cbdata)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
- const char *cookie = mg_get_header(conn, "Cookie");
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
+ const char *cookie = httplib_get_header(conn, "Cookie");
char first_str[64], count_str[64];
int count;
- (void)mg_get_cookie(cookie, "first", first_str, sizeof(first_str));
- (void)mg_get_cookie(cookie, "count", count_str, sizeof(count_str));
+ httplib_get_cookie(cookie, "first", first_str, sizeof(first_str));
+ httplib_get_cookie(cookie, "count", count_str, sizeof(count_str));
- mg_printf(conn, "HTTP/1.1 200 OK\r\nConnection: close\r\n");
+ httplib_printf(conn, "HTTP/1.1 200 OK\r\nConnection: close\r\n");
if (first_str[0] == 0) {
time_t t = time(0);
struct tm *ptm = localtime(&t);
- mg_printf(conn,
+ httplib_printf(conn,
"Set-Cookie: first=%04i-%02i-%02iT%02i:%02i:%02i\r\n",
ptm->tm_year + 1900,
ptm->tm_mon + 1,
@@ -440,42 +434,42 @@ CookieHandler(struct mg_connection *conn, void *cbdata)
ptm->tm_sec);
}
count = (count_str[0] == 0) ? 0 : atoi(count_str);
- mg_printf(conn, "Set-Cookie: count=%i\r\n", count + 1);
- mg_printf(conn, "Content-Type: text/html\r\n\r\n");
+ httplib_printf(conn, "Set-Cookie: count=%i\r\n", count + 1);
+ httplib_printf(conn, "Content-Type: text/html\r\n\r\n");
- mg_printf(conn, "");
- mg_printf(conn, "This is the CookieHandler. ");
- mg_printf(conn, "The actual uri is %s
", req_info->uri);
+ httplib_printf(conn, "");
+ httplib_printf(conn, "This is the CookieHandler. ");
+ httplib_printf(conn, "The actual uri is %s
", req_info->uri);
if (first_str[0] == 0) {
- mg_printf(conn, "This is the first time, you opened this page
");
+ httplib_printf(conn, "This is the first time, you opened this page
");
} else {
- mg_printf(conn, "You opened this page %i times before.
", count);
- mg_printf(conn, "You first opened this page on %s.
", first_str);
+ httplib_printf(conn, "You opened this page %i times before.
", count);
+ httplib_printf(conn, "You first opened this page on %s.
", first_str);
}
- mg_printf(conn, "\n");
+ httplib_printf(conn, "\n");
return 1;
}
int
-WebSocketStartHandler(struct mg_connection *conn, void *cbdata)
+WebSocketStartHandler(struct httplib_connection *conn, void *cbdata)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
"close\r\n\r\n");
- mg_printf(conn, "\n");
- mg_printf(conn, "\n\n");
- mg_printf(conn, " \n");
- mg_printf(conn, "Embedded websocket example \n");
+ httplib_printf(conn, "\n");
+ httplib_printf(conn, "\n\n");
+ httplib_printf(conn, " \n");
+ httplib_printf(conn, "Embedded websocket example \n");
#ifdef USE_WEBSOCKET
- /* mg_printf(conn, "\n"); ... xhtml style */
- mg_printf(conn, "\n");
- mg_printf(conn, "\n\n");
- mg_printf(
+ /* httplib_printf(conn, "]]>\n"); ... xhtml style */
+ httplib_printf(conn, "\n");
+ httplib_printf(conn, "\n\n");
+ httplib_printf(
conn,
"No websocket connection yet
\n");
#else
- mg_printf(conn, "\n\n");
- mg_printf(conn, "Example not compiled with USE_WEBSOCKET\n");
+ httplib_printf(conn, "\n\n");
+ httplib_printf(conn, "Example not compiled with USE_WEBSOCKET\n");
#endif
- mg_printf(conn, "\n\n");
+ httplib_printf(conn, "\n\n");
return 1;
}
@@ -517,7 +511,7 @@ WebSocketStartHandler(struct mg_connection *conn, void *cbdata)
#define MAX_WS_CLIENTS (5)
struct t_ws_client {
- struct mg_connection *conn;
+ struct httplib_connection *conn;
int state;
} static ws_clients[MAX_WS_CLIENTS];
@@ -533,39 +527,36 @@ struct t_ws_client {
int
-WebSocketConnectHandler(const struct mg_connection *conn, void *cbdata)
+WebSocketConnectHandler(const struct httplib_connection *conn, void *cbdata)
{
- struct mg_context *ctx = mg_get_context(conn);
+ struct httplib_context *ctx = httplib_get_context(conn);
int reject = 1;
int i;
- mg_lock_context(ctx);
+ httplib_lock_context(ctx);
for (i = 0; i < MAX_WS_CLIENTS; i++) {
if (ws_clients[i].conn == NULL) {
- ws_clients[i].conn = (struct mg_connection *)conn;
+ ws_clients[i].conn = (struct httplib_connection *)conn;
ws_clients[i].state = 1;
- mg_set_user_connection_data(ws_clients[i].conn,
- (void *)(ws_clients + i));
+ httplib_set_user_connection_data(ws_clients[i].conn, (void *)(ws_clients + i));
reject = 0;
break;
}
}
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
- fprintf(stdout,
- "Websocket client %s\r\n\r\n",
- (reject ? "rejected" : "accepted"));
+ fprintf(stdout, "Websocket client %s\r\n\r\n", (reject ? "rejected" : "accepted"));
return reject;
}
void
-WebSocketReadyHandler(struct mg_connection *conn, void *cbdata)
+WebSocketReadyHandler(struct httplib_connection *conn, void *cbdata)
{
const char *text = "Hello from the websocket ready handler";
- struct t_ws_client *client = mg_get_user_connection_data(conn);
+ struct t_ws_client *client = httplib_get_user_connection_data(conn);
- mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, text, strlen(text));
+ httplib_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, text, strlen(text));
fprintf(stdout, "Greeting message sent to websocket client\r\n\r\n");
ASSERT(client->conn == conn);
ASSERT(client->state == 1);
@@ -575,13 +566,9 @@ WebSocketReadyHandler(struct mg_connection *conn, void *cbdata)
int
-WebsocketDataHandler(struct mg_connection *conn,
- int bits,
- char *data,
- size_t len,
- void *cbdata)
+WebsocketDataHandler(struct httplib_connection *conn, int bits, char *data, size_t len, void *cbdata)
{
- struct t_ws_client *client = mg_get_user_connection_data(conn);
+ struct t_ws_client *client = httplib_get_user_connection_data(conn);
ASSERT(client->conn == conn);
ASSERT(client->state >= 1);
@@ -594,25 +581,24 @@ WebsocketDataHandler(struct mg_connection *conn,
void
-WebSocketCloseHandler(const struct mg_connection *conn, void *cbdata)
+WebSocketCloseHandler(const struct httplib_connection *conn, void *cbdata)
{
- struct mg_context *ctx = mg_get_context(conn);
- struct t_ws_client *client = mg_get_user_connection_data(conn);
+ struct httplib_context *ctx = httplib_get_context(conn);
+ struct t_ws_client *client = httplib_get_user_connection_data(conn);
ASSERT(client->conn == conn);
ASSERT(client->state >= 1);
- mg_lock_context(ctx);
+ httplib_lock_context(ctx);
client->state = 0;
client->conn = NULL;
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
- fprintf(stdout,
- "Client droped from the set of webserver connections\r\n\r\n");
+ fprintf(stdout, "Client droped from the set of webserver connections\r\n\r\n");
}
void
-InformWebsockets(struct mg_context *ctx)
+InformWebsockets(struct httplib_context *ctx)
{
static unsigned long cnt = 0;
char text[32];
@@ -620,16 +606,13 @@ InformWebsockets(struct mg_context *ctx)
sprintf(text, "%lu", ++cnt);
- mg_lock_context(ctx);
+ httplib_lock_context(ctx);
for (i = 0; i < MAX_WS_CLIENTS; i++) {
if (ws_clients[i].state == 2) {
- mg_websocket_write(ws_clients[i].conn,
- WEBSOCKET_OPCODE_TEXT,
- text,
- strlen(text));
+ httplib_websocket_write(ws_clients[i].conn, WEBSOCKET_OPCODE_TEXT, text, strlen(text));
}
}
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
}
#endif
@@ -747,15 +730,15 @@ main(int argc, char *argv[])
#endif
#endif
0};
- struct mg_callbacks callbacks;
- struct mg_context *ctx;
- struct mg_server_ports ports[32];
+ struct httplib_callbacks callbacks;
+ struct httplib_context *ctx;
+ struct httplib_server_ports ports[32];
int port_cnt, n;
int err = 0;
/* Check if libcivetweb has been built with all required features. */
#ifdef USE_IPV6
- if (!mg_check_feature(8)) {
+ if (!httplib_check_feature(8)) {
fprintf(stderr,
"Error: Embedded example built with IPv6 support, "
"but civetweb library build without.\n");
@@ -763,7 +746,7 @@ main(int argc, char *argv[])
}
#endif
#ifdef USE_WEBSOCKET
- if (!mg_check_feature(16)) {
+ if (!httplib_check_feature(16)) {
fprintf(stderr,
"Error: Embedded example built with websocket support, "
"but civetweb library build without.\n");
@@ -771,7 +754,7 @@ main(int argc, char *argv[])
}
#endif
#ifndef NO_SSL
- if (!mg_check_feature(2)) {
+ if (!httplib_check_feature(2)) {
fprintf(stderr,
"Error: Embedded example built with SSL support, "
"but civetweb library build without.\n");
@@ -788,58 +771,49 @@ main(int argc, char *argv[])
#ifndef NO_SSL
callbacks.init_ssl = init_ssl;
#endif
- ctx = mg_start(&callbacks, 0, options);
+ ctx = httplib_start(&callbacks, 0, options);
/* Add handler EXAMPLE_URI, to explain the example */
- mg_set_request_handler(ctx, EXAMPLE_URI, ExampleHandler, 0);
- mg_set_request_handler(ctx, EXIT_URI, ExitHandler, 0);
+ httplib_set_request_handler(ctx, EXAMPLE_URI, ExampleHandler, 0);
+ httplib_set_request_handler(ctx, EXIT_URI, ExitHandler, 0);
/* Add handler for /A* and special handler for /A/B */
- mg_set_request_handler(ctx, "/A", AHandler, 0);
- mg_set_request_handler(ctx, "/A/B", ABHandler, 0);
+ httplib_set_request_handler(ctx, "/A", AHandler, 0);
+ httplib_set_request_handler(ctx, "/A/B", ABHandler, 0);
/* Add handler for /B, /B/A, /B/B but not for /B* */
- mg_set_request_handler(ctx, "/B$", BXHandler, (void *)0);
- mg_set_request_handler(ctx, "/B/A$", BXHandler, (void *)1);
- mg_set_request_handler(ctx, "/B/B$", BXHandler, (void *)2);
+ httplib_set_request_handler(ctx, "/B$", BXHandler, (void *)0);
+ httplib_set_request_handler(ctx, "/B/A$", BXHandler, (void *)1);
+ httplib_set_request_handler(ctx, "/B/B$", BXHandler, (void *)2);
/* Add handler for all files with .foo extention */
- mg_set_request_handler(ctx, "**.foo$", FooHandler, 0);
+ httplib_set_request_handler(ctx, "**.foo$", FooHandler, 0);
/* Add handler for /close extention */
- mg_set_request_handler(ctx, "/close", CloseHandler, 0);
+ httplib_set_request_handler(ctx, "/close", CloseHandler, 0);
/* Add handler for /form (serve a file outside the document root) */
- mg_set_request_handler(ctx,
- "/form",
- FileHandler,
- (void *)"../../test/form.html");
+ httplib_set_request_handler(ctx, "/form", FileHandler, (void *)"../../test/form.html");
/* Add handler for form data */
- mg_set_request_handler(ctx,
+ httplib_set_request_handler(ctx,
"/handle_form.embedded_c.example.callback",
FormHandler,
(void *)0);
/* Add a file upload handler for parsing files on the fly */
- mg_set_request_handler(ctx,
- "/on_the_fly_form",
- FileUploadForm,
- (void *)"/on_the_fly_form.md5.callback");
- mg_set_request_handler(ctx,
- "/on_the_fly_form.md5.callback",
- CheckSumHandler,
- (void *)0);
+ httplib_set_request_handler(ctx, "/on_the_fly_form", FileUploadForm, (void *)"/on_the_fly_form.md5.callback");
+ httplib_set_request_handler(ctx, "/on_the_fly_form.md5.callback", CheckSumHandler, (void *)0);
/* Add handler for /cookie example */
- mg_set_request_handler(ctx, "/cookie", CookieHandler, 0);
+ httplib_set_request_handler(ctx, "/cookie", CookieHandler, 0);
/* Add HTTP site to open a websocket connection */
- mg_set_request_handler(ctx, "/websocket", WebSocketStartHandler, 0);
+ httplib_set_request_handler(ctx, "/websocket", WebSocketStartHandler, 0);
#ifdef USE_WEBSOCKET
/* WS site for the websocket connection */
- mg_set_websocket_handler(ctx,
+ httplib_set_websocket_handler(ctx,
"/websocket",
WebSocketConnectHandler,
WebSocketReadyHandler,
@@ -850,7 +824,7 @@ main(int argc, char *argv[])
/* List all listening ports */
memset(ports, 0, sizeof(ports));
- port_cnt = mg_get_server_ports(ctx, 32, ports);
+ port_cnt = httplib_get_server_ports(ctx, 32, ports);
printf("\n%i listening ports:\n\n", port_cnt);
for (n = 0; n < port_cnt && n < 32; n++) {
@@ -899,7 +873,7 @@ main(int argc, char *argv[])
}
/* Stop the server */
- mg_stop(ctx);
+ httplib_stop(ctx);
printf("Server stopped.\n");
printf("Bye!\n");
diff --git a/examples/embedded_cpp/embedded_cpp.cpp b/examples/embedded_cpp/embedded_cpp.cpp
index 67d1e43d..f7640d12 100644
--- a/examples/embedded_cpp/embedded_cpp.cpp
+++ b/examples/embedded_cpp/embedded_cpp.cpp
@@ -23,30 +23,30 @@ class ExampleHandler : public CivetHandler
{
public:
bool
- handleGet(CivetServer *server, struct mg_connection *conn)
+ handleGet(CivetServer *server, struct httplib_connection *conn)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: "
"text/html\r\nConnection: close\r\n\r\n");
- mg_printf(conn, "\r\n");
- mg_printf(conn,
+ httplib_printf(conn, "\r\n");
+ httplib_printf(conn,
"This is an example text from a C++ handler \r\n");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the A handler click here
\r\n");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the A handler with a parameter "
"click here
\r\n");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the A/B handler click here
\r\n");
- mg_printf(conn,
+ httplib_printf(conn,
"To see a page from the *.foo handler click here
\r\n");
- mg_printf(conn,
+ httplib_printf(conn,
"To exit click here
\r\n",
EXIT_URI);
- mg_printf(conn, "\r\n");
+ httplib_printf(conn, "\r\n");
return true;
}
};
@@ -55,12 +55,12 @@ class ExitHandler : public CivetHandler
{
public:
bool
- handleGet(CivetServer *server, struct mg_connection *conn)
+ handleGet(CivetServer *server, struct httplib_connection *conn)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: "
"text/plain\r\nConnection: close\r\n\r\n");
- mg_printf(conn, "Bye!\n");
+ httplib_printf(conn, "Bye!\n");
exitNow = true;
return true;
}
@@ -72,31 +72,31 @@ class AHandler : public CivetHandler
bool
handleAll(const char *method,
CivetServer *server,
- struct mg_connection *conn)
+ struct httplib_connection *conn)
{
std::string s = "";
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: "
"text/html\r\nConnection: close\r\n\r\n");
- mg_printf(conn, "");
- mg_printf(conn, "This is the A handler for \"%s\" ! ", method);
+ httplib_printf(conn, "");
+ httplib_printf(conn, "This is the A handler for \"%s\" ! ", method);
if (CivetServer::getParam(conn, "param", s)) {
- mg_printf(conn, "param set to %s
", s.c_str());
+ httplib_printf(conn, "param set to %s
", s.c_str());
} else {
- mg_printf(conn, "param not set
");
+ httplib_printf(conn, "param not set
");
}
- mg_printf(conn, "\n");
+ httplib_printf(conn, "\n");
return true;
}
public:
bool
- handleGet(CivetServer *server, struct mg_connection *conn)
+ handleGet(CivetServer *server, struct httplib_connection *conn)
{
return handleAll("GET", server, conn);
}
bool
- handlePost(CivetServer *server, struct mg_connection *conn)
+ handlePost(CivetServer *server, struct httplib_connection *conn)
{
return handleAll("POST", server, conn);
}
@@ -106,14 +106,14 @@ class ABHandler : public CivetHandler
{
public:
bool
- handleGet(CivetServer *server, struct mg_connection *conn)
+ handleGet(CivetServer *server, struct httplib_connection *conn)
{
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: "
"text/html\r\nConnection: close\r\n\r\n");
- mg_printf(conn, "");
- mg_printf(conn, "This is the AB handler!!! ");
- mg_printf(conn, "\n");
+ httplib_printf(conn, "");
+ httplib_printf(conn, "This is the AB handler!!! ");
+ httplib_printf(conn, "\n");
return true;
}
};
@@ -122,68 +122,64 @@ class FooHandler : public CivetHandler
{
public:
bool
- handleGet(CivetServer *server, struct mg_connection *conn)
+ handleGet(CivetServer *server, struct httplib_connection *conn)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: "
"text/html\r\nConnection: close\r\n\r\n");
- mg_printf(conn, "\n");
- mg_printf(conn, "This is the Foo GET handler!!! \n");
- mg_printf(conn,
+ httplib_printf(conn, "\n");
+ httplib_printf(conn, "This is the Foo GET handler!!! \n");
+ httplib_printf(conn,
"The request was:
%s %s HTTP/%s \n",
req_info->request_method,
req_info->uri,
req_info->http_version);
- mg_printf(conn, "\n");
+ httplib_printf(conn, "\n");
return true;
}
bool
- handlePost(CivetServer *server, struct mg_connection *conn)
+ handlePost(CivetServer *server, struct httplib_connection *conn)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
long long rlen, wlen;
long long nlen = 0;
long long tlen = req_info->content_length;
char buf[1024];
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\nContent-Type: "
"text/html\r\nConnection: close\r\n\r\n");
- mg_printf(conn, "\n");
- mg_printf(conn, "This is the Foo POST handler!!! \n");
- mg_printf(conn,
+ httplib_printf(conn, "\n");
+ httplib_printf(conn, "This is the Foo POST handler!!! \n");
+ httplib_printf(conn,
"The request was:
%s %s HTTP/%s \n",
req_info->request_method,
req_info->uri,
req_info->http_version);
- mg_printf(conn, "Content Length: %li
\n", (long)tlen);
- mg_printf(conn, "\n");
+ httplib_printf(conn, "Content Length: %li
\n", (long)tlen);
+ httplib_printf(conn, "\n");
while (nlen < tlen) {
rlen = tlen - nlen;
if (rlen > sizeof(buf)) {
rlen = sizeof(buf);
}
- rlen = mg_read(conn, buf, (size_t)rlen);
- if (rlen <= 0) {
- break;
- }
- wlen = mg_write(conn, buf, (size_t)rlen);
- if (rlen != rlen) {
- break;
- }
+ rlen = httplib_read(conn, buf, (size_t)rlen);
+ if (rlen <= 0) break;
+ wlen = httplib_write(conn, buf, (size_t)rlen);
+ if (rlen != rlen) break;
nlen += wlen;
}
- mg_printf(conn, "\n \n");
- mg_printf(conn, "\n");
+ httplib_printf(conn, "\n \n");
+ httplib_printf(conn, "\n");
return true;
}
@@ -191,10 +187,10 @@ class FooHandler : public CivetHandler
#define fopen_recursive fopen
bool
- handlePut(CivetServer *server, struct mg_connection *conn)
+ handlePut(CivetServer *server, struct httplib_connection *conn)
{
- /* Handler may access the request info using mg_get_request_info */
- const struct mg_request_info *req_info = mg_get_request_info(conn);
+ /* Handler may access the request info using httplib_get_request_info */
+ const struct httplib_request_info *req_info = httplib_get_request_info(conn);
long long rlen, wlen;
long long nlen = 0;
long long tlen = req_info->content_length;
@@ -220,7 +216,7 @@ class FooHandler : public CivetHandler
if (rlen > sizeof(buf)) {
rlen = sizeof(buf);
}
- rlen = mg_read(conn, buf, (size_t)rlen);
+ rlen = httplib_read(conn, buf, (size_t)rlen);
if (rlen <= 0) {
fail = 1;
break;
@@ -236,12 +232,12 @@ class FooHandler : public CivetHandler
}
if (fail) {
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 409 Conflict\r\n"
"Content-Type: text/plain\r\n"
"Connection: close\r\n\r\n");
} else {
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 201 Created\r\n"
"Content-Type: text/plain\r\n"
"Connection: close\r\n\r\n");
diff --git a/examples/hello/hello.c b/examples/hello/hello.c
index 39253c1a..a77af2ec 100644
--- a/examples/hello/hello.c
+++ b/examples/hello/hello.c
@@ -3,9 +3,9 @@
#include "civetweb.h"
// This function will be called by civetweb on every new request.
-static int begin_request_handler(struct mg_connection *conn)
+static int begin_request_handler(struct httplib_connection *conn)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
char content[100];
// Prepare the message we're going to send
@@ -14,7 +14,7 @@ static int begin_request_handler(struct mg_connection *conn)
request_info->remote_port);
// Send HTTP reply to the client
- mg_printf(conn,
+ httplib_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: %d\r\n" // Always set Content-Length
@@ -29,8 +29,8 @@ static int begin_request_handler(struct mg_connection *conn)
int main(void)
{
- struct mg_context *ctx;
- struct mg_callbacks callbacks;
+ struct httplib_context *ctx;
+ struct httplib_callbacks callbacks;
// List of options. Last element must be NULL.
const char *options[] = {"listening_ports", "8080", NULL};
@@ -40,14 +40,14 @@ int main(void)
callbacks.begin_request = begin_request_handler;
// Start the web server.
- ctx = mg_start(&callbacks, NULL, options);
+ ctx = httplib_start(&callbacks, NULL, options);
// Wait until user hits "enter". Server is running in separate thread.
// Navigating to http://localhost:8080 will invoke begin_request_handler().
getchar();
// Stop the server.
- mg_stop(ctx);
+ httplib_stop(ctx);
return 0;
}
diff --git a/examples/post/post.c b/examples/post/post.c
index 3c5c68c8..e9faa2a2 100644
--- a/examples/post/post.c
+++ b/examples/post/post.c
@@ -10,22 +10,22 @@ static const char *html_form =
" "
"";
-static int begin_request_handler(struct mg_connection *conn)
+static int begin_request_handler(struct httplib_connection *conn)
{
- const struct mg_request_info *ri = mg_get_request_info(conn);
+ const struct httplib_request_info *ri = httplib_get_request_info(conn);
char post_data[1024], input1[sizeof(post_data)], input2[sizeof(post_data)];
int post_data_len;
if (!strcmp(ri->uri, "/handle_post_request")) {
// User has submitted a form, show submitted data and a variable value
- post_data_len = mg_read(conn, post_data, sizeof(post_data));
+ post_data_len = httplib_read(conn, post_data, sizeof(post_data));
// Parse form data. input1 and input2 are guaranteed to be NUL-terminated
- mg_get_var(post_data, post_data_len, "input_1", input1, sizeof(input1));
- mg_get_var(post_data, post_data_len, "input_2", input2, sizeof(input2));
+ httplib_get_var(post_data, post_data_len, "input_1", input1, sizeof(input1));
+ httplib_get_var(post_data, post_data_len, "input_2", input2, sizeof(input2));
// Send reply to the client, showing submitted form values.
- mg_printf(conn, "HTTP/1.0 200 OK\r\n"
+ httplib_printf(conn, "HTTP/1.0 200 OK\r\n"
"Content-Type: text/plain\r\n\r\n"
"Submitted data: [%.*s]\n"
"Submitted data length: %d bytes\n"
@@ -34,7 +34,7 @@ static int begin_request_handler(struct mg_connection *conn)
post_data_len, post_data, post_data_len, input1, input2);
} else {
// Show HTML form.
- mg_printf(conn, "HTTP/1.0 200 OK\r\n"
+ httplib_printf(conn, "HTTP/1.0 200 OK\r\n"
"Content-Length: %d\r\n"
"Content-Type: text/html\r\n\r\n%s",
(int) strlen(html_form), html_form);
@@ -44,15 +44,15 @@ static int begin_request_handler(struct mg_connection *conn)
int main(void)
{
- struct mg_context *ctx;
+ struct httplib_context *ctx;
const char *options[] = {"listening_ports", "8080", NULL};
- struct mg_callbacks callbacks;
+ struct httplib_callbacks callbacks;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = begin_request_handler;
- ctx = mg_start(&callbacks, NULL, options);
+ ctx = httplib_start(&callbacks, NULL, options);
getchar(); // Wait until user hits "enter"
- mg_stop(ctx);
+ httplib_stop(ctx);
return 0;
}
diff --git a/examples/upload/upload.c b/examples/upload/upload.c
index 56c4be4f..2108cccb 100644
--- a/examples/upload/upload.c
+++ b/examples/upload/upload.c
@@ -29,7 +29,7 @@ typedef __int64 int64_t;
/* callback: used to generate all content */
-static int begin_request_handler(struct mg_connection *conn)
+static int begin_request_handler(struct httplib_connection *conn)
{
const char * tempPath = ".";
#ifdef _WIN32
@@ -40,10 +40,10 @@ static int begin_request_handler(struct mg_connection *conn)
tempPath = "/tmp";
#endif
- if (!strcmp(mg_get_request_info(conn)->uri, "/handle_post_request")) {
+ if (!strcmp(httplib_get_request_info(conn)->uri, "/handle_post_request")) {
- mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n\r\n");
- mg_upload(conn, tempPath);
+ httplib_printf(conn, "%s", "HTTP/1.0 200 OK\r\n\r\n");
+ httplib_upload(conn, tempPath);
} else {
/* Show HTML form. */
/* See http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1 */
@@ -60,7 +60,7 @@ static int begin_request_handler(struct mg_connection *conn)
""
"";
- mg_printf(conn, "HTTP/1.0 200 OK\r\n"
+ httplib_printf(conn, "HTTP/1.0 200 OK\r\n"
"Content-Length: %d\r\n"
"Content-Type: text/html\r\n\r\n%s",
(int) strlen(html_form), html_form);
@@ -72,9 +72,9 @@ static int begin_request_handler(struct mg_connection *conn)
/* callback: called after uploading a file is completed */
-static void upload_handler(struct mg_connection *conn, const char *path)
+static void upload_handler(struct httplib_connection *conn, const char *path)
{
- mg_printf(conn, "Saved [%s]", path);
+ httplib_printf(conn, "Saved [%s]", path);
}
@@ -85,11 +85,11 @@ int main(void)
const char * PORT = "8080";
/* Startup options for the server */
- struct mg_context *ctx;
+ struct httplib_context *ctx;
const char *options[] = {
"listening_ports", PORT,
NULL};
- struct mg_callbacks callbacks;
+ struct httplib_callbacks callbacks;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = begin_request_handler;
@@ -100,11 +100,11 @@ int main(void)
printf("Open http://localhost:%s/ in your browser.\n\n", PORT);
/* Start the server */
- ctx = mg_start(&callbacks, NULL, options);
+ ctx = httplib_start(&callbacks, NULL, options);
/* Wait until thr user hits "enter", then stop the server */
getchar();
- mg_stop(ctx);
+ httplib_stop(ctx);
return 0;
}
diff --git a/examples/websocket/WebSockCallbacks.c b/examples/websocket/WebSockCallbacks.c
index b31bc956..d7e5a16b 100644
--- a/examples/websocket/WebSockCallbacks.c
+++ b/examples/websocket/WebSockCallbacks.c
@@ -11,49 +11,49 @@
#ifdef _WIN32
#include
-#define mg_sleep(x) Sleep(x)
+#define httplib_sleep(x) Sleep(x)
#else
#include
#include
-#define mg_sleep(x) usleep((x)*1000)
+#define httplib_sleep(x) usleep((x)*1000)
#endif
static void
-send_to_all_websockets(struct mg_context *ctx, const char *data, int data_len)
+send_to_all_websockets(struct httplib_context *ctx, const char *data, int data_len)
{
int i;
- tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+ tWebSockContext *ws_ctx = (tWebSockContext *)httplib_get_user_data(ctx);
- mg_lock_context(ctx);
+ httplib_lock_context(ctx);
for (i = 0; i < MAX_NUM_OF_WEBSOCKS; i++) {
if (ws_ctx->socketList[i]
&& (ws_ctx->socketList[i]->webSockState == 2)) {
- mg_websocket_write(ws_ctx->socketList[i]->conn,
+ httplib_websocket_write(ws_ctx->socketList[i]->conn,
WEBSOCKET_OPCODE_TEXT,
data,
data_len);
}
}
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
}
void
-websocket_ready_handler(struct mg_connection *conn, void *_ignored)
+websocket_ready_handler(struct httplib_connection *conn, void *_ignored)
{
int i;
- const struct mg_request_info *rq = mg_get_request_info(conn);
- struct mg_context *ctx = mg_get_context(conn);
- tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+ const struct httplib_request_info *rq = httplib_get_request_info(conn);
+ struct httplib_context *ctx = httplib_get_context(conn);
+ tWebSockContext *ws_ctx = (tWebSockContext *)httplib_get_user_data(ctx);
tWebSockInfo *wsock = malloc(sizeof(tWebSockInfo));
assert(wsock);
wsock->webSockState = 0;
- mg_set_user_connection_data(conn, wsock);
+ httplib_set_user_connection_data(conn, wsock);
- mg_lock_context(ctx);
+ httplib_lock_context(ctx);
for (i = 0; i < MAX_NUM_OF_WEBSOCKS; i++) {
if (0 == ws_ctx->socketList[i]) {
ws_ctx->socketList[i] = wsock;
@@ -65,7 +65,7 @@ websocket_ready_handler(struct mg_connection *conn, void *_ignored)
printf("\nNew websocket attached: %s:%u\n",
rq->remote_addr,
rq->remote_port);
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
}
@@ -84,33 +84,33 @@ websocket_done(tWebSockContext *ws_ctx, tWebSockInfo *wsock)
}
}
printf("\nClose websocket attached: %s:%u\n",
- mg_get_request_info(wsock->conn)->remote_addr,
- mg_get_request_info(wsock->conn)->remote_port);
+ httplib_get_request_info(wsock->conn)->remote_addr,
+ httplib_get_request_info(wsock->conn)->remote_port);
free(wsock);
}
}
int
-websocket_data_handler(struct mg_connection *conn,
+websocket_data_handler(struct httplib_connection *conn,
int flags,
char *data,
size_t data_len,
void *_ignored)
{
- const struct mg_request_info *rq = mg_get_request_info(conn);
+ const struct httplib_request_info *rq = httplib_get_request_info(conn);
tWebSockInfo *wsock = (tWebSockInfo *)rq->conn_data;
- struct mg_context *ctx = mg_get_context(conn);
- tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+ struct httplib_context *ctx = httplib_get_context(conn);
+ tWebSockContext *ws_ctx = (tWebSockContext *)httplib_get_user_data(ctx);
char msg[128];
- mg_lock_context(ctx);
+ httplib_lock_context(ctx);
if (flags == 136) {
// close websock
websocket_done(ws_ctx, wsock);
- mg_set_user_connection_data(conn, NULL);
- mg_unlock_context(ctx);
+ httplib_set_user_connection_data(conn, NULL);
+ httplib_unlock_context(ctx);
return 1;
}
if (((data_len >= 5) && (data_len < 100) && (flags == 129))
@@ -127,42 +127,42 @@ websocket_data_handler(struct mg_connection *conn,
if (gid > 0 && chk != NULL && *chk == 0) {
wsock->webSockState = 2;
}
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
return 1;
}
// chat message
if ((wsock->webSockState == 2) && (!memcmp(data, "msg ", 4))) {
send_to_all_websockets(ctx, data, data_len);
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
return 1;
}
}
// keep alive
if ((data_len == 4) && !memcmp(data, "ping", 4)) {
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
return 1;
}
- mg_unlock_context(ctx);
+ httplib_unlock_context(ctx);
return 0;
}
void
-connection_close_handler(const struct mg_connection *conn, void *_ignored)
+connection_close_handler(const struct httplib_connection *conn, void *_ignored)
{
- const struct mg_request_info *rq = mg_get_request_info(conn);
+ const struct httplib_request_info *rq = httplib_get_request_info(conn);
tWebSockInfo *wsock = (tWebSockInfo *)rq->conn_data;
- struct mg_context *ctx = mg_get_context(conn);
- tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+ struct httplib_context *ctx = httplib_get_context(conn);
+ tWebSockContext *ws_ctx = (tWebSockContext *)httplib_get_user_data(ctx);
- mg_lock_context(ctx);
+ httplib_lock_context(ctx);
websocket_done(ws_ctx, wsock);
- mg_set_user_connection_data(conn, NULL);
- mg_unlock_context(ctx);
+ httplib_set_user_connection_data(conn, NULL);
+ httplib_unlock_context(ctx);
}
@@ -171,8 +171,8 @@ eventMain(void *arg)
{
char msg[256];
- struct mg_context *ctx = (struct mg_context *)arg;
- tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+ struct httplib_context *ctx = (struct httplib_context *)arg;
+ tWebSockContext *ws_ctx = (tWebSockContext *)httplib_get_user_data(ctx);
ws_ctx->runLoop = 1;
while (ws_ctx->runLoop) {
@@ -181,7 +181,7 @@ eventMain(void *arg)
strftime(msg, sizeof(msg), "title %c", timestr);
send_to_all_websockets(ctx, msg, strlen(msg));
- mg_sleep(1000);
+ httplib_sleep(1000);
}
return NULL;
@@ -189,7 +189,7 @@ eventMain(void *arg)
void
-websock_send_broadcast(struct mg_context *ctx, const char *data, int data_len)
+websock_send_broadcast(struct httplib_context *ctx, const char *data, int data_len)
{
char buffer[260];
@@ -204,22 +204,22 @@ websock_send_broadcast(struct mg_context *ctx, const char *data, int data_len)
void
-websock_init_lib(const struct mg_context *ctx)
+websock_init_lib(const struct httplib_context *ctx)
{
- tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+ tWebSockContext *ws_ctx = (tWebSockContext *)httplib_get_user_data(ctx);
memset(ws_ctx, 0, sizeof(*ws_ctx));
- /* todo: use mg_start_thread_id instead of mg_start_thread */
- mg_start_thread(eventMain, (void *)ctx);
+ /* todo: use httplib_start_thread_id instead of httplib_start_thread */
+ httplib_start_thread(eventMain, (void *)ctx);
}
void
-websock_exit_lib(const struct mg_context *ctx)
+websock_exit_lib(const struct httplib_context *ctx)
{
- tWebSockContext *ws_ctx = (tWebSockContext *)mg_get_user_data(ctx);
+ tWebSockContext *ws_ctx = (tWebSockContext *)httplib_get_user_data(ctx);
ws_ctx->runLoop = 0;
/* todo: wait for the thread instead of a timeout */
- mg_sleep(2000);
+ httplib_sleep(2000);
}
diff --git a/examples/websocket/WebSockCallbacks.h b/examples/websocket/WebSockCallbacks.h
index f44821da..bfa08bd7 100644
--- a/examples/websocket/WebSockCallbacks.h
+++ b/examples/websocket/WebSockCallbacks.h
@@ -11,7 +11,7 @@ extern "C" {
typedef struct tWebSockInfo {
int webSockState;
unsigned long initId;
- struct mg_connection *conn;
+ struct httplib_connection *conn;
} tWebSockInfo;
#define MAX_NUM_OF_WEBSOCKS (256)
@@ -22,23 +22,19 @@ typedef struct tWebSockContext {
} tWebSockContext;
-void websock_init_lib(const struct mg_context *ctx);
-void websock_exit_lib(const struct mg_context *ctx);
+void websock_init_lib(const struct httplib_context *ctx);
+void websock_exit_lib(const struct httplib_context *ctx);
void
-websock_send_broadcast(struct mg_context *ctx, const char *data, int data_len);
+websock_send_broadcast(struct httplib_context *ctx, const char *data, int data_len);
-void websocket_ready_handler(struct mg_connection *conn, void *_ignored);
-int websocket_data_handler(struct mg_connection *conn,
- int flags,
- char *data,
- size_t data_len,
- void *_ignored);
-void connection_close_handler(const struct mg_connection *conn, void *_ignored);
+void websocket_ready_handler(struct httplib_connection *conn, void *_ignored);
+int websocket_data_handler(struct httplib_connection *conn, int flags, char *data, size_t data_len, void *_ignored);
+void connection_close_handler(const struct httplib_connection *conn, void *_ignored);
#ifdef __cplusplus
}
#endif
-#endif
\ No newline at end of file
+#endif
diff --git a/examples/websocket/websocket.c b/examples/websocket/websocket.c
index 3aadf98b..babc52a8 100644
--- a/examples/websocket/websocket.c
+++ b/examples/websocket/websocket.c
@@ -13,8 +13,8 @@
int
main(void)
{
- struct mg_context *ctx = 0;
- struct mg_callbacks callback_funcs = {0};
+ struct httplib_context *ctx = 0;
+ struct httplib_callbacks callback_funcs = {0};
tWebSockContext ws_ctx;
char inbuf[4];
@@ -35,9 +35,9 @@ main(void)
callback_funcs.init_context = websock_init_lib;
callback_funcs.exit_context = websock_exit_lib;
- ctx = mg_start(&callback_funcs, &ws_ctx, server_options);
+ ctx = httplib_start(&callback_funcs, &ws_ctx, server_options);
- mg_set_websocket_handler(ctx,
+ httplib_set_websocket_handler(ctx,
"/MyWebSock",
NULL,
websocket_ready_handler,
@@ -46,7 +46,7 @@ main(void)
NULL);
printf("Connect to localhost:%s/websock.htm\n",
- mg_get_option(ctx, "listening_ports"));
+ httplib_get_option(ctx, "listening_ports"));
puts("Enter an (ASCII) character or * to exit:");
for (;;) {
@@ -59,7 +59,7 @@ main(void)
websock_send_broadcast(ctx, inbuf, 1);
}
- mg_stop(ctx);
+ httplib_stop(ctx);
return 0;
}
diff --git a/examples/websocket_client/websocket_client.c b/examples/websocket_client/websocket_client.c
index c7bef625..bb2554bf 100644
--- a/examples/websocket_client/websocket_client.c
+++ b/examples/websocket_client/websocket_client.c
@@ -40,10 +40,10 @@ const size_t websocket_goodbye_msg_len = 14 /* strlen(websocket_goodbye_msg) */;
/*************************************************************************************/
#if defined(MG_LEGACY_INTERFACE)
int
-websock_server_connect(const struct mg_connection *conn)
+websock_server_connect(const struct httplib_connection *conn)
#else
int
-websocket_server_connect(const struct mg_connection *conn, void *_ignored)
+websocket_server_connect(const struct httplib_connection *conn, void *_ignored)
#endif
{
printf("Server: Websocket connected\n");
@@ -53,33 +53,33 @@ websocket_server_connect(const struct mg_connection *conn, void *_ignored)
#if defined(MG_LEGACY_INTERFACE)
void
-websocket_server_ready(struct mg_connection *conn)
+websocket_server_ready(struct httplib_connection *conn)
#else
void
-websocket_server_ready(struct mg_connection *conn, void *_ignored)
+websocket_server_ready(struct httplib_connection *conn, void *_ignored)
#endif
{
printf("Server: Websocket ready\n");
/* Send websocket welcome message */
- mg_lock_connection(conn);
- mg_websocket_write(conn,
+ httplib_lock_connection(conn);
+ httplib_websocket_write(conn,
WEBSOCKET_OPCODE_TEXT,
websocket_welcome_msg,
websocket_welcome_msg_len);
- mg_unlock_connection(conn);
+ httplib_unlock_connection(conn);
}
#if defined(MG_LEGACY_INTERFACE)
int
-websocket_server_data(struct mg_connection *conn,
+websocket_server_data(struct httplib_connection *conn,
int bits,
char *data,
size_t data_len)
#else
int
-websocket_server_data(struct mg_connection *conn,
+websocket_server_data(struct httplib_connection *conn,
int bits,
char *data,
size_t data_len,
@@ -93,20 +93,20 @@ websocket_server_data(struct mg_connection *conn,
if (data_len < 3 || 0 != memcmp(data, "bye", 3)) {
/* Send websocket acknowledge message */
- mg_lock_connection(conn);
- mg_websocket_write(conn,
+ httplib_lock_connection(conn);
+ httplib_websocket_write(conn,
WEBSOCKET_OPCODE_TEXT,
websocket_acknowledge_msg,
websocket_acknowledge_msg_len);
- mg_unlock_connection(conn);
+ httplib_unlock_connection(conn);
} else {
/* Send websocket acknowledge message */
- mg_lock_connection(conn);
- mg_websocket_write(conn,
+ httplib_lock_connection(conn);
+ httplib_websocket_write(conn,
WEBSOCKET_OPCODE_TEXT,
websocket_goodbye_msg,
websocket_goodbye_msg_len);
- mg_unlock_connection(conn);
+ httplib_unlock_connection(conn);
}
return 1; /* return 1 to keep the connetion open */
@@ -115,10 +115,10 @@ websocket_server_data(struct mg_connection *conn,
#if defined(MG_LEGACY_INTERFACE)
void
-websocket_server_connection_close(const struct mg_connection *conn)
+websocket_server_connection_close(const struct httplib_connection *conn)
#else
void
-websocket_server_connection_close(const struct mg_connection *conn,
+websocket_server_connection_close(const struct httplib_connection *conn,
void *_ignored)
#endif
{
@@ -129,7 +129,7 @@ websocket_server_connection_close(const struct mg_connection *conn,
}
-struct mg_context *
+struct httplib_context *
start_websocket_server()
{
const char *options[] = {"document_root",
@@ -141,8 +141,8 @@ start_websocket_server()
"request_timeout_ms",
"5000",
0};
- struct mg_callbacks callbacks;
- struct mg_context *ctx;
+ struct httplib_callbacks callbacks;
+ struct httplib_context *ctx;
memset(&callbacks, 0, sizeof(callbacks));
@@ -153,12 +153,12 @@ start_websocket_server()
callbacks.websocket_data = websocket_server_data;
callbacks.connection_close = websocket_server_connection_close;
- ctx = mg_start(&callbacks, 0, options);
+ ctx = httplib_start(&callbacks, 0, options);
#else
/* New interface: */
- ctx = mg_start(&callbacks, 0, options);
+ ctx = httplib_start(&callbacks, 0, options);
- mg_set_websocket_handler(ctx,
+ httplib_set_websocket_handler(ctx,
"/websocket",
websocket_server_connect,
websocket_server_ready,
@@ -181,15 +181,11 @@ struct tclient_data {
};
static int
-websocket_client_data_handler(struct mg_connection *conn,
- int flags,
- char *data,
- size_t data_len,
- void *user_data)
-{
- struct mg_context *ctx = mg_get_context(conn);
+websocket_client_data_handler(struct httplib_connection *conn, int flags, char *data, size_t data_len, void *user_data) {
+
+ struct httplib_context *ctx = httplib_get_context(conn);
struct tclient_data *pclient_data =
- (struct tclient_data *)mg_get_user_data(ctx);
+ (struct tclient_data *)httplib_get_user_data(ctx);
printf("Client received data from server: ");
fwrite(data, 1, data_len, stdout);
@@ -204,12 +200,12 @@ websocket_client_data_handler(struct mg_connection *conn,
}
static void
-websocket_client_close_handler(const struct mg_connection *conn,
+websocket_client_close_handler(const struct httplib_connection *conn,
void *user_data)
{
- struct mg_context *ctx = mg_get_context(conn);
+ struct httplib_context *ctx = httplib_get_context(conn);
struct tclient_data *pclient_data =
- (struct tclient_data *)mg_get_user_data(ctx);
+ (struct tclient_data *)httplib_get_user_data(ctx);
printf("Client: Close handler\n");
pclient_data->closed++;
@@ -219,13 +215,13 @@ websocket_client_close_handler(const struct mg_connection *conn,
int
main(int argc, char *argv[])
{
- struct mg_context *ctx = NULL;
+ struct httplib_context *ctx = NULL;
struct tclient_data client1_data = {NULL, 0, 0};
struct tclient_data client2_data = {NULL, 0, 0};
struct tclient_data client3_data = {NULL, 0, 0};
- struct mg_connection *newconn1 = NULL;
- struct mg_connection *newconn2 = NULL;
- struct mg_connection *newconn3 = NULL;
+ struct httplib_connection *newconn1 = NULL;
+ struct httplib_connection *newconn2 = NULL;
+ struct httplib_connection *newconn3 = NULL;
char ebuf[100] = {0};
assert(websocket_welcome_msg_len == strlen(websocket_welcome_msg));
@@ -236,7 +232,7 @@ main(int argc, char *argv[])
printf("Server init\n\n");
/* Then connect a first client */
- newconn1 = mg_connect_websocket_client("localhost",
+ newconn1 = httplib_connect_websocket_client("localhost",
atoi(PORT),
0,
ebuf,
@@ -266,7 +262,7 @@ main(int argc, char *argv[])
client1_data.data = NULL;
client1_data.len = 0;
- mg_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "data1", 5);
+ httplib_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "data1", 5);
sleep(1); /* Should get the acknowledge message */
assert(client1_data.closed == 0);
@@ -283,7 +279,7 @@ main(int argc, char *argv[])
client1_data.len = 0;
/* Now connect a second client */
- newconn2 = mg_connect_websocket_client("localhost",
+ newconn2 = httplib_connect_websocket_client("localhost",
atoi(PORT),
0,
ebuf,
@@ -313,7 +309,7 @@ main(int argc, char *argv[])
client2_data.data = NULL;
client2_data.len = 0;
- mg_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "data2", 5);
+ httplib_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "data2", 5);
sleep(1); /* Should get the acknowledge message */
assert(client1_data.closed == 0);
@@ -329,7 +325,7 @@ main(int argc, char *argv[])
client1_data.data = NULL;
client1_data.len = 0;
- mg_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "bye", 3);
+ httplib_websocket_client_write(newconn1, WEBSOCKET_OPCODE_TEXT, "bye", 3);
sleep(1); /* Should get the goodbye message */
assert(client1_data.closed == 0);
@@ -345,7 +341,7 @@ main(int argc, char *argv[])
client1_data.data = NULL;
client1_data.len = 0;
- mg_close_connection(newconn1);
+ httplib_close_connection(newconn1);
sleep(1); /* Won't get any message */
assert(client1_data.closed == 1);
@@ -355,7 +351,7 @@ main(int argc, char *argv[])
assert(client2_data.data == NULL);
assert(client2_data.len == 0);
- mg_websocket_client_write(newconn2, WEBSOCKET_OPCODE_TEXT, "bye", 3);
+ httplib_websocket_client_write(newconn2, WEBSOCKET_OPCODE_TEXT, "bye", 3);
sleep(1); /* Should get the goodbye message */
assert(client1_data.closed == 1);
@@ -371,7 +367,7 @@ main(int argc, char *argv[])
client2_data.data = NULL;
client2_data.len = 0;
- mg_close_connection(newconn2);
+ httplib_close_connection(newconn2);
sleep(1); /* Won't get any message */
assert(client1_data.closed == 1);
@@ -382,7 +378,7 @@ main(int argc, char *argv[])
assert(client2_data.len == 0);
/* Connect client 3 */
- newconn3 = mg_connect_websocket_client("localhost",
+ newconn3 = httplib_connect_websocket_client("localhost",
atoi(PORT),
0,
ebuf,
@@ -410,7 +406,7 @@ main(int argc, char *argv[])
client3_data.data = NULL;
client3_data.len = 0;
- mg_stop(ctx);
+ httplib_stop(ctx);
printf("Server shutdown\n");
sleep(10);
diff --git a/examples/ws_server/ws_server.c b/examples/ws_server/ws_server.c
index 575a26a6..fb5ffad9 100644
--- a/examples/ws_server/ws_server.c
+++ b/examples/ws_server/ws_server.c
@@ -12,7 +12,7 @@
// simple structure for keeping track of websocket connection
struct ws_connection {
- struct mg_connection *conn;
+ struct httplib_connection *conn;
int update;
int closing;
};
@@ -36,7 +36,7 @@ static struct ws_connection ws_conn[CONNECTIONS];
static void *ws_server_thread(void *parm)
{
int wsd = (long)parm;
- struct mg_connection *conn = ws_conn[wsd].conn;
+ struct httplib_connection *conn = ws_conn[wsd].conn;
int timer = 0;
char tstr[32];
int i;
@@ -61,7 +61,7 @@ static void *ws_server_thread(void *parm)
meter[i].value = meter[i].limit;
sprintf(tstr, "meter%d:%d,%d", i+1,
meter[i].value, meter[i].limit);
- mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, tstr, strlen(tstr));
+ httplib_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, tstr, strlen(tstr));
}
/* While the connection is open, send periodic updates */
@@ -83,7 +83,7 @@ static void *ws_server_thread(void *parm)
if (!ws_conn[wsd].closing) {
sprintf(tstr, "meter%d:%d,%d", i+1,
meter[i].value, meter[i].limit);
- mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, tstr, strlen(tstr));
+ httplib_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, tstr, strlen(tstr));
}
}
}
@@ -91,7 +91,7 @@ static void *ws_server_thread(void *parm)
/* Send periodic PING to assure websocket remains connected, except if we are closing */
if (timer%100 == 0 && !ws_conn[wsd].closing)
- mg_websocket_write(conn, WEBSOCKET_OPCODE_PING, NULL, 0);
+ httplib_websocket_write(conn, WEBSOCKET_OPCODE_PING, NULL, 0);
}
fprintf(stderr, "ws_server_thread %d exiting\n", wsd);
@@ -108,7 +108,7 @@ static void *ws_server_thread(void *parm)
// On new client connection, find next available server connection and store
// new connection information. If no more server connections are available
// tell civetweb to not accept the client request.
-static int websocket_connect_handler(const struct mg_connection *conn)
+static int websocket_connect_handler(const struct httplib_connection *conn)
{
int i;
@@ -117,7 +117,7 @@ static int websocket_connect_handler(const struct mg_connection *conn)
for(i=0; i < CONNECTIONS; ++i) {
if (ws_conn[i].conn == NULL) {
fprintf(stderr, "...prep for server %d\n", i);
- ws_conn[i].conn = (struct mg_connection *)conn;
+ ws_conn[i].conn = (struct httplib_connection *)conn;
ws_conn[i].closing = 0;
ws_conn[i].update = 0;
break;
@@ -133,7 +133,7 @@ static int websocket_connect_handler(const struct mg_connection *conn)
// websocket_ready_handler()
// Once websocket negotiation is complete, start a server for the connection
-static void websocket_ready_handler(struct mg_connection *conn)
+static void websocket_ready_handler(struct httplib_connection *conn)
{
int i;
@@ -142,7 +142,7 @@ static void websocket_ready_handler(struct mg_connection *conn)
for(i=0; i < CONNECTIONS; ++i) {
if (ws_conn[i].conn == conn) {
fprintf(stderr, "...start server %d\n", i);
- mg_start_thread(ws_server_thread, (void *)(long)i);
+ httplib_start_thread(ws_server_thread, (void *)(long)i);
break;
}
}
@@ -150,7 +150,7 @@ static void websocket_ready_handler(struct mg_connection *conn)
// websocket_close_handler()
// When websocket is closed, tell the associated server to shut down
-static void websocket_close_handler(struct mg_connection *conn)
+static void websocket_close_handler(struct httplib_connection *conn)
{
int i;
@@ -168,8 +168,7 @@ static void websocket_close_handler(struct mg_connection *conn)
// flags: first byte of websocket frame, see websocket RFC,
// http://tools.ietf.org/html/rfc6455, section 5.2
// data, data_len: payload data. Mask, if any, is already applied.
-static int websocket_data_handler(struct mg_connection *conn, int flags,
- char *data, size_t data_len)
+static int websocket_data_handler(struct httplib_connection *conn, int flags, char *data, size_t data_len)
{
int i;
int wsd;
@@ -198,12 +197,12 @@ static int websocket_data_handler(struct mg_connection *conn, int flags,
/* turn on updates */
ws_conn[wsd].update = 1;
/* echo back */
- mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, data, data_len);
+ httplib_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, data, data_len);
} else if (strncmp("update off", data, data_len)== 0) {
/* turn off updates */
ws_conn[wsd].update = 0;
/* echo back */
- mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, data, data_len);
+ httplib_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, data, data_len);
}
break;
case WEBSOCKET_OPCODE_BINARY:
@@ -213,14 +212,14 @@ static int websocket_data_handler(struct mg_connection *conn, int flags,
fprintf(stderr, "CLOSE...\n");
/* If client initiated close, respond with close message in acknowlegement */
if (!ws_conn[wsd].closing) {
- mg_websocket_write(conn, WEBSOCKET_OPCODE_CONNECTION_CLOSE, data, data_len);
+ httplib_websocket_write(conn, WEBSOCKET_OPCODE_CONNECTION_CLOSE, data, data_len);
ws_conn[wsd].closing = 1; /* we should not send addional messages when close requested/acknowledged */
}
return 0; /* time to close the connection */
break;
case WEBSOCKET_OPCODE_PING:
/* client sent PING, respond with PONG */
- mg_websocket_write(conn, WEBSOCKET_OPCODE_PONG, data, data_len);
+ httplib_websocket_write(conn, WEBSOCKET_OPCODE_PONG, data, data_len);
break;
case WEBSOCKET_OPCODE_PONG:
/* received PONG to our PING, no action */
@@ -238,8 +237,8 @@ static int websocket_data_handler(struct mg_connection *conn, int flags,
int main(void)
{
char server_name[40];
- struct mg_context *ctx;
- struct mg_callbacks callbacks;
+ struct httplib_context *ctx;
+ struct httplib_callbacks callbacks;
const char *options[] = {
"listening_ports", "8080",
"document_root", "docroot",
@@ -247,9 +246,7 @@ int main(void)
};
/* get simple greeting for the web server */
- snprintf(server_name, sizeof(server_name),
- "Civetweb websocket server v. %s",
- mg_version());
+ snprintf(server_name, sizeof(server_name), "Civetweb websocket server v. %s", httplib_version());
memset(&callbacks, 0, sizeof(callbacks));
callbacks.websocket_connect = websocket_connect_handler;
@@ -257,15 +254,15 @@ int main(void)
callbacks.websocket_data = websocket_data_handler;
callbacks.connection_close = websocket_close_handler;
- ctx = mg_start(&callbacks, NULL, options);
+ ctx = httplib_start(&callbacks, NULL, options);
/* show the greeting and some basic information */
printf("%s started on port(s) %s with web root [%s]\n",
- server_name, mg_get_option(ctx, "listening_ports"),
- mg_get_option(ctx, "document_root"));
+ server_name, httplib_get_option(ctx, "listening_ports"),
+ httplib_get_option(ctx, "document_root"));
getchar(); // Wait until user hits "enter"
- mg_stop(ctx);
+ httplib_stop(ctx);
return 0;
}
diff --git a/src/LibHTTPServer.cpp b/src/LibHTTPServer.cpp
index d7d38a5e..283a4995 100644
--- a/src/LibHTTPServer.cpp
+++ b/src/LibHTTPServer.cpp
@@ -16,7 +16,7 @@
#endif
bool
-CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn)
+CivetHandler::handleGet(CivetServer *server, struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -24,7 +24,7 @@ CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn)
}
bool
-CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn)
+CivetHandler::handlePost(CivetServer *server, struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -32,7 +32,7 @@ CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn)
}
bool
-CivetHandler::handleHead(CivetServer *server, struct mg_connection *conn)
+CivetHandler::handleHead(CivetServer *server, struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -40,7 +40,7 @@ CivetHandler::handleHead(CivetServer *server, struct mg_connection *conn)
}
bool
-CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn)
+CivetHandler::handlePut(CivetServer *server, struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -48,7 +48,7 @@ CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn)
}
bool
-CivetHandler::handlePatch(CivetServer *server, struct mg_connection *conn)
+CivetHandler::handlePatch(CivetServer *server, struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -56,7 +56,7 @@ CivetHandler::handlePatch(CivetServer *server, struct mg_connection *conn)
}
bool
-CivetHandler::handleDelete(CivetServer *server, struct mg_connection *conn)
+CivetHandler::handleDelete(CivetServer *server, struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -64,7 +64,7 @@ CivetHandler::handleDelete(CivetServer *server, struct mg_connection *conn)
}
bool
-CivetHandler::handleOptions(CivetServer *server, struct mg_connection *conn)
+CivetHandler::handleOptions(CivetServer *server, struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -72,8 +72,7 @@ CivetHandler::handleOptions(CivetServer *server, struct mg_connection *conn)
}
bool
-CivetWebSocketHandler::handleConnection(CivetServer *server,
- const struct mg_connection *conn)
+CivetWebSocketHandler::handleConnection(CivetServer *server, const struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -81,8 +80,7 @@ CivetWebSocketHandler::handleConnection(CivetServer *server,
}
void
-CivetWebSocketHandler::handleReadyState(CivetServer *server,
- struct mg_connection *conn)
+CivetWebSocketHandler::handleReadyState(CivetServer *server, struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -90,11 +88,7 @@ CivetWebSocketHandler::handleReadyState(CivetServer *server,
}
bool
-CivetWebSocketHandler::handleData(CivetServer *server,
- struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len)
+CivetWebSocketHandler::handleData(CivetServer *server, struct httplib_connection *conn, int bits, char *data, size_t data_len)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -105,8 +99,7 @@ CivetWebSocketHandler::handleData(CivetServer *server,
}
void
-CivetWebSocketHandler::handleClose(CivetServer *server,
- const struct mg_connection *conn)
+CivetWebSocketHandler::handleClose(CivetServer *server, const struct httplib_connection *conn)
{
UNUSED_PARAMETER(server);
UNUSED_PARAMETER(conn);
@@ -114,9 +107,9 @@ CivetWebSocketHandler::handleClose(CivetServer *server,
}
int
-CivetServer::requestHandler(struct mg_connection *conn, void *cbdata)
+CivetServer::requestHandler(struct httplib_connection *conn, void *cbdata)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
assert(request_info != NULL);
CivetServer *me = (CivetServer *)(request_info->user_data);
assert(me != NULL);
@@ -125,9 +118,9 @@ CivetServer::requestHandler(struct mg_connection *conn, void *cbdata)
if (me->context == NULL)
return 0;
- mg_lock_context(me->context);
+ httplib_lock_context(me->context);
me->connections[conn] = CivetConnection();
- mg_unlock_context(me->context);
+ httplib_unlock_context(me->context);
CivetHandler *handler = (CivetHandler *)cbdata;
@@ -153,9 +146,9 @@ CivetServer::requestHandler(struct mg_connection *conn, void *cbdata)
}
int
-CivetServer::authHandler(struct mg_connection *conn, void *cbdata)
+CivetServer::authHandler(struct httplib_connection *conn, void *cbdata)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
assert(request_info != NULL);
CivetServer *me = (CivetServer *)(request_info->user_data);
assert(me != NULL);
@@ -164,9 +157,9 @@ CivetServer::authHandler(struct mg_connection *conn, void *cbdata)
if (me->context == NULL)
return 0;
- mg_lock_context(me->context);
+ httplib_lock_context(me->context);
me->connections[conn] = CivetConnection();
- mg_unlock_context(me->context);
+ httplib_unlock_context(me->context);
CivetAuthHandler *handler = (CivetAuthHandler *)cbdata;
@@ -178,10 +171,9 @@ CivetServer::authHandler(struct mg_connection *conn, void *cbdata)
}
int
-CivetServer::webSocketConnectionHandler(const struct mg_connection *conn,
- void *cbdata)
+CivetServer::webSocketConnectionHandler(const struct httplib_connection *conn, void *cbdata)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
assert(request_info != NULL);
CivetServer *me = (CivetServer *)(request_info->user_data);
assert(me != NULL);
@@ -200,9 +192,9 @@ CivetServer::webSocketConnectionHandler(const struct mg_connection *conn,
}
void
-CivetServer::webSocketReadyHandler(struct mg_connection *conn, void *cbdata)
+CivetServer::webSocketReadyHandler(struct httplib_connection *conn, void *cbdata)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
assert(request_info != NULL);
CivetServer *me = (CivetServer *)(request_info->user_data);
assert(me != NULL);
@@ -219,13 +211,9 @@ CivetServer::webSocketReadyHandler(struct mg_connection *conn, void *cbdata)
}
int
-CivetServer::webSocketDataHandler(struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len,
- void *cbdata)
+CivetServer::webSocketDataHandler(struct httplib_connection *conn, int bits, char *data, size_t data_len, void *cbdata)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
assert(request_info != NULL);
CivetServer *me = (CivetServer *)(request_info->user_data);
assert(me != NULL);
@@ -244,10 +232,9 @@ CivetServer::webSocketDataHandler(struct mg_connection *conn,
}
void
-CivetServer::webSocketCloseHandler(const struct mg_connection *conn,
- void *cbdata)
+CivetServer::webSocketCloseHandler(const struct httplib_connection *conn, void *cbdata)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
assert(request_info != NULL);
CivetServer *me = (CivetServer *)(request_info->user_data);
assert(me != NULL);
@@ -281,7 +268,7 @@ CivetServer::CivetServer(const char **options,
userCloseHandler = NULL;
}
callbacks.connection_close = closeHandler;
- context = mg_start(&callbacks, this, options);
+ context = httplib_start(&callbacks, this, options);
if (context == NULL)
throw CivetException("null context when constructing CivetServer. "
"Possible problem binding to port.");
@@ -307,7 +294,7 @@ CivetServer::CivetServer(std::vector options,
}
pointers.push_back(0);
- context = mg_start(&callbacks, this, &pointers[0]);
+ context = httplib_start(&callbacks, this, &pointers[0]);
if (context == NULL)
throw CivetException("null context when constructing CivetServer. "
"Possible problem binding to port.");
@@ -319,9 +306,9 @@ CivetServer::~CivetServer()
}
void
-CivetServer::closeHandler(const struct mg_connection *conn)
+CivetServer::closeHandler(const struct httplib_connection *conn)
{
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
assert(request_info != NULL);
CivetServer *me = (CivetServer *)(request_info->user_data);
assert(me != NULL);
@@ -332,22 +319,22 @@ CivetServer::closeHandler(const struct mg_connection *conn)
if (me->userCloseHandler)
me->userCloseHandler(conn);
- mg_lock_context(me->context);
- me->connections.erase(const_cast(conn));
- mg_unlock_context(me->context);
+ httplib_lock_context(me->context);
+ me->connections.erase(const_cast(conn));
+ httplib_unlock_context(me->context);
}
void
CivetServer::addHandler(const std::string &uri, CivetHandler *handler)
{
- mg_set_request_handler(context, uri.c_str(), requestHandler, handler);
+ httplib_set_request_handler(context, uri.c_str(), requestHandler, handler);
}
void
CivetServer::addWebSocketHandler(const std::string &uri,
CivetWebSocketHandler *handler)
{
- mg_set_websocket_handler(context,
+ httplib_set_websocket_handler(context,
uri.c_str(),
webSocketConnectionHandler,
webSocketReadyHandler,
@@ -359,60 +346,55 @@ CivetServer::addWebSocketHandler(const std::string &uri,
void
CivetServer::addAuthHandler(const std::string &uri, CivetAuthHandler *handler)
{
- mg_set_auth_handler(context, uri.c_str(), authHandler, handler);
+ httplib_set_auth_handler(context, uri.c_str(), authHandler, handler);
}
void
CivetServer::removeHandler(const std::string &uri)
{
- mg_set_request_handler(context, uri.c_str(), NULL, NULL);
+ httplib_set_request_handler(context, uri.c_str(), NULL, NULL);
}
void
CivetServer::removeWebSocketHandler(const std::string &uri)
{
- mg_set_websocket_handler(
- context, uri.c_str(), NULL, NULL, NULL, NULL, NULL);
+ httplib_set_websocket_handler( context, uri.c_str(), NULL, NULL, NULL, NULL, NULL);
}
void
CivetServer::removeAuthHandler(const std::string &uri)
{
- mg_set_auth_handler(context, uri.c_str(), NULL, NULL);
+ httplib_set_auth_handler(context, uri.c_str(), NULL, NULL);
}
void
CivetServer::close()
{
if (context) {
- mg_stop(context);
+ httplib_stop(context);
context = 0;
}
}
int
-CivetServer::getCookie(struct mg_connection *conn,
+CivetServer::getCookie(struct httplib_connection *conn,
const std::string &cookieName,
std::string &cookieValue)
{
// Maximum cookie length as per microsoft is 4096.
// http://msdn.microsoft.com/en-us/library/ms178194.aspx
char _cookieValue[4096];
- const char *cookie = mg_get_header(conn, "Cookie");
- int lRead = mg_get_cookie(cookie,
- cookieName.c_str(),
- _cookieValue,
- sizeof(_cookieValue));
+ const char *cookie = httplib_get_header(conn, "Cookie");
+ int lRead = httplib_get_cookie(cookie, cookieName.c_str(), _cookieValue, sizeof(_cookieValue));
cookieValue.clear();
cookieValue.append(_cookieValue);
return lRead;
}
const char *
-CivetServer::getHeader(struct mg_connection *conn,
- const std::string &headerName)
-{
- return mg_get_header(conn, headerName.c_str());
+CivetServer::getHeader(struct httplib_connection *conn, const std::string &headerName) {
+
+ return httplib_get_header(conn, headerName.c_str());
}
void
@@ -450,25 +432,22 @@ CivetServer::urlDecode(const char *src,
}
bool
-CivetServer::getParam(struct mg_connection *conn,
- const char *name,
- std::string &dst,
- size_t occurrence)
+CivetServer::getParam(struct httplib_connection *conn, const char *name, std::string &dst, size_t occurrence)
{
const char *formParams = NULL;
- const struct mg_request_info *ri = mg_get_request_info(conn);
+ const struct httplib_request_info *ri = httplib_get_request_info(conn);
assert(ri != NULL);
CivetServer *me = (CivetServer *)(ri->user_data);
assert(me != NULL);
- mg_lock_context(me->context);
+ httplib_lock_context(me->context);
CivetConnection &conobj = me->connections[conn];
- mg_lock_connection(conn);
- mg_unlock_context(me->context);
+ httplib_lock_connection(conn);
+ httplib_unlock_context(me->context);
if (conobj.postData != NULL) {
formParams = conobj.postData;
} else {
- const char *con_len_str = mg_get_header(conn, "Content-Length");
+ const char *con_len_str = httplib_get_header(conn, "Content-Length");
if (con_len_str) {
unsigned long con_len = atoi(con_len_str);
if (con_len > 0) {
@@ -479,7 +458,7 @@ CivetServer::getParam(struct mg_connection *conn,
conobj.postData = (char *)malloc(con_len + 1);
if (conobj.postData != NULL) {
// malloc may fail for huge requests
- mg_read(conn, conobj.postData, con_len);
+ httplib_read(conn, conobj.postData, con_len);
conobj.postData[con_len] = 0;
formParams = conobj.postData;
conobj.postDataLen = con_len;
@@ -492,7 +471,7 @@ CivetServer::getParam(struct mg_connection *conn,
// query_string
formParams = ri->query_string;
}
- mg_unlock_connection(conn);
+ httplib_unlock_connection(conn);
if (formParams != NULL) {
return getParam(formParams, strlen(formParams), name, dst, occurrence);
@@ -521,7 +500,7 @@ CivetServer::getParam(const char *data,
// data is "var1=val1&var2=val2...". Find variable first
for (p = data; p + name_len < e; p++) {
if ((p == data || p[-1] == '&') && p[name_len] == '='
- && !mg_strncasecmp(name, p, name_len) && 0 == occurrence--) {
+ && !httplib_strncasecmp(name, p, name_len) && 0 == occurrence--) {
// Point p to variable value
p += name_len + 1;
@@ -576,7 +555,7 @@ CivetServer::getListeningPorts()
{
std::vector ports(10);
std::vector ssl(10);
- size_t size = mg_get_ports(context, ports.size(), &ports[0], &ssl[0]);
+ size_t size = httplib_get_ports(context, ports.size(), &ports[0], &ssl[0]);
ports.resize(size);
ssl.resize(size);
return ports;
diff --git a/src/httplib_accept_new_connection.c b/src/httplib_accept_new_connection.c
index 3ea0a38e..471d78ab 100644
--- a/src/httplib_accept_new_connection.c
+++ b/src/httplib_accept_new_connection.c
@@ -26,13 +26,13 @@
#include "httplib_ssl.h"
/*
- * void XX_httplib_accept_new_connection( const struct socket *lostener, struct mg_context *ctx );
+ * void XX_httplib_accept_new_connection( const struct socket *lostener, struct httplib_context *ctx );
*
* The function XX_httplib_accept_new_connection() is used to process new
* incoming connections to the server.
*/
-void XX_httplib_accept_new_connection( const struct socket *listener, struct mg_context *ctx ) {
+void XX_httplib_accept_new_connection( const struct socket *listener, struct httplib_context *ctx ) {
struct socket so;
char src_addr[IP_ADDR_STR_LEN];
@@ -46,7 +46,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct mg_
== INVALID_SOCKET) {
} else if (!XX_httplib_check_acl(ctx, ntohl(*(uint32_t *)&so.rsa.sin.sin_addr))) {
XX_httplib_sockaddr_to_string(src_addr, sizeof(src_addr), &so.rsa);
- mg_cry( XX_httplib_fc(ctx), "%s: %s is not allowed to connect", __func__, src_addr);
+ httplib_cry( XX_httplib_fc(ctx), "%s: %s is not allowed to connect", __func__, src_addr);
closesocket(so.sock);
so.sock = INVALID_SOCKET;
} else {
@@ -55,7 +55,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct mg_
so.is_ssl = listener->is_ssl;
so.ssl_redir = listener->ssl_redir;
if (getsockname(so.sock, &so.lsa.sa, &len) != 0) {
- mg_cry( XX_httplib_fc(ctx), "%s: getsockname() failed: %s", __func__, strerror(ERRNO));
+ httplib_cry( XX_httplib_fc(ctx), "%s: getsockname() failed: %s", __func__, strerror(ERRNO));
}
/* Set TCP keep-alive. This is needed because if HTTP-level
@@ -67,7 +67,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct mg_
* Thanks to Igor Klopov who suggested the patch. */
if (setsockopt(so.sock, SOL_SOCKET, SO_KEEPALIVE, (SOCK_OPT_TYPE)&on, sizeof(on)) != 0) {
- mg_cry( XX_httplib_fc(ctx), "%s: setsockopt(SOL_SOCKET SO_KEEPALIVE) failed: %s", __func__, strerror(ERRNO));
+ httplib_cry( XX_httplib_fc(ctx), "%s: setsockopt(SOL_SOCKET SO_KEEPALIVE) failed: %s", __func__, strerror(ERRNO));
}
/* Disable TCP Nagle's algorithm. Normally TCP packets are coalesced
@@ -80,7 +80,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct mg_
if ((ctx != NULL) && (ctx->config[CONFIG_TCP_NODELAY] != NULL)
&& (!strcmp(ctx->config[CONFIG_TCP_NODELAY], "1"))) {
if (XX_httplib_set_tcp_nodelay(so.sock, 1) != 0) {
- mg_cry( XX_httplib_fc(ctx), "%s: setsockopt(IPPROTO_TCP TCP_NODELAY) failed: %s", __func__, strerror(ERRNO));
+ httplib_cry( XX_httplib_fc(ctx), "%s: setsockopt(IPPROTO_TCP TCP_NODELAY) failed: %s", __func__, strerror(ERRNO));
}
}
diff --git a/src/httplib_addenv.c b/src/httplib_addenv.c
index ce4ce4ef..c8e6029e 100644
--- a/src/httplib_addenv.c
+++ b/src/httplib_addenv.c
@@ -59,7 +59,7 @@ void XX_httplib_addenv( struct cgi_environment *env, const char *fmt, ... ) {
added = (char *)XX_httplib_realloc(env->buf, n);
if (!added) {
/* Out of memory */
- mg_cry(env->conn, "%s: Cannot allocate memory for CGI variable [%s]", __func__, fmt);
+ httplib_cry(env->conn, "%s: Cannot allocate memory for CGI variable [%s]", __func__, fmt);
return;
}
env->buf = added;
@@ -90,7 +90,7 @@ void XX_httplib_addenv( struct cgi_environment *env, const char *fmt, ... ) {
/* Now update the variable index */
space = (env->varlen - env->varused);
if (space < 2) {
- mg_cry(env->conn, "%s: Cannot register CGI variable [%s]", __func__, fmt);
+ httplib_cry(env->conn, "%s: Cannot register CGI variable [%s]", __func__, fmt);
return;
}
diff --git a/src/httplib_authorize.c b/src/httplib_authorize.c
index f8070483..49986f48 100644
--- a/src/httplib_authorize.c
+++ b/src/httplib_authorize.c
@@ -25,7 +25,7 @@
#include "httplib_main.h"
/* Authorize against the opened passwords file. Return 1 if authorized. */
-int XX_httplib_authorize( struct mg_connection *conn, struct file *filep ) {
+int XX_httplib_authorize( struct httplib_connection *conn, struct file *filep ) {
struct read_auth_file_struct workdata;
char buf[MG_BUF_LEN];
diff --git a/src/httplib_check_acl.c b/src/httplib_check_acl.c
index eaab6487..2bb553b8 100644
--- a/src/httplib_check_acl.c
+++ b/src/httplib_check_acl.c
@@ -25,7 +25,7 @@
#include "httplib_main.h"
/*
- * int XX_httplib_check_acl( struct mg_context *ctx, uint32_t remote_ip );
+ * int XX_httplib_check_acl( struct httplib_context *ctx, uint32_t remote_ip );
*
* The function XX_httplib_check_acl() is used to check of the socket address
* of a connection is allowed according to the access control list. The
@@ -33,7 +33,7 @@
* allowed and 1 if the address is allowed.
*/
-int XX_httplib_check_acl( struct mg_context *ctx, uint32_t remote_ip ) {
+int XX_httplib_check_acl( struct httplib_context *ctx, uint32_t remote_ip ) {
int allowed;
int flag;
@@ -50,7 +50,7 @@ int XX_httplib_check_acl( struct mg_context *ctx, uint32_t remote_ip ) {
while ((list = XX_httplib_next_option(list, &vec, NULL)) != NULL) {
flag = vec.ptr[0];
if ((flag != '+' && flag != '-') || XX_httplib_parse_net(&vec.ptr[1], &net, &mask) == 0) {
- mg_cry( XX_httplib_fc(ctx), "%s: subnet must be [+|-]x.x.x.x[/x]", __func__);
+ httplib_cry( XX_httplib_fc(ctx), "%s: subnet must be [+|-]x.x.x.x[/x]", __func__);
return -1;
}
diff --git a/src/httplib_check_authorization.c b/src/httplib_check_authorization.c
index 0bf624ab..0450f8bc 100644
--- a/src/httplib_check_authorization.c
+++ b/src/httplib_check_authorization.c
@@ -26,7 +26,7 @@
#include "httplib_string.h"
/* Return 1 if request is authorised, 0 otherwise. */
-int XX_httplib_check_authorization( struct mg_connection *conn, const char *path ) {
+int XX_httplib_check_authorization( struct httplib_connection *conn, const char *path ) {
char fname[PATH_MAX];
struct vec uri_vec;
@@ -44,7 +44,7 @@ int XX_httplib_check_authorization( struct mg_connection *conn, const char *path
XX_httplib_snprintf(conn, &truncated, fname, sizeof(fname), "%.*s", (int)filename_vec.len, filename_vec.ptr);
if (truncated || !XX_httplib_fopen(conn, fname, "r", &file)) {
- mg_cry(conn, "%s: cannot open %s: %s", __func__, fname, strerror(errno));
+ httplib_cry(conn, "%s: cannot open %s: %s", __func__, fname, strerror(errno));
}
break;
}
diff --git a/src/httplib_check_feature.c b/src/httplib_check_feature.c
index f5c6bf4e..e0ddc083 100644
--- a/src/httplib_check_feature.c
+++ b/src/httplib_check_feature.c
@@ -25,13 +25,13 @@
#include "httplib_main.h"
/*
- * unsigned mg_check_feature( unsigned feature );
+ * unsigned httplib_check_feature( unsigned feature );
*
- * The function mg_check_feature returns an integer indicating if a specific
+ * The function httplib_check_feature returns an integer indicating if a specific
* functionality has been compiled in at compile time.
*/
-unsigned mg_check_feature( unsigned feature ) {
+unsigned httplib_check_feature( unsigned feature ) {
static const unsigned feature_set = 0
/* Set bits for available features according to API documentation.
@@ -71,4 +71,4 @@ unsigned mg_check_feature( unsigned feature ) {
;
return (feature & feature_set);
-} /* mg_check_feature */
+} /* httplib_check_feature */
diff --git a/src/httplib_check_password.c b/src/httplib_check_password.c
index 7b4737c6..cddd9974 100644
--- a/src/httplib_check_password.c
+++ b/src/httplib_check_password.c
@@ -36,9 +36,9 @@ int XX_httplib_check_password( const char *method, const char *ha1, const char *
/* NOTE(lsm): due to a bug in MSIE, we do not compare the URI */
if (strlen(response) != 32) return 0;
- mg_md5(ha2, method, ":", uri, NULL);
- mg_md5(expected_response, ha1, ":", nonce, ":", nc, ":", cnonce, ":", qop, ":", ha2, NULL);
+ httplib_md5(ha2, method, ":", uri, NULL);
+ httplib_md5(expected_response, ha1, ":", nonce, ":", nc, ":", cnonce, ":", qop, ":", ha2, NULL);
- return mg_strcasecmp(response, expected_response) == 0;
+ return httplib_strcasecmp(response, expected_response) == 0;
} /* XX_httplib_check_password */
diff --git a/src/httplib_close_all_listening_sockets.c b/src/httplib_close_all_listening_sockets.c
index c99b3cf8..27820c4d 100644
--- a/src/httplib_close_all_listening_sockets.c
+++ b/src/httplib_close_all_listening_sockets.c
@@ -26,13 +26,13 @@
#include "httplib_memory.h"
/*
- * void XX_httplib_close_all_listening_sockets( struct mg_context *ctx );
+ * void XX_httplib_close_all_listening_sockets( struct httplib_context *ctx );
*
* The function XX_httplib_close_all_listening_sockets() closes all listening
* sockets of a given context.
*/
-void XX_httplib_close_all_listening_sockets( struct mg_context *ctx ) {
+void XX_httplib_close_all_listening_sockets( struct httplib_context *ctx ) {
unsigned int i;
diff --git a/src/httplib_close_connection.c b/src/httplib_close_connection.c
index 6724c638..d5269a77 100644
--- a/src/httplib_close_connection.c
+++ b/src/httplib_close_connection.c
@@ -28,13 +28,13 @@
#include "httplib_ssl.h"
/*
- * void XX_httplib_close_connection( struct mg_connection *conn );
+ * void XX_httplib_close_connection( struct httplib_connection *conn );
*
* The function XX_httplib_close_connection() is the internal function which
* does the heavy lifting to close a connection.
*/
-void XX_httplib_close_connection( struct mg_connection *conn ) {
+void XX_httplib_close_connection( struct httplib_connection *conn ) {
if ( conn == NULL || conn->ctx == NULL ) return;
@@ -43,7 +43,7 @@ void XX_httplib_close_connection( struct mg_connection *conn ) {
conn->ctx->callbacks.connection_close(conn);
}
- mg_lock_connection( conn );
+ httplib_lock_connection( conn );
conn->must_close = 1;
@@ -65,23 +65,23 @@ void XX_httplib_close_connection( struct mg_connection *conn ) {
conn->client.sock = INVALID_SOCKET;
}
- mg_unlock_connection( conn );
+ httplib_unlock_connection( conn );
} /* XX_httplib_close_connection */
/*
- * void mg_close_connection( struct mg_connection *conn );
+ * void httplib_close_connection( struct httplib_connection *conn );
*
- * The function mg_close_connection() closes the connection passed as a
+ * The function httplib_close_connection() closes the connection passed as a
* parameter to this function. The function does not return a success or
* failure value.
*/
-void mg_close_connection( struct mg_connection *conn ) {
+void httplib_close_connection( struct httplib_connection *conn ) {
- struct mg_context *client_ctx = NULL;
+ struct httplib_context *client_ctx = NULL;
unsigned int i;
if ( conn == NULL ) return;
@@ -109,4 +109,4 @@ void mg_close_connection( struct mg_connection *conn ) {
XX_httplib_free(conn);
}
-} /* mg_close_connection */
+} /* httplib_close_connection */
diff --git a/src/httplib_close_socket_gracefully.c b/src/httplib_close_socket_gracefully.c
index 89958fc4..8dfd4670 100644
--- a/src/httplib_close_socket_gracefully.c
+++ b/src/httplib_close_socket_gracefully.c
@@ -25,13 +25,13 @@
#include "httplib_main.h"
/*
- * void XX_httplib_close_socket_gracefully( struct mg_connection *conn );
+ * void XX_httplib_close_socket_gracefully( struct httplib_connection *conn );
*
* The function XX_httplib_close_socket_gracefully() closes a socket in a
* graceful way.
*/
-void XX_httplib_close_socket_gracefully( struct mg_connection *conn ) {
+void XX_httplib_close_socket_gracefully( struct httplib_connection *conn ) {
#if defined(_WIN32)
char buf[MG_BUF_LEN];
@@ -54,7 +54,7 @@ void XX_httplib_close_socket_gracefully( struct mg_connection *conn ) {
/* Socket already closed by client/peer, close socket without linger */
} else {
if (setsockopt(conn->client.sock, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(linger)) != 0) {
- mg_cry(conn, "%s: setsockopt(SOL_SOCKET SO_LINGER) failed: %s", __func__, strerror(ERRNO));
+ httplib_cry(conn, "%s: setsockopt(SOL_SOCKET SO_LINGER) failed: %s", __func__, strerror(ERRNO));
}
}
diff --git a/src/httplib_config_options.c b/src/httplib_config_options.c
index 777019c0..04091416 100644
--- a/src/httplib_config_options.c
+++ b/src/httplib_config_options.c
@@ -25,7 +25,7 @@
#include "httplib_main.h"
/* Config option name, config types, default value */
-struct mg_option XX_httplib_config_options[] = {
+struct httplib_option XX_httplib_config_options[] = {
{ "cgi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.cgi$|**.pl$|**.php$" },
{ "cgi_environment", CONFIG_TYPE_STRING, NULL },
{ "put_delete_auth_file", CONFIG_TYPE_FILE, NULL },
@@ -81,4 +81,4 @@ struct mg_option XX_httplib_config_options[] = {
* Check if the XX_httplib_config_options and the corresponding enum have
* compatible sizes
*/
-mg_static_assert((sizeof(XX_httplib_config_options) / sizeof(XX_httplib_config_options[0])) == (NUM_OPTIONS + 1), "XX_httplib_config_options and enum not sync");
+httplib_static_assert((sizeof(XX_httplib_config_options) / sizeof(XX_httplib_config_options[0])) == (NUM_OPTIONS + 1), "XX_httplib_config_options and enum not sync");
diff --git a/src/httplib_connect_client.c b/src/httplib_connect_client.c
index f0b23e91..85a9a57c 100644
--- a/src/httplib_connect_client.c
+++ b/src/httplib_connect_client.c
@@ -28,65 +28,64 @@
#include "httplib_ssl.h"
#include "httplib_string.h"
-static struct mg_connection * mg_connect_client_impl( const struct mg_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len );
+static struct httplib_connection * httplib_connect_client_impl( const struct httplib_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len );
/*
- * struct mg_connection *mg_connect_client_secure( const struct mg_client_options *client options, char *error buffer, size_t error_buffer_size );
+ * struct httplib_connection *httplib_connect_client_secure( const struct httplib_client_options *client options, char *error buffer, size_t error_buffer_size );
*
- * The function mg_connect_client_secure() creates a secure connection as a
+ * The function httplib_connect_client_secure() creates a secure connection as a
* client to a remote server and returns a pointer to the connection
* information, or NULL if an error occured.
*/
-CIVETWEB_API struct mg_connection *mg_connect_client_secure( const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size ) {
+CIVETWEB_API struct httplib_connection *httplib_connect_client_secure( const struct httplib_client_options *client_options, char *error_buffer, size_t error_buffer_size ) {
- return mg_connect_client_impl( client_options, 1, error_buffer, error_buffer_size );
+ return httplib_connect_client_impl( client_options, 1, error_buffer, error_buffer_size );
-} /* mg_connect_client_secure */
+} /* httplib_connect_client_secure */
/*
- * struct mg_connection *mg_connect_client( const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size );
+ * struct httplib_connection *httplib_connect_client( const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size );
*
- * The function mg_connect_client() connects to a remote server as a client
+ * The function httplib_connect_client() connects to a remote server as a client
* with the options of the connection provided as parameters.
*/
-struct mg_connection * mg_connect_client( const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size ) {
+struct httplib_connection * httplib_connect_client( const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size ) {
- struct mg_client_options opts;
+ struct httplib_client_options opts;
memset( &opts, 0, sizeof(opts) );
opts.host = host;
opts.port = port;
- return mg_connect_client_impl( &opts, use_ssl, error_buffer, error_buffer_size );
+ return httplib_connect_client_impl( &opts, use_ssl, error_buffer, error_buffer_size );
-} /* mg_connect_client */
+} /* httplib_connect_client */
/*
- * static struct mg_connection *mg_connect_client_impl( const struct mg_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len );
+ * static struct httplib_connection *httplib_connect_client_impl( const struct httplib_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len );
*
- * The function mg_connect_client_impl() is the background function doing the
+ * The function httplib_connect_client_impl() is the background function doing the
* heavy lifting to make connections as a client to remote servers.
*/
-static struct mg_connection *mg_connect_client_impl( const struct mg_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len ) {
+static struct httplib_connection *httplib_connect_client_impl( const struct httplib_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len ) {
- static struct mg_context fake_ctx;
- struct mg_connection *conn = NULL;
+ static struct httplib_context fake_ctx;
+ struct httplib_connection *conn = NULL;
SOCKET sock;
union usa sa;
if (!XX_httplib_connect_socket(&fake_ctx, client_options->host, client_options->port, use_ssl, ebuf, ebuf_len, &sock, &sa)) {
;
- } else if ((conn = (struct mg_connection *)
- XX_httplib_calloc(1, sizeof(*conn) + MAX_REQUEST_SIZE)) == NULL) {
+ } else if ((conn = (struct httplib_connection *) XX_httplib_calloc(1, sizeof(*conn) + MAX_REQUEST_SIZE)) == NULL) {
XX_httplib_snprintf(NULL, NULL, ebuf, ebuf_len, "calloc(): %s", strerror(ERRNO));
closesocket(sock);
#ifndef NO_SSL
@@ -114,7 +113,7 @@ static struct mg_connection *mg_connect_client_impl( const struct mg_client_opti
conn->client.sock = sock;
conn->client.lsa = sa;
- if (getsockname(sock, psa, &len) != 0) mg_cry(conn, "%s: getsockname() failed: %s", __func__, strerror(ERRNO));
+ if (getsockname(sock, psa, &len) != 0) httplib_cry(conn, "%s: getsockname() failed: %s", __func__, strerror(ERRNO));
conn->client.is_ssl = use_ssl ? 1 : 0;
pthread_mutex_init(&conn->mutex, &XX_httplib_pthread_mutex_attr);
@@ -161,4 +160,4 @@ static struct mg_connection *mg_connect_client_impl( const struct mg_client_opti
return conn;
-} /* mg_connect_client_impl */
+} /* httplib_connect_client_impl */
diff --git a/src/httplib_connect_socket.c b/src/httplib_connect_socket.c
index 9e3329d0..c2b03e15 100644
--- a/src/httplib_connect_socket.c
+++ b/src/httplib_connect_socket.c
@@ -36,7 +36,7 @@
* may not be null for this function to succeed.
*/
-int XX_httplib_connect_socket( struct mg_context *ctx, const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, SOCKET *sock, union usa *sa ) {
+int XX_httplib_connect_socket( struct httplib_context *ctx, const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, SOCKET *sock, union usa *sa ) {
int ip_ver = 0;
diff --git a/src/httplib_connect_websocket_client.c b/src/httplib_connect_websocket_client.c
index 7e45ab21..5cfc288c 100644
--- a/src/httplib_connect_websocket_client.c
+++ b/src/httplib_connect_websocket_client.c
@@ -27,28 +27,28 @@
#include "httplib_string.h"
/*
- * struct mg_connection *mg_connect_websocket_client();
+ * struct httplib_connection *httplib_connect_websocket_client();
*
- * The function mg_connect_websocket_client() connects as a client to a
+ * The function httplib_connect_websocket_client() connects as a client to a
* websocket on another server. If this succeeds a connection pointer is
* returned, otherwise NULL.
*/
-struct mg_connection *mg_connect_websocket_client(const char *host,
+struct httplib_connection *httplib_connect_websocket_client(const char *host,
int port,
int use_ssl,
char *error_buffer,
size_t error_buffer_size,
const char *path,
const char *origin,
- mg_websocket_data_handler data_func,
- mg_websocket_close_handler close_func,
+ httplib_websocket_data_handler data_func,
+ httplib_websocket_close_handler close_func,
void *user_data)
{
- struct mg_connection *conn = NULL;
+ struct httplib_connection *conn = NULL;
#if defined(USE_WEBSOCKET)
- struct mg_context *newctx = NULL;
+ struct httplib_context *newctx = NULL;
struct websocket_client_thread_data *thread_data;
static const char *magic = "x3JJHMbDL1EzLkh9GBhXDw==";
static const char *handshake_req;
@@ -73,7 +73,7 @@ struct mg_connection *mg_connect_websocket_client(const char *host,
}
/* Establish the client connection and request upgrade */
- conn = mg_download(host, port, use_ssl, error_buffer, error_buffer_size, handshake_req, path, host, magic, origin);
+ conn = httplib_download(host, port, use_ssl, error_buffer, error_buffer_size, handshake_req, path, host, magic, origin);
/* Connection object will be null if something goes wrong */
if (conn == NULL || (strcmp(conn->request_info.request_uri, "101") != 0)) {
@@ -89,10 +89,10 @@ struct mg_connection *mg_connect_websocket_client(const char *host,
return conn;
}
- /* For client connections, mg_context is fake. Since we need to set a
+ /* For client connections, httplib_context is fake. Since we need to set a
* callback function, we need to create a copy and modify it. */
- newctx = (struct mg_context *)XX_httplib_malloc(sizeof(struct mg_context));
- memcpy(newctx, conn->ctx, sizeof(struct mg_context));
+ newctx = (struct httplib_context *)XX_httplib_malloc(sizeof(struct httplib_context));
+ memcpy(newctx, conn->ctx, sizeof(struct httplib_context));
newctx->user_data = user_data;
newctx->context_type = 2; /* client context type */
newctx->cfg_worker_threads = 1; /* one worker thread will be created */
@@ -105,7 +105,7 @@ struct mg_connection *mg_connect_websocket_client(const char *host,
thread_data->callback_data = NULL;
/* Start a thread to read the websocket client connection
- * This thread will automatically stop when mg_disconnect is
+ * This thread will automatically stop when httplib_disconnect is
* called on the client connection */
if (XX_httplib_start_thread_with_id( XX_httplib_websocket_client_thread, (void *)thread_data, newctx->workerthreadids) != 0) {
@@ -131,4 +131,4 @@ struct mg_connection *mg_connect_websocket_client(const char *host,
return conn;
-} /* mg_connect_websocket_client */
+} /* httplib_connect_websocket_client */
diff --git a/src/httplib_consume_socket.c b/src/httplib_consume_socket.c
index d58131bd..5b8a5c3c 100644
--- a/src/httplib_consume_socket.c
+++ b/src/httplib_consume_socket.c
@@ -26,7 +26,7 @@
#include "httplib_pthread.h"
/*
- * int XX_httplib_consume_socket( struct mg_context *ctx, struct socket *sp, int thread_index );
+ * int XX_httplib_consume_socket( struct httplib_context *ctx, struct socket *sp, int thread_index );
*
* The function XX_httplib_consume_socket() takes an accepted socket from the
* queue for further processing.
@@ -34,7 +34,7 @@
#if defined(ALTERNATIVE_QUEUE)
-int XX_httplib_consume_socket( struct mg_context *ctx, struct socket *sp, int thread_index ) {
+int XX_httplib_consume_socket( struct httplib_context *ctx, struct socket *sp, int thread_index ) {
ctx->client_socks[thread_index].in_use = 0;
event_wait(ctx->client_wait_events[thread_index]);
@@ -47,7 +47,7 @@ int XX_httplib_consume_socket( struct mg_context *ctx, struct socket *sp, int th
#else /* ALTERNATIVE_QUEUE */
/* Worker threads take accepted socket from the queue */
-int XX_httplib_consume_socket( struct mg_context *ctx, struct socket *sp, int thread_index ) {
+int XX_httplib_consume_socket( struct httplib_context *ctx, struct socket *sp, int thread_index ) {
#define QUEUE_SIZE(ctx) ((int)(ARRAY_SIZE(ctx->queue)))
diff --git a/src/httplib_cry.c b/src/httplib_cry.c
index a7795879..4b10d995 100644
--- a/src/httplib_cry.c
+++ b/src/httplib_cry.c
@@ -26,7 +26,7 @@
#include "httplib_ssl.h"
/* Print error message to the opened error log stream. */
-void mg_cry(const struct mg_connection *conn, const char *fmt, ...) {
+void httplib_cry(const struct httplib_connection *conn, const char *fmt, ...) {
char buf[MG_BUF_LEN];
char src_addr[IP_ADDR_STR_LEN];
@@ -82,4 +82,4 @@ void mg_cry(const struct mg_connection *conn, const char *fmt, ...) {
}
}
-} /* mg_cry */
+} /* httplib_cry */
diff --git a/src/httplib_delete_file.c b/src/httplib_delete_file.c
index 1a07c684..311b6895 100644
--- a/src/httplib_delete_file.c
+++ b/src/httplib_delete_file.c
@@ -25,7 +25,7 @@
#include "httplib_main.h"
/*
- * void XX_httplib_delete_file( struct mg_connection *conn, const char *path );
+ * void XX_httplib_delete_file( struct httplib_connection *conn, const char *path );
*
* The function XX_httplib_delete_file() deletes a file after a request over a
* connection.
@@ -33,7 +33,7 @@
#if !defined(NO_FILES)
-void XX_httplib_delete_file( struct mg_connection *conn, const char *path ) {
+void XX_httplib_delete_file( struct httplib_connection *conn, const char *path ) {
struct de de;
diff --git a/src/httplib_discard_unread_request_data.c b/src/httplib_discard_unread_request_data.c
index e777b8ed..e6627f15 100644
--- a/src/httplib_discard_unread_request_data.c
+++ b/src/httplib_discard_unread_request_data.c
@@ -24,7 +24,7 @@
#include "httplib_main.h"
-void XX_httplib_discard_unread_request_data( struct mg_connection *conn ) {
+void XX_httplib_discard_unread_request_data( struct httplib_connection *conn ) {
char buf[MG_BUF_LEN];
size_t to_read;
@@ -40,10 +40,8 @@ void XX_httplib_discard_unread_request_data( struct mg_connection *conn ) {
/* Chunked encoding: 1=chunk not read completely, 2=chunk read
* completely */
while (conn->is_chunked == 1) {
- nread = mg_read(conn, buf, to_read);
- if (nread <= 0) {
- break;
- }
+ nread = httplib_read(conn, buf, to_read);
+ if (nread <= 0) break;
}
} else {
@@ -54,7 +52,7 @@ void XX_httplib_discard_unread_request_data( struct mg_connection *conn ) {
to_read = (size_t)(conn->content_len - conn->consumed_content);
}
- nread = mg_read(conn, buf, to_read);
+ nread = httplib_read(conn, buf, to_read);
if (nread <= 0) break;
}
}
diff --git a/src/httplib_download.c b/src/httplib_download.c
index ddfb70c4..f0f0666c 100644
--- a/src/httplib_download.c
+++ b/src/httplib_download.c
@@ -26,15 +26,15 @@
#include "httplib_string.h"
/*
- * struct mg_connection *mg_download();
+ * struct httplib_connection *httplib_download();
*
- * The function mg_download() is used to download a file from a remote location
+ * The function httplib_download() is used to download a file from a remote location
* and returns a pointer to the connection on success, or NULL on error.
*/
-struct mg_connection * mg_download( const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, const char *fmt, ... ) {
+struct httplib_connection * httplib_download( const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, const char *fmt, ... ) {
- struct mg_connection *conn;
+ struct httplib_connection *conn;
va_list ap;
int i;
int reqerr;
@@ -43,7 +43,7 @@ struct mg_connection * mg_download( const char *host, int port, int use_ssl, cha
ebuf[0] = '\0';
/* open a connection */
- conn = mg_connect_client(host, port, use_ssl, ebuf, ebuf_len);
+ conn = httplib_connect_client(host, port, use_ssl, ebuf, ebuf_len);
if (conn != NULL) {
i = XX_httplib_vprintf(conn, fmt, ap);
@@ -60,11 +60,11 @@ struct mg_connection * mg_download( const char *host, int port, int use_ssl, cha
/* if an error occured, close the connection */
if (ebuf[0] != '\0' && conn != NULL) {
- mg_close_connection(conn);
+ httplib_close_connection(conn);
conn = NULL;
}
va_end(ap);
return conn;
-} /* mg_download */
+} /* httplib_download */
diff --git a/src/httplib_fc.c b/src/httplib_fc.c
index f9d37408..c7bc62c7 100644
--- a/src/httplib_fc.c
+++ b/src/httplib_fc.c
@@ -26,9 +26,9 @@
/* Return fake connection structure. Used for logging, if connection
* is not applicable at the moment of logging. */
-struct mg_connection *XX_httplib_fc( struct mg_context *ctx ) {
+struct httplib_connection *XX_httplib_fc( struct httplib_context *ctx ) {
- static struct mg_connection fake_connection;
+ static struct httplib_connection fake_connection;
fake_connection.ctx = ctx;
return &fake_connection;
diff --git a/src/httplib_fclose_on_exec.c b/src/httplib_fclose_on_exec.c
index 1be69608..2180dae6 100644
--- a/src/httplib_fclose_on_exec.c
+++ b/src/httplib_fclose_on_exec.c
@@ -24,14 +24,14 @@
#include "httplib_main.h"
-void XX_httplib_fclose_on_exec( struct file *filep, struct mg_connection *conn ) {
+void XX_httplib_fclose_on_exec( struct file *filep, struct httplib_connection *conn ) {
if (filep != NULL && filep->fp != NULL) {
#ifdef _WIN32
(void)conn; /* Unused. */
#else
if (fcntl(fileno(filep->fp), F_SETFD, FD_CLOEXEC) != 0) {
- mg_cry(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO));
+ httplib_cry(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO));
}
#endif
}
diff --git a/src/httplib_fopen.c b/src/httplib_fopen.c
index 8a3fffda..07ddb662 100644
--- a/src/httplib_fopen.c
+++ b/src/httplib_fopen.c
@@ -29,7 +29,7 @@
* The input parameter mode is the same as for fopen.
* Either fp or membuf will be set in the output struct filep.
* The function returns 1 on success, 0 on error. */
-int XX_httplib_fopen( const struct mg_connection *conn, const char *path, const char *mode, struct file *filep ) {
+int XX_httplib_fopen( const struct httplib_connection *conn, const char *path, const char *mode, struct file *filep ) {
struct stat st;
diff --git a/src/httplib_forward_body_data.c b/src/httplib_forward_body_data.c
index 6073e054..55078e4b 100644
--- a/src/httplib_forward_body_data.c
+++ b/src/httplib_forward_body_data.c
@@ -25,14 +25,14 @@
#include "httplib_main.h"
/*
- * int XX_httplib_forward_body_data( struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl );
+ * int XX_httplib_forward_body_data( struct httplib_connection *conn, FILE *fp, SOCKET sock, SSL *ssl );
*
* The function XX_httplib_forward_body_data() forwards body data to the
* client.
*/
#if !defined(NO_CGI) || !defined(NO_FILES)
-int XX_httplib_forward_body_data( struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl ) {
+int XX_httplib_forward_body_data( struct httplib_connection *conn, FILE *fp, SOCKET sock, SSL *ssl ) {
const char *expect;
const char *body;
@@ -43,12 +43,12 @@ int XX_httplib_forward_body_data( struct mg_connection *conn, FILE *fp, SOCKET s
int64_t buffered_len;
double timeout = -1.0;
- if (!conn) { return 0; }
+ if ( conn == NULL ) return 0;
if (conn->ctx->config[REQUEST_TIMEOUT]) {
timeout = atoi(conn->ctx->config[REQUEST_TIMEOUT]) / 1000.0;
}
- expect = mg_get_header(conn, "Expect");
+ expect = httplib_get_header(conn, "Expect");
/* assert(fp != NULL); */
if (!fp) {
XX_httplib_send_http_error(conn, 500, "%s", "Error: NULL File");
@@ -59,12 +59,12 @@ int XX_httplib_forward_body_data( struct mg_connection *conn, FILE *fp, SOCKET s
/* Content length is not specified by the client. */
XX_httplib_send_http_error(conn, 411, "%s", "Error: Client did not specify content length");
} else if ((expect != NULL)
- && (mg_strcasecmp(expect, "100-continue") != 0)) {
+ && (httplib_strcasecmp(expect, "100-continue") != 0)) {
/* Client sent an "Expect: xyz" header and xyz is not 100-continue. */
XX_httplib_send_http_error(conn, 417, "Error: Can not fulfill expectation %s", expect);
} else {
if (expect != NULL) {
- (void)mg_printf(conn, "%s", "HTTP/1.1 100 Continue\r\n\r\n");
+ (void)httplib_printf(conn, "%s", "HTTP/1.1 100 Continue\r\n\r\n");
conn->status_code = 100;
} else conn->status_code = 200;
diff --git a/src/httplib_free_context.c b/src/httplib_free_context.c
index b0341d76..e8cd3a50 100644
--- a/src/httplib_free_context.c
+++ b/src/httplib_free_context.c
@@ -29,16 +29,16 @@
#include "httplib_utils.h"
/*
- * void XX_httplib_free_context( struct mg_context *ctx );
+ * void XX_httplib_free_context( struct httplib_context *ctx );
*
* The function XX_httplib_free_context() is used to free the resources
* associated with a context.
*/
-void XX_httplib_free_context( struct mg_context *ctx ) {
+void XX_httplib_free_context( struct httplib_context *ctx ) {
int i;
- struct mg_handler_info *tmp_rh;
+ struct httplib_handler_info *tmp_rh;
if ( ctx == NULL ) return;
diff --git a/src/httplib_get_builtin_mime_type.c b/src/httplib_get_builtin_mime_type.c
index 2e87e6c6..9f2e5380 100644
--- a/src/httplib_get_builtin_mime_type.c
+++ b/src/httplib_get_builtin_mime_type.c
@@ -570,14 +570,14 @@ const char *httplib_get_builtin_mime_type( const char *path ) {
while ( eind-start > 1 ) {
midden = (start+eind) >> 1;
- retval = mg_strcasecmp( ext, builtin_mime_types[midden].extension );
+ retval = httplib_strcasecmp( ext, builtin_mime_types[midden].extension );
if ( retval == 0 ) return builtin_mime_types[midden].mime_type;
else if ( retval < 0 ) eind = midden;
else start = midden;
}
- if ( ! mg_strcasecmp( ext, builtin_mime_types[start].extension ) ) return builtin_mime_types[start].mime_type;
+ if ( ! httplib_strcasecmp( ext, builtin_mime_types[start].extension ) ) return builtin_mime_types[start].mime_type;
return "text/plain";
diff --git a/src/httplib_get_context.c b/src/httplib_get_context.c
index d0b97f12..96b1cf3f 100644
--- a/src/httplib_get_context.c
+++ b/src/httplib_get_context.c
@@ -24,8 +24,8 @@
#include "httplib_main.h"
-struct mg_context * mg_get_context(const struct mg_connection *conn) {
+struct httplib_context * httplib_get_context(const struct httplib_connection *conn) {
- return (conn == NULL) ? (struct mg_context *)NULL : (conn->ctx);
+ return (conn == NULL) ? (struct httplib_context *)NULL : (conn->ctx);
-} /* mg_get_context */
+} /* httplib_get_context */
diff --git a/src/httplib_get_cookie.c b/src/httplib_get_cookie.c
index 4db4b89a..7465cc63 100644
--- a/src/httplib_get_cookie.c
+++ b/src/httplib_get_cookie.c
@@ -26,7 +26,7 @@
#include "httplib_string.h"
/* HCP24: some changes to compare hole var_name */
-int mg_get_cookie(const char *cookie_header, const char *var_name, char *dst, size_t dst_size) {
+int httplib_get_cookie(const char *cookie_header, const char *var_name, char *dst, size_t dst_size) {
const char *s;
const char *p;
@@ -64,4 +64,4 @@ int mg_get_cookie(const char *cookie_header, const char *var_name, char *dst, si
}
return len;
-} /* mg_get_cookie */
+} /* httplib_get_cookie */
diff --git a/src/httplib_get_first_ssl_listener_index.c b/src/httplib_get_first_ssl_listener_index.c
index 3465af09..a9efe16c 100644
--- a/src/httplib_get_first_ssl_listener_index.c
+++ b/src/httplib_get_first_ssl_listener_index.c
@@ -26,13 +26,13 @@
#include "httplib_ssl.h"
/*
- * int XX_httplib_get_first_ssl_listener_index( const struct mg_context *ctx );
+ * int XX_httplib_get_first_ssl_listener_index( const struct httplib_context *ctx );
*
* The function XX_httplib_get_first_ssl_listener_index() returns the first
* index of a listening socket where SSL encryption is active.
*/
-int XX_httplib_get_first_ssl_listener_index( const struct mg_context *ctx ) {
+int XX_httplib_get_first_ssl_listener_index( const struct httplib_context *ctx ) {
unsigned int i;
int idx;
diff --git a/src/httplib_get_header.c b/src/httplib_get_header.c
index 805a130a..9a449023 100644
--- a/src/httplib_get_header.c
+++ b/src/httplib_get_header.c
@@ -25,12 +25,12 @@
#include "httplib_main.h"
/* Return HTTP header value, or NULL if not found. */
-const char *XX_httplib_get_header( const struct mg_request_info *ri, const char *name ) {
+const char *XX_httplib_get_header( const struct httplib_request_info *ri, const char *name ) {
int i;
if (ri) {
for (i = 0; i < ri->num_headers; i++) {
- if (!mg_strcasecmp(name, ri->http_headers[i].name)) return ri->http_headers[i].value;
+ if (!httplib_strcasecmp(name, ri->http_headers[i].name)) return ri->http_headers[i].value;
}
}
@@ -39,10 +39,10 @@ const char *XX_httplib_get_header( const struct mg_request_info *ri, const char
} /* XX_httplib_get_header */
-const char *mg_get_header( const struct mg_connection *conn, const char *name ) {
+const char *httplib_get_header( const struct httplib_connection *conn, const char *name ) {
if ( conn == NULL ) return NULL;
return XX_httplib_get_header( & conn->request_info, name );
-} /* mg_get_header */
+} /* httplib_get_header */
diff --git a/src/httplib_get_mime_type.c b/src/httplib_get_mime_type.c
index 019c6b2e..54b7af87 100644
--- a/src/httplib_get_mime_type.c
+++ b/src/httplib_get_mime_type.c
@@ -26,7 +26,7 @@
/* Look at the "path" extension and figure what mime type it has.
* Store mime type in the vector. */
-void XX_httplib_get_mime_type( struct mg_context *ctx, const char *path, struct vec *vec ) {
+void XX_httplib_get_mime_type( struct httplib_context *ctx, const char *path, struct vec *vec ) {
struct vec ext_vec;
struct vec mime_vec;
@@ -44,7 +44,7 @@ void XX_httplib_get_mime_type( struct mg_context *ctx, const char *path, struct
while ((list = XX_httplib_next_option(list, &ext_vec, &mime_vec)) != NULL) {
/* ext now points to the path suffix */
ext = path + path_len - ext_vec.len;
- if (mg_strncasecmp(ext, ext_vec.ptr, ext_vec.len) == 0) {
+ if (httplib_strncasecmp(ext, ext_vec.ptr, ext_vec.len) == 0) {
*vec = mime_vec;
return;
}
diff --git a/src/httplib_get_option.c b/src/httplib_get_option.c
index be10201e..55d727d0 100644
--- a/src/httplib_get_option.c
+++ b/src/httplib_get_option.c
@@ -24,7 +24,7 @@
#include "httplib_main.h"
-const char *mg_get_option(const struct mg_context *ctx, const char *name) {
+const char *httplib_get_option(const struct httplib_context *ctx, const char *name) {
int i;
@@ -32,4 +32,4 @@ const char *mg_get_option(const struct mg_context *ctx, const char *name) {
else if ( ctx == NULL || ctx->config[i] == NULL ) return "";
else return ctx->config[i];
-} /* mg_get_option */
+} /* httplib_get_option */
diff --git a/src/httplib_get_rel_url_at_current_server.c b/src/httplib_get_rel_url_at_current_server.c
index 47ff5512..b6da00fb 100644
--- a/src/httplib_get_rel_url_at_current_server.c
+++ b/src/httplib_get_rel_url_at_current_server.c
@@ -25,13 +25,13 @@
#include "httplib_main.h"
/*
- * const char *XX_httplib_get_rel_url_at_current_server( const char *uri, const struct mg_connection *conn );
+ * const char *XX_httplib_get_rel_url_at_current_server( const char *uri, const struct httplib_connection *conn );
*
* The function XX_httplib_get_rel_url_at_current_server() returns the relative
* uri at the current server.
*/
-const char * XX_httplib_get_rel_url_at_current_server( const char *uri, const struct mg_connection *conn ) {
+const char * XX_httplib_get_rel_url_at_current_server( const char *uri, const struct httplib_connection *conn ) {
const char *server_domain;
size_t server_domain_len;
@@ -55,7 +55,7 @@ const char * XX_httplib_get_rel_url_at_current_server( const char *uri, const st
}
for (i = 0; XX_httplib_abs_uri_protocols[i].proto != NULL; i++) {
- if (mg_strncasecmp(uri,
+ if (httplib_strncasecmp(uri,
XX_httplib_abs_uri_protocols[i].proto,
XX_httplib_abs_uri_protocols[i].proto_len) == 0) {
diff --git a/src/httplib_get_remote_ip.c b/src/httplib_get_remote_ip.c
index 0f15b3ac..8deb37a6 100644
--- a/src/httplib_get_remote_ip.c
+++ b/src/httplib_get_remote_ip.c
@@ -25,13 +25,13 @@
#include "httplib_main.h"
/*
- * uint32_t XX_httplib_get_remote_ip( const struct mg_connection *conn );
+ * uint32_t XX_httplib_get_remote_ip( const struct httplib_connection *conn );
*
* The function XX_httplib_get_remote_ip() returns the IPv4 address of the
* remote peer.
*/
-uint32_t XX_httplib_get_remote_ip( const struct mg_connection *conn ) {
+uint32_t XX_httplib_get_remote_ip( const struct httplib_connection *conn ) {
if ( conn == NULL ) return 0;
diff --git a/src/httplib_get_request_handler.c b/src/httplib_get_request_handler.c
index e3a57001..6ef045b7 100644
--- a/src/httplib_get_request_handler.c
+++ b/src/httplib_get_request_handler.c
@@ -31,18 +31,18 @@
* for a connection.
*/
-int XX_httplib_get_request_handler( struct mg_connection *conn, int handler_type, mg_request_handler *handler, mg_websocket_connect_handler *connect_handler, mg_websocket_ready_handler *ready_handler, mg_websocket_data_handler *data_handler, mg_websocket_close_handler *close_handler, mg_authorization_handler *auth_handler, void **cbdata ) {
- const struct mg_request_info *request_info = mg_get_request_info(conn);
+int XX_httplib_get_request_handler( struct httplib_connection *conn, int handler_type, httplib_request_handler *handler, httplib_websocket_connect_handler *connect_handler, httplib_websocket_ready_handler *ready_handler, httplib_websocket_data_handler *data_handler, httplib_websocket_close_handler *close_handler, httplib_authorization_handler *auth_handler, void **cbdata ) {
+ const struct httplib_request_info *request_info = httplib_get_request_info(conn);
if ( request_info == NULL ) return 0;
const char *uri = request_info->local_uri;
size_t urilen = strlen(uri);
- struct mg_handler_info *tmp_rh;
+ struct httplib_handler_info *tmp_rh;
if ( conn == NULL || conn->ctx == NULL ) return 0;
- mg_lock_context(conn->ctx);
+ httplib_lock_context(conn->ctx);
/* first try for an exact match */
for (tmp_rh = conn->ctx->handlers; tmp_rh != NULL;
@@ -60,7 +60,7 @@ int XX_httplib_get_request_handler( struct mg_connection *conn, int handler_type
*auth_handler = tmp_rh->auth_handler;
}
*cbdata = tmp_rh->cbdata;
- mg_unlock_context(conn->ctx);
+ httplib_unlock_context(conn->ctx);
return 1;
}
}
@@ -83,7 +83,7 @@ int XX_httplib_get_request_handler( struct mg_connection *conn, int handler_type
*auth_handler = tmp_rh->auth_handler;
}
*cbdata = tmp_rh->cbdata;
- mg_unlock_context(conn->ctx);
+ httplib_unlock_context(conn->ctx);
return 1;
}
}
@@ -105,13 +105,13 @@ int XX_httplib_get_request_handler( struct mg_connection *conn, int handler_type
*auth_handler = tmp_rh->auth_handler;
}
*cbdata = tmp_rh->cbdata;
- mg_unlock_context(conn->ctx);
+ httplib_unlock_context(conn->ctx);
return 1;
}
}
}
- mg_unlock_context(conn->ctx);
+ httplib_unlock_context(conn->ctx);
return 0; /* none found */
diff --git a/src/httplib_get_request_info.c b/src/httplib_get_request_info.c
index a4b1be5d..3bf0572d 100644
--- a/src/httplib_get_request_info.c
+++ b/src/httplib_get_request_info.c
@@ -24,10 +24,10 @@
#include "httplib_main.h"
-const struct mg_request_info *mg_get_request_info( const struct mg_connection *conn ) {
+const struct httplib_request_info *httplib_get_request_info( const struct httplib_connection *conn ) {
if ( conn == NULL ) return NULL;
return & conn->request_info;
-} /* mg_get_request_info */
+} /* httplib_get_request_info */
diff --git a/src/httplib_get_response.c b/src/httplib_get_response.c
index 64b879e8..5c1862d1 100644
--- a/src/httplib_get_response.c
+++ b/src/httplib_get_response.c
@@ -26,19 +26,19 @@
#include "httplib_string.h"
/*
- * int mg_get_response( struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout );
+ * int httplib_get_response( struct httplib_connection *conn, char *ebuf, size_t ebuf_len, int timeout );
*
- * The function mg_get_response tries to get a response from a remote peer.
+ * The function httplib_get_response tries to get a response from a remote peer.
*/
-int mg_get_response( struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout ) {
+int httplib_get_response( struct httplib_connection *conn, char *ebuf, size_t ebuf_len, int timeout ) {
if ( conn == NULL ) return -1;
/* Implementation of API function for HTTP clients */
int err, ret;
- struct mg_context *octx = conn->ctx;
- struct mg_context rctx = *(conn->ctx);
+ struct httplib_context *octx = conn->ctx;
+ struct httplib_context rctx = *(conn->ctx);
char txt[32]; /* will not overflow */
if (timeout >= 0) {
@@ -61,4 +61,4 @@ int mg_get_response( struct mg_connection *conn, char *ebuf, size_t ebuf_len, in
* For the first test use <0 for error and >0 for OK */
return (ret == 0) ? -1 : +1;
-} /* mg_get_response */
+} /* httplib_get_response */
diff --git a/src/httplib_get_response_code_text.c b/src/httplib_get_response_code_text.c
index 0cdac51a..f229bd86 100644
--- a/src/httplib_get_response_code_text.c
+++ b/src/httplib_get_response_code_text.c
@@ -25,13 +25,13 @@
#include "httplib_main.h"
/*
- * const char *mg_get_response_code_text( struct mg_connection *conn, int response_code );
+ * const char *httplib_get_response_code_text( struct httplib_connection *conn, int response_code );
*
- * The function mg_get_response_code_text() returns a text associated with an
+ * The function httplib_get_response_code_text() returns a text associated with an
* HTTP response code.
*/
-const char *mg_get_response_code_text( struct mg_connection *conn, int response_code ) {
+const char *httplib_get_response_code_text( struct httplib_connection *conn, int response_code ) {
/* See IANA HTTP status code assignment:
* http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
@@ -111,7 +111,7 @@ const char *mg_get_response_code_text( struct mg_connection *conn, int response_
default:
/* This error code is unknown. This should not happen. */
- if ( conn != NULL) mg_cry( conn, "Unknown HTTP response code: %u", response_code );
+ if ( conn != NULL) httplib_cry( conn, "Unknown HTTP response code: %u", response_code );
/* Return at least a category according to RFC 2616 Section 10. */
if (response_code >= 100 && response_code < 200) return "Information";
@@ -123,4 +123,4 @@ const char *mg_get_response_code_text( struct mg_connection *conn, int response_
return "";
}
-} /* mg_get_response_code_text */
+} /* httplib_get_response_code_text */
diff --git a/src/httplib_get_server_ports.c b/src/httplib_get_server_ports.c
index 1a3f86ef..e69269e0 100644
--- a/src/httplib_get_server_ports.c
+++ b/src/httplib_get_server_ports.c
@@ -24,7 +24,7 @@
#include "httplib_main.h"
-int mg_get_server_ports(const struct mg_context *ctx, int size, struct mg_server_ports *ports) {
+int httplib_get_server_ports(const struct httplib_context *ctx, int size, struct httplib_server_ports *ports) {
int i;
int cnt = 0;
@@ -59,4 +59,4 @@ int mg_get_server_ports(const struct mg_context *ctx, int size, struct mg_server
return cnt;
-} /* mg_get_server_ports */
+} /* httplib_get_server_ports */
diff --git a/src/httplib_get_uri_type.c b/src/httplib_get_uri_type.c
index 4f7b0a2c..627839fe 100644
--- a/src/httplib_get_uri_type.c
+++ b/src/httplib_get_uri_type.c
@@ -95,7 +95,7 @@ int XX_httplib_get_uri_type( const char *uri ) {
* addressing the current server. So LibHTTP can also be used
* as a proxy server. */
for (i = 0; XX_httplib_abs_uri_protocols[i].proto != NULL; i++) {
- if (mg_strncasecmp(uri, XX_httplib_abs_uri_protocols[i].proto, XX_httplib_abs_uri_protocols[i].proto_len) == 0) {
+ if (httplib_strncasecmp(uri, XX_httplib_abs_uri_protocols[i].proto, XX_httplib_abs_uri_protocols[i].proto_len) == 0) {
hostend = strchr(uri + XX_httplib_abs_uri_protocols[i].proto_len, '/');
if (!hostend) return 0;
diff --git a/src/httplib_get_user_connection_data.c b/src/httplib_get_user_connection_data.c
index 94f1d8c5..6cf1d001 100644
--- a/src/httplib_get_user_connection_data.c
+++ b/src/httplib_get_user_connection_data.c
@@ -24,10 +24,10 @@
#include "httplib_main.h"
-void * mg_get_user_connection_data(const struct mg_connection *conn) {
+void * httplib_get_user_connection_data(const struct httplib_connection *conn) {
if (conn != NULL) return conn->request_info.conn_data;
return NULL;
-} /* mg_get_user_connection_data */
+} /* httplib_get_user_connection_data */
diff --git a/src/httplib_get_user_data.c b/src/httplib_get_user_data.c
index 8c9b470c..03cb2745 100644
--- a/src/httplib_get_user_data.c
+++ b/src/httplib_get_user_data.c
@@ -24,8 +24,8 @@
#include "httplib_main.h"
-void * mg_get_user_data(const struct mg_context *ctx) {
+void * httplib_get_user_data(const struct httplib_context *ctx) {
return (ctx == NULL) ? NULL : ctx->user_data;
-} /* mg_get_user_data */
+} /* httplib_get_user_data */
diff --git a/src/httplib_get_valid_options.c b/src/httplib_get_valid_options.c
index 51d0c0d5..6b5431a2 100644
--- a/src/httplib_get_valid_options.c
+++ b/src/httplib_get_valid_options.c
@@ -24,8 +24,8 @@
#include "httplib_main.h"
-const struct mg_option *mg_get_valid_options(void) {
+const struct httplib_option *httplib_get_valid_options(void) {
return XX_httplib_config_options;
-} /* mg_get_valid_options */
+} /* httplib_get_valid_options */
diff --git a/src/httplib_get_var.c b/src/httplib_get_var.c
index 6ef77306..552d419d 100644
--- a/src/httplib_get_var.c
+++ b/src/httplib_get_var.c
@@ -24,14 +24,14 @@
#include "httplib_main.h"
-int mg_get_var( const char *data, size_t data_len, const char *name, char *dst, size_t dst_len ) {
+int httplib_get_var( const char *data, size_t data_len, const char *name, char *dst, size_t dst_len ) {
- return mg_get_var2( data, data_len, name, dst, dst_len, 0 );
+ return httplib_get_var2( data, data_len, name, dst, dst_len, 0 );
-} /* mg_get_var */
+} /* httplib_get_var */
-int mg_get_var2( const char *data, size_t data_len, const char *name, char *dst, size_t dst_len, size_t occurrence ) {
+int httplib_get_var2( const char *data, size_t data_len, const char *name, char *dst, size_t dst_len, size_t occurrence ) {
const char *p;
const char *e;
@@ -53,7 +53,7 @@ int mg_get_var2( const char *data, size_t data_len, const char *name, char *dst,
/* data is "var1=val1&var2=val2...". Find variable first */
for (p = data; p + name_len < e; p++) {
if ((p == data || p[-1] == '&') && p[name_len] == '='
- && !mg_strncasecmp(name, p, name_len) && 0 == occurrence--) {
+ && !httplib_strncasecmp(name, p, name_len) && 0 == occurrence--) {
/* Point p to variable value */
p += name_len + 1;
@@ -64,7 +64,7 @@ int mg_get_var2( const char *data, size_t data_len, const char *name, char *dst,
if (s < p) return -3;
/* Decode variable into destination buffer */
- len = mg_url_decode(p, (int)(s - p), dst, (int)dst_len, 1);
+ len = httplib_url_decode(p, (int)(s - p), dst, (int)dst_len, 1);
/* Redirect error code from -1 to -2 (destination buffer too
* small). */
@@ -76,4 +76,4 @@ int mg_get_var2( const char *data, size_t data_len, const char *name, char *dst,
return len;
-} /* mg_get_var2 */
+} /* httplib_get_var2 */
diff --git a/src/httplib_getreq.c b/src/httplib_getreq.c
index 8263cf8b..e4ad49e9 100644
--- a/src/httplib_getreq.c
+++ b/src/httplib_getreq.c
@@ -26,12 +26,12 @@
#include "httplib_string.h"
/*
- * int XX_httplib_getreq( struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err );
+ * int XX_httplib_getreq( struct httplib_connection *conn, char *ebuf, size_t ebuf_len, int *err );
*
* The function XX_httplib_getreq() processes a request from a remote client.
*/
-int XX_httplib_getreq( struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err ) {
+int XX_httplib_getreq( struct httplib_connection *conn, char *ebuf, size_t ebuf_len, int *err ) {
const char *cl;
@@ -93,16 +93,13 @@ int XX_httplib_getreq( struct mg_connection *conn, char *ebuf, size_t ebuf_len,
conn->request_info.content_length = conn->content_len;
} else if ((cl = XX_httplib_get_header(&conn->request_info, "Transfer-Encoding"))
!= NULL
- && !mg_strcasecmp(cl, "chunked")) {
+ && !httplib_strcasecmp(cl, "chunked")) {
conn->is_chunked = 1;
- } else if (!mg_strcasecmp(conn->request_info.request_method, "POST")
- || !mg_strcasecmp(conn->request_info.request_method,
- "PUT")) {
+ } else if (!httplib_strcasecmp(conn->request_info.request_method, "POST")
+ || !httplib_strcasecmp(conn->request_info.request_method, "PUT")) {
/* POST or PUT request without content length set */
conn->content_len = -1;
- } else if (!mg_strncasecmp(conn->request_info.request_method,
- "HTTP/",
- 5)) {
+ } else if (!httplib_strncasecmp(conn->request_info.request_method, "HTTP/", 5)) {
/* Response without content length set */
conn->content_len = -1;
} else {
diff --git a/src/httplib_handle_cgi_request.c b/src/httplib_handle_cgi_request.c
index d7cf7002..94101707 100644
--- a/src/httplib_handle_cgi_request.c
+++ b/src/httplib_handle_cgi_request.c
@@ -27,7 +27,7 @@
#include "httplib_string.h"
/*
- * void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog );
+ * void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char *prog );
*
* The function XX_httplib_handle_cgi_request() handles a request for a CGI
* resource.
@@ -35,7 +35,7 @@
#if !defined(NO_CGI)
-void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog ) {
+void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char *prog ) {
char *buf;
size_t buflen;
@@ -52,7 +52,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
char *pbuf;
char dir[PATH_MAX];
char *p;
- struct mg_request_info ri;
+ struct httplib_request_info ri;
struct cgi_environment blk;
FILE *in;
FILE *out;
@@ -76,7 +76,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
XX_httplib_snprintf(conn, &truncated, dir, sizeof(dir), "%s", prog);
if (truncated) {
- mg_cry(conn, "Error: CGI program \"%s\": Path too long", prog);
+ httplib_cry(conn, "Error: CGI program \"%s\": Path too long", prog);
XX_httplib_send_http_error(conn, 500, "Error: %s", "CGI path too long");
goto done;
}
@@ -90,7 +90,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
if (pipe(fdin) != 0 || pipe(fdout) != 0 || pipe(fderr) != 0) {
status = strerror(ERRNO);
- mg_cry(conn, "Error: CGI program \"%s\": Can not create CGI pipes: %s", prog, status);
+ httplib_cry(conn, "Error: CGI program \"%s\": Can not create CGI pipes: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: Cannot create CGI pipe: %s", status);
goto done;
}
@@ -99,7 +99,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
if (pid == (pid_t)-1) {
status = strerror(ERRNO);
- mg_cry(conn, "Error: CGI program \"%s\": Can not spawn CGI process: %s", prog, status);
+ httplib_cry(conn, "Error: CGI program \"%s\": Can not spawn CGI process: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: Cannot spawn CGI process [%s]: %s", prog, status);
goto done;
}
@@ -126,21 +126,21 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
if ((in = fdopen(fdin[1], "wb")) == NULL) {
status = strerror(ERRNO);
- mg_cry(conn, "Error: CGI program \"%s\": Can not open stdin: %s", prog, status);
+ httplib_cry(conn, "Error: CGI program \"%s\": Can not open stdin: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: CGI can not open fdin\nfopen: %s", status);
goto done;
}
if ((out = fdopen(fdout[0], "rb")) == NULL) {
status = strerror(ERRNO);
- mg_cry(conn, "Error: CGI program \"%s\": Can not open stdout: %s", prog, status);
+ httplib_cry(conn, "Error: CGI program \"%s\": Can not open stdout: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: CGI can not open fdout\nfopen: %s", status);
goto done;
}
if ((err = fdopen(fderr[0], "rb")) == NULL) {
status = strerror(ERRNO);
- mg_cry(conn, "Error: CGI program \"%s\": Can not open stderr: %s", prog, status);
+ httplib_cry(conn, "Error: CGI program \"%s\": Can not open stderr: %s", prog, status);
XX_httplib_send_http_error(conn, 500, "Error: CGI can not open fdout\nfopen: %s", status);
goto done;
}
@@ -154,7 +154,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
/* This is a POST/PUT request, or another request with body data. */
if (!XX_httplib_forward_body_data(conn, in, INVALID_SOCKET, NULL)) {
/* Error sending the body data */
- mg_cry(conn, "Error: CGI program \"%s\": Forward body data failed", prog);
+ httplib_cry(conn, "Error: CGI program \"%s\": Forward body data failed", prog);
goto done;
}
}
@@ -172,7 +172,7 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
buf = (char *)XX_httplib_malloc(buflen);
if (buf == NULL) {
XX_httplib_send_http_error(conn, 500, "Error: Not enough memory for CGI buffer (%u bytes)", (unsigned int)buflen);
- mg_cry(conn, "Error: CGI program \"%s\": Not enough memory for buffer (%u " "bytes)", prog, (unsigned int)buflen);
+ httplib_cry(conn, "Error: CGI program \"%s\": Not enough memory for buffer (%u " "bytes)", prog, (unsigned int)buflen);
goto done;
}
headers_len = XX_httplib_read_request(out, conn, buf, (int)buflen, &data_len);
@@ -182,10 +182,10 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
* stderr. */
i = XX_httplib_pull_all(err, conn, buf, (int)buflen);
if (i > 0) {
- mg_cry(conn, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf);
+ httplib_cry(conn, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf);
XX_httplib_send_http_error(conn, 500, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf);
} else {
- mg_cry(conn, "Error: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", (unsigned)buflen, data_len, buf);
+ httplib_cry(conn, "Error: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", (unsigned)buflen, data_len, buf);
XX_httplib_send_http_error(conn,
500,
@@ -220,17 +220,16 @@ void XX_httplib_handle_cgi_request( struct mg_connection *conn, const char *prog
if (!XX_httplib_header_has_option(connection_state, "keep-alive")) {
conn->must_close = 1;
}
- mg_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code, status_text);
+ httplib_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code, status_text);
/* Send headers */
for (i = 0; i < ri.num_headers; i++) {
- mg_printf(conn, "%s: %s\r\n", ri.http_headers[i].name, ri.http_headers[i].value);
+ httplib_printf(conn, "%s: %s\r\n", ri.http_headers[i].name, ri.http_headers[i].value);
}
- mg_write(conn, "\r\n", 2);
+ httplib_write(conn, "\r\n", 2);
/* Send chunk of data that may have been read after the headers */
- conn->num_bytes_sent +=
- mg_write(conn, buf + headers_len, (size_t)(data_len - headers_len));
+ conn->num_bytes_sent += httplib_write(conn, buf + headers_len, (size_t)(data_len - headers_len));
/* Read the rest of CGI output and send to the client */
XX_httplib_send_file_data(conn, &fout, 0, INT64_MAX);
diff --git a/src/httplib_handle_directory_request.c b/src/httplib_handle_directory_request.c
index 48a47f46..9b700858 100644
--- a/src/httplib_handle_directory_request.c
+++ b/src/httplib_handle_directory_request.c
@@ -26,7 +26,7 @@
#include "httplib_memory.h"
#include "httplib_utils.h"
-void XX_httplib_handle_directory_request( struct mg_connection *conn, const char *dir ) {
+void XX_httplib_handle_directory_request( struct httplib_connection *conn, const char *dir ) {
unsigned int i;
int sort_direction;
@@ -46,12 +46,12 @@ void XX_httplib_handle_directory_request( struct mg_connection *conn, const char
sort_direction = ((conn->request_info.query_string != NULL) && (conn->request_info.query_string[1] == 'd')) ? 'a' : 'd';
conn->must_close = 1;
- mg_printf(conn, "HTTP/1.1 200 OK\r\n");
+ httplib_printf(conn, "HTTP/1.1 200 OK\r\n");
XX_httplib_send_static_cache_header(conn);
- mg_printf(conn, "Date: %s\r\n" "Connection: close\r\n" "Content-Type: text/html; charset=utf-8\r\n\r\n", date);
+ httplib_printf(conn, "Date: %s\r\n" "Connection: close\r\n" "Content-Type: text/html; charset=utf-8\r\n\r\n", date);
conn->num_bytes_sent +=
- mg_printf(conn,
+ httplib_printf(conn,
"Index of %s "
""
"Index of %s "
@@ -67,7 +67,7 @@ void XX_httplib_handle_directory_request( struct mg_connection *conn, const char
/* Print first entry - link to a parent directory */
conn->num_bytes_sent +=
- mg_printf(conn,
+ httplib_printf(conn,
"%s "
" %s %s \n",
conn->request_info.local_uri,
@@ -89,7 +89,7 @@ void XX_httplib_handle_directory_request( struct mg_connection *conn, const char
XX_httplib_free(data.entries);
}
- conn->num_bytes_sent += mg_printf(conn, "%s", "
");
+ conn->num_bytes_sent += httplib_printf(conn, "%s", "