48 while(atts[i] != NULL)
85 unsigned int done, len, end, i, j;
87 char buf[1024], *next;
96 fprintf(stderr,
"config_load: couldn't open %s for reading: %s\n", file, strerror(errno));
101 p = XML_ParserCreate(NULL);
104 fprintf(stderr,
"config_load: couldn't allocate XML parser\n");
114 XML_SetUserData(p, (
void *) &bd);
121 len = fread(buf, 1, 1024, f);
124 fprintf(stderr,
"config_load: read error: %s\n", strerror(errno));
133 if(!XML_Parse(p, buf, len, done))
135 fprintf(stderr,
"config_load: parse error at line %llu: %s\n", (
unsigned long long) XML_GetCurrentLineNumber(p), XML_ErrorString(XML_GetErrorCode(p)));
154 elem->
values = calloc(1,
sizeof(
char *));
163 for(i = 1; i < bd.
nad->
ecur && rv == 0; i++)
166 if(end <= bd.nad->elems[i].
depth)
178 for(j = 1; j < len; j++)
181 next = next + path[j]->
lname;
218 elem->
attrs = realloc((
void *) elem->
attrs,
sizeof(
char **) * (elem->
nvalues + 1));
319 if(elem == NULL || num >= elem->
nvalues || elem->
attrs == NULL || elem->
attrs[num] == NULL)
322 return j_attr((
const char **) elem->
attrs[num], attr);
341 #ifdef CONFIGEXPAND_GUARDED 342 static char guard[] =
"deadbeaf";
346 char *s = strndup(value, l);
348 char *var_start, *var_end;
350 while ((var_start = strstr(s,
"${")) != 0) {
352 var_end = strstr(var_start + 2,
"}");
355 char *tail = var_end + 1;
356 char *var = var_start + 2;
364 int len = (var_start - s) + strlen(tail) + strlen(var_value) + 1;
366 #ifdef CONFIGEXPAND_GUARDED 367 len +=
sizeof(guard);
369 char *expanded_str = calloc(len, 1);
371 #ifdef CONFIGEXPAND_GUARDED 372 char *p_guard = expanded_str + len -
sizeof(guard);
373 strncpy(p_guard, guard,
sizeof(guard));
376 char *
p = expanded_str;
377 strncpy(expanded_str, s, var_start - s);
380 strcpy(p, var_value);
381 p += strlen(var_value);
388 fprintf(stderr,
"config_expand: Have no '%s' defined\n", var);
394 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