diff options
| author | 2024-02-16 05:47:18 +0100 | |
|---|---|---|
| committer | 2024-02-16 05:47:18 +0100 | |
| commit | 2da394aef4c8945d327f53376cf6f645c4bfe590 (patch) | |
| tree | 92b8c77c5daf2f69ab95c51c088c1e850cc05bd6 /utils.c | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-2da394aef4c8945d327f53376cf6f645c4bfe590.tar.gz snac2-2da394aef4c8945d327f53376cf6f645c4bfe590.tar.xz snac2-2da394aef4c8945d327f53376cf6f645c4bfe590.zip | |
Added 'accept' and 'user-agent' headers to verify_links().
Diffstat (limited to 'utils.c')
| -rw-r--r-- | utils.c | 21 |
1 files changed, 17 insertions, 4 deletions
| @@ -418,6 +418,10 @@ void verify_links(snac *user) | |||
| 418 | char *k, *v; | 418 | char *k, *v; |
| 419 | int changed = 0; | 419 | int changed = 0; |
| 420 | 420 | ||
| 421 | xs *headers = xs_dict_new(); | ||
| 422 | headers = xs_dict_append(headers, "accept", "text/html"); | ||
| 423 | headers = xs_dict_append(headers, "user-agent", USER_AGENT " (link verify)"); | ||
| 424 | |||
| 421 | while (p && xs_dict_iter(&p, &k, &v)) { | 425 | while (p && xs_dict_iter(&p, &k, &v)) { |
| 422 | /* not an https link? skip */ | 426 | /* not an https link? skip */ |
| 423 | if (!xs_startswith(v, "https:/" "/")) | 427 | if (!xs_startswith(v, "https:/" "/")) |
| @@ -428,11 +432,11 @@ void verify_links(snac *user) | |||
| 428 | xs *payload = NULL; | 432 | xs *payload = NULL; |
| 429 | int p_size = 0; | 433 | int p_size = 0; |
| 430 | 434 | ||
| 431 | req = xs_http_request("GET", v, NULL, NULL, 0, &status, | 435 | req = xs_http_request("GET", v, headers, NULL, 0, &status, |
| 432 | &payload, &p_size, 0); | 436 | &payload, &p_size, 0); |
| 433 | 437 | ||
| 434 | if (!valid_status(status)) { | 438 | if (!valid_status(status)) { |
| 435 | snac_log(user, xs_fmt("verify link %s error %d", v, status)); | 439 | snac_log(user, xs_fmt("link %s verify error %d", v, status)); |
| 436 | continue; | 440 | continue; |
| 437 | } | 441 | } |
| 438 | 442 | ||
| @@ -441,6 +445,7 @@ void verify_links(snac *user) | |||
| 441 | 445 | ||
| 442 | xs_list *lp = ls; | 446 | xs_list *lp = ls; |
| 443 | char *ll; | 447 | char *ll; |
| 448 | int vfied = 0; | ||
| 444 | 449 | ||
| 445 | while (xs_list_iter(&lp, &ll)) { | 450 | while (xs_list_iter(&lp, &ll)) { |
| 446 | /* extract href and rel */ | 451 | /* extract href and rel */ |
| @@ -490,15 +495,23 @@ void verify_links(snac *user) | |||
| 490 | 495 | ||
| 491 | user->links = xs_dict_set(user->links, v, verified_at); | 496 | user->links = xs_dict_set(user->links, v, verified_at); |
| 492 | 497 | ||
| 493 | changed++; | 498 | vfied = 1; |
| 494 | 499 | ||
| 495 | snac_log(user, xs_fmt("link %s verified at %s", v, verified_at)); | 500 | break; |
| 496 | } | 501 | } |
| 497 | else | 502 | else |
| 498 | snac_debug(user, 1, | 503 | snac_debug(user, 1, |
| 499 | xs_fmt("verify link %s rel='me' found but not related (%s)", v, href)); | 504 | xs_fmt("verify link %s rel='me' found but not related (%s)", v, href)); |
| 500 | } | 505 | } |
| 501 | } | 506 | } |
| 507 | |||
| 508 | if (vfied) { | ||
| 509 | changed++; | ||
| 510 | snac_log(user, xs_fmt("link %s verified", v)); | ||
| 511 | } | ||
| 512 | else { | ||
| 513 | snac_log(user, xs_fmt("link %s not verified (rel='me' not found)", v)); | ||
| 514 | } | ||
| 502 | } | 515 | } |
| 503 | 516 | ||
| 504 | if (changed) { | 517 | if (changed) { |