From eaaa22b9437e80a965c8bcec480d5d023dec3a03 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 7 Jan 2011 17:07:17 +0800 Subject: [PATCH] Assumed the format of an item ID in the client - This in preparation for adapting the client to categorise the items in the ncurses GUI. --- src/client/main.c | 24 +++++++++++++----------- src/cokebank_basic/main.c | 19 ++++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/client/main.c b/src/client/main.c index 787eb97..9b136f8 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -30,7 +30,8 @@ // === TYPES === typedef struct sItem { - char *Ident; + char *Type; + int ID; char *Desc; int Price; } tItem; @@ -87,7 +88,7 @@ int main(int argc, char *argv[]) // > Code Type Count ... CompileRegex(&gArrayRegex, "^([0-9]{3})\\s+([A-Za-z]+)\\s+([0-9]+)", REG_EXTENDED); // // > Code Type Ident Price Desc - CompileRegex(&gItemRegex, "^([0-9]{3})\\s+([A-Za-z]+)\\s+([A-Za-z0-9:]+?)\\s+([0-9]+)\\s+(.+)$", REG_EXTENDED); + CompileRegex(&gItemRegex, "^([0-9]{3})\\s+([A-Za-z]+)\\s+([A-Za-z]+):([0-9]+)\\s+([0-9]+)\\s+(.+)$", REG_EXTENDED); // > Code 'SALT' salt CompileRegex(&gSaltRegex, "^([0-9]{3})\\s+([A-Za-z]+)\\s+(.+)$", REG_EXTENDED); // > Code 'User' Username Balance Flags @@ -273,7 +274,8 @@ int main(int argc, char *argv[]) else { for( i = 0; i < giNumItems; i ++ ) { - printf("%2i %s\t%3i %s\n", i, gaItems[i].Ident, gaItems[i].Price, gaItems[i].Desc); + printf("%2i %s:%i\t%3i %s\n", i, gaItems[i].Type, gaItems[i].ID, + gaItems[i].Price, gaItems[i].Desc); } printf(" q Quit\n"); for(;;) @@ -667,8 +669,7 @@ int Authenticate(int Socket) responseCode = atoi(buf); switch( responseCode ) { - - case 200: // Authenticated, return :) + case 200: // Autoauth succeeded, return free(buf); break; @@ -845,7 +846,7 @@ void PopulateItemList(int Socket) // Fetch item information for( i = 0; i < giNumItems; i ++ ) { - regmatch_t matches[6]; + regmatch_t matches[7]; // Get item info buf = ReadLine(Socket); @@ -856,13 +857,14 @@ void PopulateItemList(int Socket) exit(-1); } - RunRegex(&gItemRegex, buf, 6, matches, "Malformed server response"); + RunRegex(&gItemRegex, buf, 7, matches, "Malformed server response"); buf[ matches[3].rm_eo ] = '\0'; - gaItems[i].Ident = strdup( buf + matches[3].rm_so ); - gaItems[i].Price = atoi( buf + matches[4].rm_so ); - gaItems[i].Desc = strdup( buf + matches[5].rm_so ); + gaItems[i].Type = strdup( buf + matches[3].rm_so ); + gaItems[i].ID = atoi( buf + matches[4].rm_so ); + gaItems[i].Price = atoi( buf + matches[5].rm_so ); + gaItems[i].Desc = strdup( buf + matches[6].rm_so ); free(buf); } @@ -893,7 +895,7 @@ int DispenseItem(int Socket, int ItemID) if( ItemID < 0 || ItemID > giNumItems ) return -1; // Dispense! - sendf(Socket, "DISPENSE %s\n", gaItems[ItemID].Ident); + sendf(Socket, "DISPENSE %s:%i\n", gaItems[ItemID].Type, gaItems[ItemID].ID); buf = ReadLine(Socket); responseCode = atoi(buf); diff --git a/src/cokebank_basic/main.c b/src/cokebank_basic/main.c index 2e3deae..61e777c 100644 --- a/src/cokebank_basic/main.c +++ b/src/cokebank_basic/main.c @@ -32,13 +32,12 @@ char *GetUserName(int User); #if USE_LDAP char *ReadLDAPValue(const char *Filter, char *Value); #endif -void HexBin(uint8_t *Dest, int BufSize, char *Src); +void HexBin(uint8_t *Dest, int BufSize, const char *Src); // === GLOBALS === FILE *gBank_LogFile; #if USE_LDAP -char *gsLDAPServer = "mussel"; - int giLDAPPort = 389; +char *gsLDAPPath = "ldapi:///"; LDAP *gpLDAP; #endif @@ -80,7 +79,7 @@ void Init_Cokebank(const char *Argument) fprintf(stderr, "ldap_create: %s\n", ldap_err2string(rv)); exit(1); } - rv = ldap_initialize(&gpLDAP, "ldap://mussel:389"); + rv = ldap_initialize(&gpLDAP, gsLDAPPath); if(rv) { fprintf(stderr, "ldap_initialize: %s\n", ldap_err2string(rv)); exit(1); @@ -99,7 +98,7 @@ void Init_Cokebank(const char *Argument) cred.bv_val = "secret"; cred.bv_len = 6; rv = ldap_sasl_bind_s(gpLDAP, "cn=root,dc=ucc,dc=gu,dc=uwa,dc=edu,dc=au", - "", &cred, NULL, NULL, NULL); + "", &cred, NULL, NULL, &servcred); if(rv) { fprintf(stderr, "ldap_start_tls_s: %s\n", ldap_err2string(rv)); exit(1); @@ -232,13 +231,15 @@ int GetUserAuth(const char *Salt, const char *Username, const char *PasswordStri // Then create the hash from the provided salt // Compare that with the provided hash - if( giDebugLevel ) { + # if 1 + { int i; - printf("Client %i: Password hash ", Client->ID); - for(i=0;i