Files
sam-forwarder/config/type.go

110 lines
1.9 KiB
Go
Raw Normal View History

2018-09-13 18:14:22 -04:00
package i2ptunconf
import (
"strings"
)
2018-09-13 18:14:22 -04:00
// GetType takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetTypes(argc, argu, argh bool, def string, label ...string) string {
2018-09-13 18:14:22 -04:00
var typ string
if argu {
typ += "udp"
}
if argc {
2019-04-25 23:52:08 -04:00
if argh == true {
typ += "http"
}
2018-09-13 18:14:22 -04:00
typ += "client"
c.Client = true
} else {
if argh == true {
typ += "http"
} else {
typ += "server"
}
2019-09-02 20:46:17 -04:00
if typ != def {
return typ
}
2018-09-13 18:14:22 -04:00
}
if def == "kcpclient" {
2019-09-02 20:46:17 -04:00
return def
}
if def == "kcpserver" {
2019-09-02 20:46:17 -04:00
return def
}
2019-09-02 20:46:17 -04:00
if def == "eephttpd" {
return def
}
if def == "vpnclient" {
return def
}
if def == "vpnserver" {
return def
}
if def == "browserclient" {
return def
}
if c.Config == nil {
return typ
}
if x, o := c.Get("type", label...); o {
return x
}
return def
}
func (c *Conf) GetOtherType(typ, def string, label ...string) string {
2018-09-13 18:14:22 -04:00
if typ != def {
return typ
}
2018-11-29 19:05:19 -05:00
if c.Config == nil {
2018-09-13 18:14:22 -04:00
return typ
}
if x, o := c.Get("type", label...); o {
return x
}
return def
}
// SetType sets the type of proxy to create from the config file
func (c *Conf) SetType(label ...string) {
if v, ok := c.Get("type", label...); ok {
if strings.Contains(v, "client") {
c.Client = true
}
2019-08-25 20:32:50 -04:00
switch c.Type {
case "server":
2018-09-13 18:14:22 -04:00
c.Type = v
2019-08-25 20:32:50 -04:00
case "http":
c.Type = v
case "client":
c.Type = v
case "httpclient":
c.Type = v
case "browserclient":
c.Type = v
case "udpserver":
c.Type = v
case "udpclient":
c.Type = v
2019-09-02 20:46:17 -04:00
case "eephttpd":
c.Type = v
2019-08-25 20:32:50 -04:00
case "vpnserver":
c.Type = v
case "vpnclient":
c.Type = v
case "kcpclient":
c.Type = v
case "kcpserver":
c.Type = v
default:
c.Type = "browserclient"
2018-09-13 18:14:22 -04:00
}
} else {
2019-08-25 20:32:50 -04:00
c.Type = "browserclient"
}
}