Restructured code into src/<module>
[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 // === CONSTANTS ===
13 #define DEFAULT_CONFIG_FILE     "/etc/opendispense/main.cfg"
14 #define DEFAULT_ITEM_FILE       "/etc/opendispense/items.cfg"
15
16 // === HELPER MACROS ===
17 #define _EXPSTR(x)      #x
18 #define EXPSTR(x)       _EXPSTR(x)
19
20 // === STRUCTURES ===
21 typedef struct sItem    tItem;
22 typedef struct sUser    tUser;
23 typedef struct sConfigItem      tConfigItem;
24 typedef struct sHandler tHandler;
25
26 struct sItem
27 {
28         char    *Name;  //!< Display Name
29          int    Price;  //!< Price
30         
31         tHandler        *Handler;       //!< Handler for the item
32         short   ID;     //!< Item ID
33 };
34
35 struct sUser
36 {
37          int    ID;             //!< User ID (LDAP ID)
38          int    Balance;        //!< Balance in cents
39          int    Bytes;  //!< Traffic Usage
40         char    Name[]; //!< Username
41 };
42
43 struct sConfigItem
44 {
45         char    *Name;
46         char    *Value;
47 };
48
49 struct sHandler
50 {
51         char    *Name;
52          int    (*Init)(int NConfig, tConfigItem *Config);
53          int    (*CanDispense)(int User, int ID);
54          int    (*DoDispense)(int User, int ID);
55 };
56
57 // === GLOBALS ===
58 extern tItem    *gaItems;
59 extern int      giNumItems;
60 extern tHandler *gaHandlers[];
61 extern int      giNumHandlers;
62 extern int      giDebugLevel;
63
64 // === FUNCTIONS ===
65 // --- Logging ---
66 extern void     Log_Error(const char *Format, ...);
67 extern void     Log_Info(const char *Format, ...);
68
69 // --- Cokebank Functions ---
70 extern int      Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason);
71 extern int      GetBalance(int User);
72 extern char     *GetUserName(int User);
73 extern int      GetUserID(const char *Username);
74 extern int      GetUserAuth(const char *Username, const char *Password);
75
76 #endif

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