// Read from the machine (ignoring empty lines)
while( (ret = ReadLine(sizeof(tmp)-1, tmp)) == 0 );
printf("ret = %i, tmp = '%s'\n", ret, tmp);
- if( tmp[0] == ':' ) {
+ // Read back-echoed lines
+ while( tmp[0] == ':' || tmp[1] != 'l' )
+ {
ret = ReadLine(sizeof(tmp)-1, tmp);
printf("ret = %i, tmp = '%s'\n", ret, tmp);
}
int Coke_DoDispense(int UNUSED(User), int Item)
{
char tmp[32];
- int i, ret;
+ int ret;
// Sanity please
if( Item < 0 || Item > 6 ) return -1;
sprintf(tmp, "d%i\r\n", Item);
write(giCoke_SerialFD, tmp, 4);
- // Read empty lines
- while( (ret = ReadLine(sizeof(tmp)-1, tmp)) == -1 );
- if( ret == -1 ) return -1;
- // Read d%i
- while( tmp[0] == ':' ) {
+ // Read empty lines and echo-backs
+ do {
ret = ReadLine(sizeof(tmp)-1, tmp);
if( ret == -1 ) return -1;
- }
- // Get status
- ret = ReadLine(sizeof(tmp)-1, tmp);
- if( ret == -1 ) return -1;
+ #if TRACE_COKE
+ printf("Coke_DoDispense: read %i '%s'\n", ret, tmp);
+ #endif
+ } while( ret == 0 || tmp[0] == ':' || tmp[0] == 'd' );
WaitForColon(); // Eat up rest of response
int ret;
ret = regexec(regex, string, nMatches, matches, 0);
+ if( ret == REG_NOMATCH ) {
+ return -1;
+ }
if( ret ) {
size_t len = regerror(ret, regex, NULL, 0);
char errorStr[len];
space = strchr(user, ' ');
if(space) *space = '\0';
- if( giDebugLevel )
- Debug(Client, "User Info '%s'", user);
+ if( giDebugLevel ) Debug(Client, "User Info '%s'", user);
// Get recipient
uid = Bank_GetAcctByName(user);
+
+ if( giDebugLevel >= 2 ) Debug(Client, "uid = %i", uid);
if( uid == -1 ) {
- sendf(Client->Socket, "404 Invalid user");
+ sendf(Client->Socket, "404 Invalid user\n");
return ;
}