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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "vdrresponsepacket.h"
26 VDR_ResponsePacket::VDR_ResponsePacket()
39 VDR_ResponsePacket::~VDR_ResponsePacket()
41 if (!ownBlock) return; // don't free if it's a getblock
43 if (userData) free(userData);
46 void VDR_ResponsePacket::setResponse(ULONG trequestID, UCHAR* tuserData, ULONG tuserDataLength)
48 channelID = VDR::CHANNEL_REQUEST_RESPONSE;
49 requestID = trequestID;
51 userDataLength = tuserDataLength;
54 void VDR_ResponsePacket::setStream(ULONG tstreamID, UCHAR* tuserData, ULONG tuserDataLength)
56 channelID = VDR::CHANNEL_STREAM;
59 userDataLength = tuserDataLength;
62 bool VDR_ResponsePacket::end()
64 return (packetPos >= userDataLength);
67 void VDR_ResponsePacket::dumpUD()
69 TCP::dump(userData, userDataLength);
72 int VDR_ResponsePacket::serverError()
74 if ((packetPos == 0) && (userDataLength == 4) && !ntohl(*(ULONG*)userData)) return 1;
78 char* VDR_ResponsePacket::extractString()
80 if (serverError()) return NULL;
82 int length = strlen((char*)&userData[packetPos]);
83 if ((packetPos + length) > userDataLength) return NULL;
84 char* str = new char[length + 1];
85 strcpy(str, (char*)&userData[packetPos]);
86 packetPos += length + 1;
90 UCHAR VDR_ResponsePacket::extractUCHAR()
92 if ((packetPos + sizeof(UCHAR)) > userDataLength) return 0;
93 UCHAR uc = userData[packetPos];
94 packetPos += sizeof(UCHAR);
98 ULONG VDR_ResponsePacket::extractULONG()
100 if ((packetPos + sizeof(ULONG)) > userDataLength) return 0;
101 ULONG ul = ntohl(*(ULONG*)&userData[packetPos]);
102 packetPos += sizeof(ULONG);
106 ULLONG VDR_ResponsePacket::extractULLONG()
108 if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
109 ULLONG ull = ntohll(*(ULLONG*)&userData[packetPos]);
110 packetPos += sizeof(ULLONG);
114 long VDR_ResponsePacket::extractLONG()
116 if ((packetPos + sizeof(long)) > userDataLength) return 0;
117 long l = ntohl(*(long*)&userData[packetPos]);
118 packetPos += sizeof(long);
122 UCHAR* VDR_ResponsePacket::getUserData()