summaryrefslogtreecommitdiff
path: root/server/setup.c
blob: 862c917658639627554f60bf0c265ccad186a9f7 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 *  $Id: setup.c,v 1.10 2010/07/19 13:49:31 schmirl Exp $
 */
 
#include <vdr/menuitems.h>

#include "server/setup.h"
#include "server/server.h"

cStreamdevServerSetup StreamdevServerSetup;

cStreamdevServerSetup::cStreamdevServerSetup(void) {
	HideMenuEntry   = false;
	MaxClients      = 5;
	StartVTPServer  = true;
	VTPServerPort   = 2004;
	VTPPriority     = 0;
	LoopPrevention  = false;
	StartHTTPServer = true;
	HTTPServerPort  = 3000;
	HTTPPriority    = 0;
	HTTPStreamType  = stTS;
	StartIGMPServer = false;
	IGMPClientPort  = 1234;
	IGMPPriority    = 0;
	IGMPStreamType  = stTS;
	AllowSuspend    = false;
	strcpy(VTPBindIP, "0.0.0.0");
	strcpy(HTTPBindIP, "0.0.0.0");
	strcpy(IGMPBindIP, "0.0.0.0");
}

bool cStreamdevServerSetup::SetupParse(const char *Name, const char *Value) {
	if      (strcmp(Name, "HideMenuEntry") == 0)   HideMenuEntry   = atoi(Value);
	else if (strcmp(Name, "MaxClients") == 0)      MaxClients      = atoi(Value);
	else if (strcmp(Name, "StartServer") == 0)     StartVTPServer  = atoi(Value);
	else if (strcmp(Name, "ServerPort") == 0)      VTPServerPort   = atoi(Value);
	else if (strcmp(Name, "VTPPriority") == 0)     VTPPriority     = atoi(Value);
	else if (strcmp(Name, "VTPBindIP") == 0)       strcpy(VTPBindIP, Value);
	else if (strcmp(Name, "LoopPrevention") == 0)  LoopPrevention  = atoi(Value);
	else if (strcmp(Name, "StartHTTPServer") == 0) StartHTTPServer = atoi(Value);
	else if (strcmp(Name, "HTTPServerPort") == 0)  HTTPServerPort  = atoi(Value);
	else if (strcmp(Name, "HTTPPriority") == 0)    HTTPPriority    = atoi(Value);
	else if (strcmp(Name, "HTTPStreamType") == 0)  HTTPStreamType  = atoi(Value);
	else if (strcmp(Name, "HTTPBindIP") == 0)      strcpy(HTTPBindIP, Value);
	else if (strcmp(Name, "StartIGMPServer") == 0) StartIGMPServer = atoi(Value);
	else if (strcmp(Name, "IGMPClientPort") == 0)  IGMPClientPort  = atoi(Value);
	else if (strcmp(Name, "IGMPPriority") == 0)    IGMPPriority    = atoi(Value);
	else if (strcmp(Name, "IGMPStreamType") == 0)  IGMPStreamType  = atoi(Value);
	else if (strcmp(Name, "IGMPBindIP") == 0)      strcpy(IGMPBindIP, Value);
	else if (strcmp(Name, "AllowSuspend") == 0)    AllowSuspend    = atoi(Value);
	else return false;
	return true;
}

const char* cStreamdevServerMenuSetupPage::StreamTypes[st_Count - 1] = {
	"TS",
	"PES",
	"PS",
	"ES",
	"EXT"
};

cStreamdevServerMenuSetupPage::cStreamdevServerMenuSetupPage(void) {
	m_NewSetup = StreamdevServerSetup;

	Set();
}

cStreamdevServerMenuSetupPage::~cStreamdevServerMenuSetupPage() {
}

void cStreamdevServerMenuSetupPage::Set(void) {
	int current = Current();
	Clear();
	AddCategory (tr("Common Settings"));
	Add(new cMenuEditBoolItem(tr("Hide Mainmenu Entry"),       &m_NewSetup.HideMenuEntry));
	Add(new cMenuEditIntItem (tr("Maximum Number of Clients"), &m_NewSetup.MaxClients, 0, 100));

	
	AddCategory (tr("VDR-to-VDR Server"));
	Add(new cMenuEditBoolItem(tr("Start VDR-to-VDR Server"),   &m_NewSetup.StartVTPServer));
	Add(new cMenuEditIntItem (tr("VDR-to-VDR Server Port"),    &m_NewSetup.VTPServerPort, 0, 65535));
	Add(new cMenuEditIpItem  (tr("Bind to IP"),                 m_NewSetup.VTPBindIP));
	Add(new cMenuEditIntItem (tr("Legacy Client Priority"),    &m_NewSetup.VTPPriority, MINPRIORITY, MAXPRIORITY));
	Add(new cMenuEditBoolItem(tr("Client may suspend"),        &m_NewSetup.AllowSuspend));
	if (cPluginManager::CallFirstService(LOOP_PREVENTION_SERVICE))
		Add(new cMenuEditBoolItem(tr("Loop Prevention"),           &m_NewSetup.LoopPrevention));

	AddCategory (tr("HTTP Server"));
	Add(new cMenuEditBoolItem(tr("Start HTTP Server"),         &m_NewSetup.StartHTTPServer));
	Add(new cMenuEditIntItem (tr("HTTP Server Port"),          &m_NewSetup.HTTPServerPort, 0, 65535));
	Add(new cMenuEditIpItem  (tr("Bind to IP"),                 m_NewSetup.HTTPBindIP));
	Add(new cMenuEditIntItem (tr("Priority"),                  &m_NewSetup.HTTPPriority, MINPRIORITY, MAXPRIORITY));
	Add(new cMenuEditStraItem(tr("HTTP Streamtype"),           &m_NewSetup.HTTPStreamType, st_Count - 1, StreamTypes));

	AddCategory (tr("Multicast Streaming Server"));
	Add(new cMenuEditBoolItem(tr("Start IGMP Server"),         &m_NewSetup.StartIGMPServer));
	Add(new cMenuEditIntItem (tr("Multicast Client Port"),     &m_NewSetup.IGMPClientPort, 0, 65535));
	Add(new cMenuEditIpItem  (tr("Bind to IP"),                 m_NewSetup.IGMPBindIP));
	Add(new cMenuEditIntItem (tr("Priority"),                  &m_NewSetup.IGMPPriority, MINPRIORITY, MAXPRIORITY));
	Add(new cMenuEditStraItem(tr("Multicast Streamtype"),      &m_NewSetup.IGMPStreamType, st_Count - 1, StreamTypes));
	SetCurrent(Get(current));
	Display();
}

void cStreamdevServerMenuSetupPage::AddCategory(const char *Title) {

  cString str = cString::sprintf("--- %s -------------------------------------------------"
   		"---------------", Title );

  cOsdItem *item = new cOsdItem(*str);
  item->SetSelectable(false);
  Add(item);
}
	
void cStreamdevServerMenuSetupPage::Store(void) {
	bool restart = false;
	if (m_NewSetup.StartVTPServer != StreamdevServerSetup.StartVTPServer
			|| m_NewSetup.VTPServerPort != StreamdevServerSetup.VTPServerPort
			|| strcmp(m_NewSetup.VTPBindIP, StreamdevServerSetup.VTPBindIP) != 0
			|| m_NewSetup.StartHTTPServer != StreamdevServerSetup.StartHTTPServer
			|| m_NewSetup.HTTPServerPort != StreamdevServerSetup.HTTPServerPort
			|| strcmp(m_NewSetup.HTTPBindIP, StreamdevServerSetup.HTTPBindIP) != 0
			|| m_NewSetup.StartIGMPServer != StreamdevServerSetup.StartIGMPServer
			|| m_NewSetup.IGMPClientPort != StreamdevServerSetup.IGMPClientPort
			|| strcmp(m_NewSetup.IGMPBindIP, StreamdevServerSetup.IGMPBindIP) != 0) {
		restart = true;
		cStreamdevServer::Destruct();
	}
	
	SetupStore("HideMenuEntry",   m_NewSetup.HideMenuEntry);
	SetupStore("MaxClients",      m_NewSetup.MaxClients);
	SetupStore("StartServer",     m_NewSetup.StartVTPServer);
	SetupStore("ServerPort",      m_NewSetup.VTPServerPort);
	SetupStore("VTPBindIP",       m_NewSetup.VTPBindIP);
	SetupStore("VTPPriority",     m_NewSetup.VTPPriority);
	SetupStore("LoopPrevention",  m_NewSetup.LoopPrevention);
	SetupStore("StartHTTPServer", m_NewSetup.StartHTTPServer);
	SetupStore("HTTPServerPort",  m_NewSetup.HTTPServerPort);
	SetupStore("HTTPBindIP",      m_NewSetup.HTTPBindIP);
	SetupStore("HTTPPriority",    m_NewSetup.HTTPPriority);
	SetupStore("HTTPStreamType",  m_NewSetup.HTTPStreamType);
	SetupStore("StartIGMPServer", m_NewSetup.StartIGMPServer);
	SetupStore("IGMPClientPort",  m_NewSetup.IGMPClientPort);
	SetupStore("IGMPBindIP",      m_NewSetup.IGMPBindIP);
	SetupStore("IGMPPriority",    m_NewSetup.IGMPPriority);
	SetupStore("IGMPStreamType",  m_NewSetup.IGMPStreamType);
	SetupStore("AllowSuspend",    m_NewSetup.AllowSuspend);

	StreamdevServerSetup = m_NewSetup;

	if (restart) 
		cStreamdevServer::Initialize();
}