2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
23 #ifdef HAS_EVENT_SERVER
25 #include "EventPacket.h"
27 #include "utils/log.h"
29 using namespace EVENTPACKET;
31 /************************************************************************/
33 /************************************************************************/
34 bool CEventPacket::Parse(int datasize, const void *data)
36 unsigned char* buf = (unsigned char *)data;
37 if (datasize < HEADER_SIZE || datasize > PACKET_SIZE)
41 if (memcmp(data, (const void*)HEADER_SIG, HEADER_SIG_LENGTH) != 0)
44 buf += HEADER_SIG_LENGTH;
46 // extract protocol version
50 if (m_cMajVer != 2 && m_cMinVer != 0)
54 m_eType = (PacketType)ntohs(*((uint16_t*)buf));
56 if (m_eType < (unsigned short)PT_HELO || m_eType >= (unsigned short)PT_LAST)
59 // get packet sequence id
61 m_iSeq = ntohl(*((uint32_t*)buf));
63 // get total message length
65 m_iTotalPackets = ntohl(*((uint32_t*)buf));
69 m_iPayloadSize = ntohs(*((uint16_t*)buf));
71 if ((m_iPayloadSize + HEADER_SIZE) != (unsigned int)datasize)
74 // get the client's token
76 m_iClientToken = ntohl(*((uint32_t*)buf));
83 // forward past reserved bytes
92 m_pPayload = malloc(m_iPayloadSize);
95 CLog::Log(LOGERROR, "ES: Out of memory");
98 memcpy(m_pPayload, buf, (size_t)m_iPayloadSize);
104 #endif // HAS_EVENT_SERVER