diff --git a/include/CivetServer.h b/include/CivetServer.h index d50b42f9..1d453c52 100644 --- a/include/CivetServer.h +++ b/include/CivetServer.h @@ -20,7 +20,8 @@ class CivetServer; /** * Exception class for thrown exceptions within the CivetHandler object. */ -class CIVETWEB_API CivetException : public std::runtime_error { +class CIVETWEB_API CivetException : public std::runtime_error +{ public: CivetException(const std::string &msg) : std::runtime_error(msg) {} }; @@ -29,7 +30,8 @@ class CIVETWEB_API CivetException : public std::runtime_error { * Basic interface for a URI request handler. Handlers implementations * must be reentrant. */ -class CIVETWEB_API CivetHandler { +class CIVETWEB_API CivetHandler +{ public: /** * Destructor @@ -87,7 +89,8 @@ class CIVETWEB_API CivetHandler { * * Basic class for embedded web server. This has an URL mapping built-in. */ -class CIVETWEB_API CivetServer { +class CIVETWEB_API CivetServer +{ public: /** * Constructor @@ -135,7 +138,8 @@ class CIVETWEB_API CivetServer { */ void addHandler(const std::string &uri, CivetHandler *handler); - void addHandler(const std::string &uri, CivetHandler &handler) { + void addHandler(const std::string &uri, CivetHandler &handler) + { addHandler(uri, &handler); } @@ -206,8 +210,10 @@ class CIVETWEB_API CivetServer { *based). * @return true if key was found */ - static bool getParam(struct mg_connection *conn, const char *name, - std::string &dst, size_t occurrence = 0); + static bool getParam(struct mg_connection *conn, + const char *name, + std::string &dst, + size_t occurrence = 0); /** * getParam(const std::string &, const char *, std::string &, size_t) @@ -223,8 +229,11 @@ class CIVETWEB_API CivetServer { *based). * @return true if key was found */ - static bool getParam(const std::string &data, const char *name, - std::string &dst, size_t occurrence = 0) { + static bool getParam(const std::string &data, + const char *name, + std::string &dst, + size_t occurrence = 0) + { return getParam(data.c_str(), data.length(), name, dst, occurrence); } @@ -243,8 +252,11 @@ class CIVETWEB_API CivetServer { *based). * @return true if key was found */ - static bool getParam(const char *data, size_t data_len, const char *name, - std::string &dst, size_t occurrence = 0); + static bool getParam(const char *data, + size_t data_len, + const char *name, + std::string &dst, + size_t occurrence = 0); /** * urlDecode(const std::string &, std::string &, bool) @@ -256,8 +268,10 @@ class CIVETWEB_API CivetServer { * uses '+' as character for space, see RFC 1866 section 8.2.1 * http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt */ - static void urlDecode(const std::string &src, std::string &dst, - bool is_form_url_encoded = true) { + static void urlDecode(const std::string &src, + std::string &dst, + bool is_form_url_encoded = true) + { urlDecode(src.c_str(), src.length(), dst, is_form_url_encoded); } @@ -272,7 +286,9 @@ class CIVETWEB_API CivetServer { * uses '+' as character for space, see RFC 1866 section 8.2.1 * http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt */ - static void urlDecode(const char *src, size_t src_len, std::string &dst, + static void urlDecode(const char *src, + size_t src_len, + std::string &dst, bool is_form_url_encoded = true); /** @@ -285,7 +301,8 @@ class CIVETWEB_API CivetServer { * uses '+' as character for space, see RFC 1866 section 8.2.1 * http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt */ - static void urlDecode(const char *src, std::string &dst, + static void urlDecode(const char *src, + std::string &dst, bool is_form_url_encoded = true); /** @@ -295,8 +312,9 @@ class CIVETWEB_API CivetServer { * @param dst - destination string * @param append - true if string should not be cleared before encoding. */ - static void urlEncode(const std::string &src, std::string &dst, - bool append = false) { + static void + urlEncode(const std::string &src, std::string &dst, bool append = false) + { urlEncode(src.c_str(), src.length(), dst, append); } @@ -307,8 +325,8 @@ class CIVETWEB_API CivetServer { * @param dst - destination string * @param append - true if string should not be cleared before encoding. */ - static void urlEncode(const char *src, std::string &dst, - bool append = false); + static void + urlEncode(const char *src, std::string &dst, bool append = false); /** * urlEncode(const char *, size_t, std::string &, bool) @@ -318,11 +336,14 @@ class CIVETWEB_API CivetServer { * @param dst - destination string * @param append - true if string should not be cleared before encoding. */ - static void urlEncode(const char *src, size_t src_len, std::string &dst, + static void urlEncode(const char *src, + size_t src_len, + std::string &dst, bool append = false); protected: - class CivetConnection { + class CivetConnection + { public: char *postData; unsigned long postDataLen; diff --git a/include/civetweb.h b/include/civetweb.h index 90e9964a..44ddfd12 100644 --- a/include/civetweb.h +++ b/include/civetweb.h @@ -35,7 +35,7 @@ #define CIVETWEB_API #endif #elif __GNUC__ >= 4 -#define CIVETWEB_API __attribute__((visibility ("default"))) +#define CIVETWEB_API __attribute__((visibility("default"))) #else #define CIVETWEB_API #endif @@ -137,7 +137,9 @@ struct mg_callbacks { 1: keep this websocket connection open. 0: close this websocket connection. This callback is deprecated, use mg_set_websocket_handler instead. */ - int (*websocket_data)(struct mg_connection *, int bits, char *data, + int (*websocket_data)(struct mg_connection *, + int bits, + char *data, size_t data_len); /* Called when civetweb is closing a connection. The per-context mutex is @@ -158,7 +160,8 @@ struct mg_callbacks { NULL: do not serve file from memory, proceed with normal file open. non-NULL: pointer to the file contents in memory. data_len must be initilized with the size of the memory block. */ - const char *(*open_file)(const struct mg_connection *, const char *path, + const char *(*open_file)(const struct mg_connection *, + const char *path, size_t *data_len); /* Called when civetweb is about to serve Lua server page, if @@ -297,8 +300,8 @@ CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, typedef int (*mg_websocket_connect_handler)(const struct mg_connection *, void *); typedef void (*mg_websocket_ready_handler)(struct mg_connection *, void *); -typedef int (*mg_websocket_data_handler)(struct mg_connection *, int, char *, - size_t, void *); +typedef int (*mg_websocket_data_handler)( + struct mg_connection *, int, char *, size_t, void *); typedef void (*mg_websocket_close_handler)(const struct mg_connection *, void *); @@ -307,7 +310,8 @@ typedef void (*mg_websocket_close_handler)(const struct mg_connection *, Set or remove handler functions for websocket connections. This function works similar to mg_set_request_handler - see there. */ CIVETWEB_API void -mg_set_websocket_handler(struct mg_context *ctx, const char *uri, +mg_set_websocket_handler(struct mg_context *ctx, + const char *uri, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, @@ -391,7 +395,8 @@ mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl); Return: 1 on success, 0 on error. */ CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name, - const char *domain, const char *user, + const char *domain, + const char *user, const char *password); /* Return information associated with the request. */ @@ -417,8 +422,10 @@ CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len); 0 when the connection has been closed -1 on error >0 number of bytes written on success */ -CIVETWEB_API int mg_websocket_write(struct mg_connection *conn, int opcode, - const char *data, size_t data_len); +CIVETWEB_API int mg_websocket_write(struct mg_connection *conn, + int opcode, + const char *data, + size_t data_len); /* Blocks until unique access is obtained to this connection. Intended for use with websockets only. @@ -470,8 +477,8 @@ enum { /* Send data to the client using printf() semantics. Works exactly like mg_write(), but allows to do message formatting. */ CIVETWEB_API int mg_printf(struct mg_connection *, - PRINTF_FORMAT_STRING(const char *fmt), ...) - PRINTF_ARGS(2, 3); + PRINTF_FORMAT_STRING(const char *fmt), + ...) PRINTF_ARGS(2, 3); /* Send contents of the entire file together with HTTP headers. */ CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path); @@ -510,8 +517,11 @@ CIVETWEB_API const char *mg_get_header(const struct mg_connection *, Destination buffer is guaranteed to be '\0' - terminated if it is not NULL or zero length. */ -CIVETWEB_API int mg_get_var(const char *data, size_t data_len, - const char *var_name, char *dst, size_t dst_len); +CIVETWEB_API int mg_get_var(const char *data, + size_t data_len, + const char *var_name, + char *dst, + size_t dst_len); /* Get a value of particular form variable. @@ -536,8 +546,11 @@ CIVETWEB_API int mg_get_var(const char *data, size_t data_len, Destination buffer is guaranteed to be '\0' - terminated if it is not NULL or zero length. */ -CIVETWEB_API int mg_get_var2(const char *data, size_t data_len, - const char *var_name, char *dst, size_t dst_len, +CIVETWEB_API int mg_get_var2(const char *data, + size_t data_len, + const char *var_name, + char *dst, + size_t dst_len, size_t occurrence); /* Fetch value of certain cookie variable into the destination buffer. @@ -553,8 +566,10 @@ CIVETWEB_API int mg_get_var2(const char *data, size_t data_len, parameter is not found). -2 (destination buffer is NULL, zero length or too small to hold the value). */ -CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name, - char *buf, size_t buf_len); +CIVETWEB_API int mg_get_cookie(const char *cookie, + const char *var_name, + char *buf, + size_t buf_len); /* Download data from the remote web server. host: host name to connect to, e.g. "foo.com", or "10.12.40.1". @@ -572,10 +587,13 @@ CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name, "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n"); */ CIVETWEB_API struct mg_connection * -mg_download(const char *host, int port, int use_ssl, char *error_buffer, +mg_download(const char *host, + int port, + int use_ssl, + char *error_buffer, size_t error_buffer_size, - PRINTF_FORMAT_STRING(const char *request_fmt), ...) - PRINTF_ARGS(6, 7); + PRINTF_FORMAT_STRING(const char *request_fmt), + ...) PRINTF_ARGS(6, 7); /* Close the connection opened by mg_download(). */ CIVETWEB_API void mg_close_connection(struct mg_connection *conn); @@ -604,8 +622,11 @@ CIVETWEB_API const char *mg_version(void); uses '+' as character for space, see RFC 1866 section 8.2.1 http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt Return: length of the decoded data, or -1 if dst buffer is too small. */ -CIVETWEB_API int mg_url_decode(const char *src, int src_len, char *dst, - int dst_len, int is_form_url_encoded); +CIVETWEB_API int mg_url_decode(const char *src, + int src_len, + char *dst, + int dst_len, + int is_form_url_encoded); /* URL-encode input buffer into destination buffer. returns the length of the resulting buffer or -1 @@ -628,8 +649,8 @@ CIVETWEB_API char *mg_md5(char buf[33], ...); Example: mg_cry(conn,"i like %s", "logging"); */ CIVETWEB_API void mg_cry(const struct mg_connection *conn, - PRINTF_FORMAT_STRING(const char *fmt), ...) - PRINTF_ARGS(2, 3); + PRINTF_FORMAT_STRING(const char *fmt), + ...) PRINTF_ARGS(2, 3); /* utility method to compare two buffers, case incensitive. */ CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len); @@ -653,11 +674,17 @@ CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len); On error, NULL. Se error_buffer for details. */ -CIVETWEB_API struct mg_connection *mg_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, - void *user_data); +CIVETWEB_API struct mg_connection * +mg_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, + void *user_data); /* Connect to a TCP server as a client (can be used to connect to a HTTP server) Parameters: @@ -671,7 +698,8 @@ CIVETWEB_API struct mg_connection *mg_connect_websocket_client( On success, valid mg_connection object. On error, NULL. Se error_buffer for details. */ -CIVETWEB_API struct mg_connection *mg_connect_client(const char *host, int port, +CIVETWEB_API struct mg_connection *mg_connect_client(const char *host, + int port, int use_ssl, char *error_buffer, size_t error_buffer_size); @@ -689,8 +717,10 @@ enum { TIMEOUT_INFINITE = -1 }; On success, >= 0 On error/timeout, < 0 */ -CIVETWEB_API int mg_get_response(struct mg_connection *conn, char *ebuf, - size_t ebuf_len, int timeout); +CIVETWEB_API int mg_get_response(struct mg_connection *conn, + char *ebuf, + size_t ebuf_len, + int timeout); #ifdef __cplusplus } diff --git a/src/CivetServer.cpp b/src/CivetServer.cpp index 5bab2aac..3d0bf6dd 100644 --- a/src/CivetServer.cpp +++ b/src/CivetServer.cpp @@ -15,39 +15,44 @@ #define UNUSED_PARAMETER(x) (void)(x) #endif -bool CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn) { +bool CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn) +{ UNUSED_PARAMETER(server); UNUSED_PARAMETER(conn); return false; } -bool CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn) { +bool CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn) +{ UNUSED_PARAMETER(server); UNUSED_PARAMETER(conn); return false; } -bool CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn) { +bool CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn) +{ UNUSED_PARAMETER(server); UNUSED_PARAMETER(conn); return false; } -bool CivetHandler::handleDelete(CivetServer *server, - struct mg_connection *conn) { +bool CivetHandler::handleDelete(CivetServer *server, struct mg_connection *conn) +{ UNUSED_PARAMETER(server); UNUSED_PARAMETER(conn); return false; } bool CivetHandler::handleOptions(CivetServer *server, - struct mg_connection *conn) { + struct mg_connection *conn) +{ UNUSED_PARAMETER(server); UNUSED_PARAMETER(conn); return false; } -int CivetServer::requestHandler(struct mg_connection *conn, void *cbdata) { +int CivetServer::requestHandler(struct mg_connection *conn, void *cbdata) +{ const struct mg_request_info *request_info = mg_get_request_info(conn); assert(request_info != NULL); CivetServer *me = (CivetServer *)(request_info->user_data); @@ -82,7 +87,8 @@ int CivetServer::requestHandler(struct mg_connection *conn, void *cbdata) { CivetServer::CivetServer(const char **options, const struct mg_callbacks *_callbacks) - : context(0) { + : context(0) +{ struct mg_callbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); @@ -101,7 +107,8 @@ CivetServer::CivetServer(const char **options, CivetServer::~CivetServer() { close(); } -void CivetServer::closeHandler(const struct mg_connection *conn) { +void CivetServer::closeHandler(const struct mg_connection *conn) +{ const struct mg_request_info *request_info = mg_get_request_info(conn); assert(request_info != NULL); CivetServer *me = (CivetServer *)(request_info->user_data); @@ -118,15 +125,18 @@ void CivetServer::closeHandler(const struct mg_connection *conn) { mg_unlock_context(me->context); } -void CivetServer::addHandler(const std::string &uri, CivetHandler *handler) { +void CivetServer::addHandler(const std::string &uri, CivetHandler *handler) +{ mg_set_request_handler(context, uri.c_str(), requestHandler, handler); } -void CivetServer::removeHandler(const std::string &uri) { +void CivetServer::removeHandler(const std::string &uri) +{ mg_set_request_handler(context, uri.c_str(), NULL, NULL); } -void CivetServer::close() { +void CivetServer::close() +{ if (context) { mg_stop(context); context = 0; @@ -135,30 +145,37 @@ void CivetServer::close() { int CivetServer::getCookie(struct mg_connection *conn, const std::string &cookieName, - std::string &cookieValue) { + 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)); + int lRead = mg_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) { + const std::string &headerName) +{ return mg_get_header(conn, headerName.c_str()); } -void CivetServer::urlDecode(const char *src, std::string &dst, - bool is_form_url_encoded) { +void CivetServer::urlDecode(const char *src, + std::string &dst, + bool is_form_url_encoded) +{ urlDecode(src, strlen(src), dst, is_form_url_encoded); } -void CivetServer::urlDecode(const char *src, size_t src_len, std::string &dst, - bool is_form_url_encoded) { +void CivetServer::urlDecode(const char *src, + size_t src_len, + std::string &dst, + bool is_form_url_encoded) +{ int i, j, a, b; #define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W') @@ -179,8 +196,11 @@ void CivetServer::urlDecode(const char *src, size_t src_len, std::string &dst, } } -bool CivetServer::getParam(struct mg_connection *conn, const char *name, - std::string &dst, size_t occurrence) { +bool CivetServer::getParam(struct mg_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); assert(ri != NULL); @@ -227,8 +247,12 @@ bool CivetServer::getParam(struct mg_connection *conn, const char *name, return false; } -bool CivetServer::getParam(const char *data, size_t data_len, const char *name, - std::string &dst, size_t occurrence) { +bool CivetServer::getParam(const char *data, + size_t data_len, + const char *name, + std::string &dst, + size_t occurrence) +{ const char *p, *e, *s; size_t name_len; @@ -262,12 +286,16 @@ bool CivetServer::getParam(const char *data, size_t data_len, const char *name, return false; } -void CivetServer::urlEncode(const char *src, std::string &dst, bool append) { +void CivetServer::urlEncode(const char *src, std::string &dst, bool append) +{ urlEncode(src, strlen(src), dst, append); } -void CivetServer::urlEncode(const char *src, size_t src_len, std::string &dst, - bool append) { +void CivetServer::urlEncode(const char *src, + size_t src_len, + std::string &dst, + bool append) +{ static const char *dont_escape = "._-$,;~()"; static const char *hex = "0123456789abcdef"; @@ -286,7 +314,8 @@ void CivetServer::urlEncode(const char *src, size_t src_len, std::string &dst, } } -std::vector CivetServer::getListeningPorts() { +std::vector CivetServer::getListeningPorts() +{ std::vector ports(10); std::vector ssl(10); size_t size = mg_get_ports(context, ports.size(), &ports[0], &ssl[0]); @@ -295,7 +324,8 @@ std::vector CivetServer::getListeningPorts() { return ports; } -CivetServer::CivetConnection::CivetConnection() { +CivetServer::CivetConnection::CivetConnection() +{ postData = NULL; postDataLen = 0; } diff --git a/src/civetweb.c b/src/civetweb.c index f5c2cff6..9ae74cf6 100755 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -1169,7 +1169,7 @@ static void mg_set_thread_name(const char *name) threadName[sizeof(threadName) - 1] = 0; #if defined(_WIN32) - #if defined(_MSC_VER) +#if defined(_MSC_VER) /* Windows and Visual Studio Compiler */ __try { @@ -1185,34 +1185,34 @@ static void mg_set_thread_name(const char *name) (ULONG_PTR *)&info); } __except(EXCEPTION_EXECUTE_HANDLER) {} - #elif defined(__MINGW32__) +#elif defined(__MINGW32__) /* No option known to set thread name for MinGW */ ; - #endif +#endif #elif defined(__linux__) - /* Linux */ - #if defined(GLIBC_CHK) +/* Linux */ +#if defined(GLIBC_CHK) (void)pthread_setname_np(pthread_self(), threadName); - #else - (void)prctl(PR_SET_NAME, threadName, 0, 0, 0); - #endif -#elif defined(__APPLE__) || defined(__MACH__) - /* OS X */ - #if defined(GLIBC_CHK) - (void)pthread_setname_np(threadName); - #endif -#elif defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__) - /* BSD (TODO: test) */ - #if defined(GLIBC_CHK) - pthread_set_name_np(pthread_self(), threadName); - #endif -#elif defined(__AIX__) || defined(_AIX) || defined(__hpux) || defined(__sun) - /* pthread_set_name_np seems to be missing on AIX, hpux, sun, ... */ #else - /* POSIX */ - #if defined(GLIBC_CHK) + (void)prctl(PR_SET_NAME, threadName, 0, 0, 0); +#endif +#elif defined(__APPLE__) || defined(__MACH__) +/* OS X */ +#if defined(GLIBC_CHK) + (void)pthread_setname_np(threadName); +#endif +#elif defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__) +/* BSD (TODO: test) */ +#if defined(GLIBC_CHK) + pthread_set_name_np(pthread_self(), threadName); +#endif +#elif defined(__AIX__) || defined(_AIX) || defined(__hpux) || defined(__sun) +/* pthread_set_name_np seems to be missing on AIX, hpux, sun, ... */ +#else +/* POSIX */ +#if defined(GLIBC_CHK) (void)pthread_setname_np(pthread_self(), threadName); - #endif +#endif #endif } #else /* !defined(NO_THREAD_NAME) */ @@ -5244,20 +5244,24 @@ static void send_file_data(struct mg_connection *conn, } mg_write(conn, filep->membuf + offset, (size_t)len); } else if (len > 0 && filep->fp != NULL) { - /* file stored on disk */ -#if defined(LINUX_SENDFILE_TEST) -/* TODO: Test sendfile for Linux */ - if (conn->throttle==0 && conn->ssl==0) { +/* file stored on disk */ +#if defined(LINUX) + /* TODO: Test sendfile for Linux */ + if (conn->throttle == 0 && conn->ssl == 0) { off_t offs = (off_t)offset; - ssize_t sent = sendfile(conn->client.sock, fileno(filep->fp), &offs, (size_t)len); - if (sent>0) { + ssize_t sent = sendfile( + conn->client.sock, fileno(filep->fp), &offs, (size_t)len); + if (sent > 0) { conn->num_bytes_sent += sent; - return; - } - /* sent<0 means error --> try classic way */ - mg_cry(conn, "%s: sendfile() failed: %s (trying read/write)", __func__, strerror(ERRNO)); + return; /* OK */ + } + /* sent<0 means error --> try classic way */ + mg_cry(conn, + "%s: sendfile() failed: %s (trying read/write)", + __func__, + strerror(ERRNO)); } -#else +#endif if (offset > 0 && fseeko(filep->fp, offset, SEEK_SET) != 0) { mg_cry(conn, "%s: fseeko() failed: %s", __func__, strerror(ERRNO)); } else { @@ -5269,8 +5273,8 @@ static void send_file_data(struct mg_connection *conn, } /* Read from file, exit the loop on error */ - if ((num_read = (int)fread(buf, 1, (size_t)to_read, filep->fp)) <= - 0) { + if ((num_read = + (int)fread(buf, 1, (size_t)to_read, filep->fp)) <= 0) { break; } @@ -5285,7 +5289,6 @@ static void send_file_data(struct mg_connection *conn, len -= num_written; } } -#endif } } diff --git a/src/lua_civet.h b/src/lua_civet.h index e80fe609..394fcd83 100644 --- a/src/lua_civet.h +++ b/src/lua_civet.h @@ -1,4 +1,5 @@ /* "lua_civet.h" */ -/* Project internal header to allow main.c to call a non-public function in mod_lua.inl */ +/* Project internal header to allow main.c to call a non-public function in + * mod_lua.inl */ void lua_civet_open_all_libs(lua_State *L); diff --git a/src/main.c b/src/main.c index c4c04e0c..49b348df 100644 --- a/src/main.c +++ b/src/main.c @@ -299,11 +299,11 @@ static const char *get_option(char **options, const char *option_name) const char *opt_value = NULL; /* TODO (low, api makeover): options should be an array of key-value-pairs, - * like - * struct {const char * key, const char * value} options[] + * like + * struct {const char * key, const char * value} options[] * but it currently is an array with * options[2*i] = key, options[2*i + 1] = value - * (probably with a MG_LEGACY_INTERFACE definition) + * (probably with a MG_LEGACY_INTERFACE definition) */ while (options[2 * i] != NULL) { if (strcmp(options[2 * i], option_name) == 0) { @@ -1813,8 +1813,8 @@ static void change_password_file() static int manage_service(int action) { static const char *service_name = - "Civetweb"; /* TODO (mid): check using server_name instead of - * service_name */ + "Civetweb"; /* TODO (mid): check using server_name instead of + * service_name */ SC_HANDLE hSCM = NULL, hService = NULL; SERVICE_DESCRIPTION descr; char path[PATH_MAX + 20] = ""; /* Path to executable plus magic argument */ diff --git a/src/mod_lua.inl b/src/mod_lua.inl index 7f9cc7b6..03fc45da 100644 --- a/src/mod_lua.inl +++ b/src/mod_lua.inl @@ -8,9 +8,9 @@ mmap(void *addr, int64_t len, int prot, int flags, int fd, int offset) { /* TODO (low): This is an incomplete implementation of mmap for windows. * Currently it is sufficient, but there are a lot of unused parameters. - * Better use a function "mg_map" which only has the required parameters, - * and implement it using mmap in Linux and CreateFileMapping in Windows. - * Noone should expect a full mmap for Windows here. + * Better use a function "mg_map" which only has the required parameters, + * and implement it using mmap in Linux and CreateFileMapping in Windows. + * Noone should expect a full mmap for Windows here. */ HANDLE fh = (HANDLE)_get_osfhandle(fd); HANDLE mh = CreateFileMapping(fh, 0, PAGE_READONLY, 0, 0, 0); @@ -1109,14 +1109,14 @@ void lua_civet_open_all_libs(lua_State *L) } #endif #ifdef USE_LUA_BINARY - { - /* TODO (low): Test if this could be used as a replacement for bit32. - * Check again with Lua 5.3 later. */ + { + /* TODO (low): Test if this could be used as a replacement for bit32. + * Check again with Lua 5.3 later. */ extern int luaopen_binary(lua_State *); - luaL_requiref(L, "binary", luaopen_binary, 1); - lua_pop(L, 1); - } + luaL_requiref(L, "binary", luaopen_binary, 1); + lua_pop(L, 1); + } #endif }