Project

General

Profile

Feature #545 » streamdev-rss.diff

schmirl, 05/03/2011 05:14 PM

View differences:

server/connectionHTTP.c
}
if (iterator) {
// assemble base url: http://host/path/
std::string base;
tStrStrMap::const_iterator it = Headers().find(HOST);
if (it != Headers().end())
base = "http://" + it->second + "/";
else
base = (std::string) "http://" + LocalIp() + ":" +
(const char*) itoa(StreamdevServerSetup.HTTPServerPort) + "/";
base += Path;
if (Filebase.empty() || Fileext.compare(".htm") == 0 || Fileext.compare(".html") == 0) {
std::string self = Filebase + Fileext;
if (!query.empty())
std::string rss = Filebase + ".rss";
if (!query.empty()) {
self += '?' + query;
return new cHtmlChannelList(iterator, m_StreamType, self.c_str(), groupTarget.c_str());
rss += '?' + query;
}
return new cHtmlChannelList(iterator, m_StreamType, self.c_str(), rss.c_str(), groupTarget.c_str());
} else if (Fileext.compare(".m3u") == 0) {
std::string base;
tStrStrMap::const_iterator it = Headers().find(HOST);
if (it != Headers().end())
base = "http://" + it->second + "/";
else
base = (std::string) "http://" + LocalIp() + ":" +
(const char*) itoa(StreamdevServerSetup.HTTPServerPort) + "/";
base += Path;
return new cM3uChannelList(iterator, base.c_str());
} else if (Fileext.compare(".rss") == 0) {
std::string html = Filebase + ".html";
if (!query.empty())
html += '?' + query;
return new cRssChannelList(iterator, base.c_str(), html.c_str());
} else {
delete iterator;
}
server/menuHTTP.c
return typeMenu;
}
cHtmlChannelList::cHtmlChannelList(cChannelIterator *Iterator, eStreamType StreamType, const char *Self, const char *GroupTarget): cChannelList(Iterator)
cHtmlChannelList::cHtmlChannelList(cChannelIterator *Iterator, eStreamType StreamType, const char *Self, const char *Rss, const char *GroupTarget): cChannelList(Iterator)
{
streamType = StreamType;
self = strdup(Self);
rss = strdup(Rss);
groupTarget = (GroupTarget && *GroupTarget) ? strdup(GroupTarget) : NULL;
htmlState = hsRoot;
current = NULL;
......
cHtmlChannelList::~cHtmlChannelList()
{
free((void *) self);
free((void *) rss);
free((void *) groupTarget);
}
......
std::string cHtmlChannelList::HtmlHead()
{
return (std::string) "";
return (std::string) "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"" + rss + "\"/>";
}
std::string cHtmlChannelList::PageTop()
......
}
}
// ******************** cRssChannelList ******************
cRssChannelList::cRssChannelList(cChannelIterator *Iterator, const char *Base, const char *Html)
: cChannelList(Iterator),
m_IConv(cCharSetConv::SystemCharacterTable(), "UTF-8")
{
base = strdup(Base);
html = strdup(Html);
rssState = msFirst;
}
cRssChannelList::~cRssChannelList()
{
free(base);
free(html);
}
bool cRssChannelList::HasNext()
{
return rssState != msLast;
}
std::string cRssChannelList::Next()
{
std::string type_ext;
if (rssState == msFirst)
{
rssState = msContinue;
return (std::string) "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rss version=\"2.0\">\n\t<channel>\n"
"\t\t<title>VDR</title>\n"
"\t\t<link>" + base + html + "</link>\n"
"\t\t<description>VDR channel list</description>\n"
;
}
const cChannel *channel = NextChannel();
if (!channel)
{
rssState = msLast;
return "\t</channel>\n</rss>\n";
}
std::string name = (std::string) m_IConv.Convert(channel->Name());
if (channel->GroupSep())
{
return (std::string) "\t\t<item>\n\t\t<title>" +
name + "</title>\n\t\t<link>" +
base + "group.rss?group=" + (const char*) itoa(cChannelList::GetGroupIndex(channel)) + "</link>\n\t\t</item>\n";
}
else
{
return (std::string) "\t\t<item>\n\t\t<title>" +
(const char*) itoa(channel->Number()) + " " + name + "</title>\n\t\t<link>" +
base + (std::string) channel->GetChannelID().ToString() + "</link>\n\t\t</item>\n";
}
}
server/menuHTTP.h
const cChannel *current;
eStreamType streamType;
const char* self;
const char* rss;
const char* groupTarget;
std::string StreamTypeMenu();
......
}
virtual bool HasNext();
virtual std::string Next();
cHtmlChannelList(cChannelIterator *Iterator, eStreamType StreamType, const char *Self, const char *GroupTarget);
cHtmlChannelList(cChannelIterator *Iterator, eStreamType StreamType, const char *Self, const char *Rss, const char *GroupTarget);
virtual ~cHtmlChannelList();
};
......
virtual ~cM3uChannelList();
};
class cRssChannelList: public cChannelList
{
private:
char *base;
char *html;
enum eRssState { msFirst, msContinue, msLast };
eRssState rssState;
cCharSetConv m_IConv;
public:
virtual std::string HttpHeader() { return cChannelList::HttpHeader() + "Content-type: application/rss+xml\r\n"; };
virtual bool HasNext();
virtual std::string Next();
cRssChannelList(cChannelIterator *Iterator, const char *Base, const char *Html);
virtual ~cRssChannelList();
};
inline const cChannel* cChannelIterator::SkipFakeGroups(const cChannel* Group)
{
while (Group && Group->GroupSep() && !*Group->Name())
(5-5/5)