コード例 #1
0
ファイル: json.cpp プロジェクト: CepheidVar/Cataclysm-DDA
JsonArray JsonObject::get_array(const std::string &name)
{
    int pos = positions[name];
    if (pos <= start) {
        return JsonArray(); // empty array
    }
    jsin->seek(pos);
    return JsonArray(jsin);
}
コード例 #2
0
std::string JsonUtils::SearchTabJson(const SearchTabDefinition& search_tab) {
  // The JSON publishes the MapsSearchAdapter for all search url's, since the
  // JS processing code is the same for all JSON based clients.
  std::string url = search_tab.url.utf8().data();
  url = ReplaceString(url, kEarthClientSearchAdapter, kMapsSearchAdapter);

  // Collect the arg fields into a vector.
  std::vector<std::string> arg_array_entries;
  for (int i = 0; i < static_cast<int>(search_tab.fields.size()); ++i) {
    const SearchTabDefinition::Field& field = search_tab.fields[i];
    std::map<std::string, std::string> arg_field_map;
    arg_field_map["screenLabel"] = Quoted(field.label);
    arg_field_map["urlTerm"] = Quoted(field.key);

    std::string arg_entry = JsonObject(arg_field_map);
    arg_array_entries.push_back(arg_entry);
  }
  std::string args_array = JsonArray(arg_array_entries);

  // Create the map of field name-value pairs for the output JSON.
  std::map<std::string, std::string> field_map;
  field_map["tabLabel"] = Quoted(search_tab.label);
  field_map["url"] = Quoted(url);
  field_map["args"] = args_array;
  return JsonObject(field_map);
}
コード例 #3
0
ファイル: jsonobject.cpp プロジェクト: lfritz/qtjsonhelper
JsonArray JsonObject::array(const QString& key) const {
    checkContains(key);
    QJsonValue value = o.value(key);
    if ( ! value.isArray())
        wrongType("array", key);
    return JsonArray(value.toArray());
}
コード例 #4
0
ファイル: Login.cpp プロジェクト: Airbitz/airbitz-core
Status
Login::repoFind(JsonPtr &result, const std::string &type, bool create)
{
    result = JsonPtr();

    // Try 1: Use what we have:
    repoFindLocal(result, type).log(); // Failure is fine
    if (result) return Status();

    // Try 2: Sync with the server:
    ABC_CHECK(update());
    repoFindLocal(result, type).log(); // Failure is fine
    if (result) return Status();

    // Try 3: Make a new repo:
    if (create)
    {
        // Make the keys:
        DataChunk dataKey;
        DataChunk syncKey;
        ABC_CHECK(randomData(dataKey, DATA_KEY_LENGTH));
        ABC_CHECK(randomData(syncKey, SYNC_KEY_LENGTH));
        AccountRepoJson repoJson;
        ABC_CHECK(repoJson.syncKeySet(base64Encode(syncKey)));
        ABC_CHECK(repoJson.dataKeySet(base64Encode(dataKey_)));

        // Make the metadata:
        DataChunk id;
        ABC_CHECK(randomData(id, keyIdLength));
        KeyJson keyJson;
        ABC_CHECK(keyJson.idSet(base64Encode(id)));
        ABC_CHECK(keyJson.typeSet(type));
        ABC_CHECK(keyJson.keysSet(repoJson));

        // Encrypt the metadata:
        JsonBox keyBox;
        ABC_CHECK(keyBox.encrypt(keyJson.encode(), dataKey_));

        // Push the wallet to the server:
        AuthJson authJson;
        ABC_CHECK(authJson.loginSet(*this));
        ABC_CHECK(loginServerKeyAdd(authJson, keyBox, base16Encode(syncKey)));

        // Save to disk:
        LoginStashJson stashJson;
        ABC_CHECK(stashJson.load(paths.stashPath()));
        if (!stashJson.keyBoxes().ok())
            ABC_CHECK(stashJson.keyBoxesSet(JsonArray()));
        ABC_CHECK(stashJson.keyBoxes().append(keyBox));
        ABC_CHECK(stashJson.save(paths.stashPath()));

        result = repoJson;
        return Status();
    }

    return ABC_ERROR(ABC_CC_AccountDoesNotExist, "No such repo");
}
コード例 #5
0
std::string JsonUtils::SearchTabsJson(
  const std::vector<SearchTabDefinition>& search_tabs) {
  std::vector<std::string> search_tab_json_objects;
  // Create the JSON entries for each of the search tabs.
  std::vector<SearchTabDefinition>::const_iterator iter = search_tabs.begin();
  for (; iter != search_tabs.end(); ++iter) {
    search_tab_json_objects.push_back(SearchTabJson(*iter));
  }
  return JsonArray(search_tab_json_objects);
}
コード例 #6
0
std::string JsonUtils::MapLayersJson(
  const std::vector<MapLayerJSConfig::Layer>& layers,
  const DbHeader& db_header,
  const std::string& locale) {
  // Create the JSON entries for each of the layers.
  std::vector<std::string> layer_json_entries;
  for (int i = 0; i < static_cast<int>(layers.size()); ++i) {
    const MapLayerJSConfig::Layer& layer = layers[i];
    layer_json_entries.push_back(
        JsonUtils::MapLayerJson(layer, db_header, locale));
  }
  return JsonArray(layer_json_entries);
}
コード例 #7
0
std::string JsonUtils::GELayersJson(
  const std::vector<RasterDBRootGenConfig::Layer>& raster_layers,
  const std::vector<LayerConfig>& vector_layers,
  const std::string& locale) {
  std::vector<std::string> layer_json_entries;
  // Create the JSON entries for each of the search tabs, starting with
  // raster layers.
  std::vector<RasterDBRootGenConfig::Layer>::const_iterator raster_iter =
    raster_layers.begin();
  for (; raster_iter != raster_layers.end(); ++raster_iter) {
    layer_json_entries.push_back(GERasterLayerJson(*raster_iter, locale));
  }
  // Now the vector layers.
  std::vector<LayerConfig>::const_iterator iter = vector_layers.begin();
  for (; iter != vector_layers.end(); ++iter) {
    const LayerConfig& layer = *iter;
    if (!layer.skipLayer) {
      layer_json_entries.push_back(GELayerJson(layer, locale));
    }
  }
  return JsonArray(layer_json_entries);
}
コード例 #8
0
ファイル: json.cpp プロジェクト: Doffeh/Cataclysm-DDA
JsonArray JsonIn::get_array() { return JsonArray(this); }
コード例 #9
0
ファイル: JSON.cpp プロジェクト: LefterisAd/esp32-snippets
/**
 * @brief Parse a string that contains a JSON array.
 * @param [in] text The JSON text string.
 * @return A JSON array.
 */
JsonArray JSON::parseArray(std::string text) {
	return JsonArray(cJSON_Parse(text.c_str()));
} // parseArray
コード例 #10
0
ファイル: JSON.cpp プロジェクト: LefterisAd/esp32-snippets
JsonArray JsonObject::getArray(std::string name) {
	cJSON *node = cJSON_GetObjectItem(m_node, name.c_str());
	return JsonArray(node);
}
コード例 #11
0
ファイル: JSON.cpp プロジェクト: LefterisAd/esp32-snippets
/**
 * @brief Create an empty JSON array.
 * @return An empty JSON array.
 */
JsonArray JSON::createArray() {
	return JsonArray(cJSON_CreateArray());
} // createArray
コード例 #12
0
ファイル: Login.cpp プロジェクト: Airbitz/airbitz-core
Status
Login::makeEdgeLogin(JsonPtr &result, const std::string &appId,
                     const std::string &pin)
{
    result = JsonPtr();

    // Try 1: Use what we have:
    makeEdgeLoginLocal(result, appId).log(); // Failure is fine
    if (result) return Status();

    // Try 2: Sync with the server:
    ABC_CHECK(update());
    makeEdgeLoginLocal(result, appId).log(); // Failure is fine
    if (result) return Status();

    // Try 3: Make a new login:
    {
        DataChunk loginKey;
        ABC_CHECK(randomData(loginKey, DATA_KEY_LENGTH));
        JsonBox parentBox;
        ABC_CHECK(parentBox.encrypt(loginKey, dataKey_));

        // Make the access credentials:
        DataChunk loginId;
        DataChunk loginAuth;
        ABC_CHECK(randomData(loginId, scryptDefaultSize));
        ABC_CHECK(randomData(loginAuth, scryptDefaultSize));
        JsonBox loginAuthBox;
        ABC_CHECK(loginAuthBox.encrypt(loginAuth, loginKey));

        // Set up the outgoing Login object:
        LoginReplyJson server;
        ABC_CHECK(server.appIdSet(appId));
        ABC_CHECK(server.loginIdSet(base64Encode(loginId)));
        ABC_CHECK(server.loginAuthBoxSet(loginAuthBox));
        ABC_CHECK(server.parentBoxSet(parentBox));
        LoginStashJson stash = server.clone();
        ABC_CHECK(server.set("loginAuth", base64Encode(loginAuth)));

        // Set up the PIN, if we have one:
        if (pin.size())
        {
            DataChunk pin2Key;
            ABC_CHECK(randomData(pin2Key, 32));
            const auto pin2Id = hmacSha256(store.username(), pin2Key);
            const auto pin2Auth = hmacSha256(pin, pin2Key);

            // Create pin2Box:
            JsonBox pin2Box;
            ABC_CHECK(pin2Box.encrypt(loginKey, pin2Key));

            // Create pin2KeyBox:
            JsonBox pin2KeyBox;
            ABC_CHECK(pin2KeyBox.encrypt(pin2Key, loginKey));

            // Set up the server login:
            ABC_CHECK(server.set("pin2Id", base64Encode(pin2Id)));
            ABC_CHECK(server.set("pin2Auth", base64Encode(pin2Auth)));
            ABC_CHECK(server.pin2BoxSet(pin2Box));
            ABC_CHECK(server.pin2KeyBoxSet(pin2KeyBox));
            ABC_CHECK(stash.pin2KeySet(base64Encode(pin2Key)));
        }

        // Write to server:
        AuthJson authJson;
        ABC_CHECK(authJson.loginSet(*this));
        ABC_CHECK(loginServerCreateChildLogin(authJson, server));

        // Save to disk:
        LoginStashJson stashJson;
        ABC_CHECK(stashJson.load(paths.stashPath()));
        if (!stashJson.children().ok())
            ABC_CHECK(stashJson.childrenSet(JsonArray()));
        ABC_CHECK(stashJson.children().append(stash));
        ABC_CHECK(stashJson.save(paths.stashPath()));
    }

    ABC_CHECK(makeEdgeLoginLocal(result, appId).log());
    if (!result)
        return ABC_ERROR(ABC_CC_Error, "Empty edge login after creation.");
    return Status();
}
コード例 #13
0
JsonArray JsonHashTable::getArray(const char* key)
{
	return JsonArray(json, getToken(key));
}
コード例 #14
0
ファイル: JsonArray.cpp プロジェクト: Tap-In/Arduino-CPX
JsonArray JsonArray::getArray(int index)
{
    return JsonArray(json, getToken(index));
}