Fixing crappy code in coke handler, debug in others
[tpg/opendispense2.git] / src / server / main.c
index b612f6f..0692d6a 100644 (file)
 #include <unistd.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <stdarg.h>
+#include <syslog.h>
+#include "../cokebank.h"
 
 // === IMPORTS ===
-extern void    Init_Cokebank(const char *Argument);    // cokebank.c
 extern void    Init_Handlers(void);
 extern void    Load_Itemlist(void);
 extern void    Server_Start(void);
 extern int     giServer_Port;
-extern char*   gsItemListFile;
-extern char*   gsCoke_SerialPort;
-extern char*   gsSnack_SerialPort;
+extern char    *gsItemListFile;
+extern char    *gsCoke_SerialPort;
+extern char    *gsSnack_SerialPort;
 
 // === GLOBALS ===
  int   giDebugLevel = 0;
@@ -81,7 +83,10 @@ int main(int argc, char *argv[])
        
        signal(SIGINT, sigint_handler);
        
-       Init_Cokebank(gsCokebankPath);
+       openlog("odispense2", 0, LOG_LOCAL4);
+       
+       if( Bank_Initialise(gsCokebankPath) )
+               return -1;
 
        Init_Handlers();
 
@@ -98,6 +103,9 @@ int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *match
         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];
@@ -151,3 +159,26 @@ int InitSerial(const char *File, int BaudRate)
 }
 
 
+/**
+ * \brief Create a formatted heap string
+ */
+char *mkstr(const char *Format, ...)
+{
+       va_list args;
+        int    len;
+       char    *ret;
+
+       va_start(args, Format);
+       len = vsnprintf(NULL, 0, Format, args);
+       va_end(args);
+
+       ret = malloc( len + 1 );
+       if(!ret)        return NULL;
+
+       va_start(args, Format);
+       vsprintf(ret, Format, args);
+       va_end(args);
+       
+       return ret;
+}
+

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