1 /***************************************************************************
2     begin       : Mon Mar 01 2004
3     copyright   : (C) 2018 by Martin Preuss
4     email       : martin@libchipcard.de
5 
6  ***************************************************************************
7  *          Please see toplevel file COPYING for license details           *
8  ***************************************************************************/
9 
10 
11 #ifndef AH_JOB_L_H
12 #define AH_JOB_L_H
13 
14 typedef struct AH_JOB AH_JOB;
15 
16 #define AH_JOB_FLAGS_IGNOREACCOUNTS       0x00000400
17 #define AH_JOB_FLAGS_SIGNSEQONE           0x00000800
18 #define AH_JOB_FLAGS_IGNORE_ERROR         0x00001000
19 #define AH_JOB_FLAGS_NOITAN               0x00002000
20 #define AH_JOB_FLAGS_TANUSED              0x00004000
21 #define AH_JOB_FLAGS_NOSYSID              0x00008000
22 #define AH_JOB_FLAGS_NEEDCRYPT            0x00010000
23 #define AH_JOB_FLAGS_NEEDSIGN             0x00020000
24 #define AH_JOB_FLAGS_ATTACHABLE           0x00040000
25 #define AH_JOB_FLAGS_SINGLE               0x00080000
26 #define AH_JOB_FLAGS_DLGJOB               0x00100000
27 #define AH_JOB_FLAGS_CRYPT                0x00200000
28 #define AH_JOB_FLAGS_SIGN                 0x00400000
29 #define AH_JOB_FLAGS_MULTIMSG             0x00800000
30 #define AH_JOB_FLAGS_HASATTACHPOINT       0x01000000
31 #define AH_JOB_FLAGS_HASMOREMSGS          0x02000000
32 #define AH_JOB_FLAGS_HASWARNINGS          0x04000000
33 #define AH_JOB_FLAGS_HASERRORS            0x08000000
34 #define AH_JOB_FLAGS_PROCESSED            0x10000000
35 #define AH_JOB_FLAGS_COMMITTED            0x20000000
36 #define AH_JOB_FLAGS_NEEDTAN              0x40000000
37 #define AH_JOB_FLAGS_OUTBOX               0x80000000
38 
39 #define AH_JOB_TANVER_1_4 0x14
40 #define AH_JOB_TANVER_1_3 0x13
41 
42 
43 #include <gwenhywfar/misc.h>
44 #include <gwenhywfar/list2.h>
45 #include <gwenhywfar/inherit.h>
46 
47 GWEN_LIST_FUNCTION_DEFS(AH_JOB, AH_Job);
48 GWEN_INHERIT_FUNCTION_DEFS(AH_JOB);
49 GWEN_LIST2_FUNCTION_DEFS(AH_JOB, AH_Job);
50 void AH_Job_List2_FreeAll(AH_JOB_LIST2 *jl);
51 
52 #include "hbci_l.h"
53 #include "result_l.h"
54 #include <aqhbci/aqhbci.h>
55 
56 #include <aqbanking/backendsupport/user.h>
57 #include <aqbanking/types/message.h>
58 #include <aqbanking/banking_be.h>
59 
60 #include <gwenhywfar/db.h>
61 
62 
63 typedef enum {
64   AH_JobStatusUnknown=0,
65   AH_JobStatusToDo,
66   AH_JobStatusEnqueued,
67   AH_JobStatusEncoded,
68   AH_JobStatusSent,
69   AH_JobStatusAnswered,
70   AH_JobStatusError,
71 
72   AH_JobStatusAll=255
73 } AH_JOB_STATUS;
74 
75 
76 /** @name Prototypes For Virtual Functions
77  *
78  */
79 /*@{*/
80 typedef int (*AH_JOB_PROCESS_FN)(AH_JOB *j,
81                                  AB_IMEXPORTER_CONTEXT *ctx);
82 typedef int (*AH_JOB_COMMIT_FN)(AH_JOB *j, int doLock);
83 typedef int (*AH_JOB_PREPARE_FN)(AH_JOB *j);
84 
85 typedef int (*AH_JOB_ADDCHALLENGEPARAMS_FN)(AH_JOB *j, int hkTanVer, GWEN_DB_NODE *dbMethod);
86 
87 typedef int (*AH_JOB_GETLIMITS_FN)(AH_JOB *j, AB_TRANSACTION_LIMITS **pLimits);
88 typedef int (*AH_JOB_HANDLECOMMAND_FN)(AH_JOB *j, const AB_TRANSACTION *t);
89 typedef int (*AH_JOB_HANDLERESULTS_FN)(AH_JOB *j, AB_IMEXPORTER_CONTEXT *ctx);
90 
91 
92 /**
93  * This function is called on multi-message jobs and should return:
94  * <ul>
95  *   <li>0 if it is sure that no message is to follow</li>
96  *   <li>1 if there might be more message (will be checked by AqHBCI)</li>
97  *   <li>any other value (indicating an error)</li>
98  * </ul>
99  */
100 typedef int (*AH_JOB_NEXTMSG_FN)(AH_JOB *j);
101 
102 /*@}*/
103 
104 
105 /** @name Constructors, Destructors
106  *
107  */
108 /*@{*/
109 AH_JOB *AH_Job_new(const char *name,
110                    AB_PROVIDER *pro,
111                    AB_USER *u,
112                    AB_ACCOUNT *acc,
113                    int jobVersion);
114 void AH_Job_free(AH_JOB *j);
115 void AH_Job_Attach(AH_JOB *j);
116 /*@}*/
117 
118 
119 /** @name Informational Functions
120  *
121  */
122 /*@{*/
123 const char *AH_Job_GetName(const AH_JOB *j);
124 const char *AH_Job_GetDescription(const AH_JOB *j);
125 
126 const char *AH_Job_GetCode(const AH_JOB *j);
127 void AH_Job_SetCode(AH_JOB *j, const char *s);
128 
129 const char *AH_Job_GetResponseName(const AH_JOB *j);
130 void AH_Job_SetResponseName(AH_JOB *j, const char *s);
131 
132 int AH_Job_GetMinSignatures(const AH_JOB *j);
133 int AH_Job_GetSecurityProfile(const AH_JOB *j);
134 int AH_Job_GetSecurityClass(const AH_JOB *j);
135 int AH_Job_GetJobsPerMsg(const AH_JOB *j);
136 
137 int AH_Job_GetChallengeClass(const AH_JOB *j);
138 void AH_Job_SetChallengeClass(AH_JOB *j, int i);
139 
140 AB_USER *AH_Job_GetUser(const AH_JOB *j);
141 
142 GWEN_DB_NODE *AH_Job_GetParams(const AH_JOB *j);
143 GWEN_DB_NODE *AH_Job_GetArguments(const AH_JOB *j);
144 GWEN_DB_NODE *AH_Job_GetResponses(const AH_JOB *j);
145 
146 unsigned int AH_Job_GetMsgNum(const AH_JOB *j);
147 const char *AH_Job_GetDialogId(const AH_JOB *j);
148 
149 AH_JOB_STATUS AH_Job_GetStatus(const AH_JOB *j);
150 const char *AH_Job_StatusName(AH_JOB_STATUS st);
151 
152 void AH_Job_AddSigner(AH_JOB *j, const char *s);
153 int AH_Job_AddSigners(AH_JOB *j, const GWEN_STRINGLIST *sl);
154 
155 int AH_Job_HasWarnings(const AH_JOB *j);
156 int AH_Job_HasErrors(const AH_JOB *j);
157 
158 AH_RESULT_LIST *AH_Job_GetSegResults(const AH_JOB *j);
159 AH_RESULT_LIST *AH_Job_GetMsgResults(const AH_JOB *j);
160 
161 AB_MESSAGE_LIST *AH_Job_GetMessages(const AH_JOB *j);
162 
163 /**
164  * Add command to job for later reference.
165  */
166 void AH_Job_AddCommand(AH_JOB *j, AB_TRANSACTION *t);
167 AB_TRANSACTION_LIST2 *AH_Job_GetCommandList(const AH_JOB *j);
168 
169 /*@}*/
170 
171 
172 /** @name Virtual Functions
173  *
174  */
175 /*@{*/
176 int AH_Job_Process(AH_JOB *j, AB_IMEXPORTER_CONTEXT *ctx);
177 int AH_Job_Commit(AH_JOB *j, int doLock);
178 
179 /**
180  * Check whether the results for this job contain warning 3920. In this
181  * case the result must be commited.
182  * @return 0 if there is no such result, !=0 otherwise
183  */
184 int AH_Job_HasItanResult(const AH_JOB *j);
185 
186 
187 
188 int AH_Job_HasResultWithCode(const AH_JOB *j, int code);
189 
190 
191 /**
192  * You can use this from the Commit function of the inheriting class to
193  * additionally let the job do some basic stuff (like saving UPD, BPD,
194  * messages etc).
195  */
196 int AH_Job_CommitSystemData(AH_JOB *j, int doLock);
197 
198 
199 /**
200  * You can use this from the Process function of the inheriting class to
201  * additionally let the job do some basic stuff (like catching UPD, BPD,
202  * messages etc).
203  */
204 int AH_Job_DefaultProcessHandler(AH_JOB *j);
205 
206 /**
207  * You can use this from the Commit function of the inheriting class.
208  * It calls @ref AH_Job_CommitSystemData.
209  */
210 int AH_Job_DefaultCommitHandler(AH_JOB *j, int doLock);
211 
212 int AH_Job_Prepare(AH_JOB *j);
213 
214 /**
215  * This function lets the job add its challenge parameters itself.
216  * Unfortunately this is needed, because the ZKA decided to make FinTS
217  * even more complicated than it already is :-/
218  * For some HKTAN versions the list of parameters differs from others.
219  */
220 int AH_Job_AddChallengeParams(AH_JOB *j, int hkTanVer, GWEN_DB_NODE *dbMethod);
221 
222 /**
223  * Get transaction limits for a given job.
224  */
225 int AH_Job_GetLimits(AH_JOB *j, AB_TRANSACTION_LIMITS **pLimits);
226 
227 /**
228  * Handle a given command transaction.
229  * The transaction contains the command and parameters for a given job.
230  * The job should test the given transaction. If the transaction is not acceptable an
231  * error code should be returned.
232  * If zero is returned the given transaction is taken over by the job (otherwise it is not).
233  */
234 int AH_Job_HandleCommand(AH_JOB *j, const AB_TRANSACTION *t);
235 
236 /**
237  * Let the job transfer remaining results to the imExporter context.
238  * Some jobs already add their results to the context upon @ref AH_Job_Process.
239  * This function is for those jobs which don't.
240  */
241 int AH_Job_HandleResults(AH_JOB *j, AB_IMEXPORTER_CONTEXT *ctx);
242 
243 /*@}*/
244 
245 
246 /** @name Setters For Virtual Functions
247  *
248  */
249 /*@{*/
250 void AH_Job_SetProcessFn(AH_JOB *j, AH_JOB_PROCESS_FN f);
251 void AH_Job_SetCommitFn(AH_JOB *j, AH_JOB_COMMIT_FN f);
252 void AH_Job_SetNextMsgFn(AH_JOB *j, AH_JOB_NEXTMSG_FN f);
253 void AH_Job_SetPrepareFn(AH_JOB *j, AH_JOB_PREPARE_FN f);
254 void AH_Job_SetAddChallengeParamsFn(AH_JOB *j, AH_JOB_ADDCHALLENGEPARAMS_FN f);
255 
256 void AH_Job_SetGetLimitsFn(AH_JOB *j, AH_JOB_GETLIMITS_FN f);
257 void AH_Job_SetHandleCommandFn(AH_JOB *j, AH_JOB_HANDLECOMMAND_FN f);
258 void AH_Job_SetHandleResultsFn(AH_JOB *j, AH_JOB_HANDLERESULTS_FN f);
259 
260 
261 /*@}*/
262 
263 
264 void AH_Job_Dump(const AH_JOB *j, FILE *f, unsigned int insert);
265 
266 const GWEN_STRINGLIST *AH_Job_GetLogs(const AH_JOB *j);
267 
268 
269 uint32_t AH_Job_GetFirstSegment(const AH_JOB *j);
270 void AH_Job_SetFirstSegment(AH_JOB *j, uint32_t i);
271 
272 uint32_t AH_Job_GetLastSegment(const AH_JOB *j);
273 void AH_Job_SetLastSegment(AH_JOB *j, uint32_t i);
274 
275 int AH_Job_HasSegment(const AH_JOB *j, int seg);
276 
277 /**
278  * Takes over ownership of the given group.
279  */
280 void AH_Job_AddResponse(AH_JOB *j, GWEN_DB_NODE *db);
281 
282 void AH_Job_SetStatus(AH_JOB *j, AH_JOB_STATUS st);
283 
284 GWEN_XMLNODE *AH_Job_GetXmlNode(const AH_JOB *j);
285 
286 
287 const GWEN_STRINGLIST *AH_Job_GetSigners(const AH_JOB *j);
288 
289 int AH_Job_PrepareNextMessage(AH_JOB *j);
290 
291 void AH_Job_SetMsgNum(AH_JOB *j, unsigned int i);
292 void AH_Job_SetDialogId(AH_JOB *j, const char *s);
293 
294 uint32_t AH_Job_GetFlags(const AH_JOB *j);
295 void AH_Job_SetFlags(AH_JOB *j, uint32_t f);
296 void AH_Job_AddFlags(AH_JOB *j, uint32_t f);
297 void AH_Job_SubFlags(AH_JOB *j, uint32_t f);
298 
299 
300 uint32_t AH_Job_GetId(const AH_JOB *j);
301 void AH_Job_SetId(AH_JOB *j, uint32_t i);
302 
303 AH_HBCI *AH_Job_GetHbci(const AH_JOB *j);
304 AB_BANKING *AH_Job_GetBankingApi(const AH_JOB *j);
305 
306 
307 const char *AH_Job_GetExpectedSigner(const AH_JOB *j);
308 void AH_Job_SetExpectedSigner(AH_JOB *j, const char *s);
309 const char *AH_Job_GetExpectedCrypter(const AH_JOB *j);
310 void AH_Job_SetExpectedCrypter(AH_JOB *j, const char *s);
311 
312 const char *AH_Job_GetUsedTan(const AH_JOB *j);
313 void AH_Job_SetUsedTan(AH_JOB *j, const char *s);
314 
315 void AH_Job_Log(AH_JOB *j, GWEN_LOGGER_LEVEL ll, const char *txt);
316 
317 
318 GWEN_STRINGLIST *AH_Job_GetChallengeParams(const AH_JOB *j);
319 void AH_Job_AddChallengeParam(AH_JOB *j, const char *s);
320 void AH_Job_ClearChallengeParams(AH_JOB *j);
321 int AH_Job_GetChallengeClass(const AH_JOB *j);
322 void AH_Job_SetChallengeClass(AH_JOB *j, int i);
323 
324 void AH_Job_ValueToChallengeString(const AB_VALUE *v, GWEN_BUFFER *buf);
325 
326 /**
327  * This function adds all BPD groups of the job with the given name and for
328  * which XML descriptions are available. So basically, the user can choose
329  * a job version from the returned list.
330  */
331 int AH_Job_SampleBpdVersions(const char *name,
332                              AB_USER *u,
333                              GWEN_DB_NODE *dbResult);
334 
335 int AH_Job_GetMaxVersionUpUntil(const char *name, AB_USER *u, int maxVersion);
336 
337 int AH_Job_GetSegmentVersion(const AH_JOB *j);
338 
339 
340 int AH_Job_GetTransferCount(AH_JOB *j);
341 void AH_Job_IncTransferCount(AH_JOB *j);
342 int AH_Job_GetMaxTransfers(AH_JOB *j);
343 void AH_Job_SetMaxTransfers(AH_JOB *j, int i);
344 
345 AB_TRANSACTION_LIST *AH_Job_GetTransferList(const AH_JOB *j);
346 void AH_Job_AddTransfer(AH_JOB *j, AB_TRANSACTION *t);
347 AB_TRANSACTION *AH_Job_GetFirstTransfer(const AH_JOB *j);
348 
349 AB_TRANSACTION_COMMAND AH_Job_GetSupportedCommand(const AH_JOB *j);
350 void AH_Job_SetSupportedCommand(AH_JOB *j, AB_TRANSACTION_COMMAND tc);
351 
352 
353 /**
354  * This is a simple implementation of the GetLimits-callback which just creates
355  * an empty transaction limits object with just the command field set.
356  */
357 int AH_Job_GetLimits_EmptyLimits(AH_JOB *j, AB_TRANSACTION_LIMITS **pLimits);
358 
359 
360 /**
361  * Implementation of AH_Job_HandleCommand which just accepts the command
362  * and does nothing else.
363  */
364 int AH_Job_HandleCommand_Accept(AH_JOB *j, const AB_TRANSACTION *t);
365 
366 
367 /**
368  * Implementation of AH_Job_HandleResults which does nothing.
369  */
370 int AH_Job_HandleResults_Empty(AH_JOB *j, AB_IMEXPORTER_CONTEXT *ctx);
371 
372 
373 
374 void AH_Job_ReadAccountDataSeg(AB_ACCOUNT *acc, GWEN_DB_NODE *dbAccountData);
375 
376 
377 
378 AB_PROVIDER *AH_Job_GetProvider(const AH_JOB *j);
379 
380 
381 /* Get job from list by id */
382 AH_JOB *AH_Job_List_GetById(AH_JOB_LIST *jl, uint32_t id);
383 
384 
385 void AH_Job_SetStatusOnCommands(AH_JOB *j, AB_TRANSACTION_STATUS status);
386 
387 
388 #endif /* AH_JOB_L_H */
389 
390 
391 
392 
393