forked from jshiffer/go-xmpp
Removed debug comment and extra action with an IQ query
This commit is contained in:
parent
ccac8addc9
commit
6265286138
32
xmpp.go
32
xmpp.go
@ -40,7 +40,6 @@ const (
|
|||||||
nsBind = "urn:ietf:params:xml:ns:xmpp-bind"
|
nsBind = "urn:ietf:params:xml:ns:xmpp-bind"
|
||||||
nsClient = "jabber:client"
|
nsClient = "jabber:client"
|
||||||
nsSession = "urn:ietf:params:xml:ns:xmpp-session"
|
nsSession = "urn:ietf:params:xml:ns:xmpp-session"
|
||||||
nsPing = "urn:xmpp:ping"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default TLS configuration options
|
// Default TLS configuration options
|
||||||
@ -601,17 +600,12 @@ 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:
|
||||||
//fmt.Printf("$+v", val)
|
if bytes.Equal(v.Query, []byte(`<ping xmlns='urn:xmpp:ping'/>`)) {
|
||||||
_, vali, err := UnmarshalIqQuery(v.Query)
|
|
||||||
if err == nil {
|
|
||||||
switch vali.(type) {
|
|
||||||
case *serverPingRequest:
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type, Query: v.Query}, nil
|
return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type, Query: v.Query}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -785,10 +779,6 @@ type rosterItem struct {
|
|||||||
Group []string
|
Group []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type serverPingRequest struct {
|
|
||||||
XMLName xml.Name `xml:"urn:xmpp:ping ping"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan XML token stream to find next StartElement.
|
// Scan XML token stream to find next StartElement.
|
||||||
func nextStart(p *xml.Decoder) (xml.StartElement, error) {
|
func nextStart(p *xml.Decoder) (xml.StartElement, error) {
|
||||||
for {
|
for {
|
||||||
@ -895,23 +885,3 @@ func (t tee) Read(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnmarshalIqQuery(Query []byte) (xml.Name, interface{}, error) {
|
|
||||||
dec := xml.NewDecoder(bytes.NewBuffer(Query))
|
|
||||||
|
|
||||||
se, err := nextStart(dec)
|
|
||||||
if err != nil {
|
|
||||||
return xml.Name{}, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var nv interface{}
|
|
||||||
switch se.Name.Space + " " + se.Name.Local {
|
|
||||||
case nsPing + " ping":
|
|
||||||
nv = &serverPingRequest{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = dec.DecodeElement(nv, &se); err != nil {
|
|
||||||
return xml.Name{}, nil, err
|
|
||||||
}
|
|
||||||
return se.Name, nv, err
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user