From: John Hodge Date: Sat, 19 Feb 2011 03:11:00 +0000 (+0800) Subject: Debugging fixes X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b42302186308252d40184c2af8a5e1bc329db5e2;p=tpg%2Fopendispense2.git Debugging fixes --- diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index 62ea17f..56810bd 100644 --- a/src/server/handler_coke.c +++ b/src/server/handler_coke.c @@ -69,7 +69,7 @@ int Coke_CanDispense(int UNUSED(User), int Item) return -2; #if TRACE_COKE - printf("Coke_CanDispense: Flushing"); + printf("Coke_CanDispense: Flushing\n"); #endif // Flush the input buffer @@ -82,7 +82,7 @@ int Coke_CanDispense(int UNUSED(User), int Item) ret = 0; do { #if TRACE_COKE - printf("Coke_DoDispense: sending 'd7'"); + printf("Coke_DoDispense: sending 'd7'\n"); #endif write(giCoke_SerialFD, "d7\r\n", 4); } while( WaitForColon() && ret++ < 3 ); @@ -95,7 +95,7 @@ int Coke_CanDispense(int UNUSED(User), int Item) // TODO: Handle "not ok" response to D7 #if TRACE_COKE - printf("Coke_CanDispense: sending 's%i'", Item); + printf("Coke_CanDispense: sending 's%i'\n", Item); #endif // Ask the coke machine @@ -103,7 +103,7 @@ int Coke_CanDispense(int UNUSED(User), int Item) write(giCoke_SerialFD, tmp, 4); #if TRACE_COKE - printf("Coke_CanDispense: reading response"); + printf("Coke_CanDispense: reading response\n"); #endif // Read from the machine (ignoring empty lines) while( (ret = ReadLine(sizeof(tmp)-1, tmp)) == 0 ); @@ -123,7 +123,7 @@ int Coke_CanDispense(int UNUSED(User), int Item) } #if TRACE_COKE - printf("Coke_CanDispense: wait for the prompt again"); + printf("Coke_CanDispense: wait for the prompt again\n"); #endif // Eat rest of response @@ -167,7 +167,7 @@ int Coke_DoDispense(int UNUSED(User), int Item) return -2; #if TRACE_COKE - printf("Coke_DoDispense: flushing input"); + printf("Coke_DoDispense: flushing input\n"); #endif // Flush the input buffer { @@ -179,13 +179,13 @@ int Coke_DoDispense(int UNUSED(User), int Item) i = 0; do { #if TRACE_COKE - printf("Coke_DoDispense: sending 'd7'"); + printf("Coke_DoDispense: sending 'd7'\n"); #endif write(Item, "d7\r\n", 4); } while( WaitForColon() && i++ < 3 ); #if TRACE_COKE - printf("Coke_DoDispense: sending 'd%i'", Item); + printf("Coke_DoDispense: sending 'd%i'\n", Item); #endif // Dispense sprintf(tmp, "d%i\r\n", Item); @@ -206,7 +206,7 @@ int Coke_DoDispense(int UNUSED(User), int Item) WaitForColon(); // Eat up rest of response #if TRACE_COKE - printf("Coke_DoDispense: done"); + printf("Coke_DoDispense: done\n"); #endif // TODO: Regex diff --git a/src/server/server.c b/src/server/server.c index 92e26ff..a2279fd 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -68,6 +68,7 @@ void _SendUserInfo(tClient *Client, int UserID); void Server_Cmd_USERADD(tClient *Client, char *Args); void Server_Cmd_USERFLAGS(tClient *Client, char *Args); // --- Helpers --- +void Debug(tClient *Client, const char *Format, ...); int Server_int_ParseFlags(tClient *Client, const char *Str, int *Mask, int *Value); int sendf(int Socket, const char *Format, ...); @@ -341,7 +342,7 @@ void Server_Cmd_USER(tClient *Client, char *Args) // Debug! if( giDebugLevel ) - printf("Client %i authenticating as '%s'\n", Client->ID, Args); + Debug("Authenticating as '%s'", Args); // Save username if(Client->Username) @@ -402,7 +403,7 @@ void Server_Cmd_AUTOAUTH(tClient *Client, char *Args) // Check if trusted if( !Client->bIsTrusted ) { if(giDebugLevel) - printf("Client %i: Untrusted client attempting to AUTOAUTH\n", Client->ID); + Debug("Untrusted client attempting to AUTOAUTH"); sendf(Client->Socket, "401 Untrusted\n"); return ; } @@ -411,7 +412,7 @@ void Server_Cmd_AUTOAUTH(tClient *Client, char *Args) Client->UID = Bank_GetAcctByName( Args ); if( Client->UID < 0 ) { if(giDebugLevel) - printf("Client %i: Unknown user '%s'\n", Client->ID, Args); + Debug("Unknown user '%s'", Args); sendf(Client->Socket, "401 Auth Failure\n"); return ; } @@ -426,7 +427,7 @@ void Server_Cmd_AUTOAUTH(tClient *Client, char *Args) Client->bIsAuthed = 1; if(giDebugLevel) - printf("Client %i: Auto authenticated as '%s' (%i)\n", Client->ID, Args, Client->UID); + Debug("Auto authenticated as '%s' (%i)", Args, Client->UID); sendf(Client->Socket, "200 Auth OK\n"); } @@ -1030,6 +1031,9 @@ void Server_Cmd_USERINFO(tClient *Client, char *Args) space = strchr(user, ' '); if(space) *space = '\0'; + if( giDebugLevel ) + Debug(Client, "User Info '%s'", user); + // Get recipient uid = Bank_GetAcctByName(user); if( uid == -1 ) { @@ -1153,6 +1157,16 @@ void Server_Cmd_USERFLAGS(tClient *Client, char *Args) } // --- INTERNAL HELPERS --- +void Debug(tClient *Client, const char *Format, ...) +{ + va_list args; + printf("%010lli [%i] ", time(NULL), Client->ID); + va_start(args, Format); + vprintf(NULL, 0, Format, args); + va_end(args); + printf("\n"); +} + int sendf(int Socket, const char *Format, ...) { va_list args;