Annotation of embedaddon/lighttpd/src/status_counter.c, revision 1.1.1.1

1.1       misho       1: #include "status_counter.h"
                      2: 
                      3: #include <stdlib.h>
                      4: 
                      5: /**
                      6:  * The status array can carry all the status information you want
                      7:  * the key to the array is <module-prefix>.<name>
                      8:  * and the values are counters
                      9:  *
                     10:  * example:
                     11:  *   fastcgi.backends        = 10
                     12:  *   fastcgi.active-backends = 6
                     13:  *   fastcgi.backend.<key>.load = 24
                     14:  *   fastcgi.backend.<key>....
                     15:  *
                     16:  *   fastcgi.backend.<key>.disconnects = ...
                     17:  */
                     18: 
                     19: data_integer *status_counter_get_counter(server *srv, const char *s, size_t len) {
                     20:        data_integer *di;
                     21: 
                     22:        if (NULL == (di = (data_integer *)array_get_element(srv->status, s))) {
                     23:                /* not found, create it */
                     24: 
                     25:                if (NULL == (di = (data_integer *)array_get_unused_element(srv->status, TYPE_INTEGER))) {
                     26:                        di = data_integer_init();
                     27:                }
                     28:                buffer_copy_string_len(di->key, s, len);
                     29:                di->value = 0;
                     30: 
                     31:                array_insert_unique(srv->status, (data_unset *)di);
                     32:        }
                     33:        return di;
                     34: }
                     35: 
                     36: /* dummies of the statistic framework functions
                     37:  * they will be moved to a statistics.c later */
                     38: int status_counter_inc(server *srv, const char *s, size_t len) {
                     39:        data_integer *di = status_counter_get_counter(srv, s, len);
                     40: 
                     41:        di->value++;
                     42: 
                     43:        return 0;
                     44: }
                     45: 
                     46: int status_counter_dec(server *srv, const char *s, size_t len) {
                     47:        data_integer *di = status_counter_get_counter(srv, s, len);
                     48: 
                     49:        if (di->value > 0) di->value--;
                     50: 
                     51:        return 0;
                     52: }
                     53: 
                     54: int status_counter_set(server *srv, const char *s, size_t len, int val) {
                     55:        data_integer *di = status_counter_get_counter(srv, s, len);
                     56: 
                     57:        di->value = val;
                     58: 
                     59:        return 0;
                     60: }
                     61: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>