]> git.vomp.tv Git - vompclient.git/blob - vdrresponsepacket.cc
WOptionPane CWFs
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 // FIXME
22
23 #include "vdrresponsepacket.h"
24
25 #include "vdr.h"
26
27 #include "util.h"
28
29 VDR_ResponsePacket::VDR_ResponsePacket()
30 {
31   userDataLength = 0;
32   packetPos = 0;
33   userData = NULL;
34   ownBlock = true;
35   
36   channelID = 0;
37   
38   requestID = 0;
39   streamID = 0;
40   
41   flag = 0;
42 }
43
44 VDR_ResponsePacket::~VDR_ResponsePacket()
45 {
46   if (!ownBlock) return; // don't free if it's a getblock
47   
48   if (userData) free(userData);
49 }
50
51 void VDR_ResponsePacket::setResponse(ULONG trequestID, UCHAR* tuserData, ULONG tuserDataLength)
52 {
53   channelID = VDR::CHANNEL_REQUEST_RESPONSE;
54   requestID = trequestID;
55   userData = tuserData;
56   userDataLength = tuserDataLength;
57 }
58
59 void VDR_ResponsePacket::setStream(ULONG tstreamID, ULONG tflag, UCHAR* tuserData, ULONG tuserDataLength, ULONG tchannelID)
60 {
61   channelID = tchannelID;
62   streamID = tstreamID;
63   flag = tflag;
64   userData = tuserData;
65   userDataLength = tuserDataLength;
66 }
67
68 bool VDR_ResponsePacket::end()
69 {
70   return (packetPos >= userDataLength);
71 }
72
73 void VDR_ResponsePacket::dumpUD()
74 {
75   dump(userData, userDataLength);
76 }
77
78 int VDR_ResponsePacket::serverError()
79 {
80   if ((packetPos == 0) && (userDataLength == 4) && !ntohl(*(ULONG*)userData)) return 1;
81   else return 0;
82 }
83
84 std::string  VDR_ResponsePacket::extractStdString()
85 {
86   if (serverError()) return NULL;
87
88   int length = strlen((char*)&userData[packetPos]);
89   if ((packetPos + length) > userDataLength) return std::string("");
90   const char * dest_str=(char*)&userData[packetPos];
91   packetPos += length + 1;
92   return dest_str;
93 }
94
95 char* VDR_ResponsePacket::extractString()
96 {
97   if (serverError()) return NULL;
98
99   int length = strlen((char*)&userData[packetPos]);
100   if ((packetPos + length) > userDataLength) return NULL;
101   char* str = new char[length + 1];
102   strcpy(str, (char*)&userData[packetPos]);
103   packetPos += length + 1;
104   return str;
105 }
106
107 UCHAR VDR_ResponsePacket::extractUCHAR()
108 {
109   if ((packetPos + sizeof(UCHAR)) > userDataLength) return 0;
110   UCHAR uc = userData[packetPos];
111   packetPos += sizeof(UCHAR);
112   return uc;
113 }
114
115 ULONG VDR_ResponsePacket::extractULONG()
116 {
117   if ((packetPos + sizeof(ULONG)) > userDataLength) return 0;
118   ULONG ul = userData[packetPos++]<<24;
119   ul|= userData[packetPos++]<<16;
120   ul|= userData[packetPos++]<<8;
121   ul|= userData[packetPos++];
122   //packetPos += sizeof(ULONG);
123   return ul;
124 }
125
126 ULLONG VDR_ResponsePacket::extractULLONG()
127 {
128   if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
129   ULLONG ull= ((ULLONG)userData[packetPos++])<<56;
130   ull|= ((ULLONG)userData[packetPos++])<<48;
131   ull|= ((ULLONG)userData[packetPos++])<<40;
132   ull|= ((ULLONG)userData[packetPos++])<<32;
133   ull|= ((ULLONG)userData[packetPos++])<<24;
134   ull|= ((ULLONG)userData[packetPos++])<<16;
135   ull|= ((ULLONG)userData[packetPos++])<<8;
136   ull|= ((ULLONG)userData[packetPos++]);
137   return ull;
138 }
139
140 double VDR_ResponsePacket::extractdouble()
141 {
142   if ((packetPos + sizeof(ULLONG)) > userDataLength) return 0;
143   ULLONG ull = extractULLONG();
144   double d;
145   memcpy(&d,&ull,sizeof(double));
146   return d;
147 }
148
149 long VDR_ResponsePacket::extractLONG()
150 {
151   if ((packetPos + sizeof(long)) > userDataLength) return 0;
152   long l = userData[packetPos++]<<24;
153   l|= userData[packetPos++]<<16;
154   l|= userData[packetPos++]<<8;
155   l|= userData[packetPos++];
156   return l;
157 }
158
159 UCHAR* VDR_ResponsePacket::getUserData()
160 {
161   ownBlock = false;
162   return userData;
163 }
164