aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libmf.h32
-rw-r--r--lib/optcache.c76
-rw-r--r--lib/utils.c43
-rw-r--r--src/main.c32
-rw-r--r--src/mfdbtool.c13
-rw-r--r--src/srvcfg.c75
6 files changed, 127 insertions, 144 deletions
diff --git a/lib/libmf.h b/lib/libmf.h
index 96421687..4344d1a6 100644
--- a/lib/libmf.h
+++ b/lib/libmf.h
@@ -289,26 +289,36 @@ void mf_server_start(const char *program, const char *dir,
289 289
290 290
291/* optcache.c */ 291/* optcache.c */
292union mf_option_value {
293 int ov_bool;
294 char *ov_string;
295 time_t ov_time;
296 size_t ov_size;
297 mu_list_t ov_list;
298};
299
292struct mf_option_cache { 300struct mf_option_cache {
293 char *name; /* option name */ 301 char *name; /* option name */
294 void *value; /* current value */ 302 int (*handler)(char const *opt, union mf_option_value *pval, char const *arg);
295 int (*handler)(char *opt, void **pval, char *newval);
296 /* handler function, which verifies and assigns 303 /* handler function, which verifies and assigns
297 newval to pval. */ 304 arg to pval. */
298 void (*set)(void *value); /* function that actually sets the option */ 305 void (*set)(union mf_option_value *value);
306 /* function that actually sets the option */
307 union mf_option_value value; /* current value */
308 int isset; /* is the value set */
299}; 309};
300 310
301#define MF_OCF_NULL 0x01 /* Option_cache array is NULL-terminated */ 311#define MF_OCF_NULL 0x01 /* Option_cache array is NULL-terminated */
302#define MF_OCF_STATIC 0x02 /* Option_cache array is static. */ 312#define MF_OCF_STATIC 0x02 /* Option_cache array is static. */
303 313
304void mf_optcache_add(struct mf_option_cache *tab, size_t size, int flags); 314void mf_optcache_add(struct mf_option_cache *tab, size_t size, int flags);
305int mf_optcache_set_option(char *name, char *value); 315int mf_optcache_set_option(char const *name, char const *value);
306void mf_optcache_flush(void); 316void mf_optcache_flush(void);
307int mf_option_string(char *opt, void **pval, char *newval); 317int mf_option_string(char const *opt, union mf_option_value *val, char const *arg);
308int mf_option_boolean(char *opt, void **pval, char *newval); 318int mf_option_boolean(char const *opt, union mf_option_value *val, char const *arg);
309int mf_option_time(char *opt, void **pval, char *newval); 319int mf_option_timeout(char const *opt, union mf_option_value *val, char const *arg);
310int mf_option_time_t(char *opt, void **pval, char *newval); 320int mf_option_size(char const *opt, union mf_option_value *val, char const *arg);
311int mf_option_size_t(char *opt, void **pval, char *newval); 321
312 322
313void mf_init_lock_options(void); 323void mf_init_lock_options(void);
314 324
diff --git a/lib/optcache.c b/lib/optcache.c
index a059b29a..15b011b5 100644
--- a/lib/optcache.c
+++ b/lib/optcache.c
@@ -42,6 +42,7 @@ optcache_dup(struct mf_option_cache *tab, size_t size)
42 for (i = 0; i < size; i++) { 42 for (i = 0; i < size; i++) {
43 newtab[i] = tab[i]; 43 newtab[i] = tab[i];
44 newtab[i].name = mu_strdup(newtab[i].name); 44 newtab[i].name = mu_strdup(newtab[i].name);
45 newtab[i].isset = 0;
45 } 46 }
46 return newtab; 47 return newtab;
47} 48}
@@ -72,7 +73,7 @@ mf_optcache_add(struct mf_option_cache *tab, size_t size, int flags)
72} 73}
73 74
74static struct mf_option_cache * 75static struct mf_option_cache *
75find_option(char *name) 76find_option(char const *name)
76{ 77{
77 struct cache_list_elt *elt; 78 struct cache_list_elt *elt;
78 79
@@ -89,14 +90,18 @@ find_option(char *name)
89} 90}
90 91
91int 92int
92mf_optcache_set_option(char *name, char *value) 93mf_optcache_set_option(char const *name, char const *value)
93{ 94{
95 int rc;
94 struct mf_option_cache *p = find_option(name); 96 struct mf_option_cache *p = find_option(name);
95 if (!p) { 97 if (!p) {
96 errno = ENOENT; 98 errno = ENOENT;
97 return 1; 99 return 1;
98 } 100 }
99 return p->handler(name, &p->value, value); 101 rc = p->handler(name, &p->value, value);
102 if (rc == 0)
103 p->isset = 1;
104 return rc;
100} 105}
101 106
102void 107void
@@ -109,79 +114,70 @@ mf_optcache_flush()
109 struct mf_option_cache *opt; 114 struct mf_option_cache *opt;
110 115
111 for (i = 0, opt = elt->opt; i < elt->size; i++, opt++) 116 for (i = 0, opt = elt->opt; i < elt->size; i++, opt++)
112 if (opt->value && opt->set) 117 if (opt->isset && opt->set)
113 opt->set(opt->value); 118 opt->set(&opt->value);
114 } 119 }
115} 120}
116 121
117 122
118int 123int
119mf_option_string(char *opt, void **pval, char *newval) 124mf_option_string(char const *opt, union mf_option_value *val, char const *arg)
120{ 125{
121 if (*pval) 126 free(val->ov_string);
122 free(*pval); 127 val->ov_string = strdup(arg);
123 *pval = strdup(newval);
124 return 0; 128 return 0;
125} 129}
126 130
127int 131int
128mf_option_boolean(char *opt, void **pval, char *newval) 132mf_option_boolean(char const *opt, union mf_option_value *val, char const *arg)
129{ 133{
130 int val; 134 int b;
131 135
132 if (strcmp (newval, "yes") == 0 136 if (strcmp (arg, "yes") == 0
133 || strcmp (newval, "true") == 0 137 || strcmp (arg, "true") == 0
134 || strcmp (newval, "t") == 0) 138 || strcmp (arg, "t") == 0)
135 val = 1; 139 b = 1;
136 else if (strcmp (newval, "no") == 0 140 else if (strcmp (arg, "no") == 0
137 || strcmp (newval, "false") == 0 141 || strcmp (arg, "false") == 0
138 || strcmp (newval, "nil") == 0) 142 || strcmp (arg, "nil") == 0)
139 val = 0; 143 b = 0;
140 else { 144 else {
141 char *p; 145 char *p;
142 146
143 val = strtoul(newval, &p, 10); 147 b = strtoul(arg, &p, 10);
144 if (*p) { 148 if (*p) {
145 errno = EINVAL; 149 errno = EINVAL;
146 return 1; 150 return 1;
147 } 151 }
148 } 152 }
149 153
150 *pval = (void*) val; 154 val->ov_bool = b;
151 return 0; 155 return 0;
152} 156}
153 157
154int 158int
155mf_option_time(char *opt, void **pval, char *newval) 159mf_option_timeout(char const *opt, union mf_option_value *val, char const *arg)
156{ 160{
157 time_t interval; 161 time_t interval;
158 const char *endp; 162 const char *endp;
159 if (parse_time_interval(newval, &interval, &endp)) { 163
164 if (parse_time_interval(arg, &interval, &endp)) {
160 mu_error(_("%s: unrecognized time format (near `%s')"), 165 mu_error(_("%s: unrecognized time format (near `%s')"),
161 opt, endp); 166 opt, endp);
162 return 1; 167 return 1;
163 } 168 }
164 if (!*pval) 169 val->ov_time = interval;
165 *pval = mu_alloc(sizeof(time_t));
166 *(time_t*) *pval = interval;
167 return 0; 170 return 0;
168} 171}
169 172
170int 173int
171mf_option_time_t(char *opt, void **pval, char *newval) 174mf_option_size(char const *opt, union mf_option_value *val, char const *arg)
172{ 175{
173 if (!*pval) 176 char *p;
174 *pval = mu_alloc(sizeof(time_t)); 177 unsigned long n = strtoul(arg, &p, 10);
175 memcpy(*pval, newval, sizeof(time_t)); 178 if (*p)
176 return 0; 179 return 1;
177} 180 val->ov_size = n;
178
179int
180mf_option_size_t(char *opt, void **pval, char *newval)
181{
182 if (!*pval)
183 *pval = mu_alloc(sizeof(size_t));
184 memcpy(*pval, newval, sizeof(size_t));
185 return 0; 181 return 0;
186} 182}