From 849913dc5987997f9db96e23c7acf9c29f9c6d7f Mon Sep 17 00:00:00 2001 From: default Date: Sun, 2 Oct 2022 09:27:17 +0200 Subject: [PATCH] Use the time functions of xs_time.h. --- Makefile | 7 ++++--- activitypub.c | 5 +++-- http.c | 3 ++- snac.c | 21 ++------------------- snac.h | 4 ---- 5 files changed, 11 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 9f729b5..ca33810 100644 --- a/Makefile +++ b/Makefile @@ -15,14 +15,15 @@ dep: $(CC) -I/usr/local/include -MM *.c > makefile.depend activitypub.o: activitypub.c xs.h xs_encdec.h xs_json.h xs_curl.h \ - xs_mime.h xs_openssl.h xs_regex.h snac.h + xs_mime.h xs_openssl.h xs_regex.h xs_time.h snac.h data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h snac.h html.o: html.c xs.h xs_io.h xs_encdec.h xs_json.h xs_regex.h xs_set.h \ + xs_openssl.h snac.h +http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h xs_time.h \ snac.h -http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h snac.h httpd.o: httpd.c xs.h xs_io.h xs_encdec.h xs_json.h xs_socket.h \ xs_httpd.h snac.h main.o: main.c xs.h xs_io.h xs_encdec.h xs_json.h snac.h snac.o: snac.c xs.h xs_io.h xs_encdec.h xs_json.h xs_curl.h xs_openssl.h \ - xs_socket.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h snac.h + xs_socket.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h snac.h webfinger.o: webfinger.c xs.h xs_encdec.h xs_json.h xs_curl.h snac.h diff --git a/activitypub.c b/activitypub.c index 9fee973..8771ee8 100644 --- a/activitypub.c +++ b/activitypub.c @@ -8,6 +8,7 @@ #include "xs_mime.h" #include "xs_openssl.h" #include "xs_regex.h" +#include "xs_time.h" #include "snac.h" @@ -281,7 +282,7 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char /* generated values */ if (date && strcmp(date, "@now") == 0) - date = published = xs_utc_time("%Y-%m-%dT%H:%M:%SZ"); + date = published = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ"); if (id != NULL) { if (strcmp(id, "@dummy") == 0) { @@ -649,7 +650,7 @@ int process_message(snac *snac, char *msg, char *req) if (xs_is_null(xs_dict_get(f_msg, "published"))) { /* add a date if it doesn't include one (Mastodon) */ - xs *date = xs_utc_time("%Y-%m-%dT%H:%M:%SZ"); + xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ"); f_msg = xs_dict_set(f_msg, "published", date); } diff --git a/http.c b/http.c index a58aaf4..915d5f3 100644 --- a/http.c +++ b/http.c @@ -6,6 +6,7 @@ #include "xs_encdec.h" #include "xs_openssl.h" #include "xs_curl.h" +#include "xs_time.h" #include "snac.h" @@ -27,7 +28,7 @@ d_char *http_signed_request(snac *snac, char *method, char *url, char *k, *v; d_char *response; - date = xs_utc_time("%a, %d %b %Y %H:%M:%S GMT"); + date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT"); { xs *s = xs_replace(url, "https:/" "/", ""); diff --git a/snac.c b/snac.c index 3140474..93b4e05 100644 --- a/snac.c +++ b/snac.c @@ -14,6 +14,7 @@ #include "xs_mime.h" #include "xs_regex.h" #include "xs_set.h" +#include "xs_time.h" #include "snac.h" @@ -28,24 +29,6 @@ int srv_running = 0; int dbglevel = 0; -d_char *xs_time(char *fmt, int local) -/* returns a d_char with a formated time */ -{ - time_t t = time(NULL); - struct tm tm; - char tmp[64]; - - if (local) - localtime_r(&t, &tm); - else - gmtime_r(&t, &tm); - - strftime(tmp, sizeof(tmp), fmt, &tm); - - return xs_str_new(tmp); -} - - d_char *tid(int offset) /* returns a time-based Id */ { @@ -92,7 +75,7 @@ void srv_debug(int level, d_char *str) } if (dbglevel >= level) { - xs *tm = xs_local_time("%H:%M:%S"); + xs *tm = xs_str_localtime(0, "%H:%M:%S"); fprintf(stderr, "%s %s\n", tm, msg); } } diff --git a/snac.h b/snac.h index 9a597b2..dc49e8d 100644 --- a/snac.h +++ b/snac.h @@ -18,10 +18,6 @@ extern const char *susie; #define L(s) (s) -d_char *xs_time(char *fmt, int local); -#define xs_local_time(fmt) xs_time(fmt, 1) -#define xs_utc_time(fmt) xs_time(fmt, 0) - d_char *tid(int offset); double ftime(void);