summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@mongodb.com>2016-11-14 14:09:19 +1100
committerGitHub <noreply@github.com>2016-11-14 14:09:19 +1100
commit25f02285b804413361835d89caa4c195b93dcfdc (patch)
tree1b9eb63a8e84551a07243487c83b6b16764fdc8f /ext
parent370154159bc7e3b06488cbdf7deb0585baf841b6 (diff)
downloadmongo-25f02285b804413361835d89caa4c195b93dcfdc.tar.gz
WT-2962 Allow configuration of builtin extensions. (#3137)
While in the area, fix sending "config={values}" to extensions: just the values should be passed in.
Diffstat (limited to 'ext')
-rw-r--r--ext/compressors/zlib/zlib_compress.c57
-rw-r--r--ext/compressors/zstd/zstd_compress.c37
-rw-r--r--ext/datasources/helium/helium.c10
-rw-r--r--ext/encryptors/rotn/rotn_encrypt.c42
4 files changed, 35 insertions, 111 deletions
diff --git a/ext/compressors/zlib/zlib_compress.c b/ext/compressors/zlib/zlib_compress.c
index 3665ec48b9a..09a793646e7 100644
--- a/ext/compressors/zlib/zlib_compress.c
+++ b/ext/compressors/zlib/zlib_compress.c
@@ -483,8 +483,7 @@ static int
zlib_init_config(
WT_CONNECTION *connection, WT_CONFIG_ARG *config, int *zlib_levelp)
{
- WT_CONFIG_ITEM k, v;
- WT_CONFIG_PARSER *config_parser;
+ WT_CONFIG_ITEM v;
WT_EXTENSION_API *wt_api;
int ret, zlib_level;
@@ -497,49 +496,27 @@ zlib_init_config(
* level; review the configuration.
*/
wt_api = connection->get_extension_api(connection);
- if ((ret =
- wt_api->config_get(wt_api, NULL, config, "config", &v)) != 0) {
- (void)wt_api->err_printf(wt_api, NULL,
- "WT_EXTENSION_API.config_get: zlib configure: %s",
- wt_api->strerror(wt_api, NULL, ret));
- return (ret);
- }
- if ((ret = wt_api->config_parser_open(
- wt_api, NULL, v.str, v.len, &config_parser)) != 0) {
- (void)wt_api->err_printf(wt_api, NULL,
- "WT_EXTENSION_API.config_parser_open: zlib configure: %s",
- wt_api->strerror(wt_api, NULL, ret));
- return (ret);
- }
- while ((ret = config_parser->next(config_parser, &k, &v)) == 0)
- if (strlen("compression_level") == k.len &&
- strncmp("compression_level", k.str, k.len) == 0) {
- /*
- * Between 0-9: level: see zlib manual.
- */
- zlib_level = (int)v.val;
- if (zlib_level < 0 || zlib_level > 9) {
- (void)wt_api->err_printf(wt_api, NULL,
- "WT_CONFIG_PARSER.next: zlib configure: "
- "unsupported compression level %d",
- zlib_level);
- return (EINVAL);
- }
- *zlib_levelp = zlib_level;
- continue;
+ if ((ret = wt_api->config_get(
+ wt_api, NULL, config, "compression_level", &v)) == 0) {
+ /*
+ * Between 0-9: level: see zlib manual.
+ */
+ zlib_level = (int)v.val;
+ if (zlib_level < 0 || zlib_level > 9) {
+ (void)wt_api->err_printf(wt_api, NULL,
+ "zlib_init_config: "
+ "unsupported compression level %d",
+ zlib_level);
+ return (EINVAL);
}
- if (ret != WT_NOTFOUND) {
- (void)wt_api->err_printf(wt_api, NULL,
- "WT_CONFIG_PARSER.next: zlib configure: %s",
- wt_api->strerror(wt_api, NULL, ret));
- return (ret);
- }
- if ((ret = config_parser->close(config_parser)) != 0) {
+ *zlib_levelp = zlib_level;
+ } else if (ret != WT_NOTFOUND) {
(void)wt_api->err_printf(wt_api, NULL,
- "WT_CONFIG_PARSER.close: zlib configure: %s",
+ "zlib_init_config: %s",
wt_api->strerror(wt_api, NULL, ret));
return (ret);
}
+
return (0);
}
diff --git a/ext/compressors/zstd/zstd_compress.c b/ext/compressors/zstd/zstd_compress.c
index a459b01d60a..ea8ec97602f 100644
--- a/ext/compressors/zstd/zstd_compress.c
+++ b/ext/compressors/zstd/zstd_compress.c
@@ -232,8 +232,7 @@ static int
zstd_init_config(
WT_CONNECTION *connection, WT_CONFIG_ARG *config, int *compression_levelp)
{
- WT_CONFIG_ITEM k, v;
- WT_CONFIG_PARSER *config_parser;
+ WT_CONFIG_ITEM v;
WT_EXTENSION_API *wt_api;
int ret;
@@ -246,38 +245,16 @@ zstd_init_config(
* level; review the configuration.
*/
wt_api = connection->get_extension_api(connection);
- if ((ret =
- wt_api->config_get(wt_api, NULL, config, "config", &v)) != 0) {
- (void)wt_api->err_printf(wt_api, NULL,
- "WT_EXTENSION_API.config_get: zstd configure: %s",
- wt_api->strerror(wt_api, NULL, ret));
- return (ret);
- }
- if ((ret = wt_api->config_parser_open(
- wt_api, NULL, v.str, v.len, &config_parser)) != 0) {
- (void)wt_api->err_printf(wt_api, NULL,
- "WT_EXTENSION_API.config_parser_open: zstd configure: %s",
- wt_api->strerror(wt_api, NULL, ret));
- return (ret);
- }
- while ((ret = config_parser->next(config_parser, &k, &v)) == 0)
- if (strlen("compression_level") == k.len &&
- strncmp("compression_level", k.str, k.len) == 0) {
- *compression_levelp = (int)v.val;
- continue;
- }
- if (ret != WT_NOTFOUND) {
+ if ((ret = wt_api->config_get(
+ wt_api, NULL, config, "compression_level", &v)) == 0)
+ *compression_levelp = (int)v.val;
+ else if (ret != WT_NOTFOUND) {
(void)wt_api->err_printf(wt_api, NULL,
- "WT_CONFIG_PARSER.next: zstd configure: %s",
- wt_api->strerror(wt_api, NULL, ret));
- return (ret);
- }
- if ((ret = config_parser->close(config_parser)) != 0) {
- (void)wt_api->err_printf(wt_api, NULL,
- "WT_CONFIG_PARSER.close: zstd configure: %s",
+ "zstd_init_config: %s",
wt_api->strerror(wt_api, NULL, ret));
return (ret);
}
+
return (0);
}
diff --git a/ext/datasources/helium/helium.c b/ext/datasources/helium/helium.c
index 473c569f0cc..dff86bd73ac 100644
--- a/ext/datasources/helium/helium.c
+++ b/ext/datasources/helium/helium.c
@@ -3380,15 +3380,9 @@ wiredtiger_extension_init(WT_CONNECTION *connection, WT_CONFIG_ARG *config)
goto err;
ds->lockinit = 1;
- /* Get the configuration string. */
- if ((ret = wt_api->config_get(wt_api, NULL, config, "config", &v)) != 0)
- EMSG_ERR(wt_api, NULL, ret,
- "WT_EXTENSION_API.config_get: config: %s",
- wt_api->strerror(wt_api, NULL, ret));
-
/* Step through the list of Helium sources, opening each one. */
- if ((ret = wt_api->config_parser_open(
- wt_api, NULL, v.str, v.len, &config_parser)) != 0)
+ if ((ret = wt_api->config_parser_open_arg(
+ wt_api, NULL, config, &config_parser)) != 0)
EMSG_ERR(wt_api, NULL, ret,
"WT_EXTENSION_API.config_parser_open: config: %s",
wt_api->strerror(wt_api, NULL, ret));
diff --git a/ext/encryptors/rotn/rotn_encrypt.c b/ext/encryptors/rotn/rotn_encrypt.c
index 559c8e6e33a..0b905a0540d 100644
--- a/ext/encryptors/rotn/rotn_encrypt.c
+++ b/ext/encryptors/rotn/rotn_encrypt.c
@@ -76,7 +76,7 @@ typedef struct {
u_char *shift_forw; /* Encrypt shift data from secretkey */
u_char *shift_back; /* Decrypt shift data from secretkey */
size_t shift_len; /* Length of shift* byte arrays */
- int force_error; /* Force a decrypt error for testing */
+ bool force_error; /* Force a decrypt error for testing */
} ROTN_ENCRYPTOR;
/*! [WT_ENCRYPTOR initialization structure] */
@@ -429,43 +429,19 @@ rotn_terminate(WT_ENCRYPTOR *encryptor, WT_SESSION *session)
static int
rotn_configure(ROTN_ENCRYPTOR *rotn_encryptor, WT_CONFIG_ARG *config)
{
- WT_CONFIG_ITEM k, v;
- WT_CONFIG_PARSER *config_parser;
+ WT_CONFIG_ITEM v;
WT_EXTENSION_API *wt_api; /* Extension API */
- int ret, t_ret;
+ int ret;
wt_api = rotn_encryptor->wt_api;
/* Get the configuration string. */
- if ((ret = wt_api->config_get(wt_api, NULL, config, "config", &v)) != 0)
- return (rotn_error(rotn_encryptor, NULL, ret,
- "WT_EXTENSION_API.config_get"));
-
- /* Step through the list of configuration options. */
- if ((ret = wt_api->config_parser_open(
- wt_api, NULL, v.str, v.len, &config_parser)) != 0)
- return (rotn_error(rotn_encryptor, NULL, ret,
- "WT_EXTENSION_API.config_parser_open"));
-
- while ((ret = config_parser->next(config_parser, &k, &v)) == 0) {
- if (strncmp("rotn_force_error", k.str, k.len) == 0 &&
- strlen("rotn_force_error") == k.len) {
- rotn_encryptor->force_error = v.val == 0 ? 0 : 1;
- continue;
- } else {
- if ((ret = config_parser->close(config_parser)) != 0)
- return (rotn_error(rotn_encryptor,
- NULL, ret, "WT_CONFIG_PARSER.close"));
- return (rotn_error(rotn_encryptor, NULL, EINVAL,
- "unknown config key"));
- }
- }
- if ((t_ret = config_parser->close(config_parser)) != 0)
- return (rotn_error(rotn_encryptor, NULL, t_ret,
- "WT_CONFIG_PARSER.close"));
- if (ret != WT_NOTFOUND)
- return (rotn_error(rotn_encryptor, NULL, ret,
- "WT_CONFIG_PARSER.next"));
+ if ((ret = wt_api->config_get(
+ wt_api, NULL, config, "rotn_force_error", &v)) == 0)
+ rotn_encryptor->force_error = v.val != 0;
+ else if (ret != WT_NOTFOUND)
+ return (rotn_error(rotn_encryptor, NULL, EINVAL,
+ "error parsing config"));
return (0);
}