parent
60f339003e
commit
573969eadd
|
@ -15,7 +15,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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 <uhttpd.h>
|
||||||
|
#include <libubox/ulog.h>
|
||||||
|
|
||||||
static void hello_action(struct uh_client *cl)
|
static void hello_action(struct uh_client *cl)
|
||||||
{
|
{
|
||||||
|
@ -72,7 +76,7 @@ int main(int argc, char **argv)
|
||||||
if (!verbose)
|
if (!verbose)
|
||||||
ulog_threshold(LOG_ERR);
|
ulog_threshold(LOG_ERR);
|
||||||
|
|
||||||
uh_log_debug("libuhttpd version: %s", UHTTPD_VERSION_STRING);
|
ULOG_INFO("libuhttpd version: %s\n", UHTTPD_VERSION_STRING);
|
||||||
|
|
||||||
uloop_init();
|
uloop_init();
|
||||||
|
|
||||||
|
@ -82,13 +86,13 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
#if (!UHTTPD_SSL_SUPPORT)
|
#if (!UHTTPD_SSL_SUPPORT)
|
||||||
if (ssl)
|
if (ssl)
|
||||||
uh_log_debug("SSl is not compiled in");
|
ULOG_ERR("SSl is not compiled in\n");
|
||||||
#else
|
#else
|
||||||
if (ssl && srv->ssl_init(srv, "server-key.pem", "server-cert.pem") < 0)
|
if (ssl && srv->ssl_init(srv, "server-key.pem", "server-cert.pem") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
#endif
|
#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);
|
srv->add_action(srv, "/hello", hello_action);
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,7 @@ install(
|
||||||
FILES
|
FILES
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/uhttpd.h
|
${CMAKE_CURRENT_SOURCE_DIR}/uhttpd.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/log.h
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/client.h
|
${CMAKE_CURRENT_SOURCE_DIR}/client.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/common.h
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/action.h
|
${CMAKE_CURRENT_SOURCE_DIR}/action.h
|
||||||
DESTINATION
|
DESTINATION
|
||||||
include/uhttpd
|
include/uhttpd
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
#include "uhttpd.h"
|
#include "uhttpd.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#define UH_ACTION_DATA_BUF_SIZE 1024
|
#define UH_ACTION_DATA_BUF_SIZE 1024
|
||||||
#define UH_ACTION_MAX_POST_SIZE 4096
|
#define UH_ACTION_MAX_POST_SIZE 4096
|
||||||
|
|
|
@ -15,11 +15,18 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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 "uhttpd.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "uh_ssl.h"
|
#include "uh_ssl.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
const char *const http_versions[] = {
|
const char *const http_versions[] = {
|
||||||
[UH_HTTP_VER_0_9] = "HTTP/0.9",
|
[UH_HTTP_VER_0_9] = "HTTP/0.9",
|
||||||
|
|
|
@ -18,7 +18,11 @@
|
||||||
#ifndef _CLIENT_H_
|
#ifndef _CLIENT_H_
|
||||||
#define _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)
|
#if (UHTTPD_SSL_SUPPORT)
|
||||||
#include <libubox/ustream-ssl.h>
|
#include <libubox/ustream-ssl.h>
|
||||||
|
|
47
src/common.h
47
src/common.h
|
@ -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
|
|
|
@ -15,11 +15,17 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "uhttpd.h"
|
#include "uhttpd.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
static const struct mimetype uh_mime_types[] = {
|
static const struct mimetype uh_mime_types[] = {
|
||||||
{ "txt", "text/plain" },
|
{ "txt", "text/plain" },
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#ifndef _FILE_H
|
#ifndef _FILE_H
|
||||||
#define _FILE_H
|
#define _FILE_H
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
struct path_info {
|
struct path_info {
|
||||||
|
|
|
@ -14,7 +14,12 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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"
|
#include "log.h"
|
||||||
|
|
||||||
void __uh_log(const char *filename, int line, int priority, const char *fmt, ...)
|
void __uh_log(const char *filename, int line, int priority, const char *fmt, ...)
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
#ifndef _LOG_H
|
#ifndef _LOG_H
|
||||||
#define _LOG_H
|
#define _LOG_H
|
||||||
|
|
||||||
#include "common.h"
|
#include <string.h>
|
||||||
|
|
||||||
#include <libubox/ulog.h>
|
#include <libubox/ulog.h>
|
||||||
|
|
||||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||||
|
|
|
@ -17,8 +17,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "uhttpd.h"
|
#include "uhttpd.h"
|
||||||
#include "uh_ssl.h"
|
#include "uh_ssl.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
static bool _init = false;
|
static bool _init = false;
|
||||||
static struct ustream_ssl_ops *ops;
|
static struct ustream_ssl_ops *ops;
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#ifndef __UHTTPD_SSL_H
|
#ifndef __UHTTPD_SSL_H
|
||||||
#define __UHTTPD_SSL_H
|
#define __UHTTPD_SSL_H
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#if (UHTTPD_SSL_SUPPORT)
|
#if (UHTTPD_SSL_SUPPORT)
|
||||||
|
|
||||||
int uh_ssl_init(struct uh_server *srv, const char *key, const char *crt);
|
int uh_ssl_init(struct uh_server *srv, const char *key, const char *crt);
|
||||||
|
|
|
@ -15,9 +15,14 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <libubox/usock.h>
|
#include <libubox/usock.h>
|
||||||
|
#include <libubox/avl-cmp.h>
|
||||||
|
|
||||||
#include "uhttpd.h"
|
#include "uhttpd.h"
|
||||||
#include "uh_ssl.h"
|
#include "uh_ssl.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
static void uh_set_docroot(struct uh_server *srv, const char *docroot)
|
static void uh_set_docroot(struct uh_server *srv, const char *docroot)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#ifndef _UHTTPD_H
|
#ifndef _UHTTPD_H
|
||||||
#define _UHTTPD_H
|
#define _UHTTPD_H
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
void uh_printf(struct uh_client *cl, const char *format, ...)
|
void uh_printf(struct uh_client *cl, const char *format, ...)
|
||||||
|
|
Loading…
Reference in New Issue