From c84fc9afabc780a62857f7190d12f1c17b398c81 Mon Sep 17 00:00:00 2001 From: Philip Silva Date: Thu, 14 Jan 2016 14:32:03 +0100 Subject: [PATCH 1/2] Recv: handle clientIQ When sending a successful Client-To-Server Ping, one gets a Pong that looks like this: (http://xmpp.org/extensions/xep-0199.html#c2s) --- xmpp.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/xmpp.go b/xmpp.go index 5693f00..0a66fcc 100644 --- a/xmpp.go +++ b/xmpp.go @@ -173,6 +173,7 @@ func (o Options) NewClient() (*Client, error) { if err != nil { return nil, err } + if strings.LastIndex(o.Host, ":") > 0 { host = host[:strings.LastIndex(o.Host, ":")] } @@ -555,6 +556,13 @@ type Presence struct { Status string } +type IQ struct { + ID string + From string + To string + Type string +} + // Recv waits to receive the next XMPP stanza. // Return type is either a presence notification or a chat message. func (c *Client) Recv() (stanza interface{}, err error) { @@ -585,6 +593,14 @@ func (c *Client) Recv() (stanza interface{}, err error) { return Chat{Type: "roster", Roster: r}, nil case *clientPresence: return Presence{v.From, v.To, v.Type, v.Show, v.Status}, nil + case *clientIQ: + result := IQ{ + ID: v.ID, + From: v.From, + To: v.To, + Type: v.Type, + } + return result, nil } } } @@ -724,10 +740,10 @@ type clientPresence struct { type clientIQ struct { // info/query XMLName xml.Name `xml:"jabber:client iq"` - From string `xml:",attr"` - ID string `xml:",attr"` - To string `xml:",attr"` - Type string `xml:",attr"` // error, get, result, set + From string `xml:"from,attr"` + ID string `xml:"id,attr"` + To string `xml:"to,attr"` + Type string `xml:"type,attr"` // error, get, result, set Error clientError Bind bindBind } From adbceb5daecb75897939320bd284c7589f82642c Mon Sep 17 00:00:00 2001 From: Philip Silva Date: Thu, 14 Jan 2016 16:40:46 +0100 Subject: [PATCH 2/2] Recv: handle clientIQ: more terse code --- xmpp.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/xmpp.go b/xmpp.go index 0a66fcc..bb0c472 100644 --- a/xmpp.go +++ b/xmpp.go @@ -594,13 +594,7 @@ func (c *Client) Recv() (stanza interface{}, err error) { case *clientPresence: return Presence{v.From, v.To, v.Type, v.Show, v.Status}, nil case *clientIQ: - result := IQ{ - ID: v.ID, - From: v.From, - To: v.To, - Type: v.Type, - } - return result, nil + return IQ{v.ID, v.From, v.To, v.Type}, nil } } }