mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-25 08:53:36 +00:00
Use the time functions of xs_time.h.
This commit is contained in:
parent
3161eeb028
commit
849913dc59
5 changed files with 11 additions and 29 deletions
7
Makefile
7
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
3
http.c
3
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:/" "/", "");
|
||||
|
|
21
snac.c
21
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);
|
||||
}
|
||||
}
|
||||
|
|
4
snac.h
4
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue