From 99516ec31f6638ff2650557bf24b303e45b3ff09 Mon Sep 17 00:00:00 2001 From: Flo Lauber Date: Fri, 18 Jan 2013 19:14:09 -0500 Subject: [PATCH 1/4] add xml-specifier for Jid in type bindBind --- xmpp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmpp.go b/xmpp.go index eb94b52..a8469f7 100644 --- a/xmpp.go +++ b/xmpp.go @@ -308,7 +308,7 @@ type saslFailure struct { type bindBind struct { XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` Resource string - Jid string + Jid string `xml:"jid"` } // RFC 3921 B.1 jabber:client From 1e9dc674d10e6c6bcf91f8b865c279243f71510c Mon Sep 17 00:00:00 2001 From: Flo Lauber Date: Fri, 18 Jan 2013 19:48:50 -0500 Subject: [PATCH 2/4] return Presence messages in Recv --- xmpp.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/xmpp.go b/xmpp.go index a8469f7..ef2107b 100644 --- a/xmpp.go +++ b/xmpp.go @@ -222,15 +222,25 @@ type Chat struct { Text string } +type Presence struct { + From string + To string + Type string + Show string +} + // Recv wait next token of chat. -func (c *Client) Recv() (chat Chat, err error) { +func (c *Client) Recv() (event interface{}, err error) { for { _, val, err := next(c.p) if err != nil { return Chat{}, err } - if v, ok := val.(*clientMessage); ok { + switch v := val.(type) { + case *clientMessage: return Chat{v.From, v.Type, v.Body}, nil + case *clientPresence: + return Presence{v.From, v.To, v.Type, v.Show}, nil } } panic("unreachable") @@ -340,9 +350,9 @@ type clientPresence struct { Type string `xml:"type,attr"` // error, probe, subscribe, subscribed, unavailable, unsubscribe, unsubscribed Lang string `xml:"lang,attr"` - Show string `xml:"show,attr"`// away, chat, dnd, xa - Status string `xml:"status,attr"`// sb []clientText - Priority string `xml:"priority,attr"` + Show string `xml:"show"` // away, chat, dnd, xa + Status string `xml:"status,attr"` // sb []clientText + Priority string `xml:"priority,attr"` Error *clientError } From 52c3f1b7107fd29a29251014f1944c21fad0ddb8 Mon Sep 17 00:00:00 2001 From: Flo Lauber Date: Fri, 18 Jan 2013 19:49:47 -0500 Subject: [PATCH 3/4] use `Chat.type` in 's type attr in Send() Otherwise client.Send(..) cannot be used for MUC 'groupchat' messages. This might break code, if you're not setting `Chat`'s type slot and rely on `client.Send` set it to 'chat' by default --- xmpp.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xmpp.go b/xmpp.go index ef2107b..2378ef5 100644 --- a/xmpp.go +++ b/xmpp.go @@ -248,13 +248,12 @@ func (c *Client) Recv() (event interface{}, err error) { // Send sends message text. func (c *Client) Send(chat Chat) { - fmt.Fprintf(c.tls, ""+ + fmt.Fprintf(c.tls, ""+ "%s", - xmlEscape(chat.Remote), xmlEscape(chat.Text)) + xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text)) } // RFC 3920 C.1 Streams name space - type streamFeatures struct { XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"` StartTLS tlsStartTLS From 75752790ebd726dcec248b40f425162944b5ee8d Mon Sep 17 00:00:00 2001 From: Flo Lauber Date: Fri, 18 Jan 2013 19:53:38 -0500 Subject: [PATCH 4/4] add first simple version of MUC (xep-0045) support --- xmpp_muc.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 xmpp_muc.go diff --git a/xmpp_muc.go b/xmpp_muc.go new file mode 100644 index 0000000..0c56620 --- /dev/null +++ b/xmpp_muc.go @@ -0,0 +1,31 @@ +// Copyright 2013 Flo Lauber . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// TODO(flo): +// - support password protected MUC rooms +// - cleanup signatures of join/leave functions +package xmpp + +import ( + "fmt" +) + +const ( + nsMUC = "http://jabber.org/protocol/muc" + nsMUCUser = "http://jabber.org/protocol/muc#user" +) + +// xep-0045 7.2 +func (c *Client) JoinMUC(jid string) { + fmt.Fprintf(c.tls, "\n"+ + "\n"+ + "", + xmlEscape(jid), nsMUC) +} + +// xep-0045 7.14 +func (c *Client) LeaveMUC(jid string) { + fmt.Fprintf(c.tls, "", + c.jid, xmlEscape(jid)) +}