4 * This code is published under the terms of the Acess licence.
5 * See the file COPYING for details.
7 * common.h - Core Header
13 #include "../cokebank.h"
16 #define DEFAULT_CONFIG_FILE "/etc/opendispense/main.cfg"
17 #define DEFAULT_ITEM_FILE "/etc/opendispense/items.cfg"
19 // === HELPER MACROS ===
21 #define EXPSTR(x) _EXPSTR(x)
23 #define UNUSED(var) unused__##var __attribute__((__unused__))
25 #define ASSERT(cnd) do{if(!(cnd)){fprintf(stderr, "ASSERT failed at "__FILE__":"EXPSTR(__LINE__)" - "EXPSTR(cnd)"\n");exit(-1);}}while(0)
28 typedef struct sItem tItem;
29 typedef struct sUser tUser;
30 typedef struct sConfigItem tConfigItem;
31 typedef struct sHandler tHandler;
35 char *Name; //!< Display Name
37 int bHidden; //!< Hidden item?
38 int bDisabledi; //!< Disabled Item
40 tHandler *Handler; //!< Handler for the item
41 short ID; //!< Item ID
46 int ID; //!< User ID (LDAP ID)
47 int Balance; //!< Balance in cents
48 int Bytes; //!< Traffic Usage
49 char Name[]; //!< Username
61 int (*Init)(int NConfig, tConfigItem *Config);
63 * \brief Check if an item can be dispensed
64 * \return Boolean Failure
66 int (*CanDispense)(int User, int ID);
67 int (*DoDispense)(int User, int ID);
71 extern tItem *gaItems;
72 extern int giNumItems;
73 extern tHandler *gaHandlers[];
74 extern int giNumHandlers;
75 extern int giDebugLevel;
76 extern int gbNoCostMode;
79 extern void Items_UpdateFile(void);
82 extern void StartPeriodicThread(void);
83 extern void AddPeriodicFunction(void (*Fcn)(void));
84 extern void CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
85 extern int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
86 extern int InitSerial(const char *Path, int BaudRate);
87 extern char *mkstr(const char *Format, ...);
90 extern int DispenseItem(int ActualUser, int User, tItem *Item);
91 extern int DispenseRefund(int ActualUser, int DestUser, tItem *Item, int OverridePrice);
92 extern int DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, const char *ReasonGiven);
93 extern int DispenseAdd(int ActualUser, int User, int Ammount, const char *ReasonGiven);
94 extern int DispenseSet(int ActualUser, int User, int Balance, const char *ReasonGiven);
95 extern int DispenseDonate(int ActualUser, int User, int Ammount, const char *ReasonGiven);
96 extern int DispenseUpdateItem(int User, tItem *Item, const char *NewName, int NewPrice);
99 extern void Log_Error(const char *Format, ...);
100 extern void Log_Info(const char *Format, ...);
102 // --- Config Database ---
103 extern void Config_ParseFile(const char *Filename);
104 extern void Config_AddValue(const char *Key, const char *Value);
105 extern int Config_GetValueCount(const char *KeyName);
106 extern const char *Config_GetValue(const char *KeyName, int Index);
107 extern int Config_GetValue_Bool(const char *KeyName, int Index);
108 extern int Config_GetValue_Int(const char *KeyName, int Index);