summaryrefslogtreecommitdiff
path: root/vdr-smarttvweb
diff options
context:
space:
mode:
authorthlo <t.lohmar@gmx.de>2013-01-27 18:37:51 +0100
committerthlo <t.lohmar@gmx.de>2013-01-27 18:37:51 +0100
commite1766a1d404884247df96d4f631245bdc2d3d74a (patch)
treee68f130c5accd1207be69a0ded74560803efcbd5 /vdr-smarttvweb
parente269ce07fde2ca3e52568e80d8309da5d6945817 (diff)
downloadvdr-plugin-smarttvweb-e1766a1d404884247df96d4f631245bdc2d3d74a.tar.gz
vdr-plugin-smarttvweb-e1766a1d404884247df96d4f631245bdc2d3d74a.tar.bz2
epg.xml fixes
Diffstat (limited to 'vdr-smarttvweb')
-rwxr-xr-xvdr-smarttvweb/httpresource.c102
1 files changed, 90 insertions, 12 deletions
diff --git a/vdr-smarttvweb/httpresource.c b/vdr-smarttvweb/httpresource.c
index afdfbbf..07c1030 100755
--- a/vdr-smarttvweb/httpresource.c
+++ b/vdr-smarttvweb/httpresource.c
@@ -1527,14 +1527,26 @@ int cHttpResource::sendEpgXml (struct stat *statbuf) {
vector<sQueryAVP> avps;
parseQueryLine(&avps);
string id = "S19.2E-1-1107-17500";
+ string mode = "";
+ bool add_desc = true;
+
if (getQueryAttributeValue(&avps, "id", id) == ERROR){
*(mLog->log())<< DEBUGPREFIX
<< " ERROR: id not found"
<< DEBUGHDR << endl;
+ delete mResponseMessage;
sendError(400, "Bad Request", NULL, "no id in query line");
return OKAY;
}
+ if (getQueryAttributeValue(&avps, "mode", mode) == OKAY){
+ if (mode == "nodesc") {
+ add_desc = false;
+ *(mLog->log())<< DEBUGPREFIX
+ << " **** Mode: No Description ****"
+ << endl;
+ }
+ }
/* for (int i = 0; i < avps.size(); i++) {
if (avps[i].attribute == "id")
@@ -1550,21 +1562,46 @@ int cHttpResource::sendEpgXml (struct stat *statbuf) {
*(mLog->log())<< DEBUGPREFIX
<< " ERROR: Not possible to get the ChannelId from the string"
<< DEBUGHDR << endl;
- // ERROR
- // FIXME: Should send a proper error code
- return ERROR;
+ delete mResponseMessage;
+ sendError(400, "Bad Request", NULL, "Invalid Channel ID.");
+ return OKAY;
}
cSchedulesLock * lock = new cSchedulesLock(false, 500);
const cSchedules *schedules = cSchedules::Schedules(*lock);
const cSchedule *schedule = schedules->GetSchedule(chan_id);
- const cEvent * ev = schedule->GetPresentEvent();
+ if (schedule == NULL) {
+ *(mLog->log())<< DEBUGPREFIX
+ << "ERROR: Schedule is zero for guid= " << id
+ << endl;
+ delete mResponseMessage;
+ sendError(500, "Internal Server Error", NULL, "Schedule is zero.");
+ return OKAY;
+ }
- delete lock;
+ time_t now = time(NULL);
+ const cEvent *ev = NULL;
+ for(cEvent* e = schedule->Events()->First(); e; e = schedule->Events()->Next(e)) {
+ if ( (e->StartTime() <= now) && (e->EndTime() > now)) {
+ ev = e;
+
+ } else if (e->StartTime() > now + 3600) {
+ break;
+ }
+ }
- sendHeaders(200, "OK", NULL, "application/xml", -1, statbuf->st_mtime);
+ // const cEvent * ev = schedule->GetPresentEvent();
+ if (ev == NULL) {
+ *(mLog->log())<< DEBUGPREFIX
+ << "ERROR: Event is zero for guid= " << id
+ << endl;
+ delete mResponseMessage;
+ sendError(500, "Internal Server Error", NULL, "Event is zero.");
+ return OKAY;
+ }
+
string hdr = "";
hdr += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
hdr += "<tv version=\"2.0\">\n";
@@ -1572,19 +1609,57 @@ int cHttpResource::sendEpgXml (struct stat *statbuf) {
*mResponseMessage += hdr;
// Payload here
-
- string title = cUrlEncode::doXmlSaveEncode(ev->Title());
- hdr = "<title>" + title +"</title>\n";
+
+ hdr = "";
+ if (ev->Title() != NULL) {
+ string title = cUrlEncode::doXmlSaveEncode(ev->Title());
+ hdr += "<title>" + title +"</title>\n";
+ }
+ else {
+ *(mLog->log())<< DEBUGPREFIX
+ << " ERROR: title is zero for guid= " << id << endl;
+ hdr += "<title>Empty</title>\n";
+
+ delete mResponseMessage;
+ sendError(500, "Internal Server Error", NULL, "Title is zero.");
+ return OKAY;
+ }
+
hdr += "<guid>" + id + "</guid>\n";
- hdr += "<desc>";
- hdr += cUrlEncode::doXmlSaveEncode(ev->Description());
- hdr += "</desc>\n";
+ *(mLog->log())<< DEBUGPREFIX
+ << " guid= " << id
+ << " title= " << ev->Title()
+ << " start= " << ev->StartTime()
+ << " end= " << ev->EndTime()
+ << " now= " << now
+ << endl;
+ if (add_desc) {
+ hdr += "<desc>";
+ if (ev->Description() != NULL) {
+ hdr += cUrlEncode::doXmlSaveEncode(ev->Description());
+ }
+ else {
+ *(mLog->log())<< DEBUGPREFIX
+ << " ERROR: description is zero for guid= " << id << endl;
+
+ delete mResponseMessage;
+ sendError(500, "Internal Server Error", NULL, "Description is zero.");
+ return OKAY;
+ }
+ hdr += "</desc>\n";
+ }
+ else {
+ hdr += "<desc>No Description Available</desc>\n";
+ }
snprintf(f, sizeof(f), "<start>%ld</start>\n", ev->StartTime());
hdr += f ;
snprintf(f, sizeof(f), "<end>%ld</end>\n", ev->EndTime());
hdr += f;
+
+ snprintf(f, sizeof(f), "<duration>%d</duration>\n", ev->Duration());
+ hdr += f;
*mResponseMessage += hdr;
hdr = "</programme>\n";
@@ -1592,6 +1667,9 @@ int cHttpResource::sendEpgXml (struct stat *statbuf) {
*mResponseMessage += hdr;
+ delete lock;
+
+ sendHeaders(200, "OK", NULL, "application/xml", mResponseMessage->size(), -1);
#endif
return OKAY;