~samwhited/xmpp

xmpp/roster/ver.go -rw-r--r-- 1.1 KiB
92036897Sam Whited pubsub: allow creating and configuring nodes 9 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2021 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

package roster

import (
	"context"
	"encoding/xml"
	"io"

	"mellium.im/xmlstream"
	"mellium.im/xmpp"
)

// Versioning returns a stream feature that advertises roster versioning
// support.
//
// Actually attempting to negotiate the feature does nothing as it is meant to
// be informational only.
func Versioning() xmpp.StreamFeature {
	return xmpp.StreamFeature{
		Name:      xml.Name{Space: NSFeatures, Local: "ver"},
		Necessary: xmpp.Secure,
		List: func(_ context.Context, e xmlstream.TokenWriter, start xml.StartElement) (bool, error) {
			err := e.EncodeToken(start)
			if err != nil {
				return true, err
			}
			return true, e.EncodeToken(start.End())
		},
		Parse: func(_ context.Context, d *xml.Decoder, _ *xml.StartElement) (bool, interface{}, error) {
			return false, nil, d.Skip()
		},
		Negotiate: func(context.Context, *xmpp.Session, interface{}) (xmpp.SessionState, io.ReadWriter, error) {
			return 0, nil, nil
		},
	}
}