diff options
author | Keith Bostic <keith@wiredtiger.com> | 2015-03-09 16:36:42 -0400 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2015-03-09 16:36:42 -0400 |
commit | d2f6ef9c460853dfd79cf436bc8bb5b626c0fd15 (patch) | |
tree | 4f326106c1989dd1b20b2f048d3397d92e8ba562 /src/config/config_api.c | |
parent | bb3214315624f9d58de05e36aeba4124ac351fba (diff) | |
download | mongo-d2f6ef9c460853dfd79cf436bc8bb5b626c0fd15.tar.gz |
Add an API to validate configuration strings.
Diffstat (limited to 'src/config/config_api.c')
-rw-r--r-- | src/config/config_api.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/config/config_api.c b/src/config/config_api.c index d956b2d677d..d65bd742347 100644 --- a/src/config/config_api.c +++ b/src/config/config_api.c @@ -94,8 +94,7 @@ wiredtiger_config_parser_open(WT_SESSION *wt_session, * structure for iterations through the configuration string. */ memcpy(&config_parser->config_item, &config_item, sizeof(config_item)); - WT_ERR(__wt_config_initn( - session, &config_parser->config, config, len)); + WT_ERR(__wt_config_initn(session, &config_parser->config, config, len)); if (ret == 0) *config_parserp = (WT_CONFIG_PARSER *)config_parser; @@ -104,3 +103,44 @@ err: __wt_free(session, config_parser); return (ret); } + +/* + * wiredtiger_config_validate -- + * Validate a configuration string. + */ +int +wiredtiger_config_validate( + WT_SESSION *wt_session, const char *method, const char *config) +{ + WT_CONNECTION_IMPL *conn; + WT_SESSION_IMPL *session; + const WT_CONFIG_ENTRY *ep, **epp; + + session = (WT_SESSION_IMPL *)wt_session; + + if (method == NULL) + WT_RET_MSG(session, EINVAL, "no method specified"); + if (config == NULL) + WT_RET_MSG(session, EINVAL, "no configuration specified"); + + /* + * If we don't yet have a connection, look for a matching method in + * the static list, otherwise look in the configuration list (which + * has any configuration information the application has added). + */ + if (session == NULL) + ep = __wt_conn_config_match(method); + else { + conn = S2C(session); + + for (epp = conn->config_entries; (*epp)->method != NULL; ++epp) + if (strcmp((*epp)->method, method) == 0) + break; + ep = *epp; + } + if (ep == NULL || ep->method == NULL) + WT_RET_MSG(session, + WT_NOTFOUND, "no method matching %s found", method); + + return (__wt_config_check(session, ep, config, 0)); +} |