3 * UCC (University [of WA] Computer Club) Electronic Accounting System
5 * cokebank.h - Coke-Bank common definitions
7 * This file is licenced under the 3-clause BSD Licence. See the file COPYING
12 * \brief Coke Bank API Documentation
19 #define COKEBANK_SALES_ACCT ">sales" //!< Sales made into
20 #define COKEBANK_DEBT_ACCT ">liability" //!< Credit taken out of
21 #define COKEBANK_FREE_ACCT ">freeitems" //!< ODay drink costs taken out of
24 * \brief Account iterator opaque structure
26 * Opaque structure for account iterators returned by Bank_Iterator
27 * and used by Bank_IteratorNext and Bank_DelIterator
29 typedef struct sAcctIterator tAcctIterator;
32 * \brief Iterator for a collection of items
34 typedef struct sItemIterator tItemIterator;
37 * \brief Flag values for the \a Flags parameter to Bank_Iterator
41 BANK_ITFLAG_MINBALANCE = 0x01, //!< Balance value is Minium Balance
42 BANK_ITFLAG_MAXBALANCE = 0x02, //!< Balance value is Maximum Balance (higher priority)
43 BANK_ITFLAG_SEENAFTER = 0x04, //!< Last seen value is lower bound
44 BANK_ITFLAG_SEENBEFORE = 0x08, //!< Last seen value is upper bound (higher priority)
46 BANK_ITFLAG_SORT_NONE = 0x000, //!< No sorting (up to the implementation)
47 BANK_ITFLAG_SORT_NAME = 0x100, //!< Sort alphabetically ascending by name
48 BANK_ITFLAG_SORT_BAL = 0x200, //!< Sort by balance, ascending
49 BANK_ITFLAG_SORT_UNIXID = 0x300, //!< Sort by UnixUID (TODO: Needed?)
50 BANK_ITFLAG_SORT_LASTSEEN = 0x400, //!< Sort by last seen time (ascending)
51 BANK_ITFLAG_SORTMASK = 0x700, //!< Sort type mask
52 BANK_ITFLAG_REVSORT = 0x800 //!< Sort descending instead
56 * \brief User flag values
58 * User flag values used by Bank_GetFlags and Bank_SetFlags
60 enum eCokebank_Flags {
61 USER_FLAG_COKE = 0x01, //!< User is a coke member (can do coke accounting)
62 USER_FLAG_ADMIN = 0x02, //!< User is a administrator (can create, delete and lock accounts)
63 USER_FLAG_DOORGROUP = 0x04, //!< User is in the door group (can open the clubroom door)
64 USER_FLAG_INTERNAL = 0x40, //!< Account is internal (cannot be authenticated, no lower balance limit)
65 USER_FLAG_DISABLED = 0x80 //!< Account is disabled (no transactions allowed)
68 // --- Cokebank Functions ---
70 * \brief Initialise the cokebank
71 * \param Argument Cokebank argument specified in the dispense config file (typically the database path)
72 * \return Boolean Failure
74 extern int Bank_Initialise(const char *Argument);
77 * \brief Transfer money from one account to another
78 * \param SourceAcct UID (from \a Bank_GetUserID) to take the money from
79 * \param DestAcct UID (from \a Bank_GetUserID) give money to
80 * \param Ammount Amount of money (in cents) to transfer
81 * \param Reason Reason for the transfer
83 extern int Bank_Transfer(int SourceAcct, int DestAcct, int Ammount, const char *Reason);
85 * \brief Get flags on an account
86 * \param AcctID UID to get flags from
87 * \return Flag set as defined in eCokebank_Flags
89 extern int Bank_GetFlags(int AcctID);
91 * \brief Set an account's flags
92 * \param AcctID UID to set flags on
93 * \param Mask Mask of flags changed
94 * \param Value Final value of changed flags
96 extern int Bank_SetFlags(int AcctID, int Mask, int Value);
98 * \brief Get an account's balance
99 * \param AcctID Account to query
101 extern int Bank_GetBalance(int AcctID);
103 * \brief Get the name associated with an account
104 * \return Heap string
106 extern char *Bank_GetAcctName(int AcctID);
108 * \brief Get an account ID from a passed name
109 * \param Name Name to search for
110 * \return ID of the account, or -1 if not found
112 extern int Bank_GetAcctByName(const char *Name);
114 * \brief Create a new account
115 * \param Name Name for the new account (if NULL, an anoymous account is created)
116 * \return ID of the new account
118 extern int Bank_CreateAcct(const char *Name);
121 * \brief Create an account iterator
122 * \param FlagMask Mask of account flags to check
123 * \param FlagValues Wanted values for checked flags
124 * \param Flags Specifies the operation of \a MinMaxBalance and \a Timestamp (\see eBank_ItFlags)
125 * \param MinMaxBalance Mininum/Maximum balance
126 * \param LastSeen Latest/Earliest last seen time
127 * \return Pointer to an iterator across the selected data set
129 extern tAcctIterator *Bank_Iterator(int FlagMask, int FlagValues,
130 int Flags, int MinMaxBalance, time_t LastSeen);
133 * \brief Get the current entry in the iterator and move to the next
134 * \param It Iterator returned by Bank_Iterator
135 * \return Accoun ID, or -1 for end of list
137 extern int Bank_IteratorNext(tAcctIterator *It);
140 * \brief Free an allocated iterator
141 * \param It Iterator returned by Bank_Iterator
143 extern void Bank_DelIterator(tAcctIterator *It);
146 * \brief Validates a user's authentication
147 * \param Salt Salt given to the client for hashing the password
148 * \param Username Username used
149 * \param Password Password sent by the client
152 extern int Bank_GetUserAuth(const char *Salt, const char *Username, const char *Password);
155 * \brief Get an account ID from a MIFARE card ID
156 * \param CardID MIFARE card ID
159 extern int Bank_GetAcctByCard(const char *CardID);
162 * \brief Add a card to an account
163 * \param AcctID Account ID
164 * \param CardID MIFARE card ID
165 * \return Boolean failure
167 * \retval 1 Bad account ID
168 * \retval 2 Card in use
170 extern int Bank_AddAcctCard(int AcctID, const char *CardID);
173 // Server provided helper functions
176 * \brief Create a formatted string on the heap
177 * \param Format Format string
178 * \return Heap string
180 extern char *mkstr(const char *Format, ...);
183 * \brief Dispense log access
184 * \note Try not to over-use, only stuff that matters should go in here
186 extern void Log_Info(const char *Format, ...);