1package tlsrptdb
2
3import (
4 "sync"
5
6 "github.com/mjl-/bstore"
7
8 "github.com/mjl-/mox/mlog"
9 "github.com/mjl-/mox/mox-"
10)
11
12var (
13 ReportDBTypes = []any{Record{}}
14 ReportDB *bstore.DB
15 mutex sync.Mutex
16
17 // Accessed directly by tlsrptsend.
18 ResultDBTypes = []any{TLSResult{}, SuppressAddress{}}
19 ResultDB *bstore.DB
20)
21
22// Init opens and possibly initializes the databases.
23func Init() error {
24 if _, err := reportDB(mox.Shutdown); err != nil {
25 return err
26 }
27 if _, err := resultDB(mox.Shutdown); err != nil {
28 return err
29 }
30 return nil
31}
32
33// Close closes the database connections.
34func Close() {
35 log := mlog.New("tlsrptdb", nil)
36 if ResultDB != nil {
37 err := ResultDB.Close()
38 log.Check(err, "closing result database")
39 ResultDB = nil
40 }
41
42 mutex.Lock()
43 defer mutex.Unlock()
44 if ReportDB != nil {
45 err := ReportDB.Close()
46 log.Check(err, "closing report database")
47 ReportDB = nil
48 }
49}
50