static VBUCKET_CONFIG_HANDLE parse_cjson(cJSON *config) { cJSON *json; struct vbucket_config_st *vb; vb = calloc(1, sizeof(struct vbucket_config_st)); if (vb == NULL) { errstr = "Failed to allocate vbucket config struct"; return NULL; } /* set optional credentials */ json = cJSON_GetObjectItem(config, "name"); if (json != NULL && json->type == cJSON_String && strcmp(json->valuestring, "default") != 0) { vb->user = strdup(json->valuestring); } json = cJSON_GetObjectItem(config, "saslPassword"); if (json != NULL && json->type == cJSON_String) { vb->password = strdup(json->valuestring); } /* by default it uses vbucket distribution to map keys to servers */ vb->distribution = VBUCKET_DISTRIBUTION_VBUCKET; json = cJSON_GetObjectItem(config, "nodeLocator"); if (json == NULL) { /* special case: it migth be config without envelope */ if (parse_vbucket_config(vb, config) == NULL) { vbucket_config_destroy(vb); return NULL; } } else if (json->type == cJSON_String) { if (strcmp(json->valuestring, "vbucket") == 0) { vb->distribution = VBUCKET_DISTRIBUTION_VBUCKET; if (parse_vbucket_config(vb, config) == NULL) { vbucket_config_destroy(vb); return NULL; } } else if (strcmp(json->valuestring, "ketama") == 0) { vb->distribution = VBUCKET_DISTRIBUTION_KETAMA; if (parse_ketama_config(vb, config) == NULL) { vbucket_config_destroy(vb); return NULL; } } } else { errstr = "Expected string for nodeLocator"; vbucket_config_destroy(vb); return NULL; } return vb; }
static int parse_cjson(VBUCKET_CONFIG_HANDLE handle, cJSON *config) { cJSON *json; /* set optional credentials */ json = cJSON_GetObjectItem(config, "name"); if (json != NULL && json->type == cJSON_String && strcmp(json->valuestring, "default") != 0) { handle->user = strdup(json->valuestring); } json = cJSON_GetObjectItem(config, "saslPassword"); if (json != NULL && json->type == cJSON_String) { handle->password = strdup(json->valuestring); } /* by default it uses vbucket distribution to map keys to servers */ handle->distribution = VBUCKET_DISTRIBUTION_VBUCKET; json = cJSON_GetObjectItem(config, "nodeLocator"); if (json == NULL) { /* special case: it migth be config without envelope */ if (parse_vbucket_config(handle, config) == -1) { return -1; } } else if (json->type == cJSON_String) { if (strcmp(json->valuestring, "vbucket") == 0) { handle->distribution = VBUCKET_DISTRIBUTION_VBUCKET; if (parse_vbucket_config(handle, config) == -1) { return -1; } } else if (strcmp(json->valuestring, "ketama") == 0) { handle->distribution = VBUCKET_DISTRIBUTION_KETAMA; if (parse_ketama_config(handle, config) == -1) { return -1; } } } else { handle->errmsg = strdup("Expected string for nodeLocator"); return -1; } return 0; }