mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-28 07:51:19 +02:00
- helpers: rework new random-functions to get the code more reuseable
* introduceand use LOGODIR_TMP (storage dir for webchannel logos) Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
@@ -659,13 +659,14 @@ bool CPictureViewer::GetLogoName(const uint64_t& channel_id, const std::string&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc) {
|
if (cc)
|
||||||
|
{
|
||||||
if (!cc->getAlternateLogo().empty())
|
if (!cc->getAlternateLogo().empty())
|
||||||
{
|
{
|
||||||
std::string lname = dlTmpName(cc->getAlternateLogo());
|
std::string lname = downloadUrlToRandomFile(cc->getAlternateLogo(), LOGODIR_TMP);
|
||||||
name = lname;
|
|
||||||
if (width && height)
|
if (width && height)
|
||||||
getSize(lname.c_str(), width, height);
|
getSize(lname.c_str(), width, height);
|
||||||
|
name = lname;
|
||||||
cc->setAlternateLogo(lname);
|
cc->setAlternateLogo(lname);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -644,13 +644,14 @@ void *insertEventsfromXMLTV(void * data)
|
|||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
std::string url = (char *) data;
|
std::string url = (char *) data;
|
||||||
std::string url_ext = getFileExt(url);
|
std::string tmp_name = randomFile(getFileExt(url), "/tmp", 8);
|
||||||
std::string tmp_name = genTmpName(url_ext,8);
|
|
||||||
|
|
||||||
int64_t now = time_monotonic_ms();
|
int64_t now = time_monotonic_ms();
|
||||||
|
|
||||||
if (url.compare(0, 1, "/") == 0)
|
if (url.compare(0, 1, "/") == 0)
|
||||||
|
{
|
||||||
readEventsFromXMLTV(url, ev_count);
|
readEventsFromXMLTV(url, ev_count);
|
||||||
|
}
|
||||||
else if (::downloadUrl(url, tmp_name))
|
else if (::downloadUrl(url, tmp_name))
|
||||||
{
|
{
|
||||||
readEventsFromXMLTV(tmp_name, ev_count);
|
readEventsFromXMLTV(tmp_name, ev_count);
|
||||||
|
@@ -51,6 +51,7 @@
|
|||||||
|
|
||||||
#define LOGODIR ICONSDIR "/logo"
|
#define LOGODIR ICONSDIR "/logo"
|
||||||
#define LOGODIR_VAR ICONSDIR_VAR "/logo"
|
#define LOGODIR_VAR ICONSDIR_VAR "/logo"
|
||||||
|
#define LOGODIR_TMP "/tmp/.logo"
|
||||||
|
|
||||||
NEUTRINO_CPP SNeutrinoSettings g_settings;
|
NEUTRINO_CPP SNeutrinoSettings g_settings;
|
||||||
NEUTRINO_CPP SglobalInfo g_info;
|
NEUTRINO_CPP SglobalInfo g_info;
|
||||||
|
@@ -1527,32 +1527,32 @@ bool utf8_check_is_valid(const std::string &str)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string genTmpName(std::string suffix,unsigned int length)
|
std::string randomString(unsigned int length)
|
||||||
{
|
{
|
||||||
|
std::string random = "";
|
||||||
const char alphanum[] =
|
const char alphanum[] =
|
||||||
"0123456789"
|
"0123456789"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"abcdefghijklmnopqrstuvwxyz";
|
"abcdefghijklmnopqrstuvwxyz";
|
||||||
int stringLength = sizeof(alphanum) - 1;
|
|
||||||
std::string Str;
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
Str.append("/tmp/");
|
|
||||||
for(i = 0; i < length; ++i)
|
for(i = 0; i < length; ++i)
|
||||||
{
|
random += alphanum[rand() % (sizeof(alphanum) - 1)];
|
||||||
Str += alphanum[rand() % stringLength];
|
return random;
|
||||||
}
|
|
||||||
Str += ".";
|
|
||||||
Str += suffix;
|
|
||||||
return Str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string dlTmpName(std::string url)
|
std::string randomFile(std::string suffix, std::string directory, unsigned int length)
|
||||||
|
{
|
||||||
|
mkdir(directory.c_str(), 0755);
|
||||||
|
return directory + "/" + randomString(length) + "." + suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string downloadUrlToRandomFile(std::string url, std::string directory, unsigned int length)
|
||||||
{
|
{
|
||||||
if (strstr(url.c_str(), "://"))
|
if (strstr(url.c_str(), "://"))
|
||||||
{
|
{
|
||||||
std::string tmpname = genTmpName(url.substr(url.find_last_of(".")+1),10);
|
std::string file = randomFile(url.substr(url.find_last_of(".") + 1), directory, length);
|
||||||
if (downloadUrl(url,tmpname))
|
if (downloadUrl(url, file))
|
||||||
url = tmpname;
|
return file;
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@@ -159,8 +159,9 @@ std::string readFile(std::string file);
|
|||||||
std::string iso_8859_1_to_utf8(std::string &str);
|
std::string iso_8859_1_to_utf8(std::string &str);
|
||||||
bool utf8_check_is_valid(const std::string &str);
|
bool utf8_check_is_valid(const std::string &str);
|
||||||
|
|
||||||
std::string genTmpName(std::string suffix,unsigned int length);
|
std::string randomString(unsigned int length = 10);
|
||||||
std::string dlTmpName(std::string url);
|
std::string randomFile(std::string suffix = "tmp", std::string directory = "/tmp", unsigned int length = 10);
|
||||||
|
std::string downloadUrlToRandomFile(std::string url, std::string directory = "/tmp", unsigned int length = 10);
|
||||||
|
|
||||||
// curl
|
// curl
|
||||||
struct MemoryStruct {
|
struct MemoryStruct {
|
||||||
|
@@ -853,7 +853,7 @@ void CBouquetManager::loadWebchannels(int mode)
|
|||||||
{
|
{
|
||||||
std::string filename = (*it);
|
std::string filename = (*it);
|
||||||
std::string extension = getFileExt(filename);
|
std::string extension = getFileExt(filename);
|
||||||
std::string tmp_name = genTmpName(extension,8);
|
std::string tmp_name = randomFile(extension, LOGODIR_TMP);
|
||||||
bool remove_tmp = false;
|
bool remove_tmp = false;
|
||||||
|
|
||||||
if (filename.compare(0, 1, "/") == 0)
|
if (filename.compare(0, 1, "/") == 0)
|
||||||
|
@@ -21,6 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
#include <system/helpers.h>
|
#include <system/helpers.h>
|
||||||
#include <zapit/zapit.h>
|
#include <zapit/zapit.h>
|
||||||
#include <zapit/channel.h>
|
#include <zapit/channel.h>
|
||||||
@@ -110,7 +112,7 @@ void CZapitChannel::Init()
|
|||||||
bLockCount = 0;
|
bLockCount = 0;
|
||||||
bLocked = DEFAULT_CH_LOCKED;
|
bLocked = DEFAULT_CH_LOCKED;
|
||||||
bUseCI = false;
|
bUseCI = false;
|
||||||
thrLogo = NULL;
|
thrLogo = 0;
|
||||||
altlogo = "";
|
altlogo = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,11 +444,9 @@ void CZapitChannel::setThrAlternateLogo(const std::string &pLogo)
|
|||||||
void* CZapitChannel::LogoThread(void* channel)
|
void* CZapitChannel::LogoThread(void* channel)
|
||||||
{
|
{
|
||||||
CZapitChannel *cc = (CZapitChannel *)channel;
|
CZapitChannel *cc = (CZapitChannel *)channel;
|
||||||
std::string lname = cc->getAlternateLogo();
|
if (cc)
|
||||||
cc->setAlternateLogo(dlTmpName(lname));
|
cc->setAlternateLogo(downloadUrlToRandomFile(cc->getAlternateLogo(), LOGODIR_TMP));
|
||||||
|
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user