1 /***************************************************************************
2  begin       : Tue Apr 20 2010
3  copyright   : (C) 2018 by Martin Preuss
4  email       : martin@aqbanking.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 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14 
15 
16 
17 #include "dlg_ddvcard_p.h"
18 #include "aqbanking/i18n_l.h"
19 
20 #include <aqbanking/dialogs/dlg_selectbankinfo.h>
21 #include <aqbanking/backendsupport/user.h>
22 #include <aqbanking/banking_be.h>
23 
24 #include "aqhbci/banking/user.h"
25 #include "aqhbci/banking/provider.h"
26 #include "aqhbci/banking/provider_online.h"
27 #include "dlg_ddvcard_special_l.h"
28 
29 #include <gwenhywfar/gwenhywfar.h>
30 #include <gwenhywfar/misc.h>
31 #include <gwenhywfar/pathmanager.h>
32 #include <gwenhywfar/debug.h>
33 #include <gwenhywfar/gui.h>
34 
35 
36 #define PAGE_BEGIN     0
37 #define PAGE_BANK      1
38 #define PAGE_USER      2
39 #define PAGE_CREATE    3
40 #define PAGE_END       4
41 
42 
43 #define DIALOG_MINWIDTH  400
44 #define DIALOG_MINHEIGHT 200
45 
46 
47 #define MAX_CONTEXT_ID_ENTRIES 64
48 
49 
GWEN_INHERIT(GWEN_DIALOG,AH_DDVCARD_DIALOG)50 GWEN_INHERIT(GWEN_DIALOG, AH_DDVCARD_DIALOG)
51 
52 
53 
54 
55 GWEN_DIALOG *AH_DdvCardDialog_new(AB_PROVIDER *pro, GWEN_CRYPT_TOKEN *ct)
56 {
57   GWEN_DIALOG *dlg;
58   AH_DDVCARD_DIALOG *xdlg;
59   GWEN_BUFFER *fbuf;
60   int rv;
61 
62   dlg=GWEN_Dialog_new("ah_setup_ddvcard");
63   GWEN_NEW_OBJECT(AH_DDVCARD_DIALOG, xdlg);
64   GWEN_INHERIT_SETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg, xdlg,
65                        AH_DdvCardDialog_FreeData);
66   GWEN_Dialog_SetSignalHandler(dlg, AH_DdvCardDialog_SignalHandler);
67 
68   /* get path of dialog description file */
69   fbuf=GWEN_Buffer_new(0, 256, 0, 1);
70   rv=GWEN_PathManager_FindFile(AB_PM_LIBNAME, AB_PM_DATADIR,
71                                "aqbanking/backends/aqhbci/dialogs/dlg_ddvcard.dlg",
72                                fbuf);
73   if (rv<0) {
74     DBG_INFO(AQHBCI_LOGDOMAIN, "Dialog description file not found (%d).", rv);
75     GWEN_Buffer_free(fbuf);
76     GWEN_Dialog_free(dlg);
77     return NULL;
78   }
79 
80   /* read dialog from dialog description file */
81   rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(fbuf));
82   if (rv<0) {
83     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d).", rv);
84     GWEN_Buffer_free(fbuf);
85     GWEN_Dialog_free(dlg);
86     return NULL;
87   }
88   GWEN_Buffer_free(fbuf);
89 
90   xdlg->provider=pro;
91   xdlg->banking=AB_Provider_GetBanking(pro);
92   xdlg->cryptToken=ct;
93   xdlg->contextList=GWEN_Crypt_Token_Context_List_new();
94 
95   if (1) {
96     uint32_t idList[MAX_CONTEXT_ID_ENTRIES];
97     uint32_t idCount;
98     uint32_t i;
99 
100     if (!GWEN_Crypt_Token_IsOpen(ct)) {
101       rv=GWEN_Crypt_Token_Open(ct, 0, 0);
102       if (rv<0) {
103         DBG_ERROR(AQHBCI_LOGDOMAIN, "Error opening token (%d)", rv);
104         GWEN_Gui_ShowError(I18N("Error"), I18N("Could not contact card. Maybe removed? (%d)"), rv);
105         GWEN_Dialog_free(dlg);
106         return NULL;
107       }
108     }
109 
110     idCount=MAX_CONTEXT_ID_ENTRIES;
111     rv=GWEN_Crypt_Token_GetContextIdList(ct, idList, &idCount, 0);
112     if (rv<0) {
113       DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not read context id list");
114       GWEN_Dialog_free(dlg);
115       GWEN_Gui_ShowError(I18N("Error"), I18N("Could not read context id list from card (%d)"), rv);
116       return NULL;
117     }
118 
119     for (i=0; i<idCount; i++) {
120       const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
121 
122       ctx=GWEN_Crypt_Token_GetContext(ct, idList[i], 0);
123       if (ctx) {
124         GWEN_CRYPT_TOKEN_CONTEXT *nctx;
125 
126         nctx=GWEN_Crypt_Token_Context_dup(ctx);
127         GWEN_Crypt_Token_Context_List_Add(nctx, xdlg->contextList);
128         DBG_INFO(AQHBCI_LOGDOMAIN, "Added context %08x", idList[i]);
129       }
130     }
131   } /* for */
132 
133   /* preset */
134   xdlg->hbciVersion=210;
135   xdlg->flags=0;
136 
137   /* done */
138   return dlg;
139 }
140 
141 
142 
AH_DdvCardDialog_FreeData(void * bp,void * p)143 void GWENHYWFAR_CB AH_DdvCardDialog_FreeData(void *bp, void *p)
144 {
145   AH_DDVCARD_DIALOG *xdlg;
146 
147   xdlg=(AH_DDVCARD_DIALOG *) p;
148   GWEN_Crypt_Token_Context_List_free(xdlg->contextList);
149   free(xdlg->bankCode);
150   free(xdlg->bankName);
151   free(xdlg->userName);
152   free(xdlg->userId);
153   free(xdlg->customerId);
154   free(xdlg->peerId);
155   GWEN_FREE_OBJECT(xdlg);
156 }
157 
158 
159 
AH_DdvCardDialog_GetUser(const GWEN_DIALOG * dlg)160 AB_USER *AH_DdvCardDialog_GetUser(const GWEN_DIALOG *dlg)
161 {
162   AH_DDVCARD_DIALOG *xdlg;
163 
164   assert(dlg);
165   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
166   assert(xdlg);
167 
168   return xdlg->user;
169 }
170 
171 
172 
AH_DdvCardDialog_GetCryptToken(const GWEN_DIALOG * dlg)173 GWEN_CRYPT_TOKEN *AH_DdvCardDialog_GetCryptToken(const GWEN_DIALOG *dlg)
174 {
175   AH_DDVCARD_DIALOG *xdlg;
176 
177   assert(dlg);
178   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
179   assert(xdlg);
180 
181   return xdlg->cryptToken;
182 }
183 
184 
185 
AH_DdvCardDialog_GetBankCode(const GWEN_DIALOG * dlg)186 const char *AH_DdvCardDialog_GetBankCode(const GWEN_DIALOG *dlg)
187 {
188   AH_DDVCARD_DIALOG *xdlg;
189 
190   assert(dlg);
191   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
192   assert(xdlg);
193 
194   return xdlg->bankCode;
195 }
196 
197 
198 
AH_DdvCardDialog_SetBankCode(GWEN_DIALOG * dlg,const char * s)199 void AH_DdvCardDialog_SetBankCode(GWEN_DIALOG *dlg, const char *s)
200 {
201   AH_DDVCARD_DIALOG *xdlg;
202 
203   assert(dlg);
204   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
205   assert(xdlg);
206 
207   free(xdlg->bankCode);
208   if (s)
209     xdlg->bankCode=strdup(s);
210   else
211     xdlg->bankCode=NULL;
212 }
213 
214 
215 
AH_DdvCardDialog_GetBankName(const GWEN_DIALOG * dlg)216 const char *AH_DdvCardDialog_GetBankName(const GWEN_DIALOG *dlg)
217 {
218   AH_DDVCARD_DIALOG *xdlg;
219 
220   assert(dlg);
221   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
222   assert(xdlg);
223 
224   return xdlg->bankName;
225 }
226 
227 
228 
AH_DdvCardDialog_SetBankName(GWEN_DIALOG * dlg,const char * s)229 void AH_DdvCardDialog_SetBankName(GWEN_DIALOG *dlg, const char *s)
230 {
231   AH_DDVCARD_DIALOG *xdlg;
232 
233   assert(dlg);
234   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
235   assert(xdlg);
236 
237   free(xdlg->bankName);
238   if (s)
239     xdlg->bankName=strdup(s);
240   else
241     xdlg->bankName=NULL;
242 }
243 
244 
245 
AH_DdvCardDialog_GetUserName(const GWEN_DIALOG * dlg)246 const char *AH_DdvCardDialog_GetUserName(const GWEN_DIALOG *dlg)
247 {
248   AH_DDVCARD_DIALOG *xdlg;
249 
250   assert(dlg);
251   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
252   assert(xdlg);
253 
254   return xdlg->userName;
255 }
256 
257 
258 
AH_DdvCardDialog_SetUserName(GWEN_DIALOG * dlg,const char * s)259 void AH_DdvCardDialog_SetUserName(GWEN_DIALOG *dlg, const char *s)
260 {
261   AH_DDVCARD_DIALOG *xdlg;
262 
263   assert(dlg);
264   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
265   assert(xdlg);
266 
267   free(xdlg->userName);
268   if (s)
269     xdlg->userName=strdup(s);
270   else
271     xdlg->userName=NULL;
272 }
273 
274 
275 
AH_DdvCardDialog_GetUserId(const GWEN_DIALOG * dlg)276 const char *AH_DdvCardDialog_GetUserId(const GWEN_DIALOG *dlg)
277 {
278   AH_DDVCARD_DIALOG *xdlg;
279 
280   assert(dlg);
281   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
282   assert(xdlg);
283 
284   return xdlg->userId;
285 }
286 
287 
288 
AH_DdvCardDialog_SetUserId(GWEN_DIALOG * dlg,const char * s)289 void AH_DdvCardDialog_SetUserId(GWEN_DIALOG *dlg, const char *s)
290 {
291   AH_DDVCARD_DIALOG *xdlg;
292 
293   assert(dlg);
294   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
295   assert(xdlg);
296 
297   free(xdlg->userId);
298   if (s)
299     xdlg->userId=strdup(s);
300   else
301     xdlg->userId=NULL;
302 }
303 
304 
305 
AH_DdvCardDialog_GetCustomerId(const GWEN_DIALOG * dlg)306 const char *AH_DdvCardDialog_GetCustomerId(const GWEN_DIALOG *dlg)
307 {
308   AH_DDVCARD_DIALOG *xdlg;
309 
310   assert(dlg);
311   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
312   assert(xdlg);
313 
314   return xdlg->customerId;
315 }
316 
317 
318 
AH_DdvCardDialog_SetCustomerId(GWEN_DIALOG * dlg,const char * s)319 void AH_DdvCardDialog_SetCustomerId(GWEN_DIALOG *dlg, const char *s)
320 {
321   AH_DDVCARD_DIALOG *xdlg;
322 
323   assert(dlg);
324   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
325   assert(xdlg);
326 
327   free(xdlg->customerId);
328   if (s)
329     xdlg->customerId=strdup(s);
330   else
331     xdlg->customerId=NULL;
332 }
333 
334 
335 
AH_DdvCardDialog_GetUrl(const GWEN_DIALOG * dlg)336 const char *AH_DdvCardDialog_GetUrl(const GWEN_DIALOG *dlg)
337 {
338   AH_DDVCARD_DIALOG *xdlg;
339 
340   assert(dlg);
341   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
342   assert(xdlg);
343 
344   return xdlg->url;
345 }
346 
347 
348 
AH_DdvCardDialog_SetUrl(GWEN_DIALOG * dlg,const char * s)349 void AH_DdvCardDialog_SetUrl(GWEN_DIALOG *dlg, const char *s)
350 {
351   AH_DDVCARD_DIALOG *xdlg;
352 
353   assert(dlg);
354   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
355   assert(xdlg);
356 
357   free(xdlg->url);
358   if (s)
359     xdlg->url=strdup(s);
360   else
361     xdlg->url=NULL;
362 }
363 
364 
365 
AH_DdvCardDialog_GetPeerId(const GWEN_DIALOG * dlg)366 const char *AH_DdvCardDialog_GetPeerId(const GWEN_DIALOG *dlg)
367 {
368   AH_DDVCARD_DIALOG *xdlg;
369 
370   assert(dlg);
371   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
372   assert(xdlg);
373 
374   return xdlg->peerId;
375 }
376 
377 
378 
AH_DdvCardDialog_SetPeerId(GWEN_DIALOG * dlg,const char * s)379 void AH_DdvCardDialog_SetPeerId(GWEN_DIALOG *dlg, const char *s)
380 {
381   AH_DDVCARD_DIALOG *xdlg;
382 
383   assert(dlg);
384   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
385   assert(xdlg);
386 
387   free(xdlg->peerId);
388   if (s)
389     xdlg->peerId=strdup(s);
390   else
391     xdlg->peerId=NULL;
392 }
393 
394 
AH_DdvCardDialog_GetHbciVersion(const GWEN_DIALOG * dlg)395 int AH_DdvCardDialog_GetHbciVersion(const GWEN_DIALOG *dlg)
396 {
397   AH_DDVCARD_DIALOG *xdlg;
398 
399   assert(dlg);
400   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
401   assert(xdlg);
402 
403   return xdlg->hbciVersion;
404 }
405 
406 
407 
AH_DdvCardDialog_SetHbciVersion(GWEN_DIALOG * dlg,int i)408 void AH_DdvCardDialog_SetHbciVersion(GWEN_DIALOG *dlg, int i)
409 {
410   AH_DDVCARD_DIALOG *xdlg;
411 
412   assert(dlg);
413   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
414   assert(xdlg);
415 
416   xdlg->hbciVersion=i;
417 }
418 
419 
420 
AH_DdvCardDialog_GetFlags(const GWEN_DIALOG * dlg)421 uint32_t AH_DdvCardDialog_GetFlags(const GWEN_DIALOG *dlg)
422 {
423   AH_DDVCARD_DIALOG *xdlg;
424 
425   assert(dlg);
426   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
427   assert(xdlg);
428 
429   return xdlg->flags;
430 }
431 
432 
433 
AH_DdvCardDialog_SetFlags(GWEN_DIALOG * dlg,uint32_t fl)434 void AH_DdvCardDialog_SetFlags(GWEN_DIALOG *dlg, uint32_t fl)
435 {
436   AH_DDVCARD_DIALOG *xdlg;
437 
438   assert(dlg);
439   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
440   assert(xdlg);
441 
442   xdlg->flags=fl;
443 }
444 
445 
446 
AH_DdvCardDialog_AddFlags(GWEN_DIALOG * dlg,uint32_t fl)447 void AH_DdvCardDialog_AddFlags(GWEN_DIALOG *dlg, uint32_t fl)
448 {
449   AH_DDVCARD_DIALOG *xdlg;
450 
451   assert(dlg);
452   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
453   assert(xdlg);
454 
455   xdlg->flags&=~fl;
456 }
457 
458 
459 
AH_DdvCardDialog_SubFlags(GWEN_DIALOG * dlg,uint32_t fl)460 void AH_DdvCardDialog_SubFlags(GWEN_DIALOG *dlg, uint32_t fl)
461 {
462   AH_DDVCARD_DIALOG *xdlg;
463 
464   assert(dlg);
465   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
466   assert(xdlg);
467 
468   xdlg->flags&=~fl;
469 }
470 
471 
472 
473 
474 
475 
AH_DdvCardDialog_Init(GWEN_DIALOG * dlg)476 void AH_DdvCardDialog_Init(GWEN_DIALOG *dlg)
477 {
478   AH_DDVCARD_DIALOG *xdlg;
479   GWEN_DB_NODE *dbPrefs;
480   int i;
481 
482   assert(dlg);
483   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
484   assert(xdlg);
485 
486   dbPrefs=GWEN_Dialog_GetPreferences(dlg);
487 
488   GWEN_Dialog_SetCharProperty(dlg,
489                               "",
490                               GWEN_DialogProperty_Title,
491                               0,
492                               I18N("HBCI DDV-Card Setup Wizard"),
493                               0);
494 
495   /* select first page */
496   GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, 0, 0);
497 
498   /* setup intro page */
499   GWEN_Dialog_SetCharProperty(dlg,
500                               "wiz_begin_label",
501                               GWEN_DialogProperty_Title,
502                               0,
503                               I18N("<html>"
504                                    "<p>This dialog assists you in setting up a DDV Chipcard User.</p>"
505                                    "<p>Some chipcards contain user information. You can click the button below "
506                                    "to read that information from the card.</p>"
507                                    "</html>"
508                                    "This dialog assists you in setting up a DDV Chipcard User.\n"
509                                    "Some chipcards contain user information. You can click the button below\n"
510                                    "to read that information from the card."),
511                               0);
512 
513   /* setup bank page */
514   GWEN_Dialog_SetCharProperty(dlg,
515                               "wiz_bank_label",
516                               GWEN_DialogProperty_Title,
517                               0,
518                               I18N("<html>"
519                                    "<p>Please select the bank.</p>"
520                                    "<p>AqBanking has an internal database which "
521                                    "contains HBCI/FinTS information about many banks.<p>"
522                                    "<p>If there is an entry for your bank this dialog will use the "
523                                    "information from the database.</p>"
524                                    "</html>"
525                                    "Please select the bank.\n"
526                                    "AqBanking has an internal database which contains\n"
527                                    "HBCI/FinTS information about many banks.\n"
528                                    "If there is an entry for your bank this dialog will use the\n"
529                                    "information from the database."),
530                               0);
531 
532   /* setup user page */
533   GWEN_Dialog_SetCharProperty(dlg,
534                               "wiz_user_label",
535                               GWEN_DialogProperty_Title,
536                               0,
537                               I18N("<html>"
538                                    "<p>For most banks the customer id must be the same as the user id.</p>"
539                                    "<p>However, some banks actually use the customer id, so please look into "
540                                    "the documentation provided by your bank to discover whether this is the "
541                                    "case with your bank.</p>"
542                                    "</html>"
543                                    "For most banks the customer id must be the same as the user id.\n"
544                                    "However, some banks actually use the customer id, so please look into\n"
545                                    "the documentation provided by your bank to discover whether this is the\n"
546                                    "case with your bank."),
547                               0);
548 
549   /* setup creation page */
550   GWEN_Dialog_SetCharProperty(dlg,
551                               "wiz_create_label",
552                               GWEN_DialogProperty_Title,
553                               0,
554                               I18N("<html>"
555                                    "<p>We are now ready to create the user and retrieve the account list.</p>"
556                                    "<p>Click the <i>next</i> button to proceed or <i>abort</i> to abort.</p>"
557                                    "</html>"
558                                    "We are now ready to create the user and retrieve the account list.\n"
559                                    "Click the NEXT button to proceed or ABORT to abort."),
560                               0);
561 
562   /* setup extro page */
563   GWEN_Dialog_SetCharProperty(dlg,
564                               "wiz_end_label",
565                               GWEN_DialogProperty_Title,
566                               0,
567                               I18N("The user has been successfully setup."),
568                               0);
569 
570   GWEN_Dialog_SetIntProperty(dlg, "wiz_context_combo", GWEN_DialogProperty_ClearValues, 0, 0, 0);
571   if (1) {
572     const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
573     int i;
574 
575     i=1;
576     ctx=GWEN_Crypt_Token_Context_List_First(xdlg->contextList);
577     while (ctx) {
578       char numbuf[64];
579       GWEN_BUFFER *tbuf;
580       const char *s;
581 
582       tbuf=GWEN_Buffer_new(0, 256, 0, 1);
583       snprintf(numbuf, sizeof(numbuf)-1, I18N("Context %d:"), i);
584       numbuf[sizeof(numbuf)-1]=0;
585       GWEN_Buffer_AppendString(tbuf, numbuf);
586 
587       s=GWEN_Crypt_Token_Context_GetServiceId(ctx);
588       if (s && *s && strcasecmp(s, "20202020")!=0)
589         GWEN_Buffer_AppendString(tbuf, s);
590       else
591         GWEN_Buffer_AppendString(tbuf, I18N("<no bank code>"));
592       GWEN_Buffer_AppendString(tbuf, "-");
593 
594       s=GWEN_Crypt_Token_Context_GetUserId(ctx);
595       if (s && *s)
596         GWEN_Buffer_AppendString(tbuf, s);
597       else
598         GWEN_Buffer_AppendString(tbuf, I18N("<no user id>"));
599 
600       GWEN_Dialog_SetCharProperty(dlg, "wiz_context_combo", GWEN_DialogProperty_AddValue, 0, GWEN_Buffer_GetStart(tbuf), 0);
601       GWEN_Buffer_free(tbuf);
602 
603       i++;
604       ctx=GWEN_Crypt_Token_Context_List_Next(ctx);
605     }
606   }
607   GWEN_Dialog_SetIntProperty(dlg, "wiz_context_combo", GWEN_DialogProperty_Value, 0, 0, 0);
608   AH_DdvCardDialog_FromContext(dlg, 0);
609 
610   /* read width */
611   i=GWEN_DB_GetIntValue(dbPrefs, "dialog_width", 0, -1);
612   if (i>=DIALOG_MINWIDTH)
613     GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0);
614 
615   /* read height */
616   i=GWEN_DB_GetIntValue(dbPrefs, "dialog_height", 0, -1);
617   if (i>=DIALOG_MINHEIGHT)
618     GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0);
619 
620   /* disable next and previous buttons */
621   GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
622   GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
623 }
624 
625 
626 
AH_DdvCardDialog_Fini(GWEN_DIALOG * dlg)627 void AH_DdvCardDialog_Fini(GWEN_DIALOG *dlg)
628 {
629   AH_DDVCARD_DIALOG *xdlg;
630   int i;
631   GWEN_DB_NODE *dbPrefs;
632 
633   assert(dlg);
634   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
635   assert(xdlg);
636 
637   dbPrefs=GWEN_Dialog_GetPreferences(dlg);
638 
639   /* store dialog width */
640   i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1);
641   GWEN_DB_SetIntValue(dbPrefs,
642                       GWEN_DB_FLAGS_OVERWRITE_VARS,
643                       "dialog_width",
644                       i);
645 
646   /* store dialog height */
647   i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1);
648   GWEN_DB_SetIntValue(dbPrefs,
649                       GWEN_DB_FLAGS_OVERWRITE_VARS,
650                       "dialog_height",
651                       i);
652 }
653 
654 
655 
AH_DdvCardDialog_GetBankPageData(GWEN_DIALOG * dlg)656 int AH_DdvCardDialog_GetBankPageData(GWEN_DIALOG *dlg)
657 {
658   AH_DDVCARD_DIALOG *xdlg;
659   const char *s;
660 
661   assert(dlg);
662   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
663   assert(xdlg);
664 
665   s=GWEN_Dialog_GetCharProperty(dlg, "wiz_bankcode_edit", GWEN_DialogProperty_Value, 0, NULL);
666   if (s && *s)
667     AH_DdvCardDialog_SetBankCode(dlg, s);
668   else {
669     DBG_INFO(AQHBCI_LOGDOMAIN, "Missing bank code");
670     return GWEN_ERROR_NO_DATA;
671   }
672 
673   s=GWEN_Dialog_GetCharProperty(dlg, "wiz_bankname_edit", GWEN_DialogProperty_Value, 0, NULL);
674   if (s && *s)
675     AH_DdvCardDialog_SetBankName(dlg, s);
676   else
677     AH_DdvCardDialog_SetBankName(dlg, NULL);
678 
679   s=GWEN_Dialog_GetCharProperty(dlg, "wiz_url_edit", GWEN_DialogProperty_Value, 0, NULL);
680   if (s && *s)
681     AH_DdvCardDialog_SetUrl(dlg, s);
682   else {
683     DBG_INFO(AQHBCI_LOGDOMAIN, "Missing URL");
684     return GWEN_ERROR_NO_DATA;
685   }
686 
687   return 0;
688 }
689 
690 
691 
AH_DdvCardDialog_GetUserPageData(GWEN_DIALOG * dlg)692 int AH_DdvCardDialog_GetUserPageData(GWEN_DIALOG *dlg)
693 {
694   AH_DDVCARD_DIALOG *xdlg;
695   const char *s;
696 
697   assert(dlg);
698   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
699   assert(xdlg);
700 
701   s=GWEN_Dialog_GetCharProperty(dlg, "wiz_username_edit", GWEN_DialogProperty_Value, 0, NULL);
702   if (s && *s)
703     AH_DdvCardDialog_SetUserName(dlg, s);
704   else {
705     DBG_INFO(AQHBCI_LOGDOMAIN, "Missing user name");
706     return GWEN_ERROR_NO_DATA;
707   }
708 
709   s=GWEN_Dialog_GetCharProperty(dlg, "wiz_userid_edit", GWEN_DialogProperty_Value, 0, NULL);
710   if (s && *s)
711     AH_DdvCardDialog_SetUserId(dlg, s);
712   else {
713     DBG_INFO(AQHBCI_LOGDOMAIN, "Missing user id");
714     return GWEN_ERROR_NO_DATA;
715   }
716 
717   s=GWEN_Dialog_GetCharProperty(dlg, "wiz_customerid_edit", GWEN_DialogProperty_Value, 0, NULL);
718   if (s && *s)
719     AH_DdvCardDialog_SetCustomerId(dlg, s);
720   else
721     AH_DdvCardDialog_SetCustomerId(dlg, NULL);
722 
723   return 0;
724 }
725 
726 
727 
AH_DdvCardDialog_EnterPage(GWEN_DIALOG * dlg,int page,int forwards)728 int AH_DdvCardDialog_EnterPage(GWEN_DIALOG *dlg, int page, int forwards)
729 {
730   AH_DDVCARD_DIALOG *xdlg;
731   int rv;
732 
733   assert(dlg);
734   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
735   assert(xdlg);
736 
737   switch (page) {
738   case PAGE_BEGIN:
739     GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
740     GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
741     return GWEN_DialogEvent_ResultHandled;
742 
743   case PAGE_BANK:
744     GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
745     rv=AH_DdvCardDialog_GetBankPageData(dlg);
746     if (rv<0)
747       GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
748     else
749       GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
750     GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
751     return GWEN_DialogEvent_ResultHandled;
752 
753   case PAGE_USER:
754     GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
755     rv=AH_DdvCardDialog_GetUserPageData(dlg);
756     if (rv<0)
757       GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
758     else
759       GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
760     GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
761     return GWEN_DialogEvent_ResultHandled;
762 
763   case PAGE_CREATE:
764     if (!forwards)
765       GWEN_Dialog_SetCharProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Title, 0, I18N("Next"), 0);
766     GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
767     return GWEN_DialogEvent_ResultHandled;
768 
769   case PAGE_END:
770     GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
771     GWEN_Dialog_SetCharProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Title, 0, I18N("Finish"), 0);
772     GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
773     GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
774     GWEN_Dialog_SetIntProperty(dlg, "wiz_abort_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
775     return GWEN_DialogEvent_ResultHandled;
776 
777   default:
778     return GWEN_DialogEvent_ResultHandled;
779   }
780 
781   return GWEN_DialogEvent_ResultHandled;
782 }
783 
784 
785 
AH_DdvCardDialog_DoIt(GWEN_DIALOG * dlg)786 int AH_DdvCardDialog_DoIt(GWEN_DIALOG *dlg)
787 {
788   AH_DDVCARD_DIALOG *xdlg;
789   AB_USER *u;
790   GWEN_URL *url;
791   int rv;
792   uint32_t pid;
793   AB_IMEXPORTER_CONTEXT *ctx;
794 
795   assert(dlg);
796   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
797   assert(xdlg);
798 
799   u=AB_Provider_CreateUserObject(xdlg->provider);
800   if (u==NULL) {
801     DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not create user, maybe backend missing?");
802     GWEN_Gui_ShowError(I18N("Error"), "%s", I18N("Could not create user, maybe some plugins are not installed?"));
803     return GWEN_DialogEvent_ResultHandled;
804   }
805 
806   /* generic setup */
807   AB_User_SetUserName(u, xdlg->userName);
808   AB_User_SetUserId(u, xdlg->userId);
809   if (xdlg->customerId && *(xdlg->customerId))
810     AB_User_SetCustomerId(u, xdlg->customerId);
811   else
812     AB_User_SetCustomerId(u, xdlg->userId);
813   AB_User_SetCountry(u, "de");
814 
815   AB_User_SetBankCode(u, xdlg->bankCode);
816 
817   /* HBCI setup */
818   AH_User_SetTokenType(u, "ddvcard");
819   AH_User_SetTokenName(u, GWEN_Crypt_Token_GetTokenName(xdlg->cryptToken));
820   AH_User_SetCryptMode(u, AH_CryptMode_Ddv);
821   AH_User_SetTokenContextId(u, 1);
822   AH_User_SetStatus(u, AH_UserStatusEnabled);
823 
824   url=GWEN_Url_fromString(xdlg->url);
825   assert(url);
826   GWEN_Url_SetProtocol(url, "hbci");
827   if (GWEN_Url_GetPort(url)==0)
828     GWEN_Url_SetPort(url, 3000);
829   AH_User_SetServerUrl(u, url);
830   GWEN_Url_free(url);
831   AH_User_SetHbciVersion(u, xdlg->hbciVersion);
832 
833   rv=AB_Provider_AddUser(xdlg->provider, u);
834   if (rv<0) {
835     DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not add user (%d)", rv);
836     AB_User_free(u);
837     GWEN_Gui_ShowError(I18N("Error"), I18N("Could not add user (%d)"), rv);
838     return GWEN_DialogEvent_ResultHandled;
839   }
840 
841   pid=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_DELAY |
842                              GWEN_GUI_PROGRESS_ALLOW_EMBED |
843                              GWEN_GUI_PROGRESS_SHOW_PROGRESS |
844                              GWEN_GUI_PROGRESS_SHOW_ABORT,
845                              I18N("Setting Up DDV User"),
846                              I18N("The list of accounts will be retrieved."),
847                              1,
848                              0);
849   /* lock new user */
850   rv=AB_Provider_BeginExclUseUser(xdlg->provider, u);
851   if (rv<0) {
852     DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not lock user (%d)", rv);
853     GWEN_Gui_ProgressLog2(pid,
854                           GWEN_LoggerLevel_Error,
855                           I18N("Unable to lock users (%d)"), rv);
856     AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
857     GWEN_Gui_ProgressEnd(pid);
858     return GWEN_DialogEvent_ResultHandled;
859   }
860 
861   /* get account list */
862   GWEN_Gui_ProgressLog(pid,
863                        GWEN_LoggerLevel_Notice,
864                        I18N("Retrieving account list"));
865   ctx=AB_ImExporterContext_new();
866   rv=AH_Provider_GetAccounts(xdlg->provider, u, ctx, 0, 1, 0);
867   if (rv<0) {
868     AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
869     AB_ImExporterContext_free(ctx);
870     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
871     AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
872     GWEN_Gui_ProgressEnd(pid);
873     return GWEN_DialogEvent_ResultHandled;
874   }
875   AB_ImExporterContext_free(ctx);
876 
877   rv=GWEN_Gui_ProgressAdvance(pid, GWEN_GUI_PROGRESS_ONE);
878   if (rv==GWEN_ERROR_USER_ABORTED) {
879     AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
880     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
881     AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
882     GWEN_Gui_ProgressLog(pid,
883                          GWEN_LoggerLevel_Error,
884                          I18N("Aborted by user."));
885     GWEN_Gui_ProgressEnd(pid);
886     return GWEN_DialogEvent_ResultHandled;
887   }
888 
889   /* unlock user */
890   rv=AB_Provider_EndExclUseUser(xdlg->provider, u, 0);
891   if (rv<0) {
892     DBG_INFO(AQHBCI_LOGDOMAIN,
893              "Could not unlock customer [%s] (%d)",
894              AB_User_GetCustomerId(u), rv);
895     GWEN_Gui_ProgressLog2(pid,
896                           GWEN_LoggerLevel_Error,
897                           I18N("Could not unlock user %s (%d)"),
898                           AB_User_GetUserId(u), rv);
899     AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
900     AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
901     GWEN_Gui_ProgressEnd(pid);
902     return GWEN_DialogEvent_ResultHandled;
903   }
904 
905   GWEN_Dialog_SetCharProperty(dlg,
906                               "wiz_end_label",
907                               GWEN_DialogProperty_Title,
908                               0,
909                               I18N("The user has been successfully setup."),
910                               0);
911   GWEN_Gui_ProgressEnd(pid);
912   AH_DdvCardDialog_EnterPage(dlg, PAGE_END, 1);
913 
914   xdlg->user=u;
915 
916   return GWEN_DialogEvent_ResultHandled;
917 }
918 
919 
920 
AH_DdvCardDialog_Next(GWEN_DIALOG * dlg)921 int AH_DdvCardDialog_Next(GWEN_DIALOG *dlg)
922 {
923   AH_DDVCARD_DIALOG *xdlg;
924   int page;
925 
926   assert(dlg);
927   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
928   assert(xdlg);
929 
930   page=GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1);
931   if (page==PAGE_CREATE) {
932     return AH_DdvCardDialog_DoIt(dlg);
933   }
934   else if (page<PAGE_END) {
935     page++;
936     return AH_DdvCardDialog_EnterPage(dlg, page, 1);
937   }
938   else if (page==PAGE_END)
939     return GWEN_DialogEvent_ResultAccept;
940 
941   return GWEN_DialogEvent_ResultHandled;
942 }
943 
944 
945 
AH_DdvCardDialog_Previous(GWEN_DIALOG * dlg)946 int AH_DdvCardDialog_Previous(GWEN_DIALOG *dlg)
947 {
948   AH_DDVCARD_DIALOG *xdlg;
949   int page;
950 
951   assert(dlg);
952   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
953   assert(xdlg);
954 
955   page=GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1);
956   if (page>PAGE_BEGIN) {
957     page--;
958     return AH_DdvCardDialog_EnterPage(dlg, page, 0);
959   }
960 
961   return GWEN_DialogEvent_ResultHandled;
962 }
963 
964 
965 
AH_DdvCardDialog_HandleActivatedBankCode(GWEN_DIALOG * dlg)966 int AH_DdvCardDialog_HandleActivatedBankCode(GWEN_DIALOG *dlg)
967 {
968   AH_DDVCARD_DIALOG *xdlg;
969   GWEN_DIALOG *dlg2;
970   int rv;
971 
972   assert(dlg);
973   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
974   assert(xdlg);
975 
976   dlg2=AB_SelectBankInfoDialog_new(xdlg->banking, "de", NULL);
977   if (dlg2==NULL) {
978     DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not create dialog");
979     GWEN_Gui_ShowError(I18N("Error"), "%s", I18N("Could not create dialog, maybe an installation error?"));
980     return GWEN_DialogEvent_ResultHandled;
981   }
982 
983   rv=GWEN_Gui_ExecDialog(dlg2, 0);
984   if (rv==0) {
985     /* rejected */
986     GWEN_Dialog_free(dlg2);
987     return GWEN_DialogEvent_ResultHandled;
988   }
989   else {
990     const AB_BANKINFO *bi;
991 
992     bi=AB_SelectBankInfoDialog_GetSelectedBankInfo(dlg2);
993     if (bi) {
994       const char *s;
995       AB_BANKINFO_SERVICE *sv;
996 
997       s=AB_BankInfo_GetBankId(bi);
998       GWEN_Dialog_SetCharProperty(dlg,
999                                   "wiz_bankcode_edit",
1000                                   GWEN_DialogProperty_Value,
1001                                   0,
1002                                   (s && *s)?s:"",
1003                                   0);
1004 
1005       s=AB_BankInfo_GetBankName(bi);
1006       GWEN_Dialog_SetCharProperty(dlg,
1007                                   "wiz_bankname_edit",
1008                                   GWEN_DialogProperty_Value,
1009                                   0,
1010                                   (s && *s)?s:"",
1011                                   0);
1012       sv=AB_BankInfoService_List_First(AB_BankInfo_GetServices(bi));
1013       while (sv) {
1014         const char *s;
1015 
1016         s=AB_BankInfoService_GetType(sv);
1017         if (s && *s && strcasecmp(s, "HBCI")==0) {
1018           s=AB_BankInfoService_GetMode(sv);
1019           if (s && *s && strcasecmp(s, "ddv")==0)
1020             break;
1021         }
1022         sv=AB_BankInfoService_List_Next(sv);
1023       }
1024 
1025       if (sv) {
1026         /* DDV service found */
1027         s=AB_BankInfoService_GetAddress(sv);
1028         GWEN_Dialog_SetCharProperty(dlg,
1029                                     "wiz_url_edit",
1030                                     GWEN_DialogProperty_Value,
1031                                     0,
1032                                     (s && *s)?s:"",
1033                                     0);
1034         s=AB_BankInfoService_GetPversion(sv);
1035         if (s && *s) {
1036           if (strcasecmp(s, "2.01")==0 ||
1037               strcasecmp(s, "2")==0)
1038             xdlg->hbciVersion=201;
1039           else if (strcasecmp(s, "2.10")==0 ||
1040                    strcasecmp(s, "2.1")==0)
1041             xdlg->hbciVersion=210;
1042           else if (strcasecmp(s, "2.20")==0 ||
1043                    strcasecmp(s, "2.2")==0)
1044             xdlg->hbciVersion=220;
1045           else if (strcasecmp(s, "3.00")==0 ||
1046                    strcasecmp(s, "3.0")==0 ||
1047                    strcasecmp(s, "3")==0)
1048             xdlg->hbciVersion=300;
1049           else if (strcasecmp(s, "4.00")==0 ||
1050                    strcasecmp(s, "4.0")==0 ||
1051                    strcasecmp(s, "4")==0)
1052             xdlg->hbciVersion=400;
1053         }
1054       }
1055     }
1056   }
1057 
1058   GWEN_Dialog_free(dlg2);
1059 
1060   if (AH_DdvCardDialog_GetBankPageData(dlg)<0)
1061     GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
1062   else
1063     GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
1064 
1065   return GWEN_DialogEvent_ResultHandled;
1066 }
1067 
1068 
1069 
AH_DdvCardDialog_HandleActivatedSpecial(GWEN_DIALOG * dlg)1070 int AH_DdvCardDialog_HandleActivatedSpecial(GWEN_DIALOG *dlg)
1071 {
1072   AH_DDVCARD_DIALOG *xdlg;
1073   GWEN_DIALOG *dlg2;
1074   int rv;
1075 
1076   assert(dlg);
1077   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
1078   assert(xdlg);
1079 
1080   dlg2=AH_DdvCardSpecialDialog_new(xdlg->provider);
1081   if (dlg2==NULL) {
1082     DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not create dialog");
1083     GWEN_Gui_ShowError(I18N("Error"), "%s", I18N("Could not create dialog, maybe an installation error?"));
1084     return GWEN_DialogEvent_ResultHandled;
1085   }
1086 
1087   AH_DdvCardSpecialDialog_SetHbciVersion(dlg2, xdlg->hbciVersion);
1088   AH_DdvCardSpecialDialog_SetFlags(dlg2, xdlg->flags);
1089 
1090   rv=GWEN_Gui_ExecDialog(dlg2, 0);
1091   if (rv==0) {
1092     /* rejected */
1093     GWEN_Dialog_free(dlg2);
1094     return GWEN_DialogEvent_ResultHandled;
1095   }
1096   else {
1097     xdlg->hbciVersion=AH_DdvCardSpecialDialog_GetHbciVersion(dlg2);
1098     xdlg->flags=AH_DdvCardSpecialDialog_GetFlags(dlg2);
1099   }
1100 
1101   GWEN_Dialog_free(dlg2);
1102 
1103   return GWEN_DialogEvent_ResultHandled;
1104 }
1105 
1106 
1107 
AH_DdvCardDialog_FromContext(GWEN_DIALOG * dlg,int i)1108 int AH_DdvCardDialog_FromContext(GWEN_DIALOG *dlg, int i)
1109 {
1110   AH_DDVCARD_DIALOG *xdlg;
1111 
1112   assert(dlg);
1113   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
1114   assert(xdlg);
1115 
1116   if (i>=0) {
1117     GWEN_CRYPT_TOKEN_CONTEXT *ctx;
1118 
1119     ctx=GWEN_Crypt_Token_Context_List_First(xdlg->contextList);
1120     while (ctx && i--)
1121       ctx=GWEN_Crypt_Token_Context_List_Next(ctx);
1122 
1123     if (ctx) {
1124       const char *s;
1125 
1126       s=GWEN_Crypt_Token_Context_GetServiceId(ctx);
1127       if (s && strcasecmp(s, "20202020")==0)
1128         s=NULL;
1129       GWEN_Dialog_SetCharProperty(dlg,
1130                                   "wiz_bankcode_edit",
1131                                   GWEN_DialogProperty_Value,
1132                                   0,
1133                                   (s && *s)?s:"",
1134                                   0);
1135 
1136       s=GWEN_Crypt_Token_Context_GetAddress(ctx);
1137       GWEN_Dialog_SetCharProperty(dlg,
1138                                   "wiz_url_edit",
1139                                   GWEN_DialogProperty_Value,
1140                                   0,
1141                                   (s && *s)?s:"",
1142                                   0);
1143 
1144       s=GWEN_Crypt_Token_Context_GetUserId(ctx);
1145       GWEN_Dialog_SetCharProperty(dlg,
1146                                   "wiz_userid_edit",
1147                                   GWEN_DialogProperty_Value,
1148                                   0,
1149                                   (s && *s)?s:"",
1150                                   0);
1151       GWEN_Dialog_SetCharProperty(dlg,
1152                                   "wiz_customerid_edit",
1153                                   GWEN_DialogProperty_Value,
1154                                   0,
1155                                   (s && *s)?s:"",
1156                                   0);
1157 
1158     }
1159   }
1160 
1161   return GWEN_DialogEvent_ResultHandled;
1162 }
1163 
1164 
1165 
AH_DdvCardDialog_HandleActivatedContext(GWEN_DIALOG * dlg)1166 int AH_DdvCardDialog_HandleActivatedContext(GWEN_DIALOG *dlg)
1167 {
1168   int i;
1169 
1170   i=GWEN_Dialog_GetIntProperty(dlg, "wiz_context_combo", GWEN_DialogProperty_Value, 0, -1);
1171   if (i>=0)
1172     AH_DdvCardDialog_FromContext(dlg, i);
1173   return GWEN_DialogEvent_ResultHandled;
1174 }
1175 
1176 
1177 
AH_DdvCardDialog_HandleActivated(GWEN_DIALOG * dlg,const char * sender)1178 int AH_DdvCardDialog_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
1179 {
1180   if (strcasecmp(sender, "wiz_bankcode_button")==0)
1181     return AH_DdvCardDialog_HandleActivatedBankCode(dlg);
1182   else if (strcasecmp(sender, "wiz_prev_button")==0)
1183     return AH_DdvCardDialog_Previous(dlg);
1184   else if (strcasecmp(sender, "wiz_next_button")==0)
1185     return AH_DdvCardDialog_Next(dlg);
1186   else if (strcasecmp(sender, "wiz_abort_button")==0)
1187     return GWEN_DialogEvent_ResultReject;
1188   else if (strcasecmp(sender, "wiz_special_button")==0)
1189     return AH_DdvCardDialog_HandleActivatedSpecial(dlg);
1190   else if (strcasecmp(sender, "wiz_help_button")==0) {
1191     /* TODO: open a help dialog */
1192   }
1193   else if (strcasecmp(sender, "wiz_context_combo")==0)
1194     return AH_DdvCardDialog_HandleActivatedContext(dlg);
1195 
1196   return GWEN_DialogEvent_ResultNotHandled;
1197 }
1198 
1199 
1200 
AH_DdvCardDialog_HandleValueChanged(GWEN_DIALOG * dlg,const char * sender)1201 int AH_DdvCardDialog_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
1202 {
1203   if (strcasecmp(sender, "wiz_bankcode_edit")==0 ||
1204       strcasecmp(sender, "wiz_url_edit")==0 ||
1205       strcasecmp(sender, "wiz_username_edit")==0 ||
1206       strcasecmp(sender, "wiz_userid_edit")==0 ||
1207       strcasecmp(sender, "wiz_customerid_edit")==0) {
1208     int rv;
1209 
1210     if (GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1)==PAGE_BANK) {
1211       rv=AH_DdvCardDialog_GetBankPageData(dlg);
1212       if (rv<0)
1213         GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
1214       else
1215         GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
1216     }
1217     else if (GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1)==PAGE_USER) {
1218       rv=AH_DdvCardDialog_GetUserPageData(dlg);
1219       if (rv<0)
1220         GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
1221       else
1222         GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
1223     }
1224     return GWEN_DialogEvent_ResultHandled;
1225   }
1226   return GWEN_DialogEvent_ResultNotHandled;
1227 }
1228 
1229 
1230 
AH_DdvCardDialog_SignalHandler(GWEN_DIALOG * dlg,GWEN_DIALOG_EVENTTYPE t,const char * sender)1231 int GWENHYWFAR_CB AH_DdvCardDialog_SignalHandler(GWEN_DIALOG *dlg,
1232                                                  GWEN_DIALOG_EVENTTYPE t,
1233                                                  const char *sender)
1234 {
1235   AH_DDVCARD_DIALOG *xdlg;
1236 
1237   assert(dlg);
1238   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_DDVCARD_DIALOG, dlg);
1239   assert(xdlg);
1240 
1241   switch (t) {
1242   case GWEN_DialogEvent_TypeInit:
1243     AH_DdvCardDialog_Init(dlg);
1244     return GWEN_DialogEvent_ResultHandled;;
1245 
1246   case GWEN_DialogEvent_TypeFini:
1247     AH_DdvCardDialog_Fini(dlg);
1248     return GWEN_DialogEvent_ResultHandled;;
1249 
1250   case GWEN_DialogEvent_TypeValueChanged:
1251     return AH_DdvCardDialog_HandleValueChanged(dlg, sender);
1252 
1253   case GWEN_DialogEvent_TypeActivated:
1254     return AH_DdvCardDialog_HandleActivated(dlg, sender);
1255 
1256   case GWEN_DialogEvent_TypeEnabled:
1257   case GWEN_DialogEvent_TypeDisabled:
1258   case GWEN_DialogEvent_TypeClose:
1259 
1260   case GWEN_DialogEvent_TypeLast:
1261     return GWEN_DialogEvent_ResultNotHandled;
1262 
1263   }
1264 
1265   return GWEN_DialogEvent_ResultNotHandled;
1266 }
1267 
1268 
1269 
1270 
1271