version 1.1.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 "base.h" |
#include "base.h" |
#include "log.h" |
#include "log.h" |
#include "buffer.h" |
#include "buffer.h" |
Line 11
|
Line 13
|
/** |
/** |
* this is a skeleton for a lighttpd plugin |
* this is a skeleton for a lighttpd plugin |
* |
* |
* just replaces every occurance of 'skeleton' by your plugin name | * just replaces every occurrence of 'skeleton' by your plugin name |
* |
* |
* e.g. in vim: |
* e.g. in vim: |
* |
* |
Line 65 INIT_FUNC(mod_skeleton_init) {
|
Line 67 INIT_FUNC(mod_skeleton_init) {
|
return p; |
return p; |
} |
} |
|
|
/* detroy the plugin data */ | /* destroy the plugin data */ |
FREE_FUNC(mod_skeleton_free) { |
FREE_FUNC(mod_skeleton_free) { |
plugin_data *p = p_d; |
plugin_data *p = p_d; |
|
|
Line 79 FREE_FUNC(mod_skeleton_free) {
|
Line 81 FREE_FUNC(mod_skeleton_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 (!s) continue; | if (NULL == s) continue; |
|
|
array_free(s->match); |
array_free(s->match); |
|
|
Line 108 SETDEFAULTS_FUNC(mod_skeleton_set_defaults) {
|
Line 110 SETDEFAULTS_FUNC(mod_skeleton_set_defaults) {
|
|
|
if (!p) return HANDLER_ERROR; |
if (!p) return HANDLER_ERROR; |
|
|
p->config_storage = calloc(1, 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 = calloc(1, sizeof(plugin_config)); |
s = calloc(1, sizeof(plugin_config)); |
Line 120 SETDEFAULTS_FUNC(mod_skeleton_set_defaults) {
|
Line 123 SETDEFAULTS_FUNC(mod_skeleton_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; |
} |
} |
} |
} |
Line 160 static int mod_skeleton_patch_connection(server *srv,
|
Line 163 static int mod_skeleton_patch_connection(server *srv,
|
|
|
URIHANDLER_FUNC(mod_skeleton_uri_handler) { |
URIHANDLER_FUNC(mod_skeleton_uri_handler) { |
plugin_data *p = p_d; |
plugin_data *p = p_d; |
int s_len; | size_t s_len; |
size_t k, i; | size_t k; |
|
|
UNUSED(srv); |
UNUSED(srv); |
|
|
if (con->mode != DIRECT) return HANDLER_GO_ON; |
if (con->mode != DIRECT) return HANDLER_GO_ON; |
|
|
if (con->uri.path->used == 0) return HANDLER_GO_ON; | s_len = buffer_string_length(con->uri.path); |
| if (0 == s_len) return HANDLER_GO_ON; |
|
|
mod_skeleton_patch_connection(srv, con, p); |
mod_skeleton_patch_connection(srv, con, p); |
|
|
s_len = con->uri.path->used - 1; |
|
|
|
for (k = 0; k < p->conf.match->used; k++) { |
for (k = 0; k < p->conf.match->used; k++) { |
data_string *ds = (data_string *)p->conf.match->data[k]; |
data_string *ds = (data_string *)p->conf.match->data[k]; |
int ct_len = ds->value->used - 1; | size_t ct_len = buffer_string_length(ds->value); |
|
|
if (ct_len > s_len) continue; |
if (ct_len > s_len) continue; |
if (ds->value->used == 0) continue; | if (ct_len == 0) continue; |
|
|
if (0 == strncmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) { |
if (0 == strncmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) { |
con->http_status = 403; |
con->http_status = 403; |