diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 60 |
1 files changed, 30 insertions, 30 deletions
| @@ -663,12 +663,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 663 | 663 | ||
| 664 | int status = 404; | 664 | int status = 404; |
| 665 | xs_dict *args = xs_dict_get(req, "q_vars"); | 665 | xs_dict *args = xs_dict_get(req, "q_vars"); |
| 666 | xs *cmd = xs_replace(q_path, "/api/v1", ""); | 666 | xs *cmd = xs_replace(q_path, "/api", ""); |
| 667 | 667 | ||
| 668 | snac snac1 = {0}; | 668 | snac snac1 = {0}; |
| 669 | int logged_in = process_auth_token(&snac1, req); | 669 | int logged_in = process_auth_token(&snac1, req); |
| 670 | 670 | ||
| 671 | if (strcmp(cmd, "/accounts/verify_credentials") == 0) { | 671 | if (strcmp(cmd, "/v1/accounts/verify_credentials") == 0) { |
| 672 | if (logged_in) { | 672 | if (logged_in) { |
| 673 | xs *acct = xs_dict_new(); | 673 | xs *acct = xs_dict_new(); |
| 674 | 674 | ||
| @@ -700,7 +700,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 700 | } | 700 | } |
| 701 | } | 701 | } |
| 702 | else | 702 | else |
| 703 | if (strcmp(cmd, "/accounts/relationships") == 0) { | 703 | if (strcmp(cmd, "/v1/accounts/relationships") == 0) { |
| 704 | /* find if an account is followed, blocked, etc. */ | 704 | /* find if an account is followed, blocked, etc. */ |
| 705 | /* the account to get relationships about is in args "id[]" */ | 705 | /* the account to get relationships about is in args "id[]" */ |
| 706 | /* dummy by now */ | 706 | /* dummy by now */ |
| @@ -711,11 +711,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 711 | } | 711 | } |
| 712 | } | 712 | } |
| 713 | else | 713 | else |
| 714 | if (xs_startswith(cmd, "/accounts/")) { | 714 | if (xs_startswith(cmd, "/v1/accounts/")) { |
| 715 | /* account-related information */ | 715 | /* account-related information */ |
| 716 | xs *l = xs_split(cmd, "/"); | 716 | xs *l = xs_split(cmd, "/"); |
| 717 | const char *uid = xs_list_get(l, 2); | 717 | const char *uid = xs_list_get(l, 3); |
| 718 | const char *opt = xs_list_get(l, 3); | 718 | const char *opt = xs_list_get(l, 4); |
| 719 | 719 | ||
| 720 | if (uid != NULL) { | 720 | if (uid != NULL) { |
| 721 | snac snac2; | 721 | snac snac2; |
| @@ -778,7 +778,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 778 | } | 778 | } |
| 779 | } | 779 | } |
| 780 | else | 780 | else |
| 781 | if (strcmp(cmd, "/timelines/home") == 0) { | 781 | if (strcmp(cmd, "/v1/timelines/home") == 0) { |
| 782 | /* the private timeline */ | 782 | /* the private timeline */ |
| 783 | if (logged_in) { | 783 | if (logged_in) { |
| 784 | const char *max_id = xs_dict_get(args, "max_id"); | 784 | const char *max_id = xs_dict_get(args, "max_id"); |
| @@ -860,7 +860,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 860 | } | 860 | } |
| 861 | } | 861 | } |
| 862 | else | 862 | else |
| 863 | if (strcmp(cmd, "/timelines/public") == 0) { | 863 | if (strcmp(cmd, "/v1/timelines/public") == 0) { |
| 864 | /* the public timeline (public timelines for all users) */ | 864 | /* the public timeline (public timelines for all users) */ |
| 865 | /* TBD */ | 865 | /* TBD */ |
| 866 | *body = xs_dup("[]"); | 866 | *body = xs_dup("[]"); |
| @@ -868,14 +868,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 868 | status = 200; | 868 | status = 200; |
| 869 | } | 869 | } |
| 870 | else | 870 | else |
| 871 | if (strcmp(cmd, "/conversations") == 0) { | 871 | if (strcmp(cmd, "/v1/conversations") == 0) { |
| 872 | /* TBD */ | 872 | /* TBD */ |
| 873 | *body = xs_dup("[]"); | 873 | *body = xs_dup("[]"); |
| 874 | *ctype = "application/json"; | 874 | *ctype = "application/json"; |
| 875 | status = 200; | 875 | status = 200; |
| 876 | } | 876 | } |
| 877 | else | 877 | else |
| 878 | if (strcmp(cmd, "/notifications") == 0) { | 878 | if (strcmp(cmd, "/v1/notifications") == 0) { |
| 879 | if (logged_in) { | 879 | if (logged_in) { |
| 880 | xs *l = notify_list(&snac1, 0); | 880 | xs *l = notify_list(&snac1, 0); |
| 881 | xs *out = xs_list_new(); | 881 | xs *out = xs_list_new(); |
| @@ -945,63 +945,63 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 945 | status = 401; | 945 | status = 401; |
| 946 | } | 946 | } |
| 947 | else | 947 | else |
| 948 | if (strcmp(cmd, "/filters") == 0) { | 948 | if (strcmp(cmd, "/v1/filters") == 0) { |
| 949 | /* snac will never have filters */ | 949 | /* snac will never have filters */ |
| 950 | *body = xs_dup("[]"); | 950 | *body = xs_dup("[]"); |
| 951 | *ctype = "application/json"; | 951 | *ctype = "application/json"; |
| 952 | status = 200; | 952 | status = 200; |
| 953 | } | 953 | } |
| 954 | else | 954 | else |
| 955 | if (strcmp(cmd, "/favourites") == 0) { | 955 | if (strcmp(cmd, "/v1/favourites") == 0) { |
| 956 | /* snac will never support a list of favourites */ | 956 | /* snac will never support a list of favourites */ |
| 957 | *body = xs_dup("[]"); | 957 | *body = xs_dup("[]"); |
| 958 | *ctype = "application/json"; | 958 | *ctype = "application/json"; |
| 959 | status = 200; | 959 | status = 200; |
| 960 | } | 960 | } |
| 961 | else | 961 | else |
| 962 | if (strcmp(cmd, "/bookmarks") == 0) { | 962 | if (strcmp(cmd, "/v1/bookmarks") == 0) { |
| 963 | /* snac does not support bookmarks */ | 963 | /* snac does not support bookmarks */ |
| 964 | *body = xs_dup("[]"); | 964 | *body = xs_dup("[]"); |
| 965 | *ctype = "application/json"; | 965 | *ctype = "application/json"; |
| 966 | status = 200; | 966 | status = 200; |
| 967 | } | 967 | } |
| 968 | else | 968 | else |
| 969 | if (strcmp(cmd, "/lists") == 0) { | 969 | if (strcmp(cmd, "/v1/lists") == 0) { |
| 970 | /* snac does not support lists */ | 970 | /* snac does not support lists */ |
| 971 | *body = xs_dup("[]"); | 971 | *body = xs_dup("[]"); |
| 972 | *ctype = "application/json"; | 972 | *ctype = "application/json"; |
| 973 | status = 200; | 973 | status = 200; |
| 974 | } | 974 | } |
| 975 | else | 975 | else |
| 976 | if (strcmp(cmd, "/scheduled_statuses") == 0) { | 976 | if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { |
| 977 | /* snac does not scheduled notes */ | 977 | /* snac does not scheduled notes */ |
| 978 | *body = xs_dup("[]"); | 978 | *body = xs_dup("[]"); |
| 979 | *ctype = "application/json"; | 979 | *ctype = "application/json"; |
| 980 | status = 200; | 980 | status = 200; |
| 981 | } | 981 | } |
| 982 | else | 982 | else |
| 983 | if (strcmp(cmd, "/follow_requests") == 0) { | 983 | if (strcmp(cmd, "/v1/follow_requests") == 0) { |
| 984 | /* snac does not support optional follow confirmations */ | 984 | /* snac does not support optional follow confirmations */ |
| 985 | *body = xs_dup("[]"); | 985 | *body = xs_dup("[]"); |
| 986 | *ctype = "application/json"; | 986 | *ctype = "application/json"; |
| 987 | status = 200; | 987 | status = 200; |
| 988 | } | 988 | } |
| 989 | else | 989 | else |
| 990 | if (strcmp(cmd, "/announcements") == 0) { | 990 | if (strcmp(cmd, "/v1/announcements") == 0) { |
| 991 | /* snac has no announcements (yet?) */ | 991 | /* snac has no announcements (yet?) */ |
| 992 | *body = xs_dup("[]"); | 992 | *body = xs_dup("[]"); |
| 993 | *ctype = "application/json"; | 993 | *ctype = "application/json"; |
| 994 | status = 200; | 994 | status = 200; |
| 995 | } | 995 | } |
| 996 | else | 996 | else |
| 997 | if (strcmp(cmd, "/custom_emojis") == 0) { | 997 | if (strcmp(cmd, "/v1/custom_emojis") == 0) { |
| 998 | /* are you kidding me? */ | 998 | /* are you kidding me? */ |
| 999 | *body = xs_dup("[]"); | 999 | *body = xs_dup("[]"); |
| 1000 | *ctype = "application/json"; | 1000 | *ctype = "application/json"; |
| 1001 | status = 200; | 1001 | status = 200; |
| 1002 | } | 1002 | } |
| 1003 | else | 1003 | else |
| 1004 | if (strcmp(cmd, "/instance") == 0) { | 1004 | if (strcmp(cmd, "/v1/instance") == 0) { |
| 1005 | /* returns an instance object */ | 1005 | /* returns an instance object */ |
| 1006 | xs *ins = xs_dict_new(); | 1006 | xs *ins = xs_dict_new(); |
| 1007 | const char *host = xs_dict_get(srv_config, "host"); | 1007 | const char *host = xs_dict_get(srv_config, "host"); |
| @@ -1036,11 +1036,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1036 | status = 200; | 1036 | status = 200; |
| 1037 | } | 1037 | } |
| 1038 | else | 1038 | else |
| 1039 | if (xs_startswith(cmd, "/statuses/")) { | 1039 | if (xs_startswith(cmd, "/v1/statuses/")) { |
| 1040 | /* operations on a status */ | 1040 | /* operations on a status */ |
| 1041 | xs *l = xs_split(cmd, "/"); | 1041 | xs *l = xs_split(cmd, "/"); |
| 1042 | const char *id = xs_list_get(l, 2); | 1042 | const char *id = xs_list_get(l, 3); |
| 1043 | const char *op = xs_list_get(l, 3); | 1043 | const char *op = xs_list_get(l, 4); |
| 1044 | 1044 | ||
| 1045 | if (!xs_is_null(id)) { | 1045 | if (!xs_is_null(id)) { |
| 1046 | xs *msg = NULL; | 1046 | xs *msg = NULL; |
| @@ -1132,25 +1132,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1132 | } | 1132 | } |
| 1133 | } | 1133 | } |
| 1134 | else | 1134 | else |
| 1135 | if (strcmp(cmd, "/filters") == 0) { | 1135 | if (strcmp(cmd, "/v1/filters") == 0) { |
| 1136 | *body = xs_dup("[]"); | 1136 | *body = xs_dup("[]"); |
| 1137 | *ctype = "application/json"; | 1137 | *ctype = "application/json"; |
| 1138 | status = 200; | 1138 | status = 200; |
| 1139 | } | 1139 | } |
| 1140 | else | 1140 | else |
| 1141 | if (strcmp(cmd, "/preferences") == 0) { | 1141 | if (strcmp(cmd, "/v1/preferences") == 0) { |
| 1142 | *body = xs_dup("{}"); | 1142 | *body = xs_dup("{}"); |
| 1143 | *ctype = "application/json"; | 1143 | *ctype = "application/json"; |
| 1144 | status = 200; | 1144 | status = 200; |
| 1145 | } | 1145 | } |
| 1146 | else | 1146 | else |
| 1147 | if (strcmp(cmd, "/markers") == 0) { | 1147 | if (strcmp(cmd, "/v1/markers") == 0) { |
| 1148 | *body = xs_dup("{}"); | 1148 | *body = xs_dup("{}"); |
| 1149 | *ctype = "application/json"; | 1149 | *ctype = "application/json"; |
| 1150 | status = 200; | 1150 | status = 200; |
| 1151 | } | 1151 | } |
| 1152 | else | 1152 | else |
| 1153 | if (strcmp(cmd, "/followed_tags") == 0) { | 1153 | if (strcmp(cmd, "/v1/followed_tags") == 0) { |
| 1154 | *body = xs_dup("[]"); | 1154 | *body = xs_dup("[]"); |
| 1155 | *ctype = "application/json"; | 1155 | *ctype = "application/json"; |
| 1156 | status = 200; | 1156 | status = 200; |
| @@ -1249,7 +1249,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 1249 | const char *summary = xs_dict_get(args, "spoiler_text"); | 1249 | const char *summary = xs_dict_get(args, "spoiler_text"); |
| 1250 | 1250 | ||
| 1251 | xs *attach_list = xs_list_new(); | 1251 | xs *attach_list = xs_list_new(); |
| 1252 | char *irt = NULL; | 1252 | xs *irt = NULL; |
| 1253 | 1253 | ||
| 1254 | /* is it a reply? */ | 1254 | /* is it a reply? */ |
| 1255 | if (mid != NULL) { | 1255 | if (mid != NULL) { |
| @@ -1257,7 +1257,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 1257 | const char *md5 = MID_TO_MD5(mid); | 1257 | const char *md5 = MID_TO_MD5(mid); |
| 1258 | 1258 | ||
| 1259 | if (valid_status(object_get_by_md5(md5, &r_msg))) | 1259 | if (valid_status(object_get_by_md5(md5, &r_msg))) |
| 1260 | irt = xs_dict_get(r_msg, "id"); | 1260 | irt = xs_dup(xs_dict_get(r_msg, "id")); |
| 1261 | } | 1261 | } |
| 1262 | 1262 | ||
| 1263 | /* prepare the message */ | 1263 | /* prepare the message */ |
| @@ -1294,8 +1294,8 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 1294 | if (logged_in) { | 1294 | if (logged_in) { |
| 1295 | /* operations on a status */ | 1295 | /* operations on a status */ |
| 1296 | xs *l = xs_split(cmd, "/"); | 1296 | xs *l = xs_split(cmd, "/"); |
| 1297 | const char *mid = xs_list_get(l, 2); | 1297 | const char *mid = xs_list_get(l, 3); |
| 1298 | const char *op = xs_list_get(l, 3); | 1298 | const char *op = xs_list_get(l, 4); |
| 1299 | 1299 | ||
| 1300 | if (!xs_is_null(mid)) { | 1300 | if (!xs_is_null(mid)) { |
| 1301 | xs *msg = NULL; | 1301 | xs *msg = NULL; |