]> mj.ucw.cz Git - libucw.git/blob - ucw/conf-internal.h
Opt: Calling hooks, config opts added
[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 /* Item stack used by conf-intr.c */
17
18 #define MAX_STACK_SIZE 16
19
20 struct item_stack {             // used by conf-intr.c
21   struct cf_section *sec;       // nested section
22   void *base_ptr;               // because original pointers are often relative
23   int op;                       // it is performed when a closing brace is encountered
24   void *list;                   // list the operations should be done on
25   u32 mask;                     // bit array of selectors searching in a list
26   struct cf_item *item;         // cf_item of the list
27 };
28
29 /* List of dirty sections used by conf-section.c */
30
31 struct dirty_section {
32   struct cf_section *sec;
33   void *ptr;
34 };
35
36 #define GBUF_TYPE       struct dirty_section
37 #define GBUF_PREFIX(x)  dirtsec_##x
38 #include <ucw/gbuf.h>
39
40 /* Configuration context */
41
42 struct cf_context {
43   struct mempool *pool;
44   int is_active;
45   int config_loaded;                    // at least one config file was loaded
46   struct cf_parser_state *parser;
47   uns everything_committed;             // did we already commit each section?
48   uns postpone_commit;                  // counter of calls to cf_open_group()
49   uns other_options;                    // used internally by cf_getopt()
50   clist conf_entries;                   // files/strings to reload
51   struct cf_journal_item *journal;      // journalling
52   int enable_journal;
53   struct old_pools *pools;
54   struct item_stack stack[MAX_STACK_SIZE];      // interpreter stack
55   uns stack_level;
56   struct cf_section sections;           // root section
57   uns sections_initialized;
58   dirtsec_t dirty;                      // dirty sections
59   uns dirties;
60 };
61
62 /* conf-ctxt.c */
63 static inline struct cf_context *
64 cf_get_context(void)
65 {
66   struct cf_context *cc = ucwlib_thread_context()->cf_context;
67   ASSERT(cc->is_active);
68   return cc;
69 }
70
71 // In fact, this is equivalent to cf_get_context(), but it is not inlined,
72 // because we want to force the linker to include conf-context.c, which contains
73 // a constructor of the whole context mechanism.
74 struct cf_context *cf_obtain_context(void);
75
76 /* conf-intr.c */
77 #define OP_MASK 0xff            // only get the operation
78 #define OP_OPEN 0x100           // here we only get an opening brace instead of parameters
79 #define OP_1ST 0x200            // in the 1st phase selectors are recorded into the mask
80 #define OP_2ND 0x400            // in the 2nd phase real data are entered
81 enum cf_operation;
82 extern char *cf_op_names[];
83 extern char *cf_type_names[];
84
85 uns cf_type_size(enum cf_type type, struct cf_user_type *utype);
86 char *cf_interpret_line(struct cf_context *cc, char *name, enum cf_operation op, int number, char **pars);
87 void cf_init_stack(struct cf_context *cc);
88 int cf_done_stack(struct cf_context *cc);
89
90 /* conf-journal.c */
91 void cf_journal_swap(void);
92 void cf_journal_delete(void);
93
94 /* conf-section.c */
95 #define SEC_FLAG_DYNAMIC        0x80000000      // contains a dynamic attribute
96 #define SEC_FLAG_UNKNOWN        0x40000000      // ignore unknown entriies
97 #define SEC_FLAG_CANT_COPY      0x20000000      // contains lists or parsers
98 #define SEC_FLAG_NUMBER         0x0fffffff      // number of entries
99 enum cf_commit_mode { CF_NO_COMMIT, CF_COMMIT, CF_COMMIT_ALL };
100 extern struct cf_section cf_sections;
101
102 struct cf_item *cf_find_subitem(struct cf_section *sec, const char *name);
103 int cf_commit_all(enum cf_commit_mode cm);
104 void cf_add_dirty(struct cf_section *sec, void *ptr);
105
106 /* conf-getopt.c */
107 void cf_load_default(struct cf_context *cc);
108
109 #endif