diff options
Diffstat (limited to 'src/mod_cml.c')
-rw-r--r-- | src/mod_cml.c | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/src/mod_cml.c b/src/mod_cml.c index 551c2b8..2221368 100644 --- a/src/mod_cml.c +++ b/src/mod_cml.c @@ -20,50 +20,50 @@ /* init the plugin data */ INIT_FUNC(mod_cml_init) { plugin_data *p; - + p = calloc(1, sizeof(*p)); - + p->basedir = buffer_init(); p->baseurl = buffer_init(); p->trigger_handler = buffer_init(); - + return p; } /* detroy the plugin data */ FREE_FUNC(mod_cml_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->ext); - + buffer_free(s->mc_namespace); buffer_free(s->power_magnet); array_free(s->mc_hosts); - + #if defined(HAVE_MEMCACHE_H) if (s->mc) mc_free(s->mc); #endif - + free(s); } free(p->config_storage); } - + buffer_free(p->trigger_handler); buffer_free(p->basedir); buffer_free(p->baseurl); - + free(p); - + return HANDLER_GO_ON; } @@ -72,22 +72,22 @@ FREE_FUNC(mod_cml_free) { SETDEFAULTS_FUNC(mod_cml_set_defaults) { plugin_data *p = p_d; size_t i = 0; - - config_values_t cv[] = { + + config_values_t cv[] = { { "cml.extension", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ { "cml.memcache-hosts", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ { "cml.memcache-namespace", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 2 */ { "cml.power-magnet", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 3 */ { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } }; - + if (!p) return HANDLER_ERROR; - + p->config_storage = malloc(srv->config_context->used * sizeof(specific_config *)); - + for (i = 0; i < srv->config_context->used; i++) { plugin_config *s; - + s = malloc(sizeof(plugin_config)); s->ext = buffer_init(); s->mc_hosts = array_init(); @@ -96,42 +96,42 @@ SETDEFAULTS_FUNC(mod_cml_set_defaults) { #if defined(HAVE_MEMCACHE_H) s->mc = NULL; #endif - + cv[0].destination = s->ext; cv[1].destination = s->mc_hosts; cv[2].destination = s->mc_namespace; cv[3].destination = s->power_magnet; - + 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->mc_hosts->used) { #if defined(HAVE_MEMCACHE_H) size_t k; s->mc = mc_new(); - + for (k = 0; k < s->mc_hosts->used; k++) { data_string *ds = (data_string *)s->mc_hosts->data[k]; - + if (0 != mc_server_add4(s->mc, ds->value->ptr)) { - log_error_write(srv, __FILE__, __LINE__, "sb", - "connection to host failed:", + log_error_write(srv, __FILE__, __LINE__, "sb", + "connection to host failed:", ds->value); - + return HANDLER_ERROR; } } #else - log_error_write(srv, __FILE__, __LINE__, "s", + log_error_write(srv, __FILE__, __LINE__, "s", "memcache support is not compiled in but cml.memcache-hosts is set, aborting"); return HANDLER_ERROR; #endif } } - + return HANDLER_GO_ON; } @@ -140,26 +140,26 @@ SETDEFAULTS_FUNC(mod_cml_set_defaults) { static int mod_cml_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; - + PATCH(ext); #if defined(HAVE_MEMCACHE_H) PATCH(mc); #endif PATCH(mc_namespace); PATCH(power_magnet); - + /* 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("cml.extension"))) { PATCH(ext); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-hosts"))) { @@ -173,7 +173,7 @@ static int mod_cml_patch_connection(server *srv, connection *con, plugin_data *p } } } - + return 0; } #undef PATCH @@ -186,21 +186,21 @@ int cache_call_lua(server *srv, connection *con, plugin_data *p, buffer *cml_fil b = p->baseurl; buffer_copy_string_buffer(b, con->uri.path); for (c = b->ptr + b->used - 1; c > b->ptr && *c != '/'; c--); - + if (*c == '/') { b->used = c - b->ptr + 2; *(c+1) = '\0'; } - + b = p->basedir; buffer_copy_string_buffer(b, con->physical.path); for (c = b->ptr + b->used - 1; c > b->ptr && *c != '/'; c--); - + if (*c == '/') { b->used = c - b->ptr + 2; *(c+1) = '\0'; } - + /* prepare variables * - cookie-based @@ -211,30 +211,30 @@ int cache_call_lua(server *srv, connection *con, plugin_data *p, buffer *cml_fil URIHANDLER_FUNC(mod_cml_power_magnet) { plugin_data *p = p_d; - + mod_cml_patch_connection(srv, con, p); - + buffer_reset(p->basedir); buffer_reset(p->baseurl); buffer_reset(p->trigger_handler); if (buffer_is_empty(p->conf.power_magnet)) return HANDLER_GO_ON; - - /* + + /* * power-magnet: * cml.power-magnet = server.docroot + "/rewrite.cml" * * is called on EACH request, take the original REQUEST_URI and modifies the - * request header as neccesary. + * request header as neccesary. * * First use: * if file_exists("/maintainance.html") { * output_include = ( "/maintainance.html" ) - * return CACHE_HIT + * return CACHE_HIT * } * * as we only want to rewrite HTML like requests we should cover it in a conditional - * + * * */ switch(cache_call_lua(srv, con, p, p->conf.power_magnet)) { @@ -263,20 +263,20 @@ URIHANDLER_FUNC(mod_cml_power_magnet) { URIHANDLER_FUNC(mod_cml_is_handled) { plugin_data *p = p_d; - + if (buffer_is_empty(con->physical.path)) return HANDLER_ERROR; - + mod_cml_patch_connection(srv, con, p); - + buffer_reset(p->basedir); buffer_reset(p->baseurl); buffer_reset(p->trigger_handler); if (buffer_is_empty(p->conf.ext)) return HANDLER_GO_ON; - + if (!buffer_is_equal_right_len(con->physical.path, p->conf.ext, p->conf.ext->used - 1)) { return HANDLER_GO_ON; - } + } switch(cache_call_lua(srv, con, p, con->physical.path)) { case -1: @@ -308,15 +308,15 @@ URIHANDLER_FUNC(mod_cml_is_handled) { int mod_cml_plugin_init(plugin *p) { p->version = LIGHTTPD_VERSION_ID; p->name = buffer_init_string("cache"); - + p->init = mod_cml_init; p->cleanup = mod_cml_free; p->set_defaults = mod_cml_set_defaults; - + p->handle_subrequest_start = mod_cml_is_handled; p->handle_physical = mod_cml_power_magnet; - + p->data = NULL; - + return 0; } |