You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2008/07/22 06:35:46 UTC
svn commit: r678637 [22/46] - in
/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd: ./
autom4te.cache/ cygwin/ doc/ openwrt/ src/ tests/ tests/docroot/
tests/docroot/123/ tests/docroot/www/ tests/docroot/www/dummydir/
tests/docroot/www/expire/ ...
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/SConscript
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/SConscript?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/SConscript (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/SConscript Mon Jul 21 21:35:35 2008
@@ -0,0 +1,195 @@
+import os
+import re
+import types
+
+Import('env')
+
+common_src = Split("buffer.c log.c \
+ keyvalue.c chunk.c \
+ http_chunk.c stream.c fdevent.c \
+ stat_cache.c plugin.c joblist.c etag.c array.c \
+ data_string.c data_count.c data_array.c \
+ data_integer.c md5.c data_fastcgi.c \
+ fdevent_select.c fdevent_linux_rtsig.c \
+ fdevent_poll.c fdevent_linux_sysepoll.c \
+ fdevent_solaris_devpoll.c fdevent_freebsd_kqueue.c \
+ data_config.c bitset.c \
+ inet_ntop_cache.c crc32.c \
+ connections-glue.c \
+ configfile-glue.c \
+ http-header-glue.c \
+ splaytree.c network_writev.c \
+ network_write.c network_linux_sendfile.c \
+ network_freebsd_sendfile.c \
+ network_solaris_sendfilev.c network_openssl.c \
+ status_counter.c \
+")
+
+src = Split("server.c response.c connections.c network.c \
+ configfile.c configparser.c request.c proc_open.c")
+
+lemon = env.Program('lemon', 'lemon.c')
+
+configparser = env.Command(['configparser.c', 'configparser.h'], 'configparser.y', '(cd build; ../' + lemon[0].path + ' -q ../$SOURCE ../src/lempar.c; cd ..)')
+env.Depends(configparser, lemon)
+
+mod_ssi_exprparser = env.Command(['mod_ssi_exprparser.c', 'mod_ssi_exprparser.h'], 'mod_ssi_exprparser.y', '(cd build; ../' + lemon[0].path + ' -q ../$SOURCE ../src/lempar.c; cd ..)')
+env.Depends(mod_ssi_exprparser, lemon)
+
+## the modules and how they are built
+modules = {
+ 'mod_access' : { 'src' : [ 'mod_access.c' ] },
+ 'mod_alias' : { 'src' : [ 'mod_alias.c' ] },
+ 'mod_cgi' : { 'src' : [ 'mod_cgi.c' ] },
+ 'mod_fastcgi' : { 'src' : [ 'mod_fastcgi.c' ] },
+ 'mod_scgi' : { 'src' : [ 'mod_scgi.c' ] },
+ 'mod_staticfile' : { 'src' : [ 'mod_staticfile.c' ] },
+ 'mod_dirlisting' : { 'src' : [ 'mod_dirlisting.c' ], 'lib' : [ env['LIBPCRE'] ] },
+ 'mod_indexfile' : { 'src' : [ 'mod_indexfile.c' ] },
+ 'mod_setenv' : { 'src' : [ 'mod_setenv.c' ] },
+ 'mod_rrdtool' : { 'src' : [ 'mod_rrdtool.c' ] },
+ 'mod_usertrack' : { 'src' : [ 'mod_usertrack.c' ] },
+ 'mod_proxy' : { 'src' : [ 'mod_proxy.c' ] },
+ 'mod_userdir' : { 'src' : [ 'mod_userdir.c' ] },
+ 'mod_secdownload' : { 'src' : [ 'mod_secure_download.c' ] },
+ 'mod_accesslog' : { 'src' : [ 'mod_accesslog.c' ] },
+ 'mod_simple_vhost' : { 'src' : [ 'mod_simple_vhost.c' ] },
+ 'mod_evhost' : { 'src' : [ 'mod_evhost.c' ] },
+ 'mod_expire' : { 'src' : [ 'mod_expire.c' ] },
+ 'mod_status' : { 'src' : [ 'mod_status.c' ] },
+ 'mod_compress' : { 'src' : [ 'mod_compress.c' ], 'lib' : [ env['LIBZ'], env['LIBBZ2'] ] },
+ 'mod_redirect' : { 'src' : [ 'mod_redirect.c' ], 'lib' : [ env['LIBPCRE'] ] },
+ 'mod_rewrite' : { 'src' : [ 'mod_rewrite.c' ], 'lib' : [ env['LIBPCRE'] ] },
+ 'mod_auth' : {
+ 'src' : [ 'mod_auth.c', 'http_auth_digest.c', 'http_auth.c' ],
+ 'lib' : [ env['LIBCRYPT'], env['LIBLDAP'], env['LIBLBER'] ] },
+ 'mod_webdav' : { 'src' : [ 'mod_webdav.c' ], 'lib' : [ env['LIBXML2'], env['LIBSQLITE3'], env['LIBUUID'] ] },
+ 'mod_mysql_vhost' : { 'src' : [ 'mod_mysql_vhost.c' ], 'lib' : [ env['LIBMYSQL'] ] },
+ 'mod_trigger_b4_dl' : { 'src' : [ 'mod_trigger_b4_dl.c' ], 'lib' : [ env['LIBPCRE'] ] },
+ 'mod_cml' : {
+ 'src' : [ 'mod_cml_lua.c', 'mod_cml.c', 'mod_cml_funcs.c' ],
+ 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHE'], env['LIBLUA'], env['LIBLUALIB'] ] },
+ 'mod_uploadprogress' : { 'src' : [ 'mod_uploadprogress.c' ] },
+ 'mod_evasive' : { 'src' : [ 'mod_evasive.c' ] },
+ 'mod_ssi' : { 'src' : [ 'mod_ssi_exprparser.c', 'mod_ssi_expr.c', 'mod_ssi.c' ], 'lib' : [ env['LIBPCRE'] ] },
+ 'mod_flv_streaming' : { 'src' : [ 'mod_flv_streaming.c' ] },
+ 'mod_magnet' : { 'src' : [ 'mod_magnet.c', 'mod_magnet_cache.c' ], 'lib' : [ env['LIBLUA'] ] },
+}
+
+staticenv = env.Copy(CPPFLAGS=[ env['CPPFLAGS'], '-DLIGHTTPD_STATIC', '-DOPENSSL_NO_KRB5'])
+
+## all the core-sources + the modules
+staticsrc = src + common_src
+
+staticlib = env['LIBS']
+staticinit = ''
+for module in modules.keys():
+ staticsrc += modules[module]['src']
+ staticinit += "PLUGIN_INIT(%s)\n"%module
+ if modules[module].has_key('lib'):
+ staticlib += modules[module]['lib']
+
+open('plugin-static.h', 'w+').write(staticinit)
+
+## turn all src-files into objects
+staticobj = []
+for cfile in staticsrc:
+ staticobj += [ staticenv.Object('static-' + cfile.replace('.c', ''), cfile) ]
+
+staticbin = staticenv.Program('lighttpd-semi-static',
+ staticobj,
+ LIBS = staticlib
+ )
+
+## you might have to adjust the list of libs and the order for your setup
+## this is tricky, be warned
+fullstaticlib = []
+
+## try to calculate the libs for fullstatic with ldd
+## 1. find the lib
+## 2. check the deps
+## 3. add them to the libs
+searchlibs = os.pathsep.join([ '/lib/', '/usr/lib/', '/usr/local/lib/' ])
+lddre = re.compile(r'^\s+lib([^=-]+)(?:-[\.0-9]+)?\.so\.[0-9]+ =>', re.MULTILINE)
+for libs in staticlib:
+ if type(libs) is types.StringType: libs = [ libs ]
+ for lib in libs:
+ fullstaticlib += [ lib ]
+ solibpath = env.WhereIs('lib' + lib + '.so', searchlibs)
+ fullstaticlib += [ lib ]
+ if solibpath is None:
+ continue
+
+ f = os.popen('ldd ' + solibpath, 'r')
+ for aword in lddre.findall(f.read()):
+ fullstaticlib += [ aword ]
+ f.close
+
+
+fullstaticbin = staticenv.Program('lighttpd-static',
+ staticobj,
+ LIBS = fullstaticlib,
+ LINKFLAGS= ['-static']
+ )
+
+Alias('static', staticbin)
+Alias('fullstatic', fullstaticbin)
+
+implib = 'lighttpd.exe.a'
+bin_targets = ['lighttpd']
+bin_linkflags = [ env['LINKFLAGS'] ]
+if env['COMMON_LIB'] == 'lib':
+ common_lib = env.SharedLibrary('liblighttpd', common_src, LINKFLAGS = [ env['LINKFLAGS'], '-Wl,--export-dynamic' ])
+else:
+ src += common_src
+ common_lib = []
+ if env['COMMON_LIB'] == 'bin':
+ bin_linkflags += [ '-Wl,--export-all-symbols', '-Wl,--out-implib=build/' + implib ]
+ bin_targets += [ implib ]
+ else:
+ bin_linkflags += [ '-Wl,--export-dynamic' ]
+
+instbin = env.Program(bin_targets, src, LINKFLAGS = bin_linkflags, LIBS= [ env['LIBS'], common_lib, env['LIBDL'] ])
+env.Depends(instbin, configparser)
+
+spawn_fcgi = env.Program("spawn-fcgi", "spawn-fcgi.c")
+
+if env['COMMON_LIB'] == 'bin':
+ common_lib = instbin[1]
+
+env['SHLIBPREFIX'] = ''
+instlib = []
+for module in modules.keys():
+ libs = [ common_lib ]
+ if modules[module].has_key('lib'):
+ libs += modules[module]['lib']
+ instlib += env.SharedLibrary(module, modules[module]['src'], LIBS= [ libs ])
+
+inst = []
+
+Default(spawn_fcgi)
+inst += env.Install('${bindir}', spawn_fcgi)
+
+if env['build_dynamic']:
+ Default(instbin[0], instlib)
+ inst += env.Install('${sbindir}', instbin[0])
+ inst += env.Install('${libdir}', instlib)
+ if env['COMMON_LIB'] == 'lib':
+ Default(common_lib)
+ inst += env.Install('${bindir}', common_lib)
+
+if env['build_static']:
+ Default(staticbin)
+ inst += env.Install('${sbindir}', staticbin)
+
+if env['build_fullstatic']:
+ Default(fullstaticbin)
+ inst += env.Install('${sbindir}', fullstaticbin)
+
+env.Alias('dynamic', instbin)
+# default all to be installed
+env.Alias('install', inst)
+
+pkgdir = '.'
+tarname = env['package'] + '-' + env['version']
+
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/array.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/array.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/array.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/array.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,369 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <errno.h>
+#include <assert.h>
+
+#include "array.h"
+#include "buffer.h"
+
+array *array_init(void) {
+ array *a;
+
+ a = calloc(1, sizeof(*a));
+ assert(a);
+
+ a->next_power_of_2 = 1;
+
+ return a;
+}
+
+array *array_init_array(array *src) {
+ size_t i;
+ array *a = array_init();
+
+ a->used = src->used;
+ a->size = src->size;
+ a->next_power_of_2 = src->next_power_of_2;
+ a->unique_ndx = src->unique_ndx;
+
+ a->data = malloc(sizeof(*src->data) * src->size);
+ for (i = 0; i < src->size; i++) {
+ if (src->data[i]) a->data[i] = src->data[i]->copy(src->data[i]);
+ else a->data[i] = NULL;
+ }
+
+ a->sorted = malloc(sizeof(*src->sorted) * src->size);
+ memcpy(a->sorted, src->sorted, sizeof(*src->sorted) * src->size);
+ return a;
+}
+
+void array_free(array *a) {
+ size_t i;
+ if (!a) return;
+
+ if (!a->is_weakref) {
+ for (i = 0; i < a->size; i++) {
+ if (a->data[i]) a->data[i]->free(a->data[i]);
+ }
+ }
+
+ if (a->data) free(a->data);
+ if (a->sorted) free(a->sorted);
+
+ free(a);
+}
+
+void array_reset(array *a) {
+ size_t i;
+ if (!a) return;
+
+ if (!a->is_weakref) {
+ for (i = 0; i < a->used; i++) {
+ a->data[i]->reset(a->data[i]);
+ }
+ }
+
+ a->used = 0;
+}
+
+data_unset *array_pop(array *a) {
+ data_unset *du;
+
+ assert(a->used != 0);
+
+ a->used --;
+ du = a->data[a->used];
+ a->data[a->used] = NULL;
+
+ return du;
+}
+
+static int array_get_index(array *a, const char *key, size_t keylen, int *rndx) {
+ int ndx = -1;
+ int i, pos = 0;
+
+ if (key == NULL) return -1;
+
+ /* try to find the string */
+ for (i = pos = a->next_power_of_2 / 2; ; i >>= 1) {
+ int cmp;
+
+ if (pos < 0) {
+ pos += i;
+ } else if (pos >= (int)a->used) {
+ pos -= i;
+ } else {
+ cmp = buffer_caseless_compare(key, keylen, a->data[a->sorted[pos]]->key->ptr, a->data[a->sorted[pos]]->key->used);
+
+ if (cmp == 0) {
+ /* found */
+ ndx = a->sorted[pos];
+ break;
+ } else if (cmp < 0) {
+ pos -= i;
+ } else {
+ pos += i;
+ }
+ }
+ if (i == 0) break;
+ }
+
+ if (rndx) *rndx = pos;
+
+ return ndx;
+}
+
+data_unset *array_get_element(array *a, const char *key) {
+ int ndx;
+
+ if (-1 != (ndx = array_get_index(a, key, strlen(key) + 1, NULL))) {
+ /* found, leave here */
+
+ return a->data[ndx];
+ }
+
+ return NULL;
+}
+
+data_unset *array_get_unused_element(array *a, data_type_t t) {
+ data_unset *ds = NULL;
+
+ UNUSED(t);
+
+ if (a->size == 0) return NULL;
+
+ if (a->used == a->size) return NULL;
+
+ if (a->data[a->used]) {
+ ds = a->data[a->used];
+
+ a->data[a->used] = NULL;
+ }
+
+ return ds;
+}
+
+/* replace or insert data, return the old one with the same key */
+data_unset *array_replace(array *a, data_unset *du) {
+ int ndx;
+
+ if (-1 == (ndx = array_get_index(a, du->key->ptr, du->key->used, NULL))) {
+ array_insert_unique(a, du);
+ return NULL;
+ } else {
+ data_unset *old = a->data[ndx];
+ a->data[ndx] = du;
+ return old;
+ }
+}
+
+int array_insert_unique(array *a, data_unset *str) {
+ int ndx = -1;
+ int pos = 0;
+ size_t j;
+
+ /* generate unique index if neccesary */
+ if (str->key->used == 0 || str->is_index_key) {
+ buffer_copy_long(str->key, a->unique_ndx++);
+ str->is_index_key = 1;
+ }
+
+ /* try to find the string */
+ if (-1 != (ndx = array_get_index(a, str->key->ptr, str->key->used, &pos))) {
+ /* found, leave here */
+ if (a->data[ndx]->type == str->type) {
+ str->insert_dup(a->data[ndx], str);
+ } else {
+ fprintf(stderr, "a\n");
+ }
+ return 0;
+ }
+
+ /* insert */
+
+ if (a->used+1 > INT_MAX) {
+ /* we can't handle more then INT_MAX entries: see array_get_index() */
+ return -1;
+ }
+
+ if (a->size == 0) {
+ a->size = 16;
+ a->data = malloc(sizeof(*a->data) * a->size);
+ a->sorted = malloc(sizeof(*a->sorted) * a->size);
+ assert(a->data);
+ assert(a->sorted);
+ for (j = a->used; j < a->size; j++) a->data[j] = NULL;
+ } else if (a->size == a->used) {
+ a->size += 16;
+ a->data = realloc(a->data, sizeof(*a->data) * a->size);
+ a->sorted = realloc(a->sorted, sizeof(*a->sorted) * a->size);
+ assert(a->data);
+ assert(a->sorted);
+ for (j = a->used; j < a->size; j++) a->data[j] = NULL;
+ }
+
+ ndx = (int) a->used;
+
+ a->data[a->used++] = str;
+
+ if (pos != ndx &&
+ ((pos < 0) ||
+ buffer_caseless_compare(str->key->ptr, str->key->used, a->data[a->sorted[pos]]->key->ptr, a->data[a->sorted[pos]]->key->used) > 0)) {
+ pos++;
+ }
+
+ /* move everything on step to the right */
+ if (pos != ndx) {
+ memmove(a->sorted + (pos + 1), a->sorted + (pos), (ndx - pos) * sizeof(*a->sorted));
+ }
+
+ /* insert */
+ a->sorted[pos] = ndx;
+
+ if (a->next_power_of_2 == (size_t)ndx) a->next_power_of_2 <<= 1;
+
+ return 0;
+}
+
+void array_print_indent(int depth) {
+ int i;
+ for (i = 0; i < depth; i ++) {
+ fprintf(stdout, " ");
+ }
+}
+
+size_t array_get_max_key_length(array *a) {
+ size_t maxlen, i;
+
+ maxlen = 0;
+ for (i = 0; i < a->used; i ++) {
+ data_unset *du = a->data[i];
+ size_t len = strlen(du->key->ptr);
+
+ if (len > maxlen) {
+ maxlen = len;
+ }
+ }
+ return maxlen;
+}
+
+int array_print(array *a, int depth) {
+ size_t i;
+ size_t maxlen;
+ int oneline = 1;
+
+ if (a->used > 5) {
+ oneline = 0;
+ }
+ for (i = 0; i < a->used && oneline; i++) {
+ data_unset *du = a->data[i];
+ if (!du->is_index_key) {
+ oneline = 0;
+ break;
+ }
+ switch (du->type) {
+ case TYPE_INTEGER:
+ case TYPE_STRING:
+ case TYPE_COUNT:
+ break;
+ default:
+ oneline = 0;
+ break;
+ }
+ }
+ if (oneline) {
+ fprintf(stdout, "(");
+ for (i = 0; i < a->used; i++) {
+ data_unset *du = a->data[i];
+ if (i != 0) {
+ fprintf(stdout, ", ");
+ }
+ du->print(du, depth + 1);
+ }
+ fprintf(stdout, ")");
+ return 0;
+ }
+
+ maxlen = array_get_max_key_length(a);
+ fprintf(stdout, "(\n");
+ for (i = 0; i < a->used; i++) {
+ data_unset *du = a->data[i];
+ array_print_indent(depth + 1);
+ if (!du->is_index_key) {
+ int j;
+
+ if (i && (i % 5) == 0) {
+ fprintf(stdout, "# %zd\n", i);
+ array_print_indent(depth + 1);
+ }
+ fprintf(stdout, "\"%s\"", du->key->ptr);
+ for (j = maxlen - strlen(du->key->ptr); j > 0; j --) {
+ fprintf(stdout, " ");
+ }
+ fprintf(stdout, " => ");
+ }
+ du->print(du, depth + 1);
+ fprintf(stdout, ",\n");
+ }
+ if (!(i && (i - 1 % 5) == 0)) {
+ array_print_indent(depth + 1);
+ fprintf(stdout, "# %zd\n", i);
+ }
+ array_print_indent(depth);
+ fprintf(stdout, ")");
+
+ return 0;
+}
+
+#ifdef DEBUG_ARRAY
+int main (int argc, char **argv) {
+ array *a;
+ data_string *ds;
+ data_count *dc;
+
+ UNUSED(argc);
+ UNUSED(argv);
+
+ a = array_init();
+
+ ds = data_string_init();
+ buffer_copy_string(ds->key, "abc");
+ buffer_copy_string(ds->value, "alfrag");
+
+ array_insert_unique(a, (data_unset *)ds);
+
+ ds = data_string_init();
+ buffer_copy_string(ds->key, "abc");
+ buffer_copy_string(ds->value, "hameplman");
+
+ array_insert_unique(a, (data_unset *)ds);
+
+ ds = data_string_init();
+ buffer_copy_string(ds->key, "123");
+ buffer_copy_string(ds->value, "alfrag");
+
+ array_insert_unique(a, (data_unset *)ds);
+
+ dc = data_count_init();
+ buffer_copy_string(dc->key, "def");
+
+ array_insert_unique(a, (data_unset *)dc);
+
+ dc = data_count_init();
+ buffer_copy_string(dc->key, "def");
+
+ array_insert_unique(a, (data_unset *)dc);
+
+ array_print(a, 0);
+
+ array_free(a);
+
+ fprintf(stderr, "%d\n",
+ buffer_caseless_compare(CONST_STR_LEN("Content-Type"), CONST_STR_LEN("Content-type")));
+
+ return 0;
+}
+#endif
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/array.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/array.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/array.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/array.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,172 @@
+#ifndef ARRAY_H
+#define ARRAY_H
+
+#include <stdlib.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_PCRE_H
+# include <pcre.h>
+#endif
+#include "buffer.h"
+
+#define DATA_IS_STRING(x) (x->type == TYPE_STRING)
+
+typedef enum { TYPE_UNSET, TYPE_STRING, TYPE_COUNT, TYPE_ARRAY, TYPE_INTEGER, TYPE_FASTCGI, TYPE_CONFIG } data_type_t;
+#define DATA_UNSET \
+ data_type_t type; \
+ buffer *key; \
+ int is_index_key; /* 1 if key is a array index (autogenerated keys) */ \
+ struct data_unset *(*copy)(const struct data_unset *src); \
+ void (* free)(struct data_unset *p); \
+ void (* reset)(struct data_unset *p); \
+ int (*insert_dup)(struct data_unset *dst, struct data_unset *src); \
+ void (*print)(const struct data_unset *p, int depth)
+
+typedef struct data_unset {
+ DATA_UNSET;
+} data_unset;
+
+typedef struct {
+ data_unset **data;
+
+ size_t *sorted;
+
+ size_t used;
+ size_t size;
+
+ size_t unique_ndx;
+
+ size_t next_power_of_2;
+ int is_weakref; /* data is weakref, don't bother the data */
+} array;
+
+typedef struct {
+ DATA_UNSET;
+
+ int count;
+} data_count;
+
+data_count *data_count_init(void);
+
+typedef struct {
+ DATA_UNSET;
+
+ buffer *value;
+} data_string;
+
+data_string *data_string_init(void);
+data_string *data_response_init(void);
+
+typedef struct {
+ DATA_UNSET;
+
+ array *value;
+} data_array;
+
+data_array *data_array_init(void);
+
+/**
+ * possible compare ops in the configfile parser
+ */
+typedef enum {
+ CONFIG_COND_UNSET,
+ CONFIG_COND_EQ, /** == */
+ CONFIG_COND_MATCH, /** =~ */
+ CONFIG_COND_NE, /** != */
+ CONFIG_COND_NOMATCH /** !~ */
+} config_cond_t;
+
+/**
+ * possible fields to match against
+ */
+typedef enum {
+ COMP_UNSET,
+ COMP_SERVER_SOCKET,
+ COMP_HTTP_URL,
+ COMP_HTTP_HOST,
+ COMP_HTTP_REFERER,
+ COMP_HTTP_USER_AGENT,
+ COMP_HTTP_COOKIE,
+ COMP_HTTP_REMOTE_IP,
+ COMP_HTTP_QUERY_STRING,
+ COMP_HTTP_SCHEME,
+ COMP_HTTP_REQUEST_METHOD,
+
+ COMP_LAST_ELEMENT
+} comp_key_t;
+
+/* $HTTP["host"] == "incremental.home.kneschke.de" { ... }
+ * for print: comp_key op string
+ * for compare: comp cond string/regex
+ */
+
+typedef struct _data_config data_config;
+struct _data_config {
+ DATA_UNSET;
+
+ array *value;
+
+ buffer *comp_key;
+ comp_key_t comp;
+
+ config_cond_t cond;
+ buffer *op;
+
+ int context_ndx; /* more or less like an id */
+ array *childs;
+ /* nested */
+ data_config *parent;
+ /* for chaining only */
+ data_config *prev;
+ data_config *next;
+
+ buffer *string;
+#ifdef HAVE_PCRE_H
+ pcre *regex;
+ pcre_extra *regex_study;
+#endif
+};
+
+data_config *data_config_init(void);
+
+typedef struct {
+ DATA_UNSET;
+
+ int value;
+} data_integer;
+
+data_integer *data_integer_init(void);
+
+typedef struct {
+ DATA_UNSET;
+
+ buffer *host;
+
+ unsigned short port;
+
+ time_t disable_ts;
+ int is_disabled;
+ size_t balance;
+
+ int usage; /* fair-balancing needs the no. of connections active on this host */
+ int last_used_ndx; /* round robin */
+} data_fastcgi;
+
+data_fastcgi *data_fastcgi_init(void);
+
+array *array_init(void);
+array *array_init_array(array *a);
+void array_free(array *a);
+void array_reset(array *a);
+int array_insert_unique(array *a, data_unset *str);
+data_unset *array_pop(array *a);
+int array_print(array *a, int depth);
+data_unset *array_get_unused_element(array *a, data_type_t t);
+data_unset *array_get_element(array *a, const char *key);
+data_unset *array_replace(array *a, data_unset *du);
+int array_strcasecmp(const char *a, size_t a_len, const char *b, size_t b_len);
+void array_print_indent(int depth);
+size_t array_get_max_key_length(array *a);
+
+#endif
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/axis2_apache2_out_transport_info.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/axis2_apache2_out_transport_info.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/axis2_apache2_out_transport_info.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/axis2_apache2_out_transport_info.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,61 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AXIS2_APACHE2_OUT_TRANSPORT_INFO_H
+#define AXIS2_APACHE2_OUT_TRANSPORT_INFO_H
+
+/**
+ * @ingroup axis2_core_transport_http
+ * @{
+ */
+
+/**
+ * @file axis2_apache2_out_transport_info.h
+ * @brief axis2 Apache2 Out Transport Info
+ */
+
+#include <axis2_http_out_transport_info.h>
+#include <httpd.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ AXIS2_EXTERN axis2_http_out_transport_info_t *AXIS2_CALL
+
+ axis2_apache2_out_transport_info_create(
+ const axutil_env_t * env,
+ request_rec * r);
+
+ /**
+ * Free http_out_transport_info passed as void pointer. This will be
+ * cast into appropriate type and then pass the cast object
+ * into the http_out_transport_info structure's free method
+ */
+ AXIS2_EXTERN void AXIS2_CALL
+
+ axis2_apache2_out_transport_info_free_void_arg(
+ void *transport_info,
+ const axutil_env_t * env);
+
+ /** @} */
+#ifdef __cplusplus
+}
+#endif
+#endif /* AXIS2_APACHE2_OUT_TRANSPORT_INFO_H */
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/axis2_lighty_out_transport_info.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/axis2_lighty_out_transport_info.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/axis2_lighty_out_transport_info.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/axis2_lighty_out_transport_info.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AXIS2_LIGHTY_OUT_TRANSPORT_INFO_H
+#define AXIS2_LIGHTY_OUT_TRANSPORT_INFO_H
+
+/**
+ * @ingroup axis2_core_transport_http
+ * @{
+ */
+
+/**
+ * @file axis2_lighty_out_transport_info.h
+ * @brief axis2 Lighty Out Transport Info
+ */
+
+#include <axis2_http_out_transport_info.h>
+#include <base.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ AXIS2_EXTERN axis2_http_out_transport_info_t *AXIS2_CALL
+
+ axis2_lighty_out_transport_info_create(
+ const axutil_env_t * env,
+ server *srv,
+ connection *con);
+
+ /**
+ * Free http_out_transport_info passed as void pointer. This will be
+ * cast into appropriate type and then pass the cast object
+ * into the http_out_transport_info structure's free method
+ */
+ AXIS2_EXTERN void AXIS2_CALL
+
+ axis2_lighty_out_transport_info_free_void_arg(
+ void *transport_info,
+ const axutil_env_t * env);
+
+ /** @} */
+#ifdef __cplusplus
+}
+#endif
+#endif /* AXIS2_LIGHTY_OUT_TRANSPORT_INFO_H */
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/base.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/base.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/base.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/base.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,632 @@
+#ifndef _BASE_H_
+#define _BASE_H_
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <limits.h>
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+
+#include "buffer.h"
+#include "array.h"
+#include "chunk.h"
+#include "keyvalue.h"
+#include "settings.h"
+#include "fdevent.h"
+#include "sys-socket.h"
+#include "splaytree.h"
+#include "etag.h"
+
+
+#if defined HAVE_LIBSSL && defined HAVE_OPENSSL_SSL_H
+# define USE_OPENSSL
+# include <openssl/ssl.h>
+#endif
+
+#ifdef HAVE_FAM_H
+# include <fam.h>
+#endif
+
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
+#ifndef O_LARGEFILE
+# define O_LARGEFILE 0
+#endif
+
+#ifndef SIZE_MAX
+# ifdef SIZE_T_MAX
+# define SIZE_MAX SIZE_T_MAX
+# else
+# define SIZE_MAX ((size_t)~0)
+# endif
+#endif
+
+#ifndef SSIZE_MAX
+# define SSIZE_MAX ((size_t)~0 >> 1)
+#endif
+
+#ifdef __APPLE__
+#include <crt_externs.h>
+#define environ (* _NSGetEnviron())
+#else
+extern char **environ;
+#endif
+
+/* for solaris 2.5 and NetBSD 1.3.x */
+#ifndef HAVE_SOCKLEN_T
+typedef int socklen_t;
+#endif
+
+/* solaris and NetBSD 1.3.x again */
+#if (!defined(HAVE_STDINT_H)) && (!defined(HAVE_INTTYPES_H)) && (!defined(uint32_t))
+# define uint32_t u_int32_t
+#endif
+
+
+#ifndef SHUT_WR
+# define SHUT_WR 1
+#endif
+
+#include "settings.h"
+
+typedef enum { T_CONFIG_UNSET,
+ T_CONFIG_STRING,
+ T_CONFIG_SHORT,
+ T_CONFIG_BOOLEAN,
+ T_CONFIG_ARRAY,
+ T_CONFIG_LOCAL,
+ T_CONFIG_DEPRECATED,
+ T_CONFIG_UNSUPPORTED
+} config_values_type_t;
+
+typedef enum { T_CONFIG_SCOPE_UNSET,
+ T_CONFIG_SCOPE_SERVER,
+ T_CONFIG_SCOPE_CONNECTION
+} config_scope_type_t;
+
+typedef struct {
+ const char *key;
+ void *destination;
+
+ config_values_type_t type;
+ config_scope_type_t scope;
+} config_values_t;
+
+typedef enum { DIRECT, EXTERNAL } connection_type;
+
+typedef struct {
+ char *key;
+ connection_type type;
+ char *value;
+} request_handler;
+
+typedef struct {
+ char *key;
+ char *host;
+ unsigned short port;
+ int used;
+ short factor;
+} fcgi_connections;
+
+
+typedef union {
+#ifdef HAVE_IPV6
+ struct sockaddr_in6 ipv6;
+#endif
+ struct sockaddr_in ipv4;
+#ifdef HAVE_SYS_UN_H
+ struct sockaddr_un un;
+#endif
+ struct sockaddr plain;
+} sock_addr;
+
+/* fcgi_response_header contains ... */
+#define HTTP_STATUS BV(0)
+#define HTTP_CONNECTION BV(1)
+#define HTTP_CONTENT_LENGTH BV(2)
+#define HTTP_DATE BV(3)
+#define HTTP_LOCATION BV(4)
+
+typedef struct {
+ /** HEADER */
+ /* the request-line */
+ buffer *request;
+ buffer *uri;
+
+ buffer *orig_uri;
+
+ http_method_t http_method;
+ http_version_t http_version;
+
+ buffer *request_line;
+
+ /* strings to the header */
+ buffer *http_host; /* not alloced */
+ const char *http_range;
+ const char *http_content_type;
+ const char *http_if_modified_since;
+ const char *http_if_none_match;
+
+ array *headers;
+
+ /* CONTENT */
+ size_t content_length; /* returned by strtoul() */
+
+ /* internal representation */
+ int accept_encoding;
+
+ /* internal */
+ buffer *pathinfo;
+} request;
+
+typedef struct {
+ off_t content_length;
+ int keep_alive; /* used by the subrequests in proxy, cgi and fcgi to say the subrequest was keep-alive or not */
+
+ array *headers;
+
+ enum {
+ HTTP_TRANSFER_ENCODING_IDENTITY, HTTP_TRANSFER_ENCODING_CHUNKED
+ } transfer_encoding;
+} response;
+
+typedef struct {
+ buffer *scheme;
+ buffer *authority;
+ buffer *path;
+ buffer *path_raw;
+ buffer *query;
+} request_uri;
+
+typedef struct {
+ buffer *path;
+ buffer *basedir; /* path = "(basedir)(.*)" */
+
+ buffer *doc_root; /* path = doc_root + rel_path */
+ buffer *rel_path;
+
+ buffer *etag;
+} physical;
+
+typedef struct {
+ buffer *name;
+ buffer *etag;
+
+ struct stat st;
+
+ time_t stat_ts;
+
+#ifdef HAVE_LSTAT
+ char is_symlink;
+#endif
+
+#ifdef HAVE_FAM_H
+ int dir_version;
+ int dir_ndx;
+#endif
+
+ buffer *content_type;
+} stat_cache_entry;
+
+typedef struct {
+ splay_tree *files; /* the nodes of the tree are stat_cache_entry's */
+
+ buffer *dir_name; /* for building the dirname from the filename */
+#ifdef HAVE_FAM_H
+ splay_tree *dirs; /* the nodes of the tree are fam_dir_entry */
+
+ FAMConnection *fam;
+ int fam_fcce_ndx;
+#endif
+ buffer *hash_key; /* temp-store for the hash-key */
+} stat_cache;
+
+typedef struct {
+ array *mimetypes;
+
+ /* virtual-servers */
+ buffer *document_root;
+ buffer *server_name;
+ buffer *error_handler;
+ buffer *server_tag;
+ buffer *dirlist_encoding;
+ buffer *errorfile_prefix;
+
+ unsigned short max_keep_alive_requests;
+ unsigned short max_keep_alive_idle;
+ unsigned short max_read_idle;
+ unsigned short max_write_idle;
+ unsigned short use_xattr;
+ unsigned short follow_symlink;
+ unsigned short range_requests;
+
+ /* debug */
+
+ unsigned short log_file_not_found;
+ unsigned short log_request_header;
+ unsigned short log_request_handling;
+ unsigned short log_response_header;
+ unsigned short log_condition_handling;
+
+
+ /* server wide */
+ buffer *ssl_pemfile;
+ buffer *ssl_ca_file;
+ buffer *ssl_cipher_list;
+ unsigned short ssl_use_sslv2;
+
+ unsigned short use_ipv6;
+ unsigned short is_ssl;
+ unsigned short allow_http11;
+ unsigned short etag_use_inode;
+ unsigned short etag_use_mtime;
+ unsigned short etag_use_size;
+ unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */
+ unsigned short max_request_size;
+
+ unsigned short kbytes_per_second; /* connection kb/s limit */
+
+ /* configside */
+ unsigned short global_kbytes_per_second; /* */
+
+ off_t global_bytes_per_second_cnt;
+ /* server-wide traffic-shaper
+ *
+ * each context has the counter which is inited once
+ * a second by the global_kbytes_per_second config-var
+ *
+ * as soon as global_kbytes_per_second gets below 0
+ * the connected conns are "offline" a little bit
+ *
+ * the problem:
+ * we somehow have to loose our "we are writable" signal
+ * on the way.
+ *
+ */
+ off_t *global_bytes_per_second_cnt_ptr; /* */
+
+#ifdef USE_OPENSSL
+ SSL_CTX *ssl_ctx;
+#endif
+} specific_config;
+
+/* the order of the items should be the same as they are processed
+ * read before write as we use this later */
+typedef enum {
+ CON_STATE_CONNECT,
+ CON_STATE_REQUEST_START,
+ CON_STATE_READ,
+ CON_STATE_REQUEST_END,
+ CON_STATE_READ_POST,
+ CON_STATE_HANDLE_REQUEST,
+ CON_STATE_RESPONSE_START,
+ CON_STATE_WRITE,
+ CON_STATE_RESPONSE_END,
+ CON_STATE_ERROR,
+ CON_STATE_CLOSE
+} connection_state_t;
+
+typedef enum { COND_RESULT_UNSET, COND_RESULT_FALSE, COND_RESULT_TRUE } cond_result_t;
+typedef struct {
+ cond_result_t result;
+ int patterncount;
+ int matches[3 * 10];
+ buffer *comp_value; /* just a pointer */
+
+ comp_key_t comp_type;
+} cond_cache_t;
+
+typedef struct {
+ connection_state_t state;
+
+ /* timestamps */
+ time_t read_idle_ts;
+ time_t close_timeout_ts;
+ time_t write_request_ts;
+
+ time_t connection_start;
+ time_t request_start;
+
+ struct timeval start_tv;
+
+ size_t request_count; /* number of requests handled in this connection */
+ size_t loops_per_request; /* to catch endless loops in a single request
+ *
+ * used by mod_rewrite, mod_fastcgi, ... and others
+ * this is self-protection
+ */
+
+ int fd; /* the FD for this connection */
+ int fde_ndx; /* index for the fdevent-handler */
+ int ndx; /* reverse mapping to server->connection[ndx] */
+
+ /* fd states */
+ int is_readable;
+ int is_writable;
+
+ int keep_alive; /* only request.c can enable it, all other just disable */
+
+ int file_started;
+ int file_finished;
+
+ chunkqueue *write_queue; /* a large queue for low-level write ( HTTP response ) [ file, mem ] */
+ chunkqueue *read_queue; /* a small queue for low-level read ( HTTP request ) [ mem ] */
+ chunkqueue *request_content_queue; /* takes request-content into tempfile if necessary [ tempfile, mem ]*/
+
+ int traffic_limit_reached;
+
+ off_t bytes_written; /* used by mod_accesslog, mod_rrd */
+ off_t bytes_written_cur_second; /* used by mod_accesslog, mod_rrd */
+ off_t bytes_read; /* used by mod_accesslog, mod_rrd */
+ off_t bytes_header;
+
+ int http_status;
+
+ sock_addr dst_addr;
+ buffer *dst_addr_buf;
+
+ /* request */
+ buffer *parse_request;
+ unsigned int parsed_response; /* bitfield which contains the important header-fields of the parsed response header */
+
+ request request;
+ request_uri uri;
+ physical physical;
+ response response;
+
+ size_t header_len;
+
+ buffer *authed_user;
+ array *environment; /* used to pass lighttpd internal stuff to the FastCGI/CGI apps, setenv does that */
+
+ /* response */
+ int got_response;
+
+ int in_joblist;
+
+ connection_type mode;
+
+ void **plugin_ctx; /* plugin connection specific config */
+
+ specific_config conf; /* global connection specific config */
+ cond_cache_t *cond_cache;
+
+ buffer *server_name;
+
+ /* error-handler */
+ buffer *error_handler;
+ int error_handler_saved_status;
+ int in_error_handler;
+
+ void *srv_socket; /* reference to the server-socket (typecast to server_socket) */
+
+#ifdef USE_OPENSSL
+ SSL *ssl;
+ buffer *ssl_error_want_reuse_buffer;
+#endif
+ /* etag handling */
+ etag_flags_t etag_flags;
+
+ int conditional_is_valid[COMP_LAST_ELEMENT];
+} connection;
+
+typedef struct {
+ connection **ptr;
+ size_t size;
+ size_t used;
+} connections;
+
+
+#ifdef HAVE_IPV6
+typedef struct {
+ int family;
+ union {
+ struct in6_addr ipv6;
+ struct in_addr ipv4;
+ } addr;
+ char b2[INET6_ADDRSTRLEN + 1];
+ time_t ts;
+} inet_ntop_cache_type;
+#endif
+
+
+typedef struct {
+ buffer *uri;
+ time_t mtime;
+ int http_status;
+} realpath_cache_type;
+
+typedef struct {
+ time_t mtime; /* the key */
+ buffer *str; /* a buffer for the string represenation */
+} mtime_cache_type;
+
+typedef struct {
+ void *ptr;
+ size_t used;
+ size_t size;
+} buffer_plugin;
+
+typedef struct {
+ unsigned short port;
+ buffer *bindhost;
+
+ buffer *errorlog_file;
+ unsigned short errorlog_use_syslog;
+
+ unsigned short dont_daemonize;
+ buffer *changeroot;
+ buffer *username;
+ buffer *groupname;
+
+ buffer *pid_file;
+
+ buffer *event_handler;
+
+ buffer *modules_dir;
+ buffer *network_backend;
+ array *modules;
+ array *upload_tempdirs;
+
+ unsigned short max_worker;
+ unsigned short max_fds;
+ unsigned short max_conns;
+ unsigned short max_request_size;
+
+ unsigned short log_request_header_on_error;
+ unsigned short log_state_handling;
+
+ enum { STAT_CACHE_ENGINE_UNSET,
+ STAT_CACHE_ENGINE_NONE,
+ STAT_CACHE_ENGINE_SIMPLE,
+#ifdef HAVE_FAM_H
+ STAT_CACHE_ENGINE_FAM
+#endif
+ } stat_cache_engine;
+ unsigned short enable_cores;
+} server_config;
+
+typedef struct {
+ sock_addr addr;
+ int fd;
+ int fde_ndx;
+
+ buffer *ssl_pemfile;
+ buffer *ssl_ca_file;
+ buffer *ssl_cipher_list;
+ unsigned short ssl_use_sslv2;
+ unsigned short use_ipv6;
+ unsigned short is_ssl;
+
+ buffer *srv_token;
+
+#ifdef USE_OPENSSL
+ SSL_CTX *ssl_ctx;
+#endif
+ unsigned short is_proxy_ssl;
+} server_socket;
+
+typedef struct {
+ server_socket **ptr;
+
+ size_t size;
+ size_t used;
+} server_socket_array;
+
+typedef struct server {
+ server_socket_array srv_sockets;
+
+ /* the errorlog */
+ int errorlog_fd;
+ enum { ERRORLOG_STDERR, ERRORLOG_FILE, ERRORLOG_SYSLOG } errorlog_mode;
+ buffer *errorlog_buf;
+
+ fdevents *ev, *ev_ins;
+
+ buffer_plugin plugins;
+ void *plugin_slots;
+
+ /* counters */
+ int con_opened;
+ int con_read;
+ int con_written;
+ int con_closed;
+
+ int ssl_is_init;
+
+ int max_fds; /* max possible fds */
+ int cur_fds; /* currently used fds */
+ int want_fds; /* waiting fds */
+ int sockets_disabled;
+
+ size_t max_conns;
+
+ /* buffers */
+ buffer *parse_full_path;
+ buffer *response_header;
+ buffer *response_range;
+ buffer *tmp_buf;
+
+ buffer *tmp_chunk_len;
+
+ buffer *empty_string; /* is necessary for cond_match */
+
+ buffer *cond_check_buf;
+
+ /* caches */
+#ifdef HAVE_IPV6
+ inet_ntop_cache_type inet_ntop_cache[INET_NTOP_CACHE_MAX];
+#endif
+ mtime_cache_type mtime_cache[FILE_CACHE_MAX];
+
+ array *split_vals;
+
+ /* Timestamps */
+ time_t cur_ts;
+ time_t last_generated_date_ts;
+ time_t last_generated_debug_ts;
+ time_t startup_ts;
+
+ buffer *ts_debug_str;
+ buffer *ts_date_str;
+
+ /* config-file */
+ array *config;
+ array *config_touched;
+
+ array *config_context;
+ specific_config **config_storage;
+
+ server_config srvconf;
+
+ short int config_deprecated;
+ short int config_unsupported;
+
+ connections *conns;
+ connections *joblist;
+ connections *fdwaitqueue;
+
+ stat_cache *stat_cache;
+
+ /**
+ * The status array can carry all the status information you want
+ * the key to the array is <module-prefix>.<name>
+ * and the values are counters
+ *
+ * example:
+ * fastcgi.backends = 10
+ * fastcgi.active-backends = 6
+ * fastcgi.backend.<key>.load = 24
+ * fastcgi.backend.<key>....
+ *
+ * fastcgi.backend.<key>.disconnects = ...
+ */
+ array *status;
+
+ fdevent_handler_t event_handler;
+
+ int (* network_backend_write)(struct server *srv, connection *con, int fd, chunkqueue *cq);
+ int (* network_backend_read)(struct server *srv, connection *con, int fd, chunkqueue *cq);
+#ifdef USE_OPENSSL
+ int (* network_ssl_backend_write)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
+ int (* network_ssl_backend_read)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
+#endif
+
+ uid_t uid;
+ gid_t gid;
+} server;
+
+
+#endif
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/bitset.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/bitset.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/bitset.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/bitset.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,67 @@
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include "bitset.h"
+#include "buffer.h"
+
+#define BITSET_BITS \
+ ( CHAR_BIT * sizeof(size_t) )
+
+#define BITSET_MASK(pos) \
+ ( ((size_t)1) << ((pos) % BITSET_BITS) )
+
+#define BITSET_WORD(set, pos) \
+ ( (set)->bits[(pos) / BITSET_BITS] )
+
+#define BITSET_USED(nbits) \
+ ( ((nbits) + (BITSET_BITS - 1)) / BITSET_BITS )
+
+bitset *bitset_init(size_t nbits) {
+ bitset *set;
+
+ set = malloc(sizeof(*set));
+ assert(set);
+
+ set->bits = calloc(BITSET_USED(nbits), sizeof(*set->bits));
+ set->nbits = nbits;
+
+ assert(set->bits);
+
+ return set;
+}
+
+void bitset_reset(bitset *set) {
+ memset(set->bits, 0, BITSET_USED(set->nbits) * sizeof(*set->bits));
+}
+
+void bitset_free(bitset *set) {
+ free(set->bits);
+ free(set);
+}
+
+void bitset_clear_bit(bitset *set, size_t pos) {
+ if (pos >= set->nbits) {
+ SEGFAULT();
+ }
+
+ BITSET_WORD(set, pos) &= ~BITSET_MASK(pos);
+}
+
+void bitset_set_bit(bitset *set, size_t pos) {
+ if (pos >= set->nbits) {
+ SEGFAULT();
+ }
+
+ BITSET_WORD(set, pos) |= BITSET_MASK(pos);
+}
+
+int bitset_test_bit(bitset *set, size_t pos) {
+ if (pos >= set->nbits) {
+ SEGFAULT();
+ }
+
+ return (BITSET_WORD(set, pos) & BITSET_MASK(pos)) != 0;
+}
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/bitset.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/bitset.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/bitset.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/bitset.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,19 @@
+#ifndef _BITSET_H_
+#define _BITSET_H_
+
+#include <stddef.h>
+
+typedef struct {
+ size_t *bits;
+ size_t nbits;
+} bitset;
+
+bitset *bitset_init(size_t nbits);
+void bitset_reset(bitset *set);
+void bitset_free(bitset *set);
+
+void bitset_clear_bit(bitset *set, size_t pos);
+void bitset_set_bit(bitset *set, size_t pos);
+int bitset_test_bit(bitset *set, size_t pos);
+
+#endif
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/buffer.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/buffer.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/buffer.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/buffer.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,1073 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include <stdio.h>
+#include <assert.h>
+#include <ctype.h>
+
+#include "buffer.h"
+
+
+static const char hex_chars[] = "0123456789abcdef";
+
+
+/**
+ * init the buffer
+ *
+ */
+
+buffer* buffer_init(void) {
+ buffer *b;
+
+ b = malloc(sizeof(*b));
+ assert(b);
+
+ b->ptr = NULL;
+ b->size = 0;
+ b->used = 0;
+
+ return b;
+}
+
+buffer *buffer_init_buffer(buffer *src) {
+ buffer *b = buffer_init();
+ buffer_copy_string_buffer(b, src);
+ return b;
+}
+
+/**
+ * free the buffer
+ *
+ */
+
+void buffer_free(buffer *b) {
+ if (!b) return;
+
+ free(b->ptr);
+ free(b);
+}
+
+void buffer_reset(buffer *b) {
+ if (!b) return;
+
+ /* limit don't reuse buffer larger than ... bytes */
+ if (b->size > BUFFER_MAX_REUSE_SIZE) {
+ free(b->ptr);
+ b->ptr = NULL;
+ b->size = 0;
+ }
+
+ b->used = 0;
+}
+
+
+/**
+ *
+ * allocate (if neccessary) enough space for 'size' bytes and
+ * set the 'used' counter to 0
+ *
+ */
+
+#define BUFFER_PIECE_SIZE 64
+
+int buffer_prepare_copy(buffer *b, size_t size) {
+ if (!b) return -1;
+
+ if ((0 == b->size) ||
+ (size > b->size)) {
+ if (b->size) free(b->ptr);
+
+ b->size = size;
+
+ /* always allocate a multiply of BUFFER_PIECE_SIZE */
+ b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE);
+
+ b->ptr = malloc(b->size);
+ assert(b->ptr);
+ }
+ b->used = 0;
+ return 0;
+}
+
+/**
+ *
+ * increase the internal buffer (if neccessary) to append another 'size' byte
+ * ->used isn't changed
+ *
+ */
+
+int buffer_prepare_append(buffer *b, size_t size) {
+ if (!b) return -1;
+
+ if (0 == b->size) {
+ b->size = size;
+
+ /* always allocate a multiply of BUFFER_PIECE_SIZE */
+ b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE);
+
+ b->ptr = malloc(b->size);
+ b->used = 0;
+ assert(b->ptr);
+ } else if (b->used + size > b->size) {
+ b->size += size;
+
+ /* always allocate a multiply of BUFFER_PIECE_SIZE */
+ b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE);
+
+ b->ptr = realloc(b->ptr, b->size);
+ assert(b->ptr);
+ }
+ return 0;
+}
+
+int buffer_copy_string(buffer *b, const char *s) {
+ size_t s_len;
+
+ if (!s || !b) return -1;
+
+ s_len = strlen(s) + 1;
+ buffer_prepare_copy(b, s_len);
+
+ memcpy(b->ptr, s, s_len);
+ b->used = s_len;
+
+ return 0;
+}
+
+int buffer_copy_string_len(buffer *b, const char *s, size_t s_len) {
+ if (!s || !b) return -1;
+#if 0
+ /* removed optimization as we have to keep the empty string
+ * in some cases for the config handling
+ *
+ * url.access-deny = ( "" )
+ */
+ if (s_len == 0) return 0;
+#endif
+ buffer_prepare_copy(b, s_len + 1);
+
+ memcpy(b->ptr, s, s_len);
+ b->ptr[s_len] = '\0';
+ b->used = s_len + 1;
+
+ return 0;
+}
+
+int buffer_copy_string_buffer(buffer *b, const buffer *src) {
+ if (!src) return -1;
+
+ if (src->used == 0) {
+ b->used = 0;
+ return 0;
+ }
+ return buffer_copy_string_len(b, src->ptr, src->used - 1);
+}
+
+int buffer_append_string(buffer *b, const char *s) {
+ size_t s_len;
+
+ if (!s || !b) return -1;
+
+ s_len = strlen(s);
+ buffer_prepare_append(b, s_len + 1);
+ if (b->used == 0)
+ b->used++;
+
+ memcpy(b->ptr + b->used - 1, s, s_len + 1);
+ b->used += s_len;
+
+ return 0;
+}
+
+int buffer_append_string_rfill(buffer *b, const char *s, size_t maxlen) {
+ size_t s_len;
+
+ if (!s || !b) return -1;
+
+ s_len = strlen(s);
+ buffer_prepare_append(b, maxlen + 1);
+ if (b->used == 0)
+ b->used++;
+
+ memcpy(b->ptr + b->used - 1, s, s_len);
+ if (maxlen > s_len) {
+ memset(b->ptr + b->used - 1 + s_len, ' ', maxlen - s_len);
+ }
+
+ b->used += maxlen;
+ b->ptr[b->used - 1] = '\0';
+ return 0;
+}
+
+/**
+ * append a string to the end of the buffer
+ *
+ * the resulting buffer is terminated with a '\0'
+ * s is treated as a un-terminated string (a \0 is handled a normal character)
+ *
+ * @param b a buffer
+ * @param s the string
+ * @param s_len size of the string (without the terminating \0)
+ */
+
+int buffer_append_string_len(buffer *b, const char *s, size_t s_len) {
+ if (!s || !b) return -1;
+ if (s_len == 0) return 0;
+
+ buffer_prepare_append(b, s_len + 1);
+ if (b->used == 0)
+ b->used++;
+
+ memcpy(b->ptr + b->used - 1, s, s_len);
+ b->used += s_len;
+ b->ptr[b->used - 1] = '\0';
+
+ return 0;
+}
+
+int buffer_append_string_buffer(buffer *b, const buffer *src) {
+ if (!src) return -1;
+ if (src->used == 0) return 0;
+
+ return buffer_append_string_len(b, src->ptr, src->used - 1);
+}
+
+int buffer_append_memory(buffer *b, const char *s, size_t s_len) {
+ if (!s || !b) return -1;
+ if (s_len == 0) return 0;
+
+ buffer_prepare_append(b, s_len);
+ memcpy(b->ptr + b->used, s, s_len);
+ b->used += s_len;
+
+ return 0;
+}
+
+int buffer_copy_memory(buffer *b, const char *s, size_t s_len) {
+ if (!s || !b) return -1;
+
+ b->used = 0;
+
+ return buffer_append_memory(b, s, s_len);
+}
+
+int buffer_append_long_hex(buffer *b, unsigned long value) {
+ char *buf;
+ int shift = 0;
+ unsigned long copy = value;
+
+ while (copy) {
+ copy >>= 4;
+ shift++;
+ }
+ if (shift == 0)
+ shift++;
+ if (shift & 0x01)
+ shift++;
+
+ buffer_prepare_append(b, shift + 1);
+ if (b->used == 0)
+ b->used++;
+ buf = b->ptr + (b->used - 1);
+ b->used += shift;
+
+ shift <<= 2;
+ while (shift > 0) {
+ shift -= 4;
+ *(buf++) = hex_chars[(value >> shift) & 0x0F];
+ }
+ *buf = '\0';
+
+ return 0;
+}
+
+int LI_ltostr(char *buf, long val) {
+ char swap;
+ char *end;
+ int len = 1;
+
+ if (val < 0) {
+ len++;
+ *(buf++) = '-';
+ val = -val;
+ }
+
+ end = buf;
+ while (val > 9) {
+ *(end++) = '0' + (val % 10);
+ val = val / 10;
+ }
+ *(end) = '0' + val;
+ *(end + 1) = '\0';
+ len += end - buf;
+
+ while (buf < end) {
+ swap = *end;
+ *end = *buf;
+ *buf = swap;
+
+ buf++;
+ end--;
+ }
+
+ return len;
+}
+
+int buffer_append_long(buffer *b, long val) {
+ if (!b) return -1;
+
+ buffer_prepare_append(b, 32);
+ if (b->used == 0)
+ b->used++;
+
+ b->used += LI_ltostr(b->ptr + (b->used - 1), val);
+ return 0;
+}
+
+int buffer_copy_long(buffer *b, long val) {
+ if (!b) return -1;
+
+ b->used = 0;
+ return buffer_append_long(b, val);
+}
+
+#if !defined(SIZEOF_LONG) || (SIZEOF_LONG != SIZEOF_OFF_T)
+int buffer_append_off_t(buffer *b, off_t val) {
+ char swap;
+ char *end;
+ char *start;
+ int len = 1;
+
+ if (!b) return -1;
+
+ buffer_prepare_append(b, 32);
+ if (b->used == 0)
+ b->used++;
+
+ start = b->ptr + (b->used - 1);
+ if (val < 0) {
+ len++;
+ *(start++) = '-';
+ val = -val;
+ }
+
+ end = start;
+ while (val > 9) {
+ *(end++) = '0' + (val % 10);
+ val = val / 10;
+ }
+ *(end) = '0' + val;
+ *(end + 1) = '\0';
+ len += end - start;
+
+ while (start < end) {
+ swap = *end;
+ *end = *start;
+ *start = swap;
+
+ start++;
+ end--;
+ }
+
+ b->used += len;
+ return 0;
+}
+
+int buffer_copy_off_t(buffer *b, off_t val) {
+ if (!b) return -1;
+
+ b->used = 0;
+ return buffer_append_off_t(b, val);
+}
+#endif /* !defined(SIZEOF_LONG) || (SIZEOF_LONG != SIZEOF_OFF_T) */
+
+char int2hex(char c) {
+ return hex_chars[(c & 0x0F)];
+}
+
+/* converts hex char (0-9, A-Z, a-z) to decimal.
+ * returns 0xFF on invalid input.
+ */
+char hex2int(unsigned char hex) {
+ hex = hex - '0';
+ if (hex > 9) {
+ hex = (hex + '0' - 1) | 0x20;
+ hex = hex - 'a' + 11;
+ }
+ if (hex > 15)
+ hex = 0xFF;
+
+ return hex;
+}
+
+
+/**
+ * init the buffer
+ *
+ */
+
+buffer_array* buffer_array_init(void) {
+ buffer_array *b;
+
+ b = malloc(sizeof(*b));
+
+ assert(b);
+ b->ptr = NULL;
+ b->size = 0;
+ b->used = 0;
+
+ return b;
+}
+
+void buffer_array_reset(buffer_array *b) {
+ size_t i;
+
+ if (!b) return;
+
+ /* if they are too large, reduce them */
+ for (i = 0; i < b->used; i++) {
+ buffer_reset(b->ptr[i]);
+ }
+
+ b->used = 0;
+}
+
+
+/**
+ * free the buffer_array
+ *
+ */
+
+void buffer_array_free(buffer_array *b) {
+ size_t i;
+ if (!b) return;
+
+ for (i = 0; i < b->size; i++) {
+ if (b->ptr[i]) buffer_free(b->ptr[i]);
+ }
+ free(b->ptr);
+ free(b);
+}
+
+buffer *buffer_array_append_get_buffer(buffer_array *b) {
+ size_t i;
+
+ if (b->size == 0) {
+ b->size = 16;
+ b->ptr = malloc(sizeof(*b->ptr) * b->size);
+ assert(b->ptr);
+ for (i = 0; i < b->size; i++) {
+ b->ptr[i] = NULL;
+ }
+ } else if (b->size == b->used) {
+ b->size += 16;
+ b->ptr = realloc(b->ptr, sizeof(*b->ptr) * b->size);
+ assert(b->ptr);
+ for (i = b->used; i < b->size; i++) {
+ b->ptr[i] = NULL;
+ }
+ }
+
+ if (b->ptr[b->used] == NULL) {
+ b->ptr[b->used] = buffer_init();
+ }
+
+ b->ptr[b->used]->used = 0;
+
+ return b->ptr[b->used++];
+}
+
+
+char * buffer_search_string_len(buffer *b, const char *needle, size_t len) {
+ size_t i;
+ if (len == 0) return NULL;
+ if (needle == NULL) return NULL;
+
+ if (b->used < len) return NULL;
+
+ for(i = 0; i < b->used - len; i++) {
+ if (0 == memcmp(b->ptr + i, needle, len)) {
+ return b->ptr + i;
+ }
+ }
+
+ return NULL;
+}
+
+buffer *buffer_init_string(const char *str) {
+ buffer *b = buffer_init();
+
+ buffer_copy_string(b, str);
+
+ return b;
+}
+
+int buffer_is_empty(buffer *b) {
+ if (!b) return 1;
+ return (b->used == 0);
+}
+
+/**
+ * check if two buffer contain the same data
+ *
+ * HISTORY: this function was pretty much optimized, but didn't handled
+ * alignment properly.
+ */
+
+int buffer_is_equal(buffer *a, buffer *b) {
+ if (a->used != b->used) return 0;
+ if (a->used == 0) return 1;
+
+ return (0 == strcmp(a->ptr, b->ptr));
+}
+
+int buffer_is_equal_string(buffer *a, const char *s, size_t b_len) {
+ buffer b;
+
+ b.ptr = (char *)s;
+ b.used = b_len + 1;
+
+ return buffer_is_equal(a, &b);
+}
+
+/* simple-assumption:
+ *
+ * most parts are equal and doing a case conversion needs time
+ *
+ */
+int buffer_caseless_compare(const char *a, size_t a_len, const char *b, size_t b_len) {
+ size_t ndx = 0, max_ndx;
+ size_t *al, *bl;
+ size_t mask = sizeof(*al) - 1;
+
+ al = (size_t *)a;
+ bl = (size_t *)b;
+
+ /* is the alignment correct ? */
+ if ( ((size_t)al & mask) == 0 &&
+ ((size_t)bl & mask) == 0 ) {
+
+ max_ndx = ((a_len < b_len) ? a_len : b_len) & ~mask;
+
+ for (; ndx < max_ndx; ndx += sizeof(*al)) {
+ if (*al != *bl) break;
+ al++; bl++;
+
+ }
+
+ }
+
+ a = (char *)al;
+ b = (char *)bl;
+
+ max_ndx = ((a_len < b_len) ? a_len : b_len);
+
+ for (; ndx < max_ndx; ndx++) {
+ char a1 = *a++, b1 = *b++;
+
+ if (a1 != b1) {
+ if ((a1 >= 'A' && a1 <= 'Z') && (b1 >= 'a' && b1 <= 'z'))
+ a1 |= 32;
+ else if ((a1 >= 'a' && a1 <= 'z') && (b1 >= 'A' && b1 <= 'Z'))
+ b1 |= 32;
+ if ((a1 - b1) != 0) return (a1 - b1);
+
+ }
+ }
+
+ /* all chars are the same, and the length match too
+ *
+ * they are the same */
+ if (a_len == b_len) return 0;
+
+ /* if a is shorter then b, then b is larger */
+ return (a_len - b_len);
+}
+
+
+/**
+ * check if the rightmost bytes of the string are equal.
+ *
+ *
+ */
+
+int buffer_is_equal_right_len(buffer *b1, buffer *b2, size_t len) {
+ /* no, len -> equal */
+ if (len == 0) return 1;
+
+ /* len > 0, but empty buffers -> not equal */
+ if (b1->used == 0 || b2->used == 0) return 0;
+
+ /* buffers too small -> not equal */
+ if (b1->used - 1 < len || b1->used - 1 < len) return 0;
+
+ if (0 == strncmp(b1->ptr + b1->used - 1 - len,
+ b2->ptr + b2->used - 1 - len, len)) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int buffer_copy_string_hex(buffer *b, const char *in, size_t in_len) {
+ size_t i;
+
+ /* BO protection */
+ if (in_len * 2 < in_len) return -1;
+
+ buffer_prepare_copy(b, in_len * 2 + 1);
+
+ for (i = 0; i < in_len; i++) {
+ b->ptr[b->used++] = hex_chars[(in[i] >> 4) & 0x0F];
+ b->ptr[b->used++] = hex_chars[in[i] & 0x0F];
+ }
+ b->ptr[b->used++] = '\0';
+
+ return 0;
+}
+
+const char encoded_chars_rel_uri_part[] = {
+ /*
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F control chars */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */
+ 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, /* 20 - 2F space " # $ % & ' + , / */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, /* 30 - 3F : ; = ? @ < > */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50 - 5F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 70 - 7F DEL */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80 - 8F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 90 - 9F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* A0 - AF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* B0 - BF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* C0 - CF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* D0 - DF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* E0 - EF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* F0 - FF */
+};
+
+const char encoded_chars_rel_uri[] = {
+ /*
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F control chars */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */
+ 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, /* 20 - 2F space " # $ % & ' + , / */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, /* 30 - 3F : ; = ? @ < > */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50 - 5F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 70 - 7F DEL */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80 - 8F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 90 - 9F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* A0 - AF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* B0 - BF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* C0 - CF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* D0 - DF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* E0 - EF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* F0 - FF */
+};
+
+const char encoded_chars_html[] = {
+ /*
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F control chars */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */
+ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 2F & */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, /* 30 - 3F < > */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50 - 5F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 70 - 7F DEL */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80 - 8F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 90 - 9F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* A0 - AF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* B0 - BF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* C0 - CF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* D0 - DF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* E0 - EF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* F0 - FF */
+};
+
+const char encoded_chars_minimal_xml[] = {
+ /*
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F control chars */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */
+ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 2F & */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, /* 30 - 3F < > */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50 - 5F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 70 - 7F DEL */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */
+};
+
+const char encoded_chars_hex[] = {
+ /*
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F control chars */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 - 3F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 70 - 7F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80 - 8F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 90 - 9F */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* A0 - AF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* B0 - BF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* C0 - CF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* D0 - DF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* E0 - EF */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* F0 - FF */
+};
+
+const char encoded_chars_http_header[] = {
+ /*
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* 00 - 0F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 2F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 30 - 3F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50 - 5F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 70 - 7F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */
+};
+
+
+
+int buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_encoding_t encoding) {
+ unsigned char *ds, *d;
+ size_t d_len, ndx;
+ const char *map = NULL;
+
+ if (!s || !b) return -1;
+
+ if (b->ptr[b->used - 1] != '\0') {
+ SEGFAULT();
+ }
+
+ if (s_len == 0) return 0;
+
+ switch(encoding) {
+ case ENCODING_REL_URI:
+ map = encoded_chars_rel_uri;
+ break;
+ case ENCODING_REL_URI_PART:
+ map = encoded_chars_rel_uri_part;
+ break;
+ case ENCODING_HTML:
+ map = encoded_chars_html;
+ break;
+ case ENCODING_MINIMAL_XML:
+ map = encoded_chars_minimal_xml;
+ break;
+ case ENCODING_HEX:
+ map = encoded_chars_hex;
+ break;
+ case ENCODING_HTTP_HEADER:
+ map = encoded_chars_http_header;
+ break;
+ case ENCODING_UNSET:
+ break;
+ }
+
+ assert(map != NULL);
+
+ /* count to-be-encoded-characters */
+ for (ds = (unsigned char *)s, d_len = 0, ndx = 0; ndx < s_len; ds++, ndx++) {
+ if (map[*ds]) {
+ switch(encoding) {
+ case ENCODING_REL_URI:
+ case ENCODING_REL_URI_PART:
+ d_len += 3;
+ break;
+ case ENCODING_HTML:
+ case ENCODING_MINIMAL_XML:
+ d_len += 6;
+ break;
+ case ENCODING_HTTP_HEADER:
+ case ENCODING_HEX:
+ d_len += 2;
+ break;
+ case ENCODING_UNSET:
+ break;
+ }
+ } else {
+ d_len ++;
+ }
+ }
+
+ buffer_prepare_append(b, d_len);
+
+ for (ds = (unsigned char *)s, d = (unsigned char *)b->ptr + b->used - 1, d_len = 0, ndx = 0; ndx < s_len; ds++, ndx++) {
+ if (map[*ds]) {
+ switch(encoding) {
+ case ENCODING_REL_URI:
+ case ENCODING_REL_URI_PART:
+ d[d_len++] = '%';
+ d[d_len++] = hex_chars[((*ds) >> 4) & 0x0F];
+ d[d_len++] = hex_chars[(*ds) & 0x0F];
+ break;
+ case ENCODING_HTML:
+ case ENCODING_MINIMAL_XML:
+ d[d_len++] = '&';
+ d[d_len++] = '#';
+ d[d_len++] = 'x';
+ d[d_len++] = hex_chars[((*ds) >> 4) & 0x0F];
+ d[d_len++] = hex_chars[(*ds) & 0x0F];
+ d[d_len++] = ';';
+ break;
+ case ENCODING_HEX:
+ d[d_len++] = hex_chars[((*ds) >> 4) & 0x0F];
+ d[d_len++] = hex_chars[(*ds) & 0x0F];
+ break;
+ case ENCODING_HTTP_HEADER:
+ d[d_len++] = *ds;
+ d[d_len++] = '\t';
+ break;
+ case ENCODING_UNSET:
+ break;
+ }
+ } else {
+ d[d_len++] = *ds;
+ }
+ }
+
+ /* terminate buffer and calculate new length */
+ b->ptr[b->used + d_len - 1] = '\0';
+
+ b->used += d_len;
+
+ return 0;
+}
+
+
+/* decodes url-special-chars inplace.
+ * replaces non-printable characters with '_'
+ */
+
+static int buffer_urldecode_internal(buffer *url, int is_query) {
+ unsigned char high, low;
+ const char *src;
+ char *dst;
+
+ if (!url || !url->ptr) return -1;
+
+ src = (const char*) url->ptr;
+ dst = (char*) url->ptr;
+
+ while ((*src) != '\0') {
+ if (is_query && *src == '+') {
+ *dst = ' ';
+ } else if (*src == '%') {
+ *dst = '%';
+
+ high = hex2int(*(src + 1));
+ if (high != 0xFF) {
+ low = hex2int(*(src + 2));
+ if (low != 0xFF) {
+ high = (high << 4) | low;
+
+ /* map control-characters out */
+ if (high < 32 || high == 127) high = '_';
+
+ *dst = high;
+ src += 2;
+ }
+ }
+ } else {
+ *dst = *src;
+ }
+
+ dst++;
+ src++;
+ }
+
+ *dst = '\0';
+ url->used = (dst - url->ptr) + 1;
+
+ return 0;
+}
+
+int buffer_urldecode_path(buffer *url) {
+ return buffer_urldecode_internal(url, 0);
+}
+
+int buffer_urldecode_query(buffer *url) {
+ return buffer_urldecode_internal(url, 1);
+}
+
+/* Remove "/../", "//", "/./" parts from path.
+ *
+ * /blah/.. gets /
+ * /blah/../foo gets /foo
+ * /abc/./xyz gets /abc/xyz
+ * /abc//xyz gets /abc/xyz
+ *
+ * NOTE: src and dest can point to the same buffer, in which case,
+ * the operation is performed in-place.
+ */
+
+int buffer_path_simplify(buffer *dest, buffer *src)
+{
+ int toklen;
+ char c, pre1;
+ char *start, *slash, *walk, *out;
+ unsigned short pre;
+
+ if (src == NULL || src->ptr == NULL || dest == NULL)
+ return -1;
+
+ if (src == dest)
+ buffer_prepare_append(dest, 1);
+ else
+ buffer_prepare_copy(dest, src->used + 1);
+
+ walk = src->ptr;
+ start = dest->ptr;
+ out = dest->ptr;
+ slash = dest->ptr;
+
+
+#if defined(__WIN32) || defined(__CYGWIN__)
+ /* cygwin is treating \ and / the same, so we have to that too
+ */
+
+ for (walk = src->ptr; *walk; walk++) {
+ if (*walk == '\\') *walk = '/';
+ }
+ walk = src->ptr;
+#endif
+
+ while (*walk == ' ') {
+ walk++;
+ }
+
+ pre1 = *(walk++);
+ c = *(walk++);
+ pre = pre1;
+ if (pre1 != '/') {
+ pre = ('/' << 8) | pre1;
+ *(out++) = '/';
+ }
+ *(out++) = pre1;
+
+ if (pre1 == '\0') {
+ dest->used = (out - start) + 1;
+ return 0;
+ }
+
+ while (1) {
+ if (c == '/' || c == '\0') {
+ toklen = out - slash;
+ if (toklen == 3 && pre == (('.' << 8) | '.')) {
+ out = slash;
+ if (out > start) {
+ out--;
+ while (out > start && *out != '/') {
+ out--;
+ }
+ }
+
+ if (c == '\0')
+ out++;
+ } else if (toklen == 1 || pre == (('/' << 8) | '.')) {
+ out = slash;
+ if (c == '\0')
+ out++;
+ }
+
+ slash = out;
+ }
+
+ if (c == '\0')
+ break;
+
+ pre1 = c;
+ pre = (pre << 8) | pre1;
+ c = *walk;
+ *out = pre1;
+
+ out++;
+ walk++;
+ }
+
+ *out = '\0';
+ dest->used = (out - start) + 1;
+
+ return 0;
+}
+
+int light_isdigit(int c) {
+ return (c >= '0' && c <= '9');
+}
+
+int light_isxdigit(int c) {
+ if (light_isdigit(c)) return 1;
+
+ c |= 32;
+ return (c >= 'a' && c <= 'f');
+}
+
+int light_isalpha(int c) {
+ c |= 32;
+ return (c >= 'a' && c <= 'z');
+}
+
+int light_isalnum(int c) {
+ return light_isdigit(c) || light_isalpha(c);
+}
+
+int buffer_to_lower(buffer *b) {
+ char *c;
+
+ if (b->used == 0) return 0;
+
+ for (c = b->ptr; *c; c++) {
+ if (*c >= 'A' && *c <= 'Z') {
+ *c |= 32;
+ }
+ }
+
+ return 0;
+}
+
+
+int buffer_to_upper(buffer *b) {
+ char *c;
+
+ if (b->used == 0) return 0;
+
+ for (c = b->ptr; *c; c++) {
+ if (*c >= 'a' && *c <= 'z') {
+ *c &= ~32;
+ }
+ }
+
+ return 0;
+}
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/buffer.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/buffer.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/buffer.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/buffer.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,131 @@
+#ifndef _BUFFER_H_
+#define _BUFFER_H_
+
+#include <stdlib.h>
+#include <sys/types.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "settings.h"
+
+typedef struct {
+ char *ptr;
+
+ size_t used;
+ size_t size;
+} buffer;
+
+typedef struct {
+ buffer **ptr;
+
+ size_t used;
+ size_t size;
+} buffer_array;
+
+typedef struct {
+ char *ptr;
+
+ size_t offset; /* input-pointer */
+
+ size_t used; /* output-pointer */
+ size_t size;
+} read_buffer;
+
+buffer_array* buffer_array_init(void);
+void buffer_array_free(buffer_array *b);
+void buffer_array_reset(buffer_array *b);
+buffer *buffer_array_append_get_buffer(buffer_array *b);
+
+buffer* buffer_init(void);
+buffer* buffer_init_buffer(buffer *b);
+buffer* buffer_init_string(const char *str);
+void buffer_free(buffer *b);
+void buffer_reset(buffer *b);
+
+int buffer_prepare_copy(buffer *b, size_t size);
+int buffer_prepare_append(buffer *b, size_t size);
+
+int buffer_copy_string(buffer *b, const char *s);
+int buffer_copy_string_len(buffer *b, const char *s, size_t s_len);
+int buffer_copy_string_buffer(buffer *b, const buffer *src);
+int buffer_copy_string_hex(buffer *b, const char *in, size_t in_len);
+
+int buffer_copy_long(buffer *b, long val);
+
+int buffer_copy_memory(buffer *b, const char *s, size_t s_len);
+
+int buffer_append_string(buffer *b, const char *s);
+int buffer_append_string_len(buffer *b, const char *s, size_t s_len);
+int buffer_append_string_buffer(buffer *b, const buffer *src);
+int buffer_append_string_lfill(buffer *b, const char *s, size_t maxlen);
+int buffer_append_string_rfill(buffer *b, const char *s, size_t maxlen);
+
+int buffer_append_long_hex(buffer *b, unsigned long len);
+int buffer_append_long(buffer *b, long val);
+
+#if defined(SIZEOF_LONG) && (SIZEOF_LONG == SIZEOF_OFF_T)
+#define buffer_copy_off_t(x, y) buffer_copy_long(x, y)
+#define buffer_append_off_t(x, y) buffer_append_long(x, y)
+#else
+int buffer_copy_off_t(buffer *b, off_t val);
+int buffer_append_off_t(buffer *b, off_t val);
+#endif
+
+int buffer_append_memory(buffer *b, const char *s, size_t s_len);
+
+char * buffer_search_string_len(buffer *b, const char *needle, size_t len);
+
+int buffer_is_empty(buffer *b);
+int buffer_is_equal(buffer *a, buffer *b);
+int buffer_is_equal_right_len(buffer *a, buffer *b, size_t len);
+int buffer_is_equal_string(buffer *a, const char *s, size_t b_len);
+int buffer_caseless_compare(const char *a, size_t a_len, const char *b, size_t b_len);
+
+typedef enum {
+ ENCODING_UNSET,
+ ENCODING_REL_URI, /* for coding a rel-uri (/with space/and%percent) nicely as part of a href */
+ ENCODING_REL_URI_PART, /* same as ENC_REL_URL plus coding / too as %2F */
+ ENCODING_HTML, /* & becomes & and so on */
+ ENCODING_MINIMAL_XML, /* minimal encoding for xml */
+ ENCODING_HEX, /* encode string as hex */
+ ENCODING_HTTP_HEADER /* encode \n with \t\n */
+} buffer_encoding_t;
+
+int buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_encoding_t encoding);
+
+int buffer_urldecode_path(buffer *url);
+int buffer_urldecode_query(buffer *url);
+int buffer_path_simplify(buffer *dest, buffer *src);
+
+int buffer_to_lower(buffer *b);
+int buffer_to_upper(buffer *b);
+
+/** deprecated */
+int LI_ltostr(char *buf, long val);
+char hex2int(unsigned char c);
+char int2hex(char i);
+
+int light_isdigit(int c);
+int light_isxdigit(int c);
+int light_isalpha(int c);
+int light_isalnum(int c);
+
+#define BUFFER_APPEND_STRING_CONST(x, y) \
+ buffer_append_string_len(x, y, sizeof(y) - 1)
+
+#define BUFFER_COPY_STRING_CONST(x, y) \
+ buffer_copy_string_len(x, y, sizeof(y) - 1)
+
+#define BUFFER_APPEND_SLASH(x) \
+ if (x->used > 1 && x->ptr[x->used - 2] != '/') { BUFFER_APPEND_STRING_CONST(x, "/"); }
+
+#define CONST_STR_LEN(x) x, x ? sizeof(x) - 1 : 0
+#define CONST_BUF_LEN(x) x->ptr, x->used ? x->used - 1 : 0
+
+
+#define SEGFAULT() do { fprintf(stderr, "%s.%d: aborted\n", __FILE__, __LINE__); abort(); } while(0)
+#define UNUSED(x) ( (void)(x) )
+
+#endif
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/chunk.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/chunk.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/chunk.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/chunk.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,402 @@
+/**
+ * the network chunk-API
+ *
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include "chunk.h"
+
+chunkqueue *chunkqueue_init(void) {
+ chunkqueue *cq;
+
+ cq = calloc(1, sizeof(*cq));
+
+ cq->first = NULL;
+ cq->last = NULL;
+
+ cq->unused = NULL;
+
+ return cq;
+}
+
+static chunk *chunk_init(void) {
+ chunk *c;
+
+ c = calloc(1, sizeof(*c));
+
+ c->mem = buffer_init();
+ c->file.name = buffer_init();
+ c->file.fd = -1;
+ c->file.mmap.start = MAP_FAILED;
+ c->next = NULL;
+
+ return c;
+}
+
+static void chunk_free(chunk *c) {
+ if (!c) return;
+
+ buffer_free(c->mem);
+ buffer_free(c->file.name);
+
+ free(c);
+}
+
+static void chunk_reset(chunk *c) {
+ if (!c) return;
+
+ buffer_reset(c->mem);
+
+ if (c->file.is_temp && !buffer_is_empty(c->file.name)) {
+ unlink(c->file.name->ptr);
+ }
+
+ buffer_reset(c->file.name);
+
+ if (c->file.fd != -1) {
+ close(c->file.fd);
+ c->file.fd = -1;
+ }
+ if (MAP_FAILED != c->file.mmap.start) {
+ munmap(c->file.mmap.start, c->file.mmap.length);
+ c->file.mmap.start = MAP_FAILED;
+ }
+}
+
+
+void chunkqueue_free(chunkqueue *cq) {
+ chunk *c, *pc;
+
+ if (!cq) return;
+
+ for (c = cq->first; c; ) {
+ pc = c;
+ c = c->next;
+ chunk_free(pc);
+ }
+
+ for (c = cq->unused; c; ) {
+ pc = c;
+ c = c->next;
+ chunk_free(pc);
+ }
+
+ free(cq);
+}
+
+static chunk *chunkqueue_get_unused_chunk(chunkqueue *cq) {
+ chunk *c;
+
+ /* check if we have a unused chunk */
+ if (!cq->unused) {
+ c = chunk_init();
+ } else {
+ /* take the first element from the list (a stack) */
+ c = cq->unused;
+ cq->unused = c->next;
+ c->next = NULL;
+ cq->unused_chunks--;
+ }
+
+ return c;
+}
+
+static int chunkqueue_prepend_chunk(chunkqueue *cq, chunk *c) {
+ c->next = cq->first;
+ cq->first = c;
+
+ if (cq->last == NULL) {
+ cq->last = c;
+ }
+
+ return 0;
+}
+
+static int chunkqueue_append_chunk(chunkqueue *cq, chunk *c) {
+ if (cq->last) {
+ cq->last->next = c;
+ }
+ cq->last = c;
+
+ if (cq->first == NULL) {
+ cq->first = c;
+ }
+
+ return 0;
+}
+
+void chunkqueue_reset(chunkqueue *cq) {
+ chunk *c;
+ /* move everything to the unused queue */
+
+ /* mark all read written */
+ for (c = cq->first; c; c = c->next) {
+ switch(c->type) {
+ case MEM_CHUNK:
+ c->offset = c->mem->used - 1;
+ break;
+ case FILE_CHUNK:
+ c->offset = c->file.length;
+ break;
+ default:
+ break;
+ }
+ }
+
+ chunkqueue_remove_finished_chunks(cq);
+ cq->bytes_in = 0;
+ cq->bytes_out = 0;
+}
+
+int chunkqueue_append_file(chunkqueue *cq, buffer *fn, off_t offset, off_t len) {
+ chunk *c;
+
+ if (len == 0) return 0;
+
+ c = chunkqueue_get_unused_chunk(cq);
+
+ c->type = FILE_CHUNK;
+
+ buffer_copy_string_buffer(c->file.name, fn);
+ c->file.start = offset;
+ c->file.length = len;
+ c->offset = 0;
+
+ chunkqueue_append_chunk(cq, c);
+
+ return 0;
+}
+
+int chunkqueue_append_buffer(chunkqueue *cq, buffer *mem) {
+ chunk *c;
+
+ if (mem->used == 0) return 0;
+
+ c = chunkqueue_get_unused_chunk(cq);
+ c->type = MEM_CHUNK;
+ c->offset = 0;
+ buffer_copy_string_buffer(c->mem, mem);
+
+ chunkqueue_append_chunk(cq, c);
+
+ return 0;
+}
+
+int chunkqueue_append_buffer_weak(chunkqueue *cq, buffer *mem) {
+ chunk *c;
+
+ if (mem->used == 0) return 0;
+
+ c = chunkqueue_get_unused_chunk(cq);
+ c->type = MEM_CHUNK;
+ c->offset = 0;
+ if (c->mem) buffer_free(c->mem);
+ c->mem = mem;
+
+ chunkqueue_append_chunk(cq, c);
+
+ return 0;
+}
+
+int chunkqueue_prepend_buffer(chunkqueue *cq, buffer *mem) {
+ chunk *c;
+
+ if (mem->used == 0) return 0;
+
+ c = chunkqueue_get_unused_chunk(cq);
+ c->type = MEM_CHUNK;
+ c->offset = 0;
+ buffer_copy_string_buffer(c->mem, mem);
+
+ chunkqueue_prepend_chunk(cq, c);
+
+ return 0;
+}
+
+
+int chunkqueue_append_mem(chunkqueue *cq, const char * mem, size_t len) {
+ chunk *c;
+
+ if (len == 0) return 0;
+
+ c = chunkqueue_get_unused_chunk(cq);
+ c->type = MEM_CHUNK;
+ c->offset = 0;
+ buffer_copy_string_len(c->mem, mem, len - 1);
+
+ chunkqueue_append_chunk(cq, c);
+
+ return 0;
+}
+
+buffer * chunkqueue_get_prepend_buffer(chunkqueue *cq) {
+ chunk *c;
+
+ c = chunkqueue_get_unused_chunk(cq);
+
+ c->type = MEM_CHUNK;
+ c->offset = 0;
+ buffer_reset(c->mem);
+
+ chunkqueue_prepend_chunk(cq, c);
+
+ return c->mem;
+}
+
+buffer *chunkqueue_get_append_buffer(chunkqueue *cq) {
+ chunk *c;
+
+ c = chunkqueue_get_unused_chunk(cq);
+
+ c->type = MEM_CHUNK;
+ c->offset = 0;
+ buffer_reset(c->mem);
+
+ chunkqueue_append_chunk(cq, c);
+
+ return c->mem;
+}
+
+int chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs) {
+ if (!cq) return -1;
+
+ cq->tempdirs = tempdirs;
+
+ return 0;
+}
+
+chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) {
+ chunk *c;
+ buffer *template = buffer_init_string("/var/tmp/lighttpd-upload-XXXXXX");
+
+ c = chunkqueue_get_unused_chunk(cq);
+
+ c->type = FILE_CHUNK;
+ c->offset = 0;
+
+ if (cq->tempdirs && cq->tempdirs->used) {
+ size_t i;
+
+ /* we have several tempdirs, only if all of them fail we jump out */
+
+ for (i = 0; i < cq->tempdirs->used; i++) {
+ data_string *ds = (data_string *)cq->tempdirs->data[i];
+
+ buffer_copy_string_buffer(template, ds->value);
+ BUFFER_APPEND_SLASH(template);
+ BUFFER_APPEND_STRING_CONST(template, "lighttpd-upload-XXXXXX");
+
+ if (-1 != (c->file.fd = mkstemp(template->ptr))) {
+ /* only trigger the unlink if we created the temp-file successfully */
+ c->file.is_temp = 1;
+ break;
+ }
+ }
+ } else {
+ if (-1 != (c->file.fd = mkstemp(template->ptr))) {
+ /* only trigger the unlink if we created the temp-file successfully */
+ c->file.is_temp = 1;
+ }
+ }
+
+ buffer_copy_string_buffer(c->file.name, template);
+ c->file.length = 0;
+
+ chunkqueue_append_chunk(cq, c);
+
+ buffer_free(template);
+
+ return c;
+}
+
+
+off_t chunkqueue_length(chunkqueue *cq) {
+ off_t len = 0;
+ chunk *c;
+
+ for (c = cq->first; c; c = c->next) {
+ switch (c->type) {
+ case MEM_CHUNK:
+ len += c->mem->used ? c->mem->used - 1 : 0;
+ break;
+ case FILE_CHUNK:
+ len += c->file.length;
+ break;
+ default:
+ break;
+ }
+ }
+
+ return len;
+}
+
+off_t chunkqueue_written(chunkqueue *cq) {
+ off_t len = 0;
+ chunk *c;
+
+ for (c = cq->first; c; c = c->next) {
+ switch (c->type) {
+ case MEM_CHUNK:
+ case FILE_CHUNK:
+ len += c->offset;
+ break;
+ default:
+ break;
+ }
+ }
+
+ return len;
+}
+
+int chunkqueue_is_empty(chunkqueue *cq) {
+ return cq->first ? 0 : 1;
+}
+
+int chunkqueue_remove_finished_chunks(chunkqueue *cq) {
+ chunk *c;
+
+ for (c = cq->first; c; c = cq->first) {
+ int is_finished = 0;
+
+ switch (c->type) {
+ case MEM_CHUNK:
+ if (c->mem->used == 0 || (c->offset == (off_t)c->mem->used - 1)) is_finished = 1;
+ break;
+ case FILE_CHUNK:
+ if (c->offset == c->file.length) is_finished = 1;
+ break;
+ default:
+ break;
+ }
+
+ if (!is_finished) break;
+
+ chunk_reset(c);
+
+ cq->first = c->next;
+ if (c == cq->last) cq->last = NULL;
+
+ /* keep at max 4 chunks in the 'unused'-cache */
+ if (cq->unused_chunks > 4) {
+ chunk_free(c);
+ } else {
+ c->next = cq->unused;
+ cq->unused = c;
+ cq->unused_chunks++;
+ }
+ }
+
+ return 0;
+}
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/chunk.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/chunk.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/chunk.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/chunk.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,71 @@
+#ifndef _CHUNK_H_
+#define _CHUNK_H_
+
+#include "buffer.h"
+#include "array.h"
+
+typedef struct chunk {
+ enum { UNUSED_CHUNK, MEM_CHUNK, FILE_CHUNK } type;
+
+ buffer *mem; /* either the storage of the mem-chunk or the read-ahead buffer */
+
+ struct {
+ /* filechunk */
+ buffer *name; /* name of the file */
+ off_t start; /* starting offset in the file */
+ off_t length; /* octets to send from the starting offset */
+
+ int fd;
+ struct {
+ char *start; /* the start pointer of the mmap'ed area */
+ size_t length; /* size of the mmap'ed area */
+ off_t offset; /* start is <n> octet away from the start of the file */
+ } mmap;
+
+ int is_temp; /* file is temporary and will be deleted if on cleanup */
+ } file;
+
+ off_t offset; /* octets sent from this chunk
+ the size of the chunk is either
+ - mem-chunk: mem->used - 1
+ - file-chunk: file.length
+ */
+
+ struct chunk *next;
+} chunk;
+
+typedef struct {
+ chunk *first;
+ chunk *last;
+
+ chunk *unused;
+ size_t unused_chunks;
+
+ array *tempdirs;
+
+ off_t bytes_in, bytes_out;
+} chunkqueue;
+
+chunkqueue *chunkqueue_init(void);
+int chunkqueue_set_tempdirs(chunkqueue *c, array *tempdirs);
+int chunkqueue_append_file(chunkqueue *c, buffer *fn, off_t offset, off_t len);
+int chunkqueue_append_mem(chunkqueue *c, const char *mem, size_t len);
+
+int chunkqueue_append_buffer(chunkqueue *c, buffer *mem);
+int chunkqueue_append_buffer_weak(chunkqueue *c, buffer *mem);
+int chunkqueue_prepend_buffer(chunkqueue *c, buffer *mem);
+
+buffer * chunkqueue_get_append_buffer(chunkqueue *c);
+buffer * chunkqueue_get_prepend_buffer(chunkqueue *c);
+chunk * chunkqueue_get_append_tempfile(chunkqueue *cq);
+
+int chunkqueue_remove_finished_chunks(chunkqueue *cq);
+
+off_t chunkqueue_length(chunkqueue *c);
+off_t chunkqueue_written(chunkqueue *c);
+void chunkqueue_free(chunkqueue *c);
+void chunkqueue_reset(chunkqueue *c);
+
+int chunkqueue_is_empty(chunkqueue *c);
+
+#endif