]> mj.ucw.cz Git - libucw.git/blob - ucw/conf-internal.h
d8c77d622853fec9fa5191c2381d983642a46c64
[libucw.git] / ucw / conf-internal.h
1 /*
2  *      UCW Library -- Configuration files: only for internal use of conf-*.c
3  *
4  *      (c) 2001--2006 Robert Spalek <robert@ucw.cz>
5  *      (c) 2003--2012 Martin Mares <mj@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #ifndef _UCW_CONF_INTERNAL_H
12 #define _UCW_CONF_INTERNAL_H
13
14 #include <ucw/threads.h>
15
16 #define MAX_STACK_SIZE 16
17
18 struct item_stack {             // used by conf-intr.c
19   struct cf_section *sec;       // nested section
20   void *base_ptr;               // because original pointers are often relative
21   int op;                       // it is performed when a closing brace is encountered
22   void *list;                   // list the operations should be done on
23   u32 mask;                     // bit array of selectors searching in a list
24   struct cf_item *item;         // cf_item of the list
25 };
26
27 struct cf_context {
28   struct mempool *pool;
29   int is_active;
30   int need_journal;
31   char *def_file;
32   char *env_file;
33   int def_loaded;
34   struct cf_parser_state *parser;
35   uns everything_committed;             // after the 1st load, this flag is set on
36   uns postpone_commit;                  // used internally by cf_getopt()
37   uns other_options;
38   clist conf_entries;
39   struct old_pools *pools;
40   struct cf_journal_item *journal;
41   struct item_stack stack[MAX_STACK_SIZE];
42   uns stack_level;
43   uns initialized;
44   struct cf_section sections;           // root section
45 };
46
47 /* conf-ctxt.c */
48 static inline struct cf_context *
49 cf_get_context(void)
50 {
51   return ucwlib_thread_context()->cf_context;
52 }
53
54 /* conf-intr.c */
55 #define OP_MASK 0xff            // only get the operation
56 #define OP_OPEN 0x100           // here we only get an opening brace instead of parameters
57 #define OP_1ST 0x200            // in the 1st phase selectors are recorded into the mask
58 #define OP_2ND 0x400            // in the 2nd phase real data are entered
59 enum cf_operation;
60 extern char *cf_op_names[];
61 extern char *cf_type_names[];
62
63 uns cf_type_size(enum cf_type type, struct cf_user_type *utype);
64 char *cf_interpret_line(struct cf_context *cc, char *name, enum cf_operation op, int number, char **pars);
65 void cf_init_stack(struct cf_context *cc);
66 int cf_check_stack(struct cf_context *cc);
67
68 /* conf-journal.c */
69 void cf_journal_swap(void);
70 void cf_journal_delete(void);
71
72 /* conf-section.c */
73 #define SEC_FLAG_DYNAMIC        0x80000000      // contains a dynamic attribute
74 #define SEC_FLAG_UNKNOWN        0x40000000      // ignore unknown entriies
75 #define SEC_FLAG_CANT_COPY      0x20000000      // contains lists or parsers
76 #define SEC_FLAG_NUMBER         0x0fffffff      // number of entries
77 enum cf_commit_mode { CF_NO_COMMIT, CF_COMMIT, CF_COMMIT_ALL };
78 extern struct cf_section cf_sections;
79
80 struct cf_item *cf_find_subitem(struct cf_section *sec, const char *name);
81 int cf_commit_all(enum cf_commit_mode cm);
82 void cf_add_dirty(struct cf_section *sec, void *ptr);
83
84 #endif