Consolidate how we generate the "open stream" XML.
authorChris Jones <christian.jones@sri.com>
Thu, 19 Jan 2012 22:32:26 -0600
changeset 81 a74e7fc4ecee
parent 80 b0aa1bf902ee
child 82 7ce2432dd66a
Consolidate how we generate the "open stream" XML.
stream.go
xmpp.go
--- a/stream.go	Thu Jan 19 22:31:56 2012 -0600
+++ b/stream.go	Thu Jan 19 22:32:26 2012 -0600
@@ -33,6 +33,16 @@
 	f func(Stanza) bool
 }
 
+// BUG(cjyar): There's no way to specify xml:lang for the top-level
+// <stream:stream> element as the default language for this client.
+
+// Generate the "open stream" element which tells the remote we want
+// to speak XMPP. This is actually done 3 times, since we renegotiate
+// our transport layer with TLS and then with SASL.
+func openStream(jid *JID) *stream {
+	return &stream{To: jid.Domain, Version: Version}
+}
+
 // BUG(cjyar) Review all these *Client receiver methods. They should
 // probably either all be receivers, or none.
 
@@ -420,7 +430,7 @@
 
 	// Now re-send the initial handshake message to start the new
 	// session.
-	hsOut := &stream{To: cl.Jid.Domain, Version: Version}
+		hsOut := openStream()
 	cl.xmlOut <- hsOut
 }
 
@@ -483,8 +493,7 @@
 			Log.Println("Sasl authentication succeeded")
 		}
 		cl.Features = nil
-		ss := &stream{To: cl.Jid.Domain, Version: Version}
-		cl.xmlOut <- ss
+		cl.xmlOut <- openStream(cl.Jid)
 	}
 }
 
--- a/xmpp.go	Thu Jan 19 22:31:56 2012 -0600
+++ b/xmpp.go	Thu Jan 19 22:32:26 2012 -0600
@@ -182,8 +182,7 @@
 	}
 
 	// Initial handshake.
-	hsOut := &stream{To: jid.Domain, Version: Version}
-	cl.xmlOut <- hsOut
+	cl.xmlOut <- openStream(jid)
 
 	return cl, nil
 }