diff options
-rw-r--r-- | cmps/main.cc | 67 | ||||
-rw-r--r-- | cmps/nbproject/configurations.xml | 1 | ||||
-rw-r--r-- | libs/networking/include/AbstractSocket.h | 20 | ||||
-rw-r--r-- | libs/networking/include/ServerConfig.h | 13 | ||||
-rw-r--r-- | libs/networking/include/ServerSocket.h | 16 | ||||
-rw-r--r-- | libs/networking/src/HTTPServer.cc | 14 | ||||
-rw-r--r-- | libs/networking/src/ServerConfig.cc | 17 | ||||
-rw-r--r-- | libs/networking/src/ServerSocket.cc | 35 | ||||
-rw-r--r-- | libs/vdr/include/tools.h | 16 |
9 files changed, 136 insertions, 63 deletions
diff --git a/cmps/main.cc b/cmps/main.cc index 0598e12..c918ada 100644 --- a/cmps/main.cc +++ b/cmps/main.cc @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== - * + * * File: main.cc * Created: 2. Juli 2012, 16:51 * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> * Project: cmps - the backend (server) part of compound media player - * + * * 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 <HTTPServer.h> @@ -34,8 +34,16 @@ #include <JSonListAssembler.h> #include <HTMLListAssembler.h> #include <Url.h> +#include <String.h> #include <stdio.h> +#include <getopt.h> +static struct option longOptions[] = { + { "port", required_argument, NULL, 'p' } +, { "mediaRoot", required_argument, NULL, 'r' } +, { "favicon", required_argument, NULL, 'i' } +, { NULL, no_argument, NULL, 0 } +}; static int refreshScanner(void *opaque, cHTTPRequest &Request) { @@ -48,18 +56,53 @@ static int refreshScanner(void *opaque, cHTTPRequest &Request) return -1; } -/* - * - */ -int main(int argc, char** argv) +static void parseCommandline(int argc, char *argv[], cServerConfig &config) { - cServerConfig config(12345); + int c; + // set defaults first config.SetAuthorizationRequired(false); config.SetDocumentRoot("/media"); config.SetAppIcon("/media/favicon.ico"); - //TODO: parse commandline, read config + while ((c = getopt_long(argc, argv, "p:r:i:", longOptions, NULL)) != -1) { + switch (c) { + case 'p': { + if (isnumber(optarg)) { + int n = atoi(optarg); + + if (n > 0) config.SetPort(n); + } + } break; + + case 'r': { + struct stat st; + + if (!stat(optarg, &st)) { + if ((st.st_mode & S_IFMT) == S_IFDIR && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) { + config.SetDocumentRoot(optarg); + } + } + } break; + + case 'i': { + struct stat st; + + if (!stat(optarg, &st)) { + if ((st.st_mode & S_IFMT) == S_IFREG && (st.st_mode & (S_IRUSR | S_IRGRP | S_IROTH))) { + config.SetAppIcon(optarg); + } + } + } break; + } + } +} + +int main(int argc, char** argv) +{ + cServerConfig config(12345); + + parseCommandline(argc, argv, config); cFilesystemScanner *scanner = new cFilesystemScanner(); if (!scanner) { diff --git a/cmps/nbproject/configurations.xml b/cmps/nbproject/configurations.xml index 6eb9f34..aac44fd 100644 --- a/cmps/nbproject/configurations.xml +++ b/cmps/nbproject/configurations.xml @@ -45,6 +45,7 @@ projectFiles="false" kind="IMPORTANT_FILES_FOLDER"> <itemPath>Makefile</itemPath> + <itemPath>../README</itemPath> </logicalFolder> </logicalFolder> <projectmakefile>Makefile</projectmakefile> diff --git a/libs/networking/include/AbstractSocket.h b/libs/networking/include/AbstractSocket.h index ff76f52..98e77f7 100644 --- a/libs/networking/include/AbstractSocket.h +++ b/libs/networking/include/AbstractSocket.h @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== - * + * * File: AbstractSocket.h * Created: 4. Juli 2012, 07:13 * 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 - * + * * -------------------------------------------------------------- */ #ifndef ABSTRACTSOCKET_H @@ -40,13 +40,13 @@ public: protected: cAbstractSocket(int Port, int Queue = 1); cAbstractSocket(const char *ServerName, int Port); - bool Connect(); - bool Open(int Port); - cConnectionPoint *Accept(int Port, int TimeoutMs = -1); bool ForceBlockingIO(void) const { return blocking; } void SetBlockingIO(bool ForceBlockingIO = true); cConnectionPoint *GetNameAndAddress(int Socket, struct sockaddr *sa, socklen_t sa_size); - void Close(void); + virtual cConnectionPoint *Accept(int Port, int TimeoutMs = -1); + virtual bool Connect(); + virtual bool Open(int Port); + virtual void Close(void); private: int sock; diff --git a/libs/networking/include/ServerConfig.h b/libs/networking/include/ServerConfig.h index f64b5f5..c61c896 100644 --- a/libs/networking/include/ServerConfig.h +++ b/libs/networking/include/ServerConfig.h @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== - * + * * File: ServerConfig.h * Created: 8. Juli 2012, 06:12 * 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 - * + * * -------------------------------------------------------------- */ #ifndef SERVERCONFIG_H @@ -41,6 +41,7 @@ public: void SetAppIcon(const char *AppIcon); void SetAuthorizationRequired(bool Authorize) { authorizationRequired = Authorize; } void SetDocumentRoot(const char *DocumentRoot); + void SetPort(int port); private: cServerSocket server; diff --git a/libs/networking/include/ServerSocket.h b/libs/networking/include/ServerSocket.h index 2fc17fb..9465d67 100644 --- a/libs/networking/include/ServerSocket.h +++ b/libs/networking/include/ServerSocket.h @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== - * + * * File: ServerSocket.h * Created: 4. Juli 2012, 07:28 * 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 - * + * * -------------------------------------------------------------- */ #ifndef SERVERSOCKET_H @@ -31,11 +31,13 @@ class cServerSocket : public cAbstractSocket { public: cServerSocket(int Port, int Queue = 1); virtual ~cServerSocket(); - bool Open(void); + virtual bool Open(void); + virtual void Close(void); bool Active(void) const { return active; } void SetActive(bool Active = true) { active = Active; } cConnectionPoint *Accept(void); int Port(void) const { return port; } + void SetPort(int port); int ReUseAddress(void) const; void SetReUseAddress(int ReUse); void ConfigureSocket(int Socket); diff --git a/libs/networking/src/HTTPServer.cc b/libs/networking/src/HTTPServer.cc index f435e2f..3b9757b 100644 --- a/libs/networking/src/HTTPServer.cc +++ b/libs/networking/src/HTTPServer.cc @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== - * + * * File: HTTPServer.cc * Created: 4. Juli 2012, 12:16 * 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 <HTTPServer.h> @@ -66,6 +66,8 @@ void cHTTPServer::Action() } #endif fprintf(stderr, "startup server now\n"); + + ServerSocket().Open(); while (Running()) { cConnectionPoint *cp = ServerSocket().Accept(); diff --git a/libs/networking/src/ServerConfig.cc b/libs/networking/src/ServerConfig.cc index e6ad4b8..d749264 100644 --- a/libs/networking/src/ServerConfig.cc +++ b/libs/networking/src/ServerConfig.cc @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== - * + * * File: ServerConfig.cc * Created: 8. Juli 2012, 06:12 * 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> @@ -57,4 +57,9 @@ void cServerConfig::SetDocumentRoot(const char* DocumentRoot) { free(documentRoot); documentRoot = DocumentRoot ? strdup(DocumentRoot) : NULL; +} + +void cServerConfig::SetPort(int port) +{ + server.SetPort(port); }
\ No newline at end of file diff --git a/libs/networking/src/ServerSocket.cc b/libs/networking/src/ServerSocket.cc index 2ff92fb..ae51a18 100644 --- a/libs/networking/src/ServerSocket.cc +++ b/libs/networking/src/ServerSocket.cc @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== - * + * * File: ServerSocket.cc * Created: 4. Juli 2012, 07:28 * 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 <ServerSocket.h> @@ -29,7 +29,7 @@ cServerSocket::cServerSocket(int Port, int Queue) : cAbstractSocket(Port, Queue) , port(Port) - , active(true) + , active(false) { } @@ -39,7 +39,17 @@ cServerSocket::~cServerSocket() bool cServerSocket::Open(void) { - return cAbstractSocket::Open(port); + bool rv = cAbstractSocket::Open(port); + + if (rv) active = true; + + return rv; +} + +void cServerSocket::Close(void) +{ + active = false; + cAbstractSocket::Close(); } cConnectionPoint *cServerSocket::Accept(void) @@ -82,3 +92,12 @@ bool cServerSocket::ForceBlockingIO() const { return cAbstractSocket::ForceBlockingIO(); } + +void cServerSocket::SetPort(int Port) +{ + if (active) { + esyslog("ERROR: server socket is already active! Can't change port settings!"); + return; + } + port = Port; +}
\ No newline at end of file diff --git a/libs/vdr/include/tools.h b/libs/vdr/include/tools.h index bb159aa..50660bc 100644 --- a/libs/vdr/include/tools.h +++ b/libs/vdr/include/tools.h @@ -1,30 +1,30 @@ /** * File: tools.h * Project: libvdr - classes taken from vdr-project - * + * * from "Video Disk Recorder": - * + * * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * + * * The original author can be reached at kls@tvdr.de - * + * * The vdr project's page is at http://www.tvdr.de - * + * */ #ifndef TOOLS_H #define TOOLS_H |