Fixing coke handler and login (a nice cleanup)
[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          int    (*CanDispense)(int User, int ID);
56          int    (*DoDispense)(int User, int ID);
57 };
58
59 // === GLOBALS ===
60 extern tItem    *gaItems;
61 extern int      giNumItems;
62 extern tHandler *gaHandlers[];
63 extern int      giNumHandlers;
64 extern int      giDebugLevel;
65
66 // === FUNCTIONS ===
67 // --- Helpers --
68 extern void     CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
69 extern int      RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
70
71 // --- Dispense ---
72 extern int      DispenseItem(int User, tItem *Item);
73
74 // --- Logging ---
75 extern void     Log_Error(const char *Format, ...);
76 extern void     Log_Info(const char *Format, ...);
77
78 // --- Cokebank Functions ---
79 extern int      Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason);
80 extern int      GetBalance(int User);
81 extern char     *GetUserName(int User);
82 extern int      GetUserID(const char *Username);
83
84 #endif

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