//-------------------------------------------------------------------------
// y-func : get_channel_dropdown [<bouquet_nr> [<channel_id>]]
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_channels_as_dropdown(CyhookHandler *, std::string para)
{
	std::string abouquet, achannel_id, yresult, sel, sid;

	int bnumber = 1;
	int mode = NeutrinoAPI->Zapit->getMode();

	ySplitString(para," ",abouquet, achannel_id);
	if(abouquet != "")
		bnumber = atoi(abouquet.c_str());
	if(bnumber > 0) {
		bnumber--;
		ZapitChannelList channels;
		channels = mode == CZapitClient::MODE_RADIO ? g_bouquetManager->Bouquets[bnumber]->radioChannels : g_bouquetManager->Bouquets[bnumber]->tvChannels;
		for(int j = 0; j < (int) channels.size(); j++) {
			CEPGData epg;
			CZapitChannel * channel = channels[j];
			char buf[100],id[20];
			sprintf(id,PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS,channel->channel_id);
			std::string _sid = std::string(id);
			sel = (_sid == achannel_id) ? "selected=\"selected\"" : "";
			sectionsd_getActualEPGServiceKey(channel->channel_id&0xFFFFFFFFFFFFULL, &epg);
			sprintf(buf,"<option value="PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS" %s>%.20s - %.30s</option>\n", channel->channel_id, sel.c_str(), channel->getName().c_str(),epg.title.c_str());
			yresult += buf;
		}
	}
	return yresult;
}
Esempio n. 2
0
//-------------------------------------------------------------------------
// y-func : get_bouquets_as_dropdown [<bouquet>] <doshowhidden>
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_bouquets_as_dropdown(CyhookHandler *, std::string para)
{
	std::string yresult, sel, nr_str, do_show_hidden;
	int nr=1;

	ySplitString(para," ",nr_str, do_show_hidden);
	if(nr_str != "")
		nr = atoi(nr_str.c_str());

	int mode = NeutrinoAPI->Zapit->getMode();
	for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++) {
		//ZapitChannelList &channels = mode == CZapitClient::MODE_RADIO ? g_bouquetManager->Bouquets[i]->radioChannels : g_bouquetManager->Bouquets[i]->tvChannels;
		ZapitChannelList channels;
		if (mode == CZapitClient::MODE_RADIO)
			g_bouquetManager->Bouquets[i]->getRadioChannels(channels);
		else
			g_bouquetManager->Bouquets[i]->getTvChannels(channels);
		sel=(nr==(i+1)) ? "selected=\"selected\"" : "";
		if(!channels.empty() && (!g_bouquetManager->Bouquets[i]->bHidden || do_show_hidden == "true"))
			yresult += string_printf("<option value=%u %s>%s</option>\n", i + 1, sel.c_str(),
				std::string(g_bouquetManager->Bouquets[i]->bFav ? g_Locale->getText(LOCALE_FAVORITES_BOUQUETNAME) :g_bouquetManager->Bouquets[i]->Name.c_str()).c_str());
			//yresult += string_printf("<option value=%u %s>%s</option>\n", i + 1, sel.c_str(), (encodeString(std::string(g_bouquetManager->Bouquets[i]->Name.c_str()))).c_str());
	}
	return yresult;
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// Analyze URL
// Extract Filename, Path, FileExt
//	form RFC2616 / 3.2.2:
//	http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
// query data is splitted and stored in ParameterList
//-----------------------------------------------------------------------------
void CWebserverRequest::analyzeURL(std::string url)
{
	std::string fullurl = "";
	ParameterList.clear();

	// URI decode
	fullurl = decodeString(url);
	fullurl = trim(fullurl, "\r\n"); // non-HTTP-Standard: allow \r or \n in URL. Delete it.
	UrlData["fullurl"] = fullurl;

	// split Params
	if(ySplitString(url,"?",UrlData["url"],UrlData["paramstring"]))	// split pure URL and all Params
	{
		UrlData["url"] = decodeString(UrlData["url"]);
		ParseParams(UrlData["paramstring"]);			// split params to ParameterList
	}
	else								// No Params
		UrlData["url"] = fullurl;

	if(!ySplitStringLast(UrlData["url"],"/",UrlData["path"],UrlData["filename"]))
	{
		UrlData["path"] = "/";					// Set "/" if not contained
	}
	else
		UrlData["path"] += "/";
	if(( UrlData["url"].length() == 1) || (UrlData["url"][UrlData["url"].length()-1] == '/' ))
	{ // if "/" at end use index.html
		UrlData["path"] = UrlData["url"];
		UrlData["filename"] = "index.html";
	}
	ySplitStringLast(UrlData["filename"],".",UrlData["filenamepure"],UrlData["fileext"]);
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
// Parse the start-line
//	from RFC2616 / 5.1 Request-Line (start-line):
//	Request-Line   = Method SP Request-URI SP HTTP-Version CRLF (SP=Space)
//
//	Determine Reqest-Method, URL, HTTP-Version and Split Parameters
//	Split URL into path, filename, fileext .. UrlData[]
//-----------------------------------------------------------------------------
bool CWebserverRequest::ParseStartLine(std::string start_line)
{
	std::string method,url,http,tmp;

	log_level_printf(8,"<ParseStartLine>: line: %s\n", start_line.c_str() );
	if(ySplitString(start_line," ",method,tmp))
	{
		if(ySplitStringLast(tmp," ",url,Connection->httprotocol))
		{
			analyzeURL(url);
			UrlData["httprotocol"] = Connection->httprotocol;
			// determine http Method
			if(method.compare("POST") == 0)		Connection->Method = M_POST;
			else if(method.compare("GET") == 0)	Connection->Method = M_GET;
			else if(method.compare("PUT") == 0)	Connection->Method = M_PUT;
			else if(method.compare("HEAD") == 0)	Connection->Method = M_HEAD;
			else if(method.compare("PUT") == 0)	Connection->Method = M_PUT;
			else if(method.compare("DELETE") == 0)	Connection->Method = M_DELETE;
			else if(method.compare("TRACE") == 0)	Connection->Method = M_TRACE;
			else
			{
				log_level_printf(1,"Unknown Method or invalid request\n");
				Connection->Response.SendError(HTTP_NOT_IMPLEMENTED);
				log_level_printf(3,"Request: '%s'\n",rawbuffer.c_str());
				return false;
			}
			log_level_printf(3,"Request: FullURL: %s\n",UrlData["fullurl"].c_str());
			return true;
		}
	}
	return false;
}
Esempio n. 5
0
//-------------------------------------------------------------------------
// y-func : get_bouquets_as_dropdown [<bouquet>] <doshowhidden>
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_bouquets_as_dropdown(CyhookHandler *hh, std::string para)
{
	std::string ynr, yresult, sel, nr_str, do_show_hidden;
	int nr=1;
	
	ySplitString(para," ",nr_str, do_show_hidden);
	if(nr_str != "")
		nr = atoi(nr_str.c_str());

	for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++) {
		sel=(nr==(i+1)) ? "selected=\"selected\"" : "";
		if(!g_bouquetManager->Bouquets[i]->bHidden || do_show_hidden == "true")
			yresult += string_printf("<option value=%u %s>%s</option>\n", i + 1, sel.c_str(), 
				(encodeString(std::string(g_bouquetManager->Bouquets[i]->bFav ? g_Locale->getText(LOCALE_FAVORITES_BOUQUETNAME) :g_bouquetManager->Bouquets[i]->Name.c_str()))).c_str());
			//yresult += string_printf("<option value=%u %s>%s</option>\n", i + 1, sel.c_str(), (encodeString(std::string(g_bouquetManager->Bouquets[i]->Name.c_str()))).c_str());
	}
#if 0
	for (unsigned int i = 0; i < NeutrinoAPI->BouquetList.size();i++)
	{	
		sel=(nr==(i+1)) ? "selected=\"selected\"" : "";
		if(!NeutrinoAPI->BouquetList[i].hidden || do_show_hidden == "true")
			yresult += string_printf("<option value=%u %s>%s</option>\n", (NeutrinoAPI->BouquetList[i].bouquet_nr) + 1, sel.c_str(), (encodeString(std::string(NeutrinoAPI->BouquetList[i].name))).c_str());
	}
#endif
	return yresult;
}
Esempio n. 6
0
//-------------------------------------------------------------------------
// ySplitStringVector: spit string "str" and build vector of strings
//-------------------------------------------------------------------------
CStringArray ySplitStringVector(std::string str, std::string delimiter) {
	std::string left, right, rest;
	bool found;
	CStringArray split;
	rest = str;
	do {
		found = ySplitString(rest, delimiter, left, right);
		split.push_back(left);
		rest = right;
	} while (found);
	return split;
}
//-------------------------------------------------------------------------
// y-func : get_bouquets_as_templatelist <tempalte> [~<do_show_hidden>]
// TODO: select actual Bouquet
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_bouquets_as_templatelist(CyhookHandler *, std::string para)
{
	std::string yresult, ytemplate, do_show_hidden;

	ySplitString(para,"~",ytemplate, do_show_hidden);
	//ytemplate += "\n"; //FIXME add newline to printf
	for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++) {
		if(!g_bouquetManager->Bouquets[i]->bHidden || do_show_hidden == "true") {
			yresult += string_printf(ytemplate.c_str(), i + 1, g_bouquetManager->Bouquets[i]->bFav ? g_Locale->getText(LOCALE_FAVORITES_BOUQUETNAME) : g_bouquetManager->Bouquets[i]->Name.c_str());
			yresult += "\r\n";
		}
	}
	return yresult;
}
Esempio n. 8
0
//-------------------------------------------------------------------------
// y-func : dispatching and executing
//-------------------------------------------------------------------------
std::string CyParser::YWeb_cgi_func(CyhookHandler *hh, std::string ycmd) {
	std::string func, para, yresult = "ycgi func not found";
	bool found = false;
	ySplitString(ycmd, " ", func, para);

	for (unsigned int i = 0; i < (sizeof(yFuncCallList)
			/ sizeof(yFuncCallList[0])); i++)
		if (func == yFuncCallList[i].func_name) {
			yresult = (this->*yFuncCallList[i].pfunc)(hh, para);
			found = true;
			break;
		}
	log_level_printf(8, "<yparser: func>:%s Result:%s\n", func.c_str(),
			yresult.c_str());
	return yresult;
}
Esempio n. 9
0
//-------------------------------------------------------------------------
// y-func : get_bouquets_as_templatelist <tempalte> [~<do_show_hidden>]
// TODO: select actual Bouquet
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_bouquets_as_templatelist(CyhookHandler *, std::string para)
{
	std::string yresult, ytemplate, do_show_hidden;

	ySplitString(para,"~",ytemplate, do_show_hidden);
	//ytemplate += "\n"; //FIXME add newline to printf
	int mode = NeutrinoAPI->Zapit->getMode();
	for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++) {
		//ZapitChannelList &channels = mode == CZapitClient::MODE_RADIO ? g_bouquetManager->Bouquets[i]->radioChannels : g_bouquetManager->Bouquets[i]->tvChannels;
		ZapitChannelList channels;
		if (mode == CZapitClient::MODE_RADIO)
			g_bouquetManager->Bouquets[i]->getRadioChannels(channels);
		else
			g_bouquetManager->Bouquets[i]->getTvChannels(channels);
		if(!channels.empty() && (!g_bouquetManager->Bouquets[i]->bHidden || do_show_hidden == "true")) {
			yresult += string_printf(ytemplate.c_str(), i + 1, g_bouquetManager->Bouquets[i]->bFav ? g_Locale->getText(LOCALE_FAVORITES_BOUQUETNAME) : g_bouquetManager->Bouquets[i]->Name.c_str());
			yresult += "\r\n";
		}
	}
	return yresult;
}
//-------------------------------------------------------------------------
// y-func : get_bouquets_as_templatelist <tempalte> [~<do_show_hidden>]
// TODO: select actual Bouquet
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_bouquets_as_templatelist(CyhookHandler *, std::string para)
{
	std::string yresult, ytemplate, do_show_hidden;

	ySplitString(para,"~",ytemplate, do_show_hidden);
	//ytemplate += "\n"; //FIXME add newline to printf
	int mode = NeutrinoAPI->Zapit->getMode();
	for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++) {
		//ZapitChannelList &channels = mode == CZapitClient::MODE_RADIO ? g_bouquetManager->Bouquets[i]->radioChannels : g_bouquetManager->Bouquets[i]->tvChannels;
		ZapitChannelList channels;
		if (mode == CZapitClient::MODE_RADIO)
			g_bouquetManager->Bouquets[i]->getRadioChannels(channels);
		else
			g_bouquetManager->Bouquets[i]->getTvChannels(channels);
#if HAVE_DUCKBOX_HARDWARE
		if(!channels.empty() && (!g_bouquetManager->Bouquets[i]->bHidden || do_show_hidden == "true") && g_bouquetManager->Bouquets[i]->bUser) {
#else
		if(!channels.empty() && (!g_bouquetManager->Bouquets[i]->bHidden || do_show_hidden == "true")) {
#endif
			yresult += string_printf(ytemplate.c_str(), i + 1, g_bouquetManager->Bouquets[i]->bFav ? g_Locale->getText(LOCALE_FAVORITES_BOUQUETNAME) : g_bouquetManager->Bouquets[i]->Name.c_str());
			yresult += "\r\n";
		}
	}
	return yresult;
}
//-------------------------------------------------------------------------
// y-func : get_actual_bouquet_number
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_actual_bouquet_number(CyhookHandler *, std::string)
{
	int actual=0;
	for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++) {
		if(g_bouquetManager->existsChannelInBouquet(i, CZapit::getInstance()->GetCurrentChannelID())) {
			actual=i+1;
			break;
		}
	}
	return std::string(itoa(actual));
}
Esempio n. 11
0
// para ::= <type=new|modify> [timerid]
std::string  CNeutrinoYParser::func_set_timer_form(CyhookHandler *hh, std::string para)
{
	unsigned timerId=0;
	std::string cmd, stimerid;
	CTimerd::responseGetTimer timer;             // Timer
	time_t now_t = time(NULL);
	ySplitString(para, " ", cmd, stimerid);
	if(cmd != "new")
	{
		// init timerid
		if(stimerid != "")
			timerId = (unsigned)atoi(stimerid.c_str());

		NeutrinoAPI->Timerd->getTimer(timer, timerId);
		std::string zType = NeutrinoAPI->timerEventType2Str(timer.eventType);

		hh->ParamList["timerId"] = itoa(timerId);
		hh->ParamList["zType"] = zType;
	}
	// Alarm/StopTime
	struct tm *alarmTime = (cmd == "new") ? localtime(&now_t) : localtime(&(timer.alarmTime));

	hh->ParamList["alarm_mday"] = string_printf("%02d", alarmTime->tm_mday);
	hh->ParamList["alarm_mon"]  = string_printf("%02d", alarmTime->tm_mon +1);
	hh->ParamList["alarm_year"] = string_printf("%04d", alarmTime->tm_year + 1900);
	hh->ParamList["alarm_hour"] = string_printf("%02d", alarmTime->tm_hour);
	hh->ParamList["alarm_min"]  = string_printf("%02d", alarmTime->tm_min);

	struct tm *stopTime = (cmd == "new") ? alarmTime : ( (timer.stopTime > 0) ? localtime(&(timer.stopTime)) : NULL );
	if(stopTime != NULL)
	{
		hh->ParamList["stop_mday"] = string_printf("%02d", stopTime->tm_mday);
		hh->ParamList["stop_mon"]  = string_printf("%02d", stopTime->tm_mon +1);
		hh->ParamList["stop_year"] = string_printf("%04d", stopTime->tm_year + 1900);
		hh->ParamList["stop_hour"] = string_printf("%02d", stopTime->tm_hour);
		hh->ParamList["stop_min"]  = string_printf("%02d", stopTime->tm_min);

		// APid settings for Record
		if(timer.apids == TIMERD_APIDS_CONF)
			hh->ParamList["TIMERD_APIDS_CONF"] = "y";
		if(timer.apids & TIMERD_APIDS_STD)
			hh->ParamList["TIMERD_APIDS_STD"]  = "y";
		if(timer.apids & TIMERD_APIDS_ALT)
			hh->ParamList["TIMERD_APIDS_ALT"]  = "y";
		if(timer.apids & TIMERD_APIDS_AC3)
			hh->ParamList["TIMERD_APIDS_AC3"]  = "y";
	}
	else
		hh->ParamList["stop_mday"] = "0";
	// event type
	std::string sel;
	for(int i=1; i<=8;i++)
	{
		if (i != (int)CTimerd::__TIMER_NEXTPROGRAM)
		{
			std::string zType = NeutrinoAPI->timerEventType2Str((CTimerd::CTimerEventTypes) i);
			if(cmd != "new")
				sel = (i==(int)timer.eventType) ? "selected=\"selected\"" : "";
			else
				sel = (i==(int)CTimerd::TIMER_RECORD) ? "selected=\"selected\"" : "";
			hh->ParamList["timertype"] +=
				string_printf("<option value=\"%d\" %s>%s\n",i,sel.c_str(),zType.c_str());
		}
	}
	// Repeat types
	std::string zRep;
	sel = "";
	for(int i=0; i<=6;i++)
	{
		if(i!=(int)CTimerd::TIMERREPEAT_BYEVENTDESCRIPTION)
		{

			zRep = NeutrinoAPI->timerEventRepeat2Str((CTimerd::CTimerEventRepeat) i);
			if(cmd != "new")
				sel = (((int)timer.eventRepeat) == i) ? "selected=\"selected\"" : "";
			hh->ParamList["repeat"] +=
				string_printf("<option value=\"%d\" %s>%s</option>\n",i,sel.c_str(),zRep.c_str());
		}
	}
	// Repeat Weekdays
	zRep = NeutrinoAPI->timerEventRepeat2Str(CTimerd::TIMERREPEAT_WEEKDAYS);
	if(timer.eventRepeat >= CTimerd::TIMERREPEAT_WEEKDAYS && cmd != "new")
		sel = "selected=\"selected\"";
	else
		sel = "";
	hh->ParamList["repeat"] +=
		string_printf("<option value=\"%d\" %s>%s</option>\n",(int)CTimerd::TIMERREPEAT_WEEKDAYS, sel.c_str(), zRep.c_str());

	// Weekdays
	std::string weekdays;
	NeutrinoAPI->Timerd->setWeekdaysToStr(timer.eventRepeat, weekdays);
	hh->ParamList["weekdays"]=	 weekdays;

	// timer repeats
	if (timer.eventRepeat == CTimerd::TIMERREPEAT_ONCE)
		hh->ParamList["TIMERREPEAT_ONCE"]  = "y";
	hh->ParamList["timer_repeatCount"]  = itoa(timer.repeatCount);

	// program row
	t_channel_id current_channel = (cmd == "new") ? CZapit::getInstance()->GetCurrentChannelID() : timer.channel_id;
	CBouquetManager::ChannelIterator cit = g_bouquetManager->tvChannelsBegin();
	for (; !(cit.EndOfChannels()); cit++) {
		if (((*cit)->flags & CZapitChannel::REMOVED) || (*cit)->flags & CZapitChannel::NOT_FOUND)
			continue;
		sel = ((*cit)->channel_id == current_channel) ? "selected=\"selected\"" : "";
		hh->ParamList["program_row"] +=
			string_printf("<option value=\""
				PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
				"\" %s>%s</option>\n",
				(*cit)->channel_id, sel.c_str(), (*cit)->getName().c_str());
	}
	cit = g_bouquetManager->radioChannelsBegin();
	for (; !(cit.EndOfChannels()); cit++) {
		if (((*cit)->flags & CZapitChannel::REMOVED) || (*cit)->flags & CZapitChannel::NOT_FOUND)
			continue;
		sel = ((*cit)->channel_id == current_channel) ? "selected=\"selected\"" : "";
		hh->ParamList["program_row"] +=
			string_printf("<option value=\""
				PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
				"\" %s>%s</option>\n",
				(*cit)->channel_id, sel.c_str(), (*cit)->getName().c_str());
	}
	// recordingDir
	hh->ParamList["RECORD_DIR_MAXLEN"] = itoa(RECORD_DIR_MAXLEN-1);
	if(cmd != "new") {
		if(timer.eventType == CTimerd::TIMER_RECORD)
			hh->ParamList["timer_recordingDir"] = timer.recordingDir;
	}
	else
	{
		// get Default Recordingdir
		CConfigFile *Config = new CConfigFile(',');
		Config->loadConfig(NEUTRINO_CONFIGFILE);
		hh->ParamList["timer_recordingDir"] = Config->getString("network_nfs_recordingdir", "/mnt/filme");
		delete Config;
	}
	hh->ParamList["standby"] = (cmd == "new")? "0" : ((timer.standby_on)?"1":"0");
	hh->ParamList["message"] = (cmd == "new")? "" : timer.message;
	hh->ParamList["pluginname"] = (cmd == "new")? "" : timer.pluginName;

	return "";
}
Esempio n. 12
0
//-------------------------------------------------------------------------
// TODO: clean up code
// use templates?
//-------------------------------------------------------------------------
std::string CNeutrinoYParser::func_get_bouquets_with_epg(CyhookHandler *hh, std::string para)
{
	int BouquetNr = 0;
	std::string abnumber, tmp,yresult;
	ZapitChannelList channels;
	//int num;
	int mode = NeutrinoAPI->Zapit->getMode();

	ySplitString(para," ",abnumber, tmp);
	if(abnumber != "")
		BouquetNr = atoi(abnumber.c_str());
	if (BouquetNr > 0) {
		BouquetNr--;
#if 0
		channels = mode == CZapitClient::MODE_RADIO ? g_bouquetManager->Bouquets[BouquetNr]->radioChannels : g_bouquetManager->Bouquets[BouquetNr]->tvChannels;
		num = 1 + (mode == CZapitClient::MODE_RADIO ? g_bouquetManager->radioChannelsBegin().getNrofFirstChannelofBouquet(BouquetNr) : g_bouquetManager->tvChannelsBegin().getNrofFirstChannelofBouquet(BouquetNr)) ;
#endif
		if (mode == CZapitClient::MODE_RADIO)
			g_bouquetManager->Bouquets[BouquetNr]->getRadioChannels(channels);
		else
			g_bouquetManager->Bouquets[BouquetNr]->getTvChannels(channels);
	} else {
		CBouquetManager::ChannelIterator cit = mode == CZapitClient::MODE_RADIO ? g_bouquetManager->radioChannelsBegin() : g_bouquetManager->tvChannelsBegin();
		for (; !(cit.EndOfChannels()); cit++)
			channels.push_back(*cit);
		//num = 1;
	}
	NeutrinoAPI->GetChannelEvents();

	int i = 1;
	char classname;
	t_channel_id current_channel = CZapit::getInstance()->GetCurrentChannelID();
	int prozent = 100;
	CSectionsdClient::responseGetCurrentNextInfoChannelID currentNextInfo;
	std::string timestr;
	bool have_logos = false;

	if(hh->WebserverConfigList["Tuxbox.LogosURL"] != "")
		have_logos = true;
	for(int j = 0; j < (int) channels.size(); j++)
	{
		CZapitChannel * channel = channels[j];
		CChannelEvent *event;
		event = NeutrinoAPI->ChannelListEvents[channel->channel_id];

		classname = (i++ & 1) ? 'a' : 'b';
		if (channel->channel_id == current_channel)
			classname = 'c';

		std::string bouquetstr = (BouquetNr >= 0) ? ("&amp;bouquet=" + itoa(BouquetNr)) : "";
		yresult += "<tr>";

		if(have_logos)
			yresult += string_printf("<td class=\"%c\" width=\"44\" rowspan=\"2\"><a href=\"javascript:do_zap('"
					PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
					"')\"><img class=\"channel_logo\" src=\"%s\"/></a></td>", classname, channel->channel_id,
					(NeutrinoAPI->getLogoFile(hh->WebserverConfigList["Tuxbox.LogosURL"], channel->channel_id)).c_str());

		/* timer slider */
		if(event && event->duration > 0)
		{
			prozent = 100 * (time(NULL) - event->startTime) / event->duration;
			yresult += string_printf("<td class=\"%c\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><tr><td>\n"
					"\t<table border=\"0\" rules=\"none\" class=\"cslider cslider_table\">"
					"<tr>"
					"<td class=\"cslider cslider_used\" width=\"%d\"></td>"
					"<td class=\"cslider cslider_free\" width=\"%d\"></td>"
					"</tr>"
					"</table>\n</td>\n"
					, classname
					, (prozent / 10) * 3
					, (10 - (prozent / 10))*3
				);
		}
		else
		{
			yresult += string_printf("<td class=\"%c\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><tr><td>\n"
					"\t<table border=\"0\" rules=\"none\" class=\"cslider cslider_table\">"
					"<tr>"
					"<td class=\"cslider cslider_noepg\"></td>"
					"</tr>"
					"</table>\n</td>\n"
					, classname
				);
		}

		/* channel name and buttons */
		yresult += string_printf("<td>\n%s<a class=\"clist\" href=\"javascript:do_zap('"
				PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
				"')\">&nbsp;%d. %s%s</a>&nbsp;<a href=\"javascript:do_epg('"
				PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
				"','"
				PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
				"')\">%s</a>\n",
				((channel->channel_id == current_channel) ? "<a name=\"akt\"></a>" : " "),
				channel->channel_id,
				channel->number /* num + j */,
				channel->getName().c_str(),
				(channel->getServiceType() == ST_NVOD_REFERENCE_SERVICE) ? " (NVOD)" : "",
				channel->channel_id,
				channel->channel_id & 0xFFFFFFFFFFFFULL,
				((NeutrinoAPI->ChannelListEvents[channel->channel_id]) ? "<img src=\"/images/elist.gif\" alt=\"Program preview\" style=\"border: 0px\" />" : ""));

		if (channel->channel_id == current_channel)
			yresult += string_printf("\n&nbsp;&nbsp;<a href=\"javascript:do_streaminfo()\"><img src=\"/images/streaminfo.png\" alt=\"Streaminfo\" style=\"border: 0px\" /></a>");

		yresult += string_printf("</td></tr></table>\n</td>\n</tr>\n");

		if (channel->getServiceType() == ST_NVOD_REFERENCE_SERVICE)
		{
			CSectionsdClient::NVODTimesList nvod_list;
			if (CEitManager::getInstance()->getNVODTimesServiceKey(channel->channel_id, nvod_list))
			{
				CZapitClient::subServiceList subServiceList;

				for (CSectionsdClient::NVODTimesList::iterator ni = nvod_list.begin(); ni != nvod_list.end(); ++ni)
				{
					CZapitClient::commandAddSubServices cmd;
					CEPGData epg;

					// Byte Sequence by ntohs
					cmd.original_network_id = ntohs(ni->original_network_id);
					cmd.service_id = ntohs(ni->service_id);
					cmd.transport_stream_id = ntohs(ni->transport_stream_id);

					t_channel_id channel_id = CREATE_CHANNEL_ID(cmd.service_id, cmd.original_network_id, cmd.transport_stream_id);

					timestr = timeString(ni->zeit.startzeit); // FIXME: time is wrong (at least on little endian)!
					CEitManager::getInstance()->getActualEPGServiceKey(channel_id, &epg); // FIXME: der scheissendreck geht nit!!!
					yresult += string_printf("<tr>\n<td align=\"left\" style=\"width: 31px\" class=\"%cepg\">&nbsp;</td>", classname);
					yresult += string_printf("<td class=\"%cepg\">%s&nbsp;", classname, timestr.c_str());
					yresult += string_printf("%s<a href=\"javascript:do_zap('"
							PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
							")'\">%04x:%04x:%04x %s</a>", // FIXME: get name
							(channel_id == current_channel) ? "<a name=\"akt\"></a>" : " ",
							channel_id,
							bouquetstr.c_str(),
							cmd.transport_stream_id,
							cmd.original_network_id,
							cmd.service_id,
							epg.title.c_str());
					yresult += string_printf("</td>\n</tr>");

					subServiceList.push_back(cmd);
				}

				if (!(subServiceList.empty()))
					NeutrinoAPI->Zapit->setSubServices(subServiceList);
			}
		}

		else if ((event = NeutrinoAPI->ChannelListEvents[channel->channel_id]))
		{
			bool has_current_next = true;
			CEitManager::getInstance()->getCurrentNextServiceKey(channel->channel_id, currentNextInfo);
			timestr = timeString(event->startTime);

			yresult += string_printf("<tr><td class=\"%cepg\">",classname);
			yresult += string_printf("%s&nbsp;%s&nbsp;"
					"<span style=\"font-size: 8pt; white-space: nowrap\">(%ld von %d min, %d%%)</span>"
					, timestr.c_str()
					, event->description.c_str()
					, (time(NULL) - event->startTime)/60
					, event->duration / 60,prozent);

			if ((has_current_next) && (currentNextInfo.flags & CSectionsdClient::epgflags::has_next)) {
				timestr = timeString(currentNextInfo.next_zeit.startzeit);
				yresult += string_printf("<br />%s&nbsp;%s", timestr.c_str(), currentNextInfo.next_name.c_str());
			}

			yresult += string_printf("</td></tr>\n");
		}
		else
		yresult += string_printf("<tr style=\"height: 2px\"><td></td></tr>\n");
	}
	return yresult;
}
Esempio n. 13
0
std::string CyParser::YWeb_cgi_cmd(CyhookHandler *hh, std::string ycmd) {
	std::string ycmd_type, ycmd_name, yresult;

	if (ySplitString(ycmd, ":", ycmd_type, ycmd_name)) {
		if (ycmd_type == "L")
			yresult = CLanguage::getInstance()->getTranslation(ycmd_name);
		else if (ycmd_type == "script")
			yresult = YexecuteScript(hh, ycmd_name);
		else if (ycmd_type == "if-empty") {
			std::string if_value, if_then, if_else;
			if (ySplitString(ycmd_name, "~", if_value, if_then)) {
				ySplitString(if_then, "~", if_then, if_else);
				yresult = (if_value == "") ? if_then : if_else;
			}
		} else if (ycmd_type == "if-equal") {
			std::string if_left_value, if_right_value, if_then, if_else;
			if (ySplitString(ycmd_name, "~", if_left_value, if_right_value)) {
				if (ySplitString(if_right_value, "~", if_right_value, if_then)) {
					ySplitString(if_then, "~", if_then, if_else);
					yresult = (if_left_value == if_right_value) ? if_then
							: if_else;
				}
			}
		} else if (ycmd_type == "if-not-equal") {
			std::string if_left_value, if_right_value, if_then, if_else;
			if (ySplitString(ycmd_name, "~", if_left_value, if_right_value)) {
				if (ySplitString(if_right_value, "~", if_right_value, if_then)) {
					ySplitString(if_then, "~", if_then, if_else);
					yresult = (if_left_value != if_right_value) ? if_then
							: if_else;
				}
			}
		} else if (ycmd_type == "if-file-exists") {
			std::string if_value, if_then, if_else;
			if (ySplitString(ycmd_name, "~", if_value, if_then)) {
				ySplitString(if_then, "~", if_then, if_else);
				yresult = (access(if_value.c_str(), 4) == 0) ? if_then
						: if_else;
			}
		} else if (ycmd_type == "include") {
			std::string ytmp;
			std::fstream fin(ycmd_name.c_str(), std::fstream::in);
			if (fin.good()) {
				while (!fin.eof()) {
					getline(fin, ytmp);
					yresult += ytmp + "\n";
				}
				fin.close();
			}
		} else if (ycmd_type == "include-block") {
			std::string filename, blockname, tmp, ydefault;
			if (ySplitString(ycmd_name, ";", filename, tmp)) {
				ySplitString(tmp, ";", blockname, ydefault);
				yresult = YWeb_cgi_include_block(filename, blockname, ydefault);
			}
		} else if (ycmd_type == "func")
			yresult = this->YWeb_cgi_func(hh, ycmd_name);
		else if (ycmd_type == "ini-get") {
			std::string filename, varname, tmp, ydefault, yaccess;
			ySplitString(ycmd_name, "~", filename, yaccess);
			if (ySplitString(filename, ";", filename, tmp)) {
				ySplitString(tmp, ";", varname, ydefault);
				yresult = YWeb_cgi_get_ini(hh, filename, varname, yaccess);
				if (yresult == "" && ydefault != "")
					yresult = ydefault;
			} else
				yresult = "ycgi: ini-get: no ; found";
		} else if (ycmd_type == "ini-set") {
			std::string filename, varname, varvalue, tmp, yaccess;
			ySplitString(ycmd_name, "~", filename, yaccess);
			if (ySplitString(filename, ";", filename, tmp)) {
				if (ySplitString(tmp, ";", varname, varvalue))
					YWeb_cgi_set_ini(hh, filename, varname, varvalue, yaccess);
			} else
				yresult = "ycgi: ini-get: no ; found";
		} else if (ycmd_type == "var-get") {
			yresult = ycgi_vars[ycmd_name];
		} else if (ycmd_type == "var-set") {
			std::string varname, varvalue;
			if (ySplitString(ycmd_name, "=", varname, varvalue))
				ycgi_vars[varname] = varvalue;
		} else if (ycmd_type == "global-var-get") {
			pthread_mutex_lock(&yParser_mutex);
			yresult = ycgi_global_vars[ycmd_name];
			pthread_mutex_unlock(&yParser_mutex);
		} else if (ycmd_type == "global-var-set") {
			std::string varname, varvalue;
			if (ySplitString(ycmd_name, "=", varname, varvalue)) {
				pthread_mutex_lock(&yParser_mutex);
				ycgi_global_vars[varname] = varvalue;
				pthread_mutex_unlock(&yParser_mutex);
			}
		} else if (ycmd_type == "file-action") {
			std::string filename, actionname, content, tmp, ydefault;
			if (ySplitString(ycmd_name, ";", filename, tmp)) {
				ySplitString(tmp, ";", actionname, content);
				replace(content, "\r\n", "\n");
				if (actionname == "add") {
					std::fstream fout(filename.c_str(), std::fstream::out
							| std::fstream::binary);
					fout << content;
					fout.close();
				} else if (actionname == "append") {
					std::fstream fout(filename.c_str(), std::fstream::app
							| std::fstream::binary);
					fout << content;
					fout.close();
				} else if (actionname == "delete") {
					remove(filename.c_str());
				}
			}
		} else
			yresult = "ycgi-type unknown";
	} else if (hh->ParamList[ycmd] != "") {
		if ((hh->ParamList[ycmd]).find("script") == std::string::npos)
			yresult = hh->ParamList[ycmd];
		else
			yresult = "<!--Not Allowed script in " + ycmd + " -->";
	}

	return yresult;
}