Compare commits

..
41 Commits
Author SHA1 Message Date
Sergey Lyubka ace9285966 Updated years 2015-01-19 18:25:14 +00:00
Sergey Lyubka cdc167b0cc Merge pull request #459 from joshcriz/patch-1
Update Makefile
2015-01-19 16:32:24 +00:00
Josh Criz a0dd396b95 Update Makefile
Fixing typo in 'clean' section
2015-01-16 17:59:08 -06:00
Sergey Lyubka e4ad3010be Fix #416 2014-12-30 03:56:29 +00:00
Sergey Lyubka 03a82ef848 Merge pull request #452 from CurlyMoo/patch-2
Typo
2014-12-27 18:25:09 +00:00
CurlyMoo 9459d69dcc Typo 2014-12-27 18:35:09 +01:00
Sergey Lyubka b28662362d Merge pull request #449 from ursine/patch-1
64-bit length fields on ARM don't work
2014-12-21 20:54:52 +00:00
Sergey Lyubka 66450bf3d1 Merge pull request #450 from sebgod/master
mongoose.c: using application/javascript for .js
2014-12-21 16:07:12 +00:00
Sebastian Godelet 478ca05e7a mongoose.c: using application/javascript for .js
As of http://www.rfc-editor.org/rfc/rfc4329.txt, the preferred MIME type
for JavaScript is application/javascript.
2014-12-21 22:16:05 +08:00
Gary Coulbourne 8cad0a72f9 64-bit length fields on ARM don't work
ARM only allows aligned accesses.  GCC generated unaligned accesses for the copy buffer, but ARM forces alignment, causing the first two bytes to be trampled.  I changed the mechanism to create two temporaries and memcpy them in.  It now works on ARM (and x86) for large websocket chunks.
2014-12-17 19:14:30 -05:00
Sergey Lyubka 31178f4d48 Typo fixed in the comment 2014-12-15 12:03:50 +00:00
Sergey Lyubka 7a5485493e Added md5 copyright 2014-12-11 18:01:58 +00:00
Sergey Lyubka d3cbb160f5 Removed travis config file 2014-12-01 11:33:16 +00:00
Sergey Lyubka 45ff2c2c19 Removed $Date$ marker 2014-11-28 14:16:49 +00:00
Sergey Lyubka c3db7b141b Removed $Date$ from header 2014-11-28 12:21:36 +00:00
Sergey Lyubka 0a0ea36ace Fix examples/proxy_server build 2014-11-24 19:33:24 +00:00
Sergey Lyubka 72ed954721 Merge pull request #440 from zapline/patch-1
Update ReleaseNotes.md(spell mistake)
2014-11-20 07:35:24 +00:00
zapline 33e035273a Update ReleaseNotes.md
spell mistake
2014-11-20 09:58:29 +08:00
Sergey Lyubka 223f36c130 Updated Readme 2014-11-17 15:50:02 +00:00
Sergey Lyubka 4c0bc5bd03 Updated Readme 2014-11-17 15:49:37 +00:00
Sergey Lyubka 808a5f6f53 Update README.md 2014-11-13 13:48:43 +00:00
Sergey Lyubka 404e635665 Fixed Android build 2014-11-12 22:16:32 +00:00
Sergey Lyubka 9d7a60a63f Merge pull request #433 from jhnwkmn/malloc
Consistent use of NS_MALLOC, NS_FREE and NS_REALLOC
2014-11-10 10:35:07 +00:00
Johan Wikman ba9c74187b Consistent use of NS_MALLOC, NS_FREE and NS_REALLOC
malloc(), free() and realloc() were used in a number of places.
Added NS_CALLOC as well.
2014-11-10 08:29:19 +02:00
Sergey Lyubka e9d4847cbb Merge pull request #432 from jhnwkmn/o_binary
O_BINARY might be defined.
2014-11-09 10:06:16 +00:00
Sergey Lyubka ea76de07ee Merge pull request #436 from jhnwkmn/no-cgi
MONGOOSE_NO_CGI needs special handling.
2014-11-09 10:04:54 +00:00
Sergey Lyubka 5a8c468ff7 Merge pull request #435 from jhnwkmn/size-macros
Added size macros.
2014-11-09 10:01:59 +00:00
Sergey Lyubka 5b143a6237 Merge pull request #434 from jhnwkmn/no-user
Added MONGOOSE_NO_USER configuration define.
2014-11-09 09:56:31 +00:00
Sergey Lyubka d244a7fdfd Merge pull request #437 from jhnwkmn/nsf-close-immediately
If socket is about to be closed do not add to [read|write]_set.
2014-11-09 09:55:13 +00:00
Johan Wikman 300a27de99 If socket is about to be closed do not add to [read|write]_set.
If NSG_CLOSE_IMMEDIATELY is on, then the socket will be closed,
which means that (if the socket was added to either read_set or
write_set) the subsequent select will in turn be performed on a
socket that has been closed.

Standard socket implementations seem to ignore a descriptor
referring to a closed socket but LWIP
(http://savannah.nongnu.org/projects/lwip/) crashes. So better
not to add to the sets.
2014-11-07 15:48:23 +02:00
Johan Wikman 04a15a0c10 MONGOOSE_NO_CGI needs special handling.
MONGOOSE_NO_CGI is implied by both NS_DISABLE_SOCKETPAIR and
MONGOOSE_NO_FILESYSTEM. Thus, so as not to get complaints about
the same define being defined twice, some extra checks are needed.
2014-11-07 15:29:25 +02:00
Johan Wikman f0f6ae05aa Added size macros.
On very resource constraind devices you need to be able to
control the size of all buffers and structures placed on the
stack.
2014-11-07 14:31:44 +02:00
Johan Wikman 8a7d535d92 Added MONGOOSE_NO_USER configuration define.
Low-end systems, not running a proper OS, may not have the
concept of a user.
2014-11-07 14:01:13 +02:00
Sergey Lyubka e7ac6024de Merge branch 'master' of ssh://github.com/valenok/mongoose 2014-11-07 10:05:51 +00:00
Sergey Lyubka 9981b99ac8 Extra NULL check in iter2(). Fix #430 2014-11-07 10:05:42 +00:00
Johan Wikman 87a36c0c30 O_BINARY might be defined.
Some unix environments defines O_BINARY.
2014-11-07 12:02:11 +02:00
Sergey Lyubka f2b13761c0 Merge pull request #431 from jhnwkmn/reduce-includes
Conditionally include dirent.h and dlfcn.h
2014-11-07 09:51:30 +00:00
Johan Wikman 9786478a31 Conditionally include dirent.h and dlfcn.h
If you do not have a filesystem or do not support dav or
dynamic loading, the corresponding header files need not
be included (some environments might not have them).
2014-11-07 11:05:51 +02:00
Sergey Lyubka 7d236d7f33 Merge pull request #429 from AlexAltea/master
Added #define's for deprecated POSIX names
2014-11-01 20:39:34 +00:00
Alexandro Sánchez Bach e098a7292d Added #define's for deprecated POSIX names 2014-10-30 23:07:48 +01:00
Sergey Lyubka 632b3a38a9 5.5 -> 5.6 2014-10-28 11:43:51 +00:00
13 changed files with 123 additions and 117 deletions

No files matched your search

-20
View File
@@ -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 -1
View File
@@ -1,5 +1,5 @@
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
This code is dual-licensed: you can redistribute it and/or modify
+3 -1
View File
@@ -11,9 +11,11 @@ manufacturing, finance, research, automotive, gaming, IT.
* [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)
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
- Works on Windows, Mac, UNIX/Linux, iPhone, Android eCos, QNX
-12
View File
@@ -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)
+1 -1
View File
@@ -7,7 +7,7 @@ Note : You dont need root access to run mongoose on Android.
- 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)
- 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
- Using the adb tool (you need to have Android SDK installed for that),
push the generated mongoose binary to `/data/local` folder on device.
+2
View File
@@ -151,6 +151,8 @@ all Net Skeleton functions will be available too.
-DMONGOOSE_NO_LOGGING Disable access/error logging
-DMONGOOSE_NO_THREADS
-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_LUA Enable Lua scripting
+2 -2
View File
@@ -6,7 +6,7 @@ Changes in Libmongoose library:
- Added new API function: `mg_forward()` for proxying functionality
- 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
`ssl_ca_certificate` options, and instead made `listening_port` accept
`ssl://PORT:SSL_CERT:CA_CERT` notation
@@ -82,7 +82,7 @@ Changes in Libmongoose library:
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
* Added Lua Server Pages support to the free version, quick intro is at
http://cesanta.com/docs/Lua.shtml
+1 -1
View File
@@ -9,4 +9,4 @@ unix: $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp *.o *.lib
+2 -12
View File
@@ -160,20 +160,13 @@ static void setopt(struct mg_server *s, const char *opt, const char *val) {
}
int main(int argc, char *argv[]) {
const char *cert = NULL, *ca_cert = NULL, *port = "2014";
const char *mitm = NULL, *dump = NULL, *root = "proxy_web_root";
const char *port = "2014", *dump = NULL, *root = "proxy_web_root";
int i;
// Parse command line options
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-ca_cert") == 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) {
if (strcmp(argv[i], "-port") == 0 && i + 1 < argc) {
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) {
root = argv[++i];
} 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, "document_root", root);
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, "ssl_mitm_certs", mitm);
// Start two SSE pushing threads
mg_start_thread(sse_pusher_thread_func, (void *) "sse_pusher_thread_1");
+8
View File
@@ -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
View File
@@ -14,8 +14,6 @@
//
// Alternatively, you can license this library under a commercial
// license, as set out in <http://cesanta.com/>.
//
// $Date: 2014-09-16 06:47:40 UTC $
#ifdef NOEMBED_NET_SKELETON
#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
#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_VPRINTF_BUFFER_SIZE 500
struct ctl_msg {
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) {
@@ -427,7 +431,7 @@ int ns_avprintf(char **buf, size_t size, const char *fmt, va_list ap) {
// succeed or out of memory.
*buf = NULL;
while (len < 0) {
if (*buf) free(*buf);
if (*buf) NS_FREE(*buf);
size *= 2;
if ((*buf = (char *) NS_MALLOC(size)) == NULL) break;
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);
}
if (buf != mem && buf != NULL) {
free(buf);
NS_FREE(buf);
}
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) -
(ev == NS_SEND ? 0 : num_bytes), num_bytes, buf, buf_size);
fprintf(fp, "%s", buf);
free(buf);
NS_FREE(buf);
}
fclose(fp);
}
@@ -868,7 +872,7 @@ static int ns_ssl_err(struct ns_connection *conn, int res) {
#endif
static void ns_read_from_socket(struct ns_connection *conn) {
char buf[2048];
char buf[NS_READ_BUFFER_SIZE];
int n = 0;
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))) {
ns_call(conn, NS_POLL, &current_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) {
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 open(x, y, z) mg_open((x), (y), (z))
#define close(x) _close(x)
#define fileno(x) _fileno(x)
#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 pclose(x) _pclose(x)
#define mkdir(x, y) _mkdir(x)
#define rmdir(x) _rmdir(x)
#define strdup(x) _strdup(x)
#ifndef __func__
#define STRX(x) #x
#define STR(x) STRX(x)
@@ -1269,11 +1279,18 @@ typedef HANDLE process_id_t;
#else ////////////// UNIX specific defines and includes
#if !defined(MONGOOSE_NO_FILESYSTEM) &&\
(!defined(MONGOOSE_NO_DAV) || !defined(MONGOOSE_NO_DIRECTORY_LISTING))
#include <dirent.h>
#endif
#if !defined(MONGOOSE_NO_FILESYSTEM) && !defined(MONGOOSE_NO_DL)
#include <dlfcn.h>
#endif
#include <inttypes.h>
#include <pwd.h>
#if !defined(O_BINARY)
#define O_BINARY 0
#endif
#define INT64_FMT PRId64
typedef struct stat file_stat_t;
typedef pid_t process_id_t;
@@ -1307,13 +1324,15 @@ typedef pid_t process_id_t;
#define MONGOOSE_IDLE_TIMEOUT_SECONDS 300
#endif
#ifdef NS_DISABLE_SOCKETPAIR
#if defined(NS_DISABLE_SOCKETPAIR) && !defined(MONGOOSE_NO_CGI)
#define MONGOOSE_NO_CGI
#endif
#ifdef MONGOOSE_NO_FILESYSTEM
#define MONGOOSE_NO_AUTH
#if !defined(MONGOOSE_NO_CGI)
#define MONGOOSE_NO_CGI
#endif
#define MONGOOSE_NO_DAV
#define MONGOOSE_NO_DIRECTORY_LISTING
#define MONGOOSE_NO_LOGGING
@@ -1463,7 +1482,7 @@ static const struct {
{".shtm", 5, "text/html"},
{".shtml", 6, "text/html"},
{".css", 4, "text/css"},
{".js", 3, "application/x-javascript"},
{".js", 3, "application/javascript"},
{".ico", 4, "image/x-icon"},
{".gif", 4, "image/gif"},
{".jpg", 4, "image/jpeg"},
@@ -1890,7 +1909,7 @@ static void *push_to_stdin(void *arg) {
}
DBG(("%s", "FORWARED EVERYTHING TO CGI"));
CloseHandle(tp->hPipe);
free(tp);
NS_FREE(tp);
_endthread();
return NULL;
}
@@ -1911,14 +1930,14 @@ static void *pull_from_stdout(void *arg) {
CloseHandle(tp->hPipe);
shutdown(tp->s, 2); // Without this, IO thread may get truncated data
closesocket(tp->s);
free(tp);
NS_FREE(tp);
_endthread();
return NULL;
}
static void spawn_stdio_thread(sock_t sock, HANDLE hPipe,
void *(*func)(void *)) {
struct threadparam *tp = (struct threadparam *)malloc(sizeof(*tp));
struct threadparam *tp = (struct threadparam *)NS_MALLOC(sizeof(*tp));
if (tp != NULL) {
tp->s = sock;
tp->hPipe = hPipe;
@@ -2277,7 +2296,7 @@ static void on_cgi_data(struct ns_connection *nc) {
#endif // !MONGOOSE_NO_CGI
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) {
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);
}
if (buf != mem && buf != NULL) {
free(buf);
NS_FREE(buf);
}
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;
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;
}
@@ -2943,9 +2962,10 @@ size_t mg_websocket_write(struct mg_connection *conn, int opcode,
} else {
// 64-bit length field
copy[1] = 127;
* (uint32_t *) (copy + 2) = (uint32_t)
htonl((uint32_t) ((uint64_t) data_len >> 32));
* (uint32_t *) (copy + 6) = (uint32_t) htonl(data_len & 0xffffffff);
const uint32_t hi = htonl((uint32_t) ((uint64_t) data_len >> 32));
const uint32_t lo = htonl(data_len & 0xffffffff);
memcpy(copy+2,&hi,sizeof(hi));
memcpy(copy+6,&lo,sizeof(lo));
memcpy(copy + 10, data, 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);
}
if (copy != mem) {
free(copy);
NS_FREE(copy);
}
// 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);
if (buf != mem && buf != NULL) {
free(buf);
NS_FREE(buf);
}
return MG_CONN_2_CONN(conn)->ns_conn->send_iobuf.len;
@@ -3292,7 +3312,7 @@ static DIR *opendir(const char *name) {
if (name == NULL) {
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);
} else {
to_wchar(name, wpath, ARRAY_SIZE(wpath));
@@ -3303,7 +3323,7 @@ static DIR *opendir(const char *name) {
dir->handle = FindFirstFileW(wpath, &dir->info);
dir->result.d_name[0] = '\0';
} else {
free(dir);
NS_FREE(dir);
dir = NULL;
}
}
@@ -3318,7 +3338,7 @@ static int closedir(DIR *dir) {
if (dir->handle != INVALID_HANDLE_VALUE)
result = FindClose(dir->handle) ? 0 : -1;
free(dir);
NS_FREE(dir);
} else {
result = -1;
SetLastError(ERROR_BAD_ARGUMENTS);
@@ -3376,7 +3396,7 @@ static int scan_directory(struct connection *conn, const char *dir,
// Resize the array if nesessary
if (arr_ind >= arr_size) {
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
// can make strftime() segfault, see
// 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);
for (i = 0; i < num_entries; 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);
close_local_endpoint(conn);
@@ -3572,9 +3592,9 @@ static void handle_propfind(struct connection *conn, const char *path,
struct dir_entry *de = &arr[i];
mg_url_encode(de->file_name, strlen(de->file_name), buf, sizeof(buf));
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);
}
@@ -3754,6 +3774,23 @@ static FILE *open_auth_file(struct connection *conn, const char *path,
}
#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 {
uint32_t buf[4];
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,
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;
if (buf != NULL && buf_size > 0) buf[0] = '\0';
// Find where variable starts
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;
}
if (s != NULL && &s[n + 1] < end) {
s += n + 1;
if (*s == '"' || *s == '\'') ch = *s++;
if (*s == '"' || *s == '\'') ch = ch1 = *s++;
p = s;
while (p < end && p[0] != ch && p[0] != ',' && len < (int) buf_size) {
if (p[0] == '\\' && p[1] == ch) p++;
while (p < end && p[0] != ch && p[0] != ch1 && len < (int) buf_size) {
if (ch == ch1 && p[0] == '\\' && p[1] == ch) p++;
buf[len++] = *p++;
}
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
// iobuf could be reallocated, and pointers in parsed request could
// 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);
//DBG(("%p [%.*s]", conn, conn->request_len, conn->request));
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);
conn->mg_conn.status_code = 0;
conn->cl = conn->num_bytes_recv = conn->request_len = 0;
free(conn->request);
NS_FREE(conn->request);
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);
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;
return 0;
}
@@ -4754,8 +4791,8 @@ static void close_local_endpoint(struct connection *conn) {
// Gobble possible POST data sent to the URI handler
iobuf_free(&conn->ns_conn->recv_iobuf);
free(conn->request);
free(conn->path_info);
NS_FREE(conn->request);
NS_FREE(conn->path_info);
conn->endpoint.nc = 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);
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;
}
}
@@ -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)) {
struct ns_connection *tmp;
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));
tmp->mgr = &to->ns_mgr;
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) {
free(*v);
NS_FREE(*v);
*v = NULL;
}
@@ -5008,7 +5045,7 @@ const char *mg_set_option(struct mg_server *server, const char *name,
} else {
char buf[100];
ns_sock_to_str(c->sock, buf, sizeof(buf), 2);
free(*v);
NS_FREE(*v);
*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) {
server->ns_mgr.hexdump_file = *v;
#endif
#ifndef _WIN32
#if !defined(_WIN32) && !defined(MONGOOSE_NO_USER)
} else if (ind == RUN_AS_USER) {
struct passwd *pw;
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],
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;
} else {
// 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);
close_local_endpoint(conn);
conn->ns_conn = NULL;
free(conn);
NS_FREE(conn);
}
break;
@@ -5209,7 +5246,7 @@ static void iter2(struct ns_connection *nc, int ev, void *param) {
(void) ev;
//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);
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 *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);
set_default_option_values(server->config_options);
server->event_handler = handler;
+5 -7
View File
@@ -2,25 +2,23 @@
// Copyright (c) 2013-2014 Cesanta Software Limited
// 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
// published by the Free Software Foundation. For the terms of this
// 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
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// 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/>.
//
// $Date: 2014-09-09 17:07:55 UTC $
#ifndef MONGOOSE_HEADER_INCLUDED
#define MONGOOSE_HEADER_INCLUDED
#define MONGOOSE_VERSION "5.5"
#define MONGOOSE_VERSION "5.6"
#include <stdio.h> // required for FILE
#include <stddef.h> // required for size_t
@@ -53,7 +51,7 @@ struct mg_connection {
int is_websocket; // Connection is a websocket connection
int status_code; // HTTP status code for HTTP error handler
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 *callback_param;
};
+3 -2
View File
@@ -306,9 +306,9 @@ static const char *test_base64_encode(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";
char buf[10];
char buf[20];
ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0);
ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3);
ASSERT(strcmp(buf, "234") == 0);
@@ -331,6 +331,7 @@ static const char *test_mg_parse_header(void) {
ASSERT(strcmp(buf, "12\"34") == 0);
ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1);
ASSERT(strcmp(buf, "2") == 0);
ASSERT(mg_parse_header(str, "uri", buf, sizeof(buf)) == 10);
return NULL;
}