mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-23 11:02:00 -08:00
Add support for detecting Stream Management
This commit is contained in:
parent
709a95129e
commit
30e6adc073
14
stream.go
14
stream.go
@ -17,6 +17,7 @@ type StreamFeatures struct {
|
|||||||
Mechanisms saslMechanisms
|
Mechanisms saslMechanisms
|
||||||
Bind BindBind
|
Bind BindBind
|
||||||
Session sessionSession
|
Session sessionSession
|
||||||
|
StreamManagement streamManagement
|
||||||
Any []xml.Name `xml:",any"`
|
Any []xml.Name `xml:",any"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +105,19 @@ type saslMechanisms struct {
|
|||||||
Mechanism []string `xml:"mechanism"`
|
Mechanism []string `xml:"mechanism"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StreamManagement
|
||||||
|
// Reference: XEP-0198 - https://xmpp.org/extensions/xep-0198.html#feature
|
||||||
|
type streamManagement struct {
|
||||||
|
XMLName xml.Name `xml:"urn:xmpp:sm:3 sm"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sf *StreamFeatures) DoesStreamManagement() (isSupported bool) {
|
||||||
|
if sf.StreamManagement.XMLName.Space+" "+sf.StreamManagement.XMLName.Local == "urn:xmpp:sm:3 sm" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// StreamError Packet
|
// StreamError Packet
|
||||||
|
|
||||||
|
@ -45,3 +45,20 @@ func TestStartTLS(t *testing.T) {
|
|||||||
t.Error("StartTLS feature should be required")
|
t.Error("StartTLS feature should be required")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Ability to support / detect previous version of stream management feature
|
||||||
|
func TestStreamManagement(t *testing.T) {
|
||||||
|
streamFeatures := `<stream:features xmlns:stream='http://etherx.jabber.org/streams'>
|
||||||
|
<sm xmlns='urn:xmpp:sm:3'/>
|
||||||
|
</stream:features>`
|
||||||
|
|
||||||
|
var parsedSF xmpp.StreamFeatures
|
||||||
|
if err := xml.Unmarshal([]byte(streamFeatures), &parsedSF); err != nil {
|
||||||
|
t.Errorf("Unmarshal(%s) returned error: %v", streamFeatures, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ok := parsedSF.DoesStreamManagement()
|
||||||
|
if !ok {
|
||||||
|
t.Error("Stream Management feature should have been detected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user