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"
25 VDR_ResponsePacket::VDR_ResponsePacket()
30 getBlockRelease = false;
38 VDR_ResponsePacket::~VDR_ResponsePacket()
40 if (getBlockRelease) return; // don't free if it's a getblock
42 if (userData) free(userData);
45 void VDR_ResponsePacket::setResponse(ULONG trequestID, UCHAR* tuserData, ULONG tuserDataLength)
47 channelID = VDR::CHANNEL_REQUEST_RESPONSE;
48 requestID = trequestID;
50 userDataLength = tuserDataLength;
53 void VDR_ResponsePacket::setStream(ULONG tstreamID, UCHAR* tuserData, ULONG tuserDataLength)
55 channelID = VDR::CHANNEL_STREAM;
58 userDataLength = tuserDataLength;
61 bool VDR_ResponsePacket::end()
63 return (packetPos >= userDataLength);
66 int VDR_ResponsePacket::serverError()
68 if ((packetPos == 0) && (userDataLength == 4) && !ntohl(*(ULONG*)userData)) return 1;
72 char* VDR_ResponsePacket::extractString()
74 if (serverError()) return NULL;
76 int length = strlen((char*)&userData[packetPos]);
77 if ((packetPos + length) > userDataLength) return NULL;
78 char* str = new char[length + 1];
79 strcpy(str, (char*)&userData[packetPos]);
80 packetPos += length + 1;
84 UCHAR VDR_ResponsePacket::extractUCHAR()
86 if ((packetPos + sizeof(UCHAR)) > userDataLength) return 0;
87 UCHAR uc = userData[packetPos];
88 packetPos += sizeof(UCHAR);
92 ULONG VDR_ResponsePacket::extractULONG()
94 if ((packetPos + sizeof(ULONG)) > userDataLength) return 0;
95 ULONG ul = ntohl(*(ULONG*)&userData[packetPos]);
96 packetPos += sizeof(ULONG);
100 ULLONG VDR_ResponsePacket::extractULLONG()
102 if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
103 ULLONG ull = ntohll(*(ULLONG*)&userData[packetPos]);
104 packetPos += sizeof(ULLONG);
108 long VDR_ResponsePacket::extractLONG()
110 if ((packetPos + sizeof(long)) > userDataLength) return 0;
111 long l = ntohl(*(long*)&userData[packetPos]);
112 packetPos += sizeof(long);
116 UCHAR* VDR_ResponsePacket::getBlock_getUserData()
118 getBlockRelease = true;