#include <eggdrop/eggdrop.h>
Go to the source code of this file.
Data Structures | |
struct | config_handle_t |
Functions | |
static void | config_delete_var (void *client_data) |
int | config_init (void) |
int | config_shutdown (void) |
void * | config_get_root (const char *handle) |
int | config_set_root (const char *handle, void *config_root) |
int | config_delete_root (const char *handle) |
void * | config_load (const char *fname) |
int | config_save (const char *handle, const char *fname) |
int | config_destroy (void *config_root) |
void * | config_lookup_section (void *config_root,...) |
void * | config_exists (void *config_root,...) |
int | config_get_int (int *intptr, void *config_root,...) |
int | config_get_str (char **strptr, void *config_root,...) |
int | config_set_int (int intval, void *config_root,...) |
int | config_set_str (const char *strval, void *config_root,...) |
int | config_link_table (config_var_t *table, void *config_root,...) |
int | config_update_table (config_var_t *table, void *config_root,...) |
int | config_unlink_table (config_var_t *table, void *config_root,...) |
Variables | |
static const char | rcsid [] = "$Id: config.c,v 1.11 2006-01-06 00:53:10 sven Exp $" |
static bind_table_t * | BT_config_str = NULL |
static bind_table_t * | BT_config_int = NULL |
static bind_table_t * | BT_config_save = NULL |
static int | gconfig_level = 0 |
static config_handle_t * | roots = NULL |
static int | nroots = 0 |
int config_delete_root | ( | const char * | handle | ) |
Definition at line 91 of file config.c.
References config_delete_var(), nroots, NULL, and xml_node_delete_callbacked().
Referenced by config_shutdown().
00092 { 00093 int i; 00094 00095 for (i = 0; i < nroots; i++) { 00096 if (!strcasecmp(handle, roots[i].handle)) { 00097 if (roots[i].handle) free(roots[i].handle); 00098 xml_node_delete_callbacked(roots[i].root, config_delete_var); 00099 memmove(roots+i, roots+i+1, sizeof(*roots) * (nroots-i-1)); 00100 if (--nroots == 0) { 00101 free(roots); 00102 roots = NULL; 00103 } 00104 return (0); 00105 } 00106 } 00107 00108 00109 return(-1); 00110 }
static void config_delete_var | ( | void * | client_data | ) | [static] |
Definition at line 143 of file config.c.
References CONFIG_INT, CONFIG_STRING, NULL, config_var_t::ptr, and config_var_t::type.
Referenced by config_delete_root(), config_destroy(), and config_unlink_table().
00144 { 00145 config_var_t *var = client_data; 00146 00147 switch (var->type) { 00148 case (CONFIG_STRING): 00149 free(*(char **)var->ptr); 00150 *(char **) var->ptr = NULL; 00151 break; 00152 case (CONFIG_INT): 00153 break; 00154 } 00155 }
int config_destroy | ( | void * | config_root | ) |
Definition at line 157 of file config.c.
References config_delete_var(), and xml_node_delete_callbacked().
Referenced by server_config_save().
00158 { 00159 xml_node_t *root = config_root; 00160 00161 xml_node_delete_callbacked(root, config_delete_var); 00162 00163 return(0); 00164 }
void* config_exists | ( | void * | config_root, | |
... | ||||
) |
Definition at line 178 of file config.c.
References xml_node_vlookup().
Referenced by core_init(), lookup_setting(), script_config_exists(), server_config_init(), and server_config_save().
00179 { 00180 va_list args; 00181 xml_node_t *root = config_root; 00182 00183 va_start(args, config_root); 00184 root = xml_node_vlookup(root, args, 0); 00185 va_end(args); 00186 return(root); 00187 }
int config_get_int | ( | int * | intptr, | |
void * | config_root, | |||
... | ||||
) |
Definition at line 189 of file config.c.
References NULL, xml_node_get_int(), and xml_node_vlookup().
Referenced by config_link_table(), and server_config_init().
00190 { 00191 va_list args; 00192 xml_node_t *root = config_root; 00193 00194 va_start(args, config_root); 00195 root = xml_node_vlookup(root, args, 0); 00196 va_end(args); 00197 00198 if (!root) { 00199 *intptr = 0; 00200 return(-1); 00201 } 00202 return xml_node_get_int(intptr, root, NULL); 00203 }
void* config_get_root | ( | const char * | handle | ) |
Definition at line 69 of file config.c.
Referenced by bot_close(), bot_init(), chanserv_close(), chanserv_LTX_start(), config_save(), core_init(), dccparty_close(), dccparty_LTX_start(), ircparty_close(), ircparty_LTX_start(), logfile_init(), logfile_shutdown(), lookup_setting(), proxy_close(), proxy_init(), script_config_exists(), script_config_get(), script_config_set(), server_close(), server_config_init(), server_config_save(), telnetparty_close(), and telnetparty_LTX_start().
00070 { 00071 int i; 00072 00073 for (i = 0; i < nroots; i++) { 00074 if (!strcasecmp(handle, roots[i].handle)) return(roots[i].root); 00075 } 00076 return(NULL); 00077 }
int config_get_str | ( | char ** | strptr, | |
void * | config_root, | |||
... | ||||
) |
Definition at line 205 of file config.c.
References NULL, xml_node_get_str(), and xml_node_vlookup().
Referenced by config_link_table(), core_init(), logfile_init(), party_get(), party_set(), party_unset(), script_config_get(), and server_config_init().
00206 { 00207 va_list args; 00208 xml_node_t *root = config_root; 00209 00210 va_start(args, config_root); 00211 root = xml_node_vlookup(root, args, 0); 00212 va_end(args); 00213 00214 if (!root) { 00215 *strptr = NULL; 00216 return(-1); 00217 } 00218 return xml_node_get_str(strptr, root, NULL); 00219 }
int config_init | ( | void | ) |
Definition at line 45 of file config.c.
References BIND_STACKABLE, bind_table_add(), BT_config_int, BT_config_save, BTN_CONFIG_INT, BTN_CONFIG_SAVE, BTN_CONFIG_STR, and MATCH_MASK.
Referenced by eggdrop_init().
00046 { 00047 BT_config_str = bind_table_add(BTN_CONFIG_STR, 2, "ss", MATCH_MASK, BIND_STACKABLE); /* DDD */ 00048 BT_config_int = bind_table_add(BTN_CONFIG_INT, 2, "si", MATCH_MASK, BIND_STACKABLE); /* DDD */ 00049 BT_config_save = bind_table_add(BTN_CONFIG_SAVE, 1, "s", MATCH_MASK, BIND_STACKABLE); /* DDD */ 00050 return(0); 00051 }
int config_link_table | ( | config_var_t * | table, | |
void * | config_root, | |||
... | ||||
) |
Definition at line 281 of file config.c.
References xml_node::client_data, config_get_int(), config_get_str(), CONFIG_INT, CONFIG_STRING, gconfig_level, config_var_t::name, NULL, config_var_t::ptr, str_redup(), config_var_t::type, xml_node_lookup(), and xml_node_vlookup().
Referenced by bot_init(), chanserv_LTX_start(), core_config_init(), dccparty_LTX_start(), ircparty_LTX_start(), proxy_init(), server_config_init(), and telnetparty_LTX_start().
00282 { 00283 xml_node_t *node, *root = config_root; 00284 va_list args; 00285 00286 gconfig_level++; 00287 00288 va_start(args, config_root); 00289 root = xml_node_vlookup(root, args, 1); 00290 va_end(args); 00291 00292 if (!root) { 00293 gconfig_level--; 00294 return(-1); 00295 } 00296 00297 while (table->name) { 00298 node = xml_node_lookup(root, 1, table->name, 0, NULL); 00299 node->client_data = table; 00300 if (table->type == CONFIG_INT) config_get_int(table->ptr, root, table->name, 0, NULL); 00301 else if (table->type == CONFIG_STRING) { 00302 char *str; 00303 config_get_str(&str, root, table->name, 0, NULL); 00304 str_redup(table->ptr, str); 00305 } 00306 table++; 00307 } 00308 00309 gconfig_level--; 00310 return(0); 00311 }
void* config_load | ( | const char * | fname | ) |
Definition at line 112 of file config.c.
References NULL, xml_last_error(), and xml_parse_file().
Referenced by core_config_init(), and script_config_load().
00113 { 00114 xml_node_t *root; 00115 00116 root = xml_parse_file(fname); 00117 if (!root) { 00118 /* XXX: do not use putlog here since it might not be initialized yet */ 00119 fprintf(stderr, "ERROR\n"); 00120 fprintf(stderr, "\tFailed to load config '%s': %s\n\n", fname, xml_last_error()); 00121 return NULL; 00122 } 00123 00124 return(root); 00125 }
void* config_lookup_section | ( | void * | config_root, | |
... | ||||
) |
Definition at line 166 of file config.c.
References xml_node_vlookup().
Referenced by logfile_init(), logfile_shutdown(), resolve_path(), script_config_exists(), and server_config_save().
00167 { 00168 va_list args; 00169 xml_node_t *root = config_root; 00170 00171 va_start(args, config_root); 00172 root = xml_node_vlookup(root, args, 1); 00173 va_end(args); 00174 00175 return(root); 00176 }
int config_save | ( | const char * | handle, | |
const char * | fname | |||
) |
Definition at line 127 of file config.c.
References _, bind_check(), BT_config_save, config_get_root(), LOG_MISC, NULL, putlog(), XML_INDENT, xml_last_error(), and xml_save_file().
Referenced by core_config_save().
00128 { 00129 void *root; 00130 00131 root = config_get_root(handle); 00132 if (root) bind_check(BT_config_save, NULL, handle, handle); 00133 if (!fname) fname = "config.xml"; 00134 00135 if (xml_save_file(fname, root, XML_INDENT) == 0) 00136 return (0); 00137 00138 putlog(LOG_MISC, "*", _("Failed to save config '%s': %s"), fname, xml_last_error()); 00139 00140 return (-1); 00141 }
int config_set_int | ( | int | intval, | |
void * | config_root, | |||
... | ||||
) |
Definition at line 221 of file config.c.
References bind_check(), BIND_RET_BREAK, BT_config_int, xml_node::client_data, CONFIG_INT, gconfig_level, NULL, config_var_t::ptr, config_var_t::type, xml_node_fullname(), xml_node_set_int(), and xml_node_vlookup().
Referenced by config_update_table(), and server_config_save().
00222 { 00223 va_list args; 00224 xml_node_t *root = config_root; 00225 config_var_t *var; 00226 00227 va_start(args, config_root); 00228 root = xml_node_vlookup(root, args, 1); 00229 va_end(args); 00230 00231 if (!gconfig_level) { 00232 char *name; 00233 int r; 00234 00235 name = xml_node_fullname(root); 00236 gconfig_level++; 00237 r = bind_check(BT_config_int, NULL, name, name, intval); 00238 gconfig_level--; 00239 free(name); 00240 if (r & BIND_RET_BREAK) return(-1); 00241 } 00242 00243 var = root->client_data; 00244 if (var) { 00245 if (var->type == CONFIG_INT) *(int *)var->ptr = intval; 00246 } 00247 xml_node_set_int(intval, root, NULL); 00248 return(0); 00249 }
int config_set_root | ( | const char * | handle, | |
void * | config_root | |||
) |
Definition at line 79 of file config.c.
References egg_assert_val, config_handle_t::handle, nroots, NULL, and config_handle_t::root.
Referenced by core_config_init(), and script_config_load().
00080 { 00081 egg_assert_val(handle != NULL, -1); 00082 egg_assert_val(config_root != NULL, -1); 00083 00084 roots = realloc(roots, sizeof(*roots) * (nroots+1)); 00085 roots[nroots].handle = strdup(handle); 00086 roots[nroots].root = config_root; 00087 nroots++; 00088 return(0); 00089 }
int config_set_str | ( | const char * | strval, | |
void * | config_root, | |||
... | ||||
) |
Definition at line 251 of file config.c.
References bind_check(), BIND_RET_BREAK, xml_node::client_data, CONFIG_INT, CONFIG_STRING, gconfig_level, NULL, config_var_t::ptr, str_redup(), config_var_t::type, xml_node_fullname(), xml_node_set_str(), and xml_node_vlookup().
Referenced by config_update_table(), logfile_shutdown(), party_set(), party_unset(), script_config_set(), and server_config_save().
00252 { 00253 va_list args; 00254 xml_node_t *root = config_root; 00255 config_var_t *var; 00256 00257 va_start(args, config_root); 00258 root = xml_node_vlookup(root, args, 1); 00259 va_end(args); 00260 00261 if (!gconfig_level) { 00262 char *name; 00263 int r; 00264 00265 name = xml_node_fullname(root); 00266 gconfig_level++; 00267 r = bind_check(BT_config_str, NULL, name, name, strval); 00268 gconfig_level--; 00269 free(name); 00270 if (r & BIND_RET_BREAK) return(-1); 00271 } 00272 var = root->client_data; 00273 if (var) { 00274 if (var->type == CONFIG_STRING && *(char **)var->ptr != strval) str_redup(var->ptr, strval); 00275 else if (var->type == CONFIG_INT) *(int *)var->ptr = atoi(strval); 00276 } 00277 xml_node_set_str(strval, root, NULL); 00278 return(0); 00279 }
int config_shutdown | ( | void | ) |
Definition at line 53 of file config.c.
References bind_table_del(), BT_config_int, BT_config_save, config_delete_root(), and nroots.
Referenced by eggdrop_shutdown().
00054 { 00055 int i; 00056 00057 for (i = nroots - 1; i >= 0; i--) { 00058 config_delete_root(roots[i].handle); 00059 } 00060 nroots = 0; 00061 00062 bind_table_del(BT_config_str); 00063 bind_table_del(BT_config_int); 00064 bind_table_del(BT_config_save); 00065 return (0); 00066 }
int config_unlink_table | ( | config_var_t * | table, | |
void * | config_root, | |||
... | ||||
) |
Definition at line 351 of file config.c.
References config_delete_var(), config_var_t::name, NULL, xml_node_delete_callbacked(), xml_node_lookup(), and xml_node_vlookup().
Referenced by bot_close(), chanserv_close(), dccparty_close(), ircparty_close(), proxy_close(), server_close(), and telnetparty_close().
00352 { 00353 xml_node_t *node, *root = config_root; 00354 va_list args; 00355 00356 va_start(args, config_root); 00357 root = xml_node_vlookup(root, args, 1); 00358 va_end(args); 00359 00360 if (!root) return(-1); 00361 00362 while (table->name) { 00363 node = xml_node_lookup(root, 0, table->name, 0, NULL); 00364 if (node) 00365 xml_node_delete_callbacked(node, config_delete_var); 00366 table++; 00367 } 00368 return(0); 00369 }
int config_update_table | ( | config_var_t * | table, | |
void * | config_root, | |||
... | ||||
) |
Definition at line 313 of file config.c.
References xml_node::client_data, CONFIG_INT, config_set_int(), config_set_str(), CONFIG_STRING, gconfig_level, config_var_t::name, NULL, config_var_t::ptr, config_var_t::type, xml_node_lookup(), and xml_node_vlookup().
Referenced by bot_init(), chanserv_LTX_start(), core_config_init(), core_config_save(), dccparty_LTX_start(), ircparty_LTX_start(), server_config_init(), and telnetparty_LTX_start().
00314 { 00315 xml_node_t *node, *root = config_root; 00316 va_list args; 00317 00318 gconfig_level++; 00319 00320 va_start(args, config_root); 00321 root = xml_node_vlookup(root, args, 1); 00322 va_end(args); 00323 00324 if (!root) { 00325 gconfig_level--; 00326 return(-1); 00327 } 00328 00329 while (table->name) { 00330 node = xml_node_lookup(root, 1, table->name, 0, NULL); 00331 node->client_data = table; 00332 00333 switch (table->type) { 00334 00335 case (CONFIG_INT): 00336 config_set_int(*(int *)table->ptr, root, table->name, 0, NULL); 00337 break; 00338 00339 case (CONFIG_STRING): 00340 config_set_str(*(char **)table->ptr, root, table->name, 0, NULL); 00341 break; 00342 } 00343 00344 table++; 00345 } 00346 00347 gconfig_level--; 00348 return(0); 00349 }
bind_table_t * BT_config_int = NULL [static] |
Definition at line 28 of file config.c.
Referenced by config_init(), config_set_int(), and config_shutdown().
bind_table_t * BT_config_save = NULL [static] |
Definition at line 29 of file config.c.
Referenced by config_init(), config_save(), and config_shutdown().
bind_table_t* BT_config_str = NULL [static] |
int gconfig_level = 0 [static] |
Definition at line 33 of file config.c.
Referenced by config_link_table(), config_set_int(), config_set_str(), and config_update_table().
int nroots = 0 [static] |
Definition at line 41 of file config.c.
Referenced by config_delete_root(), config_get_root(), config_set_root(), and config_shutdown().
const char rcsid[] = "$Id: config.c,v 1.11 2006-01-06 00:53:10 sven Exp $" [static] |
config_handle_t* roots = NULL [static] |