[core] avoid spurious trace and error abort
[lighttpd.git] / src / status_counter.c
blob0dc267c9c84b8b9cb2bead9f4e18b7523a492fae
1 #include "first.h"
3 #include "status_counter.h"
5 #include <stdlib.h>
7 /**
8 * The status array can carry all the status information you want
9 * the key to the array is <module-prefix>.<name>
10 * and the values are counters
12 * example:
13 * fastcgi.backends = 10
14 * fastcgi.active-backends = 6
15 * fastcgi.backend.<key>.load = 24
16 * fastcgi.backend.<key>....
18 * fastcgi.backend.<key>.disconnects = ...
21 data_integer *status_counter_get_counter(server *srv, const char *s, size_t len) {
22 data_integer *di;
24 if (NULL == (di = (data_integer *)array_get_element(srv->status, s))) {
25 /* not found, create it */
27 if (NULL == (di = (data_integer *)array_get_unused_element(srv->status, TYPE_INTEGER))) {
28 di = data_integer_init();
30 buffer_copy_string_len(di->key, s, len);
31 di->value = 0;
33 array_insert_unique(srv->status, (data_unset *)di);
35 return di;
38 /* dummies of the statistic framework functions
39 * they will be moved to a statistics.c later */
40 int status_counter_inc(server *srv, const char *s, size_t len) {
41 data_integer *di = status_counter_get_counter(srv, s, len);
43 di->value++;
45 return 0;
48 int status_counter_dec(server *srv, const char *s, size_t len) {
49 data_integer *di = status_counter_get_counter(srv, s, len);
51 if (di->value > 0) di->value--;
53 return 0;
56 int status_counter_set(server *srv, const char *s, size_t len, int val) {
57 data_integer *di = status_counter_get_counter(srv, s, len);
59 di->value = val;
61 return 0;