├── .gitignore ├── BSDmakefile ├── ChangeLog ├── DESIGN ├── INFO ├── LICENSE ├── LICENSE.OpenSSL ├── Makefile ├── Makefile.dist ├── README ├── README.CyaSSL ├── README.dist ├── THANKS ├── TODO ├── VERSION ├── build ├── libcrypto.c ├── libcyassl.c ├── libopenssl.c ├── libopenssl_psk.c ├── libpthread.c ├── libu │ └── Makefile ├── libz.c ├── makecheck │ ├── GNUmakefile │ └── Makefile ├── makl_checkfork ├── makl_checkstackp ├── makl_va_list_by_value └── va_list_by_value.c ├── configure ├── configure.help ├── contrib ├── Makefile ├── iocat │ ├── Makefile │ ├── iocat.c │ └── test.sh └── iowc │ ├── Makefile │ └── iowc.c ├── doc ├── Makefile ├── contrib │ ├── apache.mime_types │ ├── rfc0822.txt │ ├── rfc1867.txt │ ├── rfc1945.txt │ ├── rfc2616.txt │ └── rfc2617.txt ├── doxy │ ├── DoxygenLayout.xml │ ├── Makefile │ ├── images │ │ ├── kl1_arch.jpg │ │ ├── kl1_proxy.gif │ │ ├── kl_bg.png │ │ └── koan2-blue.jpg │ ├── kl1.doxy.in │ └── src │ │ ├── kl.css │ │ ├── kl_footer.html │ │ └── toc.txt ├── example-site │ ├── etc │ │ ├── kloned.conf │ │ └── kloned.pem │ └── www │ │ ├── index.kl1 │ │ └── kl.css ├── man │ ├── Makefile │ ├── klone.1 │ ├── kloned.8 │ └── kloned.conf.5 └── var │ ├── kloned.conf.example │ ├── memlog.klone │ └── setkey.klone ├── etc ├── klone.vim ├── kloned-accesslog.conf ├── kloned-cgi.conf ├── kloned-embed.conf ├── kloned-https.conf ├── kloned-nodisk-clientses.conf ├── kloned-nodisk-memoryses.conf ├── kloned-psk.conf ├── kloned-rhel.init ├── kloned-v6.conf ├── kloned-vhost.conf ├── kloned.pem └── psk.db ├── klone ├── Makefile ├── access.h ├── atom.h ├── backend.h ├── broker.h ├── caes.h ├── ccipher.h ├── cgi.h ├── cgzip.h ├── cnull.h ├── codec.h ├── codecs.h ├── context.h ├── dypage.h ├── emb.h ├── embpage.h ├── field.h ├── header.h ├── hook.h ├── hookprv.h ├── http.h ├── io.h ├── ioprv.h ├── kilt.h ├── kilt_urls.h ├── klog.h ├── klogprv.h ├── klone.h ├── md5.h ├── mime_map.h ├── os.h ├── page.h ├── parser.h ├── ppc.h ├── ppc_cmd.h ├── request.h ├── response.h ├── rsfilter.h ├── run.h ├── server.h ├── server_ppc_cmd.h ├── ses_prv.h ├── session.h ├── supplier.h ├── timer.h ├── tls.h ├── tlsprv.h ├── translat.h ├── uc.h ├── utils.h ├── va.h ├── var.h ├── varprv.h ├── vars.h ├── version.h └── vhost.h ├── pkg ├── Makefile.doc └── Makefile.doxy.doc ├── site ├── Makefile └── register-def.c ├── skin └── default │ ├── DISTFILES │ ├── LICENSE │ ├── LICENSE.OpenSSL │ ├── Makefile.dist │ ├── Makefile.help │ ├── Makefile.in │ ├── README │ ├── build │ ├── host │ │ └── Makefile │ ├── makecheck │ │ ├── GNUmakefile │ │ └── Makefile │ ├── mk │ │ └── klone-app.mk │ └── target │ │ └── Makefile │ ├── configure │ ├── pack.sh │ ├── share │ ├── Makefile.example │ └── klapp.mk │ └── webapp │ ├── etc │ └── kloned.conf │ └── www │ ├── images │ └── kl_bg.png │ ├── index.kl1 │ └── kl.css ├── src ├── Makefile ├── kloned │ ├── Makefile │ ├── atom.c │ ├── child.c │ ├── child.h │ ├── entry.c │ ├── main.c │ ├── main.h │ ├── ppc.c │ ├── ppc_access_log.c │ ├── ppc_fork_child.c │ ├── ppc_log_add.c │ ├── ppc_log_get.c │ ├── ppc_nop.c │ ├── server.c │ └── server_s.h ├── libbackend │ ├── Makefile │ └── backend.c ├── libcodec │ ├── Makefile │ ├── cipher.c │ ├── cipher_cyassl.c │ ├── codec.c │ ├── gzip.c │ └── null.c ├── libemb │ ├── Makefile │ └── emb.c ├── libhook │ ├── Makefile │ ├── child_nfy.c │ ├── hook.c │ ├── req.c │ └── server_nfy.c ├── libhttp │ ├── Makefile │ ├── access.c │ ├── broker.c │ ├── cgi.c │ ├── dypage.c │ ├── http.c │ ├── http_s.h │ ├── sup_cgi.c │ ├── sup_emb.c │ ├── sup_fs.c │ ├── sup_kilt.c │ └── vhost.c ├── libio │ ├── Makefile │ ├── io.c │ ├── iofd.c │ ├── iomem.c │ └── iossl.c ├── libklog │ ├── Makefile │ ├── NOTES │ ├── common.c │ ├── file.c │ ├── klog.c │ ├── mem.c │ ├── syslog.c │ └── test │ │ ├── Makefile │ │ ├── log.conf │ │ └── main.c ├── libpage │ ├── Makefile │ ├── field.c │ ├── header.c │ ├── request.c │ ├── response.c │ ├── rsfilter.c │ ├── ses_client.c │ ├── ses_file.c │ ├── ses_mem.c │ ├── session.c │ ├── var.c │ └── vars.c ├── libtls │ ├── CONF │ ├── Makefile │ ├── TODO │ ├── cyassl.c │ ├── tls-server.conf │ ├── tls.c │ ├── tls_dh_autogen.c │ ├── tls_glue.c │ └── tls_psk.c ├── libtrans │ ├── Makefile │ ├── parser.c │ ├── trans_c.c │ └── translat.c ├── libutils │ ├── Makefile │ ├── date.c │ ├── md5.c │ ├── mime_map.c │ ├── path.c │ ├── pwd.c │ ├── timer.c │ ├── utils.c │ └── version.c └── tools │ ├── Makefile │ └── klone │ ├── Makefile │ ├── main.c │ ├── pm.c │ └── pm.h ├── test ├── Makefile ├── main.c ├── misc.c └── path.c └── webapp ├── Makefile ├── Makefile-webapp └── webapp.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | .depend 4 | pg_*.c 5 | pg_*.o 6 | pg_*.d 7 | pg_*.kld 8 | libu 9 | makl 10 | src/kloned/kloned 11 | contrib/iocat/iocat 12 | contrib/iowc/iowc 13 | doc/doxy/kl1.doxy 14 | doc/doxy/html 15 | Makefile.conf 16 | autogen.* 17 | site/register.c 18 | src/tools/klone/klone 19 | tags 20 | skin/default/Makefile 21 | klone_conf.h 22 | 23 | -------------------------------------------------------------------------------- /BSDmakefile: -------------------------------------------------------------------------------- 1 | # GNU make is required 2 | # 3 | world ${.TARGETS}: 4 | @echo "Please use GNU make" 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | KLone - Copyright (c) 2005-2012 by KoanLogic srl 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | Neither the name of the KoanLogic srl nor the names of its contributors may be 15 | used to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # source top dir 2 | KLONE_SRC_DIR := $(shell pwd) 3 | 4 | # makl vars 5 | export MAKL_DIR := ${KLONE_SRC_DIR}/makl 6 | MAKEFLAGS := -I ${MAKL_DIR}/mk 7 | 8 | SUBDIR = build/libu webapp site src klone doc 9 | 10 | ifeq ($(wildcard Makefile.conf),) 11 | help: 12 | @echo 13 | @echo " You must first run the configure script." 14 | @echo 15 | @echo " Run ./configure --help for the list of options" 16 | @echo 17 | endif 18 | 19 | include $(MAKL_DIR)/mk/subdir.mk 20 | 21 | # deps 22 | webapp site src: build/libu 23 | contrib: src 24 | 25 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | QUICKSTART 2 | ---------- 3 | 4 | NOTE: KLone needs GNU make in order to be built, which is not the default 'make' 5 | on most *BSD systems (usually you will find it as 'gmake' or 'gnumake'). 6 | 7 | 1) Configure and build KLone: 8 | 9 | $ ./configure && ${GNUMAKE} 10 | 11 | 2) Import the example web-application 12 | 13 | [ on Windows edit doc/example-site/etc/kloned.conf and remove syslog 14 | logging paragraph ] 15 | 16 | $ ${GNUMAKE} depend 17 | $ cd site && ../src/tools/klone/klone -c import ../doc/example-site 18 | $ cd .. && ${GNUMAKE} 19 | $ su 20 | # ${GNUMAKE} install 21 | 22 | 3) Launch the KLone executable: 23 | 24 | [ on Windows register the service with "kloned -i" and start it using 25 | the Services console ] 26 | 27 | $ kloned 28 | 29 | 4) Start your web browser: 30 | 31 | [ start your web browser and go to http://localhost:8080/ ] 32 | 33 | 34 | For further info and documentation, see http://www.koanlogic.com/klone 35 | -------------------------------------------------------------------------------- /README.CyaSSL: -------------------------------------------------------------------------------- 1 | 2 | CyaSSL: 3 | 4 | env CFLAGS=-DNO_FILESYSTEM ./configure --enable-opensslExtra \ 5 | --enable-singleThreaded 6 | make 7 | make install 8 | 9 | KLone: 10 | 11 | export LD_LIBRARY_PATH=/usr/local/cyassl/lib/ 12 | 13 | ./configure --lib-cyassl=/usr/local/cyassl/ --enable_cyassl ... 14 | makl 15 | 16 | Run a sample HTTPS application: 17 | 18 | cd site 19 | ../src/tools/klone/klone -c import ../doc/example-site/ 20 | cd .. 21 | makl 22 | ./src/kloned/kloned 23 | 24 | go to https://localhost:4443/ 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /README.dist: -------------------------------------------------------------------------------- 1 | # $Id: README.dist,v 1.9 2009/12/29 10:27:08 tho Exp $ 2 | 3 | $ cd skin/default && ./pack.sh 4 | 5 | # for releases: after testing etc 6 | $ git tag -f $(TAGNAME) 7 | $ git push origin master --tags 8 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | Special thanks to following people, who reported problems, provided patches and 2 | documentation, suggested improvements: 3 | 4 | Mickael Auger mickael.auger at gmail.com 5 | Davide Berra d.berra at esitelsrl.it 6 | Diana Borck diakat2000 at googlemail.com 7 | Radek Hnilica radek.hnilica at gmail.com 8 | Peter Iring peter.iring at siemens.com 9 | Christian Kelinski kelinski at gmail.com 10 | Kari Pahula kaol at iki.fi 11 | Mark Richards mark.richards at massmicro.com 12 | Steven Van Ingelgem steven at vaningelgem.be 13 | Senén de Diego atinar1@hotmail.com 14 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 3.1.0 2 | -------------------------------------------------------------------------------- /build/libcrypto.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | long ver; 6 | 7 | ver = SSLeay(); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /build/libcyassl.c: -------------------------------------------------------------------------------- 1 | #define NO_FILESYSTEM /* needed for CyaSSL_CTX_load_verify_buffer */ 2 | #include 3 | #include 4 | 5 | void SetErrorString(int , char* ); 6 | 7 | int main() 8 | { 9 | SSL_CTX *c = 0; 10 | void* f = 0; 11 | 12 | /* CyaSSL specific fun */ 13 | f = SetErrorString; 14 | 15 | /* defined if NO_FILESYSTEM is set */ 16 | f = CyaSSL_CTX_load_verify_buffer; 17 | 18 | /* defined if --enable-opensslExtra CyaSSL option has been used */ 19 | f = SSL_CTX_set_default_passwd_cb; 20 | 21 | /* defined in CyaSSL version of openssl/opensslv.h */ 22 | #ifndef CYASSL_OPENSSLV_H_ 23 | printf("openssl/opensslv.h doesn't seem to be the one from CyaSSL\n"); 24 | return 1; 25 | #endif 26 | 27 | /* defined in CyaSSL version of openssl/ssl.h */ 28 | #ifndef CYASSL_OPENSSL_H_ 29 | printf("openssl/ssl.h doesn't seem to be the one from CyaSSL\n"); 30 | return 1; 31 | #endif 32 | 33 | SSL_load_error_strings(); 34 | SSL_library_init(); 35 | 36 | (void*)SSL_CTX_new(SSLv23_server_method()); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /build/libopenssl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | long ver; 7 | 8 | /* check openssl version */ 9 | SSL_SESSION_new(); 10 | 11 | if (OPENSSL_VERSION_NUMBER < 0x00907000L) { 12 | printf("OpenSSL version 0.9.7 or better is required!\n"); 13 | return 1; 14 | } 15 | 16 | /* test linking to crypto */ 17 | ver = SSLeay(); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /build/libopenssl_psk.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main (void) 6 | { 7 | SSL_CTX ctx; 8 | 9 | /* check PSK */ 10 | SSL_CTX_set_psk_client_callback(&ctx, NULL); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /build/libpthread.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | pthread_self(); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /build/libu/Makefile: -------------------------------------------------------------------------------- 1 | include common.mk 2 | include ../../Makefile.conf 3 | 4 | PARTY_NAME = libu 5 | 6 | PARTY_NO_DOWN = true 7 | PARTY_NO_CHK = true 8 | PARTY_NO_DECOMP = true 9 | PARTY_NO_INSTALL = true 10 | 11 | PARTY_CONF = env MAKL_DIR=${SRCDIR}/makl ./configure 12 | PARTY_BASE = ../../libu 13 | PARTY_DEP = ${PARTY_BASE}/src/libu.a 14 | PARTY_ARGS = --prefix=${DESTDIR} --no_docs 15 | #PARTY_ARGS += --no_array 16 | PARTY_ARGS += --compat_1X 17 | 18 | ifneq ($(strip ${DEFOWN}),) 19 | PARTY_ARGS += --defown=${DEFOWN} 20 | endif 21 | 22 | ifneq ($(strip ${DEFGRP}),) 23 | PARTY_ARGS += --defgrp=${DEFGRP} 24 | endif 25 | 26 | ifdef LIBU_DEBUG 27 | PARTY_ARGS += --enable_debug 28 | endif 29 | 30 | ifneq ($(strip ${LIBU_LIBS}),) 31 | PARTY_ARGS += --libs=${LIBU_LIBS} 32 | endif 33 | 34 | include party.mk 35 | -------------------------------------------------------------------------------- /build/libz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | zlibVersion(); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /build/makecheck/GNUmakefile: -------------------------------------------------------------------------------- 1 | # if in this makefile then it's gnu make calling... 2 | all: 3 | 4 | -------------------------------------------------------------------------------- /build/makecheck/Makefile: -------------------------------------------------------------------------------- 1 | world ${.TARGETS}: 2 | @echo "You must use the GNU make." 3 | @echo "Please set the environment variable MAKE to the GNU make path" 4 | @echo "(ex. export MAKE=/bin/gnumake)" 5 | @exit 1 6 | 7 | -------------------------------------------------------------------------------- /build/makl_checkfork: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makl_checkfork,v 1.3 2008/10/03 19:38:27 stewy Exp $ 3 | # 4 | 5 | ##\brief Check if there's a working fork() 6 | ## 7 | ## Define HAVE_FORK 8 | ## 9 | ## \param $1 0:optional/1:required 10 | ## 11 | makl_checkfork () 12 | { 13 | tmpfile=${makl_run_dir}/snippet.c 14 | 15 | [ -z `makl_get "__noconfig__"` ] || return 16 | [ -z "$1" ] && makl_err 1 "missing argument (0=optional, 1=required)" 17 | 18 | makl_info "checking for fork() support" 19 | 20 | ${ECHO} " 21 | #include 22 | #include 23 | 24 | int main() { 25 | if(fork() < 0) 26 | return 1; 27 | return 0; 28 | } 29 | " > ${tmpfile} 30 | 31 | makl_compile_code 0 ${tmpfile} 32 | 33 | if [ $? -eq 0 ]; then 34 | makl_set_var "HAVE_FORK" 35 | return 0 36 | else 37 | [ $1 -eq 0 ] || makl_err 1 "failed fork check!" 38 | makl_unset_var "HAVE_FORK" 39 | makl_warn "failed check on optional fork check" 40 | return 1 41 | fi 42 | } 43 | -------------------------------------------------------------------------------- /build/makl_checkstackp: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makl_checkstackp,v 1.3 2009/10/26 14:38:58 tho Exp $ 3 | # 4 | 5 | ##\brief Check if -fstack-protector-all is supported by the compiler 6 | ## 7 | ## Define HAVE_STACK_PROTECTOR 8 | ## 9 | ## \param $1 0:optional/1:required 10 | ## 11 | makl_checkstackp() 12 | { 13 | tmpfile=${makl_run_dir}/snippet.c 14 | 15 | [ -z `makl_get "__noconfig__"` ] || return 16 | [ -z "$1" ] && makl_err 1 "missing argument (0=optional, 1=required)" 17 | 18 | makl_info "checking for gcc stack-protector support" 19 | 20 | ${ECHO} "int main(){return 0;}" > ${tmpfile} 21 | 22 | makl_compile_code 0 ${tmpfile} "-fstack-protector-all" 23 | 24 | if [ $? -eq 0 ]; then 25 | makl_set_var_mk "HAVE_STACK_PROTECTOR" 26 | return 0 27 | else 28 | [ $1 -eq 0 ] || makl_err 1 "failed -fstack-protector-all not supported!" 29 | makl_unset_var_mk "HAVE_STACK_PROTECTOR" 30 | makl_warn "failed check on optional -fstack-protector-all feature check" 31 | return 1 32 | fi 33 | } 34 | -------------------------------------------------------------------------------- /build/makl_va_list_by_value: -------------------------------------------------------------------------------- 1 | ## 2 | ## (un)define VA_LIST_BY_VALUE 3 | ## 4 | makl_va_list_by_value () 5 | { 6 | [ -z `makl_get "__noconfig__"` ] || return 7 | 8 | makl_info "checking va_list behaviour" 9 | 10 | makl_exec_code 0 build/va_list_by_value.c 11 | 12 | if [ $? -eq 0 ] 13 | then 14 | makl_set_var "VA_LIST_BY_VALUE" 15 | else 16 | makl_unset_var "VA_LIST_BY_VALUE" 17 | fi 18 | } 19 | -------------------------------------------------------------------------------- /build/va_list_by_value.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SZ 64 5 | 6 | int va_func (const char *fmt, ...) 7 | { 8 | va_list ap; 9 | char b1[SZ], b2[SZ]; 10 | 11 | va_start(ap, fmt); 12 | (void) vsnprintf(b1, SZ, fmt, ap); 13 | (void) vsnprintf(b2, SZ, fmt, ap); 14 | va_end(ap); 15 | 16 | return strcmp(b1, b2) == 0 ? 0 : 1; 17 | } 18 | 19 | int main (void) 20 | { 21 | return va_func("%s %d %c", "string", 100, 'x'); 22 | } 23 | -------------------------------------------------------------------------------- /configure.help: -------------------------------------------------------------------------------- 1 | 2 | 'MaKL' - a painless C project configuration tool 3 | 4 | Usage: ./CONFIGURE_SCRIPT [OPTION] ... 5 | 6 | OPTION can be defined as follows: 7 | 8 | --help [-h] display this help 9 | --help_gen [-g] generate new configure.help based on configuration 10 | --verbose [-v] show verbose debugging output 11 | --version [-V] display MaKL version 12 | --cross_compile configure for cross-compilation (no execution tests) 13 | --noclean do not clean cache at end of execution (testing only) 14 | --prefix=BASE set BASE directory for installation [BASE=] 15 | --dir-bin=BASE set BASE directory for binaries [BASE=/usr/local/bin] 16 | --dir-sbin=BASE set BASE directory for system binaries [BASE=/usr/local/sbin] 17 | --dir-conf=BASE set BASE directory for configuration [BASE=/usr/local/conf] 18 | --dir-inc=BASE set BASE directory for includes [BASE=/usr/local/includes] 19 | --dir-lib=BASE set BASE directory for libraries [BASE=/usr/local/lib] 20 | --dir-shlib=BASE set BASE directory for shared libraries [BASE=/usr/local/shlib] 21 | --dir-libex=BASE set BASE directory for executables run by programmes [BASE=/usr/local/libexec] 22 | --dir-var=BASE set BASE directory for various [BASE=/usr/local/var] 23 | --dir-share=BASE set BASE directory for shared data [BASE=/usr/local/share] 24 | --dir-man=BASE set BASE directory for man pages [BASE=/usr/local/share/man] 25 | --dir-doc=BASE set BASE directory for documentation [BASE=/usr/local/share/doc] 26 | 27 | --defown=USERID set default file owner id 28 | --defgrp=GROUPID set default file group id 29 | --defmode=MODE set default mode for regular files 30 | --defbinmode=MODE set default mode for binary files 31 | --lib-openssl=BASE set libopenssl to have BASE dir [] 32 | --lib-openssl_psk=BASE set libopenssl_psk to have BASE dir [] 33 | --lib-z=BASE set libz to have BASE dir [] 34 | 35 | --libs=BASE set all libs to have BASE dir 36 | --featx-doxygen=BASE set file for execution feature [] 37 | 38 | --enable-X=ID enable feature of type X and id ID 39 | --disable-X=ID disable feature of type X and id ID 40 | --enable_shared enable shared library build 41 | --program_suffix=SUFFIX append SUFFIX to installed program names 42 | --program_prefix=PREFIX append PREFIX to installed program names 43 | --script_suffix=SUFFIX append SUFFIX to installed script names 44 | --script_prefix=PREFIX append PREFIX to installed script names 45 | --enable_debug enables debugging of KLone app 46 | --enable_libu_debug enables debugging of LibU 47 | --enable_profile enables profiling 48 | --enable_sup_fs enables filesystem web access 49 | --enable_fs --enable_sup_fs alias 50 | --enable_sup_cgi enables external CGIs 51 | --enable_cgi --enable_sup_cgi alias 52 | --enable_warns set CFLAGS for extra warnings 53 | --disable_cxx disable C++ support 54 | --install_daemon_only install just Klone daemon file 55 | --daemon_name=NAME set the name of Klone daemon 56 | --enable_hooks call user-provided hooks_setup() to register hooks 57 | 58 | Legend: 59 | <*>: required dependency 60 | : optional dependency 61 | 62 | -------------------------------------------------------------------------------- /contrib/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.6 2005/10/26 15:24:10 tat Exp $ 2 | 3 | include ../Makefile.conf 4 | 5 | SUBDIR = iocat iowc 6 | 7 | include subdir.mk 8 | -------------------------------------------------------------------------------- /contrib/iocat/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.7 2007/07/07 09:05:12 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | PROG = iocat 7 | SRCS = iocat.c 8 | 9 | NO_INSTALL = true 10 | 11 | CFLAGS += ${SSL_CFLAGS} ${LIBZ_CFLAGS} 12 | LDFLAGS += ${SSL_LDFLAGS} ${LIBZ_LDFLAGS} 13 | 14 | LDADD += ../../src/libhttp/libhttp.a \ 15 | ../../src/libutils/libutils.a \ 16 | ../../src/libpage/libpage.a \ 17 | ../../src/libbackend/libbackend.a \ 18 | ../../src/libemb/libemb.a \ 19 | ../../src/libio/libio.a \ 20 | ../../src/libtls/libtls.a \ 21 | ../../src/libcodec/libcodec.a \ 22 | ../../site/libsite.a 23 | 24 | LDADD += ../../libu/srcs/libu.a 25 | 26 | include prog.mk 27 | -------------------------------------------------------------------------------- /contrib/iocat/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | IOCAT=iocat 4 | CODECS="-z -c" 5 | 6 | export FQN="$1" 7 | 8 | $IOCAT -e $CODECS < "$1" | $IOCAT -d $CODECS | diff - "$1" 9 | 10 | if [ $? -eq 0 ]; then 11 | echo -n "." 12 | else 13 | echo 14 | echo "$1" 15 | echo 16 | fi 17 | -------------------------------------------------------------------------------- /contrib/iowc/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.7 2007/07/07 09:05:12 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | PROG = iowc 7 | SRCS = iowc.c 8 | 9 | NO_INSTALL = true 10 | 11 | CFLAGS += ${LIBOPENSSL_CFLAGS} ${LIBZ_CFLAGS} 12 | LDFLAGS += ${LIBOPENSSL_LDFLAGS} ${LIBZ_LDFLAGS} 13 | 14 | LDADD += ../../src/libhttp/libhttp.a \ 15 | ../../src/libutils/libutils.a \ 16 | ../../src/libpage/libpage.a \ 17 | ../../src/libbackend/libbackend.a \ 18 | ../../src/libemb/libemb.a \ 19 | ../../src/libio/libio.a \ 20 | ../../src/libtls/libtls.a \ 21 | ../../src/libcodec/libcodec.a \ 22 | ../../site/libsite.a 23 | 24 | LDADD += ../../libu/srcs/libu.a 25 | 26 | include prog.mk 27 | -------------------------------------------------------------------------------- /contrib/iowc/iowc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: iowc.c,v 1.4 2006/09/24 13:26:18 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | int facility = LOG_LOCAL0; 27 | 28 | typedef struct ctx_s 29 | { 30 | char *file_in, *file_out; 31 | char **arg; 32 | size_t narg; 33 | int encode; 34 | int decode; 35 | } context_t; 36 | 37 | context_t context, *ctx = &context; 38 | 39 | static void usage() 40 | { 41 | fprintf(stderr, 42 | "Usage: iowc [infile] \n" 43 | ); 44 | exit(1); 45 | } 46 | 47 | static void parse_opt(int argc, char **argv) 48 | { 49 | int ret; 50 | 51 | while((ret = getopt(argc, argv, "h")) != -1) 52 | { 53 | switch(ret) 54 | { 55 | default: 56 | case 'h': 57 | usage(); 58 | } 59 | } 60 | 61 | ctx->narg = argc - optind; 62 | ctx->arg = argv + optind; 63 | 64 | if(ctx->narg > 0) 65 | ctx->file_in = ctx->arg[0]; 66 | } 67 | 68 | int main(int argc, char **argv) 69 | { 70 | enum { LINE_BUFSZ = 4096 }; 71 | ssize_t c; 72 | io_t *in; 73 | int n; 74 | char line[LINE_BUFSZ]; 75 | 76 | memset(ctx, 0, sizeof(context_t)); 77 | 78 | parse_opt(argc, argv); 79 | 80 | /* open the input stream */ 81 | if(ctx->file_in) 82 | { 83 | dbg_err_if(u_file_open(ctx->file_in, O_RDONLY, &in)); 84 | dbg_err_if(io_name_set(in, ctx->file_in)); 85 | } else { 86 | dbg_err_if(io_fd_create(0, 0, &in)); 87 | dbg_err_if(io_name_set(in, "stdin")); 88 | } 89 | 90 | for(n = 0; (c = io_gets(in, line, LINE_BUFSZ)) > 0; ++n) 91 | ; 92 | 93 | fprintf(stdout, "%d lines\n", n); 94 | 95 | dbg_if(io_free(in)); 96 | 97 | return EXIT_SUCCESS; 98 | err: 99 | return EXIT_FAILURE; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.1 2005/11/24 23:54:12 stewy Exp $ 2 | 3 | SUBDIR = doxy man 4 | 5 | include subdir.mk 6 | -------------------------------------------------------------------------------- /doc/doxy/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.6 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | DOXYDEST = $(DESTDIR)/doc/klone/ 7 | 8 | ifdef HAVE_DOXYGEN 9 | 10 | all: 11 | $(PATH_DOXYGEN) kl1.doxy 12 | mkdir -p html/images 13 | cp -r images html 14 | 15 | ifdef INSTALL_DAEMON_ONLY 16 | install: 17 | else # !INSTALL_DAEMON_ONLY 18 | install: all 19 | $(MKINSTALLDIRS) -p $(DOXYDEST) 20 | cp -r html $(DOXYDEST) 21 | endif # INSTALL_DAEMON_ONLY 22 | 23 | uninstall: ; rm -rf $(DOXYDEST) 24 | clean: ; rm -rf html/ 25 | 26 | else # !HAVE_DOXYGEN 27 | 28 | all clean install uninstall: 29 | 30 | endif # HAVE_DOXYGEN 31 | 32 | depend cleandepend: 33 | -------------------------------------------------------------------------------- /doc/doxy/images/kl1_arch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koanlogic/klone/bfa77f491b837278ace8efaab84bef880fc9b225/doc/doxy/images/kl1_arch.jpg -------------------------------------------------------------------------------- /doc/doxy/images/kl1_proxy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koanlogic/klone/bfa77f491b837278ace8efaab84bef880fc9b225/doc/doxy/images/kl1_proxy.gif -------------------------------------------------------------------------------- /doc/doxy/images/kl_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koanlogic/klone/bfa77f491b837278ace8efaab84bef880fc9b225/doc/doxy/images/kl_bg.png -------------------------------------------------------------------------------- /doc/doxy/images/koan2-blue.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koanlogic/klone/bfa77f491b837278ace8efaab84bef880fc9b225/doc/doxy/images/koan2-blue.jpg -------------------------------------------------------------------------------- /doc/doxy/src/kl_footer.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | ←Products 5 |
6 |
7 | Copyright © 2005-2012 - KoanLogic S.r.l. - All rights reserved 8 |
9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /doc/doxy/src/toc.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * \mainpage KLone 3 | 4 | 5 | Below is a quick reference list of essential variables and functions used by 6 | all KLone applications. 7 | 8 | A more complete list is available following the above tabs. 9 | 10 | 11 | \section essvars Essential variables 12 | 13 | Any KLone dynamic page (*.kl1) can access the following predefined objects: 14 | 15 |
    16 |
  • \ref request "request_t" *request; \n 17 | \par \n 18 | Used to access all information related to the current HTTP request such\n 19 | as form variables, cookies, HTTP header fields, uploaded files, etc. 20 | 21 |
  • \ref response "response_t" *response; \n 22 | \par \n 23 | This object lets you access and modify the HTTP response entities such as \n 24 | header fields and status codes. 25 | 26 |
  • \ref session "session_t" *session; \n 27 | \par \n 28 | Sessions are objects which can be used to preserve client related \n 29 | information throughout subsequent accesses.\n 30 | Simple functions are provided to set/get {name, value} pairs. 31 | 32 |
  • \ref basic "io_t" *out; \n 33 | \par \n 34 | The output object is used to print out dynamically generated content. 35 | 36 |
37 | 38 | \section essfuncs Essential functions 39 | 40 |
    41 | 42 |
  • 43 | \code 44 | const char* request_get_arg (request_t *rq, const char *name) 45 | \endcode 46 | \par 47 | Return the value of a form variable. 48 | 49 |
  • 50 | \code 51 | const char* request_get_field_value(request_t *rq, const char *name); 52 | \endcode 53 | \par 54 | Return the value of an header field. 55 | 56 |
  • 57 | \code 58 | int response_redirect(response_t *rs, const char *url) 59 | \endcode 60 | \par 61 | Redirect to the specified URL. 62 | 63 |
  • 64 | \code 65 | const char *session_get(session_t *ss, const char *name) 66 | \endcode 67 | \par 68 | Get the value of a session variable. 69 | 70 |
  • 71 | \code 72 | int session_set(session_t *ss, const char *name, const char *value) 73 | \endcode 74 | \par 75 | Set the value of a session variable. 76 | 77 |
78 | 79 | */ 80 | 81 | /** 82 | * \defgroup http Dynamic page interfaces 83 | * \{ 84 | * \par 85 | * Basic knowledge of the HTTP protocol is assumed. Hence only the 86 | * essential information is given. Some useful references are: 87 | * - RFC 2616 for a complete description of HTTP 1.1 header fields 88 | * - RFC 2109 for cookie format 89 | * - RFC 822 for standard data type formats 90 | * - http://www.iana.org/assignments/media-types/ for an updated 91 | * list of possible mime-types 92 | */ 93 | 94 | /** 95 | * \defgroup request Request Handling 96 | * \ingroup http 97 | */ 98 | 99 | /** 100 | * \defgroup response Response Handling 101 | * \ingroup http 102 | */ 103 | 104 | /** 105 | * \defgroup session Sessions 106 | * \ingroup http 107 | */ 108 | 109 | /** 110 | * \} 111 | */ 112 | 113 | /** 114 | * \defgroup io Input/Output 115 | * \{ 116 | * \par 117 | */ 118 | 119 | /** 120 | * \defgroup basic Basic Functions 121 | * \ingroup io 122 | */ 123 | 124 | /** 125 | * \defgroup filters Filters for Compression and Encryption 126 | * \ingroup io 127 | */ 128 | 129 | /** 130 | * \} 131 | */ 132 | 133 | /** 134 | * \defgroup ut Miscellaneous Utility Functions 135 | * \{ 136 | * \par 137 | * \} 138 | */ 139 | */ 140 | 141 | -------------------------------------------------------------------------------- /doc/example-site/etc/kloned.conf: -------------------------------------------------------------------------------- 1 | # Server List 2 | # append "my_https" to enable HTTP/S server 3 | # 4 | server_list my_http # my_https 5 | 6 | allow_root yes 7 | 8 | # use syslogd for logging 9 | log 10 | { 11 | type syslog 12 | syslog.facility LOG_LOCAL0 13 | } 14 | 15 | my_http 16 | { 17 | type http 18 | addr tcp4://*:8080 19 | 20 | dir_root /www # store your pages in /www into embfs 21 | 22 | # enable CGIs (./configure --enable_sup_cgi ... to enable CGI support) 23 | # dir_alias /cgi-bin /path/to/cgi-bin 24 | } 25 | 26 | my_https 27 | { 28 | type https 29 | addr tcp4://*:4443 30 | 31 | dir_root /www 32 | 33 | # certificate file (embfs or file system) 34 | cert_file /etc/kloned.pem 35 | } 36 | 37 | -------------------------------------------------------------------------------- /doc/example-site/etc/kloned.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQC7c0AbclOY54S368iW0NFUw2TbCRi9cCHifpSB7ZsW3/kvIGzM 3 | 42HuJcYiI5dppaazKwh0IudS58u2l1HqgK28p6yWewJeaZD2G4i51UH49ZMv0EaH 4 | nOlONEk69qH7WaMyjn4VIJPP3yVV+l6yT9kP67719c8xL6V/Ako76631VQIDAQAB 5 | AoGAWG9kNE64v++iPr8/kF+OEuZoQ6pEAMPRSLEdUTsPKziZsDElA3jXL+qkUmDm 6 | Q1KClg7cWyZIamWvR0KWxALXc9YDjm8jWllyeEOJvMOg87rHLmERt0ZVJ5kAhSwZ 7 | 4gQEghGwuYE5vEBmvwiQ7uJnJx9HP+M7LnjVMCUodVj6uRUCQQDhTbLSV/vROlkn 8 | mKzMGDXyx0A/LIcsg58+hsnljY5PxDywnrAXe6P4WWH7yvjU3fiOX8Kt/wHhFFJn 9 | AlfL+IW3AkEA1P1Gth8w6yUk8EcvGG7pLJ49JT/aiMClEICCTMalPfIm7BlPPmfI 10 | /btB9BhgzVJ2a54/tFFu768/DQW3L7I9UwJBAL63Osv7VlpB/f4aqwsI44HjUGsp 11 | kjMIJ+CR0I3USccT4hvP+FeofaBYaSzvH7txOlmqje0jk7+nqCkyPoeWk/kCQAa4 12 | h0av7Uc+QNAkLuRCe7EgvSUzwp2WFp9SrsnlasltnrTMh6ecdscq5YXiTwurknkK 13 | 4U+7UhjWGtM6XvFuWmkCQHaUdhV0dVsOZ2+z3Fk0FN8OxtB7QLLRTdMp6I+CKCw1 14 | pO+v0JT3mHBefUlakAICYqCLhRUa0ZuufIChgBBLuaQ= 15 | -----END RSA PRIVATE KEY----- 16 | -----BEGIN CERTIFICATE----- 17 | MIIDtjCCAx+gAwIBAgIBADANBgkqhkiG9w0BAQQFADCBnzELMAkGA1UEBhMCSVQx 18 | DjAMBgNVBAgTBUl0YWx5MQ4wDAYDVQQHEwVNb256YTEZMBcGA1UEChMQS29hbkxv 19 | Z2ljIHMuci5sLjEOMAwGA1UECxMFS0xvbmUxIjAgBgNVBAMTGUtMb25lIGV4YW1w 20 | bGUgY2VydGlmaWNhdGUxITAfBgkqhkiG9w0BCQEWEmluZm9Aa29hbmxvZ2ljLmNv 21 | bTAeFw0wNjAyMjQxNDAzNDRaFw0wNjAzMjYxNDAzNDRaMIGfMQswCQYDVQQGEwJJ 22 | VDEOMAwGA1UECBMFSXRhbHkxDjAMBgNVBAcTBU1vbnphMRkwFwYDVQQKExBLb2Fu 23 | TG9naWMgcy5yLmwuMQ4wDAYDVQQLEwVLTG9uZTEiMCAGA1UEAxMZS0xvbmUgZXhh 24 | bXBsZSBjZXJ0aWZpY2F0ZTEhMB8GCSqGSIb3DQEJARYSaW5mb0Brb2FubG9naWMu 25 | Y29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7c0AbclOY54S368iW0NFU 26 | w2TbCRi9cCHifpSB7ZsW3/kvIGzM42HuJcYiI5dppaazKwh0IudS58u2l1HqgK28 27 | p6yWewJeaZD2G4i51UH49ZMv0EaHnOlONEk69qH7WaMyjn4VIJPP3yVV+l6yT9kP 28 | 67719c8xL6V/Ako76631VQIDAQABo4H/MIH8MB0GA1UdDgQWBBSoZo+JdKieozmT 29 | Ll7RNZCar95mIDCBzAYDVR0jBIHEMIHBgBSoZo+JdKieozmTLl7RNZCar95mIKGB 30 | paSBojCBnzELMAkGA1UEBhMCSVQxDjAMBgNVBAgTBUl0YWx5MQ4wDAYDVQQHEwVN 31 | b256YTEZMBcGA1UEChMQS29hbkxvZ2ljIHMuci5sLjEOMAwGA1UECxMFS0xvbmUx 32 | IjAgBgNVBAMTGUtMb25lIGV4YW1wbGUgY2VydGlmaWNhdGUxITAfBgkqhkiG9w0B 33 | CQEWEmluZm9Aa29hbmxvZ2ljLmNvbYIBADAMBgNVHRMEBTADAQH/MA0GCSqGSIb3 34 | DQEBBAUAA4GBADA+6eChQK2ajtt5Pdv+8BCXMTZP7+O4dEcYxv9yEDXmIYOyh20m 35 | LoBrb10j7N0HYXTexfhyFAnZ5kKz85BXeFQIEC826brnwREYylPdtInms41j6Nje 36 | SY1Dr2FwJ2QXLWIVevdt0+IF7xm15VVS7dSLkKGM5W6J94OZqIovqpXS 37 | -----END CERTIFICATE----- 38 | -------------------------------------------------------------------------------- /doc/example-site/www/index.kl1: -------------------------------------------------------------------------------- 1 | <%! 2 | #include 3 | time_t now; 4 | %> 5 | 6 | KLone start page 7 | 8 | 9 | 10 |
11 | 12 |
13 |
14 |

Welcome to KLone (Ver. <%= KLONE_VERSION %>)!

15 |
16 |
17 |

18 | 19 |

20 | <% 21 | now = time(0); 22 | io_printf(out, "Time: %s", ctime(&now)); 23 | %> 24 |
25 | 26 |

27 | 28 | About KLone: 29 |

30 | 31 | Info
32 | Features
33 | Download
34 | Documentation
35 | 36 |
37 | 38 | 39 | Copyright (c) 2005-2012 by KoanLogic s.r.l. - All rights reserved. 40 | 41 |
42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /doc/man/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.3 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | MANFILES = klone.1 kloned.8 kloned.conf.5 7 | 8 | ifdef INSTALL_DAEMON_ONLY 9 | NO_INSTALL = true 10 | endif 11 | 12 | include man.mk 13 | -------------------------------------------------------------------------------- /doc/var/kloned.conf.example: -------------------------------------------------------------------------------- 1 | server_list my_http 2 | 3 | # use syslogd for logging 4 | log 5 | { 6 | type syslog 7 | syslog.facility LOG_LOCAL0 8 | } 9 | 10 | my_http 11 | { 12 | type http 13 | addr tcp4://*:8080 14 | dir_root /www # store your pages in /www into embfs 15 | } 16 | -------------------------------------------------------------------------------- /doc/var/memlog.klone: -------------------------------------------------------------------------------- 1 | <%! 2 | #include 3 | #include 4 | #include 5 | 6 | static int print_log_cb(const char* line, void* arg) 7 | { 8 | io_t *out = (io_t*)arg; 9 | 10 | io_printf(out, "%s", line); 11 | } 12 | 13 | %> 14 | 15 | 16 | in-memory logging viewer 17 | 18 | 19 | 20 | log : 21 | 22 | <% 23 | if(server_foreach_memlog_line(ctx->server, print_log_cb, out)) 24 | io_printf(out, ""); 25 | %> 26 |
error retrieving log lines
27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/var/setkey.klone: -------------------------------------------------------------------------------- 1 | 2 | KLone example page: set decryption key 3 | 4 | 5 |

Set decryption pass phrase:

6 |
12 | 26 |
7 |
8 | key:
9 |
10 |
11 |
13 | <% /* form submit handling */ 14 | 15 | vars_t *args = request_get_args(request); /* shortcut */ 16 | char *pp = NULL; 17 | 18 | if((pp = vars_get_value(args, "pp")) != NULL) 19 | { 20 | session_set(session, "KLONE_CIPHER_KEY", pp); 21 | io_printf(out, "Pass phrase saved.

"); 22 | } 23 | 24 | %>  25 |

27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /etc/klone.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: klone 3 | 4 | " For version 5.x: Clear all syntax items 5 | " For version 6.x: Quit when a syntax file was already loaded 6 | if version < 600 7 | syntax clear 8 | elseif exists("b:current_syntax") 9 | finish 10 | endif 11 | 12 | if !exists("main_syntax") 13 | let main_syntax = 'klone' 14 | endif 15 | 16 | " Source HTML syntax 17 | if version < 600 18 | source :p:h/html.vim 19 | else 20 | runtime! syntax/html.vim 21 | endif 22 | unlet b:current_syntax 23 | 24 | " Next syntax items are case-sensitive 25 | syn case match 26 | 27 | " Include C syntax 28 | syn include @cCode :p:h/c.vim 29 | 30 | syn region kloneDecl matchgroup=kloneTag start=/<%!/ keepend end=/%>/ contains=@cCode 31 | syn region kloneScript matchgroup=kloneTag start=/<%/ keepend end=/%>/ contains=@cCode 32 | syn region kloneExpr matchgroup=kloneTag start=/<%=/ keepend end=/%>/ contains=@cCode 33 | syn region kloneDirective start=/<%@/ end=/%>/ contains=htmlString,kloneDirName,kloneDirArg 34 | 35 | syn keyword kloneDirName contained include page taglib 36 | syn keyword kloneDirArg contained file uri prefix language extends import session buffer autoFlush 37 | syn keyword kloneDirArg contained isThreadSafe info errorPage contentType isErrorPage 38 | syn keyword kloneCommandName contained include 39 | syn keyword kloneCommandArg contained name value 40 | 41 | " Define the default highlighting. 42 | " For version 5.7 and earlier: only when not done already 43 | " For version 5.8 and later: only when an item doesn't have highlighting yet 44 | if version >= 508 || !exists("did_klone_syn_inits") 45 | if version < 508 46 | let did_klone_syn_inits = 1 47 | command -nargs=+ HiLink hi link 48 | else 49 | command -nargs=+ HiLink hi def link 50 | endif 51 | 52 | HiLink htmlComment Comment 53 | HiLink htmlCommentPart Comment 54 | " Be consistent with html highlight settings 55 | HiLink kloneTag htmlTag 56 | HiLink kloneDirective kloneTag 57 | HiLink kloneDirName htmlTagName 58 | HiLink kloneDirArg htmlArg 59 | HiLink kloneCommand kloneTag 60 | HiLink kloneCommandName htmlTagName 61 | "HiLink kloneCommandArg htmlArg 62 | delcommand HiLink 63 | endif 64 | 65 | if main_syntax == 'klone' 66 | unlet main_syntax 67 | endif 68 | 69 | let b:current_syntax = "klone" 70 | 71 | " vim: ts=8 72 | -------------------------------------------------------------------------------- /etc/kloned-accesslog.conf: -------------------------------------------------------------------------------- 1 | server_list main 2 | 3 | allow_root yes 4 | 5 | # use syslog for error logging 6 | log 7 | { 8 | type syslog 9 | syslog.facility LOG_LOCAL0 10 | } 11 | 12 | main 13 | { 14 | model prefork 15 | 16 | type http 17 | addr tcp4://*:8080 18 | 19 | # document root 20 | dir_root /path/to/dir/www 21 | 22 | # main server access log (syslog) 23 | access_log 24 | { 25 | type syslog 26 | syslog.facility LOG_LOCAL0 27 | 28 | # prefix of all log messages 29 | prefix [access_main] 30 | 31 | # don't log images and css 32 | dontlog *.css 33 | dontlog *.ico 34 | dontlog *.gif 35 | dontlog *.png 36 | dontlog *.jpg 37 | } 38 | 39 | 40 | # virtual host, applies when Host: one.example.com 41 | one.example.com 42 | { 43 | # virtual host document root 44 | dir_root /path/to/vhost/www 45 | 46 | # file based access log 47 | access_log 48 | { 49 | type file 50 | file.basename /tmp/access_wiki_log 51 | 52 | prefix [access_one] 53 | 54 | # just log .zip files downloads that don't start with "test" 55 | log *.zip 56 | 57 | dontlog test*.zip 58 | } 59 | } 60 | 61 | two.example.com 62 | { 63 | # virtual host document root 64 | dir_root /path/to/vhost/two/www 65 | 66 | # inherits access_log setting of the main server 67 | } 68 | 69 | three.example.com 70 | { 71 | # virtual host document root 72 | dir_root /path/to/vhost/three/www 73 | 74 | # access log disabled 75 | access_log no 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /etc/kloned-cgi.conf: -------------------------------------------------------------------------------- 1 | server_list my_http 2 | 3 | allow_root yes 4 | 5 | # shortcut, it's just an alias referenced by other vars 6 | php_cgi_path /usr/local/bin/php-cgi 7 | 8 | # use syslogd for logging 9 | log 10 | { 11 | type syslog 12 | syslog.facility LOG_LOCAL0 13 | } 14 | 15 | my_http 16 | { 17 | model prefork 18 | 19 | type http 20 | addr tcp4://*:8080 21 | 22 | dir_root /www # store your pages in /www into embfs 23 | 24 | # get /live/* uri from the file system (--enable_sup_fs must be used) 25 | dir_alias /live /dir/on/the/file/system/ 26 | 27 | # use the following filenames as index when a filename is not given 28 | # for ex. http://site/ or http://site/dir0/dir1/ 29 | index index.cgi index.php index.phtml 30 | 31 | # cgi related config (enable with ./configure --enable_sup_cgi ) 32 | cgi 33 | { 34 | # script_alias (i.e. the dir where scripts are allowed) 35 | script_alias /cgi-bin /dir/to/my/cgi-bin/ 36 | script_alias /cgi-bin2 /dir/to/my/second/cgi-bin-dir/ 37 | 38 | # run .cgi files as-is (must produce a valid HTTP reponse) 39 | cgi.handler exec 40 | 41 | # run .php and .phtml files through php-cgi handler 42 | php.handler ${php_cgi_path} 43 | phtml.handler ${php_cgi_path} 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /etc/kloned-embed.conf: -------------------------------------------------------------------------------- 1 | # no disk required, no logging, in-memory sessions (max 8KB of RAM) 2 | 3 | server_list my_http 4 | 5 | my_http 6 | { 7 | type http 8 | addr tcp4://*:8080 9 | dir_root /www # having your pages stored in /www into embfs 10 | 11 | session 12 | { 13 | type memory 14 | 15 | compress yes # compress sessions before saving 16 | 17 | memory.limit 8192 # use max 8KB of RAM for sessions 18 | memory.max_count 2 # or max 2 sessions 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /etc/kloned-https.conf: -------------------------------------------------------------------------------- 1 | server_list my_http my_https 2 | 3 | # use syslogd for logging 4 | log 5 | { 6 | type syslog 7 | syslog.facility LOG_LOCAL0 8 | } 9 | 10 | # unencrypted HTTP 11 | my_http 12 | { 13 | type http 14 | addr tcp4://*:8080 15 | dir_root /www # store your pages in /www into embfs 16 | } 17 | 18 | # HTTP/S server 19 | my_https 20 | { 21 | type https 22 | addr tcp4://*:4443 23 | dir_root /www 24 | 25 | # certificate path (into embfs or file system) 26 | cert_file /etc/kloned.pem 27 | } 28 | 29 | -------------------------------------------------------------------------------- /etc/kloned-nodisk-clientses.conf: -------------------------------------------------------------------------------- 1 | # no storage required, in-memory logging, client-side sessions 2 | 3 | server_list my_http 4 | 5 | log 6 | { 7 | type memory 8 | memory.limit 200 # 200 lines max 9 | } 10 | 11 | my_http 12 | { 13 | type http 14 | addr tcp4://*:8080 15 | dir_root /www # having your pages stored in /www into embfs 16 | 17 | session.type client 18 | } 19 | 20 | -------------------------------------------------------------------------------- /etc/kloned-nodisk-memoryses.conf: -------------------------------------------------------------------------------- 1 | # no storage required, in-memory logging, in-memory sessions 2 | 3 | server_list my_http 4 | 5 | log 6 | { 7 | type memory 8 | memory.limit 200 # 200 lines max 9 | } 10 | 11 | my_http 12 | { 13 | type http 14 | addr tcp4://*:8080 15 | dir_root /www # having your pages stored in /www into embfs 16 | 17 | session 18 | { 19 | type memory 20 | 21 | memory.limit 10240 # use max 10KB of RAM 22 | memory.max_count 10 # max 10 sessions 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /etc/kloned-psk.conf: -------------------------------------------------------------------------------- 1 | server_list https_psk 2 | 3 | # use syslogd for logging 4 | log 5 | { 6 | type syslog 7 | syslog.facility LOG_LOCAL0 8 | } 9 | 10 | # HTTP/S server using PSK stored in pskdb_file 11 | https_psk 12 | { 13 | type https 14 | addr tcp4://*:4443 15 | dir_root /www 16 | 17 | pskdb_file /tmp/psk.db 18 | psk_hash no 19 | psk_hint https_psk_hint 20 | } 21 | -------------------------------------------------------------------------------- /etc/kloned-rhel.init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # /etc/rc.d/init.d/kloned 4 | # 5 | # Control the kloned daemon. 6 | # 7 | # chkconfig: 2345 20 80 8 | # description: Control the kloned daemon. 9 | # processname: kloned 10 | 11 | # Source function library. 12 | . /etc/init.d/functions 13 | 14 | # change these as needed ("name" is the file name of this script) 15 | name="kloned" 16 | path="/usr/local/sbin/kloned" 17 | lock="/var/lock/subsys/kloned" 18 | 19 | start() 20 | { 21 | echo -n "Starting $name: " 22 | daemon $path 23 | RETVAL=$? 24 | 25 | echo 26 | [ $RETVAL -eq 0 ] && touch $lock 27 | return $RETVAL 28 | } 29 | 30 | stop() 31 | { 32 | echo -n "Shutting down $name: " 33 | killproc $path 34 | RETVAL=$? 35 | 36 | echo 37 | [ $RETVAL -eq 0 ] && rm -f $lock 38 | return $RETVAL 39 | } 40 | 41 | rhstatus () 42 | { 43 | status $path 44 | } 45 | 46 | case "$1" 47 | in 48 | start) 49 | start 50 | ;; 51 | stop) 52 | stop 53 | ;; 54 | status) 55 | rhstatus 56 | ;; 57 | restart|reload) 58 | stop 59 | start 60 | ;; 61 | condrestart) 62 | [ -f $lock ] && restart || : 63 | ;; 64 | *) 65 | echo "Usage: $name {start|stop|status|reload|restart}" 66 | exit 1 67 | ;; 68 | esac 69 | exit $? 70 | -------------------------------------------------------------------------------- /etc/kloned-v6.conf: -------------------------------------------------------------------------------- 1 | server_list v4 v6 2 | 3 | log 4 | { 5 | type syslog 6 | syslog.facility LOG_LOCAL0 7 | } 8 | 9 | v4 10 | { 11 | type http 12 | addr tcp4://*:8080 13 | dir_root /www 14 | } 15 | 16 | v6 17 | { 18 | type http 19 | addr tcp6://[*]:8080 20 | dir_root /www 21 | } 22 | -------------------------------------------------------------------------------- /etc/kloned-vhost.conf: -------------------------------------------------------------------------------- 1 | server_list main 2 | 3 | allow_root yes 4 | 5 | # shortcut, it's just an alias referenced by other vars 6 | php_cgi_path /usr/local/bin/php 7 | 8 | # use syslogd for logging 9 | log 10 | { 11 | type syslog 12 | syslog.facility LOG_LOCAL0 13 | } 14 | 15 | main 16 | { 17 | model prefork 18 | 19 | type http 20 | addr tcp4://*:8080 21 | 22 | access_log 23 | { 24 | # prefix added to all access log entries (default: "[access]") 25 | # prefix [access] 26 | 27 | # choose what to log (KLone logs everything by default) 28 | log *.* 29 | 30 | # choose what NOT to log 31 | dontlog *.css 32 | dontlog *.ico 33 | } 34 | 35 | # default vhost 36 | dir_root /path/to/www.mysite.com/ 37 | 38 | # applies when Host: wiki.koanlogic.com 39 | www.example.com 40 | { 41 | dir_root /path/to/www.example.com/ 42 | } 43 | 44 | www.hello.com 45 | { 46 | dir_root /path/to/www.hello.com/ 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /etc/kloned.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQC7c0AbclOY54S368iW0NFUw2TbCRi9cCHifpSB7ZsW3/kvIGzM 3 | 42HuJcYiI5dppaazKwh0IudS58u2l1HqgK28p6yWewJeaZD2G4i51UH49ZMv0EaH 4 | nOlONEk69qH7WaMyjn4VIJPP3yVV+l6yT9kP67719c8xL6V/Ako76631VQIDAQAB 5 | AoGAWG9kNE64v++iPr8/kF+OEuZoQ6pEAMPRSLEdUTsPKziZsDElA3jXL+qkUmDm 6 | Q1KClg7cWyZIamWvR0KWxALXc9YDjm8jWllyeEOJvMOg87rHLmERt0ZVJ5kAhSwZ 7 | 4gQEghGwuYE5vEBmvwiQ7uJnJx9HP+M7LnjVMCUodVj6uRUCQQDhTbLSV/vROlkn 8 | mKzMGDXyx0A/LIcsg58+hsnljY5PxDywnrAXe6P4WWH7yvjU3fiOX8Kt/wHhFFJn 9 | AlfL+IW3AkEA1P1Gth8w6yUk8EcvGG7pLJ49JT/aiMClEICCTMalPfIm7BlPPmfI 10 | /btB9BhgzVJ2a54/tFFu768/DQW3L7I9UwJBAL63Osv7VlpB/f4aqwsI44HjUGsp 11 | kjMIJ+CR0I3USccT4hvP+FeofaBYaSzvH7txOlmqje0jk7+nqCkyPoeWk/kCQAa4 12 | h0av7Uc+QNAkLuRCe7EgvSUzwp2WFp9SrsnlasltnrTMh6ecdscq5YXiTwurknkK 13 | 4U+7UhjWGtM6XvFuWmkCQHaUdhV0dVsOZ2+z3Fk0FN8OxtB7QLLRTdMp6I+CKCw1 14 | pO+v0JT3mHBefUlakAICYqCLhRUa0ZuufIChgBBLuaQ= 15 | -----END RSA PRIVATE KEY----- 16 | -----BEGIN CERTIFICATE----- 17 | MIIDtjCCAx+gAwIBAgIBADANBgkqhkiG9w0BAQQFADCBnzELMAkGA1UEBhMCSVQx 18 | DjAMBgNVBAgTBUl0YWx5MQ4wDAYDVQQHEwVNb256YTEZMBcGA1UEChMQS29hbkxv 19 | Z2ljIHMuci5sLjEOMAwGA1UECxMFS0xvbmUxIjAgBgNVBAMTGUtMb25lIGV4YW1w 20 | bGUgY2VydGlmaWNhdGUxITAfBgkqhkiG9w0BCQEWEmluZm9Aa29hbmxvZ2ljLmNv 21 | bTAeFw0wNjAyMjQxNDAzNDRaFw0wNjAzMjYxNDAzNDRaMIGfMQswCQYDVQQGEwJJ 22 | VDEOMAwGA1UECBMFSXRhbHkxDjAMBgNVBAcTBU1vbnphMRkwFwYDVQQKExBLb2Fu 23 | TG9naWMgcy5yLmwuMQ4wDAYDVQQLEwVLTG9uZTEiMCAGA1UEAxMZS0xvbmUgZXhh 24 | bXBsZSBjZXJ0aWZpY2F0ZTEhMB8GCSqGSIb3DQEJARYSaW5mb0Brb2FubG9naWMu 25 | Y29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7c0AbclOY54S368iW0NFU 26 | w2TbCRi9cCHifpSB7ZsW3/kvIGzM42HuJcYiI5dppaazKwh0IudS58u2l1HqgK28 27 | p6yWewJeaZD2G4i51UH49ZMv0EaHnOlONEk69qH7WaMyjn4VIJPP3yVV+l6yT9kP 28 | 67719c8xL6V/Ako76631VQIDAQABo4H/MIH8MB0GA1UdDgQWBBSoZo+JdKieozmT 29 | Ll7RNZCar95mIDCBzAYDVR0jBIHEMIHBgBSoZo+JdKieozmTLl7RNZCar95mIKGB 30 | paSBojCBnzELMAkGA1UEBhMCSVQxDjAMBgNVBAgTBUl0YWx5MQ4wDAYDVQQHEwVN 31 | b256YTEZMBcGA1UEChMQS29hbkxvZ2ljIHMuci5sLjEOMAwGA1UECxMFS0xvbmUx 32 | IjAgBgNVBAMTGUtMb25lIGV4YW1wbGUgY2VydGlmaWNhdGUxITAfBgkqhkiG9w0B 33 | CQEWEmluZm9Aa29hbmxvZ2ljLmNvbYIBADAMBgNVHRMEBTADAQH/MA0GCSqGSIb3 34 | DQEBBAUAA4GBADA+6eChQK2ajtt5Pdv+8BCXMTZP7+O4dEcYxv9yEDXmIYOyh20m 35 | LoBrb10j7N0HYXTexfhyFAnZ5kKz85BXeFQIEC826brnwREYylPdtInms41j6Nje 36 | SY1Dr2FwJ2QXLWIVevdt0+IF7xm15VVS7dSLkKGM5W6J94OZqIovqpXS 37 | -----END CERTIFICATE----- 38 | -------------------------------------------------------------------------------- /etc/psk.db: -------------------------------------------------------------------------------- 1 | # copy this file to /tmp to test kloned-psk.conf use-case 2 | # clear text passwords, hex coded without '0x' prefix 3 | tho:deadbeef 4 | tat:deaf 5 | stewy:0123456789abcdef 6 | -------------------------------------------------------------------------------- /klone/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.16 2008/10/27 21:28:03 tat Exp $ 2 | 3 | include common.mk 4 | include ../Makefile.conf 5 | 6 | INCDIR := $(INCDIR)/klone/ 7 | 8 | INCS = atom.h backend.h broker.h caes.h cgi.h codec.h \ 9 | codecs.h context.h cgzip.h cnull.h emb.h embpage.h field.h header.h \ 10 | http.h io.h ioprv.h klone.h klog.h klogprv.h md5.h mime_map.h os.h \ 11 | page.h parser.h ppc.h ppc_cmd.h request.h response.h rsfilter.h run.h \ 12 | server.h ses_prv.h session.h supplier.h timer.h tls.h tlsprv.h \ 13 | translat.h utils.h va.h var.h varprv.h vars.h version.h dypage.h 14 | 15 | ifdef SSL_ON 16 | INCS += ccipher.h 17 | endif 18 | 19 | ifdef INSTALL_DAEMON_ONLY 20 | NO_INSTALL = true 21 | endif 22 | 23 | include incs.mk 24 | -------------------------------------------------------------------------------- /klone/access.h: -------------------------------------------------------------------------------- 1 | #ifndef _KLONE_ACCESS_ 2 | #define _KLONE_ACCESS_ 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int access_log(http_t*, u_config_t *, request_t *, response_t *); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /klone/atom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: atom.h,v 1.8 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_ATOM_H_ 12 | #define _KLONE_ATOM_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* global server-maintaned atom list */ 22 | typedef struct atom_s 23 | { 24 | LIST_ENTRY(atom_s) np; /* next & prev pointers */ 25 | char *id; /* atom identifier */ 26 | char *data; /* atom data block */ 27 | size_t size; /* atom data block size */ 28 | void *arg; /* opaque data */ 29 | } atom_t; 30 | 31 | /* define atom list */ 32 | LIST_HEAD(atom_list_s, atom_s); 33 | typedef struct atom_list_s atom_list_t; 34 | 35 | struct atoms_s 36 | { 37 | atom_list_t list; 38 | size_t size, count; 39 | }; 40 | 41 | /* create an atom */ 42 | int atom_create(const char *id, const char *data, size_t size, void* arg, 43 | atom_t**pa); 44 | /* free an atom */ 45 | int atom_free(atom_t* atom); 46 | 47 | /* atom_t list */ 48 | struct atoms_s; 49 | typedef struct atoms_s atoms_t; 50 | 51 | /* create an atom list */ 52 | int atoms_create(atoms_t **); 53 | 54 | /* free an atom list */ 55 | int atoms_free(atoms_t *); 56 | 57 | /* sum of atoms size field */ 58 | size_t atoms_size(atoms_t *); 59 | 60 | /* # of atoms */ 61 | size_t atoms_count(atoms_t *); 62 | 63 | /* return the n-th atom */ 64 | int atoms_getn(atoms_t *, size_t n, atom_t**); 65 | 66 | /* return the atom whose ID is id */ 67 | int atoms_get(atoms_t *, const char *id, atom_t**); 68 | 69 | /* add an atom to the list */ 70 | int atoms_add(atoms_t *, atom_t*); 71 | 72 | /* add an atom to the list */ 73 | int atoms_remove(atoms_t *, atom_t*); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /klone/backend.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: backend.h,v 1.17 2008/06/04 17:48:01 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_BACKEND_H_ 12 | #define _KLONE_BACKEND_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | struct server_s; 22 | 23 | /* define page list */ 24 | LIST_HEAD(backends_s, backend_s); 25 | 26 | struct backend_s 27 | { 28 | /* statically initialized values */ 29 | const char *proto; 30 | int (*cb_init)(struct backend_s *); 31 | int (*cb_serve)(struct backend_s *, int); 32 | int (*cb_term)(struct backend_s *); 33 | 34 | /* runtime values */ 35 | struct server_s *server; 36 | u_config_t *config; 37 | u_net_addr_t *na; 38 | int model; 39 | int ld; 40 | void *arg; 41 | klog_t *klog; 42 | int id; 43 | size_t nchild; 44 | size_t max_child; 45 | size_t start_child; 46 | size_t max_rq_xchild; 47 | size_t fork_child; 48 | pid_t *child_pid; /* pid of children */ 49 | LIST_ENTRY(backend_s) np; /* next & prev pointers */ 50 | }; 51 | 52 | typedef struct backend_s backend_t; 53 | typedef struct backends_s backends_t; /* backend_t list */ 54 | 55 | #define BACKEND_STATIC_INITIALIZER(proto, init, connect, term) \ 56 | { \ 57 | proto, \ 58 | init, \ 59 | connect, \ 60 | term, \ 61 | NULL, /* server */ \ 62 | NULL, /* config */ \ 63 | NULL, /* addr */ \ 64 | 0, /* model */ \ 65 | -1, /* ld */ \ 66 | NULL, /* arg */ \ 67 | NULL, /* klog */ \ 68 | -1, /* id */ \ 69 | 0, /* nchild */ \ 70 | 0, /* max_child */ \ 71 | 0, /* start_child */ \ 72 | 0, /* max_rq_xchild*/ \ 73 | 0, /* fork_child */ \ 74 | NULL, /* children pids*/ \ 75 | LIST_ENTRY_NULL \ 76 | } 77 | 78 | 79 | extern backend_t *backend_list[]; 80 | 81 | int backend_create(const char *name, u_config_t *, backend_t **); 82 | int backend_serve(backend_t *, int fd); 83 | int backend_free(backend_t *); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /klone/broker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: broker.h,v 1.8 2007/10/25 20:26:56 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_BROKER_H_ 12 | #define _KLONE_BROKER_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | struct broker_s; 24 | typedef struct broker_s broker_t; 25 | 26 | int broker_create(broker_t **pb); 27 | int broker_free(broker_t* b); 28 | int broker_is_valid_uri(broker_t *b, http_t *h, request_t *rq, const char *buf, 29 | size_t len); 30 | int broker_serve(broker_t *b, http_t *h, request_t *rq, response_t *rs); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /klone/caes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: caes.h,v 1.4 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_CODEC_AES_H__ 12 | #define _KLONE_CODEC_AES_H__ 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /klone/ccipher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ccipher.h,v 1.8 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_CODEC_CIPHER_H_ 12 | #define _KLONE_CODEC_CIPHER_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | 17 | #ifdef SSL_ON 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #ifdef SSL_CYASSL 25 | #define EVP_MAX_KEY_LENGTH 32 26 | #define EVP_MAX_IV_LENGTH 16 27 | #define EVP_MAX_BLOCK_LENGTH 32 28 | #define EVP_aes_256_cbc() "AES-CBC-256" 29 | 30 | #endif 31 | 32 | /* possibile values for io_gzip_create */ 33 | enum { CIPHER_ENCRYPT, CIPHER_DECRYPT }; 34 | 35 | enum { 36 | CODEC_CIPHER_KEY_LEN = EVP_MAX_KEY_LENGTH, 37 | CODEC_CIPHER_KEY_BUFSZ = 2 * EVP_MAX_KEY_LENGTH, 38 | CODEC_CIPHER_IV_LEN = EVP_MAX_IV_LENGTH, 39 | CODEC_CIPHER_BLOCK_LEN = EVP_MAX_BLOCK_LENGTH, 40 | }; 41 | 42 | int codec_cipher_create(int op, const EVP_CIPHER *cipher, 43 | unsigned char *key, unsigned char *iv, codec_t **pcc); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #else /* SSL_ON */ 50 | /* to avoid ifdefs in local variable declaration (such vars will not be used 51 | anyway because the code that use them is ifdef-out) */ 52 | enum { 53 | CODEC_CIPHER_KEY_LEN = 0, 54 | CODEC_CIPHER_KEY_BUFSZ = 0, 55 | CODEC_CIPHER_IV_LEN = 0 56 | }; 57 | 58 | #endif /* SSL_ON */ 59 | 60 | #endif /* !_KLONE_CODEC_CIPHER_H_ */ 61 | -------------------------------------------------------------------------------- /klone/cgi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: cgi.h,v 1.6 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_CGI_H_ 12 | #define _KLONE_CGI_H_ 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | int cgi_set_request(request_t *rq); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /klone/cgzip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: cgzip.h,v 1.7 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_CODEC_GZIP_H_ 12 | #define _KLONE_CODEC_GZIP_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /* the codec [un]compresses (using libz) the stream to whom it's applied */ 19 | 20 | /* possibile values for io_gzip_create */ 21 | enum { GZIP_COMPRESS, GZIP_UNCOMPRESS }; 22 | 23 | int codec_gzip_create(int operation, codec_t **pioz); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /klone/cnull.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: cnull.h,v 1.5 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_CODEC_NULL_H_ 12 | #define _KLONE_CODEC_NULL_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | int codec_null_create(codec_t **pc); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /klone/codec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: codec.h,v 1.12 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_CODEC_H_ 12 | #define _KLONE_CODEC_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | enum { CODEC_FLUSH_COMPLETE, CODEC_FLUSH_CHUNK }; 24 | 25 | enum { CODEC_BUFSZ = 4096 }; 26 | 27 | TAILQ_HEAD(codec_chain_s, codec_s); 28 | typedef struct codec_chain_s codec_chain_t; 29 | 30 | typedef ssize_t (*codec_transform_t) (struct codec_s *codec, 31 | char *dst, size_t *dst_cnt, const char *src, size_t src_sz); 32 | 33 | typedef ssize_t (*codec_flush_t) (struct codec_s *codec, 34 | char *dst, size_t *dst_cnt); 35 | 36 | typedef int (*codec_free_t) (struct codec_s *codec); 37 | 38 | typedef struct codec_s 39 | { 40 | codec_transform_t transform; 41 | codec_flush_t flush; 42 | codec_free_t free; 43 | 44 | /* codec buffer */ 45 | char cbuf[CODEC_BUFSZ]; 46 | size_t ccount, coff; 47 | 48 | /* chain next & prev pointer */ 49 | TAILQ_ENTRY(codec_s) np; 50 | } codec_t; 51 | 52 | int codec_free(codec_t *codec); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /klone/codecs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: codecs.h,v 1.7 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_CODECS_H_ 12 | #define _KLONE_CODECS_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /klone/context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: context.h,v 1.13 2009/10/23 14:08:28 tho Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_CONTEXT_H_ 12 | #define _KLONE_CONTEXT_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /* global applicaton context */ 26 | typedef struct context_s 27 | { 28 | server_t *server; /* server object */ 29 | u_config_t *config; /* server config object */ 30 | backend_t *backend; /* the backend served by this child */ 31 | hook_t *hook; /* object that keep track of hooks */ 32 | char *ext_config; /* additional external config file */ 33 | int cmd_config; /* whether to override config from command-line */ 34 | char *pid_file; /* path of the PID file */ 35 | int debug; /* debugging on/off */ 36 | int daemon; /* daemon/service mode on/off */ 37 | char **arg; /* cmd line args array */ 38 | size_t narg; /* # of cmd line args */ 39 | int pipc; /* parent IPC socket descriptor */ 40 | int cgi; /* if we're in cgi mode */ 41 | int nochdir; /* do not chdir when daemon'izing */ 42 | 43 | #ifdef OS_WIN 44 | SERVICE_STATUS_HANDLE hServiceStatus; 45 | SERVICE_STATUS status; 46 | enum { SERV_NOP, SERV_INSTALL, SERV_REMOVE } serv_op; 47 | /* install/remove service bindings */ 48 | #endif 49 | } context_t; 50 | 51 | /* exported variable (see entry.c) */ 52 | extern context_t *ctx; 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /klone/dypage.h: -------------------------------------------------------------------------------- 1 | #ifndef _KLONE_DYPAGE_H_ 2 | #define _KLONE_DYPAGE_H_ 3 | #include 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct dypage_args_s; 12 | typedef struct dypage_args_s dypage_args_t; 13 | 14 | typedef void (*dypage_fun_t)(dypage_args_t *); 15 | 16 | enum { DYPAGE_MAX_PARAMS = 16 }; 17 | 18 | typedef struct dypage_param_s 19 | { 20 | const char *key, *val; 21 | } dypage_param_t; 22 | 23 | const char *dypage_get_param(dypage_args_t *args, const char *key); 24 | 25 | struct dypage_args_s 26 | { 27 | request_t *rq; 28 | response_t *rs; 29 | session_t *ss; 30 | dypage_fun_t fun; /* callback function */ 31 | void *opaque; /* additional opaque callback argument */ 32 | 33 | size_t argc; /* # of argv */ 34 | const char **argv; /* regex submatches (#0 is the full url) */ 35 | size_t nparams; /* # of named params */ 36 | dypage_param_t *params; /* array of named parameters */ 37 | }; 38 | 39 | int dypage_serve(dypage_args_t *args); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /klone/emb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: emb.h,v 1.18 2010/06/01 20:20:51 tho Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_EMB_H_ 12 | #define _KLONE_EMB_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | #ifdef HAVE_STDINT 17 | #include 18 | #endif /* HAVE_STDINT */ 19 | #include 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* supported embedded resource type */ 28 | enum { 29 | ET_FILE, /* embedded file */ 30 | ET_PAGE /* dynamic web page */ 31 | }; 32 | 33 | /* define resource list */ 34 | LIST_HEAD(emblist_s, embres_s); 35 | 36 | /* common struct for embedded resources */ 37 | typedef struct embres_s 38 | { 39 | LIST_ENTRY(embres_s) np;/* next & prev pointers */ 40 | const char *filename; /* emb resource file name */ 41 | int type; /* emb resource type (ET_*) */ 42 | } embres_t; 43 | 44 | /* embedded file */ 45 | typedef struct embfile_s 46 | { 47 | embres_t res; /* any emb resource must start with a embres_t */ 48 | size_t size; /* size of the data block */ 49 | unsigned char *data; /* file data */ 50 | int comp; /* if data is compressed */ 51 | int encrypted; /* if data is encrypted */ 52 | time_t mtime; /* time of last modification */ 53 | const char *mime_type; /* guessed mime type */ 54 | size_t file_size; /* size of the source file (not compressed) */ 55 | } embfile_t; 56 | 57 | /* embedded dynamic klone page */ 58 | typedef struct embpage_s 59 | { 60 | embres_t res; /* any emb resource must start with a embres_t */ 61 | dypage_fun_t fun; 62 | } embpage_t; 63 | 64 | int emb_init(void); 65 | int emb_term(void); 66 | int emb_register(embres_t *r); 67 | int emb_unregister(embres_t *r); 68 | int emb_lookup(const char *filename, embres_t **pr); 69 | int emb_count(void); 70 | int emb_getn(size_t n, embres_t **pr); 71 | int emb_open(const char *file, io_t **pio); 72 | 73 | int emb_list (char ***plist); 74 | void emb_list_free (char **list); 75 | int emb_to_ubuf(const char *res_name, u_buf_t **pubuf); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /klone/embpage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: embpage.h,v 1.7 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_EMB_PAGE_H_ 12 | #define _KLONE_EMB_PAGE_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | void register_page(page_t *pg); 22 | void unregister_page(page_t *pg); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /klone/field.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: field.h,v 1.6 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_FIELD_H_ 12 | #define _KLONE_FIELD_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | TAILQ_HEAD(param_list_s, param_s); 22 | typedef struct param_s 23 | { 24 | TAILQ_ENTRY(param_s) np; /* next & prev pointers */ 25 | char *name; /* param name */ 26 | char *value; /* param value */ 27 | } param_t; 28 | 29 | typedef struct param_list_s params_t; /* param list */ 30 | 31 | TAILQ_HEAD(field_list_s, field_s); 32 | typedef struct field_s 33 | { 34 | TAILQ_ENTRY(field_s) np; /* next & prev pointers */ 35 | char *name; /* field name */ 36 | char *value; /* field value */ 37 | params_t *params; /* param list */ 38 | } field_t; 39 | 40 | /* field list */ 41 | typedef struct field_list_s fields_t; /* field list */ 42 | 43 | int field_create(const char* name, const char *value, field_t**); 44 | int field_set(field_t*, const char *name, const char *value); 45 | int field_set_from_line(field_t*, const char *line); 46 | int field_free(field_t*); 47 | const char* field_get_name(field_t *f); 48 | const char* field_get_value(field_t *f); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /klone/header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: header.h,v 1.8 2007/07/13 14:00:13 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_HEADER_H_ 12 | #define _KLONE_HEADER_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* load modes */ 22 | enum { 23 | HLM_OVERRIDE,/** if a field with the same name already exists override it */ 24 | HLM_KEEP, /** if a field with the same name already exists keep it */ 25 | HLM_ADD /** if a field with the same name already exists add another 26 | field with the same name */ 27 | }; 28 | 29 | typedef struct 30 | { 31 | fields_t fields; 32 | size_t nfields; 33 | } header_t; 34 | 35 | int header_create(header_t**); 36 | int header_load(header_t*, io_t *); 37 | int header_load_from_cgienv(header_t *h); 38 | int header_load_ex(header_t *h , io_t *io, int mode); 39 | int header_free(header_t*); 40 | int header_add_field(header_t *h, field_t *f); 41 | int header_del_field(header_t *h, field_t *f); 42 | field_t* header_get_field(header_t *h, const char *name); 43 | int header_clear(header_t *h); 44 | 45 | const char* header_get_field_value(header_t *h, const char *name); 46 | 47 | int header_set_field(header_t *h, const char *name, const char *value); 48 | 49 | field_t* header_get_fieldn(header_t *h, size_t idx); 50 | size_t header_field_count(header_t *h); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /klone/hook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: hook.h,v 1.2 2007/09/04 19:48:39 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_HOOK_H_ 12 | #define _KLONE_HOOK_H_ 13 | #include 14 | #include 15 | #include 16 | 17 | struct hook_s; 18 | typedef struct hook_s hook_t; 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #ifndef ENABLE_HOOKS 25 | #include 26 | #define hook_create(hook) isspace(0) /* nop */ 27 | #define hook_free(hook) isspace(0) /* nop */ 28 | #else 29 | 30 | /* server init/term hooks */ 31 | typedef int (*hook_server_init_t)(void); 32 | typedef int (*hook_server_term_t)(void); 33 | 34 | int hook_server_init( hook_server_init_t ); 35 | int hook_server_term( hook_server_term_t ); 36 | 37 | /* children init/term hooks */ 38 | typedef int (*hook_child_init_t)(void); 39 | typedef int (*hook_child_term_t)(void); 40 | 41 | int hook_child_init( hook_child_init_t ); 42 | int hook_child_term( hook_child_term_t ); 43 | 44 | /* per-request hook */ 45 | typedef int (*hook_request_t)(request_t *, response_t *); 46 | int hook_request( hook_request_t ); 47 | 48 | /* server loop hook */ 49 | typedef int (*hook_server_loop_t)(void); 50 | int hook_server_loop( hook_server_loop_t ); 51 | 52 | /* hooks container object */ 53 | int hook_create( hook_t **phook); 54 | int hook_free( hook_t *hook); 55 | 56 | /* user-provided function used to register hooks */ 57 | void hooks_setup(void); 58 | 59 | #endif /* ENABLE_HOOKS */ 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /klone/hookprv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: hookprv.h,v 1.1 2007/09/04 12:15:16 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_HOOK_PRV_H_ 12 | #define _KLONE_HOOK_PRV_H_ 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #ifndef ENABLE_HOOKS 20 | #define hook_call( func, ... ) 21 | #else 22 | #define hook_call( func, ... ) \ 23 | do { if(ctx && ctx->hook && ctx->hook->func) \ 24 | ctx->hook->func( __VA_ARGS__ ); \ 25 | } while(0) 26 | 27 | struct hook_s 28 | { 29 | /* server hooks function pointers */ 30 | hook_server_init_t server_init; 31 | hook_server_term_t server_term; 32 | 33 | /* children hooks */ 34 | hook_child_init_t child_init; 35 | hook_child_term_t child_term; 36 | 37 | /* per-connection hook */ 38 | hook_request_t request; 39 | 40 | /* server loop hook */ 41 | hook_server_loop_t server_loop; 42 | }; 43 | 44 | #endif /* ENABLE_HOOKS */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /klone/http.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: http.h,v 1.14 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_HTTP_H_ 12 | #define _KLONE_HTTP_H_ 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /** \file */ 21 | 22 | /** HTTP response codes */ 23 | enum { 24 | HTTP_STATUS_EMPTY = 0, 25 | /**< undefined status */ 26 | HTTP_STATUS_OK = 200, 27 | /**< request succeeded */ 28 | HTTP_STATUS_CREATED = 201, 29 | /**< fulfilled request resulting in creation of new resource */ 30 | HTTP_STATUS_ACCEPTED = 202, 31 | /**< request accepted but processing not completed */ 32 | HTTP_STATUS_NO_CONTENT = 204, 33 | /**< no body returned */ 34 | HTTP_STATUS_MOVED_PERMANENTLY = 301, 35 | /**< resource relocated permanently */ 36 | HTTP_STATUS_MOVED_TEMPORARILY = 302, 37 | /**< resource relocated temporarily */ 38 | HTTP_STATUS_NOT_MODIFIED = 304, 39 | /**< GET request for unmodified document */ 40 | HTTP_STATUS_BAD_REQUEST = 400, 41 | /**< syntax error */ 42 | HTTP_STATUS_UNAUTHORIZED = 401, 43 | /**< user authentication required */ 44 | HTTP_STATUS_FORBIDDEN = 403, 45 | /**< access to resource forbidden */ 46 | HTTP_STATUS_NOT_FOUND = 404, 47 | /**< request timeout */ 48 | HTTP_STATUS_REQUEST_TIMEOUT = 408, 49 | /**< nothing found at matching request URI */ 50 | HTTP_STATUS_LENGTH_REQUIRED = 411, 51 | /**< missing Content-Length header field */ 52 | HTTP_STATUS_REQUEST_TOO_LARGE = 413, 53 | /**< decryption key is needed - KLone extension */ 54 | HTTP_STATUS_EXT_KEY_NEEDED = 430, 55 | /**< request PDU too big */ 56 | HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, 57 | /**< unexpected condition caused an error */ 58 | HTTP_STATUS_NOT_IMPLEMENTED = 501, 59 | /**< request method not supported */ 60 | HTTP_STATUS_BAD_GATEWAY = 502, 61 | /**< invalid response while acting as gateway or proxy */ 62 | HTTP_STATUS_SERVICE_UNAVAILABLE = 503 63 | /**< server unavailable due to temporary overloading or maintenance */ 64 | }; 65 | 66 | /** HTTP Methods */ 67 | enum http_method_e 68 | { 69 | HM_UNKNOWN, /**< unknown value */ 70 | HM_GET, /**< retrieve data at URI */ 71 | HM_HEAD, /**< ~HM_GET with headers only */ 72 | HM_POST, /**< create new object subordinate to specified object */ 73 | HM_PUT, /**< data in body is to be stored under URL */ 74 | HM_DELETE /**< deletion request at given URL */ 75 | }; 76 | 77 | struct http_s; 78 | typedef struct http_s http_t; 79 | 80 | struct session_opt_s; 81 | struct request_s; 82 | struct vhost_s; 83 | 84 | u_config_t *http_get_config(http_t* http); 85 | struct session_opt_s *http_get_session_opt(http_t* http); 86 | 87 | struct vhost_s* http_get_vhost(http_t *h, struct request_s *rq); 88 | struct vhost_list_s* http_get_vhost_list(http_t *h); 89 | int http_alias_resolv(http_t *h, struct request_s *rq, char *dst, 90 | const char *uri, size_t sz); 91 | const char* http_get_status_desc(int status); 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /klone/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: io.h,v 1.20 2008/07/05 16:41:07 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_IO_H_ 12 | #define _KLONE_IO_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | #include 17 | #include 18 | #ifdef SSL_ON 19 | #include 20 | #include 21 | #endif 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | struct io_s; 29 | typedef struct io_s io_t; 30 | 31 | enum io_type_e 32 | { 33 | IO_TYPE_FD, 34 | IO_TYPE_MEM, 35 | #ifdef SSL_ON 36 | IO_TYPE_SSL 37 | #endif 38 | }; 39 | 40 | enum io_fd_flags { 41 | IO_FD_NO_FLAGS, 42 | IO_FD_CLOSE /* close(2) fd on io_free */ 43 | }; 44 | 45 | enum io_mem_flags { 46 | IO_MEM_NO_FLAGS, 47 | IO_MEM_FREE_BUF /* free(3) io mem buf on io_free */ 48 | }; 49 | 50 | int io_fd_create(int fd, int flags, io_t **pio); 51 | int io_mem_create(char *buf, size_t size, int flags, io_t **pio); 52 | #ifdef SSL_ON 53 | int io_ssl_create(int fd, int flags, int client_mode, 54 | SSL_CTX *ssl_tx, io_t **pio); 55 | int io_ssl_get_SSL(io_t *io_ssl, SSL **pssl); 56 | #endif 57 | int io_fd_get_d(io_t *); 58 | char* io_mem_get_buf(io_t *); 59 | size_t io_mem_get_bufsz(io_t *io); 60 | 61 | enum io_type_e io_type(io_t *io); 62 | 63 | int io_close(io_t *io); 64 | int io_free(io_t *io); 65 | int io_dup(io_t *io, io_t **pio); 66 | int io_name_set(io_t *io, const char* name); 67 | int io_name_get(io_t *io, char* name, size_t sz); 68 | ssize_t io_read(io_t *io, char* buf, size_t size); 69 | ssize_t io_write(io_t *io, const char* buf, size_t size); 70 | ssize_t io_flush(io_t *io); 71 | ssize_t io_seek(io_t *io, size_t off); 72 | ssize_t io_tell(io_t *io); 73 | ssize_t io_copy(io_t *out, io_t *in, size_t size); 74 | ssize_t io_pipe(io_t *out, io_t *in); 75 | ssize_t io_gets(io_t *io, char *buf, size_t size); 76 | ssize_t io_get_until(io_t *io, char stop_at, char *buf, size_t size); 77 | ssize_t io_getc(io_t *io, char *c); 78 | ssize_t io_printf(io_t *io, const char* fmt, ...); 79 | ssize_t io_vprintf(io_t *io, const char *fmt, va_list ap); 80 | ssize_t io_putc(io_t *io, char c); 81 | int io_codec_add_head(io_t *io, codec_t* codec); 82 | int io_codec_add_tail(io_t *io, codec_t* codec); 83 | int io_codecs_remove(io_t *io); 84 | int io_is_secure(io_t *io); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /klone/ioprv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ioprv.h,v 1.14 2007/07/20 10:24:47 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_IO_PRV_H_ 12 | #define _KLONE_IO_PRV_H_ 13 | 14 | #include "klone_conf.h" 15 | #ifdef HAVE_STDINT 16 | #include 17 | #endif /* HAVE_STDINT */ 18 | #include 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /* functions used by io devices */ 26 | 27 | /** alloc sizeof(type) and initialize the io_t object */ 28 | #define io_create(type, pio) io_prv_create(sizeof(type), pio) 29 | int io_prv_create(size_t dev_sz, io_t **pio); 30 | 31 | typedef ssize_t (*io_read_op) (io_t*, char*, size_t); 32 | typedef ssize_t (*io_write_op) (io_t*, const char*, size_t); 33 | typedef ssize_t (*io_seek_op) (io_t*, size_t); 34 | typedef ssize_t (*io_tell_op) (io_t*); 35 | typedef int (*io_close_op) (io_t*); 36 | typedef int (*io_free_op) (io_t*); 37 | 38 | struct io_s 39 | { 40 | char *name; 41 | codec_chain_t codec_chain; 42 | int eof; 43 | int type; 44 | size_t size; 45 | 46 | /* reference count (used by dup'd io_t) */ 47 | unsigned int refcnt; 48 | 49 | /* !0 for encrypted connections */ 50 | int is_secure; 51 | 52 | /* io ops */ 53 | io_read_op read; 54 | io_write_op write; 55 | io_seek_op seek; 56 | io_tell_op tell; 57 | io_close_op close; 58 | io_free_op free; 59 | 60 | /* input buffer */ 61 | 62 | char *rbuf; /* read buffer */ 63 | size_t rbsz; /* read buffer size */ 64 | size_t rcount; /* available bytes in the buffer */ 65 | size_t roff; /* offset of the first byte to return */ 66 | 67 | size_t rtot; /* total number of bytes read from this io */ 68 | 69 | /* underflow buffer */ 70 | char *ubuf; /* underflow buffer */ 71 | size_t ucount; /* available bytes in the ubuffer */ 72 | size_t uoff; /* offset of the first byte to return */ 73 | 74 | 75 | /* output buffer */ 76 | 77 | char *wbuf; /* write buffer */ 78 | size_t wbsz; /* write buffer size */ 79 | size_t wcount; /* # of non-empty bytes in the buffer */ 80 | size_t woff; /* offset of the head of the buffer */ 81 | 82 | }; 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /klone/kilt.h: -------------------------------------------------------------------------------- 1 | #ifndef _KLONE_KILT_H_ 2 | #define _KLONE_KILT_H_ 3 | #include 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* url regex to function mapping */ 12 | typedef struct kilt_url_s 13 | { 14 | const char *pattern; /* url pattern */ 15 | dypage_fun_t fun; 16 | dypage_param_t params[DYPAGE_MAX_PARAMS]; 17 | } kilt_url_t; 18 | 19 | /* run the .kl1 script whose name is in "script" param */ 20 | void kilt_run_script(dypage_args_t *dp) ; 21 | 22 | /* function that displays passed-in arguments */ 23 | void kilt_show_params(dypage_args_t *dp); 24 | 25 | /* must be set by the user (helper macros in kilt_urls.h) */ 26 | extern kilt_url_t *kilt_urls; 27 | extern size_t kilt_nurls; 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /klone/kilt_urls.h: -------------------------------------------------------------------------------- 1 | #ifndef _KLONE_KILT_URLS_H_ 2 | #define _KLONE_KILT_URLS_H_ 3 | #include 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #define KILT_URLS(u) size_t kilt_nurls = (sizeof(u)/sizeof(kilt_url_t)); kilt_url_t *kilt_urls = u; 10 | #define NO_PARAMS { { NULL, NULL } } 11 | #define PARAMS(...) { __VA_ARGS__ }, 12 | #define P(k,v) {k,v} 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /klone/klogprv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: klogprv.h,v 1.9 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_LOGPRV_H_ 12 | #define _KLONE_LOGPRV_H_ 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | static const char *kloglev[] = 21 | { 22 | "DBG", "INF", "NTC", "WRN", "ERR", "CRT", "ALR", "EMR" 23 | }; 24 | 25 | /* common */ 26 | int klog_new (int type, int threshold, const char *ident, klog_t **pkl); 27 | int klog_open_mem (klog_t *kl, size_t ln_max); 28 | int klog_open_syslog (klog_t *kl, int fac, int logopt); 29 | int klog_open_file (klog_t *kl, const char *base, size_t npages, size_t nlines); 30 | const char *klog_to_str (int lev); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* _KLONE_LOGPRV_H_ */ 37 | -------------------------------------------------------------------------------- /klone/klone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: klone.h,v 1.10 2008/10/27 21:28:04 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_H_ 12 | #define _KLONE_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /klone/mime_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: mime_map.h,v 1.5 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_MIME_MAP_H_ 12 | #define _KLONE_MIME_MAP_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | typedef struct mime_map_s 19 | { 20 | const char *ext, *mime_type; 21 | int comp; /* if >0 compression is recommended */ 22 | } mime_map_t; 23 | 24 | extern mime_map_t mime_map[]; 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /klone/os.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: os.h,v 1.9 2006/04/27 13:04:12 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_OS_H_ 12 | #define _KLONE_OS_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | #include 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /klone/page.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: page.h,v 1.8 2006/04/22 13:14:46 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_PAGE_H_ 12 | #define _KLONE_PAGE_H_ 13 | 14 | #include "klone_conf.h" 15 | #ifdef HAVE_STDINT 16 | #include 17 | #endif /* HAVE_STDINT */ 18 | #include 19 | #include 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef void (*page_run_t)(request_t*, response_t*); 27 | 28 | typedef enum page_type_e { 29 | PAGE_TYPE_UNKNOWN, 30 | PAGE_TYPE_STATIC, 31 | PAGE_TYPE_DYNAMIC 32 | } page_type_t; 33 | 34 | /* static content page */ 35 | typedef struct page_static_s 36 | { 37 | size_t size; 38 | unsigned char *data; 39 | } page_static_t; 40 | 41 | /* dyunamic content page */ 42 | typedef struct page_dynamic_s 43 | { 44 | page_run_t run; /* run page code func pointer */ 45 | } page_dynamic_t; 46 | 47 | /* define page list */ 48 | LIST_HEAD(pages_s, page_s); 49 | 50 | struct page_s 51 | { 52 | const char *uri; /* *.kl1 file name */ 53 | const char *mime_type; /* default mime type */ 54 | page_type_t type; /* page type PAGE_TYPE_XXX */ 55 | void *sd; /* static or dyn page context */ 56 | LIST_ENTRY(page_s) np; /* next & prev pointers */ 57 | }; 58 | 59 | #define PAGE_STATIC_INIT(uri, mime, type, ptr) \ 60 | { uri, mime, type, ptr, LIST_ENTRY_NULL } 61 | 62 | typedef struct page_s page_t; 63 | typedef struct pages_s pages_t; 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /klone/parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: parser.h,v 1.8 2008/10/18 00:03:00 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_PARSER_H_ 12 | #define _KLONE_PARSER_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | struct parser_s; 24 | typedef struct parser_s parser_t; 25 | 26 | struct parser_s 27 | { 28 | io_t *in, *out; 29 | int state, prev_state, cmd_code, line, code_line; 30 | void *cb_arg; /* opaque callback funcs argument */ 31 | /* <%[.] %> where . is a non-blank char */ 32 | int (*cb_code) (parser_t *, int, void *, const char *, size_t); 33 | int (*cb_html) (parser_t *, void *, const char *, size_t); /* HTML */ 34 | }; 35 | 36 | typedef int (*parser_cb_html_t)(parser_t *, void *, const char *, size_t); 37 | typedef int (*parser_cb_code_t)(parser_t *, int, void *, const char *, size_t); 38 | 39 | int parser_create(parser_t **); 40 | int parser_free(parser_t *); 41 | int parser_run(parser_t *); 42 | int parser_reset(parser_t *); 43 | 44 | void parser_set_io(parser_t *, io_t *, io_t *); 45 | void parser_set_cb_code(parser_t *, parser_cb_code_t); 46 | void parser_set_cb_html(parser_t *, parser_cb_html_t); 47 | void parser_set_cb_arg(parser_t *, void *); 48 | 49 | void* parser_get_cb_arg(parser_t *p); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /klone/ppc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ppc.h,v 1.10 2006/01/09 12:38:37 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_PPC_H_ 12 | #define _KLONE_PPC_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | enum { PPC_MAX_DATA_SIZE = 8192 }; 22 | 23 | struct ppc_s; 24 | typedef struct ppc_s ppc_t; 25 | 26 | typedef int (*ppc_cb_t)(ppc_t*, int fd, unsigned char cmd, char *data, 27 | size_t size, void*arg); 28 | 29 | int ppc_create(ppc_t **pppc); 30 | int ppc_free(ppc_t *ppc); 31 | int ppc_register(ppc_t *ppc, unsigned char cmd, ppc_cb_t func, void *arg); 32 | int ppc_dispatch(ppc_t *ppc, int fd, unsigned char cmd, char *data, 33 | size_t size); 34 | ssize_t ppc_write(ppc_t *ppc, int fd, unsigned char cmd, char *data, 35 | size_t size); 36 | ssize_t ppc_read(ppc_t *ppc, int fd, unsigned char *cmd, char *data, 37 | size_t size); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /klone/ppc_cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ppc_cmd.h,v 1.9 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_PPC_CMD_H_ 12 | #define _KLONE_PPC_CMD_H_ 13 | 14 | /* ppc centralized command list */ 15 | enum { 16 | PPC_CMD_UNKNOWN, /* wrong command */ 17 | PPC_CMD_NOP, /* no operation */ 18 | PPC_CMD_FORK_CHILD, /* launch a new child */ 19 | PPC_CMD_RESPONSE_OK, /* ppc response success */ 20 | PPC_CMD_RESPONSE_ERROR, /* ppc response error */ 21 | 22 | /* in-memory sessions ppc commands */ 23 | PPC_CMD_MSES_SAVE, /* save a session */ 24 | PPC_CMD_MSES_GET, /* get session data */ 25 | PPC_CMD_MSES_DELOLD, /* delete the oldest ession */ 26 | PPC_CMD_MSES_REMOVE, /* remove a session */ 27 | 28 | /* logging ppc commands */ 29 | PPC_CMD_LOG_ADD, /* add a log line */ 30 | PPC_CMD_LOG_GET, /* get a log line (in-mem logging) */ 31 | 32 | /* access log commands */ 33 | PPC_CMD_ACCESS_LOG /* add an access log line */ 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /klone/response.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: response.h,v 1.12 2007/10/22 15:49:47 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_RESPONSE_H_ 12 | #define _KLONE_RESPONSE_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** \file */ 23 | 24 | enum { COOKIE_MAX_SIZE = 4096 }; 25 | 26 | struct response_s; 27 | typedef struct response_s response_t; 28 | 29 | int response_create(http_t *http, response_t **prs); 30 | int response_free(response_t *rs); 31 | int response_bind(response_t *rs, io_t *); 32 | 33 | int response_redirect(response_t *rs, const char *url); 34 | 35 | int response_set_status(response_t *rs, int code); 36 | int response_get_status(response_t *rs); 37 | void response_set_method(response_t *rs, int method); 38 | int response_get_method(response_t *rs); 39 | 40 | int response_enable_caching(response_t *rs); 41 | int response_disable_caching(response_t *rs); 42 | 43 | void response_set_cgi(response_t *rs, int cgi); 44 | 45 | int response_print_header(response_t *rs); 46 | int response_print_header_to_io(response_t *rs, io_t *io); 47 | size_t response_get_max_header_size(response_t *rs); 48 | 49 | io_t* response_io(response_t *rs); 50 | 51 | header_t* response_get_header(response_t *rs); 52 | 53 | field_t* response_get_field(response_t *rs, const char *name); 54 | const char* response_get_field_value(response_t *rs, const char *name); 55 | 56 | int response_set_field(response_t *rs, const char *name, const char *value); 57 | int response_set_content_type(response_t *rs, const char *mime_type); 58 | int response_set_content_length(response_t *rs, size_t sz); 59 | int response_set_content_encoding(response_t *rs, const char *encoding); 60 | int response_set_last_modified(response_t *rs, time_t mtime); 61 | int response_set_date(response_t *rs, time_t now); 62 | int response_del_field(response_t *rs, const char *name); 63 | 64 | int response_set_cookie(response_t *rs, const char *name, const char *value, 65 | time_t expire, const char *path, const char *domain, int secure); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /klone/rsfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: rsfilter.h,v 1.8 2007/12/03 16:05:55 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_RSFILTER_H_ 12 | #define _KLONE_RSFILTER_H_ 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /* the filter will buffer the first RFBUFSZ bytes printed so page developers 21 | * can postpone header modifications (i.e. header will be sent after RFBUFSZ 22 | * bytes of printed data or on io_flush() 23 | */ 24 | enum { RFBUFSZ = 4096 }; 25 | 26 | struct response_s; 27 | struct request_s; 28 | struct session_s; 29 | typedef struct response_filter_s response_filter_t; 30 | 31 | int response_filter_create(struct request_s *rq, struct response_s *rs, 32 | struct session_s *ss, codec_t **prf); 33 | int response_filter_feeded(codec_t *codec); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /klone/run.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: run.h,v 1.5 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_RUN_H_ 12 | #define _KLONE_RUN_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* run a dynamic object page */ 22 | int run_page(const char *, request_t*, response_t*); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /klone/server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: server.h,v 1.16 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_SERVER_H_ 12 | #define _KLONE_SERVER_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | struct u_config_s; 23 | struct server_s; 24 | typedef struct server_s server_t; 25 | 26 | enum { 27 | SERVER_LOG_FLUSH_TIMEOUT = 5, /* min # of seconds between two log flush */ 28 | 29 | /* fork/prefork */ 30 | SERVER_MAX_CHILD = 300, /* total # of child process per-server */ 31 | SERVER_MAX_BACKEND_CHILD = 150, /* max # of child allowed to run at once 32 | per-backend */ 33 | 34 | /* prefork server model limits */ 35 | SERVER_PREFORK_START_CHILD = 2, /* # of child to run on startup */ 36 | SERVER_PREFORK_MAX_RQ_CHILD = 10000 /* max # of rq a process can serve */ 37 | }; 38 | 39 | enum { 40 | SERVER_MODEL_UNSET, /* uninitialized */ 41 | SERVER_MODEL_FORK, /* fork for each incoming connection */ 42 | SERVER_MODEL_ITERATIVE, /* serialize responses */ 43 | SERVER_MODEL_PREFORK, /* prefork a few child to serve more clients */ 44 | #ifdef OS_UNIX 45 | SERVER_MODEL_DEFAULT = SERVER_MODEL_PREFORK 46 | #else 47 | SERVER_MODEL_DEFAULT = SERVER_MODEL_ITERATIVE 48 | #endif 49 | }; 50 | 51 | int server_create(struct u_config_s *config, int model, server_t **ps); 52 | int server_free(server_t *s); 53 | int server_loop(server_t *s); 54 | int server_cgi(server_t *s); 55 | int server_stop(server_t *s); 56 | ppc_t* server_get_ppc(server_t *s); 57 | 58 | int server_get_logger(server_t *s, klog_t **pkl); 59 | int server_foreach_memlog_line(server_t *s, int (*cb)(const char*, void*), 60 | void *arg); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /klone/server_ppc_cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: server_ppc_cmd.h,v 1.1 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_PPC_COMMAND_H_ 12 | #define _KLONE_PPC_COMMAND_H_ 13 | #include 14 | #include 15 | 16 | /* nop */ 17 | int server_ppc_cmd_nop(server_t *s); 18 | int server_ppc_cb_nop(ppc_t *ppc, int fd, unsigned char cmd, char *data, 19 | size_t size, void *vso); 20 | 21 | /* add log */ 22 | int syslog_to_klog(int level); 23 | int server_ppc_cmd_log_add(server_t *s, int level, const char *str); 24 | int server_ppc_cb_log_add(ppc_t *ppc, int fd, unsigned char cmd, char *data, 25 | size_t size, void *vso); 26 | 27 | /* fork child */ 28 | int server_ppc_cmd_fork_child(server_t *s, backend_t *be); 29 | int server_ppc_cb_fork_child(ppc_t *ppc, int fd, unsigned char cmd, char *data, 30 | size_t size, void *vso); 31 | 32 | /* get log lines */ 33 | int server_ppc_cmd_log_get(server_t *s, size_t i, char *line); 34 | int server_ppc_cb_log_get(ppc_t *ppc, int fd, unsigned char cmd, 35 | char *data, size_t size, void *vso); 36 | 37 | /* access_log */ 38 | int server_ppc_cmd_access_log(server_t *s, int bid, int vhostid, 39 | const char *str); 40 | int server_ppc_cb_access_log(ppc_t *ppc, int fd, unsigned char cmd, char *data, 41 | size_t size, void *vso); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /klone/session.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: session.h,v 1.10 2009/10/23 14:08:28 tho Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_SESSION_H_ 12 | #define _KLONE_SESSION_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | struct session_s; 24 | typedef struct session_s session_t; 25 | 26 | int session_free(session_t*); 27 | int session_remove(session_t*); 28 | int session_clean(session_t*); 29 | int session_age(session_t*); 30 | 31 | vars_t *session_get_vars(session_t*); 32 | const char *session_get(session_t*, const char*); 33 | const char *session_get_id (session_t *ss); 34 | int session_set(session_t*, const char*, const char*); 35 | int session_del(session_t*, const char*); 36 | int session_load(session_t *ss); 37 | int session_save(session_t *ss); 38 | int session_save_to_io(session_t*, const char*); 39 | 40 | #ifdef SSL_ON 41 | int session_set_cipher_key(session_t*, const char*, size_t); 42 | int session_get_cipher_key(session_t*, char*, size_t*); 43 | #endif 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /klone/supplier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: supplier.h,v 1.8 2008/10/27 21:28:04 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_SUPPLIER_H_ 12 | #define _KLONE_SUPPLIER_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct supplier_s 24 | { 25 | const char *name; /* descriptive name */ 26 | int (*init)(void); 27 | void (*term)(void); 28 | int (*is_valid_uri)(http_t *h, request_t *rq, const char *file, size_t len, 29 | void **handle, time_t *mtime); 30 | int (*serve)(request_t *, response_t*); 31 | } supplier_t; 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /klone/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: timer.h,v 1.5 2006/04/22 13:59:01 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_TIMERM_H_ 12 | #define _KLONE_TIMERM_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | struct timerm_s; 19 | typedef struct timerm_s timerm_t; 20 | 21 | struct talarm_s; 22 | typedef struct talarm_s talarm_t; 23 | 24 | typedef int (*talarm_cb_t)(talarm_t *, void *arg); 25 | 26 | int timerm_add(int secs, talarm_cb_t cb, void *arg, talarm_t **pa); 27 | int timerm_del(talarm_t *a); 28 | int timerm_reschedule(talarm_t *a, int secs, talarm_cb_t cb, void *arg); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /klone/tls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: tls.h,v 1.11 2008/07/10 08:56:13 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_TLS_H_ 12 | #define _KLONE_TLS_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | #ifdef SSL_ON 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | int tls_init (void); 24 | SSL_CTX *tls_load_init_ctx (u_config_t *); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* SSL_ON */ 31 | 32 | #endif /* !_KLONE_TLS_H */ 33 | -------------------------------------------------------------------------------- /klone/tlsprv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: tlsprv.h,v 1.13 2008/03/26 09:02:24 tho Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_TLS_PRV_H_ 12 | #define _KLONE_TLS_PRV_H_ 13 | 14 | #include "klone_conf.h" 15 | #ifdef SSL_ON 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* (pseudo) unique data to feed the PRNG */ 22 | struct tls_rand_seed_s 23 | { 24 | pid_t pid; 25 | long t1, t2; 26 | void *stack; 27 | }; 28 | 29 | typedef struct tls_rand_seed_s tls_rand_seed_t; 30 | 31 | /* SSL_CTX initialization parameters. Mapping of "verify_client" configuration 32 | * directive to vmode is done in the following way: 33 | * "none" -> SSL_VERIFY_NONE 34 | * "optional" -> SSL_VERIFY_PEER 35 | * "require" -> SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT */ 36 | struct tls_ctx_args_s 37 | { 38 | const char *cert; /* server certificate file (PEM) */ 39 | const char *key; /* server private key (PEM) */ 40 | const char *certchain; /* Server Certificate Authorities (PEM) */ 41 | const char *ca; /* Client Certification Authorities file (PEM) */ 42 | const char *crl; /* Certificate Revocation List (PEM) */ 43 | const char *dh; /* Diffie-Hellman parameters (PEM) */ 44 | #ifdef SSL_OPENSSL_PSK 45 | const char *pskdb; /* Pre Shared Keys password file */ 46 | int psk_is_hashed; /* !0 if password is hashed (MD5), 0 if cleartext */ 47 | const char *psk_hint; /* PSK global hint (may be overridden locally) */ 48 | #endif 49 | int crlopts; /* CRL check mode: 'all' or 'client-only' */ 50 | int depth; /* max depth for the cert chain verification */ 51 | int vmode; /* SSL verification mode */ 52 | }; 53 | 54 | typedef struct tls_ctx_args_s tls_ctx_args_t; 55 | 56 | /* used by tls.c */ 57 | #ifdef SSL_OPENSSL 58 | DH *get_dh1024 (void); 59 | BIO *bio_from_emb (const char *); 60 | BIO *tls_get_file_bio(const char *res_name); 61 | STACK_OF(X509_NAME) *tls_load_client_CA_file(const char *); 62 | #endif 63 | int tls_load_verify_locations(SSL_CTX *, const char *); 64 | int tls_use_certificate_file(SSL_CTX *, const char *, int); 65 | int tls_use_PrivateKey_file(SSL_CTX *, const char *, int); 66 | int tls_use_certificate_chain(SSL_CTX *, const char *, int, 67 | int (*)(char *, int, int, void *)); 68 | int tls_use_crls (SSL_CTX *ctx, tls_ctx_args_t *cargs); 69 | int tls_verify_cb (int ok, X509_STORE_CTX *ctx); 70 | char *tls_get_error (void); 71 | #ifdef SSL_OPENSSL_PSK 72 | int tls_psk_init (SSL_CTX *c, tls_ctx_args_t *cargs); 73 | #endif 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* SSL_ON */ 80 | #endif /* _KLONE_TLS_PRV_H_ */ 81 | -------------------------------------------------------------------------------- /klone/translat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: translat.h,v 1.10 2008/10/18 17:23:32 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_TRANSLAT_H_ 12 | #define _KLONE_TRANSLAT_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | enum { URI_BUFSZ = 1024, MIME_BUFSZ = 256, EMSG_BUFSZ = 512 }; 23 | 24 | typedef struct trans_info_s 25 | { 26 | char file_in[U_FILENAME_MAX], file_out[U_FILENAME_MAX]; 27 | char depend_out[U_FILENAME_MAX]; 28 | char uri[URI_BUFSZ], mime_type[MIME_BUFSZ]; 29 | char dfun[URI_BUFSZ]; 30 | char key[CODEC_CIPHER_KEY_BUFSZ]; 31 | char emsg[EMSG_BUFSZ]; 32 | int comp; 33 | int encrypt; 34 | size_t file_size; 35 | time_t mtime; 36 | } trans_info_t; 37 | 38 | int translate(trans_info_t*); 39 | 40 | int translate_script_to_c(io_t *in, io_t *out, trans_info_t* ti); 41 | int translate_opaque_to_c(io_t *in, io_t *out, trans_info_t* ti); 42 | int translate_is_a_script(const char *filename); 43 | int translate_makefile_filepath(const char *filepath, const char *prefix, 44 | char *buf, size_t size); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /klone/uc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: uc.h,v 1.1 2007/08/07 17:13:09 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_UC_H_ 12 | #define _KLONE_UC_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /* user-provided startup/term functions (--enable_uc configure arg is needed) */ 19 | void uc_init(void); 20 | void uc_term(void); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /klone/va.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: va.h,v 1.2 2008/10/03 16:03:04 tho Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_VA_H_ 12 | #define _KLONE_VA_H_ 13 | 14 | #include "klone_conf.h" 15 | #include 16 | #include 17 | 18 | /* provide some suitable method for performing C99 va_copy */ 19 | #if defined(va_copy) 20 | /* C99 va_copy */ 21 | #define kl_va_copy(a, b) va_copy(a, b) 22 | #elif defined(__va_copy) 23 | /* GNU libc va_copy replacement */ 24 | #define kl_va_copy(a, b) __va_copy(a, b) 25 | #else 26 | #define VA_COPY_UNAVAIL 1 27 | #endif 28 | 29 | #endif /* !_KLONE_VA_H_ */ 30 | -------------------------------------------------------------------------------- /klone/var.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: var.h,v 1.8 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_VAR_H_ 12 | #define _KLONE_VAR_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | struct var_s; 22 | typedef struct var_s var_t; 23 | 24 | int var_create(const char* name, const char *value, var_t**); 25 | int var_bin_create(const char* name, const unsigned char *data, size_t size, 26 | var_t**); 27 | int var_free(var_t*); 28 | 29 | const char* var_get_name(var_t *v); 30 | const char* var_get_value(var_t *v); 31 | size_t var_get_value_size(var_t *v); 32 | 33 | u_string_t* var_get_name_s(var_t *v); 34 | u_string_t* var_get_value_s(var_t *v); 35 | 36 | int var_set(var_t*, const char *name, const char *value); 37 | int var_set_name(var_t *v, const char *name); 38 | int var_set_value(var_t *v, const char *value); 39 | int var_set_bin_value(var_t *v, const unsigned char *data, size_t size); 40 | 41 | void var_set_opaque(var_t *v, void *blob); 42 | void* var_get_opaque(var_t *v); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /klone/varprv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: varprv.h,v 1.8 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_VAR_PRV_H_ 12 | #define _KLONE_VAR_PRV_H_ 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | struct var_s 21 | { 22 | TAILQ_ENTRY(var_s) np; /* next & prev pointers */ 23 | u_string_t *sname; /* var string name */ 24 | u_string_t *svalue; /* var string value */ 25 | char *data; 26 | size_t size; 27 | void *opaque; 28 | }; 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /klone/vars.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: vars.h,v 1.10 2008/04/18 17:31:11 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_VARLIST_H_ 12 | #define _KLONE_VARLIST_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | enum { 22 | VARS_FLAG_NONE = 0, 23 | VARS_FLAG_FOREIGN = 1 << 0 /* don't free the list of var_t on vars_free */ 24 | }; 25 | 26 | struct vars_s; 27 | typedef struct vars_s vars_t; 28 | 29 | typedef int (*vars_cb_t)(var_t*, void*); 30 | 31 | int vars_create(vars_t ** pvs); 32 | int vars_free(vars_t *vs); 33 | 34 | int vars_set_flags(vars_t *vs, int flags); 35 | 36 | int vars_add(vars_t *vs, var_t *v); 37 | int vars_del(vars_t *vs, var_t *v); 38 | 39 | /* str must be a 'name=value' string */ 40 | int vars_add_strvar(vars_t *vs, const char *str); 41 | 42 | /* str must be a (possibly url-encoded) 'name=value' string */ 43 | int vars_add_urlvar(vars_t *vs, const char *cstr, var_t **v); 44 | 45 | var_t* vars_getn(vars_t *vs, size_t n); 46 | size_t vars_count(vars_t *vs); 47 | 48 | size_t vars_countn(vars_t *vs, const char *name); 49 | 50 | void vars_foreach(vars_t *vs, int (*foreach)(var_t*, void*), void *arg); 51 | 52 | /* get first variable called "name" */ 53 | var_t* vars_get(vars_t *vs, const char *name); 54 | const char* vars_get_value(vars_t *vs, const char *name); 55 | int vars_get_value_i(vars_t *vs, const char *name); 56 | u_string_t* vars_get_value_s(vars_t *vs, const char *name); 57 | 58 | /* get i-th variable called "name" */ 59 | var_t* vars_geti(vars_t *vs, const char *name, size_t ith); 60 | const char* vars_geti_value(vars_t *vs, const char *name, size_t ith); 61 | int vars_geti_value_i(vars_t *vs, const char *name, size_t ith); 62 | u_string_t* vars_geti_value_s(vars_t *vs, const char *name, size_t ith); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /klone/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: version.h,v 1.6 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_VERSION_H_ 12 | #define _KLONE_VERSION_H_ 13 | 14 | #include "klone_conf.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | const char *klone_version(void); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /klone/vhost.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: vhost.h,v 1.3 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_VHOST_H_ 12 | #define _KLONE_VHOST_H_ 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /* define page list */ 21 | LIST_HEAD(vhost_list_s, vhost_s); 22 | 23 | struct http_s; 24 | struct klog_s; 25 | 26 | typedef struct vhost_s 27 | { 28 | LIST_ENTRY(vhost_s) np; /* next & prev pointers */ 29 | struct http_s *http; /* parent http object */ 30 | struct klog_s *klog; /* vhost logging facility */ 31 | u_config_t *config; /* vhost configuration */ 32 | u_config_t *al_config; /* cached access_log config ptr */ 33 | const char *host; /* hostname */ 34 | int id; /* position in the vhosts list */ 35 | 36 | /* cached configuration options */ 37 | const char *server_sig; /* server signature */ 38 | const char *dir_root; /* base html directory */ 39 | const char *index; /* user-provided index page(s) */ 40 | int send_enc_deflate; /* >0 if sending deflated content is not disabled*/ 41 | } vhost_t; 42 | 43 | typedef struct vhost_list_s vhost_list_t; 44 | 45 | int vhost_create(vhost_t **pv); 46 | int vhost_free(vhost_t *v); 47 | 48 | int vhost_list_create(vhost_list_t **pvs); 49 | int vhost_list_free(vhost_list_t *vs); 50 | int vhost_list_add(vhost_list_t *vs, vhost_t *vhost); 51 | vhost_t* vhost_list_get_n(vhost_list_t *vs, int n); 52 | vhost_t* vhost_list_get(vhost_list_t *vs, const char *host); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /pkg/Makefile.doc: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.doc,v 1.1 2005/11/27 15:50:37 tho Exp $ 2 | 3 | SUBDIR = man html 4 | 5 | include subdir.mk 6 | -------------------------------------------------------------------------------- /pkg/Makefile.doxy.doc: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.doxy.doc,v 1.5 2007/08/07 15:58:52 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | HTMLDOCDIR = ${DOCDIR}/klone/html/ 7 | 8 | all clean depend cleandepend: 9 | 10 | ifdef INSTALL_DAEMON_ONLY 11 | install: 12 | else 13 | install: 14 | ${MKINSTALLDIRS} ${HTMLDOCDIR} && cp -r *.html *.css ${HTMLDOCDIR} 15 | endif 16 | 17 | uninstall: 18 | rm -rf ${HTMLDOCDIR} 19 | -------------------------------------------------------------------------------- /site/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.10 2008/10/27 21:28:04 tat Exp $ 2 | 3 | include common.mk 4 | include ../Makefile.conf 5 | include ../webapp/Makefile-webapp 6 | 7 | LIB = site 8 | SRCS = register.c 9 | 10 | ifdef SSL_ON 11 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 12 | endif 13 | 14 | ifdef INSTALL_DAEMON_ONLY 15 | NO_INSTALL = true 16 | endif 17 | 18 | CFLAGS += ${WEBAPP_CFLAGS} 19 | CLEANFILES += pg_*.c pg_*.cc pg_*.o pg_*.d pg_*.kld autogen.* register.c libsite.a 20 | 21 | # if already set don't change it 22 | KLONE ?= ../src/tools/klone/klone 23 | 24 | # hack to support actual autogen.dps 25 | srcdir = . 26 | 27 | # update the list of srcs reading from autogen.mk 28 | -include autogen.mk 29 | SRCS += ${autogen_src} 30 | 31 | include lib.mk 32 | 33 | beforedepend: register.c 34 | 35 | register.c: register-def.c 36 | @cp -f $< $@ 37 | 38 | autogen.dps: 39 | @echo > $@ 40 | 41 | autogen.mk: 42 | @echo "autogen_src=" > $@ 43 | 44 | -include autogen.dps 45 | -------------------------------------------------------------------------------- /site/register-def.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if ENABLE_SUP_KILT 4 | #include 5 | #include 6 | kilt_url_t *kilt_urls = NULL; 7 | size_t kilt_nurls = 0; 8 | #endif 9 | 10 | void register_pages(void);void unregister_pages(void); 11 | void register_pages(void){} void unregister_pages(void){} 12 | -------------------------------------------------------------------------------- /skin/default/LICENSE: -------------------------------------------------------------------------------- 1 | KLone - Copyright (c) 2005-2012 by KoanLogic srl 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | Neither the name of the KoanLogic srl nor the names of its contributors may be 15 | used to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /skin/default/Makefile.dist: -------------------------------------------------------------------------------- 1 | # run make -f Makefile.dist to make the dist tarball 2 | # 3 | # a good starting point to build DISTFILES is: 4 | # 5 | # find . -follow -type f -or -type l | grep -v CVS | cut -c3- | egrep '.' \ 6 | # > DISTFILES 7 | 8 | 9 | VERSION = $(shell cat ../../VERSION) 10 | TARBALL = klone-$(VERSION).tar.gz 11 | 12 | # base src dir 13 | BASE = $(shell pwd)/../../ 14 | 15 | KLONE_CORE_TARBALL = build/dist/klone-core-$(VERSION).tar.gz 16 | 17 | ifeq ($(wildcard $(BASE)/makl/),) 18 | $(error missing $(BASE)/makl directory) 19 | endif 20 | 21 | all dist: VERSION ChangeLog build/makl $(KLONE_CORE_TARBALL) 22 | rm -f $(TARBALL) $(TARBALL).md5 23 | tar zcfh .$(TARBALL) -T DISTFILES $(KLONE_CORE_TARBALL) 24 | mkdir klone-$(VERSION) 25 | tar zxf .$(TARBALL) -C klone-$(VERSION) 26 | tar zvcf $(TARBALL) klone-$(VERSION) 27 | md5sum $(TARBALL) > $(TARBALL).md5 28 | rm -f .$(TARBALL) 29 | rm -rf klone-$(VERSION) 30 | 31 | $(KLONE_CORE_TARBALL): 32 | cd $(BASE)/makl && make toolchain rc 33 | cd $(BASE) && . makl/makl.env && ./configure && make clean && make && \ 34 | make -f Makefile.dist dist 35 | rm -rf build/dist 36 | mkdir -p build/dist 37 | cd build/dist && ln -sf $(BASE)/klone-core-$(VERSION).tar.gz 38 | 39 | ChangeLog: 40 | ln -sf $(BASE)/ChangeLog 41 | 42 | VERSION: 43 | ln -sf $(BASE)/VERSION 44 | 45 | build/makl: 46 | cd build && ln -sf $(BASE)/makl 47 | 48 | clean: 49 | rm -f $(KLONE_CORE_TARBALL) $(TARBALL) $(TARBALL).md5 50 | -------------------------------------------------------------------------------- /skin/default/Makefile.help: -------------------------------------------------------------------------------- 1 | List of supported variables 2 | 3 | + KLONE_VERSION 4 | 5 | Version of KLone to use (will be downloaded automatically) 6 | 7 | Example: 8 | KLONE_VERSION = 2.0.0 9 | 10 | + KLONE_DAEMON_NAME 11 | 12 | Filename of the compiled KLone daemon 13 | 14 | Example: 15 | KLONE_DAEMON_NAME = myapp 16 | 17 | + KLONE_CONF_ARGS 18 | 19 | List of arguments to be passed to klone-core configure script. 20 | 21 | Run 'make configure-help' to display the list of suitable arguments. 22 | 23 | Example: 24 | KLONE_CONF_ARGS = --prefix=/opt/myapp --enable_debug 25 | 26 | + KLONE_IMPORT_ARGS 27 | 28 | List of arguments used to import your webapp directory. 29 | 30 | Run 'make import-help' to display the list of options. 31 | 32 | Example: 33 | KLONE_IMPORT_ARGS = -v -z -x '*/CVS/*' 34 | 35 | + MAKL_PLATFORM 36 | 37 | Used to select the target platform when cross-compiling. 38 | 39 | Examples: 40 | MAKL_PLATFORM = linux-cris-axis 41 | MAKL_PLATFORM = linux-arm 42 | 43 | + KLONE_CUSTOM_TC 44 | 45 | Holds the full path of the toolchain to be used to compile the 46 | daemon. 47 | 48 | Examples: 49 | KLONE_CUSTOM_TC = /path/to/my-own.tc 50 | 51 | + SUBDIR 52 | 53 | A list of subdirectory to be build by 'make'. 54 | 55 | Examples: 56 | SUBDIR = libutil libother doc 57 | 58 | + WEBAPP_DIR 59 | 60 | Set the directory where the content files of the web application 61 | (html pages, images, dynamic scripts, Flash apps) are stored. 62 | 63 | If the specified directory does not exist a simple skeleton 64 | application will be automatically created in the given directory. 65 | 66 | Examples: 67 | WEBDIR_DIR = /path/to/webdir/ 68 | WEBDIR_DIR = $(shell pwd)/myappdir 69 | 70 | + WEBAPP_CFLAGS 71 | + WEBAPP_LDFLAGS 72 | + WEBAPP_LDADD 73 | 74 | Contain the compilation (WEBAPP_CFLAGS) and linking (WEBAPP_LDFLAGS) 75 | flags used when compiling web application source files. 76 | 77 | Use WEBAPP_LDADD to include static libraries (*.a) or object files 78 | (*.o). 79 | 80 | Examples: 81 | WEBDIR_CFLAGS = -D_DEBUG_ -O2 82 | WEBDIR_LDFLAGS = -L/usr/local/lib -lz -ldb 83 | WEBDIR_LDADD = $(shell pwd)/libs/util/libutil.a 84 | 85 | -------------------------------------------------------------------------------- /skin/default/Makefile.in: -------------------------------------------------------------------------------- 1 | # Variables to be defined 2 | # 3 | # KLONE_VERSION KLone version to use (will be downloaded from koanlogic.com) 4 | # 5 | # SUBDIR (optional) list of additional directories to build on make 6 | # 7 | # WEBAPP_CFLAGS (optional) additional CFLAGS 8 | # WEBAPP_LDFLAGS (optional) additional LDFLAGS 9 | # WEBAPP_LDADD (optional) additional object files and/or static libs (.a) 10 | # (requires absolute paths) 11 | # 12 | # Predefined variables: 13 | # 14 | # KLONE_APP_TOP top-dir directory (where this Makefile is stored) 15 | # KLONE_SRC location of klone source tree 16 | # 17 | -include Makefile.conf 18 | 19 | # klone version to use 20 | KLONE_VERSION ?= @{{KLONE_VERSION}} 21 | 22 | # klone configure arguments 23 | KLONE_CONF_ARGS ?= \ 24 | --prefix=$(DESTDIR) \ 25 | --libs=$(DESTDIR) 26 | 27 | # cross-compiling (see build/makl/tc/* for the list of supported platforms) 28 | # MAKL_PLATFORM ?= 29 | 30 | # or provide custom toolchain file 31 | # KLONE_CUSTOM_TC ?= 32 | 33 | # helper libs 34 | # SUBDIR ?= 35 | 36 | # web application directory (defaults to webapp/ in the current dir) 37 | # WEBAPP_DIR ?= 38 | 39 | # additional CFLAGS, LDFLAGS and LDADD (optional, use absolute paths for LDADD) 40 | WEBAPP_CFLAGS ?= -I$(KLONE_APP_TOP) -I$(KLONE_SRC) 41 | WEBAPP_LDADD ?= 42 | WEBAPP_LDFLAGS ?= 43 | 44 | -include build/mk/klone-app.mk 45 | 46 | -------------------------------------------------------------------------------- /skin/default/README: -------------------------------------------------------------------------------- 1 | COMPILATION 2 | ----------- 3 | 4 | $ ./configure 5 | $ make 6 | 7 | 8 | CUSTOMIZATION 9 | ------------- 10 | 11 | Edit KLone configuration file in webapp/etc/kloned.conf and web 12 | application files in webapp/www to customize your application. 13 | 14 | After adding, removing or modifying any file in webapp directory 15 | run 'make' to rebuild the 'kloned' daemon (by defaults it binds to 16 | port 8080). 17 | 18 | To modify compilation flags edit the top level Makefile (WEBAPP_CFLAGS, 19 | WEBAPP_LDFLAGS and WEBAPP_LDADD). Always use absolute paths for these 20 | variables. 21 | 22 | RUNNING 23 | ------- 24 | 25 | $ ./kloned 26 | 27 | If something goes wrong you can find log messages in syslog files. 28 | 29 | -------------------------------------------------------------------------------- /skin/default/build/host/Makefile: -------------------------------------------------------------------------------- 1 | include common.mk 2 | 3 | # reset MaKL platform, we want to compile for the host CPU using KLone's own 4 | # MaKL files 5 | export MAKL_PLATFORM = 6 | export MAKL_TC = 7 | export MAKL_DIR = 8 | export MAKEFLAGS= 9 | 10 | XENO_FETCH_URI = http://koanlogic.com/klone/klone-core-$(KLONE_VERSION).tar.gz 11 | 12 | XENO_UNZIP_FLAGS = zxf 13 | 14 | XENO_NO_CONF = true 15 | XENO_NO_BUILD = true 16 | XENO_NO_INSTALL = true 17 | 18 | ifeq ($(KLONE_HOST_PATCH_FILE)$(KLONE_HOST_PATCH_URI),) 19 | XENO_NO_PATCH = true 20 | endif 21 | 22 | ifdef KLONE_HOST_PATCH_FILE 23 | XENO_PATCH_FILE = $(KLONE_HOST_PATCH_FILE) 24 | endif 25 | 26 | ifdef KLONE_HOST_PATCH_URI 27 | XENO_PATCH_URI = $(KLONE_HOST_PATCH_URI) 28 | endif 29 | 30 | include xeno.mk 31 | -------------------------------------------------------------------------------- /skin/default/build/makecheck/GNUmakefile: -------------------------------------------------------------------------------- 1 | # if in this makefile then it's gnu make calling... 2 | all: 3 | 4 | -------------------------------------------------------------------------------- /skin/default/build/makecheck/Makefile: -------------------------------------------------------------------------------- 1 | world ${.TARGETS}: 2 | @echo "You must use the GNU make." 3 | @echo "Please set the environment variable MAKE to the GNU make path" 4 | @echo "(ex. export MAKE=/bin/gnumake)" 5 | @exit 1 6 | 7 | -------------------------------------------------------------------------------- /skin/default/build/target/Makefile: -------------------------------------------------------------------------------- 1 | include common.mk 2 | 3 | XENO_FETCH_URI = http://koanlogic.com/klone/klone-core-$(KLONE_VERSION).tar.gz 4 | 5 | XENO_UNZIP_FLAGS = zxf 6 | 7 | XENO_NO_CONF = true 8 | XENO_NO_BUILD = true 9 | XENO_NO_INSTALL = true 10 | 11 | ifeq ($(KLONE_TARGET_PATCH_FILE)$(KLONE_TARGET_PATCH_URI),) 12 | XENO_NO_PATCH = true 13 | endif 14 | 15 | ifdef KLONE_TARGET_PATCH_FILE 16 | XENO_PATCH_FILE = $(KLONE_TARGET_PATCH_FILE) 17 | endif 18 | 19 | ifdef KLONE_TARGET_PATCH_URI 20 | XENO_PATCH_URI = $(KLONE_TARGET_PATCH_URI) 21 | endif 22 | 23 | include xeno.mk 24 | -------------------------------------------------------------------------------- /skin/default/configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: configure,v 1.3 2007/10/09 17:39:08 tat Exp $ 4 | 5 | export makl_conf_h=klapp_conf.h 6 | export MAKL_DIR=`pwd`/build/makl 7 | 8 | if [ -z "$MAKE" ]; then 9 | MAKE=make 10 | fi 11 | 12 | # will fail using something different then GNU make 13 | ( cd build/makecheck && ${MAKE} ) || exit 1 14 | 15 | # before running configure the toolchain must be present 16 | if [ ! -r ${MAKL_DIR}/etc/toolchain.cf ]; then 17 | ${MAKE} -C ${MAKL_DIR} toolchain 18 | fi 19 | 20 | # MaKL preamble 21 | . ${MAKL_DIR}/cf/makl.init 22 | 23 | # Preprocess arguments 24 | makl_args_init "$@" 25 | 26 | # General settings 27 | makl_pkg_name "klapp" 28 | makl_pkg_version 29 | 30 | # Handle command-line arguments 31 | makl_args_handle "$@" 32 | 33 | . ${MAKL_DIR}/cf/makl.term 34 | 35 | ln -sf build/makl/mk/reloc.mk 36 | -------------------------------------------------------------------------------- /skin/default/pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | E () 4 | { 5 | echo "\033[1;37m\033[42m $@ \033[0m" 6 | tput sgr0 7 | } 8 | 9 | err () 10 | { 11 | E "####################################################################" 12 | E "# Error: $@" 13 | E "####################################################################" 14 | 15 | exit 1 16 | } 17 | 18 | wrap () 19 | { 20 | msg=$1 ; shift ; cmd=$@ 21 | 22 | E "$ "$cmd"" 23 | eval ${cmd} 2>/dev/null || err $msg 24 | } 25 | 26 | yesno () 27 | { 28 | /bin/echo -n "$1 ([yY] or [nN]) " 29 | 30 | while [ true ] 31 | do 32 | read answer 33 | case ${answer} in 34 | [Yy]) return 0 ;; 35 | [nN]) return 1 ;; 36 | *) /bin/echo -n "please say [yY] or [nN]: " ;; 37 | esac 38 | done 39 | } 40 | 41 | DISTDIR="/tmp/klone-dist" 42 | 43 | wrap "deleting dist directory $DISTDIR" \ 44 | rm -rf $DISTDIR 45 | wrap "creating dist directory $DISTDIR" \ 46 | mkdir $DISTDIR 47 | wrap "changing directory to $DISTDIR" \ 48 | cd $DISTDIR 49 | 50 | # clone fresh repos 51 | wrap "cloning makl git repository" \ 52 | git clone file:///${HOME}/work/GIT/makl 53 | wrap "cloning libu git repository" \ 54 | git clone file:///${HOME}/work/GIT/libu 55 | wrap "cloning klone git repository" \ 56 | git clone file:///${HOME}/work/GIT/klone 57 | 58 | wrap "moving into to klone subdirectory" \ 59 | cd klone 60 | wrap "pull in libu" \ 61 | ln -s ../libu 62 | wrap "pull in makl" \ 63 | ln -s ../makl 64 | 65 | wrap "moving to dist directory" \ 66 | cd skin/default 67 | wrap "launching dist make instance" \ 68 | make -f Makefile.dist 69 | 70 | TARBALL="${DISTDIR}/klone/skin/default/klone-`cat VERSION`.tar.gz" 71 | 72 | E "============================================================================" 73 | E "klone tarball ready: " 74 | E " ${TARBALL}" 75 | E "============================================================================" 76 | 77 | yesno "===> upload tarball to kl.com ?" || exit 0 78 | 79 | wrap "uploading klone tarball" \ 80 | scp ${TARBALL}* root@koanlogic.com:/var/www-anemic/www/download/klone/ 81 | 82 | exit 0 83 | -------------------------------------------------------------------------------- /skin/default/share/Makefile.example: -------------------------------------------------------------------------------- 1 | # 2 | # Run 'make help' for help on variables and targets 3 | # 4 | TOP = $(shell pwd) 5 | 6 | # which klone version? 7 | KLONE_VERSION ?= 2.4.0 8 | 9 | # set the following as needed (wget should be ok on most platforms) 10 | #export FETCH_CMD = curl -O 11 | #export FETCH_CMD = ftp 12 | #export FETCH_CMD = fetch 13 | export FETCH_CMD = wget 14 | 15 | # set the name of the daemon program (otherwise "kloned" will be used) 16 | # KLONE_DAEMON_NAME = myapp 17 | 18 | # configure script arguments (try ./configure --help) 19 | # KLONE_CONF_ARGS ?= --install_daemon_only --prefix=/my/install/dir 20 | 21 | # import arguments (any argument supported by klone import utility is allowed) 22 | # KLONE_IMPORT_ARGS ?= 23 | 24 | # cross compile 25 | # MAKL_PLATFORM ?= 26 | # or provide custom toolchain file 27 | # KLONE_CUSTOM_TC ?= 28 | 29 | # embedded fs (will be created if it does not exist) 30 | WEBAPP_DIR = $(TOP)/webapp 31 | 32 | # also build the following subdirs 33 | # SUBDIR = $(TOP)/libhelp 34 | 35 | # compiler and linker flags 36 | # WEBAPP_CFLAGS = -I$(TOP)/ 37 | # WEBAPP_LDFLAGS = 38 | # WEBAPP_LDADD = $(TOP)/libhelp/libhelp.a 39 | 40 | include klapp.mk 41 | 42 | klapp.mk: ; $(FETCH_CMD) http://koanlogic.com/klone/klapp.mk 43 | -------------------------------------------------------------------------------- /skin/default/webapp/etc/kloned.conf: -------------------------------------------------------------------------------- 1 | # $Id: kloned.conf,v 1.1 2007/07/07 14:09:57 tat Exp $ 2 | 3 | server_list app_http 4 | 5 | # needed if you want to run KLone daemon as root 6 | allow_root yes 7 | 8 | # syslog logging using LOCAL0 facility (set /etc/syslog.conf accordingly) 9 | log 10 | { 11 | type syslog 12 | syslog.facility LOG_LOCAL0 13 | } 14 | 15 | app_http 16 | { 17 | type http 18 | 19 | addr tcp4://*:8080 20 | dir_root /www 21 | } 22 | -------------------------------------------------------------------------------- /skin/default/webapp/www/images/kl_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koanlogic/klone/bfa77f491b837278ace8efaab84bef880fc9b225/skin/default/webapp/www/images/kl_bg.png -------------------------------------------------------------------------------- /skin/default/webapp/www/index.kl1: -------------------------------------------------------------------------------- 1 | <%! 2 | #include 3 | #include 4 | time_t now; 5 | %> 6 | 7 | 8 | KLone start page 9 | 10 | 11 | 12 | 13 |
14 | 15 |
16 |
17 |

Welcome to KLone (Ver. <%= KLAPP_VERSION %>)!

18 |
19 |
20 |

21 | 22 |

23 | <% 24 | now = time(0); 25 | io_printf(out, "Time: %s", ctime(&now)); 26 | %> 27 |
28 | 29 |

30 | 31 | About KLone: 32 |

33 | 34 | Info
35 | Features
36 | Tutorial
37 | Support
38 | Wiki
39 | GitHub
40 | 41 |
42 | 43 | 44 | Copyright (c) 2005-2013 by KoanLogic s.r.l. - All rights reserved. 45 | 46 |
47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.8 2007/09/04 12:15:16 tat Exp $ 2 | 3 | include ../Makefile.conf 4 | 5 | SUBDIR = libutils 6 | SUBDIR += libbackend 7 | SUBDIR += libcodec 8 | SUBDIR += libemb 9 | SUBDIR += libhttp 10 | SUBDIR += libio 11 | SUBDIR += libpage 12 | ifdef SSL_ON 13 | SUBDIR += libtls 14 | endif 15 | SUBDIR += libtrans 16 | SUBDIR += libklog 17 | ifdef ENABLE_HOOKS 18 | SUBDIR += libhook 19 | endif 20 | SUBDIR += tools 21 | SUBDIR += kloned 22 | 23 | include subdir.mk 24 | 25 | # dir dependencies 26 | kloned tools: $(filter-out kloned tools, $(SUBDIR)) 27 | -------------------------------------------------------------------------------- /src/kloned/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.32 2008/10/27 21:28:04 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | include ../../webapp/Makefile-webapp 6 | 7 | ifdef DAEMON_NAME 8 | PROG = $(DAEMON_NAME) 9 | else 10 | PROG = kloned 11 | endif 12 | 13 | INCS = main.h server_s.h server_ppc_cmd.h child.h 14 | SRCS = server.c main.c entry.c ppc.c atom.c ppc_log_add.c ppc_log_get.c \ 15 | ppc_nop.c child.c ppc_access_log.c 16 | 17 | CFLAGS += ${SSL_CFLAGS} ${LIBZ_CFLAGS} 18 | LDFLAGS += ${SSL_LDFLAGS} ${LIBZ_LDFLAGS} 19 | 20 | LDFLAGS += ${WEBAPP_LDFLAGS} 21 | 22 | ifdef OS_UNIX 23 | SRCS += ppc_fork_child.c 24 | endif 25 | 26 | LDADD += ../libhttp/libhttp.a ../libutils/libutils.a ../libpage/libpage.a \ 27 | ../libbackend/libbackend.a ../libemb/libemb.a ../libio/libio.a 28 | 29 | ifdef SSL_ON 30 | LDADD += ../libtls/libtls.a 31 | endif 32 | 33 | LDADD += ../../site/libsite.a ../libcodec/libcodec.a \ 34 | ../libklog/libklog.a ../../webapp/libwebapp.a ../libhttp/libhttp.a \ 35 | ../libpage/libpage.a ../libutils/libutils.a ../libio/libio.a \ 36 | ../libcodec/libcodec.a ../libpage/libpage.a 37 | 38 | ifdef ENABLE_HOOKS 39 | LDADD += ../libhook/libhook.a 40 | endif 41 | 42 | LDADD += ${WEBAPP_LDADD} 43 | 44 | # add libu flags 45 | CFLAGS += -I../../libu/include 46 | LDADD += ../../libu/srcs/libu.a 47 | 48 | BINDIR = ${DESTDIR}/sbin 49 | 50 | ifdef MAKL_PLATFORM 51 | # 'install' may not be able to strip cross compiled binaries 52 | INSTALL_STRIP = 53 | endif 54 | 55 | include prog.mk 56 | 57 | strip: $(PROG) 58 | @$(STRIP) $(PROG) 59 | 60 | ifdef DAEMON_NAME 61 | # always create "kloned" for backward compatibility 62 | all-hook-post: 63 | @ln -sf $(DAEMON_NAME) kloned 64 | endif 65 | 66 | -------------------------------------------------------------------------------- /src/kloned/child.c: -------------------------------------------------------------------------------- 1 | #include "klone_conf.h" 2 | #include 3 | #include "child.h" 4 | 5 | TAILQ_HEAD(child_list_s, child_s); 6 | typedef struct child_list_s child_list_t; 7 | 8 | struct children_s 9 | { 10 | child_list_t clist; 11 | size_t nchild; 12 | }; 13 | 14 | int children_add(children_t *cs, child_t *child) 15 | { 16 | dbg_return_if (cs == NULL, ~0); 17 | dbg_return_if (child == NULL, ~0); 18 | 19 | TAILQ_INSERT_TAIL(&cs->clist, child, np); 20 | cs->nchild++; 21 | 22 | return 0; 23 | } 24 | 25 | int children_del(children_t *cs, child_t *child) 26 | { 27 | dbg_return_if (cs == NULL, ~0); 28 | dbg_return_if (child == NULL, ~0); 29 | 30 | TAILQ_REMOVE(&cs->clist, child, np); 31 | cs->nchild--; 32 | 33 | return 0; 34 | } 35 | 36 | size_t children_count(children_t *cs) 37 | { 38 | dbg_return_if (cs == NULL, 0); 39 | 40 | return cs->nchild; 41 | } 42 | 43 | int children_clear(children_t *cs) 44 | { 45 | child_t *c; 46 | 47 | dbg_err_if (cs == NULL); 48 | 49 | /* free all variables */ 50 | while((c = TAILQ_FIRST(&cs->clist)) != NULL) 51 | { 52 | if(!children_del(cs, c)) 53 | child_free(c); 54 | } 55 | 56 | return 0; 57 | err: 58 | return 0; 59 | } 60 | 61 | int children_getn(children_t *cs, size_t i, child_t **pc) 62 | { 63 | child_t *c; 64 | 65 | dbg_err_if (cs == NULL); 66 | dbg_err_if (pc == NULL); 67 | dbg_err_if (i >= cs->nchild); /* out of bounds */ 68 | 69 | TAILQ_FOREACH(c, &cs->clist, np) 70 | { 71 | if(i-- == 0) 72 | { 73 | *pc = c; 74 | return 0; /* found */ 75 | } 76 | } 77 | 78 | err: 79 | return ~0; 80 | } 81 | 82 | int children_get_by_pid(children_t *cs, pid_t pid, child_t **pc) 83 | { 84 | child_t *c; 85 | 86 | dbg_goto_if (cs == NULL, notfound); 87 | dbg_goto_if (pc == NULL, notfound); 88 | 89 | TAILQ_FOREACH(c, &cs->clist, np) 90 | { 91 | if(c->pid == pid) 92 | { 93 | *pc = c; 94 | return 0; /* found */ 95 | } 96 | } 97 | 98 | notfound: 99 | return ~0; /* not found */ 100 | } 101 | 102 | int children_free(children_t *cs) 103 | { 104 | if(cs) 105 | { 106 | /* del and free all child_t objects */ 107 | dbg_if(children_clear(cs)); 108 | U_FREE(cs); 109 | } 110 | 111 | return 0; 112 | } 113 | 114 | int children_create(children_t **pcs) 115 | { 116 | children_t *cs; 117 | 118 | dbg_err_if (pcs == NULL); 119 | 120 | cs = u_zalloc(sizeof(children_t)); 121 | dbg_err_if(cs == NULL); 122 | 123 | TAILQ_INIT(&cs->clist); 124 | 125 | *pcs = cs; 126 | 127 | return 0; 128 | err: 129 | return ~0; 130 | } 131 | 132 | int child_create(pid_t pid, backend_t *be, child_t **pchild) 133 | { 134 | child_t *c; 135 | 136 | dbg_err_if (pchild == NULL); 137 | 138 | c = u_zalloc(sizeof(child_t)); 139 | dbg_err_if(c == NULL); 140 | 141 | c->pid = pid; 142 | c->be = be; 143 | c->birth = time(0); 144 | 145 | *pchild = c; 146 | 147 | return 0; 148 | err: 149 | return ~0; 150 | } 151 | 152 | int child_free(child_t *child) 153 | { 154 | U_FREE(child); 155 | return 0; 156 | } 157 | 158 | -------------------------------------------------------------------------------- /src/kloned/child.h: -------------------------------------------------------------------------------- 1 | #ifndef _KLONED_CHILD_S_H_ 2 | #define _KLONED_CHILD_S_H_ 3 | #include "klone_conf.h" 4 | #include 5 | #include 6 | #include 7 | 8 | struct child_s 9 | { 10 | TAILQ_ENTRY(child_s) np; /* next & prev pointers */ 11 | pid_t pid; 12 | backend_t *be; 13 | time_t birth; 14 | }; 15 | 16 | typedef struct child_s child_t; 17 | 18 | struct children_s; 19 | typedef struct children_s children_t; 20 | 21 | int child_create(pid_t pid, backend_t *be, child_t **pchild); 22 | int child_free(child_t *child); 23 | 24 | backend_t* child_backend(child_t *child); 25 | pid_t* child_pid(child_t *child); 26 | time_t* child_birth(child_t *child); 27 | 28 | /* list of child objects */ 29 | int children_create(children_t **pcs); 30 | int children_free(children_t *cs); 31 | int children_clear(children_t *cs); 32 | size_t children_count(children_t *cs); 33 | int children_del(children_t *cs, child_t *child); 34 | int children_add(children_t *cs, child_t *child); 35 | int children_getn(children_t *cs, size_t i, child_t **pc); 36 | int children_get_by_pid(children_t *cs, pid_t pid, child_t **pc); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/kloned/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: main.h,v 1.4 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_MAIN_H_ 12 | #define _KLONE_MAIN_H_ 13 | 14 | int app_init(void); 15 | int app_run(void); 16 | int app_term(void); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/kloned/ppc_access_log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ppc_access_log.c,v 1.1 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "server_s.h" 21 | 22 | /* struct used for ppc command PPC_CMD_LOG_ADD */ 23 | struct ppc_access_log_s 24 | { 25 | int bid; /* calling backend ID */ 26 | int vhostid; /* vhost ID */ 27 | char log[U_MAX_LOG_LENGTH]; /* log line */ 28 | }; 29 | 30 | typedef struct ppc_access_log_s ppc_access_log_t; 31 | 32 | /* client function */ 33 | int server_ppc_cmd_access_log(server_t *s, int bid, int vhostid, 34 | const char *str) 35 | { 36 | ppc_access_log_t la; 37 | 38 | nop_err_if (s == NULL); 39 | nop_err_if (s->ppc == NULL); 40 | nop_err_if (str == NULL); 41 | 42 | memset(&la, 0, sizeof(ppc_access_log_t)); 43 | 44 | la.bid = bid; 45 | la.vhostid = vhostid; 46 | (void) u_strlcpy(la.log, str, sizeof la.log); 47 | 48 | /* send the command request */ 49 | nop_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_ACCESS_LOG, (char*)&la, 50 | sizeof(la)) < 0); 51 | 52 | return 0; 53 | err: 54 | return ~0; 55 | } 56 | 57 | /* [parent] log a new message */ 58 | int server_ppc_cb_access_log(ppc_t *ppc, int fd, unsigned char cmd, char *data, 59 | size_t size, void *vso) 60 | { 61 | server_t *s; 62 | ppc_access_log_t *pla; 63 | backend_t *be; 64 | vhost_t *vhost; 65 | vhost_list_t *vhost_list; 66 | http_t *http; 67 | 68 | u_unused_args(ppc, fd, cmd, size); 69 | 70 | nop_err_if (vso == NULL); 71 | nop_err_if (data == NULL); 72 | 73 | pla = (ppc_access_log_t*) data; 74 | s = (server_t *) vso; 75 | 76 | /* get the http object */ 77 | if(!server_get_backend_by_id(s, pla->bid, &be) && be->arg) 78 | http = (http_t*)be->arg; 79 | 80 | dbg_err_if((vhost_list = http_get_vhost_list(http)) == NULL); 81 | 82 | dbg_err_if((vhost = vhost_list_get_n(vhost_list, pla->vhostid)) == NULL); 83 | 84 | /* log the line */ 85 | if(vhost->klog) 86 | nop_err_if(klog(vhost->klog, KLOG_INFO, "%s", pla->log)); 87 | 88 | return 0; 89 | err: 90 | return ~0; 91 | } 92 | 93 | -------------------------------------------------------------------------------- /src/kloned/ppc_fork_child.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ppc_fork_child.c,v 1.10 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "server_s.h" 21 | 22 | /* struct used for ppc command PPC_CMD_NOP */ 23 | struct ppc_fork_child_s 24 | { 25 | int bid; /* backend id */ 26 | }; 27 | 28 | typedef struct ppc_fork_child_s ppc_fork_child_t; 29 | 30 | /* client function */ 31 | int server_ppc_cmd_fork_child(server_t *s, backend_t *be) 32 | { 33 | ppc_fork_child_t pfc; 34 | 35 | nop_err_if (s == NULL); 36 | nop_err_if (s->ppc == NULL); 37 | nop_err_if (be == NULL); 38 | 39 | memset(&pfc, 0, sizeof(ppc_fork_child_t)); 40 | 41 | pfc.bid = be->id; 42 | 43 | /* send the command request */ 44 | nop_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_FORK_CHILD, (char*)&pfc, 45 | sizeof(ppc_fork_child_t)) < 0); 46 | 47 | return 0; 48 | err: 49 | return ~0; 50 | } 51 | 52 | /* [parent] */ 53 | int server_ppc_cb_fork_child(ppc_t *ppc, int fd, unsigned char cmd, char *data, 54 | size_t size, void *vso) 55 | { 56 | backend_t *be = NULL; 57 | ppc_fork_child_t *ppfc; 58 | 59 | u_unused_args(ppc, fd, cmd, size, vso); 60 | 61 | dbg_err_if (data == NULL); 62 | 63 | ppfc = (void *) data; 64 | 65 | dbg_err_if(server_get_backend_by_id(ctx->server, ppfc->bid, &be) || 66 | be == NULL); 67 | 68 | u_dbg("[parent] ppc spawn child"); 69 | 70 | /* try to fork now, if we can't (resource limit or max_child exceeded) 71 | then try later */ 72 | if(server_spawn_child(ctx->server, be)) 73 | be->fork_child++; /* increase # of child to spawn when possible */ 74 | 75 | return 0; 76 | err: 77 | return ~0; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /src/kloned/ppc_log_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ppc_log_add.c,v 1.13 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "server_s.h" 20 | 21 | /* struct used for ppc command PPC_CMD_LOG_ADD */ 22 | struct ppc_log_add_s 23 | { 24 | int bid; /* calling backend ID */ 25 | int level; /* log level */ 26 | char log[U_MAX_LOG_LENGTH]; /* log line */ 27 | }; 28 | 29 | typedef struct ppc_log_add_s ppc_log_add_t; 30 | 31 | int syslog_to_klog(int level) 32 | { 33 | static int klog_lev[] = 34 | { 35 | KLOG_EMERG, 36 | KLOG_ALERT, 37 | KLOG_CRIT, 38 | KLOG_ERR, 39 | KLOG_WARNING, 40 | KLOG_NOTICE, 41 | KLOG_INFO, 42 | KLOG_DEBUG 43 | }; 44 | 45 | if(level < LOG_EMERG || level > LOG_DEBUG) 46 | return KLOG_ALERT; 47 | 48 | return klog_lev[level]; 49 | } 50 | 51 | /* client function */ 52 | int server_ppc_cmd_log_add(server_t *s, int level, const char *str) 53 | { 54 | ppc_log_add_t la; 55 | 56 | nop_err_if (s == NULL); 57 | nop_err_if (s->ppc == NULL); 58 | nop_err_if (str == NULL); 59 | 60 | memset(&la, 0, sizeof(ppc_log_add_t)); 61 | 62 | la.bid = ctx->backend->id; 63 | la.level = level; 64 | u_strlcpy(la.log, str, sizeof la.log); 65 | 66 | /* send the command request */ 67 | nop_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_LOG_ADD, (char*)&la, 68 | sizeof(la)) < 0); 69 | 70 | return 0; 71 | err: 72 | return ~0; 73 | } 74 | 75 | /* [parent] log a new message */ 76 | int server_ppc_cb_log_add(ppc_t *ppc, int fd, unsigned char cmd, char *data, 77 | size_t size, void *vso) 78 | { 79 | server_t *s; 80 | ppc_log_add_t *pla; 81 | backend_t *be; 82 | klog_t *kl; 83 | 84 | u_unused_args(ppc, fd, cmd, size); 85 | 86 | nop_err_if (vso == NULL); 87 | nop_err_if (data == NULL); 88 | 89 | pla = (ppc_log_add_t *) data; 90 | s = (server_t *) vso; 91 | 92 | /* by default use server logger */ 93 | kl = s->klog; 94 | 95 | /* get the logger obj of the calling backend (if any) */ 96 | if(!server_get_backend_by_id(s, pla->bid, &be) && be->klog) 97 | kl = be->klog; 98 | 99 | /* log the line */ 100 | if(kl) 101 | nop_err_if(klog(kl, syslog_to_klog(pla->level), "%s", pla->log)); 102 | 103 | return 0; 104 | err: 105 | return ~0; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /src/kloned/ppc_log_get.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ppc_log_get.c,v 1.4 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "server_s.h" 20 | 21 | /* struct used for ppc command PPC_CMD_LOG_GET */ 22 | struct ppc_log_get_s 23 | { 24 | int bid; /* calling backend ID */ 25 | ssize_t i; /* i-th line */ 26 | char line[KLOG_LN_SZ]; /* log line */ 27 | }; 28 | 29 | typedef struct ppc_log_get_s ppc_log_get_t; 30 | 31 | /* client function */ 32 | int server_ppc_cmd_log_get(server_t *s, size_t i, char *line) 33 | { 34 | ppc_log_get_t plg; 35 | unsigned char cmd; 36 | 37 | nop_err_if (s == NULL); 38 | nop_err_if (s->ppc == NULL); 39 | nop_err_if (ctx->backend == NULL); 40 | nop_err_if (line == NULL); 41 | 42 | memset(&plg, 0, sizeof(ppc_log_get_t)); 43 | 44 | plg.bid = ctx->backend->id; 45 | plg.i = i; 46 | plg.line[0] = 0; 47 | 48 | /* send the command request */ 49 | dbg_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_LOG_GET, (char*)&plg, 50 | sizeof(plg)) < 0); 51 | 52 | /* get the response */ 53 | dbg_err_if(ppc_read(s->ppc, ctx->pipc, &cmd, (char*)&plg, sizeof(plg)) < 0); 54 | 55 | dbg_err_if(cmd != PPC_CMD_LOG_GET); 56 | 57 | nop_err_if(plg.i < 0); /* error or eof */ 58 | 59 | /* copy-out the line */ 60 | u_strlcpy(line, plg.line, sizeof line); 61 | 62 | return 0; 63 | err: 64 | return ~0; 65 | } 66 | 67 | /* [parent] get a log line */ 68 | int server_ppc_cb_log_get(ppc_t *ppc, int fd, unsigned char cmd, char *data, 69 | size_t size, void *vso) 70 | { 71 | server_t *s; 72 | ppc_log_get_t *plg; 73 | backend_t *be; 74 | klog_t *kl; 75 | 76 | u_unused_args(ppc, fd, cmd, size); 77 | 78 | dbg_err_if (vso == NULL); 79 | dbg_err_if (data == NULL); 80 | 81 | plg = (ppc_log_get_t *) data; 82 | s = (server_t *) vso; 83 | 84 | /* by default use server logger */ 85 | kl = s->klog; 86 | 87 | /* get the logger obj of the calling backend (if any) */ 88 | if(!server_get_backend_by_id(s, plg->bid, &be) && be->klog) 89 | kl = be->klog; 90 | 91 | /* get the log line */ 92 | if(kl == NULL || klog_getln(kl, plg->i, plg->line)) 93 | plg->i = -1; /* eof or error */ 94 | 95 | /* send back the response */ 96 | nop_err_if(ppc_write(s->ppc, fd, PPC_CMD_LOG_GET, (char*)plg, 97 | sizeof(ppc_log_get_t)) < 0); 98 | 99 | return 0; 100 | err: 101 | return ~0; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /src/kloned/ppc_nop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: ppc_nop.c,v 1.7 2007/11/09 22:06:26 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "server_s.h" 20 | 21 | /* struct used for ppc command PPC_CMD_NOP */ 22 | struct ppc_nop_s 23 | { 24 | int dummy; 25 | }; 26 | 27 | typedef struct ppc_nop_s ppc_nop_t; 28 | 29 | /* client function */ 30 | int server_ppc_cmd_nop(server_t *s) 31 | { 32 | ppc_nop_t nop; 33 | 34 | nop_err_if(s == NULL); 35 | nop_err_if(s->ppc == NULL); 36 | 37 | memset(&nop, 0, sizeof(ppc_nop_t)); 38 | 39 | /* send the command request */ 40 | nop_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_NOP, (char*)&nop, 41 | sizeof(nop)) < 0); 42 | 43 | return 0; 44 | err: 45 | return ~0; 46 | } 47 | 48 | /* [parent] nop op */ 49 | int server_ppc_cb_nop(ppc_t *ppc, int fd, unsigned char cmd, char *data, 50 | size_t size, void *vso) 51 | { 52 | u_unused_args(ppc, fd, cmd, data, size, vso); 53 | 54 | u_dbg("ppc nop cmd callback"); 55 | return 0; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/kloned/server_s.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: server_s.h,v 1.15 2007/06/04 16:30:58 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_SERVER_S_H_ 12 | #define _KLONE_SERVER_S_H_ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #ifdef HAVE_SYS_SELECT 21 | #include 22 | #endif 23 | #include 24 | #include "child.h" 25 | 26 | enum { SERVER_MAX_CHILD_COUNT = 1024 }; 27 | 28 | struct server_s 29 | { 30 | u_config_t *config; /* server config */ 31 | ppc_t *ppc; /* parent procedure call */ 32 | backends_t bes; /* backend list */ 33 | klog_t *klog; /* klog device */ 34 | talarm_t *al_klog_flush;/* klog flush alarm */ 35 | children_t *children; /* children list */ 36 | fd_set rdfds, wrfds, exfds; 37 | const char *chroot; /* server chroot dir */ 38 | int uid, gid; /* uid/gid used to run the server */ 39 | int hfd; /* highest set fd in fd_sets */ 40 | size_t nbackend; /* # of servers */ 41 | size_t nchild; /* # of child (only in prefork mode) */ 42 | size_t max_child; /* max # of children */ 43 | /* int fork_child; *//* # of child to fork when possible */ 44 | int stop; /* >0 will stop the loop */ 45 | int model; /* server model */ 46 | int klog_flush; /* >0 will flush the klog */ 47 | int reap_children; /* >0 will reap children (waitpid) */ 48 | int allow_root; /* >0 allow root as the owner of kloned process */ 49 | int blind_chroot; /* if blind chroot mode is enabled or disabled */ 50 | }; 51 | 52 | int server_get_backend_by_id(server_t *s, int id, backend_t **pbe); 53 | int server_spawn_child(server_t *s, backend_t *be); 54 | int server_cb_klog_flush(talarm_t *a, void *arg); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/libbackend/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.3 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = backend 7 | SRCS = backend.c 8 | 9 | ifdef SSL_ON 10 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 11 | endif 12 | 13 | ifdef INSTALL_DAEMON_ONLY 14 | NO_INSTALL = true 15 | endif 16 | 17 | include lib.mk 18 | -------------------------------------------------------------------------------- /src/libcodec/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.6 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = codec 7 | SRCS = codec.c null.c 8 | 9 | ifdef HAVE_LIBZ 10 | SRCS += gzip.c 11 | endif 12 | 13 | ifdef SSL_ON 14 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 15 | endif 16 | 17 | ifdef SSL_OPENSSL 18 | SRCS += cipher.c 19 | endif 20 | 21 | ifdef SSL_CYASSL 22 | SRCS += cipher_cyassl.c 23 | endif 24 | 25 | ifdef INSTALL_DAEMON_ONLY 26 | NO_INSTALL = true 27 | endif 28 | 29 | include lib.mk 30 | -------------------------------------------------------------------------------- /src/libcodec/codec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: codec.c,v 1.12 2007/10/26 11:21:51 tho Exp $ 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | /** 15 | * \ingroup filters 16 | * \brief Dispose all the resources allocated to the supplied codec 17 | * 18 | * Dispose all the resources allocated to the supplied \p codec 19 | * 20 | * \param codec the \c codec_t object to be disposed 21 | * 22 | * \return always successful, i.e. \c 0 23 | */ 24 | int codec_free(codec_t *codec) 25 | { 26 | if(codec) 27 | { 28 | if(codec->free) 29 | codec->free(codec); 30 | else 31 | U_FREE(codec); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/libcodec/null.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: null.c,v 1.15 2007/10/26 08:57:59 tho Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | struct codec_null_s 19 | { 20 | codec_t codec; 21 | }; 22 | 23 | typedef struct codec_null_s codec_null_t; 24 | 25 | static ssize_t null_flush(codec_t *cn, char *dst, size_t *dcount) 26 | { 27 | u_unused_args(cn, dst); 28 | *dcount = 0; 29 | return CODEC_FLUSH_COMPLETE; 30 | } 31 | 32 | static ssize_t null_transform(codec_t *cn, char *dst, size_t *dcount, 33 | const char *src, size_t src_sz) 34 | { 35 | ssize_t wr; 36 | 37 | dbg_err_if (src == NULL); 38 | dbg_err_if (dst == NULL); 39 | dbg_err_if (dcount == NULL || *dcount == 0); 40 | dbg_err_if (src_sz == 0); 41 | 42 | u_unused_args(cn); 43 | 44 | wr = U_MIN(src_sz, *dcount); 45 | memcpy(dst, src, wr); 46 | *dcount = wr; 47 | 48 | dbg_err_if(wr == 0); 49 | return wr; 50 | err: 51 | return -1; 52 | } 53 | 54 | static int null_free(codec_t *cn) 55 | { 56 | U_FREE(cn); 57 | 58 | return 0; 59 | } 60 | 61 | /** 62 | * \addtogroup filters 63 | * \{ 64 | */ 65 | 66 | /** 67 | * \brief Create a cipher \c codec_t object 68 | * 69 | * Create a null \c codec_t object at \p *pcn. 70 | * 71 | * \param pcn the created codec as a value-result arguement 72 | * 73 | * \return \c 0 on success, \c ~0 otherwise 74 | */ 75 | int codec_null_create(codec_t **pcn) 76 | { 77 | codec_null_t *cn = NULL; 78 | 79 | dbg_return_if (pcn == NULL, ~0); 80 | 81 | cn = u_zalloc(sizeof(codec_null_t)); 82 | dbg_err_if(cn == NULL); 83 | 84 | cn->codec.transform = null_transform; 85 | cn->codec.flush = null_flush; 86 | cn->codec.free = null_free; 87 | 88 | *pcn = (codec_t*)cn; 89 | 90 | return 0; 91 | err: 92 | U_FREE(cn); 93 | return ~0; 94 | } 95 | 96 | /** 97 | * \} 98 | */ 99 | -------------------------------------------------------------------------------- /src/libemb/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.3 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = emb 7 | SRCS = emb.c 8 | 9 | ifdef SSL_ON 10 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 11 | endif 12 | 13 | ifdef INSTALL_DAEMON_ONLY 14 | NO_INSTALL = true 15 | endif 16 | 17 | include lib.mk 18 | -------------------------------------------------------------------------------- /src/libhook/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.1 2007/09/04 12:15:16 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = hook 7 | SRCS = hook.c server_nfy.c child_nfy.c req.c 8 | 9 | ifdef SSL_ON 10 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 11 | endif 12 | 13 | ifdef INSTALL_DAEMON_ONLY 14 | NO_INSTALL = true 15 | endif 16 | 17 | include lib.mk 18 | -------------------------------------------------------------------------------- /src/libhook/child_nfy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * \brief Set a hook to be notified when new children get forked 7 | * 8 | * When the main server forks a child \p func will be called in the child 9 | * context so it'll have the opportunity to initialize any one-per-process 10 | * resources. 11 | * 12 | * Note that a single child can (and probably will) handle more then one HTTP 13 | * connection. 14 | * 15 | * Pass a NULL pointer to disable a previously set hook. 16 | * 17 | * \param func the function pointer 18 | * 19 | * \return 0 on success, not zero on error 20 | */ 21 | int hook_child_init( hook_child_init_t func ) 22 | { 23 | hook_t *hook; 24 | 25 | dbg_err_if(ctx == NULL); 26 | dbg_err_if(ctx->hook == NULL); 27 | 28 | ctx->hook->child_init = func; /* may be NULL */ 29 | 30 | return 0; 31 | err: 32 | return ~0; 33 | } 34 | 35 | /** 36 | * \brief Set a hook to be notified when a child is about to die 37 | * 38 | * This hook executes just before the child dies; you may use it to 39 | * free resources allocated by the hook_child_init hook. 40 | * 41 | * Pass a NULL pointer to disable a previously set hook. 42 | * 43 | * \param func the function pointer 44 | * 45 | * \return 0 on success, not zero on error 46 | */ 47 | int hook_child_term( hook_child_term_t func ) 48 | { 49 | hook_t *hook; 50 | 51 | dbg_err_if(ctx == NULL); 52 | dbg_err_if(ctx->hook == NULL); 53 | 54 | ctx->hook->child_term = func; 55 | 56 | return 0; 57 | err: 58 | return ~0; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/libhook/hook.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int hook_create(hook_t **phook) 7 | { 8 | hook_t *h = NULL; 9 | 10 | dbg_err_if(phook == NULL); 11 | 12 | h = u_zalloc(sizeof(hook_t)); 13 | dbg_err_if(h == NULL); 14 | 15 | *phook = h; 16 | 17 | return 0; 18 | err: 19 | return ~0; 20 | } 21 | 22 | int hook_free(hook_t *hook) 23 | { 24 | dbg_err_if(hook == NULL); 25 | 26 | u_free(hook); 27 | 28 | return 0; 29 | err: 30 | return ~0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/libhook/req.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * \brief Set a hook that executes on every HTTP request 7 | * 8 | * This hook will be executed on every HTTP request; for dynamic pages the hook 9 | * will fire after the execution of the code of the dynamic page. 10 | * 11 | * Pass a NULL pointer to disable a previously set hook. 12 | * 13 | * \param func the function pointer 14 | * 15 | * \return 0 on success, not zero on error 16 | */ 17 | int hook_request( hook_request_t func ) 18 | { 19 | hook_t *hook; 20 | 21 | dbg_err_if(ctx == NULL); 22 | dbg_err_if(ctx->hook == NULL); 23 | 24 | ctx->hook->request = func; /* may be NULL */ 25 | 26 | return 0; 27 | err: 28 | return ~0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/libhook/server_nfy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * \brief Set a hook that executes when on server startup 7 | * 8 | * This hook will be executed just once on server startup. 9 | * 10 | * Pass a NULL pointer to disable a previously set hook. 11 | * 12 | * \param func the function pointer 13 | * 14 | * \return 0 on success, not zero on error 15 | */ 16 | int hook_server_init( hook_server_init_t func ) 17 | { 18 | hook_t *hook; 19 | 20 | dbg_err_if(ctx == NULL); 21 | dbg_err_if(ctx->hook == NULL); 22 | 23 | ctx->hook->server_init = func; /* may be NULL */ 24 | 25 | return 0; 26 | err: 27 | return ~0; 28 | } 29 | 30 | /** 31 | * \brief Set a hook that executes just before quitting the server 32 | * 33 | * This hook is called during the shutdown procedure of the Klone server. 34 | * 35 | * Pass a NULL pointer to disable a previously set hook. 36 | * 37 | * \param func the function pointer 38 | * 39 | * \return 0 on success, not zero on error 40 | */ 41 | int hook_server_term( hook_server_term_t func ) 42 | { 43 | hook_t *hook; 44 | 45 | dbg_err_if(ctx == NULL); 46 | dbg_err_if(ctx->hook == NULL); 47 | 48 | ctx->hook->server_term = func; /* may be NULL */ 49 | 50 | return 0; 51 | err: 52 | return ~0; 53 | } 54 | 55 | /** 56 | * \brief Set a hook that executes at each main loop 57 | * 58 | * This hook is called at each main loop (approx once per second). 59 | * 60 | * Pass a NULL pointer to disable a previously set hook. 61 | * 62 | * \param func the function pointer 63 | * 64 | * \return 0 on success, not zero on error 65 | */ 66 | int hook_server_loop( hook_server_loop_t func ) 67 | { 68 | hook_t *hook; 69 | 70 | dbg_err_if(ctx == NULL); 71 | dbg_err_if(ctx->hook == NULL); 72 | 73 | ctx->hook->server_loop = func; /* may be NULL */ 74 | 75 | return 0; 76 | err: 77 | return ~0; 78 | } 79 | -------------------------------------------------------------------------------- /src/libhttp/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.7 2008/10/27 21:28:04 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = http 7 | SRCS = broker.c cgi.c http.c sup_emb.c access.c vhost.c dypage.c 8 | 9 | ifdef ENABLE_SUP_FS 10 | SRCS += sup_fs.c 11 | endif 12 | 13 | ifdef SSL_ON 14 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 15 | endif 16 | 17 | ifndef OS_WIN 18 | ifdef ENABLE_SUP_CGI 19 | SRCS += sup_cgi.c 20 | endif 21 | endif 22 | 23 | ifdef ENABLE_SUP_KILT 24 | SRCS += sup_kilt.c 25 | endif 26 | 27 | ifdef INSTALL_DAEMON_ONLY 28 | NO_INSTALL = true 29 | endif 30 | 31 | include lib.mk 32 | -------------------------------------------------------------------------------- /src/libhttp/cgi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: cgi.c,v 1.8 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | int cgi_set_request(request_t *rq) 18 | { 19 | char *ev; 20 | 21 | /* clear uri-related request fields */ 22 | request_clear_uri(rq); 23 | 24 | dbg_err_if (rq == NULL); 25 | 26 | /* dbg_err_if(request_set_filename(rq, getenv("SCRIPT_NAME"))); */ 27 | 28 | /* use PATH_INFO as script name i.e. 29 | http://site/cgi-bin/kloned/path/to/script.kl1 */ 30 | if((ev = getenv("PATH_INFO")) != NULL) 31 | dbg_err_if(request_set_filename(rq, ev)); 32 | else 33 | dbg_err_if(request_set_filename(rq, "/")); 34 | 35 | if((ev = getenv("PATH_INFO")) != NULL) 36 | dbg_err_if(request_set_path_info(rq, ev)); 37 | 38 | if((ev = getenv("QUERY_STRING")) != NULL) 39 | dbg_err_if(request_set_query_string(rq, ev)); 40 | 41 | if((ev = getenv("REQUEST_METHOD")) != NULL) 42 | dbg_err_if(request_set_method(rq, ev)); 43 | 44 | if((ev = getenv("CONTENT_TYPE")) != NULL) 45 | dbg_err_if(request_set_field(rq, "Content-Type", ev)); 46 | 47 | if((ev = getenv("CONTENT_LENGTH")) != NULL) 48 | dbg_err_if(request_set_field(rq, "Content-Length", ev)); 49 | 50 | return 0; 51 | err: 52 | return ~0; 53 | } 54 | -------------------------------------------------------------------------------- /src/libhttp/dypage.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | const char *dypage_get_param(dypage_args_t *args, const char *key) 7 | { 8 | int i; 9 | 10 | for(i = 0; i < args->nparams; ++i) 11 | if(strcmp(key, args->params[i].key) == 0) 12 | return args->params[i].val; 13 | 14 | return ""; 15 | } 16 | 17 | int dypage_serve(dypage_args_t *args) 18 | { 19 | http_t *http = NULL; 20 | codec_t *filter = NULL; 21 | session_opt_t *so; 22 | request_t *rq; 23 | response_t *rs; 24 | session_t *ss; 25 | io_t *oio; 26 | 27 | dbg_return_if(args == NULL, ~0); 28 | 29 | dbg_return_if(args->rq == NULL, ~0); 30 | dbg_return_if(args->rs == NULL, ~0); 31 | dbg_return_if(args->fun == NULL, ~0); 32 | 33 | /* alias */ 34 | rq = args->rq; 35 | rs = args->rs; 36 | 37 | /* output io object */ 38 | oio = response_io(rs); 39 | 40 | /* get session options */ 41 | dbg_err_if((http = request_get_http(rq)) == NULL); 42 | dbg_err_if((so = http_get_session_opt(http)) == NULL); 43 | 44 | /* parse URL encoded or POSTed data (POST must be read before) */ 45 | dbg_err_if(request_parse_data(rq)); 46 | 47 | /* create/get the session */ 48 | dbg_err_if(session_create(so, rq, rs, &args->ss)); 49 | 50 | /* alias */ 51 | ss = args->ss; 52 | 53 | /* set some default values */ 54 | dbg_err_if(response_set_content_type(rs, "text/html")); 55 | 56 | /* by default disable caching */ 57 | response_disable_caching(rs); 58 | 59 | /* create a response filter (used to automatically print all header fields 60 | * when the header buffer fills up) and attach it to the response io */ 61 | dbg_err_if(response_filter_create(rq, rs, ss, &filter)); 62 | io_codec_add_tail(oio, filter); 63 | 64 | /* run the page code */ 65 | args->fun(args); 66 | 67 | /* flush the output buffer */ 68 | io_flush(oio); 69 | 70 | /* if nothing has been printed by the script then write a dummy byte so 71 | * the io_t calls the filter function that, in turn, will print out the 72 | * HTTP header (rsfilter will handle it) */ 73 | if(!response_filter_feeded(filter)) 74 | io_write(oio, "\n", 1); 75 | 76 | /* save and destroy the session */ 77 | session_free(ss); args->ss = ss = NULL; 78 | 79 | return 0; 80 | err: 81 | if(args->rs) 82 | io_flush(response_io(args->rs)); 83 | if(args->ss) 84 | { 85 | session_free(args->ss); 86 | args->ss = NULL; 87 | } 88 | return ~0; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /src/libhttp/http_s.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: http_s.h,v 1.8 2007/11/09 01:30:45 tat Exp $ 9 | */ 10 | 11 | #ifndef _KLONE_HTTP_S_H_ 12 | #define _KLONE_HTTP_S_H_ 13 | #include "klone_conf.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef SSL_ON 20 | #include 21 | #include 22 | #endif 23 | 24 | struct http_s 25 | { 26 | u_config_t *config; /* server config */ 27 | broker_t *broker; /* pages broker */ 28 | int ssl; /* >0 when SSL is enabled */ 29 | #ifdef SSL_ON 30 | SSL_CTX* ssl_ctx; /* OpenSSL context */ 31 | #endif 32 | /* session options struct */ 33 | session_opt_t *sess_opt; 34 | vhost_list_t *vhosts; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/libhttp/sup_fs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: sup_fs.c,v 1.14 2008/10/27 21:28:04 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | static int fs_is_valid_uri(http_t *h, request_t *rq, const char *uri, 21 | size_t len, void **handle, time_t *mtime) 22 | { 23 | struct stat st; 24 | char fqn[U_FILENAME_MAX]; 25 | 26 | dbg_return_if (uri == NULL, 0); 27 | dbg_return_if (mtime == NULL, 0); 28 | dbg_return_if (len + 1 > U_FILENAME_MAX, 0); 29 | 30 | u_unused_args(h); 31 | 32 | memcpy(fqn, uri, len); 33 | fqn[len] = '\0'; 34 | 35 | /* fqn must be already normalized */ 36 | if(strstr(fqn, "..")) 37 | return 0; 38 | 39 | if(stat(fqn, &st) == 0 && S_ISREG(st.st_mode)) 40 | { 41 | *mtime = st.st_mtime; 42 | *handle = NULL; 43 | 44 | return 1; 45 | } else 46 | return 0; 47 | } 48 | 49 | static int fs_serve(request_t *rq, response_t *rs) 50 | { 51 | enum { BUFSZ = 4096 }; 52 | io_t *io = NULL, *out = NULL; 53 | const char *mime_type, *fqn; 54 | size_t c; 55 | char buf[BUFSZ]; 56 | struct stat st; 57 | 58 | dbg_err_if (rq == NULL); 59 | dbg_err_if (rs == NULL); 60 | 61 | /* output stream */ 62 | out = response_io(rs); 63 | dbg_err_if(out == NULL); 64 | 65 | fqn = request_get_resolved_filename(rq); 66 | 67 | /* we need file size */ 68 | dbg_err_if(stat(fqn, &st)); 69 | dbg_err_if(response_set_content_length(rs, st.st_size)); 70 | 71 | /* guess the mime type append a Content-Type field to the response*/ 72 | mime_type = u_guess_mime_type(fqn); 73 | dbg_err_if(response_set_content_type(rs, mime_type)); 74 | 75 | /* add a Last-Modified field */ 76 | dbg_err_if(response_set_last_modified(rs, st.st_mtime)); 77 | 78 | /* print the reponse header */ 79 | dbg_err_if(response_print_header_to_io(rs, out)); 80 | 81 | /* if this's a HEAD request don't print the file content */ 82 | if(response_get_method(rs) == HM_HEAD) 83 | return 0; 84 | 85 | /* open and write out the whole file */ 86 | dbg_err_if(u_file_open(request_get_resolved_filename(rq), O_RDONLY, &io)); 87 | 88 | while((c = io_read(io, buf, BUFSZ)) > 0) 89 | dbg_err_if(io_write(out, buf, c) < 0); 90 | 91 | io_free(io); 92 | 93 | return 0; 94 | err: 95 | if(io) 96 | io_free(io); 97 | return ~0; 98 | } 99 | 100 | static int fs_init(void) 101 | { 102 | return 0; 103 | } 104 | 105 | static void fs_term(void) 106 | { 107 | return; 108 | } 109 | 110 | supplier_t sup_fs = { 111 | "fs supplier", 112 | fs_init, 113 | fs_term, 114 | fs_is_valid_uri, 115 | fs_serve 116 | }; 117 | 118 | -------------------------------------------------------------------------------- /src/libhttp/vhost.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int vhost_create(vhost_t **pv) 4 | { 5 | vhost_t *v = NULL; 6 | 7 | dbg_err_if(pv == NULL); 8 | 9 | v = u_zalloc(sizeof(vhost_t)); 10 | dbg_err_if(v == NULL); 11 | 12 | *pv = v; 13 | 14 | return 0; 15 | err: 16 | return ~0; 17 | 18 | } 19 | 20 | int vhost_free(vhost_t *v) 21 | { 22 | dbg_err_if(v == NULL); 23 | 24 | u_free(v); 25 | 26 | return 0; 27 | err: 28 | return ~0; 29 | } 30 | 31 | /* insert the element at the tail of the list */ 32 | int vhost_list_add(vhost_list_t *vs, vhost_t *vhost) 33 | { 34 | vhost_t *first, *last, *elm; 35 | 36 | last = NULL; 37 | LIST_FOREACH(elm, vs, np) 38 | last = elm; 39 | 40 | if(last) 41 | { 42 | LIST_INSERT_AFTER(last, vhost, np); 43 | vhost->id = last->id + 1; 44 | } else { 45 | LIST_INSERT_HEAD(vs, vhost, np); 46 | vhost->id = 0; 47 | } 48 | 49 | return 0; 50 | err: 51 | return ~0; 52 | } 53 | 54 | vhost_t* vhost_list_get(vhost_list_t *vs, const char *host) 55 | { 56 | vhost_t *item; 57 | 58 | LIST_FOREACH(item, vs, np) 59 | { 60 | if(strcmp(item->host, host) == 0) 61 | return item; /* found */ 62 | } 63 | 64 | return NULL; /* not found */ 65 | } 66 | 67 | vhost_t* vhost_list_get_n(vhost_list_t *vs, int n) 68 | { 69 | vhost_t *item; 70 | 71 | LIST_FOREACH(item, vs, np) 72 | { 73 | if(n-- == 0) 74 | return item; 75 | } 76 | 77 | return NULL; /* not found */ 78 | } 79 | 80 | int vhost_list_create(vhost_list_t **pvs) 81 | { 82 | vhost_list_t *vs = NULL; 83 | 84 | dbg_err_if(pvs == NULL); 85 | 86 | vs = u_zalloc(sizeof(vhost_list_t)); 87 | dbg_err_if(vs == NULL); 88 | 89 | LIST_INIT(vs); 90 | 91 | *pvs = vs; 92 | 93 | return 0; 94 | err: 95 | if(pvs) 96 | u_free(pvs); 97 | return ~0; 98 | } 99 | 100 | int vhost_list_free(vhost_list_t *vs) 101 | { 102 | dbg_err_if(vs == NULL); 103 | 104 | u_free(vs); 105 | 106 | return 0; 107 | err: 108 | return ~0; 109 | } 110 | 111 | -------------------------------------------------------------------------------- /src/libio/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.6 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = io 7 | SRCS = io.c iofd.c iomem.c 8 | 9 | ifdef SSL_ON 10 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 11 | SRCS += iossl.c 12 | endif 13 | 14 | ifdef INSTALL_DAEMON_ONLY 15 | NO_INSTALL = true 16 | endif 17 | 18 | include lib.mk 19 | -------------------------------------------------------------------------------- /src/libklog/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.6 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = klog 7 | SRCS = klog.c mem.c file.c common.c 8 | 9 | ifdef HAVE_SYSLOG 10 | SRCS += syslog.c 11 | endif 12 | 13 | ifdef INSTALL_DAEMON_ONLY 14 | NO_INSTALL = true 15 | endif 16 | 17 | include lib.mk 18 | -------------------------------------------------------------------------------- /src/libklog/NOTES: -------------------------------------------------------------------------------- 1 | 2 | log 3 | { 4 | type mem|file|syslog # the obvious 5 | 6 | ident # id string in log msgs 7 | threshold DEBUG, ..., EMERG # min unfiltered log level 8 | 9 | # mem ONLY 10 | mem.limit 123 # log msgs window size 11 | 12 | # 'file' ONLY 13 | file.basename # log files basename 14 | file.limit 123 # max number of msgs in each f 15 | file.splits 456 # number of log files 16 | 17 | # 'syslog' ONLY 18 | syslog.facility LOG_LOCAL[0-7] # default facility for log msgs 19 | syslog.options LOG_{CONS, ..., PID} # multivalue directive 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/libklog/common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: common.c,v 1.6 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /* each klog_*_open() will push its private data afterwards */ 18 | int klog_new (int type, int threshold, const char *ident, klog_t **pkl) 19 | { 20 | klog_t *kl; 21 | 22 | dbg_return_if (pkl == NULL, ~0); 23 | 24 | kl = u_zalloc(sizeof(klog_t)); 25 | dbg_err_if (kl == NULL); 26 | 27 | kl->threshold = threshold; 28 | u_strlcpy(kl->ident, ident ? ident : "", sizeof kl->ident); 29 | 30 | /* check the supplied type */ 31 | switch (type) 32 | { 33 | case KLOG_TYPE_MEM: 34 | case KLOG_TYPE_FILE: 35 | case KLOG_TYPE_SYSLOG: 36 | kl->type = type; 37 | break; 38 | default: 39 | warn_err("bad klog_t type !"); 40 | } 41 | 42 | /* push out the klog_t object */ 43 | *pkl = kl; 44 | 45 | return 0; 46 | err: 47 | U_FREE(kl); 48 | return ~0; 49 | } 50 | 51 | const char *klog_to_str (int lev) 52 | { 53 | return (lev < KLOG_DEBUG || lev > KLOG_EMERG) ? "?" : kloglev[lev]; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/libklog/syslog.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: syslog.c,v 1.7 2006/01/09 12:38:38 tat Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | static int klog_to_syslog (int lev); 18 | static void klog_free_syslog (klog_syslog_t *kls); 19 | 20 | static int klog_syslog (klog_t *kl, int level, const char *fmt, va_list ap); 21 | static void klog_close_syslog (klog_t *kl); 22 | 23 | /* must be ordered */ 24 | static int sysloglev[] = 25 | { 26 | LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, 27 | LOG_ERR, LOG_CRIT, LOG_ALERT, LOG_EMERG 28 | }; 29 | 30 | /* we've a problem here because syslog(3) mantains a global context, and 31 | * we can't bind some syslog state specific to the supplied klog_t object. 32 | * instead we are forced to do openlog->vsyslog->closelog for each logged 33 | * message which is rather silly ... anyway this should be not so heavy as 34 | * it seems: in fact (a) the underlying transport is connectionless (UDP) 35 | * and (b) most of the time is spent inside the vsyslog call. */ 36 | int klog_open_syslog (klog_t *kl, int fac, int logopt) 37 | { 38 | klog_syslog_t *kls = NULL; 39 | 40 | dbg_return_if (kl == NULL, ~0); 41 | 42 | kls = u_zalloc(sizeof(klog_syslog_t)); 43 | dbg_err_if (kls == NULL); 44 | 45 | kls->facility = fac; 46 | kls->logopt = logopt; 47 | 48 | /* set private methods */ 49 | kl->cb_log = klog_syslog; 50 | kl->cb_close = klog_close_syslog; 51 | kl->cb_getln = NULL; 52 | kl->cb_countln = NULL; 53 | kl->cb_clear = NULL; 54 | kl->cb_flush = NULL; 55 | 56 | /* stick child to its parent */ 57 | kl->u.s = kls, kls = NULL; 58 | 59 | return 0; 60 | err: 61 | if (kls) 62 | klog_free_syslog(kls); 63 | return ~0; 64 | } 65 | 66 | static void klog_close_syslog (klog_t *kl) 67 | { 68 | if (kl == NULL || kl->type != KLOG_TYPE_SYSLOG || kl->u.s == NULL) 69 | return; 70 | 71 | klog_free_syslog(kl->u.s), kl->u.s = NULL; 72 | 73 | return; 74 | } 75 | 76 | static void klog_free_syslog (klog_syslog_t *kls) 77 | { 78 | if (kls == NULL) 79 | return; 80 | U_FREE(kls); 81 | return; 82 | } 83 | 84 | static int klog_syslog (klog_t *kl, int level, const char *fmt, va_list ap) 85 | { 86 | dbg_return_if (kl == NULL, ~0); 87 | dbg_return_if (kl->type != KLOG_TYPE_SYSLOG, ~0); 88 | dbg_return_if (kl->u.s == NULL, ~0); 89 | dbg_return_if (fmt == NULL, ~0); 90 | 91 | #ifdef HAVE_SYSLOG 92 | openlog(kl->ident, kl->u.s->logopt, kl->u.s->facility); 93 | vsyslog(klog_to_syslog(level), fmt, ap); 94 | closelog(); 95 | #else 96 | vsyslog(kl->u.s->facility | klog_to_syslog(level), fmt, ap); 97 | #endif /* HAVE_SYSLOG */ 98 | 99 | return 0; 100 | } 101 | 102 | static int klog_to_syslog (int lev) 103 | { 104 | return (lev < KLOG_DEBUG || lev > KLOG_EMERG) ? -1 : sysloglev[lev]; 105 | } 106 | -------------------------------------------------------------------------------- /src/libklog/test/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.5 2007/10/30 17:25:37 tat Exp $ 2 | 3 | include common.mk 4 | include ../../../Makefile.conf 5 | 6 | PROG = test 7 | SRCS = main.c 8 | 9 | CFLAGS += -g 10 | CFLAGS += ${SSL_CFLAGS} ${LIBZ_CFLAGS} 11 | LDFLAGS += ${SSL_LDFLAGS} ${LIBZ_LDFLAGS} 12 | LDFLAGS += ../../../libu/srcs/libu.a 13 | 14 | LDADD += ../libklog.a \ 15 | ../../libtrans/libtrans.a \ 16 | ../../libio/libio.a \ 17 | ../../libcodec/libcodec.a \ 18 | ../../libpage/libpage.a \ 19 | ../../libutils/libutils.a \ 20 | ../../libemb/libemb.a \ 21 | ../../libtls/libtls.a \ 22 | ../../libhttp/libhttp.a \ 23 | ../../../site/libsite.a 24 | 25 | include prog.mk 26 | -------------------------------------------------------------------------------- /src/libklog/test/log.conf: -------------------------------------------------------------------------------- 1 | log 2 | { 3 | type memory 4 | ident mlog 5 | threshold err 6 | 7 | memory 8 | { 9 | limit 10 10 | } 11 | 12 | file 13 | { 14 | basename /Users/tho/work/KL/klone/src/libklog/test/testlog 15 | limit 1 16 | splits 5 17 | } 18 | 19 | syslog 20 | { 21 | facility LOG_LOCAL7 22 | options LOG_PERROR LOG_PID LOG_NDELAY 23 | } 24 | } 25 | 26 | 27 | # log 28 | # { 29 | # type mem|file|syslog # the obvious 30 | # 31 | # ident # id string in log msgs 32 | # threshold DEBUG, ..., EMERG # min unfiltered log level 33 | # 34 | # # mem ONLY 35 | # mem.limit 123 # log msgs window size 36 | # 37 | # # 'file' ONLY 38 | # file.basename # log files basename 39 | # file.limit 123 # max number of msgs in each f 40 | # file.splits 456 # number of log files 41 | # 42 | # # 'syslog' ONLY 43 | # syslog.facility LOG_LOCAL[0-7] # default facility for log msgs 44 | # syslog.options LOG_{CONS, ..., PID} # multivalue directive 45 | # } 46 | 47 | -------------------------------------------------------------------------------- /src/libpage/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.7 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = page 7 | SRCS = \ 8 | field.c \ 9 | header.c \ 10 | request.c \ 11 | response.c \ 12 | rsfilter.c \ 13 | ses_file.c \ 14 | ses_mem.c \ 15 | session.c \ 16 | var.c \ 17 | vars.c 18 | 19 | ifdef SSL_ON 20 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 21 | SRCS += ses_client.c 22 | endif 23 | 24 | ifdef INSTALL_DAEMON_ONLY 25 | NO_INSTALL = true 26 | endif 27 | 28 | include lib.mk 29 | -------------------------------------------------------------------------------- /src/libtls/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.10 2008/03/18 17:28:02 tho Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = tls 7 | CFLAGS += $(SSL_CFLAGS) 8 | 9 | ifdef SSL_CYASSL 10 | SRCS = tls.c cyassl.c 11 | endif 12 | 13 | ifdef SSL_OPENSSL 14 | SRCS = tls_glue.c tls.c tls_dh_autogen.c 15 | endif 16 | 17 | ifdef SSL_OPENSSL_PSK 18 | SRCS += tls_psk.c 19 | endif 20 | 21 | ifdef INSTALL_DAEMON_ONLY 22 | NO_INSTALL = true 23 | endif 24 | 25 | include lib.mk 26 | 27 | #tls_dh_autogen.c: 28 | # echo "#include "klone_conf.h"" > $@ 29 | # echo "#ifdef SSL_OPENSSL" >> $@ 30 | # openssl dhparam 1024 -C -noout >> $@ 31 | # echo "#endif" >> $@ 32 | -------------------------------------------------------------------------------- /src/libtls/TODO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koanlogic/klone/bfa77f491b837278ace8efaab84bef880fc9b225/src/libtls/TODO -------------------------------------------------------------------------------- /src/libtls/tls-server.conf: -------------------------------------------------------------------------------- 1 | # 2 | # Example configuration file for HTTPS backend 3 | # 4 | 5 | # A generic HTTPS backend named "abc" 6 | server.list abc 7 | 8 | # Generic parameters 9 | server.abc.type https 10 | server.abc.addr tcp4://*:4443 11 | server.abc.dir_root /www 12 | server.abc.server_sig KL Secure Web Server 13 | 14 | # SSL stuff specific to https 15 | server.abc.cert_file /etc/ssl/server_cert.pem 16 | server.abc.key_file /etc/ssl/server_key.pem 17 | server.abc.certchain_file /etc/ssl/ca_bundle_server.pem 18 | server.abc.ca_file /etc/ssl/ca_bundle_client.pem 19 | server.abc.dh_file /etc/ssl/dh_params.pem 20 | # Self-signed or one step from a root CA 21 | server.abc.verify_depth 1 22 | # Need client certificate to complete handshake 23 | server.abc.verify_mode require 24 | -------------------------------------------------------------------------------- /src/libtls/tls_dh_autogen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: tls_dh_autogen.c,v 1.7 2008/03/18 17:28:02 tho Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #ifdef SSL_OPENSSL 13 | #ifndef HEADER_DH_H 14 | #include 15 | #endif 16 | DH *get_dh1024(void) 17 | { 18 | static unsigned char dh1024_p[]={ 19 | 0xF0,0xE6,0xAB,0x96,0x17,0xC4,0xDF,0xD7,0x87,0x46,0x7D,0x66, 20 | 0xF3,0xA3,0x54,0x4E,0x70,0x38,0xBB,0x8D,0x05,0x89,0x4B,0xF7, 21 | 0x51,0x0E,0x22,0x60,0xB0,0x02,0xA3,0x32,0xF4,0xFF,0xE4,0x0D, 22 | 0x4E,0x6C,0xF9,0xD1,0x0B,0x93,0xEC,0x2E,0x07,0x46,0x17,0x9C, 23 | 0xE3,0x3D,0x5F,0x18,0x6F,0xF0,0x06,0x5F,0x65,0xFD,0x96,0xD0, 24 | 0x6C,0xC3,0xF3,0xAA,0xC3,0xFD,0x9E,0x77,0xEC,0x08,0xD8,0x48, 25 | 0x43,0x14,0xC8,0xA1,0x4D,0xBF,0xAE,0xA7,0x10,0xA5,0xDB,0x3A, 26 | 0x5E,0xA9,0xDF,0xC6,0xBE,0x34,0x79,0x10,0x78,0xE5,0xD6,0xE0, 27 | 0xDB,0x92,0x8C,0x09,0x44,0x8B,0x6A,0x5B,0xF7,0xF7,0x7F,0x5E, 28 | 0x1A,0xE0,0xDB,0x77,0x91,0x8B,0x39,0x95,0xFC,0xDE,0xAE,0x2E, 29 | 0x2A,0x0F,0x2D,0x3D,0xEA,0x47,0x4E,0x63, 30 | }; 31 | static unsigned char dh1024_g[]={ 32 | 0x02, 33 | }; 34 | DH *dh; 35 | 36 | if ((dh=DH_new()) == NULL) return(NULL); 37 | dh->p=BN_bin2bn(dh1024_p,sizeof(dh1024_p),NULL); 38 | dh->g=BN_bin2bn(dh1024_g,sizeof(dh1024_g),NULL); 39 | if ((dh->p == NULL) || (dh->g == NULL)) 40 | { DH_free(dh); return(NULL); } 41 | return(dh); 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /src/libtls/tls_psk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: tls_psk.c,v 1.6 2008/03/26 09:02:24 tho Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #ifndef SSL_OPENSSL_PSK 18 | int tls_psk_dummy_decl_stub = 0; 19 | #else /* SSL_OPENSSL_PSK */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | static unsigned int psk_cb (SSL *ssl, const char *id, unsigned char *psk, 27 | unsigned int max_psk_len); 28 | 29 | static int __pwd_exdata_idx (void); 30 | 31 | int tls_psk_init (SSL_CTX *c, tls_ctx_args_t *cargs) 32 | { 33 | int rc; 34 | u_pwd_t *pwd = NULL; 35 | 36 | /* create pwd instance */ 37 | rc = u_pwd_init_agnostic(cargs->pskdb, cargs->psk_is_hashed, 0, &pwd); 38 | dbg_err_ifm (rc, "psk pwd creation failed (%s)", cargs->pskdb); 39 | 40 | /* stick the pwd handler into the SSL context */ 41 | SSL_CTX_set_ex_data(c, __pwd_exdata_idx(), pwd); 42 | 43 | /* set psk callback */ 44 | SSL_CTX_set_psk_server_callback(c, psk_cb); 45 | 46 | /* set global hint if provided */ 47 | if (cargs->psk_hint) 48 | dbg_err_if (!SSL_CTX_use_psk_identity_hint(c, cargs->psk_hint)); 49 | 50 | return 0; 51 | err: 52 | if (pwd) 53 | u_pwd_term(pwd); 54 | 55 | return ~0; 56 | } 57 | 58 | static unsigned int psk_cb (SSL *ssl, const char *id, unsigned char *psk, 59 | unsigned int max_psk_len) 60 | { 61 | SSL_CTX *ctx; 62 | u_pwd_t *pwd = NULL; 63 | u_pwd_rec_t *pwd_rec = NULL; 64 | int psk_len = 0; 65 | const char *__psk, *psk_hint; 66 | BIGNUM *bn = NULL; 67 | 68 | /* retrieve pwd handler that we previously cached in SSL_CTX's ex_data */ 69 | ctx = SSL_get_SSL_CTX(ssl); 70 | pwd = (u_pwd_t *) SSL_CTX_get_ex_data(ctx, __pwd_exdata_idx()); 71 | dbg_err_if (pwd == NULL); 72 | 73 | /* get a pwd record for the supplied id */ 74 | dbg_err_if (u_pwd_retr(pwd, id, &pwd_rec)); 75 | dbg_err_if ((__psk = u_pwd_rec_get_password(pwd_rec)) == NULL); 76 | /* .opaque field is used to store the optional per-user hint string */ 77 | if ((psk_hint = u_pwd_rec_get_opaque(pwd_rec))) 78 | dbg_err_if (!SSL_use_psk_identity_hint(ssl, psk_hint)); 79 | 80 | /* do the requested psk conversion */ 81 | dbg_err_if (!BN_hex2bn(&bn, __psk)); 82 | dbg_err_if ((unsigned int) BN_num_bytes(bn) > max_psk_len); 83 | dbg_err_if ((psk_len = BN_bn2bin(bn, psk)) < 0); 84 | 85 | /* dispose temp stuff */ 86 | BN_free(bn); 87 | u_pwd_rec_free(pwd, pwd_rec); 88 | 89 | return psk_len; 90 | err: 91 | if (bn) 92 | BN_free(bn); 93 | 94 | /* if we've (pwd_rec != NULL) we also have (pwd != NULL) */ 95 | if (pwd_rec) 96 | u_pwd_rec_free(pwd, pwd_rec); 97 | 98 | return 0; 99 | } 100 | 101 | static int __pwd_exdata_idx (void) 102 | { 103 | char tag[32]; 104 | static int idx = -1; 105 | 106 | if (idx < 0) 107 | { 108 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); 109 | (void) u_strlcpy(tag, "PSK pwd instance", sizeof tag); 110 | idx = SSL_CTX_get_ex_new_index(0, tag, NULL, NULL, NULL); 111 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); 112 | } 113 | 114 | return idx; 115 | } 116 | 117 | #endif /* SSL_OPENSSL_PSK */ 118 | -------------------------------------------------------------------------------- /src/libtrans/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.3 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = trans 7 | SRCS = parser.c trans_c.c translat.c 8 | 9 | ifdef SSL_ON 10 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 11 | endif 12 | 13 | ifdef INSTALL_DAEMON_ONLY 14 | NO_INSTALL = true 15 | endif 16 | 17 | include lib.mk 18 | -------------------------------------------------------------------------------- /src/libutils/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.7 2008/03/18 17:28:02 tho Exp $ 2 | 3 | include common.mk 4 | include ../../Makefile.conf 5 | 6 | LIB = utils 7 | SRCS = utils.c md5.c mime_map.c timer.c date.c version.c path.c pwd.c 8 | 9 | ifdef SSL_ON 10 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 11 | endif 12 | 13 | ifdef INSTALL_DAEMON_ONLY 14 | NO_INSTALL = true 15 | endif 16 | 17 | include lib.mk 18 | -------------------------------------------------------------------------------- /src/libutils/pwd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: pwd.c,v 1.3 2008/03/20 14:43:15 tho Exp $ 9 | */ 10 | 11 | #include "klone_conf.h" 12 | #include 13 | #include 14 | #include 15 | 16 | static int __emb_open (const char *fqn, void **pio); 17 | static char *__emb_load (char *str, int size, void *io); 18 | static void __emb_close (void *io); 19 | static int u_pwd_init_embfs (const char *fqn, u_pwd_hash_cb_t cb_hash, 20 | size_t hash_len, int in_memory, u_pwd_t **ppwd); 21 | 22 | /** 23 | * \brief Create a pwd instance from a master password db stored at \p fqn 24 | * 25 | * \param fqn path name of the master password db (will be searched 26 | * in embfs and then in the file system 27 | * \param hashed boolean to tell if passwords are hashed or cleartext 28 | * \param in_memory boolean to tell if a copy of the password db is also 29 | * kept in memory as an hash map (meaningful only for 30 | * on-disk password db's) 31 | * \param ppwd pwd instance as a result argument 32 | * 33 | * \return \c 0 on success, \c ~0 on error 34 | */ 35 | int u_pwd_init_agnostic (const char *fqn, int hashed, int in_memory, 36 | u_pwd_t **ppwd) 37 | { 38 | int where; 39 | u_pwd_hash_cb_t hfn = NULL; 40 | size_t hlen = 0; 41 | 42 | dbg_return_if (fqn == NULL, ~0); 43 | dbg_return_if (ppwd == NULL, ~0); 44 | 45 | dbg_err_if (u_path_where_art_thou(fqn, &where)); 46 | 47 | if (hashed) 48 | { 49 | hfn = u_md5; 50 | hlen = MD5_DIGEST_BUFSZ; 51 | } 52 | 53 | switch (where) 54 | { 55 | case U_PATH_IN_EMBFS: 56 | return u_pwd_init_embfs(fqn, hfn, hlen, in_memory, ppwd); 57 | case U_PATH_IN_FS: 58 | return u_pwd_init_file(fqn, hfn, hlen, in_memory, ppwd); 59 | default: 60 | dbg_err("%s: resource not found !", fqn); 61 | } 62 | 63 | /* not reached */ 64 | 65 | err: 66 | return ~0; 67 | } 68 | 69 | static int __emb_open (const char *fqn, void **pio) 70 | { 71 | io_t *io = NULL; 72 | 73 | dbg_err_if (emb_open(fqn, &io)); 74 | 75 | *pio = (void *) io; 76 | 77 | return 0; 78 | err: 79 | return ~0; 80 | } 81 | 82 | static void __emb_close (void *io) 83 | { 84 | dbg_if (io_close((io_t *) io)); 85 | return; 86 | } 87 | 88 | static char *__emb_load (char *str, int size, void *io) 89 | { 90 | dbg_err_if (io_gets((io_t *) io, str, size) <= 0); 91 | 92 | return str; 93 | err: 94 | return NULL; 95 | } 96 | 97 | static int u_pwd_init_embfs (const char *fqn, u_pwd_hash_cb_t cb_hash, 98 | size_t hash_len, int in_memory, u_pwd_t **ppwd) 99 | { 100 | return u_pwd_init(fqn, __emb_open, __emb_load, __emb_close, NULL, 101 | cb_hash, hash_len, in_memory, ppwd); 102 | } 103 | -------------------------------------------------------------------------------- /src/libutils/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2012 by KoanLogic s.r.l. 3 | * All rights reserved. 4 | * 5 | * This file is part of KLone, and as such it is subject to the license stated 6 | * in the LICENSE file which you have received as part of this distribution. 7 | * 8 | * $Id: version.c,v 1.7 2007/10/26 08:57:59 tho Exp $ 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /** 18 | * \addtogroup ut 19 | * \{ 20 | * \par 21 | */ 22 | 23 | /** 24 | * \brief Return KLone version string (x.y.z) 25 | * 26 | * Return KLone version string in the format x.y.z. 27 | * 28 | * \return the version string 29 | */ 30 | const char *klone_version(void) 31 | { 32 | return KLONE_VERSION; 33 | } 34 | 35 | /** 36 | * \} 37 | */ 38 | -------------------------------------------------------------------------------- /src/tools/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.2 2005/09/29 10:25:56 tat Exp $ 2 | 3 | SUBDIR = klone 4 | 5 | include subdir.mk 6 | -------------------------------------------------------------------------------- /src/tools/klone/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.21 2007/10/30 17:25:37 tat Exp $ 2 | 3 | include common.mk 4 | include ../../../Makefile.conf 5 | 6 | PROG = klone 7 | SRCS = main.c pm.c 8 | 9 | ifdef INSTALL_DAEMON_ONLY 10 | NO_INSTALL = true 11 | endif 12 | 13 | CFLAGS += ${SSL_CFLAGS} ${LIBZ_CFLAGS} 14 | LDFLAGS += ${SSL_LDFLAGS} ${LIBZ_LDFLAGS} 15 | 16 | LDADD += ../../libtrans/libtrans.a \ 17 | ../../libcodec/libcodec.a \ 18 | ../../libutils/libutils.a \ 19 | ../../libio/libio.a \ 20 | ../../libcodec/libcodec.a 21 | 22 | LDADD += ../../../libu/srcs/libu.a 23 | 24 | 25 | include prog.mk 26 | -------------------------------------------------------------------------------- /src/tools/klone/pm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pm.h" 3 | 4 | TAILQ_HEAD(pm_list_s, pm_s); 5 | typedef struct pm_list_s pm_list_t; 6 | 7 | /* this struct actually holds a tree but we use it as a plain linked list */ 8 | struct pm_s 9 | { 10 | TAILQ_ENTRY(pm_s) np; /* next & prev pointers */ 11 | char *pattern; 12 | 13 | pm_list_t list; 14 | }; 15 | 16 | int pm_free(pm_t *pm) 17 | { 18 | pm_t *item; 19 | 20 | dbg_err_if(pm == NULL); 21 | 22 | while((item = TAILQ_FIRST(&pm->list)) != NULL) 23 | { 24 | TAILQ_REMOVE(&pm->list, item, np); 25 | pm_free(item); 26 | 27 | } 28 | if(pm->pattern) 29 | U_FREE(pm->pattern); 30 | 31 | U_FREE(pm); 32 | 33 | return 0; 34 | err: 35 | return ~0; 36 | } 37 | 38 | 39 | int pm_create(pm_t **ppm) 40 | { 41 | pm_t *pm = NULL; 42 | 43 | dbg_err_if(ppm == NULL); 44 | 45 | pm = u_zalloc(sizeof(pm_t)); 46 | dbg_err_if(pm == NULL); 47 | 48 | TAILQ_INIT(&pm->list); 49 | 50 | *ppm = pm; 51 | 52 | return 0; 53 | err: 54 | return ~0; 55 | } 56 | 57 | int pm_add(pm_t *pm, const char *pattern) 58 | { 59 | pm_t *item = NULL; 60 | 61 | dbg_err_if(pm == NULL); 62 | dbg_err_if(pattern == NULL); 63 | 64 | dbg_err_if(pm_create(&item)); 65 | 66 | item->pattern = u_strdup(pattern); 67 | dbg_err_if(item->pattern == NULL); 68 | 69 | TAILQ_INSERT_TAIL(&pm->list, item, np); 70 | 71 | return 0; 72 | err: 73 | if(item) 74 | pm_free(item); 75 | return ~0; 76 | } 77 | 78 | int pm_remove(pm_t *pm, const char *pattern) 79 | { 80 | pm_t *item; 81 | 82 | dbg_err_if(pm == NULL); 83 | dbg_err_if(pattern == NULL); 84 | 85 | TAILQ_FOREACH(item, &pm->list, np) 86 | { 87 | if(!strcmp(pattern, item->pattern)) 88 | { 89 | TAILQ_REMOVE(&pm->list, item, np); 90 | pm_free(item); 91 | } 92 | } 93 | 94 | return 0; 95 | err: 96 | return ~0; 97 | } 98 | 99 | int pm_is_empty(pm_t *pm) 100 | { 101 | dbg_err_if(pm == NULL); 102 | 103 | return TAILQ_FIRST(&pm->list) == NULL; 104 | err: 105 | return 1; /* empty */ 106 | } 107 | 108 | int pm_match(pm_t *pm, const char *uri) 109 | { 110 | pm_t *item; 111 | 112 | dbg_err_if(pm == NULL); 113 | dbg_err_if(uri == NULL); 114 | 115 | TAILQ_FOREACH(item, &pm->list, np) 116 | { 117 | if(!fnmatch(item->pattern, uri, 0)) 118 | return 1; /* matches */ 119 | } 120 | 121 | err: 122 | return 0; /* doesn't match */ 123 | } 124 | 125 | -------------------------------------------------------------------------------- /src/tools/klone/pm.h: -------------------------------------------------------------------------------- 1 | #ifndef _KLONE_PM_H_ 2 | #define _KLONE_PM_H_ 3 | 4 | /* pattern matching object */ 5 | struct pm_s; 6 | typedef struct pm_s pm_t; 7 | 8 | int pm_create(pm_t **ppm); 9 | int pm_free(pm_t *pm); 10 | int pm_is_empty(pm_t *pm); 11 | int pm_add(pm_t *pm, const char *pattern); 12 | int pm_remove(pm_t *pm, const char *pattern); 13 | int pm_match(pm_t *pm, const char *uri); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.4 2008/03/18 22:48:51 tho Exp $ 2 | 3 | include common.mk 4 | include ../Makefile.conf 5 | 6 | PROG = runtests 7 | SRCS = main.c misc.c path.c 8 | 9 | # add libu flags 10 | CFLAGS += -I../libu/include 11 | LDADD += ../src/libhttp/libhttp.a ../src/libutils/libutils.a \ 12 | ../src/libpage/libpage.a ../src/libbackend/libbackend.a \ 13 | ../src/libemb/libemb.a ../src/libio/libio.a \ 14 | ../src/libtls/libtls.a \ 15 | ../src/libcodec/libcodec.a ../src/libklog/libklog.a \ 16 | ../src/libhttp/libhttp.a ../src/libpage/libpage.a \ 17 | ../src/libutils/libutils.a ../src/libio/libio.a \ 18 | ../src/libtls/libtls.a ../src/libcodec/libcodec.a \ 19 | ../src/libpage/libpage.a ../site/libsite.a 20 | 21 | LDADD += ../libu/srcs/libu.a 22 | CFLAGS += $(LIBOPENSSL_CFLAGS) $(LIBZ_CFLAGS) 23 | LDFLAGS += $(LIBOPENSSL_LDFLAGS) $(LIBZ_LDFLAGS) 24 | 25 | include prog.mk 26 | 27 | -------------------------------------------------------------------------------- /test/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int facility = LOG_LOCAL0; 4 | 5 | /* run ./runtests -h for help */ 6 | 7 | int main(int argc, char**argv) 8 | { 9 | U_TEST_MODULE_USE( misc ); 10 | U_TEST_MODULE_USE( path ); 11 | 12 | return u_test_run(argc, argv); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /test/path.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct path_vec_s 5 | { 6 | const char *src, *exp; 7 | }; 8 | 9 | const struct path_vec_s paths[] = { 10 | { "/", "/" }, 11 | { "\\", "/" }, 12 | { "//.", "/" }, 13 | { "\\\\.", "/" }, 14 | { "///.", "/" }, 15 | { "//.//", "/" }, 16 | { "//.//", "/" }, 17 | { "\\/./\\", "/" }, 18 | { "/.", "/" }, 19 | { "/..", "/" }, 20 | { "/../", "/" }, 21 | { "/a", "/a" }, 22 | { "/a/", "/a/" }, 23 | { "/a/..", "/" }, 24 | { "/a/../", "/" }, 25 | { "/../a", "/a" }, 26 | { "/../../../", "/" }, 27 | { "/a/b/.../c", "/a/b/.../c" }, 28 | { "/a/b/./c", "/a/b/c" }, 29 | { "/a/b/./c/", "/a/b/c/" }, 30 | { "/a/b/../c", "/a/c" }, 31 | { "/a/b/../c/", "/a/c/" }, 32 | { NULL, NULL } 33 | }; 34 | 35 | static int test_normalize(void) 36 | { 37 | char buf[512], *src, *exp; 38 | int i; 39 | 40 | for(i = 0; paths[i].src != NULL; ++i) 41 | { 42 | src = paths[i].src; 43 | exp = paths[i].exp; /* expected result */ 44 | 45 | strlcpy(buf, src, sizeof(buf)); 46 | 47 | con_err_if(u_uri_normalize(buf)); 48 | 49 | con_err_if(strcmp(buf, exp)); 50 | } 51 | return 0; 52 | err: 53 | if(src && exp && buf) 54 | u_con("[%d]: src: [%s] exp: [%s] norm: [%s]: FAILED", 55 | i, src, exp, buf); 56 | return ~0; 57 | } 58 | 59 | U_TEST_MODULE( path ) 60 | { 61 | 62 | U_TEST_RUN( test_normalize ); 63 | 64 | return 0; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /webapp/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.4 2007/08/07 14:47:10 tat Exp $ 2 | 3 | include common.mk 4 | include ../Makefile.conf 5 | include Makefile-webapp 6 | 7 | LIB = webapp 8 | 9 | SRCS = ${WEBAPP_SRCS} 10 | 11 | CFLAGS += ${WEBAPP_CFLAGS} 12 | ifdef SSL_ON 13 | CFLAGS := $(SSL_CFLAGS) $(CFLAGS) 14 | endif 15 | 16 | LDADD += ${WEBAPP_LDADD} 17 | 18 | ifdef INSTALL_DAEMON_ONLY 19 | NO_INSTALL = true 20 | endif 21 | 22 | include lib.mk 23 | -------------------------------------------------------------------------------- /webapp/Makefile-webapp: -------------------------------------------------------------------------------- 1 | # $Id: Makefile-webapp,v 1.2 2005/12/12 15:54:05 stewy Exp $ 2 | # 3 | # This file is used to setup the compilation flags for a web application. 4 | # 5 | # Rerun make from the KLone root directory and restart the kloned server 6 | # to make the changes effective. 7 | 8 | # list of source files to be included in the web application 9 | WEBAPP_SRCS = webapp.c 10 | 11 | # extra flags to be passed to the compiler 12 | WEBAPP_CFLAGS = 13 | # additional shared libraries (absolute path) 14 | WEBAPP_LDADD = 15 | # dynamically linked libraries 16 | WEBAPP_LDFLAGS = 17 | -------------------------------------------------------------------------------- /webapp/webapp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void wa_test(response_t *response) 5 | { 6 | io_printf(response_io(response), "Custom Web Application"); 7 | } 8 | --------------------------------------------------------------------------------