mirror of
https://github.com/veops/oneterm.git
synced 2025-10-30 18:36:26 +08:00
feat: guacd for rdp/vnc
This commit is contained in:
46
backend/pkg/server/guacd/instruction.go
Normal file
46
backend/pkg/server/guacd/instruction.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package guacd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
const Delimiter = ';'
|
||||
|
||||
type Instruction struct {
|
||||
Opcode string
|
||||
Args []string
|
||||
cache string
|
||||
}
|
||||
|
||||
func NewInstruction(opcode string, args ...string) *Instruction {
|
||||
return &Instruction{
|
||||
Opcode: opcode,
|
||||
Args: args,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Instruction) String() string {
|
||||
if len(i.cache) > 0 {
|
||||
return i.cache
|
||||
}
|
||||
|
||||
i.cache = fmt.Sprintf("%d.%s", len(i.Opcode), i.Opcode)
|
||||
for _, value := range i.Args {
|
||||
i.cache += fmt.Sprintf(",%d.%s", len(value), value)
|
||||
}
|
||||
i.cache += string(Delimiter)
|
||||
return i.cache
|
||||
}
|
||||
|
||||
func (i *Instruction) Parse(content string) *Instruction {
|
||||
if strings.LastIndex(content, ";") > 0 {
|
||||
content = strings.TrimRight(content, ";")
|
||||
}
|
||||
elements := strings.Split(content, ",")
|
||||
|
||||
var args = make([]string, len(elements))
|
||||
for i, e := range elements {
|
||||
args[i] = strings.Split(e, ".")[1]
|
||||
}
|
||||
return NewInstruction(args[0], args[1:]...)
|
||||
}
|
||||
Reference in New Issue
Block a user