Merge pull request #32 from Dima73/master
authorlittlesat <littlesat99@yahoo.com>
Sat, 5 Sep 2015 17:17:59 +0000 (19:17 +0200)
committerlittlesat <littlesat99@yahoo.com>
Sat, 5 Sep 2015 17:17:59 +0000 (19:17 +0200)
Update Russian locale

lib/dvb_ci/dvbci.cpp
lib/dvb_ci/dvbci.h
lib/dvb_ci/dvbci_resmgr.cpp
lib/dvb_ci/dvbci_session.cpp
lib/dvb_ci/dvbci_session.h
lib/gdi/picload.cpp
lib/python/Screens/Satconfig.py

index 56ad5e6..66c3856 100644 (file)
 
 eDVBCIInterfaces *eDVBCIInterfaces::instance = 0;
 
+
+eCIClient::eCIClient(eDVBCIInterfaces *handler, int socket) : eUnixDomainSocket(socket, 1, eApp), parent(handler)
+{
+       receivedData = NULL;
+       receivedCmd = 0;
+       CONNECT(connectionClosed_, eCIClient::connectionLost);
+       CONNECT(readyRead_, eCIClient::dataAvailable);
+}
+
+void eCIClient::connectionLost()
+{
+       if (parent) parent->connectionLost();
+}
+
+void eCIClient::dataAvailable()
+{
+       if (!receivedCmd)
+       {
+               if ((unsigned int)bytesAvailable() < sizeof(ciplus_header)) return;
+               if ((unsigned int)readBlock((char*)&header, sizeof(ciplus_header)) < sizeof(ciplus_header)) return;
+               header.magic = ntohl(header.magic);
+               header.cmd = ntohl(header.cmd);
+               header.size = ntohl(header.size);
+               if (header.magic != CIPLUSHELPER_MAGIC)
+               {
+                       if (parent) parent->connectionLost();
+                       return;
+               }
+               receivedCmd = header.cmd;
+               receivedCmdSize = header.size;
+       }
+       if (receivedCmdSize)
+       {
+               if ((unsigned int)bytesAvailable() < receivedCmdSize) return;
+               if (receivedCmdSize) delete [] receivedData;
+               receivedData = new unsigned char[receivedCmdSize];
+               if ((unsigned int)readBlock((char*)receivedData, receivedCmdSize) < receivedCmdSize) return;
+
+               ciplus_message *message = (ciplus_message *)receivedData;
+               switch (header.cmd)
+               {
+               default:
+                       {
+                               unsigned char *data = &receivedData[sizeof(ciplus_message)];
+                               parent->getSlot(ntohl(message->slot))->send(data, ntohl(message->size));
+                       }
+                       break;
+               case eCIClient::CIPLUSHELPER_STATE_CHANGED:
+                       {
+                               eDVBCISession::setAction(ntohl(message->session), receivedData[sizeof(ciplus_message)]);
+                       }
+                       break;
+               }
+               receivedCmdSize = 0;
+               receivedCmd = 0;
+       }
+}
+
+void eCIClient::sendData(int cmd, int slot, int session, unsigned long idtag, unsigned char *tag, unsigned char *data, int len)
+{
+       ciplus_message message;
+       message.slot = ntohl(slot);
+       message.idtag = ntohl(idtag);
+       memcpy(&message.tag, tag, 4);
+       message.session = ntohl(session);
+       message.size = ntohl(len);
+
+       ciplus_header header;
+       header.magic = htonl(CIPLUSHELPER_MAGIC);
+       header.size = htonl(sizeof(message) + len);
+       header.cmd = htonl(cmd);
+
+       writeBlock((const char*)&header, sizeof(header));
+       writeBlock((const char*)&message, sizeof(message));
+       if (len)
+       {
+               writeBlock((const char*)data, len);
+       }
+}
+
+void eDVBCIInterfaces::newConnection(int socket)
+{
+       if (client)
+       {
+               delete client;
+       }
+       client = new eCIClient(this, socket);
+}
+
+void eDVBCIInterfaces::connectionLost()
+{
+       if (client)
+       {
+               delete client;
+               client = NULL;
+       }
+}
+
+void eDVBCIInterfaces::sendDataToHelper(int cmd, int slot, int session, unsigned long idtag, unsigned char *tag, unsigned char *data, int len)
+{
+       if (client)     client->sendData(cmd, slot, session, idtag, tag, data, len);
+}
+
+bool eDVBCIInterfaces::isClientConnected()
+{
+       if (client) return true;
+       return false;
+}
+
+#define CIPLUS_SERVER_SOCKET "/tmp/.listen.ciplus.socket"
+
 eDVBCIInterfaces::eDVBCIInterfaces()
+ : eServerSocket(CIPLUS_SERVER_SOCKET, eApp)
 {
        int num_ci = 0;
 
        instance = this;
+       client = NULL;
 
        eDebug("[CI] scanning for common interfaces..");
 
index 8431e95..e8b817b 100644 (file)
@@ -9,6 +9,8 @@
 #include <set>
 #include <queue>
 
+#include <lib/network/serversocket.h>
+
 class eDVBCISession;
 class eDVBCIApplicationManagerSession;
 class eDVBCICAManagerSession;
@@ -117,19 +119,70 @@ typedef std::list<CIPmtHandler> PMTHandlerList;
 
 #endif // SWIG
 
+#ifndef SWIG
+class eCIClient : public eUnixDomainSocket
+{
+       struct ciplus_header
+       {
+               unsigned int magic;
+               unsigned int cmd;
+               unsigned int size;
+       }__attribute__((packed));
+
+       struct ciplus_message
+       {
+               unsigned int slot;
+               unsigned long idtag;
+               unsigned char tag[4];
+               unsigned int session;
+               unsigned int size;
+       }__attribute__((packed));
+
+       unsigned int receivedLength;
+       unsigned int receivedCmd;
+       unsigned int receivedCmdSize;
+       unsigned char *receivedData;
+
+       ciplus_header header;
+protected:
+       eDVBCIInterfaces *parent;
+       void connectionLost();
+       void dataAvailable();
+public:
+       eCIClient(eDVBCIInterfaces *handler, int socket);
+       void sendData(int cmd, int slot, int session, unsigned long idtag, unsigned char *tag, unsigned char *data, int len);
+
+       enum
+       {
+               CIPLUSHELPER_SESSION_CREATE = 1000,
+               CIPLUSHELPER_SESSION_CLOSE = 1001,
+               CIPLUSHELPER_RECV_APDU = 1002,
+               CIPLUSHELPER_DOACTION = 1003,
+               CIPLUSHELPER_STATE_CHANGED = 1004,
+               CIPLUSHELPER_DATA = 1005,
+               CIPLUSHELPER_MAGIC = 987654321,
+       };
+};
+
+class eDVBCIInterfaces: public eServerSocket
+#else
 class eDVBCIInterfaces
+#endif
 {
        DECLARE_REF(eDVBCIInterfaces);
        static eDVBCIInterfaces *instance;
        eSmartPtrList<eDVBCISlot> m_slots;
-       eDVBCISlot *getSlot(int slotid);
-       PMTHandlerList m_pmt_handlers;
+       PMTHandlerList m_pmt_handlers; 
+
+       eCIClient *client;
 #ifndef SWIG
 public:
 #endif
        eDVBCIInterfaces();
        ~eDVBCIInterfaces();
 
+       eDVBCISlot *getSlot(int slotid);
+
        void addPMTHandler(eDVBServicePMTHandler *pmthandler);
        void removePMTHandler(eDVBServicePMTHandler *pmthandler);
        void recheckPMTHandlers();
@@ -148,6 +201,10 @@ public:
        int sendCAPMT(int slot);
        int setInputSource(int tunerno, data_source source);
        int setCIClockRate(int slot, int rate);
+
+       void newConnection(int socket);
+       void connectionLost();
+
 #ifdef SWIG
 public:
 #endif
@@ -156,6 +213,9 @@ public:
        PyObject *getDescrambleRules(int slotid);
        RESULT setDescrambleRules(int slotid, SWIG_PYOBJECT(ePyObject) );
        PyObject *readCICaIds(int slotid);
+
+       void sendDataToHelper(int cmd, int slot, int session, unsigned long idtag, unsigned char *tag, unsigned char *data, int len);
+       bool isClientConnected();
 };
 
 #endif
index 7f889da..fbe476b 100644 (file)
@@ -68,7 +68,10 @@ int eDVBCIResourceManagerSession::doAction()
        case stateProfileEnquiry:
        {
                const unsigned char tag[3]={0x9F, 0x80, 0x11};
-               const unsigned char data[][4]=
+
+               if (!eDVBCIInterfaces::getInstance()->isClientConnected())
+               {
+                       const unsigned char data[][4]=
                        {
                                {0x00, 0x01, 0x00, 0x41},
                                {0x00, 0x02, 0x00, 0x41},
@@ -78,7 +81,28 @@ int eDVBCIResourceManagerSession::doAction()
                                {0x00, 0x40, 0x00, 0x41},
 //                             {0x00, 0x10, 0x00, 0x41}, // auth.
                        };
-               sendAPDU(tag, data, sizeof(data));
+                       sendAPDU(tag, data, sizeof(data));
+               }
+               else
+               {
+                       const unsigned char data[][4]=
+                       {
+                               {0x00, 0x01, 0x00, 0x41},
+                               {0x00, 0x02, 0x00, 0x41},
+                               {0x00, 0x02, 0x00, 0x42},
+                               {0x00, 0x03, 0x00, 0x41},
+                               {0x00, 0x20, 0x00, 0x41},
+                               {0x00, 0x24, 0x00, 0x41},
+                               {0x00, 0x40, 0x00, 0x41},
+                               {0x00, 0x02, 0x00, 0x43},
+                               {0x00, 0x8C, 0x10, 0x01},
+                               {0x00, 0x8D, 0x10, 0x01},
+                               {0x00, 0x8E, 0x10, 0x01},
+                               {0x00, 0x97, 0x10, 0x01},
+                               {0x00, 0x41, 0x00, 0x41},
+                       };
+                       sendAPDU(tag, data, sizeof(data));
+               }
                state=stateFinal;
                return 0;
        }
index 16014fd..8186037 100644 (file)
@@ -7,6 +7,33 @@
 #include <lib/dvb_ci/dvbci_camgr.h>
 #include <lib/dvb_ci/dvbci_datetimemgr.h>
 #include <lib/dvb_ci/dvbci_mmi.h>
+#include <lib/dvb_ci/dvbci.h>
+#include <lib/dvb_ci/dvbci_ui.h>
+
+eDVBCIPlusHelper::eDVBCIPlusHelper(eDVBCISlot *tslot, unsigned long tag, int session)
+{
+       m_tslot = tslot;
+       m_tag = tag;
+       m_session = session;
+       eDVBCIInterfaces::getInstance()->sendDataToHelper(eCIClient::CIPLUSHELPER_SESSION_CREATE, m_tslot->getSlotID(), m_session, m_tag, (unsigned char *)"\x00\x00\x00\x00", NULL, 0);
+}
+
+eDVBCIPlusHelper::~eDVBCIPlusHelper()
+{
+       eDVBCIInterfaces::getInstance()->sendDataToHelper(eCIClient::CIPLUSHELPER_SESSION_CLOSE, m_tslot->getSlotID(), m_session, m_tag, (unsigned char *)"\x00\x00\x00\x00", NULL, 0);
+}
+
+int eDVBCIPlusHelper::receivedAPDU(const unsigned char *tag, const void *data, int len)
+{
+       eDVBCIInterfaces::getInstance()->sendDataToHelper(eCIClient::CIPLUSHELPER_RECV_APDU, m_tslot->getSlotID(), m_session, m_tag, (unsigned char *)tag, (unsigned char *)data, len);
+       return 0;
+}
+
+int eDVBCIPlusHelper::doAction()
+{
+       eDVBCIInterfaces::getInstance()->sendDataToHelper(eCIClient::CIPLUSHELPER_DOACTION, m_tslot->getSlotID(), m_session, m_tag, (unsigned char *)"\x00\x00\x00\x00", NULL, 0);
+       return 0;
+}
 
 DEFINE_REF(eDVBCISession);
 
@@ -148,6 +175,7 @@ void eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resourc
                eDebug("[CI SESS] RESOURCE MANAGER");
                break;
        case 0x00020041:
+       case 0x00020043:
                session=new eDVBCIApplicationManagerSession(slot);
                eDebug("[CI SESS] APPLICATION MANAGER");
                break;
@@ -155,10 +183,6 @@ void eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resourc
                session = new eDVBCICAManagerSession(slot);
                eDebug("[CI SESS] CA MANAGER");
                break;
-       case 0x00240041:
-               session=new eDVBCIDateTimeSession;
-               eDebug("[CI SESS] DATE-TIME");
-               break;
        case 0x00400041:
                session = new eDVBCIMMISession(slot);
                eDebug("[CI SESS] MMI - create session");
@@ -167,7 +191,22 @@ void eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resourc
 //             session=new eDVBCIAuthSession;
                eDebug("[CI SESS] AuthSession");
 //             break;
+       case 0x00240041:
+               if (!eDVBCIInterfaces::getInstance()->isClientConnected())
+               {
+                       session=new eDVBCIDateTimeSession;
+                       eDebug("[CI SESS] DATE-TIME");
+                       break;
+               }
+       case 0x008C1001:
+       case 0x008D1001:
+       case 0x008E1001:
        case 0x00200041:
+               if (eDVBCIInterfaces::getInstance()->isClientConnected())
+               {
+                       session = new eDVBCIPlusHelper(slot, tag, session_nb);
+               }
+               break;
        default:
                eDebug("[CI SESS] unknown resource type %02x %02x %02x %02x", resource_identifier[0], resource_identifier[1], resource_identifier[2],resource_identifier[3]);
                session=0;
@@ -324,3 +363,14 @@ eDVBCISession::~eDVBCISession()
 //     eDebug("[CI SESS] destroy %p", this);
 }
 
+void eDVBCISession::setAction(unsigned int session, int val)
+{
+       if (val)
+       {
+               if (sessions[session - 1])
+               {
+                       sessions[session - 1]->action = val;
+                       sessions[session - 1]->poll();
+               }
+       }
+}
index 199a5e4..3e81ae9 100644 (file)
@@ -45,6 +45,20 @@ public:
 
        static int pollAll();
 
+       static void setAction(unsigned int session, int val);
+};
+
+class eDVBCIPlusHelper: public eDVBCISession
+{
+       eDVBCISlot *m_tslot;
+       unsigned long m_tag;
+       int m_session;
+
+       int receivedAPDU(const unsigned char *tag, const void *data, int len);
+       int doAction();
+public:
+       eDVBCIPlusHelper(eDVBCISlot *tslot, unsigned long tag, int session);
+       ~eDVBCIPlusHelper();
 };
 
 #endif
index 926566e..3aeb409 100644 (file)
@@ -7,6 +7,8 @@
 #include <lib/gdi/picexif.h>
 
 extern "C" {
+#define HAVE_BOOLEAN
+#define boolean int
 #include <jpeglib.h>
 #include <gif_lib.h>
 }
index b38f96b..3fcc980 100644 (file)
@@ -702,7 +702,7 @@ class SelectSatsEntryScreen(Screen):
                        <ePixmap pixmap="skin_default/div-h.png" position="0,375" zPosition="1" size="540,2" transparent="1" alphatest="on" />
                        <widget name="hint" position="10,380" size="540,25" font="Regular;19" halign="center" transparent="1" />
                </screen>"""
-       def __init__(self, session, userSatlist=[]):
+       def __init__(self, session, userSatlist=""):
                Screen.__init__(self, session)
                self["key_red"] = Button(_("Cancel"))
                self["key_green"] = Button(_("Save"))
@@ -710,9 +710,14 @@ class SelectSatsEntryScreen(Screen):
                self["key_blue"] = Button(_("Select all"))
                self["hint"] = Label(_("Press OK to toggle the selection"))
                SatList = []
+               if not isinstance(userSatlist, str):
+                       userSatlist = ""
+               else:
+                       userSatlist = userSatlist.replace("]", "").replace("[", "")
                for sat in nimmanager.getSatList():
                        selected = False
-                       if isinstance(userSatlist, str) and str(sat[0]) in userSatlist:
+                       sat_str = str(sat[0])
+                       if userSatlist and ("," not in userSatlist and sat_str == userSatlist) or ((', ' + sat_str + ',' in userSatlist) or (userSatlist.startswith(sat_str + ',')) or (userSatlist.endswith(', ' + sat_str))):
                                selected = True
                        SatList.append((sat[0], sat[1], sat[2], selected))
                sat_list = [SelectionEntryComponent(x[1], x[0], x[2], x[3]) for x in SatList]