Fixes to bugs pointed by [BOB]
[tpg/opendispense2.git] / src / cokebank.h
1 /*
2  * OpenDispense 2 
3  * UCC (University [of WA] Computer Club) Electronic Accounting System
4  *
5  * cokebank.h - Coke-Bank common definitions
6  *
7  * This file is licenced under the 3-clause BSD Licence. See the file COPYING
8  * for full details.
9  */
10 /**
11  * \file cokebank.h
12  * \brief Coke Bank API Documentation
13  */
14 #ifndef _COKEBANK_H_
15 #define _COKEBANK_H_
16
17 #include <stdlib.h>
18
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
22
23 /**
24  * \brief Account iterator opaque structure
25  *
26  * Opaque structure for account iterators returned by Bank_Iterator
27  * and used by Bank_IteratorNext and Bank_DelIterator
28  */
29 typedef struct sAcctIterator    tAcctIterator;
30
31 /**
32  * \brief Flag values for the \a Flags parameter to Bank_Iterator
33  */
34 enum eBank_ItFlags
35 {
36         BANK_ITFLAG_MINBALANCE  = 0x01, //!< Balance value is Minium Balance
37         BANK_ITFLAG_MAXBALANCE  = 0x02, //!< Balance value is Maximum Balance (higher priority)
38         BANK_ITFLAG_SEENAFTER   = 0x04, //!< Last seen value is lower bound
39         BANK_ITFLAG_SEENBEFORE  = 0x08, //!< Last seen value is upper bound (higher priority)
40         
41         BANK_ITFLAG_SORT_NONE   = 0x000,        //!< No sorting (up to the implementation)
42         BANK_ITFLAG_SORT_NAME   = 0x100,        //!< Sort alphabetically ascending by name
43         BANK_ITFLAG_SORT_BAL    = 0x200,        //!< Sort by balance, ascending
44         BANK_ITFLAG_SORT_UNIXID = 0x300,        //!< Sort by UnixUID (TODO: Needed?)
45         BANK_ITFLAG_SORT_LASTSEEN = 0x400,      //!< Sort by last seen time (ascending)
46         BANK_ITFLAG_SORTMASK    = 0x700,        //!< Sort type mask
47         BANK_ITFLAG_REVSORT     = 0x800 //!< Sort descending instead
48 };
49
50 /**
51  * \brief User flag values
52  *
53  * User flag values used by Bank_GetFlags and Bank_SetFlags
54  */
55 enum eCokebank_Flags {  
56         USER_FLAG_COKE          = 0x01, //!< User is a coke member (can do coke accounting)
57         USER_FLAG_ADMIN         = 0x02, //!< User is a administrator (can create, delete and lock accounts)
58         USER_FLAG_DOORGROUP     = 0x04, //!< User is in the door group (can open the clubroom door)
59         USER_FLAG_INTERNAL      = 0x40, //!< Account is internal (cannot be authenticated, no lower balance limit)
60         USER_FLAG_DISABLED      = 0x80  //!< Account is disabled (no transactions allowed)
61 };
62
63 // --- Cokebank Functions ---
64 /**
65  * \brief Initialise the cokebank
66  * \param Argument      Cokebank argument specified in the dispense config file (typically the database path)
67  * \return Boolean Failure
68  */
69 extern int      Bank_Initialise(const char *Argument);
70
71 /**
72  * \brief Transfer money from one account to another
73  * \param SourceAcct    UID (from \a Bank_GetUserID) to take the money from
74  * \param DestAcct      UID (from \a Bank_GetUserID) give money to
75  * \param Ammount       Amount of money (in cents) to transfer
76  * \param Reason        Reason for the transfer
77  */
78 extern int      Bank_Transfer(int SourceAcct, int DestAcct, int Ammount, const char *Reason);
79 /**
80  * \brief Get flags on an account
81  * \param AcctID        UID to get flags from
82  * \return Flag set as defined in eCokebank_Flags
83  */
84 extern int      Bank_GetFlags(int AcctID);
85 /**
86  * \brief Set an account's flags
87  * \param AcctID        UID to set flags on
88  * \param Mask  Mask of flags changed
89  * \param Value Final value of changed flags
90  */
91 extern int      Bank_SetFlags(int AcctID, int Mask, int Value);
92 /**
93  * \brief Get an account's balance
94  * \param AcctID        Account to query
95  */
96 extern int      Bank_GetBalance(int AcctID);
97 /**
98  * \brief Get the name associated with an account
99  * \return Heap string
100  */
101 extern char     *Bank_GetAcctName(int AcctID);
102 /**
103  * \brief Get an account ID from a passed name
104  * \param Name  Name to search for
105  * \return ID of the account, or -1 if not found
106  */
107 extern int      Bank_GetAcctByName(const char *Name);
108 /**
109  * \brief Create a new account
110  * \param Name  Name for the new account (if NULL, an anoymous account is created)
111  * \return ID of the new account
112  */
113 extern int      Bank_CreateAcct(const char *Name);
114
115 /**
116  * \brief Create an account iterator
117  * \param FlagMask      Mask of account flags to check
118  * \param FlagValues    Wanted values for checked flags
119  * \param Flags Specifies the operation of \a MinMaxBalance and \a Timestamp  (\see eBank_ItFlags)
120  * \param MinMaxBalance Mininum/Maximum balance
121  * \param LastSeen      Latest/Earliest last seen time
122  * \return Pointer to an iterator across the selected data set
123  */
124 extern tAcctIterator    *Bank_Iterator(int FlagMask, int FlagValues,
125         int Flags, int MinMaxBalance, time_t LastSeen);
126
127 /**
128  * \brief Get the current entry in the iterator and move to the next
129  * \param It    Iterator returned by Bank_Iterator
130  * \return Accoun ID, or -1 for end of list
131  */
132 extern int      Bank_IteratorNext(tAcctIterator *It);
133
134 /**
135  * \brief Free an allocated iterator
136  * \param It    Iterator returned by Bank_Iterator
137  */
138 extern void     Bank_DelIterator(tAcctIterator *It);
139
140 /**
141  * \brief Validates a user's authentication
142  * \param Salt  Salt given to the client for hashing the password
143  * \param Username      Username used
144  * \param Password      Password sent by the client
145  * \return User ID
146  */
147 extern int      Bank_GetUserAuth(const char *Salt, const char *Username, const char *Password);
148
149 /**
150  * \brief Get an account ID from a MIFARE card ID
151  * \param CardID        MIFARE card ID
152  * \return Account ID
153  */
154 extern int      Bank_GetAcctByCard(const char *CardID);
155
156 /**
157  * \brief Add a card to an account
158  * \param AcctID        Account ID
159  * \param CardID        MIFARE card ID
160  * \return Boolean failure
161  * \retval 0    Success
162  * \retval 1    Bad account ID
163  * \retval 2    Card in use
164  */
165 extern int      Bank_AddAcctCard(int AcctID, const char *CardID);
166
167 // ---
168 // Server provided helper functions
169 // ---
170 /**
171  * \brief Create a formatted string on the heap
172  * \param Format        Format string
173  * \return Heap string
174  */
175 extern char     *mkstr(const char *Format, ...);
176
177 /**
178  * \brief Dispense log access
179  * \note Try not to over-use, only stuff that matters should go in here
180  */
181 extern void     Log_Info(const char *Format, ...);
182
183 #endif

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