コード例 #1
0
ファイル: amf0serializer.cpp プロジェクト: Undev/crtmpserver
bool AMF0Serializer::WriteObject(IOBuffer &buffer, Variant &variant,
		bool writeType) {

	if (writeType)
		buffer.ReadFromRepeat(AMF0_OBJECT, 1);

	Variant temp = variant;

	FOR_VECTOR_ITERATOR(string, _keysOrder, i) {
		if (temp.HasKey(VECTOR_VAL(i))) {
			if (!WriteShortString(buffer, VECTOR_VAL(i), false)) {
				FATAL("Unable to serialize key");
				return false;
			}
			if (!Write(buffer, temp[VECTOR_VAL(i)])) {
				FATAL("Unable to serialize value");
				return false;
			}
			temp.RemoveKey(VECTOR_VAL(i));
		}
	}

	FOR_MAP(temp, string, Variant, i) {
		string key = MAP_KEY(i);
		if (key.find(VAR_INDEX_VALUE) == 0) {
			key = key.substr(VAR_INDEX_VALUE_LEN);
		}
		if (!WriteShortString(buffer, key, false)) {
			FATAL("Unable to serialize key");
			return false;
		}
		if (!Write(buffer, MAP_VAL(i))) {
			FATAL("Unable to serialize value");
			return false;
		}
	}
コード例 #2
0
ファイル: amf0serializer.cpp プロジェクト: 2php/crtmpserver
bool AMF0Serializer::WriteObject(IOBuffer &buffer, Variant &variant,
		bool writeType) {

	if (writeType)
		buffer.ReadFromRepeat(AMF0_OBJECT, 1);

	Variant temp = variant;

	FOR_VECTOR_ITERATOR(string, _keysOrder, i) {
		if (temp.HasKey(VECTOR_VAL(i))) {
			if (!WriteShortString(buffer, VECTOR_VAL(i), false)) {
				FATAL("Unable to serialize key");
				return false;
			}
			if (!Write(buffer, temp[VECTOR_VAL(i)])) {
				FATAL("Unable to serialize value");
				return false;
			}
			temp.RemoveKey(VECTOR_VAL(i));
		}
	}

	FOR_MAP(temp, string, Variant, i) {
		string key = MAP_KEY(i);
		if ((key.length() == 10) && (key[0] == '0') && (key[1] == 'x')) {
			key = format("%"PRIu32, (uint32_t) strtol(key.c_str(), NULL, 16));
		}
		if (!WriteShortString(buffer, key, false)) {
			FATAL("Unable to serialize key");
			return false;
		}
		if (!Write(buffer, MAP_VAL(i))) {
			FATAL("Unable to serialize value");
			return false;
		}
	}
コード例 #3
0
ファイル: sdp.cpp プロジェクト: 9aa5/crtmpserver
bool SDP::ParseTransportLinePart(string raw, Variant &result) {
	result.Reset();
	result["original"] = raw;

	//1. split after ';'
	vector<string> parts;
	split(raw, ";", parts);

	//2. Construct the result
	for (uint32_t i = 0; i < parts.size(); i++) {
		string part = parts[i];
		trim(part);
		if (part == "")
			continue;
		string::size_type pos = part.find('=');
		if (pos == string::npos) {
			result[lowerCase(part)] = (bool)true;
			continue;
		}
		result[lowerCase(part.substr(0, pos))] = part.substr(pos + 1);
	}

	vector<string> keys;
	ADD_VECTOR_END(keys, "client_port");
	ADD_VECTOR_END(keys, "server_port");
	ADD_VECTOR_END(keys, "interleaved");

	for (uint32_t i = 0; i < keys.size(); i++) {
		string key = keys[i];
		if (!result.HasKey(key))
			continue;
		parts.clear();
		raw = (string) result[key];
		split(raw, "-", parts);
		if ((parts.size() != 2) && (parts.size() != 1)) {
			FATAL("Invalid transport line: %s", STR(raw));
			return false;
		}
		string all = "";
		uint16_t data = 0;
		uint16_t rtcp = 0;
		if (parts.size() == 2) {
			data = (uint16_t) atoi(STR(parts[0]));
			rtcp = (uint16_t) atoi(STR(parts[1]));
			if (((data % 2) != 0) || ((data + 1) != rtcp)) {
				FATAL("Invalid transport line: %s", STR(raw));
				return false;
			}
			all = format("%"PRIu16"-%"PRIu16, data, rtcp);
		} else {
			data = (uint16_t) atoi(STR(parts[0]));
			all = format("%"PRIu16, data);
			rtcp = 0;
		}
		if (all != raw) {
			FATAL("Invalid transport line: %s", STR(raw));
			return false;
		}
		result.RemoveKey(key);
		result[key]["data"] = (uint16_t) data;
		result[key]["rtcp"] = (uint16_t) rtcp;
		result[key]["all"] = all;
	}

	return true;
}
コード例 #4
0
ファイル: luautils.cpp プロジェクト: Akagi201/crtmpserver
bool PopVariant(lua_State *pLuaState, Variant &variant, int32_t idx, bool pop) {
	variant.Reset();
	int32_t type = lua_type(pLuaState, idx);
	switch (type) {
		case LUA_TNIL:
		{
			variant.Reset();
			if (pop)
				lua_remove(pLuaState, idx);
			break;
		}
		case LUA_TBOOLEAN:
		{
			variant = (bool)(lua_toboolean(pLuaState, idx) != 0);
			if (pop)
				lua_remove(pLuaState, idx);
			break;
		}
		case LUA_TNUMBER:
		{
			lua_Number luaNumber = lua_tonumber(pLuaState, idx);
			if (pop)
				lua_remove(pLuaState, idx);
			variant = (double) luaNumber;
			variant.Compact();

			break;
		}
		case LUA_TSTRING:
		{
			string nullable = lua_tostring(pLuaState, idx);
			if (pop)
				lua_remove(pLuaState, idx);
			if (nullable == VAR_NULL_VALUE)
				variant = Variant();
			else
				variant = nullable;
			break;
		}
		case LUA_TTABLE:
		{
			bool isArray = true;
			lua_pushnil(pLuaState);
			while (lua_next(pLuaState, idx) != 0) {
				Variant value;
				if (!PopVariant(pLuaState, value, lua_gettop(pLuaState)))
					return false;

				Variant key;
				if (!PopVariant(pLuaState, key, lua_gettop(pLuaState), false))
					return false;

				variant[key] = value;
				isArray &= (key == _V_NUMERIC);
			}

			variant.IsArray(isArray);

			if (variant.HasKey(VAR_MAP_NAME)) {
				variant.SetTypeName(variant[VAR_MAP_NAME]);
				variant.RemoveKey(VAR_MAP_NAME);
			} else {
				variant.ConvertToTimestamp();
			}
			if (pop)
				lua_remove(pLuaState, idx);
			break;
		}
		default:
		{
			WARN("Element type not supported: %d (0x%x)", type, type);
			return false;
			break;
		}
	}
	return true;
}