bool NssCache::LoadJsonUsersToCache()

in src/oslogin_utils.cc [216:268]


bool NssCache::LoadJsonUsersToCache(string response) {
  Reset();

  json_object* root = ParseJsonRoot(response);
  if (root == NULL) {
    return false;
  }

  bool ret = false;
  int arraylen = 0;
  json_object* login_profiles = NULL;

  // First grab the page token.
  json_object* page_token_object;
  if (json_object_object_get_ex(root, "nextPageToken", &page_token_object)) {
    page_token_ = json_object_get_string(page_token_object);
  } else {
    goto cleanup;
  }

  // A page_token of 0 means we are done. This response will not contain any
  // login profiles.
  if (page_token_ == "0") {
    page_token_ = "";
    on_last_page_ = true;
    ret = true;
    goto cleanup;
  }

  // Now grab all of the loginProfiles.
  if (!json_object_object_get_ex(root, "loginProfiles", &login_profiles)) {
    goto cleanup;
  }

  if (json_object_get_type(login_profiles) != json_type_array) {
    goto cleanup;
  }

  arraylen = json_object_array_length(login_profiles);
  if (arraylen == 0 || arraylen > cache_size_) {
    goto cleanup;
  }

  for (int i = 0; i < arraylen; i++) {
    json_object* profile = json_object_array_get_idx(login_profiles, i);
    entry_cache_.push_back(json_object_to_json_string_ext(profile, JSON_C_TO_STRING_PLAIN));
  }
  ret = true;

cleanup:
  json_object_put(root);
  return ret;
}