diff options
-rw-r--r-- | limox.go | 4 | ||||
-rw-r--r-- | xmpp.go | 43 |
2 files changed, 44 insertions, 3 deletions
@@ -85,14 +85,14 @@ func (l *Limox) run() error { func (l *Limox) buttonCallback() { switch l.State { case Disconnected: - log.Println("Starting connection establishment") + log.Println("Starting connection establishment ...") go l.xmpp(l.JidEditor.Text(), l.PwdEditor.Text()) l.State = Connecting case Connecting: log.Println("Aborted connection establishment") l.State = Disconnected case Connected: - log.Println("Disconnected") + log.Println("Disconnecting ...") l.GuiEvents <- Disconnect l.State = Disconnected } @@ -1,9 +1,15 @@ package main import ( - "log" "crypto/tls" "crypto/x509" + "encoding/xml" + "log" + "strings" +) + +const ( + StreamCloser = `</stream:stream>` ) type XmppEvent uint8 @@ -32,6 +38,8 @@ func (l *Limox) xmpp(jid string, pwd string) { } l.XmppEvents <- XmppConnect + sendStreamStart(conn, jid) + var closing bool = false for { ev := <-l.GuiEvents @@ -46,10 +54,43 @@ func (l *Limox) xmpp(jid string, pwd string) { } } + log.Print("C: " + StreamCloser) + conn.Write([]byte(StreamCloser)) conn.Close() l.XmppEvents <- XmppDisconnect } +type StreamInit struct { + XMLName xml.Name `xml:"stream:stream"` + From string `xml:"from,attr"` + To string `xml:"to,attr"` + Version string `xml:"version,attr"` + XmlLang string `xml:"xml:lang,attr"` + Xmlns string `xml:"xmlns,attr"` + XmlnsStream string `xml:"xmlns:stream,attr"` +} + +func sendStreamStart(t *tls.Conn, jid string) { + data := StreamInit{ + From: jid, + To: domainpart(jid), + Version: "1.0", + XmlLang: "en", + Xmlns: "jabber:client", + XmlnsStream: "http://etherx.jabber.org/streams", + } + + serialized, err := xml.Marshal(data) + if err != nil { + log.Fatal(err) + } + + str := strings.TrimSuffix(string(serialized), StreamCloser) + log.Print("C: " + str) + + t.Write([]byte(serialized)) +} + // domainpart extracts the domain name from a JID / XMPP address. See // https://datatracker.ietf.org/doc/html/rfc7622#section-3.2 for details. func domainpart(jid string) string { |