pam_pkcs11 0.6.8

- Main Page
- Data Structures
- Files
- Directories

- File List
- Globals

scconf.h
Go to the documentation of this file.

    00001 /*
    00002  * $Id: scconf.h 233 2007-04-04 09:52:54Z ludovic.rousseau $
    00003  *
    00004  * Copyright (C) 2002
    00005  *  Antti Tapaninen <aet@cc.hut.fi>
    00006  *
    00007  * Originally based on source by Timo Sirainen <tss@iki.fi>
    00008  *
    00009  * This library is free software; you can redistribute it and/or
    00010  * modify it under the terms of the GNU Lesser General Public
    00011  * License as published by the Free Software Foundation; either
    00012  * version 2.1 of the License, or (at your option) any later version.
    00013  *
    00014  * This library is distributed in the hope that it will be useful,
    00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00017  * Lesser General Public License for more details.
    00018  *
    00019  * You should have received a copy of the GNU Lesser General Public
    00020  * License along with this library; if not, write to the Free Software
    00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00022  */
    00023
    00024 #ifndef _SC_CONF_H
    00025 #define _SC_CONF_H
    00026
    00027 #ifdef __cplusplus
    00028 extern "C" {
    00029 #endif
    00030
    00031 typedef struct _scconf_entry {
    00032         const char *name;
    00033         unsigned int type;
    00034         unsigned int flags;
    00035         void *parm;
    00036         void *arg;
    00037 } scconf_entry;
    00038
    00039 /* Entry flags */
    00040 #define SCCONF_PRESENT          0x00000001
    00041 #define SCCONF_MANDATORY        0x00000002
    00042 #define SCCONF_ALLOC            0x00000004
    00043 #define SCCONF_ALL_BLOCKS       0x00000008
    00044 #define SCCONF_VERBOSE          0x00000010      /* For debugging purposes only */
    00045
    00046 /* Entry types */
    00047 #define SCCONF_CALLBACK         1
    00048 #define SCCONF_BLOCK            2
    00049 #define SCCONF_LIST             3
    00050
    00051 #define SCCONF_BOOLEAN          11
    00052 #define SCCONF_INTEGER          12
    00053 #define SCCONF_STRING           13
    00054
    00055 typedef struct _scconf_block scconf_block;
    00056
    00057 typedef struct _scconf_list {
    00058         struct _scconf_list *next;
    00059         char *data;
    00060 } scconf_list;
    00061
    00062 #define SCCONF_ITEM_TYPE_COMMENT        0       /* key = NULL, comment */
    00063 #define SCCONF_ITEM_TYPE_BLOCK          1       /* key = key, block */
    00064 #define SCCONF_ITEM_TYPE_VALUE          2       /* key = key, list */
    00065
    00066 typedef struct _scconf_item {
    00067         struct _scconf_item *next;
    00068         int type;
    00069         char *key;
    00070         union {
    00071                 char *comment;
    00072                 scconf_block *block;
    00073                 scconf_list *list;
    00074         } value;
    00075 } scconf_item;
    00076
    00077 struct _scconf_block {
    00078         scconf_block *parent;
    00079         scconf_list *name;
    00080         scconf_item *items;
    00081 };
    00082
    00083 typedef struct {
    00084         char *filename;
    00085         int debug;
    00086         scconf_block *root;
    00087         char *errmsg;
    00088 } scconf_context;
    00089
    00090 /* Allocate scconf_context
    00091  * The filename can be NULL
    00092  */
    00093 extern scconf_context *scconf_new(const char *filename);
    00094
    00095 /* Free scconf_context
    00096  */
    00097 extern void scconf_free(scconf_context * config);
    00098
    00099 /* Parse configuration
    00100  * Returns 1 = ok, 0 = error, -1 = error opening config file
    00101  */
    00102 extern int scconf_parse(scconf_context * config);
    00103
    00104 /* Parse a static configuration string
    00105  * Returns 1 = ok, 0 = error
    00106  */
    00107 extern int scconf_parse_string(scconf_context * config, const char *string);
    00108
    00109 /* Parse entries
    00110  */
    00111 extern int scconf_parse_entries(const scconf_context * config, const scconf_block * block, scconf_entry * entry);
    00112
    00113 /* Write config to a file
    00114  * If the filename is NULL, use the config->filename
    00115  * Returns 0 = ok, else = errno
    00116  */
    00117 extern int scconf_write(scconf_context * config, const char *filename);
    00118
    00119 /* Write configuration entries to block
    00120  */
    00121 extern int scconf_write_entries(scconf_context * config, scconf_block * block, scconf_entry * entry);
    00122
    00123 /* Find a block by the item_name
    00124  * If the block is NULL, the root block is used
    00125  */
    00126 extern const scconf_block *scconf_find_block(const scconf_context * config, const scconf_block * block, const char *item_name);
    00127
    00128 /* Find blocks by the item_name
    00129  * If the block is NULL, the root block is used
    00130  * The key can be used to specify what the blocks first name should be
    00131  */
    00132 extern scconf_block **scconf_find_blocks(const scconf_context * config, const scconf_block * block, const char *item_name, const char *key);
    00133
    00134 /* Get a list of values for option
    00135  */
    00136 extern const scconf_list *scconf_find_list(const scconf_block * block, const char *option);
    00137
    00138 /* Return the first string of the option
    00139  * If no option found, return def
    00140  */
    00141 extern const char *scconf_get_str(const scconf_block * block, const char *option, const char *def);
    00142
    00143 /* Return the first value of the option as integer
    00144  * If no option found, return def
    00145  */
    00146 extern int scconf_get_int(const scconf_block * block, const char *option, int def);
    00147
    00148 /* Return the first value of the option as boolean
    00149  * If no option found, return def
    00150  */
    00151 extern int scconf_get_bool(const scconf_block * block, const char *option, int def);
    00152
    00153 /* Write value to a block as a string
    00154  */
    00155 extern const char *scconf_put_str(scconf_block * block, const char *option, const char *value);
    00156
    00157 /* Write value to a block as an integer
    00158  */
    00159 extern int scconf_put_int(scconf_block * block, const char *option, int value);
    00160
    00161 /* Write value to a block as a boolean
    00162  */
    00163 extern int scconf_put_bool(scconf_block * block, const char *option, int value);
    00164
    00165 /* Add block structure
    00166  * If the block is NULL, the root block is used
    00167  */
    00168 extern scconf_block *scconf_block_add(scconf_context * config, scconf_block * block, const char *key, const scconf_list *name);
    00169
    00170 /* Copy block structure (recursive)
    00171  */
    00172 extern scconf_block *scconf_block_copy(const scconf_block * src, scconf_block ** dst);
    00173
    00174 /* Free block structure (recursive)
    00175  */
    00176 extern void scconf_block_destroy(scconf_block * block);
    00177
    00178 /* Add item to block structure
    00179  * If the block is NULL, the root block is used
    00180  */
    00181 extern scconf_item *scconf_item_add(scconf_context * config, scconf_block * block, scconf_item * item, int type, const char *key, const void *data);
    00182
    00183 /* Copy item structure (recursive)
    00184  */
    00185 extern scconf_item *scconf_item_copy(const scconf_item * src, scconf_item ** dst);
    00186
    00187 /* Free item structure (recursive)
    00188  */
    00189 extern void scconf_item_destroy(scconf_item * item);
    00190
    00191 /* Add a new value to the list
    00192  */
    00193 extern scconf_list *scconf_list_add(scconf_list ** list, const char *value);
    00194
    00195 /* Copy list structure
    00196  */
    00197 extern scconf_list *scconf_list_copy(const scconf_list * src, scconf_list ** dst);
    00198
    00199 /* Free list structure
    00200  */
    00201 extern void scconf_list_destroy(scconf_list * list);
    00202
    00203 /* Return the length of an list array
    00204  */
    00205 extern int scconf_list_array_length(const scconf_list * list);
    00206
    00207 /* Return the combined length of the strings on all arrays
    00208  */
    00209 extern int scconf_list_strings_length(const scconf_list * list);
    00210
    00211 /* Return an allocated string that contains all
    00212  * the strings in a list separated by the filler
    00213  * The filler can be NULL
    00214  */
    00215 extern char *scconf_list_strdup(const scconf_list * list, const char *filler);
    00216
    00217 /* Returns an allocated array of const char *pointers to
    00218  * list elements.
    00219  * Last pointer is NULL
    00220  * Array must be freed, but pointers to strings belong to scconf_list
    00221  */
    00222 extern const char **scconf_list_toarray(const scconf_list * list);
    00223
    00224 #ifdef __cplusplus
    00225 }
    00226 #endif
    00227 #endif