-/*
- * File: main.c
- * Author: "Fulup Ar Foll"
- *
- * Created on 05 December 2015, 15:38
- */
-
-#include "local-def.h"
-
-#include <syslog.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <getopt.h>
-#include <pwd.h>
-
-#define AFB_VERSION "0.1"
-
-static sigjmp_buf exitPoint; // context save for set/longjmp
-
-/*----------------------------------------------------------
- | printversion
- | print version and copyright
- +--------------------------------------------------------- */
- static void printVersion (void) {
-
- fprintf (stderr,"\n----------------------------------------- \n");
- fprintf (stderr,"| AFB [Application Framework Binder] version=%s |\n", AFB_VERSION);
- fprintf (stderr,"----------------------------------------- \n");
- fprintf (stderr,"| Copyright(C) 2015 Fulup Ar Foll /IoT.bzh [fulup -at- iot.bzh]\n");
- fprintf (stderr,"| AFB comes with ABSOLUTELY NO WARRANTY.\n");
- fprintf (stderr,"| Licence [what ever makes you happy] until you fix bugs by yourself :)\n\n");
- exit (0);
- } // end printVersion
-
-
-// Define command line option
-#define SET_VERBOSE 101
-#define SET_BACKGROUND 105
-#define SET_FORGROUND 106
-#define KILL_PREV_EXIT 107
-#define KILL_PREV_REST 108
-#define SET_FAKE_MOD 109
-
-#define SET_TCP_PORT 120
-#define SET_ROOT_DIR 121
-#define SET_ROOT_BASE 122
-#define SET_ROOT_API 123
-#define SET_ROOT_ALIAS 124
-
-#define SET_CACHE_TO 130
-#define SET_USERID 131
-#define SET_PID_FILE 132
-#define SET_SESSION_DIR 133
-#define SET_CONFIG_FILE 134
-#define SET_CONFIG_SAVE 135
-#define SET_CONFIG_EXIT 138
-
-#define SET_AUTH_TOKEN 141
-#define SET_LDPATH 142
-#define SET_APITIMEOUT 143
-#define SET_CNTXTIMEOUT 144
-
-#define DISPLAY_VERSION 150
-#define DISPLAY_HELP 151
-
-#define SET_MODE 160
-#define SET_READYFD 161
-
-// Command line structure hold cli --command + help text
-typedef struct {
- int val; // command number within application
- int has_arg; // command number within application
- char *name; // command as used in --xxxx cli
- char *help; // help text
-} AFB_options;
-
-
-// Supported option
-static AFB_options cliOptions [] = {
- {SET_VERBOSE ,0,"verbose" , "Verbose Mode"},
-
- {SET_FORGROUND ,0,"foreground" , "Get all in foreground mode"},
- {SET_BACKGROUND ,0,"daemon" , "Get all in background mode"},
- {KILL_PREV_EXIT ,0,"kill" , "Kill active process if any and exit"},
- {KILL_PREV_REST ,0,"restart" , "Kill active process if any and restart"},
-
- {SET_TCP_PORT ,1,"port" , "HTTP listening TCP port [default 1234]"},
- {SET_ROOT_DIR ,1,"rootdir" , "HTTP Root Directory [default $HOME/.AFB]"},
- {SET_ROOT_BASE ,1,"rootbase" , "Angular Base Root URL [default /opa]"},
- {SET_ROOT_API ,1,"rootapi" , "HTML Root API URL [default /api]"},
- {SET_ROOT_ALIAS ,1,"alias" , "Muliple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"},
-
- {SET_APITIMEOUT ,1,"apitimeout" , "Plugin API timeout in seconds [default 10]"},
- {SET_CNTXTIMEOUT ,1,"cntxtimeout" , "Client Session Context Timeout [default 900]"},
- {SET_CACHE_TO ,1,"cache-eol" , "Client cache end of live [default 3600s]"},
-
- {SET_USERID ,1,"setuid" , "Change user id [default don't change]"},
- {SET_PID_FILE ,1,"pidfile" , "PID file path [default none]"},
- {SET_SESSION_DIR ,1,"sessiondir" , "Sessions file path [default rootdir/sessions]"},
- {SET_CONFIG_FILE ,1,"config" , "Config Filename [default rootdir/sessions/configs/default.AFB]"},
- {SET_CONFIG_SAVE ,0,"save" , "Save config on disk [default no]"},
- {SET_CONFIG_EXIT ,0,"saveonly" , "Save config on disk and then exit"},
-
- {SET_LDPATH ,1,"ldpaths" , "Load Plugins from dir1:dir2:... [default = PLUGIN_INSTALL_DIR"},
- {SET_AUTH_TOKEN ,1,"token" , "Initial Secret [default=no-session, --token="" for session without authentication]"},
-
- {DISPLAY_VERSION ,0,"version" , "Display version and copyright"},
- {DISPLAY_HELP ,0,"help" , "Display this help"},
-
- {SET_MODE ,1,"mode" , "set the mode: either local, remote or global"},
- {SET_READYFD ,1,"readyfd" , "set the #fd to signal when ready"},
- {0, 0, NULL, NULL}
- };
-
-static AFB_aliasdir aliasdir[MAX_ALIAS];
-static int aliascount=0;