Skip to content

Commit

Permalink
Support multiple command elements
Browse files Browse the repository at this point in the history
  • Loading branch information
bodqhrohro authored and mremond committed May 16, 2024
1 parent 9af32ad commit 655f875
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
10 changes: 5 additions & 5 deletions stanza/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
type Command struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/commands command"`

CommandElement CommandElement
CommandElements []CommandElement

BadAction *struct{} `xml:"bad-action,omitempty"`
BadLocale *struct{} `xml:"bad-locale,omitempty"`
Expand Down Expand Up @@ -124,19 +124,19 @@ func (c *Command) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
case "actions":
a := Actions{}
err = d.DecodeElement(&a, &tt)
c.CommandElement = &a
c.CommandElements = append(c.CommandElements, &a)
case "note":
nt := Note{}
err = d.DecodeElement(&nt, &tt)
c.CommandElement = &nt
c.CommandElements = append(c.CommandElements, &nt)
case "x":
f := Form{}
err = d.DecodeElement(&f, &tt)
c.CommandElement = &f
c.CommandElements = append(c.CommandElements, &f)
default:
n := Node{}
err = d.DecodeElement(&n, &tt)
c.CommandElement = &n
c.CommandElements = append(c.CommandElements, &n)
if err != nil {
return err
}
Expand Down
21 changes: 14 additions & 7 deletions stanza/pubsub_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ func NewApprovePendingSubRequest(serviceId, sessionId, nodeId string) (*IQ, erro
}
iq.Payload = &Command{
// the command name ('node' attribute of the command element) MUST have a value of "http://jabber.org/protocol/pubsub#get-pending"
Node: "http://jabber.org/protocol/pubsub#get-pending",
Action: CommandActionExecute,
SessionId: sessionId,
CommandElement: &n,
Node: "http://jabber.org/protocol/pubsub#get-pending",
Action: CommandActionExecute,
SessionId: sessionId,
CommandElements: []CommandElement{&n},
}
return iq, nil
}
Expand Down Expand Up @@ -353,11 +353,18 @@ func (iq *IQ) GetFormFields() (map[string]*Field, error) {

case *Command:
fieldMap := make(map[string]*Field)
co, ok := payload.CommandElement.(*Form)
if !ok {
var form *Form
for _, ce := range payload.CommandElements {
fo, ok := ce.(*Form)
if ok {
form = fo
break
}
}
if form == nil {
return nil, errors.New("this IQ does not contain a command payload with a form")
}
for _, elt := range co.Fields {
for _, elt := range form.Fields {
fieldMap[elt.Var] = elt
}
return fieldMap, nil
Expand Down

0 comments on commit 655f875

Please sign in to comment.