From b779075a7b512d47c407842c760d304c5ee26dc8 Mon Sep 17 00:00:00 2001 From: David Blain Date: Wed, 9 Mar 2011 17:15:15 -0500 Subject: [PATCH] Renamed mythXml to internetContent and made into a simple HttpServerExtension (All upnp references removed. mythxml is no longer advertised in the upnp device) --- mythtv/programs/mythbackend/httpstatus.cpp | 145 ++++++- mythtv/programs/mythbackend/httpstatus.h | 12 + .../programs/mythbackend/internetContent.cpp | 220 ++++++++++ mythtv/programs/mythbackend/internetContent.h | 46 ++ mythtv/programs/mythbackend/mediaserver.cpp | 17 +- mythtv/programs/mythbackend/mythbackend.pro | 4 +- mythtv/programs/mythbackend/mythxml.cpp | 408 ------------------ mythtv/programs/mythbackend/mythxml.h | 197 --------- 8 files changed, 425 insertions(+), 624 deletions(-) create mode 100644 mythtv/programs/mythbackend/internetContent.cpp create mode 100644 mythtv/programs/mythbackend/internetContent.h delete mode 100644 mythtv/programs/mythbackend/mythxml.cpp delete mode 100644 mythtv/programs/mythbackend/mythxml.h diff --git a/mythtv/programs/mythbackend/httpstatus.cpp b/mythtv/programs/mythbackend/httpstatus.cpp index 5394082e2f3..ae3c3925817 100644 --- a/mythtv/programs/mythbackend/httpstatus.cpp +++ b/mythtv/programs/mythbackend/httpstatus.cpp @@ -23,9 +23,9 @@ // MythTV headers #include "httpstatus.h" -#include "mythxml.h" #include "mythcorecontext.h" +#include "mythversion.h" #include "decodeencode.h" #include "mythdbcon.h" #include "compat.h" @@ -38,6 +38,7 @@ #include "cardutil.h" #include "mythsystem.h" #include "exitcodes.h" +#include "jobqueue.h" ///////////////////////////////////////////////////////////////////////////// // @@ -222,7 +223,7 @@ void HttpStatus::FillStatusXML( QDomDocument *pDoc ) if (pInfo) { - MythXML::FillProgramInfo(pDoc, encoder, pInfo); + FillProgramInfo(pDoc, encoder, pInfo); delete pInfo; } @@ -258,7 +259,7 @@ void HttpStatus::FillStatusXML( QDomDocument *pDoc ) QDateTime::currentDateTime())) { iNumRecordings++; - MythXML::FillProgramInfo(pDoc, scheduled, *itProg); + FillProgramInfo(pDoc, scheduled, *itProg); } } @@ -317,7 +318,7 @@ void HttpStatus::FillStatusXML( QDomDocument *pDoc ) QDomText textNode = pDoc->createTextNode((*it).comment); job.appendChild(textNode); - MythXML::FillProgramInfo(pDoc, job, &pginfo); + FillProgramInfo(pDoc, job, &pginfo); } jobqueue.setAttribute( "count", jobs.size() ); @@ -1388,4 +1389,140 @@ int HttpStatus::PrintMiscellaneousInfo( QTextStream &os, QDomElement info ) return( 1 ); } +void HttpStatus::FillProgramInfo(QDomDocument *pDoc, + QDomNode &node, + ProgramInfo *pInfo, + bool bIncChannel /* = true */, + bool bDetails /* = true */) +{ + if ((pDoc == NULL) || (pInfo == NULL)) + return; + + // Build Program Element + + QDomElement program = pDoc->createElement( "Program" ); + node.appendChild( program ); + + program.setAttribute( "startTime" , + pInfo->GetScheduledStartTime(ISODate)); + program.setAttribute( "endTime" , pInfo->GetScheduledEndTime(ISODate)); + program.setAttribute( "title" , pInfo->GetTitle() ); + program.setAttribute( "subTitle" , pInfo->GetSubtitle()); + program.setAttribute( "category" , pInfo->GetCategory()); + program.setAttribute( "catType" , pInfo->GetCategoryType()); + program.setAttribute( "repeat" , pInfo->IsRepeat() ); + + if (bDetails) + { + + program.setAttribute( "seriesId" , pInfo->GetSeriesID() ); + program.setAttribute( "programId" , pInfo->GetProgramID() ); + program.setAttribute( "stars" , pInfo->GetStars() ); + program.setAttribute( "fileSize" , + QString::number( pInfo->GetFilesize() )); + program.setAttribute( "lastModified", + pInfo->GetLastModifiedTime(ISODate) ); + program.setAttribute( "programFlags", pInfo->GetProgramFlags() ); + program.setAttribute( "hostname" , pInfo->GetHostname() ); + + if (pInfo->GetOriginalAirDate().isValid()) + program.setAttribute( "airdate" , pInfo->GetOriginalAirDate() + .toString(Qt::ISODate) ); + + QDomText textNode = pDoc->createTextNode( pInfo->GetDescription() ); + program.appendChild( textNode ); + + } + + if ( bIncChannel ) + { + // Build Channel Child Element + + QDomElement channel = pDoc->createElement( "Channel" ); + program.appendChild( channel ); + + FillChannelInfo( channel, pInfo, bDetails ); + } + + // Build Recording Child Element + + if ( pInfo->GetRecordingStatus() != rsUnknown ) + { + QDomElement recording = pDoc->createElement( "Recording" ); + program.appendChild( recording ); + + recording.setAttribute( "recStatus" , + pInfo->GetRecordingStatus() ); + recording.setAttribute( "recPriority" , + pInfo->GetRecordingPriority() ); + recording.setAttribute( "recStartTs" , + pInfo->GetRecordingStartTime(ISODate) ); + recording.setAttribute( "recEndTs" , + pInfo->GetRecordingEndTime(ISODate) ); + + if (bDetails) + { + recording.setAttribute( "recordId" , + pInfo->GetRecordingRuleID() ); + recording.setAttribute( "recGroup" , + pInfo->GetRecordingGroup() ); + recording.setAttribute( "playGroup" , + pInfo->GetPlaybackGroup() ); + recording.setAttribute( "recType" , + pInfo->GetRecordingRuleType() ); + recording.setAttribute( "dupInType" , + pInfo->GetDuplicateCheckSource() ); + recording.setAttribute( "dupMethod" , + pInfo->GetDuplicateCheckMethod() ); + recording.setAttribute( "encoderId" , + pInfo->GetCardID() ); + const RecordingInfo ri(*pInfo); + recording.setAttribute( "recProfile" , + ri.GetProgramRecordingProfile()); + //recording.setAttribute( "preRollSeconds", m_nPreRollSeconds ); + } + } +} + +///////////////////////////////////////////////////////////////////////////// +// +///////////////////////////////////////////////////////////////////////////// + +void HttpStatus::FillChannelInfo( QDomElement &channel, + ProgramInfo *pInfo, + bool bDetails /* = true */ ) +{ + if (pInfo) + { +/* + QString sHostName = gCoreContext->GetHostName(); + QString sPort = gCoreContext->GetSettingOnHost( "BackendStatusPort", + sHostName); + QString sIconURL = QString( "http://%1:%2/getChannelIcon?ChanId=%3" ) + .arg( sHostName ) + .arg( sPort ) + .arg( pInfo->chanid ); +*/ + + channel.setAttribute( "chanId" , pInfo->GetChanID() ); + channel.setAttribute( "chanNum" , pInfo->GetChanNum()); + channel.setAttribute( "callSign" , pInfo->GetChannelSchedulingID()); + //channel.setAttribute( "iconURL" , sIconURL ); + channel.setAttribute( "channelName", pInfo->GetChannelName()); + + if (bDetails) + { + channel.setAttribute( "chanFilters", + pInfo->GetChannelPlaybackFilters() ); + channel.setAttribute( "sourceId" , pInfo->GetSourceID() ); + channel.setAttribute( "inputId" , pInfo->GetInputID() ); + channel.setAttribute( "commFree" , + (pInfo->IsCommercialFree()) ? 1 : 0 ); + } + } +} + + + + // vim:set shiftwidth=4 tabstop=4 expandtab: diff --git a/mythtv/programs/mythbackend/httpstatus.h b/mythtv/programs/mythbackend/httpstatus.h index 2c2a7c4e8b8..8f1e2c523ff 100644 --- a/mythtv/programs/mythbackend/httpstatus.h +++ b/mythtv/programs/mythbackend/httpstatus.h @@ -16,6 +16,7 @@ #include #include "httpserver.h" +#include "programinfo.h" typedef enum { @@ -66,6 +67,17 @@ class HttpStatus : public HttpServerExtension int PrintMachineInfo ( QTextStream &os, QDomElement info ); int PrintMiscellaneousInfo ( QTextStream &os, QDomElement info ); + void FillProgramInfo ( QDomDocument *pDoc, + QDomNode &node, + ProgramInfo *pInfo, + bool bIncChannel = true, + bool bDetails = true ); + + void FillChannelInfo ( QDomElement &channel, + ProgramInfo *pInfo, + bool bDetails = true ); + + public: HttpStatus( QMap *tvList, Scheduler *sched, AutoExpire *expirer, bool bIsMaster ); diff --git a/mythtv/programs/mythbackend/internetContent.cpp b/mythtv/programs/mythbackend/internetContent.cpp new file mode 100644 index 00000000000..b2a80997ab2 --- /dev/null +++ b/mythtv/programs/mythbackend/internetContent.cpp @@ -0,0 +1,220 @@ +// Program Name: internetContent.cpp +// +// Purpose - Html & XML status HttpServerExtension +// +// Created By : David Blain Created On : Oct. 24, 2005 +// Modified By : Daniel Kristjansson Modified On: Oct. 31, 2007 +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include + +#include "internetContent.h" + +#include "mythcorecontext.h" +#include "util.h" +#include "mythsystem.h" +#include "mythdirs.h" + +#include "rssparse.h" +#include "netutils.h" +#include "netgrabbermanager.h" + +///////////////////////////////////////////////////////////////////////////// +// +///////////////////////////////////////////////////////////////////////////// + +InternetContent::InternetContent( const QString &sSharePath) + : HttpServerExtension( "InternetContent", sSharePath) +{ +} + +///////////////////////////////////////////////////////////////////////////// +// +///////////////////////////////////////////////////////////////////////////// + +InternetContent::~InternetContent() +{ +} + +///////////////////////////////////////////////////////////////////////////// +// +///////////////////////////////////////////////////////////////////////////// + +bool InternetContent::ProcessRequest( HttpWorkerThread *pThread, HTTPRequest *pRequest ) +{ + try + { + if (pRequest) + { + if (pRequest->m_sBaseUrl != "/InternetContent") + return false; + + VERBOSE(VB_UPNP, QString("InternetContent::ProcessRequest: %1 : %2") + .arg(pRequest->m_sMethod) + .arg(pRequest->m_sRawRequest)); + + // -------------------------------------------------------------- + + if (pRequest->m_sMethod == "GetInternetSearch") + { + GetInternetSearch( pRequest ); + return true; + } + + // -------------------------------------------------------------- + + if (pRequest->m_sMethod == "GetInternetSources") + { + GetInternetSources( pRequest ); + return true; + } + + // -------------------------------------------------------------- + + if (pRequest->m_sMethod == "GetInternetContent") + { + GetInternetContent( pRequest ); + return true; + } + } + } + catch( ... ) + { + VERBOSE( VB_IMPORTANT, + "InternetContent::ProcessRequest() - Unexpected Exception" ); + } + + return false; +} + +// ========================================================================== +// Request handler Methods +// ========================================================================== + +///////////////////////////////////////////////////////////////////////////// +// +///////////////////////////////////////////////////////////////////////////// + +void InternetContent::GetInternetSearch( HTTPRequest *pRequest ) +{ + pRequest->m_eResponseType = ResponseTypeHTML; + + QString grabber = pRequest->m_mapParams[ "Grabber" ]; + QString query = pRequest->m_mapParams[ "Query" ]; + QString page = pRequest->m_mapParams[ "Page" ]; + + if (grabber.isEmpty() || query.isEmpty() || page.isEmpty()) + return; + + uint pagenum = page.toUInt(); + QString command = QString("%1internetcontent/%2").arg(GetShareDir()) + .arg(grabber); + + if (!QFile::exists(command)) + { + pRequest->FormatRawResponse( QString("Grabber %1 does " + "not exist!").arg(command) ); + return; + } + + VERBOSE(VB_GENERAL, QString("InternetContent::GetInternetSearch Executing " + "Command: %1 -p %2 -S '%3'").arg(command).arg(pagenum).arg(query)); + + Search *search = new Search(); + QEventLoop loop; + + QObject::connect(search, SIGNAL(finishedSearch(Search *)), + &loop, SLOT(quit(void))); + QObject::connect(search, SIGNAL(searchTimedOut(Search *)), + &loop, SLOT(quit(void))); + + search->executeSearch(command, query, pagenum); + loop.exec(); + + search->process(); + + QDomDocument ret; + ret.setContent(search->GetData()); + + delete search; + + if (ret.isNull()) + return; + + pRequest->FormatRawResponse( ret.toString() ); +} + +///////////////////////////////////////////////////////////////////////////// +// +///////////////////////////////////////////////////////////////////////////// + +void InternetContent::GetInternetSources( HTTPRequest *pRequest ) +{ + pRequest->m_eResponseType = ResponseTypeHTML; + + QString ret; + QString GrabberDir = QString("%1/internetcontent/").arg(GetShareDir()); + QDir GrabberPath(GrabberDir); + QStringList Grabbers = GrabberPath.entryList(QDir::Files | QDir::Executable); + + for (QStringList::const_iterator i = Grabbers.begin(); + i != Grabbers.end(); ++i) + { + QString commandline = GrabberDir + (*i); + MythSystem scriptcheck(commandline, QStringList("-v"), + kMSRunShell | kMSStdOut | kMSBuffered); + scriptcheck.Run(); + scriptcheck.Wait(); + QByteArray result = scriptcheck.ReadAll(); + + if (!result.isEmpty() && result.toLower().startsWith("")) + ret += result; + } + + NameValues list; + + list.push_back( NameValue( "InternetContent", ret )); + + pRequest->FormatActionResponse( list ); +} + +///////////////////////////////////////////////////////////////////////////// +// +///////////////////////////////////////////////////////////////////////////// + +void InternetContent::GetInternetContent( HTTPRequest *pRequest ) +{ + pRequest->m_eResponseType = ResponseTypeHTML; + + QString grabber = pRequest->m_mapParams[ "Grabber" ]; + + if (grabber.isEmpty()) + return; + + QString contentDir = QString("%1internetcontent/").arg(GetShareDir()); + QString htmlFile(contentDir + grabber); + + // Try to prevent directory traversal + QFileInfo fileInfo(htmlFile); + if (fileInfo.canonicalFilePath().startsWith(contentDir) && + QFile::exists( htmlFile )) + { + pRequest->m_eResponseType = ResponseTypeFile; + pRequest->m_nResponseStatus = 200; + pRequest->m_sFileName = htmlFile; + } + else + { + pRequest->FormatRawResponse( QString("File %1 does " + "not exist!").arg(htmlFile) ); + } +} + +// vim:set shiftwidth=4 tabstop=4 expandtab: diff --git a/mythtv/programs/mythbackend/internetContent.h b/mythtv/programs/mythbackend/internetContent.h new file mode 100644 index 00000000000..6d603d8d33f --- /dev/null +++ b/mythtv/programs/mythbackend/internetContent.h @@ -0,0 +1,46 @@ +////////////////////////////////////////////////////////////////////////////// +// Program Name: internetContent.h +// +// Purpose - MythTV XML protocol HttpServerExtension +// +// Created By : David Blain Created On : Oct. 24, 2005 +// Modified By : Modified On: +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef INTERNETCONTENT_H_ +#define INTERNETCONTENT_H_ + +#include +#include +#include + +#include "httpserver.h" + +#include "mythcontext.h" + +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +// +// +// +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// + +class InternetContent : public HttpServerExtension +{ + private: + + void GetInternetSearch( HTTPRequest *pRequest ); + void GetInternetSources( HTTPRequest *pRequest ); + void GetInternetContent( HTTPRequest *pRequest ); + + public: + InternetContent( const QString &sSharePath); + virtual ~InternetContent(); + + bool ProcessRequest( HttpWorkerThread *pThread, HTTPRequest *pRequest ); + +}; + +#endif diff --git a/mythtv/programs/mythbackend/mediaserver.cpp b/mythtv/programs/mythbackend/mediaserver.cpp index bcfc2283b1e..de3ff76b0a7 100644 --- a/mythtv/programs/mythbackend/mediaserver.cpp +++ b/mythtv/programs/mythbackend/mediaserver.cpp @@ -9,7 +9,7 @@ ////////////////////////////////////////////////////////////////////////////// #include "mediaserver.h" -#include "mythxml.h" +#include "internetContent.h" #include "mythdirs.h" #include "upnpcdstv.h" @@ -78,15 +78,9 @@ MediaServer::MediaServer( bool bIsMaster, bool bDisableUPnp /* = FALSE */ ) QString sDeviceType; if ( bIsMaster ) - { sFileName += "devicemaster.xml"; - sDeviceType = "urn:schemas-mythtv-org:device:MasterMediaServer:1"; - } else - { sFileName += "deviceslave.xml"; - sDeviceType = "urn:schemas-mythtv-org:device:SlaveMediaServer:1"; - } // ------------------------------------------------------------------ // Make sure our device Description is loaded. @@ -96,16 +90,13 @@ MediaServer::MediaServer( bool bIsMaster, bool bDisableUPnp /* = FALSE */ ) g_UPnpDeviceDesc.Load( sFileName ); - UPnpDevice *pMythDevice = UPnpDeviceDesc::FindDevice( RootDevice(), - sDeviceType ); - // ------------------------------------------------------------------ - // Register the MythXML protocol... + // Register Http Server Extensions... // ------------------------------------------------------------------ - VERBOSE(VB_UPNP, "MediaServer::Registering MythXML Service." ); + VERBOSE(VB_UPNP, "MediaServer::Registering Http Server Extensions." ); - m_pHttpServer->RegisterExtension( new MythXML( pMythDevice , m_sSharePath)); + m_pHttpServer->RegisterExtension( new InternetContent ( m_sSharePath )); m_pHttpServer->RegisterExtension( new MythServiceHost ( m_sSharePath )); m_pHttpServer->RegisterExtension( new GuideServiceHost ( m_sSharePath )); diff --git a/mythtv/programs/mythbackend/mythbackend.pro b/mythtv/programs/mythbackend/mythbackend.pro index 6898f550812..833ad347da1 100644 --- a/mythtv/programs/mythbackend/mythbackend.pro +++ b/mythtv/programs/mythbackend/mythbackend.pro @@ -21,7 +21,7 @@ QMAKE_CLEAN += $(TARGET) HEADERS += autoexpire.h encoderlink.h filetransfer.h httpstatus.h mainserver.h HEADERS += playbacksock.h scheduler.h server.h housekeeper.h backendutil.h HEADERS += upnpcdstv.h upnpcdsmusic.h upnpcdsvideo.h mediaserver.h -HEADERS += mythxml.h main_helpers.h backendcontext.h +HEADERS += internetContent.h main_helpers.h backendcontext.h HEADERS += serviceHosts/mythServiceHost.h serviceHosts/guideServiceHost.h HEADERS += serviceHosts/contentServiceHost.h serviceHosts/dvrServiceHost.h @@ -33,7 +33,7 @@ SOURCES += autoexpire.cpp encoderlink.cpp filetransfer.cpp httpstatus.cpp SOURCES += main.cpp mainserver.cpp playbacksock.cpp scheduler.cpp server.cpp SOURCES += housekeeper.cpp backendutil.cpp SOURCES += upnpcdstv.cpp upnpcdsmusic.cpp upnpcdsvideo.cpp mediaserver.cpp -SOURCES += mythxml.cpp main_helpers.cpp backendcontext.cpp +SOURCES += internetContent.cpp main_helpers.cpp backendcontext.cpp SOURCES += services/myth.cpp services/guide.cpp services/content.cpp SOURCES += services/dvr.cpp diff --git a/mythtv/programs/mythbackend/mythxml.cpp b/mythtv/programs/mythbackend/mythxml.cpp deleted file mode 100644 index d2d28e56301..00000000000 --- a/mythtv/programs/mythbackend/mythxml.cpp +++ /dev/null @@ -1,408 +0,0 @@ -// Program Name: MythXML.cpp -// -// Purpose - Html & XML status HttpServerExtension -// -// Created By : David Blain Created On : Oct. 24, 2005 -// Modified By : Daniel Kristjansson Modified On: Oct. 31, 2007 -// -////////////////////////////////////////////////////////////////////////////// - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "compat.h" -#include "mythxml.h" -#include "backendutil.h" - -#include "mythcorecontext.h" -#include "util.h" -#include "mythdbcon.h" -#include "mythdb.h" -#include "mythdirs.h" - -#include "previewgenerator.h" -#include "backendutil.h" -#include "mythconfig.h" -#include "programinfo.h" -#include "channelutil.h" -#include "storagegroup.h" -#include "mythsystem.h" - -#include "rssparse.h" -#include "netutils.h" -#include "netgrabbermanager.h" - -///////////////////////////////////////////////////////////////////////////// -// -///////////////////////////////////////////////////////////////////////////// - -MythXML::MythXML( UPnpDevice *pDevice , const QString &sSharePath) - : Eventing( "MythXML", "MYTHTV_Event", sSharePath), m_bIsMaster(false) -{ - m_nPreRollSeconds = gCoreContext->GetNumSetting("RecordPreRoll", 0); - - // Add any event variables... - - // --- none at this time. - - QString sUPnpDescPath = UPnp::g_pConfig->GetValue( "UPnP/DescXmlPath", - m_sSharePath ); - - m_sServiceDescFileName = sUPnpDescPath + "MXML_scpd.xml"; - m_sControlUrl = "/Myth"; - - // Add our Service Definition to the device. - - RegisterService( pDevice ); -} - -///////////////////////////////////////////////////////////////////////////// -// -///////////////////////////////////////////////////////////////////////////// - -MythXML::~MythXML() -{ -} - -///////////////////////////////////////////////////////////////////////////// -// -///////////////////////////////////////////////////////////////////////////// - -MythXMLMethod MythXML::GetMethod( const QString &sURI ) -{ - if (sURI == "GetServDesc" ) return MXML_GetServiceDescription; - - if (sURI == "GetInternetSearch" ) return MXML_GetInternetSearch; - if (sURI == "GetInternetSources" ) return MXML_GetInternetSources; - if (sURI == "GetInternetContent" ) return MXML_GetInternetContent; - - return MXML_Unknown; -} - -///////////////////////////////////////////////////////////////////////////// -// -///////////////////////////////////////////////////////////////////////////// - -bool MythXML::ProcessRequest( HttpWorkerThread *pThread, HTTPRequest *pRequest ) -{ - try - { - if (pRequest) - { - if (pRequest->m_sBaseUrl == "/Myth/GetInternetSearch") - { - pRequest->m_sBaseUrl = m_sControlUrl; - pRequest->m_sMethod = "GetInternetSearch"; - } - else if (pRequest->m_sBaseUrl == "/Myth/GetInternetSources") - { - pRequest->m_sBaseUrl = m_sControlUrl; - pRequest->m_sMethod = "GetInternetSources"; - } - - if (pRequest->m_sBaseUrl != m_sControlUrl) - return false; - - VERBOSE(VB_UPNP, QString("MythXML::ProcessRequest: %1 : %2") - .arg(pRequest->m_sMethod) - .arg(pRequest->m_sRawRequest)); - - switch( GetMethod( pRequest->m_sMethod )) - { - case MXML_GetServiceDescription: - pRequest->FormatFileResponse( m_sServiceDescFileName ); - return true; - - case MXML_GetInternetSearch : - GetInternetSearch( pRequest ); - return true; - case MXML_GetInternetSources : - GetInternetSources( pRequest ); - return true; - case MXML_GetInternetContent : - GetInternetContent( pRequest ); - return true; - - default: - { - // UPnp::FormatErrorResponse( pRequest, - // UPnPResult_InvalidAction ); - - return false; - } - } - } - } - catch( ... ) - { - VERBOSE( VB_IMPORTANT, - "MythXML::ProcessRequest() - Unexpected Exception" ); - } - - return false; -} - -// ========================================================================== -// Request handler Methods -// ========================================================================== - -///////////////////////////////////////////////////////////////////////////// -// -///////////////////////////////////////////////////////////////////////////// - -void MythXML::GetInternetSearch( HTTPRequest *pRequest ) -{ - pRequest->m_eResponseType = ResponseTypeHTML; - - QString grabber = pRequest->m_mapParams[ "Grabber" ]; - QString query = pRequest->m_mapParams[ "Query" ]; - QString page = pRequest->m_mapParams[ "Page" ]; - - if (grabber.isEmpty() || query.isEmpty() || page.isEmpty()) - return; - - uint pagenum = page.toUInt(); - QString command = QString("%1internetcontent/%2").arg(GetShareDir()) - .arg(grabber); - - if (!QFile::exists(command)) - { - pRequest->FormatRawResponse( QString("Grabber %1 does " - "not exist!").arg(command) ); - return; - } - - VERBOSE(VB_GENERAL, QString("MythXML::GetInternetSearch Executing " - "Command: %1 -p %2 -S '%3'").arg(command).arg(pagenum).arg(query)); - - Search *search = new Search(); - QEventLoop loop; - - QObject::connect(search, SIGNAL(finishedSearch(Search *)), - &loop, SLOT(quit(void))); - QObject::connect(search, SIGNAL(searchTimedOut(Search *)), - &loop, SLOT(quit(void))); - - search->executeSearch(command, query, pagenum); - loop.exec(); - - search->process(); - - QDomDocument ret; - ret.setContent(search->GetData()); - - delete search; - - if (ret.isNull()) - return; - - pRequest->FormatRawResponse( ret.toString() ); -} - -void MythXML::GetInternetSources( HTTPRequest *pRequest ) -{ - pRequest->m_eResponseType = ResponseTypeHTML; - - QString ret; - QString GrabberDir = QString("%1/internetcontent/").arg(GetShareDir()); - QDir GrabberPath(GrabberDir); - QStringList Grabbers = GrabberPath.entryList(QDir::Files | QDir::Executable); - - for (QStringList::const_iterator i = Grabbers.begin(); - i != Grabbers.end(); ++i) - { - QString commandline = GrabberDir + (*i); - MythSystem scriptcheck(commandline, QStringList("-v"), - kMSRunShell | kMSStdOut | kMSBuffered); - scriptcheck.Run(); - scriptcheck.Wait(); - QByteArray result = scriptcheck.ReadAll(); - - if (!result.isEmpty() && result.toLower().startsWith("")) - ret += result; - } - - NameValues list; - - list.push_back( NameValue( "InternetContent", ret )); - - pRequest->FormatActionResponse( list ); -} - -void MythXML::GetInternetContent( HTTPRequest *pRequest ) -{ - pRequest->m_eResponseType = ResponseTypeHTML; - - QString grabber = pRequest->m_mapParams[ "Grabber" ]; - - if (grabber.isEmpty()) - return; - - QString contentDir = QString("%1internetcontent/").arg(GetShareDir()); - QString htmlFile(contentDir + grabber); - - // Try to prevent directory traversal - QFileInfo fileInfo(htmlFile); - if (fileInfo.canonicalFilePath().startsWith(contentDir) && - QFile::exists( htmlFile )) - { - pRequest->m_eResponseType = ResponseTypeFile; - pRequest->m_nResponseStatus = 200; - pRequest->m_sFileName = htmlFile; - } - else - { - pRequest->FormatRawResponse( QString("File %1 does " - "not exist!").arg(htmlFile) ); - } -} - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -// -// Static Methods -// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -void MythXML::FillProgramInfo(QDomDocument *pDoc, - QDomNode &node, - ProgramInfo *pInfo, - bool bIncChannel /* = true */, - bool bDetails /* = true */) -{ - if ((pDoc == NULL) || (pInfo == NULL)) - return; - - // Build Program Element - - QDomElement program = pDoc->createElement( "Program" ); - node.appendChild( program ); - - program.setAttribute( "startTime" , - pInfo->GetScheduledStartTime(ISODate)); - program.setAttribute( "endTime" , pInfo->GetScheduledEndTime(ISODate)); - program.setAttribute( "title" , pInfo->GetTitle() ); - program.setAttribute( "subTitle" , pInfo->GetSubtitle()); - program.setAttribute( "category" , pInfo->GetCategory()); - program.setAttribute( "catType" , pInfo->GetCategoryType()); - program.setAttribute( "repeat" , pInfo->IsRepeat() ); - - if (bDetails) - { - - program.setAttribute( "seriesId" , pInfo->GetSeriesID() ); - program.setAttribute( "programId" , pInfo->GetProgramID() ); - program.setAttribute( "stars" , pInfo->GetStars() ); - program.setAttribute( "fileSize" , - QString::number( pInfo->GetFilesize() )); - program.setAttribute( "lastModified", - pInfo->GetLastModifiedTime(ISODate) ); - program.setAttribute( "programFlags", pInfo->GetProgramFlags() ); - program.setAttribute( "hostname" , pInfo->GetHostname() ); - - if (pInfo->GetOriginalAirDate().isValid()) - program.setAttribute( "airdate" , pInfo->GetOriginalAirDate() - .toString(Qt::ISODate) ); - - QDomText textNode = pDoc->createTextNode( pInfo->GetDescription() ); - program.appendChild( textNode ); - - } - - if ( bIncChannel ) - { - // Build Channel Child Element - - QDomElement channel = pDoc->createElement( "Channel" ); - program.appendChild( channel ); - - FillChannelInfo( channel, pInfo, bDetails ); - } - - // Build Recording Child Element - - if ( pInfo->GetRecordingStatus() != rsUnknown ) - { - QDomElement recording = pDoc->createElement( "Recording" ); - program.appendChild( recording ); - - recording.setAttribute( "recStatus" , - pInfo->GetRecordingStatus() ); - recording.setAttribute( "recPriority" , - pInfo->GetRecordingPriority() ); - recording.setAttribute( "recStartTs" , - pInfo->GetRecordingStartTime(ISODate) ); - recording.setAttribute( "recEndTs" , - pInfo->GetRecordingEndTime(ISODate) ); - - if (bDetails) - { - recording.setAttribute( "recordId" , - pInfo->GetRecordingRuleID() ); - recording.setAttribute( "recGroup" , - pInfo->GetRecordingGroup() ); - recording.setAttribute( "playGroup" , - pInfo->GetPlaybackGroup() ); - recording.setAttribute( "recType" , - pInfo->GetRecordingRuleType() ); - recording.setAttribute( "dupInType" , - pInfo->GetDuplicateCheckSource() ); - recording.setAttribute( "dupMethod" , - pInfo->GetDuplicateCheckMethod() ); - recording.setAttribute( "encoderId" , - pInfo->GetCardID() ); - const RecordingInfo ri(*pInfo); - recording.setAttribute( "recProfile" , - ri.GetProgramRecordingProfile()); - //recording.setAttribute( "preRollSeconds", m_nPreRollSeconds ); - } - } -} - -///////////////////////////////////////////////////////////////////////////// -// -///////////////////////////////////////////////////////////////////////////// - -void MythXML::FillChannelInfo( QDomElement &channel, - ProgramInfo *pInfo, - bool bDetails /* = true */ ) -{ - if (pInfo) - { -/* - QString sHostName = gCoreContext->GetHostName(); - QString sPort = gCoreContext->GetSettingOnHost( "BackendStatusPort", - sHostName); - QString sIconURL = QString( "http://%1:%2/getChannelIcon?ChanId=%3" ) - .arg( sHostName ) - .arg( sPort ) - .arg( pInfo->chanid ); -*/ - - channel.setAttribute( "chanId" , pInfo->GetChanID() ); - channel.setAttribute( "chanNum" , pInfo->GetChanNum()); - channel.setAttribute( "callSign" , pInfo->GetChannelSchedulingID()); - //channel.setAttribute( "iconURL" , sIconURL ); - channel.setAttribute( "channelName", pInfo->GetChannelName()); - - if (bDetails) - { - channel.setAttribute( "chanFilters", - pInfo->GetChannelPlaybackFilters() ); - channel.setAttribute( "sourceId" , pInfo->GetSourceID() ); - channel.setAttribute( "inputId" , pInfo->GetInputID() ); - channel.setAttribute( "commFree" , - (pInfo->IsCommercialFree()) ? 1 : 0 ); - } - } -} - -// vim:set shiftwidth=4 tabstop=4 expandtab: diff --git a/mythtv/programs/mythbackend/mythxml.h b/mythtv/programs/mythbackend/mythxml.h deleted file mode 100644 index 5e575162ef1..00000000000 --- a/mythtv/programs/mythbackend/mythxml.h +++ /dev/null @@ -1,197 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// Program Name: mythxml.h -// -// Purpose - MythTV XML protocol HttpServerExtension -// -// Created By : David Blain Created On : Oct. 24, 2005 -// Modified By : Modified On: -// -////////////////////////////////////////////////////////////////////////////// - -#ifndef MYTHXML_H_ -#define MYTHXML_H_ - -#include -#include -#include - -#include "upnp.h" -#include "eventing.h" - -#include "autoexpire.h" -#include "mythcontext.h" -#include "jobqueue.h" -#include "recordinginfo.h" -#include "scheduler.h" - -extern AutoExpire *expirer; -extern Scheduler *sched; - -typedef enum -{ - MXML_Unknown = 0, - MXML_GetServiceDescription = 1, - - MXML_GetInternetSearch = 18, - MXML_GetInternetSources = 19, - MXML_GetInternetContent = 20, - -} MythXMLMethod; - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -// -// -// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -class MythXML : public Eventing -{ - private: - - QString m_sControlUrl; - QString m_sServiceDescFileName; - - bool m_bIsMaster; - int m_nPreRollSeconds; - - protected: - - // Implement UPnpServiceImpl methods that we can - - virtual QString GetServiceType () { return "urn:schemas-mythtv-org:service:MythTv:1"; } - virtual QString GetServiceId () { return "urn:mythtv-org:serviceId:MYTHTV_1-0"; } - virtual QString GetServiceControlURL() { return m_sControlUrl.mid( 1 ); } - virtual QString GetServiceDescURL () { return m_sControlUrl.mid( 1 ) + "/GetServDesc"; } - - private: - - MythXMLMethod GetMethod( const QString &sURI ); - - void GetInternetSearch( HTTPRequest *pRequest ); - void GetInternetSources( HTTPRequest *pRequest ); - void GetInternetContent( HTTPRequest *pRequest ); - - void GetDeviceDesc ( HTTPRequest *pRequest ); - - public: - MythXML( UPnpDevice *pDevice , const QString &sSharePath); - virtual ~MythXML(); - - bool ProcessRequest( HttpWorkerThread *pThread, HTTPRequest *pRequest ); - - // Static methods shared with HttpStatus - - static void FillProgramInfo ( QDomDocument *pDoc, - QDomNode &node, - ProgramInfo *pInfo, - bool bIncChannel = true, - bool bDetails = true ); - - static void FillChannelInfo ( QDomElement &channel, - ProgramInfo *pInfo, - bool bDetails = true ); - -}; - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -// -// -// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -class ThreadData : public HttpWorkerData -{ - public: - - typedef enum - { - DT_Unknown = 0, - DT_File = 1, - DT_Recording = 2, - DT_Music = 3, - DT_Video = 4 - - - } ThreadDataType; - - - ThreadDataType m_eType; - - QString m_sStorageGroup; - QString m_sChanId; - QString m_sStartTime; - QString m_sBaseFileName; - QString m_sFileName; - QString m_sVideoID; - - int m_nTrackNumber; - - public: - - ThreadData( ThreadDataType eType ) - { - m_nTrackNumber = 0; - m_eType = eType; - } - - ThreadData( long nTrackNumber, const QString &sFileName ) - { - m_eType = DT_Music; - m_nTrackNumber = nTrackNumber; - m_sFileName = sFileName; - } - - ThreadData( const QString &sChanId, - const QString &sStartTime, - const QString &sFileName ) - { - m_eType = DT_Recording; - m_sChanId = sChanId; - m_sStartTime = sStartTime; - m_sFileName = sFileName; - m_nTrackNumber = 0; - } - - ThreadData( const QString &sVideoID, - const QString &sFileName ) - { - m_eType = DT_Video; - m_sVideoID = sVideoID; - m_sFileName = sFileName; - m_nTrackNumber = 0; - } - - - virtual ~ThreadData() - { - } - - void SetFileData( const QString &sStorageGroup, - const QString &sStorageGroupFile, - const QString &sFileName ) - { - m_sStorageGroup = sStorageGroup; - m_sBaseFileName = sStorageGroupFile; - m_sFileName = sFileName; - } - - bool IsSameFile( const QString &sStorageGroup, - const QString &sFileName ) - { - return( (sStorageGroup == m_sStorageGroup) && - (sFileName == m_sFileName) ); - } - - bool IsSameRecording( const QString &sChanId, - const QString &sStartTime ) - { - return( (sChanId == m_sChanId ) && (sStartTime == m_sStartTime )); - } -}; - - -#endif