48 while(atts[i] != NULL)
85 int done, len, end, i, j, attr;
86 char buf[1024], *next;
95 fprintf(stderr,
"config_load: couldn't open %s for reading: %s\n", file, strerror(errno));
100 p = XML_ParserCreate(NULL);
103 fprintf(stderr,
"config_load: couldn't allocate XML parser\n");
113 XML_SetUserData(p, (
void *) &bd);
120 len = fread(buf, 1, 1024, f);
123 fprintf(stderr,
"config_load: read error: %s\n", strerror(errno));
132 if(!XML_Parse(p, buf, len, done))
134 fprintf(stderr,
"config_load: parse error at line %llu: %s\n", (
unsigned long long) XML_GetCurrentLineNumber(p), XML_ErrorString(XML_GetErrorCode(p)));
153 elem->
values = calloc(1,
sizeof(
char *));
162 for(i = 1; i < bd.
nad->
ecur && rv == 0; i++)
165 if(end <= bd.nad->elems[i].
depth)
177 for(j = 1; j < len; j++)
180 next = next + path[j]->
lname;
217 elem->
attrs = realloc((
void *) elem->
attrs,
sizeof(
char **) * (elem->
nvalues + 1));
321 return j_attr((
const char **) elem->
attrs[num], attr);
340 #ifdef CONFIGEXPAND_GUARDED
341 static char guard[] =
"deadbeaf";
345 char *s = strndup(value, l);
347 char *var_start, *var_end;
349 while ((var_start = strstr(s,
"${")) != 0) {
351 var_end = strstr(var_start + 2,
"}");
354 char *tail = var_end + 1;
355 char *var = var_start + 2;
363 int len = (var_start - s) + strlen(tail) + strlen(var_value) + 1;
365 #ifdef CONFIGEXPAND_GUARDED
366 len +=
sizeof(guard);
368 char *expanded_str = calloc(len, 1);
370 #ifdef CONFIGEXPAND_GUARDED
371 char *p_guard = expanded_str + len -
sizeof(guard);
372 strncpy(p_guard, guard,
sizeof(guard));
375 char *p = expanded_str;
376 strncpy(expanded_str, s, var_start - s);
379 strcpy(p, var_value);
380 p += strlen(var_value);
387 fprintf(stderr,
"config_expand: Have no '%s' defined\n", var);
393 fprintf(stderr,
"config_expand: } missmatch\n");
struct nad_elem_st * elems
nad_t nad_new(void)
create a new nad
int nad_append_attr(nad_t nad, int ns, const char *name, const char *val)
attach new attr to the last elem
int config_load_with_id(config_t c, const char *file, const char *id)
turn an xml file into a config hash
#define NAD_CDATA_L(N, E)
void * pmalloc(pool_t p, int size)
void config_free(config_t c)
cleanup
void nad_append_cdata(nad_t nad, const char *cdata, int len, int depth)
append new cdata to the last elem
config_t config_new(void)
new config structure
struct nad_attr_st * attrs
holder for the config hash and nad
int nad_append_elem(nad_t nad, int ns, const char *name, int depth)
create a new elem on the list
void nad_free(nad_t nad)
free that nad
#define NAD_ANAME_L(N, A)
static void _config_endElement(void *arg, const char *name)
char * config_get_attr(config_t c, const char *key, int num, const char *attr)
get an attr for this value
static void _config_reaper(const char *key, int keylen, void *val, void *arg)
cleanup helper
void * pmalloco(pool_t p, int size)
easy safety utility (for creating blank mem for structs, etc)
char * pstrdupx(pool_t p, const char *src, int len)
use given size
void xhash_put(xht h, const char *key, void *val)
static char * _config_expandx(config_t c, const char *value, int l)
config_elem_t config_get(config_t c, const char *key)
get the config element for this key
struct config_elem_st * config_elem_t
void xhash_walk(xht h, xhash_walker w, void *arg)
int config_load(config_t c, const char *file)
turn an xml file into a config hash
pool_t xhash_pool(xht h)
get our pool
struct config_st * config_t
static void _config_startElement(void *arg, const char *name, const char **atts)
char * pstrdup(pool_t p, const char *src)
XXX efficient: move this to const char * and then loop throug the existing heaps to see if src is wit...
void * xhash_get(xht h, const char *key)
char * j_attr(const char **atts, const char *attr)
char * config_expand(config_t c, const char *value)
const char * config_get_one(config_t c, const char *key, int num)
get config value n for this key
static void _config_charData(void *arg, const char *str, int len)
int config_count(config_t c, const char *key)
how many values for this key?
const char * config_get_one_default(config_t c, const char *key, int num, const char *default_value)
get config value n for this key, returns default_value if not found
parse a buffer into a nad