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
/
aqbanking.go
107 lines (87 loc) · 2.65 KB
/
aqbanking.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Package aqbanking is a go wrapper around aqbanking version 5.0.24 to 5.5.1
//
// Details about aqbanking are available at the official homepage: http://www.aqbanking.de/
package aqbanking
import (
"fmt"
"unsafe"
)
/*
#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 <aqbanking/banking.h>
*/
import "C"
// Version wraps AQBanking version informations
type Version struct {
Major int
Minor int
Patchlevel int
}
// AQBanking represents a single aqbanking database path, located at a given path
type AQBanking struct {
Name string
Version Version
gui *gui
ptr *C.AB_BANKING
}
// NewAQBanking creates a new AQBanking instance, given valid database path and name
func NewAQBanking(name string, dbPath string) (*AQBanking, error) {
inst := &AQBanking{
Name: name,
Version: getVersion(),
}
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
var cPath *C.char
if dbPath != "" {
cPath := C.CString(dbPath)
defer C.free(unsafe.Pointer(cPath))
}
inst.ptr = C.AB_Banking_new(cName, cPath, 0)
inst.gui = newNonInteractiveGui()
inst.gui.attach(inst)
if err := C.AB_Banking_Init(inst.ptr); err != 0 {
return nil, newError("unable to initialize aqbanking", err)
}
// version string is not allowed to be longer than 5 characters
inst.SetRuntimeConfig("fintsApplicationVersionString", fmt.Sprintf("%d.%d", inst.Version.Major, inst.Version.Minor))
inst.SetRuntimeConfig("fintsRegistrationKey", "32F8A67FE34B57AB8D7E4FE70")
return inst, nil
}
// DefaultAQBanking returns an aqbanking instance initialized with aqbankings default
// database path (most likely $HOME)
func DefaultAQBanking() (*AQBanking, error) {
return NewAQBanking("local", "")
}
// SetRuntimeConfig sets a runtime configuration value
func (ab *AQBanking) SetRuntimeConfig(key, value string) {
cKey := C.CString(key)
cValue := C.CString(value)
C.AB_Banking_RuntimeConfig_SetCharValue(ab.ptr, cKey, cValue)
C.free(unsafe.Pointer(cKey))
C.free(unsafe.Pointer(cValue))
}
// Free frees all underlying aqbanking pointers
func (ab *AQBanking) Free() error {
ab.gui.free()
C.AB_Banking_Fini(ab.ptr)
C.AB_Banking_free(ab.ptr)
return nil
}
func getVersion() Version {
var major, minor, patchlevel, build C.int
C.AB_Banking_GetVersion(&major, &minor, &patchlevel, &build)
return Version{
int(major),
int(minor),
int(patchlevel),
}
}
func (version Version) String() string {
return fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patchlevel)
}