ae244a22c8157c1bb7f4f5ba801994c900aa6ebf
[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
22 /**
23  * \brief Account iterator opaque structure
24  *
25  * Opaque structure for account iterators returned by Bank_Iterator
26  * and used by Bank_IteratorNext and Bank_DelIterator
27  */
28 typedef struct sAcctIterator    tAcctIterator;
29
30 enum eBank_ItFlags
31 {
32         BANK_ITFLAG_MINBALANCE  = 0x01,
33         BANK_ITFLAG_MAXBALANCE  = 0x02,
34         BANK_ITFLAG_SEENBEFORE  = 0x04,
35         BANK_ITFLAG_SEENAFTER   = 0x08,
36         
37         BANK_ITFLAG_SORT_NONE   = 0x000,
38         BANK_ITFLAG_SORT_NAME   = 0x100,
39         BANK_ITFLAG_SORT_BAL    = 0x200,
40         BANK_ITFLAG_SORT_UNIXID = 0x300,
41         BANK_ITFLAG_SORT_LASTSEEN       = 0x400,
42         BANK_ITFLAG_SORTMASK    = 0x700,
43         BANK_ITFLAG_REVSORT     = 0x800
44 };
45
46 /**
47  * \brief User flag values
48  *
49  * User flag values used by Bank_GetFlags and Bank_SetFlags
50  */
51 enum eCokebank_Flags {  
52         USER_FLAG_COKE          = 0x01, //!< User is a coke member (can do coke accounting)
53         USER_FLAG_WHEEL         = 0x02, //!< User is a wheel member (can create, delete and lock accounts)
54         USER_FLAG_DOORGROUP     = 0x04, //!< User is in the door group (can open the clubroom door)
55         USER_FLAG_INTERNAL      = 0x40, //!< Account is internal (cannot be authenticated, no lower balance limit)
56         USER_FLAG_DISABLED      = 0x80  //!< Account is disabled (no transactions allowed)
57 };
58
59 // --- Cokebank Functions ---
60 /**
61  * \brief Initialise the cokebank
62  * \param Argument      Cokebank argument specified in the dispense config file (typically the database path)
63  * \return Boolean Failure
64  */
65 extern int      Bank_Initialise(const char *Argument);
66
67 /**
68  * \brief Transfer money from one account to another
69  * \param SourceUser    UID (from \a Bank_GetUserID) to take the money from
70  * \param DestUser      UID (from \a Bank_GetUserID) give money to
71  * \param Ammount       Amount of money (in cents) to transfer
72  * \param Reason        Reason for the transfer
73  */
74 extern int      Bank_Transfer(int SourceAcct, int DestAcct, int Ammount, const char *Reason);
75 /**
76  * \brief Get flags on an account
77  * \param AcctID        UID to get flags from
78  * \return Flag set as defined in eCokebank_Flags
79  */
80 extern int      Bank_GetFlags(int AcctID);
81 /**
82  * \brief Set an account's flags
83  * \param AcctID        UID to set flags on
84  * \param Mask  Mask of flags changed
85  * \param Value Final value of changed flags
86  */
87 extern int      Bank_SetFlags(int AcctID, int Mask, int Value);
88 /**
89  * \brief Get an account's balance
90  * \param AcctID        Account to query
91  */
92 extern int      Bank_GetBalance(int AcctID);
93 /**
94  * \brief Get the name associated with an account
95  * \return Heap string
96  */
97 extern char     *Bank_GetAcctName(int AcctID);
98 /**
99  * \brief Get an account ID from a passed name
100  */
101 extern int      Bank_GetAcctByName(const char *Name);
102 /**
103  * \brief Create a new account
104  * \param Username      Name for the new account (if NULL, an anoymous account is created)
105  * \return ID of the new account
106  */
107 extern int      Bank_CreateAcct(const char *Name);
108
109 /**
110  * \brief Create an account iterator
111  * \param FlagMask      Mask of account flags to check
112  * \param FlagValues    Wanted values for checked flags
113  * \param Flags Specifies the operation of \a MinMaxBalance and \a Timestamp  (\see eBank_ItFlags)
114  * \param MinMaxBalance Mininum/Maximum balance
115  * \param LastSeen      Latest/Earliest last seen time
116  * \return Pointer to an iterator across the selected data set
117  */
118 extern tAcctIterator    *Bank_Iterator(int FlagMask, int FlagValues,
119         int Flags, int MinMaxBalance, time_t LastSeen);
120
121 /**
122  * \brief Get the current entry in the iterator and move to the next
123  * \param It    Iterator returned by Bank_Iterator
124  * \return Accoun ID, or -1 for end of list
125  */
126 extern int      Bank_IteratorNext(tAcctIterator *It);
127
128 /**
129  * \brief Free an allocated iterator
130  * \param It    Iterator returned by Bank_Iterator
131  */
132 extern void     Bank_DelIterator(tAcctIterator *It);
133
134 /**
135  * \brief Validates a user's authentication
136  * \param Salt  Salt given to the client for hashing the password
137  * \param Username      Username used
138  * \param Password      Password sent by the client
139  * \return User ID
140  */
141 extern int      Bank_GetUserAuth(const char *Salt, const char *Username, const char *Password);
142
143 /**
144  * \brief Get an account ID from a MIFARE card ID
145  * \param CardID        MIFARE card ID
146  * \return Account ID
147  */
148 extern int      Bank_GetAcctByCard(const char *CardID);
149
150 /**
151  * \brief Add a card to an account
152  * \param AcctID        Account ID
153  * \param CardID        MIFARE card ID
154  * \return Boolean failure
155  * \retval 0    Success
156  * \retval 1    Bad account ID
157  * \retval 2    Card in use
158  */
159 extern int      Bank_AddAcctCard(int AcctID, const char *CardID);
160
161 // ---
162 // Server provided helper functions
163 // ---
164 /**
165  * \brief Create a formatted string on the heap
166  * \param Format        Format string
167  * \return Heap string
168  */
169 extern char     *mkstr(const char *Format, ...);
170
171 #endif

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