fix: command handlers are now atomically locked

This commit is contained in:
evilsocket 2019-02-26 13:26:28 +01:00
commit e46ea6c9a9
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
3 changed files with 21 additions and 12 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"regexp"
"strconv"
"sync"
"github.com/evilsocket/islazy/str"
"github.com/evilsocket/islazy/tui"
@ -15,11 +16,13 @@ import (
const IPv4Validator = `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`
type ModuleHandler struct {
sync.Mutex
Name string
Description string
Parser *regexp.Regexp
Exec func(args []string) error
Completer *readline.PrefixCompleter
exec func(args []string) error
}
func NewModuleHandler(name string, expr string, desc string, exec func(args []string) error) ModuleHandler {
@ -27,7 +30,7 @@ func NewModuleHandler(name string, expr string, desc string, exec func(args []st
Name: name,
Description: desc,
Parser: nil,
Exec: exec,
exec: exec,
}
if expr != "" {
@ -62,6 +65,12 @@ func (h *ModuleHandler) Parse(line string) (bool, []string) {
return false, nil
}
func (h *ModuleHandler) Exec(args []string) error {
h.Lock()
defer h.Unlock()
return h.exec(args)
}
type JSONModuleHandler struct {
Name string `json:"name"`
Description string `json:"description"`