Cleanup work (much needed)
[tpg/opendispense2.git] / src / server / common.h
1 /*
2  * OpenDispense2
3  *
4  * This code is published under the terms of the Acess licence.
5  * See the file COPYING for details.
6  *
7  * common.h - Core Header
8  */
9 #ifndef _COMMON_H_
10 #define _COMMON_H_
11
12 #include <regex.h>
13
14 // === CONSTANTS ===
15 #define DEFAULT_CONFIG_FILE     "/etc/opendispense/main.cfg"
16 #define DEFAULT_ITEM_FILE       "/etc/opendispense/items.cfg"
17
18 // === HELPER MACROS ===
19 #define _EXPSTR(x)      #x
20 #define EXPSTR(x)       _EXPSTR(x)
21
22 // === STRUCTURES ===
23 typedef struct sItem    tItem;
24 typedef struct sUser    tUser;
25 typedef struct sConfigItem      tConfigItem;
26 typedef struct sHandler tHandler;
27
28 struct sItem
29 {
30         char    *Name;  //!< Display Name
31          int    Price;  //!< Price
32         
33         tHandler        *Handler;       //!< Handler for the item
34         short   ID;     //!< Item ID
35 };
36
37 struct sUser
38 {
39          int    ID;             //!< User ID (LDAP ID)
40          int    Balance;        //!< Balance in cents
41          int    Bytes;  //!< Traffic Usage
42         char    Name[]; //!< Username
43 };
44
45 struct sConfigItem
46 {
47         char    *Name;
48         char    *Value;
49 };
50
51 struct sHandler
52 {
53         char    *Name;
54          int    (*Init)(int NConfig, tConfigItem *Config);
55         /**
56          * \brief Check if an item can be dispensed
57          * \return Boolean Failure
58          */
59          int    (*CanDispense)(int User, int ID);
60          int    (*DoDispense)(int User, int ID);
61 };
62
63 // === GLOBALS ===
64 extern tItem    *gaItems;
65 extern int      giNumItems;
66 extern tHandler *gaHandlers[];
67 extern int      giNumHandlers;
68 extern int      giDebugLevel;
69
70 // === FUNCTIONS ===
71 // --- Helpers --
72 extern void     CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
73 extern int      RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
74 extern int      InitSerial(const char *Path, int BaudRate);
75 extern char     *mkstr(const char *Format, ...);
76
77 // --- Dispense ---
78 extern int      DispenseItem(int User, tItem *Item);
79
80 // --- Logging ---
81 extern void     Log_Error(const char *Format, ...);
82 extern void     Log_Info(const char *Format, ...);
83
84 // --- Cokebank Functions ---
85 extern int      Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason);
86 extern int      GetBalance(int User);
87 extern char     *GetUserName(int User);
88 extern int      GetUserID(const char *Username);
89
90 #endif

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