mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 06:25:04 +00:00
make compatible with subway tooter app
This commit is contained in:
parent
d86b96b5a3
commit
253e627ee0
2 changed files with 50 additions and 1 deletions
24
mastoapi.c
24
mastoapi.c
|
@ -359,6 +359,12 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
}
|
||||
|
||||
/* no code?
|
||||
I'm not sure of the impacts of this right now, but Subway Tooter does not
|
||||
provide a code so one must be generated */
|
||||
if (xs_is_null(code)){
|
||||
code = random_str();
|
||||
}
|
||||
if (gtype && code && cid && csec && ruri) {
|
||||
xs *app = app_get(cid);
|
||||
|
||||
|
@ -1408,7 +1414,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
const char *type = xs_dict_get(msg, "type");
|
||||
if (!xs_match(type, "Note|Question|Page|Article"))
|
||||
continue;
|
||||
|
||||
const char *from = NULL;
|
||||
if (strcmp(type, "Page") == 0)
|
||||
from = xs_dict_get(msg, "audience");
|
||||
|
@ -1622,6 +1627,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
status = 200;
|
||||
}
|
||||
else
|
||||
if (strcmp(cmd, "/v2/filters") == 0) { /** **/
|
||||
/* snac will never have filters
|
||||
* but still, without a v2 endpoint a short delay is introduced
|
||||
* in some apps */
|
||||
*body = xs_dup("[]");
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
else
|
||||
if (strcmp(cmd, "/v1/favourites") == 0) { /** **/
|
||||
/* snac will never support a list of favourites */
|
||||
*body = xs_dup("[]");
|
||||
|
@ -1990,6 +2004,14 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|||
if (!xs_is_null(payload))
|
||||
args = xs_json_loads(payload);
|
||||
}
|
||||
else if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded"))
|
||||
{
|
||||
// Some apps send form data instead of json so we should cater for those
|
||||
if (!xs_is_null(payload)) {
|
||||
xs *upl = xs_url_dec(payload);
|
||||
args = xs_url_vars(upl);
|
||||
}
|
||||
}
|
||||
else
|
||||
args = xs_dup(xs_dict_get(req, "p_vars"));
|
||||
|
||||
|
|
27
xs_formdata.h
Normal file
27
xs_formdata.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* copyright (c) 2022 - 2024 grunfink et al. / MIT license */
|
||||
#include "xs.h"
|
||||
|
||||
#ifndef _XS_FORMDATA_H
|
||||
|
||||
#define _XS_FORMDATA_H
|
||||
|
||||
xs_val *xs_formdata_loads(const xs_str *formdata);
|
||||
|
||||
#ifdef XS_IMPLEMENTATION
|
||||
|
||||
/** IMPLEMENTATION **/
|
||||
|
||||
xs_val *xs_formdata_loads(const xs_str *formdata)
|
||||
/* loads a string in formdata format and converts to a multiple data */
|
||||
{
|
||||
xs_val *v = NULL;
|
||||
xs_list *args = xs_split(formdata, "&");
|
||||
int i = 0;
|
||||
while (){}
|
||||
printf("args: %s\r\n", args); fflush(stdout);
|
||||
printf("data: %s\r\n", formdata); fflush(stdout);
|
||||
}
|
||||
|
||||
#endif /* XS_IMPLEMENTATION */
|
||||
|
||||
#endif /* _XS_FORMDATA_H */
|
Loading…
Reference in a new issue