diff options
author | geronimo <geronimo013@gmx.de> | 2012-07-13 06:17:43 +0200 |
---|---|---|
committer | geronimo <geronimo013@gmx.de> | 2012-07-13 06:17:43 +0200 |
commit | 8d311771df7448ada1410bfce0993fdaa3698106 (patch) | |
tree | 90d37c7238ac2b46ec05a2ba1acbd8cec6af6dea /cmps | |
parent | e9237d65ac03840de56e50cacf95001273bcff59 (diff) | |
download | cmp-8d311771df7448ada1410bfce0993fdaa3698106.tar.gz cmp-8d311771df7448ada1410bfce0993fdaa3698106.tar.bz2 |
added basic commandline support for cmps
Diffstat (limited to 'cmps')
-rw-r--r-- | cmps/main.cc | 67 | ||||
-rw-r--r-- | cmps/nbproject/configurations.xml | 1 |
2 files changed, 56 insertions, 12 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> |