summaryrefslogtreecommitdiff
path: root/xmpp/streams.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/streams.go')
-rw-r--r--xmpp/streams.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/xmpp/streams.go b/xmpp/streams.go
new file mode 100644
index 0000000..9f6ffe8
--- /dev/null
+++ b/xmpp/streams.go
@@ -0,0 +1,64 @@
+package xmpp
+
+import (
+ "encoding/xml"
+ "log"
+)
+
+type streamFeatures struct {
+ SaslMechanisms []string `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms>mechanism"`
+ Bind *bool `xml:"urn:ietf:params:xml:ns:xmpp-bind bind,omitempty"`
+}
+
+func handleStreamFeatures(s *session, f streamFeatures) {
+ if len(f.SaslMechanisms) > 0 {
+ for _, v := range f.SaslMechanisms {
+ if v == "PLAIN" {
+ s.sasl()
+ return
+ }
+ }
+ log.Println("No compatible SASL mechanism found!")
+ return
+ }
+
+ if f.Bind != nil {
+ s.sendBind()
+ return
+ }
+}
+
+func openStream(e *xml.Encoder, jid string) {
+ start := xml.StartElement{
+ xml.Name{"jabber:client", "stream:stream"},
+ []xml.Attr{
+ xml.Attr{xml.Name{"", "from"}, jid},
+ xml.Attr{xml.Name{"", "to"}, domainpart(jid)},
+ xml.Attr{xml.Name{"", "version"}, "1.0"},
+ xml.Attr{xml.Name{"", "xml:lang"}, "en"},
+ xml.Attr{xml.Name{"", "xmlns:stream"}, "http://etherx.jabber.org/streams"},
+ },
+ }
+
+ err := e.EncodeToken(start)
+ if err != nil {
+ log.Println("Could not encode stream start!")
+ }
+ err = e.Flush()
+ if err != nil {
+ log.Println("Could not flush after stream start!")
+ }
+}
+
+func closeStream(e *xml.Encoder) {
+ end := xml.EndElement{xml.Name{"jabber:client", "stream:stream"}}
+
+ err := e.EncodeToken(end)
+ if err != nil {
+ log.Println("Could not encode stream end!")
+ }
+ err = e.Flush()
+ if err != nil {
+ log.Println("Could not flush after stream end!")
+ }
+}