Skip to content
Snippets Groups Projects
Commit 635a6185 authored by Mark Tearle's avatar Mark Tearle
Browse files

Client - Code to load up config file and set dispense server/port

parent a2a3817b
No related merge requests found
#
# OpenDispense2 Client config file
#
dispense_server merlo.ucc.asn.au
dispense_port 11021
...@@ -8,7 +8,7 @@ LDFLAGS := -g -lncurses ...@@ -8,7 +8,7 @@ LDFLAGS := -g -lncurses
BIN := ../../dispense BIN := ../../dispense
OBJ := main.o protocol.o menu.o OBJ := main.o protocol.o menu.o
OBJ += doregex.o OBJ += doregex.o config.o
DEPFILES := $(OBJ:%.o=%.d) DEPFILES := $(OBJ:%.o=%.d)
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <limits.h> // INT_MIN/INT_MAX #include <limits.h> // INT_MIN/INT_MAX
#include "common.h" #include "common.h"
#include "../common/doregex.h" #include "../common/doregex.h"
#include "../common/config.h"
#define USE_NCURSES_INTERFACE 0 #define USE_NCURSES_INTERFACE 0
#define DEBUG_TRACE_SERVER 0 #define DEBUG_TRACE_SERVER 0
...@@ -38,8 +39,12 @@ char *trim(char *string); ...@@ -38,8 +39,12 @@ char *trim(char *string);
void CompileRegex(regex_t *regex, const char *pattern, int flags); void CompileRegex(regex_t *regex, const char *pattern, int flags);
// === GLOBALS === // === GLOBALS ===
char *gsDispenseServer = "merlo.ucc.gu.uwa.edu.au"; const char *gsConfigFile = "/etc/opendispense/client.conf";
const char *gsDispenseServer = "merlo.ucc.gu.uwa.edu.au";
int giDispensePort = 11020; int giDispensePort = 11020;
int giDispenseServerSet = 0; // True if set by command line
int giDispensePortSet = 0; // True if set by command line
tItem *gaItems; tItem *gaItems;
int giNumItems; int giNumItems;
...@@ -149,6 +154,8 @@ void ShowUsage(void) ...@@ -149,6 +154,8 @@ void ShowUsage(void)
" -m <min balance>\n" " -m <min balance>\n"
" -M <max balance>\n" " -M <max balance>\n"
" Set the Maximum/Minimum balances shown in `dispense acct`\n" " Set the Maximum/Minimum balances shown in `dispense acct`\n"
" -f <configfile>\n"
" Set the config file path (default: `/etc/opendispense/client.conf'\n"
"Definitions:\n" "Definitions:\n"
" <itemid>\n" " <itemid>\n"
" Item ID of the form <type>:<num> where <type> is a non-empty string of alpha-numeric characters, and <num> is a non-negative integer\n" " Item ID of the form <type>:<num> where <type> is a non-empty string of alpha-numeric characters, and <num> is a non-negative integer\n"
...@@ -604,6 +611,18 @@ int main(int argc, char *argv[]) ...@@ -604,6 +611,18 @@ int main(int argc, char *argv[])
if( ret ) if( ret )
return ret; return ret;
// Load config file
Config_ParseFile(gsConfigFile);
// Parse config values
if (!giDispenseServerSet) {
gsDispenseServer = Config_GetValue("dispense_server",0);
}
if (!giDispensePortSet) {
giDispensePort = Config_GetValue_Int("dispense_port",0);
}
// Sub-commands // Sub-commands
if( strcmp(gsTextArgs[0], "finger") == 0 ) { if( strcmp(gsTextArgs[0], "finger") == 0 ) {
return subcommand_finger(); return subcommand_finger();
...@@ -865,6 +884,15 @@ int ParseArguments(int argc, char *argv[]) ...@@ -865,6 +884,15 @@ int ParseArguments(int argc, char *argv[])
giMaximumBalance = atoi(argv[++i]); giMaximumBalance = atoi(argv[++i]);
break; break;
case 'f': // Override Config File
if( i + 1 >= argc ) {
fprintf(stderr, "%s: -f takes an argument\n", argv[0]);
ShowUsage();
return RV_ARGUMENTS;
}
gsConfigFile = argv[++i];
break;
case 'u': // Override User case 'u': // Override User
if( i + 1 >= argc ) { if( i + 1 >= argc ) {
fprintf(stderr, "%s: -u takes an argument\n", argv[0]); fprintf(stderr, "%s: -u takes an argument\n", argv[0]);
...@@ -881,6 +909,7 @@ int ParseArguments(int argc, char *argv[]) ...@@ -881,6 +909,7 @@ int ParseArguments(int argc, char *argv[])
return RV_ARGUMENTS; return RV_ARGUMENTS;
} }
gsDispenseServer = argv[++i]; gsDispenseServer = argv[++i];
giDispenseServerSet = 1;
break; break;
case 'P': // Override remote port case 'P': // Override remote port
if( i + 1 >= argc ) { if( i + 1 >= argc ) {
...@@ -889,6 +918,7 @@ int ParseArguments(int argc, char *argv[]) ...@@ -889,6 +918,7 @@ int ParseArguments(int argc, char *argv[])
return RV_ARGUMENTS; return RV_ARGUMENTS;
} }
giDispensePort = atoi(argv[++i]); giDispensePort = atoi(argv[++i]);
giDispensePortSet = 1;
break; break;
// Set slot name/price // Set slot name/price
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment