2 Copyright 2007 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 #include "vdrresponsepacket.h"
\r
26 VDR_ResponsePacket::VDR_ResponsePacket()
\r
41 VDR_ResponsePacket::~VDR_ResponsePacket()
\r
43 if (!ownBlock) return; // don't free if it's a getblock
\r
45 if (userData) free(userData);
\r
48 void VDR_ResponsePacket::setResponse(ULONG trequestID, UCHAR* tuserData, ULONG tuserDataLength)
\r
50 channelID = VDR::CHANNEL_REQUEST_RESPONSE;
\r
51 requestID = trequestID;
\r
52 userData = tuserData;
\r
53 userDataLength = tuserDataLength;
\r
56 void VDR_ResponsePacket::setStream(ULONG tstreamID, ULONG tflag, UCHAR* tuserData, ULONG tuserDataLength)
\r
58 channelID = VDR::CHANNEL_STREAM;
\r
59 streamID = tstreamID;
\r
61 userData = tuserData;
\r
62 userDataLength = tuserDataLength;
\r
65 bool VDR_ResponsePacket::end()
\r
67 return (packetPos >= userDataLength);
\r
70 void VDR_ResponsePacket::dumpUD()
\r
72 TCP::dump(userData, userDataLength);
\r
75 int VDR_ResponsePacket::serverError()
\r
77 if ((packetPos == 0) && (userDataLength == 4) && !ntohl(*(ULONG*)userData)) return 1;
\r
81 char* VDR_ResponsePacket::extractString()
\r
83 if (serverError()) return NULL;
\r
85 int length = strlen((char*)&userData[packetPos]);
\r
86 if ((packetPos + length) > userDataLength) return NULL;
\r
87 char* str = new char[length + 1];
\r
88 strcpy(str, (char*)&userData[packetPos]);
\r
89 packetPos += length + 1;
\r
93 UCHAR VDR_ResponsePacket::extractUCHAR()
\r
95 if ((packetPos + sizeof(UCHAR)) > userDataLength) return 0;
\r
96 UCHAR uc = userData[packetPos];
\r
97 packetPos += sizeof(UCHAR);
\r
101 ULONG VDR_ResponsePacket::extractULONG()
\r
103 if ((packetPos + sizeof(ULONG)) > userDataLength) return 0;
\r
104 ULONG ul = userData[packetPos++]<<24;
\r
105 ul|= userData[packetPos++]<<16;
\r
106 ul|= userData[packetPos++]<<8;
\r
107 ul|= userData[packetPos++];
\r
108 //packetPos += sizeof(ULONG);
\r
112 ULLONG VDR_ResponsePacket::extractULLONG()
\r
114 if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
\r
115 ULLONG ull= ((ULLONG)userData[packetPos++])<<56;
\r
116 ull|= ((ULLONG)userData[packetPos++])<<48;
\r
117 ull|= ((ULLONG)userData[packetPos++])<<40;
\r
118 ull|= ((ULLONG)userData[packetPos++])<<32;
\r
119 ull|= ((ULLONG)userData[packetPos++])<<24;
\r
120 ull|= ((ULLONG)userData[packetPos++])<<16;
\r
121 ull|= ((ULLONG)userData[packetPos++])<<8;
\r
122 ull|= ((ULLONG)userData[packetPos++]);
\r
126 double VDR_ResponsePacket::extractdouble()
\r
128 if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
\r
129 ULLONG ull = extractULLONG();
\r
131 memcpy(&d,&ull,sizeof(double));
\r
135 long VDR_ResponsePacket::extractLONG()
\r
137 if ((packetPos + sizeof(long)) > userDataLength) return 0;
\r
138 long l = userData[packetPos++]<<24;
\r
139 l|= userData[packetPos++]<<16;
\r
140 l|= userData[packetPos++]<<8;
\r
141 l|= userData[packetPos++];
\r
145 UCHAR* VDR_ResponsePacket::getUserData()
\r