]> git.sur5r.net Git - openldap/blob - contrib/slapd-modules/trace/trace.c
trace overlay: traces overlay execution
[openldap] / contrib / slapd-modules / trace / trace.c
1 /* trace.c - traces overlay invocation */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2006 The OpenLDAP Foundation.
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 the 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 in
18  * OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #ifdef SLAPD_OVER_TRACE
24
25 #include <stdio.h>
26
27 #include <ac/string.h>
28 #include <ac/socket.h>
29
30 #include "slap.h"
31 #include "lutil.h"
32
33 static int
34 trace_op2str( Operation *op, char **op_strp, char **op_oidp )
35 {
36         *op_oidp = "";
37
38         switch ( op->o_tag ) {
39         case LDAP_REQ_BIND:
40                 *op_strp = "BIND";
41                 break;
42
43         case LDAP_REQ_UNBIND:
44                 *op_strp = "UNBIND";
45                 break;
46
47         case LDAP_REQ_SEARCH:
48                 *op_strp = "SEARCH";
49                 break;
50
51         case LDAP_REQ_MODIFY:
52                 *op_strp = "MODIFY";
53                 break;
54
55         case LDAP_REQ_ADD:
56                 *op_strp = "ADD";
57                 break;
58
59         case LDAP_REQ_DELETE:
60                 *op_strp = "DELETE";
61                 break;
62
63         case LDAP_REQ_MODRDN:
64                 *op_strp = "MODRDN";
65                 break;
66
67         case LDAP_REQ_COMPARE:
68                 *op_strp = "COMPARE";
69                 break;
70
71         case LDAP_REQ_ABANDON:
72                 *op_strp = "ABANDON";
73                 break;
74
75         case LDAP_REQ_EXTENDED:
76                 *op_strp = "EXTENDED";
77                 *op_oidp = op->ore_reqoid.bv_val;
78                 break;
79
80         default:
81                 assert( 0 );
82         }
83
84         return 0;
85 }
86
87 static int
88 trace_op_func( Operation *op, SlapReply *rs )
89 {
90         char    *op_str = NULL;
91         char    *op_oid = "";
92
93         (void)trace_op2str( op, &op_str, &op_oid );
94
95         Log4( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
96                 "%s trace op=%s oid=%s dn=\"%s\"\n",
97                 op->o_log_prefix, op_str, op_oid,
98                 BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val );
99
100         return SLAP_CB_CONTINUE;
101 }
102
103 static int
104 trace_response( Operation *op, SlapReply *rs )
105 {
106         char    *op_str = NULL;
107         char    *op_oid = "";
108
109         (void)trace_op2str( op, &op_str, &op_oid );
110
111         Log5( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
112                 "%s trace op=%s RESPONSE oid=%s dn=\"%s\" err=%d\n",
113                 op->o_log_prefix, op_str, op_oid,
114                 BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val,
115                 rs->sr_err );
116
117         return SLAP_CB_CONTINUE;
118 }
119
120 static int
121 trace_db_init(
122         BackendDB *be )
123 {
124         Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
125                 "trace DB_INIT\n" );
126
127         return 0;
128 }
129
130 static int
131 trace_db_config(
132         BackendDB       *be,
133         const char      *fname,
134         int             lineno,
135         int             argc,
136         char            **argv )
137 {
138         Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
139                 "trace DB_CONFIG argc=%d argv[0]=\"%s\"\n",
140                 argc, argv[ 0 ] );
141
142         return 0;
143 }
144
145 static int
146 trace_db_open(
147         BackendDB *be )
148 {
149         Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
150                 "trace DB_OPEN\n" );
151
152         return 0;
153 }
154
155 static int
156 trace_db_close(
157         BackendDB *be )
158 {
159         Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
160                 "trace DB_CLOSE\n" );
161
162         return 0;
163 }
164
165 static int
166 trace_db_destroy(
167         BackendDB *be )
168 {
169         Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
170                 "trace DB_DESTROY\n" );
171
172         return 0;
173 }
174
175 static slap_overinst            trace;
176
177 int
178 trace_initialize()
179 {
180         trace.on_bi.bi_type = "trace";
181
182         trace.on_bi.bi_db_init = trace_db_init;
183         trace.on_bi.bi_db_open = trace_db_open;
184         trace.on_bi.bi_db_config = trace_db_config;
185         trace.on_bi.bi_db_close = trace_db_close;
186         trace.on_bi.bi_db_destroy = trace_db_destroy;
187
188         trace.on_bi.bi_op_add = trace_op_func;
189         trace.on_bi.bi_op_bind = trace_op_func;
190         trace.on_bi.bi_op_unbind = trace_op_func;
191         trace.on_bi.bi_op_compare = trace_op_func;
192         trace.on_bi.bi_op_delete = trace_op_func;
193         trace.on_bi.bi_op_modify = trace_op_func;
194         trace.on_bi.bi_op_modrdn = trace_op_func;
195         trace.on_bi.bi_op_search = trace_op_func;
196         trace.on_bi.bi_op_abandon = trace_op_func;
197         trace.on_bi.bi_extended = trace_op_func;
198
199         trace.on_response = trace_response;
200
201         return overlay_register( &trace );
202 }
203
204 #if SLAPD_OVER_TRACE == SLAPD_MOD_DYNAMIC
205 int
206 init_module( int argc, char *argv[] )
207 {
208         return trace_initialize();
209 }
210 #endif /* SLAPD_OVER_TRACE == SLAPD_MOD_DYNAMIC */
211
212 #endif /* defined(SLAPD_OVER_TRACE) */