#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
+#include <fcntl.h> // O_*
#include <string.h>
#include <limits.h>
#include <stdarg.h>
return ;
}
-#if 0
+ //
if( gbServer_RunInBackground )
{
+ int newin, newout, newerr;
int pid = fork();
if( pid == -1 ) {
fprintf(stderr, "ERROR: Unable to fork\n");
// Parent, quit
exit(0);
}
- // In child, sort out stdin/stdout
- reopen(0, "/dev/null", O_READ);
- reopen(1, gsServer_LogFile, O_CREAT|O_APPEND);
- reopen(2, gsServer_ErrorLog, O_CREAT|O_APPEND);
+ // In child
+ // - Sort out stdin/stdout
+ newin = open("/dev/null", O_RDONLY);
+ newout = open(gsServer_LogFile, O_CREAT|O_APPEND, 0644);
+ newerr = open(gsServer_ErrorLog, O_CREAT|O_APPEND, 0644);
+ dup2(newin, 0);
+ dup2(newout, 1);
+ dup2(newerr, 2);
}
-#endif
// Listen
if( listen(giServer_Socket, MAX_CONNECTION_QUEUE) < 0 ) {
}
// Get UID
- Client->UID = Bank_GetAcctByName( username );
+ Client->UID = Bank_GetAcctByName( username, 0 );
if( Client->UID < 0 ) {
if(giDebugLevel)
Debug(Client, "Unknown user '%s'", username);
}
// Set id
- Client->EffectiveUID = Bank_GetAcctByName(username);
+ Client->EffectiveUID = Bank_GetAcctByName(username, 0);
if( Client->EffectiveUID == -1 ) {
sendf(Client->Socket, "404 User not found\n");
return ;
}
}
+ // KNOWN HACK: Naming a slot 'dead' disables it
+ if( strcmp(Item->Name, "dead") == 0 )
+ status = "sold"; // Another status?
+
sendf(Client->Socket,
"202 Item %s:%i %s %i %s\n",
Item->Handler->Name, Item->ID, status, Item->Price, Item->Name
return ;
}
- uid = Bank_GetAcctByName(username);
+ uid = Bank_GetAcctByName(username, 0);
if( uid == -1 ) {
sendf(Client->Socket, "404 Unknown user\n");
return ;
}
// Get recipient
- uid = Bank_GetAcctByName(recipient);
+ uid = Bank_GetAcctByName(recipient, 0);
if( uid == -1 ) {
sendf(Client->Socket, "404 Invalid target user\n");
return ;
}
// Get recipient
- uid = Bank_GetAcctByName(user);
+ uid = Bank_GetAcctByName(user, 0);
if( uid == -1 ) {
sendf(Client->Socket, "404 Invalid user\n");
return ;
}
// Get recipient
- uid = Bank_GetAcctByName(user);
+ uid = Bank_GetAcctByName(user, 0);
if( uid == -1 ) {
sendf(Client->Socket, "404 Invalid user\n");
return ;
if( giDebugLevel ) Debug(Client, "User Info '%s'", user);
// Get recipient
- uid = Bank_GetAcctByName(user);
+ uid = Bank_GetAcctByName(user, 0);
if( giDebugLevel >= 2 ) Debug(Client, "uid = %i", uid);
if( uid == -1 ) {
}
// Get UID
- uid = Bank_GetAcctByName(username);
+ uid = Bank_GetAcctByName(username, 0);
if( uid == -1 ) {
sendf(Client->Socket, "404 User '%s' not found\n", username);
return ;
sendf(Client->Socket, "407 Invalid price set\n");
}
- // Update the item
- free(item->Name);
- item->Name = strdup(description);
- item->Price = price;
-
- // Update item file
- Items_UpdateFile();
-
- // Return OK
- sendf(Client->Socket, "200 Item updated\n");
+ switch( DispenseUpdateItem( Client->UID, item, description, price ) )
+ {
+ case 0:
+ // Return OK
+ sendf(Client->Socket, "200 Item updated\n");
+ break;
+ default:
+ break;
+ }
}
// --- INTERNAL HELPERS ---