Pass the TLS config as a parameter to the Client constructor. Updated the example program.
authorChris Jones <christian.jones@sri.com>
Sat, 07 Sep 2013 14:43:54 -0700
changeset 130 da6f37ae3ffe
parent 129 cccf2b2fe34d
child 131 f9ccfaf672ed
Pass the TLS config as a parameter to the Client constructor. Updated the example program.
example/interact.go
xmpp/stream.go
xmpp/xmpp.go
--- a/example/interact.go	Sat Sep 07 11:46:42 2013 -0700
+++ b/example/interact.go	Sat Sep 07 14:43:54 2013 -0700
@@ -5,7 +5,7 @@
 package main
 
 import (
-	xmpp ".."
+	"../xmpp"
 	"crypto/tls"
 	"encoding/xml"
 	"flag"
@@ -31,8 +31,6 @@
 	// 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
@@ -47,11 +45,12 @@
 		os.Exit(2)
 	}
 
-	c, err := xmpp.NewClient(&jid, *pw, nil)
+	tlsConf := tls.Config{InsecureSkipVerify: true}
+	c, err := xmpp.NewClient(&jid, *pw, tlsConf, nil)
 	if err != nil {
 		log.Fatalf("NewClient(%v): %v", jid, err)
 	}
-	defer close(c.Out)
+	defer close(c.Send)
 
 	err = c.StartSession(&xmpp.Presence{})
 	if err != nil {
@@ -69,7 +68,7 @@
 			fmt.Printf("s: %v\n", obj)
 		}
 		fmt.Println("done reading")
-	}(c.In)
+	}(c.Recv)
 
 	p := make([]byte, 1024)
 	for {
@@ -104,7 +103,7 @@
 		}
 		err = dec.Decode(stan)
 		if err == nil {
-			c.Out <- stan
+			c.Send <- stan
 		} else {
 			fmt.Printf("Parse error: %v\n", err)
 			break
--- a/xmpp/stream.go	Sat Sep 07 11:46:42 2013 -0700
+++ b/xmpp/stream.go	Sat Sep 07 14:43:54 2013 -0700
@@ -341,7 +341,7 @@
 	cl.socketSync.Wait()
 
 	// Negotiate TLS with the server.
-	tls := tls.Client(tcp, &cl.TlsConfig)
+	tls := tls.Client(tcp, &cl.tlsConfig)
 
 	// Make the TLS connection available to the reader, and wait
 	// for it to signal that it's working again.
--- a/xmpp/xmpp.go	Sat Sep 07 11:46:42 2013 -0700
+++ b/xmpp/xmpp.go	Sat Sep 07 14:43:54 2013 -0700
@@ -92,7 +92,7 @@
 	Features                     *Features
 	sendFilterAdd, recvFilterAdd chan Filter
 	// Allows the user to override the TLS configuration.
-	TlsConfig tls.Config
+	tlsConfig tls.Config
 }
 
 // Connect to the appropriate server and authenticate as the given JID
@@ -101,7 +101,7 @@
 // has completed. The negotiation will occur asynchronously, and any
 // send operation to Client.Out will block until negotiation (resource
 // binding) is complete.
-func NewClient(jid *JID, password string, exts []Extension) (*Client, error) {
+func NewClient(jid *JID, password string, tlsconf tls.Config, exts []Extension) (*Client, error) {
 	// Include the mandatory extensions.
 	roster := newRosterExt()
 	exts = append(exts, roster.Extension)
@@ -140,6 +140,7 @@
 	cl.socket = tcp
 	cl.handlers = make(chan *stanzaHandler, 100)
 	cl.inputControl = make(chan int)
+	cl.tlsConfig = tlsconf
 
 	extStanza := make(map[xml.Name]reflect.Type)
 	for _, ext := range exts {