2
0

Compare commits

...

4 Commits

Author SHA1 Message Date
77f9f06c2a [tests] disable non-prefix crypt auth (deprecated, not available on all platforms)
Change-Id: I6918c2041737ca228b16b776030f03eff2f9cf23
2023-07-12 16:56:21 +02:00
dd17dcc380 [crypt] some crypt[_r] implementations return NULL instead of a failure token; li_safe_crypt returns FALSE in that case (and clears the buffer)
Change-Id: I74f78b522333023b5d0bfd052ae137895b4b8e2f
2023-07-12 15:51:39 +02:00
52b19412af fix glib g_string_append_len usage (broken with GSTR_LEN macro)
Change-Id: I6e3ba995b6b094f16f49957cf5d1d03099255a61
2023-07-11 00:27:47 +02:00
0c3ee6741d [build] add meson support
drop HAVE_CONFIG_H - we always want #include <lighttpd/config.h> to
work, and HAVE_CONFIG_H is a too generic name anyway.

Change-Id: Ie8dba7dfd82308bd8fc68e36bce6d2584b7a9d96
2023-01-15 19:46:56 +01:00
59 changed files with 1062 additions and 336 deletions

9
contrib/meson.build Normal file
View File

@ -0,0 +1,9 @@
install_data(
'core__cached_html.lua',
'core.lua',
'core__xsendfile.lua',
'secdownload.lua',
'secdownload__secdownload.lua',
install_dir: lua_dir,
install_tag: 'runtime',
)

4
doc/meson.build Normal file
View File

@ -0,0 +1,4 @@
install_man(
'lighttpd2.8',
'lighttpd2-worker.8',
)

View File

@ -0,0 +1 @@
configure_file(output: 'config.h', configuration: conf_data)

View File

@ -45,9 +45,7 @@
# endif
#endif
#ifdef HAVE_CONFIG_H
#include <lighttpd/config.h>
#endif
#define GLIB_DISABLE_DEPRECATION_WARNINGS

View File

@ -1,9 +1,7 @@
#ifndef SYS_SOCKET_H
#define SYS_SOCKET_H
#ifdef HAVE_CONFIG_H
#include <lighttpd/config.h>
#endif
#ifdef _WIN32
#ifndef FD_SETSIZE

View File

@ -84,9 +84,11 @@ LI_API void li_string_append_int(GString *dest, gint64 val);
LI_API void li_apr_sha1_base64(GString *dest, const GString *passwd);
LI_API void li_apr_md5_crypt(GString *dest, const GString *password, const GString *salt);
LI_API void li_safe_crypt(GString *dest, const GString *password, const GString *salt);
/* dest can be empty if salt is invalid (in which case li_safe_crypt returns FALSE) */
LI_API gboolean li_safe_crypt(GString *dest, const GString *password, const GString *salt);
INLINE GString* _li_g_string_append_len(GString *s, const gchar *val, gssize len);
/* g_string_append_len is a macro, and g_string_append_len(s, GSTR_LEN(x)) doesn't work; build inline wrapper */
INLINE GString *li_g_string_append_len(GString *s, const gchar *val, gssize len);
INLINE void li_g_string_clear(GString *s);
INLINE void li_g_string_free(gpointer data);
@ -130,7 +132,7 @@ LI_API gboolean _li_set_sys_error(GError **error, const gchar *msg, const gchar
INLINE void li_path_append_slash(GString *path) {
if (path->len == 0 || path->str[path->len-1] != '/')
g_string_append_len(path, "/", 1);
li_g_string_append_len(path, "/", 1);
}
/** warning: This "GString" does not make sure that there is a terminating '\0', and you shouldn't modify the GString */
@ -142,12 +144,8 @@ INLINE GString li_const_gstring(const gchar *str, gsize len) {
return gs;
}
#ifndef g_string_append_len
# define g_string_append_len _li_g_string_append_len
#endif
INLINE GString* _li_g_string_append_len(GString *s, const gchar *val, gssize len) {
return g_string_insert_len(s, -1, val, len);
INLINE GString* li_g_string_append_len(GString *s, const gchar *val, gssize len) {
return g_string_append_len(s, val, len);
}
INLINE void li_g_string_clear(GString *s) {

3
include/meson.build Normal file
View File

@ -0,0 +1,3 @@
inc_dir = include_directories('.', is_system: true)
subdir('lighttpd')

331
meson.build Normal file
View File

@ -0,0 +1,331 @@
project(
'lighttpd',
'c',
default_options: [
'buildtype=debugoptimized',
'c_std=c99', # gnu99?
],
version: '2.0.0',
license: 'MIT',
)
libexec_dir = get_option('prefix') / get_option('libexecdir')
# include_dir = get_option('prefix') / get_option('includedir')
modules_dir = get_option('prefix') / get_option('libdir') / (meson.project_name() + '-' + meson.project_version())
lua_dir = get_option('prefix') / get_option('datadir') / 'lighttpd2/lua'
compiler = meson.get_compiler('c')
dep_not_found = dependency('', required: false)
if target_machine.system() == 'windows'
add_project_arguments(
'-DNVALGRIND',
language: 'c'
)
# link ws2_32 ?
# ... ?
endif
# ragel to compile parsers
ragel_bin = find_program('ragel')
ragel_gen = generator(
ragel_bin,
output: '@BASENAME@.c',
arguments: ['-C', '-T1', '-o', '@OUTPUT@', '@INPUT@'],
)
ragel_gen_t0 = generator(
ragel_bin,
output: '@BASENAME@.c',
arguments: ['-C', '-T0', '-o', '@OUTPUT@', '@INPUT@'],
)
add_project_arguments(
'-D_FILE_OFFSET_BITS=64',
'-D_LARGEFILE_SOURCE',
'-D_LARGE_FILES',
language: 'c',
)
conf_data = configuration_data()
conf_data.set_quoted('PACKAGE_VERSION', meson.project_version())
conf_data.set_quoted('PACKAGE_NAME', meson.project_name())
conf_data.set_quoted('DEFAULT_LIBEXECDIR', libexec_dir)
conf_data.set_quoted('DEFAULT_LIBDIR', modules_dir)
# if target_machine.system() == 'windows'
# conf_data.set_quoted('DEFAULT_LIBDIR', 'lib')
# endif
conf_data.set_quoted('DEFAULT_LUADIR', lua_dir)
dep_threads = dependency('threads')
dep_gthread = dependency('gthread-2.0', version: '>=2.16')
dep_gmodule = dependency('gmodule-2.0', version: '>=2.16')
# find libev manually
dep_ev = compiler.find_library(
'ev',
has_headers: 'ev.h',
)
if not compiler.has_function(
'ev_time',
prefix: '#include <ev.h>',
dependencies: dep_ev,
)
error('Missing ev_time() in libev')
endif
if get_option('lua')
dep_lua = dependency('lua5.1', 'lua-5.1', 'lua')
opt_dep_lua = dep_lua
conf_data.set10('HAVE_LUA_H', true)
else
dep_lua = disabler()
opt_dep_lua = dep_not_found
endif
if get_option('unwind')
dep_unwind = dependency('libunwind')
conf_data.set10('HAVE_LIBUNWIND', true)
endif
if get_option('openssl')
dep_openssl = dependency('openssl') # should find both ssl and crypto
else
dep_openssl = disabler()
endif
if get_option('gnutls')
dep_gnutls = dependency('gnutls')
else
dep_gnutls = disabler()
endif
if get_option('sni')
opt_dep_idn = declare_dependency(
compile_args: '-DUSE_SNI',
dependencies: dependency('libidn')
)
else
opt_dep_idn = dep_not_found
endif
if get_option('bzip2')
opt_dep_bzip2 = compiler.find_library(
'bz2',
has_headers: 'bzlib.h',
)
if not compiler.has_function(
'BZ2_bzCompressInit',
prefix: '#include <bzlib.h>',
dependencies: opt_dep_bzip2,
)
error('Found libbz2, but missing BZ2_bzCompressInit()')
endif
conf_data.set10('HAVE_BZIP', true)
else
opt_dep_bzip2 = dep_not_found
endif
if get_option('deflate') ## zlib/gzip??
opt_dep_zlib = dependency('zlib')
conf_data.set10('HAVE_ZLIB', true)
else
opt_dep_zlib = dep_not_found
endif
if opt_dep_bzip2.found() or opt_dep_zlib.found()
dep_deflate = declare_dependency(dependencies: [opt_dep_bzip2, opt_dep_zlib])
else
dep_deflate = disabler()
endif
warn_c_args = [
'-Wshadow',
'-W',
'-pedantic',
]
warn_link_args = []
if get_option('extra-warnings')
warn_c_args += [
'-Wmissing-declarations',
'-Wdeclaration-after-statement',
'-Wcast-align',
'-Wsign-compare',
'-Wnested-externs',
'-Wpointer-arith',
'-Wmissing-prototypes',
'-Wshadow',
'-Wno-pointer-sign',
'-Wformat-security',
]
endif
check_sys_includes = [
'inttypes.h',
'stddef.h',
'stdint.h',
'sys/mman.h',
'sys/resource.h',
'sys/sendfile.h',
'sys/types.h',
'sys/uio.h',
'sys/un.h',
'unistd.h',
]
if get_option('profiler')
check_sys_includes += ['execinfo.h']
add_project_arguments(
'-DWITH_PROFILER',
language: 'c'
)
endif
check_libc_functions = [
'getrlimit',
'gmtime_r',
'inet_aton',
'inet_ntop',
'localtime_r',
'madvise',
'mmap',
'posix_fadvise',
'sendfile',
'sendfile64',
'sendfilev',
'writev',
'accept4',
]
# run compiler/env checks
foreach sys_include: check_sys_includes
if compiler.has_header(sys_include)
conf_data.set10('HAVE_' + sys_include.underscorify().to_upper(), true)
endif
endforeach
foreach libc_function: check_libc_functions
if compiler.has_function(libc_function)
conf_data.set10('HAVE_' + libc_function.underscorify().to_upper(), true)
endif
endforeach
add_project_arguments(
compiler.get_supported_arguments(warn_c_args),
language: 'c'
)
add_project_link_arguments(
compiler.get_supported_link_arguments(warn_link_args),
language: 'c'
)
# manual libcrypt with crypt_r check
lib_crypt = compiler.find_library(
'crypt',
required: false,
has_headers: 'crypt.h',
)
if lib_crypt.found()
if compiler.has_function(
'crypt_r',
prefix: '#include <crypt.h>',
dependencies: lib_crypt,
)
conf_data.set10('HAVE_CRYPT_H', true)
conf_data.set10('HAVE_CRYPT_R', true)
else
error('Found libcrypt, but missing crypt_r')
endif
else
warning('Missing libcrypt, using crypt instead of crypt_r')
endif
# need libm for fmod in throttle.c
lib_m = compiler.find_library('m')
# IPv6 support is mandatory by default
if get_option('ipv6')
if compiler.has_type(
'struct sockaddr_in6',
prefix: [
'#include <sys/types.h>',
'#include <sys/socket.h>',
'#include <netinet/in.h>',
],
)
conf_data.set10('HAVE_IPV6', true)
else
error('Missing struct sockaddr_in6, needed for IPv6 support')
endif
endif
# auto detect 'struct sockaddr_storage' - should work fine without it.
if compiler.has_type(
'struct sockaddr_storage',
prefix: '#include <sys/socket.h>',
)
conf_data.set10('HAVE_SOCKADDR_STORAGE', true)
endif
if target_machine.system() == 'freebsd'
lib_kvm = compiler.find_library(
'kvm',
has_headers: 'kvm.h',
)
if not compiler.has_function(
'kvm_open',
prefix: '#include <kvm.h>',
dependencies: lib_kvm,
)
error('Found libkvm, but missing kvm_open')
endif
else
lib_kvm = dep_not_found
endif
main_deps = [
dep_threads,
dep_gthread,
dep_gmodule,
dep_ev,
]
subdir('contrib')
subdir('doc')
subdir('include')
subdir('src')
subdir('tests')
summary(
{
'libexec path': libexec_dir,
'modules path': modules_dir,
'lua plugin path': lua_dir,
},
section: 'Paths',
)
summary(
{
'lua': get_option('lua'),
'ipv6': get_option('ipv6'),
'config-parser': get_option('config-parser'),
'unwind': get_option('unwind'),
'openssl': get_option('openssl'),
'gnutls': get_option('gnutls'),
'sni': get_option('sni'),
'bzip2': get_option('bzip2'),
'deflate': get_option('deflate'),
'profiler': get_option('profiler'),
},
section: 'Features',
)
summary(
{
'detected libcrypt/crypt_r()': lib_crypt.found(),
'detected mmap()': conf_data.get('HAVE_MMAP', 0) == 1,
'detected writev()': conf_data.get('HAVE_WRITEV', 0) == 1,
'detected sendfile*()': (
conf_data.get('HAVE_SENDFILE', 0) == 1
or conf_data.get('HAVE_SENDFILE64', 0) == 1
or conf_data.get('HAVE_SENDFILEV', 0) == 1
),
},
section: 'Detected',
)

12
meson_options.txt Normal file
View File

@ -0,0 +1,12 @@
option('lua', type : 'boolean', value : true, description : 'Build with lua (5.1); extends core and other modules, and builds mod_lua')
option('ipv6', type : 'boolean', value : true, description : 'Build with IPv6 support')
option('config-parser', type : 'boolean', value : true, description : 'Build with standard config parser')
option('unwind', type : 'boolean', value : true, description : 'Build with (lib)unwind support in asserts to print backtraces')
option('openssl', type : 'boolean', value : true, description : 'Build mod_openssl')
option('gnutls', type : 'boolean', value : true, description : 'Build mod_gnutls')
option('sni', type : 'boolean', value : true, description : 'Build mod_openssl/mod_gnutls with SNI support')
option('bzip2', type : 'boolean', value : true, description : 'Build mod_deflate with bzip2 support')
option('deflate', type : 'boolean', value : true, description : 'Build mod_deflate with zlib (deflate) support')
option('extra-warnings', type : 'boolean', value : true, description : 'Build with extra warnings enabled')
# option('static', type : 'boolean', value : false, description : 'Build static lighttpd with all modules included')
option('profiler', type : 'boolean', value : false, description : 'Build with memory profiler')

View File

@ -93,7 +93,7 @@ GQuark li_angel_config_parser_error_quark(void) {
}
action name {
g_string_append_len(ctx->token_string, ctx->mark, fpc - ctx->mark);
li_g_string_append_len(ctx->token_string, ctx->mark, fpc - ctx->mark);
return TK_NAME;
}
@ -617,7 +617,7 @@ static gboolean op_execute(liValue **vresult, liConfigToken op, liValue *v1, liV
case LI_VALUE_STRING:
switch (op) {
case TK_PLUS:
g_string_append_len(v1->data.string, GSTR_LEN(v2->data.string));
li_g_string_append_len(v1->data.string, GSTR_LEN(v2->data.string));
*vresult = v1;
v1 = NULL;
break;

View File

@ -52,14 +52,14 @@ void li_log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar
srv->log.last_ts = li_cur_ts;
}
g_string_append_len(log_line, GSTR_LEN(log_ts));
li_g_string_append_len(log_line, GSTR_LEN(log_ts));
}
va_start(ap, fmt);
g_string_append_vprintf(log_line, fmt, ap);
va_end(ap);
g_string_append_len(log_line, CONST_STR_LEN("\n"));
li_g_string_append_len(log_line, CONST_STR_LEN("\n"));
fprintf(stderr, "%s", log_line->str);
}

36
src/angel/meson.build Normal file
View File

@ -0,0 +1,36 @@
src_angel_shared = [
'angel_log.c',
'angel_plugin.c',
'angel_plugin_core.c',
'angel_proc.c',
'angel_server.c',
'angel_value.c',
] + ragel_gen.process(
'angel_config_parser.rl',
)
lib_shared_angel = library(
'lighttpd-' + meson.project_version() + '-sharedangel',
src_angel_shared,
include_directories: inc_dir,
dependencies: [
main_deps,
],
link_with: lib_common,
install: true,
)
bin_angel = executable(
'lighttpd2',
'angel_main.c',
include_directories: inc_dir,
dependencies: [
main_deps,
],
link_with: [
lib_common,
lib_shared_angel,
],
install: true,
install_dir: get_option('sbindir')
)

View File

@ -575,8 +575,8 @@ static gboolean prepare_call_header(GString **pbuf,
if (!li_angel_data_write_int32(buf, fd_count, err)) return FALSE;
if (type != ANGEL_CALL_SEND_RESULT) {
g_string_append_len(buf, mod, mod_len);
g_string_append_len(buf, action, action_len);
li_g_string_append_len(buf, mod, mod_len);
li_g_string_append_len(buf, action, action_len);
}
return TRUE;

View File

@ -20,19 +20,19 @@ static gboolean error_eof(GError **err, const gchar *info) {
gboolean li_angel_data_write_int32(GString *buf, gint32 i, GError **err) {
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
g_string_append_len(buf, (const gchar*) &i, sizeof(i));
li_g_string_append_len(buf, (const gchar*) &i, sizeof(i));
return TRUE;
}
gboolean li_angel_data_write_int64(GString *buf, gint64 i, GError **err) {
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
g_string_append_len(buf, (const gchar*) &i, sizeof(i));
li_g_string_append_len(buf, (const gchar*) &i, sizeof(i));
return TRUE;
}
gboolean li_angel_data_write_char (GString *buf, gchar c, GError **err) {
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
g_string_append_len(buf, &c, sizeof(c));
li_g_string_append_len(buf, &c, sizeof(c));
return TRUE;
}
@ -46,7 +46,7 @@ gboolean li_angel_data_write_str (GString *buf, const GString *str, GError **er
return FALSE;
}
if (!li_angel_data_write_int32(buf, str->len, err)) return FALSE;
g_string_append_len(buf, GSTR_LEN(str));
li_g_string_append_len(buf, GSTR_LEN(str));
return TRUE;
}
@ -106,7 +106,7 @@ gboolean li_angel_data_read_mem (liAngelBuffer *buf, GString **val, gsize len,
} else {
g_string_truncate(s, 0);
}
g_string_append_len(s, buf->data->str + buf->pos, len);
li_g_string_append_len(s, buf->data->str + buf->pos, len);
buf->pos += len;
return TRUE;
}

38
src/common/meson.build Normal file
View File

@ -0,0 +1,38 @@
src_common = [
'angel_connection.c',
'angel_data.c',
'buffer.c',
'encoding.c',
'events.c',
'fetch.c',
'idlist.c',
'jobqueue.c',
'memcached.c',
'mempool.c',
'module.c',
'radix.c',
'sys_memory.c',
'sys_socket.c',
'tasklet.c',
'utils.c',
'value.c',
# 'value_impl.c', -- "templated", gets included in main and angel
'waitqueue.c',
] + ragel_gen.process('ip_parsers.rl')
if get_option('profiler')
src_common += ['profiler.c']
endif
lib_common = library(
'lighttpd-' + meson.project_version() + '-common',
src_common,
include_directories: inc_dir,
dependencies: [
main_deps,
dep_unwind,
lib_crypt,
lib_kvm,
],
install: true,
)

View File

@ -1,5 +1,6 @@
#include <lighttpd/module.h>
#include <lighttpd/utils.h>
liModules *li_modules_new(gpointer main, const gchar *module_dir, gboolean module_resident) {
liModules *m = g_slice_new(liModules);
@ -77,9 +78,9 @@ liModule* li_module_load(liModules *mods, const gchar* name) {
/* temporary strings for mod_xyz_init and mod_xyz_free */
m_init_str = g_string_new(name);
g_string_append_len(m_init_str, CONST_STR_LEN("_init"));
li_g_string_append_len(m_init_str, CONST_STR_LEN("_init"));
m_free_str = g_string_new(name);
g_string_append_len(m_free_str, CONST_STR_LEN("_free"));
li_g_string_append_len(m_free_str, CONST_STR_LEN("_free"));
if (!g_module_symbol(mod->module, m_init_str->str, (gpointer *)&m_init)
|| !g_module_symbol(mod->module, m_free_str->str, (gpointer *)&mod->free)

View File

@ -628,12 +628,12 @@ GString *li_sockaddr_to_string(liSocketAddress addr, GString *dest, gboolean sho
dest = g_string_sized_new(0);
else
g_string_truncate(dest, 0);
g_string_append_len(dest, CONST_STR_LEN("unix:"));
li_g_string_append_len(dest, CONST_STR_LEN("unix:"));
{
const char* path_start = saddr_up.un->sun_path;
const char* path_end = ((const char*)saddr_up.un) + addr.len;
size_t path_len = path_end - path_start;
g_string_append_len(dest, path_start, strnlen(path_start, path_len));
li_g_string_append_len(dest, path_start, strnlen(path_start, path_len));
}
break;
#endif
@ -807,7 +807,7 @@ gboolean li_string_prefix(const GString *str, const gchar *s, gsize len) {
GString *li_string_assign_len(GString *string, const gchar *val, gssize len) {
g_string_truncate(string, 0);
g_string_append_len(string, val, len);
li_g_string_append_len(string, val, len);
return string;
}
@ -902,7 +902,7 @@ void li_apr_sha1_base64(GString *dest, const GString *passwd) {
static void md5_crypt_to64(GString *dest, guint number, guint len) {
static const gchar code[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for ( ; len-- > 0; ) {
g_string_append_len(dest, code + (number & 63), 1);
li_g_string_append_len(dest, code + (number & 63), 1);
number /= 64;
}
}
@ -979,9 +979,9 @@ void li_apr_md5_crypt(GString *dest, const GString *password, const GString *sal
}
li_g_string_clear(dest);
g_string_append_len(dest, CONST_STR_LEN(APR1_MAGIC));
g_string_append_len(dest, rsalt.str, rsalt.len);
g_string_append_len(dest, CONST_STR_LEN("$"));
li_g_string_append_len(dest, CONST_STR_LEN(APR1_MAGIC));
li_g_string_append_len(dest, rsalt.str, rsalt.len);
li_g_string_append_len(dest, CONST_STR_LEN("$"));
md5_crypt_to64(dest, (digest[ 0] << 16) | (digest[ 6] << 8) | digest[12], 4);
md5_crypt_to64(dest, (digest[ 1] << 16) | (digest[ 7] << 8) | digest[13], 4);
md5_crypt_to64(dest, (digest[ 2] << 16) | (digest[ 8] << 8) | digest[14], 4);
@ -990,16 +990,23 @@ void li_apr_md5_crypt(GString *dest, const GString *password, const GString *sal
md5_crypt_to64(dest, digest[11] , 2);
}
void li_safe_crypt(GString *dest, const GString *password, const GString *salt) {
gboolean li_safe_crypt(GString *dest, const GString *password, const GString *salt) {
g_string_truncate(dest, 0);
if (g_str_has_prefix(salt->str, "$apr1$")) {
li_apr_md5_crypt(dest, password, salt);
return TRUE;
} else {
const char *crypt_res;
#ifdef HAVE_CRYPT_R
struct crypt_data buffer;
memset(&buffer, 0, sizeof(buffer));
g_string_assign(dest, crypt_r(password->str, salt->str, &buffer));
crypt_res = crypt_r(password->str, salt->str, &buffer);
if (NULL != crypt_res) {
g_string_assign(dest, crypt_res);
}
#else
/* This is an acceptable hack: any library that uses crypt() itself is "broken"
* for threaded usage anyway; and our own usage is protected.
@ -1007,9 +1014,13 @@ void li_safe_crypt(GString *dest, const GString *password, const GString *salt)
static GStaticMutex crypt_mutex = G_STATIC_MUTEX_INIT;
g_static_mutex_lock(&crypt_mutex);
g_string_assign(dest, crypt(password->str, salt->str));
crypt_res = crypt(password->str, salt->str);
if (NULL != crypt_res) {
g_string_assign(dest, crypt_res);
}
g_static_mutex_unlock(&crypt_mutex);
#endif
return crypt_res != NULL;
}
}

View File

@ -48,7 +48,7 @@ GString *li_common_value_to_string_(liValue *val) {
break;
case LI_VALUE_STRING:
str = g_string_new_len(CONST_STR_LEN("\""));
g_string_append_len(str, GSTR_LEN(val->data.string));
li_g_string_append_len(str, GSTR_LEN(val->data.string));
g_string_append_c(str, '"');
break;
case LI_VALUE_LIST:
@ -59,7 +59,7 @@ GString *li_common_value_to_string_(liValue *val) {
g_string_free(tmp, TRUE);
for (guint i = 1; i < val->data.list->len; i++) {
tmp = li_value_to_string(g_ptr_array_index(val->data.list, i));
g_string_append_len(str, CONST_STR_LEN(", "));
li_g_string_append_len(str, CONST_STR_LEN(", "));
g_string_append(str, tmp->str);
g_string_free(tmp, TRUE);
}

View File

@ -823,7 +823,7 @@ gboolean li_chunkqueue_extract_to(liChunkQueue *cq, goffset len, GString *dest,
gchar *buf;
off_t we_have;
if (LI_HANDLER_GO_ON != li_chunkiter_read(ci, coff, len, &buf, &we_have, err)) goto error;
g_string_append_len(dest, buf, we_have);
li_g_string_append_len(dest, buf, we_have);
coff += we_have;
len -= we_have;
if (len <= 0) return TRUE;

View File

@ -74,7 +74,7 @@ gboolean li_chunk_extract_to(liChunkParserMark from, liChunkParserMark to, GStri
dest->len += we_have;
dest->str[dest->len] = '\0';
} else {
g_string_append_len(dest, buf, we_have);
li_g_string_append_len(dest, buf, we_have);
}
i.pos += we_have;
}
@ -90,7 +90,7 @@ gboolean li_chunk_extract_to(liChunkParserMark from, liChunkParserMark to, GStri
dest->len += we_have;
dest->str[dest->len] = '\0';
} else {
g_string_append_len(dest, buf, we_have);
li_g_string_append_len(dest, buf, we_have);
}
i.pos += we_have;
}

View File

@ -141,7 +141,7 @@ GQuark li_config_error_quark(void) {
}
action name {
g_string_append_len(ctx->token_string, ctx->mark, fpc - ctx->mark);
li_g_string_append_len(ctx->token_string, ctx->mark, fpc - ctx->mark);
return TK_NAME;
}
@ -824,7 +824,7 @@ static gboolean op_execute(liValue **vresult, liConfigToken op, liValue *v1, liV
case LI_VALUE_STRING:
switch (op) {
case TK_PLUS:
g_string_append_len(v1->data.string, GSTR_LEN(v2->data.string));
li_g_string_append_len(v1->data.string, GSTR_LEN(v2->data.string));
*vresult = v1;
v1 = NULL;
break;

View File

@ -125,9 +125,9 @@ GString* li_lua_print_get_string(lua_State *L, int from, int to) {
if (0 == len) continue;
if (buf->len > 0) {
g_string_append_c(buf, ' ');
g_string_append_len(buf, s, len);
li_g_string_append_len(buf, s, len);
} else {
g_string_append_len(buf, s, len);
li_g_string_append_len(buf, s, len);
}
}
lua_pop(L, 1);

View File

@ -143,8 +143,8 @@ void li_environment_dup2cgi(liVRequest *vr, liEnvironmentDup *envdup, liAddEnvir
add_env_var(envdup, callback, param, CONST_STR_LEN("PATH_INFO"), GSTR_LEN(vr->physical.pathinfo));
if (vr->physical.pathinfo->len) {
g_string_truncate(tmp, 0);
g_string_append_len(tmp, GSTR_LEN(vr->physical.doc_root)); /* TODO: perhaps an option for alternative doc-root? */
g_string_append_len(tmp, GSTR_LEN(vr->physical.pathinfo));
li_g_string_append_len(tmp, GSTR_LEN(vr->physical.doc_root)); /* TODO: perhaps an option for alternative doc-root? */
li_g_string_append_len(tmp, GSTR_LEN(vr->physical.pathinfo));
add_env_var(envdup, callback, param, CONST_STR_LEN("PATH_TRANSLATED"), GSTR_LEN(tmp));
}
@ -184,9 +184,9 @@ void li_environment_dup2cgi(liVRequest *vr, liEnvironmentDup *envdup, liAddEnvir
const GString hkey = li_const_gstring(h->data->str, h->keylen);
g_string_truncate(tmp, 0);
if (!li_strncase_equal(&hkey, CONST_STR_LEN("CONTENT-TYPE"))) {
g_string_append_len(tmp, CONST_STR_LEN("HTTP_"));
li_g_string_append_len(tmp, CONST_STR_LEN("HTTP_"));
}
g_string_append_len(tmp, h->data->str, h->keylen);
li_g_string_append_len(tmp, h->data->str, h->keylen);
cgi_fix_header_name(tmp);
add_env_var(envdup, callback, param, GSTR_LEN(tmp), h->data->str + h->keylen+2, h->data->len - (h->keylen+2));

View File

@ -123,9 +123,9 @@ void li_etag_mutate(GString *mut, GString *etag) {
for (h=0, i=0; i < etag->len; ++i) h = (h<<5)^(h>>27)^(etag->str[i]);
g_string_truncate(mut, 0);
g_string_append_len(mut, CONST_STR_LEN("\""));
li_g_string_append_len(mut, CONST_STR_LEN("\""));
li_string_append_int(mut, (guint64) h);
g_string_append_len(mut, CONST_STR_LEN("\""));
li_g_string_append_len(mut, CONST_STR_LEN("\""));
}
void li_etag_set_header(liVRequest *vr, struct stat *st, gboolean *cachable) {
@ -144,12 +144,12 @@ void li_etag_set_header(liVRequest *vr, struct stat *st, gboolean *cachable) {
}
if (flags & LI_ETAG_USE_SIZE) {
if (tmp_str->len != 0) g_string_append_len(tmp_str, CONST_STR_LEN("-"));
if (tmp_str->len != 0) li_g_string_append_len(tmp_str, CONST_STR_LEN("-"));
li_string_append_int(tmp_str, st->st_size);
}
if (flags & LI_ETAG_USE_MTIME) {
if (tmp_str->len != 0) g_string_append_len(tmp_str, CONST_STR_LEN("-"));
if (tmp_str->len != 0) li_g_string_append_len(tmp_str, CONST_STR_LEN("-"));
li_string_append_int(tmp_str, st->st_mtime);
}

View File

@ -72,9 +72,9 @@ static gboolean bod_open(bod_state *state) {
const char tmpl[] = "lighttpd-buffer-XXXXXX", basedir[] = "/var/tmp";
tmpfilename = g_string_sized_new((sizeof(basedir) - 1) + 1 + (sizeof(tmpl) - 1));
g_string_append_len(tmpfilename, CONST_STR_LEN(basedir)); /* TODO: add config option */
li_g_string_append_len(tmpfilename, CONST_STR_LEN(basedir)); /* TODO: add config option */
li_path_append_slash(tmpfilename);
g_string_append_len(tmpfilename, CONST_STR_LEN(tmpl));
li_g_string_append_len(tmpfilename, CONST_STR_LEN(tmpl));
fd = g_mkstemp(tmpfilename->str);
if (-1 == fd) {

View File

@ -209,8 +209,8 @@ void li_http_header_get_all(GString *dest, liHttpHeaders *headers, const gchar *
for (l = li_http_header_find_first(headers, key, keylen); l; l = li_http_header_find_next(l, key, keylen)) {
liHttpHeader *h = (liHttpHeader*) l->data;
if (dest->len) g_string_append_len(dest, CONST_STR_LEN(", "));
g_string_append_len(dest, &h->data->str[h->keylen+2], h->data->len - (h->keylen + 2));
if (dest->len) li_g_string_append_len(dest, CONST_STR_LEN(", "));
li_g_string_append_len(dest, &h->data->str[h->keylen+2], h->data->len - (h->keylen + 2));
}
}

View File

@ -351,7 +351,7 @@ static void log_watcher_cb(liEventBase *watcher, int events) {
g_string_prepend_len(msg, GSTR_LEN(ts));
}
g_string_append_len(msg, CONST_STR_LEN("\n"));
li_g_string_append_len(msg, CONST_STR_LEN("\n"));
log = log_open(srv, log_entry->path);

100
src/main/meson.build Normal file
View File

@ -0,0 +1,100 @@
src_shared = [
'angel.c',
'angel_fake.c',
'actions.c',
'base_lua.c',
'backends.c',
'chunk.c',
'chunk_parser.c',
'collect.c',
'condition.c',
'connection.c',
'environment.c',
'etag.c',
'filter.c',
'filter_chunked.c',
'filter_buffer_on_disk.c',
'http_headers.c',
'lighttpd_glue.c',
'log.c',
'mimetype.c',
'network.c',
'network_write.c',
'network_writev.c',
'network_sendfile.c',
'options.c',
'pattern.c',
'plugin.c',
'request.c',
'response.c',
'server.c',
'stat_cache.c',
'stream.c',
'stream_http_response.c',
'stream_simple_socket.c',
'throttle.c',
'value.c',
'virtualrequest.c',
'worker.c',
'plugin_core.c',
] + ragel_gen.process(
'http_range_parser.rl',
'http_request_parser.rl',
'http_response_parser.rl',
'url_parser.rl',
)
if not get_option('config-parser')
conf_data.set10('WITHOUT_CONFIG_PARSER', true)
else
src_shared += ragel_gen_t0.process('config_parser.rl')
endif
if get_option('lua')
src_shared += [
'actions_lua.c',
'condition_lua.c',
'config_lua.c',
'value_lua.c',
'chunk_lua.c',
'core_lua.c',
'environment_lua.c',
'filters_lua.c',
'http_headers_lua.c',
'physical_lua.c',
'request_lua.c',
'response_lua.c',
'stat_lua.c',
'subrequest_lua.c',
'virtualrequest_lua.c',
]
endif
lib_shared = library(
'lighttpd-' + meson.project_version() + '-shared',
src_shared,
include_directories: inc_dir,
dependencies: [
main_deps,
opt_dep_lua,
lib_m, # TODO: fmod in throttle.c
],
link_with: lib_common,
install: true,
)
bin_worker = executable(
'lighttpd2-worker',
'lighttpd_worker.c',
include_directories: inc_dir,
dependencies: [
main_deps,
opt_dep_lua,
],
link_with: [
lib_shared,
lib_common,
],
install: true,
install_dir: libexec_dir,
)

View File

@ -206,7 +206,7 @@ liPattern *li_pattern_new(liServer *srv, const gchar* str) {
/* copy every chunk between escapes into dest buffer */
for (first = c ; *c && '$' != *c && '%' != *c; c++) {
if (*c == '\\') {
if (first != c) g_string_append_len(part.data.str, first, c - first);
if (first != c) li_g_string_append_len(part.data.str, first, c - first);
c++;
first = c;
if (*c != '\\' && *c != '?' && *c != '$' && *c != '%') {
@ -218,7 +218,7 @@ liPattern *li_pattern_new(liServer *srv, const gchar* str) {
}
}
}
if (first != c) g_string_append_len(part.data.str, first, c - first);
if (first != c) li_g_string_append_len(part.data.str, first, c - first);
g_array_append_val(pattern, part);
}
@ -268,7 +268,7 @@ void li_pattern_eval(liVRequest *vr, GString *dest, liPattern *pattern, liPatter
switch (part->type) {
case PATTERN_STRING:
g_string_append_len(dest, GSTR_LEN(part->data.str));
li_g_string_append_len(dest, GSTR_LEN(part->data.str));
break;
case PATTERN_NTH:
if (NULL != nth_callback) {
@ -315,7 +315,7 @@ void li_pattern_array_cb(GString *pattern_result, guint from, guint to, gpointer
for (i = from; i <= to; i++) {
GString *str = g_array_index(a, GString*, i);
if (NULL != str) {
g_string_append_len(pattern_result, GSTR_LEN(str));
li_g_string_append_len(pattern_result, GSTR_LEN(str));
}
}
} else {
@ -323,7 +323,7 @@ void li_pattern_array_cb(GString *pattern_result, guint from, guint to, gpointer
for (i = from + 1; i-- >= to; ) {
GString *str = g_array_index(a, GString*, i);
if (NULL != str) {
g_string_append_len(pattern_result, GSTR_LEN(str));
li_g_string_append_len(pattern_result, GSTR_LEN(str));
}
}
}
@ -340,14 +340,14 @@ void li_pattern_regex_cb(GString *pattern_result, guint from, guint to, gpointer
to = MIN(to, G_MAXINT);
for (i = from; i <= to; i++) {
if (g_match_info_fetch_pos(match_info, (gint) i, &start_pos, &end_pos)) {
g_string_append_len(pattern_result, g_match_info_get_string(match_info) + start_pos, end_pos - start_pos);
li_g_string_append_len(pattern_result, g_match_info_get_string(match_info) + start_pos, end_pos - start_pos);
}
}
} else {
from = MIN(from, G_MAXINT); /* => from+1 is defined */
for (i = from + 1; --i >= to; ) {
if (g_match_info_fetch_pos(match_info, (gint) i, &start_pos, &end_pos)) {
g_string_append_len(pattern_result, g_match_info_get_string(match_info) + start_pos, end_pos - start_pos);
li_g_string_append_len(pattern_result, g_match_info_get_string(match_info) + start_pos, end_pos - start_pos);
}
}
}

View File

@ -16,7 +16,7 @@ static int lua_physical_attr_write_##attr(liPhysical *phys, lua_State *L) { \
luaL_checkstring(L, 3); \
s = lua_tolstring(L, 3, &len); \
g_string_truncate(phys->attr, 0); \
g_string_append_len(phys->attr, s, len); \
li_g_string_append_len(phys->attr, s, len); \
return 0; \
}

View File

@ -117,7 +117,7 @@ static void core_docroot_nth_cb(GString *pattern_result, guint to, guint from, g
/* ranges including 0 will only get the complete hostname */
if (0 == from || 0 == to) {
g_string_append_len(pattern_result, GSTR_LEN(ctx->hostname));
li_g_string_append_len(pattern_result, GSTR_LEN(ctx->hostname));
return;
}
@ -136,7 +136,7 @@ static void core_docroot_nth_cb(GString *pattern_result, guint to, guint from, g
if (first) {
first = FALSE;
} else {
g_string_append_len(pattern_result, CONST_STR_LEN("."));
li_g_string_append_len(pattern_result, CONST_STR_LEN("."));
}
g_string_append(pattern_result, ctx->splits[ctx->split_len - i]);
}
@ -145,7 +145,7 @@ static void core_docroot_nth_cb(GString *pattern_result, guint to, guint from, g
if (first) {
first = FALSE;
} else {
g_string_append_len(pattern_result, CONST_STR_LEN("."));
li_g_string_append_len(pattern_result, CONST_STR_LEN("."));
}
g_string_append(pattern_result, ctx->splits[ctx->split_len - i]);
}
@ -210,10 +210,10 @@ static liHandlerResult core_handle_docroot(liVRequest *vr, gpointer param, gpoin
/* build physical path: docroot + uri.path */
g_string_truncate(vr->physical.path, 0);
g_string_append_len(vr->physical.path, GSTR_LEN(vr->physical.doc_root));
li_g_string_append_len(vr->physical.path, GSTR_LEN(vr->physical.doc_root));
if (vr->request.uri.path->len == 0 || vr->request.uri.path->str[0] != '/')
li_path_append_slash(vr->physical.path);
g_string_append_len(vr->physical.path, GSTR_LEN(vr->request.uri.path));
li_g_string_append_len(vr->physical.path, GSTR_LEN(vr->request.uri.path));
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
VR_DEBUG(vr, "docroot: \"%s\"", vr->physical.doc_root->str);
@ -316,8 +316,8 @@ static liHandlerResult core_handle_alias(liVRequest *vr, gpointer _param, gpoint
/* build physical path: docroot + uri.path */
g_string_truncate(vr->physical.path, 0);
g_string_append_len(vr->physical.path, GSTR_LEN(vr->physical.doc_root));
g_string_append_len(vr->physical.path, vr->request.uri.path->str + preflen, vr->request.uri.path->len - preflen);
li_g_string_append_len(vr->physical.path, GSTR_LEN(vr->physical.doc_root));
li_g_string_append_len(vr->physical.path, vr->request.uri.path->str + preflen, vr->request.uri.path->len - preflen);
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
VR_DEBUG(vr, "alias physical path: %s", vr->physical.path->str);
@ -445,7 +445,7 @@ static liHandlerResult core_handle_index(liVRequest *vr, gpointer param, gpointe
/* we use two temporary strings here, one to append to docroot and one to append to physical path */
tmp_docroot = vr->wrk->tmp_str;
g_string_truncate(tmp_docroot, 0);
g_string_append_len(vr->wrk->tmp_str, GSTR_LEN(vr->physical.doc_root));
li_g_string_append_len(vr->wrk->tmp_str, GSTR_LEN(vr->physical.doc_root));
tmp_path = g_string_new_len(GSTR_LEN(vr->physical.path));
/* loop through the list to find a possible index file */
@ -455,7 +455,7 @@ static liHandlerResult core_handle_index(liVRequest *vr, gpointer param, gpointe
if (file->str[0] == '/') {
/* entries beginning with a slash shall be looked up directly at the docroot */
g_string_truncate(tmp_docroot, vr->physical.doc_root->len);
g_string_append_len(tmp_docroot, GSTR_LEN(file));
li_g_string_append_len(tmp_docroot, GSTR_LEN(file));
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
VR_DEBUG(vr, "trying index file: '%s' -> '%s'", file->str, tmp_docroot->str);
}
@ -470,7 +470,7 @@ static liHandlerResult core_handle_index(liVRequest *vr, gpointer param, gpointe
}
g_string_truncate(tmp_path, vr->physical.path->len);
g_string_append_len(tmp_path, GSTR_LEN(file));
li_g_string_append_len(tmp_path, GSTR_LEN(file));
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
VR_DEBUG(vr, "trying index file: '%s' -> '%s'", file->str, tmp_path->str);
}
@ -490,8 +490,8 @@ static liHandlerResult core_handle_index(liVRequest *vr, gpointer param, gpointe
g_string_truncate(vr->request.uri.path, 0);
}
g_string_append_len(vr->physical.path, GSTR_LEN(file));
g_string_append_len(vr->request.uri.path, GSTR_LEN(file));
li_g_string_append_len(vr->physical.path, GSTR_LEN(file));
li_g_string_append_len(vr->request.uri.path, GSTR_LEN(file));
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
VR_DEBUG(vr, "using index file: '%s'", file->str);
@ -1990,13 +1990,13 @@ static gboolean core_register_fetch_files_static(liServer *srv, liPlugin* p, liV
g_string_truncate(filename, 0);
if (NULL != basedir) {
g_string_append_len(filename, GSTR_LEN(basedir));
li_g_string_append_len(filename, GSTR_LEN(basedir));
li_path_append_slash(filename);
}
g_string_append_len(filename, GSTR_LEN(&entry));
li_g_string_append_len(filename, GSTR_LEN(&entry));
if (NULL != subfile) {
li_path_append_slash(filename);
g_string_append_len(filename, GSTR_LEN(subfile));
li_g_string_append_len(filename, GSTR_LEN(subfile));
}
if (!g_file_test(filename->str, G_FILE_TEST_IS_REGULAR)) continue;

View File

@ -110,7 +110,7 @@ static gboolean request_parse_url(liVRequest *vr) {
li_path_simplify(req->uri.path);
if (0 == req->uri.raw_orig_path->len) {
g_string_append_len(req->uri.raw_orig_path, GSTR_LEN(req->uri.raw_path)); /* save orig raw uri */
li_g_string_append_len(req->uri.raw_orig_path, GSTR_LEN(req->uri.raw_path)); /* save orig raw uri */
}
return TRUE;
@ -123,9 +123,9 @@ gboolean li_request_validate_header(liConnection *con) {
gboolean transfer_encoding_chunked = FALSE;
if (con->info.is_ssl) {
g_string_append_len(req->uri.scheme, CONST_STR_LEN("https"));
li_g_string_append_len(req->uri.scheme, CONST_STR_LEN("https"));
} else {
g_string_append_len(req->uri.scheme, CONST_STR_LEN("http"));
li_g_string_append_len(req->uri.scheme, CONST_STR_LEN("http"));
}
switch (req->http_version) {
@ -157,7 +157,7 @@ gboolean li_request_validate_header(liConnection *con) {
}
hh = (liHttpHeader*) l->data;
g_string_append_len(req->uri.authority, LI_HEADER_VALUE_LEN(hh));
li_g_string_append_len(req->uri.authority, LI_HEADER_VALUE_LEN(hh));
/* check header after we parsed the url, as it may override uri.authority */
}

View File

@ -163,7 +163,7 @@ static int lua_requesturi_attr_write_##attr(liRequestUri *uri, lua_State *L) { \
luaL_checkstring(L, 3); \
s = lua_tolstring(L, 3, &len); \
g_string_truncate(uri->attr, 0); \
g_string_append_len(uri->attr, s, len); \
li_g_string_append_len(uri->attr, s, len); \
return 0; \
}

View File

@ -80,9 +80,9 @@ void li_response_send_headers(liVRequest *vr, liChunkQueue *raw_out, liChunkQueu
/* Status line */
if (vr->request.http_version == LI_HTTP_VERSION_1_1) {
g_string_append_len(head, CONST_STR_LEN("HTTP/1.1 "));
li_g_string_append_len(head, CONST_STR_LEN("HTTP/1.1 "));
} else {
g_string_append_len(head, CONST_STR_LEN("HTTP/1.0 "));
li_g_string_append_len(head, CONST_STR_LEN("HTTP/1.0 "));
}
{
@ -91,20 +91,20 @@ void li_response_send_headers(liVRequest *vr, liChunkQueue *raw_out, liChunkQueu
gchar *str = li_http_status_string(vr->response.http_status, &len);
li_http_status_to_str(vr->response.http_status, status_str);
status_str[3] = ' ';
g_string_append_len(head, status_str, 4);
g_string_append_len(head, str, len);
g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_g_string_append_len(head, status_str, 4);
li_g_string_append_len(head, str, len);
li_g_string_append_len(head, CONST_STR_LEN("\r\n"));
}
/* connection header, if needed. connection entries in the list are ignored below, send them directly */
if (upgraded) {
g_string_append_len(head, CONST_STR_LEN("Connection: Upgrade\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("Connection: Upgrade\r\n"));
} else if (vr->request.http_version == LI_HTTP_VERSION_1_1) {
if (!vr->coninfo->keep_alive)
g_string_append_len(head, CONST_STR_LEN("Connection: close\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("Connection: close\r\n"));
} else {
if (vr->coninfo->keep_alive)
g_string_append_len(head, CONST_STR_LEN("Connection: keep-alive\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("Connection: keep-alive\r\n"));
}
/* Append headers */
@ -117,8 +117,8 @@ void li_response_send_headers(liVRequest *vr, liChunkQueue *raw_out, liChunkQueu
header = (liHttpHeader*) iter->data;
/* ignore connection headers from backends. set con->info.keep_alive = FALSE to disable keep-alive */
if (li_http_header_key_is(header, CONST_STR_LEN("connection"))) continue;
g_string_append_len(head, GSTR_LEN(header->data));
g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_g_string_append_len(head, GSTR_LEN(header->data));
li_g_string_append_len(head, CONST_STR_LEN("\r\n"));
if (!have_date && li_http_header_key_is(header, CONST_STR_LEN("date"))) have_date = TRUE;
if (!have_server && li_http_header_key_is(header, CONST_STR_LEN("server"))) have_server = TRUE;
}
@ -126,23 +126,23 @@ void li_response_send_headers(liVRequest *vr, liChunkQueue *raw_out, liChunkQueu
if (!have_date) {
GString *d = li_worker_current_timestamp(vr->wrk, LI_GMTIME, LI_TS_FORMAT_HEADER);
/* HTTP/1.1 requires a Date: header */
g_string_append_len(head, CONST_STR_LEN("Date: "));
g_string_append_len(head, GSTR_LEN(d));
g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("Date: "));
li_g_string_append_len(head, GSTR_LEN(d));
li_g_string_append_len(head, CONST_STR_LEN("\r\n"));
}
if (!have_server) {
GString *tag = CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_TAG).string;
if (tag->len) {
g_string_append_len(head, CONST_STR_LEN("Server: "));
g_string_append_len(head, GSTR_LEN(tag));
g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("Server: "));
li_g_string_append_len(head, GSTR_LEN(tag));
li_g_string_append_len(head, CONST_STR_LEN("\r\n"));
}
}
}
g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_chunkqueue_append_string(raw_out, head);
if (NULL != tmp_cq) {
@ -218,7 +218,7 @@ static void li_response_send_error_page(liVRequest *vr, liChunkQueue *response_b
html = g_string_sized_new(1023);
g_string_append_len(html, CONST_STR_LEN(
li_g_string_append_len(html, CONST_STR_LEN(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"
"<html>\n"
" <head>\n"
@ -227,12 +227,12 @@ static void li_response_send_error_page(liVRequest *vr, liChunkQueue *response_b
li_http_status_to_str(vr->response.http_status, status_code);
g_string_append_len(html, status_code, 3);
g_string_append_len(html, CONST_STR_LEN(" - "));
li_g_string_append_len(html, status_code, 3);
li_g_string_append_len(html, CONST_STR_LEN(" - "));
str = li_http_status_string(vr->response.http_status, &len);
g_string_append_len(html, str, len);
li_g_string_append_len(html, str, len);
g_string_append_len(html, CONST_STR_LEN(
li_g_string_append_len(html, CONST_STR_LEN(
"</title>\n"
" <style type=\"text/css\">\n"
" body { font-size: 62.5%; }\n"
@ -256,17 +256,17 @@ static void li_response_send_error_page(liVRequest *vr, liChunkQueue *response_b
" <h1>Error "
));
g_string_append_len(html, status_code, 3);
g_string_append_len(html, CONST_STR_LEN(" - "));
g_string_append_len(html, str, len);
g_string_append_len(html, CONST_STR_LEN("</h1>\n"));
li_g_string_append_len(html, status_code, 3);
li_g_string_append_len(html, CONST_STR_LEN(" - "));
li_g_string_append_len(html, str, len);
li_g_string_append_len(html, CONST_STR_LEN("</h1>\n"));
str = li_response_error_description(vr->response.http_status, &len);
g_string_append_len(html, str, len);
li_g_string_append_len(html, str, len);
g_string_append_len(html, CONST_STR_LEN(" <p id=\"footer\">"));
g_string_append_len(html, GSTR_LEN(CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_TAG).string));
g_string_append_len(html, CONST_STR_LEN(
li_g_string_append_len(html, CONST_STR_LEN(" <p id=\"footer\">"));
li_g_string_append_len(html, GSTR_LEN(CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_TAG).string));
li_g_string_append_len(html, CONST_STR_LEN(
"</p>\n"
" </div>\n"
" </body>\n"

View File

@ -120,7 +120,7 @@ static void stat_cache_run(gpointer data) {
sce->dirlist = g_array_sized_new(FALSE, FALSE, sizeof(liStatCacheEntryData), 32);
str = g_string_sized_new(sce->data.path->len + 64);
g_string_append_len(str, GSTR_LEN(sce->data.path));
li_g_string_append_len(str, GSTR_LEN(sce->data.path));
/* glibc claims modern readdir are thread-safe, and
* readdir_r has issues. no way to check readdir is actually
@ -143,7 +143,7 @@ static void stat_cache_run(gpointer data) {
/* make sure the path ends with / (or whatever) */
if (!sce->data.path->len || sce->data.path->str[sce->data.path->len-1] != G_DIR_SEPARATOR)
g_string_append_c(str, G_DIR_SEPARATOR);
g_string_append_len(str, GSTR_LEN(sced.path));
li_g_string_append_len(str, GSTR_LEN(sced.path));
if (stat(str->str, &sced.st) == -1) {
sced.failed = TRUE;

View File

@ -12,24 +12,24 @@
action save_host {
g_string_truncate(uri->host, 0);
g_string_append_len(uri->host, host_mark, fpc - host_mark);
li_g_string_append_len(uri->host, host_mark, fpc - host_mark);
g_string_ascii_down(uri->host);
}
action save_authority {
g_string_truncate(uri->authority, 0);
g_string_append_len(uri->authority, mark, fpc - mark);
li_g_string_append_len(uri->authority, mark, fpc - mark);
g_string_ascii_down(uri->authority);
}
action save_path {
g_string_append_len(uri->path, mark, fpc - mark);
g_string_append_len(uri->raw_path, mark, fpc - mark);
li_g_string_append_len(uri->path, mark, fpc - mark);
li_g_string_append_len(uri->raw_path, mark, fpc - mark);
}
action save_query {
g_string_append_len(uri->query, mark, fpc - mark);
g_string_append_len(uri->raw_path, mark-1, fpc - mark+1); /* include '?' in append */
li_g_string_append_len(uri->query, mark, fpc - mark);
li_g_string_append_len(uri->raw_path, mark-1, fpc - mark+1); /* include '?' in append */
}
action save_scheme {
g_string_append_len(uri->scheme, mark, fpc - mark);
li_g_string_append_len(uri->scheme, mark, fpc - mark);
}
pct_encoded = "%" xdigit xdigit;

View File

@ -557,18 +557,18 @@ gboolean li_vrequest_redirect_directory(liVRequest *vr) {
if (li_vrequest_is_handled(vr)) return FALSE;
g_string_truncate(uri, 0);
g_string_append_len(uri, GSTR_LEN(vr->request.uri.scheme));
g_string_append_len(uri, CONST_STR_LEN("://"));
li_g_string_append_len(uri, GSTR_LEN(vr->request.uri.scheme));
li_g_string_append_len(uri, CONST_STR_LEN("://"));
if (vr->request.uri.authority->len > 0) {
g_string_append_len(uri, GSTR_LEN(vr->request.uri.authority));
li_g_string_append_len(uri, GSTR_LEN(vr->request.uri.authority));
} else {
g_string_append_len(uri, GSTR_LEN(vr->coninfo->local_addr_str));
li_g_string_append_len(uri, GSTR_LEN(vr->coninfo->local_addr_str));
}
li_string_encode_append(vr->request.uri.path->str, uri, LI_ENCODING_URI);
g_string_append_c(uri, '/');
if (vr->request.uri.query->len) {
g_string_append_c(uri, '?');
g_string_append_len(uri, GSTR_LEN(vr->request.uri.query));
li_g_string_append_len(uri, GSTR_LEN(vr->request.uri.query));
}
return li_vrequest_redirect(vr, uri);

5
src/meson.build Normal file
View File

@ -0,0 +1,5 @@
subdir('common')
subdir('angel')
subdir('main')
subdir('modules')
subdir('unittests')

113
src/modules/meson.build Normal file
View File

@ -0,0 +1,113 @@
modules = {
'access': {
'sources': ['mod_access.c'],
},
'accesslog': {
'sources': ['mod_accesslog.c'],
},
'auth': {
'sources': ['mod_auth.c'],
},
'balance': {
'sources': ['mod_balance.c'],
},
'cache_disk_etag': {
'sources': ['mod_cache_disk_etag.c'],
},
'debug': {
'sources': ['mod_debug.c'],
},
'deflate': {
'sources': ['mod_deflate.c'],
'dependencies': dep_deflate,
},
'dirlist': {
'sources': ['mod_dirlist.c'],
},
'expire': {
'sources': ['mod_expire.c'],
},
'fastcgi': {
'sources': ['mod_fastcgi.c', 'fastcgi_stream.c'],
},
'flv': {
'sources': ['mod_flv.c'],
},
'fortune': {
'sources': ['mod_fortune.c'],
},
'gnutls': {
'sources': ['mod_gnutls.c', 'gnutls_filter.c', 'gnutls_ocsp.c'],
'dependencies': [dep_gnutls, opt_dep_idn],
},
'limit': {
'sources': ['mod_limit.c'],
},
'lua': {
'sources': ['mod_lua.c'],
'dependencies': dep_lua,
},
'memcached': {
'sources': ['mod_memcached.c'],
'dependencies': opt_dep_lua,
},
'openssl': {
'sources': ['mod_openssl.c', 'openssl_filter.c'],
'dependencies': [dep_openssl, opt_dep_idn],
},
'progress': {
'sources': ['mod_progress.c'],
},
'proxy': {
'sources': ['mod_proxy.c'],
},
'redirect': {
'sources': ['mod_redirect.c'],
},
'rewrite': {
'sources': ['mod_rewrite.c'],
},
'scgi': {
'sources': ['mod_scgi.c'],
},
'status': {
'sources': ['mod_status.c'],
},
'throttle': {
'sources': ['mod_throttle.c'],
},
'userdir': {
'sources': ['mod_userdir.c'],
},
'vhost': {
'sources': ['mod_vhost.c'],
},
}
modules_build_dir = meson.current_build_dir()
all_modules = []
enabled_modules = []
foreach name, def: modules
deps = main_deps + def.get('dependencies', [])
expect_mod = true
foreach dep: deps
if not dep.found()
expect_mod = false
endif
endforeach
mod = shared_module(
'mod_' + name,
def['sources'],
dependencies: main_deps + def.get('dependencies', []),
c_args: def.get('c_args', []),
include_directories: inc_dir,
install: true,
install_dir: modules_dir,
)
all_modules += mod
if expect_mod
enabled_modules += mod
endif
endforeach

View File

@ -110,13 +110,13 @@ static void al_append_escaped(GString *log, GString *str) {
/* exceptions: " => \", \ => \\, whitespace chars => \n \t etc. */
for (guint i = 0; i < str->len; i++) {
switch (str->str[i]) {
case '"': g_string_append_len(log, CONST_STR_LEN("\\\"")); break;
case '\\': g_string_append_len(log, CONST_STR_LEN("\\\\")); break;
case '\b': g_string_append_len(log, CONST_STR_LEN("\\b")); break;
case '\n': g_string_append_len(log, CONST_STR_LEN("\\n")); break;
case '\r': g_string_append_len(log, CONST_STR_LEN("\\r")); break;
case '\t': g_string_append_len(log, CONST_STR_LEN("\\t")); break;
case '\v': g_string_append_len(log, CONST_STR_LEN("\\v")); break;
case '"': li_g_string_append_len(log, CONST_STR_LEN("\\\"")); break;
case '\\': li_g_string_append_len(log, CONST_STR_LEN("\\\\")); break;
case '\b': li_g_string_append_len(log, CONST_STR_LEN("\\b")); break;
case '\n': li_g_string_append_len(log, CONST_STR_LEN("\\n")); break;
case '\r': li_g_string_append_len(log, CONST_STR_LEN("\\r")); break;
case '\t': li_g_string_append_len(log, CONST_STR_LEN("\\t")); break;
case '\v': li_g_string_append_len(log, CONST_STR_LEN("\\v")); break;
default:
if (str->str[i] >= ' ' && str->str[i] <= '~') {
/* printable chars */
@ -128,7 +128,7 @@ static void al_append_escaped(GString *log, GString *str) {
hh[2] = (h > 9) ? (h - 10 + 'A') : (h + '0');
h = str->str[i] % 16;
hh[3] = (h > 9) ? (h - 10 + 'A') : (h + '0');
g_string_append_len(log, &hh[0], 4);
li_g_string_append_len(log, &hh[0], 4);
}
break;
}
@ -225,10 +225,10 @@ static GString *al_format_log(liVRequest *vr, al_data *ald, GArray *format) {
g_string_append_c(str, '%');
break;
case AL_FORMAT_REMOTE_ADDR:
g_string_append_len(str, GSTR_LEN(vr->coninfo->remote_addr_str));
li_g_string_append_len(str, GSTR_LEN(vr->coninfo->remote_addr_str));
break;
case AL_FORMAT_LOCAL_ADDR:
g_string_append_len(str, GSTR_LEN(vr->coninfo->local_addr_str));
li_g_string_append_len(str, GSTR_LEN(vr->coninfo->local_addr_str));
break;
case AL_FORMAT_BYTES_RESPONSE:
li_string_append_int(str, (NULL != vr->coninfo->resp) ? vr->coninfo->resp->out->bytes_out : 0);
@ -251,7 +251,7 @@ static GString *al_format_log(liVRequest *vr, al_data *ald, GArray *format) {
break;
case AL_FORMAT_FILENAME:
if (phys->path->len)
g_string_append_len(str, GSTR_LEN(phys->path));
li_g_string_append_len(str, GSTR_LEN(phys->path));
else
g_string_append_c(str, '-');
break;
@ -263,7 +263,7 @@ static GString *al_format_log(liVRequest *vr, al_data *ald, GArray *format) {
g_string_append_c(str, '-');
break;
case AL_FORMAT_METHOD:
g_string_append_len(str, GSTR_LEN(req->http_method_str));
li_g_string_append_len(str, GSTR_LEN(req->http_method_str));
break;
case AL_FORMAT_RESPONSE_HEADER:
li_http_header_get_all(vr->wrk->tmp_str, resp->headers, GSTR_LEN(e->key));
@ -288,12 +288,12 @@ static GString *al_format_log(liVRequest *vr, al_data *ald, GArray *format) {
g_string_append_c(str, '-');
break;
case AL_FORMAT_FIRST_LINE:
g_string_append_len(str, GSTR_LEN(req->http_method_str));
li_g_string_append_len(str, GSTR_LEN(req->http_method_str));
g_string_append_c(str, ' ');
al_append_escaped(str, req->uri.raw_orig_path);
g_string_append_c(str, ' ');
tmp_str = li_http_version_string(req->http_version, &len);
g_string_append_len(str, tmp_str, len);
li_g_string_append_len(str, tmp_str, len);
break;
case AL_FORMAT_STATUS_CODE:
li_string_append_int(str, resp->http_status);
@ -301,7 +301,7 @@ static GString *al_format_log(liVRequest *vr, al_data *ald, GArray *format) {
case AL_FORMAT_TIME:
/* todo: implement format string */
tmp_gstr2 = li_worker_current_timestamp(vr->wrk, LI_LOCALTIME, ald->ts_ndx);
g_string_append_len(str, GSTR_LEN(tmp_gstr2));
li_g_string_append_len(str, GSTR_LEN(tmp_gstr2));
break;
case AL_FORMAT_DURATION_SECONDS:
li_string_append_int(str, li_cur_ts(vr->wrk) - vr->ts_started);
@ -309,22 +309,22 @@ static GString *al_format_log(liVRequest *vr, al_data *ald, GArray *format) {
case AL_FORMAT_AUTHED_USER:
tmp_gstr2 = li_environment_get(&vr->env, CONST_STR_LEN("REMOTE_USER"));
if (tmp_gstr2)
g_string_append_len(str, GSTR_LEN(tmp_gstr2));
li_g_string_append_len(str, GSTR_LEN(tmp_gstr2));
else
g_string_append_c(str, '-');
break;
case AL_FORMAT_PATH:
g_string_append_len(str, GSTR_LEN(req->uri.path));
li_g_string_append_len(str, GSTR_LEN(req->uri.path));
break;
case AL_FORMAT_SERVER_NAME:
if (CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_NAME).string)
g_string_append_len(str, GSTR_LEN(CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_NAME).string));
li_g_string_append_len(str, GSTR_LEN(CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_NAME).string));
else
g_string_append_len(str, GSTR_LEN(req->uri.host));
li_g_string_append_len(str, GSTR_LEN(req->uri.host));
break;
case AL_FORMAT_HOSTNAME:
if (req->uri.host->len)
g_string_append_len(str, GSTR_LEN(req->uri.host));
li_g_string_append_len(str, GSTR_LEN(req->uri.host));
else
g_string_append_c(str, '-');
break;
@ -353,7 +353,7 @@ static GString *al_format_log(liVRequest *vr, al_data *ald, GArray *format) {
}
} else {
/* append normal string */
g_string_append_len(str, GSTR_LEN(e->key));
li_g_string_append_len(str, GSTR_LEN(e->key));
}
}

View File

@ -261,7 +261,13 @@ static gboolean auth_backend_htpasswd(liVRequest *vr, const GString *username, c
}
} else {
const GString salt = { (gchar*) pass, strlen(pass), 0 };
li_safe_crypt(vr->wrk->tmp_str, password, &salt);
if (!li_safe_crypt(vr->wrk->tmp_str, password, &salt)) {
if (debug) {
VR_DEBUG(vr, "Invalid password salt/hash \"%s\" for user \"%s\"", pass, username->str);
}
goto out;
}
if (0 != g_strcmp0(pass, vr->wrk->tmp_str->str)) {
if (debug) {
@ -390,8 +396,8 @@ static liHandlerResult auth_basic(liVRequest *vr, gpointer param, gpointer *cont
}
g_string_truncate(vr->wrk->tmp_str, 0);
g_string_append_len(vr->wrk->tmp_str, CONST_STR_LEN("Basic realm=\""));
g_string_append_len(vr->wrk->tmp_str, GSTR_LEN(bdata->realm));
li_g_string_append_len(vr->wrk->tmp_str, CONST_STR_LEN("Basic realm=\""));
li_g_string_append_len(vr->wrk->tmp_str, GSTR_LEN(bdata->realm));
g_string_append_c(vr->wrk->tmp_str, '"');
/* generate header always */

View File

@ -65,8 +65,8 @@ static gboolean mkdir_for_file(liVRequest *vr, char *filename) {
static gboolean cache_etag_file_start(liVRequest *vr, cache_etag_file *cfile) {
cfile->tmpfilename = g_string_sized_new(cfile->filename->len + 7);
g_string_append_len(cfile->tmpfilename, GSTR_LEN(cfile->filename));
g_string_append_len(cfile->tmpfilename, CONST_STR_LEN("-XXXXXX"));
li_g_string_append_len(cfile->tmpfilename, GSTR_LEN(cfile->filename));
li_g_string_append_len(cfile->tmpfilename, CONST_STR_LEN("-XXXXXX"));
if (!mkdir_for_file(vr, cfile->tmpfilename->str)) {
return FALSE;
@ -207,9 +207,9 @@ forward:
static GString* createFileName(liVRequest *vr, GString *path, liHttpHeader *etagheader) {
GString *file = g_string_sized_new(255);
gchar* etag_base64 = g_base64_encode((guchar*) LI_HEADER_VALUE_LEN(etagheader));
g_string_append_len(file, GSTR_LEN(path));
g_string_append_len(file, GSTR_LEN(vr->request.uri.path));
g_string_append_len(file, CONST_STR_LEN("-"));
li_g_string_append_len(file, GSTR_LEN(path));
li_g_string_append_len(file, GSTR_LEN(vr->request.uri.path));
li_g_string_append_len(file, CONST_STR_LEN("-"));
g_string_append(file, etag_base64);
g_free(etag_base64);
return file;

View File

@ -161,7 +161,7 @@ static gpointer debug_collect_func(liWorker *wrk, gpointer fdata) {
cd->path->str,
cd->query->str
);
g_string_append_len(cd->detailed, CONST_STR_LEN("}</pre>"));
li_g_string_append_len(cd->detailed, CONST_STR_LEN("}</pre>"));
}
}
}
@ -211,7 +211,7 @@ static void debug_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result,
html = g_string_sized_new(2047);
g_string_append_len(html, CONST_STR_LEN("<html>\n<head>\n<title>Lighttpd mod_debug</title>\n"
li_g_string_append_len(html, CONST_STR_LEN("<html>\n<head>\n<title>Lighttpd mod_debug</title>\n"
"<style>a { color: blue; }</style>\n"
"</head>\n<body>\n"));
@ -225,7 +225,7 @@ static void debug_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result,
vr->wrk->io_timeout_queue.timer.libevmess.timer.repeat
);
g_string_append_len(html, CONST_STR_LEN("<table><tr><th>Client</th><th>Duration</th><th></th></tr>\n"));
li_g_string_append_len(html, CONST_STR_LEN("<table><tr><th>Client</th><th>Duration</th><th></th></tr>\n"));
for (i = 0; i < result->len; i++) {
GArray *cons = g_ptr_array_index(result, i);
@ -255,11 +255,11 @@ static void debug_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result,
g_array_free(cons, TRUE);
}
g_string_append_len(html, CONST_STR_LEN("</table>\n"));
li_g_string_append_len(html, CONST_STR_LEN("</table>\n"));
g_string_free(duration, TRUE);
}
g_string_append_len(html, CONST_STR_LEN("</body>\n</html>\n"));
li_g_string_append_len(html, CONST_STR_LEN("</body>\n</html>\n"));
if (li_vrequest_handle_direct(vr)) {
li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html; charset=utf-8"));

View File

@ -485,12 +485,12 @@ static gboolean cached_handle_etag(liVRequest *vr, gboolean debug, liHttpHeader
if (!hh_etag) return FALSE;
g_string_truncate(s, 0);
g_string_append_len(s, LI_HEADER_VALUE_LEN(hh_etag));
g_string_append_len(s, CONST_STR_LEN("-"));
g_string_append_len(s, enc_name, strlen(enc_name));
li_g_string_append_len(s, LI_HEADER_VALUE_LEN(hh_etag));
li_g_string_append_len(s, CONST_STR_LEN("-"));
li_g_string_append_len(s, enc_name, strlen(enc_name));
li_etag_mutate(s, s);
g_string_truncate(hh_etag->data, hh_etag->keylen + 2);
g_string_append_len(hh_etag->data, GSTR_LEN(s));
li_g_string_append_len(hh_etag->data, GSTR_LEN(s));
if (200 == vr->response.http_status && li_http_response_handle_cachable(vr)) {
if (debug || CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {

View File

@ -206,7 +206,7 @@ typedef struct dirlist_plugin_data dirlist_plugin_data;
static void try_append_file(liVRequest *vr, GString **curbuf, const gchar *filename, gboolean encode_html) {
GString *f = vr->wrk->tmp_str;
g_string_truncate(f, 0);
g_string_append_len(f, GSTR_LEN(vr->physical.path));
li_g_string_append_len(f, GSTR_LEN(vr->physical.path));
li_path_append_slash(f);
g_string_append(f, filename);
@ -246,9 +246,9 @@ static void try_append_file(liVRequest *vr, GString **curbuf, const gchar *filen
return; /* file too big, ignore */
}
g_string_append_len(*curbuf, CONST_STR_LEN("<pre>"));
li_g_string_append_len(*curbuf, CONST_STR_LEN("<pre>"));
li_string_encode_append(contents, *curbuf, LI_ENCODING_HTML);
g_string_append_len(*curbuf, CONST_STR_LEN("</pre>"));
li_g_string_append_len(*curbuf, CONST_STR_LEN("</pre>"));
g_free(contents);
}
}
@ -435,14 +435,14 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context
if (dd->css) {
/* custom css */
g_string_append_len(listing, CONST_STR_LEN(" <link rel=\"stylesheet\" type=\"text/css\" href=\""));
g_string_append_len(listing, GSTR_LEN(dd->css));
g_string_append_len(listing, CONST_STR_LEN("\" />\n"));
li_g_string_append_len(listing, CONST_STR_LEN(" <link rel=\"stylesheet\" type=\"text/css\" href=\""));
li_g_string_append_len(listing, GSTR_LEN(dd->css));
li_g_string_append_len(listing, CONST_STR_LEN("\" />\n"));
} else {
/* default css */
g_string_append_len(listing, CONST_STR_LEN(html_css));
li_g_string_append_len(listing, CONST_STR_LEN(html_css));
}
g_string_append_len(listing, CONST_STR_LEN(html_header_end));
li_g_string_append_len(listing, CONST_STR_LEN(html_header_end));
try_append_file(vr, &listing, "HEADER.txt", dd->encode_header);
@ -462,23 +462,23 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context
datebuflen = strftime(datebuf, sizeof(datebuf), "%Y-%b-%d %H:%M:%S", &tm);
datebuf[datebuflen] = '\0';
g_string_append_len(listing, CONST_STR_LEN(" <tr group=\"1\"><td><a href=\""));
li_g_string_append_len(listing, CONST_STR_LEN(" <tr group=\"1\"><td><a href=\""));
li_string_encode(sced->path->str, encoded, LI_ENCODING_URI);
g_string_append_len(listing, GSTR_LEN(encoded));
g_string_append_len(listing, CONST_STR_LEN("/\">"));
li_g_string_append_len(listing, GSTR_LEN(encoded));
li_g_string_append_len(listing, CONST_STR_LEN("/\">"));
li_string_encode(sced->path->str, encoded, LI_ENCODING_HTML);
g_string_append_len(listing, GSTR_LEN(encoded));
g_string_append_len(listing, CONST_STR_LEN("</a></td><td class=\"modified\" val=\""));
li_g_string_append_len(listing, GSTR_LEN(encoded));
li_g_string_append_len(listing, CONST_STR_LEN("</a></td><td class=\"modified\" val=\""));
li_string_append_int(listing, sced->st.st_mtime);
g_string_append_len(listing, CONST_STR_LEN("\">"));
g_string_append_len(listing, datebuf, datebuflen);
g_string_append_len(listing, CONST_STR_LEN("</td>"
li_g_string_append_len(listing, CONST_STR_LEN("\">"));
li_g_string_append_len(listing, datebuf, datebuflen);
li_g_string_append_len(listing, CONST_STR_LEN("</td>"
"<td class=\"size\" val=\"0\">-</td>"
"<td class=\"type\">Directory</td></tr>\n"));
}
}
/*g_string_append_len(listing, CONST_STR_LEN("<tr><td colspan=\"4\">&nbsp;</td></tr>\n"));*/
/*li_g_string_append_len(listing, CONST_STR_LEN("<tr><td colspan=\"4\">&nbsp;</td></tr>\n"));*/
/* list files */
for (i = 0; i < files->len; i++) {
@ -491,29 +491,29 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context
dirlist_format_size(sizebuf, sced->st.st_size);
g_string_append_len(listing, CONST_STR_LEN(" <tr group=\"2\"><td><a href=\""));
li_g_string_append_len(listing, CONST_STR_LEN(" <tr group=\"2\"><td><a href=\""));
li_string_encode(sced->path->str, encoded, LI_ENCODING_URI);
g_string_append_len(listing, GSTR_LEN(encoded));
g_string_append_len(listing, CONST_STR_LEN("\">"));
li_g_string_append_len(listing, GSTR_LEN(encoded));
li_g_string_append_len(listing, CONST_STR_LEN("\">"));
li_string_encode(sced->path->str, encoded, LI_ENCODING_HTML);
g_string_append_len(listing, GSTR_LEN(encoded));
g_string_append_len(listing, CONST_STR_LEN(
li_g_string_append_len(listing, GSTR_LEN(encoded));
li_g_string_append_len(listing, CONST_STR_LEN(
"</a></td>"
"<td class=\"modified\" val=\""));
li_string_append_int(listing, sced->st.st_mtime);
g_string_append_len(listing, CONST_STR_LEN("\">"));
g_string_append_len(listing, datebuf, datebuflen);
g_string_append_len(listing, CONST_STR_LEN("</td><td class=\"size\" val=\""));
li_g_string_append_len(listing, CONST_STR_LEN("\">"));
li_g_string_append_len(listing, datebuf, datebuflen);
li_g_string_append_len(listing, CONST_STR_LEN("</td><td class=\"size\" val=\""));
li_string_append_int(listing, sced->st.st_size);
g_string_append_len(listing, CONST_STR_LEN("\">"));
li_g_string_append_len(listing, CONST_STR_LEN("\">"));
g_string_append(listing, sizebuf);
g_string_append_len(listing, CONST_STR_LEN("</td><td class=\"type\">"));
li_g_string_append_len(listing, CONST_STR_LEN("</td><td class=\"type\">"));
if (mime_str) {
g_string_append_len(listing, GSTR_LEN(mime_str));
li_g_string_append_len(listing, GSTR_LEN(mime_str));
} else {
g_string_append_len(listing, CONST_STR_LEN("application/octet-stream"));
li_g_string_append_len(listing, CONST_STR_LEN("application/octet-stream"));
}
g_string_append_len(listing, CONST_STR_LEN("</td></tr>\n"));
li_g_string_append_len(listing, CONST_STR_LEN("</td></tr>\n"));
/*
g_string_append_printf(listing, html_table_row,
@ -524,12 +524,12 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context
*/
}
g_string_append_len(listing, CONST_STR_LEN(html_table_end));
li_g_string_append_len(listing, CONST_STR_LEN(html_table_end));
try_append_file(vr, &listing, "README.txt", dd->encode_readme);
if (dd->include_sort) {
g_string_append_len(listing, CONST_STR_LEN(javascript_sort));
li_g_string_append_len(listing, CONST_STR_LEN(javascript_sort));
}
g_string_append_printf(listing, html_footer, CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_TAG).string->str);

View File

@ -80,7 +80,7 @@ static liHandlerResult expire(liVRequest *vr, gpointer param, gpointer *context)
/* finally set the headers */
li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Expires"), GSTR_LEN(date_str));
g_string_truncate(date_str, 0);
g_string_append_len(date_str, CONST_STR_LEN("max-age="));
li_g_string_append_len(date_str, CONST_STR_LEN("max-age="));
li_string_append_int(date_str, max_age);
li_http_header_append(vr->response.headers, CONST_STR_LEN("Cache-Control"), GSTR_LEN(date_str));

View File

@ -1016,7 +1016,7 @@ static gboolean gnutls_setup(liServer *srv, liPlugin* p, liValue *val, gpointer
if (protect_against_beast) {
g_string_assign(s, priority);
g_string_append_len(s, CONST_STR_LEN(":-CIPHER-ALL:+ARCFOUR-128"));
li_g_string_append_len(s, CONST_STR_LEN(":-CIPHER-ALL:+ARCFOUR-128"));
if (GNUTLS_E_SUCCESS > (r = gnutls_priority_init(&prio, s->str, &errpos))) {
ERROR(srv, "gnutls_priority_init failed(priority '%s', error at '%s') (%s): %s",
s->str, errpos,

View File

@ -63,7 +63,7 @@ static gboolean lua_find_file(GString *filename) {
/* try DEFAULT_LUADIR */
li_string_assign_len(tmp, CONST_STR_LEN(DEFAULT_LUADIR "/"));
g_string_append_len(tmp, GSTR_LEN(filename));
li_g_string_append_len(tmp, GSTR_LEN(filename));
if (-1 != stat(tmp->str, &st) && S_ISREG(st.st_mode)) {
li_string_assign_len(filename, GSTR_LEN(tmp));
} else {

View File

@ -245,7 +245,7 @@ static void openssl_setenv_X509_add_entries(liVRequest *vr, X509 *x509, const gc
const char * xobjsn;
g_string_truncate(k, 0);
g_string_append_len(k, prefix, prefix_len);
li_g_string_append_len(k, prefix, prefix_len);
for (i = 0, j = X509_NAME_entry_count(xn); i < j; ++i) {
if (!(xe = X509_NAME_get_entry(xn, i))

View File

@ -219,7 +219,7 @@ static void progress_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *resu
li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("application/x-javascript"));
if (format == PROGRESS_FORMAT_LEGACY) {
g_string_append_len(output, CONST_STR_LEN("new Object("));
li_g_string_append_len(output, CONST_STR_LEN("new Object("));
} else if (format == PROGRESS_FORMAT_JSONP) {
gchar *val;
guint len;
@ -236,13 +236,13 @@ static void progress_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *resu
/* was there a bad char? */
if (c != val+len) {
g_string_append_len(output, CONST_STR_LEN("progress("));
li_g_string_append_len(output, CONST_STR_LEN("progress("));
} else {
g_string_append_len(output,val, len);
li_g_string_append_len(output,val, len);
g_string_append_c(output, '(');
}
} else {
g_string_append_len(output, CONST_STR_LEN("progress("));
li_g_string_append_len(output, CONST_STR_LEN("progress("));
}
}
@ -251,7 +251,7 @@ static void progress_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *resu
if (debug)
VR_DEBUG(vr, "progress.show: progress id \"%s\" unknown", job->id);
g_string_append_len(output, CONST_STR_LEN("{\"state\": \"unknown\"}"));
li_g_string_append_len(output, CONST_STR_LEN("{\"state\": \"unknown\"}"));
} else {
if (debug)
VR_DEBUG(vr, "progress.show: progress id \"%s\" found", job->id);

View File

@ -45,27 +45,27 @@ static void proxy_send_headers(liVRequest *vr, liChunkQueue *out) {
liHttpHeaderTokenizer header_tokenizer;
GString *tmp_str = vr->wrk->tmp_str;
g_string_append_len(head, GSTR_LEN(vr->request.http_method_str));
g_string_append_len(head, CONST_STR_LEN(" "));
li_g_string_append_len(head, GSTR_LEN(vr->request.http_method_str));
li_g_string_append_len(head, CONST_STR_LEN(" "));
g_string_append_len(head, GSTR_LEN(vr->request.uri.raw_path));
li_g_string_append_len(head, GSTR_LEN(vr->request.uri.raw_path));
switch (vr->request.http_version) {
case LI_HTTP_VERSION_1_1:
g_string_append_len(head, CONST_STR_LEN(" HTTP/1.1\r\n"));
li_g_string_append_len(head, CONST_STR_LEN(" HTTP/1.1\r\n"));
/* although we understand keep-alive signalling we don't reuse connection, so tell backend */
g_string_append_len(head, CONST_STR_LEN("Connection: close\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("Connection: close\r\n"));
break;
case LI_HTTP_VERSION_1_0:
default:
g_string_append_len(head, CONST_STR_LEN(" HTTP/1.0\r\n"));
li_g_string_append_len(head, CONST_STR_LEN(" HTTP/1.0\r\n"));
break;
}
li_http_header_tokenizer_start(&header_tokenizer, vr->request.headers, CONST_STR_LEN("Connection"));
while (li_http_header_tokenizer_next(&header_tokenizer, tmp_str)) {
if (0 == g_ascii_strcasecmp(tmp_str->str, "Upgrade")) {
g_string_append_len(head, CONST_STR_LEN("Connection: Upgrade\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("Connection: Upgrade\r\n"));
}
}
@ -82,22 +82,22 @@ static void proxy_send_headers(liVRequest *vr, liChunkQueue *out) {
if (li_http_header_key_is(header, CONST_STR_LEN("Proxy-Connection"))) continue;
if (li_http_header_key_is(header, CONST_STR_LEN("X-Forwarded-Proto"))) continue;
if (li_http_header_key_is(header, CONST_STR_LEN("X-Forwarded-For"))) continue;
g_string_append_len(head, GSTR_LEN(header->data));
g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_g_string_append_len(head, GSTR_LEN(header->data));
li_g_string_append_len(head, CONST_STR_LEN("\r\n"));
}
g_string_append_len(head, CONST_STR_LEN("X-Forwarded-For: "));
g_string_append_len(head, GSTR_LEN(vr->coninfo->remote_addr_str));
g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("X-Forwarded-For: "));
li_g_string_append_len(head, GSTR_LEN(vr->coninfo->remote_addr_str));
li_g_string_append_len(head, CONST_STR_LEN("\r\n"));
if (vr->coninfo->is_ssl) {
g_string_append_len(head, CONST_STR_LEN("X-Forwarded-Proto: https\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("X-Forwarded-Proto: https\r\n"));
} else {
g_string_append_len(head, CONST_STR_LEN("X-Forwarded-Proto: http\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("X-Forwarded-Proto: http\r\n"));
}
/* terminate http header */
g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_g_string_append_len(head, CONST_STR_LEN("\r\n"));
li_chunkqueue_append_string(out, head);
}

View File

@ -111,15 +111,15 @@ static gboolean redirect_internal(liVRequest *vr, GString *dest, redirect_rule *
break;
case REDIRECT_ABSOLUTE_PATH:
/* /foo/bar?baz */
g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
g_string_append_len(dest, CONST_STR_LEN("://"));
g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
li_g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
li_g_string_append_len(dest, CONST_STR_LEN("://"));
li_g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
break;
case REDIRECT_RELATIVE_PATH:
/* foo/bar?baz */
g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
g_string_append_len(dest, CONST_STR_LEN("://"));
g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
li_g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
li_g_string_append_len(dest, CONST_STR_LEN("://"));
li_g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
/* search for last slash /foo/bar */
{
gchar *c;
@ -127,15 +127,15 @@ static gboolean redirect_internal(liVRequest *vr, GString *dest, redirect_rule *
if (*c == '/') break;
}
g_string_append_len(dest, vr->request.uri.path->str, c - vr->request.uri.path->str + 1);
li_g_string_append_len(dest, vr->request.uri.path->str, c - vr->request.uri.path->str + 1);
}
break;
case REDIRECT_RELATIVE_QUERY:
/* ?bar */
g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
g_string_append_len(dest, CONST_STR_LEN("://"));
g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
g_string_append_len(dest, GSTR_LEN(vr->request.uri.path));
li_g_string_append_len(dest, GSTR_LEN(vr->request.uri.scheme));
li_g_string_append_len(dest, CONST_STR_LEN("://"));
li_g_string_append_len(dest, GSTR_LEN(vr->request.uri.authority));
li_g_string_append_len(dest, GSTR_LEN(vr->request.uri.path));
break;
}

View File

@ -190,19 +190,19 @@ static liHandlerResult rewrite(liVRequest *vr, gpointer param, gpointer *context
/* change request query */
if (NULL != rule->querystring) {
g_string_truncate(vr->request.uri.query, 0);
g_string_append_len(vr->request.uri.query, GSTR_LEN(dest_query));
li_g_string_append_len(vr->request.uri.query, GSTR_LEN(dest_query));
}
/* change request path */
g_string_truncate(vr->request.uri.path, 0);
g_string_append_len(vr->request.uri.path, GSTR_LEN(dest_path));
li_g_string_append_len(vr->request.uri.path, GSTR_LEN(dest_path));
li_path_simplify(vr->request.uri.path);
/* rebuild raw_path */
li_string_encode(vr->request.uri.path->str, vr->request.uri.raw_path, LI_ENCODING_URI);
if (vr->request.uri.query->len > 0) {
g_string_append_len(vr->request.uri.raw_path, CONST_STR_LEN("?"));
g_string_append_len(vr->request.uri.raw_path, GSTR_LEN(vr->request.uri.query));
li_g_string_append_len(vr->request.uri.raw_path, CONST_STR_LEN("?"));
li_g_string_append_len(vr->request.uri.raw_path, GSTR_LEN(vr->request.uri.query));
}
/* stop at first matching regex */

View File

@ -547,30 +547,30 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
count_mem = g_string_sized_new(10);
tmpstr = vr->wrk->tmp_str;
g_string_append_len(html, CONST_STR_LEN(html_header));
g_string_append_len(html, CONST_STR_LEN(html_js));
li_g_string_append_len(html, CONST_STR_LEN(html_header));
li_g_string_append_len(html, CONST_STR_LEN(html_js));
/* auto refresh */
if (li_querystring_find(vr->request.uri.query, CONST_STR_LEN("refresh"), &val, &len)) {
g_string_append_len(html, CONST_STR_LEN("<meta http-equiv=\"refresh\" content=\""));
li_g_string_append_len(html, CONST_STR_LEN("<meta http-equiv=\"refresh\" content=\""));
/* temp char swap */
c = val[len]; val[len] = '\0';
li_string_encode_append(val, html, LI_ENCODING_HTML);
val[len] = c;
g_string_append_len(html, CONST_STR_LEN("\">\n"));
li_g_string_append_len(html, CONST_STR_LEN("\">\n"));
}
/* css */
css = _OPTIONPTR(vr, p, 0).string;
if (!css || !css->len) /* default css */
g_string_append_len(html, CONST_STR_LEN(css_default));
li_g_string_append_len(html, CONST_STR_LEN(css_default));
else if (g_str_equal(css->str, "blue")) /* blue css */
g_string_append_len(html, CONST_STR_LEN(css_blue));
li_g_string_append_len(html, CONST_STR_LEN(css_blue));
else /* external css */
g_string_append_printf(html, " <link rel=\"stylesheet\" rev=\"stylesheet\" href=\"%s\" media=\"screen\" />\n", css->str);
g_string_append_len(html, CONST_STR_LEN(
li_g_string_append_len(html, CONST_STR_LEN(
" </head>\n"
" <body>\n"
));
@ -587,8 +587,8 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
/* worker information, absolute values */
g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Absolute stats</strong></div>\n"));
g_string_append_len(html, CONST_STR_LEN(html_worker_th));
li_g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Absolute stats</strong></div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(html_worker_th));
#define PERCENTAGE(x, y) (y ? (x * 100 / y) : 0)
for (i = 0; i < result->len; i++) {
@ -613,12 +613,12 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
count_bin->str, G_GUINT64_CONSTANT(100),
count_bout->str, G_GUINT64_CONSTANT(100),
total_connections, 100);
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
/* worker information, avg values */
g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Average stats</strong> (since start)</div>\n"));
li_g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Average stats</strong> (since start)</div>\n"));
g_string_append_len(html, CONST_STR_LEN(html_worker_th_avg));
li_g_string_append_len(html, CONST_STR_LEN(html_worker_th_avg));
#define PERCENTAGE(x) (sd->stat ## x ? (sd->stat ## x * 100 / total ## x) : 0)
for (i = 0; i < result->len; i++) {
@ -646,12 +646,12 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
count_bout->str,
(guint)(totals->active_cons_cum / uptime)
);
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
/* worker information, 5 seconds avg values */
g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Average stats</strong> (5 seconds)</div>\n"));
g_string_append_len(html, CONST_STR_LEN(html_worker_th_avg));
li_g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Average stats</strong> (5 seconds)</div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(html_worker_th_avg));
#define PERCENTAGE(x) (sd->stat ## x ? (sd->stat ## x * 100 / total ## x) : 0)
for (i = 0; i < result->len; i++) {
@ -679,12 +679,12 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
count_bout->str,
totals->active_cons_5s
);
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
/* worker information, peak values */
g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Peak stats</strong></div>\n"));
g_string_append_len(html, CONST_STR_LEN(html_worker_th_avg));
li_g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Peak stats</strong></div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(html_worker_th_avg));
for (i = 0; i < result->len; i++) {
mod_status_wrk_data *sd = g_ptr_array_index(result, i);
@ -710,11 +710,11 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
count_bout->str,
totals->peak.active_cons
);
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
/* connection counts */
g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Connections</strong> (states, sum)</div>\n"));
li_g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Connections</strong> (states, sum)</div>\n"));
g_string_append_printf(html, html_connections_sum,
connection_count[LI_CON_STATE_DEAD] + connection_count[LI_CON_STATE_CLOSE],
connection_count[LI_CON_STATE_REQUEST_START], connection_count[LI_CON_STATE_READ_REQUEST_HEADER],
@ -723,7 +723,7 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
);
/* response status codes */
g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>HTTP Status codes</strong> (sum)</div>\n"));
li_g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>HTTP Status codes</strong> (sum)</div>\n"));
g_string_append_printf(html, html_status_codes, mod_status_response_codes[0], mod_status_response_codes[1],
mod_status_response_codes[2], mod_status_response_codes[3], mod_status_response_codes[4]
);
@ -743,8 +743,8 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
req_len = g_string_sized_new(10);
resp_len = g_string_sized_new(10);
g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Active connections</strong></div>\n"));
g_string_append_len(html, CONST_STR_LEN(html_connections_th));
li_g_string_append_len(html, CONST_STR_LEN("<div class=\"title\"><strong>Active connections</strong></div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(html_connections_th));
for (i = 0; i < result->len; i++) {
mod_status_wrk_data *sd = g_ptr_array_index(result, i);
@ -780,7 +780,7 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
}
}
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
g_string_free(ts_started, TRUE);
g_string_free(ts_timeout, TRUE);
@ -792,7 +792,7 @@ static GString *status_info_full(liVRequest *vr, liPlugin *p, gboolean short_inf
g_string_free(resp_len, TRUE);
}
g_string_append_len(html, CONST_STR_LEN(
li_g_string_append_len(html, CONST_STR_LEN(
" </body>\n"
"</html>\n"
));
@ -813,59 +813,59 @@ static GString *status_info_plain(liVRequest *vr, guint uptime, liStatistics *to
html = g_string_sized_new(1024 - 1);
/* absolute values */
g_string_append_len(html, CONST_STR_LEN("# Absolute Values\nuptime: "));
li_g_string_append_len(html, CONST_STR_LEN("# Absolute Values\nuptime: "));
li_string_append_int(html, (gint64)uptime);
g_string_append_len(html, CONST_STR_LEN("\nmemory_usage: "));
li_g_string_append_len(html, CONST_STR_LEN("\nmemory_usage: "));
li_string_append_int(html, li_memory_usage());
g_string_append_len(html, CONST_STR_LEN("\nrequests_abs: "));
li_g_string_append_len(html, CONST_STR_LEN("\nrequests_abs: "));
li_string_append_int(html, totals->requests);
g_string_append_len(html, CONST_STR_LEN("\ntraffic_out_abs: "));
li_g_string_append_len(html, CONST_STR_LEN("\ntraffic_out_abs: "));
li_string_append_int(html, totals->bytes_out);
g_string_append_len(html, CONST_STR_LEN("\ntraffic_in_abs: "));
li_g_string_append_len(html, CONST_STR_LEN("\ntraffic_in_abs: "));
li_string_append_int(html, totals->bytes_in);
g_string_append_len(html, CONST_STR_LEN("\nconnections_abs: "));
li_g_string_append_len(html, CONST_STR_LEN("\nconnections_abs: "));
li_string_append_int(html, total_connections);
/* average since start */
g_string_append_len(html, CONST_STR_LEN("\n\n# Average Values (since start)\nrequests_avg: "));
li_g_string_append_len(html, CONST_STR_LEN("\n\n# Average Values (since start)\nrequests_avg: "));
li_string_append_int(html, totals->requests / uptime);
g_string_append_len(html, CONST_STR_LEN("\ntraffic_out_avg: "));
li_g_string_append_len(html, CONST_STR_LEN("\ntraffic_out_avg: "));
li_string_append_int(html, totals->bytes_out / uptime);
g_string_append_len(html, CONST_STR_LEN("\ntraffic_in_avg: "));
li_g_string_append_len(html, CONST_STR_LEN("\ntraffic_in_avg: "));
li_string_append_int(html, totals->bytes_in / uptime);
g_string_append_len(html, CONST_STR_LEN("\nconnections_avg: "));
li_g_string_append_len(html, CONST_STR_LEN("\nconnections_avg: "));
li_string_append_int(html, totals->active_cons_cum / uptime);
/* average last 5 seconds */
g_string_append_len(html, CONST_STR_LEN("\n\n# Average Values (5 seconds)\nrequests_avg_5sec: "));
li_g_string_append_len(html, CONST_STR_LEN("\n\n# Average Values (5 seconds)\nrequests_avg_5sec: "));
li_string_append_int(html, totals->requests_5s_diff / 5);
g_string_append_len(html, CONST_STR_LEN("\ntraffic_out_avg_5sec: "));
li_g_string_append_len(html, CONST_STR_LEN("\ntraffic_out_avg_5sec: "));
li_string_append_int(html, totals->bytes_out_5s_diff / 5);
g_string_append_len(html, CONST_STR_LEN("\ntraffic_in_avg_5sec: "));
li_g_string_append_len(html, CONST_STR_LEN("\ntraffic_in_avg_5sec: "));
li_string_append_int(html, totals->bytes_in_5s_diff / 5);
g_string_append_len(html, CONST_STR_LEN("\nconnections_avg_5sec: "));
li_g_string_append_len(html, CONST_STR_LEN("\nconnections_avg_5sec: "));
li_string_append_int(html, totals->active_cons_5s / 5);
/* connection states */
g_string_append_len(html, CONST_STR_LEN("\n\n# Connection States\nconnection_state_start: "));
li_g_string_append_len(html, CONST_STR_LEN("\n\n# Connection States\nconnection_state_start: "));
li_string_append_int(html, connection_count[LI_CON_STATE_REQUEST_START]);
g_string_append_len(html, CONST_STR_LEN("\nconnection_state_read_header: "));
li_g_string_append_len(html, CONST_STR_LEN("\nconnection_state_read_header: "));
li_string_append_int(html, connection_count[LI_CON_STATE_READ_REQUEST_HEADER]);
g_string_append_len(html, CONST_STR_LEN("\nconnection_state_handle_request: "));
li_g_string_append_len(html, CONST_STR_LEN("\nconnection_state_handle_request: "));
li_string_append_int(html, connection_count[LI_CON_STATE_HANDLE_MAINVR]);
g_string_append_len(html, CONST_STR_LEN("\nconnection_state_write_response: "));
li_g_string_append_len(html, CONST_STR_LEN("\nconnection_state_write_response: "));
li_string_append_int(html, connection_count[LI_CON_STATE_WRITE]);
g_string_append_len(html, CONST_STR_LEN("\nconnection_state_keep_alive: "));
li_g_string_append_len(html, CONST_STR_LEN("\nconnection_state_keep_alive: "));
li_string_append_int(html, connection_count[LI_CON_STATE_KEEP_ALIVE]);
g_string_append_len(html, CONST_STR_LEN("\nconnection_state_upgraded: "));
li_g_string_append_len(html, CONST_STR_LEN("\nconnection_state_upgraded: "));
li_string_append_int(html, connection_count[LI_CON_STATE_UPGRADED]);
/* status cpdes */
g_string_append_len(html, CONST_STR_LEN("\n\n# Status Codes (since start)\nstatus_1xx: "));
li_g_string_append_len(html, CONST_STR_LEN("\n\n# Status Codes (since start)\nstatus_1xx: "));
li_string_append_int(html, mod_status_response_codes[0]);
g_string_append_len(html, CONST_STR_LEN("\nstatus_2xx: "));
li_g_string_append_len(html, CONST_STR_LEN("\nstatus_2xx: "));
li_string_append_int(html, mod_status_response_codes[1]);
g_string_append_len(html, CONST_STR_LEN("\nstatus_3xx: "));
li_g_string_append_len(html, CONST_STR_LEN("\nstatus_3xx: "));
li_string_append_int(html, mod_status_response_codes[2]);
g_string_append_len(html, CONST_STR_LEN("\nstatus_4xx: "));
li_g_string_append_len(html, CONST_STR_LEN("\nstatus_4xx: "));
li_string_append_int(html, mod_status_response_codes[3]);
g_string_append_len(html, CONST_STR_LEN("\nstatus_5xx: "));
li_g_string_append_len(html, CONST_STR_LEN("\nstatus_5xx: "));
li_string_append_int(html, mod_status_response_codes[4]);
li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain"));
@ -880,31 +880,31 @@ static GString *status_info_auto(liVRequest *vr, guint uptime, liStatistics *tot
html = g_string_sized_new(1024 - 1);
/* absolute values */
g_string_append_len(html, CONST_STR_LEN("Total Accesses: "));
li_g_string_append_len(html, CONST_STR_LEN("Total Accesses: "));
li_string_append_int(html, totals->requests);
g_string_append_len(html, CONST_STR_LEN("\nTotal kBytes: "));
li_g_string_append_len(html, CONST_STR_LEN("\nTotal kBytes: "));
li_string_append_int(html, totals->bytes_out / 1024);
g_string_append_len(html, CONST_STR_LEN("\nUptime: "));
li_g_string_append_len(html, CONST_STR_LEN("\nUptime: "));
li_string_append_int(html, (gint64)uptime);
/* connection states */
g_string_append_len(html, CONST_STR_LEN("\nBusyServers: "));
li_g_string_append_len(html, CONST_STR_LEN("\nBusyServers: "));
li_string_append_int(html, connection_count[3]+connection_count[4]+connection_count[5]+connection_count[6]+connection_count[7]);
g_string_append_len(html, CONST_STR_LEN("\nIdleServers: "));
li_g_string_append_len(html, CONST_STR_LEN("\nIdleServers: "));
li_string_append_int(html, connection_count[0]+connection_count[1]+connection_count[2]);
/* average since start */
g_string_append_len(html, CONST_STR_LEN("\nTraffic: "));
li_g_string_append_len(html, CONST_STR_LEN("\nTraffic: "));
li_string_append_int(html, totals->bytes_out / uptime);
/* average last 5 seconds */
g_string_append_len(html, CONST_STR_LEN("\nTraffic5s: "));
li_g_string_append_len(html, CONST_STR_LEN("\nTraffic5s: "));
li_string_append_int(html, totals->bytes_out_5s_diff / 5);
/* output scoreboard */
g_string_append_len(html, CONST_STR_LEN("\nScoreboard: "));
li_g_string_append_len(html, CONST_STR_LEN("\nScoreboard: "));
for (i = 0; i <= LI_CON_STATE_LAST; i++) {
for (j = 0; j < connection_count[i]; j++) {
g_string_append_c(html, liConnectionState_short[i]);
}
}
g_string_append_len(html, CONST_STR_LEN("\n"));
li_g_string_append_len(html, CONST_STR_LEN("\n"));
li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain"));
@ -1017,7 +1017,7 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
html = g_string_sized_new(8*1024-1);
tmp_str = g_string_sized_new(10);
g_string_append_len(html, CONST_STR_LEN(html_header));
li_g_string_append_len(html, CONST_STR_LEN(html_header));
/* auto refresh */
{
@ -1026,12 +1026,12 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
gchar c;
if (li_querystring_find(vr->request.uri.query, CONST_STR_LEN("refresh"), &val, &len)) {
g_string_append_len(html, CONST_STR_LEN("<meta http-equiv=\"refresh\" content=\""));
li_g_string_append_len(html, CONST_STR_LEN("<meta http-equiv=\"refresh\" content=\""));
/* temp char swap */
c = val[len]; val[len] = '\0';
li_string_encode_append(val, html, LI_ENCODING_HTML);
val[len] = c;
g_string_append_len(html, CONST_STR_LEN("\">\n"));
li_g_string_append_len(html, CONST_STR_LEN("\">\n"));
}
}
@ -1040,14 +1040,14 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
GString* css = _OPTIONPTR(vr, p, 0).string;
if (!css || !css->len) /* default css */
g_string_append_len(html, CONST_STR_LEN(css_default));
li_g_string_append_len(html, CONST_STR_LEN(css_default));
else if (g_str_equal(css->str, "blue")) /* blue css */
g_string_append_len(html, CONST_STR_LEN(css_blue));
li_g_string_append_len(html, CONST_STR_LEN(css_blue));
else /* external css */
g_string_append_printf(html, " <link rel=\"stylesheet\" rev=\"stylesheet\" href=\"%s\" media=\"screen\" />\n", css->str);
}
g_string_append_len(html, CONST_STR_LEN(
li_g_string_append_len(html, CONST_STR_LEN(
" </head>\n"
" <body>\n"
));
@ -1093,7 +1093,7 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
slim_fd = slim_core = "unknown";
#endif
g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Server info</strong></div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Server info</strong></div>\n"));
g_string_append_printf(html, html_server_info,
g_get_host_name(), g_get_user_name(), getuid(), li_event_loop_backend_string(&vr->wrk->loop),
slim_fd, g_atomic_int_get(&vr->wrk->srv->max_connections), slim_core, (guint64) vr->wrk->srv->io_timeout
@ -1106,8 +1106,8 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
/* library info */
{
g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Libraries</strong></div>\n"));
g_string_append_len(html, CONST_STR_LEN(html_libinfo_th));
li_g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Libraries</strong></div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(html_libinfo_th));
g_string_truncate(tmp_str, 0);
g_string_append_printf(tmp_str, "%u.%u.%u", glib_major_version, glib_minor_version, glib_micro_version);
@ -1129,15 +1129,15 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
vr->wrk->tmp_str->str
);
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
}
/* libev info */
{
guint i;
g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>libev backends</strong></div>\n"));
g_string_append_len(html, CONST_STR_LEN(html_libev_th));
li_g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>libev backends</strong></div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(html_libev_th));
/* supported backend, aka compiled in */
i = ev_supported_backends();
@ -1161,7 +1161,7 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
i & EVBACKEND_PORT ? "yes" : "no"
);
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
}
/* list modules */
@ -1171,8 +1171,8 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
GHashTableIter iter;
GArray *list = g_array_sized_new(FALSE, FALSE, sizeof(gchar*), g_hash_table_size(vr->wrk->srv->plugins));
g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Loaded modules</strong></div>\n"));
g_string_append_len(html, CONST_STR_LEN(" <table cellspacing=\"0\">\n"));
li_g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Loaded modules</strong></div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" <table cellspacing=\"0\">\n"));
g_hash_table_iter_init(&iter, vr->wrk->srv->plugins);
@ -1185,11 +1185,11 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
for (i = 1; i < list->len; i++) {
if (col == 0) {
g_string_append_len(html, CONST_STR_LEN(" <tr>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" <tr>\n"));
col++;
}
else if (col == 5) {
g_string_append_len(html, CONST_STR_LEN(" </tr>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </tr>\n"));
col = 0;
continue;
} else {
@ -1201,12 +1201,12 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
if (col) {
for (i = 5 - col; i; i--)
g_string_append_len(html, CONST_STR_LEN(" <td></td>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" <td></td>\n"));
g_string_append_len(html, CONST_STR_LEN(" </tr>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </tr>\n"));
}
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
g_array_free(list, TRUE);
}
@ -1216,19 +1216,19 @@ static liHandlerResult status_info_runtime(liVRequest *vr, liPlugin *p) {
gchar **e;
gchar **env = g_listenv();
g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Process environment</strong></div>\n"));
g_string_append_len(html, CONST_STR_LEN(" <table cellspacing=\"0\">\n"));
li_g_string_append_len(html, CONST_STR_LEN(" <div class=\"title\"><strong>Process environment</strong></div>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" <table cellspacing=\"0\">\n"));
for (e = env; *e; e++) {
g_string_append_printf(html, " <tr><td class=\"left\">%s</td><td class=\"left\">%s</td></tr>\n", *e, getenv(*e));
}
g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
li_g_string_append_len(html, CONST_STR_LEN(" </table>\n"));
g_strfreev(env);
}
g_string_append_len(html, CONST_STR_LEN(
li_g_string_append_len(html, CONST_STR_LEN(
" </body>\n"
"</html>\n"
));

View File

@ -103,10 +103,10 @@ static liHandlerResult userdir(liVRequest *vr, gpointer param, gpointer *context
part = &g_array_index(parts, userdir_part, i);
switch (part->type) {
case USERDIR_PART_STRING:
g_string_append_len(vr->physical.doc_root, GSTR_LEN(part->data.str));
li_g_string_append_len(vr->physical.doc_root, GSTR_LEN(part->data.str));
break;
case USERDIR_PART_USERNAME:
g_string_append_len(vr->physical.doc_root, username, username_len);
li_g_string_append_len(vr->physical.doc_root, username, username_len);
has_username = TRUE;
break;
case USERDIR_PART_LETTER:
@ -120,7 +120,7 @@ static liHandlerResult userdir(liVRequest *vr, gpointer param, gpointer *context
/* pattern without username, append it. /usr/web/ => /usr/web/user/ */
if (vr->physical.doc_root->str[vr->physical.doc_root->len-1] != G_DIR_SEPARATOR)
g_string_append_c(vr->physical.doc_root, G_DIR_SEPARATOR);
g_string_append_len(vr->physical.doc_root, username, username_len);
li_g_string_append_len(vr->physical.doc_root, username, username_len);
}
/* ensure that docroot is ending with a slash */
@ -129,15 +129,15 @@ static liHandlerResult userdir(liVRequest *vr, gpointer param, gpointer *context
/* build physical path: docroot + uri.path */
g_string_truncate(vr->physical.path, 0);
g_string_append_len(vr->physical.path, GSTR_LEN(vr->physical.doc_root));
g_string_append_len(vr->physical.path, username + username_len, vr->request.uri.path->str - username - username_len);
li_g_string_append_len(vr->physical.path, GSTR_LEN(vr->physical.doc_root));
li_g_string_append_len(vr->physical.path, username + username_len, vr->request.uri.path->str - username - username_len);
/* rewrite request path to skip username */
g_string_truncate(vr->wrk->tmp_str, 0);
g_string_append_len(vr->wrk->tmp_str, username + username_len, vr->request.uri.path->str - username - username_len);
li_g_string_append_len(vr->wrk->tmp_str, username + username_len, vr->request.uri.path->str - username - username_len);
g_string_truncate(vr->request.uri.path, 0);
if (vr->wrk->tmp_str->len)
g_string_append_len(vr->request.uri.path, GSTR_LEN(vr->wrk->tmp_str));
li_g_string_append_len(vr->request.uri.path, GSTR_LEN(vr->wrk->tmp_str));
else
g_string_append_c(vr->request.uri.path, G_DIR_SEPARATOR);

View File

@ -366,7 +366,7 @@ INLINE liSSLClientHelloParserResult _li_ssl_client_hello_parse(liSSLClientHelloP
case 5:
if (0 == context->sni_type && !context->sni_complete) {
guint take = MIN(context->sni_hostname_remaining, (guint) (extension_pe - p));
g_string_append_len(server_name, (gchar*) p, take);
li_g_string_append_len(server_name, (gchar*) p, take);
context->sni_hostname_remaining -= take;
p += take;
if (0 == context->sni_hostname_remaining) {

45
src/unittests/meson.build Normal file
View File

@ -0,0 +1,45 @@
unittests = {
'Chunk-UnitTest': {
'binary': 'test-chunk',
'sources': ['test-chunk.c'],
},
'HttpRequestParser-UnitTest': {
'binary': 'test-http-request-parser',
'sources': ['test-http-request-parser.c'],
},
'IpParser-UnitTest': {
'binary': 'test-ip-parser',
'sources': ['test-ip-parser.c'],
},
'Radix-UnitTest': {
'binary': 'test-radix',
'sources': ['test-radix.c'],
},
'RangeParser-UnitTest': {
'binary': 'test-range-parser',
'sources': ['test-range-parser.c'],
},
'Utils-UnitTest': {
'binary': 'test-utils',
'sources': ['test-utils.c'],
},
}
foreach name, def: unittests
test_bin = executable(
def['binary'],
def['sources'],
include_directories: inc_dir,
dependencies: main_deps + def.get('dependencies', []),
link_with: [
lib_shared,
lib_common,
],
build_by_default: false,
)
test(
name,
test_bin,
protocol: 'tap',
)
endforeach

16
tests/meson.build Normal file
View File

@ -0,0 +1,16 @@
runtest_file = files('runtests.py')
test(
'http',
runtest_file,
args: [
'--angel', bin_angel.full_path(),
'--worker', bin_worker.full_path(),
'--plugindir', modules_build_dir,
],
depends: [
bin_angel,
bin_worker,
enabled_modules,
],
)

View File

@ -6,7 +6,7 @@ from pylt.requests import CurlRequest
# userI:passI for I in [1..4] with [apr-md5, crypt, plain and apr-sha]
PASSWORDS = """user1:$apr1$mhpONdUp$xSRcAbK2F6hLFUzW59tzW/
user2:JTMoqfZHCS0aI
# user2:JTMoqfZHCS0aI
user3:pass3
user4:{SHA}LbTBgR9CRYKpD41+53mVzwGNlEM=
"""
@ -34,10 +34,11 @@ class TestCryptFail(CurlRequest):
AUTH = "user2:test2"
class TestCryptSuccess(CurlRequest):
URL = "/test.txt"
EXPECT_RESPONSE_CODE = 200
AUTH = "user2:pass2"
# no-prefix crypt deprecated
# class TestCryptSuccess(CurlRequest):
# URL = "/test.txt"
# EXPECT_RESPONSE_CODE = 200
# AUTH = "user2:pass2"
class TestPlainFail(CurlRequest):