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.
21 #include "vdrresponsepacket.h"
26 VDR_ResponsePacket::VDR_ResponsePacket()
41 VDR_ResponsePacket::~VDR_ResponsePacket()
43 if (!ownBlock) return; // don't free if it's a getblock
45 if (userData) free(userData);
48 void VDR_ResponsePacket::setResponse(ULONG trequestID, UCHAR* tuserData, ULONG tuserDataLength)
50 channelID = VDR::CHANNEL_REQUEST_RESPONSE;
51 requestID = trequestID;
53 userDataLength = tuserDataLength;
56 void VDR_ResponsePacket::setStream(ULONG tstreamID, ULONG tflag, UCHAR* tuserData, ULONG tuserDataLength)
58 channelID = VDR::CHANNEL_STREAM;
62 userDataLength = tuserDataLength;
65 bool VDR_ResponsePacket::end()
67 return (packetPos >= userDataLength);
70 void VDR_ResponsePacket::dumpUD()
72 TCP::dump(userData, userDataLength);
75 int VDR_ResponsePacket::serverError()
77 if ((packetPos == 0) && (userDataLength == 4) && !ntohl(*(ULONG*)userData)) return 1;
81 char* VDR_ResponsePacket::extractString()
83 if (serverError()) return NULL;
85 int length = strlen((char*)&userData[packetPos]);
86 if ((packetPos + length) > userDataLength) return NULL;
87 char* str = new char[length + 1];
88 strcpy(str, (char*)&userData[packetPos]);
89 packetPos += length + 1;
93 UCHAR VDR_ResponsePacket::extractUCHAR()
95 if ((packetPos + sizeof(UCHAR)) > userDataLength) return 0;
96 UCHAR uc = userData[packetPos];
97 packetPos += sizeof(UCHAR);
101 ULONG VDR_ResponsePacket::extractULONG()
103 if ((packetPos + sizeof(ULONG)) > userDataLength) return 0;
104 ULONG ul = userData[packetPos++]<<24;
105 ul|= userData[packetPos++]<<16;
106 ul|= userData[packetPos++]<<8;
107 ul|= userData[packetPos++];
108 //packetPos += sizeof(ULONG);
112 ULLONG VDR_ResponsePacket::extractULLONG()
114 if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
115 ULLONG ull= ((ULLONG)userData[packetPos++])<<56;
116 ull|= ((ULLONG)userData[packetPos++])<<48;
117 ull|= ((ULLONG)userData[packetPos++])<<40;
118 ull|= ((ULLONG)userData[packetPos++])<<32;
119 ull|= ((ULLONG)userData[packetPos++])<<24;
120 ull|= ((ULLONG)userData[packetPos++])<<16;
121 ull|= ((ULLONG)userData[packetPos++])<<8;
122 ull|= ((ULLONG)userData[packetPos++]);
126 double VDR_ResponsePacket::extractdouble()
128 if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
129 ULLONG ull = extractULLONG();
131 memcpy(&d,&ull,sizeof(double));
135 long VDR_ResponsePacket::extractLONG()
137 if ((packetPos + sizeof(long)) > userDataLength) return 0;
138 long l = userData[packetPos++]<<24;
139 l|= userData[packetPos++]<<16;
140 l|= userData[packetPos++]<<8;
141 l|= userData[packetPos++];
145 UCHAR* VDR_ResponsePacket::getUserData()