bool CNotificationLogitechMediaServer::SendMessageImplementation(const std::string &Subject, const std::string &Text, const std::string &ExtraData, const int Priority, const std::string &Sound, const bool bFromNotification)
{
	std::string	sSubject("Domoticz");
	if (Subject != Text)
	{
		sSubject = Subject;
	}

	CDomoticzHardwareBase *pHardware = m_mainworker.GetHardwareByType(HTYPE_LogitechMediaServer);
	CLogitechMediaServer* pLMS = dynamic_cast<CLogitechMediaServer*>(pHardware);

	if (pHardware == NULL) {
		std::stringstream logline;
		logline << "Error sending notification: 'Logitech Media Server' not found in Hardware-list";
		_log.Log(LOG_ERROR, "%s", logline.str().c_str());
		return false;
	}

	// Loop through semi-colon separated IP Addresses
	std::vector<std::string> results;
	StringSplit(_PlayerMac, ";", results);

	for (int i = 0; i < (int)results.size(); i++)
	{
		std::string sPlayerId = results[i];
		pLMS->SendText(sPlayerId, sSubject, Text, _Duration);
	}
	return true;
}
Пример #2
0
bool CFrontPageEditor::AddEditForm(CWholePage *pPageXML, const TDVCHAR *pSubject, const TDVCHAR *pBody, const TDVCHAR *pSkin, const TDVCHAR* pDate, int iRegistered)
{
    CTDVString sSubject(pSubject);
    CTDVString sBody(pBody);
    CTDVString sDate(pDate);
    CXMLObject::EscapeAllXML(&sSubject);
    CXMLObject::EscapeAllXML(&sBody);
    CXMLObject::EscapeAllXML(&sDate);
    CTDVString sXML;
    sXML = "<FRONTPAGE-EDIT-FORM><SUBJECT>";
    sXML << sSubject << "</SUBJECT>";
    sXML << "<BODY>" << sBody << "</BODY>";
    sXML << "<REGISTERED>" << iRegistered << "</REGISTERED>";
    sXML << "<SKIN>" << pSkin << "</SKIN>";
    sXML << "<DATE>" << sDate << "</DATE>";
    sXML << "</FRONTPAGE-EDIT-FORM>";
    pPageXML->AddInside("H2G2", sXML);
    return true;
}
Пример #3
0
bool CNotificationKodi::SendMessageImplementation(
	const uint64_t Idx,
	const std::string &Name,
	const std::string &Subject,
	const std::string &Text,
	const std::string &ExtraData,
	const int Priority,
	const std::string &Sound,
	const bool bFromNotification)
{
	std::string	sSubject("Domoticz");
	if (Subject != Text)
	{
		sSubject = Subject;
	}
	else
	{
		size_t	posDevice = ExtraData.find("|Name=");
		if (posDevice != std::string::npos)
		{
			posDevice+=6;
			sSubject = ExtraData.substr(posDevice, ExtraData.find("|", posDevice)-posDevice);
		}
	}

	std::string	sIconFile = GetIconFile(ExtraData);

	// Loop through semi-colon separated IP Addresses
	std::vector<std::string> results;
	StringSplit(_IPAddress, ";", results);
	for (int i=0; i < (int)results.size(); i++)
	{
		std::stringstream logline;
		logline << "Kodi Notification (" << results[i] << ":" << _Port << ", TTL " << _TTL << "): " << sSubject << ", " << Text << ", Icon " << sIconFile;
		_log.Log(LOG_NORM, "%s", logline.str().c_str());

		CAddress	_Address;
		int			_Sock;
		bool		bMulticast = (results[i].substr(0,4) >= "224.") && (results[i].substr(0,4) <= "239.");

		CAddress my_addr(results[i].c_str(), _Port);
		_Address = my_addr;
		_Sock = -1;
		if (bMulticast) {
			_Sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
			setsockopt(_Sock, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&_TTL, sizeof(_TTL));
			u_char loop = 1;
			setsockopt(_Sock, IPPROTO_IP, IP_MULTICAST_LOOP, (const char*) &loop, sizeof(loop));
		}
		else {
			_Sock = socket(AF_INET, SOCK_DGRAM, 0);
		}
		
		if (_Sock < 0)
		{
			logline << "Error creating socket: " << results[i] << ":" << _Port;
			_log.Log(LOG_ERROR, "%s", logline.str().c_str());
			return false;
		}

		_Address.Bind(_Sock);

		CPacketNOTIFICATION packet(sSubject.c_str(), Text.c_str(), ICON_PNG, (!sIconFile.empty())?sIconFile.c_str():NULL);
		if (!packet.Send(_Sock, _Address)) {
			std::stringstream logline;
			logline << "Error sending notification: " << results[i] << ":" << _Port;
			_log.Log(LOG_ERROR, "%s", logline.str().c_str());
			return false;
		}
	}
	return true;
}