~samwhited/xmpp

ref: 81044e37710b73ce452f6b8527512dfb0eced8d8 xmpp/config.go -rw-r--r-- 1.5 KiB
81044e37Sam Whited Clean up long doc comment that was no longer valid 5 years 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2016 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

package xmpp

import (
	"crypto/tls"

	"golang.org/x/text/language"
	"mellium.im/xmpp/internal"
	"mellium.im/xmpp/jid"
)

// Config represents the configuration of an XMPP session.
type Config struct {
	// An XMPP server address.
	Location *jid.JID

	// An XMPP connection origin (local address).
	Origin *jid.JID

	// The supported stream features.
	Features []StreamFeature

	// The default language for any streams constructed using this config.
	Lang language.Tag

	// True if this is a server-to-server session.
	S2S bool

	// TLS config for STARTTLS.
	TLSConfig *tls.Config

	// XMPP protocol version
	Version internal.Version
}

// NewClientConfig constructs a new client-to-server session configuration with
// sane defaults.
func NewClientConfig(origin *jid.JID, features ...StreamFeature) *Config {
	return &Config{
		Features: features,
		Location: origin.Domain(),
		Origin:   origin,
		Version:  internal.DefaultVersion,
	}
}

// NewServerConfig constructs a new server-to-server session configuration with
// sane defaults.
func NewServerConfig(location, origin *jid.JID, features ...StreamFeature) *Config {
	return &Config{
		Features: features,
		Location: location,
		Origin:   origin,
		S2S:      true,
		Version:  internal.DefaultVersion,
	}
}

func (config *Config) connType() string {
	if config.S2S {
		return "xmpp-server"
	}
	return "xmpp-client"
}