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
|
@ -2772,23 +2772,9 @@ struct cfgst * config_init (const char *configfile)
|
||||||
cfgst->error = 0;
|
cfgst->error = 0;
|
||||||
|
|
||||||
/* configfile == NULL will get you the default configuration */
|
/* configfile == NULL will get you the default configuration */
|
||||||
if ( configfile ) {
|
if (configfile) {
|
||||||
char *copy = ddsrt_strdup(configfile), *cursor = copy, *tok;
|
char *copy = ddsrt_strdup(configfile), *cursor = copy;
|
||||||
while ( (tok = ddsrt_strsep(&cursor, ",")) != NULL ) {
|
|
||||||
struct ut_xmlpCallbacks cb;
|
struct ut_xmlpCallbacks cb;
|
||||||
struct ut_xmlpState *qx;
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
DDSRT_WARNING_MSVC_OFF(4996);
|
|
||||||
if ( (fp = fopen(tok, "r")) == NULL ) {
|
|
||||||
if ( strncmp(tok, "file://", 7) != 0 || (fp = fopen(tok + 7, "r")) == NULL ) {
|
|
||||||
DDS_ERROR("can't open configuration file %s\n", tok);
|
|
||||||
ddsrt_free(copy);
|
|
||||||
ddsrt_free(cfgst);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DDSRT_WARNING_MSVC_ON(4996);
|
|
||||||
|
|
||||||
cb.attr = proc_attr;
|
cb.attr = proc_attr;
|
||||||
cb.elem_close = proc_elem_close;
|
cb.elem_close = proc_elem_close;
|
||||||
|
@ -2796,21 +2782,53 @@ struct cfgst * config_init (const char *configfile)
|
||||||
cb.elem_open = proc_elem_open;
|
cb.elem_open = proc_elem_open;
|
||||||
cb.error = proc_error;
|
cb.error = proc_error;
|
||||||
|
|
||||||
if ( (qx = ut_xmlpNewFile(fp, cfgst, &cb)) == NULL ) {
|
while (ok && cursor && cursor[0]) {
|
||||||
fclose(fp);
|
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) {
|
||||||
|
DDS_ERROR("can't open configuration file %s\n", tok);
|
||||||
ddsrt_free(copy);
|
ddsrt_free(copy);
|
||||||
ddsrt_free(cfgst);
|
ddsrt_free(cfgst);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
DDSRT_WARNING_MSVC_ON(4996);
|
||||||
|
qx = ut_xmlpNewFile(fp, cfgst, &cb);
|
||||||
|
}
|
||||||
cfgst_push(cfgst, 0, &root_cfgelem, &config);
|
cfgst_push(cfgst, 0, &root_cfgelem, &config);
|
||||||
|
|
||||||
ok = (ut_xmlpParse(qx) >= 0) && !cfgst->error;
|
ok = (ut_xmlpParse(qx) >= 0) && !cfgst->error;
|
||||||
/* Pop until stack empty: error handling is rather brutal */
|
/* Pop until stack empty: error handling is rather brutal */
|
||||||
assert(!ok || cfgst->path_depth == 1);
|
assert(!ok || cfgst->path_depth == 1);
|
||||||
while ( cfgst->path_depth > 0 )
|
while (cfgst->path_depth > 0) {
|
||||||
cfgst_pop(cfgst);
|
cfgst_pop(cfgst);
|
||||||
ut_xmlpFree(qx);
|
}
|
||||||
|
if (fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
} else if (ok) {
|
||||||
|
cursor = tok + ut_xmlpGetBufpos (qx);
|
||||||
|
}
|
||||||
|
ut_xmlpFree(qx);
|
||||||
|
while (cursor && cursor[0] == ',') {
|
||||||
|
cursor++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ddsrt_free(copy);
|
ddsrt_free(copy);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue