aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2024-02-03 18:33:37 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2024-02-03 18:33:37 +0300
commite7d5a2a2666adc13c3046e89b30fae87aa5d06e3 (patch)
tree12e954f2e03f1b7781e2e04032440db90798f2c4
parent21dc5fa6c6c843fcf263b6483d21bc4b284aad1c (diff)
Accept forms with arbitrary action
-rw-r--r--xmpp/handlers.go94
1 files changed, 46 insertions, 48 deletions
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index c71fc19..c6406e9 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -706,62 +706,60 @@ func handleSetQueryCommand(s xmpp.Sender, iq *stanza.IQ, command *stanza.Command
if !ok {
return
}
+ _, toOk := toToID(iq.To)
var cmdString string
- if command.Action == "" || command.Action == stanza.CommandActionExecute {
- _, ok := toToID(iq.To)
- if !ok {
- cmd, ok := telegram.GetCommand(telegram.CommandTypeTransport, command.Node)
- if ok && cmd.RequiredArgs > 0 {
- var fields []*stanza.Field
- for i, arg := range cmd.Arguments {
- fields = append(fields, &stanza.Field{
- Var: strconv.FormatInt(int64(i), 10),
- Label: arg,
- })
+ if !toOk {
+ form, formOk := command.CommandElement.(*stanza.Form)
+ if formOk {
+ // just for the case the client messed the order somehow
+ sort.Slice(form.Fields, func(i int, j int) bool {
+ iField := form.Fields[i]
+ jField := form.Fields[j]
+ if iField != nil && jField != nil {
+ ii, iErr := strconv.ParseInt(iField.Var, 10, 64)
+ ji, jErr := strconv.ParseInt(jField.Var, 10, 64)
+ return iErr == nil && jErr == nil && ii < ji
}
- answer.Payload = &stanza.Command{
- SessionId: command.Node,
- Node: command.Node,
- Status: stanza.CommandStatusExecuting,
- CommandElement: &stanza.Form{
- Title: command.Node,
- Instructions: []string{cmd.Description},
- Fields: fields,
- },
+ return false
+ })
+
+ var cmd strings.Builder
+ cmd.WriteString("/")
+ cmd.WriteString(command.Node)
+ for _, field := range form.Fields {
+ cmd.WriteString(" ")
+ if len(field.ValuesList) > 0 {
+ cmd.WriteString(field.ValuesList[0])
}
- } else {
- cmdString = "/" + command.Node
}
- }
- } else if command.Action == stanza.CommandActionComplete {
- _, ok := toToID(iq.To)
- if !ok {
- form, ok := command.CommandElement.(*stanza.Form)
- if ok {
- // just for the case the client messed the order somehow
- sort.Slice(form.Fields, func(i int, j int) bool {
- iField := form.Fields[i]
- jField := form.Fields[j]
- if iField != nil && jField != nil {
- ii, iErr := strconv.ParseInt(iField.Var, 10, 64)
- ji, jErr := strconv.ParseInt(jField.Var, 10, 64)
- return iErr == nil && jErr == nil && ii < ji
+
+ cmdString = cmd.String()
+ } else {
+ if command.Action == "" || command.Action == stanza.CommandActionExecute {
+ cmd, ok := telegram.GetCommand(telegram.CommandTypeTransport, command.Node)
+ if ok && cmd.RequiredArgs > 0 {
+ var fields []*stanza.Field
+ for i, arg := range cmd.Arguments {
+ fields = append(fields, &stanza.Field{
+ Var: strconv.FormatInt(int64(i), 10),
+ Label: arg,
+ })
}
- return false
- })
-
- var cmd strings.Builder
- cmd.WriteString("/")
- cmd.WriteString(command.Node)
- for _, field := range form.Fields {
- cmd.WriteString(" ")
- if len(field.ValuesList) > 0 {
- cmd.WriteString(field.ValuesList[0])
+ answer.Payload = &stanza.Command{
+ SessionId: command.Node,
+ Node: command.Node,
+ Status: stanza.CommandStatusExecuting,
+ CommandElement: &stanza.Form{
+ Type: stanza.FormTypeForm,
+ Title: command.Node,
+ Instructions: []string{cmd.Description},
+ Fields: fields,
+ },
}
+ } else {
+ cmdString = "/" + command.Node
}
-
- cmdString = cmd.String()
}
}
}