# HG changeset patch # User Chris Jones # Date 1378590234 25200 # Node ID da6f37ae3ffe018738003a0e739830b408027700 # Parent cccf2b2fe34d36ed601df2f0e2f660ecd8c5236a Pass the TLS config as a parameter to the Client constructor. Updated the example program. diff -r cccf2b2fe34d -r da6f37ae3ffe example/interact.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 diff -r cccf2b2fe34d -r da6f37ae3ffe xmpp/stream.go --- 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. diff -r cccf2b2fe34d -r da6f37ae3ffe xmpp/xmpp.go --- 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 {