2016-03-19 15:14:35 +00:00
|
|
|
#include "first.h"
|
|
|
|
|
2018-03-25 07:45:05 +00:00
|
|
|
#include "mod_cml.h"
|
|
|
|
|
|
|
|
#include "base.h"
|
2005-07-06 11:58:19 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "plugin.h"
|
|
|
|
|
2009-10-11 14:31:42 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-07-06 16:36:46 +00:00
|
|
|
INIT_FUNC(mod_cml_init) {
|
2019-10-27 06:14:46 +00:00
|
|
|
return calloc(1, sizeof(plugin_data));
|
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2019-11-19 08:39:40 +00:00
|
|
|
FREE_FUNC(mod_cml_free) {
|
|
|
|
plugin_data * const p = p_d;
|
|
|
|
free(p->trigger_handler.ptr);
|
|
|
|
free(p->basedir.ptr);
|
|
|
|
free(p->baseurl.ptr);
|
2019-10-27 06:14:46 +00:00
|
|
|
if (NULL == p->cvlist) return;
|
|
|
|
#if defined(USE_MEMCACHED)
|
|
|
|
/* (init i to 0 if global context; to 1 to skip empty global context) */
|
|
|
|
for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) {
|
|
|
|
config_plugin_value_t *cpv = p->cvlist + p->cvlist[i].v.u2[0];
|
|
|
|
for (; -1 != cpv->k_id; ++cpv) {
|
|
|
|
switch (cpv->k_id) {
|
|
|
|
case 1: /* cml.memcache-hosts */
|
|
|
|
if (cpv->vtype == T_CONFIG_LOCAL && NULL != cpv->v.v)
|
|
|
|
memcached_free(cpv->v.v); /* mod_cml_free_memcached() */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
static int mod_cml_init_memcached(server *srv, config_plugin_value_t * const cpv) {
|
|
|
|
const array * const mc_hosts = cpv->v.a;
|
|
|
|
if (0 == mc_hosts->used) {
|
|
|
|
cpv->v.v = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(USE_MEMCACHED)
|
|
|
|
|
|
|
|
buffer * const opts = srv->tmp_buf;
|
|
|
|
buffer_clear(opts);
|
|
|
|
for (uint32_t k = 0; k < mc_hosts->used; ++k) {
|
|
|
|
const data_string * const ds = (const data_string *)mc_hosts->data[k];
|
|
|
|
buffer_append_string_len(opts, CONST_STR_LEN(" --SERVER="));
|
|
|
|
buffer_append_string_buffer(opts, &ds->value);
|
|
|
|
}
|
|
|
|
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
cpv->v.v = memcached(opts->ptr+1, buffer_clen(opts)-1);
|
2019-10-27 06:14:46 +00:00
|
|
|
|
|
|
|
if (cpv->v.v) {
|
|
|
|
cpv->vtype = T_CONFIG_LOCAL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_error(srv->errh, __FILE__, __LINE__,
|
|
|
|
"configuring memcached failed for option string: %s", opts->ptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
log_error(srv->errh, __FILE__, __LINE__,
|
|
|
|
"memcache support is not compiled in but cml.memcache-hosts is set, "
|
|
|
|
"aborting");
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#endif
|
2005-07-06 11:58:19 +00:00
|
|
|
}
|
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
static void mod_cml_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) {
|
|
|
|
switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */
|
|
|
|
case 0: /* cml.extension */
|
|
|
|
pconf->ext = cpv->v.b;
|
|
|
|
break;
|
|
|
|
case 1: /* cml.memcache-hosts *//* setdefaults inits memcached_st *memc */
|
|
|
|
#if defined(USE_MEMCACHED)
|
|
|
|
if (cpv->vtype != T_CONFIG_LOCAL) break;
|
|
|
|
pconf->memc = cpv->v.v;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 2: /* cml.memcache-namespace */
|
|
|
|
/*pconf->mc_namespace = cpv->v.b;*//*(unused)*/
|
|
|
|
break;
|
|
|
|
case 3: /* cml.power-magnet */
|
|
|
|
pconf->power_magnet = cpv->v.b;
|
|
|
|
break;
|
|
|
|
default:/* should not happen */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
static void mod_cml_merge_config(plugin_config * const pconf, const config_plugin_value_t *cpv) {
|
|
|
|
do {
|
|
|
|
mod_cml_merge_config_cpv(pconf, cpv);
|
|
|
|
} while ((++cpv)->k_id != -1);
|
2005-07-06 11:58:19 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
static void mod_cml_patch_config(request_st * const r, plugin_data * const p) {
|
2019-10-27 06:14:46 +00:00
|
|
|
memcpy(&p->conf, &p->defaults, sizeof(plugin_config));
|
|
|
|
for (int i = 1, used = p->nconfig; i < used; ++i) {
|
2020-01-13 02:51:12 +00:00
|
|
|
if (config_check_cond(r, (uint32_t)p->cvlist[i].k_id))
|
2019-10-27 06:14:46 +00:00
|
|
|
mod_cml_merge_config(&p->conf, p->cvlist + p->cvlist[i].v.u2[0]);
|
|
|
|
}
|
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
SETDEFAULTS_FUNC(mod_cml_set_defaults) {
|
|
|
|
static const config_plugin_keys_t cpk[] = {
|
|
|
|
{ CONST_STR_LEN("cml.extension"),
|
|
|
|
T_CONFIG_STRING,
|
|
|
|
T_CONFIG_SCOPE_CONNECTION }
|
|
|
|
,{ CONST_STR_LEN("cml.memcache-hosts"),
|
2019-12-08 00:15:55 +00:00
|
|
|
T_CONFIG_ARRAY_VLIST,
|
2019-10-27 06:14:46 +00:00
|
|
|
T_CONFIG_SCOPE_CONNECTION }
|
|
|
|
,{ CONST_STR_LEN("cml.memcache-namespace"), /*(unused)*/
|
|
|
|
T_CONFIG_STRING,
|
|
|
|
T_CONFIG_SCOPE_CONNECTION }
|
|
|
|
,{ CONST_STR_LEN("cml.power-magnet"),
|
|
|
|
T_CONFIG_STRING,
|
|
|
|
T_CONFIG_SCOPE_CONNECTION }
|
|
|
|
,{ NULL, 0,
|
|
|
|
T_CONFIG_UNSET,
|
|
|
|
T_CONFIG_SCOPE_UNSET }
|
|
|
|
};
|
|
|
|
|
|
|
|
plugin_data * const p = p_d;
|
|
|
|
if (!config_plugin_values_init(srv, p, cpk, "mod_cml"))
|
|
|
|
return HANDLER_ERROR;
|
|
|
|
|
|
|
|
/* process and validate config directives
|
|
|
|
* (init i to 0 if global context; to 1 to skip empty global context) */
|
|
|
|
for (int i = !p->cvlist[0].v.u2[1]; i < p->nconfig; ++i) {
|
|
|
|
config_plugin_value_t *cpv = p->cvlist + p->cvlist[i].v.u2[0];
|
|
|
|
for (; -1 != cpv->k_id; ++cpv) {
|
|
|
|
switch (cpv->k_id) {
|
|
|
|
case 0: /* cml.extension */
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
if (buffer_is_blank(cpv->v.b))
|
|
|
|
cpv->v.b = NULL;
|
2019-10-27 06:14:46 +00:00
|
|
|
break;
|
|
|
|
case 1: /* cml.memcache-hosts */ /* config converted to memc handles */
|
|
|
|
if (!mod_cml_init_memcached(srv, cpv)) {
|
|
|
|
return HANDLER_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: /* cml.memcache-namespace *//*(unused)*/
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
break;
|
2019-10-27 06:14:46 +00:00
|
|
|
case 3: /* cml.power-magnet */
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
if (buffer_is_blank(cpv->v.b))
|
|
|
|
cpv->v.b = NULL;
|
2019-10-27 06:14:46 +00:00
|
|
|
break;
|
|
|
|
default:/* should not happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize p->defaults from global config context */
|
|
|
|
if (p->nconfig > 0 && p->cvlist->v.u2[1]) {
|
|
|
|
const config_plugin_value_t *cpv = p->cvlist + p->cvlist->v.u2[0];
|
|
|
|
if (-1 != cpv->k_id)
|
|
|
|
mod_cml_merge_config(&p->defaults, cpv);
|
|
|
|
}
|
|
|
|
|
2021-10-25 08:34:03 +00:00
|
|
|
log_error(srv->errh, __FILE__, __LINE__,
|
|
|
|
"Warning: mod_%s is deprecated "
|
|
|
|
"and will be removed from a future lighttpd release in early 2022. "
|
|
|
|
"https://wiki.lighttpd.net/Docs_ConfigurationOptions#Deprecated",
|
|
|
|
p->self->name);
|
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
return HANDLER_GO_ON;
|
2005-07-06 11:58:19 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
static int cache_call_lua(request_st * const r, plugin_data * const p, const buffer * const cml_file) {
|
2005-07-06 11:58:19 +00:00
|
|
|
buffer *b;
|
|
|
|
char *c;
|
2005-12-29 12:16:10 +00:00
|
|
|
|
2005-07-06 11:58:19 +00:00
|
|
|
/* cleanup basedir */
|
2019-10-27 06:14:46 +00:00
|
|
|
b = &p->baseurl;
|
2020-01-13 02:51:12 +00:00
|
|
|
buffer_copy_buffer(b, &r->uri.path);
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
for (c = b->ptr + buffer_clen(b); c > b->ptr && *c != '/'; c--);
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-07-11 11:01:59 +00:00
|
|
|
if (*c == '/') {
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
buffer_truncate(b, c - b->ptr + 1);
|
2005-07-11 11:01:59 +00:00
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
b = &p->basedir;
|
2020-01-13 02:51:12 +00:00
|
|
|
buffer_copy_buffer(b, &r->physical.path);
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
for (c = b->ptr + buffer_clen(b); c > b->ptr && *c != '/'; c--);
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-07-06 11:58:19 +00:00
|
|
|
if (*c == '/') {
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
buffer_truncate(b, c - b->ptr + 1);
|
2005-07-06 11:58:19 +00:00
|
|
|
}
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-12-29 12:16:10 +00:00
|
|
|
|
2005-07-06 11:58:19 +00:00
|
|
|
/* prepare variables
|
|
|
|
* - cookie-based
|
|
|
|
* - get-param-based
|
|
|
|
*/
|
2020-01-13 02:51:12 +00:00
|
|
|
return cache_parse_lua(r, p, cml_file);
|
2005-12-29 12:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
URIHANDLER_FUNC(mod_cml_power_magnet) {
|
|
|
|
plugin_data *p = p_d;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
mod_cml_patch_config(r, p);
|
2005-12-29 12:16:10 +00:00
|
|
|
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
if (!p->conf.power_magnet) return HANDLER_GO_ON;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
buffer_clear(&p->basedir);
|
|
|
|
buffer_clear(&p->baseurl);
|
|
|
|
buffer_clear(&p->trigger_handler);
|
|
|
|
|
2006-10-04 13:26:23 +00:00
|
|
|
/*
|
2005-12-29 12:16:10 +00:00
|
|
|
* power-magnet:
|
|
|
|
* cml.power-magnet = server.docroot + "/rewrite.cml"
|
|
|
|
*
|
|
|
|
* is called on EACH request, take the original REQUEST_URI and modifies the
|
2020-02-22 22:24:12 +00:00
|
|
|
* request header as necessary.
|
2005-12-29 12:16:10 +00:00
|
|
|
*
|
|
|
|
* First use:
|
2020-02-22 22:24:12 +00:00
|
|
|
* if file_exists("/maintenance.html") {
|
|
|
|
* output_include = ( "/maintenance.html" )
|
2006-10-04 13:26:23 +00:00
|
|
|
* return CACHE_HIT
|
2005-12-29 12:16:10 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* as we only want to rewrite HTML like requests we should cover it in a conditional
|
2006-10-04 13:26:23 +00:00
|
|
|
*
|
2005-12-29 12:16:10 +00:00
|
|
|
* */
|
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
switch(cache_call_lua(r, p, p->conf.power_magnet)) {
|
2005-12-29 12:16:10 +00:00
|
|
|
case -1:
|
|
|
|
/* error */
|
2020-01-13 02:51:12 +00:00
|
|
|
if (r->conf.log_request_handling) {
|
|
|
|
log_error(r->conf.errh, __FILE__, __LINE__, "cache-error");
|
2005-12-29 12:16:10 +00:00
|
|
|
}
|
2020-01-13 02:51:12 +00:00
|
|
|
r->http_status = 500;
|
2005-12-29 12:16:10 +00:00
|
|
|
return HANDLER_COMEBACK;
|
|
|
|
case 0:
|
2020-01-13 02:51:12 +00:00
|
|
|
if (r->conf.log_request_handling) {
|
|
|
|
log_error(r->conf.errh, __FILE__, __LINE__, "cache-hit");
|
2005-12-29 12:16:10 +00:00
|
|
|
}
|
|
|
|
/* cache-hit */
|
|
|
|
return HANDLER_FINISHED;
|
|
|
|
case 1:
|
|
|
|
/* cache miss */
|
|
|
|
return HANDLER_GO_ON;
|
|
|
|
default:
|
2020-01-13 02:51:12 +00:00
|
|
|
r->http_status = 500;
|
2005-12-29 12:16:10 +00:00
|
|
|
return HANDLER_COMEBACK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
URIHANDLER_FUNC(mod_cml_is_handled) {
|
|
|
|
plugin_data *p = p_d;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2021-05-04 02:18:20 +00:00
|
|
|
/* r->physical.path is non-empty for handle_subrequest_start */
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
/*if (buffer_is_blank(&r->physical.path)) return HANDLER_ERROR;*/
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
mod_cml_patch_config(r, p);
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
if (!p->conf.ext) return HANDLER_GO_ON;
|
2005-12-29 12:16:10 +00:00
|
|
|
|
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
2021-06-09 02:57:36 +00:00
|
|
|
const uint32_t elen = buffer_clen(p->conf.ext);
|
|
|
|
const uint32_t plen = buffer_clen(&r->physical.path);
|
2021-05-07 02:51:39 +00:00
|
|
|
if (plen < elen || 0 != memcmp(r->physical.path.ptr+plen-elen, p->conf.ext->ptr, elen)) {
|
2005-12-29 12:16:10 +00:00
|
|
|
return HANDLER_GO_ON;
|
2006-10-04 13:26:23 +00:00
|
|
|
}
|
2005-12-29 12:16:10 +00:00
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
buffer_clear(&p->basedir);
|
|
|
|
buffer_clear(&p->baseurl);
|
|
|
|
buffer_clear(&p->trigger_handler);
|
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
switch(cache_call_lua(r, p, &r->physical.path)) {
|
2005-07-06 11:58:19 +00:00
|
|
|
case -1:
|
2005-07-11 11:01:59 +00:00
|
|
|
/* error */
|
2020-01-13 02:51:12 +00:00
|
|
|
if (r->conf.log_request_handling) {
|
|
|
|
log_error(r->conf.errh, __FILE__, __LINE__, "cache-error");
|
2005-07-11 11:01:59 +00:00
|
|
|
}
|
2020-01-13 02:51:12 +00:00
|
|
|
r->http_status = 500;
|
2005-07-06 11:58:19 +00:00
|
|
|
return HANDLER_COMEBACK;
|
|
|
|
case 0:
|
2020-01-13 02:51:12 +00:00
|
|
|
if (r->conf.log_request_handling) {
|
|
|
|
log_error(r->conf.errh, __FILE__, __LINE__, "cache-hit");
|
2005-07-11 11:01:59 +00:00
|
|
|
}
|
|
|
|
/* cache-hit */
|
2005-07-06 11:58:19 +00:00
|
|
|
return HANDLER_FINISHED;
|
|
|
|
case 1:
|
2020-01-13 02:51:12 +00:00
|
|
|
if (r->conf.log_request_handling) {
|
|
|
|
log_error(r->conf.errh, __FILE__, __LINE__, "cache-miss");
|
2005-07-11 11:01:59 +00:00
|
|
|
}
|
|
|
|
/* cache miss */
|
2005-07-06 11:58:19 +00:00
|
|
|
return HANDLER_COMEBACK;
|
2005-12-29 12:16:10 +00:00
|
|
|
default:
|
2020-01-13 02:51:12 +00:00
|
|
|
r->http_status = 500;
|
2005-12-29 12:16:10 +00:00
|
|
|
return HANDLER_COMEBACK;
|
2005-07-06 11:58:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 06:14:46 +00:00
|
|
|
|
2009-03-07 21:05:37 +00:00
|
|
|
int mod_cml_plugin_init(plugin *p);
|
2005-07-06 16:36:46 +00:00
|
|
|
int mod_cml_plugin_init(plugin *p) {
|
2005-07-06 11:58:19 +00:00
|
|
|
p->version = LIGHTTPD_VERSION_ID;
|
2019-10-19 04:30:54 +00:00
|
|
|
p->name = "cache";
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-07-06 16:36:46 +00:00
|
|
|
p->init = mod_cml_init;
|
|
|
|
p->cleanup = mod_cml_free;
|
|
|
|
p->set_defaults = mod_cml_set_defaults;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-07-06 16:36:46 +00:00
|
|
|
p->handle_subrequest_start = mod_cml_is_handled;
|
2005-12-29 12:16:10 +00:00
|
|
|
p->handle_physical = mod_cml_power_magnet;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-07-06 11:58:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|