From 7acc044a527fd0d62afb4ff8742fc77e91f17e00 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 3 May 2022 21:24:27 +0200 Subject: ox: use glib date function in _gettimestamp and fix memleak --- src/xmpp/ox.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/xmpp/ox.c b/src/xmpp/ox.c index d6ce9434..fab3d675 100644 --- a/src/xmpp/ox.c +++ b/src/xmpp/ox.c @@ -55,14 +55,13 @@ static int _ox_metadata_result(xmpp_stanza_t* const stanza, void* const userdata static void _ox_request_public_key(const char* const jid, const char* const fingerprint); static int _ox_public_key_result(xmpp_stanza_t* const stanza, void* const userdata); -/*! - * \brief Current Date and Time. +/* Return Current Date and Time. * * XEP-0082: XMPP Date and Time Profiles * https://xmpp.org/extensions/xep-0082.html * - * \return YYYY-MM-DDThh:mm:ssZ - * + * According to ISO8601 + * YYYY-MM-DDThh:mm:ssZ */ static char* _gettimestamp(); @@ -268,7 +267,9 @@ _ox_metadata_node__public_key(const char* const fingerprint) xmpp_stanza_t* pubkeymetadata = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pubkeymetadata, STANZA_NAME_PUBKEY_METADATA); xmpp_stanza_set_attribute(pubkeymetadata, STANZA_ATTR_V4_FINGERPRINT, fingerprint); - xmpp_stanza_set_attribute(pubkeymetadata, STANZA_ATTR_DATE, _gettimestamp()); + char* timestamp = _gettimestamp(); + xmpp_stanza_set_attribute(pubkeymetadata, STANZA_ATTR_DATE, timestamp); + free(timestamp); xmpp_stanza_add_child(publickeyslist, pubkeymetadata); xmpp_stanza_add_child(item, publickeyslist); @@ -476,13 +477,10 @@ _ox_public_key_result(xmpp_stanza_t* const stanza, void* const userdata) char* _gettimestamp() { - time_t now = time(NULL); - struct tm* tm = localtime(&now); - char buf[255]; - strftime(buf, sizeof(buf), "%FT%T", tm); - GString* d = g_string_new(buf); - g_string_append(d, "Z"); - return strdup(d->str); + GDateTime* dt = g_date_time_new_now_local(); + gchar* datestr = g_date_time_format(dt, "%FT%TZ"); + g_date_time_unref(dt); + return datestr; } #endif // HAVE_LIBGPGME -- cgit 1.4.1-2-gfad0 hlt'/>
path: root/tools/iso/kernel.soso/sleep.c
blob: bc7696985c04ae01c1cd732e0d4611f92e5c12f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16