User enumeration implemented
[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 #include "../cokebank.h"
14
15 // === CONSTANTS ===
16 #define DEFAULT_CONFIG_FILE     "/etc/opendispense/main.cfg"
17 #define DEFAULT_ITEM_FILE       "/etc/opendispense/items.cfg"
18
19 // === HELPER MACROS ===
20 #define _EXPSTR(x)      #x
21 #define EXPSTR(x)       _EXPSTR(x)
22
23 // === STRUCTURES ===
24 typedef struct sItem    tItem;
25 typedef struct sUser    tUser;
26 typedef struct sConfigItem      tConfigItem;
27 typedef struct sHandler tHandler;
28
29 struct sItem
30 {
31         char    *Name;  //!< Display Name
32          int    Price;  //!< Price
33         
34         tHandler        *Handler;       //!< Handler for the item
35         short   ID;     //!< Item ID
36 };
37
38 struct sUser
39 {
40          int    ID;             //!< User ID (LDAP ID)
41          int    Balance;        //!< Balance in cents
42          int    Bytes;  //!< Traffic Usage
43         char    Name[]; //!< Username
44 };
45
46 struct sConfigItem
47 {
48         char    *Name;
49         char    *Value;
50 };
51
52 struct sHandler
53 {
54         char    *Name;
55          int    (*Init)(int NConfig, tConfigItem *Config);
56         /**
57          * \brief Check if an item can be dispensed
58          * \return Boolean Failure
59          */
60          int    (*CanDispense)(int User, int ID);
61          int    (*DoDispense)(int User, int ID);
62 };
63
64 // === GLOBALS ===
65 extern tItem    *gaItems;
66 extern int      giNumItems;
67 extern tHandler *gaHandlers[];
68 extern int      giNumHandlers;
69 extern int      giDebugLevel;
70
71 // === FUNCTIONS ===
72 // --- Helpers --
73 extern void     CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
74 extern int      RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
75 extern int      InitSerial(const char *Path, int BaudRate);
76 extern char     *mkstr(const char *Format, ...);
77
78 // --- Dispense ---
79 extern int      DispenseItem(int User, tItem *Item);
80 extern int      DispenseGive(int SrcUser, int DestUser, int Ammount, const char *ReasonGiven);
81 extern int      DispenseAdd(int User, int ByUser, int Ammount, const char *ReasonGiven);
82
83 // --- Logging ---
84 extern void     Log_Error(const char *Format, ...);
85 extern void     Log_Info(const char *Format, ...);
86
87 #endif

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