diff options
| author | 2024-02-20 06:10:42 +0100 | |
|---|---|---|
| committer | 2024-02-20 06:10:42 +0100 | |
| commit | a3b9ef5b98530a81f648b397fed91d78349dc4cd (patch) | |
| tree | 1c5cee9bdbe8127e3079eba761f4d084fa9322b5 | |
| parent | Enqueue a verify_links q_item in admin/user-setup. (diff) | |
| download | penes-snac2-a3b9ef5b98530a81f648b397fed91d78349dc4cd.tar.gz penes-snac2-a3b9ef5b98530a81f648b397fed91d78349dc4cd.tar.xz penes-snac2-a3b9ef5b98530a81f648b397fed91d78349dc4cd.zip | |
The link verification time is stored as a time_t.
This way, it will be easier in an eventual future to test if
a link verification is too old to be trusted.
Diffstat (limited to '')
| -rw-r--r-- | html.c | 16 | ||||
| -rw-r--r-- | mastoapi.c | 24 | ||||
| -rw-r--r-- | utils.c | 4 |
3 files changed, 33 insertions, 11 deletions
| @@ -779,11 +779,21 @@ static xs_html *html_user_body(snac *user, int local) | |||
| 779 | 779 | ||
| 780 | if (xs_startswith(v, "https:/" "/")) { | 780 | if (xs_startswith(v, "https:/" "/")) { |
| 781 | /* is this link validated? */ | 781 | /* is this link validated? */ |
| 782 | char *val_date = xs_dict_get(val_links, v); | 782 | xs *verified_link = NULL; |
| 783 | xs_number *val_time = xs_dict_get(val_links, v); | ||
| 783 | 784 | ||
| 784 | if (!xs_is_null(val_date) && *val_date) { | 785 | if (xs_type(val_time) == XSTYPE_NUMBER) { |
| 786 | time_t t = xs_number_get(val_time); | ||
| 787 | |||
| 788 | if (t > 0) { | ||
| 789 | xs *s1 = xs_str_utctime(t, ISO_DATE_SPEC); | ||
| 790 | verified_link = xs_fmt("%s (%s)", L("verified link"), s1); | ||
| 791 | } | ||
| 792 | } | ||
| 793 | |||
| 794 | if (!xs_is_null(verified_link)) { | ||
| 785 | value = xs_html_tag("span", | 795 | value = xs_html_tag("span", |
| 786 | xs_html_attr("title", L("verified link")), | 796 | xs_html_attr("title", verified_link), |
| 787 | xs_html_raw("✔ "), | 797 | xs_html_raw("✔ "), |
| 788 | xs_html_tag("a", | 798 | xs_html_tag("a", |
| 789 | xs_html_attr("href", v), | 799 | xs_html_attr("href", v), |
| @@ -642,10 +642,17 @@ xs_dict *mastoapi_account(const xs_dict *actor) | |||
| 642 | 642 | ||
| 643 | if (!xs_is_null(type) && !xs_is_null(name) && | 643 | if (!xs_is_null(type) && !xs_is_null(name) && |
| 644 | !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) { | 644 | !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) { |
| 645 | char *val_date = NULL; | 645 | xs *val_date = NULL; |
| 646 | 646 | ||
| 647 | if (xs_startswith(value, "https:/" "/")) | 647 | if (xs_startswith(value, "https:/" "/")) { |
| 648 | val_date = xs_dict_get(val_links, value); | 648 | xs_number *verified_time = xs_dict_get(val_links, value); |
| 649 | if (xs_type(verified_time) == XSTYPE_NUMBER) { | ||
| 650 | time_t t = xs_number_get(verified_time); | ||
| 651 | |||
| 652 | if (t > 0) | ||
| 653 | val_date = xs_str_utctime(t, ISO_DATE_SPEC); | ||
| 654 | } | ||
| 655 | } | ||
| 649 | 656 | ||
| 650 | xs *d = xs_dict_new(); | 657 | xs *d = xs_dict_new(); |
| 651 | 658 | ||
| @@ -1161,10 +1168,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1161 | val_links = xs_stock_dict; | 1168 | val_links = xs_stock_dict; |
| 1162 | 1169 | ||
| 1163 | while (xs_dict_iter(&metadata, &k, &v)) { | 1170 | while (xs_dict_iter(&metadata, &k, &v)) { |
| 1164 | char *val_date = NULL; | 1171 | xs *val_date = NULL; |
| 1165 | 1172 | ||
| 1166 | if (xs_startswith(v, "https:/" "/")) | 1173 | xs_number *verified_time = xs_dict_get(val_links, v); |
| 1167 | val_date = xs_dict_get(val_links, v); | 1174 | if (xs_type(verified_time) == XSTYPE_NUMBER) { |
| 1175 | time_t t = xs_number_get(verified_time); | ||
| 1176 | |||
| 1177 | if (t > 0) | ||
| 1178 | val_date = xs_str_utctime(t, ISO_DATE_SPEC); | ||
| 1179 | } | ||
| 1168 | 1180 | ||
| 1169 | xs *d = xs_dict_new(); | 1181 | xs *d = xs_dict_new(); |
| 1170 | 1182 | ||
| @@ -491,12 +491,12 @@ void verify_links(snac *user) | |||
| 491 | /* is it the same as the actor? */ | 491 | /* is it the same as the actor? */ |
| 492 | if (strcmp(href, user->actor) == 0) { | 492 | if (strcmp(href, user->actor) == 0) { |
| 493 | /* got it! */ | 493 | /* got it! */ |
| 494 | xs *verified_at = xs_str_utctime(0, ISO_DATE_SPEC); | 494 | xs *verified_time = xs_number_new((double)time(NULL)); |
| 495 | 495 | ||
| 496 | if (user->links == NULL) | 496 | if (user->links == NULL) |
| 497 | user->links = xs_dict_new(); | 497 | user->links = xs_dict_new(); |
| 498 | 498 | ||
| 499 | user->links = xs_dict_set(user->links, v, verified_at); | 499 | user->links = xs_dict_set(user->links, v, verified_time); |
| 500 | 500 | ||
| 501 | vfied = 1; | 501 | vfied = 1; |
| 502 | } | 502 | } |