servicemp3record: set http headers via service reference path string
authorbetacentauri <betacentauri@arcor.de>
Mon, 23 Nov 2015 10:25:47 +0000 (11:25 +0100)
committerErik Slagter <erik@openpli.org>
Tue, 24 Nov 2015 14:22:46 +0000 (15:22 +0100)
To be able to set http headers for every service, we allow
passing http headers in service reference path string:

http%3a//www.path.mp4#h1=v1&h2=v2:sname
h1,h2 are header names and v1,v2 are corresponding header values

Example of bouquet entry with http headers:
SERVICE 4097:0:0:0:0:0:0:0:0:0:http%3a//www.path.mp4#h1=v1&h2=v2:sname

(cherry picked from commit 217baf9d8f82d4b1662a5fe66c4219358c6d462f)
Signed-off-by: Erik Slagter <erik@openpli.org>

lib/service/servicemp3record.cpp

index 1bdd6cf..1548ed4 100644 (file)
@@ -22,6 +22,7 @@ eServiceMP3Record::eServiceMP3Record(const eServiceReference &ref):
        m_error = 0;
        m_simulate = false;
        m_recording_pipeline = 0;
+       m_extra_headers = "";
 
        CONNECT(m_pump.recv_msg, eServiceMP3Record::gstPoll);
        CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3Record::sourceTimeout);
@@ -33,7 +34,6 @@ eServiceMP3Record::eServiceMP3Record(const eServiceReference &ref):
        }
        if (m_useragent.empty())
                m_useragent = "Enigma2 Mediaplayer";
-       m_extra_headers = eConfigManager::getConfigValue("config.mediaplayer.extraHeaders");
 }
 
 eServiceMP3Record::~eServiceMP3Record()
@@ -136,8 +136,19 @@ int eServiceMP3Record::doPrepare()
        if (m_state == stateIdle)
        {
                gchar *uri;
-               eDebug("[eMP3ServiceRecord] doPrepare uri=%s", m_ref.path.c_str());
-               uri = g_strdup_printf ("%s", m_ref.path.c_str());
+               size_t pos = m_ref.path.find('#');
+               std::string stream_uri;
+               if (pos != std::string::npos && m_ref.path.compare(0, 4, "http") == 0)
+               {
+                       stream_uri = m_ref.path.substr(0, pos);
+                       m_extra_headers = m_ref.path.substr(pos + 1);
+               }
+               else
+               {
+                       stream_uri = m_ref.path;
+               }
+               eDebug("[eMP3ServiceRecord] doPrepare uri=%s", stream_uri.c_str());
+               uri = g_strdup_printf ("%s", stream_uri.c_str());
 
                m_recording_pipeline = gst_pipeline_new ("recording-pipeline");
                m_source = gst_element_factory_make("uridecodebin", "uridec");
@@ -399,7 +410,7 @@ void eServiceMP3Record::handleUridecNotifySource(GObject *object, GParamSpec *un
                                std::string name, value;
                                size_t start = pos;
                                size_t len = std::string::npos;
-                               pos = _this->m_extra_headers.find(':', pos);
+                               pos = _this->m_extra_headers.find('=', pos);
                                if (pos != std::string::npos)
                                {
                                        len = pos - start;
@@ -407,7 +418,7 @@ void eServiceMP3Record::handleUridecNotifySource(GObject *object, GParamSpec *un
                                        name = _this->m_extra_headers.substr(start, len);
                                        start = pos;
                                        len = std::string::npos;
-                                       pos = _this->m_extra_headers.find('|', pos);
+                                       pos = _this->m_extra_headers.find('&', pos);
                                        if (pos != std::string::npos)
                                        {
                                                len = pos - start;