Compare commits
1 commit
commands-f
...
160-regres
Author | SHA1 | Date | |
---|---|---|---|
Bohdan Horbeshko | e55463fc98 |
|
@ -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"`
|
||||||
|
|
||||||
CommandElements []CommandElement
|
CommandElement 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,8 +56,6 @@ 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"`
|
||||||
|
@ -70,8 +68,6 @@ 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"`
|
||||||
}
|
}
|
||||||
|
@ -121,22 +117,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 "actions":
|
case "affiliations":
|
||||||
a := Actions{}
|
a := Actions{}
|
||||||
err = d.DecodeElement(&a, &tt)
|
err = d.DecodeElement(&a, &tt)
|
||||||
c.CommandElements = append(c.CommandElements, &a)
|
c.CommandElement = &a
|
||||||
case "note":
|
case "configure":
|
||||||
nt := Note{}
|
nt := Note{}
|
||||||
err = d.DecodeElement(&nt, &tt)
|
err = d.DecodeElement(&nt, &tt)
|
||||||
c.CommandElements = append(c.CommandElements, &nt)
|
c.CommandElement = &nt
|
||||||
case "x":
|
case "x":
|
||||||
f := Form{}
|
f := Form{}
|
||||||
err = d.DecodeElement(&f, &tt)
|
err = d.DecodeElement(&f, &tt)
|
||||||
c.CommandElements = append(c.CommandElements, &f)
|
c.CommandElement = &f
|
||||||
default:
|
default:
|
||||||
n := Node{}
|
n := Node{}
|
||||||
err = d.DecodeElement(&n, &tt)
|
err = d.DecodeElement(&n, &tt)
|
||||||
c.CommandElements = append(c.CommandElements, &n)
|
c.CommandElement = &n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
CommandElements: []CommandElement{&n},
|
CommandElement: &n,
|
||||||
}
|
}
|
||||||
return iq, nil
|
return iq, nil
|
||||||
}
|
}
|
||||||
|
@ -353,18 +353,11 @@ func (iq *IQ) GetFormFields() (map[string]*Field, error) {
|
||||||
|
|
||||||
case *Command:
|
case *Command:
|
||||||
fieldMap := make(map[string]*Field)
|
fieldMap := make(map[string]*Field)
|
||||||
var form *Form
|
co, ok := payload.CommandElement.(*Form)
|
||||||
for _, ce := range payload.CommandElements {
|
if !ok {
|
||||||
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 form.Fields {
|
for _, elt := range co.Fields {
|
||||||
fieldMap[elt.Var] = elt
|
fieldMap[elt.Var] = elt
|
||||||
}
|
}
|
||||||
return fieldMap, nil
|
return fieldMap, nil
|
||||||
|
|
|
@ -114,18 +114,23 @@ func (sm *StreamManager) Stop() {
|
||||||
|
|
||||||
func (sm *StreamManager) connect() error {
|
func (sm *StreamManager) connect() error {
|
||||||
if sm.client != nil {
|
if sm.client != nil {
|
||||||
if c, ok := sm.client.(*Client); ok {
|
var scs *SyncConnState
|
||||||
if c.CurrentState.getState() == StateDisconnected {
|
if client, ok := sm.client.(*Client); ok {
|
||||||
sm.Metrics = initMetrics()
|
scs = &client.CurrentState
|
||||||
err := c.Connect()
|
}
|
||||||
if err != nil {
|
if component, ok := sm.client.(*Component); ok {
|
||||||
return err
|
scs = &component.CurrentState
|
||||||
}
|
}
|
||||||
if sm.PostConnect != nil {
|
if scs != nil && scs.getState() == StateDisconnected {
|
||||||
sm.PostConnect(sm.client)
|
sm.Metrics = initMetrics()
|
||||||
}
|
err := sm.client.Connect()
|
||||||
return nil
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
if sm.PostConnect != nil {
|
||||||
|
sm.PostConnect(sm.client)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.New("client is not disconnected")
|
return errors.New("client is not disconnected")
|
||||||
|
|
Loading…
Reference in a new issue