Browse Source

[multiple] use buffer_append_* aggregates

reduces the number of round-trips into some frequently-called routines
master
Glenn Strauss 9 months ago
parent
commit
dc01487ea6
  1. 40
      src/configparser.y
  2. 13
      src/connections.c
  3. 9
      src/data_string.c
  4. 25
      src/gw_backend.c
  5. 17
      src/h2.c
  6. 11
      src/http-header-glue.c
  7. 14
      src/http_header.c
  8. 4
      src/http_range.c
  9. 6
      src/mod_ajp13.c
  10. 27
      src/mod_auth.c
  11. 35
      src/mod_authn_mysql.c
  12. 9
      src/mod_deflate.c
  13. 92
      src/mod_dirlisting.c
  14. 11
      src/mod_fastcgi.c
  15. 10
      src/mod_nss.c
  16. 20
      src/mod_proxy.c
  17. 15
      src/mod_rrdtool.c
  18. 4
      src/mod_secdownload.c
  19. 1
      src/mod_simple_vhost.c
  20. 15
      src/mod_ssi.c
  21. 388
      src/mod_status.c
  22. 4
      src/mod_trigger_b4_dl.c
  23. 9
      src/mod_usertrack.c
  24. 3
      src/mod_vhostdb_dbi.c
  25. 225
      src/mod_webdav.c
  26. 10
      src/plugin.c
  27. 8
      src/request.c
  28. 14
      src/response.c
  29. 3
      src/sock_addr.c

40
src/configparser.y

@ -132,9 +132,9 @@ static int configparser_remoteip_normalize_compat(buffer *rvalue) {
int rc;
if (rvalue->ptr[0] != '[') {
buffer_append_string_len(b, CONST_STR_LEN("["));
buffer_append_string_buffer(b, rvalue);
buffer_append_string_len(b, CONST_STR_LEN("]"));
buffer_append_str3(b, CONST_STR_LEN("["),
CONST_BUF_LEN(rvalue),
CONST_STR_LEN("]"));
} else {
buffer_append_string_buffer(b, rvalue);
}
@ -207,19 +207,23 @@ configparser_parse_condition(config_t * const ctx, const buffer * const obj_tag,
return; /* unreachable */
}
const uint32_t comp_offset = buffer_string_length(&ctx->current->key)+3;
buffer * const tb = ctx->srv->tmp_buf;
buffer_copy_buffer(tb, &ctx->current->key);
buffer_append_string_len(tb, CONST_STR_LEN(" / "));
const uint32_t comp_offset = buffer_string_length(tb);
buffer_append_string_len(tb, CONST_STR_LEN("$"));
buffer_append_string_buffer(tb, obj_tag); /*(HTTP, REQUEST_HEADER, SERVER)*/
buffer_append_string_len(tb, CONST_STR_LEN("[\""));
buffer_append_string_buffer(tb, comp_tag);
buffer_append_string_len(tb, CONST_STR_LEN("\"] "));
buffer_append_string_len(tb, op, 2);
buffer_append_string_len(tb, CONST_STR_LEN(" \""));
buffer_append_string_buffer(tb, rvalue);
buffer_append_string_len(tb, CONST_STR_LEN("\""));
buffer_clear(tb);
struct const_iovec iov[] = {
{ CONST_BUF_LEN(&ctx->current->key) }
,{ CONST_STR_LEN(" / ") } /* comp_offset */
,{ CONST_STR_LEN("$") }
,{ CONST_BUF_LEN(obj_tag) } /*(HTTP, REQUEST_HEADER, SERVER)*/
,{ CONST_STR_LEN("[\"") }
,{ CONST_BUF_LEN(comp_tag) }
,{ CONST_STR_LEN("\"] ") }
,{ op, 2 }
,{ CONST_STR_LEN(" \"") }
,{ CONST_BUF_LEN(rvalue) }
,{ CONST_STR_LEN("\"") }
};
buffer_append_iovec(tb, iov, sizeof(iov)/sizeof(*iov));
data_config *dc;
if (NULL != (dc = configparser_get_data_config(ctx->all_configs,
@ -322,9 +326,9 @@ configparser_parse_else_condition(config_t * const ctx)
{
data_config * const dc = data_config_init();
dc->cond = CONFIG_COND_ELSE;
buffer_copy_buffer(&dc->key, &ctx->current->key);
buffer_append_string_len(&dc->key, CONST_STR_LEN(" / "));
buffer_append_string_len(&dc->key, CONST_STR_LEN("else_tmp_token"));
buffer_append_str2(&dc->key, CONST_BUF_LEN(&ctx->current->key),
CONST_STR_LEN(" / "
"else_tmp_token"));
configparser_push(ctx, dc, 1);
}

13
src/connections.c

@ -417,14 +417,11 @@ connection_send_1xx (request_st * const r, connection * const con)
http_status_append(b, r->http_status);
for (uint32_t i = 0; i < r->resp_headers.used; ++i) {
const data_string * const ds = (data_string *)r->resp_headers.data[i];
if (buffer_string_is_empty(&ds->value)) continue;
if (buffer_string_is_empty(&ds->key)) continue;
buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
buffer_append_string_buffer(b, &ds->key);
buffer_append_string_len(b, CONST_STR_LEN(": "));
buffer_append_string_buffer(b, &ds->value);
const uint32_t klen = buffer_string_length(&ds->key);
const uint32_t vlen = buffer_string_length(&ds->value);
if (0 == klen || 0 == vlen) continue;
buffer_append_str2(b, CONST_STR_LEN("\r\n"), ds->key.ptr, klen);
buffer_append_str2(b, CONST_STR_LEN(": "), ds->value.ptr, vlen);
}
buffer_append_string_len(b, CONST_STR_LEN("\r\n\r\n"));
chunkqueue_append_buffer_commit(cq);

9
src/data_string.c

@ -30,12 +30,11 @@ static int data_string_insert_dup(data_unset *dst, data_unset *src) {
data_string *ds_dst = (data_string *)dst;
data_string *ds_src = (data_string *)src;
if (!buffer_is_empty(&ds_dst->value)) {
buffer_append_string_len(&ds_dst->value, CONST_STR_LEN(", "));
buffer_append_string_buffer(&ds_dst->value, &ds_src->value);
} else {
if (!buffer_is_empty(&ds_dst->value))
buffer_append_str2(&ds_dst->value, CONST_STR_LEN(", "),
CONST_BUF_LEN(&ds_src->value));
else
buffer_copy_buffer(&ds_dst->value, &ds_src->value);
}
src->fn->free(src);

25
src/gw_backend.c

@ -375,8 +375,10 @@ static int gw_proc_sockaddr_init(gw_host * const host, gw_proc * const proc, log
errno = EINVAL;
return -1;
}
buffer_copy_string_len(proc->connection_name, CONST_STR_LEN("unix:"));
buffer_append_string_buffer(proc->connection_name, proc->unixsocket);
buffer_clear(proc->connection_name);
buffer_append_str2(proc->connection_name,
CONST_STR_LEN("unix:"),
CONST_BUF_LEN(proc->unixsocket));
}
else {
/*(note: name resolution here is *blocking* if IP string not supplied)*/
@ -394,9 +396,11 @@ static int gw_proc_sockaddr_init(gw_host * const host, gw_proc * const proc, log
sock_addr_inet_ntop_copy_buffer(h, &addr);
host->family = sock_addr_get_family(&addr);
}
buffer_copy_string_len(proc->connection_name, CONST_STR_LEN("tcp:"));
buffer_append_string_buffer(proc->connection_name, host->host);
buffer_append_string_len(proc->connection_name, CONST_STR_LEN(":"));
buffer_clear(proc->connection_name);
buffer_append_str3(proc->connection_name,
CONST_STR_LEN("tcp:"),
CONST_BUF_LEN(host->host),
CONST_STR_LEN(":"));
buffer_append_int(proc->connection_name, proc->port);
}
@ -653,8 +657,9 @@ static void gw_proc_spawn(gw_host * const host, log_error_st * const errh, const
if (buffer_string_is_empty(host->unixsocket)) {
proc->port = host->port + proc->id;
} else {
buffer_copy_buffer(proc->unixsocket, host->unixsocket);
buffer_append_string_len(proc->unixsocket, CONST_STR_LEN("-"));
buffer_clear(proc->unixsocket);
buffer_append_str2(proc->unixsocket, CONST_BUF_LEN(host->unixsocket),
CONST_STR_LEN("-"));
buffer_append_int(proc->unixsocket, proc->id);
}
@ -1628,9 +1633,9 @@ int gw_set_defaults_backend(server *srv, gw_plugin_data *p, const array *a, gw_p
if (buffer_string_is_empty(host->unixsocket)) {
proc->port = host->port + pno;
} else {
buffer_copy_buffer(proc->unixsocket, host->unixsocket);
buffer_append_string_len(proc->unixsocket,
CONST_STR_LEN("-"));
buffer_append_str2(proc->unixsocket,
CONST_BUF_LEN(host->unixsocket),
CONST_STR_LEN("-"));
buffer_append_int(proc->unixsocket, pno);
}

17
src/h2.c

@ -1997,8 +1997,8 @@ h2_send_headers (request_st * const r, connection * const con)
&& !buffer_string_is_empty(r->conf.server_tag)) {
buffer * const b = chunk_buffer_acquire();
const uint32_t vlen = buffer_string_length(r->conf.server_tag);
buffer_copy_string_len(b, CONST_STR_LEN("server: "));
buffer_append_string_len(b, CONST_BUF_LEN(r->conf.server_tag));
buffer_append_str2(b, CONST_STR_LEN("server: "),
r->conf.server_tag->ptr, vlen);
alen += 6+vlen+4;
@ -2144,14 +2144,11 @@ h2_send_1xx (request_st * const r, connection * const con)
buffer_append_int(b, r->http_status);
for (uint32_t i = 0; i < r->resp_headers.used; ++i) {
const data_string * const ds = (data_string *)r->resp_headers.data[i];
if (buffer_string_is_empty(&ds->value)) continue;
if (buffer_string_is_empty(&ds->key)) continue;
buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
buffer_append_string_buffer(b, &ds->key);
buffer_append_string_len(b, CONST_STR_LEN(": "));
buffer_append_string_buffer(b, &ds->value);
const uint32_t klen = buffer_string_length(&ds->key);
const uint32_t vlen = buffer_string_length(&ds->value);
if (0 == klen || 0 == vlen) continue;
buffer_append_str2(b, CONST_STR_LEN("\r\n"), ds->key.ptr, klen);
buffer_append_str2(b, CONST_STR_LEN(": "), ds->value.ptr, vlen);
}
buffer_append_string_len(b, CONST_STR_LEN("\r\n\r\n"));

11
src/http-header-glue.c

@ -104,8 +104,8 @@ int http_response_redirect_to_directory(request_st * const r, int status) {
buffer_clear(o);
/* XXX: store flag in global at startup? */
if (r->con->srv->srvconf.absolute_dir_redirect) {
buffer_copy_buffer(o, &r->uri.scheme);
buffer_append_string_len(o, CONST_STR_LEN("://"));
buffer_append_str2(o, CONST_BUF_LEN(&r->uri.scheme),
CONST_STR_LEN("://"));
if (0 != http_response_buffer_append_authority(r, o)) {
return -1;
}
@ -125,10 +125,9 @@ int http_response_redirect_to_directory(request_st * const r, int status) {
buffer_append_string_encoded(vb, CONST_BUF_LEN(&r->uri.path),
ENCODING_REL_URI);
buffer_append_string_len(vb, CONST_STR_LEN("/"));
if (!buffer_string_is_empty(&r->uri.query)) {
buffer_append_string_len(o, CONST_STR_LEN("?"));
buffer_append_string_buffer(o, &r->uri.query);
}
if (!buffer_string_is_empty(&r->uri.query))
buffer_append_str2(vb, CONST_STR_LEN("?"),
CONST_BUF_LEN(&r->uri.query));
return 0;
}

14
src/http_header.c

@ -249,17 +249,15 @@ void http_header_response_append(request_st * const r, enum http_header_e id, co
__attribute_cold__
static void http_header_response_insert_addtl(request_st * const r, enum http_header_e id, const char *k, uint32_t klen, buffer * const vb, uint32_t vlen) {
UNUSED(id);
buffer_append_string_len(vb, CONST_STR_LEN("\r\n"));
char *h = buffer_string_prepare_append(vb, 2 + klen + vlen + 2);
buffer_append_str3(vb, CONST_STR_LEN("\r\n"), k, klen, CONST_STR_LEN(": "));
if (r->http_version >= HTTP_VERSION_2) {
r->resp_header_repeated = 1;
char * const h = buffer_string_prepare_append(vb, klen + vlen + 2);
for (uint32_t i = 0; i < klen; ++i)
h[i] = !light_isupper(k[i]) ? k[i] : (k[i] | 0x20);
buffer_commit(vb, klen);
h += 2;
for (uint32_t i = 0; i < klen; ++i) {
if (light_isupper(h[i])) h[i] |= 0x20;
}
}
else
buffer_append_string_len(vb, k, klen);
buffer_append_string_len(vb, CONST_STR_LEN(": "));
}
void http_header_response_insert(request_st * const r, enum http_header_e id, const char *k, uint32_t klen, const char *v, uint32_t vlen) {

4
src/http_range.c

@ -207,8 +207,8 @@ http_range_multi (request_st * const r,
http_header_response_get(r, HTTP_HEADER_CONTENT_TYPE,
CONST_STR_LEN("Content-Type"));
if (content_type) {
buffer_append_string_len(tb, CONST_STR_LEN("\r\nContent-Type: "));
buffer_append_string_len(tb, CONST_BUF_LEN(content_type));
buffer_append_str2(tb, CONST_STR_LEN("\r\nContent-Type: "),
CONST_BUF_LEN(content_type));
}
buffer_append_string_len(tb,CONST_STR_LEN("\r\nContent-Range: bytes "));
const uint32_t prefix_len = buffer_string_length(tb);

6
src/mod_ajp13.c

@ -729,9 +729,9 @@ ajp13_expand_headers (buffer * const b, handler_ctx * const hctx, uint32_t plen)
else {
if (plen < len+1) break;
plen -= len+1;
buffer_append_string_len(b, CONST_STR_LEN("\n"));
buffer_append_string_len(b, (char *)ptr, len);
buffer_append_string_len(b, CONST_STR_LEN(": "));
buffer_append_str3(b, CONST_STR_LEN("\n"),
(char *)ptr, len,
CONST_STR_LEN(": "));
ptr += len+1;
}

27
src/mod_auth.c

@ -720,12 +720,12 @@ static handler_t mod_auth_send_400_bad_request(request_st * const r) {
static handler_t mod_auth_send_401_unauthorized_basic(request_st * const r, const buffer * const realm) {
r->http_status = 401;
r->handler_module = NULL;
buffer * const vb =
buffer_append_str3(
http_header_response_set_ptr(r, HTTP_HEADER_WWW_AUTHENTICATE,
CONST_STR_LEN("WWW-Authenticate"));
buffer_copy_string_len(vb, CONST_STR_LEN("Basic realm=\""));
buffer_append_string_buffer(vb, realm);
buffer_append_string_len(vb, CONST_STR_LEN("\", charset=\"UTF-8\""));
CONST_STR_LEN("WWW-Authenticate")),
CONST_STR_LEN("Basic realm=\""),
CONST_BUF_LEN(realm),
CONST_STR_LEN("\", charset=\"UTF-8\""));
return HANDLER_FINISHED;
}
@ -1133,14 +1133,15 @@ static void mod_auth_digest_www_authenticate(buffer *b, time_t cur_ts, const str
buffer_clear(b);
for (int i = 0; i < n; ++i) {
if (i > 0) {
buffer_append_string_len(b,CONST_STR_LEN("\r\nWWW-Authenticate: "));
}
buffer_append_string_len(b, CONST_STR_LEN("Digest realm=\""));
buffer_append_string_buffer(b, require->realm);
buffer_append_string_len(b, CONST_STR_LEN("\", charset=\"UTF-8\", algorithm="));
buffer_append_string_len(b, algoname[i], algolen[i]);
buffer_append_string_len(b, CONST_STR_LEN(", nonce=\""));
struct const_iovec iov[] = {
{ CONST_STR_LEN("\r\nWWW-Authenticate: ") }
,{ CONST_STR_LEN("Digest realm=\"") }
,{ CONST_BUF_LEN(require->realm) }
,{ CONST_STR_LEN("\", charset=\"UTF-8\", algorithm=") }
,{ algoname[i], algolen[i] }
,{ CONST_STR_LEN(", nonce=\"") }
};
buffer_append_iovec(b, iov+(0==i), sizeof(iov)/sizeof(*iov)-(0==i));
mod_auth_append_nonce(b, cur_ts, require, algoid[i], NULL);
buffer_append_string_len(b, CONST_STR_LEN("\", qop=\"auth\""));
if (nonce_stale) {

35
src/mod_authn_mysql.c

@ -35,7 +35,6 @@
#include "plugin.h"
#include "safe_memclear.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -385,7 +384,7 @@ static handler_t mod_authn_mysql_query(request_st * const r, void *p_d, http_aut
}
do {
char q[1024], uname[512], urealm[512];
char uname[512], urealm[512];
unsigned long mrc;
if (ai->ulen > sizeof(uname)/2-1)
@ -415,19 +414,25 @@ static handler_t mod_authn_mysql_query(request_st * const r, void *p_d, http_aut
if ((unsigned long)~0 == mrc) break;
#endif
rc = snprintf(q, sizeof(q),
"SELECT %s FROM %s WHERE %s='%s' AND %s='%s'",
p->conf.auth_mysql_col_pass,
p->conf.auth_mysql_users_table,
p->conf.auth_mysql_col_user,
uname,
p->conf.auth_mysql_col_realm,
urealm);
if (rc >= (int)sizeof(q)) {
rc = -1;
break;
}
buffer * const tb = r->tmp_buf;
buffer_clear(tb);
struct const_iovec iov[] = {
{ CONST_STR_LEN("SELECT ") }
,{ p->conf.auth_mysql_col_pass, strlen(p->conf.auth_mysql_col_pass) }
,{ CONST_STR_LEN(" FROM ") }
,{ p->conf.auth_mysql_users_table, strlen(p->conf.auth_mysql_users_table) }
,{ CONST_STR_LEN(" WHERE ") }
,{ p->conf.auth_mysql_col_user, strlen(p->conf.auth_mysql_col_user) }
,{ CONST_STR_LEN("='") }
,{ uname, strlen(uname) }
,{ CONST_STR_LEN("' AND ") }
,{ p->conf.auth_mysql_col_realm, strlen(p->conf.auth_mysql_col_realm) }
,{ CONST_STR_LEN("='") }
,{ urealm, strlen(urealm) }
,{ CONST_STR_LEN("'") }
};
buffer_append_iovec(tb, iov, sizeof(iov)/sizeof(*iov));
char * const q = tb->ptr;
/* for now we stay synchronous */
if (0 != mysql_query(p->mysql_conn, q)) {

9
src/mod_deflate.c

@ -291,12 +291,13 @@ static buffer * mod_deflate_cache_file_name(request_st * const r, const buffer *
/* XXX: future: for shorter paths into the cache, we could checksum path,
* and then shard it to avoid a huge single directory.
* Alternatively, could use &r->uri.path, minus any
* (matching) &r->pathinfo suffix, with result url-encoded */
* (matching) &r->pathinfo suffix, with result url-encoded
* Alternative, we could shard etag which is already our "checksum" */
buffer * const tb = r->tmp_buf;
buffer_copy_buffer(tb, cache_dir);
buffer_append_string_len(tb, CONST_BUF_LEN(&r->physical.path));
buffer_append_string_len(tb, CONST_STR_LEN("-"));
buffer_append_string_len(tb, etag->ptr+1, buffer_string_length(etag)-2);
buffer_append_path_len(tb, CONST_BUF_LEN(&r->physical.path));
buffer_append_str2(tb, CONST_STR_LEN("-"), /*(strip surrounding '"')*/
etag->ptr+1, buffer_string_length(etag)-2);
return tb;
}

92
src/mod_dirlisting.c

@ -641,39 +641,41 @@ static const char js_simple_table_init_sort[] = \
"}\n";
static void http_dirlist_append_js_table_resort (buffer * const b, const request_st * const r) {
char col = '0';
char ascending = '0';
char init_sort[] = "0,0";
if (!buffer_string_is_empty(&r->uri.query)) {
const char *qs = r->uri.query.ptr;
do {
if (qs[0] == 'C' && qs[1] == '=') {
const int col = 0;
switch (qs[2]) {
case 'N': col = '0'; break;
case 'M': col = '1'; break;
case 'S': col = '2'; break;
case 'N': init_sort[col] = '0'; break;
case 'M': init_sort[col] = '1'; break;
case 'S': init_sort[col] = '2'; break;
case 'T':
case 'D': col = '3'; break;
case 'D': init_sort[col] = '3'; break;
default: break;
}
}
else if (qs[0] == 'O' && qs[1] == '=') {
const int order = 2;
switch (qs[2]) {
case 'A': ascending = '1'; break;
case 'D': ascending = '0'; break;
case 'A': init_sort[order] = '1'; break;
case 'D': init_sort[order] = '0'; break;
default: break;
}
}
} while ((qs = strchr(qs, '&')) && *++qs);
}
buffer_append_string_len(b, CONST_STR_LEN("\n<script type=\"text/javascript\">\n// <!--\n\n"));
buffer_append_string_len(b, js_simple_table_resort, sizeof(js_simple_table_resort)-1);
buffer_append_string_len(b, js_simple_table_init_sort, sizeof(js_simple_table_init_sort)-1);
buffer_append_string_len(b, CONST_STR_LEN("\ninit_sort("));
buffer_append_string_len(b, &col, 1);
buffer_append_string_len(b, CONST_STR_LEN(", "));
buffer_append_string_len(b, &ascending, 1);
buffer_append_string_len(b, CONST_STR_LEN(");\n\n// -->\n</script>\n\n"));
struct const_iovec iov[] = {
{ CONST_STR_LEN("\n<script type=\"text/javascript\">\n// <!--\n\n") }
,{ CONST_STR_LEN(js_simple_table_resort) }
,{ CONST_STR_LEN(js_simple_table_init_sort) }
,{ CONST_STR_LEN("\ninit_sort(") }
,{ CONST_STR_LEN(init_sort) }
,{ CONST_STR_LEN(");\n\n// -->\n</script>\n\n") }
};
buffer_append_iovec(b, iov, sizeof(iov)/sizeof(*iov));
}
static void http_list_directory_header(request_st * const r, plugin_data * const p) {
@ -687,19 +689,21 @@ static void http_list_directory_header(request_st * const r, plugin_data * const
"<head>\n"
));
if (!buffer_string_is_empty(p->conf.encoding)) {
buffer_append_string_len(out, CONST_STR_LEN("<meta charset=\""));
buffer_append_string_buffer(out, p->conf.encoding);
buffer_append_string_len(out, CONST_STR_LEN("\">\n"));
buffer_append_str3(out,
CONST_STR_LEN("<meta charset=\""),
CONST_BUF_LEN(p->conf.encoding),
CONST_STR_LEN("\">\n"));
}
buffer_append_string_len(out, CONST_STR_LEN("<title>Index of "));
buffer_append_string_encoded(out, CONST_BUF_LEN(&r->uri.path), ENCODING_MINIMAL_XML);
buffer_append_string_len(out, CONST_STR_LEN("</title>\n"));
if (!buffer_string_is_empty(p->conf.external_css)) {
buffer_append_string_len(out, CONST_STR_LEN("<meta name=\"viewport\" content=\"initial-scale=1\">"));
buffer_append_string_len(out, CONST_STR_LEN("<link rel=\"stylesheet\" type=\"text/css\" href=\""));
buffer_append_string_buffer(out, p->conf.external_css);
buffer_append_string_len(out, CONST_STR_LEN("\">\n"));
buffer_append_str3(out,
CONST_STR_LEN("<meta name=\"viewport\" content=\"initial-scale=1\">"
"<link rel=\"stylesheet\" type=\"text/css\" href=\""),
CONST_BUF_LEN(p->conf.external_css),
CONST_STR_LEN("\">\n"));
} else {
buffer_append_string_len(out, CONST_STR_LEN(
"<style type=\"text/css\">\n"
@ -795,22 +799,17 @@ static void http_list_directory_footer(request_st * const r, plugin_data * const
: !buffer_string_is_empty(r->conf.server_tag)
? r->conf.server_tag
: NULL;
buffer_append_string_len(out, CONST_STR_LEN(
"<div class=\"foot\">"
));
if (footer)
buffer_append_string_buffer(out, footer);
buffer_append_string_len(out, CONST_STR_LEN(
"</div>\n"
));
buffer_append_str3(out,
CONST_STR_LEN("<div class=\"foot\">"),
CONST_BUF_LEN(footer),
CONST_STR_LEN("</div>\n"));
if (!buffer_string_is_empty(p->conf.external_js)) {
buffer_append_string_len(out, CONST_STR_LEN("<script type=\"text/javascript\" src=\""));
buffer_append_string_buffer(out, p->conf.external_js);
buffer_append_string_len(out, CONST_STR_LEN("\"></script>\n"));
buffer_append_str3(out,
CONST_STR_LEN("<script type=\"text/javascript\" src=\""),
CONST_BUF_LEN(p->conf.external_js),
CONST_STR_LEN("\"></script>\n"));
} else if (buffer_is_empty(p->conf.external_js)) {
http_dirlist_append_js_table_resort(out, r);
}
@ -998,19 +997,22 @@ static int http_list_directory(request_st * const r, plugin_data * const p) {
content_type = &octet_stream;
}
http_list_directory_sizefmt(sizebuf, sizeof(sizebuf), tmp->size);
buffer_append_string_len(out, CONST_STR_LEN("<tr><td class=\"n\"><a href=\""));
buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_REL_URI_PART);
buffer_append_string_len(out, CONST_STR_LEN("\">"));
buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_MINIMAL_XML);
buffer_append_string_len(out, CONST_STR_LEN("</a></td><td class=\"m\">"));
buffer_append_strftime(out, "%Y-%b-%d %T", localtime_r(&tmp->mtime, &tm));
buffer_append_string_len(out, CONST_STR_LEN("</td><td class=\"s\">"));
buffer_append_string(out, sizebuf);
buffer_append_string_len(out, CONST_STR_LEN("</td><td class=\"t\">"));
buffer_append_string_buffer(out, content_type);
buffer_append_string_len(out, CONST_STR_LEN("</td></tr>\n"));
size_t buflen =
http_list_directory_sizefmt(sizebuf, sizeof(sizebuf), tmp->size);
struct const_iovec iov[] = {
{ CONST_STR_LEN("</td><td class=\"s\">") }
,{ sizebuf, buflen }
,{ CONST_STR_LEN("</td><td class=\"t\">") }
,{ CONST_BUF_LEN(content_type) }
,{ CONST_STR_LEN("</td></tr>\n") }
};
buffer_append_iovec(out, iov, sizeof(iov)/sizeof(*iov));
free(tmp);
@ -1089,8 +1091,8 @@ URIHANDLER_FUNC(mod_dirlisting_subrequest) {
if (buffer_string_is_empty(p->conf.encoding)) {
buffer_copy_string_len(vb, CONST_STR_LEN("text/html"));
} else {
buffer_copy_string_len(vb, CONST_STR_LEN("text/html; charset="));
buffer_append_string_buffer(vb, p->conf.encoding);
buffer_append_str2(vb, CONST_STR_LEN("text/html; charset="),
CONST_BUF_LEN(p->conf.encoding));
}
return HANDLER_FINISHED;

11
src/mod_fastcgi.c

@ -171,11 +171,7 @@ static int fcgi_env_add(void *venv, const char *key, size_t key_len, const char
if (buffer_string_length(env) + len >= fmax)
return -1; /* we can't append more headers, ignore it */
char * const dst = buffer_extend(env, len);
memcpy(dst, len_enc, len_enc_len);
memcpy(dst + len_enc_len, key, key_len);
if (val_len) memcpy(dst + len_enc_len + key_len, val, val_len);
buffer_append_str3(env, len_enc, len_enc_len, key, key_len, val, val_len);
return 0;
}
@ -267,10 +263,9 @@ static handler_t fcgi_create_env(handler_ctx *hctx) {
beginRecord.body.roleB1 = 0;
beginRecord.body.flags = 0;
memset(beginRecord.body.reserved, 0, sizeof(beginRecord.body.reserved));
buffer_copy_string_len(b, (const char *)&beginRecord, sizeof(beginRecord));
fcgi_header(&header, FCGI_PARAMS, request_id, 0, 0); /*(set aside space to fill in later)*/
buffer_append_string_len(b, (const char *)&header, sizeof(header));
buffer_append_str2(b, (const char *)&beginRecord, sizeof(beginRecord),
(const char *)&header, sizeof(header));
/* send FCGI_PARAMS */

10
src/mod_nss.c

@ -2423,11 +2423,11 @@ https_add_ssl_client_cert (request_st * const r, CERTCertificate *peer)
for (uint32_t i = 0; pem[i]; ++i) {
if (pem[i] != '\r') pem[len++] = pem[i]; /*(translate \r\n to \n)*/
}
buffer * const vb =
http_header_env_set_ptr(r, CONST_STR_LEN("SSL_CLIENT_CERT"));
buffer_copy_string_len(vb, CONST_STR_LEN(PEM_BEGIN_CERT"\n"));
buffer_append_string_len(vb, pem, len);
buffer_append_string_len(vb,CONST_STR_LEN("\n"PEM_END_CERT"\n"));
buffer_append_str3(
http_header_env_set_ptr(r, CONST_STR_LEN("SSL_CLIENT_CERT")),
CONST_STR_LEN(PEM_BEGIN_CERT"\n"),
pem, len,
CONST_STR_LEN("\n"PEM_END_CERT"\n"));
PORT_Free(pem);
}

20
src/mod_proxy.c

@ -692,9 +692,9 @@ static void proxy_set_Forwarded(connection * const con, request_st * const r, co
* e.g. for="...:port")*/
buffer_append_string_buffer(b, con->dst_addr_buf);
} else if (family == AF_INET6) {
buffer_append_string_len(b, CONST_STR_LEN("\"["));
buffer_append_string_buffer(b, con->dst_addr_buf);
buffer_append_string_len(b, CONST_STR_LEN("]\""));
buffer_append_str3(b, CONST_STR_LEN("\"["),
CONST_BUF_LEN(con->dst_addr_buf),
CONST_STR_LEN("]\""));
} else {
buffer_append_string_len(b, CONST_STR_LEN("\""));
buffer_append_string_backslash_escaped(
@ -738,8 +738,7 @@ static void proxy_set_Forwarded(connection * const con, request_st * const r, co
* (not checking if quoted-string and encoding needed) */
if (semicolon) buffer_append_string_len(b, CONST_STR_LEN(";"));
if (NULL != eproto) {
buffer_append_string_len(b, CONST_STR_LEN("proto="));
buffer_append_string_buffer(b, eproto);
buffer_append_str2(b,CONST_STR_LEN("proto="),CONST_BUF_LEN(eproto));
} else if (con->srv_socket->is_ssl) {
buffer_append_string_len(b, CONST_STR_LEN("proto=https"));
} else {
@ -855,8 +854,7 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) {
/* request line */
http_method_append(b, r->http_method);
buffer_append_string_len(b, CONST_STR_LEN(" "));
buffer_append_string_buffer(b, &r->target);
buffer_append_str2(b, CONST_STR_LEN(" "), CONST_BUF_LEN(&r->target));
if (remap_headers)
http_header_remap_uri(b, buffer_string_length(b) - buffer_string_length(&r->target), &hctx->conf.header, 1);
@ -870,11 +868,11 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) {
log_error(r->conf.errh, __FILE__, __LINE__,
"proxy - using \"%s\" as HTTP Host", hctx->gw.host->id->ptr);
}
buffer_append_string_len(b, CONST_STR_LEN("\r\nHost: "));
buffer_append_string_buffer(b, hctx->gw.host->id);
buffer_append_str2(b, CONST_STR_LEN("\r\nHost: "),
CONST_BUF_LEN(hctx->gw.host->id));
} else if (!buffer_string_is_empty(r->http_host)) {
buffer_append_string_len(b, CONST_STR_LEN("\r\nHost: "));
buffer_append_string_buffer(b, r->http_host);
buffer_append_str2(b, CONST_STR_LEN("\r\nHost: "),
CONST_BUF_LEN(r->http_host));
if (remap_headers) {
size_t alen = buffer_string_length(r->http_host);
http_header_remap_host(b, buffer_string_length(b) - alen, &hctx->conf.header, 1, alen);

15
src/mod_rrdtool.c

@ -276,9 +276,11 @@ static int mod_rrdtool_create_rrd(server *srv, plugin_data *p, rrd_config *s, ch
/* create a new one */
buffer * const cmd = srv->tmp_buf;
buffer_copy_string_len(cmd, CONST_STR_LEN("create "));
buffer_append_string_buffer(cmd, s->path_rrd);
buffer_append_string_len(cmd, CONST_STR_LEN(
buffer_clear(cmd);
buffer_append_str3(cmd,
CONST_STR_LEN("create "),
CONST_BUF_LEN(s->path_rrd),
CONST_STR_LEN(
" --step 60 "
"DS:InOctets:ABSOLUTE:600:U:U "
"DS:OutOctets:ABSOLUTE:600:U:U "
@ -330,9 +332,10 @@ static int mod_rrd_write_data(server *srv, plugin_data *p, rrd_config *s) {
return 0;
buffer * const cmd = srv->tmp_buf;
buffer_copy_string_len(cmd, CONST_STR_LEN("update "));
buffer_append_string_buffer(cmd, s->path_rrd);
buffer_append_string_len(cmd, CONST_STR_LEN(" N:"));
buffer_clear(cmd);
buffer_append_str3(cmd, CONST_STR_LEN("update "),
CONST_BUF_LEN(s->path_rrd),
CONST_STR_LEN(" N:"));
buffer_append_int(cmd, s->bytes_read);
buffer_append_string_len(cmd, CONST_STR_LEN(":"));
buffer_append_int(cmd, s->bytes_written);

4
src/mod_secdownload.c

@ -479,8 +479,8 @@ URIHANDLER_FUNC(mod_secdownload_uri_handler) {
if (protected_path != tb->ptr) {
buffer_copy_string(tb, protected_path);
}
buffer_append_string_len(tb, CONST_STR_LEN("?"));
buffer_append_string_buffer(tb, &r->uri.query);
buffer_append_str2(tb, CONST_STR_LEN("?"),
CONST_BUF_LEN(&r->uri.query));
/* assign last in case tb->ptr is reallocated */
protected_path = tb->ptr;
}

1
src/mod_simple_vhost.c

@ -128,7 +128,6 @@ SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
}
static void build_doc_root_path(buffer *out, const buffer *sroot, const buffer *host, const buffer *droot) {
force_assert(!buffer_string_is_empty(sroot));
buffer_copy_buffer(out, sroot);
if (!buffer_string_is_empty(host)) {

15
src/mod_ssi.c

@ -509,14 +509,13 @@ static int process_ssi_stmt(request_st * const r, handler_ctx * const p, const c
} else {
/* virtual */
if (virt_path[0] == '/') {
buffer_copy_string(tb, virt_path);
} else {
buffer_clear(tb);
if (virt_path[0] != '/') {
/* there is always a / */
const char * const sl = strrchr(r->uri.path.ptr, '/');
buffer_copy_string_len(tb, r->uri.path.ptr, sl - r->uri.path.ptr + 1);
buffer_append_string(tb, virt_path);
}
buffer_append_string(tb, virt_path);
buffer_urldecode_path(tb);
if (!buffer_is_valid_UTF8(tb)) {
@ -591,7 +590,7 @@ static int process_ssi_stmt(request_st * const r, handler_ctx * const p, const c
for (j = 0; s > 1024 && abr[j+1]; s /= 1024, j++);
buffer_append_int(tb, s);
buffer_append_string(tb, abr[j]);
buffer_append_string_len(tb, abr[j], j ? 3 : 2);
} else {
buffer_append_int(tb, stb.st_size);
}
@ -725,16 +724,14 @@ static int process_ssi_stmt(request_st * const r, handler_ctx * const p, const c
for (i = 0; i < p->ssi_vars->used; i++) {
data_string *ds = (data_string *)p->ssi_vars->sorted[i];
buffer_append_string_buffer(tb, &ds->key);
buffer_append_string_len(tb, CONST_STR_LEN("="));
buffer_append_str2(tb, CONST_BUF_LEN(&ds->key), CONST_STR_LEN("="));
buffer_append_string_encoded(tb, CONST_BUF_LEN(&ds->value), ENCODING_MINIMAL_XML);
buffer_append_string_len(tb, CONST_STR_LEN("\n"));
}
for (i = 0; i < p->ssi_cgi_env->used; i++) {
data_string *ds = (data_string *)p->ssi_cgi_env->sorted[i];
buffer_append_string_buffer(tb, &ds->key);
buffer_append_string_len(tb, CONST_STR_LEN("="));
buffer_append_str2(tb, CONST_BUF_LEN(&ds->key), CONST_STR_LEN("="));
buffer_append_string_encoded(tb, CONST_BUF_LEN(&ds->value), ENCODING_MINIMAL_XML);
buffer_append_string_len(tb, CONST_STR_LEN("\n"));
}

388
src/mod_status.c

@ -121,23 +121,38 @@ SETDEFAULTS_FUNC(mod_status_set_defaults) {
static const char *
mod_status_get_state (request_state_t state)
static void
mod_status_append_state (buffer * const b, request_state_t state)
{
const char *s;
size_t n;
switch (state) {
case CON_STATE_CONNECT: return "connect";
case CON_STATE_READ: return "read";
case CON_STATE_READ_POST: return "readpost";
case CON_STATE_WRITE: return "write";
case CON_STATE_CLOSE: return "close";
case CON_STATE_ERROR: return "error";
case CON_STATE_HANDLE_REQUEST: return "handle-req";
case CON_STATE_REQUEST_START: return "req-start";
case CON_STATE_REQUEST_END: return "req-end";
case CON_STATE_RESPONSE_START: return "resp-start";
case CON_STATE_RESPONSE_END: return "resp-end";
default: return "(unknown)";
case CON_STATE_CONNECT:
s = "connect"; n = sizeof("connect")-1; break;
case CON_STATE_READ:
s = "read"; n = sizeof("read")-1; break;
case CON_STATE_READ_POST:
s = "readpost"; n = sizeof("readpost")-1; break;
case CON_STATE_WRITE:
s = "write"; n = sizeof("write")-1; break;
case CON_STATE_CLOSE:
s = "close"; n = sizeof("close")-1; break;
case CON_STATE_ERROR:
s = "error"; n = sizeof("error")-1; break;
case CON_STATE_HANDLE_REQUEST:
s = "handle-req"; n = sizeof("handle-req")-1; break;
case CON_STATE_REQUEST_START:
s = "req-start"; n = sizeof("req-start")-1; break;
case CON_STATE_REQUEST_END:
s = "req-end"; n = sizeof("req-end")-1; break;
case CON_STATE_RESPONSE_START:
s = "resp-start"; n = sizeof("resp-start")-1; break;
case CON_STATE_RESPONSE_END:
s = "resp-end"; n = sizeof("resp-end")-1; break;
default:
s = "(unknown)"; n = sizeof("(unknown)")-1; break;
}
buffer_append_string_len(b, s, n);
}
@ -161,65 +176,46 @@ mod_status_get_short_state (request_state_t state)
}
static int mod_status_row_append(buffer *b, const char *key, const char *value) {
buffer_append_string_len(b, CONST_STR_LEN(" <tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" <td><b>"));
buffer_append_string(b, key);
buffer_append_string_len(b, CONST_STR_LEN("</b></td>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" <td>"));
buffer_append_string(b, value);
buffer_append_string_len(b, CONST_STR_LEN("</td>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" </tr>\n"));
return 0;
}
static int mod_status_header_append(buffer *b, const char *key) {
buffer_append_string_len(b, CONST_STR_LEN(" <tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" <th colspan=\"2\">"));
buffer_append_string(b, key);
buffer_append_string_len(b, CONST_STR_LEN("</th>\n"));
buffer_append_string_len(b, CONST_STR_LEN(" </tr>\n"));
return 0;
}
static void mod_status_header_append_sort(buffer *b, plugin_data *p, const char* k, size_t klen)
{
if (p->conf.sort) {
buffer_append_string_len(b, CONST_STR_LEN("<th class=\"status\"><a href=\"#\" class=\"sortheader\" onclick=\"resort(this);return false;\">"));
buffer_append_string_len(b, k, klen);
buffer_append_string_len(b, CONST_STR_LEN("<span class=\"sortarrow\">:</span></a></th>\n"));
} else {
buffer_append_string_len(b, CONST_STR_LEN("<th class=\"status\">"));
buffer_append_string_len(b, k, klen);
buffer_append_string_len(b, CONST_STR_LEN("</th>\n"));
}
return 0;
p->conf.sort
? buffer_append_str3(b,
CONST_STR_LEN("<th class=\"status\"><a href=\"#\" class=\"sortheader\" onclick=\"resort(this);return false;\">"),
k, klen,
CONST_STR_LEN("<span class=\"sortarrow\">:</span></a></th>\n"))
: buffer_append_str3(b,
CONST_STR_LEN("<th class=\"status\">"),
k, klen,
CONST_STR_LEN("</th>\n"));
}
static int mod_status_get_multiplier(double *avg, char *multiplier, int size) {
*multiplier = ' ';
static void mod_status_get_multiplier(buffer *b, double avg, int size) {
char unit[] = " ";
if (*avg > size) { *avg /= size; *multiplier = 'k'; }
if (*avg > size) { *avg /= size; *multiplier = 'M'; }
if (*avg > size) { *avg /= size; *multiplier = 'G'; }
if (*avg > size) { *avg /= size; *multiplier = 'T'; }
if (*avg > size) { *avg /= size; *multiplier = 'P'; }
if (*avg > size) { *avg /= size; *multiplier = 'E'; }
if (*avg > size) { *avg /= size; *multiplier = 'Z'; }
if (*avg > size) { *avg /= size; *multiplier = 'Y'; }
if (avg > size) { avg /= size; unit[1] = 'k'; }
if (avg > size) { avg /= size; unit[1] = 'M'; }
if (avg > size) { avg /= size; unit[1] = 'G'; }
if (avg > size) { avg /= size; unit[1] = 'T'; }
if (avg > size) { avg /= size; unit[1] = 'P'; }
if (avg > size) { avg /= size; unit[1] = 'E'; }
if (avg > size) { avg /= size; unit[1] = 'Z'; }
if (avg > size) { avg /= size; unit[1] = 'Y'; }
return 0;
if (size == 1000) {
buffer_append_int(b, (intmax_t)avg);
}
else { /* (size == 1024) */
char buf[32+1];
buffer_append_string_len(b, buf, (size_t)
snprintf(buf, sizeof(buf), "%.2f", avg));
}
buffer_append_string_len(b, unit, 2);
}
static void mod_status_html_rtable_r (buffer * const b, const request_st * const r, const connection * const con, const time_t cur_ts) {
buffer_append_string_len(b, CONST_STR_LEN("<tr><td class=\"string\">"));
buffer_append_string_buffer(b, con->dst_addr_buf);
buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
buffer_append_str3(b, CONST_STR_LEN("<tr><td class=\"string\">"),
CONST_BUF_LEN(con->dst_addr_buf),
CONST_STR_LEN("</td><td class=\"int\">"));
if (r->reqbody_length) {
buffer_append_int(b, r->reqbody_queue.bytes_in);
@ -241,7 +237,7 @@ static void mod_status_html_rtable_r (buffer * const b, const request_st * const
buffer_append_string_len(b, CONST_STR_LEN("keep-alive"));
}
else
buffer_append_string(b, mod_status_get_state(r->state));
mod_status_append_state(b, r->state);
buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
@ -312,8 +308,6 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st *
buffer_string_prepare_append(b, 8192-1);/*(status page base HTML is ~5.2k)*/
double avg;
uint32_t j;
char multiplier = '\0';
char buf[32];
time_t ts;
const time_t cur_ts = log_epoch_secs;
@ -427,17 +421,16 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st *
/* connection listing */
buffer_append_string_len(b, CONST_STR_LEN("<h1>Server-Status ("));
buffer_append_string_buffer(b, r->conf.server_tag);
buffer_append_string_len(b, CONST_STR_LEN(")</h1>"));
buffer_append_string_len(b, CONST_STR_LEN("<table summary=\"status\" class=\"status\">"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Hostname</td><td class=\"string\">"));
buffer_append_str3(b, CONST_STR_LEN("<h1>Server-Status ("),
CONST_BUF_LEN(r->conf.server_tag),
CONST_STR_LEN(")</h1>"
"<table summary=\"status\" class=\"status\">"
"<tr><td>Hostname</td><td class=\"string\">"));
buffer_append_string_encoded(b, CONST_BUF_LEN(&r->uri.authority), ENCODING_HTML);
buffer_append_string_len(b, CONST_STR_LEN(" ("));
buffer_append_string_encoded(b, CONST_BUF_LEN(r->server_name), ENCODING_HTML);
buffer_append_string_len(b, CONST_STR_LEN(")</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Uptime</td><td class=\"string\">"));
buffer_append_string_len(b, CONST_STR_LEN(")</td></tr>\n"
"<tr><td>Uptime</td><td class=\"string\">"));
ts = cur_ts - srv->startup_ts;
@ -468,69 +461,34 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st *
}
buffer_append_int(b, seconds);
buffer_append_string_len(b, CONST_STR_LEN(" s"));
buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Started at</td><td class=\"string\">"));
buffer_append_string_len(b, CONST_STR_LEN(" s"
"</td></tr>\n"
"<tr><td>Started at</td><td class=\"string\">"));
ts = srv->startup_ts;
struct tm tm;
buffer_append_strftime(b, "%F %T", localtime_r(&ts, &tm));
buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">absolute (since start)</th></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"
"<tr><th colspan=\"2\">absolute (since start)</th></tr>\n"
"<tr><td>Requests</td><td class=\"string\">"));
avg = p->abs_requests;
mod_status_get_multiplier(&avg, &multiplier, 1000);
buffer_append_int(b, avg);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("req</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
mod_status_get_multiplier(b, avg, 1000);
buffer_append_string_len(b, CONST_STR_LEN("req</td></tr>\n"
"<tr><td>Traffic</td><td class=\"string\">"));
avg = p->abs_traffic_out;
mod_status_get_multiplier(&avg, &multiplier, 1024);
snprintf(buf, sizeof(buf), "%.2f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("byte</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">average (since start)</th></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
mod_status_get_multiplier(b, avg, 1024);
buffer_append_string_len(b, CONST_STR_LEN("byte</td></tr>\n"
"<tr><th colspan=\"2\">average (since start)</th></tr>\n"
"<tr><td>Requests</td><td class=\"string\">"));
avg = p->abs_requests / (cur_ts - srv->startup_ts);
mod_status_get_multiplier(&avg, &multiplier, 1000);
buffer_append_int(b, avg);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("req/s</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
mod_status_get_multiplier(b, avg, 1000);
buffer_append_string_len(b, CONST_STR_LEN("req/s</td></tr>\n"
"<tr><td>Traffic</td><td class=\"string\">"));
avg = p->abs_traffic_out / (cur_ts - srv->startup_ts);
mod_status_get_multiplier(&avg, &multiplier, 1024);
snprintf(buf, sizeof(buf), "%.2f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("byte/s</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">average (5s sliding average)</th></tr>\n"));
mod_status_get_multiplier(b, avg, 1024);
buffer_append_string_len(b, CONST_STR_LEN("byte/s</td></tr>\n"
"<tr><th colspan=\"2\">average (5s sliding average)</th></tr>\n"));
for (j = 0, avg = 0; j < 5; j++) {
avg += p->mod_5s_requests[j];
}
@ -539,12 +497,7 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st *
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
mod_status_get_multiplier(&avg, &multiplier, 1000);
buffer_append_int(b, avg);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
mod_status_get_multiplier(b, avg, 1000);
buffer_append_string_len(b, CONST_STR_LEN("req/s</td></tr>\n"));
for (j = 0, avg = 0; j < 5; j++) {
@ -555,19 +508,11 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st *
buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
mod_status_get_multiplier(&avg, &multiplier, 1024);
snprintf(buf, sizeof(buf), "%.2f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN(" "));
if (multiplier) buffer_append_string_len(b, &multiplier, 1);
buffer_append_string_len(b, CONST_STR_LEN("byte/s</td></tr>\n"));
buffer_append_string_len(b, CONST_STR_LEN("</table>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<hr />\n<pre>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<b>"));
mod_status_get_multiplier(b, avg, 1024);
buffer_append_string_len(b, CONST_STR_LEN("byte/s</td></tr>\n"
"</table>\n"
"<hr />\n<pre>\n"
"<b>"));
buffer_append_int(b, srv->conns.used);
buffer_append_string_len(b, CONST_STR_LEN(" connections</b>\n"));
@ -593,8 +538,8 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st *
buffer_append_string_len(b, CONST_STR_LEN("\n"));
}
}
buffer_append_string_len(b, CONST_STR_LEN("\n\n<table>\n"));
buffer_append_string_len(b, CONST_STR_LEN("<tr><td style=\"text-align:right\">"));
buffer_append_string_len(b, CONST_STR_LEN("\n\n<table>\n"
"<tr><td style=\"text-align:right\">"));
buffer_append_int(b, cstates[CON_STATE_CLOSE+2]);
buffer_append_string_len(b, CONST_STR_LEN("<td>&nbsp;&nbsp;k = keep-alive</td></tr>\n"));
for (j = 0; j < CON_STATE_CLOSE+2; ++j) {
@ -602,10 +547,10 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st *
if (0 == cstates[j] && j == CON_STATE_CLOSE+1) continue;
buffer_append_string_len(b, CONST_STR_LEN("<tr><td style=\"text-align:right\">"));
buffer_append_int(b, cstates[j]);
buffer_append_string_len(b, CONST_STR_LEN("</td><td>&nbsp;&nbsp;"));
buffer_append_string_len(b, mod_status_get_short_state(j), 1);
buffer_append_string_len(b, CONST_STR_LEN(" = "));
buffer_append_string(b, mod_status_get_state(j));
buffer_append_str3(b, CONST_STR_LEN("</td><td>&nbsp;&nbsp;"),
mod_status_get_short_state(j), 1,
CONST_STR_LEN(" = "));
mod_status_append_state(b, j);
buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
}
buffer_append_string_len(b, CONST_STR_LEN(
@ -642,39 +587,24 @@ static handler_t mod_status_handle_server_status_html(server *srv, request_st *
static handler_t mod_status_handle_server_status_text(server *srv, request_st * const r, plugin_data *p) {
buffer *b = chunkqueue_append_buffer_open(&r->write_queue);
double avg;
char buf[32];
/* output total number of requests */
buffer_append_string_len(b, CONST_STR_LEN("Total Accesses: "));
avg = p->abs_requests;
snprintf(buf, sizeof(buf) - 1, "%.0f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN("\n"));
buffer_append_int(b, (intmax_t)p->abs_requests);
/* output total traffic out in kbytes */
buffer_append_string_len(b, CONST_STR_LEN("Total kBytes: "));
avg = p->abs_traffic_out / 1024;
snprintf(buf, sizeof(buf) - 1, "%.0f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN("\n"));
buffer_append_string_len(b, CONST_STR_LEN("\nTotal kBytes: "));
buffer_append_int(b, (intmax_t)(p->abs_traffic_out / 1024));
/* output uptime */
buffer_append_string_len(b, CONST_STR_LEN("Uptime: "));
buffer_append_string_len(b, CONST_STR_LEN("\nUptime: "));
buffer_append_int(b, log_epoch_secs - srv->startup_ts);
buffer_append_string_len(b, CONST_STR_LEN("\n"));
/* output busy servers */
buffer_append_string_len(b, CONST_STR_LEN("BusyServers: "));
buffer_append_string_len(b, CONST_STR_LEN("\nBusyServers: "));
buffer_append_int(b, srv->conns.used);
buffer_append_string_len(b, CONST_STR_LEN("\n"));
buffer_append_string_len(b, CONST_STR_LEN("IdleServers: "));
buffer_append_string_len(b, CONST_STR_LEN("\nIdleServers: "));
buffer_append_int(b, srv->conns.size - srv->conns.used);
buffer_append_string_len(b, CONST_STR_LEN("\n"));
/* output scoreboard */
buffer_append_string_len(b, CONST_STR_LEN("Scoreboard: "));
buffer_append_string_len(b, CONST_STR_LEN("\nScoreboard: "));
for (uint32_t i = 0; i < srv->conns.used; ++i) {
connection *c = srv->conns.ptr[i];
const request_st * const cr = &c->request;
@ -702,7 +632,6 @@ static handler_t mod_status_handle_server_status_text(server *srv, request_st *
static handler_t mod_status_handle_server_status_json(server *srv, request_st * const r, plugin_data *p) {
buffer *b = chunkqueue_append_buffer_open(&r->write_queue);
double avg;
char buf[32];
uint32_t j;
unsigned int jsonp = 0;
@ -715,37 +644,24 @@ static handler_t mod_status_handle_server_status_json(server *srv, request_st *
int len = 0;
while (light_isalnum(f[len]) || f[len] == '_') ++len;
if (0 != len && light_isalpha(f[0]) && f[len] == '\0') {
buffer_append_string_len(b, f, len);
buffer_append_string_len(b, CONST_STR_LEN("("));
buffer_append_str2(b, f, len, CONST_STR_LEN("("));
jsonp = 1;
}
}
/* output total number of requests */
buffer_append_string_len(b, CONST_STR_LEN("{\n\t\"RequestsTotal\": "));
avg = p->abs_requests;
snprintf(buf, sizeof(buf) - 1, "%.0f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN(",\n"));
buffer_append_int(b, (intmax_t)p->abs_requests);
/* output total traffic out in kbytes */
buffer_append_string_len(b, CONST_STR_LEN("\t\"TrafficTotal\": "));
avg = p->abs_traffic_out / 1024;
snprintf(buf, sizeof(buf) - 1, "%.0f", avg);
buffer_append_string(b, buf);
buffer_append_string_len(b, CONST_STR_LEN(",\n"));
buffer_append_string_len(b, CONST_STR_LEN(",\n\t\"TrafficTotal\": "));
buffer_append_int(b, (intmax_t)(p->abs_traffic_out / 1024));
/* output uptime */
buffer_append_string_len(b, CONST_STR_LEN("\t\"Uptime\": "));
buffer_append_string_len(b, CONST_STR_LEN(",\n\t\"Uptime\": "));
buffer_append_int(b, log_epoch_secs - srv->startup_ts);
buffer_append_string_len(b, CONST_STR_LEN(",\n"));
/* output busy servers */
buffer_append_string_len(b, CONST_STR_LEN("\t\"BusyServers\": "));
buffer_append_string_len(b, CONST_STR_LEN(",\n\t\"BusyServers\": "));
buffer_append_int(b, srv->conns.used);
buffer_append_string_len(b, CONST_STR_LEN(",\n"));
buffer_append_string_len(b, CONST_STR_LEN("\t\"IdleServers\": "));
buffer_append_string_len(b, CONST_STR_LEN(",\n\t\"IdleServers\": "));
buffer_append_int(b, srv->conns.size - srv->conns.used);
buffer_append_string_len(b, CONST_STR_LEN(",\n"));
@ -795,8 +711,8 @@ static handler_t mod_status_handle_server_statistics(request_st * const r) {
b = chunkqueue_append_buffer_open(&r->write_queue);
for (i = 0; i < st->used; i++) {
buffer_append_string_buffer(b, &st->sorted[i]->key);
buffer_append_string_len(b, CONST_STR_LEN(": "));
buffer_append_str2(b, CONST_BUF_LEN(&st->sorted[i]->key),
CONST_STR_LEN(": "));
buffer_append_int(b, ((data_integer *)st->sorted[i])->value);
buffer_append_string_len(b, CONST_STR_LEN("\n"));
}