You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2008/07/22 06:35:46 UTC

svn commit: r678637 [37/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/mod_setenv.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_setenv.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_setenv.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_setenv.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,247 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "base.h"
+#include "log.h"
+#include "buffer.h"
+
+#include "plugin.h"
+
+#include "response.h"
+
+/* plugin config for all request/connections */
+
+typedef struct {
+	int handled; /* make sure that we only apply the headers once */
+} handler_ctx;
+
+typedef struct {
+	array *request_header;
+	array *response_header;
+
+	array *environment;
+} plugin_config;
+
+typedef struct {
+	PLUGIN_DATA;
+
+	plugin_config **config_storage;
+
+	plugin_config conf;
+} plugin_data;
+
+static handler_ctx * handler_ctx_init() {
+	handler_ctx * hctx;
+
+	hctx = calloc(1, sizeof(*hctx));
+
+	hctx->handled = 0;
+
+	return hctx;
+}
+
+static void handler_ctx_free(handler_ctx *hctx) {
+	free(hctx);
+}
+
+
+/* init the plugin data */
+INIT_FUNC(mod_setenv_init) {
+	plugin_data *p;
+
+	p = calloc(1, sizeof(*p));
+
+	return p;
+}
+
+/* detroy the plugin data */
+FREE_FUNC(mod_setenv_free) {
+	plugin_data *p = p_d;
+
+	UNUSED(srv);
+
+	if (!p) return HANDLER_GO_ON;
+
+	if (p->config_storage) {
+		size_t i;
+		for (i = 0; i < srv->config_context->used; i++) {
+			plugin_config *s = p->config_storage[i];
+
+			array_free(s->request_header);
+			array_free(s->response_header);
+			array_free(s->environment);
+
+			free(s);
+		}
+		free(p->config_storage);
+	}
+
+	free(p);
+
+	return HANDLER_GO_ON;
+}
+
+/* handle plugin config and check values */
+
+SETDEFAULTS_FUNC(mod_setenv_set_defaults) {
+	plugin_data *p = p_d;
+	size_t i = 0;
+
+	config_values_t cv[] = {
+		{ "setenv.add-request-header",  NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
+		{ "setenv.add-response-header", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 1 */
+		{ "setenv.add-environment",     NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 2 */
+		{ NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
+	};
+
+	if (!p) return HANDLER_ERROR;
+
+	p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
+
+	for (i = 0; i < srv->config_context->used; i++) {
+		plugin_config *s;
+
+		s = calloc(1, sizeof(plugin_config));
+		s->request_header   = array_init();
+		s->response_header  = array_init();
+		s->environment      = array_init();
+
+		cv[0].destination = s->request_header;
+		cv[1].destination = s->response_header;
+		cv[2].destination = s->environment;
+
+		p->config_storage[i] = s;
+
+		if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
+			return HANDLER_ERROR;
+		}
+	}
+
+	return HANDLER_GO_ON;
+}
+
+#define PATCH(x) \
+	p->conf.x = s->x;
+static int mod_setenv_patch_connection(server *srv, connection *con, plugin_data *p) {
+	size_t i, j;
+	plugin_config *s = p->config_storage[0];
+
+	PATCH(request_header);
+	PATCH(response_header);
+	PATCH(environment);
+
+	/* skip the first, the global context */
+	for (i = 1; i < srv->config_context->used; i++) {
+		data_config *dc = (data_config *)srv->config_context->data[i];
+		s = p->config_storage[i];
+
+		/* condition didn't match */
+		if (!config_check_cond(srv, con, dc)) continue;
+
+		/* merge config */
+		for (j = 0; j < dc->value->used; j++) {
+			data_unset *du = dc->value->data[j];
+
+			if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-request-header"))) {
+				PATCH(request_header);
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-response-header"))) {
+				PATCH(response_header);
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-environment"))) {
+				PATCH(environment);
+			}
+		}
+	}
+
+	return 0;
+}
+#undef PATCH
+
+URIHANDLER_FUNC(mod_setenv_uri_handler) {
+	plugin_data *p = p_d;
+	size_t k;
+	handler_ctx *hctx;
+
+	if (con->plugin_ctx[p->id]) {
+		hctx = con->plugin_ctx[p->id];
+	} else {
+		hctx = handler_ctx_init();
+
+		con->plugin_ctx[p->id] = hctx;
+	}
+
+	if (hctx->handled) {
+		return HANDLER_GO_ON;
+	}
+
+	hctx->handled = 1;
+
+	mod_setenv_patch_connection(srv, con, p);
+
+	for (k = 0; k < p->conf.request_header->used; k++) {
+		data_string *ds = (data_string *)p->conf.request_header->data[k];
+		data_string *ds_dst;
+
+		if (NULL == (ds_dst = (data_string *)array_get_unused_element(con->request.headers, TYPE_STRING))) {
+			ds_dst = data_string_init();
+		}
+
+		buffer_copy_string_buffer(ds_dst->key, ds->key);
+		buffer_copy_string_buffer(ds_dst->value, ds->value);
+
+		array_insert_unique(con->request.headers, (data_unset *)ds_dst);
+	}
+
+	for (k = 0; k < p->conf.environment->used; k++) {
+		data_string *ds = (data_string *)p->conf.environment->data[k];
+		data_string *ds_dst;
+
+		if (NULL == (ds_dst = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
+			ds_dst = data_string_init();
+		}
+
+		buffer_copy_string_buffer(ds_dst->key, ds->key);
+		buffer_copy_string_buffer(ds_dst->value, ds->value);
+
+		array_insert_unique(con->environment, (data_unset *)ds_dst);
+	}
+
+	for (k = 0; k < p->conf.response_header->used; k++) {
+		data_string *ds = (data_string *)p->conf.response_header->data[k];
+
+		response_header_insert(srv, con, CONST_BUF_LEN(ds->key), CONST_BUF_LEN(ds->value));
+	}
+
+	/* not found */
+	return HANDLER_GO_ON;
+}
+
+REQUESTDONE_FUNC(mod_setenv_reset) {
+	plugin_data *p = p_d;
+
+	UNUSED(srv);
+
+	if (con->plugin_ctx[p->id]) {
+		handler_ctx_free(con->plugin_ctx[p->id]);
+		con->plugin_ctx[p->id] = NULL;
+	}
+
+	return HANDLER_GO_ON;
+}
+
+/* this function is called at dlopen() time and inits the callbacks */
+
+int mod_setenv_plugin_init(plugin *p) {
+	p->version     = LIGHTTPD_VERSION_ID;
+	p->name        = buffer_init_string("setenv");
+
+	p->init        = mod_setenv_init;
+	p->handle_uri_clean  = mod_setenv_uri_handler;
+	p->set_defaults  = mod_setenv_set_defaults;
+	p->cleanup     = mod_setenv_free;
+
+	p->handle_request_done  = mod_setenv_reset;
+
+	p->data        = NULL;
+
+	return 0;
+}

Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_simple_vhost.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_simple_vhost.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_simple_vhost.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_simple_vhost.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,281 @@
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "base.h"
+#include "log.h"
+#include "buffer.h"
+#include "stat_cache.h"
+
+#include "plugin.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+typedef struct {
+	buffer *server_root;
+	buffer *default_host;
+	buffer *document_root;
+
+	buffer *docroot_cache_key;
+	buffer *docroot_cache_value;
+	buffer *docroot_cache_servername;
+
+	unsigned short debug;
+} plugin_config;
+
+typedef struct {
+	PLUGIN_DATA;
+
+	buffer *doc_root;
+
+	plugin_config **config_storage;
+	plugin_config conf;
+} plugin_data;
+
+INIT_FUNC(mod_simple_vhost_init) {
+	plugin_data *p;
+
+	p = calloc(1, sizeof(*p));
+
+	p->doc_root = buffer_init();
+
+	return p;
+}
+
+FREE_FUNC(mod_simple_vhost_free) {
+	plugin_data *p = p_d;
+
+	UNUSED(srv);
+
+	if (!p) return HANDLER_GO_ON;
+
+	if (p->config_storage) {
+		size_t i;
+		for (i = 0; i < srv->config_context->used; i++) {
+			plugin_config *s = p->config_storage[i];
+
+			buffer_free(s->document_root);
+			buffer_free(s->default_host);
+			buffer_free(s->server_root);
+
+			buffer_free(s->docroot_cache_key);
+			buffer_free(s->docroot_cache_value);
+			buffer_free(s->docroot_cache_servername);
+
+			free(s);
+		}
+
+		free(p->config_storage);
+	}
+
+	buffer_free(p->doc_root);
+
+	free(p);
+
+	return HANDLER_GO_ON;
+}
+
+SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
+	plugin_data *p = p_d;
+	size_t i;
+
+	config_values_t cv[] = {
+		{ "simple-vhost.server-root",       NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+		{ "simple-vhost.default-host",      NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+		{ "simple-vhost.document-root",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+		{ "simple-vhost.debug",             NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
+		{ NULL,                             NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
+	};
+
+	if (!p) return HANDLER_ERROR;
+
+	p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
+
+	for (i = 0; i < srv->config_context->used; i++) {
+		plugin_config *s;
+
+		s = calloc(1, sizeof(plugin_config));
+
+		s->server_root = buffer_init();
+		s->default_host = buffer_init();
+		s->document_root = buffer_init();
+
+		s->docroot_cache_key = buffer_init();
+		s->docroot_cache_value = buffer_init();
+		s->docroot_cache_servername = buffer_init();
+
+		s->debug = 0;
+
+		cv[0].destination = s->server_root;
+		cv[1].destination = s->default_host;
+		cv[2].destination = s->document_root;
+		cv[3].destination = &(s->debug);
+
+
+		p->config_storage[i] = s;
+
+		if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
+			return HANDLER_ERROR;
+		}
+	}
+
+	return HANDLER_GO_ON;
+}
+
+static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer *out, buffer *host) {
+	stat_cache_entry *sce = NULL;
+
+	buffer_prepare_copy(out, 128);
+
+	if (p->conf.server_root->used) {
+		buffer_copy_string_buffer(out, p->conf.server_root);
+
+		if (host->used) {
+			/* a hostname has to start with a alpha-numerical character
+			 * and must not contain a slash "/"
+			 */
+			char *dp;
+
+			BUFFER_APPEND_SLASH(out);
+
+			if (NULL == (dp = strchr(host->ptr, ':'))) {
+				buffer_append_string_buffer(out, host);
+			} else {
+				buffer_append_string_len(out, host->ptr, dp - host->ptr);
+			}
+		}
+		BUFFER_APPEND_SLASH(out);
+
+		if (p->conf.document_root->used > 2 && p->conf.document_root->ptr[0] == '/') {
+			buffer_append_string_len(out, p->conf.document_root->ptr + 1, p->conf.document_root->used - 2);
+		} else {
+			buffer_append_string_buffer(out, p->conf.document_root);
+			BUFFER_APPEND_SLASH(out);
+		}
+	} else {
+		buffer_copy_string_buffer(out, con->conf.document_root);
+		BUFFER_APPEND_SLASH(out);
+	}
+
+	if (HANDLER_ERROR == stat_cache_get_entry(srv, con, out, &sce)) {
+		if (p->conf.debug) {
+			log_error_write(srv, __FILE__, __LINE__, "sb",
+					strerror(errno), out);
+		}
+		return -1;
+	} else if (!S_ISDIR(sce->st.st_mode)) {
+		return -1;
+	}
+
+	return 0;
+}
+
+
+#define PATCH(x) \
+	p->conf.x = s->x;
+static int mod_simple_vhost_patch_connection(server *srv, connection *con, plugin_data *p) {
+	size_t i, j;
+	plugin_config *s = p->config_storage[0];
+
+	PATCH(server_root);
+	PATCH(default_host);
+	PATCH(document_root);
+
+	PATCH(docroot_cache_key);
+	PATCH(docroot_cache_value);
+	PATCH(docroot_cache_servername);
+
+	PATCH(debug);
+
+	/* skip the first, the global context */
+	for (i = 1; i < srv->config_context->used; i++) {
+		data_config *dc = (data_config *)srv->config_context->data[i];
+		s = p->config_storage[i];
+
+		/* condition didn't match */
+		if (!config_check_cond(srv, con, dc)) continue;
+
+		/* merge config */
+		for (j = 0; j < dc->value->used; j++) {
+			data_unset *du = dc->value->data[j];
+
+			if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.server-root"))) {
+				PATCH(server_root);
+				PATCH(docroot_cache_key);
+				PATCH(docroot_cache_value);
+				PATCH(docroot_cache_servername);
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.default-host"))) {
+				PATCH(default_host);
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.document-root"))) {
+				PATCH(document_root);
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.debug"))) {
+				PATCH(debug);
+			}
+		}
+	}
+
+	return 0;
+}
+#undef PATCH
+
+static handler_t mod_simple_vhost_docroot(server *srv, connection *con, void *p_data) {
+	plugin_data *p = p_data;
+
+	/*
+	 * cache the last successfull translation from hostname (authority) to docroot
+	 * - this saves us a stat() call
+	 *
+	 */
+
+	mod_simple_vhost_patch_connection(srv, con, p);
+
+	if (p->conf.docroot_cache_key->used &&
+	    con->uri.authority->used &&
+	    buffer_is_equal(p->conf.docroot_cache_key, con->uri.authority)) {
+		/* cache hit */
+		buffer_copy_string_buffer(con->physical.doc_root, p->conf.docroot_cache_value);
+		buffer_copy_string_buffer(con->server_name,       p->conf.docroot_cache_servername);
+	} else {
+		/* build document-root */
+		if ((con->uri.authority->used == 0) ||
+		    build_doc_root(srv, con, p, p->doc_root, con->uri.authority)) {
+			/* not found, fallback the default-host */
+			if (build_doc_root(srv, con, p,
+					   p->doc_root,
+					   p->conf.default_host)) {
+				return HANDLER_GO_ON;
+			} else {
+				buffer_copy_string_buffer(con->server_name, p->conf.default_host);
+			}
+		} else {
+			buffer_copy_string_buffer(con->server_name, con->uri.authority);
+		}
+
+		/* copy to cache */
+		buffer_copy_string_buffer(p->conf.docroot_cache_key,        con->uri.authority);
+		buffer_copy_string_buffer(p->conf.docroot_cache_value,      p->doc_root);
+		buffer_copy_string_buffer(p->conf.docroot_cache_servername, con->server_name);
+
+		buffer_copy_string_buffer(con->physical.doc_root, p->doc_root);
+	}
+
+	return HANDLER_GO_ON;
+}
+
+
+int mod_simple_vhost_plugin_init(plugin *p) {
+	p->version     = LIGHTTPD_VERSION_ID;
+	p->name        = buffer_init_string("simple_vhost");
+
+	p->init        = mod_simple_vhost_init;
+	p->set_defaults = mod_simple_vhost_set_defaults;
+	p->handle_docroot  = mod_simple_vhost_docroot;
+	p->cleanup     = mod_simple_vhost_free;
+
+	p->data        = NULL;
+
+	return 0;
+}

Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_skeleton.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_skeleton.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_skeleton.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_skeleton.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,210 @@
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "base.h"
+#include "log.h"
+#include "buffer.h"
+
+#include "plugin.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/**
+ * this is a skeleton for a lighttpd plugin
+ *
+ * just replaces every occurance of 'skeleton' by your plugin name
+ *
+ * e.g. in vim:
+ *
+ *   :%s/skeleton/myhandler/
+ *
+ */
+
+
+
+/* plugin config for all request/connections */
+
+typedef struct {
+	array *match;
+} plugin_config;
+
+typedef struct {
+	PLUGIN_DATA;
+
+	buffer *match_buf;
+
+	plugin_config **config_storage;
+
+	plugin_config conf;
+} plugin_data;
+
+typedef struct {
+	size_t foo;
+} handler_ctx;
+
+static handler_ctx * handler_ctx_init() {
+	handler_ctx * hctx;
+
+	hctx = calloc(1, sizeof(*hctx));
+
+	return hctx;
+}
+
+static void handler_ctx_free(handler_ctx *hctx) {
+
+	free(hctx);
+}
+
+/* init the plugin data */
+INIT_FUNC(mod_skeleton_init) {
+	plugin_data *p;
+
+	p = calloc(1, sizeof(*p));
+
+	p->match_buf = buffer_init();
+
+	return p;
+}
+
+/* detroy the plugin data */
+FREE_FUNC(mod_skeleton_free) {
+	plugin_data *p = p_d;
+
+	UNUSED(srv);
+
+	if (!p) return HANDLER_GO_ON;
+
+	if (p->config_storage) {
+		size_t i;
+
+		for (i = 0; i < srv->config_context->used; i++) {
+			plugin_config *s = p->config_storage[i];
+
+			if (!s) continue;
+
+			array_free(s->match);
+
+			free(s);
+		}
+		free(p->config_storage);
+	}
+
+	buffer_free(p->match_buf);
+
+	free(p);
+
+	return HANDLER_GO_ON;
+}
+
+/* handle plugin config and check values */
+
+SETDEFAULTS_FUNC(mod_skeleton_set_defaults) {
+	plugin_data *p = p_d;
+	size_t i = 0;
+
+	config_values_t cv[] = {
+		{ "skeleton.array",             NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
+		{ NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
+	};
+
+	if (!p) return HANDLER_ERROR;
+
+	p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
+
+	for (i = 0; i < srv->config_context->used; i++) {
+		plugin_config *s;
+
+		s = calloc(1, sizeof(plugin_config));
+		s->match    = array_init();
+
+		cv[0].destination = s->match;
+
+		p->config_storage[i] = s;
+
+		if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
+			return HANDLER_ERROR;
+		}
+	}
+
+	return HANDLER_GO_ON;
+}
+
+#define PATCH(x) \
+	p->conf.x = s->x;
+static int mod_skeleton_patch_connection(server *srv, connection *con, plugin_data *p) {
+	size_t i, j;
+	plugin_config *s = p->config_storage[0];
+
+	PATCH(match);
+
+	/* skip the first, the global context */
+	for (i = 1; i < srv->config_context->used; i++) {
+		data_config *dc = (data_config *)srv->config_context->data[i];
+		s = p->config_storage[i];
+
+		/* condition didn't match */
+		if (!config_check_cond(srv, con, dc)) continue;
+
+		/* merge config */
+		for (j = 0; j < dc->value->used; j++) {
+			data_unset *du = dc->value->data[j];
+
+			if (buffer_is_equal_string(du->key, CONST_STR_LEN("skeleton.array"))) {
+				PATCH(match);
+			}
+		}
+	}
+
+	return 0;
+}
+#undef PATCH
+
+URIHANDLER_FUNC(mod_skeleton_uri_handler) {
+	plugin_data *p = p_d;
+	int s_len;
+	size_t k, i;
+
+	UNUSED(srv);
+
+	if (con->uri.path->used == 0) return HANDLER_GO_ON;
+
+	mod_skeleton_patch_connection(srv, con, p);
+
+	s_len = con->uri.path->used - 1;
+
+	for (k = 0; k < p->conf.match->used; k++) {
+		data_string *ds = (data_string *)p->conf.match->data[k];
+		int ct_len = ds->value->used - 1;
+
+		if (ct_len > s_len) continue;
+		if (ds->value->used == 0) continue;
+
+		if (0 == strncmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) {
+			con->http_status = 403;
+
+			return HANDLER_FINISHED;
+		}
+	}
+
+	/* not found */
+	return HANDLER_GO_ON;
+}
+
+/* this function is called at dlopen() time and inits the callbacks */
+
+int mod_skeleton_plugin_init(plugin *p) {
+	p->version     = LIGHTTPD_VERSION_ID;
+	p->name        = buffer_init_string("skeleton");
+
+	p->init        = mod_skeleton_init;
+	p->handle_uri_clean  = mod_skeleton_uri_handler;
+	p->set_defaults  = mod_skeleton_set_defaults;
+	p->cleanup     = mod_skeleton_free;
+
+	p->data        = NULL;
+
+	return 0;
+}

Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,1136 @@
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "base.h"
+#include "log.h"
+#include "buffer.h"
+#include "stat_cache.h"
+
+#include "plugin.h"
+#include "stream.h"
+
+#include "response.h"
+
+#include "mod_ssi.h"
+
+#include "inet_ntop_cache.h"
+
+#include "sys-socket.h"
+
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+
+#ifdef HAVE_FORK
+#include <sys/wait.h>
+#endif
+
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+
+#include "etag.h"
+
+/* The newest modified time of included files for include statement */
+static volatile time_t include_file_last_mtime = 0;
+
+/* init the plugin data */
+INIT_FUNC(mod_ssi_init) {
+	plugin_data *p;
+
+	p = calloc(1, sizeof(*p));
+
+	p->timefmt = buffer_init();
+	p->stat_fn = buffer_init();
+
+	p->ssi_vars = array_init();
+	p->ssi_cgi_env = array_init();
+
+	return p;
+}
+
+/* detroy the plugin data */
+FREE_FUNC(mod_ssi_free) {
+	plugin_data *p = p_d;
+	UNUSED(srv);
+
+	if (!p) return HANDLER_GO_ON;
+
+	if (p->config_storage) {
+		size_t i;
+		for (i = 0; i < srv->config_context->used; i++) {
+			plugin_config *s = p->config_storage[i];
+
+			array_free(s->ssi_extension);
+
+			free(s);
+		}
+		free(p->config_storage);
+	}
+
+	array_free(p->ssi_vars);
+	array_free(p->ssi_cgi_env);
+#ifdef HAVE_PCRE_H
+	pcre_free(p->ssi_regex);
+#endif
+	buffer_free(p->timefmt);
+	buffer_free(p->stat_fn);
+
+	free(p);
+
+	return HANDLER_GO_ON;
+}
+
+/* handle plugin config and check values */
+
+SETDEFAULTS_FUNC(mod_ssi_set_defaults) {
+	plugin_data *p = p_d;
+	size_t i = 0;
+#ifdef HAVE_PCRE_H
+	const char *errptr;
+	int erroff;
+#endif
+
+	config_values_t cv[] = {
+		{ "ssi.extension",              NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
+		{ NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
+	};
+
+	if (!p) return HANDLER_ERROR;
+
+	p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
+
+	for (i = 0; i < srv->config_context->used; i++) {
+		plugin_config *s;
+
+		s = calloc(1, sizeof(plugin_config));
+		s->ssi_extension  = array_init();
+
+		cv[0].destination = s->ssi_extension;
+
+		p->config_storage[i] = s;
+
+		if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
+			return HANDLER_ERROR;
+		}
+	}
+
+#ifdef HAVE_PCRE_H
+	/* allow 2 params */
+	if (NULL == (p->ssi_regex = pcre_compile("<!--#([a-z]+)\\s+(?:([a-z]+)=\"(.*?)(?<!\\\\)\"\\s*)?(?:([a-z]+)=\"(.*?)(?<!\\\\)\"\\s*)?-->", 0, &errptr, &erroff, NULL))) {
+		log_error_write(srv, __FILE__, __LINE__, "sds",
+				"ssi: pcre ",
+				erroff, errptr);
+		return HANDLER_ERROR;
+	}
+#else
+	log_error_write(srv, __FILE__, __LINE__, "s",
+			"mod_ssi: pcre support is missing, please recompile with pcre support or remove mod_ssi from the list of modules");
+	return HANDLER_ERROR;
+#endif
+
+	return HANDLER_GO_ON;
+}
+
+int ssi_env_add(array *env, const char *key, const char *val) {
+	data_string *ds;
+
+	if (NULL == (ds = (data_string *)array_get_unused_element(env, TYPE_STRING))) {
+		ds = data_string_init();
+	}
+	buffer_copy_string(ds->key,   key);
+	buffer_copy_string(ds->value, val);
+
+	array_insert_unique(env, (data_unset *)ds);
+
+	return 0;
+}
+
+/**
+ *
+ *  the next two functions are take from fcgi.c
+ *
+ */
+
+static int ssi_env_add_request_headers(server *srv, connection *con, plugin_data *p) {
+	size_t i;
+
+	for (i = 0; i < con->request.headers->used; i++) {
+		data_string *ds;
+
+		ds = (data_string *)con->request.headers->data[i];
+
+		if (ds->value->used && ds->key->used) {
+			size_t j;
+			buffer_reset(srv->tmp_buf);
+
+			/* don't forward the Authorization: Header */
+			if (0 == strcasecmp(ds->key->ptr, "AUTHORIZATION")) {
+				continue;
+			}
+
+			if (0 != strcasecmp(ds->key->ptr, "CONTENT-TYPE")) {
+				buffer_copy_string(srv->tmp_buf, "HTTP_");
+				srv->tmp_buf->used--;
+			}
+
+			buffer_prepare_append(srv->tmp_buf, ds->key->used + 2);
+			for (j = 0; j < ds->key->used - 1; j++) {
+				char c = '_';
+				if (light_isalpha(ds->key->ptr[j])) {
+					/* upper-case */
+					c = ds->key->ptr[j] & ~32;
+				} else if (light_isdigit(ds->key->ptr[j])) {
+					/* copy */
+					c = ds->key->ptr[j];
+				}
+				srv->tmp_buf->ptr[srv->tmp_buf->used++] = c;
+			}
+			srv->tmp_buf->ptr[srv->tmp_buf->used] = '\0';
+
+			ssi_env_add(p->ssi_cgi_env, srv->tmp_buf->ptr, ds->value->ptr);
+		}
+	}
+
+	return 0;
+}
+
+static int build_ssi_cgi_vars(server *srv, connection *con, plugin_data *p) {
+	char buf[32];
+
+	server_socket *srv_sock = con->srv_socket;
+
+#ifdef HAVE_IPV6
+	char b2[INET6_ADDRSTRLEN + 1];
+#endif
+
+#define CONST_STRING(x) \
+		x
+
+	array_reset(p->ssi_cgi_env);
+
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("SERVER_SOFTWARE"), PACKAGE_NAME"/"PACKAGE_VERSION);
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("SERVER_NAME"),
+#ifdef HAVE_IPV6
+		     inet_ntop(srv_sock->addr.plain.sa_family,
+			       srv_sock->addr.plain.sa_family == AF_INET6 ?
+			       (const void *) &(srv_sock->addr.ipv6.sin6_addr) :
+			       (const void *) &(srv_sock->addr.ipv4.sin_addr),
+			       b2, sizeof(b2)-1)
+#else
+		     inet_ntoa(srv_sock->addr.ipv4.sin_addr)
+#endif
+		     );
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("GATEWAY_INTERFACE"), "CGI/1.1");
+
+	LI_ltostr(buf,
+#ifdef HAVE_IPV6
+	       ntohs(srv_sock->addr.plain.sa_family ? srv_sock->addr.ipv6.sin6_port : srv_sock->addr.ipv4.sin_port)
+#else
+	       ntohs(srv_sock->addr.ipv4.sin_port)
+#endif
+	       );
+
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("SERVER_PORT"), buf);
+
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("REMOTE_ADDR"),
+		    inet_ntop_cache_get_ip(srv, &(con->dst_addr)));
+
+	if (con->authed_user->used) {
+		ssi_env_add(p->ssi_cgi_env, CONST_STRING("REMOTE_USER"),
+			     con->authed_user->ptr);
+	}
+
+	if (con->request.content_length > 0) {
+		/* CGI-SPEC 6.1.2 and FastCGI spec 6.3 */
+
+		/* request.content_length < SSIZE_MAX, see request.c */
+		LI_ltostr(buf, con->request.content_length);
+		ssi_env_add(p->ssi_cgi_env, CONST_STRING("CONTENT_LENGTH"), buf);
+	}
+
+	/*
+	 * SCRIPT_NAME, PATH_INFO and PATH_TRANSLATED according to
+	 * http://cgi-spec.golux.com/draft-coar-cgi-v11-03-clean.html
+	 * (6.1.14, 6.1.6, 6.1.7)
+	 */
+
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("SCRIPT_NAME"), con->uri.path->ptr);
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("PATH_INFO"), "");
+
+	/*
+	 * SCRIPT_FILENAME and DOCUMENT_ROOT for php. The PHP manual
+	 * http://www.php.net/manual/en/reserved.variables.php
+	 * treatment of PATH_TRANSLATED is different from the one of CGI specs.
+	 * TODO: this code should be checked against cgi.fix_pathinfo php
+	 * parameter.
+	 */
+
+	if (con->request.pathinfo->used) {
+		ssi_env_add(p->ssi_cgi_env, CONST_STRING("PATH_INFO"), con->request.pathinfo->ptr);
+	}
+
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("SCRIPT_FILENAME"), con->physical.path->ptr);
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("DOCUMENT_ROOT"), con->physical.doc_root->ptr);
+
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("REQUEST_URI"), con->request.uri->ptr);
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("QUERY_STRING"), con->uri.query->used ? con->uri.query->ptr : "");
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("REQUEST_METHOD"), get_http_method_name(con->request.http_method));
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("REDIRECT_STATUS"), "200");
+	ssi_env_add(p->ssi_cgi_env, CONST_STRING("SERVER_PROTOCOL"), get_http_version_name(con->request.http_version));
+
+	ssi_env_add_request_headers(srv, con, p);
+
+	return 0;
+}
+
+static int process_ssi_stmt(server *srv, connection *con, plugin_data *p,
+			    const char **l, size_t n) {
+	size_t i, ssicmd = 0;
+	char buf[255];
+	buffer *b = NULL;
+
+	struct {
+		const char *var;
+		enum { SSI_UNSET, SSI_ECHO, SSI_FSIZE, SSI_INCLUDE, SSI_FLASTMOD,
+				SSI_CONFIG, SSI_PRINTENV, SSI_SET, SSI_IF, SSI_ELIF,
+				SSI_ELSE, SSI_ENDIF, SSI_EXEC } type;
+	} ssicmds[] = {
+		{ "echo",     SSI_ECHO },
+		{ "include",  SSI_INCLUDE },
+		{ "flastmod", SSI_FLASTMOD },
+		{ "fsize",    SSI_FSIZE },
+		{ "config",   SSI_CONFIG },
+		{ "printenv", SSI_PRINTENV },
+		{ "set",      SSI_SET },
+		{ "if",       SSI_IF },
+		{ "elif",     SSI_ELIF },
+		{ "endif",    SSI_ENDIF },
+		{ "else",     SSI_ELSE },
+		{ "exec",     SSI_EXEC },
+
+		{ NULL, SSI_UNSET }
+	};
+
+	for (i = 0; ssicmds[i].var; i++) {
+		if (0 == strcmp(l[1], ssicmds[i].var)) {
+			ssicmd = ssicmds[i].type;
+			break;
+		}
+	}
+
+	switch(ssicmd) {
+	case SSI_ECHO: {
+		/* echo */
+		int var = 0, enc = 0;
+		const char *var_val = NULL;
+		stat_cache_entry *sce = NULL;
+
+		struct {
+			const char *var;
+			enum { SSI_ECHO_UNSET, SSI_ECHO_DATE_GMT, SSI_ECHO_DATE_LOCAL, SSI_ECHO_DOCUMENT_NAME, SSI_ECHO_DOCUMENT_URI,
+					SSI_ECHO_LAST_MODIFIED, SSI_ECHO_USER_NAME } type;
+		} echovars[] = {
+			{ "DATE_GMT",      SSI_ECHO_DATE_GMT },
+			{ "DATE_LOCAL",    SSI_ECHO_DATE_LOCAL },
+			{ "DOCUMENT_NAME", SSI_ECHO_DOCUMENT_NAME },
+			{ "DOCUMENT_URI",  SSI_ECHO_DOCUMENT_URI },
+			{ "LAST_MODIFIED", SSI_ECHO_LAST_MODIFIED },
+			{ "USER_NAME",     SSI_ECHO_USER_NAME },
+
+			{ NULL, SSI_ECHO_UNSET }
+		};
+
+		struct {
+			const char *var;
+			enum { SSI_ENC_UNSET, SSI_ENC_URL, SSI_ENC_NONE, SSI_ENC_ENTITY } type;
+		} encvars[] = {
+			{ "url",          SSI_ENC_URL },
+			{ "none",         SSI_ENC_NONE },
+			{ "entity",       SSI_ENC_ENTITY },
+
+			{ NULL, SSI_ENC_UNSET }
+		};
+
+		for (i = 2; i < n; i += 2) {
+			if (0 == strcmp(l[i], "var")) {
+				int j;
+
+				var_val = l[i+1];
+
+				for (j = 0; echovars[j].var; j++) {
+					if (0 == strcmp(l[i+1], echovars[j].var)) {
+						var = echovars[j].type;
+						break;
+					}
+				}
+			} else if (0 == strcmp(l[i], "encoding")) {
+				int j;
+
+				for (j = 0; encvars[j].var; j++) {
+					if (0 == strcmp(l[i+1], encvars[j].var)) {
+						enc = encvars[j].type;
+						break;
+					}
+				}
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sss",
+						"ssi: unknow attribute for ",
+						l[1], l[i]);
+			}
+		}
+
+		if (p->if_is_false) break;
+
+		if (!var_val) {
+			log_error_write(srv, __FILE__, __LINE__, "sss",
+					"ssi: ",
+					l[1], "var is missing");
+			break;
+		}
+
+		stat_cache_get_entry(srv, con, con->physical.path, &sce);
+
+		switch(var) {
+		case SSI_ECHO_USER_NAME: {
+			struct passwd *pw;
+
+			b = chunkqueue_get_append_buffer(con->write_queue);
+#ifdef HAVE_PWD_H
+			if (NULL == (pw = getpwuid(sce->st.st_uid))) {
+				buffer_copy_long(b, sce->st.st_uid);
+			} else {
+				buffer_copy_string(b, pw->pw_name);
+			}
+#else
+			buffer_copy_long(b, sce->st.st_uid);
+#endif
+			break;
+		}
+		case SSI_ECHO_LAST_MODIFIED:	{
+			time_t t = sce->st.st_mtime;
+
+			b = chunkqueue_get_append_buffer(con->write_queue);
+			if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) {
+				buffer_copy_string(b, "(none)");
+			} else {
+				buffer_copy_string(b, buf);
+			}
+			break;
+		}
+		case SSI_ECHO_DATE_LOCAL: {
+			time_t t = time(NULL);
+
+			b = chunkqueue_get_append_buffer(con->write_queue);
+			if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) {
+				buffer_copy_string(b, "(none)");
+			} else {
+				buffer_copy_string(b, buf);
+			}
+			break;
+		}
+		case SSI_ECHO_DATE_GMT: {
+			time_t t = time(NULL);
+
+			b = chunkqueue_get_append_buffer(con->write_queue);
+			if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, gmtime(&t))) {
+				buffer_copy_string(b, "(none)");
+			} else {
+				buffer_copy_string(b, buf);
+			}
+			break;
+		}
+		case SSI_ECHO_DOCUMENT_NAME: {
+			char *sl;
+
+			b = chunkqueue_get_append_buffer(con->write_queue);
+			if (NULL == (sl = strrchr(con->physical.path->ptr, '/'))) {
+				buffer_copy_string_buffer(b, con->physical.path);
+			} else {
+				buffer_copy_string(b, sl + 1);
+			}
+			break;
+		}
+		case SSI_ECHO_DOCUMENT_URI: {
+			b = chunkqueue_get_append_buffer(con->write_queue);
+			buffer_copy_string_buffer(b, con->uri.path);
+			break;
+		}
+		default: {
+			data_string *ds;
+			/* check if it is a cgi-var */
+
+			b = chunkqueue_get_append_buffer(con->write_queue);
+
+			if (NULL != (ds = (data_string *)array_get_element(p->ssi_cgi_env, var_val))) {
+				buffer_copy_string_buffer(b, ds->value);
+			} else {
+				buffer_copy_string(b, "(none)");
+			}
+
+			break;
+		}
+		}
+		break;
+	}
+	case SSI_INCLUDE:
+	case SSI_FLASTMOD:
+	case SSI_FSIZE: {
+		const char * file_path = NULL, *virt_path = NULL;
+		struct stat st;
+		char *sl;
+
+		for (i = 2; i < n; i += 2) {
+			if (0 == strcmp(l[i], "file")) {
+				file_path = l[i+1];
+			} else if (0 == strcmp(l[i], "virtual")) {
+				virt_path = l[i+1];
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sss",
+						"ssi: unknow attribute for ",
+						l[1], l[i]);
+			}
+		}
+
+		if (!file_path && !virt_path) {
+			log_error_write(srv, __FILE__, __LINE__, "sss",
+					"ssi: ",
+					l[1], "file or virtual are missing");
+			break;
+		}
+
+		if (file_path && virt_path) {
+			log_error_write(srv, __FILE__, __LINE__, "sss",
+					"ssi: ",
+					l[1], "only one of file and virtual is allowed here");
+			break;
+		}
+
+
+		if (p->if_is_false) break;
+
+		if (file_path) {
+			/* current doc-root */
+			if (NULL == (sl = strrchr(con->physical.path->ptr, '/'))) {
+				buffer_copy_string(p->stat_fn, "/");
+			} else {
+				buffer_copy_string_len(p->stat_fn, con->physical.path->ptr, sl - con->physical.path->ptr + 1);
+			}
+
+			buffer_copy_string(srv->tmp_buf, file_path);
+			buffer_urldecode_path(srv->tmp_buf);
+			buffer_path_simplify(srv->tmp_buf, srv->tmp_buf);
+			buffer_append_string_buffer(p->stat_fn, srv->tmp_buf);
+		} else {
+			/* virtual */
+
+			if (virt_path[0] == '/') {
+				buffer_copy_string(p->stat_fn, virt_path);
+			} else {
+				/* there is always a / */
+				sl = strrchr(con->uri.path->ptr, '/');
+
+				buffer_copy_string_len(p->stat_fn, con->uri.path->ptr, sl - con->uri.path->ptr + 1);
+				buffer_append_string(p->stat_fn, virt_path);
+			}
+
+			buffer_urldecode_path(p->stat_fn);
+			buffer_path_simplify(srv->tmp_buf, p->stat_fn);
+
+			/* we have an uri */
+
+			buffer_copy_string_buffer(p->stat_fn, con->physical.doc_root);
+			buffer_append_string_buffer(p->stat_fn, srv->tmp_buf);
+		}
+
+		if (0 == stat(p->stat_fn->ptr, &st)) {
+			time_t t = st.st_mtime;
+
+			switch (ssicmd) {
+			case SSI_FSIZE:
+				b = chunkqueue_get_append_buffer(con->write_queue);
+				if (p->sizefmt) {
+					int j = 0;
+					const char *abr[] = { " B", " kB", " MB", " GB", " TB", NULL };
+
+					off_t s = st.st_size;
+
+					for (j = 0; s > 1024 && abr[j+1]; s /= 1024, j++);
+
+					buffer_copy_off_t(b, s);
+					buffer_append_string(b, abr[j]);
+				} else {
+					buffer_copy_off_t(b, st.st_size);
+				}
+				break;
+			case SSI_FLASTMOD:
+				b = chunkqueue_get_append_buffer(con->write_queue);
+				if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) {
+					buffer_copy_string(b, "(none)");
+				} else {
+					buffer_copy_string(b, buf);
+				}
+				break;
+			case SSI_INCLUDE:
+				chunkqueue_append_file(con->write_queue, p->stat_fn, 0, st.st_size);
+
+				/* Keep the newest mtime of included files */
+				if (st.st_mtime > include_file_last_mtime)
+				  include_file_last_mtime = st.st_mtime;
+
+				break;
+			}
+		} else {
+			log_error_write(srv, __FILE__, __LINE__, "sbs",
+					"ssi: stating failed ",
+					p->stat_fn, strerror(errno));
+		}
+		break;
+	}
+	case SSI_SET: {
+		const char *key = NULL, *val = NULL;
+		for (i = 2; i < n; i += 2) {
+			if (0 == strcmp(l[i], "var")) {
+				key = l[i+1];
+			} else if (0 == strcmp(l[i], "value")) {
+				val = l[i+1];
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sss",
+						"ssi: unknow attribute for ",
+						l[1], l[i]);
+			}
+		}
+
+		if (p->if_is_false) break;
+
+		if (key && val) {
+			data_string *ds;
+
+			if (NULL == (ds = (data_string *)array_get_unused_element(p->ssi_vars, TYPE_STRING))) {
+				ds = data_string_init();
+			}
+			buffer_copy_string(ds->key,   key);
+			buffer_copy_string(ds->value, val);
+
+			array_insert_unique(p->ssi_vars, (data_unset *)ds);
+		} else {
+			log_error_write(srv, __FILE__, __LINE__, "sss",
+					"ssi: var and value have to be set in",
+					l[0], l[1]);
+		}
+		break;
+	}
+	case SSI_CONFIG:
+		if (p->if_is_false) break;
+
+		for (i = 2; i < n; i += 2) {
+			if (0 == strcmp(l[i], "timefmt")) {
+				buffer_copy_string(p->timefmt, l[i+1]);
+			} else if (0 == strcmp(l[i], "sizefmt")) {
+				if (0 == strcmp(l[i+1], "abbrev")) {
+					p->sizefmt = 1;
+				} else if (0 == strcmp(l[i+1], "abbrev")) {
+					p->sizefmt = 0;
+				} else {
+					log_error_write(srv, __FILE__, __LINE__, "sssss",
+							"ssi: unknow value for attribute '",
+							l[i],
+							"' for ",
+							l[1], l[i+1]);
+				}
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sss",
+						"ssi: unknow attribute for ",
+						l[1], l[i]);
+			}
+		}
+		break;
+	case SSI_PRINTENV:
+		if (p->if_is_false) break;
+
+		b = chunkqueue_get_append_buffer(con->write_queue);
+		buffer_copy_string(b, "<pre>");
+		for (i = 0; i < p->ssi_vars->used; i++) {
+			data_string *ds = (data_string *)p->ssi_vars->data[p->ssi_vars->sorted[i]];
+
+			buffer_append_string_buffer(b, ds->key);
+			buffer_append_string(b, ": ");
+			buffer_append_string_buffer(b, ds->value);
+			buffer_append_string(b, "<br />");
+
+		}
+		buffer_append_string(b, "</pre>");
+
+		break;
+	case SSI_EXEC: {
+		const char *cmd = NULL;
+		pid_t pid;
+		int from_exec_fds[2];
+
+		for (i = 2; i < n; i += 2) {
+			if (0 == strcmp(l[i], "cmd")) {
+				cmd = l[i+1];
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sss",
+						"ssi: unknow attribute for ",
+						l[1], l[i]);
+			}
+		}
+
+		if (p->if_is_false) break;
+
+		/* create a return pipe and send output to the html-page
+		 *
+		 * as exec is assumed evil it is implemented synchronously
+		 */
+
+		if (!cmd) break;
+#ifdef HAVE_FORK
+		if (pipe(from_exec_fds)) {
+			log_error_write(srv, __FILE__, __LINE__, "ss",
+					"pipe failed: ", strerror(errno));
+			return -1;
+		}
+
+		/* fork, execve */
+		switch (pid = fork()) {
+		case 0: {
+			/* move stdout to from_rrdtool_fd[1] */
+			close(STDOUT_FILENO);
+			dup2(from_exec_fds[1], STDOUT_FILENO);
+			close(from_exec_fds[1]);
+			/* not needed */
+			close(from_exec_fds[0]);
+
+			/* close stdin */
+			close(STDIN_FILENO);
+
+			execl("/bin/sh", "sh", "-c", cmd, (char *)NULL);
+
+			log_error_write(srv, __FILE__, __LINE__, "sss", "spawing exec failed:", strerror(errno), cmd);
+
+			/* */
+			SEGFAULT();
+			break;
+		}
+		case -1:
+			/* error */
+			log_error_write(srv, __FILE__, __LINE__, "ss", "fork failed:", strerror(errno));
+			break;
+		default: {
+			/* father */
+			int status;
+			ssize_t r;
+			int was_interrupted = 0;
+
+			close(from_exec_fds[1]);
+
+			/* wait for the client to end */
+
+			/*
+			 * OpenBSD and Solaris send a EINTR on SIGCHILD even if we ignore it
+			 */
+			do {
+				if (-1 == waitpid(pid, &status, 0)) {
+					if (errno == EINTR) {
+						was_interrupted++;
+					} else {
+						was_interrupted = 0;
+						log_error_write(srv, __FILE__, __LINE__, "ss", "waitpid failed:", strerror(errno));
+					}
+				} else if (WIFEXITED(status)) {
+					int toread;
+					/* read everything from client and paste it into the output */
+					was_interrupted = 0;
+	
+					while(1) {
+						if (ioctl(from_exec_fds[0], FIONREAD, &toread)) {
+							log_error_write(srv, __FILE__, __LINE__, "s",
+								"unexpected end-of-file (perhaps the ssi-exec process died)");
+							return -1;
+						}
+	
+						if (toread > 0) {
+							b = chunkqueue_get_append_buffer(con->write_queue);
+	
+							buffer_prepare_copy(b, toread + 1);
+	
+							if ((r = read(from_exec_fds[0], b->ptr, b->size - 1)) < 0) {
+								/* read failed */
+								break;
+							} else {
+								b->used = r;
+								b->ptr[b->used++] = '\0';
+							}
+						} else {
+							break;
+						}
+					}
+				} else {
+					was_interrupted = 0;
+					log_error_write(srv, __FILE__, __LINE__, "s", "process exited abnormally");
+				}
+			} while (was_interrupted > 0 && was_interrupted < 4); /* if waitpid() gets interrupted, retry, but max 4 times */
+
+			close(from_exec_fds[0]);
+
+			break;
+		}
+		}
+#else
+
+		return -1;
+#endif
+
+		break;
+	}
+	case SSI_IF: {
+		const char *expr = NULL;
+
+		for (i = 2; i < n; i += 2) {
+			if (0 == strcmp(l[i], "expr")) {
+				expr = l[i+1];
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sss",
+						"ssi: unknow attribute for ",
+						l[1], l[i]);
+			}
+		}
+
+		if (!expr) {
+			log_error_write(srv, __FILE__, __LINE__, "sss",
+					"ssi: ",
+					l[1], "expr missing");
+			break;
+		}
+
+		if ((!p->if_is_false) &&
+		    ((p->if_is_false_level == 0) ||
+		     (p->if_level < p->if_is_false_level))) {
+			switch (ssi_eval_expr(srv, con, p, expr)) {
+			case -1:
+			case 0:
+				p->if_is_false = 1;
+				p->if_is_false_level = p->if_level;
+				break;
+			case 1:
+				p->if_is_false = 0;
+				break;
+			}
+		}
+
+		p->if_level++;
+
+		break;
+	}
+	case SSI_ELSE:
+		p->if_level--;
+
+		if (p->if_is_false) {
+			if ((p->if_level == p->if_is_false_level) &&
+			    (p->if_is_false_endif == 0)) {
+				p->if_is_false = 0;
+			}
+		} else {
+			p->if_is_false = 1;
+
+			p->if_is_false_level = p->if_level;
+		}
+		p->if_level++;
+
+		break;
+	case SSI_ELIF: {
+		const char *expr = NULL;
+		for (i = 2; i < n; i += 2) {
+			if (0 == strcmp(l[i], "expr")) {
+				expr = l[i+1];
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sss",
+						"ssi: unknow attribute for ",
+						l[1], l[i]);
+			}
+		}
+
+		if (!expr) {
+			log_error_write(srv, __FILE__, __LINE__, "sss",
+					"ssi: ",
+					l[1], "expr missing");
+			break;
+		}
+
+		p->if_level--;
+
+		if (p->if_level == p->if_is_false_level) {
+			if ((p->if_is_false) &&
+			    (p->if_is_false_endif == 0)) {
+				switch (ssi_eval_expr(srv, con, p, expr)) {
+				case -1:
+				case 0:
+					p->if_is_false = 1;
+					p->if_is_false_level = p->if_level;
+					break;
+				case 1:
+					p->if_is_false = 0;
+					break;
+				}
+			} else {
+				p->if_is_false = 1;
+				p->if_is_false_level = p->if_level;
+				p->if_is_false_endif = 1;
+			}
+		}
+
+		p->if_level++;
+
+		break;
+	}
+	case SSI_ENDIF:
+		p->if_level--;
+
+		if (p->if_level == p->if_is_false_level) {
+			p->if_is_false = 0;
+			p->if_is_false_endif = 0;
+		}
+
+		break;
+	default:
+		log_error_write(srv, __FILE__, __LINE__, "ss",
+				"ssi: unknow ssi-command:",
+				l[1]);
+		break;
+	}
+
+	return 0;
+
+}
+
+static int mod_ssi_handle_request(server *srv, connection *con, plugin_data *p) {
+	stream s;
+#ifdef  HAVE_PCRE_H
+	int i, n;
+
+#define N 10
+	int ovec[N * 3];
+#endif
+
+	/* get a stream to the file */
+
+	array_reset(p->ssi_vars);
+	array_reset(p->ssi_cgi_env);
+	buffer_copy_string(p->timefmt, "%a, %d %b %Y %H:%M:%S %Z");
+	p->sizefmt = 0;
+	build_ssi_cgi_vars(srv, con, p);
+	p->if_is_false = 0;
+
+	/* Reset the modified time of included files */
+	include_file_last_mtime = 0;
+
+	if (-1 == stream_open(&s, con->physical.path)) {
+		log_error_write(srv, __FILE__, __LINE__, "sb",
+				"stream-open: ", con->physical.path);
+		return -1;
+	}
+
+
+	/**
+	 * <!--#element attribute=value attribute=value ... -->
+	 *
+	 * config       DONE
+	 *   errmsg     -- missing
+	 *   sizefmt    DONE
+	 *   timefmt    DONE
+	 * echo         DONE
+	 *   var        DONE
+	 *   encoding   -- missing
+	 * exec         DONE
+	 *   cgi        -- never
+	 *   cmd        DONE
+	 * fsize        DONE
+	 *   file       DONE
+	 *   virtual    DONE
+	 * flastmod     DONE
+	 *   file       DONE
+	 *   virtual    DONE
+	 * include      DONE
+	 *   file       DONE
+	 *   virtual    DONE
+	 * printenv     DONE
+	 * set          DONE
+	 *   var        DONE
+	 *   value      DONE
+	 *
+	 * if           DONE
+	 * elif         DONE
+	 * else         DONE
+	 * endif        DONE
+	 *
+	 *
+	 * expressions
+	 * AND, OR      DONE
+	 * comp         DONE
+	 * ${...}       -- missing
+	 * $...         DONE
+	 * '...'        DONE
+	 * ( ... )      DONE
+	 *
+	 *
+	 *
+	 * ** all DONE **
+	 * DATE_GMT
+	 *   The current date in Greenwich Mean Time.
+	 * DATE_LOCAL
+	 *   The current date in the local time zone.
+	 * DOCUMENT_NAME
+	 *   The filename (excluding directories) of the document requested by the user.
+	 * DOCUMENT_URI
+	 *   The (%-decoded) URL path of the document requested by the user. Note that in the case of nested include files, this is not then URL for the current document.
+	 * LAST_MODIFIED
+	 *   The last modification date of the document requested by the user.
+	 * USER_NAME
+	 *   Contains the owner of the file which included it.
+	 *
+	 */
+#ifdef HAVE_PCRE_H
+	for (i = 0; (n = pcre_exec(p->ssi_regex, NULL, s.start, s.size, i, 0, ovec, N * 3)) > 0; i = ovec[1]) {
+		const char **l;
+		/* take everything from last offset to current match pos */
+
+		if (!p->if_is_false) chunkqueue_append_file(con->write_queue, con->physical.path, i, ovec[0] - i);
+
+		pcre_get_substring_list(s.start, ovec, n, &l);
+		process_ssi_stmt(srv, con, p, l, n);
+		pcre_free_substring_list(l);
+	}
+
+	switch(n) {
+	case PCRE_ERROR_NOMATCH:
+		/* copy everything/the rest */
+		chunkqueue_append_file(con->write_queue, con->physical.path, i, s.size - i);
+
+		break;
+	default:
+		log_error_write(srv, __FILE__, __LINE__, "sd",
+				"execution error while matching: ", n);
+		break;
+	}
+#endif
+
+
+	stream_close(&s);
+
+	con->file_started  = 1;
+	con->file_finished = 1;
+
+	response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
+
+	{
+  	/* Generate "ETag" & "Last-Modified" headers */
+
+		stat_cache_entry *sce = NULL;
+		time_t lm_time = 0;
+		buffer *mtime = NULL;
+
+		stat_cache_get_entry(srv, con, con->physical.path, &sce);
+
+		etag_mutate(con->physical.etag, sce->etag);
+		response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
+
+		if (sce->st.st_mtime > include_file_last_mtime)
+			lm_time = sce->st.st_mtime;
+		else
+			lm_time = include_file_last_mtime;
+
+		mtime = strftime_cache_get(srv, lm_time);
+		response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
+	}
+
+	/* Reset the modified time of included files */
+	include_file_last_mtime = 0;
+
+	/* reset physical.path */
+	buffer_reset(con->physical.path);
+
+	return 0;
+}
+
+#define PATCH(x) \
+	p->conf.x = s->x;
+static int mod_ssi_patch_connection(server *srv, connection *con, plugin_data *p) {
+	size_t i, j;
+	plugin_config *s = p->config_storage[0];
+
+	PATCH(ssi_extension);
+
+	/* skip the first, the global context */
+	for (i = 1; i < srv->config_context->used; i++) {
+		data_config *dc = (data_config *)srv->config_context->data[i];
+		s = p->config_storage[i];
+
+		/* condition didn't match */
+		if (!config_check_cond(srv, con, dc)) continue;
+
+		/* merge config */
+		for (j = 0; j < dc->value->used; j++) {
+			data_unset *du = dc->value->data[j];
+
+			if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.extension"))) {
+				PATCH(ssi_extension);
+			}
+		}
+	}
+
+	return 0;
+}
+#undef PATCH
+
+URIHANDLER_FUNC(mod_ssi_physical_path) {
+	plugin_data *p = p_d;
+	size_t k;
+
+	if (con->physical.path->used == 0) return HANDLER_GO_ON;
+
+	mod_ssi_patch_connection(srv, con, p);
+
+	for (k = 0; k < p->conf.ssi_extension->used; k++) {
+		data_string *ds = (data_string *)p->conf.ssi_extension->data[k];
+
+		if (ds->value->used == 0) continue;
+
+		if (buffer_is_equal_right_len(con->physical.path, ds->value, ds->value->used - 1)) {
+			/* handle ssi-request */
+
+			if (mod_ssi_handle_request(srv, con, p)) {
+				/* on error */
+				con->http_status = 500;
+			}
+
+			return HANDLER_FINISHED;
+		}
+	}
+
+	/* not found */
+	return HANDLER_GO_ON;
+}
+
+/* this function is called at dlopen() time and inits the callbacks */
+
+int mod_ssi_plugin_init(plugin *p) {
+	p->version     = LIGHTTPD_VERSION_ID;
+	p->name        = buffer_init_string("ssi");
+
+	p->init        = mod_ssi_init;
+	p->handle_subrequest_start = mod_ssi_physical_path;
+	p->set_defaults  = mod_ssi_set_defaults;
+	p->cleanup     = mod_ssi_free;
+
+	p->data        = NULL;
+
+	return 0;
+}

Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,43 @@
+#ifndef _MOD_SSI_H_
+#define _MOD_SSI_H_
+
+#include "base.h"
+#include "buffer.h"
+#include "array.h"
+
+#include "plugin.h"
+
+#ifdef HAVE_PCRE_H
+#include <pcre.h>
+#endif
+
+/* plugin config for all request/connections */
+
+typedef struct {
+	array *ssi_extension;
+} plugin_config;
+
+typedef struct {
+	PLUGIN_DATA;
+
+#ifdef HAVE_PCRE_H
+	pcre *ssi_regex;
+#endif
+	buffer *timefmt;
+	int sizefmt;
+
+	buffer *stat_fn;
+
+	array *ssi_vars;
+	array *ssi_cgi_env;
+
+	int if_level, if_is_false_level, if_is_false, if_is_false_endif;
+
+	plugin_config **config_storage;
+
+	plugin_config conf;
+} plugin_data;
+
+int ssi_eval_expr(server *srv, connection *con, plugin_data *p, const char *expr);
+
+#endif

Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_expr.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_expr.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_expr.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_expr.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,324 @@
+#include <ctype.h>
+#include <string.h>
+
+#include "buffer.h"
+#include "log.h"
+#include "mod_ssi.h"
+#include "mod_ssi_expr.h"
+#include "mod_ssi_exprparser.h"
+
+typedef struct {
+	const char *input;
+	size_t offset;
+	size_t size;
+
+	int line_pos;
+
+	int in_key;
+	int in_brace;
+	int in_cond;
+} ssi_tokenizer_t;
+
+ssi_val_t *ssi_val_init() {
+	ssi_val_t *s;
+
+	s = calloc(1, sizeof(*s));
+
+	return s;
+}
+
+void ssi_val_free(ssi_val_t *s) {
+	if (s->str) buffer_free(s->str);
+
+	free(s);
+}
+
+int ssi_val_tobool(ssi_val_t *B) {
+	if (B->type == SSI_TYPE_STRING) {
+		return B->str->used > 1 ? 1 : 0;
+	} else {
+		return B->bo;
+	}
+}
+
+static int ssi_expr_tokenizer(server *srv, connection *con, plugin_data *p,
+			      ssi_tokenizer_t *t, int *token_id, buffer *token) {
+	int tid = 0;
+	size_t i;
+
+	UNUSED(con);
+
+	for (tid = 0; tid == 0 && t->offset < t->size && t->input[t->offset] ; ) {
+		char c = t->input[t->offset];
+		data_string *ds;
+
+		switch (c) {
+		case '=':
+			tid = TK_EQ;
+
+			t->offset++;
+			t->line_pos++;
+
+			buffer_copy_string(token, "(=)");
+
+			break;
+		case '>':
+			if (t->input[t->offset + 1] == '=') {
+				t->offset += 2;
+				t->line_pos += 2;
+
+				tid = TK_GE;
+
+				buffer_copy_string(token, "(>=)");
+			} else {
+				t->offset += 1;
+				t->line_pos += 1;
+
+				tid = TK_GT;
+
+				buffer_copy_string(token, "(>)");
+			}
+
+			break;
+		case '<':
+			if (t->input[t->offset + 1] == '=') {
+				t->offset += 2;
+				t->line_pos += 2;
+
+				tid = TK_LE;
+
+				buffer_copy_string(token, "(<=)");
+			} else {
+				t->offset += 1;
+				t->line_pos += 1;
+
+				tid = TK_LT;
+
+				buffer_copy_string(token, "(<)");
+			}
+
+			break;
+
+		case '!':
+			if (t->input[t->offset + 1] == '=') {
+				t->offset += 2;
+				t->line_pos += 2;
+
+				tid = TK_NE;
+
+				buffer_copy_string(token, "(!=)");
+			} else {
+				t->offset += 1;
+				t->line_pos += 1;
+
+				tid = TK_NOT;
+
+				buffer_copy_string(token, "(!)");
+			}
+
+			break;
+		case '&':
+			if (t->input[t->offset + 1] == '&') {
+				t->offset += 2;
+				t->line_pos += 2;
+
+				tid = TK_AND;
+
+				buffer_copy_string(token, "(&&)");
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sds",
+						"pos:", t->line_pos,
+						"missing second &");
+				return -1;
+			}
+
+			break;
+		case '|':
+			if (t->input[t->offset + 1] == '|') {
+				t->offset += 2;
+				t->line_pos += 2;
+
+				tid = TK_OR;
+
+				buffer_copy_string(token, "(||)");
+			} else {
+				log_error_write(srv, __FILE__, __LINE__, "sds",
+						"pos:", t->line_pos,
+						"missing second |");
+				return -1;
+			}
+
+			break;
+		case '\t':
+		case ' ':
+			t->offset++;
+			t->line_pos++;
+			break;
+
+		case '\'':
+			/* search for the terminating " */
+			for (i = 1; t->input[t->offset + i] && t->input[t->offset + i] != '\'';  i++);
+
+			if (t->input[t->offset + i]) {
+				tid = TK_VALUE;
+
+				buffer_copy_string_len(token, t->input + t->offset + 1, i-1);
+
+				t->offset += i + 1;
+				t->line_pos += i + 1;
+			} else {
+				/* ERROR */
+
+				log_error_write(srv, __FILE__, __LINE__, "sds",
+						"pos:", t->line_pos,
+						"missing closing quote");
+
+				return -1;
+			}
+
+			break;
+		case '(':
+			t->offset++;
+			t->in_brace++;
+
+			tid = TK_LPARAN;
+
+			buffer_copy_string(token, "(");
+			break;
+		case ')':
+			t->offset++;
+			t->in_brace--;
+
+			tid = TK_RPARAN;
+
+			buffer_copy_string(token, ")");
+			break;
+		case '$':
+			if (t->input[t->offset + 1] == '{') {
+				for (i = 2; t->input[t->offset + i] && t->input[t->offset + i] != '}';  i++);
+
+				if (t->input[t->offset + i] != '}') {
+					log_error_write(srv, __FILE__, __LINE__, "sds",
+							"pos:", t->line_pos,
+							"missing closing quote");
+
+					return -1;
+				}
+
+				buffer_copy_string_len(token, t->input + t->offset + 2, i-3);
+			} else {
+				for (i = 1; isalpha(t->input[t->offset + i]) || t->input[t->offset + i] == '_';  i++);
+
+				buffer_copy_string_len(token, t->input + t->offset + 1, i-1);
+			}
+
+			tid = TK_VALUE;
+
+			if (NULL != (ds = (data_string *)array_get_element(p->ssi_cgi_env, token->ptr))) {
+				buffer_copy_string_buffer(token, ds->value);
+			} else if (NULL != (ds = (data_string *)array_get_element(p->ssi_vars, token->ptr))) {
+				buffer_copy_string_buffer(token, ds->value);
+			} else {
+				buffer_copy_string(token, "");
+			}
+
+			t->offset += i;
+			t->line_pos += i;
+
+			break;
+		default:
+			for (i = 0; isgraph(t->input[t->offset + i]);  i++) {
+				char d = t->input[t->offset + i];
+				switch(d) {
+				case ' ':
+				case '\t':
+				case ')':
+				case '(':
+				case '\'':
+				case '=':
+				case '!':
+				case '<':
+				case '>':
+				case '&':
+				case '|':
+					break;
+				}
+			}
+
+			tid = TK_VALUE;
+
+			buffer_copy_string_len(token, t->input + t->offset, i);
+
+			t->offset += i;
+			t->line_pos += i;
+
+			break;
+		}
+	}
+
+	if (tid) {
+		*token_id = tid;
+
+		return 1;
+	} else if (t->offset < t->size) {
+		log_error_write(srv, __FILE__, __LINE__, "sds",
+				"pos:", t->line_pos,
+				"foobar");
+	}
+	return 0;
+}
+
+int ssi_eval_expr(server *srv, connection *con, plugin_data *p, const char *expr) {
+	ssi_tokenizer_t t;
+	void *pParser;
+	int token_id;
+	buffer *token;
+	ssi_ctx_t context;
+	int ret;
+
+	t.input = expr;
+	t.offset = 0;
+	t.size = strlen(expr);
+	t.line_pos = 1;
+
+	t.in_key = 1;
+	t.in_brace = 0;
+	t.in_cond = 0;
+
+	context.ok = 1;
+	context.srv = srv;
+
+	/* default context */
+
+	pParser = ssiexprparserAlloc( malloc );
+	token = buffer_init();
+	while((1 == (ret = ssi_expr_tokenizer(srv, con, p, &t, &token_id, token))) && context.ok) {
+		ssiexprparser(pParser, token_id, token, &context);
+
+		token = buffer_init();
+	}
+	ssiexprparser(pParser, 0, token, &context);
+	ssiexprparserFree(pParser, free );
+
+	buffer_free(token);
+
+	if (ret == -1) {
+		log_error_write(srv, __FILE__, __LINE__, "s",
+				"expr parser failed");
+		return -1;
+	}
+
+	if (context.ok == 0) {
+		log_error_write(srv, __FILE__, __LINE__, "sds",
+				"pos:", t.line_pos,
+				"parser failed somehow near here");
+		return -1;
+	}
+#if 0
+	log_error_write(srv, __FILE__, __LINE__, "ssd",
+			"expr: ",
+			expr,
+			context.val.bo);
+#endif
+	return context.val.bo;
+}

Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_expr.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_expr.h?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_expr.h (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_expr.h Mon Jul 21 21:35:35 2008
@@ -0,0 +1,31 @@
+#ifndef _MOD_SSI_EXPR_H_
+#define _MOD_SSI_EXPR_H_
+
+#include "buffer.h"
+
+typedef struct {
+	enum { SSI_TYPE_UNSET, SSI_TYPE_BOOL, SSI_TYPE_STRING } type;
+
+	buffer *str;
+	int     bo;
+} ssi_val_t;
+
+typedef struct {
+	int     ok;
+
+	ssi_val_t val;
+
+	void   *srv;
+} ssi_ctx_t;
+
+typedef enum { SSI_COND_UNSET, SSI_COND_LE, SSI_COND_GE, SSI_COND_EQ, SSI_COND_NE, SSI_COND_LT, SSI_COND_GT } ssi_expr_cond;
+
+void *ssiexprparserAlloc(void *(*mallocProc)(size_t));
+void ssiexprparserFree(void *p, void (*freeProc)(void*));
+void ssiexprparser(void *yyp, int yymajor, buffer *yyminor, ssi_ctx_t *ctx);
+
+int ssi_val_tobool(ssi_val_t *B);
+ssi_val_t *ssi_val_init();
+void ssi_val_free(ssi_val_t *s);
+
+#endif

Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_exprparser.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_exprparser.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_exprparser.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_ssi_exprparser.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,951 @@
+/* Driver template for the LEMON parser generator.
+** The author disclaims copyright to this source code.
+*/
+/* First off, code is include which follows the "include" declaration
+** in the input file. */
+#include <stdio.h>
+#line 6 "./mod_ssi_exprparser.y"
+
+#include <assert.h>
+#include <string.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "mod_ssi_expr.h"
+#include "buffer.h"
+
+#line 18 "mod_ssi_exprparser.c"
+/* Next is all token values, in a form suitable for use by makeheaders.
+** This section will be null unless lemon is run with the -m switch.
+*/
+/*
+** These constants (all generated automatically by the parser generator)
+** specify the various kinds of tokens (terminals) that the parser
+** understands.
+**
+** Each symbol here is a terminal symbol in the grammar.
+*/
+/* Make sure the INTERFACE macro is defined.
+*/
+#ifndef INTERFACE
+# define INTERFACE 1
+#endif
+/* The next thing included is series of defines which control
+** various aspects of the generated parser.
+**    YYCODETYPE         is the data type used for storing terminal
+**                       and nonterminal numbers.  "unsigned char" is
+**                       used if there are fewer than 250 terminals
+**                       and nonterminals.  "int" is used otherwise.
+**    YYNOCODE           is a number of type YYCODETYPE which corresponds
+**                       to no legal terminal or nonterminal number.  This
+**                       number is used to fill in empty slots of the hash
+**                       table.
+**    YYFALLBACK         If defined, this indicates that one or more tokens
+**                       have fall-back values which should be used if the
+**                       original value of the token will not parse.
+**    YYACTIONTYPE       is the data type used for storing terminal
+**                       and nonterminal numbers.  "unsigned char" is
+**                       used if there are fewer than 250 rules and
+**                       states combined.  "int" is used otherwise.
+**    ssiexprparserTOKENTYPE     is the data type used for minor tokens given
+**                       directly to the parser from the tokenizer.
+**    YYMINORTYPE        is the data type used for all minor tokens.
+**                       This is typically a union of many types, one of
+**                       which is ssiexprparserTOKENTYPE.  The entry in the union
+**                       for base tokens is called "yy0".
+**    YYSTACKDEPTH       is the maximum depth of the parser's stack.
+**    ssiexprparserARG_SDECL     A static variable declaration for the %extra_argument
+**    ssiexprparserARG_PDECL     A parameter declaration for the %extra_argument
+**    ssiexprparserARG_STORE     Code to store %extra_argument into yypParser
+**    ssiexprparserARG_FETCH     Code to extract %extra_argument from yypParser
+**    YYNSTATE           the combined number of states.
+**    YYNRULE            the number of rules in the grammar
+**    YYERRORSYMBOL      is the code number of the error symbol.  If not
+**                       defined, then do no error processing.
+*/
+/*  */
+#define YYCODETYPE unsigned char
+#define YYNOCODE 20
+#define YYACTIONTYPE unsigned char
+#define ssiexprparserTOKENTYPE buffer *
+typedef union {
+  ssiexprparserTOKENTYPE yy0;
+  int yy8;
+  buffer * yy19;
+  ssi_val_t * yy29;
+  int yy39;
+} YYMINORTYPE;
+#define YYSTACKDEPTH 100
+#define ssiexprparserARG_SDECL ssi_ctx_t *ctx;
+#define ssiexprparserARG_PDECL ,ssi_ctx_t *ctx
+#define ssiexprparserARG_FETCH ssi_ctx_t *ctx = yypParser->ctx
+#define ssiexprparserARG_STORE yypParser->ctx = ctx
+#define YYNSTATE 23
+#define YYNRULE 16
+#define YYERRORSYMBOL 13
+#define YYERRSYMDT yy39
+#define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
+#define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
+#define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
+
+/* Next are that tables used to determine what action to take based on the
+** current state and lookahead token.  These tables are used to implement
+** functions that take a state number and lookahead value and return an
+** action integer.
+**
+** Suppose the action integer is N.  Then the action is determined as
+** follows
+**
+**   0 <= N < YYNSTATE                  Shift N.  That is, push the lookahead
+**                                      token onto the stack and goto state N.
+**
+**   YYNSTATE <= N < YYNSTATE+YYNRULE   Reduce by rule N-YYNSTATE.
+**
+**   N == YYNSTATE+YYNRULE              A syntax error has occurred.
+**
+**   N == YYNSTATE+YYNRULE+1            The parser accepts its input.
+**
+**   N == YYNSTATE+YYNRULE+2            No such action.  Denotes unused
+**                                      slots in the yy_action[] table.
+**
+** The action table is constructed as a single large table named yy_action[].
+** Given state S and lookahead X, the action is computed as
+**
+**      yy_action[ yy_shift_ofst[S] + X ]
+**
+** If the index value yy_shift_ofst[S]+X is out of range or if the value
+** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
+** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
+** and that yy_default[S] should be used instead.
+**
+** The formula above is for computing the action when the lookahead is
+** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
+** a reduce action) then the yy_reduce_ofst[] array is used in place of
+** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
+** YY_SHIFT_USE_DFLT.
+**
+** The following are the tables generated in this section:
+**
+**  yy_action[]        A single table containing all actions.
+**  yy_lookahead[]     A table containing the lookahead for each entry in
+**                     yy_action.  Used to detect hash collisions.
+**  yy_shift_ofst[]    For each state, the offset into yy_action for
+**                     shifting terminals.
+**  yy_reduce_ofst[]   For each state, the offset into yy_action for
+**                     shifting non-terminals after a reduce.
+**  yy_default[]       Default action for each state.
+*/
+static YYACTIONTYPE yy_action[] = {
+ /*     0 */     5,    7,   17,   18,   22,   20,   21,   19,    2,   14,
+ /*    10 */     1,   23,   40,    9,   11,    3,   16,    2,   14,   12,
+ /*    20 */     4,   14,    5,    7,    6,   14,    7,    8,   14,   10,
+ /*    30 */    14,   13,   37,   37,   15,
+};
+static YYCODETYPE yy_lookahead[] = {
+ /*     0 */     1,    2,    3,    4,    5,    6,    7,    8,   14,   15,
+ /*    10 */    16,    0,   18,    9,   10,   17,   12,   14,   15,   16,
+ /*    20 */    14,   15,    1,    2,   14,   15,    2,   14,   15,   14,
+ /*    30 */    15,   11,   19,   19,   12,
+};
+#define YY_SHIFT_USE_DFLT (-2)
+static signed char yy_shift_ofst[] = {
+ /*     0 */     4,   11,   -1,    4,   21,    4,   24,    4,   -2,    4,
+ /*    10 */    -2,    4,   20,   -2,   22,   -2,   -2,   -2,   -2,   -2,
+ /*    20 */    -2,   -2,   -2,
+};
+#define YY_REDUCE_USE_DFLT (-7)
+static signed char yy_reduce_ofst[] = {
+ /*     0 */    -6,   -7,   -2,    6,   -7,   10,   -7,   13,   -7,   15,
+ /*    10 */    -7,    3,   -7,   -7,   -7,   -7,   -7,   -7,   -7,   -7,
+ /*    20 */    -7,   -7,   -7,
+};
+static YYACTIONTYPE yy_default[] = {
+ /*     0 */    39,   39,   25,   39,   24,   39,   26,   39,   27,   39,
+ /*    10 */    28,   39,   39,   29,   30,   32,   31,   33,   34,   35,
+ /*    20 */    36,   37,   38,
+};
+#define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0]))
+
+/* The next table maps tokens into fallback tokens.  If a construct
+** like the following:
+**
+**      %fallback ID X Y Z.
+**
+** appears in the grammer, then ID becomes a fallback token for X, Y,
+** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
+** but it does not parse, the type of the token is changed to ID and
+** the parse is retried before an error is thrown.
+*/
+#ifdef YYFALLBACK
+static const YYCODETYPE yyFallback[] = {
+};
+#endif /* YYFALLBACK */
+
+/* The following structure represents a single element of the
+** parser's stack.  Information stored includes:
+**
+**   +  The state number for the parser at this level of the stack.
+**
+**   +  The value of the token stored at this level of the stack.
+**      (In other words, the "major" token.)
+**
+**   +  The semantic value stored at this level of the stack.  This is
+**      the information used by the action routines in the grammar.
+**      It is sometimes called the "minor" token.
+*/
+struct yyStackEntry {
+  int stateno;       /* The state-number */
+  int major;         /* The major token value.  This is the code
+                     ** number for the token at this stack level */
+  YYMINORTYPE minor; /* The user-supplied minor token value.  This
+                     ** is the value of the token  */
+};
+typedef struct yyStackEntry yyStackEntry;
+
+/* The state of the parser is completely contained in an instance of
+** the following structure */
+struct yyParser {
+  int yyidx;                    /* Index of top element in stack */
+  int yyerrcnt;                 /* Shifts left before out of the error */
+  ssiexprparserARG_SDECL                /* A place to hold %extra_argument */
+  yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
+};
+typedef struct yyParser yyParser;
+
+#ifndef NDEBUG
+#include <stdio.h>
+static FILE *yyTraceFILE = 0;
+static char *yyTracePrompt = 0;
+#endif /* NDEBUG */
+
+#ifndef NDEBUG
+/*
+** Turn parser tracing on by giving a stream to which to write the trace
+** and a prompt to preface each trace message.  Tracing is turned off
+** by making either argument NULL
+**
+** Inputs:
+** <ul>
+** <li> A FILE* to which trace output should be written.
+**      If NULL, then tracing is turned off.
+** <li> A prefix string written at the beginning of every
+**      line of trace output.  If NULL, then tracing is
+**      turned off.
+** </ul>
+**
+** Outputs:
+** None.
+*/
+void ssiexprparserTrace(FILE *TraceFILE, char *zTracePrompt){
+  yyTraceFILE = TraceFILE;
+  yyTracePrompt = zTracePrompt;
+  if( yyTraceFILE==0 ) yyTracePrompt = 0;
+  else if( yyTracePrompt==0 ) yyTraceFILE = 0;
+}
+#endif /* NDEBUG */
+
+#ifndef NDEBUG
+/* For tracing shifts, the names of all terminals and nonterminals
+** are required.  The following table supplies these names */
+static const char *yyTokenName[] = {
+  "$",             "AND",           "OR",            "EQ",          
+  "NE",            "GT",            "GE",            "LT",          
+  "LE",            "NOT",           "LPARAN",        "RPARAN",      
+  "VALUE",         "error",         "expr",          "value",       
+  "exprline",      "cond",          "input",       
+};
+#endif /* NDEBUG */
+
+#ifndef NDEBUG
+/* For tracing reduce actions, the names of all rules are required.
+*/
+static const char *yyRuleName[] = {
+ /*   0 */ "input ::= exprline",
+ /*   1 */ "exprline ::= expr cond expr",
+ /*   2 */ "exprline ::= expr",
+ /*   3 */ "expr ::= expr AND expr",
+ /*   4 */ "expr ::= expr OR expr",
+ /*   5 */ "expr ::= NOT expr",
+ /*   6 */ "expr ::= LPARAN exprline RPARAN",
+ /*   7 */ "expr ::= value",
+ /*   8 */ "value ::= VALUE",
+ /*   9 */ "value ::= value VALUE",
+ /*  10 */ "cond ::= EQ",
+ /*  11 */ "cond ::= NE",
+ /*  12 */ "cond ::= LE",
+ /*  13 */ "cond ::= GE",
+ /*  14 */ "cond ::= LT",
+ /*  15 */ "cond ::= GT",
+};
+#endif /* NDEBUG */
+
+/*
+** This function returns the symbolic name associated with a token
+** value.
+*/
+const char *ssiexprparserTokenName(int tokenType){
+#ifndef NDEBUG
+  if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
+    return yyTokenName[tokenType];
+  }else{
+    return "Unknown";
+  }
+#else
+  return "";
+#endif
+}
+
+/*
+** This function allocates a new parser.
+** The only argument is a pointer to a function which works like
+** malloc.
+**
+** Inputs:
+** A pointer to the function used to allocate memory.
+**
+** Outputs:
+** A pointer to a parser.  This pointer is used in subsequent calls
+** to ssiexprparser and ssiexprparserFree.
+*/
+void *ssiexprparserAlloc(void *(*mallocProc)(size_t)){
+  yyParser *pParser;
+  pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
+  if( pParser ){
+    pParser->yyidx = -1;
+  }
+  return pParser;
+}
+
+/* The following function deletes the value associated with a
+** symbol.  The symbol can be either a terminal or nonterminal.
+** "yymajor" is the symbol code, and "yypminor" is a pointer to
+** the value.
+*/
+static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
+  switch( yymajor ){
+    /* Here is inserted the actions which take place when a
+    ** terminal or non-terminal is destroyed.  This can happen
+    ** when the symbol is popped from the stack during a
+    ** reduce or during error processing or when a parser is
+    ** being destroyed before it is finished parsing.
+    **
+    ** Note: during a reduce, the only symbols destroyed are those
+    ** which appear on the RHS of the rule, but which are not used
+    ** inside the C code.
+    */
+    case 1:
+    case 2:
+    case 3:
+    case 4:
+    case 5:
+    case 6:
+    case 7:
+    case 8:
+    case 9:
+    case 10:
+    case 11:
+    case 12:
+#line 24 "./mod_ssi_exprparser.y"
+{ buffer_free((yypminor->yy0)); }
+#line 350 "mod_ssi_exprparser.c"
+      break;
+    default:  break;   /* If no destructor action specified: do nothing */
+  }
+}
+
+/*
+** Pop the parser's stack once.
+**
+** If there is a destructor routine associated with the token which
+** is popped from the stack, then call it.
+**
+** Return the major token number for the symbol popped.
+*/
+static int yy_pop_parser_stack(yyParser *pParser){
+  YYCODETYPE yymajor;
+  yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
+
+  if( pParser->yyidx<0 ) return 0;
+#ifndef NDEBUG
+  if( yyTraceFILE && pParser->yyidx>=0 ){
+    fprintf(yyTraceFILE,"%sPopping %s\n",
+      yyTracePrompt,
+      yyTokenName[yytos->major]);
+  }
+#endif
+  yymajor = yytos->major;
+  yy_destructor( yymajor, &yytos->minor);
+  pParser->yyidx--;
+  return yymajor;
+}
+
+/*
+** Deallocate and destroy a parser.  Destructors are all called for
+** all stack elements before shutting the parser down.
+**
+** Inputs:
+** <ul>
+** <li>  A pointer to the parser.  This should be a pointer
+**       obtained from ssiexprparserAlloc.
+** <li>  A pointer to a function used to reclaim memory obtained
+**       from malloc.
+** </ul>
+*/
+void ssiexprparserFree(
+  void *p,                    /* The parser to be deleted */
+  void (*freeProc)(void*)     /* Function used to reclaim memory */
+){
+  yyParser *pParser = (yyParser*)p;
+  if( pParser==0 ) return;
+  while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
+  (*freeProc)((void*)pParser);
+}
+
+/*
+** Find the appropriate action for a parser given the terminal
+** look-ahead token iLookAhead.
+**
+** If the look-ahead token is YYNOCODE, then check to see if the action is
+** independent of the look-ahead.  If it is, return the action, otherwise
+** return YY_NO_ACTION.
+*/
+static int yy_find_shift_action(
+  yyParser *pParser,        /* The parser */
+  int iLookAhead            /* The look-ahead token */
+){
+  int i;
+  int stateno = pParser->yystack[pParser->yyidx].stateno;
+
+  /* if( pParser->yyidx<0 ) return YY_NO_ACTION;  */
+  i = yy_shift_ofst[stateno];
+  if( i==YY_SHIFT_USE_DFLT ){
+    return yy_default[stateno];
+  }
+  if( iLookAhead==YYNOCODE ){
+    return YY_NO_ACTION;
+  }
+  i += iLookAhead;
+  if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
+#ifdef YYFALLBACK
+    int iFallback;            /* Fallback token */
+    if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
+           && (iFallback = yyFallback[iLookAhead])!=0 ){
+#ifndef NDEBUG
+      if( yyTraceFILE ){
+        fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
+           yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
+      }
+#endif
+      return yy_find_shift_action(pParser, iFallback);
+    }
+#endif
+    return yy_default[stateno];
+  }else{
+    return yy_action[i];
+  }
+}
+
+/*
+** Find the appropriate action for a parser given the non-terminal
+** look-ahead token iLookAhead.
+**
+** If the look-ahead token is YYNOCODE, then check to see if the action is
+** independent of the look-ahead.  If it is, return the action, otherwise
+** return YY_NO_ACTION.
+*/
+static int yy_find_reduce_action(
+  yyParser *pParser,        /* The parser */
+  int iLookAhead            /* The look-ahead token */
+){
+  int i;
+  int stateno = pParser->yystack[pParser->yyidx].stateno;
+
+  i = yy_reduce_ofst[stateno];
+  if( i==YY_REDUCE_USE_DFLT ){
+    return yy_default[stateno];
+  }
+  if( iLookAhead==YYNOCODE ){
+    return YY_NO_ACTION;
+  }
+  i += iLookAhead;
+  if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
+    return yy_default[stateno];
+  }else{
+    return yy_action[i];
+  }
+}
+
+/*
+** Perform a shift action.
+*/
+static void yy_shift(
+  yyParser *yypParser,          /* The parser to be shifted */
+  int yyNewState,               /* The new state to shift in */
+  int yyMajor,                  /* The major token to shift in */
+  YYMINORTYPE *yypMinor         /* Pointer ot the minor token to shift in */
+){
+  yyStackEntry *yytos;
+  yypParser->yyidx++;
+  if( yypParser->yyidx>=YYSTACKDEPTH ){
+     ssiexprparserARG_FETCH;
+     yypParser->yyidx--;
+#ifndef NDEBUG
+     if( yyTraceFILE ){
+       fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
+     }
+#endif
+     while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
+     /* Here code is inserted which will execute if the parser
+     ** stack every overflows */
+     ssiexprparserARG_STORE; /* Suppress warning about unused %extra_argument var */
+     return;
+  }
+  yytos = &yypParser->yystack[yypParser->yyidx];
+  yytos->stateno = yyNewState;
+  yytos->major = yyMajor;
+  yytos->minor = *yypMinor;
+#ifndef NDEBUG
+  if( yyTraceFILE && yypParser->yyidx>0 ){
+    int i;
+    fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
+    fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
+    for(i=1; i<=yypParser->yyidx; i++)
+      fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
+    fprintf(yyTraceFILE,"\n");
+  }
+#endif
+}
+
+/* The following table contains information about every rule that
+** is used during the reduce.
+*/
+static struct {
+  YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
+  unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
+} yyRuleInfo[] = {
+  { 18, 1 },
+  { 16, 3 },
+  { 16, 1 },
+  { 14, 3 },
+  { 14, 3 },
+  { 14, 2 },
+  { 14, 3 },
+  { 14, 1 },
+  { 15, 1 },
+  { 15, 2 },
+  { 17, 1 },
+  { 17, 1 },
+  { 17, 1 },
+  { 17, 1 },
+  { 17, 1 },
+  { 17, 1 },
+};
+
+static void yy_accept(yyParser*);  /* Forward Declaration */
+
+/*
+** Perform a reduce action and the shift that must immediately
+** follow the reduce.
+*/
+static void yy_reduce(
+  yyParser *yypParser,         /* The parser */
+  int yyruleno                 /* Number of the rule by which to reduce */
+){
+  int yygoto;                     /* The next state */
+  int yyact;                      /* The next action */
+  YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
+  yyStackEntry *yymsp;            /* The top of the parser's stack */
+  int yysize;                     /* Amount to pop the stack */
+  ssiexprparserARG_FETCH;
+  yymsp = &yypParser->yystack[yypParser->yyidx];
+#ifndef NDEBUG
+  if( yyTraceFILE && yyruleno>=0
+        && yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
+    fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
+      yyRuleName[yyruleno]);
+  }
+#endif /* NDEBUG */
+
+  switch( yyruleno ){
+  /* Beginning here are the reduction cases.  A typical example
+  ** follows:
+  **   case 0:
+  **  #line <lineno> <grammarfile>
+  **     { ... }           // User supplied code
+  **  #line <lineno> <thisfile>
+  **     break;
+  */
+      case 0:
+#line 31 "./mod_ssi_exprparser.y"
+{
+  ctx->val.bo = ssi_val_tobool(yymsp[0].minor.yy29);
+  ctx->val.type = SSI_TYPE_BOOL;
+
+  ssi_val_free(yymsp[0].minor.yy29);
+}
+#line 586 "mod_ssi_exprparser.c"
+        break;
+      case 1:
+#line 38 "./mod_ssi_exprparser.y"
+{
+  int cmp;
+
+  if (yymsp[-2].minor.yy29->type == SSI_TYPE_STRING &&
+      yymsp[0].minor.yy29->type == SSI_TYPE_STRING) {
+       cmp = strcmp(yymsp[-2].minor.yy29->str->ptr, yymsp[0].minor.yy29->str->ptr);
+  } else {
+    cmp = ssi_val_tobool(yymsp[-2].minor.yy29) - ssi_val_tobool(yymsp[0].minor.yy29);
+  }
+
+  yygotominor.yy29 = yymsp[-2].minor.yy29;
+
+  switch(yymsp[-1].minor.yy8) {
+  case SSI_COND_EQ: yygotominor.yy29->bo = (cmp == 0) ? 1 : 0; break;
+  case SSI_COND_NE: yygotominor.yy29->bo = (cmp != 0) ? 1 : 0; break;
+  case SSI_COND_GE: yygotominor.yy29->bo = (cmp >= 0) ? 1 : 0; break;
+  case SSI_COND_GT: yygotominor.yy29->bo = (cmp > 0) ? 1 : 0; break;
+  case SSI_COND_LE: yygotominor.yy29->bo = (cmp <= 0) ? 1 : 0; break;
+  case SSI_COND_LT: yygotominor.yy29->bo = (cmp < 0) ? 1 : 0; break;
+  }
+
+  yygotominor.yy29->type = SSI_TYPE_BOOL;
+
+  ssi_val_free(yymsp[0].minor.yy29);
+}
+#line 615 "mod_ssi_exprparser.c"
+        break;
+      case 2:
+#line 63 "./mod_ssi_exprparser.y"
+{
+  yygotominor.yy29 = yymsp[0].minor.yy29;
+}
+#line 622 "mod_ssi_exprparser.c"
+        break;
+      case 3:
+#line 66 "./mod_ssi_exprparser.y"
+{
+  int e;
+
+  e = ssi_val_tobool(yymsp[-2].minor.yy29) && ssi_val_tobool(yymsp[0].minor.yy29);
+
+  yygotominor.yy29 = yymsp[-2].minor.yy29;
+  yygotominor.yy29->bo = e;
+  yygotominor.yy29->type = SSI_TYPE_BOOL;
+  ssi_val_free(yymsp[0].minor.yy29);
+}
+#line 636 "mod_ssi_exprparser.c"
+  yy_destructor(1,&yymsp[-1].minor);
+        break;
+      case 4:
+#line 77 "./mod_ssi_exprparser.y"
+{
+  int e;
+
+  e = ssi_val_tobool(yymsp[-2].minor.yy29) || ssi_val_tobool(yymsp[0].minor.yy29);
+
+  yygotominor.yy29 = yymsp[-2].minor.yy29;
+  yygotominor.yy29->bo = e;
+  yygotominor.yy29->type = SSI_TYPE_BOOL;
+  ssi_val_free(yymsp[0].minor.yy29);
+}
+#line 651 "mod_ssi_exprparser.c"
+  yy_destructor(2,&yymsp[-1].minor);
+        break;
+      case 5:
+#line 88 "./mod_ssi_exprparser.y"
+{
+  int e;
+
+  e = !ssi_val_tobool(yymsp[0].minor.yy29);
+
+  yygotominor.yy29 = yymsp[0].minor.yy29;
+  yygotominor.yy29->bo = e;
+  yygotominor.yy29->type = SSI_TYPE_BOOL;
+}
+#line 665 "mod_ssi_exprparser.c"
+  yy_destructor(9,&yymsp[-1].minor);
+        break;
+      case 6:
+#line 97 "./mod_ssi_exprparser.y"
+{
+  yygotominor.yy29 = yymsp[-1].minor.yy29;
+}
+#line 673 "mod_ssi_exprparser.c"
+  yy_destructor(10,&yymsp[-2].minor);
+  yy_destructor(11,&yymsp[0].minor);
+        break;
+      case 7:
+#line 101 "./mod_ssi_exprparser.y"
+{
+  yygotominor.yy29 = ssi_val_init();
+  yygotominor.yy29->str = yymsp[0].minor.yy19;
+  yygotominor.yy29->type = SSI_TYPE_STRING;
+}
+#line 684 "mod_ssi_exprparser.c"
+        break;
+      case 8:
+#line 107 "./mod_ssi_exprparser.y"
+{
+  yygotominor.yy19 = buffer_init_string(yymsp[0].minor.yy0->ptr);
+}
+#line 691 "mod_ssi_exprparser.c"
+        break;
+      case 9:
+#line 111 "./mod_ssi_exprparser.y"
+{
+  yygotominor.yy19 = yymsp[-1].minor.yy19;
+  buffer_append_string_buffer(yygotominor.yy19, yymsp[0].minor.yy0);
+}
+#line 699 "mod_ssi_exprparser.c"
+        break;
+      case 10:
+#line 116 "./mod_ssi_exprparser.y"
+{ yygotominor.yy8 = SSI_COND_EQ; }
+#line 704 "mod_ssi_exprparser.c"
+  yy_destructor(3,&yymsp[0].minor);
+        break;
+      case 11:
+#line 117 "./mod_ssi_exprparser.y"
+{ yygotominor.yy8 = SSI_COND_NE; }
+#line 710 "mod_ssi_exprparser.c"
+  yy_destructor(4,&yymsp[0].minor);
+        break;
+      case 12:
+#line 118 "./mod_ssi_exprparser.y"
+{ yygotominor.yy8 = SSI_COND_LE; }
+#line 716 "mod_ssi_exprparser.c"
+  yy_destructor(8,&yymsp[0].minor);
+        break;
+      case 13:
+#line 119 "./mod_ssi_exprparser.y"
+{ yygotominor.yy8 = SSI_COND_GE; }
+#line 722 "mod_ssi_exprparser.c"
+  yy_destructor(6,&yymsp[0].minor);
+        break;
+      case 14:
+#line 120 "./mod_ssi_exprparser.y"
+{ yygotominor.yy8 = SSI_COND_LT; }
+#line 728 "mod_ssi_exprparser.c"
+  yy_destructor(7,&yymsp[0].minor);
+        break;
+      case 15:
+#line 121 "./mod_ssi_exprparser.y"
+{ yygotominor.yy8 = SSI_COND_GT; }
+#line 734 "mod_ssi_exprparser.c"
+  yy_destructor(5,&yymsp[0].minor);
+        break;
+  };
+  yygoto = yyRuleInfo[yyruleno].lhs;
+  yysize = yyRuleInfo[yyruleno].nrhs;
+  yypParser->yyidx -= yysize;
+  yyact = yy_find_reduce_action(yypParser,yygoto);
+  if( yyact < YYNSTATE ){
+    yy_shift(yypParser,yyact,yygoto,&yygotominor);
+  }else if( yyact == YYNSTATE + YYNRULE + 1 ){
+    yy_accept(yypParser);
+  }
+}
+
+/*
+** The following code executes when the parse fails
+*/
+static void yy_parse_failed(
+  yyParser *yypParser           /* The parser */
+){
+  ssiexprparserARG_FETCH;
+#ifndef NDEBUG
+  if( yyTraceFILE ){
+    fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
+  }
+#endif
+  while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
+  /* Here code is inserted which will be executed whenever the
+  ** parser fails */
+#line 16 "./mod_ssi_exprparser.y"
+
+  ctx->ok = 0;
+
+#line 768 "mod_ssi_exprparser.c"
+  ssiexprparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
+}
+
+/*
+** The following code executes when a syntax error first occurs.
+*/
+static void yy_syntax_error(
+  yyParser *yypParser,           /* The parser */
+  int yymajor,                   /* The major type of the error token */
+  YYMINORTYPE yyminor            /* The minor type of the error token */
+){
+  ssiexprparserARG_FETCH;
+#define TOKEN (yyminor.yy0)
+  ssiexprparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
+}
+
+/*
+** The following is executed when the parser accepts
+*/
+static void yy_accept(
+  yyParser *yypParser           /* The parser */
+){
+  ssiexprparserARG_FETCH;
+#ifndef NDEBUG
+  if( yyTraceFILE ){
+    fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
+  }
+#endif
+  while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
+  /* Here code is inserted which will be executed whenever the
+  ** parser accepts */
+  ssiexprparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
+}
+
+/* The main parser program.
+** The first argument is a pointer to a structure obtained from
+** "ssiexprparserAlloc" which describes the current state of the parser.
+** The second argument is the major token number.  The third is
+** the minor token.  The fourth optional argument is whatever the
+** user wants (and specified in the grammar) and is available for
+** use by the action routines.
+**
+** Inputs:
+** <ul>
+** <li> A pointer to the parser (an opaque structure.)
+** <li> The major token number.
+** <li> The minor token number.
+** <li> An option argument of a grammar-specified type.
+** </ul>
+**
+** Outputs:
+** None.
+*/
+void ssiexprparser(
+  void *yyp,                   /* The parser */
+  int yymajor,                 /* The major token code number */
+  ssiexprparserTOKENTYPE yyminor       /* The value for the token */
+  ssiexprparserARG_PDECL               /* Optional %extra_argument parameter */
+){
+  YYMINORTYPE yyminorunion;
+  int yyact;            /* The parser action. */
+  int yyendofinput;     /* True if we are at the end of input */
+  int yyerrorhit = 0;   /* True if yymajor has invoked an error */
+  yyParser *yypParser;  /* The parser */
+
+  /* (re)initialize the parser, if necessary */
+  yypParser = (yyParser*)yyp;
+  if( yypParser->yyidx<0 ){
+    if( yymajor==0 ) return;
+    yypParser->yyidx = 0;
+    yypParser->yyerrcnt = -1;
+    yypParser->yystack[0].stateno = 0;
+    yypParser->yystack[0].major = 0;
+  }
+  yyminorunion.yy0 = yyminor;
+  yyendofinput = (yymajor==0);
+  ssiexprparserARG_STORE;
+
+#ifndef NDEBUG
+  if( yyTraceFILE ){
+    fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
+  }
+#endif
+
+  do{
+    yyact = yy_find_shift_action(yypParser,yymajor);
+    if( yyact<YYNSTATE ){
+      yy_shift(yypParser,yyact,yymajor,&yyminorunion);
+      yypParser->yyerrcnt--;
+      if( yyendofinput && yypParser->yyidx>=0 ){
+        yymajor = 0;
+      }else{
+        yymajor = YYNOCODE;
+      }
+    }else if( yyact < YYNSTATE + YYNRULE ){
+      yy_reduce(yypParser,yyact-YYNSTATE);
+    }else if( yyact == YY_ERROR_ACTION ){
+      int yymx;
+#ifndef NDEBUG
+      if( yyTraceFILE ){
+        fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
+      }
+#endif
+#ifdef YYERRORSYMBOL
+      /* A syntax error has occurred.
+      ** The response to an error depends upon whether or not the
+      ** grammar defines an error token "ERROR".
+      **
+      ** This is what we do if the grammar does define ERROR:
+      **
+      **  * Call the %syntax_error function.
+      **
+      **  * Begin popping the stack until we enter a state where
+      **    it is legal to shift the error symbol, then shift
+      **    the error symbol.
+      **
+      **  * Set the error count to three.
+      **
+      **  * Begin accepting and shifting new tokens.  No new error
+      **    processing will occur until three tokens have been
+      **    shifted successfully.
+      **
+      */
+      if( yypParser->yyerrcnt<0 ){
+        yy_syntax_error(yypParser,yymajor,yyminorunion);
+      }
+      yymx = yypParser->yystack[yypParser->yyidx].major;
+      if( yymx==YYERRORSYMBOL || yyerrorhit ){
+#ifndef NDEBUG
+        if( yyTraceFILE ){
+          fprintf(yyTraceFILE,"%sDiscard input token %s\n",
+             yyTracePrompt,yyTokenName[yymajor]);
+        }
+#endif
+        yy_destructor(yymajor,&yyminorunion);
+        yymajor = YYNOCODE;
+      }else{
+         while(
+          yypParser->yyidx >= 0 &&
+          yymx != YYERRORSYMBOL &&
+          (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE
+        ){
+          yy_pop_parser_stack(yypParser);
+        }
+        if( yypParser->yyidx < 0 || yymajor==0 ){
+          yy_destructor(yymajor,&yyminorunion);
+          yy_parse_failed(yypParser);
+          yymajor = YYNOCODE;
+        }else if( yymx!=YYERRORSYMBOL ){
+          YYMINORTYPE u2;
+          u2.YYERRSYMDT = 0;
+          yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
+        }
+      }
+      yypParser->yyerrcnt = 3;
+      yyerrorhit = 1;
+#else  /* YYERRORSYMBOL is not defined */
+      /* This is what we do if the grammar does not define ERROR:
+      **
+      **  * Report an error message, and throw away the input token.
+      **
+      **  * If the input token is $, then fail the parse.
+      **
+      ** As before, subsequent error messages are suppressed until
+      ** three input tokens have been successfully shifted.
+      */
+      if( yypParser->yyerrcnt<=0 ){
+        yy_syntax_error(yypParser,yymajor,yyminorunion);
+      }
+      yypParser->yyerrcnt = 3;
+      yy_destructor(yymajor,&yyminorunion);
+      if( yyendofinput ){
+        yy_parse_failed(yypParser);
+      }
+      yymajor = YYNOCODE;
+#endif
+    }else{
+      yy_accept(yypParser);
+      yymajor = YYNOCODE;
+    }
+  }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
+  return;
+}