2018-11-29 08:19:40 +00:00
|
|
|
package curl2info
|
|
|
|
|
|
|
|
func init() {
|
2018-11-29 08:26:31 +00:00
|
|
|
optionTrie = newTrie()
|
2018-11-29 08:19:40 +00:00
|
|
|
oelist := []*optionExecute{
|
|
|
|
{"-H", 10, parseHeader, nil},
|
|
|
|
{"-X", 10, parseOptX, nil},
|
|
|
|
{"-A", 15, parseUserAgent, &extract{re: "^-A +(.+)", execute: extractData}},
|
|
|
|
{"-I", 15, parseOptI, nil},
|
|
|
|
{"-d", 10, parseBodyASCII, &extract{re: "^-d +(.+)", execute: extractData}},
|
|
|
|
{"-u", 15, parseUser, &extract{re: "^-u +(.+)", execute: extractData}},
|
|
|
|
{"-k", 15, parseInsecure, nil},
|
|
|
|
// Body
|
|
|
|
{"--data", 10, parseBodyASCII, &extract{re: "--data +(.+)", execute: extractData}},
|
|
|
|
{"--data-urlencode", 10, parseBodyURLEncode, &extract{re: "--data-urlencode +(.+)", execute: extractData}},
|
|
|
|
{"--data-binary", 10, parseBodyBinary, &extract{re: "--data-binary +(.+)", execute: extractData}},
|
|
|
|
{"--data-ascii", 10, parseBodyASCII, &extract{re: "--data-ascii +(.+)", execute: extractData}},
|
|
|
|
{"--data-raw", 10, parseBodyRaw, &extract{re: "--data-raw +(.+)", execute: extractData}},
|
|
|
|
//"--"
|
|
|
|
{"--header", 10, parseHeader, nil},
|
|
|
|
{"--insecure", 15, parseInsecure, nil},
|
2018-11-30 09:03:17 +00:00
|
|
|
{"--task", 10, parseITask, &extract{re: "--task +(.+)", execute: extractData}},
|
2018-11-29 08:19:40 +00:00
|
|
|
{"--user-agent", 15, parseUserAgent, &extract{re: "--user-agent +(.+)", execute: extractData}},
|
|
|
|
{"--user", 15, parseUser, &extract{re: "--user +(.+)", execute: extractData}},
|
|
|
|
{"--connect-timeout", 15, parseTimeout, &extract{re: "--connect-timeout +(.+)", execute: extractData}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, oe := range oelist {
|
|
|
|
optionTrie.Insert(oe)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Println("support options:", optionTrie.AllWords())
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract 用于提取设置的数据
|
|
|
|
type extract struct {
|
|
|
|
re string
|
|
|
|
execute func(re, soption string) string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (et *extract) Execute(soption string) string {
|
|
|
|
return et.execute(et.re, soption)
|
|
|
|
}
|
|
|
|
|
|
|
|
// OptionTrie 设置的前缀树
|
2018-11-29 08:26:31 +00:00
|
|
|
var optionTrie *hTrie
|
2018-11-29 08:19:40 +00:00
|
|
|
|
|
|
|
type optionExecute struct {
|
|
|
|
Prefix string
|
|
|
|
|
|
|
|
Priority int
|
|
|
|
|
|
|
|
Execute func(*CURL, string) // 执行函数
|
|
|
|
Extract *extract // 提取的方法结构与参数
|
|
|
|
}
|
|
|
|
|
|
|
|
func (oe *optionExecute) GetWord() string {
|
|
|
|
return oe.Prefix + " "
|
|
|
|
}
|
|
|
|
|
|
|
|
func (oe *optionExecute) BuildFunction(curl *CURL, soption string) *parseFunction {
|
|
|
|
data := soption
|
|
|
|
if oe.Extract != nil {
|
|
|
|
data = oe.Extract.Execute(data)
|
|
|
|
}
|
|
|
|
return &parseFunction{ParamCURL: curl, ParamData: data, ExecuteFunction: oe.Execute, Priority: oe.Priority}
|
|
|
|
}
|