Browse Source

use log_* functions for debugging and don't segfault on evaluation

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.3.x@428 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.3.15
Jan Kneschke 17 years ago
parent
commit
6d60bcb040
  1. 5
      src/mod_cml.c
  2. 4
      src/mod_cml.h
  3. 18
      src/mod_cml_funcs.c
  4. 39
      src/mod_cml_logic.c

5
src/mod_cml.c

@ -30,6 +30,7 @@ INIT_FUNC(mod_cml_init) {
p->eval = buffer_array_init();
p->trigger_if = buffer_array_init();
p->output_include = buffer_array_init();
p->params = tnode_val_array_init();
return p;
}
@ -54,6 +55,8 @@ FREE_FUNC(mod_cml_free) {
free(p->config_storage);
}
tnode_val_array_free(p->params);
buffer_array_free(p->eval);
buffer_array_free(p->trigger_if);
buffer_array_free(p->output_include);
@ -289,6 +292,8 @@ URIHANDLER_FUNC(mod_cml_is_handled) {
buffer_reset(p->session_id);
buffer_reset(p->trigger_handler);
tnode_val_array_reset(p->params);
if (buffer_is_empty(p->conf.ext)) return HANDLER_GO_ON;
ct_len = p->conf.ext->used - 1;

4
src/mod_cml.h

@ -78,6 +78,10 @@ int cache_parse(server *srv, connection *con, plugin_data *p, buffer *fn);
int tnode_prepare_long(tnode *t);
int tnode_prepare_string(tnode *t);
tnode_val_array *tnode_val_array_init();
void tnode_val_array_free(tnode_val_array *tva);
void tnode_val_array_reset(tnode_val_array *tva);
#define CACHE_FUNC_PROTO(x) int x(server *srv, connection *con, plugin_data *p, tnode *result)
CACHE_FUNC_PROTO(f_unix_time_now);

18
src/mod_cml_funcs.c

@ -33,8 +33,9 @@ CACHE_FUNC_PROTO(f_file_mtime) {
UNUSED(con);
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
fprintf(stderr, "%s.%d: f_file_mtime: I need a string: %d\n",
__FILE__, __LINE__, p->params->ptr[0]->type);
log_error_write(srv, __FILE__, __LINE__, "sd",
"f_file_mtime: I need a string:",
p->params->ptr[0]->type);
return -1;
}
@ -46,7 +47,8 @@ CACHE_FUNC_PROTO(f_file_mtime) {
buffer_append_string_buffer(b, p->params->ptr[0]->data.str);
if (-1 == stat(b->ptr, &st)) {
log_error_write(srv, __FILE__, __LINE__, "sbs", "trigger.if file.mtime():", b, strerror(errno));
log_error_write(srv, __FILE__, __LINE__, "sbs",
"trigger.if file.mtime():", b, strerror(errno));
buffer_free(b);
return -1;
@ -64,8 +66,9 @@ CACHE_FUNC_PROTO(f_mysql_escape) {
UNUSED(con);
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
fprintf(stderr, "%s.%d: f_mysql_escape: I need a string: %d\n",
__FILE__, __LINE__, p->params->ptr[0]->type);
log_error_write(srv, __FILE__, __LINE__, "sd",
"f_mysql_escape: I need a string:",
p->params->ptr[0]->type);
return -1;
}
@ -81,8 +84,9 @@ CACHE_FUNC_PROTO(f_mysql_query) {
UNUSED(con);
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
fprintf(stderr, "%s.%d: f_mysql_escape: I need a string: %d\n",
__FILE__, __LINE__, p->params->ptr[0]->type);
log_error_write(srv, __FILE__, __LINE__, "sd",
"f_mysql_query: I need a string:",
p->params->ptr[0]->type);
return -1;
}

39
src/mod_cml_logic.c

@ -92,6 +92,19 @@ void tnode_val_array_free(tnode_val_array *tva) {
free(tva);
}
void tnode_val_array_reset(tnode_val_array *tva) {
size_t i;
if (!tva) return;
for (i = 0; i < tva->used; i++) {
tnode_val_free(tva->ptr[i]);
}
tva->used = 0;
}
tnode *tnode_init() {
tnode *t;
@ -329,25 +342,25 @@ int cache_trigger_parse(server *srv, connection *con, plugin_data *p, buffer *t
/* parse parameters */
if (0 != cache_parse_parameters(srv, con, p, br_open + 1, t->used - slen - 3, p->params)) {
fprintf(stderr, "%s.%d: parsing parameters failed\n",
__FILE__, __LINE__
);
log_error_write(srv, __FILE__, __LINE__, "s",
"parsing parameters failed");
return -1;
}
if (p->params->used != f[i].params) {
fprintf(stderr, "%s.%d: wrong param-count for %s: %d, expected %d\n",
__FILE__, __LINE__,
f[i].name,
p->params->used,
f[i].params
);
log_error_write(srv, __FILE__, __LINE__, "sssdsd",
"wrong param-count for", f[i].name,
"got", p->params->used,
"expected", f[i].params);
return -1;
}
if (0 != f[i].func(srv, con, p, n)) {
fprintf(stderr, "%s.%d: function %s failed\n", __FILE__, __LINE__, f[i].name);
log_error_write(srv, __FILE__, __LINE__, "ss",
"calling function failed for",
f[i].name);
return -1;
}
@ -362,9 +375,9 @@ int cache_trigger_parse(server *srv, connection *con, plugin_data *p, buffer *t
if (*err != '\0') {
/* isn't a int */
fprintf(stderr, "%s.%d: can't evaluate: '%s', '%s'\n",
__FILE__, __LINE__,
t->ptr, err);
log_error_write(srv, __FILE__, __LINE__, "sss",
"can't evaluate:",
t->ptr, err);
return -1;
}

Loading…
Cancel
Save