Let configuration mechanism be extensible
[cascardo/atompub.git] / atom / config.c
1 /*
2  *  Copyright (C) 2007  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along
15  *  with this program; if not, write to the Free Software Foundation, Inc.,
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19
20 #include <atompub/atom.h>
21
22 #include <glib.h>
23
24 struct _atom_config
25 {
26   void * data;
27   char * (*get_str) (AtomCtx *, char *, char *);
28 };
29
30 AtomConfig *
31 atom_config_new (void)
32 {
33   AtomConfig * config;
34   config = g_slice_new (AtomConfig);
35   config->data = NULL;
36   config->get_str = NULL;
37   return config;
38 }
39
40 void
41 atom_config_delete (AtomConfig *config)
42 {
43   g_slice_free (AtomConfig, config);
44 }
45
46 void
47 atom_config_get_str_set (AtomConfig * config,
48                          char * get_str (AtomCtx *, char *, char *))
49 {
50   config->get_str = get_str;
51 }
52
53 void
54 atom_config_data_set (AtomConfig * config, void * data)
55 {
56   config->data = data;
57 }
58
59 void *
60 atom_config_data (AtomConfig * config)
61 {
62   return config->data;
63 }
64
65 char *
66 atom_config_get_str (AtomCtx *ctx, char *namespace, char *key)
67 {
68   AtomConfig *config;
69   config = atom_config (ctx);
70   if (config && config->get_str)
71     return config->get_str (ctx, namespace, key);
72   return NULL;
73 }