forked from jshiffer/go-xmpp
add conference support
This commit is contained in:
parent
c18873b880
commit
1e7b50b41c
@ -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("<presence/>")
|
||||
// test conf
|
||||
talk.JoinMUCNoHistory("test@conference.jabb3r.org", "bot")
|
||||
for {
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
line, err := in.ReadString('\n')
|
||||
|
24
xmpp.go
24
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) {
|
||||
}
|
||||
// <query xmlns='jabber:iq:roster' ver='5'>
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user