gwenhywfar  4.3.3
configmgr.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Mon Aug 11 2008
3  copyright : (C) 2008 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 #define DISABLE_DEBUGLOG
31 
32 
33 #include "configmgr_p.h"
34 
35 #include <gwenhywfar/gwenhywfar.h>
36 #include <gwenhywfar/misc.h>
37 #include <gwenhywfar/url.h>
38 #include <gwenhywfar/debug.h>
39 
40 
41 #include <stdlib.h>
42 #include <assert.h>
43 #include <string.h>
44 #include <errno.h>
45 #include <ctype.h>
46 
47 
48 
50 
51 GWEN_INHERIT(GWEN_PLUGIN, GWEN_CONFIGMGR_PLUGIN)
52 
53 
54 
57  int err;
58  GWEN_STRINGLIST *sl;
59 
62  if (err) {
63  DBG_ERROR(GWEN_LOGDOMAIN, "Could not register ConfigMgr plugin manager");
64  return err;
65  }
66 
67  /* create plugin paths */
69  if (sl) {
71  GWEN_BUFFER *pbuf;
72 
73  pbuf=GWEN_Buffer_new(0, 256, 0, 1);
74 
76  while(se) {
79  DBG_INFO(GWEN_LOGDOMAIN, "Adding plugin path [%s]",
80  GWEN_Buffer_GetStart(pbuf));
82  GWEN_Buffer_GetStart(pbuf));
83  GWEN_Buffer_Reset(pbuf);
85  }
86  GWEN_Buffer_free(pbuf);
88  }
89 
90  return 0;
91 }
92 
93 
94 
97 
99  if (pm) {
100  int rv;
101 
103  if (rv) {
105  "Could not unregister ConfigMgr plugin manager (%d)", rv);
106  return rv;
107  }
108  else
110  }
111 
112  return 0;
113 }
114 
115 
116 
117 
119  GWEN_CONFIGMGR *mgr;
120 
123 
124  if (url)
125  mgr->url=strdup(url);
126 
127  return mgr;
128 }
129 
130 
131 
133  if (mgr) {
135  free(mgr->url);
136  GWEN_FREE_OBJECT(mgr);
137  }
138 }
139 
140 
141 
145 
146  assert(mgr);
147  of=mgr->getGroupFn;
148  mgr->getGroupFn=f;
149 
150  return of;
151 }
152 
153 
154 
158 
159  assert(mgr);
160  of=mgr->setGroupFn;
161  mgr->setGroupFn=f;
162 
163  return of;
164 }
165 
166 
167 
171 
172  assert(mgr);
173  of=mgr->lockGroupFn;
174  mgr->lockGroupFn=f;
175 
176  return of;
177 }
178 
179 
180 
184 
185  assert(mgr);
186  of=mgr->unlockGroupFn;
187  mgr->unlockGroupFn=f;
188 
189  return of;
190 }
191 
192 
193 
197 
198  assert(mgr);
199  of=mgr->getUniqueIdFn;
200  mgr->getUniqueIdFn=f;
201 
202  return of;
203 }
204 
205 
206 
210 
211  assert(mgr);
212  of=mgr->deleteGroupFn;
213  mgr->deleteGroupFn=f;
214 
215  return of;
216 }
217 
218 
219 
223 
224  assert(mgr);
225  of=mgr->listGroupsFn;
226  mgr->listGroupsFn=f;
227 
228  return of;
229 }
230 
231 
232 
236 
237  assert(mgr);
238  of=mgr->listSubGroupsFn;
239  mgr->listSubGroupsFn=f;
240 
241  return of;
242 }
243 
244 
245 
247  const char *groupName,
248  const char *subGroupName,
249  GWEN_DB_NODE **pDb) {
250  assert(mgr);
251  if (mgr->getGroupFn)
252  return mgr->getGroupFn(mgr, groupName, subGroupName, pDb);
253  else
255 }
256 
257 
258 
260  const char *groupName,
261  const char *subGroupName,
262  GWEN_DB_NODE *db) {
263  assert(mgr);
264  if (mgr->setGroupFn)
265  return mgr->setGroupFn(mgr, groupName, subGroupName, db);
266  else
268 }
269 
270 
271 
273  const char *groupName,
274  const char *subGroupName) {
275  assert(mgr);
276  if (mgr->lockGroupFn)
277  return mgr->lockGroupFn(mgr, groupName, subGroupName);
278  else
280 }
281 
282 
283 
285  const char *groupName,
286  const char *subGroupName) {
287  assert(mgr);
288  if (mgr->unlockGroupFn)
289  return mgr->unlockGroupFn(mgr, groupName, subGroupName);
290  else
292 }
293 
294 
295 
297  const char *groupName,
298  char *buffer,
299  uint32_t bufferLen) {
300  assert(mgr);
301  if (mgr->getUniqueIdFn)
302  return mgr->getUniqueIdFn(mgr, groupName, buffer, bufferLen);
303  else
305 }
306 
307 
308 
310  const char *groupName,
311  const char *subGroupName) {
312  assert(mgr);
313  if (mgr->deleteGroupFn)
314  return mgr->deleteGroupFn(mgr, groupName, subGroupName);
315  else
317 }
318 
319 
320 
322  GWEN_STRINGLIST *sl) {
323  assert(mgr);
324  if (mgr->listGroupsFn)
325  return mgr->listGroupsFn(mgr, sl);
326  else
328 }
329 
330 
332  const char *groupName,
333  GWEN_STRINGLIST *sl) {
334  assert(mgr);
335  if (mgr->listSubGroupsFn)
336  return mgr->listSubGroupsFn(mgr, groupName, sl);
337  else
339 }
340 
341 
342 
343 
344 
345 
346 
347 
348 
350  const char *name,
351  const char *fileName) {
352  GWEN_PLUGIN *pl;
353  GWEN_CONFIGMGR_PLUGIN *xpl;
354 
355  pl=GWEN_Plugin_new(pm, name, fileName);
356  GWEN_NEW_OBJECT(GWEN_CONFIGMGR_PLUGIN, xpl);
357  GWEN_INHERIT_SETDATA(GWEN_PLUGIN, GWEN_CONFIGMGR_PLUGIN, pl, xpl,
359 
360  return pl;
361 }
362 
363 
364 
366  GWEN_CONFIGMGR_PLUGIN *xpl;
367 
368  xpl=(GWEN_CONFIGMGR_PLUGIN*)p;
369  GWEN_FREE_OBJECT(xpl);
370 }
371 
372 
373 
376  GWEN_CONFIGMGR_PLUGIN *xpl;
377 
378  assert(pl);
379  xpl=GWEN_INHERIT_GETDATA(GWEN_PLUGIN, GWEN_CONFIGMGR_PLUGIN, pl);
380  assert(xpl);
381 
382  xpl->factoryFn=f;
383 }
384 
385 
386 
388  const char *url) {
389  GWEN_CONFIGMGR_PLUGIN *xpl;
390 
391  assert(pl);
392  xpl=GWEN_INHERIT_GETDATA(GWEN_PLUGIN, GWEN_CONFIGMGR_PLUGIN, pl);
393  assert(xpl);
394 
395  assert(xpl->factoryFn);
396  return xpl->factoryFn(pl, url);
397 }
398 
399 
400 
403  GWEN_PLUGIN *pl;
404  GWEN_CONFIGMGR *mgr=NULL;
405  GWEN_URL *purl;
406  const char *modname;
407 
409  if (!pm) {
410  DBG_ERROR(GWEN_LOGDOMAIN, "No plugin manager for \"ConfigMgr\" found");
411  return 0;
412  }
413 
414  purl=GWEN_Url_fromString(url);
415  if (purl==NULL) {
416  DBG_INFO(GWEN_LOGDOMAIN, "Invalid url [%s]", url);
417  return NULL;
418  }
419 
420  modname=GWEN_Url_GetProtocol(purl);
421  if (modname==NULL)
422  modname="file";
423 
424  pl=GWEN_PluginManager_GetPlugin(pm, modname);
425  if (!pl) {
426  DBG_INFO(GWEN_LOGDOMAIN, "ConfigMgr-Plugin \"%s\" not found", modname);
427  GWEN_Url_free(purl);
428  return 0;
429  }
430  GWEN_Url_free(purl);
431 
432  mgr=GWEN_ConfigMgr_Plugin_Factory(pl, url);
433  if (mgr==NULL) {
435  "Plugin did not create a GWEN_CONFIGMGR");
436  }
437 
438  return mgr;
439 }
440 
441 
442 
443 
444 
445 
446 
447 
448