All - Rework config API to allow default/optional values
[tpg/opendispense2.git] / src / server / server.c
index e76c459..b09c794 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "common.h"
+#include "../common/config.h"
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -147,7 +148,7 @@ void Server_Start(void)
        gaServer_TrustedHosts = malloc(giServer_NumTrustedHosts * sizeof(*gaServer_TrustedHosts));
        for( int i = 0; i < giServer_NumTrustedHosts; i ++ )
        {
-               const char      *addr = Config_GetValue("trusted_host", i);
+               const char      *addr = Config_GetValue_Idx("trusted_host", i);
                
                if( inet_aton(addr, &gaServer_TrustedHosts[i]) == 0 ) {
                        fprintf(stderr, "Invalid IP address '%s'\n", addr);
@@ -1165,17 +1166,15 @@ void Server_Cmd_SET(tClient *Client, char *Args)
                return ;
        }
 
+       int origBalance, rv;
        // Do give
-       switch( DispenseSet(Client->UID, uid, iAmmount, reason) )
+       switch( rv = DispenseSet(Client->UID, uid, iAmmount, reason, &origBalance) )
        {
        case 0:
-               sendf(Client->Socket, "200 Add OK\n");
-               return ;
-       case 2:
-               sendf(Client->Socket, "402 Poor Guy\n");
+               sendf(Client->Socket, "200 Add OK (%i)\n", origBalance);
                return ;
        default:
-               sendf(Client->Socket, "500 Unknown error\n");
+               sendf(Client->Socket, "500 Unknown error (%i)\n", rv);
                return ;
        }
 }

UCC git Repository :: git.ucc.asn.au