|
version 1.1, 2013/10/14 10:32:48
|
version 1.1.1.3, 2016/11/02 10:35:00
|
|
Line 1
|
Line 1
|
| |
#include "first.h" |
| |
|
| #include "buffer.h" |
#include "buffer.h" |
| #include "server.h" |
#include "server.h" |
| #include "log.h" |
#include "log.h" |
|
Line 43 FREE_FUNC(mod_cml_free) {
|
Line 45 FREE_FUNC(mod_cml_free) {
|
| for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
| plugin_config *s = p->config_storage[i]; |
plugin_config *s = p->config_storage[i]; |
| |
|
| |
if (NULL == s) continue; |
| |
|
| buffer_free(s->ext); |
buffer_free(s->ext); |
| |
|
| buffer_free(s->mc_namespace); |
buffer_free(s->mc_namespace); |
| buffer_free(s->power_magnet); |
buffer_free(s->power_magnet); |
| array_free(s->mc_hosts); |
array_free(s->mc_hosts); |
| |
|
| #if defined(HAVE_MEMCACHE_H) | #if defined(USE_MEMCACHED) |
| if (s->mc) mc_free(s->mc); | if (s->memc) memcached_free(s->memc); |
| #endif |
#endif |
| |
|
| free(s); |
free(s); |
|
Line 83 SETDEFAULTS_FUNC(mod_cml_set_defaults) {
|
Line 87 SETDEFAULTS_FUNC(mod_cml_set_defaults) {
|
| |
|
| if (!p) return HANDLER_ERROR; |
if (!p) return HANDLER_ERROR; |
| |
|
| p->config_storage = malloc(srv->config_context->used * sizeof(specific_config *)); | p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); |
| |
|
| for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
| |
data_config const* config = (data_config const*)srv->config_context->data[i]; |
| plugin_config *s; |
plugin_config *s; |
| |
|
| s = malloc(sizeof(plugin_config)); |
s = malloc(sizeof(plugin_config)); |
|
Line 93 SETDEFAULTS_FUNC(mod_cml_set_defaults) {
|
Line 98 SETDEFAULTS_FUNC(mod_cml_set_defaults) {
|
| s->mc_hosts = array_init(); |
s->mc_hosts = array_init(); |
| s->mc_namespace = buffer_init(); |
s->mc_namespace = buffer_init(); |
| s->power_magnet = buffer_init(); |
s->power_magnet = buffer_init(); |
| #if defined(HAVE_MEMCACHE_H) | #if defined(USE_MEMCACHED) |
| s->mc = NULL; | s->memc = NULL; |
| #endif |
#endif |
| |
|
| cv[0].destination = s->ext; |
cv[0].destination = s->ext; |
|
Line 104 SETDEFAULTS_FUNC(mod_cml_set_defaults) {
|
Line 109 SETDEFAULTS_FUNC(mod_cml_set_defaults) {
|
| |
|
| p->config_storage[i] = s; |
p->config_storage[i] = s; |
| |
|
| if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { | if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) { |
| return HANDLER_ERROR; |
return HANDLER_ERROR; |
| } |
} |
| |
|
| if (s->mc_hosts->used) { |
if (s->mc_hosts->used) { |
| #if defined(HAVE_MEMCACHE_H) | #if defined(USE_MEMCACHED) |
| | buffer *option_string = buffer_init(); |
| size_t k; |
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[0]; |
| | |
| | buffer_append_string_len(option_string, CONST_STR_LEN("--SERVER=")); |
| | buffer_append_string_buffer(option_string, ds->value); |
| | } |
| | |
| | for (k = 1; k < s->mc_hosts->used; k++) { |
| data_string *ds = (data_string *)s->mc_hosts->data[k]; |
data_string *ds = (data_string *)s->mc_hosts->data[k]; |
| |
|
| if (0 != mc_server_add4(s->mc, ds->value->ptr)) { | buffer_append_string_len(option_string, CONST_STR_LEN(" --SERVER=")); |
| log_error_write(srv, __FILE__, __LINE__, "sb", | buffer_append_string_buffer(option_string, ds->value); |
| "connection to host failed:", | } |
| ds->value); | |
| |
|
| return HANDLER_ERROR; | s->memc = memcached(CONST_BUF_LEN(option_string)); |
| } | |
| | if (NULL == s->memc) { |
| | log_error_write(srv, __FILE__, __LINE__, "sb", |
| | "configuring memcached failed for option string:", |
| | option_string); |
| } |
} |
| |
buffer_free(option_string); |
| |
|
| |
if (NULL == s->memc) return HANDLER_ERROR; |
| #else |
#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"); | "memcache support is not compiled in but cml.memcache-hosts is set, aborting"); |
| return HANDLER_ERROR; |
return HANDLER_ERROR; |
| #endif |
#endif |
| } |
} |
|
Line 142 static int mod_cml_patch_connection(server *srv, conne
|
Line 160 static int mod_cml_patch_connection(server *srv, conne
|
| plugin_config *s = p->config_storage[0]; |
plugin_config *s = p->config_storage[0]; |
| |
|
| PATCH(ext); |
PATCH(ext); |
| #if defined(HAVE_MEMCACHE_H) | #if defined(USE_MEMCACHED) |
| PATCH(mc); | PATCH(memc); |
| #endif |
#endif |
| PATCH(mc_namespace); |
PATCH(mc_namespace); |
| PATCH(power_magnet); |
PATCH(power_magnet); |
|
Line 163 static int mod_cml_patch_connection(server *srv, conne
|
Line 181 static int mod_cml_patch_connection(server *srv, conne
|
| if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.extension"))) { |
if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.extension"))) { |
| PATCH(ext); |
PATCH(ext); |
| } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-hosts"))) { |
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-hosts"))) { |
| #if defined(HAVE_MEMCACHE_H) | #if defined(USE_MEMCACHED) |
| PATCH(mc); | PATCH(memc); |
| #endif |
#endif |
| } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-namespace"))) { |
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-namespace"))) { |
| PATCH(mc_namespace); |
PATCH(mc_namespace); |
|
Line 184 static int cache_call_lua(server *srv, connection *con
|
Line 202 static int cache_call_lua(server *srv, connection *con
|
| |
|
| /* cleanup basedir */ |
/* cleanup basedir */ |
| b = p->baseurl; |
b = p->baseurl; |
| buffer_copy_string_buffer(b, con->uri.path); | buffer_copy_buffer(b, con->uri.path); |
| for (c = b->ptr + b->used - 1; c > b->ptr && *c != '/'; c--); | for (c = b->ptr + buffer_string_length(b); c > b->ptr && *c != '/'; c--); |
| |
|
| if (*c == '/') { |
if (*c == '/') { |
| b->used = c - b->ptr + 2; | buffer_string_set_length(b, c - b->ptr + 1); |
| *(c+1) = '\0'; | |
| } |
} |
| |
|
| b = p->basedir; |
b = p->basedir; |
| buffer_copy_string_buffer(b, con->physical.path); | buffer_copy_buffer(b, con->physical.path); |
| for (c = b->ptr + b->used - 1; c > b->ptr && *c != '/'; c--); | for (c = b->ptr + buffer_string_length(b); c > b->ptr && *c != '/'; c--); |
| |
|
| if (*c == '/') { |
if (*c == '/') { |
| b->used = c - b->ptr + 2; | buffer_string_set_length(b, c - b->ptr + 1); |
| *(c+1) = '\0'; | |
| } |
} |
| |
|
| |
|
|
Line 218 URIHANDLER_FUNC(mod_cml_power_magnet) {
|
Line 234 URIHANDLER_FUNC(mod_cml_power_magnet) {
|
| buffer_reset(p->baseurl); |
buffer_reset(p->baseurl); |
| buffer_reset(p->trigger_handler); |
buffer_reset(p->trigger_handler); |
| |
|
| if (buffer_is_empty(p->conf.power_magnet)) return HANDLER_GO_ON; | if (buffer_string_is_empty(p->conf.power_magnet)) return HANDLER_GO_ON; |
| |
|
| /* |
/* |
| * power-magnet: |
* power-magnet: |
|
Line 264 URIHANDLER_FUNC(mod_cml_power_magnet) {
|
Line 280 URIHANDLER_FUNC(mod_cml_power_magnet) {
|
| URIHANDLER_FUNC(mod_cml_is_handled) { |
URIHANDLER_FUNC(mod_cml_is_handled) { |
| plugin_data *p = p_d; |
plugin_data *p = p_d; |
| |
|
| if (buffer_is_empty(con->physical.path)) return HANDLER_ERROR; | if (buffer_string_is_empty(con->physical.path)) return HANDLER_ERROR; |
| |
|
| mod_cml_patch_connection(srv, con, p); |
mod_cml_patch_connection(srv, con, p); |
| |
|
|
Line 272 URIHANDLER_FUNC(mod_cml_is_handled) {
|
Line 288 URIHANDLER_FUNC(mod_cml_is_handled) {
|
| buffer_reset(p->baseurl); |
buffer_reset(p->baseurl); |
| buffer_reset(p->trigger_handler); |
buffer_reset(p->trigger_handler); |
| |
|
| if (buffer_is_empty(p->conf.ext)) return HANDLER_GO_ON; | if (buffer_string_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)) { | if (!buffer_is_equal_right_len(con->physical.path, p->conf.ext, buffer_string_length(p->conf.ext))) { |
| return HANDLER_GO_ON; |
return HANDLER_GO_ON; |
| } |
} |
| |
|