Made the input and output channels of type Stanza rather than
authorChris Jones <chris@cjones.org>
Wed, 28 Dec 2011 13:24:08 -0700
changeset 23 b5de44679389
parent 22 d6b7b4cbf50d
child 24 fff79efe06f6
Made the input and output channels of type Stanza rather than interface{}. We should handle everything internally that's not an iq, message, or presence.
examples/interact.go
stream.go
xmpp.go
--- a/examples/interact.go	Wed Dec 28 13:14:46 2011 -0700
+++ b/examples/interact.go	Wed Dec 28 13:24:08 2011 -0700
@@ -30,7 +30,7 @@
 	}
 	defer c.Close()
 
-	go func(ch <-chan interface{}) {
+	go func(ch <-chan xmpp.Stanza) {
 		for obj := range ch {
 			fmt.Printf("s: %v\n", obj)
 		}
--- a/stream.go	Wed Dec 28 13:14:46 2011 -0700
+++ b/stream.go	Wed Dec 28 13:24:08 2011 -0700
@@ -189,7 +189,7 @@
 	}
 }
 
-func (cl *Client) readStream(srvIn <-chan interface{}, cliOut chan<- interface{}) {
+func (cl *Client) readStream(srvIn <-chan interface{}, cliOut chan<- Stanza) {
 	defer tryClose(srvIn, cliOut)
 
 	handlers := make(map[string] func(Stanza) bool)
@@ -213,14 +213,19 @@
 			default:
 				send = true
 			}
-			if st, ok := x.(Stanza) ; ok &&
-				handlers[st.XId()] != nil {
+			st, ok := x.(Stanza)
+			if !ok {
+				log.Printf("Unhandled non-stanza: %v",
+					x)
+				continue
+			}
+			if handlers[st.XId()] != nil {
 				f := handlers[st.XId()]
 				handlers[st.XId()] = nil
 				send = f(st)
 			}
 			if send {
-				cliOut <- x
+				cliOut <- st
 			}
 		}
 	}
@@ -229,7 +234,7 @@
 // BUG(cjyar) Disable this loop until resource binding is
 // complete. Otherwise the app might inject something weird into our
 // negotiation stream.
-func writeStream(srvOut chan<- interface{}, cliIn <-chan interface{}) {
+func writeStream(srvOut chan<- interface{}, cliIn <-chan Stanza) {
 	defer tryClose(srvOut, cliIn)
 
 	for x := range cliIn {
--- a/xmpp.go	Wed Dec 28 13:14:46 2011 -0700
+++ b/xmpp.go	Wed Dec 28 13:24:08 2011 -0700
@@ -58,11 +58,10 @@
 	// Incoming XMPP stanzas from the server will be published on
 	// this channel. Information which is only used by this
 	// library to set up the XMPP stream will not appear here.
-	// BUG(cjyar) Make these channels of type Stanza.
-	In <-chan interface{}
+	In <-chan Stanza
 	// Outgoing XMPP stanzas to the server should be sent to this
 	// channel.
-	Out chan<- interface{}
+	Out chan<- Stanza
 	xmlOut chan<- interface{}
 	// BUG(cjyar) Remove this. Make a Stanza parser method
 	// available for use by interact.go and similar applications.
@@ -164,14 +163,14 @@
 	return ch
 }
 
-func (cl *Client) startStreamReader(xmlIn <-chan interface{}, srvOut chan<- interface{}) <-chan interface{} {
-	ch := make(chan interface{})
+func (cl *Client) startStreamReader(xmlIn <-chan interface{}, srvOut chan<- interface{}) <-chan Stanza {
+	ch := make(chan Stanza)
 	go cl.readStream(xmlIn, ch)
 	return ch
 }
 
-func startStreamWriter(xmlOut chan<- interface{}) chan<- interface{} {
-	ch := make(chan interface{})
+func startStreamWriter(xmlOut chan<- interface{}) chan<- Stanza {
+	ch := make(chan Stanza)
 	go writeStream(xmlOut, ch)
 	return ch
 }