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 [30/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_accesslog.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_accesslog.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_accesslog.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_accesslog.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,877 @@
+#define _GNU_SOURCE
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <time.h>
+
+#include <stdio.h>
+
+#include "base.h"
+#include "log.h"
+#include "buffer.h"
+
+#include "plugin.h"
+
+#include "inet_ntop_cache.h"
+
+#include "sys-socket.h"
+
+#ifdef HAVE_SYSLOG_H
+# include <syslog.h>
+#endif
+
+typedef struct {
+ char key;
+ enum {
+ FORMAT_UNSET,
+ FORMAT_UNSUPPORTED,
+ FORMAT_PERCENT,
+ FORMAT_REMOTE_HOST,
+ FORMAT_REMOTE_IDENT,
+ FORMAT_REMOTE_USER,
+ FORMAT_TIMESTAMP,
+ FORMAT_REQUEST_LINE,
+ FORMAT_STATUS,
+ FORMAT_BYTES_OUT_NO_HEADER,
+ FORMAT_HEADER,
+
+ FORMAT_REMOTE_ADDR,
+ FORMAT_LOCAL_ADDR,
+ FORMAT_COOKIE,
+ FORMAT_TIME_USED_MS,
+ FORMAT_ENV,
+ FORMAT_FILENAME,
+ FORMAT_REQUEST_PROTOCOL,
+ FORMAT_REQUEST_METHOD,
+ FORMAT_SERVER_PORT,
+ FORMAT_QUERY_STRING,
+ FORMAT_TIME_USED,
+ FORMAT_URL,
+ FORMAT_SERVER_NAME,
+ FORMAT_HTTP_HOST,
+ FORMAT_CONNECTION_STATUS,
+ FORMAT_BYTES_IN,
+ FORMAT_BYTES_OUT,
+
+ FORMAT_RESPONSE_HEADER
+ } type;
+} format_mapping;
+
+/**
+ *
+ *
+ * "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
+ *
+ */
+
+const format_mapping fmap[] =
+{
+ { '%', FORMAT_PERCENT },
+ { 'h', FORMAT_REMOTE_HOST },
+ { 'l', FORMAT_REMOTE_IDENT },
+ { 'u', FORMAT_REMOTE_USER },
+ { 't', FORMAT_TIMESTAMP },
+ { 'r', FORMAT_REQUEST_LINE },
+ { 's', FORMAT_STATUS },
+ { 'b', FORMAT_BYTES_OUT_NO_HEADER },
+ { 'i', FORMAT_HEADER },
+
+ { 'a', FORMAT_REMOTE_ADDR },
+ { 'A', FORMAT_LOCAL_ADDR },
+ { 'B', FORMAT_BYTES_OUT_NO_HEADER },
+ { 'C', FORMAT_COOKIE },
+ { 'D', FORMAT_TIME_USED_MS },
+ { 'e', FORMAT_ENV },
+ { 'f', FORMAT_FILENAME },
+ { 'H', FORMAT_REQUEST_PROTOCOL },
+ { 'm', FORMAT_REQUEST_METHOD },
+ { 'n', FORMAT_UNSUPPORTED }, /* we have no notes */
+ { 'p', FORMAT_SERVER_PORT },
+ { 'P', FORMAT_UNSUPPORTED }, /* we are only one process */
+ { 'q', FORMAT_QUERY_STRING },
+ { 'T', FORMAT_TIME_USED },
+ { 'U', FORMAT_URL }, /* w/o querystring */
+ { 'v', FORMAT_SERVER_NAME },
+ { 'V', FORMAT_HTTP_HOST },
+ { 'X', FORMAT_CONNECTION_STATUS },
+ { 'I', FORMAT_BYTES_IN },
+ { 'O', FORMAT_BYTES_OUT },
+
+ { 'o', FORMAT_RESPONSE_HEADER },
+
+ { '\0', FORMAT_UNSET }
+};
+
+
+typedef struct {
+ enum { FIELD_UNSET, FIELD_STRING, FIELD_FORMAT } type;
+
+ buffer *string;
+ int field;
+} format_field;
+
+typedef struct {
+ format_field **ptr;
+
+ size_t used;
+ size_t size;
+} format_fields;
+
+typedef struct {
+ buffer *access_logfile;
+ buffer *format;
+ unsigned short use_syslog;
+
+
+ int log_access_fd;
+ time_t last_generated_accesslog_ts;
+ time_t *last_generated_accesslog_ts_ptr;
+
+
+ buffer *access_logbuffer;
+ buffer *ts_accesslog_str;
+
+ format_fields *parsed_format;
+} plugin_config;
+
+typedef struct {
+ PLUGIN_DATA;
+
+ plugin_config **config_storage;
+ plugin_config conf;
+} plugin_data;
+
+INIT_FUNC(mod_accesslog_init) {
+ plugin_data *p;
+
+ p = calloc(1, sizeof(*p));
+
+ return p;
+}
+
+int accesslog_parse_format(server *srv, format_fields *fields, buffer *format) {
+ size_t i, j, k = 0, start = 0;
+
+ if (format->used == 0) return -1;
+
+ for (i = 0; i < format->used - 1; i++) {
+ switch(format->ptr[i]) {
+ case '%':
+ if (i > 0 && start != i) {
+ /* copy the string before this % */
+ if (fields->size == 0) {
+ fields->size = 16;
+ fields->used = 0;
+ fields->ptr = malloc(fields->size * sizeof(format_fields * ));
+ } else if (fields->used == fields->size) {
+ fields->size += 16;
+ fields->ptr = realloc(fields->ptr, fields->size * sizeof(format_fields * ));
+ }
+
+ fields->ptr[fields->used] = malloc(sizeof(format_fields));
+ fields->ptr[fields->used]->type = FIELD_STRING;
+ fields->ptr[fields->used]->string = buffer_init();
+
+ buffer_copy_string_len(fields->ptr[fields->used]->string, format->ptr + start, i - start);
+
+ fields->used++;
+ }
+
+ /* we need a new field */
+
+ if (fields->size == 0) {
+ fields->size = 16;
+ fields->used = 0;
+ fields->ptr = malloc(fields->size * sizeof(format_fields * ));
+ } else if (fields->used == fields->size) {
+ fields->size += 16;
+ fields->ptr = realloc(fields->ptr, fields->size * sizeof(format_fields * ));
+ }
+
+ /* search for the terminating command */
+ switch (format->ptr[i+1]) {
+ case '>':
+ case '<':
+ /* after the } has to be a character */
+ if (format->ptr[i+2] == '\0') {
+ log_error_write(srv, __FILE__, __LINE__, "s", "%< and %> have to be followed by a format-specifier");
+ return -1;
+ }
+
+
+ for (j = 0; fmap[j].key != '\0'; j++) {
+ if (fmap[j].key != format->ptr[i+2]) continue;
+
+ /* found key */
+
+ fields->ptr[fields->used] = malloc(sizeof(format_fields));
+ fields->ptr[fields->used]->type = FIELD_FORMAT;
+ fields->ptr[fields->used]->field = fmap[j].type;
+ fields->ptr[fields->used]->string = NULL;
+
+ fields->used++;
+
+ break;
+ }
+
+ if (fmap[j].key == '\0') {
+ log_error_write(srv, __FILE__, __LINE__, "s", "%< and %> have to be followed by a valid format-specifier");
+ return -1;
+ }
+
+ start = i + 3;
+ i = start - 1; /* skip the string */
+
+ break;
+ case '{':
+ /* go forward to } */
+
+ for (k = i+2; k < format->used - 1; k++) {
+ if (format->ptr[k] == '}') break;
+ }
+
+ if (k == format->used - 1) {
+ log_error_write(srv, __FILE__, __LINE__, "s", "%{ has to be terminated by a }");
+ return -1;
+ }
+
+ /* after the } has to be a character */
+ if (format->ptr[k+1] == '\0') {
+ log_error_write(srv, __FILE__, __LINE__, "s", "%{...} has to be followed by a format-specifier");
+ return -1;
+ }
+
+ if (k == i + 2) {
+ log_error_write(srv, __FILE__, __LINE__, "s", "%{...} has to be contain a string");
+ return -1;
+ }
+
+ for (j = 0; fmap[j].key != '\0'; j++) {
+ if (fmap[j].key != format->ptr[k+1]) continue;
+
+ /* found key */
+
+ fields->ptr[fields->used] = malloc(sizeof(format_fields));
+ fields->ptr[fields->used]->type = FIELD_FORMAT;
+ fields->ptr[fields->used]->field = fmap[j].type;
+ fields->ptr[fields->used]->string = buffer_init();
+
+ buffer_copy_string_len(fields->ptr[fields->used]->string, format->ptr + i + 2, k - (i + 2));
+
+ fields->used++;
+
+ break;
+ }
+
+ if (fmap[j].key == '\0') {
+ log_error_write(srv, __FILE__, __LINE__, "s", "%{...} has to be followed by a valid format-specifier");
+ return -1;
+ }
+
+ start = k + 2;
+ i = start - 1; /* skip the string */
+
+ break;
+ default:
+ /* after the % has to be a character */
+ if (format->ptr[i+1] == '\0') {
+ log_error_write(srv, __FILE__, __LINE__, "s", "% has to be followed by a format-specifier");
+ return -1;
+ }
+
+ for (j = 0; fmap[j].key != '\0'; j++) {
+ if (fmap[j].key != format->ptr[i+1]) continue;
+
+ /* found key */
+
+ fields->ptr[fields->used] = malloc(sizeof(format_fields));
+ fields->ptr[fields->used]->type = FIELD_FORMAT;
+ fields->ptr[fields->used]->field = fmap[j].type;
+ fields->ptr[fields->used]->string = NULL;
+
+ fields->used++;
+
+ break;
+ }
+
+ if (fmap[j].key == '\0') {
+ log_error_write(srv, __FILE__, __LINE__, "s", "% has to be followed by a valid format-specifier");
+ return -1;
+ }
+
+ start = i + 2;
+ i = start - 1; /* skip the string */
+
+ break;
+ }
+
+ break;
+ }
+ }
+
+ if (start < i) {
+ /* copy the string */
+ if (fields->size == 0) {
+ fields->size = 16;
+ fields->used = 0;
+ fields->ptr = malloc(fields->size * sizeof(format_fields * ));
+ } else if (fields->used == fields->size) {
+ fields->size += 16;
+ fields->ptr = realloc(fields->ptr, fields->size * sizeof(format_fields * ));
+ }
+
+ fields->ptr[fields->used] = malloc(sizeof(format_fields));
+ fields->ptr[fields->used]->type = FIELD_STRING;
+ fields->ptr[fields->used]->string = buffer_init();
+
+ buffer_copy_string_len(fields->ptr[fields->used]->string, format->ptr + start, i - start);
+
+ fields->used++;
+ }
+
+ return 0;
+}
+
+FREE_FUNC(mod_accesslog_free) {
+ plugin_data *p = p_d;
+ size_t i;
+
+ if (!p) return HANDLER_GO_ON;
+
+ if (p->config_storage) {
+
+ for (i = 0; i < srv->config_context->used; i++) {
+ plugin_config *s = p->config_storage[i];
+
+ if (!s) continue;
+
+ if (s->access_logbuffer->used) {
+ if (s->use_syslog) {
+# ifdef HAVE_SYSLOG_H
+ if (s->access_logbuffer->used > 2) {
+ syslog(LOG_INFO, "%*s", s->access_logbuffer->used - 2, s->access_logbuffer->ptr);
+ }
+# endif
+ } else if (s->log_access_fd != -1) {
+ write(s->log_access_fd, s->access_logbuffer->ptr, s->access_logbuffer->used - 1);
+ }
+ }
+
+ if (s->log_access_fd != -1) close(s->log_access_fd);
+
+ buffer_free(s->ts_accesslog_str);
+ buffer_free(s->access_logbuffer);
+ buffer_free(s->format);
+ buffer_free(s->access_logfile);
+
+ if (s->parsed_format) {
+ size_t j;
+ for (j = 0; j < s->parsed_format->used; j++) {
+ if (s->parsed_format->ptr[j]->string) buffer_free(s->parsed_format->ptr[j]->string);
+ free(s->parsed_format->ptr[j]);
+ }
+ free(s->parsed_format->ptr);
+ free(s->parsed_format);
+ }
+
+ free(s);
+ }
+
+ free(p->config_storage);
+ }
+
+ free(p);
+
+ return HANDLER_GO_ON;
+}
+
+SETDEFAULTS_FUNC(log_access_open) {
+ plugin_data *p = p_d;
+ size_t i = 0;
+
+ config_values_t cv[] = {
+ { "accesslog.filename", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "accesslog.use-syslog", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },
+ { "accesslog.format", NULL, T_CONFIG_STRING, 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->access_logfile = buffer_init();
+ s->format = buffer_init();
+ s->access_logbuffer = buffer_init();
+ s->ts_accesslog_str = buffer_init();
+ s->log_access_fd = -1;
+ s->last_generated_accesslog_ts = 0;
+ s->last_generated_accesslog_ts_ptr = &(s->last_generated_accesslog_ts);
+
+
+ cv[0].destination = s->access_logfile;
+ cv[1].destination = &(s->use_syslog);
+ cv[2].destination = s->format;
+
+ p->config_storage[i] = s;
+
+ if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
+ return HANDLER_ERROR;
+ }
+
+ if (i == 0 && buffer_is_empty(s->format)) {
+ /* set a default logfile string */
+
+ buffer_copy_string(s->format, "%h %V %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"");
+ }
+
+ /* parse */
+
+ if (s->format->used) {
+ s->parsed_format = calloc(1, sizeof(*(s->parsed_format)));
+
+ if (-1 == accesslog_parse_format(srv, s->parsed_format, s->format)) {
+
+ log_error_write(srv, __FILE__, __LINE__, "sb",
+ "parsing accesslog-definition failed:", s->format);
+
+ return HANDLER_ERROR;
+ }
+#if 0
+ /* debugging */
+ for (j = 0; j < s->parsed_format->used; j++) {
+ switch (s->parsed_format->ptr[j]->type) {
+ case FIELD_FORMAT:
+ log_error_write(srv, __FILE__, __LINE__, "ssds",
+ "config:", "format", s->parsed_format->ptr[j]->field,
+ s->parsed_format->ptr[j]->string ?
+ s->parsed_format->ptr[j]->string->ptr : "" );
+ break;
+ case FIELD_STRING:
+ log_error_write(srv, __FILE__, __LINE__, "ssbs", "config:", "string '", s->parsed_format->ptr[j]->string, "'");
+ break;
+ default:
+ break;
+ }
+ }
+#endif
+ }
+
+ if (s->use_syslog) {
+ /* ignore the next checks */
+ continue;
+ }
+
+ if (buffer_is_empty(s->access_logfile)) continue;
+
+ if (s->access_logfile->ptr[0] == '|') {
+#ifdef HAVE_FORK
+ /* create write pipe and spawn process */
+
+ int to_log_fds[2];
+ pid_t pid;
+
+ if (pipe(to_log_fds)) {
+ log_error_write(srv, __FILE__, __LINE__, "ss", "pipe failed: ", strerror(errno));
+ return HANDLER_ERROR;
+ }
+
+ /* fork, execve */
+ switch (pid = fork()) {
+ case 0:
+ /* child */
+
+ close(STDIN_FILENO);
+ dup2(to_log_fds[0], STDIN_FILENO);
+ close(to_log_fds[0]);
+ /* not needed */
+ close(to_log_fds[1]);
+
+ /* we don't need the client socket */
+ for (i = 3; i < 256; i++) {
+ close(i);
+ }
+
+ /* exec the log-process (skip the | )
+ *
+ */
+
+ execl("/bin/sh", "sh", "-c", s->access_logfile->ptr + 1, (char *)NULL);
+
+ log_error_write(srv, __FILE__, __LINE__, "sss",
+ "spawning log-process failed: ", strerror(errno),
+ s->access_logfile->ptr + 1);
+
+ exit(-1);
+ break;
+ case -1:
+ /* error */
+ log_error_write(srv, __FILE__, __LINE__, "ss", "fork failed: ", strerror(errno));
+ break;
+ default:
+ close(to_log_fds[0]);
+
+ s->log_access_fd = to_log_fds[1];
+
+ break;
+ }
+#else
+ return -1;
+#endif
+ } else if (-1 == (s->log_access_fd =
+ open(s->access_logfile->ptr, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) {
+
+ log_error_write(srv, __FILE__, __LINE__, "ssb",
+ "opening access-log failed:",
+ strerror(errno), s->access_logfile);
+
+ return HANDLER_ERROR;
+ }
+ fcntl(s->log_access_fd, F_SETFD, FD_CLOEXEC);
+
+ }
+
+ return HANDLER_GO_ON;
+}
+
+SIGHUP_FUNC(log_access_cycle) {
+ plugin_data *p = p_d;
+ size_t i;
+
+ if (!p->config_storage) return HANDLER_GO_ON;
+
+ for (i = 0; i < srv->config_context->used; i++) {
+ plugin_config *s = p->config_storage[i];
+
+ if (s->access_logbuffer->used) {
+ if (s->use_syslog) {
+#ifdef HAVE_SYSLOG_H
+ if (s->access_logbuffer->used > 2) {
+ /* syslog appends a \n on its own */
+ syslog(LOG_INFO, "%*s", s->access_logbuffer->used - 2, s->access_logbuffer->ptr);
+ }
+#endif
+ } else if (s->log_access_fd != -1) {
+ write(s->log_access_fd, s->access_logbuffer->ptr, s->access_logbuffer->used - 1);
+ }
+
+ buffer_reset(s->access_logbuffer);
+ }
+
+ if (s->use_syslog == 0 &&
+ !buffer_is_empty(s->access_logfile) &&
+ s->access_logfile->ptr[0] != '|') {
+
+ close(s->log_access_fd);
+
+ if (-1 == (s->log_access_fd =
+ open(s->access_logfile->ptr, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) {
+
+ log_error_write(srv, __FILE__, __LINE__, "ss", "cycling access-log failed:", strerror(errno));
+
+ return HANDLER_ERROR;
+ }
+ }
+ }
+
+ return HANDLER_GO_ON;
+}
+
+#define PATCH(x) \
+ p->conf.x = s->x;
+static int mod_accesslog_patch_connection(server *srv, connection *con, plugin_data *p) {
+ size_t i, j;
+ plugin_config *s = p->config_storage[0];
+
+ PATCH(access_logfile);
+ PATCH(format);
+ PATCH(log_access_fd);
+ PATCH(last_generated_accesslog_ts_ptr);
+ PATCH(access_logbuffer);
+ PATCH(ts_accesslog_str);
+ PATCH(parsed_format);
+ PATCH(use_syslog);
+
+ /* 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("accesslog.filename"))) {
+ PATCH(access_logfile);
+ PATCH(log_access_fd);
+ PATCH(last_generated_accesslog_ts_ptr);
+ PATCH(access_logbuffer);
+ PATCH(ts_accesslog_str);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.format"))) {
+ PATCH(format);
+ PATCH(parsed_format);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.use-syslog"))) {
+ PATCH(use_syslog);
+ PATCH(last_generated_accesslog_ts_ptr);
+ PATCH(access_logbuffer);
+ PATCH(ts_accesslog_str);
+ }
+ }
+ }
+
+ return 0;
+}
+#undef PATCH
+
+REQUESTDONE_FUNC(log_access_write) {
+ plugin_data *p = p_d;
+ buffer *b;
+ size_t j;
+
+ int newts = 0;
+ data_string *ds;
+
+ mod_accesslog_patch_connection(srv, con, p);
+
+ b = p->conf.access_logbuffer;
+ if (b->used == 0) {
+ buffer_copy_string(b, "");
+ }
+
+ for (j = 0; j < p->conf.parsed_format->used; j++) {
+ switch(p->conf.parsed_format->ptr[j]->type) {
+ case FIELD_STRING:
+ buffer_append_string_buffer(b, p->conf.parsed_format->ptr[j]->string);
+ break;
+ case FIELD_FORMAT:
+ switch(p->conf.parsed_format->ptr[j]->field) {
+ case FORMAT_TIMESTAMP:
+
+ /* cache the generated timestamp */
+ if (srv->cur_ts != *(p->conf.last_generated_accesslog_ts_ptr)) {
+ struct tm tm;
+#if defined(HAVE_STRUCT_TM_GMTOFF)
+ long scd, hrs, min;
+#endif
+
+ buffer_prepare_copy(p->conf.ts_accesslog_str, 255);
+#if defined(HAVE_STRUCT_TM_GMTOFF)
+# ifdef HAVE_LOCALTIME_R
+ localtime_r(&(srv->cur_ts), &tm);
+ strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S ", &tm);
+# else
+ strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S ", localtime_r(&(srv->cur_ts)));
+# endif
+ p->conf.ts_accesslog_str->used = strlen(p->conf.ts_accesslog_str->ptr) + 1;
+
+ buffer_append_string(p->conf.ts_accesslog_str, tm.tm_gmtoff >= 0 ? "+" : "-");
+
+ scd = abs(tm.tm_gmtoff);
+ hrs = scd / 3600;
+ min = (scd % 3600) / 60;
+
+ /* hours */
+ if (hrs < 10) buffer_append_string(p->conf.ts_accesslog_str, "0");
+ buffer_append_long(p->conf.ts_accesslog_str, hrs);
+
+ if (min < 10) buffer_append_string(p->conf.ts_accesslog_str, "0");
+ buffer_append_long(p->conf.ts_accesslog_str, min);
+ BUFFER_APPEND_STRING_CONST(p->conf.ts_accesslog_str, "]");
+#else
+#ifdef HAVE_GMTIME_R
+ gmtime_r(&(srv->cur_ts), &tm);
+ strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S +0000]", &tm);
+#else
+ strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S +0000]", gmtime(&(srv->cur_ts)));
+#endif
+ p->conf.ts_accesslog_str->used = strlen(p->conf.ts_accesslog_str->ptr) + 1;
+#endif
+
+ *(p->conf.last_generated_accesslog_ts_ptr) = srv->cur_ts;
+ newts = 1;
+ }
+
+ buffer_append_string_buffer(b, p->conf.ts_accesslog_str);
+
+ break;
+ case FORMAT_REMOTE_HOST:
+
+ /* handle inet_ntop cache */
+
+ buffer_append_string(b, inet_ntop_cache_get_ip(srv, &(con->dst_addr)));
+
+ break;
+ case FORMAT_REMOTE_IDENT:
+ /* ident */
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ break;
+ case FORMAT_REMOTE_USER:
+ if (con->authed_user->used > 1) {
+ buffer_append_string_buffer(b, con->authed_user);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_REQUEST_LINE:
+ if (con->request.request_line->used) {
+ buffer_append_string_buffer(b, con->request.request_line);
+ }
+ break;
+ case FORMAT_STATUS:
+ buffer_append_long(b, con->http_status);
+ break;
+
+ case FORMAT_BYTES_OUT_NO_HEADER:
+ if (con->bytes_written > 0) {
+ buffer_append_off_t(b,
+ con->bytes_written - con->bytes_header <= 0 ? 0 : con->bytes_written - con->bytes_header);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_HEADER:
+ if (NULL != (ds = (data_string *)array_get_element(con->request.headers, p->conf.parsed_format->ptr[j]->string->ptr))) {
+ buffer_append_string_buffer(b, ds->value);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_RESPONSE_HEADER:
+ if (NULL != (ds = (data_string *)array_get_element(con->response.headers, p->conf.parsed_format->ptr[j]->string->ptr))) {
+ buffer_append_string_buffer(b, ds->value);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_FILENAME:
+ if (con->physical.path->used > 1) {
+ buffer_append_string_buffer(b, con->physical.path);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_BYTES_OUT:
+ if (con->bytes_written > 0) {
+ buffer_append_off_t(b, con->bytes_written);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_BYTES_IN:
+ if (con->bytes_read > 0) {
+ buffer_append_off_t(b, con->bytes_read);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_TIME_USED:
+ buffer_append_long(b, srv->cur_ts - con->request_start);
+ break;
+ case FORMAT_SERVER_NAME:
+ if (con->server_name->used > 1) {
+ buffer_append_string_buffer(b, con->server_name);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_HTTP_HOST:
+ if (con->uri.authority->used > 1) {
+ buffer_append_string_buffer(b, con->uri.authority);
+ } else {
+ BUFFER_APPEND_STRING_CONST(b, "-");
+ }
+ break;
+ case FORMAT_REQUEST_PROTOCOL:
+ buffer_append_string(b,
+ con->request.http_version == HTTP_VERSION_1_1 ? "HTTP/1.1" : "HTTP/1.0");
+ break;
+ case FORMAT_REQUEST_METHOD:
+ buffer_append_string(b, get_http_method_name(con->request.http_method));
+ break;
+ case FORMAT_PERCENT:
+ buffer_append_string(b, "%");
+ break;
+ case FORMAT_SERVER_PORT:
+ buffer_append_long(b, srv->srvconf.port);
+ break;
+ case FORMAT_QUERY_STRING:
+ buffer_append_string_buffer(b, con->uri.query);
+ break;
+ case FORMAT_URL:
+ buffer_append_string_buffer(b, con->uri.path_raw);
+ break;
+ case FORMAT_CONNECTION_STATUS:
+ switch(con->keep_alive) {
+ case 0: buffer_append_string(b, "-"); break;
+ default: buffer_append_string(b, "+"); break;
+ }
+ break;
+ default:
+ /*
+ { 'a', FORMAT_REMOTE_ADDR },
+ { 'A', FORMAT_LOCAL_ADDR },
+ { 'C', FORMAT_COOKIE },
+ { 'D', FORMAT_TIME_USED_MS },
+ { 'e', FORMAT_ENV },
+ */
+
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ BUFFER_APPEND_STRING_CONST(b, "\n");
+
+ if (p->conf.use_syslog || /* syslog doesn't cache */
+ (p->conf.access_logfile->used && p->conf.access_logfile->ptr[0] == '|') || /* pipes don't cache */
+ newts ||
+ b->used > BUFFER_MAX_REUSE_SIZE) {
+ if (p->conf.use_syslog) {
+#ifdef HAVE_SYSLOG_H
+ if (b->used > 2) {
+ /* syslog appends a \n on its own */
+ syslog(LOG_INFO, "%*s", b->used - 2, b->ptr);
+ }
+#endif
+ } else if (p->conf.log_access_fd != -1) {
+ write(p->conf.log_access_fd, b->ptr, b->used - 1);
+ }
+ buffer_reset(b);
+ }
+
+ return HANDLER_GO_ON;
+}
+
+
+int mod_accesslog_plugin_init(plugin *p) {
+ p->version = LIGHTTPD_VERSION_ID;
+ p->name = buffer_init_string("accesslog");
+
+ p->init = mod_accesslog_init;
+ p->set_defaults= log_access_open;
+ p->cleanup = mod_accesslog_free;
+
+ p->handle_request_done = log_access_write;
+ p->handle_sighup = log_access_cycle;
+
+ p->data = NULL;
+
+ return 0;
+}
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_alias.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_alias.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_alias.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_alias.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,203 @@
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "base.h"
+#include "log.h"
+#include "buffer.h"
+
+#include "plugin.h"
+
+/* plugin config for all request/connections */
+typedef struct {
+ array *alias;
+} plugin_config;
+
+typedef struct {
+ PLUGIN_DATA;
+
+ plugin_config **config_storage;
+
+ plugin_config conf;
+} plugin_data;
+
+/* init the plugin data */
+INIT_FUNC(mod_alias_init) {
+ plugin_data *p;
+
+ p = calloc(1, sizeof(*p));
+
+
+
+ return p;
+}
+
+/* detroy the plugin data */
+FREE_FUNC(mod_alias_free) {
+ plugin_data *p = p_d;
+
+ 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->alias);
+
+ free(s);
+ }
+ free(p->config_storage);
+ }
+
+ free(p);
+
+ return HANDLER_GO_ON;
+}
+
+/* handle plugin config and check values */
+
+SETDEFAULTS_FUNC(mod_alias_set_defaults) {
+ plugin_data *p = p_d;
+ size_t i = 0;
+
+ config_values_t cv[] = {
+ { "alias.url", 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->alias = array_init();
+ cv[0].destination = s->alias;
+
+ p->config_storage[i] = s;
+
+ if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
+ return HANDLER_ERROR;
+ }
+ if (s->alias->used >= 2) {
+ const array *a = s->alias;
+ size_t j, k;
+
+ for (j = 0; j < a->used; j ++) {
+ const buffer *prefix = a->data[a->sorted[j]]->key;
+ for (k = j + 1; k < a->used; k ++) {
+ const buffer *key = a->data[a->sorted[k]]->key;
+
+ if (key->used < prefix->used) {
+ break;
+ }
+ if (memcmp(key->ptr, prefix->ptr, prefix->used - 1) != 0) {
+ break;
+ }
+ /* ok, they have same prefix. check position */
+ if (a->sorted[j] < a->sorted[k]) {
+ fprintf(stderr, "url.alias: `%s' will never match as `%s' matched first\n",
+ key->ptr,
+ prefix->ptr);
+ return HANDLER_ERROR;
+ }
+ }
+ }
+ }
+ }
+
+ return HANDLER_GO_ON;
+}
+
+#define PATCH(x) \
+ p->conf.x = s->x;
+static int mod_alias_patch_connection(server *srv, connection *con, plugin_data *p) {
+ size_t i, j;
+ plugin_config *s = p->config_storage[0];
+
+ PATCH(alias);
+
+ /* 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("alias.url"))) {
+ PATCH(alias);
+ }
+ }
+ }
+
+ return 0;
+}
+#undef PATCH
+
+PHYSICALPATH_FUNC(mod_alias_physical_handler) {
+ plugin_data *p = p_d;
+ int uri_len, basedir_len;
+ char *uri_ptr;
+ size_t k;
+
+ if (con->physical.path->used == 0) return HANDLER_GO_ON;
+
+ mod_alias_patch_connection(srv, con, p);
+
+ /* not to include the tailing slash */
+ basedir_len = (con->physical.basedir->used - 1) - 1;
+ uri_len = con->physical.path->used - 1 - basedir_len;
+ uri_ptr = con->physical.path->ptr + basedir_len;
+
+ for (k = 0; k < p->conf.alias->used; k++) {
+ data_string *ds = (data_string *)p->conf.alias->data[k];
+ int alias_len = ds->key->used - 1;
+
+ if (alias_len > uri_len) continue;
+ if (ds->key->used == 0) continue;
+
+ if (0 == (con->conf.force_lowercase_filenames ?
+ strncasecmp(uri_ptr, ds->key->ptr, alias_len) :
+ strncmp(uri_ptr, ds->key->ptr, alias_len))) {
+ /* matched */
+
+ buffer_copy_string_buffer(con->physical.basedir, ds->value);
+ buffer_copy_string_buffer(srv->tmp_buf, ds->value);
+ buffer_append_string(srv->tmp_buf, uri_ptr + alias_len);
+ buffer_copy_string_buffer(con->physical.path, srv->tmp_buf);
+
+ return HANDLER_GO_ON;
+ }
+ }
+
+ /* not found */
+ return HANDLER_GO_ON;
+}
+
+/* this function is called at dlopen() time and inits the callbacks */
+
+int mod_alias_plugin_init(plugin *p) {
+ p->version = LIGHTTPD_VERSION_ID;
+ p->name = buffer_init_string("alias");
+
+ p->init = mod_alias_init;
+ p->handle_physical= mod_alias_physical_handler;
+ p->set_defaults = mod_alias_set_defaults;
+ p->cleanup = mod_alias_free;
+
+ p->data = NULL;
+
+ return 0;
+}
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_auth.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_auth.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_auth.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_auth.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,614 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "plugin.h"
+#include "http_auth.h"
+#include "log.h"
+#include "response.h"
+
+handler_t auth_ldap_init(server *srv, mod_auth_plugin_config *s);
+
+
+/**
+ * the basic and digest auth framework
+ *
+ * - config handling
+ * - protocol handling
+ *
+ * http_auth.c
+ * http_auth_digest.c
+ *
+ * do the real work
+ */
+
+INIT_FUNC(mod_auth_init) {
+ mod_auth_plugin_data *p;
+
+ p = calloc(1, sizeof(*p));
+
+ p->tmp_buf = buffer_init();
+
+ p->auth_user = buffer_init();
+#ifdef USE_LDAP
+ p->ldap_filter = buffer_init();
+#endif
+
+ return p;
+}
+
+FREE_FUNC(mod_auth_free) {
+ mod_auth_plugin_data *p = p_d;
+
+ UNUSED(srv);
+
+ if (!p) return HANDLER_GO_ON;
+
+ buffer_free(p->tmp_buf);
+ buffer_free(p->auth_user);
+#ifdef USE_LDAP
+ buffer_free(p->ldap_filter);
+#endif
+
+ if (p->config_storage) {
+ size_t i;
+ for (i = 0; i < srv->config_context->used; i++) {
+ mod_auth_plugin_config *s = p->config_storage[i];
+
+ if (!s) continue;
+
+ array_free(s->auth_require);
+ buffer_free(s->auth_plain_groupfile);
+ buffer_free(s->auth_plain_userfile);
+ buffer_free(s->auth_htdigest_userfile);
+ buffer_free(s->auth_htpasswd_userfile);
+ buffer_free(s->auth_backend_conf);
+
+ buffer_free(s->auth_ldap_hostname);
+ buffer_free(s->auth_ldap_basedn);
+ buffer_free(s->auth_ldap_binddn);
+ buffer_free(s->auth_ldap_bindpw);
+ buffer_free(s->auth_ldap_filter);
+ buffer_free(s->auth_ldap_cafile);
+
+#ifdef USE_LDAP
+ buffer_free(s->ldap_filter_pre);
+ buffer_free(s->ldap_filter_post);
+
+ if (s->ldap) ldap_unbind_s(s->ldap);
+#endif
+
+ free(s);
+ }
+ free(p->config_storage);
+ }
+
+ free(p);
+
+ return HANDLER_GO_ON;
+}
+
+#define PATCH(x) \
+ p->conf.x = s->x;
+static int mod_auth_patch_connection(server *srv, connection *con, mod_auth_plugin_data *p) {
+ size_t i, j;
+ mod_auth_plugin_config *s = p->config_storage[0];
+
+ PATCH(auth_backend);
+ PATCH(auth_plain_groupfile);
+ PATCH(auth_plain_userfile);
+ PATCH(auth_htdigest_userfile);
+ PATCH(auth_htpasswd_userfile);
+ PATCH(auth_require);
+ PATCH(auth_debug);
+ PATCH(auth_ldap_hostname);
+ PATCH(auth_ldap_basedn);
+ PATCH(auth_ldap_binddn);
+ PATCH(auth_ldap_bindpw);
+ PATCH(auth_ldap_filter);
+ PATCH(auth_ldap_cafile);
+ PATCH(auth_ldap_starttls);
+ PATCH(auth_ldap_allow_empty_pw);
+#ifdef USE_LDAP
+ PATCH(ldap);
+ PATCH(ldap_filter_pre);
+ PATCH(ldap_filter_post);
+#endif
+
+ /* 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("auth.backend"))) {
+ PATCH(auth_backend);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.plain.groupfile"))) {
+ PATCH(auth_plain_groupfile);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.plain.userfile"))) {
+ PATCH(auth_plain_userfile);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.htdigest.userfile"))) {
+ PATCH(auth_htdigest_userfile);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.htpasswd.userfile"))) {
+ PATCH(auth_htpasswd_userfile);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.require"))) {
+ PATCH(auth_require);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.debug"))) {
+ PATCH(auth_debug);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.hostname"))) {
+ PATCH(auth_ldap_hostname);
+#ifdef USE_LDAP
+ PATCH(ldap);
+ PATCH(ldap_filter_pre);
+ PATCH(ldap_filter_post);
+#endif
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.base-dn"))) {
+ PATCH(auth_ldap_basedn);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.filter"))) {
+ PATCH(auth_ldap_filter);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.ca-file"))) {
+ PATCH(auth_ldap_cafile);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.starttls"))) {
+ PATCH(auth_ldap_starttls);
+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.allow-empty-pw"))) {
+ PATCH(auth_ldap_allow_empty_pw);
+ }
+ }
+ }
+
+ return 0;
+}
+#undef PATCH
+
+static handler_t mod_auth_uri_handler(server *srv, connection *con, void *p_d) {
+ size_t k;
+ int auth_required = 0, auth_satisfied = 0;
+ char *http_authorization = NULL;
+ data_string *ds;
+ mod_auth_plugin_data *p = p_d;
+ array *req;
+
+ /* select the right config */
+ mod_auth_patch_connection(srv, con, p);
+
+ if (p->conf.auth_require == NULL) return HANDLER_GO_ON;
+
+ /*
+ * AUTH
+ *
+ */
+
+ /* do we have to ask for auth ? */
+
+ auth_required = 0;
+ auth_satisfied = 0;
+
+ /* search auth-directives for path */
+ for (k = 0; k < p->conf.auth_require->used; k++) {
+ buffer *require = p->conf.auth_require->data[k]->key;
+
+ if (require->used == 0) continue;
+ if (con->uri.path->used < require->used) continue;
+
+ /* if we have a case-insensitive FS we have to lower-case the URI here too */
+
+ if (con->conf.force_lowercase_filenames) {
+ if (0 == strncasecmp(con->uri.path->ptr, require->ptr, require->used - 1)) {
+ auth_required = 1;
+ break;
+ }
+ } else {
+ if (0 == strncmp(con->uri.path->ptr, require->ptr, require->used - 1)) {
+ auth_required = 1;
+ break;
+ }
+ }
+ }
+
+ /* nothing to do for us */
+ if (auth_required == 0) return HANDLER_GO_ON;
+
+ req = ((data_array *)(p->conf.auth_require->data[k]))->value;
+
+ /* try to get Authorization-header */
+
+ if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "Authorization"))) {
+ http_authorization = ds->value->ptr;
+ }
+
+ if (ds && ds->value && ds->value->used) {
+ char *auth_realm;
+ data_string *method;
+
+ method = (data_string *)array_get_element(req, "method");
+
+ /* parse auth-header */
+ if (NULL != (auth_realm = strchr(http_authorization, ' '))) {
+ int auth_type_len = auth_realm - http_authorization;
+
+ if ((auth_type_len == 5) &&
+ (0 == strncasecmp(http_authorization, "Basic", auth_type_len))) {
+
+ if (0 == strcmp(method->value->ptr, "basic")) {
+ auth_satisfied = http_auth_basic_check(srv, con, p, req, con->uri.path, auth_realm+1);
+ }
+ } else if ((auth_type_len == 6) &&
+ (0 == strncasecmp(http_authorization, "Digest", auth_type_len))) {
+ if (0 == strcmp(method->value->ptr, "digest")) {
+ if (-1 == (auth_satisfied = http_auth_digest_check(srv, con, p, req, con->uri.path, auth_realm+1))) {
+ con->http_status = 400;
+
+ /* a field was missing */
+
+ return HANDLER_FINISHED;
+ }
+ }
+ } else {
+ log_error_write(srv, __FILE__, __LINE__, "ss",
+ "unknown authentification type:",
+ http_authorization);
+ }
+ }
+ }
+
+ if (!auth_satisfied) {
+ data_string *method, *realm;
+ method = (data_string *)array_get_element(req, "method");
+ realm = (data_string *)array_get_element(req, "realm");
+
+ con->http_status = 401;
+
+ if (0 == strcmp(method->value->ptr, "basic")) {
+ buffer_copy_string(p->tmp_buf, "Basic realm=\"");
+ buffer_append_string_buffer(p->tmp_buf, realm->value);
+ buffer_append_string(p->tmp_buf, "\"");
+
+ response_header_insert(srv, con, CONST_STR_LEN("WWW-Authenticate"), CONST_BUF_LEN(p->tmp_buf));
+ } else if (0 == strcmp(method->value->ptr, "digest")) {
+ char hh[33];
+ http_auth_digest_generate_nonce(srv, p, srv->tmp_buf, hh);
+
+ buffer_copy_string(p->tmp_buf, "Digest realm=\"");
+ buffer_append_string_buffer(p->tmp_buf, realm->value);
+ buffer_append_string(p->tmp_buf, "\", nonce=\"");
+ buffer_append_string(p->tmp_buf, hh);
+ buffer_append_string(p->tmp_buf, "\", qop=\"auth\"");
+
+ response_header_insert(srv, con, CONST_STR_LEN("WWW-Authenticate"), CONST_BUF_LEN(p->tmp_buf));
+ } else {
+ /* evil */
+ }
+ return HANDLER_FINISHED;
+ } else {
+ /* the REMOTE_USER header */
+
+ buffer_copy_string_buffer(con->authed_user, p->auth_user);
+ }
+
+ return HANDLER_GO_ON;
+}
+
+SETDEFAULTS_FUNC(mod_auth_set_defaults) {
+ mod_auth_plugin_data *p = p_d;
+ size_t i;
+
+ config_values_t cv[] = {
+ { "auth.backend", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
+ { "auth.backend.plain.groupfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.plain.userfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.require", NULL, T_CONFIG_LOCAL, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.ldap.hostname", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.ldap.base-dn", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.ldap.filter", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.ldap.ca-file", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.ldap.starttls", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.ldap.bind-dn", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.ldap.bind-pw", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 10 */
+ { "auth.backend.ldap.allow-empty-pw", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.htdigest.userfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.backend.htpasswd.userfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "auth.debug", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 13 */
+ { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
+ };
+
+ p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
+
+ for (i = 0; i < srv->config_context->used; i++) {
+ mod_auth_plugin_config *s;
+ size_t n;
+ data_array *da;
+ array *ca;
+
+ s = calloc(1, sizeof(mod_auth_plugin_config));
+ s->auth_plain_groupfile = buffer_init();
+ s->auth_plain_userfile = buffer_init();
+ s->auth_htdigest_userfile = buffer_init();
+ s->auth_htpasswd_userfile = buffer_init();
+ s->auth_backend_conf = buffer_init();
+
+ s->auth_ldap_hostname = buffer_init();
+ s->auth_ldap_basedn = buffer_init();
+ s->auth_ldap_binddn = buffer_init();
+ s->auth_ldap_bindpw = buffer_init();
+ s->auth_ldap_filter = buffer_init();
+ s->auth_ldap_cafile = buffer_init();
+ s->auth_ldap_starttls = 0;
+ s->auth_debug = 0;
+
+ s->auth_require = array_init();
+
+#ifdef USE_LDAP
+ s->ldap_filter_pre = buffer_init();
+ s->ldap_filter_post = buffer_init();
+ s->ldap = NULL;
+#endif
+
+ cv[0].destination = s->auth_backend_conf;
+ cv[1].destination = s->auth_plain_groupfile;
+ cv[2].destination = s->auth_plain_userfile;
+ cv[3].destination = s->auth_require;
+ cv[4].destination = s->auth_ldap_hostname;
+ cv[5].destination = s->auth_ldap_basedn;
+ cv[6].destination = s->auth_ldap_filter;
+ cv[7].destination = s->auth_ldap_cafile;
+ cv[8].destination = &(s->auth_ldap_starttls);
+ cv[9].destination = s->auth_ldap_binddn;
+ cv[10].destination = s->auth_ldap_bindpw;
+ cv[11].destination = &(s->auth_ldap_allow_empty_pw);
+ cv[12].destination = s->auth_htdigest_userfile;
+ cv[13].destination = s->auth_htpasswd_userfile;
+ cv[14].destination = &(s->auth_debug);
+
+ p->config_storage[i] = s;
+ ca = ((data_config *)srv->config_context->data[i])->value;
+
+ if (0 != config_insert_values_global(srv, ca, cv)) {
+ return HANDLER_ERROR;
+ }
+
+ if (s->auth_backend_conf->used) {
+ if (0 == strcmp(s->auth_backend_conf->ptr, "htpasswd")) {
+ s->auth_backend = AUTH_BACKEND_HTPASSWD;
+ } else if (0 == strcmp(s->auth_backend_conf->ptr, "htdigest")) {
+ s->auth_backend = AUTH_BACKEND_HTDIGEST;
+ } else if (0 == strcmp(s->auth_backend_conf->ptr, "plain")) {
+ s->auth_backend = AUTH_BACKEND_PLAIN;
+ } else if (0 == strcmp(s->auth_backend_conf->ptr, "ldap")) {
+ s->auth_backend = AUTH_BACKEND_LDAP;
+ } else {
+ log_error_write(srv, __FILE__, __LINE__, "sb", "auth.backend not supported:", s->auth_backend_conf);
+
+ return HANDLER_ERROR;
+ }
+ }
+
+ /* no auth.require for this section */
+ if (NULL == (da = (data_array *)array_get_element(ca, "auth.require"))) continue;
+
+ if (da->type != TYPE_ARRAY) continue;
+
+ for (n = 0; n < da->value->used; n++) {
+ size_t m;
+ data_array *da_file = (data_array *)da->value->data[n];
+ const char *method, *realm, *require;
+
+ if (da->value->data[n]->type != TYPE_ARRAY) {
+ log_error_write(srv, __FILE__, __LINE__, "ss",
+ "auth.require should contain an array as in:",
+ "auth.require = ( \"...\" => ( ..., ...) )");
+
+ return HANDLER_ERROR;
+ }
+
+ method = realm = require = NULL;
+
+ for (m = 0; m < da_file->value->used; m++) {
+ if (da_file->value->data[m]->type == TYPE_STRING) {
+ if (0 == strcmp(da_file->value->data[m]->key->ptr, "method")) {
+ method = ((data_string *)(da_file->value->data[m]))->value->ptr;
+ } else if (0 == strcmp(da_file->value->data[m]->key->ptr, "realm")) {
+ realm = ((data_string *)(da_file->value->data[m]))->value->ptr;
+ } else if (0 == strcmp(da_file->value->data[m]->key->ptr, "require")) {
+ require = ((data_string *)(da_file->value->data[m]))->value->ptr;
+ } else {
+ log_error_write(srv, __FILE__, __LINE__, "ssbs",
+ "the field is unknown in:",
+ "auth.require = ( \"...\" => ( ..., -> \"",
+ da_file->value->data[m]->key,
+ "\" <- => \"...\" ) )");
+
+ return HANDLER_ERROR;
+ }
+ } else {
+ log_error_write(srv, __FILE__, __LINE__, "ssbs",
+ "a string was expected for:",
+ "auth.require = ( \"...\" => ( ..., -> \"",
+ da_file->value->data[m]->key,
+ "\" <- => \"...\" ) )");
+
+ return HANDLER_ERROR;
+ }
+ }
+
+ if (method == NULL) {
+ log_error_write(srv, __FILE__, __LINE__, "ss",
+ "the require field is missing in:",
+ "auth.require = ( \"...\" => ( ..., \"method\" => \"...\" ) )");
+ return HANDLER_ERROR;
+ } else {
+ if (0 != strcmp(method, "basic") &&
+ 0 != strcmp(method, "digest")) {
+ log_error_write(srv, __FILE__, __LINE__, "ss",
+ "method has to be either \"basic\" or \"digest\" in",
+ "auth.require = ( \"...\" => ( ..., \"method\" => \"...\") )");
+ return HANDLER_ERROR;
+ }
+ }
+
+ if (realm == NULL) {
+ log_error_write(srv, __FILE__, __LINE__, "ss",
+ "the require field is missing in:",
+ "auth.require = ( \"...\" => ( ..., \"realm\" => \"...\" ) )");
+ return HANDLER_ERROR;
+ }
+
+ if (require == NULL) {
+ log_error_write(srv, __FILE__, __LINE__, "ss",
+ "the require field is missing in:",
+ "auth.require = ( \"...\" => ( ..., \"require\" => \"...\" ) )");
+ return HANDLER_ERROR;
+ }
+
+ if (method && realm && require) {
+ data_string *ds;
+ data_array *a;
+
+ a = data_array_init();
+ buffer_copy_string_buffer(a->key, da_file->key);
+
+ ds = data_string_init();
+
+ buffer_copy_string(ds->key, "method");
+ buffer_copy_string(ds->value, method);
+
+ array_insert_unique(a->value, (data_unset *)ds);
+
+ ds = data_string_init();
+
+ buffer_copy_string(ds->key, "realm");
+ buffer_copy_string(ds->value, realm);
+
+ array_insert_unique(a->value, (data_unset *)ds);
+
+ ds = data_string_init();
+
+ buffer_copy_string(ds->key, "require");
+ buffer_copy_string(ds->value, require);
+
+ array_insert_unique(a->value, (data_unset *)ds);
+
+ array_insert_unique(s->auth_require, (data_unset *)a);
+ }
+ }
+
+ switch(s->auth_backend) {
+ case AUTH_BACKEND_LDAP: {
+ handler_t ret = auth_ldap_init(srv, s);
+ if (ret == HANDLER_ERROR)
+ return (ret);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ return HANDLER_GO_ON;
+}
+
+handler_t auth_ldap_init(server *srv, mod_auth_plugin_config *s) {
+#ifdef USE_LDAP
+ int ret;
+#if 0
+ if (s->auth_ldap_basedn->used == 0) {
+ log_error_write(srv, __FILE__, __LINE__, "s", "ldap: auth.backend.ldap.base-dn has to be set");
+
+ return HANDLER_ERROR;
+ }
+#endif
+
+ if (s->auth_ldap_filter->used) {
+ char *dollar;
+
+ /* parse filter */
+
+ if (NULL == (dollar = strchr(s->auth_ldap_filter->ptr, '$'))) {
+ log_error_write(srv, __FILE__, __LINE__, "s", "ldap: auth.backend.ldap.filter is missing a replace-operator '$'");
+
+ return HANDLER_ERROR;
+ }
+
+ buffer_copy_string_len(s->ldap_filter_pre, s->auth_ldap_filter->ptr, dollar - s->auth_ldap_filter->ptr);
+ buffer_copy_string(s->ldap_filter_post, dollar+1);
+ }
+
+ if (s->auth_ldap_hostname->used) {
+ if (NULL == (s->ldap = ldap_init(s->auth_ldap_hostname->ptr, LDAP_PORT))) {
+ log_error_write(srv, __FILE__, __LINE__, "ss", "ldap ...", strerror(errno));
+
+ return HANDLER_ERROR;
+ }
+
+ ret = LDAP_VERSION3;
+ if (LDAP_OPT_SUCCESS != (ret = ldap_set_option(s->ldap, LDAP_OPT_PROTOCOL_VERSION, &ret))) {
+ log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
+
+ return HANDLER_ERROR;
+ }
+
+ if (s->auth_ldap_starttls) {
+ /* if no CA file is given, it is ok, as we will use encryption
+ * if the server requires a CAfile it will tell us */
+ if (!buffer_is_empty(s->auth_ldap_cafile)) {
+ if (LDAP_OPT_SUCCESS != (ret = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE,
+ s->auth_ldap_cafile->ptr))) {
+ log_error_write(srv, __FILE__, __LINE__, "ss",
+ "Loading CA certificate failed:", ldap_err2string(ret));
+
+ return HANDLER_ERROR;
+ }
+ }
+
+ if (LDAP_OPT_SUCCESS != (ret = ldap_start_tls_s(s->ldap, NULL, NULL))) {
+ log_error_write(srv, __FILE__, __LINE__, "ss", "ldap startTLS failed:", ldap_err2string(ret));
+
+ return HANDLER_ERROR;
+ }
+ }
+
+
+ /* 1. */
+ if (s->auth_ldap_binddn->used) {
+ if (LDAP_SUCCESS != (ret = ldap_simple_bind_s(s->ldap, s->auth_ldap_binddn->ptr, s->auth_ldap_bindpw->ptr))) {
+ log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
+
+ return HANDLER_ERROR;
+ }
+ } else {
+ if (LDAP_SUCCESS != (ret = ldap_simple_bind_s(s->ldap, NULL, NULL))) {
+ log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
+
+ return HANDLER_ERROR;
+ }
+ }
+ }
+#else
+ log_error_write(srv, __FILE__, __LINE__, "s", "no ldap support available");
+ return HANDLER_ERROR;
+#endif
+ return HANDLER_GO_ON;
+}
+
+int mod_auth_plugin_init(plugin *p) {
+ p->version = LIGHTTPD_VERSION_ID;
+ p->name = buffer_init_string("auth");
+ p->init = mod_auth_init;
+ p->set_defaults = mod_auth_set_defaults;
+ p->handle_uri_clean = mod_auth_uri_handler;
+ p->cleanup = mod_auth_free;
+
+ p->data = NULL;
+
+ return 0;
+}
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_auth.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_auth.h?rev=678637&view=auto
==============================================================================
(empty)
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_axis2.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_axis2.c?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_axis2.c (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_axis2.c Mon Jul 21 21:35:35 2008
@@ -0,0 +1,493 @@
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "base.h"
+#include "log.h"
+#include "buffer.h"
+#include "response.h"
+
+#include "plugin.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <axutil_error_default.h>
+#include <axutil_log_default.h>
+#include <axutil_thread_pool.h>
+#include <axiom_xml_reader.h>
+#include <axutil_version.h>
+#include <axis2_http_transport.h>
+#include <axis2_conf_ctx.h>
+#include <axis2_conf_init.h>
+#include <axutil_class_loader.h>
+#include <axis2_conf_ctx.h>
+
+#include <axis2_http_transport.h>
+#include <axis2_msg_ctx.h>
+#include <axis2_http_out_transport_info.h>
+#include <axis2_http_transport_utils.h>
+#include <axis2_http_accept_record.h>
+#include "lighty_stream.h"
+#include "axis2_lighty_out_transport_info.h"
+
+/* plugin config for all request/connections */
+typedef struct {
+ buffer *axis2c_repo;
+ buffer *axis2c_logfile;
+ buffer *axis2c_loglevel;
+} plugin_config;
+
+typedef struct {
+ PLUGIN_DATA;
+ buffer *axis2c_repo_buf;
+
+ plugin_config **config_storage;
+
+ plugin_config conf;
+
+ /* mod_axis2 related values */
+ axutil_env_t *env;
+
+ axis2_conf_ctx_t *conf_ctx;
+
+} plugin_data;
+
+
+static int axis2_lighty_init_server (server *srv, plugin_data *p_d);
+
+static int axis2_lighty_process_request (server *srv, connection *con, plugin_data *p);
+
+
+/* init the plugin data */
+INIT_FUNC(mod_axis2_init)
+{
+ plugin_data *p;
+
+ p = calloc(1, sizeof(*p));
+
+ p->axis2c_repo_buf = buffer_init();
+ return p;
+}
+
+/* detroy the plugin data */
+FREE_FUNC(mod_axis2_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;
+
+ buffer_free(s->axis2c_repo);
+
+ free(s);
+ }
+ free(p->config_storage);
+ }
+
+ if (p->conf_ctx && p->env)
+ {
+ axis2_conf_ctx_free(p->conf_ctx, p->env);
+ axutil_env_free(p->env);
+ p->conf_ctx = NULL;
+ p->env = NULL;
+ }
+
+ buffer_free(p->axis2c_repo_buf);
+ free(p);
+ return HANDLER_GO_ON;
+}
+
+SETDEFAULTS_FUNC(mod_axis2_set_defaults)
+{
+ plugin_data *p = p_d;
+ size_t i = 0;
+
+ /* values accessing from lighttpd.conf */
+ config_values_t cv[] = {
+ { "axis2c.repo-path", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "axis2c.logfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
+ { "axis2c.loglevel", 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->axis2c_repo = buffer_init();
+ s->axis2c_logfile = buffer_init ();
+ s->axis2c_loglevel = buffer_init ();
+
+ cv[0].destination = s->axis2c_repo;
+ cv[1].destination = s->axis2c_logfile;
+ cv[2].destination = s->axis2c_loglevel;
+
+ p->config_storage[i] = s;
+
+ if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv))
+ {
+ return HANDLER_ERROR;
+ }
+ }
+
+ /* initializing and setting defaults values in axis2/c */
+ axis2_lighty_init_server (srv, p);
+ return HANDLER_GO_ON;
+}
+
+
+#define PATCH(x) \
+ p->conf.x = s->x;
+static int mod_axis2_patch_connection(server *srv, connection *con, plugin_data *p)
+{
+ size_t i, j;
+ plugin_config *s = p->config_storage[0];
+
+ PATCH(axis2c_repo);
+
+ /* 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("axis2c.repo-path")))
+ {
+ PATCH(axis2c_repo);
+ }
+ else if(buffer_is_equal_string(du->key, CONST_STR_LEN("axis2c.logfile")))
+ {
+ PATCH(axis2c_logfile);
+ }
+ else if (buffer_is_equal_string(du->key, CONST_STR_LEN("axis2c.logfile")))
+ {
+ PATCH(axis2c_loglevel);
+ }
+ }
+ }
+
+ return 0;
+}
+#undef PATCH
+
+
+SUBREQUEST_FUNC(mode_axis2_subrequest_start)
+{
+ plugin_data *p = p_d;
+ mod_axis2_patch_connection(srv, con, p);
+ axis2_lighty_process_request (srv, con, p);
+ return HANDLER_FINISHED;
+}
+
+
+static int axis2_lighty_init_server (server *srv, plugin_data *p)
+{
+ axutil_env_t *env;
+ axis2_conf_t *conf;
+ axutil_hash_t* svc_map = NULL;
+ axutil_hash_index_t *hi = NULL;
+ void* svc = NULL;
+ plugin_config *plg;
+ axis2_char_t *repo_path = NULL;
+ axis2_char_t *log_file = NULL;
+ unsigned int log_level = 0;
+
+ if (!p)
+ {
+ log_error_write(srv, __FILE__, __LINE__, "s",
+ "plugin data is null, unable to proceed");
+ return HANDLER_ERROR;
+ }
+
+ plg = p->config_storage[0];
+
+ if (!plg)
+ {
+ log_error_write(srv, __FILE__, __LINE__, "s",
+ "unable to retrieve mod_axis2 plugin from configuration storage");
+ return HANDLER_ERROR;
+ }
+
+ log_file = (axis2_char_t *)plg->axis2c_logfile->ptr;
+ if (!log_file)
+ {
+ log_error_write(srv, __FILE__, __LINE__, "s",
+ "unable to find axis2c.logfile in lighttpd.conf");
+ return HANDLER_ERROR;
+ }
+
+ log_level = (unsigned int)plg->axis2c_loglevel->ptr;
+
+ if (!log_level)
+ {
+ log_error_write(srv, __FILE__, __LINE__, "s",
+ "unable to find axis2c.loglevel in lighttpd.conf");
+ return HANDLER_ERROR;
+ }
+
+
+ p->env = axutil_env_create_all (log_file, log_level);
+
+ if (!p->env)
+ {
+ log_error_write(srv, __FILE__, __LINE__, "sssd",
+ "env creation faild for mod_axis2 log_file",
+ log_file,"and log_level", log_level );
+ return HANDLER_ERROR;
+ }
+
+ env = p->env;
+
+ /* we are using config_storage to access axis2c.repo value from
+ * configuration file */
+
+ repo_path = (axis2_char_t *)plg->axis2c_repo->ptr;
+
+ if (!repo_path)
+ {
+ log_error_write(srv, __FILE__, __LINE__, "s",
+ "unable to find axis2c.repo-path in lighttpd.conf");
+ return HANDLER_ERROR;
+ }
+
+
+ p->conf_ctx = axis2_build_conf_ctx (env, axutil_strdup(env, repo_path));
+
+ if (!p->conf_ctx)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "conf ctx creation failed for %s repo path", repo_path);
+ }
+
+ conf = axis2_conf_ctx_get_conf (p->conf_ctx, env);
+
+ if (!conf)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "unable to get conf for %s repo path", repo_path);
+ }
+
+ svc_map = axis2_conf_get_all_svcs (conf, env);
+ if (!svc_map)
+ {
+ AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI,
+ "svcs map is NULL");
+ }
+
+ for (hi = axutil_hash_first(svc_map, env);
+ hi; hi = axutil_hash_next(env, hi))
+ {
+ void *impl_class = NULL;
+ axutil_param_t *impl_info_param = NULL;
+
+ axutil_hash_this(hi, NULL, NULL, &svc);
+ if (!svc)
+ continue;
+ impl_class = axis2_svc_get_impl_class(svc, env);
+ if (impl_class)
+ continue;
+ impl_info_param = axis2_svc_get_param(svc, env, AXIS2_SERVICE_CLASS);
+ if (!impl_info_param)
+ continue;
+
+ axutil_class_loader_init(env);
+ impl_class = axutil_class_loader_create_dll(env, impl_info_param);
+ axis2_svc_set_impl_class(svc, env, impl_class);
+ if (impl_class)
+ {
+ AXIS2_SVC_SKELETON_INIT((axis2_svc_skeleton_t *) impl_class, env);
+ }
+ }
+
+ AXIS2_LOG_INFO(env->log, "lighty mod axis2 services loaded");
+
+ return HANDLER_GO_ON;
+}
+
+
+#define PTR(x) x->ptr
+
+static int axis2_lighty_process_request (server *srv, connection *con, plugin_data *p)
+{
+ axutil_env_t *env;
+ axis2_conf_ctx_t *conf_ctx = NULL;
+ unsigned int content_length = 0;
+ unsigned int http_version = -1;
+ axis2_char_t *request_url = NULL;
+ const axis2_char_t *content_type = NULL;
+ axis2_http_transport_in_t transport_in;
+ axis2_http_transport_out_t transport_out;
+ axis2_transport_out_desc_t * out_desc = NULL;
+ axis2_transport_in_desc_t * in_desc = NULL;
+ axis2_msg_ctx_t *msg_ctx = NULL;
+ axutil_stream_t *in_stream = NULL;
+ axis2_http_out_transport_info_t *lighty_out_transport_info = NULL;
+ buffer *b;
+
+ b = buffer_init ();
+
+ if (!p->env)
+ {
+ log_error_write(srv, __FILE__, __LINE__, "s",
+ "axis2c env is null, unable to continue");
+
+ return HANDLER_ERROR;
+ }
+
+ env = p->env;
+
+ conf_ctx = p->conf_ctx;
+
+ if (!conf_ctx)
+ {
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "conf ctx is null unable to continue");
+ return HANDLER_ERROR;
+ }
+
+ /* initialzing transport_in and transport_out structures */
+ memset (&transport_in, 0, sizeof(transport_in));
+ memset (&transport_out, 0, sizeof(transport_out));
+
+ content_length = (unsigned int)con->request.content_length;
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "request content length %d", content_length);
+
+ http_version = con->request.http_version;
+
+ request_url = axutil_strcat (env, PTR(con->uri.scheme), "://", PTR(con->uri.authority),
+ PTR(con->uri.path), NULL);
+
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "url %s", request_url);
+
+ content_type = con->request.http_content_type;
+
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "http content type %s", content_type);
+
+ out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(conf_ctx, env),
+ env, AXIS2_TRANSPORT_ENUM_HTTP);
+ /** transport in description */
+ in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(conf_ctx, env),
+ env, AXIS2_TRANSPORT_ENUM_HTTP);
+
+ /* filling transport_in structure */
+ transport_in.request_uri = axutil_strdup (env, request_url);
+ transport_in.content_length = content_length;
+ transport_in.content_type = (axis2_char_t *)content_type;
+
+ switch (http_version)
+ {
+ case HTTP_VERSION_1_1:
+ {
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "Clinet http version is HTTP 1.1");
+ }
+ break;
+ case HTTP_VERSION_1_0:
+ {
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "Client http version is HTTP 1.0");
+ }
+ break;
+ };
+
+ msg_ctx = axis2_msg_ctx_create (env, conf_ctx, in_desc, out_desc);
+ transport_in.msg_ctx = msg_ctx;
+
+ lighty_out_transport_info = axis2_lighty_out_transport_info_create (env, srv, con);
+ transport_in.out_transport_info = lighty_out_transport_info;
+
+ in_stream = axutil_stream_create_lighty(env, con);
+ transport_in.in_stream = in_stream;
+
+
+ switch (con->request.http_method){
+ case HTTP_METHOD_POST:
+ {
+ transport_in.request_method = AXIS2_HTTP_METHOD_POST;
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "processing POST request");
+ }
+ break;
+ case HTTP_METHOD_GET:
+ {
+ transport_in.request_method = AXIS2_HTTP_METHOD_GET;
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "processing GET request");
+ }
+ break;
+ case HTTP_METHOD_PUT:
+ {
+ transport_in.request_method = AXIS2_HTTP_METHOD_PUT;
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "processing PUT request");
+ }
+ break;
+ case HTTP_METHOD_HEAD:
+ {
+ transport_in.request_method = AXIS2_HTTP_METHOD_HEAD;
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "processing HEAD request");
+ }
+ break;
+ case HTTP_METHOD_DELETE:
+ {
+ transport_in.request_method = AXIS2_HTTP_METHOD_DELETE;
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "processing DELETE request");
+ }
+ break;
+ default:
+ {
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "http method not handled");
+ }
+ };
+
+ axis2_http_transport_utils_process_request(env, conf_ctx, &transport_in, &transport_out);
+
+ buffer_copy_off_t (b, transport_out.response_data_length);
+ response_header_overwrite(srv, con, CONST_STR_LEN("Content-Length"), CONST_BUF_LEN(b));
+
+ buffer_reset (b);
+ buffer_copy_string (b, transport_out.response_data);
+ chunkqueue_append_buffer(con->write_queue, b);
+
+ AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "response %s", b->ptr);
+ return HANDLER_GO_ON;
+}
+
+#undef PTR
+
+/* this function is called at dlopen() time and inits the callbacks */
+int mod_axis2_plugin_init(plugin *p)
+{
+ p->version = LIGHTTPD_VERSION_ID;
+ p->name = buffer_init_string("axis2c");
+
+ p->init = mod_axis2_init;
+ p->set_defaults = mod_axis2_set_defaults;
+ p->cleanup = mod_axis2_free;
+ p->handle_subrequest_start = mode_axis2_subrequest_start;
+ p->data = NULL;
+
+ return 0;
+}
+
Added: webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_axis2.loT
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_axis2.loT?rev=678637&view=auto
==============================================================================
--- webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_axis2.loT (added)
+++ webservices/axis2/branches/c/lighttpd_mod_axis2/lighttpd/src/mod_axis2.loT Mon Jul 21 21:35:35 2008
@@ -0,0 +1,7 @@
+# mod_axis2.lo - a libtool object file
+# Generated by ltmain.sh - GNU libtool 1.5.26 Debian 1.5.26-4 (1.1220.2.493 2008/02/01 16:58:18)
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.