diff options
-rw-r--r-- | build_win/wiredtiger.def | 1 | ||||
-rw-r--r-- | dist/api_config.py | 15 | ||||
-rw-r--r-- | dist/s_export.list | 1 | ||||
-rw-r--r-- | dist/s_funcs.list | 1 | ||||
-rw-r--r-- | examples/c/ex_all.c | 5 | ||||
-rw-r--r-- | src/config/config_api.c | 44 | ||||
-rw-r--r-- | src/config/config_def.c | 15 | ||||
-rw-r--r-- | src/include/extern.h | 1 | ||||
-rw-r--r-- | src/include/wiredtiger.in | 20 |
9 files changed, 100 insertions, 3 deletions
diff --git a/build_win/wiredtiger.def b/build_win/wiredtiger.def index 86096fb778d..25e7a01e0d9 100644 --- a/build_win/wiredtiger.def +++ b/build_win/wiredtiger.def @@ -1,6 +1,7 @@ LIBRARY WIREDTIGER EXPORTS wiredtiger_config_parser_open + wiredtiger_config_validate wiredtiger_open wiredtiger_pack_close wiredtiger_pack_int diff --git a/dist/api_config.py b/dist/api_config.py index 83a57ad4e0d..0514b20c7c2 100644 --- a/dist/api_config.py +++ b/dist/api_config.py @@ -311,6 +311,21 @@ __wt_conn_config_discard(WT_SESSION_IMPL *session) \t__wt_free(session, conn->config_entries); } + +/* + * __wt_conn_config_match -- + * Return the static configuration entry for a method. + */ +const WT_CONFIG_ENTRY * +__wt_conn_config_match(const char *method) +{ +\tconst WT_CONFIG_ENTRY *ep; + +\tfor (ep = config_entries; ep->method != NULL; ++ep) +\t\tif (strcmp(method, ep->method) == 0) +\t\t\treturn (ep); +\treturn (NULL); +} ''') tfile.close() diff --git a/dist/s_export.list b/dist/s_export.list index d3803bc3afa..c7f088bc2d5 100644 --- a/dist/s_export.list +++ b/dist/s_export.list @@ -1,5 +1,6 @@ # List of OK external symbols. wiredtiger_config_parser_open +wiredtiger_config_validate wiredtiger_open wiredtiger_pack_close wiredtiger_pack_int diff --git a/dist/s_funcs.list b/dist/s_funcs.list index 4bb9796c11f..9b343e21507 100644 --- a/dist/s_funcs.list +++ b/dist/s_funcs.list @@ -30,6 +30,7 @@ __wt_nlpo2_round __wt_print_huffman_code __wt_try_readlock wiredtiger_config_parser_open +wiredtiger_config_validate wiredtiger_pack_int wiredtiger_pack_item wiredtiger_pack_str diff --git a/examples/c/ex_all.c b/examples/c/ex_all.c index 51c63e307c6..b27fcbfdcea 100644 --- a/examples/c/ex_all.c +++ b/examples/c/ex_all.c @@ -885,6 +885,11 @@ connection_ops(WT_CONNECTION *conn) } /*! [Check if the database is newly created] */ + /*! [Validate a configuration string] */ + ret = wiredtiger_config_validate( + NULL, "session.create", "allocation_size=32KB"); + /*! [Validate a configuration string] */ + { /*! [Open a session] */ WT_SESSION *session; 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)); +} diff --git a/src/config/config_def.c b/src/config/config_def.c index 43d87c518e4..19d2f0a49a1 100644 --- a/src/config/config_def.c +++ b/src/config/config_def.c @@ -793,3 +793,18 @@ __wt_conn_config_discard(WT_SESSION_IMPL *session) __wt_free(session, conn->config_entries); } + +/* + * __wt_conn_config_match -- + * Return the static configuration entry for a method. + */ +const WT_CONFIG_ENTRY * +__wt_conn_config_match(const char *method) +{ + const WT_CONFIG_ENTRY *ep; + + for (ep = config_entries; ep->method != NULL; ++ep) + if (strcmp(method, ep->method) == 0) + return (ep); + return (NULL); +} diff --git a/src/include/extern.h b/src/include/extern.h index bddbb5e01eb..afc48fb3dcd 100644 --- a/src/include/extern.h +++ b/src/include/extern.h @@ -196,6 +196,7 @@ extern int __wt_config_merge( WT_SESSION_IMPL *session, const char **cfg, const extern int __wt_config_concat( WT_SESSION_IMPL *session, const char **cfg, char **config_ret); extern int __wt_conn_config_init(WT_SESSION_IMPL *session); extern void __wt_conn_config_discard(WT_SESSION_IMPL *session); +extern const WT_CONFIG_ENTRY *__wt_conn_config_match(const char *method); extern int __wt_ext_config_parser_open(WT_EXTENSION_API *wt_ext, WT_SESSION *wt_session, const char *config, size_t len, WT_CONFIG_PARSER **config_parserp); extern int __wt_ext_config_get(WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, WT_CONFIG_ARG *cfg_arg, const char *key, WT_CONFIG_ITEM *cval); extern int __wt_config_upgrade(WT_SESSION_IMPL *session, WT_ITEM *buf); diff --git a/src/include/wiredtiger.in b/src/include/wiredtiger.in index fea6fc6c948..4796280e908 100644 --- a/src/include/wiredtiger.in +++ b/src/include/wiredtiger.in @@ -2399,7 +2399,7 @@ int wiredtiger_unpack_uint(WT_PACK_STREAM *ps, uint64_t *up); /*! @} */ /*! - * @name Configuration string parsing + * @name Configuration strings * @{ */ @@ -2456,6 +2456,22 @@ struct __wt_config_item { }; /*! + * Validate a configuration string for a WiredTiger API. + * This API is outside the scope of a WiredTiger connection handle, since + * applications may need to validate configuration strings prior to calling + * ::wiredtiger_open. + * @param session the session handle to be used for error reporting (if NULL, + * error messages will be written to stderr). + * @param method the WiredTiger function or method to check. + * @param config the configuration string being parsed. + * @returns zero for success, non-zero to indicate an error. + * + * @snippet ex_all.c Validate a configuration string + */ +int wiredtiger_config_validate( + WT_SESSION *session, const char *method, const char *config); + +/*! * Create a handle that can be used to parse or create configuration strings * compatible with WiredTiger APIs. * This API is outside the scope of a WiredTiger connection handle, since @@ -2468,6 +2484,8 @@ struct __wt_config_item { * @param len the number of valid bytes in \c config * @param[out] config_parserp A pointer to the newly opened handle * @errors + * + * @snippet ex_config_parse.c Create a configuration parser */ int wiredtiger_config_parser_open(WT_SESSION *session, const char *config, size_t len, WT_CONFIG_PARSER **config_parserp); |