2016-01-15 11:43:06 +00:00
|
|
|
// +build json
|
|
|
|
|
|
|
|
package inbound
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2016-02-03 10:58:42 +00:00
|
|
|
proto "github.com/v2ray/v2ray-core/common/protocol"
|
2016-01-15 11:43:06 +00:00
|
|
|
"github.com/v2ray/v2ray-core/proxy/internal/config"
|
|
|
|
)
|
|
|
|
|
2016-01-19 00:21:07 +00: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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
|
|
|
type JsonConfig struct {
|
2016-02-03 10:58:42 +00:00
|
|
|
Users []*proto.User `json:"clients"`
|
2016-01-19 00:21:07 +00:00
|
|
|
Features *FeaturesConfig `json:"features"`
|
|
|
|
}
|
|
|
|
jsonConfig := new(JsonConfig)
|
|
|
|
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
this.AllowedUsers = jsonConfig.Users
|
|
|
|
this.Features = jsonConfig.Features
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-15 11:43:06 +00:00
|
|
|
func init() {
|
2016-01-25 16:19:09 +00:00
|
|
|
config.RegisterInboundConfig("vmess",
|
2016-01-15 11:43:06 +00:00
|
|
|
func(data []byte) (interface{}, error) {
|
2016-01-19 00:21:07 +00:00
|
|
|
config := new(Config)
|
|
|
|
err := json.Unmarshal(data, config)
|
|
|
|
return config, err
|
2016-01-15 11:43:06 +00:00
|
|
|
})
|
|
|
|
}
|