summaryrefslogtreecommitdiff
path: root/vdr-vdrmanager/vdrmanagerthread.cpp
blob: b0c37ba522b931287b1b8e8d05a11460f15b0c34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * VdrmonThread
 */
#include <string.h>
#include <vdr/plugin.h>
#include <vdr/thread.h>
#include "vdrmanagerthread.h"
#include "select.h"
#include "helpers.h"

cVdrManagerThread::cVdrManagerThread(int port,
#if VDRMANAGER_USE_SSL
                                     int sslPort,
#endif
                                     const char * password, bool forceCheckSvdrp,
                                     int compressionMode
#if VDRMANAGER_USE_SSL
                                     , const char * certFile, const char * keyFile
#endif
                                     )
{
  select = NULL;
  this->port = port;
  this->password = password;
  this->forceCheckSvdrp = forceCheckSvdrp;
  this->compressionMode = compressionMode;
#if VDRMANAGER_USE_SSL
  this->sslPort = sslPort;
  this->certFile = certFile;
  this->keyFile = keyFile;
#endif
}

cVdrManagerThread::~cVdrManagerThread()
{
  Cleanup();
}

void cVdrManagerThread::Action(void)
{
  // create listener socket
  if (!Init()) {
    Cleanup();
    return;
  }

  // do processing
  select->Action();

  // cleanup
  Cleanup();
}

bool cVdrManagerThread::Init()
{
  // create select
  select = new cSelect();
  if (select == NULL)
    return false;

  // create server socket
  cVdrmanagerServerSocket * sock = new cVdrmanagerServerSocket();
  if (sock == NULL || !sock->Create(port, password, forceCheckSvdrp, compressionMode, NULL, NULL))
    return false;

  // register server sockets
  select->SetServerSockets(sock, NULL);

#if VDRMANAGER_USE_SSL
  cVdrmanagerServerSocket * sslSock;
  if (!access(certFile, R_OK) && !access(keyFile, R_OK))  {
    sslSock = new cVdrmanagerServerSocket();
    if (sslSock == NULL || !sslSock->Create(sslPort, password, forceCheckSvdrp, compressionMode, certFile, keyFile)) {
      return false;
    }
  } else {
    sslSock = NULL;
    esyslog("[vdrmanager] SSL key files %s and %s can't be read. SSL disabled.", certFile, keyFile);
  }

  // register server sockets
  select->SetServerSockets(sock, sslSock);
#endif

  return true;
}

void cVdrManagerThread::Cleanup()
{
  if (select) {
    delete select;
    select = NULL;
  }
}

void cVdrManagerThread::Shutdown()
{
}