Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added to internal http server - ability to serve any file from the <s…

…harepath>/html folder.

This functionality was requested for use in new web based setup/configuration.
  • Loading branch information...
commit 28c30ecf765ec6e1e474a887f433cc06f20465ab 1 parent c542f3f
@dblain dblain authored
View
97 mythtv/libs/libmythupnp/htmlserver.cpp
@@ -0,0 +1,97 @@
+//////////////////////////////////////////////////////////////////////////////
+// Program Name: htmlserver.cpp
+// Created : Mar. 9, 2011
+//
+// Purpose : Http server extension to serve up static html content
+//
+// Copyright (c) 2011 David Blain <dblain@mythtv.org>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or at your option any later version of the LGPL.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library. If not, see <http://www.gnu.org/licenses/>.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "mythverbose.h"
+#include "htmlserver.h"
+
+#include <QFileInfo>
+#include <QDir>
+
+/////////////////////////////////////////////////////////////////////////////
+//
+/////////////////////////////////////////////////////////////////////////////
+
+HtmlServerExtension::HtmlServerExtension( const QString sSharePath)
+ : HttpServerExtension( "Html" , sSharePath)
+{
+ // Cache the absolute path for the share directory.
+
+ QDir dir( sSharePath );
+
+ dir.makeAbsolute();
+
+ m_sAbsoluteSharePath = dir.absolutePath();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+//
+/////////////////////////////////////////////////////////////////////////////
+
+HtmlServerExtension::~HtmlServerExtension( )
+{
+}
+
+/////////////////////////////////////////////////////////////////////////////
+//
+/////////////////////////////////////////////////////////////////////////////
+
+bool HtmlServerExtension::ProcessRequest( HttpWorkerThread *, HTTPRequest *pRequest )
+{
+ if (pRequest)
+ {
+ if ( pRequest->m_sBaseUrl.startsWith("/html") == false)
+ return( false );
+
+ QFileInfo oInfo( m_sAbsoluteSharePath + pRequest->m_sResourceUrl );
+
+ if (oInfo.exists() == true )
+ {
+ oInfo.makeAbsolute();
+
+ QString sResName = oInfo.canonicalFilePath();
+
+ // --------------------------------------------------------------
+ // Checking for url's that contain ../ or similar.
+ // --------------------------------------------------------------
+
+ if ( sResName.startsWith( m_sAbsoluteSharePath, Qt::CaseInsensitive ))
+ {
+ if (oInfo.exists())
+ {
+ if (oInfo.isSymLink())
+ pRequest->FormatFileResponse( oInfo.symLinkTarget() );
+ else
+ pRequest->FormatFileResponse( sResName );
+
+ return true;
+ }
+ }
+ }
+
+ // force return as a 404...
+ pRequest->FormatFileResponse( "" );
+ }
+
+ return( true );
+}
+
View
50 mythtv/libs/libmythupnp/htmlserver.h
@@ -0,0 +1,50 @@
+//////////////////////////////////////////////////////////////////////////////
+// Program Name: htmlserver.h
+// Created : Mar. 9, 2011
+//
+// Purpose : Http server extension to serve up static html content
+//
+// Copyright (c) 2011 David Blain <dblain@mythtv.org>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or at your option any later version of the LGPL.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library. If not, see <http://www.gnu.org/licenses/>.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef __HTMLSERVER_H__
+#define __HTMLSERVER_H__
+
+#include "httpserver.h"
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+//
+// HtmlExtension Class Definition
+//
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+class UPNP_PUBLIC HtmlServerExtension : public HttpServerExtension
+{
+ private:
+
+ QString m_sAbsoluteSharePath;
+
+ public:
+ HtmlServerExtension( const QString sSharePath);
+ virtual ~HtmlServerExtension( );
+
+ bool ProcessRequest( HttpWorkerThread *pThread, HTTPRequest *pRequest );
+};
+
+#endif
View
2  mythtv/libs/libmythupnp/httprequest.cpp
@@ -1106,6 +1106,8 @@ void HTTPRequest::ProcessRequestLine( const QString &sLine )
//m_sBaseUrl = tokens[1].section( '?', 0, 0).trimmed();
m_sBaseUrl = (QUrl::fromPercentEncoding(tokens[1].toUtf8())).section( '?', 0, 0).trimmed();
+ m_sResourceUrl = m_sBaseUrl; // Save complete url without paramaters
+
// Process any Query String Parameters
//QString sQueryStr = tokens[1].section( '?', 1, 1 );
View
1  mythtv/libs/libmythupnp/httprequest.h
@@ -117,6 +117,7 @@ class UPNP_PUBLIC HTTPRequest
QString m_sRawRequest;
QString m_sBaseUrl;
+ QString m_sResourceUrl;
QString m_sMethod;
QStringMap m_mapParams;
View
8 mythtv/libs/libmythupnp/libmythupnp.pro
@@ -23,7 +23,7 @@ HEADERS += httpserver.h upnpcds.h upnpcdsobjects.h bufferedsocketdevice.h upnpms
HEADERS += eventing.h upnpcmgr.h upnptaskevent.h upnptaskcache.h ssdpcache.h
HEADERS += upnpimpl.h multicast.h broadcast.h configuration.h
HEADERS += soapclient.h mythxmlclient.h mmembuf.h upnpexp.h
-HEADERS += servicehost.h wsdl.h
+HEADERS += servicehost.h wsdl.h htmlserver.h
HEADERS += serializers/serializer.h serializers/xmlSerializer.h
HEADERS += serializers/jsonSerializer.h serializers/soapSerializer.h
@@ -33,7 +33,7 @@ SOURCES += upnpdevice.cpp upnptasknotify.cpp upnptasksearch.cpp threadpool.cpp
SOURCES += httpserver.cpp upnpcds.cpp upnpcdsobjects.cpp bufferedsocketdevice.cpp
SOURCES += eventing.cpp upnpcmgr.cpp upnpmsrr.cpp upnptaskevent.cpp ssdpcache.cpp
SOURCES += configuration.cpp soapclient.cpp mythxmlclient.cpp mmembuf.cpp
-SOURCES += multicast.cpp
+SOURCES += multicast.cpp htmlserver.cpp
SOURCES += servicehost.cpp wsdl.cpp
SOURCES += serializers/serializer.cpp serializers/xmlSerializer.cpp
@@ -59,8 +59,8 @@ inc.files += upnpdevice.h upnptasknotify.h upnptasksearch.h threadpool.h upnputi
inc.files += httpserver.h httpstatus.h upnpcds.h upnpcdsobjects.h
inc.files += eventing.h upnpcmgr.h upnptaskevent.h upnptaskcache.h ssdpcache.h
inc.files += upnpimpl.h multicast.h broadcast.h configuration.h
-inc.files += soapclient.h mythxmlclient.h mmembuf.h
-inc.files += servicehost.h wsdl.h
+inc.files += soapclient.h mythxmlclient.h mmembuf.h
+inc.files += servicehost.h wsdl.h htmlserver.h
inc.files += serializers/serializer.h serializers/xmlSerializer.h
inc.files += serializers/jsonSerializer.h serializers/soapSerializer.h
View
3  mythtv/programs/mythbackend/mediaserver.cpp
@@ -15,6 +15,7 @@
#include "upnpcdstv.h"
#include "upnpcdsmusic.h"
#include "upnpcdsvideo.h"
+#include "htmlserver.h"
#include "serviceHosts/mythServiceHost.h"
#include "serviceHosts/guideServiceHost.h"
@@ -111,6 +112,8 @@ MediaServer::MediaServer( bool bIsMaster, bool bDisableUPnp /* = FALSE */ )
m_pHttpServer->RegisterExtension( new ContentServiceHost( m_sSharePath ));
m_pHttpServer->RegisterExtension( new DvrServiceHost ( m_sSharePath ));
+ m_pHttpServer->RegisterExtension( new HtmlServerExtension( m_sSharePath ));
+
if (sIP == "localhost" || sIP.startsWith("127."))
{
VERBOSE(VB_IMPORTANT, "MediaServer:: Loopback address specified - "
Please sign in to comment.
Something went wrong with that request. Please try again.