r15854: more talloc_set_destructor() typesafe fixes
[abartlet/samba.git/.git] / source4 / lib / ldb / modules / skel.c
1 /* 
2    ldb database library
3
4    Copyright (C) Simo Sorce  2004
5
6      ** NOTE! The following LGPL license applies to the ldb
7      ** library. This does NOT imply that all of Samba is released
8      ** under the LGPL
9    
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25 /*
26  *  Name: ldb
27  *
28  *  Component: ldb skel module
29  *
30  *  Description: example module
31  *
32  *  Author: Simo Sorce
33  */
34
35 #include "includes.h"
36 #include "ldb/include/includes.h"
37
38 struct private_data {
39
40         char *some_private_data;
41 };
42
43 /* search */
44 static int skel_search(struct ldb_module *module, struct ldb_request *req)
45 {
46         return ldb_next_request(module, req);
47 }
48
49 /* add */
50 static int skel_add(struct ldb_module *module, struct ldb_request *req){
51         return ldb_next_request(module, req);
52 }
53
54 /* modify */
55 static int skel_modify(struct ldb_module *module, struct ldb_request *req)
56 {
57         return ldb_next_request(module, req);
58 }
59
60 /* delete */
61 static int skel_delete(struct ldb_module *module, struct ldb_request *req)
62 {
63         return ldb_next_request(module, req);
64 }
65
66 /* rename */
67 static int skel_rename(struct ldb_module *module, struct ldb_request *req)
68 {
69         return ldb_next_request(module, req);
70 }
71
72 /* start a transaction */
73 static int skel_start_trans(struct ldb_module *module)
74 {
75         return ldb_next_start_trans(module);
76 }
77
78 /* end a transaction */
79 static int skel_end_trans(struct ldb_module *module)
80 {
81         return ldb_next_end_trans(module);
82 }
83
84 /* delete a transaction */
85 static int skel_del_trans(struct ldb_module *module)
86 {
87         return ldb_next_del_trans(module);
88 }
89
90 static int skel_destructor(struct ldb_module *ctx)
91 {
92         struct private_data *data = talloc_get_type(ctx->private_data, struct private_data);
93         /* put your clean-up functions here */
94         if (data->some_private_data) talloc_free(data->some_private_data);
95         return 0;
96 }
97
98 static int skel_request(struct ldb_module *module, struct ldb_request *req)
99 {
100         switch (req->operation) {
101
102         case LDB_REQ_SEARCH:
103                 return skel_search(module, req);
104
105         case LDB_REQ_ADD:
106                 return skel_add(module, req);
107
108         case LDB_REQ_MODIFY:
109                 return skel_modify(module, req);
110
111         case LDB_REQ_DELETE:
112                 return skel_delete(module, req);
113
114         case LDB_REQ_RENAME:
115                 return skel_rename(module,
116                                    req);
117
118         default:
119                 return ldb_next_request(module, req);
120
121         }
122 }
123
124 static int skel_init(struct ldb_module *ctx)
125 {
126         struct private_data *data;
127
128         data = talloc(ctx, struct private_data);
129         if (data == NULL) {
130                 return 1;
131         }
132
133         data->some_private_data = NULL;
134         ctx->private_data = data;
135
136         talloc_set_destructor (ctx, skel_destructor);
137
138         return ldb_next_init(ctx);
139 }
140
141 static const struct ldb_module_ops skel_ops = {
142         .name              = "skel",
143         .init_context      = skel_init,
144         .request           = skel_request,
145         .start_transaction = skel_start_trans,
146         .end_transaction   = skel_end_trans,
147         .del_transaction   = skel_del_trans,
148 };
149
150 int ldb_skel_init(void)
151 {
152         return ldb_register_module(&skel_ops);
153 }