]> www.vanbest.org Git - sasc-ng.git/commitdiff
check SCAPI version on library load
authorleslie <unknown>
Mon, 8 Jun 2009 13:05:36 +0000 (21:05 +0800)
committerleslie <unknown>
Mon, 8 Jun 2009 13:05:36 +0000 (21:05 +0800)
22 files changed:
Makefile
sc.c
systems/cardclient/cc.c
systems/conax/conax.c
systems/constcw/constcw.c
systems/cryptoworks/cryptoworks.c
systems/irdeto/irdeto.c
systems/nagra/nagra.c
systems/nds/nds.c
systems/sc-conax/sc-conax.c
systems/sc-cryptoworks/sc-cryptoworks.c
systems/sc-irdeto/sc-irdeto.c
systems/sc-nagra/sc-nagra.c
systems/sc-seca/sc-seca.c
systems/sc-viaccess/sc-viaccess.c
systems/sc-videoguard2/sc-videoguard2.c
systems/seca/seca.c
systems/shl/shl.c
systems/viaccess/viaccess.c
testing/Makefile
testing/compat.c
version.h

index 7641ec318babf448c0040cd0da3079b09524beb8..656e422c04330276c8a4b47eb5882aa0621b930a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@ SUBREL  := $(shell if test -d .hg; then \
                      echo -n "Unknown"; \
                    fi)
 VERSION := $(RELEASE)-$(SUBREL)
-SCAPIVERS := $(shell sed -ne '/define SCAPIVERS/ s/^.[a-zA-Z ]*\([0-9]*\).*$$/\1/p' $(PLUGIN).c)
+SCAPIVERS := $(shell sed -ne '/define SCAPIVERS/ s/^.[a-zA-Z ]*\([0-9]*\).*$$/\1/p' version.h)
 
 ### The directory environment:
 
diff --git a/sc.c b/sc.c
index 7fb7e119cfc6b2fe70285c2efd7866b253231dc6..b2051af469a6b055baa0a16b5317bc1bad92949b 100644 (file)
--- a/sc.c
+++ b/sc.c
@@ -77,9 +77,6 @@
 #error Your VDR API version is too old. See README.
 #endif
 
-// SC API version number for loading shared libraries
-#define SCAPIVERS 24
-
 static cPlugin *ScPlugin;
 static cOpts *ScOpts, *LogOpts;
 static const char * const cfgsub="sc";
@@ -1137,12 +1134,18 @@ cScDll::~cScDll()
 bool cScDll::Load(void)
 {
   char *base=rindex(fileName,'/');
-  if(!base) base=fileName;
+  if(base) base++; else base=fileName;
   PRINTF(L_CORE_DYN,"loading library: %s",base);
   if(!handle) {
     handle=dlopen(fileName,RTLD_NOW|RTLD_LOCAL);
-    if(handle) return true;
-    PRINTF(L_GEN_ERROR,"dload: %s: %s",base,dlerror());
+    if(handle) {
+      dlerror();
+      int *libapivers=(int *)dlsym(handle,"ScLibApiVersion");
+      const char *error=dlerror();
+      if(!error && *libapivers==SCAPIVERS) return true;
+      else PRINTF(L_GEN_ERROR,"dload: %s: SCAPI version doesn't match (plugin=%d, library=%d)",base,SCAPIVERS,!error?*libapivers:0);
+      }
+    else PRINTF(L_GEN_ERROR,"dload: %s: %s",base,dlerror());
     }
   return false;
 }
@@ -1223,6 +1226,7 @@ private:
   cScDlls dlls;
 #endif
   cScHousekeeper *keeper;
+  bool dllSuccess;
 public:
   cScPlugin(void);
   virtual ~cScPlugin();
@@ -1265,9 +1269,11 @@ cScPlugin::cScPlugin(void)
   LogOpts->Add(new cOptBool ("LogSyslog"   ,trNOOP("Log to syslog")       ,&logcfg.logSys));
   LogOpts->Add(new cOptBool ("LogUserMsg"  ,trNOOP("Show user messages")  ,&logcfg.logUser));
 #ifndef STATICBUILD
-  dlls.Load();
+  dllSuccess=dlls.Load();
+#else
+  dllSuccess=true;
 #endif
-  cScDvbDevice::Capture();
+  if(dllSuccess) cScDvbDevice::Capture();
   keeper=0;
 }
 
@@ -1281,7 +1287,7 @@ cScPlugin::~cScPlugin()
 bool cScPlugin::Initialize(void)
 {
   PRINTF(L_GEN_INFO,"SC version %s initializing",ScVersion);
-  return cScDvbDevice::Initialize();
+  return dllSuccess && cScDvbDevice::Initialize();
 }
 
 bool cScPlugin::Start(void)
index e7afdfae7be24694c74bb542cd67ae1383dc8e56..1f73c96603651737f103cd8904803cc90953e78b 100644 (file)
@@ -29,6 +29,9 @@
 #include "misc.h"
 #include "opts.h"
 #include "log-core.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_NAME          "Cardclient"
 #define SYSTEM_PRI           -15
index 390760b26b24aee1339015d0c7e4bfa88a1a975a..9bc6cc13defbf5c6c6eef0c6393aee31c1f2791b 100644 (file)
@@ -26,6 +26,9 @@
 #include "data.h"
 #include "misc.h"
 #include "log-sys.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_CONAX         0x0B00
 
index 901c307f3fbe302c3c2c2265fe93932ba820c36a..314e9a7c3fd985848a2e2ac71d5571b7e313cab7 100644 (file)
@@ -28,6 +28,9 @@
 #include "system-common.h"
 #include "data.h"
 #include "misc.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_NAME          "ConstCW"
 #define SYSTEM_PRI           -20
index 1fc0d6b5b644b8fdc27e5f2998dc231e7217b105..c8a2b0ca343f1c993ebd6dc4225602017c8a9da2 100644 (file)
@@ -28,6 +28,9 @@
 #include "crypto.h"
 #include "misc.h"
 #include "log-sys.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_CRYPTOWORKS   0x0D00
 
index 02b166e2503837c7e8dcada006a094b20cb6dfa1..ebcf00745ca602f4cf2e957910f91fd404047450 100644 (file)
@@ -25,6 +25,9 @@
 
 #include "irdeto.h"
 #include "log-irdeto.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 static const struct LogModule lm_sys = {
   (LMOD_ENABLE|L_SYS_ALL)&LOPT_MASK,
index 09fa8849d381dc0416b5f77e4f92a1dfc1051630..5436c70ac00c67da153289b79358702a2f70c03e 100644 (file)
@@ -25,6 +25,9 @@
 #include "nagra-def.h"
 #include "log-nagra.h"
 #include "log-core.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 static const struct LogModule lm_sys = {
   (LMOD_ENABLE|L_SYS_ALL)&LOPT_MASK,
index 0d04ed0846b227e073c5471a1133b35e43f17dc6..159a0140e480bac75e0ea0ddb2553d02c48a713d 100644 (file)
@@ -19,6 +19,9 @@
 
 #include "nds.h"
 #include "log-nds.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 static const struct LogModule lm_sys = {
   (LMOD_ENABLE|L_SYS_ALL)&LOPT_MASK,
index 06a9b2ea035f2e6409c690ce27e9820f213d3ecd..83925bfd057d634b78f7b4665d87a106c454787d 100644 (file)
@@ -25,6 +25,9 @@
 #include "parse.h"
 #include "misc.h"
 #include "log-sc.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_CONAX         0x0B00
 
index fa54bffb1e4b51cec5d146c137a8680f2e4350bf..1f3eb7e2ef5d844c11ce5714493f522e510d0f3d 100644 (file)
@@ -30,6 +30,9 @@
 #include "misc.h"
 #include "log-sc.h"
 #include "log-core.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_NAME          "SC-Cryptoworks"
 #define SYSTEM_PRI           -5
index 2a316f568c76ac6af8d08c081c13a23e4b422348..783b9eca94566c938697911a0fa0870e8354af1d 100644 (file)
@@ -30,6 +30,9 @@
 #include "parse.h"
 #include "log-sc.h"
 #include "log-core.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_NAME          "SC-Irdeto"
 #define SYSTEM_PRI           -5
index e0feeac0d52b2769ff628eb9df44d5e82c5fe6b2..7a17be652838384495e5ea473479efd00613035f 100644 (file)
@@ -28,6 +28,9 @@
 #include "helper.h"
 #include "log-sc.h"
 #include "log-core.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_NAGRA         0x1801
 
index 763da5fa6556e40e9e4bf9526e80ddedb1dd44e5..d0ff7426ca2d838632ad91cd8e2a4188f77894af 100644 (file)
@@ -28,6 +28,9 @@
 #include "opts.h"
 #include "parse.h"
 #include "log-sc.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_SECA          0x0100
 
index 5b0faf45895772366e509f65a9945df960a88a23..7561462963edc4d10e6927b074ae9d5b2202b0bf 100644 (file)
@@ -27,6 +27,9 @@
 #include "misc.h"
 #include "log-sc.h"
 #include "log-core.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_VIACCESS      0x0500
 
index 3080e88a484df21a5636278242f408a2db188801..7e98e1e1688ba631adc9cac57b12fb5d17f96b34 100644 (file)
@@ -29,6 +29,9 @@
 #include "helper.h"
 #include "log-sc.h"
 #include "log-core.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_VIDEOGUARD2   0x0900
 
index 5f51736568bc1d2acf9b09765b425f2292b29e44..572303261d6f5db1d1646499f0d11fd6007e7de8 100644 (file)
@@ -32,6 +32,9 @@
 #include "misc.h"
 #include "log-sys.h"
 #include "log-core.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_SECA          0x0100
 
index 95a8877c3988fddf73c552e688eeae9e9e445e9b..af42e4b3d059fcfd1bedc65c279bcbcd4dc4d4c0 100644 (file)
@@ -32,6 +32,9 @@
 #include "filter.h"
 #include "misc.h"
 #include "log-sys.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_SHL           0x4A60
 
index 305083a550ff696e6285bcd1fbc530d017970669..51782473d44acbe95a18a38cc60fe4be3ab256fc 100644 (file)
@@ -30,6 +30,9 @@
 #include "viaccess.h"
 #include "tps.h"
 #include "log-viaccess.h"
+#include "version.h"
+
+SCAPIVERSTAG();
 
 #define SYSTEM_NAME          "Viaccess"
 #define SYSTEM_PRI           -10
index 189fea5f68794a1c1552f74aeebcf893eadea584..72f02b9194af8cec423267e8a77c60a468ab152d 100644 (file)
@@ -14,12 +14,11 @@ CXXFLAGS ?= -g -march=pentium3 -O2 -Wall -Woverloaded-virtual
 
 ### Includes and Defines
 
-SCAPIVERS = $(shell sed -ne '/define SCAPIVERS/ s/^.[a-zA-Z ]*\([0-9]*\).*$$/\1/p' ../sc.c)
 APIVERSION = $(shell sed -ne '/define APIVERSION/ s/^.*"\(.*\)".*$$/\1/p' $(VDRDIR)/include/vdr/config.h)
 APIVERSNUM = $(shell sed -ne '/define APIVERSNUM/ s/^.[a-zA-Z ]*\([0-9]*\) .*$$/\1/p' $(VDRDIR)/include/vdr/config.h)
 
 INCLUDES = -I.. -I$(VDRDIR)/include
-DEFINES  = -DAPIVERSNUM=$(APIVERSNUM) -DAPIVERSION='"$(APIVERSION)"' -DSCAPIVERS=$(SCAPIVERS) -D_GNU_SOURCE
+DEFINES  = -DAPIVERSNUM=$(APIVERSNUM) -DAPIVERSION='"$(APIVERSION)"' -D_GNU_SOURCE
 
 OBJS = misc.o log.o override.o data.o crypto.o parse.o system.o system-common.o smartcard.o network.o filter.o version.o
 SHAREDOBJS = compat.o $(VDRDIR)/tools.o $(VDRDIR)/thread.o
index 56d8ac67db613bda1b6c0b7a5ed6b612b3467347..01a3ffd4c9c43e5e6ea17757e82cf50e9617224f 100644 (file)
 static bool DllLoad(const char *fileName)
 {
   const char *base=rindex(fileName,'/');
-  if(!base) base=fileName;
+  if(base) base++; else base=fileName;
   void *handle=dlopen(fileName,RTLD_NOW|RTLD_LOCAL);
-  if(handle) return true;
-  printf("dload: %s: %s\n",base,dlerror());
+  if(handle) {
+    dlerror();
+    int *libapivers=(int *)dlsym(handle,"ScLibApiVersion");
+    const char *error=dlerror();
+    if(!error && *libapivers==SCAPIVERS)
+      return true;
+    else printf("dload: %s: SCAPI version doesn't match (plugin=%d, library=%d)\n",base,SCAPIVERS,!error?*libapivers:0);
+    }
+  else printf("dload: %s: %s\n",base,dlerror());
   return false;
 }
 
@@ -39,7 +46,7 @@ bool DllsLoad(const char *libdir)
   struct dirent *e;
   while((e=dir.Next())) {
     if(!fnmatch(pat,e->d_name,FNM_PATHNAME|FNM_NOESCAPE)) {
-      DllLoad(AddDirectory(libdir,e->d_name));
+      if(!DllLoad(AddDirectory(libdir,e->d_name))) res=false;
       }
     }
   return res;
index 956a976793de6443440efa64c2a21468b18b5102..6f3bcddf68a72f469033ed2b0b903b5d508c8582 100644 (file)
--- a/version.h
+++ b/version.h
@@ -24,4 +24,8 @@
 
 extern const char *ScVersion;
 
+// SC API version number for loading shared libraries
+#define SCAPIVERS 24
+#define SCAPIVERSTAG() int ScLibApiVersion=SCAPIVERS
+
 #endif