Permalink
Browse files

Bug 1223: allow json to be nested

Change-Id: I75afe036d0bd46c6d792c32cdd659bc490039532
Reviewed-on: http://review.northscale.com:8080/342
Tested-by: Sean Lynch <seanl@literati.org>
Reviewed-by: Sean Lynch <seanl@literati.org>
  • Loading branch information...
1 parent f51ad6b commit f7a77df3f8c5dadd5d25bc6cc7db8f8dc92ba448 @steveyen steveyen committed with seanlynch Jun 8, 2010
Showing with 30 additions and 2 deletions.
  1. +5 −0 src/vbucket.c
  2. +25 −2 tests/testapp.c
View
@@ -155,6 +155,11 @@ static int populate_buckets(struct vbucket_config_st *vb, cJSON *c) {
}
static VBUCKET_CONFIG_HANDLE parse_cjson(cJSON *c) {
+ cJSON *body = cJSON_GetObjectItem(c, "vbucketServerMap");
+ if (body != NULL) {
+ return parse_cjson(body); // Allows clients to have a JSON envelope.
+ }
+
cJSON *jHashAlgorithm = cJSON_GetObjectItem(c, "hashAlgorithm");
if (jHashAlgorithm == NULL || jHashAlgorithm->type != cJSON_String) {
errstr = "Expected string for hashAlgorithm";
View
@@ -19,6 +19,23 @@ static const char *config =
" ]\n"
"}";
+static const char *configInEnvelope =
+"{ \"otherKeyThatIsIgnored\": 12345,\n"
+ "\"vbucketServerMap\": \n"
+ "{\n"
+ " \"hashAlgorithm\": \"CRC\",\n"
+ " \"numReplicas\": 2,\n"
+ " \"serverList\": [\"server1:11211\", \"server2:11210\", \"server3:11211\"],\n"
+ " \"vBucketMap\":\n"
+ " [\n"
+ " [0, 1, 2],\n"
+ " [1, 2, 0],\n"
+ " [2, 1, -1],\n"
+ " [1, 2, 0]\n"
+ " ]\n"
+ "}"
+"}";
+
struct key_st {
char *key;
int vbucket;
@@ -51,8 +68,8 @@ static const struct vb_st vbuckets[] =
{ 1, { 2, 0 } }
};
-int main(void) {
- VBUCKET_CONFIG_HANDLE vb = vbucket_config_parse_string(config);
+static void testConfig(const char *c) {
+ VBUCKET_CONFIG_HANDLE vb = vbucket_config_parse_string(c);
if (vb == NULL) {
fprintf(stderr, "vbucket_config_parse_string error: %s\n", vbucket_get_error());
abort();
@@ -90,3 +107,9 @@ int main(void) {
vbucket_config_destroy(vb);
}
+int main(void) {
+ testConfig(config);
+ testConfig(configInEnvelope);
+}
+
+

0 comments on commit f7a77df

Please sign in to comment.