servicemp3/record: unambiguous usage of User-Agent header
authormx3L <mx3ldev@gmail.com>
Thu, 3 Dec 2015 17:23:28 +0000 (18:23 +0100)
committermx3L <mx3ldev@gmail.com>
Fri, 4 Dec 2015 07:37:54 +0000 (08:37 +0100)
user-agent header could be currently set either by
config entry or by passing it in service reference
path string as an extra header.

Problem is that if we set it in service reference path
string, it's not working and user-agent is still
set from config entry or default value is used.

To avoid confusion of which option to use and to
allow to set different user-agent header for every
service, we allow to set it only in service
reference path string

http://forums.openpli.org/topic/39602-servicemp3-and-custom-user-agent-header/?view=findpost&p=517256

lib/service/servicemp3.cpp
lib/service/servicemp3record.cpp

index f6729ab..35d8b0f 100644 (file)
@@ -420,6 +420,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
        m_use_chapter_entries = false; /* TOC chapter support CVR */
        m_last_seek_pos = 0; /* CVR last seek position */
 #endif
+       m_useragent = "Enigma2 Mediaplayer";
        m_extra_headers = "";
        m_download_buffer_path = "";
        m_prev_decoder_time = -1;
@@ -443,6 +444,17 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
                filename_str = m_ref.path.substr(0, pos);
                filename = filename_str.c_str();
                m_extra_headers = m_ref.path.substr(pos + 1);
+
+               pos = m_extra_headers.find("User-Agent=");
+               if (pos != std::string::npos)
+               {
+                       size_t hpos_start = pos + 11;
+                       size_t hpos_end = m_extra_headers.find('&', hpos_start);
+                       if (hpos_end != std::string::npos)
+                               m_useragent = m_extra_headers.substr(hpos_start, hpos_end - hpos_start);
+                       else
+                               m_useragent = m_extra_headers.substr(hpos_start);
+               }
        }
        else
                filename = m_ref.path.c_str();
@@ -517,12 +529,6 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
                CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
 
                std::string config_str;
-               if (eConfigManager::getConfigBoolValue("config.mediaplayer.useAlternateUserAgent"))
-               {
-                       m_useragent = eConfigManager::getConfigValue("config.mediaplayer.alternateUserAgent");
-               }
-               if (m_useragent.empty())
-                       m_useragent = "Enigma2 Mediaplayer";
                if ( m_ref.getData(7) & BUFFERING_ENABLED )
                {
                        m_use_prefillbuffer = true;
index 1548ed4..01a1316 100644 (file)
@@ -22,18 +22,13 @@ eServiceMP3Record::eServiceMP3Record(const eServiceReference &ref):
        m_error = 0;
        m_simulate = false;
        m_recording_pipeline = 0;
+       m_useragent = "Enigma2 Mediaplayer";
        m_extra_headers = "";
 
        CONNECT(m_pump.recv_msg, eServiceMP3Record::gstPoll);
        CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3Record::sourceTimeout);
 
        std::string config_str;
-       if (eConfigManager::getConfigBoolValue("config.mediaplayer.useAlternateUserAgent"))
-       {
-               m_useragent = eConfigManager::getConfigValue("config.mediaplayer.alternateUserAgent");
-       }
-       if (m_useragent.empty())
-               m_useragent = "Enigma2 Mediaplayer";
 }
 
 eServiceMP3Record::~eServiceMP3Record()
@@ -142,6 +137,18 @@ int eServiceMP3Record::doPrepare()
                {
                        stream_uri = m_ref.path.substr(0, pos);
                        m_extra_headers = m_ref.path.substr(pos + 1);
+
+                       pos = m_extra_headers.find("User-Agent=");
+                       if (pos != std::string::npos)
+                       {
+                               size_t hpos_start = pos + 11;
+                               size_t hpos_end = m_extra_headers.find('&', hpos_start);
+                               if (hpos_end != std::string::npos)
+                                       m_useragent = m_extra_headers.substr(hpos_start, hpos_end - hpos_start);
+                               else
+                                       m_useragent = m_extra_headers.substr(hpos_start);
+                       }
+
                }
                else
                {