~samwhited/xmpp

cd21cc574895fc380c4323fc1e44b98e6c89405d — Sam Whited 4 years ago 30563f9
Add API to get the most recent stream features
2 files changed, 15 insertions(+), 0 deletions(-)

M conn.go
M features.go
M conn.go => conn.go +11 -0
@@ 10,6 10,7 @@ import (
	"errors"
	"io"
	"net"
	"sync"
	"time"

	"mellium.im/xmpp/jid"


@@ 29,6 30,7 @@ type Conn struct {

	// The stream features advertised for the current streams.
	features map[xml.Name]struct{}
	flock    sync.Mutex

	in struct {
		stream


@@ 40,6 42,15 @@ type Conn struct {
	}
}

// Features returns a set of the currently available stream features (including
// those that have already been negotiated).
func (c *Conn) Features() map[xml.Name]struct{} {
	c.flock.Lock()
	defer c.flock.Unlock()

	return c.features
}

// NewConn attempts to use an existing connection (or any io.ReadWriteCloser) to
// negotiate an XMPP session based on the given config. If the provided context
// is canceled before stream negotiation is complete an error is returned. After

M features.go => features.go +4 -0
@@ 152,6 152,10 @@ func readStreamFeatures(ctx context.Context, conn *Conn, start xml.StartElement)
		return nil, streamerror.BadNamespacePrefix
	}

	// Lock the connection features list.
	conn.flock.Lock()
	defer conn.flock.Unlock()

	sf := &streamFeaturesList{
		cache: make(map[xml.Name]sfData),
	}