Compare commits

..

2 commits

Author SHA1 Message Date
Bohdan Horbeshko e55463fc98 Fix passing Component to StreamManager
0a4acd12c3, which fixes #160, introduced
a regression as it assumed only Client may implement StreamClient, and
passing a component triggers an unconditional "client is not
disconnected" error.
2021-12-18 10:55:35 -05:00
bodqhrohro 5f99e1cd06 Support partial JIDs in Bare/Full methods 2021-12-14 12:01:36 +01:00
3 changed files with 16 additions and 22 deletions

View file

@ -21,7 +21,6 @@ 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

View file

@ -16,7 +16,6 @@ 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 {
@ -49,15 +48,6 @@ 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

View file

@ -114,10 +114,16 @@ 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 {
scs = &client.CurrentState
}
if component, ok := sm.client.(*Component); ok {
scs = &component.CurrentState
}
if scs != nil && scs.getState() == StateDisconnected {
sm.Metrics = initMetrics() sm.Metrics = initMetrics()
err := c.Connect() err := sm.client.Connect()
if err != nil { if err != nil {
return err return err
} }
@ -127,7 +133,6 @@ func (sm *StreamManager) connect() error {
return nil return nil
} }
} }
}
return errors.New("client is not disconnected") return errors.New("client is not disconnected")
} }