Added the ability to parse <stream:features>.
authorChris Jones <chris@cjones.org>
Mon, 26 Dec 2011 11:48:35 -0700
changeset 8 30a7752cf8f7
parent 7 4f0f66f9a441
child 9 4fe926b03827
Added the ability to parse <stream:features>.
structs.go
xmpp.go
--- a/structs.go	Sun Dec 25 19:02:53 2011 -0700
+++ b/structs.go	Mon Dec 26 11:48:35 2011 -0700
@@ -66,9 +66,23 @@
 }
 var _ xml.Marshaler = &errText{}
 
+type Features struct {
+	Starttls starttls
+	Mechanisms mechs
+}
+
+type starttls struct {
+	required *string
+}
+
+type mechs struct {
+	Mechanism []string
+}
+
 type Unrecognized struct {
 	XMLName xml.Name
 }
+var _ fmt.Stringer = &Unrecognized{}
 
 func (jid *JID) String() string {
 	result := jid.Domain
@@ -171,3 +185,8 @@
 		io.WriteString(w, `"`)
 	}
 }
+
+func (u *Unrecognized) String() string {
+	return fmt.Sprintf("unrecognized{%s %s}", u.XMLName.Space,
+		u.XMLName.Local)
+}
--- a/xmpp.go	Sun Dec 25 19:02:53 2011 -0700
+++ b/xmpp.go	Mon Dec 26 11:48:35 2011 -0700
@@ -73,6 +73,10 @@
 	go readXml(cl.tcp, cl.in, debug)
 	go writeXml(cl.tcp, cl.out, debug)
 
+	// Initial handshake.
+	hsOut := &Stream{To: jid.Domain, Version: Version}
+	cl.Out <- hsOut
+
 	return cl, nil
 }
 
@@ -125,8 +129,12 @@
 			continue
 		case "stream error":
 			obj = &StreamError{}
+		case nsStream + " features":
+			obj = &Features{}
 		default:
 			obj = &Unrecognized{}
+			log.Printf("Ignoring unrecognized: %s %s\n",
+				se.Name.Space, se.Name.Local)
 		}
 
 		// Read the complete XML stanza.