Skip to content

Commit

Permalink
share url parse shadowsocks SIP003 plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
whalechoi committed Apr 2, 2024
1 parent 859caa1 commit a61daf8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 10 additions & 0 deletions main/shareurls/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ func parseShadowsocks(ssUrl string) (ShareUrl, error) {
methodAndPassword := strings.Split(info, ":")
ss.Method = methodAndPassword[0]
ss.Password = methodAndPassword[1]
ssQuery, err := url.ParseQuery(ssParse.RawQuery)
if err != nil {
return nil, e.New("shadowsocks url parse query err, ", err).WithPrefix(tagParser)
}
//parse shadowsocks SIP003 plugin
if plugins, ok := ssQuery["plugin"]; ok && len(plugins) == 1 {
plugin := strings.Split(plugins[0], ";")
ss.Plugin = plugin[0]
ss.PluginOpt = strings.TrimPrefix(plugins[0], plugin[0]+";")
}
}
return ss, nil
}
Expand Down
18 changes: 13 additions & 5 deletions main/shareurls/shadowsocks/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
const tagShadowsocks = "shadowsocks"

type Shadowsocks struct {
Remarks string
Server string
Port string
Method string
Password string
Remarks string
Server string
Port string
Method string
Password string
Plugin string
PluginOpt string
}

func (this *Shadowsocks) GetNodeInfo() string {
Expand All @@ -38,6 +40,12 @@ func (this *Shadowsocks) ToOutboundWithTag(coreType string, tag string) (interfa
outboundObject["server_port"], _ = strconv.Atoi(this.Port)
outboundObject["method"] = this.Method
outboundObject["password"] = this.Password
if len(this.Plugin) > 0 {
outboundObject["plugin"] = this.Plugin
}
if len(this.PluginOpt) > 0 {
outboundObject["plugin_opts"] = this.PluginOpt
}
return outboundObject, nil
default:
return nil, e.New("unsupported core type " + coreType).WithPrefix(tagShadowsocks).WithPathObj(*this)
Expand Down

0 comments on commit a61daf8

Please sign in to comment.