summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/matterbridge
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-12-12 14:11:11 +0100
committerGitHub <noreply@github.com>2021-12-12 14:11:11 +0100
commit6cb359cb808e2353db2675b58da95ac0349689fe (patch)
tree80c94d34fe3d6c1c0a53a39e689ead1da77a5bc4 /vendor/github.com/matterbridge
parentae2ad824a91456041c4fba04b926b4778153d997 (diff)
downloadmatterbridge-msglm-6cb359cb808e2353db2675b58da95ac0349689fe.tar.gz
matterbridge-msglm-6cb359cb808e2353db2675b58da95ac0349689fe.tar.bz2
matterbridge-msglm-6cb359cb808e2353db2675b58da95ac0349689fe.zip
Fix vendored xmpp (#1661)
Diffstat (limited to 'vendor/github.com/matterbridge')
-rw-r--r--vendor/github.com/matterbridge/go-xmpp/xmpp.go44
-rw-r--r--vendor/github.com/matterbridge/go-xmpp/xmpp_information_query.go2
2 files changed, 31 insertions, 15 deletions
diff --git a/vendor/github.com/matterbridge/go-xmpp/xmpp.go b/vendor/github.com/matterbridge/go-xmpp/xmpp.go
index 5b8cdcf7..30a7ff74 100644
--- a/vendor/github.com/matterbridge/go-xmpp/xmpp.go
+++ b/vendor/github.com/matterbridge/go-xmpp/xmpp.go
@@ -43,7 +43,7 @@ const (
)
// Default TLS configuration options
-var DefaultConfig tls.Config
+var DefaultConfig = &tls.Config{}
// DebugWriter is the writer used to write debugging output to.
var DebugWriter io.Writer = os.Stderr
@@ -76,7 +76,7 @@ func containsIgnoreCase(s, substr string) bool {
return strings.Contains(s, substr)
}
-func connect(host, user, passwd string) (net.Conn, error) {
+func connect(host, user, passwd string, timeout time.Duration) (net.Conn, error) {
addr := host
if strings.TrimSpace(host) == "" {
@@ -117,7 +117,7 @@ func connect(host, user, passwd string) (net.Conn, error) {
}
}
- c, err := net.Dial("tcp", addr)
+ c, err := net.DialTimeout("tcp", addr, timeout)
if err != nil {
return nil, err
}
@@ -153,6 +153,10 @@ type Options struct {
// Password supplies the password to use for authentication with the remote server.
Password string
+ // DialTimeout is the time limit for establishing a connection. A
+ // DialTimeout of zero means no timeout.
+ DialTimeout time.Duration
+
// Resource specifies an XMPP client resource, like "bot", instead of accepting one
// from the server. Use "" to let the server generate one for your client.
Resource string
@@ -221,7 +225,7 @@ func (o Options) NewClient() (*Client, error) {
}
}
}
- c, err := connect(host, o.User, o.Password)
+ c, err := connect(host, o.User, o.Password, o.DialTimeout)
if err != nil {
return nil, err
}
@@ -237,11 +241,11 @@ func (o Options) NewClient() (*Client, error) {
var tlsconn *tls.Conn
if o.TLSConfig != nil {
tlsconn = tls.Client(c, o.TLSConfig)
+ host = o.TLSConfig.ServerName
} else {
- DefaultConfig.ServerName = host
- newconfig := DefaultConfig
+ newconfig := DefaultConfig.Clone()
newconfig.ServerName = host
- tlsconn = tls.Client(c, &newconfig)
+ tlsconn = tls.Client(c, newconfig)
}
if err = tlsconn.Handshake(); err != nil {
return nil, err
@@ -331,7 +335,6 @@ func cnonce() string {
}
func (c *Client) init(o *Options) error {
-
var domain string
var user string
a := strings.SplitN(o.User, "@", 2)
@@ -497,7 +500,7 @@ func (c *Client) init(o *Options) error {
c.domain = domain
if o.Session {
- //if server support session, open it
+ // if server support session, open it
fmt.Fprintf(c.conn, "<iq to='%s' type='set' id='%x'><session xmlns='%s'/></iq>", xmlEscape(domain), cookie, nsSession)
}
@@ -532,9 +535,8 @@ func (c *Client) startTLSIfRequired(f *streamFeatures, o *Options, domain string
tc := o.TLSConfig
if tc == nil {
- tc = new(tls.Config)
- *tc = DefaultConfig
- //TODO(scott): we should consider using the server's address or reverse lookup
+ tc = DefaultConfig.Clone()
+ // TODO(scott): we should consider using the server's address or reverse lookup
tc.ServerName = domain
}
t := tls.Client(c.conn, tc)
@@ -652,6 +654,10 @@ func (c *Client) Recv() (stanza interface{}, err error) {
// Handle Pubsub notifications
switch v.Event.Items.Node {
case XMPPNS_AVATAR_PEP_METADATA:
+ if len(v.Event.Items.Items) == 0 {
+ return AvatarMetadata{}, errors.New("No avatar metadata items available")
+ }
+
return handleAvatarMetadata(v.Event.Items.Items[0].Body,
v.From)
// I am not sure whether this can even happen.
@@ -797,10 +803,18 @@ func (c *Client) Recv() (stanza interface{}, err error) {
switch p.Node {
case XMPPNS_AVATAR_PEP_DATA:
+ if len(p.Items) == 0 {
+ return AvatarData{}, errors.New("No avatar data items available")
+ }
+
return handleAvatarData(p.Items[0].Body,
v.From,
p.Items[0].ID)
case XMPPNS_AVATAR_PEP_METADATA:
+ if len(p.Items) == 0 {
+ return AvatarMetadata{}, errors.New("No avatar metadata items available")
+ }
+
return handleAvatarMetadata(p.Items[0].Body,
v.From)
default:
@@ -842,8 +856,10 @@ func (c *Client) Recv() (stanza interface{}, err error) {
return Chat{}, err
}
- return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type,
- Query: res}, nil
+ return IQ{
+ ID: v.ID, From: v.From, To: v.To, Type: v.Type,
+ Query: res,
+ }, nil
}
}
}
diff --git a/vendor/github.com/matterbridge/go-xmpp/xmpp_information_query.go b/vendor/github.com/matterbridge/go-xmpp/xmpp_information_query.go
index 15114c9f..90dee955 100644
--- a/vendor/github.com/matterbridge/go-xmpp/xmpp_information_query.go
+++ b/vendor/github.com/matterbridge/go-xmpp/xmpp_information_query.go
@@ -39,7 +39,7 @@ func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, bod
return id, err
}
-// rawInformation send a IQ request with the the payload body to the server
+// rawInformation send a IQ request with the payload body to the server
func (c *Client) RawInformation(from, to, id, iqType, body string) (string, error) {
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>"
_, err := fmt.Fprintf(c.conn, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)