pam_pkcs11 0.6.12
scconf.h
Go to the documentation of this file.
1/*
2 * $Id$
3 *
4 * Copyright (C) 2002
5 * Antti Tapaninen <aet@cc.hut.fi>
6 *
7 * Originally based on source by Timo Sirainen <tss@iki.fi>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#ifndef _SC_CONF_H
25#define _SC_CONF_H
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31typedef struct _scconf_entry {
32 const char *name;
33 unsigned int type;
34 unsigned int flags;
35 void *parm;
36 void *arg;
38
39/* Entry flags */
40#define SCCONF_PRESENT 0x00000001
41#define SCCONF_MANDATORY 0x00000002
42#define SCCONF_ALLOC 0x00000004
43#define SCCONF_ALL_BLOCKS 0x00000008
44#define SCCONF_VERBOSE 0x00000010 /* For debugging purposes only */
45
46/* Entry types */
47#define SCCONF_CALLBACK 1
48#define SCCONF_BLOCK 2
49#define SCCONF_LIST 3
50
51#define SCCONF_BOOLEAN 11
52#define SCCONF_INTEGER 12
53#define SCCONF_STRING 13
54
56
57typedef struct _scconf_list {
59 char *data;
61
62#define SCCONF_ITEM_TYPE_COMMENT 0 /* key = NULL, comment */
63#define SCCONF_ITEM_TYPE_BLOCK 1 /* key = key, block */
64#define SCCONF_ITEM_TYPE_VALUE 2 /* key = key, list */
65
76
82
83typedef struct {
84 char *filename;
85 int debug;
87 char *errmsg;
89
90/* Allocate scconf_context
91 * The filename can be NULL
92 */
93extern scconf_context *scconf_new(const char *filename);
94
95/* Free scconf_context
96 */
97extern void scconf_free(scconf_context * config);
98
99/* Parse configuration
100 * Returns 1 = ok, 0 = error, -1 = error opening config file
101 */
102extern int scconf_parse(scconf_context * config);
103
104/* Parse a static configuration string
105 * Returns 1 = ok, 0 = error
106 */
107extern int scconf_parse_string(scconf_context * config, const char *string);
108
109/* Parse entries
110 */
111extern int scconf_parse_entries(const scconf_context * config, const scconf_block * block, scconf_entry * entry);
112
113/* Write config to a file
114 * If the filename is NULL, use the config->filename
115 * Returns 0 = ok, else = errno
116 */
117extern int scconf_write(scconf_context * config, const char *filename);
118
119/* Write configuration entries to block
120 */
121extern int scconf_write_entries(scconf_context * config, scconf_block * block, scconf_entry * entry);
122
123/* Find a block by the item_name
124 * If the block is NULL, the root block is used
125 */
126extern const scconf_block *scconf_find_block(const scconf_context * config, const scconf_block * block, const char *item_name);
127
128/* Find blocks by the item_name
129 * If the block is NULL, the root block is used
130 * The key can be used to specify what the blocks first name should be
131 */
132extern scconf_block **scconf_find_blocks(const scconf_context * config, const scconf_block * block, const char *item_name, const char *key);
133
134/* Get a list of values for option
135 */
136extern const scconf_list *scconf_find_list(const scconf_block * block, const char *option);
137
138/* Return the first string of the option
139 * If no option found, return def
140 */
141extern const char *scconf_get_str(const scconf_block * block, const char *option, const char *def);
142
143/* Return the first value of the option as integer
144 * If no option found, return def
145 */
146extern int scconf_get_int(const scconf_block * block, const char *option, int def);
147
148/* Return the first value of the option as boolean
149 * If no option found, return def
150 */
151extern int scconf_get_bool(const scconf_block * block, const char *option, int def);
152
153/* Write value to a block as a string
154 */
155extern const char *scconf_put_str(scconf_block * block, const char *option, const char *value);
156
157/* Write value to a block as an integer
158 */
159extern int scconf_put_int(scconf_block * block, const char *option, int value);
160
161/* Write value to a block as a boolean
162 */
163extern int scconf_put_bool(scconf_block * block, const char *option, int value);
164
165/* Add block structure
166 * If the block is NULL, the root block is used
167 */
168extern scconf_block *scconf_block_add(scconf_context * config, scconf_block * block, const char *key, const scconf_list *name);
169
170/* Copy block structure (recursive)
171 */
173
174/* Free block structure (recursive)
175 */
177
178/* Add item to block structure
179 * If the block is NULL, the root block is used
180 */
181extern scconf_item *scconf_item_add(scconf_context * config, scconf_block * block, scconf_item * item, int type, const char *key, const void *data);
182
183/* Copy item structure (recursive)
184 */
186
187/* Free item structure (recursive)
188 */
190
191/* Add a new value to the list
192 */
193extern scconf_list *scconf_list_add(scconf_list ** list, const char *value);
194
195/* Copy list structure
196 */
198
199/* Free list structure
200 */
202
203/* Return the length of an list array
204 */
205extern int scconf_list_array_length(const scconf_list * list);
206
207/* Return the combined length of the strings on all arrays
208 */
210
211/* Return an allocated string that contains all
212 * the strings in a list separated by the filler
213 * The filler can be NULL
214 */
215extern char *scconf_list_strdup(const scconf_list * list, const char *filler);
216
217/* Returns an allocated array of const char *pointers to
218 * list elements.
219 * Last pointer is NULL
220 * Array must be freed, but pointers to strings belong to scconf_list
221 */
222extern const char **scconf_list_toarray(const scconf_list * list);
223
224#ifdef __cplusplus
225}
226#endif
227#endif
scconf_block ** scconf_find_blocks(const scconf_context *config, const scconf_block *block, const char *item_name, const char *key)
int scconf_write_entries(scconf_context *config, scconf_block *block, scconf_entry *entry)
int scconf_write(scconf_context *config, const char *filename)
const char * scconf_get_str(const scconf_block *block, const char *option, const char *def)
struct _scconf_list scconf_list
char * scconf_list_strdup(const scconf_list *list, const char *filler)
scconf_block * scconf_block_add(scconf_context *config, scconf_block *block, const char *key, const scconf_list *name)
struct _scconf_entry scconf_entry
const scconf_block * scconf_find_block(const scconf_context *config, const scconf_block *block, const char *item_name)
const char * scconf_put_str(scconf_block *block, const char *option, const char *value)
void scconf_item_destroy(scconf_item *item)
const scconf_list * scconf_find_list(const scconf_block *block, const char *option)
scconf_item * scconf_item_copy(const scconf_item *src, scconf_item **dst)
void scconf_block_destroy(scconf_block *block)
scconf_context * scconf_new(const char *filename)
int scconf_list_array_length(const scconf_list *list)
void scconf_free(scconf_context *config)
const char ** scconf_list_toarray(const scconf_list *list)
int scconf_put_bool(scconf_block *block, const char *option, int value)
int scconf_parse_string(scconf_context *config, const char *string)
struct _scconf_block scconf_block
Definition scconf.h:55
scconf_block * scconf_block_copy(const scconf_block *src, scconf_block **dst)
int scconf_put_int(scconf_block *block, const char *option, int value)
scconf_list * scconf_list_add(scconf_list **list, const char *value)
scconf_item * scconf_item_add(scconf_context *config, scconf_block *block, scconf_item *item, int type, const char *key, const void *data)
void scconf_list_destroy(scconf_list *list)
int scconf_get_bool(const scconf_block *block, const char *option, int def)
struct _scconf_item scconf_item
int scconf_list_strings_length(const scconf_list *list)
scconf_list * scconf_list_copy(const scconf_list *src, scconf_list **dst)
int scconf_get_int(const scconf_block *block, const char *option, int def)
int scconf_parse_entries(const scconf_context *config, const scconf_block *block, scconf_entry *entry)
int scconf_parse(scconf_context *config)
scconf_list * name
Definition scconf.h:79
scconf_block * parent
Definition scconf.h:78
scconf_item * items
Definition scconf.h:80
Definition scconf.h:31
void * parm
Definition scconf.h:35
unsigned int type
Definition scconf.h:33
const char * name
Definition scconf.h:32
void * arg
Definition scconf.h:36
unsigned int flags
Definition scconf.h:34
char * comment
Definition scconf.h:71
union _scconf_item::@125036262375344023160164043363017225002377064032 value
char * key
Definition scconf.h:69
scconf_list * list
Definition scconf.h:73
scconf_block * block
Definition scconf.h:72
struct _scconf_item * next
Definition scconf.h:67
struct _scconf_list * next
Definition scconf.h:58
char * data
Definition scconf.h:59
char * errmsg
Definition scconf.h:87
scconf_block * root
Definition scconf.h:86
char * filename
Definition scconf.h:84