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
|
// ping ignore
|
||||||
if v.Type == "result" && v.ID == "c2s1" {
|
if v.Type == "result" && v.ID == "c2s1" {
|
||||||
fmt.Printf("Got pong from %s to %s\n", v.From, v.To)
|
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:
|
default:
|
||||||
fmt.Printf("def: %v\n", v)
|
fmt.Printf("def: %v\n", v)
|
||||||
@ -110,7 +113,8 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
// get roster first
|
// get roster first
|
||||||
talk.Roster()
|
talk.Roster()
|
||||||
talk.SendOrg("<presence/>")
|
// test conf
|
||||||
|
talk.JoinMUCNoHistory("test@conference.jabb3r.org", "bot")
|
||||||
for {
|
for {
|
||||||
in := bufio.NewReader(os.Stdin)
|
in := bufio.NewReader(os.Stdin)
|
||||||
line, err := in.ReadString('\n')
|
line, err := in.ReadString('\n')
|
||||||
|
16
xmpp.go
16
xmpp.go
@ -24,6 +24,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -617,7 +618,8 @@ type IQ struct {
|
|||||||
From string
|
From string
|
||||||
To string
|
To string
|
||||||
Type string
|
Type string
|
||||||
Query []byte
|
Query string
|
||||||
|
QueryName xml.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recv waits to receive the next XMPP stanza.
|
// Recv waits to receive the next XMPP stanza.
|
||||||
@ -656,7 +658,7 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
|||||||
case *clientIQ:
|
case *clientIQ:
|
||||||
// TODO check more strictly
|
// TODO check more strictly
|
||||||
if v.Query.XMLName.Space == "urn:xmpp:ping" {
|
if v.Query.XMLName.Space == "urn:xmpp:ping" {
|
||||||
fmt.Println("clientIQ ping")
|
log.Print("clientIQ ping")
|
||||||
err := c.SendResultPing(v.ID, v.From)
|
err := c.SendResultPing(v.ID, v.From)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Chat{}, err
|
return Chat{}, err
|
||||||
@ -664,10 +666,14 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
|||||||
}
|
}
|
||||||
// <query xmlns='jabber:iq:roster' ver='5'>
|
// <query xmlns='jabber:iq:roster' ver='5'>
|
||||||
// TODO: shall we check XMLName.Local is "query"?
|
// TODO: shall we check XMLName.Local is "query"?
|
||||||
if (v.Type == "result" || v.Type == "set") &&
|
if v.Query.XMLName.Space == "jabber:iq:roster" {
|
||||||
v.Query.XMLName.Space == "jabber:iq:roster" {
|
|
||||||
var item rosterItem
|
var item rosterItem
|
||||||
var r Roster
|
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, "/>")
|
vv := strings.Split(v.Query.InnerXML, "/>")
|
||||||
for _, ss := range vv {
|
for _, ss := range vv {
|
||||||
if strings.TrimSpace(ss) == "" {
|
if strings.TrimSpace(ss) == "" {
|
||||||
@ -686,7 +692,7 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
|||||||
return Chat{Type: "roster", Roster: r}, nil
|
return Chat{Type: "roster", Roster: r}, nil
|
||||||
}
|
}
|
||||||
return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type,
|
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