parent
3e1e74a34a
commit
b9f3b8e32c
@ -1,5 +1,64 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include "miniwebcam.h"
|
||||||
|
|
||||||
Configuration config;
|
Configuration config;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup default values for all configuration options
|
||||||
|
*/
|
||||||
|
Configuration::Configuration() {
|
||||||
|
http_port = DEFAULT_HTTP_PORT;
|
||||||
|
https_port = DEFAULT_HTTPS_PORT;
|
||||||
|
runasdaemon = 0;
|
||||||
|
|
||||||
|
initflags = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
Configuration::~Configuration() {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* print current configuration
|
||||||
|
*/
|
||||||
|
int Configuration::Print() {
|
||||||
|
printf ("#\n# default ports for http and https\n");
|
||||||
|
if (http_port == DEFAULT_HTTP_PORT) printf ("# ");
|
||||||
|
printf ("http_port %d\n", http_port);
|
||||||
|
if (https_port == DEFAULT_HTTPS_PORT) printf ("# ");
|
||||||
|
printf ("https_port %d\n", https_port);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Configuration::LoadArgs(int argc, char **argv) {
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
if (strcmp(argv[i], "-F") == 0) runasdaemon = 0;
|
||||||
|
if (strcmp(argv[i], "-D") == 0) runasdaemon = 1;
|
||||||
|
|
||||||
|
if (strcmp(argv[i], "-dump_config") == 0) initflags |= CONF_INITFLAGS_PRINT;
|
||||||
|
if (strcmp(argv[i], "-h") == 0) initflags |= CONF_INITFLAGS_HELP;
|
||||||
|
|
||||||
|
if (strcmp(argv[i], "-http_port") == 0) {
|
||||||
|
if (++i < argc) {
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ErrorExit("missing port parameter", -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Configuration::Help() {
|
||||||
|
printf ("Parameters:\n");
|
||||||
|
printf (" -F run in foreground\n");
|
||||||
|
printf (" -D run as daemon\n");
|
||||||
|
printf ("\n");
|
||||||
|
printf (" -dump_config print the config file\n");
|
||||||
|
printf ("\n");
|
||||||
|
printf (" -H print this help\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,29 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string>
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include "miniwebcam.h"
|
||||||
|
|
||||||
|
void ErrorExit(std::string text, int errorcode) {
|
||||||
|
printf ("Error: %s\n", text.c_str());
|
||||||
|
exit (errorcode);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
config.LoadArgs (argc, argv);
|
||||||
|
if (config.GetInitFlags() & CONF_INITFLAGS_PRINT) {
|
||||||
|
config.Print();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.GetInitFlags() & CONF_INITFLAGS_HELP) {
|
||||||
|
config.Help();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
printf ("MiniWebCam:\n");
|
printf ("MiniWebCam:\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
#ifndef _MINIWEBCAM_H_
|
||||||
|
#define _MINIWEBCAM_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void ErrorExit(std::string text, int errorcode);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
Loading…
Reference in new issue