Code reorder and doc cleanup.
authorChris Jones <christian.jones@sri.com>
Sun, 15 Sep 2013 16:41:02 -0600
changeset 150 fa7f6ff10c67
parent 149 22c96a9ab289
child 151 352f76a05f78
Code reorder and doc cleanup.
TODO.txt
xmpp/layer3.go
xmpp/sasl.go
--- a/TODO.txt	Sun Sep 15 16:30:55 2013 -0600
+++ b/TODO.txt	Sun Sep 15 16:41:02 2013 -0600
@@ -1,5 +1,5 @@
-Review all these *Client receiver methods. They should probably either
-all be receivers, or none.
+Review all the *Client receiver methods in layer3.go. They should
+probably either all be receivers, or none.
 
 Maybe put auth-related stuff into its own structure inside Client,
 instead of at Client's top level.
--- a/xmpp/layer3.go	Sun Sep 15 16:30:55 2013 -0600
+++ b/xmpp/layer3.go	Sun Sep 15 16:41:02 2013 -0600
@@ -15,50 +15,6 @@
 	f func(Stanza) bool
 }
 
-// Receive XMLish structures, handle all the stream-related ones, and
-// send XMPP stanzas on to the client.
-func (cl *Client) recvStream(recvXml <-chan interface{}, sendXmpp chan<- Stanza) {
-	defer close(sendXmpp)
-
-	handlers := make(map[string]func(Stanza) bool)
-Loop:
-	for {
-		select {
-		case h := <-cl.handlers:
-			handlers[h.id] = h.f
-		case x, ok := <-recvXml:
-			if !ok {
-				break Loop
-			}
-			switch obj := x.(type) {
-			case *stream:
-				handleStream(obj)
-			case *streamError:
-				cl.handleStreamError(obj)
-			case *Features:
-				cl.handleFeatures(obj)
-			case *starttls:
-				cl.handleTls(obj)
-			case *auth:
-				cl.handleSasl(obj)
-			case Stanza:
-				send := true
-				id := obj.GetHeader().Id
-				if handlers[id] != nil {
-					f := handlers[id]
-					delete(handlers, id)
-					send = f(obj)
-				}
-				if send {
-					sendXmpp <- obj
-				}
-			default:
-				Warn.Logf("Unhandled non-stanza: %T %#v", x, x)
-			}
-		}
-	}
-}
-
 // Receive XMPP stanzas from the client and send them on to the
 // remote. Don't allow the client to send us any stanzas until
 // negotiation has completed.  This loop is paused until resource
@@ -96,7 +52,47 @@
 	}
 }
 
-func handleStream(ss *stream) {
+// Receive XMLish structures, handle all the stream-related ones, and
+// send XMPP stanzas on to the client.
+func (cl *Client) recvStream(recvXml <-chan interface{}, sendXmpp chan<- Stanza) {
+	defer close(sendXmpp)
+
+	handlers := make(map[string]func(Stanza) bool)
+	for {
+		select {
+		case h := <-cl.handlers:
+			handlers[h.id] = h.f
+		case x, ok := <-recvXml:
+			if !ok {
+				return
+			}
+			switch obj := x.(type) {
+			case *stream:
+				// Do nothing.
+			case *streamError:
+				cl.handleStreamError(obj)
+			case *Features:
+				cl.handleFeatures(obj)
+			case *starttls:
+				cl.handleTls(obj)
+			case *auth:
+				cl.handleSasl(obj)
+			case Stanza:
+				send := true
+				id := obj.GetHeader().Id
+				if handlers[id] != nil {
+					f := handlers[id]
+					delete(handlers, id)
+					send = f(obj)
+				}
+				if send {
+					sendXmpp <- obj
+				}
+			default:
+				Warn.Logf("Unhandled non-stanza: %T %#v", x, x)
+			}
+		}
+	}
 }
 
 func (cl *Client) handleStreamError(se *streamError) {
@@ -132,17 +128,6 @@
 	cl.sendXml <- &stream{To: cl.Jid.Domain, Version: XMPPVersion}
 }
 
-// Register a callback to handle the next XMPP stanza (iq, message, or
-// presence) with a given id. The provided function will not be called
-// more than once. If it returns false, the stanza will not be made
-// available on the normal Client.Recv channel. The callback must not
-// read from that channel, as deliveries on it cannot proceed until
-// the handler returns true or false.
-func (cl *Client) SetCallback(id string, f func(Stanza) bool) {
-	h := &callback{id: id, f: f}
-	cl.handlers <- h
-}
-
 // Send a request to bind a resource. RFC 3920, section 7.
 func (cl *Client) bind() {
 	res := cl.Jid.Resource
@@ -190,3 +175,14 @@
 	cl.SetCallback(msg.Id, f)
 	cl.sendXml <- msg
 }
+
+// Register a callback to handle the next XMPP stanza (iq, message, or
+// presence) with a given id. The provided function will not be called
+// more than once. If it returns false, the stanza will not be made
+// available on the normal Client.Recv channel. The callback must not
+// read from that channel, as deliveries on it cannot proceed until
+// the handler returns true or false.
+func (cl *Client) SetCallback(id string, f func(Stanza) bool) {
+	h := &callback{id: id, f: f}
+	cl.handlers <- h
+}
--- a/xmpp/sasl.go	Sun Sep 15 16:30:55 2013 -0600
+++ b/xmpp/sasl.go	Sun Sep 15 16:41:02 2013 -0600
@@ -13,6 +13,8 @@
 	"strings"
 )
 
+// Server is advertising auth mechanisms it supports. Choose one and
+// respond.
 // BUG(cjyar): Doesn't implement TLS/SASL EXTERNAL.
 func (cl *Client) chooseSasl(fe *Features) {
 	var digestMd5 bool
@@ -30,6 +32,7 @@
 	}
 }
 
+// Server is responding to our auth request.
 func (cl *Client) handleSasl(srv *auth) {
 	switch strings.ToLower(srv.XMLName.Local) {
 	case "challenge":