From 512c85b9aad68127e62244fdd8666779c053a50c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 6 Jan 2011 14:07:32 +0800 Subject: [PATCH 1/1] Implemented limits on `dispense acct` and in ENUM_USERS --- RunServerTest | 8 ++++---- src/client/main.c | 37 ++++++++++++++++++++++++++++++++----- src/server/server.c | 18 +++++++++++++++++- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/RunServerTest b/RunServerTest index 49bc04a..5bedb53 100755 --- a/RunServerTest +++ b/RunServerTest @@ -3,8 +3,8 @@ ARGS="--itemsfile items.cfg -p 11020" ARGS=$ARGS" --cokeport /dev/ttyUSB0" -#if [ "x$1" == "xdbg" ]; then -# LD_LIBRARY_PATH=. gdb --args ./dispsrv $ARGS -#else +if [ "x$1" = "xdbg" ]; then + LD_LIBRARY_PATH=. gdb --args ./dispsrv $ARGS +else LD_LIBRARY_PATH=. ./dispsrv $ARGS -#fi +fi diff --git a/src/client/main.c b/src/client/main.c index acef5b5..f095096 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -15,6 +15,7 @@ #include #include #include +#include #include // close #include // gethostbyname @@ -67,9 +68,10 @@ tItem *gaItems; regex_t gArrayRegex, gItemRegex, gSaltRegex, gUserInfoRegex; int gbIsAuthenticated = 0; -char *gsOverrideUser; //!< '-u' argument (dispense as another user) +char *gsOverrideUser; //!< '-u' Dispense as another user int gbUseNCurses = 0; //!< '-G' Use the NCurses GUI? - int giSocket = -1; + int giMinimumBalance = INT_MIN; //!< '-m' Minumum balance for `dispense acct` + int giMaximumBalance = INT_MAX; //!< '-M' Maximum balance for `dispense acct` // === CODE === int main(int argc, char *argv[]) @@ -102,6 +104,13 @@ int main(int argc, char *argv[]) ShowUsage(); return 0; + case 'm': // Minimum balance + giMinimumBalance = atoi(argv[++i]); + break; + case 'M': // Maximum balance + giMaximumBalance = atoi(argv[++i]); + break; + case 'u': // Override User gsOverrideUser = argv[++i]; break; @@ -130,8 +139,8 @@ int main(int argc, char *argv[]) // argv[i+1]: Username // Alter account? - if( i + 2 < argc ) { - + if( i + 2 < argc ) + { if( i + 3 >= argc ) { fprintf(stderr, "Error: `dispense acct' needs a reason\n"); exit(1); @@ -241,6 +250,9 @@ void ShowUsage(void) "\t\tShow help text\n" "\t-G\n" "\t\tUse alternate GUI\n" + "\t-m \n" + "\t-M \n" + "\t\tSet the Maximum/Minimum balances shown in `dispense acct`\n" ); } @@ -869,7 +881,22 @@ int Dispense_EnumUsers(int Socket) int nUsers; regmatch_t matches[4]; - sendf(Socket, "ENUM_USERS\n"); + if( giMinimumBalance != INT_MIN ) { + if( giMaximumBalance != INT_MAX ) { + sendf(Socket, "ENUM_USERS %i %i\n", giMinimumBalance, giMaximumBalance); + } + else { + sendf(Socket, "ENUM_USERS %i\n", giMinimumBalance); + } + } + else { + if( giMaximumBalance != INT_MAX ) { + sendf(Socket, "ENUM_USERS - %i\n", giMaximumBalance); + } + else { + sendf(Socket, "ENUM_USERS\n"); + } + } buf = ReadLine(Socket); responseCode = atoi(buf); diff --git a/src/server/server.c b/src/server/server.c index 85e2025..3dc1786 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -615,7 +615,23 @@ void Server_Cmd_ENUMUSERS(tClient *Client, char *Args) int numUsr = GetMaxID(); // Parse arguments - //minBal = atoi(Args); + if( Args && strlen(Args) ) + { + char *min = Args, *max; + + max = strchr(Args, ' '); + if( max ) { + *max = '\0'; + max ++; + } + + // If != "-" + if( strcmp(min, "-") != 0 ) + minBal = atoi(min); + // If != "-" + if( max && strcmp(max, "-") != 0 ) + maxBal = atoi(max); + } // Get return number for( i = 0; i < numUsr; i ++ ) -- 2.20.1