From: Willy Tarreau Date: Mon, 29 Oct 2012 15:14:26 +0000 (+0100) Subject: CLEANUP: replace chunk_printf() with chunk_appendf() X-Git-Tag: v1.5-dev13~88 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7780473c3bbb7359d5d2861eb8421f9db24d70cd;p=thirdparty%2Fhaproxy.git CLEANUP: replace chunk_printf() with chunk_appendf() This function's naming was misleading as it is used to append data at the end of a string, causing some surprizes when used for the first time! Add a chunk_printf() function which does what its name suggests. --- diff --git a/include/common/chunk.h b/include/common/chunk.h index e7d6040f2a..191f9e75dc 100644 --- a/include/common/chunk.h +++ b/include/common/chunk.h @@ -40,6 +40,9 @@ struct chunk { int chunk_printf(struct chunk *chk, const char *fmt, ...) __attribute__ ((format(printf, 2, 3))); +int chunk_appendf(struct chunk *chk, const char *fmt, ...) + __attribute__ ((format(printf, 2, 3))); + int chunk_htmlencode(struct chunk *dst, struct chunk *src); int chunk_asciiencode(struct chunk *dst, struct chunk *src, char qc); int chunk_strcmp(const struct chunk *chk, const char *str); diff --git a/src/checks.c b/src/checks.c index 0c385cae57..8e4954936c 100644 --- a/src/checks.c +++ b/src/checks.c @@ -151,39 +151,39 @@ const char *get_analyze_status(short analyze_status) { static void server_status_printf(struct chunk *msg, struct server *s, unsigned options, int xferred) { if (s->track) - chunk_printf(msg, " via %s/%s", + chunk_appendf(msg, " via %s/%s", s->track->proxy->id, s->track->id); if (options & SSP_O_HCHK) { - chunk_printf(msg, ", reason: %s", get_check_status_description(s->check.status)); + chunk_appendf(msg, ", reason: %s", get_check_status_description(s->check.status)); if (s->check.status >= HCHK_STATUS_L57DATA) - chunk_printf(msg, ", code: %d", s->check.code); + chunk_appendf(msg, ", code: %d", s->check.code); if (*s->check.desc) { struct chunk src; - chunk_printf(msg, ", info: \""); + chunk_appendf(msg, ", info: \""); chunk_initlen(&src, s->check.desc, 0, strlen(s->check.desc)); chunk_asciiencode(msg, &src, '"'); - chunk_printf(msg, "\""); + chunk_appendf(msg, "\""); } if (s->check.duration >= 0) - chunk_printf(msg, ", check duration: %ldms", s->check.duration); + chunk_appendf(msg, ", check duration: %ldms", s->check.duration); } if (xferred >= 0) { if (!(s->state & SRV_RUNNING)) - chunk_printf(msg, ". %d active and %d backup servers left.%s" + chunk_appendf(msg, ". %d active and %d backup servers left.%s" " %d sessions active, %d requeued, %d remaining in queue", s->proxy->srv_act, s->proxy->srv_bck, (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", s->cur_sess, xferred, s->nbpend); else - chunk_printf(msg, ". %d active and %d backup servers online.%s" + chunk_appendf(msg, ". %d active and %d backup servers online.%s" " %d sessions requeued, %d total in queue", s->proxy->srv_act, s->proxy->srv_bck, (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", @@ -274,7 +274,7 @@ static void set_server_check_status(struct server *s, short status, char *desc) } /* FIXME end: calculate local version of the health/rise/fall/state */ - chunk_printf(&msg, + chunk_appendf(&msg, "Health check for %sserver %s/%s %s%s", s->state & SRV_BACKUP ? "backup " : "", s->proxy->id, s->id, @@ -283,7 +283,7 @@ static void set_server_check_status(struct server *s, short status, char *desc) server_status_printf(&msg, s, SSP_O_HCHK, -1); - chunk_printf(&msg, ", status: %d/%d %s", + chunk_appendf(&msg, ", status: %d/%d %s", (state & SRV_RUNNING) ? (health - rise + 1) : (health), (state & SRV_RUNNING) ? (fall) : (rise), (state & SRV_RUNNING)?"UP":"DOWN"); @@ -421,11 +421,11 @@ void set_server_down(struct server *s) chunk_init(&msg, trash, global.tune.bufsize); if (s->state & SRV_MAINTAIN) { - chunk_printf(&msg, + chunk_appendf(&msg, "%sServer %s/%s is DOWN for maintenance", s->state & SRV_BACKUP ? "Backup " : "", s->proxy->id, s->id); } else { - chunk_printf(&msg, + chunk_appendf(&msg, "%sServer %s/%s is DOWN", s->state & SRV_BACKUP ? "Backup " : "", s->proxy->id, s->id); @@ -513,11 +513,11 @@ void set_server_up(struct server *s) { chunk_init(&msg, trash, global.tune.bufsize); if (old_state & SRV_MAINTAIN) { - chunk_printf(&msg, + chunk_appendf(&msg, "%sServer %s/%s is UP (leaving maintenance)", s->state & SRV_BACKUP ? "Backup " : "", s->proxy->id, s->id); } else { - chunk_printf(&msg, + chunk_appendf(&msg, "%sServer %s/%s is UP", s->state & SRV_BACKUP ? "Backup " : "", s->proxy->id, s->id); @@ -559,7 +559,7 @@ static void set_server_disabled(struct server *s) { chunk_init(&msg, trash, global.tune.bufsize); - chunk_printf(&msg, + chunk_appendf(&msg, "Load-balancing on %sServer %s/%s is disabled", s->state & SRV_BACKUP ? "Backup " : "", s->proxy->id, s->id); @@ -596,7 +596,7 @@ static void set_server_enabled(struct server *s) { chunk_init(&msg, trash, global.tune.bufsize); - chunk_printf(&msg, + chunk_appendf(&msg, "Load-balancing on %sServer %s/%s is enabled again", s->state & SRV_BACKUP ? "Backup " : "", s->proxy->id, s->id); diff --git a/src/chunk.c b/src/chunk.c index 5b1552c5dc..d027569b43 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -18,12 +18,37 @@ #include #include +/* + * Does an snprintf() at the beginning of chunk , respecting the limit of + * at most chk->size chars. If the chk->len is over, nothing is added. Returns + * the new chunk size, or < 0 in case of failure. + */ +int chunk_printf(struct chunk *chk, const char *fmt, ...) +{ + va_list argp; + int ret; + + if (!chk->str || !chk->size) + return 0; + + va_start(argp, fmt); + ret = vsnprintf(chk->str, chk->size, fmt, argp); + va_end(argp); + chk->len = ret; + + if (ret >= chk->size) + ret = -1; + + chk->len = ret; + return chk->len; +} + /* * Does an snprintf() at the end of chunk , respecting the limit of * at most chk->size chars. If the chk->len is over, nothing is added. Returns * the new chunk size. */ -int chunk_printf(struct chunk *chk, const char *fmt, ...) +int chunk_appendf(struct chunk *chk, const char *fmt, ...) { va_list argp; int ret; diff --git a/src/dumpstats.c b/src/dumpstats.c index 0732e2a6e3..cdf0bbb2e1 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -339,7 +339,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx static int print_csv_header(struct chunk *msg) { - return chunk_printf(msg, + return chunk_appendf(msg, "# pxname,svname," "qcur,qmax," "scur,smax,slim,stot," @@ -433,13 +433,13 @@ static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_inte { struct session *s = si->conn->xprt_ctx; - chunk_printf(msg, "# table: %s, type: %s, size:%d, used:%d\n", + chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); /* any other information should be dumped here */ if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) - chunk_printf(msg, "# contents not dumped due to insufficient privileges\n"); + chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); if (bi_putchk(si->ib, msg) == -1) return 0; @@ -456,31 +456,31 @@ static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_int { int dt; - chunk_printf(msg, "%p:", entry); + chunk_appendf(msg, "%p:", entry); if (proxy->table.type == STKTABLE_TYPE_IP) { char addr[INET_ADDRSTRLEN]; inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); - chunk_printf(msg, " key=%s", addr); + chunk_appendf(msg, " key=%s", addr); } else if (proxy->table.type == STKTABLE_TYPE_IPV6) { char addr[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); - chunk_printf(msg, " key=%s", addr); + chunk_appendf(msg, " key=%s", addr); } else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { - chunk_printf(msg, " key=%u", *(unsigned int *)entry->key.key); + chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); } else if (proxy->table.type == STKTABLE_TYPE_STRING) { - chunk_printf(msg, " key="); + chunk_appendf(msg, " key="); dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); } else { - chunk_printf(msg, " key="); + chunk_appendf(msg, " key="); dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); } - chunk_printf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire)); + chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire)); for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { void *ptr; @@ -488,29 +488,29 @@ static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_int if (proxy->table.data_ofs[dt] == 0) continue; if (stktable_data_types[dt].arg_type == ARG_T_DELAY) - chunk_printf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u); + chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u); else - chunk_printf(msg, " %s=", stktable_data_types[dt].name); + chunk_appendf(msg, " %s=", stktable_data_types[dt].name); ptr = stktable_data_ptr(&proxy->table, entry, dt); switch (stktable_data_types[dt].std_type) { case STD_T_SINT: - chunk_printf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); + chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); break; case STD_T_UINT: - chunk_printf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); + chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); break; case STD_T_ULL: - chunk_printf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); + chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); break; case STD_T_FRQP: - chunk_printf(msg, "%d", + chunk_appendf(msg, "%d", read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), proxy->table.data_arg[dt].u)); break; } } - chunk_printf(msg, "\n"); + chunk_appendf(msg, "\n"); if (bi_putchk(si->ib, msg) == -1) return 0; @@ -1689,7 +1689,7 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si) case STAT_ST_INFO: up = (now.tv_sec - start_date.tv_sec); if (si->applet.ctx.stats.flags & STAT_SHOW_INFO) { - chunk_printf(&msg, + chunk_appendf(&msg, "Name: " PRODUCT_NAME "\n" "Version: " HAPROXY_VERSION "\n" "Release_date: " HAPROXY_DATE "\n" @@ -1788,7 +1788,7 @@ static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri) switch (si->conn->xprt_st) { case STAT_ST_INIT: - chunk_printf(&msg, + chunk_appendf(&msg, "HTTP/1.0 303 See Other\r\n" "Cache-Control: no-cache\r\n" "Content-Type: text/plain\r\n" @@ -1800,7 +1800,7 @@ static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri) stat_status_codes[si->applet.ctx.stats.st_code]) ? stat_status_codes[si->applet.ctx.stats.st_code] : stat_status_codes[STAT_STATUS_UNKN]); - chunk_printf(&msg, "\r\n\r\n"); + chunk_appendf(&msg, "\r\n\r\n"); if (bi_putchk(si->ib, &msg) == -1) return 0; @@ -1892,7 +1892,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) switch (si->conn->xprt_st) { case STAT_ST_INIT: - chunk_printf(&msg, + chunk_appendf(&msg, "HTTP/1.0 200 OK\r\n" "Cache-Control: no-cache\r\n" "Connection: close\r\n" @@ -1900,10 +1900,10 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) (si->applet.ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html"); if (uri->refresh > 0 && !(si->applet.ctx.stats.flags & STAT_NO_REFRESH)) - chunk_printf(&msg, "Refresh: %d\r\n", + chunk_appendf(&msg, "Refresh: %d\r\n", uri->refresh); - chunk_printf(&msg, "\r\n"); + chunk_appendf(&msg, "\r\n"); s->txn.status = 200; if (bi_putchk(rep, &msg) == -1) @@ -1926,7 +1926,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) case STAT_ST_HEAD: if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { /* WARNING! This must fit in the first buffer !!! */ - chunk_printf(&msg, + chunk_appendf(&msg, "\n" "Statistics Report for " PRODUCT_NAME "%s%s\n" @@ -2035,7 +2035,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) * become tricky if we want to support 4kB buffers ! */ if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { - chunk_printf(&msg, + chunk_appendf(&msg, "

" PRODUCT_NAME "%s

\n" "

Statistics Report for pid %d%s%s%s%s

\n" @@ -2084,13 +2084,13 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) ); if (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) - chunk_printf(&msg, + chunk_appendf(&msg, "
  • Show all servers
    \n", uri->uri_prefix, "", (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); else - chunk_printf(&msg, + chunk_appendf(&msg, "
  • Hide 'DOWN' servers
    \n", uri->uri_prefix, ";up", @@ -2098,31 +2098,31 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) if (uri->refresh > 0) { if (si->applet.ctx.stats.flags & STAT_NO_REFRESH) - chunk_printf(&msg, + chunk_appendf(&msg, "
  • Enable refresh
    \n", uri->uri_prefix, (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", ""); else - chunk_printf(&msg, + chunk_appendf(&msg, "
  • Disable refresh
    \n", uri->uri_prefix, (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", ";norefresh"); } - chunk_printf(&msg, + chunk_appendf(&msg, "
  • Refresh now
    \n", uri->uri_prefix, (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); - chunk_printf(&msg, + chunk_appendf(&msg, "
  • CSV export
    \n", uri->uri_prefix, (uri->refresh > 0) ? ";norefresh" : ""); - chunk_printf(&msg, + chunk_appendf(&msg, "" "" "External resources:
      \n" @@ -2138,21 +2138,21 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) if (si->applet.ctx.stats.st_code) { switch (si->applet.ctx.stats.st_code) { case STAT_STATUS_DONE: - chunk_printf(&msg, + chunk_appendf(&msg, "

      " "[X] " "Action processed successfully." "
      \n", uri->uri_prefix); break; case STAT_STATUS_NONE: - chunk_printf(&msg, + chunk_appendf(&msg, "

      " "[X] " "Nothing has changed." "
      \n", uri->uri_prefix); break; case STAT_STATUS_PART: - chunk_printf(&msg, + chunk_appendf(&msg, "

      " "[X] " "Action partially processed.
      " @@ -2160,7 +2160,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) "
      \n", uri->uri_prefix); break; case STAT_STATUS_ERRP: - chunk_printf(&msg, + chunk_appendf(&msg, "

      " "[X] " "Action not processed because of invalid parameters." @@ -2172,7 +2172,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) "
      \n", uri->uri_prefix); break; case STAT_STATUS_EXCD: - chunk_printf(&msg, + chunk_appendf(&msg, "

      " "[X] " "Action not processed : the buffer couldn't store all the data.
      " @@ -2180,20 +2180,20 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) "
      \n", uri->uri_prefix); break; case STAT_STATUS_DENY: - chunk_printf(&msg, + chunk_appendf(&msg, "

      " "[X] " "Action denied." "
      \n", uri->uri_prefix); break; default: - chunk_printf(&msg, + chunk_appendf(&msg, "

      " "[X] " "Unexpected result." "
      \n", uri->uri_prefix); } - chunk_printf(&msg,"

      \n"); + chunk_appendf(&msg,"

      \n"); } if (bi_putchk(rep, &msg) == -1) @@ -2226,7 +2226,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) case STAT_ST_END: if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { - chunk_printf(&msg, "\n"); + chunk_appendf(&msg, "\n"); if (bi_putchk(rep, &msg) == -1) return 0; } @@ -2299,27 +2299,27 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { /* A form to enable/disable this proxy servers */ - chunk_printf(&msg, + chunk_appendf(&msg, "

      ", uri->uri_prefix); } /* print a new table */ - chunk_printf(&msg, + chunk_appendf(&msg, "\n" "" "" "" @@ -2334,10 +2334,10 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { /* Column heading for Enable or Disable server */ - chunk_printf(&msg, ""); + chunk_appendf(&msg, ""); } - chunk_printf(&msg, + chunk_appendf(&msg, "" "" "" @@ -2368,16 +2368,16 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc if ((px->cap & PR_CAP_FE) && (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_FE)))) { if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { - chunk_printf(&msg, + chunk_appendf(&msg, /* name, queue */ ""); if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { /* Column sub-heading for Enable or Disable server */ - chunk_printf(&msg, ""); + chunk_appendf(&msg, ""); } - chunk_printf(&msg, + chunk_appendf(&msg, "" @@ -2386,7 +2386,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc px->id, px->id); if (px->mode == PR_MODE_HTTP) { - chunk_printf(&msg, + chunk_appendf(&msg, /* sessions rate : current, max, limit */ "" "", @@ -2396,7 +2396,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc U2H1(px->fe_counters.sps_max), LIM2A2(px->fe_sps_lim, "-")); } else { - chunk_printf(&msg, + chunk_appendf(&msg, /* sessions rate : current, max, limit */ "" "", @@ -2404,7 +2404,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc U2H1(px->fe_counters.sps_max), LIM2A2(px->fe_sps_lim, "-")); } - chunk_printf(&msg, + chunk_appendf(&msg, /* sessions: current, max, limit */ "" "mode == PR_MODE_HTTP) { int i; - chunk_printf(&msg, " title=\"%lld requests:", px->fe_counters.p.http.cum_req); + chunk_appendf(&msg, " title=\"%lld requests:", px->fe_counters.p.http.cum_req); for (i = 1; i < 6; i++) - chunk_printf(&msg, " %dxx=%lld,", i, px->fe_counters.p.http.rsp[i]); + chunk_appendf(&msg, " %dxx=%lld,", i, px->fe_counters.p.http.rsp[i]); - chunk_printf(&msg, " other=%lld,", px->fe_counters.p.http.rsp[0]); - chunk_printf(&msg, " intercepted=%lld\"", px->fe_counters.intercepted_req); + chunk_appendf(&msg, " other=%lld,", px->fe_counters.p.http.rsp[0]); + chunk_appendf(&msg, " intercepted=%lld\"", px->fe_counters.intercepted_req); } - chunk_printf(&msg, + chunk_appendf(&msg, /* sessions: total, lbtot */ ">%s%s%s" /* bytes : in, out */ @@ -2435,7 +2435,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc (px->mode == PR_MODE_HTTP)?"":"", U2H7(px->fe_counters.bytes_in), U2H8(px->fe_counters.bytes_out)); - chunk_printf(&msg, + chunk_appendf(&msg, /* denied: req, resp */ "" /* errors : request, connect, response */ @@ -2452,7 +2452,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP"); } else { - chunk_printf(&msg, + chunk_appendf(&msg, /* pxid, name, queue cur, queue max, */ "%s,FRONTEND,,," /* sessions : current, max, limit, total */ @@ -2491,26 +2491,26 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc int i; for (i=1; i<6; i++) - chunk_printf(&msg, "%lld,", px->fe_counters.p.http.rsp[i]); + chunk_appendf(&msg, "%lld,", px->fe_counters.p.http.rsp[i]); - chunk_printf(&msg, "%lld,", px->fe_counters.p.http.rsp[0]); + chunk_appendf(&msg, "%lld,", px->fe_counters.p.http.rsp[0]); } else { - chunk_printf(&msg, ",,,,,,"); + chunk_appendf(&msg, ",,,,,,"); } /* failed health analyses */ - chunk_printf(&msg, ","); + chunk_appendf(&msg, ","); /* requests : req_rate, req_rate_max, req_tot, */ - chunk_printf(&msg, "%u,%u,%lld,", + chunk_appendf(&msg, "%u,%u,%lld,", read_freq_ctr(&px->fe_req_per_sec), px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); /* errors: cli_aborts, srv_aborts */ - chunk_printf(&msg, ",,"); + chunk_appendf(&msg, ",,"); /* finish with EOL */ - chunk_printf(&msg, "\n"); + chunk_appendf(&msg, "\n"); } if (bi_putchk(rep, &msg) == -1) @@ -2540,40 +2540,40 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc } if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { - chunk_printf(&msg, ""); + chunk_appendf(&msg, ""); if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { /* Column sub-heading for Enable or Disable server */ - chunk_printf(&msg, ""); + chunk_appendf(&msg, ""); } - chunk_printf(&msg, "" @@ -2591,7 +2591,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn), U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out)); - chunk_printf(&msg, + chunk_appendf(&msg, /* denied: req, resp */ "" /* errors: request, connect, response */ @@ -2607,7 +2607,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc U2H2(l->counters->failed_req), (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); } else { - chunk_printf(&msg, + chunk_appendf(&msg, /* pxid, name, queue cur, queue max, */ "%s,%s,,," /* sessions: current, max, limit, total */ @@ -2710,67 +2710,67 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc "NOLB %d/%d ↓", "NOLB", "no check" }; if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) { - chunk_printf(&msg, + chunk_appendf(&msg, /* name */ "" ); } else { - chunk_printf(&msg, + chunk_appendf(&msg, /* name */ "", (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state); } if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { - chunk_printf(&msg, + chunk_appendf(&msg, "", sv->id); } - chunk_printf(&msg, "" /* queue : current, max, limit */ @@ -2792,15 +2792,15 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc if (px->mode == PR_MODE_HTTP) { int i; - chunk_printf(&msg, " title=\"rsp codes:"); + chunk_appendf(&msg, " title=\"rsp codes:"); for (i = 1; i < 6; i++) - chunk_printf(&msg, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]); + chunk_appendf(&msg, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]); - chunk_printf(&msg, " other=%lld\"", sv->counters.p.http.rsp[0]); + chunk_appendf(&msg, " other=%lld\"", sv->counters.p.http.rsp[0]); } - chunk_printf(&msg, + chunk_appendf(&msg, /* sessions: total, lbtot */ ">%s%s%s", (px->mode == PR_MODE_HTTP)?"":"", @@ -2808,7 +2808,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc (px->mode == PR_MODE_HTTP)?"":"", U2H1(sv->counters.cum_lbconn)); - chunk_printf(&msg, + chunk_appendf(&msg, /* bytes : in, out */ "" /* denied: req, resp */ @@ -2829,54 +2829,54 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc sv->counters.retries, sv->counters.redispatches); /* status, lest check */ - chunk_printf(&msg, "" /* act, bck */ @@ -2888,23 +2888,23 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc /* check failures: unique, fatal, down time */ if (sv->state & SRV_CHECKED) { - chunk_printf(&msg, "" "" "", svs->counters.down_trans, human_time(srv_downtime(sv), 1)); } else if (sv != svs) - chunk_printf(&msg, + chunk_appendf(&msg, "", svs->proxy->id, svs->id, svs->proxy->id, svs->id); else - chunk_printf(&msg, + chunk_appendf(&msg, ""); /* throttle */ @@ -2913,10 +2913,10 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc now.tv_sec >= sv->last_change) { unsigned int ratio; ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); - chunk_printf(&msg, + chunk_appendf(&msg, "\n", ratio); } else { - chunk_printf(&msg, + chunk_appendf(&msg, "\n"); } } else { @@ -2924,7 +2924,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc "UP %d/%d,", "UP,", "NOLB %d/%d,", "NOLB,", "no check," }; - chunk_printf(&msg, + chunk_appendf(&msg, /* pxid, name */ "%s,%s," /* queue : current, max */ @@ -2950,19 +2950,19 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc /* status */ if (sv->state & SRV_MAINTAIN) { - chunk_printf(&msg, "MAINT,"); + chunk_appendf(&msg, "MAINT,"); } else if (svs != sv && svs->state & SRV_MAINTAIN) { - chunk_printf(&msg, "MAINT(via),"); + chunk_appendf(&msg, "MAINT(via),"); } else { - chunk_printf(&msg, + chunk_appendf(&msg, srv_hlt_st[sv_state], (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); } - chunk_printf(&msg, + chunk_appendf(&msg, /* weight, active, backup */ "%d,%d,%d," "", @@ -2972,16 +2972,16 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc /* check failures: unique, fatal; last change, total downtime */ if (sv->state & SRV_CHECKED) - chunk_printf(&msg, + chunk_appendf(&msg, "%lld,%lld,%d,%d,", sv->counters.failed_checks, sv->counters.down_trans, (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); else - chunk_printf(&msg, + chunk_appendf(&msg, ",,,,"); /* queue limit, pid, iid, sid, */ - chunk_printf(&msg, + chunk_appendf(&msg, "%s," "%d,%d,%d,", LIM2A0(sv->maxqueue, ""), @@ -2993,45 +2993,45 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc now.tv_sec >= sv->last_change) { unsigned int ratio; ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); - chunk_printf(&msg, "%d", ratio); + chunk_appendf(&msg, "%d", ratio); } /* sessions: lbtot */ - chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn); + chunk_appendf(&msg, ",%lld,", sv->counters.cum_lbconn); /* tracked */ if (sv->track) - chunk_printf(&msg, "%s/%s,", + chunk_appendf(&msg, "%s/%s,", sv->track->proxy->id, sv->track->id); else - chunk_printf(&msg, ","); + chunk_appendf(&msg, ","); /* type */ - chunk_printf(&msg, "%d,", STATS_TYPE_SV); + chunk_appendf(&msg, "%d,", STATS_TYPE_SV); /* rate */ - chunk_printf(&msg, "%u,,%u,", + chunk_appendf(&msg, "%u,,%u,", read_freq_ctr(&sv->sess_per_sec), sv->counters.sps_max); if (sv->state & SRV_CHECKED) { /* check_status */ - chunk_printf(&msg, "%s,", get_check_status_info(sv->check.status)); + chunk_appendf(&msg, "%s,", get_check_status_info(sv->check.status)); /* check_code */ if (sv->check.status >= HCHK_STATUS_L57DATA) - chunk_printf(&msg, "%u,", sv->check.code); + chunk_appendf(&msg, "%u,", sv->check.code); else - chunk_printf(&msg, ","); + chunk_appendf(&msg, ","); /* check_duration */ if (sv->check.status >= HCHK_STATUS_CHECKED) - chunk_printf(&msg, "%lu,", sv->check.duration); + chunk_appendf(&msg, "%lu,", sv->check.duration); else - chunk_printf(&msg, ","); + chunk_appendf(&msg, ","); } else { - chunk_printf(&msg, ",,,"); + chunk_appendf(&msg, ",,,"); } /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ @@ -3039,25 +3039,25 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc int i; for (i=1; i<6; i++) - chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[i]); + chunk_appendf(&msg, "%lld,", sv->counters.p.http.rsp[i]); - chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[0]); + chunk_appendf(&msg, "%lld,", sv->counters.p.http.rsp[0]); } else { - chunk_printf(&msg, ",,,,,,"); + chunk_appendf(&msg, ",,,,,,"); } /* failed health analyses */ - chunk_printf(&msg, "%lld,", sv->counters.failed_hana); + chunk_appendf(&msg, "%lld,", sv->counters.failed_hana); /* requests : req_rate, req_rate_max, req_tot, */ - chunk_printf(&msg, ",,,"); + chunk_appendf(&msg, ",,,"); /* errors: cli_aborts, srv_aborts */ - chunk_printf(&msg, "%lld,%lld,", + chunk_appendf(&msg, "%lld,%lld,", sv->counters.cli_aborts, sv->counters.srv_aborts); /* finish with EOL */ - chunk_printf(&msg, "\n"); + chunk_appendf(&msg, "\n"); } if (bi_putchk(rep, &msg) == -1) return 0; @@ -3071,35 +3071,35 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc if ((px->cap & PR_CAP_BE) && (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))) { if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { - chunk_printf(&msg, ""); + chunk_appendf(&msg, ""); if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { /* Column sub-heading for Enable or Disable server */ - chunk_printf(&msg, ""); + chunk_appendf(&msg, ""); } - chunk_printf(&msg, "" @@ -3114,7 +3114,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->be_counters.nbpend_max), U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_counters.sps_max)); - chunk_printf(&msg, + chunk_appendf(&msg, /* sessions: current, max, limit */ "" "mode == PR_MODE_HTTP) { int i; - chunk_printf(&msg, " title=\"rsp codes:"); + chunk_appendf(&msg, " title=\"rsp codes:"); for (i = 1; i < 6; i++) - chunk_printf(&msg, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]); + chunk_appendf(&msg, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]); - chunk_printf(&msg, " other=%lld\"", px->be_counters.p.http.rsp[0]); + chunk_appendf(&msg, " other=%lld\"", px->be_counters.p.http.rsp[0]); } - chunk_printf(&msg, + chunk_appendf(&msg, /* sessions: total, lbtot */ ">%s%s%s" /* bytes: in, out */ @@ -3145,7 +3145,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc U2H7(px->be_counters.cum_lbconn), U2H8(px->be_counters.bytes_in), U2H9(px->be_counters.bytes_out)); - chunk_printf(&msg, + chunk_appendf(&msg, /* denied: req, resp */ "" /* errors : request, connect */ @@ -3173,7 +3173,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, px->srv_act, px->srv_bck); - chunk_printf(&msg, + chunk_appendf(&msg, /* rest of backend: nothing, down transitions, total downtime, throttle */ "" "" @@ -3182,7 +3182,7 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc px->down_trans, px->srv?human_time(be_downtime(px), 1):" "); } else { - chunk_printf(&msg, + chunk_appendf(&msg, /* pxid, name */ "%s,BACKEND," /* queue : current, max */ @@ -3233,25 +3233,25 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc int i; for (i=1; i<6; i++) - chunk_printf(&msg, "%lld,", px->be_counters.p.http.rsp[i]); + chunk_appendf(&msg, "%lld,", px->be_counters.p.http.rsp[i]); - chunk_printf(&msg, "%lld,", px->be_counters.p.http.rsp[0]); + chunk_appendf(&msg, "%lld,", px->be_counters.p.http.rsp[0]); } else { - chunk_printf(&msg, ",,,,,,"); + chunk_appendf(&msg, ",,,,,,"); } /* failed health analyses */ - chunk_printf(&msg, ","); + chunk_appendf(&msg, ","); /* requests : req_rate, req_rate_max, req_tot, */ - chunk_printf(&msg, ",,,"); + chunk_appendf(&msg, ",,,"); /* errors: cli_aborts, srv_aborts */ - chunk_printf(&msg, "%lld,%lld,", + chunk_appendf(&msg, "%lld,%lld,", px->be_counters.cli_aborts, px->be_counters.srv_aborts); /* finish with EOL */ - chunk_printf(&msg, "\n"); + chunk_appendf(&msg, "\n"); } if (bi_putchk(rep, &msg) == -1) @@ -3263,11 +3263,11 @@ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struc case STAT_PX_ST_END: if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { - chunk_printf(&msg, "
      flags&ST_SHLGNDS) { /* cap, mode, id */ - chunk_printf(&msg, " title=\"cap: %s, mode: %s, id: %d", + chunk_appendf(&msg, " title=\"cap: %s, mode: %s, id: %d", proxy_cap_str(px->cap), proxy_mode_str(px->mode), px->uuid); - chunk_printf(&msg, "\""); + chunk_appendf(&msg, "\""); } - chunk_printf(&msg, + chunk_appendf(&msg, ">%s" "%s%s%sQueueSession rateSessions
      " "" "Frontend%s%s%s%s%s%s%s%s%s%s%s
      flags&ST_SHLGNDS) { char str[INET6_ADDRSTRLEN]; int port; - chunk_printf(&msg, " title=\""); + chunk_appendf(&msg, " title=\""); port = get_host_port(&l->addr); switch (addr_to_str(&l->addr, str, sizeof(str))) { case AF_INET: - chunk_printf(&msg, "IPv4: %s:%d, ", str, port); + chunk_appendf(&msg, "IPv4: %s:%d, ", str, port); break; case AF_INET6: - chunk_printf(&msg, "IPv6: [%s]:%d, ", str, port); + chunk_appendf(&msg, "IPv6: [%s]:%d, ", str, port); break; case AF_UNIX: - chunk_printf(&msg, "unix, "); + chunk_appendf(&msg, "unix, "); break; case -1: - chunk_printf(&msg, "(%s), ", strerror(errno)); + chunk_appendf(&msg, "(%s), ", strerror(errno)); break; } /* id */ - chunk_printf(&msg, "id: %d\"", l->luid); + chunk_appendf(&msg, "id: %d\"", l->luid); } - chunk_printf(&msg, + chunk_appendf(&msg, /* name, queue */ ">%s" "%s%s%s%s
      flags&ST_SHLGNDS) { char str[INET6_ADDRSTRLEN]; - chunk_printf(&msg, " title=\""); + chunk_appendf(&msg, " title=\""); switch (addr_to_str(&sv->addr, str, sizeof(str))) { case AF_INET: - chunk_printf(&msg, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); + chunk_appendf(&msg, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); break; case AF_INET6: - chunk_printf(&msg, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); + chunk_appendf(&msg, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); break; case AF_UNIX: - chunk_printf(&msg, "unix, "); + chunk_appendf(&msg, "unix, "); break; case -1: - chunk_printf(&msg, "(%s), ", strerror(errno)); + chunk_appendf(&msg, "(%s), ", strerror(errno)); break; default: /* address family not supported */ break; } /* id */ - chunk_printf(&msg, "id: %d", sv->puid); + chunk_appendf(&msg, "id: %d", sv->puid); /* cookie */ if (sv->cookie) { struct chunk src; - chunk_printf(&msg, ", cookie: '"); + chunk_appendf(&msg, ", cookie: '"); chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); chunk_htmlencode(&msg, &src); - chunk_printf(&msg, "'"); + chunk_appendf(&msg, "'"); } - chunk_printf(&msg, "\""); + chunk_appendf(&msg, "\""); } - chunk_printf(&msg, + chunk_appendf(&msg, ">%s" "%s%s%s%s%s"); + chunk_appendf(&msg, ""); if (sv->state & SRV_MAINTAIN) { - chunk_printf(&msg, "%s ", + chunk_appendf(&msg, "%s ", human_time(now.tv_sec - sv->last_change, 1)); - chunk_printf(&msg, "MAINT"); + chunk_appendf(&msg, "MAINT"); } else if (svs != sv && svs->state & SRV_MAINTAIN) { - chunk_printf(&msg, "%s ", + chunk_appendf(&msg, "%s ", human_time(now.tv_sec - svs->last_change, 1)); - chunk_printf(&msg, "MAINT(via)"); + chunk_appendf(&msg, "MAINT(via)"); } else if (svs->state & SRV_CHECKED) { - chunk_printf(&msg, "%s ", + chunk_appendf(&msg, "%s ", human_time(now.tv_sec - svs->last_change, 1)); - chunk_printf(&msg, + chunk_appendf(&msg, srv_hlt_st[sv_state], (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); } if (sv->state & SRV_CHECKED) { - chunk_printf(&msg, "check.status)); if (*sv->check.desc) { struct chunk src; - chunk_printf(&msg, ": "); + chunk_appendf(&msg, ": "); chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); chunk_htmlencode(&msg, &src); } - chunk_printf(&msg, "\"> %s%s", + chunk_appendf(&msg, "\"> %s%s", tv_iszero(&sv->check.start)?"":"* ", get_check_status_info(sv->check.status)); if (sv->check.status >= HCHK_STATUS_L57DATA) - chunk_printf(&msg, "/%d", sv->check.code); + chunk_appendf(&msg, "/%d", sv->check.code); if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) - chunk_printf(&msg, " in %lums", sv->check.duration); + chunk_appendf(&msg, " in %lums", sv->check.duration); } else - chunk_printf(&msg, ""); + chunk_appendf(&msg, ""); - chunk_printf(&msg, + chunk_appendf(&msg, /* weight */ "%d%lld", + chunk_appendf(&msg, "%lld", svs->observe?"/Health Analyses":"", svs->counters.failed_checks); if (svs->observe) - chunk_printf(&msg, "/%lld", svs->counters.failed_hana); + chunk_appendf(&msg, "/%lld", svs->counters.failed_hana); - chunk_printf(&msg, + chunk_appendf(&msg, "%lld%svia %s/%s%d %%
      -
      flags&ST_SHLGNDS) { /* balancing */ - chunk_printf(&msg, " title=\"balancing: %s", + chunk_appendf(&msg, " title=\"balancing: %s", backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); /* cookie */ if (px->cookie_name) { struct chunk src; - chunk_printf(&msg, ", cookie: '"); + chunk_appendf(&msg, ", cookie: '"); chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); chunk_htmlencode(&msg, &src); - chunk_printf(&msg, "'"); + chunk_appendf(&msg, "'"); } - chunk_printf(&msg, "\""); + chunk_appendf(&msg, "\""); } - chunk_printf(&msg, + chunk_appendf(&msg, /* name */ ">%s" "Backend%s%s%s%s%s%s%s %d%s
      "); + chunk_appendf(&msg, ""); if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { /* close the form used to enable/disable this proxy servers */ - chunk_printf(&msg, + chunk_appendf(&msg, "Choose the action to perform on the checked servers : " "