Optimize code

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2018-01-17 12:50:25 +08:00
parent 60f339003e
commit 573969eadd
15 changed files with 52 additions and 56 deletions

View File

@ -15,7 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <uhttpd.h>
#include <libubox/ulog.h>
static void hello_action(struct uh_client *cl)
{
@ -72,7 +76,7 @@ int main(int argc, char **argv)
if (!verbose)
ulog_threshold(LOG_ERR);
uh_log_debug("libuhttpd version: %s", UHTTPD_VERSION_STRING);
ULOG_INFO("libuhttpd version: %s\n", UHTTPD_VERSION_STRING);
uloop_init();
@ -82,13 +86,13 @@ int main(int argc, char **argv)
#if (!UHTTPD_SSL_SUPPORT)
if (ssl)
uh_log_debug("SSl is not compiled in");
ULOG_ERR("SSl is not compiled in\n");
#else
if (ssl && srv->ssl_init(srv, "server-key.pem", "server-cert.pem") < 0)
goto done;
#endif
uh_log_debug("Listen on: %s *:%d", srv->ssl ? "https" : "http", port);
ULOG_INFO("Listen on: %s *:%d\n", srv->ssl ? "https" : "http", port);
srv->add_action(srv, "/hello", hello_action);

View File

@ -34,9 +34,7 @@ install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/config.h
${CMAKE_CURRENT_SOURCE_DIR}/uhttpd.h
${CMAKE_CURRENT_SOURCE_DIR}/log.h
${CMAKE_CURRENT_SOURCE_DIR}/client.h
${CMAKE_CURRENT_SOURCE_DIR}/common.h
${CMAKE_CURRENT_SOURCE_DIR}/action.h
DESTINATION
include/uhttpd

View File

@ -19,8 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "action.h"
#include "uhttpd.h"
#include "log.h"
#define UH_ACTION_DATA_BUF_SIZE 1024
#define UH_ACTION_MAX_POST_SIZE 4096

View File

@ -15,11 +15,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include <assert.h>
#include <arpa/inet.h>
#include <linux/limits.h>
#include <libubox/blobmsg.h>
#include "uhttpd.h"
#include "client.h"
#include "file.h"
#include "utils.h"
#include "uh_ssl.h"
#include "log.h"
const char *const http_versions[] = {
[UH_HTTP_VER_0_9] = "HTTP/0.9",

View File

@ -18,7 +18,11 @@
#ifndef _CLIENT_H_
#define _CLIENT_H_
#include "common.h"
#include <netinet/in.h>
#include <libubox/kvlist.h>
#include <libubox/ustream.h>
#include "config.h"
#if (UHTTPD_SSL_SUPPORT)
#include <libubox/ustream-ssl.h>

View File

@ -1,47 +0,0 @@
/*
* Copyright (C) 2017 Jianhui Zhao <jianhuizhao329@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _COMMON_H
#define _COMMON_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include <stdbool.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/limits.h>
#include <libubox/uloop.h>
#include <libubox/utils.h>
#include <libubox/blobmsg.h>
#include <libubox/kvlist.h>
#include <libubox/avl-cmp.h>
#include <libubox/ustream.h>
#include "config.h"
#include "log.h"
#endif

View File

@ -15,11 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include "file.h"
#include "utils.h"
#include "uhttpd.h"
#include "log.h"
static const struct mimetype uh_mime_types[] = {
{ "txt", "text/plain" },

View File

@ -18,6 +18,8 @@
#ifndef _FILE_H
#define _FILE_H
#include <sys/stat.h>
#include "client.h"
struct path_info {

View File

@ -14,7 +14,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include "log.h"
void __uh_log(const char *filename, int line, int priority, const char *fmt, ...)

View File

@ -18,8 +18,7 @@
#ifndef _LOG_H
#define _LOG_H
#include "common.h"
#include <string.h>
#include <libubox/ulog.h>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

View File

@ -17,8 +17,11 @@
*/
#include <dlfcn.h>
#include <errno.h>
#include "uhttpd.h"
#include "uh_ssl.h"
#include "log.h"
static bool _init = false;
static struct ustream_ssl_ops *ops;

View File

@ -19,6 +19,8 @@
#ifndef __UHTTPD_SSL_H
#define __UHTTPD_SSL_H
#include "config.h"
#if (UHTTPD_SSL_SUPPORT)
int uh_ssl_init(struct uh_server *srv, const char *key, const char *crt);

View File

@ -15,9 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <unistd.h>
#include <libubox/usock.h>
#include <libubox/avl-cmp.h>
#include "uhttpd.h"
#include "uh_ssl.h"
#include "log.h"
static void uh_set_docroot(struct uh_server *srv, const char *docroot)
{

View File

@ -18,6 +18,7 @@
#ifndef _UHTTPD_H
#define _UHTTPD_H
#include "config.h"
#include "client.h"
#include "action.h"

View File

@ -15,6 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "utils.h"
void uh_printf(struct uh_client *cl, const char *format, ...)