1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-11-26 23:07:17 +00:00

better args handling

This commit is contained in:
Andrew Karpow 2013-11-11 15:53:54 +01:00
parent 501cbda19d
commit 81859d486b
4 changed files with 55 additions and 17 deletions

View File

@ -3,7 +3,6 @@
#include <string.h> #include <string.h>
#include "http_server.h" #include "http_server.h"
#define LOCAL_RESOURCE_PATH DATADIR"/htdocs"
char *resource_path = LOCAL_RESOURCE_PATH; char *resource_path = LOCAL_RESOURCE_PATH;
struct serveable { struct serveable {

View File

@ -9,3 +9,4 @@ int callback_http(struct libwebsocket_context *context,
enum libwebsocket_callback_reasons reason, void *user, enum libwebsocket_callback_reasons reason, void *user,
void *in, size_t len); void *in, size_t len);
#define LOCAL_RESOURCE_PATH DATADIR"/htdocs"

View File

@ -47,3 +47,6 @@ int mpd_put_state(char *buffer);
int mpd_put_current_song(char *buffer); int mpd_put_current_song(char *buffer);
int mpd_put_playlist(char *buffer); int mpd_put_playlist(char *buffer);
int mpd_put_browse(char *buffer, char *path); int mpd_put_browse(char *buffer, char *path);
int mpd_port;
const char *mpd_host;

View File

@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h>
#include <sys/time.h> #include <sys/time.h>
#include "http_server.h" #include "http_server.h"
@ -41,23 +42,48 @@ void bye()
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int n, gid = -1, uid = -1; int n, gid = -1, uid = -1;
int option_index = 0;
unsigned int oldus = 0;
struct libwebsocket_context *context; struct libwebsocket_context *context;
struct lws_context_creation_info info;
const char *cert_filepath = NULL; const char *cert_filepath = NULL;
const char *private_key_filepath = NULL; const char *private_key_filepath = NULL;
const char *iface = NULL; const char *iface = NULL;
struct lws_context_creation_info info;
unsigned int oldus = 0;
atexit(bye); atexit(bye);
memset(&info, 0, sizeof info); memset(&info, 0, sizeof info);
info.port = 80; info.port = 8080;
mpd_host = "127.0.0.1";
mpd_port = 6600;
lws_set_log_level(LLL_ERR | LLL_WARN, NULL);
while((n = getopt(argc, argv, "i:p:r:c:k:g:u:h")) != -1) { static struct option long_options[] = {
{"host", required_argument, 0, 'h'},
{"port", required_argument, 0, 'p'},
{"interface", required_argument, 0, 'i'},
{"webport", required_argument, 0, 'w'},
{"resourcepath", required_argument, 0, 'r'},
{"ssl_cert", required_argument, 0, 'c'},
{"ssl_key", required_argument, 0, 'k'},
{"gid", required_argument, 0, 'g'},
{"uid", required_argument, 0, 'u'},
{"verbose", optional_argument, 0, 'v'},
{"help", no_argument, 0, 0 },
{0, 0, 0, 0 }
};
while((n = getopt_long(argc, argv, "h:p:i:r:c:k:g:uv::W",
long_options, &option_index)) != -1) {
switch (n) { switch (n) {
case 'h':
mpd_host = optarg;
break;
case 'p':
mpd_port = atoi(optarg);
case 'i': case 'i':
iface = optarg; iface = optarg;
break; break;
case 'p': case 'w':
info.port = atoi(optarg); info.port = atoi(optarg);
break; break;
case 'r': case 'r':
@ -75,17 +101,26 @@ int main(int argc, char **argv)
case 'u': case 'u':
uid = atoi(optarg); uid = atoi(optarg);
break; break;
case '?': case 'v':
case 'h': if(optarg)
lwsl_err("Usage: %s [OPTION]...\n" lws_set_log_level(strtol(optarg, NULL, 10), NULL);
"\t[-p <port>]\n" else
"\t[-i <interface>]\n" lws_set_log_level(LLL_ERR | LLL_WARN |
"\t[-r <htdocs path>]\n" LLL_NOTICE | LLL_INFO, NULL);
"\t[-c <ssl certificate filepath>]\n" break;
"\t[-k <ssl private key filepath>]\n" default:
"\t[-g <group id after socket bind>]\n" fprintf(stderr, "Usage: %s [OPTION]...\n\n"
"\t[-u <user id after socket bind>]\n" "\t-h, --host <host>\t\tconnect to mpd at host [localhost]\n"
"\t[-h]\n" "\t-p, --port <port>\t\tconnect to mpd at port [6600]\n"
"\t-i, --interface <interface>\tlisten interface for webserver [all]\n"
"\t-w, --webport <port>\t\tlisten port for webserver [8080]\n"
"\t-r, --resourcepath <path>\tresourcepath for webserver [" LOCAL_RESOURCE_PATH "]\n"
"\t-c, --ssl_cert <filepath>\tssl certificate ssl_private_key_filepath\n"
"\t-k, --ssl_key <filepath>\tssl private key filepath\n"
"\t-u, --uid <id>\t\t\tuser id after socket bind\n"
"\t-g, --gid <id>\t\t\tgroup id after socket bind\n"
"\t-v, --verbose[<level>]\t\tverbosity level\n"
"\t--help\t\t\t\tthis help\n"
, argv[0]); , argv[0]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }