in src/oslogin_utils.cc [1002:1043]
bool ParseJsonToChallenges(const string& json, std::vector<Challenge>* challenges) {
bool ret = false;
json_object* root = ParseJsonRoot(json);
if (root == NULL) {
return ret;
}
json_object* challengeId = NULL;
json_object* challengeType = NULL;
json_object* challengeStatus = NULL;
json_object* jsonChallenges = NULL;
if (!json_object_object_get_ex(root, "challenges", &jsonChallenges)) {
goto cleanup;
}
for (int i = 0; i < (int)json_object_array_length(jsonChallenges); ++i) {
if (!json_object_object_get_ex(json_object_array_get_idx(jsonChallenges, i),
"challengeId", &challengeId)) {
goto cleanup;
}
if (!json_object_object_get_ex(json_object_array_get_idx(jsonChallenges, i),
"challengeType", &challengeType)) {
goto cleanup;
}
if (!json_object_object_get_ex(json_object_array_get_idx(jsonChallenges, i),
"status", &challengeStatus)) {
goto cleanup;
}
Challenge challenge;
challenge.id = json_object_get_int(challengeId);
challenge.type = json_object_get_string(challengeType);
challenge.status = json_object_get_string(challengeStatus);
challenges->push_back(challenge);
}
ret = true;
cleanup:
json_object_put(root);
return ret;
}