new: HID devices are now exported by the api.rest module

This commit is contained in:
evilsocket 2019-02-21 11:43:48 +01:00
commit e0e1f4e6df
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
5 changed files with 64 additions and 7 deletions

View file

@ -1,6 +1,7 @@
package network
import (
"encoding/json"
"sync"
"time"
)
@ -15,6 +16,10 @@ type HID struct {
lostCb HIDDevLostCallback
}
type hidJSON struct {
Devices []*HIDDevice `json:"devices"`
}
func NewHID(newcb HIDDevNewCallback, lostcb HIDDevLostCallback) *HID {
return &HID{
devices: make(map[string]*HIDDevice),
@ -23,6 +28,18 @@ func NewHID(newcb HIDDevNewCallback, lostcb HIDDevLostCallback) *HID {
}
}
func (h *HID) MarshalJSON() ([]byte, error) {
doc := hidJSON{
Devices: make([]*HIDDevice, 0),
}
for _, dev := range h.devices {
doc.Devices = append(doc.Devices, dev)
}
return json.Marshal(doc)
}
func (b *HID) Get(id string) (dev *HIDDevice, found bool) {
b.RLock()
defer b.RUnlock()