summaryrefslogtreecommitdiff
path: root/ci.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2017-01-09 13:42:41 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2017-01-09 13:42:41 +0100
commitd1ddb3978185ce8b3a7f783fac74b82a352fd650 (patch)
treec8bcd73d403a300a942db03118427f6f61f59c98 /ci.c
parent882273d508675c22d54b5a367b70729f6adee6cb (diff)
downloadvdr-d1ddb3978185ce8b3a7f783fac74b82a352fd650.tar.gz
vdr-d1ddb3978185ce8b3a7f783fac74b82a352fd650.tar.bz2
The channel/CAM relations are now stored in the file 'cam.data'; fixed a flaw in handling timeouts for encrypted channels
Diffstat (limited to 'ci.c')
-rw-r--r--ci.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/ci.c b/ci.c
index 606875b8..fd3acd84 100644
--- a/ci.c
+++ b/ci.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: ci.c 4.3 2016/12/23 14:00:45 kls Exp $
+ * $Id: ci.c 4.4 2017/01/09 12:51:05 kls Exp $
*/
#include "ci.h"
@@ -13,6 +13,7 @@
#include <malloc.h>
#include <netinet/in.h>
#include <poll.h>
+#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <time.h>
@@ -2317,6 +2318,7 @@ void cChannelCamRelation::ClrDecrypt(int CamSlotNumber)
// --- cChannelCamRelations --------------------------------------------------
+#define MAX_CAM_NUMBER 32
#define CHANNEL_CAM_RELATIONS_CLEANUP_INTERVAL 3600 // seconds between cleanups
cChannelCamRelations ChannelCamRelations;
@@ -2414,3 +2416,60 @@ void cChannelCamRelations::ClrDecrypt(tChannelID ChannelID, int CamSlotNumber)
if (ccr)
ccr->ClrDecrypt(CamSlotNumber);
}
+
+void cChannelCamRelations::Load(const char *FileName)
+{
+ cMutexLock MutexLock(&mutex);
+ fileName = FileName;
+ if (access(fileName, R_OK) == 0) {
+ dsyslog("loading %s", *fileName);
+ if (FILE *f = fopen(fileName, "r")) {
+ cReadLine ReadLine;
+ char *s;
+ while ((s = ReadLine.Read(f)) != NULL) {
+ if (char *p = strchr(s, ' ')) {
+ *p = 0;
+ if (*++p) {
+ tChannelID ChannelID = tChannelID::FromString(s);
+ if (ChannelID.Valid()) {
+ char *q;
+ char *strtok_next;
+ while ((q = strtok_r(p, " ", &strtok_next)) != NULL) {
+ int CamSlotNumber = atoi(q);
+ if (CamSlotNumber >= 1 && CamSlotNumber <= MAX_CAM_NUMBER)
+ SetDecrypt(ChannelID, CamSlotNumber);
+ p = NULL;
+ }
+ }
+ }
+ }
+ }
+ fclose(f);
+ }
+ else
+ LOG_ERROR_STR(*fileName);
+ }
+}
+
+void cChannelCamRelations::Save(void)
+{
+ cMutexLock MutexLock(&mutex);
+ dsyslog("saving %s", *fileName);
+ cSafeFile f(fileName);
+ if (f.Open()) {
+ for (cChannelCamRelation *ccr = First(); ccr; ccr = Next(ccr)) {
+ if (ccr->ChannelID().Valid()) {
+ cString s;
+ for (int i = 1; i <= MAX_CAM_NUMBER; i++) {
+ if (ccr->CamDecrypt(i))
+ s = cString::sprintf("%s%s%d", *s ? *s : "", *s ? " " : "", i);
+ }
+ if (*s)
+ fprintf(f, "%s %s\n", *ccr->ChannelID().ToString(), *s);
+ }
+ }
+ f.Close();
+ }
+ else
+ LOG_ERROR_STR(*fileName);
+}