add urn:xmpp:time; now response jabber GetInfo

This commit is contained in:
Jesse Kuang 2019-01-10 23:36:50 +08:00
parent 66c008d798
commit 51b558cd2c
3 changed files with 21 additions and 8 deletions

View File

@ -20,7 +20,7 @@ MAKEFILE=GNUmakefile
all: bin/example
@[ -d bin ] || exit
bin/example: _example/example.go xmpp.go
bin/example: _example/example.go xmpp.go xmpp_version.go
@[ -d bin ] || mkdir bin
go build -o $@ _example/example.go
@strip $@ || echo "example OK"

View File

@ -677,6 +677,10 @@ func (c *Client) Recv() (stanza interface{}, err error) {
if err := c.SendIQLast(v.ID, v.From, v.To); err != nil {
return Chat{}, err
}
case "urn:xmpp:time":
if err := c.SendIQtime(v.ID, v.From, v.To); err != nil {
return Chat{}, err
}
case "jabber:iq:roster":
var item rosterItem
var r Roster

View File

@ -19,14 +19,23 @@ func (c *Client) SendVersion(id, toServer, fromU string) error {
}
func (c *Client) SendIQLast(id, toServer, fromU string) error {
_, err := fmt.Fprintf(c.conn, "<iq type='result' from='%s' to='%s'"+
"id='%s' type='result'>\n", xmlEscape(fromU),
xmlEscape(toServer), xmlEscape(id))
if err != nil {
return err
}
ss := fmt.Sprintf("<iq type='result' from='%s' to='%s'"+
" id='%s'>\n", xmlEscape(fromU), xmlEscape(toServer), xmlEscape(id))
tt := time.Now().Sub(c.loginTime)
_, err = fmt.Fprintf(c.conn, "<query xmlns='jabber:iq:last' "+
ss += fmt.Sprintf("<query xmlns='jabber:iq:last' "+
"seconds='%d'>Working</query>\n</iq>", int(tt.Seconds()))
_, err := fmt.Fprint(c.conn, ss)
return err
}
func (c *Client) SendIQtime(id, toServer, fromU string) error {
ss := fmt.Sprintf("<iq type='result' from='%s' to='%s'"+
" id='%s'>\n", xmlEscape(fromU), xmlEscape(toServer), xmlEscape(id))
tt := time.Now()
zoneN, _ := tt.Zone()
ss += fmt.Sprintf("<time xmlns='urn:xmpp:time'>\n<tzo>%s</tzo>"+
"<utc>%s</utc></time>\n</iq>", zoneN,
tt.UTC().Format("2006-01-02T15:03:04Z"))
_, err := fmt.Fprint(c.conn, ss)
return err
}