From 1e7b50b41ca89f802b3d79d2ac825e682b7d1b1d Mon Sep 17 00:00:00 2001 From: Jesse Kuang Date: Thu, 10 Jan 2019 14:46:50 +0800 Subject: [PATCH] add conference support --- _example/example.go | 6 +++++- xmpp.go | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/_example/example.go b/_example/example.go index d0da4a3..c1f51f0 100644 --- a/_example/example.go +++ b/_example/example.go @@ -102,6 +102,9 @@ func main() { // ping ignore if v.Type == "result" && v.ID == "c2s1" { fmt.Printf("Got pong from %s to %s\n", v.From, v.To) + } else { + fmt.Printf("Got from %s to %s IQ, tag: (%v), query(%s)\n", + v.From, v.To, v.QueryName, v.Query) } default: fmt.Printf("def: %v\n", v) @@ -110,7 +113,8 @@ func main() { }() // get roster first talk.Roster() - talk.SendOrg("") + // test conf + talk.JoinMUCNoHistory("test@conference.jabb3r.org", "bot") for { in := bufio.NewReader(os.Stdin) line, err := in.ReadString('\n') diff --git a/xmpp.go b/xmpp.go index e704a47..b7c89f3 100644 --- a/xmpp.go +++ b/xmpp.go @@ -24,6 +24,7 @@ import ( "errors" "fmt" "io" + "log" "math/big" "net" "net/http" @@ -613,11 +614,12 @@ type Presence struct { } type IQ struct { - ID string - From string - To string - Type string - Query []byte + ID string + From string + To string + Type string + Query string + QueryName xml.Name } // Recv waits to receive the next XMPP stanza. @@ -656,7 +658,7 @@ func (c *Client) Recv() (stanza interface{}, err error) { case *clientIQ: // TODO check more strictly if v.Query.XMLName.Space == "urn:xmpp:ping" { - fmt.Println("clientIQ ping") + log.Print("clientIQ ping") err := c.SendResultPing(v.ID, v.From) if err != nil { return Chat{}, err @@ -664,10 +666,14 @@ func (c *Client) Recv() (stanza interface{}, err error) { } // // TODO: shall we check XMLName.Local is "query"? - if (v.Type == "result" || v.Type == "set") && - v.Query.XMLName.Space == "jabber:iq:roster" { + if v.Query.XMLName.Space == "jabber:iq:roster" { var item rosterItem var r Roster + if v.Type != "result" && v.Type != "set" { + // only result and set processed + return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type, + Query: v.Query.InnerXML, QueryName: v.Query.XMLName}, nil + } vv := strings.Split(v.Query.InnerXML, "/>") for _, ss := range vv { if strings.TrimSpace(ss) == "" { @@ -686,7 +692,7 @@ func (c *Client) Recv() (stanza interface{}, err error) { return Chat{Type: "roster", Roster: r}, nil } return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type, - Query: []byte(v.Query.InnerXML)}, nil + Query: v.Query.InnerXML, QueryName: v.Query.XMLName}, nil } } }