re-add lost signal connection of HTTP-Source agent setter
[enigma2.git] / lib / service / service.cpp
index 8ac7ebd41495c8e800fe0575fd73c68faa075de7..8c674c5e2daeaf883cbab2fe0d55a73dd65dfd5c 100644 (file)
@@ -4,7 +4,52 @@
 #include <lib/service/service.h>
 #include <lib/base/init_num.h>
 #include <lib/base/init.h>
-#include <Python.h>
+#include <lib/python/python.h>
+
+static std::string encode(const std::string s)
+{
+       int len = s.size();
+       std::string res;
+       int i;
+       for (i=0; i<len; ++i)
+       {
+               unsigned char c = s[i];
+               if ((c == ':') || (c < 32) || (c == '%'))
+               {
+                       res += "%";
+                       char hex[8];
+                       snprintf(hex, 8, "%02x", c);
+                       res += hex;
+               } else
+                       res += c;
+       }
+       return res;
+}
+
+static std::string decode(const std::string s)
+{
+       int len = s.size();
+       std::string res;
+       int i;
+       for (i=0; i<len; ++i)
+       {
+               unsigned char c = s[i];
+               if (c != '%')
+                       res += c;
+               else
+               {
+                       i += 2;
+                       if (i >= len)
+                               break;
+                       char t[3] = {s[i - 1], s[i], 0};
+                       unsigned char r = strtoul(t, 0, 0x10);
+                       if (r)
+                               res += r;
+               }
+       }
+       return res;
+}
+
 
 eServiceReference::eServiceReference(const std::string &string)
 {
@@ -35,6 +80,9 @@ eServiceReference::eServiceReference(const std::string &string)
                else
                        path=pathstr;
        }
+       
+       path = decode(path);
+       name = decode(name);
 }
 
 std::string eServiceReference::toString() const
@@ -45,9 +93,9 @@ std::string eServiceReference::toString() const
        ret += getNum(flags);
        for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
                ret+=":"+ getNum(data[i], 0x10);
-       ret+=":"+path;
+       ret+=":"+encode(path); /* we absolutely have a problem when the path contains a ':' (for example: http://). we need an encoding here. */
        if (name.length())
-               ret+=":"+name;
+               ret+=":"+encode(name);
        return ret;
 }
 
@@ -58,7 +106,7 @@ std::string eServiceReference::toCompareString() const
        ret += ":0";
        for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
                ret+=":"+getNum(data[i], 0x10);
-       ret+=":"+path;
+       ret+=":"+encode(path);
        return ret;
 }
 
@@ -139,18 +187,57 @@ RESULT eServiceCenter::offlineOperations(const eServiceReference &ref, ePtr<iSer
        return i->second->offlineOperations(ref, ptr);
 }
 
-RESULT eServiceCenter::addServiceFactory(int id, iServiceHandler *hnd)
+RESULT eServiceCenter::addServiceFactory(int id, iServiceHandler *hnd, std::list<std::string> &extensions)
 {
        handler.insert(std::pair<int,ePtr<iServiceHandler> >(id, hnd));
+       this->extensions[id]=extensions;
        return 0;
 }
 
 RESULT eServiceCenter::removeServiceFactory(int id)
 {
        handler.erase(id);
+       extensions.erase(id);
+       return 0;
+}
+
+RESULT eServiceCenter::addFactoryExtension(int id, const char *extension)
+{
+       std::map<int, std::list<std::string> >::iterator it = extensions.find(id);
+       if (it == extensions.end())
+               return -1;
+       it->second.push_back(extension);
        return 0;
 }
 
+RESULT eServiceCenter::removeFactoryExtension(int id, const char *extension)
+{
+       std::map<int, std::list<std::string> >::iterator it = extensions.find(id);
+       if (it == extensions.end())
+               return -1;
+       it->second.remove(extension);
+       return 0;
+}
+
+
+int eServiceCenter::getServiceTypeForExtension(const char *str)
+{
+       for (std::map<int, std::list<std::string> >::iterator sit(extensions.begin()); sit != extensions.end(); ++sit)
+       {
+               for (std::list<std::string>::iterator eit(sit->second.begin()); eit != sit->second.end(); ++eit)
+               {
+                       if (*eit == str)
+                               return sit->first;
+               }
+       }
+       return -1;
+}
+
+int eServiceCenter::getServiceTypeForExtension(const std::string &str)
+{
+       return getServiceTypeForExtension(str.c_str());
+}
+
        /* default handlers */
 RESULT iServiceHandler::info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr)
 {
@@ -171,9 +258,9 @@ int iStaticServiceInformation::getLength(const eServiceReference &ref)
        return -1;
 }
 
-bool iStaticServiceInformation::isPlayable(const eServiceReference &ref, const eServiceReference &ignore)
+int iStaticServiceInformation::isPlayable(const eServiceReference &ref, const eServiceReference &ignore, bool simulate)
 {
-       return true;
+       return 0;
 }
 
 RESULT iServiceInformation::getEvent(ePtr<eServiceEvent> &evt, int m_nownext)
@@ -192,6 +279,11 @@ std::string iStaticServiceInformation::getInfoString(const eServiceReference &re
        return "";
 }
 
+PyObject *iStaticServiceInformation::getInfoObject(const eServiceReference &ref, int w)
+{
+       Py_RETURN_NONE;
+}
+
 int iServiceInformation::getInfo(int w)
 {
        return -1;
@@ -204,8 +296,7 @@ std::string iServiceInformation::getInfoString(int w)
 
 PyObject* iServiceInformation::getInfoObject(int w)
 {
-       Py_INCREF(Py_None);
-       return Py_None;
+       Py_RETURN_NONE;
 }
 
 int iStaticServiceInformation::setInfo(const eServiceReference &ref, int w, int v)