| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | // +build json | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package freedom | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | 	"encoding/json" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/v2ray/v2ray-core/common/serial" | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | 	"github.com/v2ray/v2ray-core/proxy/internal/config" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | func (this *Config) UnmarshalJSON(data []byte) error { | 
					
						
							|  |  |  | 	type JsonConfig struct { | 
					
						
							|  |  |  | 		DomainStrategy string `json:"domainStrategy"` | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	jsonConfig := new(JsonConfig) | 
					
						
							|  |  |  | 	if err := json.Unmarshal(data, jsonConfig); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	this.DomainStrategy = DomainStrategyAsIs | 
					
						
							| 
									
										
										
										
											2016-05-23 20:25:24 +02:00
										 |  |  | 	domainStrategy := serial.StringT(jsonConfig.DomainStrategy).ToLower() | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | 	if domainStrategy.String() == "useip" { | 
					
						
							|  |  |  | 		this.DomainStrategy = DomainStrategyUseIP | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | func init() { | 
					
						
							| 
									
										
										
										
											2016-01-25 17:19:09 +01:00
										 |  |  | 	config.RegisterOutboundConfig("freedom", | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | 		func(data []byte) (interface{}, error) { | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | 			c := new(Config) | 
					
						
							|  |  |  | 			if err := json.Unmarshal(data, c); err != nil { | 
					
						
							|  |  |  | 				return nil, err | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return c, nil | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | 		}) | 
					
						
							|  |  |  | } |