*/
-gras_error_t gras_cfg_new(gras_cfg_t **whereto) {
- return gras_dict_new((gras_dict_t**)whereto);
+void gras_cfg_new(gras_cfg_t **whereto) {
+ gras_dict_new((gras_dict_t**)whereto);
}
/**
*
*/
-gras_error_t
+void
gras_cfg_cpy(gras_cfg_t **whereto, gras_cfg_t *tocopy) {
gras_dict_cursor_t *cursor=NULL;
gras_cfgelm_t *cell=NULL;
char *name=NULL;
- int errcode=no_error;
*whereto=NULL;
gras_assert0(tocopy,"cannot copy NULL config");
gras_dict_foreach((gras_dict_t*)tocopy,cursor,name,cell) {
- if ((errcode=gras_cfg_register(*whereto, name, cell->type,
- cell->min, cell->max)) != no_error) {
- if (cursor) gras_dict_cursor_free(cursor);
- if (*whereto) gras_cfg_free(whereto);
- return errcode;
- }
+ gras_cfg_register(*whereto, name, cell->type, cell->min, cell->max);
}
-
- return errcode;
}
void gras_cfg_free(gras_cfg_t **cfg) {
* register an element within a config set
*/
-gras_error_t
+void
gras_cfg_register(gras_cfg_t *cfg,
const char *name, gras_cfgelm_type_t type,
int min, int max){
gras_error_t errcode;
DEBUG4("Register cfg elm %s (%d to %d %s)",name,min,max,gras_cfgelm_type_name[type]);
- TRYCATCH(mismatch_error,gras_dict_get((gras_dict_t*)cfg,name,(void**)&res));
+ errcode = gras_dict_get((gras_dict_t*)cfg,name,(void**)&res);
- if (errcode != mismatch_error) {
+ if (errcode == no_error) {
WARN1("Config elem %s registered twice.",name);
/* Will be removed by the insertion of the new one */
}
+ gras_assert_error(mismatch_error);
res=gras_new(gras_cfgelm_t,1);
- if (!res)
- RAISE_MALLOC;
res->type=type;
res->min=min;
switch (type) {
case gras_cfgelm_int:
- TRY(gras_dynar_new(&(res->content), sizeof(int), NULL));
+ gras_dynar_new(&(res->content), sizeof(int), NULL);
break;
case gras_cfgelm_double:
- TRY(gras_dynar_new(&(res->content), sizeof(double), NULL));
+ gras_dynar_new(&(res->content), sizeof(double), NULL);
break;
case gras_cfgelm_string:
- TRY(gras_dynar_new(&(res->content),sizeof(char*),&gras_cfg_str_free));
+ gras_dynar_new(&(res->content),sizeof(char*),&gras_cfg_str_free);
break;
case gras_cfgelm_host:
- TRY(gras_dynar_new(&(res->content),sizeof(gras_host_t*),&gras_cfg_host_free));
+ gras_dynar_new(&(res->content),sizeof(gras_host_t*),&gras_cfg_host_free);
break;
default:
ERROR1("%d is an invalide type code",type);
}
- return gras_dict_set((gras_dict_t*)cfg,name,res,&gras_cfgelm_free);
+ gras_dict_set((gras_dict_t*)cfg,name,res,&gras_cfgelm_free);
}
/**
gras_error_t
gras_cfg_register_str(gras_cfg_t *cfg,const char *entry) {
- char *entrycpy=(char*)strdup(entry);
+ char *entrycpy=gras_strdup(entry);
char *tok;
int min,max;
gras_cfgelm_type_t type;
- gras_error_t errcode;
-
tok=strchr(entrycpy, ':');
if (!tok) {
ERROR3("%s%s%s",
gras_abort();
}
- TRYCLEAN(gras_cfg_register(cfg,entrycpy,type,min,max),
- gras_free(entrycpy));
+ gras_cfg_register(cfg,entrycpy,type,min,max);
gras_free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */
return no_error;
if (!options || !strlen(options)) { /* nothing to do */
return no_error;
}
- optionlist_cpy=(char*)strdup(options);
+ optionlist_cpy=gras_strdup(options);
DEBUG1("List to parse and set:'%s'",options);
option=optionlist_cpy;
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_int,&cell));
if (cell->max > 1) {
- return gras_dynar_push(cell->content,&val);
+ gras_dynar_push(cell->content,&val);
} else {
- return gras_dynar_set(cell->content,0,&val);
+ gras_dynar_set(cell->content,0,&val);
}
+ return no_error;
}
/**
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_double,&cell));
if (cell->max > 1) {
- return gras_dynar_push(cell->content,&val);
+ gras_dynar_push(cell->content,&val);
} else {
- return gras_dynar_set(cell->content,0,&val);
+ gras_dynar_set(cell->content,0,&val);
}
+ return no_error;
}
/**
gras_cfg_set_string(gras_cfg_t *cfg,const char*name, const char*val) {
gras_cfgelm_t *cell;
gras_error_t errcode;
- char *newval = (char*)strdup(val);
+ char *newval = gras_strdup(val);
VERB2("Configuration setting: %s=%s",name,val);
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_string,&cell));
if (cell->max > 1) {
- return gras_dynar_push(cell->content,&newval);
+ gras_dynar_push(cell->content,&newval);
} else {
- return gras_dynar_set(cell->content,0,&newval);
+ gras_dynar_set(cell->content,0,&newval);
}
+ return no_error;
}
/**
gras_host_t *val=gras_new(gras_host_t,1);
VERB3("Configuration setting: %s=%s:%d",name,host,port);
- if (!val)
- RAISE_MALLOC;
- val->name = (char*)strdup(name);
+
+ val->name = gras_strdup(name);
val->port = port;
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_host,&cell));
if (cell->max > 1) {
- return gras_dynar_push(cell->content,&val);
+ gras_dynar_push(cell->content,&val);
} else {
- return gras_dynar_set(cell->content,0,&val);
+ gras_dynar_set(cell->content,0,&val);
}
+ return no_error;
}
/* ---- [ Removing ] ---- */