Debian Codegraph @

session/session_parse.go

raw symbols SCIP
1 package sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/"
5 "stringsscip-go gomod github.com/golang/go/src go1.16 strings/"
6
7 "github.com/evilsocket/islazy/strscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/"
8 )
9
10 func ParseCommandsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/ParseCommands().(line string) []string {
11 args := []string{}
12 buf := ""
13
14 singleQuoted := false
15 doubleQuoted := false
16 finish := false
17
18 line = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(line, `""`, `"<empty>"`, -1)
19 line = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(line, `''`, `"<empty>"`, -1)
20 for _, c := range line {
21 switch c {
22 case ';':
23 if !singleQuoted && !doubleQuoted {
24 finish = true
25 } else {
26 buf += string(c)
27 }
28
29 case '"':
30 if doubleQuoted {
31 // finish of quote
32 doubleQuoted = false
33 } else if singleQuoted {
34 // quote initiated with ', so we ignore it
35 buf += string(c)
36 } else {
37 // quote init here
38 doubleQuoted = true
39 }
40
41 case '\'':
42 if singleQuoted {
43 singleQuoted = false
44 } else if doubleQuoted {
45 buf += string(c)
46 } else {
47 singleQuoted = true
48 }
49
50 default:
51 buf += string(c)
52 }
53
54 if finish {
55 buf = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(buf, `<empty>`, `""`, -1)
56 args = append(args, buf)
57 finish = false
58 buf = ""
59 }
60 }
61
62 if len(buf) > 0 {
63 buf = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(buf, `<empty>`, `""`, -1)
64 args = append(args, buf)
65 }
66
67 cmds := make([]string, 0)
68 for _, cmd := range args {
69 cmd = strscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/.Trimscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/Trim().(cmd)
70 if cmd != "" || (len(cmd) > 0 && cmd[0] != '#') {
71 cmds = append(cmds, cmd)
72 }
73 }
74
75 return cmds
76 }
77
78 func (s *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) parseEnvTokensscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#parseEnvTokens().(str string) (string, error) {
79 for _, m := range reEnvVarCapturescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/reEnvVarCapture..FindAllStringscip-go gomod github.com/golang/go/src go1.16 regexp/Regexp#FindAllString().(str, -1) {
80 varName := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Trimscip-go gomod github.com/golang/go/src go1.16 strings/Trim().(stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(m, "env.", "", -1), "{}")
81 if found, value := s.Envscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Env..Getscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Get().(varName); found {
82 str = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(str, m, value, -1)
83 } else {
84 return "", fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("variable '%s' is not defined", varName)
85 }
86 }
87 return str, nil
88 }