1 /***************************************************************************
2  begin       : Mon Mar 01 2004
3  copyright   : (C) 2018 by Martin Preuss
4  email       : martin@libchipcard.de
5 
6  ***************************************************************************
7  * This file is part of the project "AqBanking".                           *
8  * Please see toplevel file COPYING of that project for license details.   *
9  ***************************************************************************/
10 
11 /** @file banking_be.h
12  * @short This file is used by provider backends.
13  */
14 
15 
16 #ifndef AQBANKING_BANKING_BE_H
17 #define AQBANKING_BANKING_BE_H
18 
19 #include <gwenhywfar/db.h>
20 
21 #include <aqbanking/banking.h>
22 #include <aqbanking/backendsupport/provider_be.h>
23 #include <aqbanking/backendsupport/swiftdescr.h>
24 
25 
26 #include <gwenhywfar/httpsession.h>
27 #include <gwenhywfar/ct.h>
28 #include <gwenhywfar/plugindescr.h>
29 
30 
31 #define AB_CFG_GROUP_BACKENDS   "backends"
32 #define AB_CFG_GROUP_BANKINFO   "bankinfo"
33 #define AB_CFG_GROUP_IMEXPORTER "imexporter"
34 
35 #define AB_CFG_GROUP_USERS      "users"
36 #define AB_CFG_GROUP_ACCOUNTS   "accounts"
37 
38 #define AB_PM_LIBNAME           "aqbanking"
39 #define AB_PM_SYSCONFDIR        "sysconfdir"
40 #define AB_PM_DATADIR           "datadir"
41 #define AB_PM_WIZARDDIR         "wizarddir"
42 #define AB_PM_LOCALEDIR         "localedir"
43 
44 
45 
46 /** @addtogroup G_AB_BE_BANKING
47  */
48 /*@{*/
49 
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 
56 /** @name Functions Used by Backends And Wizards
57  *
58  */
59 /*@{*/
60 
61 /**
62  * Returns the list of global data folders. In most cases this is something
63  * like $PREFIX/share/. Plugins are required to use the folders
64  * returned here + "aqbanking" when searching for their specific data instead
65  * of using the compile time fixed values. This way it is easier under
66  * windows to find data.
67  */
68 GWEN_STRINGLIST *AB_Banking_GetGlobalDataDirs(void);
69 
70 
71 GWEN_STRINGLIST *AB_Banking_GetGlobalSysconfDirs(void);
72 
73 
74 /**
75  * Loads the given provider and initializes it.
76  * Only after calling this function the provider can be used.
77  * You need to call @ref AB_Banking_EndUseProvider() if you're done.
78  *
79  * @return 0 if ok, error code otherwise
80  *
81  * @param ab pointer to the AB_BANKING object (needs to be initialized, i.e. @ref AB_Banking_Init called).
82  * @param modname (e.g. "aqhbci")
83  */
84 AB_PROVIDER *AB_Banking_BeginUseProvider(AB_BANKING *ab, const char *modname);
85 
86 /**
87  * Call this as soon as the provider isn't actually needed anymore.
88  * This probably unloads the plugin, at least it is deinitialized.
89  *
90  * @return 0 if ok, error code otherwise
91  *
92  * @param ab pointer to the AB_BANKING object (needs to be initialized, i.e. @ref AB_Banking_Init called).
93  * @param pro pointer to provider object returned by @ref AB_Banking_BeginUseProvider
94  *
95  */
96 int AB_Banking_EndUseProvider(AB_BANKING *ab, AB_PROVIDER *pro);
97 
98 
99 /**
100  * Find the path of a given datafile for an im-/exporter.
101  *
102  * @return 0 if okay, error code otherwise
103  * @param ab pointer to the AB_BANKING object (needs to be initialized, i.e. @ref AB_Banking_Init called).
104  * @param imExpName name of the im-/exporter
105  * @param fileNAme to look for
106  * @param fullPathBuffer buffer to receive the complete path to the given file (if found)
107  */
108 int AB_Banking_FindDataFileForImExporter(AB_BANKING *ab, const char *imExpName, const char *fileName,
109                                          GWEN_BUFFER *fullPathBuffer);
110 
111 
112 /**
113  * List all data files for the given im-/exporter matching the given file mask.
114  *
115  * @return stringlist containing one entry for each file (absolute path)
116  * @param ab pointer to the AB_BANKING object (needs to be initialized, i.e. @ref AB_Banking_Init called).
117  * @param imExpName name of the im-/exporter
118  * @param fileMask mask fore the file name to match (wildcards and jokers allowed, e.g. "*.xml")
119  */
120 GWEN_STRINGLIST *AB_Banking_ListDataFilesForImExporter(AB_BANKING *ab, const char *imExpName, const char *fileMask);
121 
122 
123 /*@}*/
124 
125 
126 
127 /** @name Administration of Crypt Token List
128  *
129  */
130 /*@{*/
131 int AB_Banking_GetCryptToken(AB_BANKING *ab,
132                              const char *tname,
133                              const char *cname,
134                              GWEN_CRYPT_TOKEN **pCt);
135 
136 void AB_Banking_ClearCryptTokenList(AB_BANKING *ab);
137 
138 int AB_Banking_CheckCryptToken(AB_BANKING *ab,
139                                GWEN_CRYPT_TOKEN_DEVICE devt,
140                                GWEN_BUFFER *typeName,
141                                GWEN_BUFFER *tokenName);
142 
143 /*@}*/
144 
145 
146 /**
147  * Get a named unique id.
148  * Previously there was only one source for unique ids which was used for everything, fastly increasing that id.
149  * Now new id counters can be incremented separately.
150  * @param ab pointer to AB_BANKING object
151  * @param idName name of the id to get (e.g. "account", "user", "job" etc)
152  * @param startAtStdUniqueId if the given id is zero and this var is !=0 start with the current standard uniqueId
153  */
154 int AB_Banking_GetNamedUniqueId(AB_BANKING *ab, const char *idName, int startAtStdUniqueId);
155 
156 
157 int AB_Banking_GetCert(AB_BANKING *ab,
158                        const char *url,
159                        const char *defaultProto,
160                        int defaultPort,
161                        uint32_t *httpFlags,
162                        uint32_t pid);
163 
164 
165 /**
166  * This copies the name of the folder for AqBanking's backend data into
167  * the given GWEN_Buffer.
168  *
169  * An example path would be "/home/USER/.aqbanking/backends/aqhbci/data".
170  *
171  * @return 0 if ok, error code otherwise (see @ref GWEN_ERROR)
172  * @param ab pointer to the AB_BANKING object
173  * @param name name of the online banking provider (e.g. "aqhbci")
174  * @param buf buffer to append the path name to
175  */
176 int AB_Banking_GetProviderUserDataDir(const AB_BANKING *ab,
177                                       const char *name,
178                                       GWEN_BUFFER *buf);
179 
180 
181 /**
182  * Returns the name of the user folder for application data.
183  * Normally this is something like "/home/me/.aqbanking/apps".
184  * Your application may choose to create folders below this one to store
185  * user data. If you only add AqBanking to an existing program to add
186  * home banking support you will most likely use your own folders and thus
187  * won't need this function.
188  * @return 0 if ok, error code otherwise (see @ref AB_ERROR)
189  * @param ab pointer to the AB_BANKING object
190  * @param buf GWEN_BUFFER to append the path name to
191  */
192 int AB_Banking_GetAppUserDataDir(const AB_BANKING *ab, GWEN_BUFFER *buf);
193 
194 
195 
196 /** @name Account Spec Management Functions
197  *
198  */
199 /*@{*/
200 
201 int AB_Banking_ReadAccountSpec(const AB_BANKING *ab, uint32_t uniqueId, AB_ACCOUNT_SPEC **pAccountSpec);
202 int AB_Banking_WriteAccountSpec(AB_BANKING *ab, const AB_ACCOUNT_SPEC *accountSpec);
203 int AB_Banking_DeleteAccountSpec(AB_BANKING *ab, uint32_t uid);
204 
205 /*@}*/
206 
207 
208 
209 
210 
211 /**
212  * @return 0 if there are some groups, error code otherwise (especially GWEN_ERROR_PARTIAL if some groups couldn't be read
213  *           and GWEN_ERROR_NOT_FOUND if there no groups found).
214  * @param ab AQBANKING object
215  * @param groupName name of the config group
216  * @param uidField name of an integer variable in the config groups which MUST NOT be zero (NULL to skip this test)
217  * @param matchVar name of a variable in the config groups whose value must match matchVal (NULL to skip this test)
218  * @param matchVal value to match the matchVar variable (NULL for empty value)
219  * @param pDb pointer to a variable to receive the newly created DB, each subgroup contains a config group
220  */
221 int AB_Banking_ReadConfigGroups(const AB_BANKING *ab,
222                                 const char *groupName,
223                                 const char *uidField,
224                                 const char *matchVar,
225                                 const char *matchVal,
226                                 GWEN_DB_NODE **pDb);
227 
228 
229 
230 
231 /**
232  * This function tries to fill missing fields in a given transaction.
233  * It tries to fill missing data from the given local account (IBAN, BIC, owner name etc).
234  *
235  * @param ab pointer to the AB_BANKING object
236  * @param localAccount account from which local info is copied (may be NULL)
237  * @param t transaction to fill
238  */
239 void AB_Banking_FillGapsInTransaction(AB_BANKING *ab, AB_ACCOUNT *localAccount, AB_TRANSACTION *t);
240 
241 
242 /**
243  * Get a list of SWIFT descriptors supported by the given imExporter.
244  *
245  * a SWIFT descriptor is an object holding the elements of a SWIFT format name (e.g. "pain.001.002.03").
246  * Normally you would use "xml" for the name of the imexporter.
247  */
248 AB_SWIFT_DESCR_LIST *AB_Banking_GetSwiftDescriptorsForImExporter(AB_BANKING *ab, const char *imExporterName);
249 
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 
255 /*@}*/
256 
257 
258 #endif /* AQBANKING_BANKING_BE_H */
259 
260 
261 
262 
263 
264 
265