forked from jshiffer/go-xmpp
Merge pull request #76 from TallaInc/improvement/information-query
expose information queries for custom extensions
This commit is contained in:
commit
e44d1877bb
13
xmpp.go
13
xmpp.go
@ -562,10 +562,11 @@ type Presence struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IQ struct {
|
type IQ struct {
|
||||||
ID string
|
ID string
|
||||||
From string
|
From string
|
||||||
To string
|
To string
|
||||||
Type string
|
Type string
|
||||||
|
Query []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recv waits to receive the next XMPP stanza.
|
// Recv waits to receive the next XMPP stanza.
|
||||||
@ -599,7 +600,7 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
|||||||
case *clientPresence:
|
case *clientPresence:
|
||||||
return Presence{v.From, v.To, v.Type, v.Show, v.Status}, nil
|
return Presence{v.From, v.To, v.Type, v.Show, v.Status}, nil
|
||||||
case *clientIQ:
|
case *clientIQ:
|
||||||
return IQ{v.ID, v.From, v.To, v.Type}, nil
|
return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type, Query: v.Query}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -747,6 +748,7 @@ type clientIQ struct { // info/query
|
|||||||
ID string `xml:"id,attr"`
|
ID string `xml:"id,attr"`
|
||||||
To string `xml:"to,attr"`
|
To string `xml:"to,attr"`
|
||||||
Type string `xml:"type,attr"` // error, get, result, set
|
Type string `xml:"type,attr"` // error, get, result, set
|
||||||
|
Query []byte `xml:",innerxml"`
|
||||||
Error clientError
|
Error clientError
|
||||||
Bind bindBind
|
Bind bindBind
|
||||||
}
|
}
|
||||||
@ -839,6 +841,7 @@ func next(p *xml.Decoder) (xml.Name, interface{}, error) {
|
|||||||
if err = p.DecodeElement(nv, &se); err != nil {
|
if err = p.DecodeElement(nv, &se); err != nil {
|
||||||
return xml.Name{}, nil, err
|
return xml.Name{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return se.Name, nv, err
|
return se.Name, nv, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package xmpp
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
const xmlIqGet = "<iq from='%s' to='%s' id='%d' type='get'><query xmlns='http://jabber.org/protocol/disco#items'/></iq>"
|
|
||||||
|
|
||||||
func (c *Client) Discovery() {
|
|
||||||
cookie := getCookie()
|
|
||||||
fmt.Fprintf(c.conn, xmlIqGet, xmlEscape(c.jid), xmlEscape(c.domain), cookie)
|
|
||||||
}
|
|
24
xmpp_information_query.go
Normal file
24
xmpp_information_query.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package xmpp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
const IQTypeGet = "get"
|
||||||
|
const IQTypeSet = "set"
|
||||||
|
const IQTypeResult = "result"
|
||||||
|
|
||||||
|
func (c *Client) Discovery() (string, error) {
|
||||||
|
const namespace = "http://jabber.org/protocol/disco#items"
|
||||||
|
// use getCookie for a pseudo random id.
|
||||||
|
reqID := strconv.FormatUint(uint64(getCookie()), 10)
|
||||||
|
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, namespace, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// RawInformationQuery sends an information query request to the server.
|
||||||
|
func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error) {
|
||||||
|
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>"
|
||||||
|
_, err := fmt.Fprintf(c.conn, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
|
||||||
|
return id, err
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user