diff options
| author | 2023-06-15 17:51:24 +0200 | |
|---|---|---|
| committer | 2023-06-15 17:51:24 +0200 | |
| commit | 478cb2cf15324289884847412b61b193f51fb532 (patch) | |
| tree | b2b38e64b6baa581f775be01d4f9e2ec184a8e92 | |
| parent | Backport from xs. (diff) | |
| download | snac2-478cb2cf15324289884847412b61b193f51fb532.tar.gz snac2-478cb2cf15324289884847412b61b193f51fb532.tar.xz snac2-478cb2cf15324289884847412b61b193f51fb532.zip | |
Use xs_stock_* values wherever possible.
| -rw-r--r-- | html.c | 14 | ||||
| -rw-r--r-- | mastoapi.c | 76 |
2 files changed, 38 insertions, 52 deletions
| @@ -1851,9 +1851,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 1851 | msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv); | 1851 | msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv); |
| 1852 | 1852 | ||
| 1853 | if (sensitive != NULL) { | 1853 | if (sensitive != NULL) { |
| 1854 | xs *t = xs_val_new(XSTYPE_TRUE); | 1854 | msg = xs_dict_set(msg, "sensitive", xs_stock_true); |
| 1855 | |||
| 1856 | msg = xs_dict_set(msg, "sensitive", t); | ||
| 1857 | msg = xs_dict_set(msg, "summary", "..."); | 1855 | msg = xs_dict_set(msg, "summary", "..."); |
| 1858 | } | 1856 | } |
| 1859 | 1857 | ||
| @@ -2010,8 +2008,6 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 2010 | /* change of user data */ | 2008 | /* change of user data */ |
| 2011 | char *v; | 2009 | char *v; |
| 2012 | char *p1, *p2; | 2010 | char *p1, *p2; |
| 2013 | xs *byes = xs_val_new(XSTYPE_TRUE); | ||
| 2014 | xs *bno = xs_val_new(XSTYPE_FALSE); | ||
| 2015 | 2011 | ||
| 2016 | if ((v = xs_dict_get(p_vars, "name")) != NULL) | 2012 | if ((v = xs_dict_get(p_vars, "name")) != NULL) |
| 2017 | snac.config = xs_dict_set(snac.config, "name", v); | 2013 | snac.config = xs_dict_set(snac.config, "name", v); |
| @@ -2036,13 +2032,13 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 2036 | snac.config = xs_dict_set(snac.config, "purge_days", days); | 2032 | snac.config = xs_dict_set(snac.config, "purge_days", days); |
| 2037 | } | 2033 | } |
| 2038 | if ((v = xs_dict_get(p_vars, "drop_dm_from_unknown")) != NULL && strcmp(v, "on") == 0) | 2034 | if ((v = xs_dict_get(p_vars, "drop_dm_from_unknown")) != NULL && strcmp(v, "on") == 0) |
| 2039 | snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", byes); | 2035 | snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", xs_stock_true); |
| 2040 | else | 2036 | else |
| 2041 | snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", bno); | 2037 | snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", xs_stock_false); |
| 2042 | if ((v = xs_dict_get(p_vars, "bot")) != NULL && strcmp(v, "on") == 0) | 2038 | if ((v = xs_dict_get(p_vars, "bot")) != NULL && strcmp(v, "on") == 0) |
| 2043 | snac.config = xs_dict_set(snac.config, "bot", byes); | 2039 | snac.config = xs_dict_set(snac.config, "bot", xs_stock_true); |
| 2044 | else | 2040 | else |
| 2045 | snac.config = xs_dict_set(snac.config, "bot", bno); | 2041 | snac.config = xs_dict_set(snac.config, "bot", xs_stock_false); |
| 2046 | 2042 | ||
| 2047 | /* avatar upload */ | 2043 | /* avatar upload */ |
| 2048 | xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file"); | 2044 | xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file"); |
| @@ -523,9 +523,9 @@ xs_dict *mastoapi_account(const xs_dict *actor) | |||
| 523 | note = ""; | 523 | note = ""; |
| 524 | 524 | ||
| 525 | if (strcmp(xs_dict_get(actor, "type"), "Service") == 0) | 525 | if (strcmp(xs_dict_get(actor, "type"), "Service") == 0) |
| 526 | acct = xs_dict_append(acct, "bot", "true"); | 526 | acct = xs_dict_append(acct, "bot", xs_stock_true); |
| 527 | else | 527 | else |
| 528 | acct = xs_dict_append(acct, "bot", "false"); | 528 | acct = xs_dict_append(acct, "bot", xs_stock_false); |
| 529 | 529 | ||
| 530 | acct = xs_dict_append(acct, "note", note); | 530 | acct = xs_dict_append(acct, "note", note); |
| 531 | 531 | ||
| @@ -559,7 +559,6 @@ xs_dict *mastoapi_account(const xs_dict *actor) | |||
| 559 | if (!xs_is_null(p = xs_dict_get(actor, "tag"))) { | 559 | if (!xs_is_null(p = xs_dict_get(actor, "tag"))) { |
| 560 | xs *eml = xs_list_new(); | 560 | xs *eml = xs_list_new(); |
| 561 | xs_dict *v; | 561 | xs_dict *v; |
| 562 | xs *t = xs_val_new(XSTYPE_TRUE); | ||
| 563 | 562 | ||
| 564 | while (xs_list_iter(&p, &v)) { | 563 | while (xs_list_iter(&p, &v)) { |
| 565 | const char *type = xs_dict_get(v, "type"); | 564 | const char *type = xs_dict_get(v, "type"); |
| @@ -578,7 +577,7 @@ xs_dict *mastoapi_account(const xs_dict *actor) | |||
| 578 | d1 = xs_dict_append(d1, "shortcode", nm); | 577 | d1 = xs_dict_append(d1, "shortcode", nm); |
| 579 | d1 = xs_dict_append(d1, "url", url); | 578 | d1 = xs_dict_append(d1, "url", url); |
| 580 | d1 = xs_dict_append(d1, "static_url", url); | 579 | d1 = xs_dict_append(d1, "static_url", url); |
| 581 | d1 = xs_dict_append(d1, "visible_in_picker", t); | 580 | d1 = xs_dict_append(d1, "visible_in_picker", xs_stock_true); |
| 582 | 581 | ||
| 583 | eml = xs_list_append(eml, d1); | 582 | eml = xs_list_append(eml, d1); |
| 584 | } | 583 | } |
| @@ -598,8 +597,6 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) | |||
| 598 | { | 597 | { |
| 599 | xs_dict *poll = xs_dict_new(); | 598 | xs_dict *poll = xs_dict_new(); |
| 600 | xs *mid = mastoapi_id(msg); | 599 | xs *mid = mastoapi_id(msg); |
| 601 | xs *f = xs_val_new(XSTYPE_FALSE); | ||
| 602 | xs *t = xs_val_new(XSTYPE_TRUE); | ||
| 603 | xs_list *opts = NULL; | 600 | xs_list *opts = NULL; |
| 604 | xs_val *v; | 601 | xs_val *v; |
| 605 | int num_votes = 0; | 602 | int num_votes = 0; |
| @@ -607,13 +604,14 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) | |||
| 607 | 604 | ||
| 608 | poll = xs_dict_append(poll, "id", mid); | 605 | poll = xs_dict_append(poll, "id", mid); |
| 609 | poll = xs_dict_append(poll, "expires_at", xs_dict_get(msg, "endTime")); | 606 | poll = xs_dict_append(poll, "expires_at", xs_dict_get(msg, "endTime")); |
| 610 | poll = xs_dict_append(poll, "expired", xs_dict_get(msg, "closed") != NULL ? t : f); | 607 | poll = xs_dict_append(poll, "expired", |
| 608 | xs_dict_get(msg, "closed") != NULL ? xs_stock_true : xs_stock_false); | ||
| 611 | 609 | ||
| 612 | if ((opts = xs_dict_get(msg, "oneOf")) != NULL) | 610 | if ((opts = xs_dict_get(msg, "oneOf")) != NULL) |
| 613 | poll = xs_dict_append(poll, "multiple", f); | 611 | poll = xs_dict_append(poll, "multiple", xs_stock_false); |
| 614 | else { | 612 | else { |
| 615 | opts = xs_dict_get(msg, "anyOf"); | 613 | opts = xs_dict_get(msg, "anyOf"); |
| 616 | poll = xs_dict_append(poll, "multiple", t); | 614 | poll = xs_dict_append(poll, "multiple", xs_stock_true); |
| 617 | } | 615 | } |
| 618 | 616 | ||
| 619 | while (xs_list_iter(&opts, &v)) { | 617 | while (xs_list_iter(&opts, &v)) { |
| @@ -639,7 +637,7 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) | |||
| 639 | poll = xs_dict_append(poll, "votes_count", vc); | 637 | poll = xs_dict_append(poll, "votes_count", vc); |
| 640 | 638 | ||
| 641 | poll = xs_dict_append(poll, "voted", | 639 | poll = xs_dict_append(poll, "voted", |
| 642 | was_question_voted(snac, xs_dict_get(msg, "id")) ? t : f); | 640 | was_question_voted(snac, xs_dict_get(msg, "id")) ? xs_stock_true : xs_stock_false); |
| 643 | 641 | ||
| 644 | return poll; | 642 | return poll; |
| 645 | } | 643 | } |
| @@ -660,9 +658,6 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 660 | 658 | ||
| 661 | xs *acct = mastoapi_account(actor); | 659 | xs *acct = mastoapi_account(actor); |
| 662 | 660 | ||
| 663 | xs *f = xs_val_new(XSTYPE_FALSE); | ||
| 664 | xs *t = xs_val_new(XSTYPE_TRUE); | ||
| 665 | xs *n = xs_val_new(XSTYPE_NULL); | ||
| 666 | xs *idx = NULL; | 661 | xs *idx = NULL; |
| 667 | xs *ixc = NULL; | 662 | xs *ixc = NULL; |
| 668 | char *tmp; | 663 | char *tmp; |
| @@ -682,7 +677,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 682 | 677 | ||
| 683 | tmp = xs_dict_get(msg, "sensitive"); | 678 | tmp = xs_dict_get(msg, "sensitive"); |
| 684 | if (xs_is_null(tmp)) | 679 | if (xs_is_null(tmp)) |
| 685 | tmp = f; | 680 | tmp = xs_stock_false; |
| 686 | 681 | ||
| 687 | st = xs_dict_append(st, "sensitive", tmp); | 682 | st = xs_dict_append(st, "sensitive", tmp); |
| 688 | 683 | ||
| @@ -781,12 +776,11 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 781 | 776 | ||
| 782 | if (!xs_is_null(url)) { | 777 | if (!xs_is_null(url)) { |
| 783 | xs *nm = xs_strip_chars_i(xs_dup(name), ":"); | 778 | xs *nm = xs_strip_chars_i(xs_dup(name), ":"); |
| 784 | xs *t = xs_val_new(XSTYPE_TRUE); | ||
| 785 | 779 | ||
| 786 | d1 = xs_dict_append(d1, "shortcode", nm); | 780 | d1 = xs_dict_append(d1, "shortcode", nm); |
| 787 | d1 = xs_dict_append(d1, "url", url); | 781 | d1 = xs_dict_append(d1, "url", url); |
| 788 | d1 = xs_dict_append(d1, "static_url", url); | 782 | d1 = xs_dict_append(d1, "static_url", url); |
| 789 | d1 = xs_dict_append(d1, "visible_in_picker", t); | 783 | d1 = xs_dict_append(d1, "visible_in_picker", xs_stock_true); |
| 790 | d1 = xs_dict_append(d1, "category", "Emojis"); | 784 | d1 = xs_dict_append(d1, "category", "Emojis"); |
| 791 | 785 | ||
| 792 | eml = xs_list_append(eml, d1); | 786 | eml = xs_list_append(eml, d1); |
| @@ -807,7 +801,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 807 | 801 | ||
| 808 | st = xs_dict_append(st, "favourites_count", ixc); | 802 | st = xs_dict_append(st, "favourites_count", ixc); |
| 809 | st = xs_dict_append(st, "favourited", | 803 | st = xs_dict_append(st, "favourited", |
| 810 | xs_list_in(idx, snac->md5) != -1 ? t : f); | 804 | xs_list_in(idx, snac->md5) != -1 ? xs_stock_true : xs_stock_false); |
| 811 | 805 | ||
| 812 | xs_free(idx); | 806 | xs_free(idx); |
| 813 | xs_free(ixc); | 807 | xs_free(ixc); |
| @@ -816,7 +810,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 816 | 810 | ||
| 817 | st = xs_dict_append(st, "reblogs_count", ixc); | 811 | st = xs_dict_append(st, "reblogs_count", ixc); |
| 818 | st = xs_dict_append(st, "reblogged", | 812 | st = xs_dict_append(st, "reblogged", |
| 819 | xs_list_in(idx, snac->md5) != -1 ? t : f); | 813 | xs_list_in(idx, snac->md5) != -1 ? xs_stock_true : xs_stock_false); |
| 820 | 814 | ||
| 821 | xs_free(idx); | 815 | xs_free(idx); |
| 822 | xs_free(ixc); | 816 | xs_free(ixc); |
| @@ -826,8 +820,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 826 | st = xs_dict_append(st, "replies_count", ixc); | 820 | st = xs_dict_append(st, "replies_count", ixc); |
| 827 | 821 | ||
| 828 | /* default in_reply_to values */ | 822 | /* default in_reply_to values */ |
| 829 | st = xs_dict_append(st, "in_reply_to_id", n); | 823 | st = xs_dict_append(st, "in_reply_to_id", xs_stock_null); |
| 830 | st = xs_dict_append(st, "in_reply_to_account_id", n); | 824 | st = xs_dict_append(st, "in_reply_to_account_id", xs_stock_null); |
| 831 | 825 | ||
| 832 | tmp = xs_dict_get(msg, "inReplyTo"); | 826 | tmp = xs_dict_get(msg, "inReplyTo"); |
| 833 | if (!xs_is_null(tmp)) { | 827 | if (!xs_is_null(tmp)) { |
| @@ -845,10 +839,10 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 845 | } | 839 | } |
| 846 | } | 840 | } |
| 847 | 841 | ||
| 848 | st = xs_dict_append(st, "reblog", n); | 842 | st = xs_dict_append(st, "reblog", xs_stock_null); |
| 849 | st = xs_dict_append(st, "poll", n); | 843 | st = xs_dict_append(st, "poll", xs_stock_null); |
| 850 | st = xs_dict_append(st, "card", n); | 844 | st = xs_dict_append(st, "card", xs_stock_null); |
| 851 | st = xs_dict_append(st, "language", n); | 845 | st = xs_dict_append(st, "language", xs_stock_null); |
| 852 | 846 | ||
| 853 | tmp = xs_dict_get(msg, "sourceContent"); | 847 | tmp = xs_dict_get(msg, "sourceContent"); |
| 854 | if (xs_is_null(tmp)) | 848 | if (xs_is_null(tmp)) |
| @@ -858,7 +852,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 858 | 852 | ||
| 859 | tmp = xs_dict_get(msg, "updated"); | 853 | tmp = xs_dict_get(msg, "updated"); |
| 860 | if (xs_is_null(tmp)) | 854 | if (xs_is_null(tmp)) |
| 861 | tmp = n; | 855 | tmp = xs_stock_null; |
| 862 | 856 | ||
| 863 | st = xs_dict_append(st, "edited_at", tmp); | 857 | st = xs_dict_append(st, "edited_at", tmp); |
| 864 | 858 | ||
| @@ -877,29 +871,27 @@ xs_dict *mastoapi_relationship(snac *snac, const char *md5) | |||
| 877 | xs *actor_o = NULL; | 871 | xs *actor_o = NULL; |
| 878 | 872 | ||
| 879 | if (valid_status(object_get_by_md5(md5, &actor_o))) { | 873 | if (valid_status(object_get_by_md5(md5, &actor_o))) { |
| 880 | xs *t = xs_val_new(XSTYPE_TRUE); | ||
| 881 | xs *f = xs_val_new(XSTYPE_FALSE); | ||
| 882 | rel = xs_dict_new(); | 874 | rel = xs_dict_new(); |
| 883 | 875 | ||
| 884 | const char *actor = xs_dict_get(actor_o, "id"); | 876 | const char *actor = xs_dict_get(actor_o, "id"); |
| 885 | 877 | ||
| 886 | rel = xs_dict_append(rel, "id", md5); | 878 | rel = xs_dict_append(rel, "id", md5); |
| 887 | rel = xs_dict_append(rel, "following", | 879 | rel = xs_dict_append(rel, "following", |
| 888 | following_check(snac, actor) ? t : f); | 880 | following_check(snac, actor) ? xs_stock_true : xs_stock_false); |
| 889 | 881 | ||
| 890 | rel = xs_dict_append(rel, "showing_reblogs", t); | 882 | rel = xs_dict_append(rel, "showing_reblogs", xs_stock_true); |
| 891 | rel = xs_dict_append(rel, "notifying", f); | 883 | rel = xs_dict_append(rel, "notifying", xs_stock_false); |
| 892 | rel = xs_dict_append(rel, "followed_by", | 884 | rel = xs_dict_append(rel, "followed_by", |
| 893 | follower_check(snac, actor) ? t : f); | 885 | follower_check(snac, actor) ? xs_stock_true : xs_stock_false); |
| 894 | 886 | ||
| 895 | rel = xs_dict_append(rel, "blocking", | 887 | rel = xs_dict_append(rel, "blocking", |
| 896 | is_muted(snac, actor) ? t : f); | 888 | is_muted(snac, actor) ? xs_stock_true : xs_stock_false); |
| 897 | 889 | ||
| 898 | rel = xs_dict_append(rel, "muting", f); | 890 | rel = xs_dict_append(rel, "muting", xs_stock_false); |
| 899 | rel = xs_dict_append(rel, "muting_notifications", f); | 891 | rel = xs_dict_append(rel, "muting_notifications", xs_stock_false); |
| 900 | rel = xs_dict_append(rel, "requested", f); | 892 | rel = xs_dict_append(rel, "requested", xs_stock_false); |
| 901 | rel = xs_dict_append(rel, "domain_blocking", f); | 893 | rel = xs_dict_append(rel, "domain_blocking", xs_stock_false); |
| 902 | rel = xs_dict_append(rel, "endorsed", f); | 894 | rel = xs_dict_append(rel, "endorsed", xs_stock_false); |
| 903 | rel = xs_dict_append(rel, "note", ""); | 895 | rel = xs_dict_append(rel, "note", ""); |
| 904 | } | 896 | } |
| 905 | 897 | ||
| @@ -1482,10 +1474,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1482 | d1 = xs_dict_append(d1, "domain_count", z); | 1474 | d1 = xs_dict_append(d1, "domain_count", z); |
| 1483 | ins = xs_dict_append(ins, "stats", d1); | 1475 | ins = xs_dict_append(ins, "stats", d1); |
| 1484 | 1476 | ||
| 1485 | xs *f = xs_val_new(XSTYPE_FALSE); | 1477 | ins = xs_dict_append(ins, "registrations", xs_stock_false); |
| 1486 | ins = xs_dict_append(ins, "registrations", f); | 1478 | ins = xs_dict_append(ins, "approval_required", xs_stock_false); |
| 1487 | ins = xs_dict_append(ins, "approval_required", f); | 1479 | ins = xs_dict_append(ins, "invites_enabled", xs_stock_false); |
| 1488 | ins = xs_dict_append(ins, "invites_enabled", f); | ||
| 1489 | 1480 | ||
| 1490 | xs *cfg = xs_dict_new(); | 1481 | xs *cfg = xs_dict_new(); |
| 1491 | 1482 | ||
| @@ -1846,8 +1837,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 1846 | strcmp(visibility, "public") == 0 ? 0 : 1); | 1837 | strcmp(visibility, "public") == 0 ? 0 : 1); |
| 1847 | 1838 | ||
| 1848 | if (!xs_is_null(summary) && *summary) { | 1839 | if (!xs_is_null(summary) && *summary) { |
| 1849 | xs *t = xs_val_new(XSTYPE_TRUE); | 1840 | msg = xs_dict_set(msg, "sensitive", xs_stock_true); |
| 1850 | msg = xs_dict_set(msg, "sensitive", t); | ||
| 1851 | msg = xs_dict_set(msg, "summary", summary); | 1841 | msg = xs_dict_set(msg, "summary", summary); |
| 1852 | } | 1842 | } |
| 1853 | 1843 | ||