Add support for detecting Stream Management

This commit is contained in:
Mickael Remond 2019-06-10 16:36:47 +02:00
parent 709a95129e
commit 30e6adc073
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3
2 changed files with 36 additions and 5 deletions

View File

@ -13,11 +13,12 @@ type StreamFeatures struct {
// Server capabilities hash // Server capabilities hash
Caps Caps Caps Caps
// Stream features // Stream features
StartTLS tlsStartTLS StartTLS tlsStartTLS
Mechanisms saslMechanisms Mechanisms saslMechanisms
Bind BindBind Bind BindBind
Session sessionSession Session sessionSession
Any []xml.Name `xml:",any"` StreamManagement streamManagement
Any []xml.Name `xml:",any"`
} }
func (StreamFeatures) Name() string { func (StreamFeatures) Name() string {
@ -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

View File

@ -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")
}
}