[multiple] plugin_stats array

use global rather than passing around (server *) just for that

li_itostrn() and li_utostrn() return string length
(rather than requiring subsequent strlen() to find length)
personal/stbuehler/ci-build
Glenn Strauss 4 years ago
parent 50bdb55de8
commit f24e6d696a

@ -36,6 +36,10 @@ void array_free_data(array * const a) {
if (data[i]) data[i]->fn->free(data[i]);
}
free(data);
a->data = NULL;
a->sorted = NULL;
a->used = 0;
a->size = 0;
}
void array_copy_array(array * const dst, const array * const src) {

@ -356,21 +356,6 @@ struct server {
buffer *ts_date_str;
log_error_st *errh;
/**
* The status array can carry all the status information you want
* the key to the array is <module-prefix>.<name>
* and the values are counters
*
* example:
* fastcgi.backends = 10
* fastcgi.active-backends = 6
* fastcgi.backend.<key>.load = 24
* fastcgi.backend.<key>....
*
* fastcgi.backend.<key>.disconnects = ...
*/
array status;
server_config srvconf;
/* caches */

@ -306,30 +306,22 @@ void buffer_append_strftime(buffer *b, const char *format, const struct tm *tm)
}
void li_itostrn(char *buf, size_t buf_len, intmax_t val) {
size_t li_itostrn(char *buf, size_t buf_len, intmax_t val) {
char p_buf[LI_ITOSTRING_LENGTH];
char* const p_buf_end = p_buf + sizeof(p_buf);
char* str = p_buf_end - 1;
*str = '\0';
str = itostr(str, val);
force_assert(p_buf_end > str && str >= p_buf);
force_assert(buf_len >= (size_t) (p_buf_end - str));
memcpy(buf, str, p_buf_end - str);
char* const str = itostr(p_buf+sizeof(p_buf), val);
size_t len = (size_t)(p_buf+sizeof(p_buf)-str);
force_assert(len <= buf_len);
memcpy(buf, str, len);
return len;
}
void li_utostrn(char *buf, size_t buf_len, uintmax_t val) {
size_t li_utostrn(char *buf, size_t buf_len, uintmax_t val) {
char p_buf[LI_ITOSTRING_LENGTH];
char* const p_buf_end = p_buf + sizeof(p_buf);
char* str = p_buf_end - 1;
*str = '\0';
str = utostr(str, val);
force_assert(p_buf_end > str && str >= p_buf);
force_assert(buf_len >= (size_t) (p_buf_end - str));
memcpy(buf, str, p_buf_end - str);
char* const str = utostr(p_buf+sizeof(p_buf), val);
size_t len = (size_t)(p_buf+sizeof(p_buf)-str);
force_assert(len <= buf_len);
memcpy(buf, str, len);
return len;
}
#define li_ntox_lc(n) ((n) <= 9 ? (n) + '0' : (n) + 'a' - 10)

@ -97,8 +97,8 @@ void buffer_append_strftime(buffer *b, const char *format, const struct tm *tm);
/* '-', log_10 (2^bits) = bits * log 2 / log 10 < bits * 0.31, terminating 0 */
#define LI_ITOSTRING_LENGTH (2 + (8 * sizeof(intmax_t) * 31 + 99) / 100)
void li_itostrn(char *buf, size_t buf_len, intmax_t val);
void li_utostrn(char *buf, size_t buf_len, uintmax_t val);
size_t li_itostrn(char *buf, size_t buf_len, intmax_t val);
size_t li_utostrn(char *buf, size_t buf_len, uintmax_t val);
/* buf must be (at least) 2*s_len + 1 big. uses lower-case hex letters. */
#define li_tohex(buf,buf_len,s,s_len) li_tohex_lc((buf),(buf_len),(s),(s_len))

@ -33,50 +33,67 @@
#include "status_counter.h"
static int * gw_status_get_counter(server *srv, gw_host *host, gw_proc *proc, const char *tag, size_t len) {
buffer *b = srv->tmp_buf;
buffer_copy_string_len(b, CONST_STR_LEN("gw.backend."));
buffer_append_string_buffer(b, host->id);
__attribute_noinline__
static int * gw_status_get_counter(gw_host *host, gw_proc *proc, const char *tag, size_t tlen) {
/*(At the cost of some memory, could prepare strings for host and for proc
* so that here we would copy ready made string for proc (or if NULL,
* for host), and then append tag to produce key)*/
char label[288];
size_t llen = sizeof("gw.backend.")-1, len;
memcpy(label, "gw.backend.", llen);
len = buffer_string_length(host->id);
force_assert(len < sizeof(label) - llen);
memcpy(label+llen, host->id->ptr, len);
llen += len;
if (proc) {
buffer_append_string_len(b, CONST_STR_LEN("."));
buffer_append_int(b, proc->id);
force_assert(llen < sizeof(label) - (LI_ITOSTRING_LENGTH + 1));
label[llen++] = '.';
len = li_utostrn(label+llen, LI_ITOSTRING_LENGTH, proc->id);
llen += len;
}
buffer_append_string_len(b, tag, len);
return status_counter_get_counter(srv, CONST_BUF_LEN(b));
force_assert(tlen < sizeof(label) - llen);
memcpy(label+llen, tag, tlen);
llen += tlen;
label[llen] = '\0';
return status_counter_get_counter(label, llen);
}
static void gw_proc_tag_inc(server *srv, gw_host *host, gw_proc *proc, const char *tag, size_t len) {
++(*gw_status_get_counter(srv, host, proc, tag, len));
static void gw_proc_tag_inc(gw_host *host, gw_proc *proc, const char *tag, size_t len) {
++(*gw_status_get_counter(host, proc, tag, len));
}
static void gw_proc_load_inc(server *srv, gw_host *host, gw_proc *proc) {
*gw_status_get_counter(srv,host,proc,CONST_STR_LEN(".load")) = ++proc->load;
static void gw_proc_load_inc(gw_host *host, gw_proc *proc) {
*gw_status_get_counter(host, proc, CONST_STR_LEN(".load")) = ++proc->load;
status_counter_inc(srv, CONST_STR_LEN("gw.active-requests"));
status_counter_inc(CONST_STR_LEN("gw.active-requests"));
}
static void gw_proc_load_dec(server *srv, gw_host *host, gw_proc *proc) {
*gw_status_get_counter(srv,host,proc,CONST_STR_LEN(".load")) = --proc->load;
static void gw_proc_load_dec(gw_host *host, gw_proc *proc) {
*gw_status_get_counter(host, proc, CONST_STR_LEN(".load")) = --proc->load;
status_counter_dec(srv, CONST_STR_LEN("gw.active-requests"));
status_counter_dec(CONST_STR_LEN("gw.active-requests"));
}
static void gw_host_assign(server *srv, gw_host *host) {
*gw_status_get_counter(srv,host,NULL,CONST_STR_LEN(".load")) = ++host->load;
static void gw_host_assign(gw_host *host) {
*gw_status_get_counter(host, NULL, CONST_STR_LEN(".load")) = ++host->load;
}
static void gw_host_reset(server *srv, gw_host *host) {
*gw_status_get_counter(srv,host,NULL,CONST_STR_LEN(".load")) = --host->load;
static void gw_host_reset(gw_host *host) {
*gw_status_get_counter(host, NULL, CONST_STR_LEN(".load")) = --host->load;
}
static int gw_status_init(server *srv, gw_host *host, gw_proc *proc) {
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".disabled")) = 0;
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".died")) = 0;
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".overloaded")) = 0;
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".connected")) = 0;
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".load")) = 0;
static int gw_status_init(gw_host *host, gw_proc *proc) {
*gw_status_get_counter(host, proc, CONST_STR_LEN(".disabled")) = 0;
*gw_status_get_counter(host, proc, CONST_STR_LEN(".died")) = 0;
*gw_status_get_counter(host, proc, CONST_STR_LEN(".overloaded")) = 0;
*gw_status_get_counter(host, proc, CONST_STR_LEN(".connected")) = 0;
*gw_status_get_counter(host, proc, CONST_STR_LEN(".load")) = 0;
*gw_status_get_counter(srv, host, NULL, CONST_STR_LEN(".load")) = 0;
*gw_status_get_counter(host, NULL, CONST_STR_LEN(".load")) = 0;
return 0;
}
@ -195,7 +212,7 @@ static int gw_extension_insert(gw_exts *ext, const buffer *key, gw_host *fh) {
}
static void gw_proc_connect_success(server *srv, gw_host *host, gw_proc *proc, int debug) {
gw_proc_tag_inc(srv, host, proc, CONST_STR_LEN(".connected"));
gw_proc_tag_inc(host, proc, CONST_STR_LEN(".connected"));
proc->last_used = srv->cur_ts;
if (debug) {
@ -262,15 +279,15 @@ static void gw_proc_connect_error(server *srv, gw_host *host, gw_proc *proc, pid
}
if (EAGAIN == errnum) {
gw_proc_tag_inc(srv, host, proc, CONST_STR_LEN(".overloaded"));
gw_proc_tag_inc(host, proc, CONST_STR_LEN(".overloaded"));
}
else {
gw_proc_tag_inc(srv, host, proc, CONST_STR_LEN(".died"));
gw_proc_tag_inc(host, proc, CONST_STR_LEN(".died"));
}
}
static void gw_proc_release(server *srv, gw_host *host, gw_proc *proc, int debug) {
gw_proc_load_dec(srv, host, proc);
gw_proc_load_dec(host, proc);
if (debug) {
log_error(srv->errh, __FILE__, __LINE__,
@ -1617,7 +1634,7 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p
goto error;
}
gw_status_init(srv, host, proc);
gw_status_init(host, proc);
proc->next = host->first;
if (host->first) host->first->prev = proc;
@ -1638,7 +1655,7 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p
buffer_copy_buffer(proc->unixsocket, host->unixsocket);
}
gw_status_init(srv, host, proc);
gw_status_init(host, proc);
host->first = proc;
@ -1735,7 +1752,7 @@ static void gw_backend_close(server *srv, gw_handler_ctx *hctx) {
hctx->proc = NULL;
}
gw_host_reset(srv, hctx->host);
gw_host_reset(hctx->host);
hctx->host = NULL;
}
}
@ -1760,7 +1777,7 @@ static handler_t gw_reconnect(server *srv, gw_handler_ctx *hctx) {
hctx->conf.balance, hctx->conf.debug);
if (NULL == hctx->host) return HANDLER_FINISHED;
gw_host_assign(srv, hctx->host);
gw_host_assign(hctx->host);
hctx->request_id = 0;
hctx->opts.xsendfile_allow = hctx->host->xsendfile_allow;
hctx->opts.xsendfile_docroot = hctx->host->xsendfile_docroot;
@ -1819,7 +1836,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
if (proc->load < hctx->proc->load) hctx->proc = proc;
}
gw_proc_load_inc(srv, hctx->host, hctx->proc);
gw_proc_load_inc(hctx->host, hctx->proc);
hctx->fd = fdevent_socket_nb_cloexec(hctx->host->family,SOCK_STREAM,0);
if (-1 == hctx->fd) {
@ -1972,6 +1989,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
}
}
__attribute_cold__
static handler_t gw_write_error(server *srv, gw_handler_ctx *hctx) {
connection *con = hctx->remote_conn;
int status = con->http_status;
@ -2474,7 +2492,7 @@ handler_t gw_check_extension(connection *con, gw_plugin_data *p, int uri_path_ha
hctx->host = host;
hctx->proc = NULL;
hctx->ext = extension;
gw_host_assign(con->srv, host);
gw_host_assign(host);
hctx->gw_mode = gw_mode;
if (gw_mode == GW_AUTHORIZER) {

@ -1344,8 +1344,8 @@ int http_cgi_headers (connection *con, http_cgi_opts *opts, http_cgi_header_appe
/* (CONTENT_LENGTH must be first for SCGI) */
if (!opts->authorizer) {
li_itostrn(buf, sizeof(buf), con->request.content_length);
rc |= cb(vdata, CONST_STR_LEN("CONTENT_LENGTH"), buf, strlen(buf));
rc |= cb(vdata, CONST_STR_LEN("CONTENT_LENGTH"),
buf, li_itostrn(buf,sizeof(buf),con->request.content_length));
}
if (!buffer_string_is_empty(con->uri.query)) {
@ -1474,8 +1474,8 @@ int http_cgi_headers (connection *con, http_cgi_opts *opts, http_cgi_header_appe
}
addr = &srv_sock->addr;
li_utostrn(buf, sizeof(buf), sock_addr_get_port(addr));
rc |= cb(vdata, CONST_STR_LEN("SERVER_PORT"), buf, strlen(buf));
rc |= cb(vdata, CONST_STR_LEN("SERVER_PORT"),
buf, li_utostrn(buf,sizeof(buf),sock_addr_get_port(addr)));
switch (addr->plain.sa_family) {
case AF_INET:
@ -1520,8 +1520,8 @@ int http_cgi_headers (connection *con, http_cgi_opts *opts, http_cgi_header_appe
rc |= cb(vdata, CONST_STR_LEN("REMOTE_ADDR"),
CONST_BUF_LEN(con->dst_addr_buf));
li_utostrn(buf, sizeof(buf), sock_addr_get_port(&con->dst_addr));
rc |= cb(vdata, CONST_STR_LEN("REMOTE_PORT"), buf, strlen(buf));
rc |= cb(vdata, CONST_STR_LEN("REMOTE_PORT"), buf,
li_utostrn(buf,sizeof(buf),sock_addr_get_port(&con->dst_addr)));
for (n = 0; n < con->request.headers.used; n++) {
data_string *ds = (data_string *)con->request.headers.data[n];

@ -670,14 +670,15 @@ static void mod_auth_digest_mutate_sha256(http_auth_info_t *ai, const char *m, c
static void mod_auth_digest_nonce_sha256(buffer *b, time_t cur_ts, int rnd) {
SHA256_CTX ctx;
size_t len;
unsigned char h[HTTP_AUTH_DIGEST_SHA256_BINLEN];
char hh[HTTP_AUTH_DIGEST_SHA256_BINLEN*2+1];
force_assert(sizeof(hh) >= LI_ITOSTRING_LENGTH);
SHA256_Init(&ctx);
li_itostrn(hh, sizeof(hh), cur_ts);
SHA256_Update(&ctx, (unsigned char *)hh, strlen(hh));
li_itostrn(hh, sizeof(hh), rnd);
SHA256_Update(&ctx, (unsigned char *)hh, strlen(hh));
len = li_itostrn(hh, sizeof(hh), cur_ts);
SHA256_Update(&ctx, (unsigned char *)hh, len);
len = li_itostrn(hh, sizeof(hh), rnd);
SHA256_Update(&ctx, (unsigned char *)hh, len);
SHA256_Final(h, &ctx);
li_tohex(hh, sizeof(hh), (const char *)h, sizeof(h));
buffer_append_string_len(b, hh, sizeof(hh)-1);
@ -738,14 +739,15 @@ static void mod_auth_digest_mutate_sha512_256(http_auth_info_t *ai, const char *
static void mod_auth_digest_nonce_sha512_256(buffer *b, time_t cur_ts, int rnd) {
SHA512_CTX ctx;
size_t len;
unsigned char h[HTTP_AUTH_DIGEST_SHA512_256_BINLEN];
char hh[HTTP_AUTH_DIGEST_SHA512_256_BINLEN*2+1];
force_assert(sizeof(hh) >= LI_ITOSTRING_LENGTH);
SHA512_256_Init(&ctx);
li_itostrn(hh, sizeof(hh), cur_ts);
SHA512_256_Update(&ctx, (unsigned char *)hh, strlen(hh));
li_itostrn(hh, sizeof(hh), rnd);
SHA512_256_Update(&ctx, (unsigned char *)hh, strlen(hh));
len = li_itostrn(hh, sizeof(hh), cur_ts);
SHA512_256_Update(&ctx, (unsigned char *)hh, len);
len = li_itostrn(hh, sizeof(hh), rnd);
SHA512_256_Update(&ctx, (unsigned char *)hh, len);
SHA512_256_Final(h, &ctx);
li_tohex(hh, sizeof(hh), (const char *)h, sizeof(h));
buffer_append_string_len(b, hh, sizeof(hh)-1);
@ -810,14 +812,15 @@ static void mod_auth_digest_mutate_md5(http_auth_info_t *ai, const char *m, cons
static void mod_auth_digest_nonce_md5(buffer *b, time_t cur_ts, int rnd) {
li_MD5_CTX ctx;
size_t len;
unsigned char h[HTTP_AUTH_DIGEST_MD5_BINLEN];
char hh[HTTP_AUTH_DIGEST_MD5_BINLEN*2+1];
force_assert(sizeof(hh) >= LI_ITOSTRING_LENGTH);
li_MD5_Init(&ctx);
li_itostrn(hh, sizeof(hh), cur_ts);
li_MD5_Update(&ctx, (unsigned char *)hh, strlen(hh));
li_itostrn(hh, sizeof(hh), rnd);
li_MD5_Update(&ctx, (unsigned char *)hh, strlen(hh));
len = li_itostrn(hh, sizeof(hh), cur_ts);
li_MD5_Update(&ctx, (unsigned char *)hh, len);
len = li_itostrn(hh, sizeof(hh), rnd);
li_MD5_Update(&ctx, (unsigned char *)hh, len);
li_MD5_Final(h, &ctx);
li_tohex(hh, sizeof(hh), (const char *)h, sizeof(h));
buffer_append_string_len(b, hh, sizeof(hh)-1);

@ -481,8 +481,8 @@ static void mod_compress_note_ratio(connection *con, off_t in, off_t out) {
/*(should be called only at end of successful response compression)*/
char ratio[LI_ITOSTRING_LENGTH];
if (0 == in) return;
li_itostrn(ratio, sizeof(ratio), out * 100 / in);
http_header_env_set(con, CONST_STR_LEN("ratio"), ratio, strlen(ratio));
http_header_env_set(con, CONST_STR_LEN("ratio"),
ratio, li_itostrn(ratio,sizeof(ratio),out*100/in));
}
static int deflate_file_to_file(connection *con, plugin_data *p, int ifd, buffer *fn, stat_cache_entry *sce, int type) {

@ -724,8 +724,9 @@ static void mod_deflate_note_ratio(connection *con, handler_ctx *hctx) {
/*(should be called only at end of successful response compression)*/
char ratio[LI_ITOSTRING_LENGTH];
if (0 == hctx->bytes_in) return;
li_itostrn(ratio, sizeof(ratio), hctx->bytes_out * 100 / hctx->bytes_in);
http_header_env_set(con, CONST_STR_LEN("ratio"), ratio, strlen(ratio));
size_t len =
li_itostrn(ratio, sizeof(ratio), hctx->bytes_out * 100 / hctx->bytes_in);
http_header_env_set(con, CONST_STR_LEN("ratio"), ratio, len);
}
static int mod_deflate_stream_end(handler_ctx *hctx) {

@ -425,8 +425,7 @@ static int http_list_directory_sizefmt(char *buf, size_t bufsz, off_t size) {
u++;
}
li_itostrn(buf, bufsz, size);
buflen = strlen(buf);
buflen = li_itostrn(buf, bufsz, size);
if (buflen + 3 >= bufsz) return buflen;
buf[buflen+0] = '.';
buf[buflen+1] = remain + '0';

@ -333,7 +333,7 @@ static handler_t fcgi_create_env(handler_ctx *hctx) {
}
fcgi_stdin_append(hctx);
status_counter_inc(con->srv, CONST_STR_LEN("fastcgi.requests"));
status_counter_inc(CONST_STR_LEN("fastcgi.requests"));
return HANDLER_GO_ON;
}

@ -251,14 +251,14 @@ static handler_t mod_geoip_query (connection *con, plugin_data *p) {
{
char dc[LI_ITOSTRING_LENGTH];
li_utostrn(dc, sizeof(dc), gir->dma_code);
http_header_env_set(con, CONST_STR_LEN("GEOIP_CITY_DMA_CODE"), dc, strlen(dc));
http_header_env_set(con, CONST_STR_LEN("GEOIP_CITY_DMA_CODE"),
dc, li_utostrn(dc, sizeof(dc), gir->dma_code));
}
{
char ac[LI_ITOSTRING_LENGTH];
li_utostrn(ac, sizeof(ac), gir->area_code);
http_header_env_set(con, CONST_STR_LEN("GEOIP_CITY_AREA_CODE"), ac, strlen(ac));
http_header_env_set(con, CONST_STR_LEN("GEOIP_CITY_AREA_CODE"),
ac, li_utostrn(ac, sizeof(ac), gir->area_code));
}
GeoIPRecord_delete(gir);

@ -21,7 +21,6 @@
#include <lua.h>
#include <lauxlib.h>
#define LUA_RIDX_LIGHTTPD_SERVER "lighty.srv"
#define LUA_RIDX_LIGHTTPD_CONNECTION "lighty.con"
#define MAGNET_RESTART_REQUEST 99
@ -253,16 +252,6 @@ static int magnet_array_pairs(lua_State *L, array *a) {
return 1;
}
static server* magnet_get_server(lua_State *L) {
server *srv;
lua_getfield(L, LUA_REGISTRYINDEX, LUA_RIDX_LIGHTTPD_SERVER);
srv = lua_touserdata(L, -1);
lua_pop(L, 1);
return srv;
}
static connection* magnet_get_connection(lua_State *L) {
connection *con;
@ -406,33 +395,26 @@ static int magnet_reqhdr_pairs(lua_State *L) {
}
static int magnet_status_get(lua_State *L) {
int *i;
server *srv = magnet_get_server(L);
/* __index: param 1 is the (empty) table the value was not found in */
const_buffer key = magnet_checkconstbuffer(L, 2);
i = status_counter_get_counter(srv, key.ptr, key.len);
int *i = status_counter_get_counter(key.ptr, key.len);
lua_pushinteger(L, (lua_Integer)*i);
return 1;
}
static int magnet_status_set(lua_State *L) {
server *srv = magnet_get_server(L);
/* __newindex: param 1 is the (empty) table the value is supposed to be set in */
const_buffer key = magnet_checkconstbuffer(L, 2);
int counter = (int) luaL_checkinteger(L, 3);
status_counter_set(srv, key.ptr, key.len, counter);
status_counter_set(key.ptr, key.len, counter);
return 0;
}
static int magnet_status_pairs(lua_State *L) {
server *srv = magnet_get_server(L);
return magnet_array_pairs(L, &srv->status);
return magnet_array_pairs(L, &plugin_stats);
}
typedef struct {
@ -811,9 +793,6 @@ static handler_t magnet_attract(connection *con, plugin_data *p, buffer *name) {
force_assert(lua_gettop(L) == 1);
force_assert(lua_isfunction(L, func_ndx));
lua_pushlightuserdata(L, con->srv);
lua_setfield(L, LUA_REGISTRYINDEX, LUA_RIDX_LIGHTTPD_SERVER);
lua_pushlightuserdata(L, con);
lua_setfield(L, LUA_REGISTRYINDEX, LUA_RIDX_LIGHTTPD_CONNECTION);

@ -337,39 +337,39 @@ geoip2_env_set (array * const env, const char * const k,
* However, note that the strings *are not* '\0'-terminated */
char buf[35];
if (!data->has_data || 0 == data->offset) return;
const char *v = buf;
size_t vlen;
switch (data->type) {
case MMDB_DATA_TYPE_UTF8_STRING:
array_set_key_value(env, k, klen, data->utf8_string, data->data_size);
return;
v = data->utf8_string;
vlen = data->data_size;
break;
case MMDB_DATA_TYPE_BOOLEAN:
array_set_key_value(env, k, klen, data->boolean ? "1" : "0", 1);
return;
v = data->boolean ? "1" : "0";
vlen = 1;
break;
case MMDB_DATA_TYPE_BYTES:
array_set_key_value(env, k, klen,
(const char *) data->bytes, data->data_size);
return;
v = (const char *)data->bytes;
vlen = data->data_size;
break;
case MMDB_DATA_TYPE_DOUBLE:
array_set_key_value(env, k, klen,
buf, snprintf(buf, sizeof(buf), "%.5f",
data->double_value));
return;
vlen = snprintf(buf, sizeof(buf), "%.5f", data->double_value);
break;
case MMDB_DATA_TYPE_FLOAT:
array_set_key_value(env, k, klen,
buf, snprintf(buf, sizeof(buf), "%.5f",
data->float_value));
return;
vlen = snprintf(buf, sizeof(buf), "%.5f", data->float_value);
break;
case MMDB_DATA_TYPE_INT32:
li_itostrn(buf, sizeof(buf), data->int32);
vlen = li_itostrn(buf, sizeof(buf), data->int32);
break;
case MMDB_DATA_TYPE_UINT32:
li_utostrn(buf, sizeof(buf), data->uint32);
vlen = li_utostrn(buf, sizeof(buf), data->uint32);
break;
case MMDB_DATA_TYPE_UINT16:
li_utostrn(buf, sizeof(buf), data->uint16);
vlen = li_utostrn(buf, sizeof(buf), data->uint16);
break;
case MMDB_DATA_TYPE_UINT64:
/* truncated value on 32-bit unless uintmax_t is 64-bit (long long) */
li_utostrn(buf, sizeof(buf), data->uint64);
vlen = li_utostrn(buf, sizeof(buf), data->uint64);
break;
case MMDB_DATA_TYPE_UINT128:
buf[0] = '0';
@ -379,13 +379,13 @@ geoip2_env_set (array * const env, const char * const k,
#else
li_tohex_uc(buf+2, sizeof(buf)-2, (char *)&data->uint128, 16);
#endif
array_set_key_value(env, k, klen, buf, 34);
return;
vlen = 34;
break;
default: /*(ignore unknown data type)*/
return;
}
array_set_key_value(env, k, klen, buf, strlen(buf)); /*(numerical types)*/
array_set_key_value(env, k, klen, v, vlen);
}

@ -2330,26 +2330,18 @@ http_cgi_ssl_env (server *srv, connection *con, handler_ctx *hctx)
UNUSED(srv);
s = SSL_get_version(hctx->ssl);
http_header_env_set(con,
CONST_STR_LEN("SSL_PROTOCOL"),
s, strlen(s));
http_header_env_set(con, CONST_STR_LEN("SSL_PROTOCOL"), s, strlen(s));
if ((cipher = SSL_get_current_cipher(hctx->ssl))) {
int usekeysize, algkeysize;
char buf[LI_ITOSTRING_LENGTH];
s = SSL_CIPHER_get_name(cipher);
http_header_env_set(con,
CONST_STR_LEN("SSL_CIPHER"),
s, strlen(s));
http_header_env_set(con, CONST_STR_LEN("SSL_CIPHER"), s, strlen(s));
usekeysize = SSL_CIPHER_get_bits(cipher, &algkeysize);
li_itostrn(buf, sizeof(buf), usekeysize);
http_header_env_set(con,
CONST_STR_LEN("SSL_CIPHER_USEKEYSIZE"),
buf, strlen(buf));
li_itostrn(buf, sizeof(buf), algkeysize);
http_header_env_set(con,
CONST_STR_LEN("SSL_CIPHER_ALGKEYSIZE"),
buf, strlen(buf));
http_header_env_set(con, CONST_STR_LEN("SSL_CIPHER_USEKEYSIZE"),
buf, li_itostrn(buf, sizeof(buf), usekeysize));
http_header_env_set(con, CONST_STR_LEN("SSL_CIPHER_ALGKEYSIZE"),
buf, li_itostrn(buf, sizeof(buf), algkeysize));
}
}

@ -888,8 +888,8 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) {
const buffer *vb = http_header_request_get(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"));
if (NULL == vb) {
char buf[LI_ITOSTRING_LENGTH];
li_itostrn(buf, sizeof(buf), con->request.content_length);
http_header_request_set(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"), buf, strlen(buf));
http_header_request_set(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"),
buf, li_itostrn(buf, sizeof(buf), con->request.content_length));
}
}
@ -979,7 +979,7 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) {
hctx->gw.wb_reqlen = -hctx->gw.wb_reqlen;
}
status_counter_inc(con->srv, CONST_STR_LEN("proxy.requests"));
status_counter_inc(CONST_STR_LEN("proxy.requests"));
return HANDLER_GO_ON;
}
@ -992,7 +992,7 @@ static handler_t proxy_create_env_connect(gw_handler_ctx *gwhctx) {
gw_set_transparent(&hctx->gw);
http_response_upgrade_read_body_unknown(con);
status_counter_inc(con->srv, CONST_STR_LEN("proxy.requests"));
status_counter_inc(CONST_STR_LEN("proxy.requests"));
return HANDLER_GO_ON;
}

@ -282,7 +282,7 @@ static handler_t scgi_create_env(handler_ctx *hctx) {
hctx->wb_reqlen = -hctx->wb_reqlen;
}
status_counter_inc(con->srv, CONST_STR_LEN("scgi.requests"));
status_counter_inc(CONST_STR_LEN("scgi.requests"));
return HANDLER_GO_ON;
}

@ -130,7 +130,7 @@ static handler_t sockproxy_create_env_connect(handler_ctx *hctx) {
gw_set_transparent(hctx);
http_response_upgrade_read_body_unknown(con);
status_counter_inc(con->srv, CONST_STR_LEN("sockproxy.requests"));
status_counter_inc(CONST_STR_LEN("sockproxy.requests"));
return HANDLER_GO_ON;
}

@ -713,7 +713,7 @@ static handler_t mod_status_handle_server_status_json(server *srv, connection *c
static handler_t mod_status_handle_server_statistics(connection *con) {
buffer *b;
size_t i;
array *st = &con->srv->status;
array *st = &plugin_stats;
if (0 == st->used) {
/* we have nothing to send */

@ -150,6 +150,7 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
__attribute_noinline__
static handler_t mod_usertrack_set_cookie(connection *con, plugin_data *p) {
buffer *cookie;
size_t len;
unsigned char h[16];
li_MD5_CTX Md5Ctx;
char hh[LI_ITOSTRING_LENGTH];
@ -167,10 +168,10 @@ static handler_t mod_usertrack_set_cookie(connection *con, plugin_data *p) {
li_MD5_Update(&Md5Ctx, CONST_BUF_LEN(con->uri.path));
li_MD5_Update(&Md5Ctx, CONST_STR_LEN("+"));
li_itostrn(hh, sizeof(hh), con->srv->cur_ts);
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh));
li_itostrn(hh, sizeof(hh), li_rand_pseudo());
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh));
len = li_itostrn(hh, sizeof(hh), con->srv->cur_ts);
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, len);
len = li_itostrn(hh, sizeof(hh), li_rand_pseudo());
li_MD5_Update(&Md5Ctx, (unsigned char *)hh, len);
li_MD5_Final(h, &Md5Ctx);

@ -897,9 +897,9 @@ webdav_xml_doc_lock_acquired (connection * const con,
/*(http_status is set by caller to 200 OK or 201 Created)*/
char tbuf[32] = "Second-";
li_itostrn(tbuf+sizeof("Second-")-1, sizeof(tbuf)-(sizeof("Second-")-1),
lockdata->timeout);
const uint32_t tbuf_len = strlen(tbuf);
const uint32_t tbuf_len =
li_itostrn(tbuf+sizeof("Second-")-1, sizeof(tbuf)-(sizeof("Second-")-1),
lockdata->timeout);
http_header_response_set(con, HTTP_HEADER_OTHER,
CONST_STR_LEN("Timeout"),
tbuf, tbuf_len);
@ -4318,8 +4318,10 @@ mod_webdav_put_linkat_rename (connection * const con,
chunk *c = cq->first;
char pathproc[32] = "/proc/self/fd/";
li_itostrn(pathproc+sizeof("/proc/self/fd/")-1,
sizeof(pathproc)-(sizeof("/proc/self/fd/")-1), (long)c->file.fd);
size_t plen =
li_itostrn(pathproc+sizeof("/proc/self/fd/")-1,
sizeof(pathproc)-(sizeof("/proc/self/fd/")-1), c->file.fd);
pathproc[plen] = '\0';
if (0 == linkat(AT_FDCWD, pathproc, AT_FDCWD, pathtemp, AT_SYMLINK_FOLLOW)){
struct stat st;
#ifdef RENAME_NOREPLACE /*(renameat2() not well-supported yet)*/

@ -2,11 +2,14 @@
#include "plugin.h"
#include "base.h"
#include "array.h"
#include "log.h"
#include <string.h>
#include <stdlib.h>
array plugin_stats; /* global */
#ifdef HAVE_VALGRIND_VALGRIND_H
# include <valgrind/valgrind.h>
#endif
@ -557,4 +560,5 @@ void plugins_free(server *srv) {
srv->plugins.ptr = NULL;
srv->plugins.used = 0;
srv->plugins.size = 0;
array_free_data(&plugin_stats);
}

@ -7,6 +7,23 @@
#include "array.h"
#include "plugin_config.h"
/**
* The status array can carry all the status information you want
* the key to the array is <module-prefix>.<name>
* and the values are counters
*
* example:
* fastcgi.backends = 10
* fastcgi.active-backends = 6
* fastcgi.backend.<key>.load = 24
* fastcgi.backend.<key>....
*
* fastcgi.backend.<key>.disconnects = ...
*/
extern array plugin_stats;
#define SERVER_FUNC(x) \
static handler_t x(server *srv, void *p_d)

@ -285,8 +285,6 @@ static void server_free(server *srv) {
config_free(srv);
array_free_data(&srv->status);
free(srv->joblist.ptr);
free(srv->fdwaitqueue.ptr);

@ -5,38 +5,37 @@
#include "base_decls.h"
static inline
int *status_counter_get_counter(server *srv, const char *s, size_t len);
int *status_counter_get_counter(const char *s, size_t len);
static inline
void status_counter_inc(server *srv, const char *s, size_t len);
void status_counter_inc(const char *s, size_t len);
static inline
void status_counter_dec(server *srv, const char *s, size_t len);
void status_counter_dec(const char *s, size_t len);
static inline
void status_counter_set(server *srv, const char *s, size_t len, int val);
void status_counter_set(const char *s, size_t len, int val);
/* inline status counter routines */
#include "base.h" /* (srv->status) */
#include "array.h"
#include "plugin.h"
__attribute_returns_nonnull__
static inline
int *status_counter_get_counter(server *srv, const char *s, size_t len) {
return array_get_int_ptr(&srv->status, s, len);
int *status_counter_get_counter(const char *s, size_t len) {
return array_get_int_ptr(&plugin_stats, s, len);
}
static inline
void status_counter_inc(server *srv, const char *s, size_t len) {
++(*array_get_int_ptr(&srv->status, s, len));
void status_counter_inc(const char *s, size_t len) {
++(*array_get_int_ptr(&plugin_stats, s, len));
}
static inline
void status_counter_dec(server *srv, const char *s, size_t len) {
--(*array_get_int_ptr(&srv->status, s, len));
void status_counter_dec(const char *s, size_t len) {
--(*array_get_int_ptr(&plugin_stats, s, len));
}
static inline
void status_counter_set(server *srv, const char *s, size_t len, int val) {
*array_get_int_ptr(&srv->status, s, len) = val;
void status_counter_set(const char *s, size_t len, int val) {
*array_get_int_ptr(&plugin_stats, s, len) = val;
}

Loading…
Cancel
Save