~samwhited/xmpp

a4a9e7896bfa86f4386340123d2ea9cd2412aa61 — Sam Whited 2 years ago 092e5a5 v0.6.0
xmpp: remove lang from session creation functions

Since the lang is rarely actually used and we have an advanced
configuration now (by manually creating the Negotiator with
NewNegotiator) there's not much point to having it on the simpler
dialer/session negotiation functions. This is a breaking change.
3 files changed, 16 insertions(+), 13 deletions(-)

M doc.go
M echobot_example_test.go
M session.go
M doc.go => doc.go +7 -4
@@ 22,7 22,7 @@
//
//
//     session, err := xmpp.DialClientSession(
//         context.TODO(), addr, "en",
//         context.TODO(), addr,
//         xmpp.BindResource(),
//         xmpp.StartTLS(true, nil),
//         xmpp.SASL("", pass, sasl.ScramSha1Plus, sasl.ScramSha1, sasl.Plain),


@@ 37,7 37,7 @@
//     conn, err := xmpp.DialClient(context.TODO(), "tcp", addr)
//     …
//     session, err := xmpp.NewClientSession(
//         context.TODO(), addr, "en", conn,
//         context.TODO(), addr, conn,
//         xmpp.BindResource(),
//         xmpp.StartTLS(true, nil),
//         xmpp.SASL("", pass, sasl.ScramSha1Plus, sasl.ScramSha1, sasl.Plain),


@@ 47,11 47,14 @@
// If complete control over the session establishment process is needed the
// NegotiateSession function can be used to support custom session negotiation
// protocols or to customize options around the default negotiator by using the
// NewClientNegotiator and NewServerNegotiator functions.
// NewNegotiator function.
//
//     session, err := xmpp.NegotiateSession(
//         context.TODO(), addr.Domain(), addr, conn,
//         component.Negotiator(addr, secret, false),
//         xmpp.NewNegotiator(xmpp.StreamConfig{
//             Lang: "en",
//             …
//         }),
//     )
//
// The default Negotiator and related functions use a list of StreamFeature's to

M echobot_example_test.go => echobot_example_test.go +1 -1
@@ 26,7 26,7 @@ const (
func Example_echobot() {
	j := jid.MustParse(login)
	s, err := xmpp.DialClientSession(
		context.TODO(), j, "en",
		context.TODO(), j,
		xmpp.BindResource(),
		xmpp.StartTLS(true, &tls.Config{
			ServerName: j.Domain().String(),

M session.go => session.go +8 -8
@@ 194,12 194,12 @@ func stanzaAddID(w xmlstream.TokenWriter) xmlstream.TokenWriter {
//
// If the provided context is canceled after stream negotiation is complete it
// has no effect on the session.
func DialClientSession(ctx context.Context, origin jid.JID, lang string, features ...StreamFeature) (*Session, error) {
func DialClientSession(ctx context.Context, origin jid.JID, features ...StreamFeature) (*Session, error) {
	conn, err := DialClient(ctx, "tcp", origin)
	if err != nil {
		return nil, err
	}
	return NegotiateSession(ctx, origin.Domain(), origin, conn, NewNegotiator(StreamConfig{Lang: lang, Features: features}))
	return NegotiateSession(ctx, origin.Domain(), origin, conn, NewNegotiator(StreamConfig{Features: features}))
}

// DialServerSession uses a default dialer to create a TCP connection and


@@ 207,12 207,12 @@ func DialClientSession(ctx context.Context, origin jid.JID, lang string, feature
//
// If the provided context is canceled after stream negotiation is complete it
// has no effect on the session.
func DialServerSession(ctx context.Context, location, origin jid.JID, lang string, features ...StreamFeature) (*Session, error) {
func DialServerSession(ctx context.Context, location, origin jid.JID, features ...StreamFeature) (*Session, error) {
	conn, err := DialServer(ctx, "tcp", location)
	if err != nil {
		return nil, err
	}
	return NegotiateSession(ctx, location, origin, conn, NewNegotiator(StreamConfig{Lang: lang, S2S: true, Features: features}))
	return NegotiateSession(ctx, location, origin, conn, NewNegotiator(StreamConfig{S2S: true, Features: features}))
}

// NewClientSession attempts to use an existing connection (or any


@@ 220,8 220,8 @@ func DialServerSession(ctx context.Context, location, origin jid.JID, lang strin
// If the provided context is canceled before stream negotiation is complete an
// error is returned.
// After stream negotiation if the context is canceled it has no effect.
func NewClientSession(ctx context.Context, origin jid.JID, lang string, rw io.ReadWriter, features ...StreamFeature) (*Session, error) {
	return NegotiateSession(ctx, origin.Domain(), origin, rw, NewNegotiator(StreamConfig{Lang: lang, Features: features}))
func NewClientSession(ctx context.Context, origin jid.JID, rw io.ReadWriter, features ...StreamFeature) (*Session, error) {
	return NegotiateSession(ctx, origin.Domain(), origin, rw, NewNegotiator(StreamConfig{Features: features}))
}

// NewServerSession attempts to use an existing connection (or any


@@ 229,8 229,8 @@ func NewClientSession(ctx context.Context, origin jid.JID, lang string, rw io.Re
// If the provided context is canceled before stream negotiation is complete an
// error is returned.
// After stream negotiation if the context is canceled it has no effect.
func NewServerSession(ctx context.Context, location, origin jid.JID, lang string, rw io.ReadWriter, features ...StreamFeature) (*Session, error) {
	return NegotiateSession(ctx, location, origin, rw, NewNegotiator(StreamConfig{Lang: lang, S2S: true, Features: features}))
func NewServerSession(ctx context.Context, location, origin jid.JID, rw io.ReadWriter, features ...StreamFeature) (*Session, error) {
	return NegotiateSession(ctx, location, origin, rw, NewNegotiator(StreamConfig{S2S: true, Features: features}))
}

// Serve decodes incoming XML tokens from the connection and delegates handling