1 /***************************************************************************
2  begin       : Mon Apr 12 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_pintan_special_p.h"
18 #include "i18n_l.h"
19 
20 #include <aqbanking/backendsupport/user.h>
21 #include <aqbanking/banking_be.h>
22 
23 #include "aqhbci/banking/user.h"
24 #include "aqhbci/banking/provider.h"
25 
26 #include <gwenhywfar/gwenhywfar.h>
27 #include <gwenhywfar/misc.h>
28 #include <gwenhywfar/pathmanager.h>
29 #include <gwenhywfar/debug.h>
30 #include <gwenhywfar/gui.h>
31 
32 
33 #define DIALOG_MINWIDTH  200
34 #define DIALOG_MINHEIGHT 100
35 
36 
37 
GWEN_INHERIT(GWEN_DIALOG,AH_PINTAN_SPECIAL_DIALOG)38 GWEN_INHERIT(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG)
39 
40 
41 
42 
43 GWEN_DIALOG *AH_PinTanSpecialDialog_new(AB_PROVIDER *pro)
44 {
45   GWEN_DIALOG *dlg;
46   AH_PINTAN_SPECIAL_DIALOG *xdlg;
47   GWEN_BUFFER *fbuf;
48   int rv;
49 
50   dlg=GWEN_Dialog_new("ah_setup_pintan_special");
51   GWEN_NEW_OBJECT(AH_PINTAN_SPECIAL_DIALOG, xdlg);
52   GWEN_INHERIT_SETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg, xdlg,
53                        AH_PinTanSpecialDialog_FreeData);
54   GWEN_Dialog_SetSignalHandler(dlg, AH_PinTanSpecialDialog_SignalHandler);
55 
56   /* get path of dialog description file */
57   fbuf=GWEN_Buffer_new(0, 256, 0, 1);
58   rv=GWEN_PathManager_FindFile(AB_PM_LIBNAME, AB_PM_DATADIR,
59                                "aqbanking/backends/aqhbci/dialogs/dlg_pintan_special.dlg",
60                                fbuf);
61   if (rv<0) {
62     DBG_INFO(AQHBCI_LOGDOMAIN, "Dialog description file not found (%d).", rv);
63     GWEN_Buffer_free(fbuf);
64     GWEN_Dialog_free(dlg);
65     return NULL;
66   }
67 
68   /* read dialog from dialog description file */
69   rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(fbuf));
70   if (rv<0) {
71     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d).", rv);
72     GWEN_Buffer_free(fbuf);
73     GWEN_Dialog_free(dlg);
74     return NULL;
75   }
76   GWEN_Buffer_free(fbuf);
77 
78   xdlg->banking=AB_Provider_GetBanking(pro);
79   xdlg->provider=pro;
80 
81   /* preset */
82   xdlg->hbciVersion=300;
83   xdlg->httpVMajor=1;
84   xdlg->httpVMinor=1;
85 
86   /* done */
87   return dlg;
88 }
89 
90 
91 
AH_PinTanSpecialDialog_FreeData(void * bp,void * p)92 void GWENHYWFAR_CB AH_PinTanSpecialDialog_FreeData(void *bp, void *p)
93 {
94   AH_PINTAN_SPECIAL_DIALOG *xdlg;
95 
96   xdlg=(AH_PINTAN_SPECIAL_DIALOG *) p;
97 
98   free(xdlg->tanMediumId);
99 
100   GWEN_FREE_OBJECT(xdlg);
101 }
102 
103 
104 
AH_PinTanSpecialDialog_GetHttpVMajor(const GWEN_DIALOG * dlg)105 int AH_PinTanSpecialDialog_GetHttpVMajor(const GWEN_DIALOG *dlg)
106 {
107   AH_PINTAN_SPECIAL_DIALOG *xdlg;
108 
109   assert(dlg);
110   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
111   assert(xdlg);
112 
113   return xdlg->httpVMajor;
114 }
115 
116 
117 
AH_PinTanSpecialDialog_GetHttpVMinor(const GWEN_DIALOG * dlg)118 int AH_PinTanSpecialDialog_GetHttpVMinor(const GWEN_DIALOG *dlg)
119 {
120   AH_PINTAN_SPECIAL_DIALOG *xdlg;
121 
122   assert(dlg);
123   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
124   assert(xdlg);
125 
126   return xdlg->httpVMinor;
127 }
128 
129 
130 
AH_PinTanSpecialDialog_SetHttpVersion(GWEN_DIALOG * dlg,int vmajor,int vminor)131 void AH_PinTanSpecialDialog_SetHttpVersion(GWEN_DIALOG *dlg, int vmajor, int vminor)
132 {
133   AH_PINTAN_SPECIAL_DIALOG *xdlg;
134 
135   assert(dlg);
136   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
137   assert(xdlg);
138 
139   xdlg->httpVMajor=vmajor;
140   xdlg->httpVMinor=vminor;
141 }
142 
143 
144 
AH_PinTanSpecialDialog_GetHbciVersion(const GWEN_DIALOG * dlg)145 int AH_PinTanSpecialDialog_GetHbciVersion(const GWEN_DIALOG *dlg)
146 {
147   AH_PINTAN_SPECIAL_DIALOG *xdlg;
148 
149   assert(dlg);
150   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
151   assert(xdlg);
152 
153   return xdlg->hbciVersion;
154 }
155 
156 
157 
AH_PinTanSpecialDialog_SetHbciVersion(GWEN_DIALOG * dlg,int i)158 void AH_PinTanSpecialDialog_SetHbciVersion(GWEN_DIALOG *dlg, int i)
159 {
160   AH_PINTAN_SPECIAL_DIALOG *xdlg;
161 
162   assert(dlg);
163   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
164   assert(xdlg);
165 
166   xdlg->hbciVersion=i;
167 }
168 
169 
170 
AH_PinTanSpecialDialog_GetFlags(const GWEN_DIALOG * dlg)171 uint32_t AH_PinTanSpecialDialog_GetFlags(const GWEN_DIALOG *dlg)
172 {
173   AH_PINTAN_SPECIAL_DIALOG *xdlg;
174 
175   assert(dlg);
176   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
177   assert(xdlg);
178 
179   return xdlg->flags;
180 }
181 
182 
183 
AH_PinTanSpecialDialog_SetFlags(GWEN_DIALOG * dlg,uint32_t fl)184 void AH_PinTanSpecialDialog_SetFlags(GWEN_DIALOG *dlg, uint32_t fl)
185 {
186   AH_PINTAN_SPECIAL_DIALOG *xdlg;
187 
188   assert(dlg);
189   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
190   assert(xdlg);
191 
192   xdlg->flags=fl;
193 }
194 
195 
196 
AH_PinTanSpecialDialog_AddFlags(GWEN_DIALOG * dlg,uint32_t fl)197 void AH_PinTanSpecialDialog_AddFlags(GWEN_DIALOG *dlg, uint32_t fl)
198 {
199   AH_PINTAN_SPECIAL_DIALOG *xdlg;
200 
201   assert(dlg);
202   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
203   assert(xdlg);
204 
205   xdlg->flags&=~fl;
206 }
207 
208 
209 
AH_PinTanSpecialDialog_SubFlags(GWEN_DIALOG * dlg,uint32_t fl)210 void AH_PinTanSpecialDialog_SubFlags(GWEN_DIALOG *dlg, uint32_t fl)
211 {
212   AH_PINTAN_SPECIAL_DIALOG *xdlg;
213 
214   assert(dlg);
215   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
216   assert(xdlg);
217 
218   xdlg->flags&=~fl;
219 }
220 
221 
222 
AH_PinTanSpecialDialog_GetTanMediumId(const GWEN_DIALOG * dlg)223 const char *AH_PinTanSpecialDialog_GetTanMediumId(const GWEN_DIALOG *dlg)
224 {
225   AH_PINTAN_SPECIAL_DIALOG *xdlg;
226 
227   assert(dlg);
228   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
229   assert(xdlg);
230 
231   return xdlg->tanMediumId;
232 }
233 
234 
235 
AH_PinTanSpecialDialog_SetTanMediumId(GWEN_DIALOG * dlg,const char * s)236 void AH_PinTanSpecialDialog_SetTanMediumId(GWEN_DIALOG *dlg, const char *s)
237 {
238   AH_PINTAN_SPECIAL_DIALOG *xdlg;
239 
240   assert(dlg);
241   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
242   assert(xdlg);
243 
244   free(xdlg->tanMediumId);
245   if (s && *s)
246     xdlg->tanMediumId=strdup(s);
247   else
248     xdlg->tanMediumId=NULL;
249 }
250 
251 
252 
AH_PinTanSpecialDialog_Init(GWEN_DIALOG * dlg)253 void AH_PinTanSpecialDialog_Init(GWEN_DIALOG *dlg)
254 {
255   AH_PINTAN_SPECIAL_DIALOG *xdlg;
256   GWEN_DB_NODE *dbPrefs;
257   int i;
258 
259   assert(dlg);
260   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
261   assert(xdlg);
262 
263   dbPrefs=GWEN_Dialog_GetPreferences(dlg);
264 
265   GWEN_Dialog_SetCharProperty(dlg,
266                               "",
267                               GWEN_DialogProperty_Title,
268                               0,
269                               I18N("HBCI PIN/TAN Special Settings"),
270                               0);
271 
272   GWEN_Dialog_SetCharProperty(dlg, "hbciVersionCombo", GWEN_DialogProperty_AddValue, 0, "2.20", 0);
273   GWEN_Dialog_SetCharProperty(dlg, "hbciVersionCombo", GWEN_DialogProperty_AddValue, 0, "3.0", 0);
274 
275   GWEN_Dialog_SetCharProperty(dlg, "httpVersionCombo", GWEN_DialogProperty_AddValue, 0, "1.0", 0);
276   GWEN_Dialog_SetCharProperty(dlg, "httpVersionCombo", GWEN_DialogProperty_AddValue, 0, "1.1", 0);
277 
278   /* toGui */
279   switch (((xdlg->httpVMajor)<<8)+xdlg->httpVMinor) {
280   case 0x0100:
281     GWEN_Dialog_SetIntProperty(dlg, "httpVersionCombo", GWEN_DialogProperty_Value, 0, 0, 0);
282     break;
283   case 0x0101:
284     GWEN_Dialog_SetIntProperty(dlg, "httpVersionCombo", GWEN_DialogProperty_Value, 0, 1, 0);
285     break;
286   default:
287     break;
288   }
289 
290   switch (xdlg->hbciVersion) {
291   case 220:
292     GWEN_Dialog_SetIntProperty(dlg, "hbciVersionCombo", GWEN_DialogProperty_Value, 0, 0, 0);
293     break;
294   case 300:
295     GWEN_Dialog_SetIntProperty(dlg, "hbciVersionCombo", GWEN_DialogProperty_Value, 0, 1, 0);
296     break;
297   default:
298     break;
299   }
300 
301   GWEN_Dialog_SetIntProperty(dlg, "noBase64Check", GWEN_DialogProperty_Value, 0,
302                              (xdlg->flags & AH_USER_FLAGS_NO_BASE64)?1:0,
303                              0);
304 
305   GWEN_Dialog_SetIntProperty(dlg, "omitSmsAccountCheck", GWEN_DialogProperty_Value, 0,
306                              (xdlg->flags & AH_USER_FLAGS_TAN_OMIT_SMS_ACCOUNT)?1:0,
307                              0);
308 
309   if (xdlg->tanMediumId)
310     GWEN_Dialog_SetCharProperty(dlg, "tanMediumIdEdit", GWEN_DialogProperty_Value, 0, xdlg->tanMediumId, 0);
311   /* set tooltip */
312   GWEN_Dialog_SetCharProperty(dlg, "tanMediumIdEdit", GWEN_DialogProperty_ToolTip, 0,
313                               I18N("For smsTAN or mTAN this is your mobile phone number. "
314                                    "Please ask your bank for the necessary format of this number."),
315                               0);
316 
317 
318   /* read width */
319   i=GWEN_DB_GetIntValue(dbPrefs, "dialog_width", 0, -1);
320   if (i>=DIALOG_MINWIDTH)
321     GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0);
322 
323   /* read height */
324   i=GWEN_DB_GetIntValue(dbPrefs, "dialog_height", 0, -1);
325   if (i>=DIALOG_MINHEIGHT)
326     GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0);
327 }
328 
329 
330 
AH_PinTanSpecialDialog_Fini(GWEN_DIALOG * dlg)331 void AH_PinTanSpecialDialog_Fini(GWEN_DIALOG *dlg)
332 {
333   AH_PINTAN_SPECIAL_DIALOG *xdlg;
334   int i;
335   GWEN_DB_NODE *dbPrefs;
336   uint32_t flags;
337   const char *s;
338 
339   assert(dlg);
340   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
341   assert(xdlg);
342 
343   dbPrefs=GWEN_Dialog_GetPreferences(dlg);
344 
345   /* fromGui */
346   i=GWEN_Dialog_GetIntProperty(dlg, "hbciVersionCombo", GWEN_DialogProperty_Value, 0, -1);
347   switch (i) {
348   case 0:
349     xdlg->hbciVersion=220;
350     break;
351   default:
352   case 1:
353     xdlg->hbciVersion=300;
354     break;
355   }
356 
357   i=GWEN_Dialog_GetIntProperty(dlg, "httpVersionCombo", GWEN_DialogProperty_Value, 0, -1);
358   switch (i) {
359   case 0:
360     xdlg->httpVMajor=1;
361     xdlg->httpVMinor=0;
362     break;
363   default:
364   case 1:
365     xdlg->httpVMajor=1;
366     xdlg->httpVMinor=1;
367     break;
368   }
369 
370   flags=0;
371   if (GWEN_Dialog_GetIntProperty(dlg, "noBase64Check", GWEN_DialogProperty_Value, 0, 0))
372     flags|=AH_USER_FLAGS_NO_BASE64;
373   if (GWEN_Dialog_GetIntProperty(dlg, "omitSmsAccountCheck", GWEN_DialogProperty_Value, 0, 0))
374     flags|=AH_USER_FLAGS_TAN_OMIT_SMS_ACCOUNT;
375   xdlg->flags=flags;
376 
377   s=GWEN_Dialog_GetCharProperty(dlg, "tanMediumIdEdit", GWEN_DialogProperty_Value, 0, NULL);
378   AH_PinTanSpecialDialog_SetTanMediumId(dlg, s);
379 
380   /* store dialog width */
381   i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1);
382   GWEN_DB_SetIntValue(dbPrefs,
383                       GWEN_DB_FLAGS_OVERWRITE_VARS,
384                       "dialog_width",
385                       i);
386 
387   /* store dialog height */
388   i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1);
389   GWEN_DB_SetIntValue(dbPrefs,
390                       GWEN_DB_FLAGS_OVERWRITE_VARS,
391                       "dialog_height",
392                       i);
393 }
394 
395 
396 
AH_PinTanSpecialDialog_HandleActivated(GWEN_DIALOG * dlg,const char * sender)397 int AH_PinTanSpecialDialog_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
398 {
399   DBG_NOTICE(0, "Activated: %s", sender);
400   if (strcasecmp(sender, "okButton")==0)
401     return GWEN_DialogEvent_ResultAccept;
402   else if (strcasecmp(sender, "abortButton")==0)
403     return GWEN_DialogEvent_ResultReject;
404   else if (strcasecmp(sender, "helpButton")==0) {
405     /* TODO: open a help dialog */
406   }
407 
408   return GWEN_DialogEvent_ResultNotHandled;
409 }
410 
411 
412 
AH_PinTanSpecialDialog_SignalHandler(GWEN_DIALOG * dlg,GWEN_DIALOG_EVENTTYPE t,const char * sender)413 int GWENHYWFAR_CB AH_PinTanSpecialDialog_SignalHandler(GWEN_DIALOG *dlg,
414                                                        GWEN_DIALOG_EVENTTYPE t,
415                                                        const char *sender)
416 {
417   AH_PINTAN_SPECIAL_DIALOG *xdlg;
418 
419   assert(dlg);
420   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_PINTAN_SPECIAL_DIALOG, dlg);
421   assert(xdlg);
422 
423   switch (t) {
424   case GWEN_DialogEvent_TypeInit:
425     AH_PinTanSpecialDialog_Init(dlg);
426     return GWEN_DialogEvent_ResultHandled;;
427 
428   case GWEN_DialogEvent_TypeFini:
429     AH_PinTanSpecialDialog_Fini(dlg);
430     return GWEN_DialogEvent_ResultHandled;;
431 
432   case GWEN_DialogEvent_TypeValueChanged:
433     return GWEN_DialogEvent_ResultHandled;;
434 
435   case GWEN_DialogEvent_TypeActivated:
436     return AH_PinTanSpecialDialog_HandleActivated(dlg, sender);
437 
438   case GWEN_DialogEvent_TypeEnabled:
439   case GWEN_DialogEvent_TypeDisabled:
440   case GWEN_DialogEvent_TypeClose:
441 
442   case GWEN_DialogEvent_TypeLast:
443     return GWEN_DialogEvent_ResultNotHandled;
444 
445   }
446 
447   return GWEN_DialogEvent_ResultNotHandled;
448 }
449 
450 
451 
452 
453 
454 
455