This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gui.go
84 lines (71 loc) · 2 KB
/
gui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package aqbanking
/*
#cgo LDFLAGS: -laqbanking
#cgo LDFLAGS: -lgwenhywfar
#cgo darwin CFLAGS: -I/usr/local/include/gwenhywfar5
#cgo darwin CFLAGS: -I/usr/local/include/aqbanking6
#cgo linux CFLAGS: -I/usr/include/gwenhywfar5
#cgo linux CFLAGS: -I/usr/include/aqbanking6
#include <gwenhywfar/cgui.h>
#include <aqbanking/gui/abgui.h>
#include <gwenhywfar/gwenhywfar.h>
// forward declaration to allow cgui.go to use our go callback fnc
int goAqbankingGetPasswordFn_cgo(
GWEN_GUI *gui,
uint32_t flags,
const char *token,
const char *title,
const char *text,
char *buffer,
int minLen,
int maxLen,
uint32_t guiid
);
*/
import "C"
import (
"fmt"
"unsafe"
)
type gui struct {
ptr *C.struct_GWEN_GUI
}
//export aqbankingGetPasswordFn
func aqbankingGetPasswordFn(token *C.char, buffer unsafe.Pointer, minLen, maxLen int) int {
pin, ok := knownAqbankingPins[C.GoString(token)]
if ok {
C.memcpy(buffer, unsafe.Pointer(C.CString(pin)), C.size_t(len(pin)))
}
return 0
}
var knownAqbankingPins = map[string]string{}
func newGui(interactive bool) *gui {
abGui := C.GWEN_Gui_CGui_new()
if !interactive {
C.GWEN_Gui_SetFlags(abGui, C.GWEN_GUI_FLAGS_ACCEPTVALIDCERTS|C.GWEN_GUI_FLAGS_NONINTERACTIVE)
} else {
C.GWEN_Gui_SetFlags(abGui, C.GWEN_GUI_FLAGS_ACCEPTVALIDCERTS)
}
C.GWEN_Gui_SetCharSet(abGui, C.CString("UTF-8"))
C.GWEN_Gui_SetGui(abGui)
C.GWEN_Gui_SetGetPasswordFn(abGui, (C.GWEN_GUI_GETPASSWORD_FN)(C.goAqbankingGetPasswordFn_cgo))
return &gui{
abGui,
}
}
func newNonInteractiveGui() *gui {
return newGui(false)
}
func (g *gui) attach(aq *AQBanking) {
C.AB_Gui_Extend(g.ptr, aq.ptr)
}
// RegisterPin registers a given Pin code with the aqbanking gui.
// pins can be added at any point in time prior to making a request.
// Pins are stored in memory only. When the process exits, all pins are forgotten.
func (ab *AQBanking) RegisterPin(pin Pin) {
key := fmt.Sprintf("PIN_%v_%v", pin.BankCode(), pin.UserID())
knownAqbankingPins[key] = pin.Pin()
}
func (g *gui) free() {
C.GWEN_Gui_free(g.ptr)
}