nhttpd: try to fix threaded nhttp crashes (again)

Origin commit data
------------------
Branch: ni/coolstream
Commit: 14a73c3b80
Author: [CST] Focus <focus.cst@gmail.com>
Date: 2016-03-08 (Tue, 08 Mar 2016)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
[CST] Focus
2016-03-08 18:05:34 +03:00
parent c8418d2c17
commit a5be5f3911
4 changed files with 80 additions and 64 deletions

View File

@@ -807,7 +807,8 @@ int CControlAPI::rc_send(int ev, unsigned int code, unsigned int value)
//-----------------------------------------------------------------------------
// The code here is based on rcsim. Thx Carjay!
void CControlAPI::RCEmCGI(CyhookHandler *hh) {
void CControlAPI::RCEmCGI(CyhookHandler *hh)
{
if (hh->ParamList.empty()) {
hh->SendError();
return;
@@ -1038,39 +1039,38 @@ void CControlAPI::LogolistCGI(CyhookHandler *hh)
//-----------------------------------------------------------------------------
// get actual and next event data for given channel
//-----------------------------------------------------------------------------
std::string CControlAPI::_GetBouquetActualEPGItem(CyhookHandler *hh, CZapitChannel * channel) {
std::string CControlAPI::_GetBouquetActualEPGItem(CyhookHandler *hh, CZapitChannel * channel)
{
std::string result, firstEPG, secondEPG = "";
t_channel_id current_channel = CZapit::getInstance()->GetCurrentChannelID();
std::string timestr;
CShortEPGData epg;
CSectionsdClient::responseGetCurrentNextInfoChannelID currentNextInfo;
CChannelEvent *event;
NeutrinoAPI->Lock();
event = NeutrinoAPI->ChannelListEvents[channel->getChannelID()];
NeutrinoAPI->Unlock();
CChannelEvent event;
NeutrinoAPI->GetChannelEvent(channel->getChannelID(), event);
bool return_epginfo = (hh->ParamList["epginfo"] != "false");
result += hh->outPair("isActiveChannel", (channel->getChannelID() == current_channel) ? "true" : "false", false);
if (event) {
if (event.eventID) {
int percentage = 100;
if (event->duration > 0)
percentage = 100 * (time(NULL) - event->startTime) / event->duration;
if (event.duration > 0)
percentage = 100 * (time(NULL) - event.startTime) / event.duration;
CEitManager::getInstance()->getCurrentNextServiceKey(channel->getChannelID(), currentNextInfo);
timestr = timeString(event->startTime);
timestr = timeString(event.startTime);
firstEPG += hh->outPair("eventid", string_printf("%llu", currentNextInfo.current_uniqueKey), true);
firstEPG += hh->outPair("description", hh->outValue(event->description), true);
firstEPG += hh->outPair("description", hh->outValue(event.description), true);
if (return_epginfo && CEitManager::getInstance()->getEPGidShort(currentNextInfo.current_uniqueKey, &epg))
{
firstEPG += hh->outPair("info1", hh->outValue(epg.info1), true);
firstEPG += hh->outPair("info2", hh->outValue(epg.info2), true);
}
firstEPG += hh->outPair("startTime", timestr, true);
firstEPG += hh->outPair("timeTotal", string_printf("%d", event->duration / 60), true);
firstEPG += hh->outPair("timeElapsed", string_printf("%d", (time(NULL) - event->startTime) / 60), true);
firstEPG += hh->outPair("timeTotal", string_printf("%d", event.duration / 60), true);
firstEPG += hh->outPair("timeElapsed", string_printf("%d", (time(NULL) - event.startTime) / 60), true);
firstEPG += hh->outPair("percentage", string_printf("%d", percentage), false);
if (currentNextInfo.flags & CSectionsdClient::epgflags::has_next) {
@@ -1100,7 +1100,8 @@ std::string CControlAPI::_GetBouquetActualEPGItem(CyhookHandler *hh, CZapitChann
//-----------------------------------------------------------------------------
// produce data (collection) for given channel
std::string CControlAPI::_GetBouquetWriteItem(CyhookHandler *hh, CZapitChannel * channel, int bouquetNr, int channelNr) {
std::string CControlAPI::_GetBouquetWriteItem(CyhookHandler *hh, CZapitChannel * channel, int bouquetNr, int channelNr)
{
std::string result = "";
bool isEPGdetails = !(hh->ParamList["epg"].empty());
if (hh->outType == json || hh->outType == xml) {
@@ -1123,18 +1124,16 @@ std::string CControlAPI::_GetBouquetWriteItem(CyhookHandler *hh, CZapitChannel *
result = hh->outArrayItem("channel", result, false);
}
else {
CChannelEvent *event;
NeutrinoAPI->Lock();
event = NeutrinoAPI->ChannelListEvents[channel->getChannelID()];
NeutrinoAPI->Unlock();
CChannelEvent event;
NeutrinoAPI->GetChannelEvent(channel->getChannelID(), event);
if (event && isEPGdetails) {
if (event.eventID && isEPGdetails) {
result += string_printf("%u "
PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
" %s (%s)\n",
channelNr,
channel->getChannelID(),
channel->getName().c_str(), event->description.c_str());
channel->getName().c_str(), event.description.c_str());
} else {
result += string_printf("%u "
PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
@@ -1212,7 +1211,8 @@ std::string CControlAPI::_GetBouquetWriteItem(CyhookHandler *hh, CZapitChannel *
* @endcode
*/
//-------------------------------------------------------------------------
void CControlAPI::GetBouquetCGI(CyhookHandler *hh) {
void CControlAPI::GetBouquetCGI(CyhookHandler *hh)
{
TOutType outType = hh->outStart(true /*old mode*/);
std::string result = "";
@@ -1412,7 +1412,8 @@ void CControlAPI::GetChannelCGI(CyhookHandler *hh)
* @endcode
*/
//-------------------------------------------------------------------------
void CControlAPI::GetBouquetsCGI(CyhookHandler *hh) {
void CControlAPI::GetBouquetsCGI(CyhookHandler *hh)
{
bool show_hidden = true;
bool encode = false;
std::string result = "";
@@ -1472,10 +1473,12 @@ void CControlAPI::GetBouquetsCGI(CyhookHandler *hh) {
//-----------------------------------------------------------------------------
// details EPG Information for channelid
//-----------------------------------------------------------------------------
std::string CControlAPI::channelEPGformated(CyhookHandler *hh, int bouquetnr, t_channel_id channel_id, int max, long stoptime) {
std::string CControlAPI::channelEPGformated(CyhookHandler *hh, int bouquetnr, t_channel_id channel_id, int max, long stoptime)
{
std::string result = "";
std::string channelData = "";
CEitManager::getInstance()->getEventsServiceKey(channel_id, NeutrinoAPI->eList);
CChannelEventList eList;
CEitManager::getInstance()->getEventsServiceKey(channel_id, eList);
channelData += hh->outPair("channel_name", hh->outValue(NeutrinoAPI->GetServiceName(channel_id)), true);
channelData += hh->outPair("channel_id", string_printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel_id), true);
channelData += hh->outPair("channel_short_id", string_printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel_id & 0xFFFFFFFFFFFFULL), (bouquetnr > -1));
@@ -1486,7 +1489,7 @@ std::string CControlAPI::channelEPGformated(CyhookHandler *hh, int bouquetnr, t_
int i = 0;
CChannelEventList::iterator eventIterator;
bool isFirstLine = true;
for (eventIterator = NeutrinoAPI->eList.begin(); eventIterator != NeutrinoAPI->eList.end(); ++eventIterator, i++) {
for (eventIterator = eList.begin(); eventIterator != eList.end(); ++eventIterator, i++) {
if ((max != -1 && i >= max) || (stoptime != -1 && eventIterator->startTime >= stoptime))
break;
std::string prog = "";
@@ -1536,7 +1539,8 @@ std::string CControlAPI::channelEPGformated(CyhookHandler *hh, int bouquetnr, t_
//-----------------------------------------------------------------------------
// Detailed EPG list in XML or JSON
//-----------------------------------------------------------------------------
void CControlAPI::epgDetailList(CyhookHandler *hh) {
void CControlAPI::epgDetailList(CyhookHandler *hh)
{
// ------ get parameters -------
// max = maximal output items
int max = -1;
@@ -1579,7 +1583,6 @@ void CControlAPI::epgDetailList(CyhookHandler *hh) {
hh->outStart(true /*old mode*/);
std::string result = "";
NeutrinoAPI->eList.clear();
if (bouquetnr >= 0 || all_bouquets) {
int bouquet_size = (int) g_bouquetManager->Bouquets.size();
int start_bouquet = 0;
@@ -1829,8 +1832,8 @@ void CControlAPI::SendFoundEvents(CyhookHandler *hh, bool xml_format)
*/
//-------------------------------------------------------------------------
void CControlAPI::EpgCGI(CyhookHandler *hh) {
NeutrinoAPI->eList.clear();
void CControlAPI::EpgCGI(CyhookHandler *hh)
{
bool param_empty = hh->ParamList.empty();
hh->SetHeader(HTTP_OK, "text/plain; charset=UTF-8"); // default
// Detailed EPG list in XML or JSON
@@ -1841,24 +1844,22 @@ void CControlAPI::EpgCGI(CyhookHandler *hh) {
else if (param_empty || hh->ParamList["1"] == "ext") {
hh->SetHeader(HTTP_OK, "text/plain; charset=UTF-8");
bool isExt = (hh->ParamList["1"] == "ext");
CChannelEvent *event = NULL;
CChannelEvent event;
NeutrinoAPI->GetChannelEvents();
int mode = NeutrinoAPI->Zapit->getMode();
CBouquetManager::ChannelIterator cit = mode == CZapitClient::MODE_RADIO ? g_bouquetManager->radioChannelsBegin() : g_bouquetManager->tvChannelsBegin();
for (; !(cit.EndOfChannels()); cit++) {
CZapitChannel * channel = *cit;
NeutrinoAPI->Lock();
event = NeutrinoAPI->ChannelListEvents[channel->getChannelID()];
NeutrinoAPI->Unlock();
if (event) {
NeutrinoAPI->GetChannelEvent(channel->getChannelID(), event);
if (event.eventID) {
if (!isExt) {
hh->printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
" %llu %s\n", channel->getChannelID(), event->eventID, event->description.c_str());
" %llu %s\n", channel->getChannelID(), event.eventID, event.description.c_str());
}
else { // ext output
hh->printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
" %ld %u %llu %s\n", channel->getChannelID(), event->startTime, event->duration, event->eventID, event->description.c_str());
" %ld %u %llu %s\n", channel->getChannelID(), event.startTime, event.duration, event.eventID, event.description.c_str());
}
}
}
@@ -1897,9 +1898,10 @@ void CControlAPI::EpgCGI(CyhookHandler *hh) {
else if (!(hh->ParamList["id"].empty())) {
t_channel_id channel_id = 0;
sscanf(hh->ParamList["id"].c_str(), SCANF_CHANNEL_ID_TYPE, &channel_id);
CEitManager::getInstance()->getEventsServiceKey(channel_id, NeutrinoAPI->eList);
CChannelEventList eList;
CEitManager::getInstance()->getEventsServiceKey(channel_id, eList);
CChannelEventList::iterator eventIterator;
for (eventIterator = NeutrinoAPI->eList.begin(); eventIterator != NeutrinoAPI->eList.end(); ++eventIterator) {
for (eventIterator = eList.begin(); eventIterator != eList.end(); ++eventIterator) {
CShortEPGData epg;
if (CEitManager::getInstance()->getEPGidShort(eventIterator->eventID, &epg)) {
hh->printf("%llu %ld %d\n", eventIterator->eventID, eventIterator->startTime, eventIterator->duration);
@@ -2113,10 +2115,11 @@ void CControlAPI::LCDAction(CyhookHandler *hh)
void CControlAPI::SendEventList(CyhookHandler *hh, t_channel_id channel_id)
{
int pos = 0;
CEitManager::getInstance()->getEventsServiceKey(channel_id, NeutrinoAPI->eList);
CChannelEventList eList;
CEitManager::getInstance()->getEventsServiceKey(channel_id, eList);
CChannelEventList::iterator eventIterator;
for (eventIterator = NeutrinoAPI->eList.begin(); eventIterator != NeutrinoAPI->eList.end(); ++eventIterator, pos++)
for (eventIterator = eList.begin(); eventIterator != eList.end(); ++eventIterator, pos++)
hh->printf("%llu %ld %d %s\n", eventIterator->eventID, eventIterator->startTime, eventIterator->duration, eventIterator->description.c_str());
}
@@ -3141,7 +3144,8 @@ void CControlAPI::logoCGI(CyhookHandler *hh)
* @endcode
*/
//-------------------------------------------------------------------------
void CControlAPI::ConfigCGI(CyhookHandler *hh) {
void CControlAPI::ConfigCGI(CyhookHandler *hh)
{
bool load = true;
CConfigFile *Config = new CConfigFile(',');
ConfigDataMap conf;
@@ -3264,7 +3268,8 @@ void CControlAPI::ConfigCGI(CyhookHandler *hh) {
* action =new_folder|delete|read_file|write_file|set_properties
*/
//-----------------------------------------------------------------------------
void CControlAPI::FileCGI(CyhookHandler *hh) {
void CControlAPI::FileCGI(CyhookHandler *hh)
{
std::string result = "";
if (hh->ParamList["action"] == "list") { // directory list: action=list&path=<path>
@@ -3400,7 +3405,8 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
* @endcode
*/
//-----------------------------------------------------------------------------
void CControlAPI::StatfsCGI(CyhookHandler *hh) {
void CControlAPI::StatfsCGI(CyhookHandler *hh)
{
std::string result = "";
if (hh->ParamList["path"].empty())
@@ -3459,7 +3465,8 @@ void CControlAPI::StatfsCGI(CyhookHandler *hh) {
*
*/
//-----------------------------------------------------------------------------
void CControlAPI::getDirCGI(CyhookHandler *hh) {
void CControlAPI::getDirCGI(CyhookHandler *hh)
{
std::string result = "";
std::string item = "";
bool isFirstLine = true;
@@ -3519,7 +3526,8 @@ void CControlAPI::getDirCGI(CyhookHandler *hh) {
}
//Helpfunction to get subdirs of a dir
std::string CControlAPI::getSubdirectories(CyhookHandler *hh, std::string path, std::string result) {
std::string CControlAPI::getSubdirectories(CyhookHandler *hh, std::string path, std::string result)
{
std::string item = "";
std::string dirname;
DIR *dirp;