]> git.vomp.tv Git - vompclient.git/blob - vdrresponsepacket.cc
Start of new live tv
[vompclient.git] / vdrresponsepacket.cc
1 /*
2     Copyright 2007 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "vdrresponsepacket.h"
22
23 #include "vdr.h"
24
25 VDR_ResponsePacket::VDR_ResponsePacket()
26 {
27   userDataLength = 0;
28   packetPos = 0;
29   userData = NULL;
30   getBlockRelease = false;
31   
32   channelID = 0;
33   
34   requestID = 0;
35   streamID = 0;
36 }
37
38 VDR_ResponsePacket::~VDR_ResponsePacket()
39 {
40   if (getBlockRelease) return; // don't free if it's a getblock
41   
42   if (userData) free(userData);
43 }
44
45 void VDR_ResponsePacket::setResponse(ULONG trequestID, UCHAR* tuserData, ULONG tuserDataLength)
46 {
47   channelID = VDR::CHANNEL_REQUEST_RESPONSE;
48   requestID = trequestID;
49   userData = tuserData;
50   userDataLength = tuserDataLength;
51 }
52
53 void VDR_ResponsePacket::setStream(ULONG tstreamID, UCHAR* tuserData, ULONG tuserDataLength)
54 {
55   channelID = VDR::CHANNEL_STREAM;
56   streamID = tstreamID;
57   userData = tuserData;
58   userDataLength = tuserDataLength;
59 }
60
61 bool VDR_ResponsePacket::end()
62 {
63   return (packetPos >= userDataLength);
64 }
65
66 int VDR_ResponsePacket::serverError()
67 {
68   if ((packetPos == 0) && (userDataLength == 4) && !ntohl(*(ULONG*)userData)) return 1;
69   else return 0;
70 }
71
72 char* VDR_ResponsePacket::extractString()
73 {
74   if (serverError()) return NULL;
75
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;
81   return str;
82 }
83
84 UCHAR VDR_ResponsePacket::extractUCHAR()
85 {
86   if ((packetPos + sizeof(UCHAR)) > userDataLength) return 0;
87   UCHAR uc = userData[packetPos];
88   packetPos += sizeof(UCHAR);
89   return uc;
90 }
91
92 ULONG VDR_ResponsePacket::extractULONG()
93 {
94   if ((packetPos + sizeof(ULONG)) > userDataLength) return 0;
95   ULONG ul = ntohl(*(ULONG*)&userData[packetPos]);
96   packetPos += sizeof(ULONG);
97   return ul;
98 }
99
100 ULLONG VDR_ResponsePacket::extractULLONG()
101 {
102   if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
103   ULLONG ull = ntohll(*(ULLONG*)&userData[packetPos]);
104   packetPos += sizeof(ULLONG);
105   return ull;
106 }
107
108 long VDR_ResponsePacket::extractLONG()
109 {
110   if ((packetPos + sizeof(long)) > userDataLength) return 0;
111   long l = ntohl(*(long*)&userData[packetPos]);
112   packetPos += sizeof(long);
113   return l;
114 }
115
116 UCHAR* VDR_ResponsePacket::getBlock_getUserData()
117 {
118   getBlockRelease = true;
119   return userData;
120 }
121