1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-19 10:56:06 -05:00
v2fly/proxy/vmess/inbound/config_json.go

88 lines
2.1 KiB
Go
Raw Normal View History

// +build json
package inbound
import (
"encoding/json"
proto "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy/internal/config"
)
2016-01-18 19:21:07 -05:00
func (this *DetourConfig) UnmarshalJSON(data []byte) error {
type JsonDetourConfig struct {
ToTag string `json:"to"`
}
jsonConfig := new(JsonDetourConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.ToTag = jsonConfig.ToTag
return nil
}
func (this *FeaturesConfig) UnmarshalJSON(data []byte) error {
type JsonFeaturesConfig struct {
Detour *DetourConfig `json:"detour"`
}
jsonConfig := new(JsonFeaturesConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.Detour = jsonConfig.Detour
return nil
}
2016-02-25 08:38:41 -05:00
func (this *DefaultConfig) UnmarshalJSON(data []byte) error {
type JsonDefaultConfig struct {
AlterIDs uint16 `json:"alterId"`
Level byte `json:"level"`
}
jsonConfig := new(JsonDefaultConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.AlterIDs = jsonConfig.AlterIDs
if this.AlterIDs == 0 {
this.AlterIDs = 32
}
this.Level = proto.UserLevel(jsonConfig.Level)
return nil
}
2016-01-18 19:21:07 -05:00
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
2016-04-24 16:40:43 -04:00
Users []*proto.User `json:"clients"`
Features *FeaturesConfig `json:"features"`
Defaults *DefaultConfig `json:"default"`
DetourConfig *DetourConfig `json:"detour"`
2016-01-18 19:21:07 -05:00
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.AllowedUsers = jsonConfig.Users
2016-04-24 16:54:41 -04:00
this.Features = jsonConfig.Features // Backward compatibility
2016-02-25 08:38:41 -05:00
this.Defaults = jsonConfig.Defaults
if this.Defaults == nil {
this.Defaults = &DefaultConfig{
Level: proto.UserLevel(0),
AlterIDs: 32,
}
}
2016-04-24 16:54:41 -04:00
// Backward compatibility
2016-04-24 16:40:43 -04:00
if this.Features != nil && this.DetourConfig == nil {
this.DetourConfig = this.Features.Detour
}
2016-01-18 19:21:07 -05:00
return nil
}
func init() {
config.RegisterInboundConfig("vmess",
func(data []byte) (interface{}, error) {
2016-01-18 19:21:07 -05:00
config := new(Config)
err := json.Unmarshal(data, config)
return config, err
})
}