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"
23 VDR_ResponsePacket::VDR_ResponsePacket()
28 getBlockRelease = false;
31 VDR_ResponsePacket::~VDR_ResponsePacket()
33 if (getBlockRelease) return; // don't free if it's a getblock
35 if (packet) free(packet);
38 void VDR_ResponsePacket::set(UCHAR* tpacket, ULONG tpacketLength)
41 packetLength = tpacketLength;
44 ULONG VDR_ResponsePacket::getLength()
49 bool VDR_ResponsePacket::end()
51 return (packetPos >= packetLength);
54 int VDR_ResponsePacket::serverError()
56 if ((packetPos == 0) && (packetLength == 4) && !ntohl(*(ULONG*)packet)) return 1;
60 char* VDR_ResponsePacket::extractString()
62 if (serverError()) return NULL;
64 int length = strlen((char*)&packet[packetPos]);
65 if ((packetPos + length) > packetLength) return NULL;
66 char* str = new char[length + 1];
67 strcpy(str, (char*)&packet[packetPos]);
68 packetPos += length + 1;
72 UCHAR VDR_ResponsePacket::extractUCHAR()
74 if ((packetPos + sizeof(UCHAR)) > packetLength) return 0;
75 UCHAR uc = packet[packetPos];
76 packetPos += sizeof(UCHAR);
80 ULONG VDR_ResponsePacket::extractULONG()
82 if ((packetPos + sizeof(ULONG)) > packetLength) return 0;
83 ULONG ul = ntohl(*(ULONG*)&packet[packetPos]);
84 packetPos += sizeof(ULONG);
88 ULLONG VDR_ResponsePacket::extractULLONG()
90 if ((packetPos + sizeof(ULLONG)) > packetLength) return 0;
91 ULLONG ull = ntohll(*(ULLONG*)&packet[packetPos]);
92 packetPos += sizeof(ULLONG);
96 long VDR_ResponsePacket::extractLONG()
98 if ((packetPos + sizeof(long)) > packetLength) return 0;
99 long l = ntohl(*(long*)&packet[packetPos]);
100 packetPos += sizeof(long);
104 UCHAR* VDR_ResponsePacket::getBlock_getPacket()
106 getBlockRelease = true;