2 Copyright 2007 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "vdrresponsepacket.h"
29 VDR_ResponsePacket::VDR_ResponsePacket()
44 VDR_ResponsePacket::~VDR_ResponsePacket()
46 if (!ownBlock) return; // don't free if it's a getblock
48 if (userData) free(userData);
51 void VDR_ResponsePacket::setResponse(ULONG trequestID, UCHAR* tuserData, ULONG tuserDataLength)
53 channelID = VDR::CHANNEL_REQUEST_RESPONSE;
54 requestID = trequestID;
56 userDataLength = tuserDataLength;
59 void VDR_ResponsePacket::setStream(ULONG tstreamID, ULONG tflag, UCHAR* tuserData, ULONG tuserDataLength, ULONG tchannelID)
61 channelID = tchannelID;
65 userDataLength = tuserDataLength;
68 bool VDR_ResponsePacket::end()
70 return (packetPos >= userDataLength);
73 void VDR_ResponsePacket::dumpUD()
75 dump(userData, userDataLength);
78 int VDR_ResponsePacket::serverError()
80 if ((packetPos == 0) && (userDataLength == 4) && !ntohl(*(ULONG*)userData)) return 1;
84 std::string VDR_ResponsePacket::extractStdString()
86 if (serverError()) return NULL;
88 int length = strlen((char*)&userData[packetPos]);
89 if ((packetPos + length) > userDataLength) return std::string("");
90 const char * dest_str=(char*)&userData[packetPos];
91 packetPos += length + 1;
95 char* VDR_ResponsePacket::extractString()
97 if (serverError()) return NULL;
99 int length = strlen((char*)&userData[packetPos]);
100 if ((packetPos + length) > userDataLength) return NULL;
101 char* str = new char[length + 1];
102 strcpy(str, (char*)&userData[packetPos]);
103 packetPos += length + 1;
107 UCHAR VDR_ResponsePacket::extractUCHAR()
109 if ((packetPos + sizeof(UCHAR)) > userDataLength) return 0;
110 UCHAR uc = userData[packetPos];
111 packetPos += sizeof(UCHAR);
115 ULONG VDR_ResponsePacket::extractULONG()
117 if ((packetPos + sizeof(ULONG)) > userDataLength) return 0;
118 ULONG ul = userData[packetPos++]<<24;
119 ul|= userData[packetPos++]<<16;
120 ul|= userData[packetPos++]<<8;
121 ul|= userData[packetPos++];
122 //packetPos += sizeof(ULONG);
126 ULLONG VDR_ResponsePacket::extractULLONG()
128 if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
129 ULLONG ull= ((ULLONG)userData[packetPos++])<<56;
130 ull|= ((ULLONG)userData[packetPos++])<<48;
131 ull|= ((ULLONG)userData[packetPos++])<<40;
132 ull|= ((ULLONG)userData[packetPos++])<<32;
133 ull|= ((ULLONG)userData[packetPos++])<<24;
134 ull|= ((ULLONG)userData[packetPos++])<<16;
135 ull|= ((ULLONG)userData[packetPos++])<<8;
136 ull|= ((ULLONG)userData[packetPos++]);
140 double VDR_ResponsePacket::extractdouble()
142 if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
143 ULLONG ull = extractULLONG();
145 memcpy(&d,&ull,sizeof(double));
149 long VDR_ResponsePacket::extractLONG()
151 if ((packetPos + sizeof(long)) > userDataLength) return 0;
152 long l = userData[packetPos++]<<24;
153 l|= userData[packetPos++]<<16;
154 l|= userData[packetPos++]<<8;
155 l|= userData[packetPos++];
159 UCHAR* VDR_ResponsePacket::getUserData()