allow configuration input (typically CYCLONEDDS_URI) to include XML fragments
The configuration handling already allowed specifying multiple files in CYCLONEDDS_URI to be read in-order, this extends the behaviour to also allow the contents of these files to be embedded. This makes it possible to set a configuration without requiring a file system, or to add some ad-hoc options. Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
15a3d7d3ad
commit
a39701fc2e
1 changed files with 47 additions and 29 deletions
|
@ -2773,12 +2773,33 @@ struct cfgst * config_init (const char *configfile)
|
|||
|
||||
/* configfile == NULL will get you the default configuration */
|
||||
if (configfile) {
|
||||
char *copy = ddsrt_strdup(configfile), *cursor = copy, *tok;
|
||||
while ( (tok = ddsrt_strsep(&cursor, ",")) != NULL ) {
|
||||
char *copy = ddsrt_strdup(configfile), *cursor = copy;
|
||||
struct ut_xmlpCallbacks cb;
|
||||
|
||||
cb.attr = proc_attr;
|
||||
cb.elem_close = proc_elem_close;
|
||||
cb.elem_data = proc_elem_data;
|
||||
cb.elem_open = proc_elem_open;
|
||||
cb.error = proc_error;
|
||||
|
||||
while (ok && cursor && cursor[0]) {
|
||||
struct ut_xmlpState *qx;
|
||||
FILE *fp;
|
||||
|
||||
char *tok;
|
||||
tok = cursor;
|
||||
if (tok[0] == '<') {
|
||||
/* Read XML directly from input string */
|
||||
qx = ut_xmlpNewString (tok, cfgst, &cb);
|
||||
ut_xmlpSetRequireEOF (qx, 0);
|
||||
fp = NULL;
|
||||
} else {
|
||||
char *comma;
|
||||
if ((comma = strchr (cursor, ',')) == NULL) {
|
||||
cursor = NULL;
|
||||
} else {
|
||||
*comma = 0;
|
||||
cursor = comma + 1;
|
||||
}
|
||||
DDSRT_WARNING_MSVC_OFF(4996);
|
||||
if ((fp = fopen(tok, "r")) == NULL) {
|
||||
if (strncmp(tok, "file://", 7) != 0 || (fp = fopen(tok + 7, "r")) == NULL) {
|
||||
|
@ -2789,28 +2810,25 @@ struct cfgst * config_init (const char *configfile)
|
|||
}
|
||||
}
|
||||
DDSRT_WARNING_MSVC_ON(4996);
|
||||
|
||||
cb.attr = proc_attr;
|
||||
cb.elem_close = proc_elem_close;
|
||||
cb.elem_data = proc_elem_data;
|
||||
cb.elem_open = proc_elem_open;
|
||||
cb.error = proc_error;
|
||||
|
||||
if ( (qx = ut_xmlpNewFile(fp, cfgst, &cb)) == NULL ) {
|
||||
fclose(fp);
|
||||
ddsrt_free(copy);
|
||||
ddsrt_free(cfgst);
|
||||
return NULL;
|
||||
qx = ut_xmlpNewFile(fp, cfgst, &cb);
|
||||
}
|
||||
cfgst_push(cfgst, 0, &root_cfgelem, &config);
|
||||
|
||||
ok = (ut_xmlpParse(qx) >= 0) && !cfgst->error;
|
||||
/* Pop until stack empty: error handling is rather brutal */
|
||||
assert(!ok || cfgst->path_depth == 1);
|
||||
while ( cfgst->path_depth > 0 )
|
||||
while (cfgst->path_depth > 0) {
|
||||
cfgst_pop(cfgst);
|
||||
ut_xmlpFree(qx);
|
||||
}
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
} else if (ok) {
|
||||
cursor = tok + ut_xmlpGetBufpos (qx);
|
||||
}
|
||||
ut_xmlpFree(qx);
|
||||
while (cursor && cursor[0] == ',') {
|
||||
cursor++;
|
||||
}
|
||||
}
|
||||
ddsrt_free(copy);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue