* UCW Library -- Configuration files
*
* (c) 2001--2006 Robert Spalek <robert@ucw.cz>
- * (c) 2003--2012 Martin Mares <mj@ucw.cz>
+ * (c) 2003--2014 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
#define _UCW_CONF_H
#include <ucw/clists.h>
+#include <ucw/gary.h>
+
+#ifdef CONFIG_UCW_CLEAN_ABI
+#define cf_close_group ucw_cf_close_group
+#define cf_declare_rel_section ucw_cf_declare_rel_section
+#define cf_declare_section ucw_cf_declare_section
+#define cf_delete_context ucw_cf_delete_context
+#define cf_dump_sections ucw_cf_dump_sections
+#define cf_find_item ucw_cf_find_item
+#define cf_get_pool ucw_cf_get_pool
+#define cf_init_section ucw_cf_init_section
+#define cf_journal_block ucw_cf_journal_block
+#define cf_journal_commit_transaction ucw_cf_journal_commit_transaction
+#define cf_journal_new_transaction ucw_cf_journal_new_transaction
+#define cf_journal_rollback_transaction ucw_cf_journal_rollback_transaction
+#define cf_load ucw_cf_load
+#define cf_malloc ucw_cf_malloc
+#define cf_malloc_zero ucw_cf_malloc_zero
+#define cf_modify_item ucw_cf_modify_item
+#define cf_new_context ucw_cf_new_context
+#define cf_open_group ucw_cf_open_group
+#define cf_parse_double ucw_cf_parse_double
+#define cf_parse_int ucw_cf_parse_int
+#define cf_parse_ip ucw_cf_parse_ip
+#define cf_parse_u64 ucw_cf_parse_u64
+#define cf_printf ucw_cf_printf
+#define cf_reload ucw_cf_reload
+#define cf_revert ucw_cf_revert
+#define cf_set ucw_cf_set
+#define cf_set_journalling ucw_cf_set_journalling
+#define cf_strdup ucw_cf_strdup
+#define cf_switch_context ucw_cf_switch_context
+#endif
struct mempool;
* All configuration settings made within the context are rolled back
* (except when journalling is turned off). All memory allocated on behalf
* of the context is freed, which includes memory obtained by calls to
- * cf_malloc().
+ * @cf_malloc().
**/
-void cf_free_context(struct cf_context *cc);
+void cf_delete_context(struct cf_context *cc);
/**
* Make the given configuration context current and return the previously
/**
* Reload configuration from @file, replace the old one.
* If @file is NULL, reload all loaded configuration files and re-apply
- * bits of configuration passed to cf_set().
+ * bits of configuration passed to @cf_set().
* Returns a non-zero value upon error. In that case, all configuration
* settings are rolled back to the state before calling this function.
**/
void cf_open_group(void);
/**
- * Close a group opened by cf_open_group(). Returns a non-zero value upon error,
+ * Close a group opened by @cf_open_group(). Returns a non-zero value upon error,
* which usually means that a commit hook has failed.
**/
int cf_close_group(void);
* @cf_journal_block() on the overwritten memory block. It returns an error
* message or NULL if everything is all right.
**/
-typedef char *cf_parser(uns number, char **pars, void *ptr);
+typedef char *cf_parser(uint number, char **pars, void *ptr);
/**
* A parser function for user-defined types gets a string and a pointer to
* the destination variable. It must store the value within [ptr,ptr+size),
typedef char *cf_copier(void *dest, void *src);
struct cf_user_type { /** Structure to store information about user-defined variable type. **/
- uns size; // of the parsed attribute
+ uint size; // of the parsed attribute
char *name; // name of the type (for dumping)
cf_parser1 *parser; // how to parse it
cf_dumper1 *dumper; // how to dump the type
};
struct cf_section { /** A section. **/
- uns size; // 0 for a global block, sizeof(struct) for a section
+ uint size; // 0 for a global block, sizeof(struct) for a section
cf_hook *init; // fills in default values (no need to bzero)
cf_hook *commit; // verifies parsed data (optional)
cf_copier *copy; // copies values from another instance (optional, no need to copy basic attributes)
struct cf_item *cfg; // CC_END-terminated array of items
- uns flags; // for internal use only
+ uint flags; // for internal use only
};
/***
* struct list_node {
* cnode n; // This one is for the list itself
* char *name;
- * uns value;
+ * uint value;
* };
*
* static struct clist nodes;
* CF_TYPE(struct list_node),
* CF_ITEMS {
* CF_STRING("name", PTR_TO(struct list_node, name)),
- * CF_UNS("value", PTR_TO(struct list_node, value)),
+ * CF_UINT("value", PTR_TO(struct list_node, value)),
* CF_END
* }
* };
#define CF_INT(n,p) CF_STATIC(n,p,INT,int,1) /** Single `int` value. **/
#define CF_INT_ARY(n,p,c) CF_STATIC(n,p,INT,int,c) /** Static array of integers. **/
#define CF_INT_DYN(n,p,c) CF_DYNAMIC(n,p,INT,int,c) /** Dynamic array of integers. **/
-#define CF_UNS(n,p) CF_STATIC(n,p,INT,uns,1) /** Single `uns` (`unsigned`) value. **/
-#define CF_UNS_ARY(n,p,c) CF_STATIC(n,p,INT,uns,c) /** Static array of unsigned integers. **/
-#define CF_UNS_DYN(n,p,c) CF_DYNAMIC(n,p,INT,uns,c) /** Dynamic array of unsigned integers. **/
+#define CF_UINT(n,p) CF_STATIC(n,p,INT,uint,1) /** Single `uint` (`unsigned`) value. **/
+#define CF_UINT_ARY(n,p,c) CF_STATIC(n,p,INT,uint,c) /** Static array of unsigned integers. **/
+#define CF_UINT_DYN(n,p,c) CF_DYNAMIC(n,p,INT,uint,c) /** Dynamic array of unsigned integers. **/
#define CF_U64(n,p) CF_STATIC(n,p,U64,u64,1) /** Single unsigned 64bit integer (`u64`). **/
#define CF_U64_ARY(n,p,c) CF_STATIC(n,p,U64,u64,c) /** Static array of u64s. **/
#define CF_U64_DYN(n,p,c) CF_DYNAMIC(n,p,U64,u64,c) /** Dynamic array of u64s. **/
#define CF_IP(n,p) CF_STATIC(n,p,IP,u32,1) /** Single IPv4 address. **/
#define CF_IP_ARY(n,p,c) CF_STATIC(n,p,IP,u32,c) /** Static array of IP addresses. **/.
#define CF_IP_DYN(n,p,c) CF_DYNAMIC(n,p,IP,u32,c) /** Dynamic array of IP addresses. **/
+
+/* FIXME: Backwards compatibility only, should not be used at is will be removed soon. */
+#define CF_UNS CF_UINT
+#define CF_UNS_ARY CF_UINT_ARY
+#define CF_UNS_DYN CF_UINT_DYN
+
/**
* A string.
* You provide a pointer to a `char *` variable and it will fill it with
**/
#define CF_ANY_NUM -0x7fffffff
-#define DARY_LEN(a) ((uns*)a)[-1] /** Length of an dynamic array. **/
-#define DARY_ALLOC(type,len,val...) ((struct { uns l; type a[len]; }) { .l = len, .a = { val } }).a
- // creates a static instance of a dynamic array
+#define DARY_LEN(a) GARY_SIZE(a) /** Length of an dynamic array. An alias for `GARY_SIZE`. **/
/***
* [[alloc]]
* cf_set(), or cf_getopt() on the particular context.
***/
struct mempool *cf_get_pool(void); /** Return a pointer to the current configuration pool. **/
-void *cf_malloc(uns size); /** Returns @size bytes of memory allocated from the current configuration pool. **/
-void *cf_malloc_zero(uns size); /** Like @cf_malloc(), but zeroes the memory. **/
+void *cf_malloc(uint size); /** Returns @size bytes of memory allocated from the current configuration pool. **/
+void *cf_malloc_zero(uint size); /** Like @cf_malloc(), but zeroes the memory. **/
char *cf_strdup(const char *s); /** Copy a string into @cf_malloc()ed memory. **/
char *cf_printf(const char *fmt, ...) FORMAT_CHECK(printf,1,2); /** printf() into @cf_malloc()ed memory. **/
* <<custom_parser,Custom parsers>> do not need to call it, it is called
* before them.
**/
-void cf_journal_block(void *ptr, uns len);
+void cf_journal_block(void *ptr, uint len);
#define CF_JOURNAL_VAR(var) cf_journal_block(&(var), sizeof(var)) // Store a single value into the journal
struct cf_journal_item; /** Opaque identifier of the journal state. **/
* get back to it. The @new_pool parameter tells if a new memory pool
* should be created and used from now.
**/
-struct cf_journal_item *cf_journal_new_transaction(uns new_pool);
+struct cf_journal_item *cf_journal_new_transaction(uint new_pool);
/**
* Marks current state as a complete transaction. The @new_pool
* parameter tells if the transaction was created with new memory pool
* is the journal state returned from last
* @cf_journal_new_transaction() call.
**/
-void cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj);
+void cf_journal_commit_transaction(uint new_pool, struct cf_journal_item *oldj);
/**
* Returns to an old journal state, reverting anything the current
* transaction did. The @new_pool parameter must be the same as the
* is the journal state you got from @cf_journal_new_transaction() --
* it is the state to return to.
**/
-void cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj);
+void cf_journal_rollback_transaction(uint new_pool, struct cf_journal_item *oldj);
/***
* [[declare]]
* If @allow_unknown is set to 0 and a variable not described in @sec
* is found in the configuration file, it produces an error.
* If you set it to 1, all such variables are ignored.
+ *
+ * Please note that a single section definition cannot be used in multiple
+ * configuration contexts simultaneously.
+ **/
+void cf_declare_section(const char *name, struct cf_section *sec, uint allow_unknown);
+/**
+ * Like @cf_declare_section(), but instead of item pointers, the section
+ * contains offsets relative to @ptr. In other words, it does the same
+ * as `CF_SECTION`, but for top-level sections.
**/
-void cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown);
+void cf_declare_rel_section(const char *name, struct cf_section *sec, void *ptr, uint allow_unknown);
/**
* If you have a section in a structure and you want to initialize it
* (eg. if you want a copy of default values outside the configuration),
*
* This is used mostly internally. You probably do not need it.
**/
-void cf_init_section(const char *name, struct cf_section *sec, void *ptr, uns do_bzero);
+void cf_init_section(const char *name, struct cf_section *sec, void *ptr, uint do_bzero);
/***
* [[bparser]]