]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/proto-back-monitor.h
multiple precision with BIGNUM/gmp/ulong
[openldap] / servers / slapd / back-monitor / proto-back-monitor.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2001-2004 The OpenLDAP Foundation.
5  * Portions Copyright 2001-2003 Pierangelo Masarati.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Pierangelo Masarati for inclusion
18  * in OpenLDAP Software.
19  */
20
21 #ifndef _PROTO_BACK_MONITOR
22 #define _PROTO_BACK_MONITOR
23
24 #include <ldap_cdefs.h>
25
26 #include "external.h"
27
28 LDAP_BEGIN_DECL
29
30 /*
31  * entry
32  */
33 int monitor_entry_test_flags LDAP_P(( struct monitorentrypriv *mp, int cond ));
34
35 /*
36  * backends
37  */
38 int monitor_subsys_backend_init LDAP_P(( BackendDB *be ));
39
40 /*
41  * databases 
42  */
43 int monitor_subsys_database_init LDAP_P(( BackendDB *be ));
44 int monitor_subsys_database_modify LDAP_P(( Operation *op, Entry *e ));
45
46 /*
47  * threads
48  */
49 int monitor_subsys_thread_init LDAP_P(( BackendDB *be ));
50 int monitor_subsys_thread_update LDAP_P(( Operation *op, Entry *e ));
51
52 /*
53  * connections
54  */
55 int monitor_subsys_conn_init LDAP_P(( BackendDB *be ));
56 int monitor_subsys_conn_update LDAP_P(( Operation *op, Entry *e ));
57 int monitor_subsys_conn_create LDAP_P(( Operation *op, struct berval *ndn,
58                         Entry *e_parent, Entry **ep ));
59
60 /*
61  * waiters
62  */
63 int monitor_subsys_rww_init LDAP_P(( BackendDB *be ));
64 int monitor_subsys_rww_update LDAP_P(( Operation *op, Entry *e ));
65
66 /*
67  * log
68  */
69 int monitor_subsys_log_init LDAP_P(( BackendDB *be ));
70 int monitor_subsys_log_modify LDAP_P(( Operation *op, Entry *e ));
71
72 /*
73  * operations
74  */
75 int monitor_subsys_ops_init LDAP_P(( BackendDB *be ));
76 int monitor_subsys_ops_update LDAP_P(( Operation *op, Entry *e ));
77
78 /*
79  * overlay
80  */
81 int monitor_subsys_overlay_init LDAP_P(( BackendDB *be ));
82
83 /*
84  * sent
85  */
86 int monitor_subsys_sent_init LDAP_P(( BackendDB *be ));
87 int monitor_subsys_sent_update LDAP_P(( Operation *op, Entry *e ));
88
89 /*
90  * listener
91  */
92 int monitor_subsys_listener_init LDAP_P(( BackendDB *be ));
93
94 /*
95  * time
96  */
97 int monitor_subsys_time_init LDAP_P(( BackendDB *be ));
98 int monitor_subsys_time_update LDAP_P(( Operation *op, Entry *e ));
99
100 /* NOTE: this macro assumes that bv has been allocated
101  * by ber_* malloc functions or is { 0L, NULL } */
102 #if defined(HAVE_BIGNUM)
103 #define UI2BV(bv,ui) \
104         do { \
105                 char            *val; \
106                 ber_len_t       len; \
107                 val = BN_bn2dec(ui); \
108                 if (val) { \
109                         len = strlen(val); \
110                         if ( len > (bv)->bv_len ) { \
111                                 (bv)->bv_val = ber_memrealloc( (bv)->bv_val, len + 1 ); \
112                         } \
113                         AC_MEMCPY((bv)->bv_val, val, len + 1); \
114                         (bv)->bv_len = len; \
115                         OPENSSL_free(val); \
116                 } else { \
117                         ber_memfree( (bv)->bv_val ); \
118                         BER_BVZERO( (bv) ); \
119                 } \
120         } while ( 0 )
121 #elif defined(HAVE_GMP)
122 /* NOTE: according to the documentation, the result 
123  * of mpz_sizeinbase() can exceed the length of the
124  * string representation of the number by 1
125  */
126 #define UI2BV(bv,ui) \
127         do { \
128                 ber_len_t       len = mpz_sizeinbase( (ui), 10 ); \
129                 if ( len > (bv)->bv_len ) { \
130                         (bv)->bv_val = ber_memrealloc( (bv)->bv_val, len + 1 ); \
131                 } \
132                 (void)mpz_get_str( (bv)->bv_val, 10, (ui) ); \
133                 if ( (bv)->bv_val[ len - 1 ] == '\0' ) { \
134                         len--; \
135                 } \
136                 (bv)->bv_len = len; \
137         } while ( 0 )
138 #else /* ! HAVE_BIGNUM && ! HAVE_GMP */
139 #define UI2BV(bv,ui) \
140         do { \
141                 char            buf[] = "+9223372036854775807L"; \
142                 ber_len_t       len; \
143                 snprintf( buf, sizeof( buf ), "%lu", (ui) ); \
144                 len = strlen( buf ); \
145                 if ( len > (bv)->bv_len ) { \
146                         (bv)->bv_val = ber_memrealloc( (bv)->bv_val, len + 1 ); \
147                 } \
148                 AC_MEMCPY( (bv)->bv_val, buf, len + 1 ); \
149         } while ( 0 )
150 #endif /* ! HAVE_GMP */
151
152 LDAP_END_DECL
153
154 #endif /* _PROTO_BACK_MONITOR */
155