summaryrefslogtreecommitdiff
path: root/vdr-vdrmanager/sock.h
blob: 25a7b83dc073878206ec68375da6d4c378cb9866 (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
/*
 * extendes sockets
 */

#ifndef _VDRMON_SOCK
#define _VDRMON_SOCK

#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string>

using namespace std;

class cVdrmanagerSocket
{
protected:
  int sock;
  const char * password;
  bool forceCheckSvdrp;
  int compressionMode;
protected:
  cVdrmanagerSocket();
  bool IsPasswordSet();
public:
  virtual ~cVdrmanagerSocket();
  void Close();
  int GetSocket();
  bool MakeDontBlock();
  const char * GetPassword();
};

class cVdrmanagerClientSocket : public cVdrmanagerSocket
{
private:
  string readbuf;
  string writebuf;
  char * sendbuf;
  size_t sendsize;
  size_t sendoffset;
  bool disconnected;
  bool initDisconnect;
  int client;
  bool login;
  bool compression;
  bool initCompression;
  int compressionMode;
public:
  cVdrmanagerClientSocket(const char * password, int compressionMode);
  virtual ~cVdrmanagerClientSocket();
  bool Attach(int fd);
  bool IsLineComplete();
  bool GetLine(string& line);
  bool PutLine(string line);
  bool Read();
  bool Disconnected();
  void Disconnect();
  bool Flush();
  int GetClientId();
  bool WritePending();
  bool IsLoggedIn();
  void SetLoggedIn();
  void ActivateCompression();
  void Compress();
};

class cVdrmanagerServerSocket : public cVdrmanagerSocket
{
public:
  cVdrmanagerServerSocket();
  virtual ~cVdrmanagerServerSocket();
  bool Create(int port, const char * password, bool forceCheckSvdrp, int compressionMode);
  cVdrmanagerClientSocket * Accept();
};

#endif