Optimize code

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao committed 2018-01-10 23:30:24 +08:00
1 parent 769b6d2dbd
commit 33e2f8e272
9 files changed
+135 -75

No files matched your search

-8
View File
@@ -14,16 +14,9 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${LIBUBOX_INCLUDE_DIR})
set(EXTRA_LIBS ${LIBUBOX_LIBRARY} dl)
set(SOURCE_FILES uhttpd.c client.c log.c utils.c file.c action.c)
set(UHTTPD_DEBUG_CONFIG 0)
option(UHTTPD_DEBUG "Turn on debug" OFF)
if(UHTTPD_DEBUG)
set(UHTTPD_DEBUG_CONFIG 1)
endif()
set(UHTTPD_SSL_SUPPORT_CONFIG 1)
option(UHTTPD_SSL_SUPPORT "SSL support" ON)
if(UHTTPD_SSL_SUPPORT)
list(APPEND SOURCE_FILES uh_ssl.c)
else()
@@ -57,5 +50,4 @@ install(
message("")
message(STATUS "UHTTPD_VERSION: ${UHTTPD_VERSION_MAJOR}.${UHTTPD_VERSION_MINOR}.${UHTTPD_VERSION_PATCH}")
message(STATUS "UHTTPD_SSL_SUPPORT: ${UHTTPD_SSL_SUPPORT}")
message(STATUS "UHTTPD_DEBUG: ${UHTTPD_DEBUG}")
message("")
-7
View File
@@ -213,8 +213,6 @@ static void client_free(struct uh_client *cl)
kvlist_free(&cl->request.var);
kvlist_free(&cl->request.header);
cl->srv->nclients--;
uh_log_debug("client_free: %s:%d", inet_ntoa(cl->peer_addr.sin_addr), cl->peer_addr.sin_port);
free(cl);
}
}
@@ -280,11 +278,6 @@ static int client_parse_request(struct uh_client *cl, char *data)
if (req->version < UH_HTTP_VER_1_1)
cl->connection_close = true;
uh_log_debug("http path: %s", kvlist_get(&req->url, "path"));
uh_log_debug("http query: %s", kvlist_get(&req->url, "query"));
uh_log_debug("http method: %s", http_methods[h_method]);
uh_log_debug("http version: %s", http_versions[h_version]);
return CLIENT_STATE_HEADER;
}
-2
View File
@@ -23,8 +23,6 @@
#define UHTTPD_VERSION_PATCH @UHTTPD_VERSION_PATCH@
#define UHTTPD_VERSION_STRING "@UHTTPD_VERSION_MAJOR@.@UHTTPD_VERSION_MINOR@.@UHTTPD_VERSION_PATCH@"
#define UHTTPD_DEBUG @UHTTPD_DEBUG_CONFIG@
#define UHTTPD_SSL_SUPPORT @UHTTPD_SSL_SUPPORT_CONFIG@
#endif
-6
View File
@@ -398,12 +398,6 @@ bool handle_file_request(struct uh_client *cl, const char *path)
if (!pi)
return false;
uh_log_debug("pi->root: %s", pi->root);
uh_log_debug("pi->phys: %s", pi->phys);
uh_log_debug("pi->name: %s", pi->name);
uh_log_debug("pi->info: %s", pi->info);
uh_log_debug("pi->redirected: %d", pi->redirected);
if (pi->redirected)
return true;
+4 -11
View File
@@ -17,29 +17,22 @@
#include "log.h"
void __uh_log(const char *filename, int line, int priority, const char *format, ...)
void __uh_log(const char *filename, int line, int priority, const char *fmt, ...)
{
va_list ap;
static char buf[128];
snprintf(buf, sizeof(buf), "(%s:%d) ", filename, line);
va_start(ap, format);
vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), format, ap);
va_start(ap, fmt);
vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt, ap);
va_end(ap);
if (priority == LOG_ERR && errno > 0) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ":%s", strerror(errno));
errno = 0;
}
syslog(priority, "%s", buf);
#if (UHTTPD_DEBUG)
fprintf(stderr, "%s\n", buf);
#else
if (priority == LOG_ERR)
fprintf(stderr, "%s\n", buf);
#endif
ulog(priority, "%s\n", buf);
}
+7 -11
View File
@@ -18,25 +18,21 @@
#ifndef _LOG_H
#define _LOG_H
#include <syslog.h>
#include "common.h"
#include <libubox/ulog.h>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
/*
* Use the syslog output log and include the name and number of rows at the call
*/
#define uh_log(priority, format...) __uh_log(__FILENAME__, __LINE__, priority, format)
#define uh_log(priority, fmt...) __uh_log(__FILENAME__, __LINE__, priority, fmt)
#if (UHTTPD_DEBUG)
#define uh_log_debug(format...) uh_log(LOG_DEBUG, format)
#else
#define uh_log_debug(format...)
#endif
#define uh_log_debug(fmt...) uh_log(LOG_DEBUG, fmt)
#define uh_log_info(fmt...) uh_log(LOG_INFO, fmt)
#define uh_log_err(fmt...) uh_log(LOG_ERR, fmt)
#define uh_log_info(format...) uh_log(LOG_INFO, format)
#define uh_log_err(format...) uh_log(LOG_ERR, format)
void __uh_log(const char *filename, int line, int priority, const char *format, ...);
void __uh_log(const char *filename, int line, int priority, const char *fmt, ...);
#endif