about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-05-03 21:24:27 +0200
committerMichael Vetter <jubalh@iodoru.org>2022-05-03 21:26:31 +0200
commit7acc044a527fd0d62afb4ff8742fc77e91f17e00 (patch)
treed22b128b6ac174311d53795169e4a0a306c2a157
parente16bff232860e054d0fe9c1ddc5aa746365e65a5 (diff)
downloadprofani-tty-7acc044a527fd0d62afb4ff8742fc77e91f17e00.tar.gz
ox: use glib date function in _gettimestamp and fix memleak
-rw-r--r--src/xmpp/ox.c22
1 files changed, 10 insertions, 12 deletions
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