1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "TuxBoxDirectory.h"
#include "DirectoryCache.h"
#include "CurlFile.h"
#include "utils/HttpHeader.h"
#include "utils/TuxBoxUtil.h"
#include "URL.h"
#include "utils/XBMCTinyXML.h"
#include "settings/AdvancedSettings.h"
#include "FileItem.h"
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "utils/StringUtils.h"
using namespace XFILE;
CTuxBoxDirectory::CTuxBoxDirectory(void)
{
}
CTuxBoxDirectory::~CTuxBoxDirectory(void)
{
}
bool CTuxBoxDirectory::GetDirectory(const CURL& url2, CFileItemList &items)
{
const std::string strPath = url2.Get();
// so we know that we have enigma2
static bool enigma2 = false;
// Detect and delete slash at end
std::string strRoot = strPath;
URIUtils::RemoveSlashAtEnd(strRoot);
//Get the request strings
std::string strBQRequest;
std::string strXMLRootString;
std::string strXMLChildString;
if(!GetRootAndChildString(strRoot, strBQRequest, strXMLRootString, strXMLChildString))
return false;
//Set url Protocol
CURL url(strRoot);
std::string strFilter;
std::string protocol = url.GetProtocol();
url.SetProtocol("http");
bool bIsBouquet=false;
if (url.HasOption("path"))
{
// send Zap!
return g_tuxbox.ZapToUrl(url, url.GetOption("path"));
}
else
{
if (url.HasOption("reference") || enigma2)
{
//List reference
strFilter = url.GetOption("reference");
bIsBouquet = false; //On Empty is Bouquet
if (enigma2)
{
std::string strPort = StringUtils::Format(":%i",url.GetPort());
if (!StringUtils::EndsWith(strRoot, strPort)) // If not root dir, enable Channels
strFilter = "e2"; // Disable Bouquets for Enigma2
GetRootAndChildStringEnigma2(strBQRequest, strXMLRootString, strXMLChildString);
}
url.SetOptions("");
url.SetFileName(strBQRequest);
}
}
if(strFilter.empty())
{
url.SetOptions("");
url.SetFileName(strBQRequest);
bIsBouquet = true;
}
//Open
CCurlFile http;
int iTryConnect = 0;
int iWaitTimer = 20;
bool result = false;
while (iTryConnect < 4)
{
http.SetTimeout(iWaitTimer);
if(http.Open(url))
{
//We are connected!
iTryConnect = 4;
// restore protocol
url.SetProtocol(protocol);
int size_read = 0;
int size_total = (int)http.GetLength();
int data_size = 0;
std::string data;
data.reserve(size_total);
// read response from server into string buffer
char buffer[16384];
while ((size_read = http.Read(buffer, sizeof(buffer)-1)) > 0)
{
buffer[size_read] = 0;
data += buffer;
data_size += size_read;
}
http.Close();
// parse returned xml
CXBMCTinyXML doc;
StringUtils::Replace(data, "></",">-</"); //FILL EMPTY ELEMENTS WITH "-"!
doc.Parse(data, http.GetServerReportedCharset());
TiXmlElement *root = doc.RootElement();
if(root == NULL)
{
CLog::Log(LOGERROR, "%s - Unable to parse xml", __FUNCTION__);
CLog::Log(LOGERROR, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str());
return false;
}
if(strXMLRootString == root->Value() && bIsBouquet)
{
data.clear();
if (enigma2)
result = g_tuxbox.ParseBouquetsEnigma2(root, items, url, strFilter, strXMLChildString);
else
result = g_tuxbox.ParseBouquets(root, items, url, strFilter, strXMLChildString);
}
else if( strXMLRootString == root->Value() && !strFilter.empty() )
{
data.clear();
if (enigma2)
result = g_tuxbox.ParseChannelsEnigma2(root, items, url, strFilter, strXMLChildString);
else
result = g_tuxbox.ParseChannels(root, items, url, strFilter, strXMLChildString);
}
else
{
CLog::Log(LOGERROR, "%s - Invalid root xml element for TuxBox", __FUNCTION__);
CLog::Log(LOGERROR, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str());
data.clear();
result = false;
}
}
else
{
CLog::Log(LOGERROR, "%s - Unable to get XML structure! Try count:%i, Wait Timer:%is",__FUNCTION__, iTryConnect, iWaitTimer);
iTryConnect++;
if (iTryConnect == 2) //try enigma2 instead of enigma1, best entrypoint here i thought
{
enigma2 = true;
GetRootAndChildStringEnigma2(strBQRequest, strXMLRootString, strXMLChildString);
url.SetOptions("");
url.SetFileName(strBQRequest);
// iTryConnect = 0;
iWaitTimer = 20;
}
else
iWaitTimer = iWaitTimer+10;
result = false;
http.Close(); // Close old connections
}
}
items.SetContent("movies");
return result;
}
void CTuxBoxDirectory::GetRootAndChildStringEnigma2(std::string& strBQRequest, std::string& strXMLRootString, std::string& strXMLChildString )
{
// Allways take getallservices for Enigma2
strBQRequest = "web/getallservices"; //Bouquets and Channels
strXMLRootString = StringUtils::Format("e2servicelistrecursive");
strXMLChildString = StringUtils::Format("e2bouquet");
}
bool CTuxBoxDirectory::GetRootAndChildString(const std::string strPath, std::string& strBQRequest, std::string& strXMLRootString, std::string& strXMLChildString )
{
//Advanced Settings: RootMode! Movies:
if(g_advancedSettings.m_iTuxBoxDefaultRootMenu == 3) //Movies! Fixed-> mode=3&submode=4
{
CLog::Log(LOGDEBUG, "%s - Default defined RootMenu : (3) Movies", __FUNCTION__);
strBQRequest = "xml/services?mode=3&submode=4";
strXMLRootString = StringUtils::Format("movies");
strXMLChildString = StringUtils::Format("service");
}
else if(g_advancedSettings.m_iTuxBoxDefaultRootMenu <= 0 || g_advancedSettings.m_iTuxBoxDefaultRootMenu == 1 ||
g_advancedSettings.m_iTuxBoxDefaultRootMenu > 4 )
{
//Falling Back to the Default RootMenu => 0 Bouquets
if(g_advancedSettings.m_iTuxBoxDefaultRootMenu < 0 || g_advancedSettings.m_iTuxBoxDefaultRootMenu > 4)
{
g_advancedSettings.m_iTuxBoxDefaultRootMenu = 0;
}
//Advanced Settings: SubMenu!
if(g_advancedSettings.m_bTuxBoxSubMenuSelection)
{
CLog::Log(LOGDEBUG, "%s SubMenu Channel Selection is Enabled! Requesting Submenu!", __FUNCTION__);
// DeActivated: Timing Problems, bug in TuxBox.. etc.!
bool bReqMoRe = true;
// Detect the RootMode !
if (strPath.find("?mode=") != std::string::npos)
{
std::string strMode;
bReqMoRe=false;
strMode = g_tuxbox.DetectSubMode(strPath, strXMLRootString, strXMLChildString);
}
if(bReqMoRe)
{
//PopUp Context and Request SubMode with root and child string
strBQRequest = g_tuxbox.GetSubMode(g_advancedSettings.m_iTuxBoxDefaultRootMenu, strXMLRootString, strXMLChildString);
if(strBQRequest.empty())
{
strBQRequest = "xml/services?mode=0&submode=4"; //Bouquets
strXMLRootString = StringUtils::Format("bouquets");
strXMLChildString = StringUtils::Format("bouquet");
}
}
}
else
{
//Advanced Settings: Set Default Subemnu
if(g_advancedSettings.m_iTuxBoxDefaultSubMenu == 1)
{
CLog::Log(LOGDEBUG, "%s - Default defined SubMenu : (1) Services", __FUNCTION__);
strBQRequest = "xml/services?mode=0&submode=1"; //Services
strXMLRootString = StringUtils::Format("services");
strXMLChildString = StringUtils::Format("service");
}
else if(g_advancedSettings.m_iTuxBoxDefaultSubMenu == 2)
{
CLog::Log(LOGDEBUG, "%s - Default defined SubMenu : (2) Satellites", __FUNCTION__);
strBQRequest = "xml/services?mode=0&submode=2"; //Satellites
strXMLRootString = StringUtils::Format("satellites");
strXMLChildString = StringUtils::Format("satellite");
}
else if(g_advancedSettings.m_iTuxBoxDefaultSubMenu == 3)
{
CLog::Log(LOGDEBUG, "%s - Default defined SubMenu : (3) Providers", __FUNCTION__);
strBQRequest = "xml/services?mode=0&submode=3"; //Providers
strXMLRootString = StringUtils::Format("providers");
strXMLChildString = StringUtils::Format("provider");
}
else
{
CLog::Log(LOGDEBUG, "%s - Default defined SubMenu : (4) Bouquets", __FUNCTION__);
strBQRequest = "xml/services?mode=0&submode=4"; //Bouquets
strXMLRootString = StringUtils::Format("bouquets");
strXMLChildString = StringUtils::Format("bouquet");
}
}
}
if(strBQRequest.empty() || strXMLRootString.empty() || strXMLChildString.empty())
return false;
else
return true;
}
|