forked from kodi-pvr/pvr.nextpvr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Rolling File, several fixes for v18 API changes, use more data fr…
…om backend when available
- Loading branch information
emveepee
committed
Feb 16, 2019
1 parent
78c6633
commit 86c2adf
Showing
16 changed files
with
1,477 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (C) 2005-2011 Team XBMC | ||
* http://www.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 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
|
||
#include "BackendRequest.h" | ||
#include "Filesystem.h" | ||
|
||
#define HTTP_OK 200 | ||
#define HTTP_NOTFOUND 404 | ||
#define HTTP_BADREQUEST 400 | ||
|
||
using namespace ADDON; | ||
|
||
namespace NextPVR | ||
{ | ||
Request *m_backEnd; | ||
int Request::DoRequest(const char *resource, std::string &response) | ||
{ | ||
P8PLATFORM::CLockObject lock(m_mutexRequest); | ||
m_start = time(nullptr); | ||
// build request string, adding SID if requred | ||
char strURL[1024]; | ||
|
||
if (strstr(resource, "method=session") == NULL) | ||
snprintf(strURL,sizeof(strURL),"http://%s:%d%s&sid=%s", g_szHostname.c_str(), g_iPort, resource, m_sid); | ||
else | ||
snprintf(strURL,sizeof(strURL),"http://%s:%d%s", g_szHostname.c_str(), g_iPort, resource); | ||
|
||
// ask XBMC to read the URL for us | ||
int resultCode = HTTP_NOTFOUND; | ||
void* fileHandle = XBMC->OpenFile(strURL, READ_NO_CACHE); | ||
if (fileHandle) | ||
{ | ||
char buffer[1024]; | ||
while (XBMC->ReadFileString(fileHandle, buffer, 1024)) | ||
{ | ||
response.append(buffer); | ||
} | ||
XBMC->CloseFile(fileHandle); | ||
resultCode = HTTP_OK; | ||
if ((response.empty() || strstr(response.c_str(), "<rsp stat=\"ok\">") == NULL) && strstr(resource, "method=channel.stream.info") == NULL ) | ||
{ | ||
XBMC->Log(LOG_ERROR, "DoRequest failed, response=%s", response.c_str()); | ||
resultCode = HTTP_BADREQUEST; | ||
} | ||
} | ||
XBMC->Log(LOG_DEBUG, "DoRequest return %s %d %d %d", resource, resultCode,response.length(),time(nullptr) -m_start); | ||
|
||
return resultCode; | ||
} | ||
int Request::FileCopy(const char *resource,std::string fileName) | ||
{ | ||
P8PLATFORM::CLockObject lock(m_mutexRequest); | ||
int written = 0; | ||
m_start = time(nullptr); | ||
|
||
char strURL[1024]; | ||
char separator = (strchr(resource,'?') == nullptr) ? '?' : '&'; | ||
snprintf(strURL,sizeof(strURL),"http://%s:%d%s%csid=%s", g_szHostname.c_str(), g_iPort, resource, separator, m_sid); | ||
|
||
// ask XBMC to read the URL for us | ||
int resultCode = HTTP_NOTFOUND; | ||
void* inputFile = XBMC->OpenFile(strURL, READ_NO_CACHE); | ||
int datalen; | ||
if (inputFile) | ||
{ | ||
void* outputFile = XBMC->OpenFileForWrite(fileName.c_str(), true); | ||
if (outputFile) | ||
{ | ||
char buffer[1024]; | ||
while (datalen=XBMC->ReadFile(inputFile, buffer, sizeof(buffer))) | ||
{ | ||
XBMC->WriteFile(outputFile, buffer, datalen); | ||
written += datalen; | ||
} | ||
XBMC->CloseFile(inputFile); | ||
XBMC->CloseFile(outputFile); | ||
resultCode = HTTP_OK; | ||
} | ||
} | ||
if (written == 0) | ||
{ | ||
resultCode = HTTP_BADREQUEST; | ||
} | ||
XBMC->Log(LOG_DEBUG, "FileCopy (%s - %s) %d %d %d", resource, fileName.c_str(), resultCode,written,time(nullptr) -m_start); | ||
|
||
return resultCode; | ||
} | ||
bool Request::PingBackend() | ||
{ | ||
char strURL[1024]; | ||
snprintf(strURL,sizeof(strURL),"http://%s:%d%s|connection-timeout=2", g_szHostname.c_str(), g_iPort, "/service?method=recording.lastupdated"); | ||
void* fileHandle = XBMC->OpenFile(strURL, READ_NO_CACHE); | ||
if (fileHandle) | ||
{ | ||
XBMC->CloseFile(fileHandle); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
/* | ||
* Copyright (C) 2005-2011 Team XBMC | ||
* http://www.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 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <ctime> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "client.h" | ||
#include "p8-platform/threads/mutex.h" | ||
|
||
using namespace ADDON; | ||
|
||
namespace NextPVR | ||
{ | ||
class Request | ||
{ | ||
public: | ||
int DoRequest(const char *resource, std::string &response); | ||
int FileCopy(const char *resource, std::string fileName); | ||
void setSID(char *newsid) {strcpy(m_sid,newsid);}; | ||
bool PingBackend(); | ||
const char *getSID() {return m_sid;}; | ||
Request(void){}; | ||
virtual ~Request() {}; | ||
private: | ||
P8PLATFORM::CMutex m_mutexRequest; | ||
time_t m_start; | ||
char m_sid[64]; | ||
}; | ||
extern Request *m_backEnd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.