Skip to content

Commit

Permalink
Merge pull request #77 from ros-tel/master
Browse files Browse the repository at this point in the history
Auto reply on server ping-request
  • Loading branch information
mattn committed Sep 9, 2016
2 parents e44d187 + 6265286 commit 62f9ce3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions xmpp.go
Expand Up @@ -600,6 +600,12 @@ func (c *Client) Recv() (stanza interface{}, err error) {
case *clientPresence:
return Presence{v.From, v.To, v.Type, v.Show, v.Status}, nil
case *clientIQ:
if bytes.Equal(v.Query, []byte(`<ping xmlns='urn:xmpp:ping'/>`)) {
err := c.SendResultPing(v.ID, v.From)
if err != nil {
return Chat{}, err
}
}
return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type, Query: v.Query}, nil
}
}
Expand Down
6 changes: 6 additions & 0 deletions xmpp_ping.go
Expand Up @@ -25,3 +25,9 @@ func (c *Client) PingS2S(fromServer, toServer string) error {
xmlEscape(fromServer), xmlEscape(toServer))
return err
}

func (c *Client) SendResultPing(id, toServer string) error {
_, err := fmt.Fprintf(c.conn, "<iq type='result' to='%s' id='%s'/>",
xmlEscape(toServer), xmlEscape(id))
return err
}

0 comments on commit 62f9ce3

Please sign in to comment.