Make the server's advertised features available to the app.
authorChris Jones <chris@cjones.org>
Thu, 29 Dec 2011 11:25:26 -0700
changeset 32 4e68d8f89dc3
parent 31 1dc47df5c99f
child 33 571713f49494
Make the server's advertised features available to the app.
stream.go
structs.go
xmpp.go
--- a/stream.go	Thu Dec 29 11:17:52 2011 -0700
+++ b/stream.go	Thu Dec 29 11:25:26 2011 -0700
@@ -253,6 +253,7 @@
 }
 
 func (cl *Client) handleFeatures(fe *Features) {
+	cl.Features = fe
 	if fe.Starttls != nil {
 		start := &starttls{XMLName: xml.Name{Space: nsTLS,
 			Local: "starttls"}}
@@ -297,6 +298,7 @@
 	tcp.SetReadTimeout(0)
 
 	log.Println("TLS negotiation succeeded.")
+	cl.Features = nil
 
 	// Now re-send the initial handshake message to start the new
 	// session.
@@ -357,6 +359,7 @@
 		log.Println("SASL authentication failed")
 	case "success":
 		log.Println("SASL authentication succeeded")
+		cl.Features = nil
 		ss := &stream{To: cl.Jid.Domain, Version: Version}
 		cl.xmlOut <- ss
 	}
--- a/structs.go	Thu Dec 29 11:17:52 2011 -0700
+++ b/structs.go	Thu Dec 29 11:25:26 2011 -0700
@@ -52,11 +52,12 @@
 }
 var _ xml.Marshaler = &errText{}
 
-// BUG(cjyar) Store this in Client and make it available to the app.
 type Features struct {
 	Starttls *starttls
 	Mechanisms mechs
 	Bind *Generic
+	Session *Generic
+	Any *Generic
 }
 
 type starttls struct {
--- a/xmpp.go	Thu Dec 29 11:17:52 2011 -0700
+++ b/xmpp.go	Thu Dec 29 11:25:26 2011 -0700
@@ -68,6 +68,11 @@
 	// channel.
 	Out chan<- Stanza
 	xmlOut chan<- interface{}
+	// Features advertised by the remote. This will be updated
+	// asynchronously as new features are received throughout the
+	// connection process. It should not be updated once
+	// StartSession() returns.
+	Features *Features
 }
 var _ io.Closer = &Client{}