diff options
author | Keith Bostic <keith@wiredtiger.com> | 2015-04-15 14:28:59 -0400 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2015-04-15 14:28:59 -0400 |
commit | c4fd5d8eb50897e10116a77a10a0ed180202c94e (patch) | |
tree | 88fade7b8dd803af7f5fafe9ec7ecf88f9d574e5 /src/config/config_api.c | |
parent | ff9c14539f4d68c6671e4463508997740c07437a (diff) | |
download | mongo-c4fd5d8eb50897e10116a77a10a0ed180202c94e.tar.gz |
Instead of requiring applications use our configuration strings, translate
a short list of possible function or method names, where method names are
the public handle (for example, "WT_SESSION"), a dot, and the method name,
for example ("WT_SESSION.create").
Diffstat (limited to 'src/config/config_api.c')
-rw-r--r-- | src/config/config_api.c | 87 |
1 files changed, 78 insertions, 9 deletions
diff --git a/src/config/config_api.c b/src/config/config_api.c index d65bd742347..83a63f95e59 100644 --- a/src/config/config_api.c +++ b/src/config/config_api.c @@ -105,42 +105,111 @@ err: __wt_free(session, config_parser); } /* + * Translation table of the API methods supported by wiredtiger_config_validate + * API. + */ +static const struct { + const char *method; + const char *config; +} name_to_config_list[] = { + { "WT_CONNECTION.async_new_op", "connection.async_new_op" }, + { "WT_CONNECTION.close", "connection.close" }, + { "WT_CONNECTION.load_extension", "connection.load_extension" }, + { "WT_CONNECTION.open_session", "connection.open_session" }, + { "WT_CONNECTION.reconfigure", "connection.reconfigure" }, + { "WT_CURSOR.close", "cursor.close" }, + { "WT_CURSOR.reconfigure", "cursor.reconfigure" }, + { "WT_SESSION.begin_transaction", "session.begin_transaction" }, + { "WT_SESSION.checkpoint", "session.checkpoint" }, + { "WT_SESSION.close", "session.close" }, + { "WT_SESSION.commit_transaction", "session.commit_transaction" }, + { "WT_SESSION.compact", "session.compact" }, + { "WT_SESSION.create", "session.create" }, + { "WT_SESSION.drop", "session.drop" }, + { "WT_SESSION.open_cursor", "session.open_cursor" }, + { "WT_SESSION.reconfigure", "session.reconfigure" }, + { "WT_SESSION.rename", "session.rename" }, + { "WT_SESSION.rollback_transaction", "session.rollback_transaction" }, + { "WT_SESSION.salvage", "session.salvage" }, + { "WT_SESSION.strerror", "session.strerror" }, + { "WT_SESSION.truncate", "session.truncate" }, + { "WT_SESSION.upgrade", "session.upgrade" }, + { "WT_SESSION.verify", "session.verify" }, + { "wiredtiger_open", "wiredtiger_open" }, +}; + +/* + * __wt_name_to_config -- + * Translate a stylized handle/method name to one of our configuration + * entries. + */ +static int +__wt_name_to_config( + WT_SESSION_IMPL *session, const char *method, const char **configp) +{ + u_int base, indx, limit; + int cmp; + + for (base = 0, limit = + WT_ELEMENTS(name_to_config_list); limit != 0; limit >>= 1) { + indx = base + (limit >> 1); + cmp = strcmp(name_to_config_list[indx].method, method); + if (cmp == 0) { + *configp = name_to_config_list[indx].config; + return (0); + } + if (cmp < 0) { + base = indx + 1; + --limit; + } + } + WT_RET_MSG(session, EINVAL, + "unknown or unsupported configuration method: '%s'", method); +} + +/* * wiredtiger_config_validate -- * Validate a configuration string. */ int wiredtiger_config_validate( - WT_SESSION *wt_session, const char *method, const char *config) + WT_SESSION *wt_session, const char *name, const char *config) { WT_CONNECTION_IMPL *conn; WT_SESSION_IMPL *session; const WT_CONFIG_ENTRY *ep, **epp; + const char *trans; session = (WT_SESSION_IMPL *)wt_session; - if (method == NULL) - WT_RET_MSG(session, EINVAL, "no method specified"); + if (name == NULL) + WT_RET_MSG(session, EINVAL, "no name specified"); if (config == NULL) WT_RET_MSG(session, EINVAL, "no configuration specified"); + /* + * Translate the name to a WiredTiger configuration string name. + */ + WT_RET(__wt_name_to_config(session, name, &trans)); + /* - * 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 we don't yet have a connection, look for a matching name 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); + ep = __wt_conn_config_match(trans); else { conn = S2C(session); for (epp = conn->config_entries; (*epp)->method != NULL; ++epp) - if (strcmp((*epp)->method, method) == 0) + if (strcmp((*epp)->method, trans) == 0) break; ep = *epp; } if (ep == NULL || ep->method == NULL) WT_RET_MSG(session, - WT_NOTFOUND, "no method matching %s found", method); + WT_NOTFOUND, "no method matching %s found", name); return (__wt_config_check(session, ep, config, 0)); } |