Compare commits
12 commits
160-regres
...
process-on
Author | SHA1 | Date | |
---|---|---|---|
Bohdan Horbeshko | 6725c38623 | ||
Bohdan Horbeshko | a21cbec9ec | ||
Bohdan Horbeshko | 380694353e | ||
Bohdan Horbeshko | 18c46e6c59 | ||
Bohdan Horbeshko | 9fa807d7ed | ||
Bohdan Horbeshko | 023858225b | ||
Bohdan Horbeshko | 35d9cd68e5 | ||
Bohdan Horbeshko | 69619ebc6d | ||
Bohdan Horbeshko | 306b4ff58e | ||
Bohdan Horbeshko | 39809352e2 | ||
Bohdan Horbeshko | f8c4ecb59d | ||
9abd5be0aa |
|
@ -23,7 +23,7 @@ const (
|
||||||
type Command struct {
|
type Command struct {
|
||||||
XMLName xml.Name `xml:"http://jabber.org/protocol/commands command"`
|
XMLName xml.Name `xml:"http://jabber.org/protocol/commands command"`
|
||||||
|
|
||||||
CommandElement CommandElement
|
CommandElements []CommandElement
|
||||||
|
|
||||||
BadAction *struct{} `xml:"bad-action,omitempty"`
|
BadAction *struct{} `xml:"bad-action,omitempty"`
|
||||||
BadLocale *struct{} `xml:"bad-locale,omitempty"`
|
BadLocale *struct{} `xml:"bad-locale,omitempty"`
|
||||||
|
@ -56,6 +56,8 @@ type CommandElement interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Actions struct {
|
type Actions struct {
|
||||||
|
XMLName xml.Name `xml:"actions"`
|
||||||
|
|
||||||
Prev *struct{} `xml:"prev,omitempty"`
|
Prev *struct{} `xml:"prev,omitempty"`
|
||||||
Next *struct{} `xml:"next,omitempty"`
|
Next *struct{} `xml:"next,omitempty"`
|
||||||
Complete *struct{} `xml:"complete,omitempty"`
|
Complete *struct{} `xml:"complete,omitempty"`
|
||||||
|
@ -68,6 +70,8 @@ func (a *Actions) Ref() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Note struct {
|
type Note struct {
|
||||||
|
XMLName xml.Name `xml:"note"`
|
||||||
|
|
||||||
Text string `xml:",cdata"`
|
Text string `xml:",cdata"`
|
||||||
Type string `xml:"type,attr,omitempty"`
|
Type string `xml:"type,attr,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -117,22 +121,22 @@ func (c *Command) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
var err error
|
var err error
|
||||||
switch tt.Name.Local {
|
switch tt.Name.Local {
|
||||||
|
|
||||||
case "affiliations":
|
case "actions":
|
||||||
a := Actions{}
|
a := Actions{}
|
||||||
err = d.DecodeElement(&a, &tt)
|
err = d.DecodeElement(&a, &tt)
|
||||||
c.CommandElement = &a
|
c.CommandElements = append(c.CommandElements, &a)
|
||||||
case "configure":
|
case "note":
|
||||||
nt := Note{}
|
nt := Note{}
|
||||||
err = d.DecodeElement(&nt, &tt)
|
err = d.DecodeElement(&nt, &tt)
|
||||||
c.CommandElement = &nt
|
c.CommandElements = append(c.CommandElements, &nt)
|
||||||
case "x":
|
case "x":
|
||||||
f := Form{}
|
f := Form{}
|
||||||
err = d.DecodeElement(&f, &tt)
|
err = d.DecodeElement(&f, &tt)
|
||||||
c.CommandElement = &f
|
c.CommandElements = append(c.CommandElements, &f)
|
||||||
default:
|
default:
|
||||||
n := Node{}
|
n := Node{}
|
||||||
err = d.DecodeElement(&n, &tt)
|
err = d.DecodeElement(&n, &tt)
|
||||||
c.CommandElement = &n
|
c.CommandElements = append(c.CommandElements, &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ type DiscoInfo struct {
|
||||||
Identity []Identity `xml:"identity"`
|
Identity []Identity `xml:"identity"`
|
||||||
Features []Feature `xml:"feature"`
|
Features []Feature `xml:"feature"`
|
||||||
ResultSet *ResultSet `xml:"set,omitempty"`
|
ResultSet *ResultSet `xml:"set,omitempty"`
|
||||||
|
Form *Form `xml:"x,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace lets DiscoInfo implement the IQPayload interface
|
// Namespace lets DiscoInfo implement the IQPayload interface
|
||||||
|
|
|
@ -16,6 +16,7 @@ func TestDiscoInfo_Builder(t *testing.T) {
|
||||||
disco := iq.DiscoInfo()
|
disco := iq.DiscoInfo()
|
||||||
disco.AddIdentity("Test Component", "gateway", "service")
|
disco.AddIdentity("Test Component", "gateway", "service")
|
||||||
disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1")
|
disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1")
|
||||||
|
disco.Form = stanza.NewForm([]*stanza.Field{}, "result")
|
||||||
|
|
||||||
parsedIQ, err := checkMarshalling(t, iq)
|
parsedIQ, err := checkMarshalling(t, iq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -48,6 +49,15 @@ func TestDiscoInfo_Builder(t *testing.T) {
|
||||||
t.Errorf("Incorrect identity name: %#v", pp.Identity[0].Name)
|
t.Errorf("Incorrect identity name: %#v", pp.Identity[0].Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check form
|
||||||
|
if pp.Form == nil {
|
||||||
|
t.Errorf("Form is nil")
|
||||||
|
} else {
|
||||||
|
if len(pp.Form.Fields) != 0 {
|
||||||
|
t.Errorf("Form fields length mismatch: %#v", pp.Form.Fields)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements XEP-0030 example 17
|
// Implements XEP-0030 example 17
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (j *Jid) Full() string {
|
||||||
if j.Resource == "" {
|
if j.Resource == "" {
|
||||||
return j.Bare()
|
return j.Bare()
|
||||||
} else if j.Node == "" {
|
} else if j.Node == "" {
|
||||||
return j.Node + "/" + j.Resource
|
return j.Domain + "/" + j.Resource
|
||||||
} else {
|
} else {
|
||||||
return j.Node + "@" + j.Domain + "/" + j.Resource
|
return j.Node + "@" + j.Domain + "/" + j.Resource
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ func TestIncorrectJids(t *testing.T) {
|
||||||
func TestFull(t *testing.T) {
|
func TestFull(t *testing.T) {
|
||||||
fullJids := []string{
|
fullJids := []string{
|
||||||
"test@domain.com/my resource",
|
"test@domain.com/my resource",
|
||||||
|
"domain.com/my resource",
|
||||||
"test@domain.com",
|
"test@domain.com",
|
||||||
"domain.com",
|
"domain.com",
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,10 +237,10 @@ func NewApprovePendingSubRequest(serviceId, sessionId, nodeId string) (*IQ, erro
|
||||||
}
|
}
|
||||||
iq.Payload = &Command{
|
iq.Payload = &Command{
|
||||||
// the command name ('node' attribute of the command element) MUST have a value of "http://jabber.org/protocol/pubsub#get-pending"
|
// 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",
|
Node: "http://jabber.org/protocol/pubsub#get-pending",
|
||||||
Action: CommandActionExecute,
|
Action: CommandActionExecute,
|
||||||
SessionId: sessionId,
|
SessionId: sessionId,
|
||||||
CommandElement: &n,
|
CommandElements: []CommandElement{&n},
|
||||||
}
|
}
|
||||||
return iq, nil
|
return iq, nil
|
||||||
}
|
}
|
||||||
|
@ -353,11 +353,18 @@ func (iq *IQ) GetFormFields() (map[string]*Field, error) {
|
||||||
|
|
||||||
case *Command:
|
case *Command:
|
||||||
fieldMap := make(map[string]*Field)
|
fieldMap := make(map[string]*Field)
|
||||||
co, ok := payload.CommandElement.(*Form)
|
var form *Form
|
||||||
if !ok {
|
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")
|
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
|
fieldMap[elt.Var] = elt
|
||||||
}
|
}
|
||||||
return fieldMap, nil
|
return fieldMap, nil
|
||||||
|
|
Loading…
Reference in a new issue