summaryrefslogtreecommitdiff
path: root/libs/networking/src
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-29 13:11:47 (GMT)
committergeronimo <geronimo013@gmx.de>2012-07-29 13:11:47 (GMT)
commit85cb3f04252b0228830903b21c08bb64e9919c18 (patch)
tree5c00dbd8d296861aa56cca598ee2a36e51971822 /libs/networking/src
parent736033f3d532c4814eeff84db5dbf99f0249df6e (diff)
downloadcmp-85cb3f04252b0228830903b21c08bb64e9919c18.tar.gz
cmp-85cb3f04252b0228830903b21c08bb64e9919c18.tar.bz2
changed server setup to config file, little rearrangement of sources
Diffstat (limited to 'libs/networking/src')
-rw-r--r--libs/networking/src/ConnectionHandler.cc12
-rw-r--r--libs/networking/src/HTTPResponse.cc12
-rw-r--r--libs/networking/src/ServerConfig.cc127
-rw-r--r--libs/networking/src/Url.cc229
4 files changed, 127 insertions, 253 deletions
diff --git a/libs/networking/src/ConnectionHandler.cc b/libs/networking/src/ConnectionHandler.cc
index abed00f..4e87750 100644
--- a/libs/networking/src/ConnectionHandler.cc
+++ b/libs/networking/src/ConnectionHandler.cc
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
- *
+ *
* File: ConnectionHandler.cc
* Created: 4. Juli 2012, 07
* 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 <ConnectionHandler.h>
diff --git a/libs/networking/src/HTTPResponse.cc b/libs/networking/src/HTTPResponse.cc
index e9ae8eb..f76fff5 100644
--- a/libs/networking/src/HTTPResponse.cc
+++ b/libs/networking/src/HTTPResponse.cc
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
- *
+ *
* File: HTTPResponse.cc
* Created: 4. 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 <HTTPResponse.h>
diff --git a/libs/networking/src/ServerConfig.cc b/libs/networking/src/ServerConfig.cc
index a339497..0b29d8a 100644
--- a/libs/networking/src/ServerConfig.cc
+++ b/libs/networking/src/ServerConfig.cc
@@ -1,47 +1,60 @@
/**
* ======================== 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(int Port)
- : server(Port, 5)
+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(appIconPath);
+ FREE(configBaseDir);
FREE(documentRoot);
+ FREE(appIconPath);
+ FREE(mediaInfo);
+ FREE(ffmpeg);
}
-void cServerConfig::SetAppIcon(const char* AppIcon)
+void cServerConfig::SetAppIcon(const char *AppIcon)
{
struct stat st;
@@ -53,13 +66,103 @@ void cServerConfig::SetAppIcon(const char* AppIcon)
else esyslog("ERROR: failed to stat application icon! %s", AppIcon);
}
-void cServerConfig::SetDocumentRoot(const char* DocumentRoot)
+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);
-} \ No newline at end of file
+}
+
+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;
+}
diff --git a/libs/networking/src/Url.cc b/libs/networking/src/Url.cc
deleted file mode 100644
index ce951e6..0000000
--- a/libs/networking/src/Url.cc
+++ /dev/null
@@ -1,229 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: Url.cc
- * Created: 4. Juli 2012, 05
- * 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 <Url.h>
-#include <Codec.h>
-#include <util.h>
-#ifdef DEBUG
-#include <iostream>
-#endif
-#include <stdio.h>
-#include <string.h>
-#include <vector>
-
-static cURLEncoder * encoder = NULL;
-static cURLDecoder * decoder = NULL;
-
-cUrl::cUrl(const char* RawURL)
- : path(NULL)
-{
- ParseURL(RawURL);
-}
-
-cUrl::~cUrl()
-{
- FREE(path);
-}
-
-cURLDecoder* cUrl::Decoder(void)
-{
- if (!decoder) decoder = new cURLDecoder();
- return decoder;
-}
-
-cURLEncoder* cUrl::Encoder(void)
-{
- if (!encoder) encoder = new cURLEncoder();
- return encoder;
-}
-
-const char *cUrl::Parameter(const char* Name)
-{
- std::tr1::unordered_map<std::string, std::string>::iterator found = parameters.find(Name);
- if (found != parameters.end()) return found->second.c_str();
- return NULL;
-}
-
-void cUrl::SetParameter(const char* Name, const char* Value)
-{
- std::string name = Name;
- std::string value = Value ? Value : " ";
- parameters[name] = value;
-}
-
-size_t cUrl::EstimatedSize(void ) const
-{
- size_t rv = parameters.size() * 3;
-
- if (path) rv += strlen(path) + 4;
- ParameterMap::const_iterator pm = parameters.begin();
-
- while (pm != parameters.end()) {
- rv += pm->first.length() * 3;
- rv += pm->second.length() * 3;
- ++pm;
- }
- return rv;
-}
-
-void cUrl::ParseURL(const char *URL)
-{
- FREE(path);
- parameters.clear();
- if (!URL) return;
- const char *q = strchr(URL, '?'); // divider between url and querystring
-// char *realURL;
-// size_t l;
-
- if (!q) q = URL + strlen(URL);
-// l = q - URL;
-// realURL = (char *)malloc(l + 2);
-// if (!realURL) return;
-// strncpy(realURL, URL, l);
-// realURL[l] = 0;
- path = Decoder()->Decode(URL, q - URL);
- if (*q) ParseQueryString(++q);
-}
-
-void cUrl::ParseQueryString(const char* QueryString)
-{
- if (!(QueryString && *QueryString)) return;
- const char *start, *last;
- char *scratch = strdup(QueryString);
- char *p, *end;
- size_t srcLen = strlen(QueryString);
-
- for (start = (const char *)scratch, end = (char *) start, last = scratch + srcLen; end && start < last; start = (const char *)++end) {
- end = (char *) strchr(start, '&');
- if (!end) end = (char *)start + strlen(start);
- *end = 0;
- p = (char *) strchr(start, '=');
- if (p) {
- *p++ = 0;
- char *pn = p ? Decoder()->Decode(start) : NULL;
- char *pv = p ? Decoder()->Decode(p) : NULL;
-
- std::string name = pn;
- std::string value = pv ? pv : " ";
-
- parameters[name] = value;
-
- free(pn);
- free(pv);
- }
- else {
- char *pn = Decoder()->Decode(start);
-
- std::string name = pn;
- parameters[name] = " ";
- free(pn);
- }
- }
- free(scratch);
-}
-
-char* cUrl::ToString(void) const
-///< returns the address of the newly allocated buffer
-{
- size_t bufSize = EstimatedSize();
- char *rv = (char *)malloc(bufSize);
-
- if (!rv) return NULL;
- int n = WriteBuf(rv, bufSize);
-
- if (n < 0) {
- bufSize += 128;
- rv = (char *) realloc(rv, bufSize);
- WriteBuf(rv, bufSize);
- }
- return rv;
-}
-
-int cUrl::WriteBuf(char* buf, size_t bufSize) const
-///< returns the characters written. -1 as return value indicates a buffer overrun.
-{
- char *p, *tmp;
- bool first = true;
- int n = 0;
-
- if (path) n += snprintf(buf + n, bufSize - n, "%s", path);
- p = buf + n;
- ParameterMap::const_iterator pm = parameters.begin();
-
- while (pm != parameters.end()) {
- tmp = Encoder()->Encode(pm->first.c_str());
- if (p - buf + strlen(tmp) + 2 > bufSize)
- return -1;
- if (first) {
- first = false;
- *p++ = '?';
- }
- else *p++ = '&';
- strcpy(p, tmp);
- p += strlen(p);
- FREE(tmp);
-
- if (strcmp(pm->second.c_str(), " ")) {
- tmp = Encoder()->Encode(pm->second.c_str());
- if (p - buf + strlen(tmp) + 2 > bufSize)
- return -1;
- *p++ = '=';
- strcpy(p, tmp);
- p += strlen(p);
- FREE(tmp);
- }
- ++pm;
- }
- p += strlen(p);
-
- return p - buf;
-}
-
-#ifdef DEBUG
-void cUrl::Dump(void )
-{
- ParameterMap::const_iterator pm = parameters.begin();
-
- while (pm != parameters.end()) {
- std::cout << "parameter [" << pm->first << "]";
- if (strcmp(pm->second.c_str(), " "))
- std::cout << " has value <|" << pm->second << "|>" << std::endl;
- else
- std::cout << " has NO value!" << std::endl;
- ++pm;
- }
-}
-#endif
-
-void cUrl::Cleanup(void )
-{
- if (encoder) {
- delete encoder;
- encoder = NULL;
- }
- if (decoder) {
- delete decoder;
- decoder = NULL;
- }
-} \ No newline at end of file