Allow the user to override the TLS config. Also fixed up some log statements.
authorChris Jones <christian.jones@sri.com>
Sun, 16 Dec 2012 15:54:39 -0700
changeset 105 aa895dfae3f6
parent 104 99e03b33b20d
child 106 ffb9d27fea79
Allow the user to override the TLS config. Also fixed up some log statements.
examples/interact.go
stream.go
structs.go
xmpp.go
--- a/examples/interact.go	Sun Dec 16 15:24:55 2012 -0700
+++ b/examples/interact.go	Sun Dec 16 15:54:39 2012 -0700
@@ -6,6 +6,7 @@
 
 import (
 	xmpp ".."
+	"crypto/tls"
 	"flag"
 	"fmt"
 	"log"
@@ -28,6 +29,8 @@
 	xmpp.Debug = logger
 	xmpp.Info = logger
 	xmpp.Warn = logger
+
+	xmpp.TlsConfig = tls.Config{InsecureSkipVerify: true}
 }
 
 // Demonstrate the API, and allow the user to interact with an XMPP
--- a/stream.go	Sun Dec 16 15:24:55 2012 -0700
+++ b/stream.go	Sun Dec 16 15:54:39 2012 -0700
@@ -299,7 +299,7 @@
 				break Loop
 			}
 			if x == nil {
-				Info.Logf("Refusing to send nil stanza")
+				Info.Log("Refusing to send nil stanza")
 				continue
 			}
 			srvOut <- x
@@ -317,7 +317,7 @@
 		select {
 		case newFilterOut := <-filterOut:
 			if newFilterOut == nil {
-				Warn.Logf("Received nil filter")
+				Warn.Log("Received nil filter")
 				filterIn <- nil
 				continue
 			}
@@ -381,7 +381,7 @@
 	cl.socketSync.Wait()
 
 	// Negotiate TLS with the server.
-	tls := tls.Client(tcp, nil)
+	tls := tls.Client(tcp, &TlsConfig)
 
 	// Make the TLS connection available to the reader, and wait
 	// for it to signal that it's working again.
@@ -389,7 +389,7 @@
 	cl.socket = tls
 	cl.socketSync.Wait()
 
-	Info.Logf("TLS negotiation succeeded.")
+	Info.Log("TLS negotiation succeeded.")
 	cl.Features = nil
 
 	// Now re-send the initial handshake message to start the new
@@ -446,9 +446,9 @@
 			cl.saslDigest2(srvMap)
 		}
 	case "failure":
-		Info.Logf("SASL authentication failed")
+		Info.Log("SASL authentication failed")
 	case "success":
-		Info.Logf("Sasl authentication succeeded")
+		Info.Log("Sasl authentication succeeded")
 		cl.Features = nil
 		ss := &stream{To: cl.Jid.Domain, Version: Version}
 		cl.xmlOut <- ss
@@ -464,7 +464,7 @@
 		}
 	}
 	if !hasAuth {
-		Warn.Logf("Server doesn't support SASL auth")
+		Warn.Log("Server doesn't support SASL auth")
 		return
 	}
 
@@ -600,10 +600,10 @@
 	f := func(st Stanza) bool {
 		iq, ok := st.(*Iq)
 		if !ok {
-			Warn.Logf("non-iq response")
+			Warn.Log("non-iq response")
 		}
 		if iq.Type == "error" {
-			Warn.Logf("Resource binding failed")
+			Warn.Log("Resource binding failed")
 			return false
 		}
 		var bindRepl *bindIq
@@ -619,7 +619,7 @@
 		}
 		jidStr := bindRepl.Jid
 		if jidStr == nil || *jidStr == "" {
-			Warn.Logf("Can't bind empty resource")
+			Warn.Log("Can't bind empty resource")
 			return false
 		}
 		jid := new(JID)
--- a/structs.go	Sun Dec 16 15:24:55 2012 -0700
+++ b/structs.go	Sun Dec 16 15:54:39 2012 -0700
@@ -274,7 +274,7 @@
 func (er *Error) Error() string {
 	buf, err := xml.Marshal(er)
 	if err != nil {
-		Warn.Logf("double bad error: couldn't marshal error")
+		Warn.Log("double bad error: couldn't marshal error")
 		return "unreadable error"
 	}
 	return string(buf)
--- a/xmpp.go	Sun Dec 16 15:24:55 2012 -0700
+++ b/xmpp.go	Sun Dec 16 15:54:39 2012 -0700
@@ -8,6 +8,7 @@
 
 import (
 	"bytes"
+	"crypto/tls"
 	"encoding/xml"
 	"errors"
 	"fmt"
@@ -59,6 +60,9 @@
 	Start          func(*Client)
 }
 
+// Allows the user to override the TLS configuration.
+var TlsConfig tls.Config
+
 // The client in a client-server XMPP connection.
 type Client struct {
 	// This client's unique ID. It's unique within the context of
@@ -269,7 +273,7 @@
 	f := func(st Stanza) bool {
 		iq, ok := st.(*Iq)
 		if !ok {
-			Warn.Logf("iq reply not iq; can't start session")
+			Warn.Log("iq reply not iq; can't start session")
 			ch <- errors.New("bad session start reply")
 			return false
 		}