Merge pull request #77 from ros-tel/master

Auto reply on server ping-request
This commit is contained in:
mattn 2016-09-09 14:33:26 +09:00 committed by GitHub
commit 62f9ce3246
2 changed files with 12 additions and 0 deletions

View File

@ -600,6 +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:
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 return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type, Query: v.Query}, nil
} }
} }

View File

@ -25,3 +25,9 @@ func (c *Client) PingS2S(fromServer, toServer string) error {
xmlEscape(fromServer), xmlEscape(toServer)) xmlEscape(fromServer), xmlEscape(toServer))
return err 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
}