diff options
author | Keith Bostic <keith@wiredtiger.com> | 2015-04-19 11:56:22 -0400 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2015-04-19 11:56:22 -0400 |
commit | 7aee6d5dabb7942aeb685e797b103c47c9337186 (patch) | |
tree | 806540fecb090c390401fd228bc837df937c17c0 /src/config/config_collapse.c | |
parent | c1084903ff665e599c35a2e88d91da72afcf6332 (diff) | |
download | mongo-7aee6d5dabb7942aeb685e797b103c47c9337186.tar.gz |
Add support to the __wt_config_merge() call to remove strings we don't
want in the final configuration string, then strip out "create=" and
"encryption=(secretkey=)".
Diffstat (limited to 'src/config/config_collapse.c')
-rw-r--r-- | src/config/config_collapse.c | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/src/config/config_collapse.c b/src/config/config_collapse.c index 23cb03c9b3a..564798ecc42 100644 --- a/src/config/config_collapse.c +++ b/src/config/config_collapse.c @@ -92,6 +92,7 @@ err: __wt_scr_free(session, &tmp); typedef struct { char *k, *v; /* key, value */ size_t gen; /* generation */ + int strip; /* remove the value */ } WT_CONFIG_MERGE_ENTRY; /* @@ -110,7 +111,7 @@ typedef struct { */ static int __config_merge_scan(WT_SESSION_IMPL *session, - const char *key, const char *value, WT_CONFIG_MERGE *cp) + const char *key, const char *value, int strip, WT_CONFIG_MERGE *cp) { WT_CONFIG cparser; WT_CONFIG_ITEM k, v; @@ -180,7 +181,7 @@ __config_merge_scan(WT_SESSION_IMPL *session, if (v.type == WT_CONFIG_ITEM_STRUCT && strchr(vb->data, '=') != NULL) { WT_ERR(__config_merge_scan( - session, kb->data, vb->data, cp)); + session, kb->data, vb->data, strip, cp)); continue; } @@ -193,6 +194,7 @@ __config_merge_scan(WT_SESSION_IMPL *session, WT_ERR(__wt_strndup(session, vb->data, vb->size, &cp->entries[cp->entries_next].v)); cp->entries[cp->entries_next].gen = cp->entries_next; + cp->entries[cp->entries_next].strip = strip; ++cp->entries_next; } WT_ERR_NOTFOUND_OK(ret); @@ -222,8 +224,8 @@ __config_merge_format_next(WT_SESSION_IMPL *session, const char *prefix, size_t plen, size_t *enp, WT_CONFIG_MERGE *cp, WT_ITEM *build) { WT_CONFIG_MERGE_ENTRY *ep; - size_t len1, len2, next; - char *p; + size_t len1, len2, next, saved_len; + const char *p; for (; *enp < cp->entries_next; ++*enp) { ep = &cp->entries[*enp]; @@ -267,6 +269,9 @@ __config_merge_format_next(WT_SESSION_IMPL *session, const char *prefix, * new level. */ if ((p = strchr(ep->k + plen, SEPC)) != NULL) { + /* Save the start location of the new level. */ + saved_len = build->size; + next = WT_PTRDIFF(p, ep->k); WT_RET(__wt_buf_catfmt(session, build, "%.*s=(", (int)(next - plen), ep->k + plen)); @@ -274,9 +279,22 @@ __config_merge_format_next(WT_SESSION_IMPL *session, const char *prefix, session, ep->k, next + 1, enp, cp, build)); __strip_comma(build); WT_RET(__wt_buf_catfmt(session, build, "),")); + + /* + * It's possible the level contained nothing, check and + * discard empty levels. + */ + p = build->data; + if (p[build->size - 3] == '(') + build->size = saved_len; + continue; } + /* Discard flagged entries. */ + if (ep->strip) + continue; + /* Append the entry to the buffer. */ WT_RET(__wt_buf_catfmt( session, build, "%s=%s,", ep->k + plen, ep->v)); @@ -330,23 +348,26 @@ __config_merge_cmp(const void *a, const void *b) /* * __wt_config_merge -- - * Merge a set of configuration strings into newly allocated memory. + * Merge a set of configuration strings into newly allocated memory, + * optionally discarding configuration items. * * This function takes a NULL-terminated list of configuration strings (where * the values are in order from least to most preferred), and merges them into * newly allocated memory. The algorithm is to walk the configuration strings * and build a table of each key/value pair. The pairs are sorted based on the * name and the configuration string in which they were found, and a final - * configuration string is built from the result. + * configuration string is built from the result. Additionally, a configuration + * string can be specified and those configuration values are removed from the + * final string. * * Note: - * Nested structures are parsed and merge. For example, if configuration + * Nested structures are parsed and merged. For example, if configuration * strings "key=(k1=v1,k2=v2)" and "key=(k1=v2)" appear, the result will * be "key=(k1=v2,k2=v2)" because the nested values are merged. */ int -__wt_config_merge( - WT_SESSION_IMPL *session, const char **cfg, const char **config_ret) +__wt_config_merge(WT_SESSION_IMPL *session, + const char **cfg, const char *cfg_strip, const char **config_ret) { WT_CONFIG_MERGE merge; WT_DECL_RET; @@ -358,9 +379,16 @@ __wt_config_merge( WT_RET(__wt_realloc_def( session, &merge.entries_allocated, 100, &merge.entries)); - /* Scan the configuration strings, entering them into the array. */ + /* + * Scan the configuration strings, entering them into the array. The + * list of configuration values to be removed must be scanned last + * so their generation numbers are the highest. + */ for (; *cfg != NULL; ++cfg) - WT_ERR(__config_merge_scan(session, NULL, *cfg, &merge)); + WT_ERR(__config_merge_scan(session, NULL, *cfg, 0, &merge)); + if (cfg_strip != NULL) + WT_ERR( + __config_merge_scan(session, NULL, cfg_strip, 1, &merge)); /* * Sort the array by key and, in the case of identical keys, by |