From e1766a1d404884247df96d4f631245bdc2d3d74a Mon Sep 17 00:00:00 2001 From: thlo Date: Sun, 27 Jan 2013 18:37:51 +0100 Subject: epg.xml fixes --- vdr-smarttvweb/httpresource.c | 102 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 12 deletions(-) (limited to 'vdr-smarttvweb') 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 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 += "\n"; hdr += "\n"; @@ -1572,19 +1609,57 @@ int cHttpResource::sendEpgXml (struct stat *statbuf) { *mResponseMessage += hdr; // Payload here - - string title = cUrlEncode::doXmlSaveEncode(ev->Title()); - hdr = "" + title +"\n"; + + hdr = ""; + if (ev->Title() != NULL) { + string title = cUrlEncode::doXmlSaveEncode(ev->Title()); + hdr += "" + title +"\n"; + } + else { + *(mLog->log())<< DEBUGPREFIX + << " ERROR: title is zero for guid= " << id << endl; + hdr += "Empty\n"; + + delete mResponseMessage; + sendError(500, "Internal Server Error", NULL, "Title is zero."); + return OKAY; + } + hdr += "" + id + "\n"; - hdr += ""; - hdr += cUrlEncode::doXmlSaveEncode(ev->Description()); - hdr += "\n"; + *(mLog->log())<< DEBUGPREFIX + << " guid= " << id + << " title= " << ev->Title() + << " start= " << ev->StartTime() + << " end= " << ev->EndTime() + << " now= " << now + << endl; + if (add_desc) { + hdr += ""; + 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 += "\n"; + } + else { + hdr += "No Description Available\n"; + } snprintf(f, sizeof(f), "%ld\n", ev->StartTime()); hdr += f ; snprintf(f, sizeof(f), "%ld\n", ev->EndTime()); hdr += f; + + snprintf(f, sizeof(f), "%d\n", ev->Duration()); + hdr += f; *mResponseMessage += hdr; hdr = "\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; -- cgit v1.2.3