예제 #1
0
파일: so.cpp 프로젝트: keyanmca/crtmp
void SO::RegisterProtocol(uint32_t protocolId)
{
    _registeredProtocols[protocolId] = protocolId;

    DirtyInfo di;

    //1. Clear
    di.propertyName = format("SOT_SC_CLEAR_DATA_%u", protocolId);
    di.type = SOT_SC_CLEAR_DATA;
    ADD_VECTOR_END(_dirtyPropsByProtocol[protocolId], di);


    //2. Initial
    di.propertyName = format("SOT_SC_INITIAL_DATA_%u", protocolId);
    di.type = SOT_SC_INITIAL_DATA;
    ADD_VECTOR_END(_dirtyPropsByProtocol[protocolId], di);

    //3. Mark all properties as updated

    FOR_MAP(_payload, string, Variant, i)
    {
        di.propertyName = MAP_KEY(i);
        di.type = SOT_SC_UPDATE_DATA;
        ADD_VECTOR_END(_dirtyPropsByProtocol[protocolId], di);
    }
예제 #2
0
TSPacketPMT::operator string() {
	string result = "";
	result += format("tableId:                %hhu\n", _tableId);
	result += format("sectionSyntaxIndicator: %hhu\n", _sectionSyntaxIndicator);
	result += format("reserved1:              %hhu\n", _reserved1);
	result += format("reserved2:              %hhu\n", _reserved2);
	result += format("sectionLength:          %hu\n", _sectionLength);
	result += format("programNumber:          %hu\n", _programNumber);
	result += format("reserved3:              %hhu\n", _reserved3);
	result += format("versionNumber:          %hhu\n", _versionNumber);
	result += format("currentNextIndicator:   %hhu\n", _currentNextIndicator);
	result += format("sectionNumber:          %hhu\n", _sectionNumber);
	result += format("lastSectionNumber:      %hhu\n", _lastSectionNumber);
	result += format("reserved4:              %hhu\n", _reserved4);
	result += format("pcrPid:                 %hu\n", _pcrPid);
	result += format("reserved5:              %hhu\n", _reserved5);
	result += format("programInfoLength:      %hu\n", _programInfoLength);
	result += format("crc:                    %x\n", _crc);
	result += format("descriptors count:      %"PRIz"u\n", _programInfoDescriptors.size());
	for (uint32_t i = 0; i < _programInfoDescriptors.size(); i++) {
		result += format("\t%s", STR(_programInfoDescriptors[i]));
		if (i != _programInfoDescriptors.size() - 1)
			result += "\n";
	}
	result += format("streams count:          %"PRIz"u\n", _streams.size());

	FOR_MAP(_streams, uint16_t, TSStreamInfo, i) {
		result += format("\t%hu: %s\n", MAP_KEY(i), STR(MAP_VAL(i).toString(1)));
	}
예제 #3
0
bool RTMPProtocolSerializer::SerializeInvoke(IOBuffer &buffer,
		Variant &message) {

	string functionName = message[RM_INVOKE_FUNCTION];
	if (!_amf0.WriteShortString(buffer, functionName)) {
		FATAL("Unable to write %s", STR(RM_INVOKE_FUNCTION));
		return false;
	}

	if (!_amf0.WriteDouble(buffer, message[RM_INVOKE_ID])) {
		FATAL("Unable to write %s", STR(RM_INVOKE_ID));
		return false;
	}

	FOR_MAP(message[RM_INVOKE_PARAMS], string, Variant, i) {
		if (!_amf0.Write(buffer, MAP_VAL(i))) {
			FATAL("Unable to serialize invoke parameter %s: %s",
					STR(MAP_KEY(i)),
					STR(message.ToString()));
			return false;
		}
	}

	return true;
}
예제 #4
0
파일: sdp.cpp 프로젝트: Undev/crtmpserver
bool SDP::ParseSDPLineA(string &attributeName, Variant &value, string line) {
	string::size_type pos = line.find(':');
	if ((pos == string::npos)
			|| (pos == 0)
			|| (pos == (line.size() - 1))) {
		attributeName = line;
		value = (bool)true;
		return true;
	}

	attributeName = line.substr(0, pos);
	string rawValue = line.substr(line.find(':') + 1);
	if (attributeName == "control") {
		value = rawValue;
		return true;
	} else if (attributeName == "maxprate") {
		value = (double) strtod(STR(rawValue), NULL);
		return true;
	} else if (attributeName.find("x-") == 0) {
		value = rawValue;
		return true;
	} else if (attributeName == "rtpmap") {
		//rtpmap:<payload type> <encoding name>/<clock rate>[/<encoding parameters>]
		vector<string> parts;
		split(rawValue, " ", parts);
		if (parts.size() != 2)
			return false;
		value["payloadType"] = (uint8_t) atoi(STR(parts[0]));
		split(parts[1], "/", parts);
		if ((parts.size() != 2) && (parts.size() != 3))
			return false;
		value["encodingName"] = parts[0];
		if (lowerCase((string) value["encodingName"]) == "h264") {
			value["encodingName"] = (uint64_t) CODEC_VIDEO_AVC;
		} else if ((string) lowerCase(value["encodingName"]) == "mpeg4-generic") {
			value["encodingName"] = (uint64_t) CODEC_AUDIO_AAC;
		} else {
			WARN("Invalid codec");
			value.Reset();
			return true;
		}
		value["clockRate"] = (uint32_t) atoi(STR(parts[1]));
		if (parts.size() == 3) {
			value["encodingParameters"] = parts[2];
		}

		return true;
	} else if (attributeName == "fmtp") {
		replace(rawValue, "; ", ";");
		vector<string> parts;
		split(rawValue, " ", parts);
		if (parts.size() != 2)
			return false;
		value["payloadType"] = (uint8_t) atoi(STR(parts[0]));
		map<string, string> temp = mapping(parts[1], ";", "=", false);

		FOR_MAP(temp, string, string, i) {
			value[MAP_KEY(i)] = MAP_VAL(i);
		}
예제 #5
0
	FOR_MAP(message[RM_NOTIFY_PARAMS], string, Variant, i) {
		if (!_amf0.Write(buffer, MAP_VAL(i))) {
			FATAL("Unable to serialize invoke parameter %s: %s",
					STR(MAP_KEY(i)),
					STR(message.ToString()));
			return false;
		}
	}
bool InboundJSONCLIProtocol::ParseCommand(string &command) {
	//1. Replace the '\\' escape sequence
	replace(command, "\\\\", "_#slash#_");

	//2. Replace the '\ ' escape sequence
	replace(command, "\\ ", "_#space#_");

	//2. Replace the '\=' escape sequence
	replace(command, "\\=", "_#equal#_");

	//2. Replace the '\,' escape sequence
	replace(command, "\\,", "_#coma#_");

	//3. Append "cmd=" in front of the command
	command = "cmd=" + command;
//	INFO("command: `%s`", STR(command));

	//4. create the map
	map<string, string> rawMap = mapping(command, " ", "=", true);

	//5. Create the variant
	Variant message;
	message["command"] = rawMap["cmd"];
	rawMap.erase("cmd");

	string key;
	string value;
	vector<string> list;

	FOR_MAP(rawMap, string, string, i) {
		key = MAP_KEY(i);
		replace(key, "_#space#_", " ");
		replace(key, "_#slash#_", "\\");
		replace(key, "_#equal#_", "=");
		replace(key, "_#coma#_", ",");

		value = MAP_VAL(i);
		replace(value, "_#space#_", " ");
		replace(value, "_#slash#_", "\\");
		replace(value, "_#equal#_", "=");

		list.clear();
		split(value, ",", list);
		if (list.size() != 1) {
			for (uint32_t j = 0; j < list.size(); j++) {
				trim(list[j]);
				if (list[j] == "")
					continue;
				replace(list[j], "_#coma#_", ",");
				message["parameters"][key].PushToArray(list[j]);
			}
		} else {
			replace(value, "_#coma#_", ",");
			message["parameters"][key] = value;
		}
	}
예제 #7
0
bool BaseHTTPProtocol::EnqueueForOutbound() {
	//1. Get the output buffer
	if (_pNearProtocol == NULL) {
		FATAL("No near protocol");
		return false;
	}
	IOBuffer *pBuffer = _pNearProtocol->GetOutputBuffer();
	uint32_t bufferLength = 0;
	if (pBuffer != NULL) {
		bufferLength = GETAVAILABLEBYTESCOUNT(*pBuffer);
	}

	//3. add or replace X-Powered-By attribute
	_outboundHeaders[HTTP_HEADERS_X_POWERED_BY] = HTTP_HEADERS_X_POWERED_BY_US;

	//4. add or replace the Server attribute
	if (GetType() == PT_INBOUND_HTTP) {
		_outboundHeaders[HTTP_HEADERS_SERVER] = HTTP_HEADERS_SERVER_US;
	}

	//5. Get rid of the Content-Length attribute and add it only if necessary
	_outboundHeaders.RemoveKey(HTTP_HEADERS_CONTENT_LENGTH);
	if (bufferLength > 0) {
		_outboundHeaders[HTTP_HEADERS_CONTENT_LENGTH] = format("%u", bufferLength);
	}

	//6. Get rid of Transfer-Encoding attribute
	_outboundHeaders.RemoveKey(HTTP_HEADERS_TRANSFER_ENCODING);

	//7. Write the first line of the request/response
	_outputBuffer.ReadFromString(GetOutputFirstLine() + "\r\n");

	//8. Write the headers and the final '\r\n'

	FOR_MAP(_outboundHeaders, string, Variant, i) {
		if (MAP_VAL(i) != V_STRING) {
			FATAL("Invalid HTTP headers:\n%s", STR(_outboundHeaders.ToString()));
			return false;
		}
		_outputBuffer.ReadFromString(format("%s: %s\r\n", STR(MAP_KEY(i)), STR(MAP_VAL(i))));
	}
	_outboundHeaders.Reset();
	_outboundHeaders.IsArray(false);
	_outputBuffer.ReadFromString("\r\n");

	//9. Write the actual content if necessary
	if (bufferLength > 0) {
		_outputBuffer.ReadFromBuffer(GETIBPOINTER(*pBuffer), GETAVAILABLEBYTESCOUNT(*pBuffer));

		//10. Empty the upper output buffer
		pBuffer->IgnoreAll();
	}

	//11. Let the request flow further
	return BaseProtocol::EnqueueForOutbound();
}
예제 #8
0
void Localization::LoadJSON(const JSONValue& source)
{
    for (JSONObject::const_iterator i = source.GetObject().begin(); i != source.GetObject().end(); ++i)
    {
        QString id = MAP_KEY(i);
        if (id.isEmpty())
        {
            URHO3D_LOGWARNING("Localization::LoadJSON(source): string ID is empty");
            continue;
        }
        const JSONObject& langs = MAP_VALUE(i).GetObject();
        for (JSONObject::const_iterator j = langs.begin(); j != langs.end(); ++j)
        {
            const QString& lang = MAP_KEY(j);
            if (lang.isEmpty())
            {
                URHO3D_LOGWARNING("Localization::LoadJSON(source): language name is empty, string ID=\"" + id + "\"");
                continue;
            }
            const QString stringRef = MAP_VALUE(j).GetString();
            if (stringRef.isEmpty())
            {
                URHO3D_LOGWARNING(
                    "Localization::LoadJSON(source): translation is empty, string ID=\"" + id + "\", language=\"" + lang + "\"");
                continue;
            }
            if (strings_[StringHash(lang)][StringHash(id)] != s_dummy)
            {
                URHO3D_LOGWARNING(
                    "Localization::LoadJSON(source): override translation, string ID=\"" + id + "\", language=\"" + lang + "\"");
            }
            strings_[StringHash(lang)][StringHash(id)] = stringRef;
            if (!languages_.contains(lang))
                languages_.push_back(lang);
            if (languageIndex_ == -1)
                languageIndex_ = 0;
        }
    }
}
예제 #9
0
bool BaseV4L2VideoCapture::SelectDeviceStream(string streamName) {
  FOR_MAP(_deviceVideoStreams, uint16_t, DeviceVideoStream *, i) {
    if(streamName.compare(MAP_VAL(i)->GetVideoStreamName()) == 0){
      _pCurrentDeviceStream.clear();
      _pCurrentDeviceStream.insert(pair<uint16_t, DeviceVideoStream*>(MAP_KEY(i), MAP_VAL(i)));
      return true;
    }
  }
  //if(MAP_HAS1(_deviceVideoStreams, deviceStreamId)){
  //  _pCurrentDeviceStream = MAP_VAL(_deviceVideoStreams.find(deviceStreamId));
  //  return true;
  //}
  WARN("Unable to find stream by name: %s", STR(streamName));
  return false;
}
예제 #10
0
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;
		}
	}
예제 #11
0
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;
		}
	}
예제 #12
0
bool PushVariant(lua_State *pLuaState,
		Variant &variant, bool substituteNullables) {
	switch ((VariantType) variant) {
		case V_UNDEFINED:
		case V_NULL:
		{
			if (substituteNullables)
				lua_pushstring(pLuaState, VAR_NULL_VALUE);
			else
				lua_pushnil(pLuaState);
			return true;
			break;
		}
		case V_STRING:
		{
			lua_pushstring(pLuaState, STR(variant));
			return true;
			break;
		}
		case V_INT8:
		case V_INT16:
		case V_INT32:
		case V_INT64:
		case V_UINT8:
		case V_UINT16:
		case V_UINT32:
		case V_UINT64:
		case V_DOUBLE:
		{
			lua_pushnumber(pLuaState, (double) variant);
			return true;
			break;
		}
		case V_BOOL:
		{
			lua_pushboolean(pLuaState, (bool)variant);
			return true;
			break;
		}
		case V_TIMESTAMP:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_TIMESTAMP);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, tempTm.tm_year + 1900);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, tempTm.tm_mon+1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, tempTm.tm_mday);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_HOUR);
			lua_pushnumber(pLuaState, tempTm.tm_hour);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MIN);
			lua_pushnumber(pLuaState, tempTm.tm_min);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_SEC);
			lua_pushnumber(pLuaState, tempTm.tm_sec);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_ISDST);
			lua_pushboolean(pLuaState, false);
			lua_settable(pLuaState, -3);

			return true;
			break;
		}
		case V_DATE:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_DATE);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, tempTm.tm_year + 1900);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, tempTm.tm_mon);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, tempTm.tm_mday);
			lua_settable(pLuaState, -3);
			return true;
			break;
		}
		case V_TIME:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_TIME);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, 1970);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_HOUR);
			lua_pushnumber(pLuaState, tempTm.tm_hour);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MIN);
			lua_pushnumber(pLuaState, tempTm.tm_min);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_SEC);
			lua_pushnumber(pLuaState, tempTm.tm_sec);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_ISDST);
			lua_pushboolean(pLuaState, false);
			lua_settable(pLuaState, -3);

			return true;
			break;
		}
		case V_TYPED_MAP:
		case V_MAP:
		{
			lua_createtable(pLuaState, 0, 0);

			if ((VariantType) variant == V_TYPED_MAP) {
				lua_pushstring(pLuaState, VAR_MAP_NAME);
				lua_pushstring(pLuaState, STR(variant.GetTypeName()));
				lua_settable(pLuaState, -3);
			}

			FOR_MAP(variant, string, Variant, i) {
				if (MAP_KEY(i).find(VAR_INDEX_VALUE) == 0) {
					string temp = MAP_KEY(i).substr(VAR_INDEX_VALUE_LEN,
							string::npos);
					char *error = NULL;
					double index = strtod(STR(temp), &error);
					if (error == STR(temp) + temp.size()) {
						lua_pushnumber(pLuaState, index);
					} else {
						lua_pushstring(pLuaState, STR(MAP_KEY(i)));
					}
				} else {
					lua_pushstring(pLuaState, STR(MAP_KEY(i)));
				}
				if (!PushVariant(pLuaState, MAP_VAL(i), true)) {
					FINEST("Unable to push primitive");
					return false;
				}
				lua_settable(pLuaState, -3);
			}
			return true;
			break;
		}
		default:
		{
			FATAL("Unknown type %hhu", (VariantType) variant);
			return false;
			break;
		}
	}
	return true;
}
예제 #13
0
bool PushVariant(lua_State *pLuaState,
		Variant &variant, bool substituteNullables) {
	switch ((VariantType) variant) {
		case V_UNDEFINED:
		case V_NULL:
		{
			if (substituteNullables)
				lua_pushstring(pLuaState, VAR_NULL_VALUE);
			else
				lua_pushnil(pLuaState);
			return true;
			break;
		}
		case V_STRING:
		{
			lua_pushstring(pLuaState, STR(variant));
			return true;
			break;
		}
		case V_INT8:
		case V_INT16:
		case V_INT32:
		case V_INT64:
		case V_UINT8:
		case V_UINT16:
		case V_UINT32:
		case V_UINT64:
		case V_DOUBLE:
		{
			lua_pushnumber(pLuaState, (double) variant);
			return true;
			break;
		}
		case V_BOOL:
		{
			lua_pushboolean(pLuaState, (bool)variant);
			return true;
			break;
		}
		case V_TIMESTAMP:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_TIMESTAMP);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, tempTm.tm_year + 1900);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, tempTm.tm_mon + 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, tempTm.tm_mday);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_HOUR);
			lua_pushnumber(pLuaState, tempTm.tm_hour + 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MIN);
			lua_pushnumber(pLuaState, tempTm.tm_min);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_SEC);
			lua_pushnumber(pLuaState, tempTm.tm_sec);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_ISDST);
			lua_pushboolean(pLuaState, false);
			lua_settable(pLuaState, -3);

			return true;
			break;
		}
		case V_DATE:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_DATE);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, tempTm.tm_year + 1900);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, tempTm.tm_mon + 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, tempTm.tm_mday);
			lua_settable(pLuaState, -3);
			return true;
			break;
		}
		case V_TIME:
		{
			struct tm tempTm = (struct tm) variant;

			lua_createtable(pLuaState, 0, 0);

			lua_pushstring(pLuaState, VAR_TYPE);
			lua_pushstring(pLuaState, VAR_TIME);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_YEAR);
			lua_pushnumber(pLuaState, 1970);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MONTH);
			lua_pushnumber(pLuaState, 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_DAY);
			lua_pushnumber(pLuaState, 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_HOUR);
			lua_pushnumber(pLuaState, tempTm.tm_hour + 1);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_MIN);
			lua_pushnumber(pLuaState, tempTm.tm_min);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_SEC);
			lua_pushnumber(pLuaState, tempTm.tm_sec);
			lua_settable(pLuaState, -3);

			lua_pushstring(pLuaState, VAR_ISDST);
			lua_pushboolean(pLuaState, false);
			lua_settable(pLuaState, -3);

			return true;
			break;
		}
		case V_TYPED_MAP:
		case V_MAP:
		{
			lua_createtable(pLuaState, 0, 0);

			if ((VariantType) variant == V_TYPED_MAP) {
				lua_pushstring(pLuaState, VAR_MAP_NAME);
				lua_pushstring(pLuaState, STR(variant.GetTypeName()));
				lua_settable(pLuaState, -3);
			}

			FOR_MAP(variant, string, Variant, i) {
				const char *pKey = MAP_KEY(i).c_str();
				if ((MAP_KEY(i).length() == 10) && (pKey[0] == '0')
						&& (pKey[1] == 'x')) {
					uint32_t index = (uint32_t) strtol(pKey, NULL, 16);
					lua_pushnumber(pLuaState, index);
				} else {
					lua_pushstring(pLuaState, pKey);
				}
				if (!PushVariant(pLuaState, MAP_VAL(i), true)) {
					FINEST("Unable to push primitive");
					return false;
				}
				lua_settable(pLuaState, -3);
			}
			return true;
			break;
		}
		default:
		{
			FATAL("Unknown type %d", (VariantType) variant);
			return false;
			break;
		}
	}
}
예제 #14
0
파일: uri.cpp 프로젝트: dista/crtmpserver
bool parseURI(string stringUri, URI &uri) {
	/*
	 * schema://[username[:password]@]host[:port][/[path[?parameters]]]
	 */
	LOG_URI("------------------------");
	LOG_URI("stringUri: `%s`", STR(stringUri));
	string fullUri;
	string fullUriWithAuth = stringUri;
	string scheme;
	string authentication;
	string username;
	string password;
	string hostPort;
	string host;
	string portString;
	uint16_t port;
	bool portSpecified;
	string fullDocumentPathWithParameters;
	string fullDocumentPath;
	string fullParameters;
	string documentPath;
	string document;
	string documentWithFullParameters;
	Variant parameters;

	string::size_type cursor = 0;
	string::size_type pos = 0;

	//1. Reset
	uri.Reset();

	//2. trim
	trim(stringUri);
	if (stringUri == "") {
		FATAL("Empty uri");
		return false;
	}

	//2. Get the scheme and the default port
	pos = stringUri.find("://", cursor);
	if (pos == string::npos) {
		FATAL("Unable to determine scheme");
		return false;
	}
	scheme = lowerCase(stringUri.substr(cursor, pos - cursor));
	cursor = pos + 3;
	if (_schemeToPort.size() == 0) {
		_schemeToPort["http"] = 80;
		_schemeToPort["rtmpt"] = 80;
		_schemeToPort["rtmpte"] = 80;
		_schemeToPort["https"] = 443;
		_schemeToPort["rtmps"] = 443;
		_schemeToPort["rtsp"] = 554;
		_schemeToPort["rtmp"] = 1935;
		_schemeToPort["rtmpe"] = 1935;
		_schemeToPort["mms"] = 1755;
	}
	if (MAP_HAS1(_schemeToPort, scheme)) {
		port = _schemeToPort[scheme];
	}
	//	else {
	//		FATAL("Scheme `%s` not supported", STR(scheme));
	//		return false;
	//	}
	LOG_URI("scheme: %s; default port: %"PRIu16, STR(scheme), port);

	//3. get the authentication portion. the search starts from
	//where the scheme detection left and up to the first / character
	string::size_type limit = stringUri.find("/", cursor);
	bool hasAuthentication = false;
	pos = stringUri.find("@", cursor);
	if (pos != string::npos) {
		if (limit != string::npos) {
			hasAuthentication = pos<limit;
		}
		hasAuthentication = true;
	}
	if (hasAuthentication) {
		authentication = stringUri.substr(cursor, pos - cursor);
		fullUri = stringUri.substr(0, cursor);
		fullUri += stringUri.substr(pos + 1);
		cursor = pos + 1;
	} else {
		fullUri = fullUriWithAuth;
	}
	if (authentication != "") {
		pos = authentication.find(":");
		if (pos != string::npos) {
			username = authentication.substr(0, pos);
			password = authentication.substr(pos + 1);
		} else {
			username = authentication;
			password = "";
		}
	}
	LOG_URI("fullUri: `%s`; fullUriWithAuth: `%s`", STR(fullUri), STR(fullUriWithAuth));
	LOG_URI("username: `%s`; password: `%s`", STR(username), STR(password));

	//4. Get the host:port
	pos = stringUri.find("/", cursor);
	if (pos == string::npos) {
		hostPort = stringUri.substr(cursor);
		cursor = stringUri.size() - 1;
		fullDocumentPathWithParameters = "/";
	} else {
		hostPort = stringUri.substr(cursor, pos - cursor);
		cursor = pos + 1;
		fullDocumentPathWithParameters = "/" + stringUri.substr(cursor);
	}
	trim(hostPort);
	if (hostPort == "") {
		FATAL("Invalid host:port specified");
		return false;
	}
	pos = hostPort.find(":");
	if (pos == string::npos) {
		host = hostPort;
		portSpecified = false;
	} else {
		host = hostPort.substr(0, pos);
		trim(host);
		portString = hostPort.substr(pos + 1);
		portSpecified = true;
		port = (uint16_t) atoi(STR(portString));
		if (format("%"PRIu16, port) != portString) {
			FATAL("Invalid port number specified: `%s`", STR(portString));
			return false;
		}
	}
	LOG_URI("host: %s; port: %"PRIu16"; portSpecified: %d", STR(host), port, portSpecified);

	//5. fullDocumentPathWithParameters
	fullDocumentPath = "/";
	fullParameters = "";
	documentPath = "/";
	document = "";
	documentWithFullParameters = "";
	parameters.Reset();
	parameters.IsArray(false);
	if (fullDocumentPathWithParameters != "/") {
		pos = fullDocumentPathWithParameters.find("?");
		if (pos == string::npos) {
			fullDocumentPath = fullDocumentPathWithParameters;
			fullParameters = "";
		} else {
			fullDocumentPath = fullDocumentPathWithParameters.substr(0, pos);
			fullParameters = fullDocumentPathWithParameters.substr(pos + 1);
		}

		trim(fullParameters);
		if (fullParameters != "") {
			vector<string> elements;
			split(fullParameters, "&", elements);
			for (uint32_t i = 0; i < elements.size(); i++) {
				string kvp = elements[i];
				if (kvp == "")
					continue;
				string k = "";
				string v = "";
				pos = kvp.find("=");
				if (pos == string::npos) {
					k = kvp;
					v = "";
				} else {
					k = kvp.substr(0, pos);
					v = kvp.substr(pos + 1);
				}
				if (k == "")
					continue;
				parameters[k] = v;
			}
		}

		for (string::size_type i = fullDocumentPath.size() - 1; i >= 0; i--) {
			if (fullDocumentPath[i] == '/')
				break;
			document = fullDocumentPath[i] + document;
		}
		documentPath = fullDocumentPath.substr(0, fullDocumentPath.size() - document.size());
		documentWithFullParameters = document;
		if (fullParameters != "")
			documentWithFullParameters += "?" + fullParameters;
	}
	LOG_URI("fullDocumentPathWithParameters: `%s`", STR(fullDocumentPathWithParameters));
	LOG_URI("fullDocumentPath: `%s`", STR(fullDocumentPath));
	LOG_URI("fullParameters: `%s`", STR(fullParameters));
	LOG_URI("documentPath: `%s`", STR(documentPath));
	LOG_URI("document: `%s`", STR(document));
	LOG_URI("documentWithFullParameters: `%s`", STR(documentWithFullParameters));
	LOG_URI("parameters:");
#ifdef DEBUG_URI

	FOR_MAP(parameters, string, Variant, i) {
		LOG_URI("\t`%s`: `%s`", STR(MAP_KEY(i)), STR(MAP_VAL(i)));
	}
예제 #15
0
static MWKEY MapKey (int key)
{
	switch (key)
	{
	MAP_KEY(LEFT);
	MAP_KEY(RIGHT);
	MAP_KEY(UP);
	MAP_KEY(DOWN);
	MAP_KEY(INSERT);
	MAP_KEY(DELETE);
	MAP_KEY(HOME);
	MAP_KEY(END);
	MAP_KEY(PAGEUP);
	MAP_KEY(PAGEDOWN);
	MAP_KEY(KP0);
	MAP_KEY(KP1);
	MAP_KEY(KP2);
	MAP_KEY(KP3);
	MAP_KEY(KP4);
	MAP_KEY(KP5);
	MAP_KEY(KP6);
	MAP_KEY(KP7);
	MAP_KEY(KP8);
	MAP_KEY(KP9);
	MAP_KEY(KP_PERIOD);
	MAP_KEY(KP_DIVIDE);
	MAP_KEY(KP_MULTIPLY);
	MAP_KEY(KP_MINUS);
	MAP_KEY(KP_PLUS);
	MAP_KEY(KP_ENTER);
	MAP_KEY(KP_EQUALS);
	MAP_KEY(LSHIFT);
	MAP_KEY(RSHIFT);
	MAP_KEY(LCTRL);
	MAP_KEY(RCTRL);
	MAP_KEY(LALT);
	MAP_KEY(RALT);
	MAP_KEY(MENU);
	case MAK_CLEAR: return MWKEY_BACKSPACE;
	case MAK_FIRE: return MWKEY_ACCEPT;
	case MAK_SOFTLEFT: return MWKEY_LMETA;
	case MAK_SOFTRIGHT: return MWKEY_RMETA;
	default: return key;
	}
	return MWKEY_UNKNOWN;
}
예제 #16
0
 //FOR_MAP (_mTicketMap, uint64_t, uint64_t, i) {
 //  DEBUG ("ticket:%llu", MAP_KEY(i));
 //}
 FOR_MAP (_mClientIdKeyMap, string, string, i) {
   DEBUG ("clientId:%s key:%s", STR(MAP_KEY(i)), STR(MAP_VAL(i)));
 }
예제 #17
0
	FOR_MAP(_clients, uint32_t, RTPClient, i) {
		BaseProtocol *pProtocol = ProtocolManager::GetProtocol(MAP_KEY(i));
		if (pProtocol != NULL)
			pProtocol->EnqueueForDelete();
	}
예제 #18
0
LRESULT KeyboardWinAPI::wndproc (HWND msgwin, UINT msg, WPARAM wParam, LPARAM lParam)
{
        LPARAM repeat_count = lParam & 0x0000FFFF;
        LPARAM scan_code = lParam & 0x00FF0000;
        LPARAM extended = lParam & 0x01000000;
        LPARAM context_code = lParam & 0x20000000;
        LPARAM was_down = lParam & 0x40000000;
        LPARAM key_up = lParam & 0x80000000;
        std::string key;
        if (key_up) {
            key = "-";
        } else {
            key = was_down ? "=" : "+";
        }
        bool have_key = false;
        switch (msg) {
                case WM_CHAR:
                case WM_UNICHAR: {
                        key = ":";
                        // control chars
                        if (wParam < 0x20 || (wParam >= 0x7f && wParam < 0xa0)) break;
                        encode_utf8(wParam, key);
                        if (verbose) {
                            CLOG << (void*)msg << ": \"" << key << "\" from " << wParam << ": " << "x" << repeat_count << std::endl;
                        }
                        have_key = true;
                }; break;

                case WM_KEYDOWN:
                case WM_KEYUP:
                case WM_SYSKEYDOWN:
                case WM_SYSKEYUP:
                if (verbose) {
                    CLOG << (void*)msg << ": " << key << wParam << ": " << "x" << repeat_count << std::endl;
                }
                switch (wParam) {
                        #define MAP_KEY(vk, name) case vk: { \
                            key += name; \
                            have_key = true; \
                        }; break
                        MAP_KEY(VK_SPACE, "Space");
                        MAP_KEY(VK_BACK, "BackSpace");
                        MAP_KEY(VK_ESCAPE,"Escape");
                        MAP_KEY(VK_CAPITAL, "CapsLock");
                        MAP_KEY(VK_TAB, "Tab");
                        MAP_KEY(VK_RETURN, "Return");
                        MAP_KEY(VK_CONTROL, "Ctrl");
                        //MAP_KEY(VK_LCONTROL, "Ctrl");
                        //MAP_KEY(VK_RCONTROL, "Ctrl");
                        MAP_KEY(VK_MENU, "Alt");
                        //MAP_KEY(VK_LMENU, "Alt");
                        //MAP_KEY(VK_RMENU, "Alt");

                        MAP_KEY(VK_F1, "F1");
                        MAP_KEY(VK_F2, "F2");
                        MAP_KEY(VK_F3, "F3");
                        MAP_KEY(VK_F4, "F4");
                        MAP_KEY(VK_F5, "F5");
                        MAP_KEY(VK_F6, "F6");
                        MAP_KEY(VK_F7, "F7");
                        MAP_KEY(VK_F8, "F8");
                        MAP_KEY(VK_F9, "F9");
                        MAP_KEY(VK_F10, "F10");
                        MAP_KEY(VK_F11, "F11");
                        MAP_KEY(VK_F12, "F12");
                        MAP_KEY(VK_F13, "F13");
                        MAP_KEY(VK_F14, "F14");
                        MAP_KEY(VK_F15, "F15");

                        MAP_KEY(VK_NUMPAD0, "NUMPAD0");
                        MAP_KEY(VK_NUMPAD1, "NUMPAD1");
                        MAP_KEY(VK_NUMPAD2, "NUMPAD2");
                        MAP_KEY(VK_NUMPAD3, "NUMPAD3");
                        MAP_KEY(VK_NUMPAD4, "NUMPAD4");
                        MAP_KEY(VK_NUMPAD5, "NUMPAD5");
                        MAP_KEY(VK_NUMPAD6, "NUMPAD6");
                        MAP_KEY(VK_NUMPAD7, "NUMPAD7");
                        MAP_KEY(VK_NUMPAD8, "NUMPAD8");
                        MAP_KEY(VK_NUMPAD9, "NUMPAD9");

                        MAP_KEY(VK_UP, "Up");
                        MAP_KEY(VK_DOWN, "Down");
                        MAP_KEY(VK_LEFT, "Left");
                        MAP_KEY(VK_RIGHT, "Right");

                        MAP_KEY(VK_PRIOR, "PageUp");
                        MAP_KEY(VK_NEXT, "PageDown");
                        MAP_KEY(VK_HOME, "Home");
                        MAP_KEY(VK_END, "End");

                        MAP_KEY(VK_NUMLOCK, "NumLock");
                        MAP_KEY(VK_SCROLL, "Scroll");
                        MAP_KEY(VK_PAUSE, "Pause");

                        MAP_KEY(VK_SHIFT, "Shift");

                        MAP_KEY(VK_INSERT, "Insert");
                        MAP_KEY(VK_DELETE, "Delete");

                        MAP_KEY(VK_LWIN, "Win");
                        MAP_KEY(VK_RWIN, "Win");
                        MAP_KEY(VK_APPS, "Menu");

                        MAP_KEY(VK_SNAPSHOT, "PrintScreen");

                        MAP_KEY(VK_CONVERT, "Convert");
                        MAP_KEY(VK_NONCONVERT, "Nonconvert");
                        MAP_KEY(VK_ACCEPT, "Accept");
                        MAP_KEY(VK_MODECHANGE, "Modechange");
                        MAP_KEY(VK_SELECT, "Select");
                        MAP_KEY(VK_PRINT, "Print");
                        MAP_KEY(VK_EXECUTE, "Execute");
                        MAP_KEY(VK_HELP, "Help");

                        default: {
                                key += getPress(wParam, scan_code);
                                have_key = true;
                        }
                }
                break;
        }

        if (have_key) {
                for (int i=0 ; i<repeat_count ; ++i)
                    presses.push_back(key);
        }

        return CallWindowProc(old_wndproc, msgwin, msg, wParam, lParam);
}
예제 #19
0
파일: uri.cpp 프로젝트: Undev/crtmpserver
bool parseURI(string stringUri, URI &uri) {
	LOG_URI_SPLIT("stringUri: %s", STR(stringUri));
	uri.Reset();
	trim(stringUri);
	if (stringUri == "")
		return false;

	if (stringUri.size() > 1024)
		return false;

	uri.fullUri = stringUri;
	LOG_URI_SPLIT("uri.fullUri: %s", STR(uri.fullUri));


	// scheme://user:pwd@host:port/document/parts/here

	vector<string> components;
	split(stringUri, "/", components);
	for (uint32_t i = 0; i < components.size(); i++) {
		LOG_URI_SPLIT("%u: %s", i, STR(components[i]));
	}

	//0 - scheme:
	if (components[0] == "")
		return false;

	if (components[0][components[0].size() - 1] != ':')
		return false;

	uri.scheme = lowerCase(components[0].substr(0, components[0].size() - 1));
	LOG_URI_SPLIT("uri.scheme: %s", STR(uri.scheme));


	//1 - nothing
	if (components[1] != "")
		return false;

	//2 - user:pwd@host:port
	vector<string> hostComponents;
	if (components[2].find("@") != string::npos) {
		split(components[2], "@", hostComponents);
		if (hostComponents.size() != 2)
			return false;
		if ((hostComponents[0] == "")
				|| (hostComponents[1] == "")) {
			return false;
		}
		components[2] = hostComponents[1];
		vector<string> userNamePasswordComponents;
		split(hostComponents[0], ":", userNamePasswordComponents);
		if (userNamePasswordComponents.size() != 2)
			return false;
		if ((userNamePasswordComponents[0] == "")
				|| (userNamePasswordComponents[1] == "")) {
			return false;
		}
		uri.userName = userNamePasswordComponents[0];
		LOG_URI_SPLIT("uri.userName: %s", STR(uri.userName));
		uri.password = userNamePasswordComponents[1];
		LOG_URI_SPLIT("uri.password: %s", STR(uri.password));
	}

	split(components[2], ":", hostComponents);
	if (hostComponents.size() == 1) {
		if (hostComponents[0] == "")
			return false;
		uri.host = hostComponents[0];
		LOG_URI_SPLIT("uri.host: %s", STR(uri.host));
	} else if (hostComponents.size() == 2) {
		if ((hostComponents[0] == "")
				|| (hostComponents[0] == ""))
			return false;
		uri.host = hostComponents[0];
		LOG_URI_SPLIT("uri.host: %s", STR(uri.host));
		int32_t port = atoi(STR(hostComponents[1]));
		if ((port <= 0) || (port > 65535))
			return false;
		uri.port = (uint16_t) port;
	} else {
		return false;
	}

	if (uri.port == 0) {
		if (___schemeToPort.size() == 0) {
			___schemeToPort["http"] = 80;
			___schemeToPort["rtmpt"] = 80;
			___schemeToPort["rtmpte"] = 80;
			___schemeToPort["https"] = 443;
			___schemeToPort["rtmps"] = 443;
			___schemeToPort["rtsp"] = 554;
			___schemeToPort["rtmp"] = 1935;
			___schemeToPort["rtmpe"] = 1935;
			___schemeToPort["mms"] = 1755;
		}
		if (MAP_HAS1(___schemeToPort, uri.scheme))
			uri.port = ___schemeToPort[uri.scheme];
		else
			return false;
	}
	LOG_URI_SPLIT("uri.port: %u", uri.port);

	for (uint32_t i = 3; i < components.size(); i++) {
		uri.fullDocumentPath += "/" + components[i];
	}
	LOG_URI_SPLIT("uri.fullDocumentPath: %s", STR(uri.fullDocumentPath));

	uri.documentPath = "/";
	for (uint32_t i = 3; i < components.size() - 1; i++) {
		uri.documentPath += components[i];
		if (i != components.size() - 2)
			uri.documentPath += "/";
	}
	LOG_URI_SPLIT("uri.documentPath: %s", STR(uri.documentPath));

	if ((components.size() - 1) >= 3) {
		uri.document = components[components.size() - 1];
		vector<string> documentComponents;
		split(uri.document, "?", documentComponents);
		if (documentComponents.size() == 2) {
			uri.document = documentComponents[0];
			map<string, string> params;
			params = mapping(documentComponents[1], "&", "=", true);

			FOR_MAP(params, string, string, i) {
				uri.parameters[MAP_KEY(i)] = MAP_VAL(i);
				LOG_URI_SPLIT("uri.parameters[\"%s\"]: %s",
						STR(MAP_KEY(i)),
						STR(MAP_VAL(i)));
			}
예제 #20
0
static KeyCode VKKeyToKeyCode(WPARAM p)
{
    uint32 key_code = (uint32)p;
    KeyCode result = KeyCode_UNKNOWN;

#define MAP_KEY(vk, res) case vk: result = res; break

    switch (key_code)
    {
    MAP_KEY(VK_BACK     , KeyCode_BACKSPACE);
    MAP_KEY(VK_TAB      , KeyCode_TAB);
    MAP_KEY(VK_RETURN   , KeyCode_ENTER);
    MAP_KEY(VK_SHIFT    , KeyCode_SHIFT);
    MAP_KEY(VK_CONTROL  , KeyCode_CONTROL);
    MAP_KEY(VK_MENU     , KeyCode_ALT);
    MAP_KEY(VK_CAPITAL  , KeyCode_CAPSLOCK);
    MAP_KEY(VK_ESCAPE   , KeyCode_ESCAPE);
    MAP_KEY(VK_SPACE    , KeyCode_SPACE);
    MAP_KEY(VK_LEFT     , KeyCode_LEFT);
    MAP_KEY(VK_UP       , KeyCode_UP);
    MAP_KEY(VK_RIGHT    , KeyCode_RIGHT);
    MAP_KEY(VK_DOWN     , KeyCode_DOWN);
    MAP_KEY(VK_OEM_1    , KeyCode_SEMICOLON);
    MAP_KEY(VK_OEM_3    , KeyCode_BACKQUOTE);

#undef MAP_KEY

    default:
    {
        if (key_code >= 'A' && key_code < 'Z')
        {
            result = (KeyCode)(KeyCode_a + (key_code - 'A'));
        }
        else if (key_code >= 0x30 && key_code <= 0x39)
        {
            result = (KeyCode)(KeyCode_0 + (key_code - 0x30));
        }
        else if (key_code >= VK_F1 && key_code <= VK_F12)
        {
            result = (KeyCode)(KeyCode_F1 + (key_code - VK_F1));
        }
        else
        {
            OutputDebugString("Unhandled Key Press!!!");
            //assert(!"Unmapped key press!");
        }
    } break;
    }

    //OutputDebugString("Pressed A Key!\n");

    return result;
}