mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-27 12:26:24 +00:00
Compare commits
41
Commits
5.5
...
5.5_20140120
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ace9285966 | ||
|
|
cdc167b0cc | ||
|
|
a0dd396b95 | ||
|
|
e4ad3010be | ||
|
|
03a82ef848 | ||
|
|
9459d69dcc | ||
|
|
b28662362d | ||
|
|
66450bf3d1 | ||
|
|
478ca05e7a | ||
|
|
8cad0a72f9 | ||
|
|
31178f4d48 | ||
|
|
7a5485493e | ||
|
|
d3cbb160f5 | ||
|
|
45ff2c2c19 | ||
|
|
c3db7b141b | ||
|
|
0a0ea36ace | ||
|
|
72ed954721 | ||
|
|
33e035273a | ||
|
|
223f36c130 | ||
|
|
4c0bc5bd03 | ||
|
|
808a5f6f53 | ||
|
|
404e635665 | ||
|
|
9d7a60a63f | ||
|
|
ba9c74187b | ||
|
|
e9d4847cbb | ||
|
|
ea76de07ee | ||
|
|
5a8c468ff7 | ||
|
|
5b143a6237 | ||
|
|
d244a7fdfd | ||
|
|
300a27de99 | ||
|
|
04a15a0c10 | ||
|
|
f0f6ae05aa | ||
|
|
8a7d535d92 | ||
|
|
e7ac6024de | ||
|
|
9981b99ac8 | ||
|
|
87a36c0c30 | ||
|
|
f2b13761c0 | ||
|
|
9786478a31 | ||
|
|
7d236d7f33 | ||
|
|
e098a7292d | ||
|
|
632b3a38a9 |
No files matched your search
-20
@@ -1,20 +0,0 @@
|
|||||||
language: cpp
|
|
||||||
|
|
||||||
env:
|
|
||||||
matrix:
|
|
||||||
- MONGOOSE_NO_SOCKETPAIR
|
|
||||||
- MONGOOSE_NO_FILESYSTEM
|
|
||||||
- MONGOOSE_NO_AUTH
|
|
||||||
- MONGOOSE_NO_DAV
|
|
||||||
- MONGOOSE_NO_DIRECTORY_LISTING
|
|
||||||
- MONGOOSE_NO_LOGGING
|
|
||||||
- MONGOOSE_NO_SSI
|
|
||||||
- MONGOOSE_NO_DL
|
|
||||||
- MONGOOSE_NO_WEBSOCKET
|
|
||||||
|
|
||||||
compiler:
|
|
||||||
- gcc
|
|
||||||
- clang
|
|
||||||
|
|
||||||
script:
|
|
||||||
- cd test && make
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
|
Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
|
||||||
Copyright (c) 2013 Cesanta Software Limited
|
Copyright (c) 2013-2015 Cesanta Software Limited
|
||||||
All rights reserved
|
All rights reserved
|
||||||
|
|
||||||
This code is dual-licensed: you can redistribute it and/or modify
|
This code is dual-licensed: you can redistribute it and/or modify
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ manufacturing, finance, research, automotive, gaming, IT.
|
|||||||
|
|
||||||
|
|
||||||
* [Mailing list](http://groups.google.com/group/mongoose-users)
|
* [Mailing list](http://groups.google.com/group/mongoose-users)
|
||||||
* [Downloads](http://cesanta.com/mongoose.shtml)
|
* [Downloads](http://cesanta.com/products.shtml)
|
||||||
* [Documentation](http://cesanta.com/docs.shtml)
|
* [Documentation](http://cesanta.com/docs.shtml)
|
||||||
|
|
||||||
|
Check out Fossa - our [embedded multi-protocol library](https://github.com/cesanta/fossa) with TCP,UDP,HTTP,Websocket,MQTT,DNS support, designed for Internet Of Things!
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
|
||||||
- Works on Windows, Mac, UNIX/Linux, iPhone, Android eCos, QNX
|
- Works on Windows, Mac, UNIX/Linux, iPhone, Android eCos, QNX
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
LOCAL_PATH := $(call my-dir)/../..
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
# To build with lua support, uncomment two lines below:
|
|
||||||
#LUA_SOURCES := build/lua_5.2.1.c build/sqlite3.c build/lsqlite3.c
|
|
||||||
#LUA_FLAGS := -I$(LOCAL_PATH)/build -DTHREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DUSE_LUA -DUSE_LUA_SQLITE3 -DLUA_COMPAT_ALL -D"getlocaledecpoint() ='.'"
|
|
||||||
|
|
||||||
LOCAL_CFLAGS := -std=c99 -O2 -W -Wall -pthread -pipe $(LUA_FLAGS) $(COPT)
|
|
||||||
LOCAL_MODULE := mongoose
|
|
||||||
LOCAL_SRC_FILES := examples/server.c mongoose.c $(LUA_SOURCES)
|
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
|
||||||
@@ -7,7 +7,7 @@ Note : You dont need root access to run mongoose on Android.
|
|||||||
|
|
||||||
- Clone Mongoose Git repo
|
- Clone Mongoose Git repo
|
||||||
- Download the Android NDK from [http://developer.android.com/tools/sdk/ndk/index.html](http://developer.android.com/tools/sdk/ndk/index.html)
|
- Download the Android NDK from [http://developer.android.com/tools/sdk/ndk/index.html](http://developer.android.com/tools/sdk/ndk/index.html)
|
||||||
- Run `/path-to-ndk/ndk-build -C /path-to-mongoose/examples`
|
- Run `/path-to-ndk/ndk-build -C /path/to/mongoose`
|
||||||
That should generate mongoose/lib/armeabi/mongoose
|
That should generate mongoose/lib/armeabi/mongoose
|
||||||
- Using the adb tool (you need to have Android SDK installed for that),
|
- Using the adb tool (you need to have Android SDK installed for that),
|
||||||
push the generated mongoose binary to `/data/local` folder on device.
|
push the generated mongoose binary to `/data/local` folder on device.
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ all Net Skeleton functions will be available too.
|
|||||||
-DMONGOOSE_NO_LOGGING Disable access/error logging
|
-DMONGOOSE_NO_LOGGING Disable access/error logging
|
||||||
-DMONGOOSE_NO_THREADS
|
-DMONGOOSE_NO_THREADS
|
||||||
-DMONGOOSE_NO_WEBSOCKET Disable WebSocket support
|
-DMONGOOSE_NO_WEBSOCKET Disable WebSocket support
|
||||||
|
-DMONGOOSE_NO_USER No concept of a user on used platform.
|
||||||
|
(Platform does not provide getpwnam, setgid or setuid)
|
||||||
|
|
||||||
-DMONGOOSE_USE_IDLE_TIMEOUT_SECONDS=X Idle connection timeout, default is 30
|
-DMONGOOSE_USE_IDLE_TIMEOUT_SECONDS=X Idle connection timeout, default is 30
|
||||||
-DMONGOOSE_USE_LUA Enable Lua scripting
|
-DMONGOOSE_USE_LUA Enable Lua scripting
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Changes in Libmongoose library:
|
|||||||
|
|
||||||
- Added new API function: `mg_forward()` for proxying functionality
|
- Added new API function: `mg_forward()` for proxying functionality
|
||||||
- Added new API function: `mg_send_file_data()` for sending file data
|
- Added new API function: `mg_send_file_data()` for sending file data
|
||||||
- Added new utility API functions: `mg_mmap() and mg_munpap()`
|
- Added new utility API functions: `mg_mmap() and mg_munmap()`
|
||||||
- Changed the way SSL settings are handled: removed `ssl_certificate` and
|
- Changed the way SSL settings are handled: removed `ssl_certificate` and
|
||||||
`ssl_ca_certificate` options, and instead made `listening_port` accept
|
`ssl_ca_certificate` options, and instead made `listening_port` accept
|
||||||
`ssl://PORT:SSL_CERT:CA_CERT` notation
|
`ssl://PORT:SSL_CERT:CA_CERT` notation
|
||||||
@@ -82,7 +82,7 @@ Changes in Libmongoose library:
|
|||||||
|
|
||||||
Changes in pre-compiled binaries:
|
Changes in pre-compiled binaries:
|
||||||
|
|
||||||
* New awesome Mongoose logos buy our designer Katrin - thanks Katrin!
|
* New awesome Mongoose logos by our designer Katrin - thanks Katrin!
|
||||||
Check them out at http://cesanta.com/products.shtml
|
Check them out at http://cesanta.com/products.shtml
|
||||||
* Added Lua Server Pages support to the free version, quick intro is at
|
* Added Lua Server Pages support to the free version, quick intro is at
|
||||||
http://cesanta.com/docs/Lua.shtml
|
http://cesanta.com/docs/Lua.shtml
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ unix: $(SOURCES)
|
|||||||
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp *.o *.lib
|
||||||
@@ -160,20 +160,13 @@ static void setopt(struct mg_server *s, const char *opt, const char *val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
const char *cert = NULL, *ca_cert = NULL, *port = "2014";
|
const char *port = "2014", *dump = NULL, *root = "proxy_web_root";
|
||||||
const char *mitm = NULL, *dump = NULL, *root = "proxy_web_root";
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// Parse command line options
|
// Parse command line options
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (strcmp(argv[i], "-ca_cert") == 0 && i + 1 < argc) {
|
if (strcmp(argv[i], "-port") == 0 && i + 1 < argc) {
|
||||||
ca_cert = argv[++i];
|
|
||||||
} else if (strcmp(argv[i], "-cert") == 0 && i + 1 < argc) {
|
|
||||||
cert = argv[++i];
|
|
||||||
} else if (strcmp(argv[i], "-port") == 0 && i + 1 < argc) {
|
|
||||||
port = argv[++i];
|
port = argv[++i];
|
||||||
} else if (strcmp(argv[i], "-mitm") == 0 && i + 1 < argc) {
|
|
||||||
mitm = argv[++i];
|
|
||||||
} else if (strcmp(argv[i], "-root") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "-root") == 0 && i + 1 < argc) {
|
||||||
root = argv[++i];
|
root = argv[++i];
|
||||||
} else if (strcmp(argv[i], "-dump") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "-dump") == 0 && i + 1 < argc) {
|
||||||
@@ -191,10 +184,7 @@ int main(int argc, char *argv[]) {
|
|||||||
setopt(s_server, "enable_proxy", "yes");
|
setopt(s_server, "enable_proxy", "yes");
|
||||||
setopt(s_server, "document_root", root);
|
setopt(s_server, "document_root", root);
|
||||||
setopt(s_server, "listening_port", port);
|
setopt(s_server, "listening_port", port);
|
||||||
setopt(s_server, "ssl_certificate", cert);
|
|
||||||
setopt(s_server, "ssl_ca_certificate", ca_cert);
|
|
||||||
setopt(s_server, "hexdump_file", dump);
|
setopt(s_server, "hexdump_file", dump);
|
||||||
setopt(s_server, "ssl_mitm_certs", mitm);
|
|
||||||
|
|
||||||
// Start two SSE pushing threads
|
// Start two SSE pushing threads
|
||||||
mg_start_thread(sse_pusher_thread_func, (void *) "sse_pusher_thread_1");
|
mg_start_thread(sse_pusher_thread_func, (void *) "sse_pusher_thread_1");
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
LOCAL_PATH := $(call my-dir)/..
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := -std=c99 -O2 -W -Wall -pthread -pipe $(COPT)
|
||||||
|
LOCAL_MODULE := mongoose
|
||||||
|
LOCAL_SRC_FILES := examples/web_server/web_server.c mongoose.c
|
||||||
|
|
||||||
|
include $(BUILD_EXECUTABLE)
|
||||||
+95
-58
@@ -14,8 +14,6 @@
|
|||||||
//
|
//
|
||||||
// Alternatively, you can license this library under a commercial
|
// Alternatively, you can license this library under a commercial
|
||||||
// license, as set out in <http://cesanta.com/>.
|
// license, as set out in <http://cesanta.com/>.
|
||||||
//
|
|
||||||
// $Date: 2014-09-16 06:47:40 UTC $
|
|
||||||
|
|
||||||
#ifdef NOEMBED_NET_SKELETON
|
#ifdef NOEMBED_NET_SKELETON
|
||||||
#include "net_skeleton.h"
|
#include "net_skeleton.h"
|
||||||
@@ -305,12 +303,18 @@ int ns_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
|
|||||||
#define NS_FREE free
|
#define NS_FREE free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NS_CALLOC
|
||||||
|
#define NS_CALLOC calloc
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NS_CTL_MSG_MESSAGE_SIZE (8 * 1024)
|
||||||
|
#define NS_READ_BUFFER_SIZE 2048
|
||||||
#define NS_UDP_RECEIVE_BUFFER_SIZE 2000
|
#define NS_UDP_RECEIVE_BUFFER_SIZE 2000
|
||||||
#define NS_VPRINTF_BUFFER_SIZE 500
|
#define NS_VPRINTF_BUFFER_SIZE 500
|
||||||
|
|
||||||
struct ctl_msg {
|
struct ctl_msg {
|
||||||
ns_callback_t callback;
|
ns_callback_t callback;
|
||||||
char message[1024 * 8];
|
char message[NS_CTL_MSG_MESSAGE_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
void iobuf_resize(struct iobuf *io, size_t new_size) {
|
void iobuf_resize(struct iobuf *io, size_t new_size) {
|
||||||
@@ -427,7 +431,7 @@ int ns_avprintf(char **buf, size_t size, const char *fmt, va_list ap) {
|
|||||||
// succeed or out of memory.
|
// succeed or out of memory.
|
||||||
*buf = NULL;
|
*buf = NULL;
|
||||||
while (len < 0) {
|
while (len < 0) {
|
||||||
if (*buf) free(*buf);
|
if (*buf) NS_FREE(*buf);
|
||||||
size *= 2;
|
size *= 2;
|
||||||
if ((*buf = (char *) NS_MALLOC(size)) == NULL) break;
|
if ((*buf = (char *) NS_MALLOC(size)) == NULL) break;
|
||||||
va_copy(ap_copy, ap);
|
va_copy(ap_copy, ap);
|
||||||
@@ -456,7 +460,7 @@ int ns_vprintf(struct ns_connection *nc, const char *fmt, va_list ap) {
|
|||||||
ns_out(nc, buf, len);
|
ns_out(nc, buf, len);
|
||||||
}
|
}
|
||||||
if (buf != mem && buf != NULL) {
|
if (buf != mem && buf != NULL) {
|
||||||
free(buf);
|
NS_FREE(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
@@ -490,7 +494,7 @@ static void hexdump(struct ns_connection *nc, const char *path,
|
|||||||
ns_hexdump(io->buf + (ev == NS_SEND ? 0 : io->len) -
|
ns_hexdump(io->buf + (ev == NS_SEND ? 0 : io->len) -
|
||||||
(ev == NS_SEND ? 0 : num_bytes), num_bytes, buf, buf_size);
|
(ev == NS_SEND ? 0 : num_bytes), num_bytes, buf, buf_size);
|
||||||
fprintf(fp, "%s", buf);
|
fprintf(fp, "%s", buf);
|
||||||
free(buf);
|
NS_FREE(buf);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
@@ -868,7 +872,7 @@ static int ns_ssl_err(struct ns_connection *conn, int res) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void ns_read_from_socket(struct ns_connection *conn) {
|
static void ns_read_from_socket(struct ns_connection *conn) {
|
||||||
char buf[2048];
|
char buf[NS_READ_BUFFER_SIZE];
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
if (conn->flags & NSF_CONNECTING) {
|
if (conn->flags & NSF_CONNECTING) {
|
||||||
@@ -1024,18 +1028,19 @@ time_t ns_mgr_poll(struct ns_mgr *mgr, int milli) {
|
|||||||
if (!(conn->flags & (NSF_LISTENING | NSF_CONNECTING))) {
|
if (!(conn->flags & (NSF_LISTENING | NSF_CONNECTING))) {
|
||||||
ns_call(conn, NS_POLL, ¤t_time);
|
ns_call(conn, NS_POLL, ¤t_time);
|
||||||
}
|
}
|
||||||
if (!(conn->flags & NSF_WANT_WRITE)) {
|
|
||||||
//DBG(("%p read_set", conn));
|
|
||||||
ns_add_to_set(conn->sock, &read_set, &max_fd);
|
|
||||||
}
|
|
||||||
if (((conn->flags & NSF_CONNECTING) && !(conn->flags & NSF_WANT_READ)) ||
|
|
||||||
(conn->send_iobuf.len > 0 && !(conn->flags & NSF_CONNECTING) &&
|
|
||||||
!(conn->flags & NSF_BUFFER_BUT_DONT_SEND))) {
|
|
||||||
//DBG(("%p write_set", conn));
|
|
||||||
ns_add_to_set(conn->sock, &write_set, &max_fd);
|
|
||||||
}
|
|
||||||
if (conn->flags & NSF_CLOSE_IMMEDIATELY) {
|
if (conn->flags & NSF_CLOSE_IMMEDIATELY) {
|
||||||
ns_close_conn(conn);
|
ns_close_conn(conn);
|
||||||
|
} else {
|
||||||
|
if (!(conn->flags & NSF_WANT_WRITE)) {
|
||||||
|
//DBG(("%p read_set", conn));
|
||||||
|
ns_add_to_set(conn->sock, &read_set, &max_fd);
|
||||||
|
}
|
||||||
|
if (((conn->flags & NSF_CONNECTING) && !(conn->flags & NSF_WANT_READ)) ||
|
||||||
|
(conn->send_iobuf.len > 0 && !(conn->flags & NSF_CONNECTING) &&
|
||||||
|
!(conn->flags & NSF_BUFFER_BUT_DONT_SEND))) {
|
||||||
|
//DBG(("%p write_set", conn));
|
||||||
|
ns_add_to_set(conn->sock, &write_set, &max_fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1247,10 +1252,15 @@ void ns_mgr_free(struct ns_mgr *s) {
|
|||||||
#define fopen(x, y) mg_fopen((x), (y))
|
#define fopen(x, y) mg_fopen((x), (y))
|
||||||
#define open(x, y, z) mg_open((x), (y), (z))
|
#define open(x, y, z) mg_open((x), (y), (z))
|
||||||
#define close(x) _close(x)
|
#define close(x) _close(x)
|
||||||
|
#define fileno(x) _fileno(x)
|
||||||
#define lseek(x, y, z) _lseeki64((x), (y), (z))
|
#define lseek(x, y, z) _lseeki64((x), (y), (z))
|
||||||
|
#define read(x, y, z) _read((x), (y), (z))
|
||||||
|
#define write(x, y, z) _write((x), (y), (z))
|
||||||
#define popen(x, y) _popen((x), (y))
|
#define popen(x, y) _popen((x), (y))
|
||||||
#define pclose(x) _pclose(x)
|
#define pclose(x) _pclose(x)
|
||||||
#define mkdir(x, y) _mkdir(x)
|
#define mkdir(x, y) _mkdir(x)
|
||||||
|
#define rmdir(x) _rmdir(x)
|
||||||
|
#define strdup(x) _strdup(x)
|
||||||
#ifndef __func__
|
#ifndef __func__
|
||||||
#define STRX(x) #x
|
#define STRX(x) #x
|
||||||
#define STR(x) STRX(x)
|
#define STR(x) STRX(x)
|
||||||
@@ -1269,11 +1279,18 @@ typedef HANDLE process_id_t;
|
|||||||
|
|
||||||
#else ////////////// UNIX specific defines and includes
|
#else ////////////// UNIX specific defines and includes
|
||||||
|
|
||||||
|
#if !defined(MONGOOSE_NO_FILESYSTEM) &&\
|
||||||
|
(!defined(MONGOOSE_NO_DAV) || !defined(MONGOOSE_NO_DIRECTORY_LISTING))
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#endif
|
||||||
|
#if !defined(MONGOOSE_NO_FILESYSTEM) && !defined(MONGOOSE_NO_DL)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#endif
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#if !defined(O_BINARY)
|
||||||
#define O_BINARY 0
|
#define O_BINARY 0
|
||||||
|
#endif
|
||||||
#define INT64_FMT PRId64
|
#define INT64_FMT PRId64
|
||||||
typedef struct stat file_stat_t;
|
typedef struct stat file_stat_t;
|
||||||
typedef pid_t process_id_t;
|
typedef pid_t process_id_t;
|
||||||
@@ -1307,13 +1324,15 @@ typedef pid_t process_id_t;
|
|||||||
#define MONGOOSE_IDLE_TIMEOUT_SECONDS 300
|
#define MONGOOSE_IDLE_TIMEOUT_SECONDS 300
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NS_DISABLE_SOCKETPAIR
|
#if defined(NS_DISABLE_SOCKETPAIR) && !defined(MONGOOSE_NO_CGI)
|
||||||
#define MONGOOSE_NO_CGI
|
#define MONGOOSE_NO_CGI
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MONGOOSE_NO_FILESYSTEM
|
#ifdef MONGOOSE_NO_FILESYSTEM
|
||||||
#define MONGOOSE_NO_AUTH
|
#define MONGOOSE_NO_AUTH
|
||||||
|
#if !defined(MONGOOSE_NO_CGI)
|
||||||
#define MONGOOSE_NO_CGI
|
#define MONGOOSE_NO_CGI
|
||||||
|
#endif
|
||||||
#define MONGOOSE_NO_DAV
|
#define MONGOOSE_NO_DAV
|
||||||
#define MONGOOSE_NO_DIRECTORY_LISTING
|
#define MONGOOSE_NO_DIRECTORY_LISTING
|
||||||
#define MONGOOSE_NO_LOGGING
|
#define MONGOOSE_NO_LOGGING
|
||||||
@@ -1463,7 +1482,7 @@ static const struct {
|
|||||||
{".shtm", 5, "text/html"},
|
{".shtm", 5, "text/html"},
|
||||||
{".shtml", 6, "text/html"},
|
{".shtml", 6, "text/html"},
|
||||||
{".css", 4, "text/css"},
|
{".css", 4, "text/css"},
|
||||||
{".js", 3, "application/x-javascript"},
|
{".js", 3, "application/javascript"},
|
||||||
{".ico", 4, "image/x-icon"},
|
{".ico", 4, "image/x-icon"},
|
||||||
{".gif", 4, "image/gif"},
|
{".gif", 4, "image/gif"},
|
||||||
{".jpg", 4, "image/jpeg"},
|
{".jpg", 4, "image/jpeg"},
|
||||||
@@ -1890,7 +1909,7 @@ static void *push_to_stdin(void *arg) {
|
|||||||
}
|
}
|
||||||
DBG(("%s", "FORWARED EVERYTHING TO CGI"));
|
DBG(("%s", "FORWARED EVERYTHING TO CGI"));
|
||||||
CloseHandle(tp->hPipe);
|
CloseHandle(tp->hPipe);
|
||||||
free(tp);
|
NS_FREE(tp);
|
||||||
_endthread();
|
_endthread();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1911,14 +1930,14 @@ static void *pull_from_stdout(void *arg) {
|
|||||||
CloseHandle(tp->hPipe);
|
CloseHandle(tp->hPipe);
|
||||||
shutdown(tp->s, 2); // Without this, IO thread may get truncated data
|
shutdown(tp->s, 2); // Without this, IO thread may get truncated data
|
||||||
closesocket(tp->s);
|
closesocket(tp->s);
|
||||||
free(tp);
|
NS_FREE(tp);
|
||||||
_endthread();
|
_endthread();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spawn_stdio_thread(sock_t sock, HANDLE hPipe,
|
static void spawn_stdio_thread(sock_t sock, HANDLE hPipe,
|
||||||
void *(*func)(void *)) {
|
void *(*func)(void *)) {
|
||||||
struct threadparam *tp = (struct threadparam *)malloc(sizeof(*tp));
|
struct threadparam *tp = (struct threadparam *)NS_MALLOC(sizeof(*tp));
|
||||||
if (tp != NULL) {
|
if (tp != NULL) {
|
||||||
tp->s = sock;
|
tp->s = sock;
|
||||||
tp->hPipe = hPipe;
|
tp->hPipe = hPipe;
|
||||||
@@ -2277,7 +2296,7 @@ static void on_cgi_data(struct ns_connection *nc) {
|
|||||||
#endif // !MONGOOSE_NO_CGI
|
#endif // !MONGOOSE_NO_CGI
|
||||||
|
|
||||||
static char *mg_strdup(const char *str) {
|
static char *mg_strdup(const char *str) {
|
||||||
char *copy = (char *) malloc(strlen(str) + 1);
|
char *copy = (char *) NS_MALLOC(strlen(str) + 1);
|
||||||
if (copy != NULL) {
|
if (copy != NULL) {
|
||||||
strcpy(copy, str);
|
strcpy(copy, str);
|
||||||
}
|
}
|
||||||
@@ -2673,7 +2692,7 @@ size_t mg_printf_data(struct mg_connection *c, const char *fmt, ...) {
|
|||||||
write_chunk((struct connection *) conn, buf, len);
|
write_chunk((struct connection *) conn, buf, len);
|
||||||
}
|
}
|
||||||
if (buf != mem && buf != NULL) {
|
if (buf != mem && buf != NULL) {
|
||||||
free(buf);
|
NS_FREE(buf);
|
||||||
}
|
}
|
||||||
return conn->ns_conn->send_iobuf.len;
|
return conn->ns_conn->send_iobuf.len;
|
||||||
}
|
}
|
||||||
@@ -2922,7 +2941,7 @@ size_t mg_websocket_write(struct mg_connection *conn, int opcode,
|
|||||||
size_t copy_len = 0;
|
size_t copy_len = 0;
|
||||||
|
|
||||||
if (data_len + 10 > sizeof(mem) &&
|
if (data_len + 10 > sizeof(mem) &&
|
||||||
(copy = (unsigned char *) malloc(data_len + 10)) == NULL) {
|
(copy = (unsigned char *) NS_MALLOC(data_len + 10)) == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2943,9 +2962,10 @@ size_t mg_websocket_write(struct mg_connection *conn, int opcode,
|
|||||||
} else {
|
} else {
|
||||||
// 64-bit length field
|
// 64-bit length field
|
||||||
copy[1] = 127;
|
copy[1] = 127;
|
||||||
* (uint32_t *) (copy + 2) = (uint32_t)
|
const uint32_t hi = htonl((uint32_t) ((uint64_t) data_len >> 32));
|
||||||
htonl((uint32_t) ((uint64_t) data_len >> 32));
|
const uint32_t lo = htonl(data_len & 0xffffffff);
|
||||||
* (uint32_t *) (copy + 6) = (uint32_t) htonl(data_len & 0xffffffff);
|
memcpy(copy+2,&hi,sizeof(hi));
|
||||||
|
memcpy(copy+6,&lo,sizeof(lo));
|
||||||
memcpy(copy + 10, data, data_len);
|
memcpy(copy + 10, data, data_len);
|
||||||
copy_len = 10 + data_len;
|
copy_len = 10 + data_len;
|
||||||
}
|
}
|
||||||
@@ -2954,7 +2974,7 @@ size_t mg_websocket_write(struct mg_connection *conn, int opcode,
|
|||||||
mg_write(conn, copy, copy_len);
|
mg_write(conn, copy, copy_len);
|
||||||
}
|
}
|
||||||
if (copy != mem) {
|
if (copy != mem) {
|
||||||
free(copy);
|
NS_FREE(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we send closing frame, schedule a connection to be closed after
|
// If we send closing frame, schedule a connection to be closed after
|
||||||
@@ -2979,7 +2999,7 @@ size_t mg_websocket_printf(struct mg_connection *conn, int opcode,
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (buf != mem && buf != NULL) {
|
if (buf != mem && buf != NULL) {
|
||||||
free(buf);
|
NS_FREE(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return MG_CONN_2_CONN(conn)->ns_conn->send_iobuf.len;
|
return MG_CONN_2_CONN(conn)->ns_conn->send_iobuf.len;
|
||||||
@@ -3292,7 +3312,7 @@ static DIR *opendir(const char *name) {
|
|||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
SetLastError(ERROR_BAD_ARGUMENTS);
|
SetLastError(ERROR_BAD_ARGUMENTS);
|
||||||
} else if ((dir = (DIR *) malloc(sizeof(*dir))) == NULL) {
|
} else if ((dir = (DIR *) NS_MALLOC(sizeof(*dir))) == NULL) {
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
} else {
|
} else {
|
||||||
to_wchar(name, wpath, ARRAY_SIZE(wpath));
|
to_wchar(name, wpath, ARRAY_SIZE(wpath));
|
||||||
@@ -3303,7 +3323,7 @@ static DIR *opendir(const char *name) {
|
|||||||
dir->handle = FindFirstFileW(wpath, &dir->info);
|
dir->handle = FindFirstFileW(wpath, &dir->info);
|
||||||
dir->result.d_name[0] = '\0';
|
dir->result.d_name[0] = '\0';
|
||||||
} else {
|
} else {
|
||||||
free(dir);
|
NS_FREE(dir);
|
||||||
dir = NULL;
|
dir = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3318,7 +3338,7 @@ static int closedir(DIR *dir) {
|
|||||||
if (dir->handle != INVALID_HANDLE_VALUE)
|
if (dir->handle != INVALID_HANDLE_VALUE)
|
||||||
result = FindClose(dir->handle) ? 0 : -1;
|
result = FindClose(dir->handle) ? 0 : -1;
|
||||||
|
|
||||||
free(dir);
|
NS_FREE(dir);
|
||||||
} else {
|
} else {
|
||||||
result = -1;
|
result = -1;
|
||||||
SetLastError(ERROR_BAD_ARGUMENTS);
|
SetLastError(ERROR_BAD_ARGUMENTS);
|
||||||
@@ -3376,7 +3396,7 @@ static int scan_directory(struct connection *conn, const char *dir,
|
|||||||
// Resize the array if nesessary
|
// Resize the array if nesessary
|
||||||
if (arr_ind >= arr_size) {
|
if (arr_ind >= arr_size) {
|
||||||
if ((p = (struct dir_entry *)
|
if ((p = (struct dir_entry *)
|
||||||
realloc(*arr, (inc + arr_size) * sizeof(**arr))) != NULL) {
|
NS_REALLOC(*arr, (inc + arr_size) * sizeof(**arr))) != NULL) {
|
||||||
// Memset new chunk to zero, otherwize st_mtime will have garbage which
|
// Memset new chunk to zero, otherwize st_mtime will have garbage which
|
||||||
// can make strftime() segfault, see
|
// can make strftime() segfault, see
|
||||||
// http://code.google.com/p/mongoose/issues/detail?id=79
|
// http://code.google.com/p/mongoose/issues/detail?id=79
|
||||||
@@ -3502,9 +3522,9 @@ static void send_directory_listing(struct connection *conn, const char *dir) {
|
|||||||
qsort(arr, num_entries, sizeof(arr[0]), compare_dir_entries);
|
qsort(arr, num_entries, sizeof(arr[0]), compare_dir_entries);
|
||||||
for (i = 0; i < num_entries; i++) {
|
for (i = 0; i < num_entries; i++) {
|
||||||
print_dir_entry(&arr[i]);
|
print_dir_entry(&arr[i]);
|
||||||
free(arr[i].file_name);
|
NS_FREE(arr[i].file_name);
|
||||||
}
|
}
|
||||||
free(arr);
|
NS_FREE(arr);
|
||||||
|
|
||||||
write_terminating_chunk(conn);
|
write_terminating_chunk(conn);
|
||||||
close_local_endpoint(conn);
|
close_local_endpoint(conn);
|
||||||
@@ -3572,9 +3592,9 @@ static void handle_propfind(struct connection *conn, const char *path,
|
|||||||
struct dir_entry *de = &arr[i];
|
struct dir_entry *de = &arr[i];
|
||||||
mg_url_encode(de->file_name, strlen(de->file_name), buf, sizeof(buf));
|
mg_url_encode(de->file_name, strlen(de->file_name), buf, sizeof(buf));
|
||||||
print_props(conn, buf, &de->st);
|
print_props(conn, buf, &de->st);
|
||||||
free(de->file_name);
|
NS_FREE(de->file_name);
|
||||||
}
|
}
|
||||||
free(arr);
|
NS_FREE(arr);
|
||||||
}
|
}
|
||||||
ns_send(conn->ns_conn, footer, sizeof(footer) - 1);
|
ns_send(conn->ns_conn, footer, sizeof(footer) - 1);
|
||||||
}
|
}
|
||||||
@@ -3754,6 +3774,23 @@ static FILE *open_auth_file(struct connection *conn, const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(HAVE_MD5) && !defined(MONGOOSE_NO_AUTH)
|
#if !defined(HAVE_MD5) && !defined(MONGOOSE_NO_AUTH)
|
||||||
|
/*
|
||||||
|
* This code implements the MD5 message-digest algorithm.
|
||||||
|
* The algorithm is due to Ron Rivest. This code was
|
||||||
|
* written by Colin Plumb in 1993, no copyright is claimed.
|
||||||
|
* This code is in the public domain; do with it what you wish.
|
||||||
|
*
|
||||||
|
* Equivalent code is available from RSA Data Security, Inc.
|
||||||
|
* This code has been tested against that, and is equivalent,
|
||||||
|
* except that you don't need to include two pages of legalese
|
||||||
|
* with every copy.
|
||||||
|
*
|
||||||
|
* To compute the message digest of a chunk of bytes, declare an
|
||||||
|
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
||||||
|
* needed on buffers full of bytes, and then call MD5Final, which
|
||||||
|
* will fill a supplied 16-byte array with the digest.
|
||||||
|
*/
|
||||||
|
|
||||||
typedef struct MD5Context {
|
typedef struct MD5Context {
|
||||||
uint32_t buf[4];
|
uint32_t buf[4];
|
||||||
uint32_t bits[2];
|
uint32_t bits[2];
|
||||||
@@ -4068,23 +4105,23 @@ static int is_dav_request(const struct connection *conn) {
|
|||||||
|
|
||||||
static int parse_header(const char *str, int str_len, const char *var_name,
|
static int parse_header(const char *str, int str_len, const char *var_name,
|
||||||
char *buf, size_t buf_size) {
|
char *buf, size_t buf_size) {
|
||||||
int ch = ' ', len = 0, n = strlen(var_name);
|
int ch = ' ', ch1 = ',', len = 0, n = strlen(var_name);
|
||||||
const char *p, *end = str + str_len, *s = NULL;
|
const char *p, *end = str + str_len, *s = NULL;
|
||||||
|
|
||||||
if (buf != NULL && buf_size > 0) buf[0] = '\0';
|
if (buf != NULL && buf_size > 0) buf[0] = '\0';
|
||||||
|
|
||||||
// Find where variable starts
|
// Find where variable starts
|
||||||
for (s = str; s != NULL && s + n < end; s++) {
|
for (s = str; s != NULL && s + n < end; s++) {
|
||||||
if ((s == str || s[-1] == ' ' || s[-1] == ',') && s[n] == '=' &&
|
if ((s == str || s[-1] == ch || s[-1] == ch1) && s[n] == '=' &&
|
||||||
!memcmp(s, var_name, n)) break;
|
!memcmp(s, var_name, n)) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s != NULL && &s[n + 1] < end) {
|
if (s != NULL && &s[n + 1] < end) {
|
||||||
s += n + 1;
|
s += n + 1;
|
||||||
if (*s == '"' || *s == '\'') ch = *s++;
|
if (*s == '"' || *s == '\'') ch = ch1 = *s++;
|
||||||
p = s;
|
p = s;
|
||||||
while (p < end && p[0] != ch && p[0] != ',' && len < (int) buf_size) {
|
while (p < end && p[0] != ch && p[0] != ch1 && len < (int) buf_size) {
|
||||||
if (p[0] == '\\' && p[1] == ch) p++;
|
if (ch == ch1 && p[0] == '\\' && p[1] == ch) p++;
|
||||||
buf[len++] = *p++;
|
buf[len++] = *p++;
|
||||||
}
|
}
|
||||||
if (len >= (int) buf_size || (ch != ' ' && *p != ch)) {
|
if (len >= (int) buf_size || (ch != ' ' && *p != ch)) {
|
||||||
@@ -4544,7 +4581,7 @@ static void try_parse(struct connection *conn) {
|
|||||||
// If request is buffered in, remove it from the iobuf. This is because
|
// If request is buffered in, remove it from the iobuf. This is because
|
||||||
// iobuf could be reallocated, and pointers in parsed request could
|
// iobuf could be reallocated, and pointers in parsed request could
|
||||||
// become invalid.
|
// become invalid.
|
||||||
conn->request = (char *) malloc(conn->request_len);
|
conn->request = (char *) NS_MALLOC(conn->request_len);
|
||||||
memcpy(conn->request, io->buf, conn->request_len);
|
memcpy(conn->request, io->buf, conn->request_len);
|
||||||
//DBG(("%p [%.*s]", conn, conn->request_len, conn->request));
|
//DBG(("%p [%.*s]", conn, conn->request_len, conn->request));
|
||||||
iobuf_remove(io, conn->request_len);
|
iobuf_remove(io, conn->request_len);
|
||||||
@@ -4638,7 +4675,7 @@ static void call_http_client_handler(struct connection *conn) {
|
|||||||
iobuf_remove(&conn->ns_conn->recv_iobuf, conn->mg_conn.content_len);
|
iobuf_remove(&conn->ns_conn->recv_iobuf, conn->mg_conn.content_len);
|
||||||
conn->mg_conn.status_code = 0;
|
conn->mg_conn.status_code = 0;
|
||||||
conn->cl = conn->num_bytes_recv = conn->request_len = 0;
|
conn->cl = conn->num_bytes_recv = conn->request_len = 0;
|
||||||
free(conn->request);
|
NS_FREE(conn->request);
|
||||||
conn->request = NULL;
|
conn->request = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4662,7 +4699,7 @@ struct mg_connection *mg_connect(struct mg_server *server, const char *addr) {
|
|||||||
nsconn = ns_connect(&server->ns_mgr, addr, mg_ev_handler, NULL);
|
nsconn = ns_connect(&server->ns_mgr, addr, mg_ev_handler, NULL);
|
||||||
if (nsconn == NULL) return 0;
|
if (nsconn == NULL) return 0;
|
||||||
|
|
||||||
if ((conn = (struct connection *) calloc(1, sizeof(*conn))) == NULL) {
|
if ((conn = (struct connection *) NS_CALLOC(1, sizeof(*conn))) == NULL) {
|
||||||
nsconn->flags |= NSF_CLOSE_IMMEDIATELY;
|
nsconn->flags |= NSF_CLOSE_IMMEDIATELY;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -4754,8 +4791,8 @@ static void close_local_endpoint(struct connection *conn) {
|
|||||||
|
|
||||||
// Gobble possible POST data sent to the URI handler
|
// Gobble possible POST data sent to the URI handler
|
||||||
iobuf_free(&conn->ns_conn->recv_iobuf);
|
iobuf_free(&conn->ns_conn->recv_iobuf);
|
||||||
free(conn->request);
|
NS_FREE(conn->request);
|
||||||
free(conn->path_info);
|
NS_FREE(conn->path_info);
|
||||||
conn->endpoint.nc = NULL;
|
conn->endpoint.nc = NULL;
|
||||||
conn->request = conn->path_info = NULL;
|
conn->request = conn->path_info = NULL;
|
||||||
|
|
||||||
@@ -4813,9 +4850,9 @@ void mg_destroy_server(struct mg_server **server) {
|
|||||||
|
|
||||||
ns_mgr_free(&s->ns_mgr);
|
ns_mgr_free(&s->ns_mgr);
|
||||||
for (i = 0; i < (int) ARRAY_SIZE(s->config_options); i++) {
|
for (i = 0; i < (int) ARRAY_SIZE(s->config_options); i++) {
|
||||||
free(s->config_options[i]); // It is OK to free(NULL)
|
NS_FREE(s->config_options[i]); // It is OK to free(NULL)
|
||||||
}
|
}
|
||||||
free(s);
|
NS_FREE(s);
|
||||||
*server = NULL;
|
*server = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4941,7 +4978,7 @@ void mg_copy_listeners(struct mg_server *s, struct mg_server *to) {
|
|||||||
for (c = ns_next(&s->ns_mgr, NULL); c != NULL; c = ns_next(&s->ns_mgr, c)) {
|
for (c = ns_next(&s->ns_mgr, NULL); c != NULL; c = ns_next(&s->ns_mgr, c)) {
|
||||||
struct ns_connection *tmp;
|
struct ns_connection *tmp;
|
||||||
if ((c->flags & NSF_LISTENING) &&
|
if ((c->flags & NSF_LISTENING) &&
|
||||||
(tmp = (struct ns_connection *) malloc(sizeof(*tmp))) != NULL) {
|
(tmp = (struct ns_connection *) NS_MALLOC(sizeof(*tmp))) != NULL) {
|
||||||
memcpy(tmp, c, sizeof(*tmp));
|
memcpy(tmp, c, sizeof(*tmp));
|
||||||
tmp->mgr = &to->ns_mgr;
|
tmp->mgr = &to->ns_mgr;
|
||||||
ns_add_conn(tmp->mgr, tmp);
|
ns_add_conn(tmp->mgr, tmp);
|
||||||
@@ -4988,7 +5025,7 @@ const char *mg_set_option(struct mg_server *server, const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*v != NULL) {
|
if (*v != NULL) {
|
||||||
free(*v);
|
NS_FREE(*v);
|
||||||
*v = NULL;
|
*v = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5008,7 +5045,7 @@ const char *mg_set_option(struct mg_server *server, const char *name,
|
|||||||
} else {
|
} else {
|
||||||
char buf[100];
|
char buf[100];
|
||||||
ns_sock_to_str(c->sock, buf, sizeof(buf), 2);
|
ns_sock_to_str(c->sock, buf, sizeof(buf), 2);
|
||||||
free(*v);
|
NS_FREE(*v);
|
||||||
*v = mg_strdup(buf);
|
*v = mg_strdup(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5016,7 +5053,7 @@ const char *mg_set_option(struct mg_server *server, const char *name,
|
|||||||
} else if (ind == HEXDUMP_FILE) {
|
} else if (ind == HEXDUMP_FILE) {
|
||||||
server->ns_mgr.hexdump_file = *v;
|
server->ns_mgr.hexdump_file = *v;
|
||||||
#endif
|
#endif
|
||||||
#ifndef _WIN32
|
#if !defined(_WIN32) && !defined(MONGOOSE_NO_USER)
|
||||||
} else if (ind == RUN_AS_USER) {
|
} else if (ind == RUN_AS_USER) {
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
if ((pw = getpwnam(value)) == NULL) {
|
if ((pw = getpwnam(value)) == NULL) {
|
||||||
@@ -5050,7 +5087,7 @@ static void on_accept(struct ns_connection *nc, union socket_address *sa) {
|
|||||||
|
|
||||||
if (!check_acl(server->config_options[ACCESS_CONTROL_LIST],
|
if (!check_acl(server->config_options[ACCESS_CONTROL_LIST],
|
||||||
ntohl(* (uint32_t *) &sa->sin.sin_addr)) ||
|
ntohl(* (uint32_t *) &sa->sin.sin_addr)) ||
|
||||||
(conn = (struct connection *) calloc(1, sizeof(*conn))) == NULL) {
|
(conn = (struct connection *) NS_CALLOC(1, sizeof(*conn))) == NULL) {
|
||||||
nc->flags |= NSF_CLOSE_IMMEDIATELY;
|
nc->flags |= NSF_CLOSE_IMMEDIATELY;
|
||||||
} else {
|
} else {
|
||||||
// Circularly link two connection structures
|
// Circularly link two connection structures
|
||||||
@@ -5162,7 +5199,7 @@ static void mg_ev_handler(struct ns_connection *nc, int ev, void *p) {
|
|||||||
call_user(conn, MG_CLOSE);
|
call_user(conn, MG_CLOSE);
|
||||||
close_local_endpoint(conn);
|
close_local_endpoint(conn);
|
||||||
conn->ns_conn = NULL;
|
conn->ns_conn = NULL;
|
||||||
free(conn);
|
NS_FREE(conn);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -5209,7 +5246,7 @@ static void iter2(struct ns_connection *nc, int ev, void *param) {
|
|||||||
(void) ev;
|
(void) ev;
|
||||||
|
|
||||||
//DBG(("%p [%s]", conn, msg));
|
//DBG(("%p [%s]", conn, msg));
|
||||||
if (sscanf(msg, "%p %n", &func, &n) && func != NULL) {
|
if (sscanf(msg, "%p %n", &func, &n) && func != NULL && conn != NULL) {
|
||||||
conn->mg_conn.callback_param = (void *) (msg + n);
|
conn->mg_conn.callback_param = (void *) (msg + n);
|
||||||
func(&conn->mg_conn, MG_POLL);
|
func(&conn->mg_conn, MG_POLL);
|
||||||
}
|
}
|
||||||
@@ -5242,7 +5279,7 @@ const char *mg_get_option(const struct mg_server *server, const char *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct mg_server *mg_create_server(void *server_data, mg_handler_t handler) {
|
struct mg_server *mg_create_server(void *server_data, mg_handler_t handler) {
|
||||||
struct mg_server *server = (struct mg_server *) calloc(1, sizeof(*server));
|
struct mg_server *server = (struct mg_server *) NS_CALLOC(1, sizeof(*server));
|
||||||
ns_mgr_init(&server->ns_mgr, server_data);
|
ns_mgr_init(&server->ns_mgr, server_data);
|
||||||
set_default_option_values(server->config_options);
|
set_default_option_values(server->config_options);
|
||||||
server->event_handler = handler;
|
server->event_handler = handler;
|
||||||
|
|||||||
+5
-7
@@ -2,25 +2,23 @@
|
|||||||
// Copyright (c) 2013-2014 Cesanta Software Limited
|
// Copyright (c) 2013-2014 Cesanta Software Limited
|
||||||
// All rights reserved
|
// All rights reserved
|
||||||
//
|
//
|
||||||
// This library is dual-licensed: you can redistribute it and/or modify
|
// This software is dual-licensed: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License version 2 as
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
// published by the Free Software Foundation. For the terms of this
|
// published by the Free Software Foundation. For the terms of this
|
||||||
// license, see <http://www.gnu.org/licenses/>.
|
// license, see <http://www.gnu.org/licenses/>.
|
||||||
//
|
//
|
||||||
// You are free to use this library under the terms of the GNU General
|
// You are free to use this software under the terms of the GNU General
|
||||||
// Public License, but WITHOUT ANY WARRANTY; without even the implied
|
// Public License, but WITHOUT ANY WARRANTY; without even the implied
|
||||||
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
// See the GNU General Public License for more details.
|
// See the GNU General Public License for more details.
|
||||||
//
|
//
|
||||||
// Alternatively, you can license this library under a commercial
|
// Alternatively, you can license this software under a commercial
|
||||||
// license, as set out in <http://cesanta.com/>.
|
// license, as set out in <http://cesanta.com/>.
|
||||||
//
|
|
||||||
// $Date: 2014-09-09 17:07:55 UTC $
|
|
||||||
|
|
||||||
#ifndef MONGOOSE_HEADER_INCLUDED
|
#ifndef MONGOOSE_HEADER_INCLUDED
|
||||||
#define MONGOOSE_HEADER_INCLUDED
|
#define MONGOOSE_HEADER_INCLUDED
|
||||||
|
|
||||||
#define MONGOOSE_VERSION "5.5"
|
#define MONGOOSE_VERSION "5.6"
|
||||||
|
|
||||||
#include <stdio.h> // required for FILE
|
#include <stdio.h> // required for FILE
|
||||||
#include <stddef.h> // required for size_t
|
#include <stddef.h> // required for size_t
|
||||||
@@ -53,7 +51,7 @@ struct mg_connection {
|
|||||||
int is_websocket; // Connection is a websocket connection
|
int is_websocket; // Connection is a websocket connection
|
||||||
int status_code; // HTTP status code for HTTP error handler
|
int status_code; // HTTP status code for HTTP error handler
|
||||||
int wsbits; // First byte of the websocket frame
|
int wsbits; // First byte of the websocket frame
|
||||||
void *server_param; // Parameter passed to mg_add_uri_handler()
|
void *server_param; // Parameter passed to mg_create_server()
|
||||||
void *connection_param; // Placeholder for connection-specific data
|
void *connection_param; // Placeholder for connection-specific data
|
||||||
void *callback_param;
|
void *callback_param;
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-2
@@ -306,9 +306,9 @@ static const char *test_base64_encode(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char *test_mg_parse_header(void) {
|
static const char *test_mg_parse_header(void) {
|
||||||
const char *str = "xx=1 kl yy, ert=234 kl=123, "
|
const char *str = "xx=1 kl yy, ert=234 kl=123, uri=\"/?name=x,y\", "
|
||||||
"ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234";
|
"ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234";
|
||||||
char buf[10];
|
char buf[20];
|
||||||
ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0);
|
ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0);
|
||||||
ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3);
|
ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3);
|
||||||
ASSERT(strcmp(buf, "234") == 0);
|
ASSERT(strcmp(buf, "234") == 0);
|
||||||
@@ -331,6 +331,7 @@ static const char *test_mg_parse_header(void) {
|
|||||||
ASSERT(strcmp(buf, "12\"34") == 0);
|
ASSERT(strcmp(buf, "12\"34") == 0);
|
||||||
ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1);
|
ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1);
|
||||||
ASSERT(strcmp(buf, "2") == 0);
|
ASSERT(strcmp(buf, "2") == 0);
|
||||||
|
ASSERT(mg_parse_header(str, "uri", buf, sizeof(buf)) == 10);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user