Пример #1
0
int32_t core::wim::phone_login::parse_response_data(const rapidjson::Value& _data)
{
	int32_t err = wpie_http_parse_response;

	try
	{
		auto iter_phone_verified = _data.FindMember("phone_verified");
		if (iter_phone_verified == _data.MemberEnd() || !iter_phone_verified->value.IsBool())
			return wpie_http_parse_response;

		if (!iter_phone_verified->value.GetBool())
			return wpie_phone_not_verified;

		auto iter_session_key = _data.FindMember("sessionKey");
		if (iter_session_key == _data.MemberEnd() || !iter_session_key->value.IsString())
			return wpie_http_parse_response;

		session_key_ = iter_session_key->value.GetString();

		auto iter_host_time = _data.FindMember("hostTime");
		if (iter_host_time == _data.MemberEnd() || !iter_host_time->value.IsUint())
			return wpie_http_parse_response;

		host_time_ = iter_host_time->value.GetUint();

		auto iter_token = _data.FindMember("token");
		if (iter_token == _data.MemberEnd() || !iter_token->value.IsObject())
			return wpie_http_parse_response;

		auto iter_expired_in = iter_token->value.FindMember("expiresIn");
		auto iter_a = iter_token->value.FindMember("a");
		if (iter_expired_in == iter_token->value.MemberEnd() || iter_a == iter_token->value.MemberEnd() ||
			!iter_expired_in->value.IsUint() || !iter_a->value.IsString())
			return wpie_http_parse_response;

		expired_in_ = iter_expired_in->value.GetUint();
		a_token_ = iter_a->value.GetString();

		time_offset_ = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) - host_time_;

		err = 0;
	}
	catch (const std::exception&)
	{
		
	}
	
	
	return err;
}
Пример #2
0
int32_t core::wim::validate_phone::parse_response_data(const rapidjson::Value& _data)
{
	auto iter_trans_id = _data.FindMember("trans_id");
	if (iter_trans_id == _data.MemberEnd() || !iter_trans_id->value.IsString())
		return wpie_http_parse_response;

	trans_id_ = iter_trans_id->value.GetString();

	auto iter_existing = _data.FindMember("existring");
	if (iter_existing != _data.MemberEnd() && iter_existing->value.IsInt())
		existing_ = !!iter_existing->value.GetInt();
	
	return 0;
}
bool search_contacts_response::unserialize(const rapidjson::Value& _node)
{
    { auto i = _node.FindMember("finish"); if (i != _node.MemberEnd() && i->value.IsBool()) finish_ = i->value.GetBool(); }
    { auto i = _node.FindMember("newTag"); if (i != _node.MemberEnd() && i->value.IsString()) next_tag_ = rapidjson_get_string(i->value); }

    return unserialize_contacts(_node) && unserialize_chats(_node);
}
Пример #4
0
bool GetVectorFromJSON(const rapidjson::Value& inObject, const char* inProperty, Vector3& outVector)
{
	auto itr = inObject.FindMember(inProperty);
	if (itr == inObject.MemberEnd())
	{
		return false;
	}

	auto& property = itr->value;
	if (!property.IsArray() || property.Size() != 3)
	{
		return false;
	}

	for (rapidjson::SizeType i = 0; i < 3; i++)
	{
		if (!property[i].IsDouble())
		{
			return false;
		}
	}

	outVector.x = property[0].GetDouble();
	outVector.y = property[1].GetDouble();
	outVector.z = property[2].GetDouble();

	return true;
}
Пример #5
0
bool GetQuaternionFromJSON(const rapidjson::Value& inObject, const char* inProperty, Quaternion& outQuat)
{
	auto itr = inObject.FindMember(inProperty);
	if (itr == inObject.MemberEnd())
	{
		return false;
	}

	auto& property = itr->value;

	for (rapidjson::SizeType i = 0; i < 4; i++)
	{
		if (!property[i].IsDouble())
		{
			return false;
		}
	}

	outQuat.x = property[0].GetDouble();
	outQuat.y = property[1].GetDouble();
	outQuat.z = property[2].GetDouble();
	outQuat.w = property[3].GetDouble();

	return true;
}
Пример #6
0
bool JSASTNode::Parse(const rapidjson::Value& value)
{
    assert(value.IsObject());

    for (Value::ConstMemberIterator itr = value.MemberBegin();
         itr != value.MemberEnd(); ++itr)
    {
        String name = itr->name.GetString();

        if (name == "loc")
        {
            ParseLoc(itr->value);
        }
        else if (name == "type")
        {
            // TODO: Verify type
        }
        else if (name == "range")
        {
            ParseRange(itr->value);
        }

    }

    return true;

}
Пример #7
0
void JSONObjectToDetailedWares(const rapidjson::Value& Obj,
                               FluidHubAPIClient::WaresDetailsByID_t& WMap)
{
    WMap.clear();

    if (Obj.IsObject())
    {
        for (rapidjson::Value::ConstMemberIterator it = Obj.MemberBegin(); it != Obj.MemberEnd(); ++it)
        {
            if (it->value.IsObject())
            {
                std::string WareID = it->name.GetString();

                WMap[WareID] = FluidHubAPIClient::WareDetailedDescription();

                rapidjson::Value::ConstMemberIterator itMember = it->value.FindMember("shortdesc");
                if (itMember != it->value.MemberEnd() && itMember->value.IsString())
                {
                    WMap[WareID].ShortDescription = std::string(itMember->value.GetString());
                }

                itMember = it->value.FindMember("git-url");
                if (itMember != it->value.MemberEnd() && itMember->value.IsString())
                {
                    WMap[WareID].GitUrl = std::string(itMember->value.GetString());
                }

                itMember = it->value.FindMember("git-branches");
                if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
                {
                    JSONArrayToStringVector(itMember->value,WMap[WareID].GitBranches);
                }

                itMember = it->value.FindMember("issues-counts");
                if (itMember != it->value.MemberEnd() && itMember->value.IsObject())
                {
                    for (rapidjson::Value::ConstMemberIterator itCounters = itMember->value.MemberBegin();
                            itCounters != itMember->value.MemberEnd();
                            ++itCounters)
                    {
                        if (itCounters->value.IsInt())
                            WMap[WareID].IssuesCounters[itCounters->name.GetString()] = itCounters->value.GetInt();
                    }
                }

                itMember = it->value.FindMember("users-ro");
                if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
                {
                    JSONArrayToStringSet(itMember->value,WMap[WareID].ROUsers);
                }

                itMember = it->value.FindMember("users-rw");
                if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
                {
                    JSONArrayToStringSet(itMember->value,WMap[WareID].RWUsers);
                }
            }
        }
    }
}
Пример #8
0
QueryError OnPing(const rapidjson::Value &p_Args, std::string *p_Result)
{
    // Get the "address" argument
    auto s_AddressValue = p_Args.FindMember("address");
    if (s_AddressValue == p_Args.MemberEnd() || !s_AddressValue->value.IsString())
    {
        *p_Result = "Bad query: An \"address\" argument is required and must be a string";
        return QueryError_BadQuery;
    }

    // Parse it
    Blam::Network::NetworkAddress blamAddress;
    if (!Blam::Network::NetworkAddress::Parse(s_AddressValue->value.GetString(), 11774, &blamAddress))
    {
        *p_Result = "Invalid argument: The \"address\" argument is not a valid IP address.";
        return QueryError_InvalidArgument;
    }

    // Register our ping handler if it isn't already
    if (!PingHandlerRegistered)
    {
        PingId = Patches::Network::OnPong(PongReceived);
        PingHandlerRegistered = true;
    }

    // Send a ping message
    auto session = Blam::Network::GetActiveSession();
    if (!session || !session->Gateway->Ping(blamAddress, PingId))
    {
        *p_Result = "Network error: Failed to send ping";
        return QueryError_NetworkError;
    }
    return QueryError_Ok;
}
Пример #9
0
bool JSASTProgram::Parse(const rapidjson::Value& value)
{
    JSASTNode::Parse(value);

    for (Value::ConstMemberIterator itr = value.MemberBegin();
         itr != value.MemberEnd(); ++itr)
    {
        String name = itr->name.GetString();

        if (name == "body")
        {
            ParseStatementArray(itr->value, body_);
        }

        if (name == "comments")
        {
            if (itr->value.IsArray())
            {
                for (Value::ConstValueIterator citr = itr->value.Begin();
                     citr != itr->value.End();
                     citr++)
                {
                    JSASTComment* comment = new JSASTComment();
                    assert(citr->IsObject());
                    comment->Parse(*citr);
                    comments_.Push(comment);
                }
            }
        }

    }

    return true;

}
Пример #10
0
std::size_t GeoJSONFileParser::parse_top(const rapidjson::Value& top) {
    const auto json_geometry = top.FindMember("geometry");
    if (json_geometry == top.MemberEnd()) {
        error("Missing 'geometry' name.");
    }

    if (!json_geometry->value.IsObject()) {
        error("Expected 'geometry' value to be an object.");
    }

    std::string geometry_type{get_value_as_string(json_geometry->value, "type")};
    if (geometry_type.empty()) {
        error("Missing 'geometry.type'.");
    }
    if (geometry_type != "Polygon" && geometry_type != "MultiPolygon") {
        error("Expected 'geometry.type' value to be 'Polygon' or 'MultiPolygon'.");
    }

    const auto json_coordinates = json_geometry->value.FindMember("coordinates");
    if (json_coordinates == json_geometry->value.MemberEnd()) {
        error("Missing 'coordinates' name in 'geometry' object.");
    }

    if (!json_coordinates->value.IsArray()) {
        error("Expected 'geometry.coordinates' value to be an array.");
    }

    if (geometry_type == "Polygon") {
        return parse_polygon_array(json_coordinates->value, m_buffer);
    }

    return parse_multipolygon_array(json_coordinates->value, m_buffer);
}
Пример #11
0
    virtual void fromJson(const rapidjson::Value &v, const Scene &scene)
    {
        JsonUtils::fromJson(v, "output_directory", _outputDirectory);

        _outputDirectory.freezeWorkingDirectory();
        DirectoryChange change(_outputDirectory);

        JsonUtils::fromJson(v, "output_file", _outputFile);
        JsonUtils::fromJson(v, "hdr_output_file", _hdrOutputFile);
        JsonUtils::fromJson(v, "variance_output_file", _varianceOutputFile);
        JsonUtils::fromJson(v, "resume_render_file", _resumeRenderFile);
        JsonUtils::fromJson(v, "overwrite_output_files", _overwriteOutputFiles);
        JsonUtils::fromJson(v, "adaptive_sampling", _useAdaptiveSampling);
        JsonUtils::fromJson(v, "enable_resume_render", _enableResumeRender);
        JsonUtils::fromJson(v, "stratified_sampler", _useSobol);
        JsonUtils::fromJson(v, "scene_bvh", _useSceneBvh);
        JsonUtils::fromJson(v, "spp", _spp);
        JsonUtils::fromJson(v, "spp_step", _sppStep);
        JsonUtils::fromJson(v, "checkpoint_interval", _checkpointInterval);
        JsonUtils::fromJson(v, "timeout", _timeout);

        auto outputs = v.FindMember("output_buffers");
        if (outputs != v.MemberEnd() && outputs->value.IsArray()) {
            for (rapidjson::SizeType i = 0; i < outputs->value.Size(); ++i) {
                _outputs.emplace_back();
                _outputs.back().fromJson(outputs->value[i], scene);
            }
        }
    }
Пример #12
0
int32_t fetch_event_typing::parse(const rapidjson::Value& _node_event_data)
{
    const auto it_status = _node_event_data.FindMember("typingStatus");

    if (it_status != _node_event_data.MemberEnd() && it_status->value.IsString())
    {
        std::string status = it_status->value.GetString();
        is_typing_ = (status == "typing");
    }

    const auto it_aimid = _node_event_data.FindMember("aimId");

    if (it_aimid != _node_event_data.MemberEnd() && it_aimid->value.IsString())
    {
        aimid_ = it_aimid->value.GetString();
    }
    else
    {
        return -1;
    }

    const auto it_attr = _node_event_data.FindMember("MChat_Attrs");

    if (it_attr != _node_event_data.MemberEnd() && it_attr->value.IsObject())
    {
        const auto itsender = it_attr->value.FindMember("sender");

        if (itsender != it_attr->value.MemberEnd() && itsender->value.IsString())
        {
            chatter_aimid_ = itsender->value.GetString();
        }

        const auto itoptions = it_attr->value.FindMember("options");

        if (itoptions != it_attr->value.MemberEnd() && itoptions->value.IsObject())
        {
            const auto itname = itoptions->value.FindMember("senderName");

            if (itname != itoptions->value.MemberEnd() && itname->value.IsString())
            {
                chatter_name_ = itname->value.GetString();
            }
        }
    }

    return 0;
}
Пример #13
0
void parseState(const std::string& tag, const rapidjson::Value& button, std::unordered_map<std::string, TexturePtr>& stateMap) {
	for (auto it = button.MemberBegin(); it != button.MemberEnd(); it++) {
		std::string name = it->name.GetString();
		const rapidjson::Value& value = it->value;
		TexturePtr texture(GCC_NEW Texture(tag, value["x"].GetDouble(), value["y"].GetDouble(), value["w"].GetDouble(), value["h"].GetDouble()));
		stateMap.emplace(name, texture);
	}
}
Пример #14
0
 void Inspector::applyConfigToView(const rapidjson::Value &config)
 {
     for(rapidjson::Value::ConstMemberIterator it = config.MemberBegin();
         it != config.MemberEnd(); ++it)
     {
         setTargetProperty(it->name.GetString(), it->value);
     }
 }
Пример #15
0
name_t::name_t(const rapidjson::Value &json_value) {

    auto last_iter = json_value.FindMember("last");
    if ( last_iter != json_value.MemberEnd() ) {

        assert(last_iter->value.IsString());
        last = last_iter->value.GetString();
    }

    auto first_iter = json_value.FindMember("first");
    if ( first_iter != json_value.MemberEnd() ) {

        assert(first_iter->value.IsString());
        first = first_iter->value.GetString();
    }

}
Пример #16
0
int32_t fetch_event_imstate::parse(const rapidjson::Value& _node_event_data)
{
    auto iter_imstates = _node_event_data.FindMember("imStates");
    if  (iter_imstates == _node_event_data.MemberEnd() || !iter_imstates->value.IsArray())
        return wpie_error_parse_response;

    for (auto iter_state = iter_imstates->value.Begin(); iter_state != iter_imstates->value.End(); ++iter_state)
    {
        imstate ustate;

        auto iter_request_id = iter_state->FindMember("sendReqId");
        if (iter_request_id == iter_state->MemberEnd() || !iter_request_id->value.IsString())
            continue;

        ustate.set_request_id(rapidjson_get_string(iter_request_id->value));

        auto iter_msg_id = iter_state->FindMember("msgId");
        if (iter_msg_id == iter_state->MemberEnd() || !iter_msg_id->value.IsString())
            continue;

        ustate.set_msg_id(rapidjson_get_string(iter_msg_id->value));

        auto iter_state_state = iter_state->FindMember("state");
        if (iter_state_state == iter_state->MemberEnd() || !iter_state_state->value.IsString())
            continue;

        const std::string state = rapidjson_get_string(iter_state_state->value);

        if (state == "failed")
            ustate.set_state(imstate_sent_state::failed);
        else if (state == "sent")
            ustate.set_state(imstate_sent_state::sent);
        else if (state == "delivered")
            ustate.set_state(imstate_sent_state::delivered);

        auto iter_hist_msg_id = iter_state->FindMember("histMsgId");
        if (iter_hist_msg_id != iter_state->MemberEnd() && iter_hist_msg_id->value.IsInt64())
        {
            ustate.set_hist_msg_id(iter_hist_msg_id->value.GetInt64());
        }

        auto iter_before_hist_msg_id = iter_state->FindMember("beforeHistMsgId");
        if (iter_before_hist_msg_id != iter_state->MemberEnd() && iter_before_hist_msg_id->value.IsInt64())
        {
            ustate.set_before_hist_msg_id(iter_before_hist_msg_id->value.GetInt64());
        }

        auto iter_error_code = iter_state->FindMember("errorCode");
        if (iter_error_code != iter_state->MemberEnd() && iter_error_code->value.IsInt())
        {
            ustate.set_error_code(iter_error_code->value.GetInt());
        }

        states_.push_back(ustate);
    }

    return 0;
}
Пример #17
0
	/*!
	Sets box geometry from given rapidjson object.

	Given object must have "start" and "end" items
	and both must be arrays of 3 numbers.
	*/
	void set_geometry(const rapidjson::Value& object)
	{
		const auto& obj_start_i = object.FindMember("start");
		if (obj_start_i == object.MemberEnd()) {
			throw std::invalid_argument(__FILE__ ": Given object doesn't have a start item.");
		}
		const auto& obj_start = obj_start_i->value;

		if (not obj_start.IsArray()) {
			throw std::invalid_argument(__FILE__ ": Start item isn't an array.");
		}

		if (obj_start.Size() != 3) {
			throw std::invalid_argument(__FILE__ ": Start item doesn't have a length of 3.");
		}

		this->start_rw[0] = obj_start[0].GetDouble();
		this->start_rw[1] = obj_start[1].GetDouble();
		this->start_rw[2] = obj_start[2].GetDouble();

		const auto& obj_end_i = object.FindMember("end");
		if (obj_end_i == object.MemberEnd()) {
			throw std::invalid_argument(__FILE__ ": Given object doesn't have an end item.");
		}
		const auto& obj_end = obj_end_i->value;

		if (not obj_end.IsArray()) {
			throw std::invalid_argument(__FILE__ ": End item isn't an array.");
		}

		if (obj_end.Size() != 3) {
			throw std::invalid_argument(__FILE__ ": End item doesn't have a length of 3.");
		}

		this->end_rw[0] = obj_end[0].GetDouble();
		this->end_rw[1] = obj_end[1].GetDouble();
		this->end_rw[2] = obj_end[2].GetDouble();

		for (size_t i = 0; i < 3; i++) {
			if (this->end_rw[i] <= this->start_rw[i]) {
				throw std::invalid_argument(__FILE__ ": Given object ends before it starts.");
			}
		}
	}
Пример #18
0
QueryError OnCommand(const rapidjson::Value &p_Args, std::string *p_Result)
{
    // Get the "command" argument
    auto s_CommandValue = p_Args.FindMember("command");
    if (s_CommandValue == p_Args.MemberEnd() || !s_CommandValue->value.IsString())
    {
        *p_Result = "Bad query: A \"command\" argument is required and must be a string";
        return QueryError_BadQuery;
    }

    // Get the "internal" argument (defaults to false)
    auto s_InternalValue = p_Args.FindMember("internal");
    auto s_IsInternal = (s_InternalValue != p_Args.MemberEnd() && s_InternalValue->value.IsBool() && s_InternalValue->value.GetBool());

    // Run the command
    if (!Modules::CommandMap::Instance().ExecuteCommandWithStatus(s_CommandValue->value.GetString(), !s_IsInternal, p_Result))
        return QueryError_CommandFailed;
    return QueryError_Ok;
}
Пример #19
0
int32_t robusto_add_client::parse_results(const rapidjson::Value& _node_results)
{
    auto iter_client_id = _node_results.FindMember("clientId");
    if (iter_client_id == _node_results.MemberEnd())
        return wpie_http_parse_response;

    client_id_ = iter_client_id->value.GetUint();

    return 0;
}
Пример #20
0
void PrintValue(rapidjson::Value &value)
{
	rapidjson::Type type = value.GetType();

	if (type == rapidjson::Type::kNumberType)
	{
		printf("%d", value.GetInt());
	}
	else if (type == rapidjson::Type::kStringType)
	{
		printf("%s", value.GetString());
	}
	else if (type == rapidjson::Type::kTrueType)
	{
		printf("가능");
	}
	else if (type == rapidjson::Type::kFalseType)
	{
		printf("불가능");
	}
	else if (type == rapidjson::Type::kArrayType)
	{
		for (int i = 0; i < value.Size(); i++)
		{
			PrintValue(value[i]);
			if (i < value.Size() - 1)
				printf(", ");
		}
		printf("\n");
	}
	else if (type == rapidjson::Type::kObjectType)
	{
		for (auto iter = value.MemberBegin(); iter != value.MemberEnd(); iter++)
		{
			rapidjson::Value &member = iter->value;
			std::string name = iter->name.GetString();

			if (member.GetType() == rapidjson::Type::kObjectType || member.GetType() == rapidjson::Type::kArrayType)
			{
				printf("\n- %s -\n", name.c_str());
				PrintValue(member);
			}
			else
			{
				printf("%s : ", name.c_str());
				PrintValue(member);
				printf("\n");
			}
		}
	}
	else
	{
		printf("Null");
	}
}
Пример #21
0
	inline auto GetIterator(const rapidjson::Value& value, const char* name)
	{
		auto it = value.FindMember(name);

		if (it == value.MemberEnd())
		{
			SDR::Error::Make("Member Json value \"%s\" not found", name);
		}

		return it;
	}
Пример #22
0
int32_t favorite::unserialize(const rapidjson::Value& _node)
{
    auto iter_aimid = _node.FindMember("aimId");

    if (iter_aimid == _node.MemberEnd() || !iter_aimid->value.IsString())
        return -1;

    aimid_ = iter_aimid->value.GetString();

    auto iter_time = _node.FindMember("time");
    if (iter_time == _node.MemberEnd() || !iter_time->value.IsInt64())
    {
        time_ = 0;
        return 0;
    }

    time_ = iter_time->value.GetInt64();

    return 0;
}
Пример #23
0
 void etcd_packer::unpack_int(rapidjson::Value &json_val, const char *key, uint64_t &out) {
     rapidjson::Value::MemberIterator iter = json_val.FindMember(key);
     if (iter == json_val.MemberEnd()) {
         out = 0;
     } else {
         if (iter->value.IsUint64()) {
             out = iter->value.GetUint64();
         } else if (iter->value.IsString()) {
             const char *val = iter->value.GetString();
             ::util::string::str2int(out, val);
         }
     }
 }
Пример #24
0
        bool etcd_packer::unpack_string(rapidjson::Value &json_val, const char *key, std::string &val) {
            rapidjson::Value::MemberIterator iter = json_val.FindMember(key);
            if (iter == json_val.MemberEnd()) {
                return false;
            }

            switch (iter->value.GetType()) {
            case rapidjson::kNullType: {
                val.clear();
                break;
            }
            case rapidjson::kFalseType: {
                val = "false";
                break;
            }
            case rapidjson::kTrueType: {
                val = "true";
                break;
            }
            case rapidjson::kObjectType: {
                val = "[object object]";
                break;
            }
            case rapidjson::kArrayType: {
                val = "[object array]";
                break;
            }
            case rapidjson::kStringType: {
                val = iter->value.GetString();
                break;
            }
            case rapidjson::kNumberType: {
                std::stringstream ss;
                if (iter->value.IsDouble()) {
                    ss << iter->value.GetDouble();
                } else if (iter->value.IsInt()) {
                    ss << iter->value.GetInt();
                } else if (iter->value.IsUint()) {
                    ss << iter->value.GetUint();
                } else if (iter->value.IsInt64()) {
                    ss << iter->value.GetInt64();
                } else {
                    ss << iter->value.GetUint64();
                }
                val = ss.str();
                break;
            }
            }

            return true;
        }
Пример #25
0
int32_t my_info::unserialize(const rapidjson::Value& _node)
{
    auto iter_aimid = _node.FindMember("aimId");
    if (iter_aimid != _node.MemberEnd() && iter_aimid->value.IsString())
        aimId_ = iter_aimid->value.GetString();

    auto iter_displayId = _node.FindMember("displayId");
    if (iter_displayId != _node.MemberEnd() && iter_displayId->value.IsString())
        displayId_ = iter_displayId->value.GetString();

    auto iter_friendlyName = _node.FindMember("friendly");
    if (iter_friendlyName != _node.MemberEnd() && iter_friendlyName->value.IsString())
        friendlyName_ = iter_friendlyName->value.GetString();

    auto iter_state = _node.FindMember("state");
    if (iter_state != _node.MemberEnd() && iter_state->value.IsString())
        state_ = iter_state->value.GetString();

    auto iter_userType = _node.FindMember("userType");
    if (iter_userType != _node.MemberEnd() && iter_userType->value.IsString())
        userType_ = iter_userType->value.GetString();

    auto iter_phoneNumber = _node.FindMember("attachedPhoneNumber");
    if (iter_phoneNumber != _node.MemberEnd() && iter_phoneNumber->value.IsString())
        phoneNumber_ = iter_phoneNumber->value.GetString();

    auto iter_flags = _node.FindMember("globalFlags");
    if (iter_flags != _node.MemberEnd() && iter_flags->value.IsUint())
        flags_ = iter_flags->value.GetUint();

    auto iter_expressions = _node.FindMember("expressions");
    if (iter_expressions != _node.MemberEnd())
    {
        const auto & expression_node = iter_expressions->value;
        auto iter_large_icon = expression_node.FindMember("largeBuddyIcon");
        if (iter_large_icon != expression_node.MemberEnd() && iter_large_icon->value.IsString())
            largeIconId_ = iter_large_icon->value.GetString();
    }

    if (state_ == "occupied" || state_ == "na" || state_ == "busy")
        state_ = "dnd";
    else if (state_ == "away")
        state_ = "away";
    else if (state_ != "offline" && state_ != "invisible")
        state_ = "online";

    return 0;
}
Пример #26
0
std::string get_value_as_string(const rapidjson::Value& object, const char* key) {
    assert(object.IsObject());

    const auto it = object.FindMember(key);
    if (it == object.MemberEnd()) {
        return "";
    }

    if (it->value.IsString()) {
        return it->value.GetString();
    }

    throw config_error{std::string{"Value for name '"} + key + "' must be a string."};
}
Пример #27
0
QueryError OnCaptureInput(const rapidjson::Value &p_Args, std::string *p_Result)
{
    // Get the "capture" argument
    auto s_CaptureValue = p_Args.FindMember("capture");
    if (s_CaptureValue == p_Args.MemberEnd() || !s_CaptureValue->value.IsBool())
    {
        *p_Result = "Bad query: A \"capture\" argument is required and must be a boolean";
        return QueryError_BadQuery;
    }

    // Toggle input capture
    Web::Ui::ScreenLayer::CaptureInput(s_CaptureValue->value.GetBool());
    return QueryError_Ok;
}
Пример #28
0
QueryError OnSendChat(const rapidjson::Value &p_Args, std::string *p_Result)
{
    auto message = p_Args.FindMember("message");
    auto teamChat = p_Args.FindMember("teamChat");

    if (message == p_Args.MemberEnd() || !message->value.IsString())
    {
        *p_Result = "Bad query: A \"message\" argument is required and must be a string";
        return QueryError_BadQuery;
    }
    if (teamChat == p_Args.MemberEnd() || !teamChat->value.IsBool())
    {
        *p_Result = "Bad query: A \"teamChat\" argument is required and must be a boolean";
        return QueryError_BadQuery;
    }

    if(teamChat->value.GetBool())
        *p_Result = Server::Chat::SendTeamMessage(message->value.GetString());
    else
        *p_Result = Server::Chat::SendGlobalMessage(message->value.GetString());

    return QueryError_Ok;
}
Пример #29
0
void ArchiveMetadata::loadJson(const rapidjson::Value& metadataDoc) {
    rapidjson::Value::ConstMemberIterator itr = metadataDoc.FindMember("archive_name");
    if (itr != metadataDoc.MemberEnd())
        archiveName.assign(itr->value.GetString());

    archiveFormatName.assign(metadataDoc["archive_format_name"].GetString());
    archiveFormat = metadataDoc["archive_format"].GetUint64();

    focusedEntry = metadataDoc["focused_entry"].GetString();
  
    for (const auto &entryVal : metadataDoc["archive_structure"].GetArray()) {
        entryMetadata.push_back(ArchiveEntryMetadata::fromJson(entryVal));
    }
}
Пример #30
0
        bool etcd_packer::unpack_base64(rapidjson::Value &json_val, const char *key, std::string &val) {
            rapidjson::Value::MemberIterator iter = json_val.FindMember(key);
            if (iter == json_val.MemberEnd()) {
                return false;
            }

            if (!iter->value.IsString()) {
                return false;
            }

            const char *base64_val    = iter->value.GetString();
            size_t      base64_val_sz = strlen(base64_val);

            return 0 == util::base64_decode(val, reinterpret_cast<const unsigned char *>(base64_val), base64_val_sz);
        }