~ubuntu-branches/ubuntu/hardy/lighttpd/hardy-updates

« back to all changes in this revision

Viewing changes to src/status_counter.c

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-10-10 13:57:38 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061010135738-gn4pp1ut1s1g27pb
Tags: 1.4.13~r1370-1ubuntu1
* Merge from Debian unstable (Closes: Malone #64900). Remaining changes:
  - Add an additional dependency on libterm-readline-perl-perl
    (Malone #43895)

Show diffs side-by-side

added added

removed removed

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