From: John Hodge Date: Fri, 4 Mar 2011 08:45:21 +0000 (+0800) Subject: Merge branch 'master' of ssh.ucc.asn.au:tpg/opendispense2 X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Fopendispense2.git;a=commitdiff_plain;h=4fef498619ca05876568c6bc5114fadd7c2496ee;hp=7ba426116326af469bc8c73aae4fc1c56ebb3612 Merge branch 'master' of ssh.ucc.asn.au:tpg/opendispense2 --- diff --git a/src/client/main.c b/src/client/main.c index 7dc9499..71f58f9 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -49,8 +49,10 @@ enum eReturnValues RV_PERMISSIONS, RV_ARGUMENTS, RV_BALANCE, + RV_SERVER_ERROR, // Generic for 5xx codes RV_UNKNOWN_ERROR = -1, - RV_SOCKET_ERROR = -2 + RV_SOCKET_ERROR = -2, + RV_UNKNOWN_RESPONSE = -3, }; // === TYPES === @@ -63,8 +65,8 @@ typedef struct sItem { } tItem; // === PROTOTYPES === - int main(int argc, char *argv[]); void ShowUsage(void); + int main(int argc, char *argv[]); // --- GUI --- int ShowNCursesUI(void); int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted); @@ -114,6 +116,60 @@ char *gsUserFlags; //!< User's flag set int giDispenseCount = 1; //!< Number of dispenses to do // === CODE === +void ShowUsage(void) +{ + printf( + "Usage:\n" + " == Everyone ==\n" + " dispense\n" + " Show interactive list\n" + " dispense ||\n" + " Dispense named item ( matches if it is a unique prefix)\n" + " dispense give \"\"\n" + " Give money to another user\n" + " dispense donate \"\"\n" + " Donate to the club\n" + " dispense iteminfo \n" + " Get the name and price for an item\n" + " == Coke members == \n" + " dispense acct []\n" + " Show user balances\n" + " dispense acct [+-] \"\"\n" + " Alter a account value\n" + " dispense refund []\n" + " Refund an item to a user (with optional price override)\n" + " == Dispense administrators ==\n" + " dispense acct = \"\"\n" + " Set an account balance\n" + " dispense user add \n" + " Create new account\n" + " dispense user type \n" + " Alter a user's flags\n" + " is a comma-separated list of user, coke, admin, internal or disabled\n" + " Flags are removed by preceding the name with '-' or '!'\n" + "\n" + "General Options:\n" + " -c \n" + " Dispense multiple times\n" + " -u \n" + " Set a different user (Coke members only)\n" + " -h / -?\n" + " Show help text\n" + " -G\n" + " Use alternate GUI\n" + " -n\n" + " Dry run - Do not actually do dispenses\n" + " -m \n" + " -M \n" + " Set the Maximum/Minimum balances shown in `dispense acct`\n" + "Definitions:\n" + " \n" + " Item ID of the form : where is a non-empty string of alpha-numeric characters, and is a non-negative integer\n" +// " \n" +// " Account name\n" + ); +} + int main(int argc, char *argv[]) { int sock; @@ -217,6 +273,11 @@ int main(int argc, char *argv[]) gbDryRun = 1; break; default: + if( !isdigit(argv[i][0]) ) { + fprintf(stderr, "%s: Unknown switch '%s'\n", argv[0], argv[i]); + ShowUsage(); + return RV_ARGUMENTS; + } if( text_argc + 1 == MAX_TXT_ARGS ) { fprintf(stderr, "ERROR: Too many arguments\n"); @@ -642,51 +703,6 @@ int main(int argc, char *argv[]) return ret; } -void ShowUsage(void) -{ - printf( - "Usage:\n" - " == Everyone ==\n" - " dispense\n" - " Show interactive list\n" - " dispense ||\n" - " Dispense named item ( matches if it is a unique prefix)\n" - " dispense give \"\"\n" - " Give money to another user\n" - " dispense donate \"\"\n" - " Donate to the club\n" - " dispense iteminfo :\n" - " Get the name and price for an item\n" - " == Coke members == \n" - " dispense acct []\n" - " Show user balances\n" - " dispense acct [+-] \"\"\n" - " Alter a account value\n" - " == Dispense administrators ==\n" - " dispense acct = \"\"\n" - " Set an account balance\n" - " dispense user add \n" - " Create new coke account (Admins only)\n" - " dispense user type \n" - " Alter a user's flags\n" - " is a comma-separated list of user, coke, admin or disabled\n" - " Flags are removed by preceding the name with '-' or '!'\n" - "\n" - "General Options:\n" - " -c \n" - " Dispense multiple times\n" - " -u \n" - " Set a different user (Coke members only)\n" - " -h / -?\n" - " Show help text\n" - " -G\n" - " Use alternate GUI\n" - " -m \n" - " -M \n" - " Set the Maximum/Minimum balances shown in `dispense acct`\n" - ); -} - // ------------------- // --- NCurses GUI --- // ------------------- @@ -1530,11 +1546,11 @@ int DispenseItem(int Socket, const char *Type, int ID) break; case 500: printf("Item failed to dispense, is the slot empty?\n"); - ret = 1; + ret = RV_SERVER_ERROR; break; case 501: printf("Dispense not possible (slot empty/permissions)\n"); - ret = 1; + ret = RV_SERVER_ERROR; break; default: printf("Unknown response code %i ('%s')\n", responseCode, buf); @@ -1577,16 +1593,16 @@ int Dispense_AlterBalance(int Socket, const char *Username, int Ammount, const c case 200: return 0; // OK case 402: fprintf(stderr, "Insufficient balance\n"); - return 1; + return RV_BAD_ITEM; case 403: // Not in coke fprintf(stderr, "You are not in coke (sucker)\n"); - return 1; + return RV_PERMISSIONS; case 404: // Unknown user fprintf(stderr, "Unknown user '%s'\n", Username); - return 2; + return RV_INVALID_USER; default: fprintf(stderr, "Unknown response code %i\n", responseCode); - return -1; + return RV_UNKNOWN_RESPONSE; } return -1; @@ -1618,13 +1634,13 @@ int Dispense_SetBalance(int Socket, const char *Username, int Balance, const cha case 200: return 0; // OK case 403: // Not in coke fprintf(stderr, "You are not an admin\n"); - return 1; + return RV_PERMISSIONS; case 404: // Unknown user fprintf(stderr, "Unknown user '%s'\n", Username); - return 2; + return RV_INVALID_USER; default: fprintf(stderr, "Unknown response code %i\n", responseCode); - return -1; + return RV_UNKNOWN_RESPONSE; } return -1; @@ -1640,13 +1656,13 @@ int Dispense_Give(int Socket, const char *Username, int Ammount, const char *Rea if( Ammount < 0 ) { printf("Sorry, you can only give, you can't take.\n"); - return 1; + return RV_ARGUMENTS; } // Fast return on zero if( Ammount == 0 ) { printf("Are you actually going to give any?\n"); - return 1; + return RV_ARGUMENTS; } // Check for a dry run @@ -1664,19 +1680,19 @@ int Dispense_Give(int Socket, const char *Username, int Ammount, const char *Rea { case 200: printf("Give succeeded\n"); - return 0; // OK + return RV_SUCCESS; // OK case 402: fprintf(stderr, "Insufficient balance\n"); - return 1; + return RV_BALANCE; case 404: // Unknown user fprintf(stderr, "Unknown user '%s'\n", Username); - return 2; + return RV_INVALID_USER; default: fprintf(stderr, "Unknown response code %i\n", responseCode); - return -1; + return RV_UNKNOWN_RESPONSE; } return -1; @@ -1702,7 +1718,7 @@ int Dispense_Refund(int Socket, const char *Username, const char *Item, int Pric } // Send the query - sendf(Socket, "REFUND %s %s %i", Username, Item, PriceOverride); + sendf(Socket, "REFUND %s %s %i\n", Username, Item, PriceOverride); buf = ReadLine(Socket); responseCode = atoi(buf); diff --git a/src/server/server.c b/src/server/server.c index 1ebb612..4404f9e 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -253,7 +253,7 @@ void Server_Cleanup(void) { printf("\nClose(%i)\n", giServer_Socket); close(giServer_Socket); - unlink("/var/run/dispsrv"); + unlink("/var/run/dispsrv.pid"); } /**