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
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/**
* ======================== legal notice ======================
*
* File: ServerConfig.cc
* Created: 8. Juli 2012, 06
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libnetworking: classes for tcp/ip sockets and http-protocol handling
*
* CMP - compound media player
*
* is a client/server mediaplayer intended to play any media from any workstation
* without the need to export or mount shares. cmps is an easy to use backend
* with a (ready to use) HTML-interface. Additionally the backend supports
* authentication via HTTP-digest authorization.
* cmpc is a client with vdr-like osd-menues.
*
* Copyright (c) 2012 Reinhard Mantey, some rights reserved!
* published under Creative Commons by-sa
* For details see http://creativecommons.org/licenses/by-sa/3.0/
*
* The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
*
* --------------------------------------------------------------
*/
#include <ServerConfig.h>
#include <ConfigReader.h>
#include <LineReader.h>
#include <FileReader.h>
#include <File.h>
#include <Logging.h>
#include <util.h>
#include <sys/stat.h>
#include <sys/types.h>
cServerConfig::cServerConfig(const char *ConfigBaseDir)
: server(12345, 5)
, authorizationRequired(false)
, wantExtendedScan(false)
, configBaseDir(ConfigBaseDir ? strdup(ConfigBaseDir) : NULL)
, credentialsFile(NULL)
, documentRoot(NULL)
, appIconPath(NULL)
, mediaInfo(NULL)
, ffmpeg(NULL)
{
}
cServerConfig::~cServerConfig()
{
FREE(configBaseDir);
FREE(documentRoot);
FREE(appIconPath);
FREE(mediaInfo);
FREE(ffmpeg);
}
void cServerConfig::SetAppIcon(const char *AppIcon)
{
struct stat st;
if (!AppIcon) return;
if (!stat(AppIcon, &st)) {
FREE(appIconPath);
appIconPath = strdup(AppIcon);
}
else esyslog("ERROR: failed to stat application icon! %s", AppIcon);
}
void cServerConfig::SetConfigBaseDir(const char *ConfigBaseDir)
{
free(configBaseDir);
configBaseDir = ConfigBaseDir ? strdup(ConfigBaseDir) : NULL;
}
void cServerConfig::SetCredentialsFile(const char *FileName)
{
free(credentialsFile);
credentialsFile = FileName ? strdup(FileName) : NULL;
}
void cServerConfig::SetDocumentRoot(const char *DocumentRoot)
{
free(documentRoot);
documentRoot = DocumentRoot ? strdup(DocumentRoot) : NULL;
}
void cServerConfig::SetMediaInfo(const char *MediaInfo)
{
free(mediaInfo);
mediaInfo = MediaInfo ? strdup(MediaInfo) : NULL;
}
void cServerConfig::SetFFMpeg(const char* FFMpeg)
{
free(ffmpeg);
ffmpeg = FFMpeg ? strdup(FFMpeg) : NULL;
}
void cServerConfig::SetPort(int port)
{
server.SetPort(port);
}
void cServerConfig::Dump(void)
{
isyslog("server-config - socket #%d", server.Port());
isyslog("server-config - authorization required: %s", authorizationRequired ? "yes" : "no");
isyslog("server-config - do extended scan: %s", wantExtendedScan ? "yes" : "no");
isyslog("server-config - application dir: %s", configBaseDir);
isyslog("server-config - credentials file: %s", credentialsFile);
isyslog("server-config - media root: %s", documentRoot);
isyslog("server-config - app icon: %s", appIconPath);
isyslog("server-config - mediainfo: %s", mediaInfo);
isyslog("server-config - ffmpeg: %s", ffmpeg);
}
int cServerConfig::Load(const char* FileName)
{
cConfigReader *cr = new cConfigReader(new cLineReader(new cFileReader(new cFile(configBaseDir, FileName))));
cConfigReader::ConfigEntry *ce;
int numberOfEntries = 0;
while ((ce = cr->ReadValue())) {
std::string name = std::get<0>(*ce);
if (!strcmp("media-root", name.c_str())) {
SetDocumentRoot(std::get<1>(*ce).c_str());
++numberOfEntries;
}
else if (!strcmp("favicon", name.c_str())) {
SetAppIcon(std::get<1>(*ce).c_str());
++numberOfEntries;
}
else if (!strcmp("cmps-port", name.c_str())) {
SetPort(atoi(std::get<1>(*ce).c_str()));
++numberOfEntries;
}
#ifdef NOT_YET
else if (!strcmp("want-auth", name.c_str())) {
SetAuthorizationRequired(!strcasecmp("true", std::get<1>(*ce).c_str()));
++numberOfEntries;
}
#endif
else if (!strcmp("want-meta", name.c_str())) {
SetWantExtendedScan(!strcasecmp("true", std::get<1>(*ce).c_str()));
++numberOfEntries;
}
else if (!strcmp("mediainfo", name.c_str())) {
SetMediaInfo(std::get<1>(*ce).c_str());
++numberOfEntries;
}
else if (!strcmp("ffmpeg", name.c_str())) {
SetFFMpeg(std::get<1>(*ce).c_str());
++numberOfEntries;
}
delete ce;
}
cr->Close();
delete cr;
return numberOfEntries > 0;
}
int cServerConfig::Store(const char* FileName)
{
//TODO:
return 0;
}
|