Files
opera-proxy/seclient/messages.go
T

97 lines
1.7 KiB
Go
Raw Normal View History

2021-03-25 19:58:30 +02:00
package seclient
import (
"encoding/json"
"errors"
"fmt"
"net"
2021-03-25 19:58:30 +02:00
"strconv"
)
2021-03-25 20:29:37 +02:00
const (
SE_STATUS_OK int64 = 0
)
2021-03-25 19:58:30 +02:00
type SEStatusPair struct {
2021-03-25 20:29:37 +02:00
Code int64
Message string
2021-03-25 19:58:30 +02:00
}
func (p *SEStatusPair) UnmarshalJSON(b []byte) error {
var tmp map[string]string
err := json.Unmarshal(b, &tmp)
if err != nil {
return err
}
if len(tmp) != 1 {
return errors.New("ambiguous status")
}
var strCode, strStatus string
for k, v := range tmp {
strCode = k
strStatus = v
}
code, err := strconv.ParseInt(strCode, 10, 64)
if err != nil {
return err
}
*p = SEStatusPair{
2021-03-25 20:29:37 +02:00
Code: code,
Message: strStatus,
2021-03-25 19:58:30 +02:00
}
return nil
}
2021-03-25 20:29:37 +02:00
type SERegisterSubscriberResponse struct {
Data interface{} `json:"data"`
Status SEStatusPair `json:"return_code"`
}
2021-03-25 22:09:36 +02:00
type SERegisterDeviceData struct {
ClientType string `json:"client_type"`
DeviceID string `json:"device_id"`
DevicePassword string `json:"device_password"`
}
type SERegisterDeviceResponse struct {
Data SERegisterDeviceData `json:"data"`
Status SEStatusPair `json:"return_code"`
}
2021-03-26 21:52:09 +02:00
type SEGeoEntry struct {
2021-03-26 22:09:37 +02:00
Country string `json:"country,omitempty"`
2021-03-26 21:52:09 +02:00
CountryCode string `json:"country_code"`
}
type SEGeoListResponse struct {
Data struct {
Geos []SEGeoEntry `json:"geos"`
2021-03-26 22:09:37 +02:00
} `json:"data"`
Status SEStatusPair `json:"return_code"`
}
type SEIPEntry struct {
Geo SEGeoEntry `json:"geo"`
IP string `json:"ip"`
Ports []uint16 `json:"ports"`
}
2021-03-27 00:43:33 +02:00
func (e *SEIPEntry) NetAddr() string {
if len(e.Ports) == 0 {
return net.JoinHostPort(e.IP, "443")
} else {
return net.JoinHostPort(e.IP, fmt.Sprintf("%d", e.Ports[0]))
}
}
2021-03-26 22:09:37 +02:00
type SEDiscoverResponse struct {
Data struct {
IPs []SEIPEntry `json:"ips"`
} `json:"data"`
Status SEStatusPair `json:"return_code"`
2021-03-26 21:52:09 +02:00
}