From 51b558cd2cef8c66321eee4b2c2ede5af5df574b Mon Sep 17 00:00:00 2001 From: Jesse Kuang <2829915232@qq.com> Date: Thu, 10 Jan 2019 23:36:50 +0800 Subject: [PATCH] add urn:xmpp:time; now response jabber GetInfo --- GNUmakefile | 2 +- xmpp.go | 4 ++++ xmpp_version.go | 23 ++++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 00b2b5c..25808b9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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" diff --git a/xmpp.go b/xmpp.go index bb0b454..a2e6956 100644 --- a/xmpp.go +++ b/xmpp.go @@ -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 diff --git a/xmpp_version.go b/xmpp_version.go index b13f74e..05108ef 100644 --- a/xmpp_version.go +++ b/xmpp_version.go @@ -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, "\n", xmlEscape(fromU), - xmlEscape(toServer), xmlEscape(id)) - if err != nil { - return err - } + ss := fmt.Sprintf("\n", xmlEscape(fromU), xmlEscape(toServer), xmlEscape(id)) tt := time.Now().Sub(c.loginTime) - _, err = fmt.Fprintf(c.conn, "Working\n", int(tt.Seconds())) + _, err := fmt.Fprint(c.conn, ss) + return err +} + +func (c *Client) SendIQtime(id, toServer, fromU string) error { + ss := fmt.Sprintf("\n", xmlEscape(fromU), xmlEscape(toServer), xmlEscape(id)) + tt := time.Now() + zoneN, _ := tt.Zone() + ss += fmt.Sprintf("\n", zoneN, + tt.UTC().Format("2006-01-02T15:03:04Z")) + _, err := fmt.Fprint(c.conn, ss) return err }