summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-12 10:41:15 +0200
committerGravatar default2023-04-12 10:41:15 +0200
commit885031bed9e54876fb262921b11df23aa00cedb6 (patch)
treea1541acecaa547b5a637600d76e8a0df1fde6225
parentUse the ctime instead of the published date in mastoapi_id(). (diff)
downloadpenes-snac2-885031bed9e54876fb262921b11df23aa00cedb6.tar.gz
penes-snac2-885031bed9e54876fb262921b11df23aa00cedb6.tar.xz
penes-snac2-885031bed9e54876fb262921b11df23aa00cedb6.zip
Don't generate invalid JSON if an attachment has no description.
-rw-r--r--data.c10
-rw-r--r--mastoapi.c15
-rw-r--r--snac.h2
3 files changed, 22 insertions, 5 deletions
diff --git a/data.c b/data.c
index 6ca5e0a..bfbf26a 100644
--- a/data.c
+++ b/data.c
@@ -1971,7 +1971,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req,
1971 1971
1972 1972
1973void srv_archive_error(const char *prefix, const xs_str *err, 1973void srv_archive_error(const char *prefix, const xs_str *err,
1974 const xs_dict *req, const xs_dict *data) 1974 const xs_dict *req, const xs_val *data)
1975/* archives an error */ 1975/* archives an error */
1976{ 1976{
1977 xs *ntid = tid(0); 1977 xs *ntid = tid(0);
@@ -1993,8 +1993,12 @@ void srv_archive_error(const char *prefix, const xs_str *err,
1993 if (data) { 1993 if (data) {
1994 fprintf(f, "Data:\n"); 1994 fprintf(f, "Data:\n");
1995 1995
1996 xs *j = xs_json_dumps_pp(data, 4); 1996 if (xs_type(data) == XSTYPE_LIST || xs_type(data) == XSTYPE_DICT) {
1997 fwrite(j, strlen(j), 1, f); 1997 xs *j = xs_json_dumps_pp(data, 4);
1998 fwrite(j, strlen(j), 1, f);
1999 }
2000 else
2001 fprintf(f, "%s", data);
1998 2002
1999 fprintf(f, "\n"); 2003 fprintf(f, "\n");
2000 } 2004 }
diff --git a/mastoapi.c b/mastoapi.c
index be1ba61..3cfaa34 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -506,7 +506,12 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
506 matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url")); 506 matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url"));
507 matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url")); 507 matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url"));
508 matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url")); 508 matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url"));
509 matte = xs_dict_append(matte, "description", xs_dict_get(aobj, "name")); 509
510 const char *name = xs_dict_get(aobj, "name");
511 if (xs_is_null(name))
512 name = "";
513
514 matte = xs_dict_append(matte, "description", name);
510 515
511 matt = xs_list_append(matt, matte); 516 matt = xs_list_append(matt, matte);
512 } 517 }
@@ -730,6 +735,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
730 *ctype = "application/json"; 735 *ctype = "application/json";
731 status = 200; 736 status = 200;
732 737
738 {
739 xs *j = xs_json_loads(*body);
740 if (j == NULL) {
741 srv_debug(0, xs_fmt("mastoapi timeline: bad JSON"));
742 srv_archive_error("mastoapi_timeline", "bad JSON", req, *body);
743 }
744 }
745
733 srv_debug(0, xs_fmt("mastoapi timeline: returned %d entries", xs_list_len(out))); 746 srv_debug(0, xs_fmt("mastoapi timeline: returned %d entries", xs_list_len(out)));
734 } 747 }
735 else { 748 else {
diff --git a/snac.h b/snac.h
index 0784b26..5388850 100644
--- a/snac.h
+++ b/snac.h
@@ -56,7 +56,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req,
56 int status, xs_dict *headers, 56 int status, xs_dict *headers,
57 const char *body, int b_size); 57 const char *body, int b_size);
58void srv_archive_error(const char *prefix, const xs_str *err, 58void srv_archive_error(const char *prefix, const xs_str *err,
59 const xs_dict *req, const xs_dict *data); 59 const xs_dict *req, const xs_val *data);
60 60
61double mtime_nl(const char *fn, int *n_link); 61double mtime_nl(const char *fn, int *n_link);
62#define mtime(fn) mtime_nl(fn, NULL) 62#define mtime(fn) mtime_nl(fn, NULL)