|
|
|
@ -15,6 +15,23 @@
|
|
|
|
|
|
|
|
|
|
#include "mod_cml.h"
|
|
|
|
|
|
|
|
|
|
#ifdef USE_OPENSSL
|
|
|
|
|
# include <openssl/md5.h>
|
|
|
|
|
#else
|
|
|
|
|
# include "md5_global.h"
|
|
|
|
|
# include "md5.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define HASHLEN 16
|
|
|
|
|
typedef unsigned char HASH[HASHLEN];
|
|
|
|
|
#define HASHHEXLEN 32
|
|
|
|
|
typedef char HASHHEX[HASHHEXLEN+1];
|
|
|
|
|
#ifdef USE_OPENSSL
|
|
|
|
|
#define IN const
|
|
|
|
|
#else
|
|
|
|
|
#define IN
|
|
|
|
|
#endif
|
|
|
|
|
#define OUT
|
|
|
|
|
|
|
|
|
|
CACHE_FUNC_PROTO(f_unix_time_now) {
|
|
|
|
|
UNUSED(srv);
|
|
|
|
@ -61,12 +78,124 @@ CACHE_FUNC_PROTO(f_file_mtime) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int split_query_string(server *srv, connection *con, array *vals) {
|
|
|
|
|
size_t key_start = 0, key_end = 0,
|
|
|
|
|
value_start = 0;
|
|
|
|
|
size_t is_key = 1;
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < con->uri.query->used; i++) {
|
|
|
|
|
switch(con->uri.query->ptr[i]) {
|
|
|
|
|
case '=':
|
|
|
|
|
if (is_key) {
|
|
|
|
|
key_end = i - 1;
|
|
|
|
|
value_start = i + 1;
|
|
|
|
|
|
|
|
|
|
is_key = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case '&':
|
|
|
|
|
case '\0': /* fin symbol */
|
|
|
|
|
if (!is_key) {
|
|
|
|
|
data_string *ds;
|
|
|
|
|
|
|
|
|
|
/* we need at least a = since the last & */
|
|
|
|
|
|
|
|
|
|
if (NULL == (ds = (data_string *)array_get_unused_element(vals, TYPE_STRING))) {
|
|
|
|
|
ds = data_string_init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer_copy_string_len(ds->key, con->uri.query->ptr + key_start, key_end - key_start);
|
|
|
|
|
buffer_copy_string_len(ds->value, con->uri.query->ptr + value_start, i - value_start);
|
|
|
|
|
|
|
|
|
|
array_insert_unique(vals, (data_unset *)ds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
key_start = i + 1;
|
|
|
|
|
value_start = 0;
|
|
|
|
|
is_key = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CACHE_FUNC_PROTO(f_http_request_get_param) {
|
|
|
|
|
array *qry_str;
|
|
|
|
|
data_string *ds;
|
|
|
|
|
|
|
|
|
|
/* fetch data from the con-> request query string */
|
|
|
|
|
|
|
|
|
|
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sd",
|
|
|
|
|
"f_http_request_get_param: I need a string:",
|
|
|
|
|
p->params->ptr[0]->type);
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qry_str = array_init();
|
|
|
|
|
|
|
|
|
|
split_query_string(srv, con, qry_str);
|
|
|
|
|
|
|
|
|
|
tnode_prepare_string(result);
|
|
|
|
|
|
|
|
|
|
if (NULL == (ds = (data_string *)array_get_element(qry_str, p->params->ptr[0]->data.str->ptr))) {
|
|
|
|
|
|
|
|
|
|
buffer_copy_string(VAL_STRING(result), "");
|
|
|
|
|
|
|
|
|
|
array_free(qry_str);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer_copy_string_buffer(VAL_STRING(result), ds->value);
|
|
|
|
|
|
|
|
|
|
array_free(qry_str);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CACHE_FUNC_PROTO(f_crypto_md5) {
|
|
|
|
|
MD5_CTX Md5Ctx;
|
|
|
|
|
HASH HA1;
|
|
|
|
|
|
|
|
|
|
/* fetch data from the con-> request query string */
|
|
|
|
|
|
|
|
|
|
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sd",
|
|
|
|
|
"f_http_request_get_param: I need a string:",
|
|
|
|
|
p->params->ptr[0]->type);
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MD5_Init(&Md5Ctx);
|
|
|
|
|
MD5_Update(&Md5Ctx, (unsigned char *)p->params->ptr[0]->data.str->ptr, p->params->ptr[0]->data.str->used - 1);
|
|
|
|
|
MD5_Final(HA1, &Md5Ctx);
|
|
|
|
|
|
|
|
|
|
tnode_prepare_string(result);
|
|
|
|
|
buffer_copy_string_hex(VAL_STRING(result), (char *)HA1, 16);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_MEMCACHE_H
|
|
|
|
|
CACHE_FUNC_PROTO(f_memcache_exists) {
|
|
|
|
|
char *r;
|
|
|
|
|
|
|
|
|
|
UNUSED(con);
|
|
|
|
|
|
|
|
|
|
if (!p->conf.mc) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sd",
|
|
|
|
|
"f_memcache_exists: no memcache.hosts set:",
|
|
|
|
|
p->params->ptr[0]->type);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sd",
|
|
|
|
|
"f_memcache_exists: I need a string:",
|
|
|
|
@ -96,21 +225,24 @@ CACHE_FUNC_PROTO(f_memcache_get_string) {
|
|
|
|
|
|
|
|
|
|
UNUSED(con);
|
|
|
|
|
|
|
|
|
|
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
|
|
|
|
|
if (!p->conf.mc) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sd",
|
|
|
|
|
"f_memcache_get: I need a string:",
|
|
|
|
|
"f_memcache_get_string: no memcache.hosts set:",
|
|
|
|
|
p->params->ptr[0]->type);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sb",
|
|
|
|
|
"f_memcache_get: couldn't find:",
|
|
|
|
|
p->params->ptr[0]->data.str);
|
|
|
|
|
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sd",
|
|
|
|
|
"f_memcache_get_string: I need a string:",
|
|
|
|
|
p->params->ptr[0]->type);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NULL == (r = mc_aget(p->conf.mc,
|
|
|
|
|
p->params->ptr[0]->data.str->ptr, p->params->ptr[0]->data.str->used - 1))) {
|
|
|
|
|
p->params->ptr[0]->data.str->ptr, p->params->ptr[0]->data.str->used - 1))) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sb",
|
|
|
|
|
"f_memcache_get: couldn't find:",
|
|
|
|
|
"f_memcache_get_string: couldn't find:",
|
|
|
|
|
p->params->ptr[0]->data.str);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
@ -127,19 +259,24 @@ CACHE_FUNC_PROTO(f_memcache_get_long) {
|
|
|
|
|
|
|
|
|
|
UNUSED(con);
|
|
|
|
|
|
|
|
|
|
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
|
|
|
|
|
if (!p->conf.mc) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sd",
|
|
|
|
|
"f_memcache_get: I need a string:",
|
|
|
|
|
"f_memcache_get_long: no memcache.hosts set:",
|
|
|
|
|
p->params->ptr[0]->type);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (p->params->ptr[0]->type != T_NODE_VALUE_STRING) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sd",
|
|
|
|
|
"f_memcache_get_long: I need a string:",
|
|
|
|
|
p->params->ptr[0]->type);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NULL == (r = mc_aget(p->conf.mc,
|
|
|
|
|
CONST_BUF_LEN(p->params->ptr[0]->data.str)))) {
|
|
|
|
|
log_error_write(srv, __FILE__, __LINE__, "sb",
|
|
|
|
|
"f_memcache_get: couldn't find:",
|
|
|
|
|
"f_memcache_get_long: couldn't find:",
|
|
|
|
|
p->params->ptr[0]->data.str);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|