Skip to content

Commit 7f564d2

Browse files
committed
in_http: merging HTTP server and working in plugin
Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
1 parent 3ab208c commit 7f564d2

File tree

446 files changed

+94601
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

446 files changed

+94601
-2
lines changed

CMakeLists.txt

+16-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,23 @@ set(WITH_SYSTEM_MALLOC 1)
5454

5555
# Lib: build the core libraries used by Fluent-Bit
5656
add_subdirectory(lib/msgpack-0.5.9)
57-
add_subdirectory(lib/mk_core)
5857
add_subdirectory(lib/jsmn)
58+
if(WITH_IN_HTTP)
59+
set(WITH_PLUGIN_AUTH 0)
60+
set(WITH_PLUGIN_CGI 0)
61+
set(WITH_PLUGIN_CHEETAH 0)
62+
set(WITH_PLUGIN_DIRLISTING 0)
63+
set(WITH_PLUGIN_FASTCGI 0)
64+
set(WITH_PLUGIN_LIANA 1)
65+
set(WITH_PLUGIN_LOGGER 0)
66+
set(WITH_PLUGIN_MANDRIL 0)
67+
set(WITH_PLUGIN_TLS 0)
68+
set(WITH_SYSTEM_MALLOC 1)
69+
add_subdirectory(lib/monkey)
70+
else()
71+
add_subdirectory(lib/monkey/mk_core)
72+
endif()
73+
5974

6075
# SSL/TLS: add encryption support
6176
if(WITH_SSL_TLS)

lib/monkey/.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
*.[aod]
2+
*~
3+
*.so*
4+
*.pyc
5+
bin/*
6+
Makefile
7+
mk_env.h
8+
mk_info.h
9+
*.dpkg
10+
*.pc
11+
*.lo
12+
tags
13+
*.log
14+
logs/*
15+
callgrind.out.*
16+
tests/lib/bin/*
17+
plugins.conf
18+
plugins.list
19+
plugins/Make.common
20+
plugins/auth/mk_passwd
21+
lib/python/monkey.c
22+
lib/python/bin/*
23+
lib/python/conf/*
24+
lib/python/jemalloc.config
25+
src/include/
26+
build/
27+
include/monkey/mk_static_plugins.h

lib/monkey/.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: c
2+
compiler:
3+
- gcc
4+
- clang
5+
6+
notifications:
7+
irc: "irc.freenode.net#monkey"
8+
9+
# Disable SSL as the test box have a old PolarSSL version (Ubuntu 12.04)
10+
# before_install:
11+
# - sudo apt-get update -qq
12+
# - sudo apt-get install -y libpolarssl-dev
13+
14+
script: ./configure --trace && make

lib/monkey/CMakeLists.txt

+319
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
# Let's have fun!
2+
3+
cmake_minimum_required(VERSION 2.8)
4+
project(monkey C)
5+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
6+
set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
7+
8+
# CMake includes
9+
include(CheckSymbolExists)
10+
include(CheckLibraryExists)
11+
include(CheckIncludeFile)
12+
include(ExternalProject)
13+
include(GNUInstallDirs)
14+
15+
# Set default compiler options
16+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra")
17+
18+
# Monkey Version
19+
set(MK_VERSION_MAJOR 1)
20+
set(MK_VERSION_MINOR 6)
21+
set(MK_VERSION_PATCH 0)
22+
set(MK_VERSION_STR "${MK_VERSION_MAJOR}.${MK_VERSION_MINOR}.${MK_VERSION_PATCH}")
23+
24+
# ============================================
25+
# ============= BUILD OPTIONS ================
26+
# ============================================
27+
28+
# Project
29+
option(BUILD_LOCAL "Build locally, no install" No)
30+
31+
# Monkey Core
32+
option(WITH_DEBUG "Build with debug symbols" No)
33+
option(WITH_ACCEPT "Use accept(2) system call" No)
34+
option(WITH_ACCEPT4 "Use accept4(2) system call" Yes)
35+
option(WITH_LINUX_KQUEUE "Use Linux kqueue emulator" No)
36+
option(WITH_TRACE "Enable Trace mode" No)
37+
option(WITH_UCLIB "Enable uClib libc support" No)
38+
option(WITH_MUSL "Enable Musl libc support" No)
39+
option(WITH_BACKTRACE "Enable Backtrace feature" Yes)
40+
option(WITH_LINUX_TRACE "Enable Lttng support" No)
41+
option(WITH_PTHREAD_TLS "Use old Pthread TLS mode" No)
42+
option(WITH_SYSTEM_MALLOC "Use system memory allocator" No)
43+
44+
# Plugins: what should be build ?, these options
45+
# will be processed later on the plugins/CMakeLists.txt file
46+
option(WITH_PLUGIN_AUTH "Basic authentication" Yes)
47+
option(WITH_PLUGIN_CGI "CGI support" No)
48+
option(WITH_PLUGIN_CHEETAH "Cheetah Shell Interface" Yes)
49+
option(WITH_PLUGIN_DIRLISTING "Directory Listing" Yes)
50+
option(WITH_PLUGIN_FASTCGI "FastCGI" No)
51+
option(WITH_PLUGIN_LIANA "Basic network layer" Yes)
52+
option(WITH_PLUGIN_LOGGER "Log Writer" Yes)
53+
option(WITH_PLUGIN_MANDRIL "Security" Yes)
54+
option(WITH_PLUGIN_TLS "TLS/SSL support" No)
55+
56+
# Options to build Monkey with/without binary and
57+
# static/dynamic library modes (default is always just
58+
# one target binary).
59+
option(WITHOUT_BIN "Do not build binary" No)
60+
option(WITH_STATIC_LIB_MODE "Static library mode" No)
61+
62+
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
63+
set(WITH_ACCEPT 1)
64+
set(WITH_ACCEPT4 0)
65+
set(WITH_SYSTEM_MALLOC 1)
66+
endif()
67+
68+
# This variable allows to define a list of plugins that must
69+
# be included when building the project. The value are the plugins
70+
# names separated by a colon, e.g: -DWITH_PLUGINS=cgi,mbedtls
71+
if(WITH_PLUGINS)
72+
string(REPLACE "," ";" plugins ${WITH_PLUGINS})
73+
foreach(name ${plugins})
74+
message(STATUS "Plugin force enable: ${name}")
75+
string(TOUPPER ${name} NAME)
76+
set(WITH_PLUGIN_${NAME} 1)
77+
endforeach()
78+
endif()
79+
80+
if(WITHOUT_PLUGINS)
81+
string(REPLACE "," ";" plugins ${WITHOUT_PLUGINS})
82+
foreach(name ${plugins})
83+
message(STATUS "Plugin force disable: ${name}")
84+
string(TOUPPER ${name} NAME)
85+
set(WITH_PLUGIN_${NAME} 0)
86+
endforeach()
87+
endif()
88+
89+
if(STATIC_PLUGINS)
90+
set(STATIC_PLUGINS "${STATIC_PLUGINS},liana")
91+
else()
92+
set(STATIC_PLUGINS "liana")
93+
endif()
94+
95+
# Variable to be populated by plugins/CMakeLists.txt. It will contain the
96+
# code required to initialize any static plugin.
97+
set(STATIC_PLUGINS_INIT "")
98+
set(STATIC_PLUGINS_LIBS "")
99+
100+
# ===========================================
101+
# ============== DEPENDENCIES ===============
102+
# ===========================================
103+
104+
# Find pthreads
105+
find_package(Threads)
106+
107+
if(WITH_DEBUG)
108+
set(CMAKE_BUILD_TYPE "Debug")
109+
endif()
110+
111+
# Check for accept(2) v/s accept(4)
112+
if(WITH_ACCEPT)
113+
set(WITH_ACCEPT4 No)
114+
add_definitions(-DACCEPT_GENERIC)
115+
elseif(WITH_ACCEPT4)
116+
# accept(4) requires _GNU_SOURCE defined
117+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
118+
check_symbol_exists(accept4 sys/socket.h HAVE_ACCEPT4)
119+
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
120+
121+
# check the results
122+
if(NOT HAVE_ACCEPT4)
123+
# switch back to accept(2)
124+
set(WITH_ACCEPT Yes)
125+
endif()
126+
endif()
127+
128+
# Check for Linux Kqueue library emulator
129+
if(WITH_LINUX_KQUEUE)
130+
find_package(Libkqueue REQUIRED)
131+
if(NOT LIBKQUEUE_FOUND)
132+
message(FATAL_ERROR "Linux libkqueue was not found." )
133+
else()
134+
add_definitions(-DLINUX_KQUEUE)
135+
endif()
136+
endif()
137+
138+
# Check Trace
139+
if(WITH_TRACE)
140+
add_definitions(-DTRACE)
141+
endif()
142+
143+
# Check Uclib library
144+
if(WITH_UCLIB)
145+
add_definitions(-DUCLIB_MODE)
146+
endif()
147+
148+
# Check Musl library
149+
if(WITH_MUSL)
150+
add_definitions(-DMUSL_MODE)
151+
endif()
152+
153+
# Check Backtrace support
154+
if(WITH_BACKTRACE)
155+
check_include_file("execinfo.h" HAVE_BACKTRACE)
156+
if (NOT HAVE_BACKTRACE)
157+
set(WITH_BACKTRACE No)
158+
endif()
159+
else()
160+
add_definitions(-DNO_BACKTRACE)
161+
endif()
162+
163+
# Check for LTTng-UST
164+
if(WITH_LINUX_TRACE)
165+
check_include_file("lttng/tracepoint.h" HAVE_LTTNG)
166+
if (NOT HAVE_LTTNG)
167+
message(FATAL_ERROR "LTTng-UST is not installed in your system." )
168+
else()
169+
add_definitions(-DLINUX_TRACE)
170+
endif()
171+
endif()
172+
173+
# Use old Pthread TLS
174+
if(WITH_PTHREAD_TLS)
175+
add_definitions(-DPTHREAD_TLS)
176+
endif()
177+
178+
# Use system memory allocator instead of Jemalloc
179+
if(WITH_SYSTEM_MALLOC)
180+
add_definitions(-DMALLOC_LIBC)
181+
else()
182+
# Prepare the Jemalloc build
183+
add_definitions(-DMALLOC_JEMALLOC)
184+
add_definitions(-DJEMALLOC_MANGLE)
185+
186+
# Link to Jemalloc as an external dependency
187+
ExternalProject_Add(jemalloc
188+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/jemalloc
189+
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/deps/jemalloc/configure --with-jemalloc-prefix=je_ --enable-cc-silence --prefix=<INSTALL_DIR>
190+
CFLAGS=-std=gnu99\ -Wall\ -pipe\ -g3\ -O3\ -funroll-loops
191+
BUILD_COMMAND ${MAKE}
192+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/
193+
INSTALL_COMMAND $(MAKE) install_lib_static install_include)
194+
195+
add_library(libjemalloc STATIC IMPORTED GLOBAL)
196+
set_target_properties(libjemalloc PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/lib/libjemalloc_pic.a")
197+
add_dependencies(libjemalloc jemalloc)
198+
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include/")
199+
endif()
200+
201+
# ============================================
202+
# =========== CONFIGURATION FILES=============
203+
# ============================================
204+
205+
# Default values for conf/monkey.conf
206+
set(MK_CONF_LISTEN "2001")
207+
set(MK_CONF_WORKERS "0")
208+
set(MK_CONF_TIMEOUT "15")
209+
set(MK_CONF_PIDFILE "monkey.pid")
210+
set(MK_CONF_USERDIR "public_html")
211+
set(MK_CONF_INDEXFILE "index.html index.htm index.php")
212+
set(MK_CONF_HIDEVERSION "Off")
213+
set(MK_CONF_RESUME "On")
214+
set(MK_CONF_USER "www-data")
215+
set(MK_CONF_KA "On")
216+
set(MK_CONF_KA_TIMEOUT "5")
217+
set(MK_CONF_KA_MAXREQ "1000")
218+
set(MK_CONF_REQ_SIZE "32")
219+
set(MK_CONF_SYMLINK "Off")
220+
set(MK_CONF_TRANSPORT "liana")
221+
set(MK_CONF_DEFAULT_MIME "text/plain")
222+
set(MK_CONF_FDT "On")
223+
set(MK_CONF_OVERCAPACITY "Resist")
224+
225+
# Default values for conf/sites/default
226+
set(MK_VH_SERVERNAME "127.0.0.1")
227+
set(MK_VH_DOCUMENT_ROOT MK_DATADIR)
228+
set(MK_VH_LOG_ACCESS MK_LOGDIR)
229+
set(MK_VH_LOG_ERROR MK_LOGDIR)
230+
231+
232+
# Paths
233+
if(BUILD_LOCAL)
234+
# This mode aims to be backward compatible with older versions of Monkey where
235+
# a './configure && make' were enough to have the server running without installing
236+
# any component.
237+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
238+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/monkey")
239+
set(MK_PATH_CONF "${CMAKE_CURRENT_BINARY_DIR}/conf/")
240+
set(MK_PATH_PIDFILE "${CMAKE_CURRENT_BINARY_DIR}")
241+
set(MK_PATH_WWW "${CMAKE_CURRENT_BINARY_DIR}/../htdocs/")
242+
set(MK_PATH_LOG "${CMAKE_CURRENT_BINARY_DIR}/log/")
243+
file(MAKE_DIRECTORY ${MK_PATH_LOG})
244+
else()
245+
# Custom SYSCONFDIR
246+
if(NOT INSTALL_SYSCONFDIR)
247+
set(MK_PATH_CONF ${CMAKE_INSTALL_FULL_SYSCONFDIR}/monkey/ CACHE STRING "Server configuration")
248+
else()
249+
set(MK_PATH_CONF ${INSTALL_SYSCONFDIR}/ CACHE STRING "Server configuration")
250+
endif()
251+
252+
# Custom LOGDIR
253+
if(NOT INSTALL_LOGDIR)
254+
set(MK_PATH_LOG ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/monkey CACHE STRING "Server logs")
255+
else()
256+
set(MK_PATH_LOG ${INSTALL_LOGDIR} CACHE STRING "Server logs")
257+
endif()
258+
259+
# Custom PIDFILE
260+
if(NOT PID_FILE)
261+
set(MK_PATH_PIDFILE ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run CACHE STRING "Server PID")
262+
else()
263+
set(MK_PATH_PIDFILE ${PID_FILE} CACHE STRING "Server PID")
264+
endif()
265+
266+
# Custom WEBROOT
267+
if(NOT INSTALL_WEBROOTDIR)
268+
set(MK_PATH_WWW ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/www/monkey CACHE STRING "Server Web documents")
269+
else()
270+
set(MK_PATH_WWW ${INSTALL_WEBROOTDIR} CACHE STRING "Server Web documents")
271+
endif()
272+
273+
# Headers
274+
if(NOT INSTALL_INCLUDEDIR)
275+
set(MK_PATH_HEADERS ${CMAKE_INSTALL_INCLUDEDIR}/monkey CACHE STRING "Server header files (development)")
276+
else()
277+
set(MK_PATH_HEADERS ${INSTALL_INCLUDEDIR} CACHE STRING "Server header files (development)")
278+
endif()
279+
endif()
280+
281+
configure_file(
282+
"${PROJECT_SOURCE_DIR}/include/monkey/mk_info.h.in"
283+
"${PROJECT_SOURCE_DIR}/include/monkey/mk_info.h"
284+
)
285+
286+
configure_file(
287+
"${PROJECT_SOURCE_DIR}/include/monkey/mk_env.h.in"
288+
"${PROJECT_SOURCE_DIR}/include/monkey/mk_env.h"
289+
)
290+
291+
292+
# General Headers
293+
include_directories(./)
294+
include_directories(include)
295+
include_directories(monkey)
296+
297+
# Instruct CMake to build the the code base
298+
# =========================================
299+
# mk_core : generic utilities
300+
# plugins : plugins for mk_server
301+
# mk_server: server code base: plugins, protocols, scheduler.. (no executable)
302+
# mk_bin : server executable
303+
#
304+
add_subdirectory(mk_core)
305+
add_subdirectory(plugins)
306+
add_subdirectory(mk_server)
307+
if(NOT WITHOUT_BIN)
308+
add_subdirectory(mk_bin)
309+
endif()
310+
311+
# Configuration, headers generation and others
312+
add_subdirectory(conf)
313+
add_subdirectory(htdocs)
314+
add_subdirectory(include)
315+
316+
# Install (missings ?) paths
317+
install(DIRECTORY DESTINATION ${MK_PATH_LOG})
318+
install(DIRECTORY DESTINATION ${MK_PATH_PIDFILE})
319+
install(DIRECTORY DESTINATION ${MK_PATH_WWW})

0 commit comments

Comments
 (0)