-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification.go
66 lines (61 loc) · 2.45 KB
/
notification.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
package libeuicc
/*
#include "es9p.h"
#include "es10b.h"
#include "tostr.h"
*/
import "C"
import (
"errors"
)
type Notification struct {
SeqNumber int
ProfileManagementOperation NotificationProfileManagementOperation
NotificationAddress string
Iccid string
}
// GetNotifications returns the list of notifications.
func (e *Libeuicc) GetNotifications() ([]*Notification, error) {
var cNotifications *C.struct_es10b_notification_metadata_list
if C.es10b_list_notification(e.euiccCtx, &cNotifications) == CError {
return nil, errors.New("es10b_list_notification failed")
}
defer C.es10b_notification_metadata_list_free_all(cNotifications)
var notifications []*Notification
for cNotification := cNotifications; cNotification != nil; cNotification = cNotification.next {
notifications = append(notifications, &Notification{
SeqNumber: int(cNotification.seqNumber),
ProfileManagementOperation: NotificationProfileManagementOperation(C.GoString(C.euicc_profilemanagementoperation2str(cNotification.profileManagementOperation))),
NotificationAddress: C.GoString(cNotification.notificationAddress),
Iccid: C.GoString(cNotification.iccid),
})
}
return notifications, nil
}
// ProcessNotification processes the notification with the given sequence number.
// If remove is true, the notification will be removed from the eUICC.
func (e *Libeuicc) ProcessNotification(seqNumber int, remove bool) error {
defer e.cleanupHttp()
var notification C.struct_es10b_pending_notification
if C.es10b_retrieve_notifications_list(e.euiccCtx, ¬ification, C.ulong(seqNumber)) == CError {
return errors.New("es10b_retrieve_notifications_list failed")
}
e.euiccCtx.http.server_address = notification.notificationAddress
if C.es9p_handle_notification(e.euiccCtx, notification.b64_PendingNotification) == CError {
return errors.New("es9p_handle_notification failed")
}
defer C.es10b_pending_notification_free(¬ification)
if remove {
if C.es10b_remove_notification_from_list(e.euiccCtx, C.ulong(seqNumber)) == CError {
return errors.New("es10b_remove_notification failed")
}
}
return nil
}
// DeleteNotification deletes the notification with the given sequence number.
func (e *Libeuicc) DeleteNotification(seqNumber int) error {
if C.es10b_remove_notification_from_list(e.euiccCtx, C.ulong(seqNumber)) == CError {
return errors.New("es10b_remove_notification failed")
}
return nil
}