mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Also delete the app in token revokation.
This commit is contained in:
parent
74098ec443
commit
429be774d2
1 changed files with 30 additions and 0 deletions
30
mastoapi.c
30
mastoapi.c
|
@ -34,6 +34,9 @@ static xs_str *random_str(void)
|
||||||
int app_add(const char *id, const xs_dict *app)
|
int app_add(const char *id, const xs_dict *app)
|
||||||
/* stores an app */
|
/* stores an app */
|
||||||
{
|
{
|
||||||
|
if (!xs_is_hex(id))
|
||||||
|
return 500;
|
||||||
|
|
||||||
int status = 201;
|
int status = 201;
|
||||||
xs *fn = xs_fmt("%s/app/", srv_basedir);
|
xs *fn = xs_fmt("%s/app/", srv_basedir);
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -57,6 +60,9 @@ int app_add(const char *id, const xs_dict *app)
|
||||||
xs_dict *app_get(const char *id)
|
xs_dict *app_get(const char *id)
|
||||||
/* gets an app */
|
/* gets an app */
|
||||||
{
|
{
|
||||||
|
if (!xs_is_hex(id))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
xs *fn = xs_fmt("%s/app/%s.json", srv_basedir, id);
|
xs *fn = xs_fmt("%s/app/%s.json", srv_basedir, id);
|
||||||
xs_dict *app = NULL;
|
xs_dict *app = NULL;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -72,9 +78,24 @@ xs_dict *app_get(const char *id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int app_del(const char *id)
|
||||||
|
/* deletes an app */
|
||||||
|
{
|
||||||
|
if (!xs_is_hex(id))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
xs *fn = xs_fmt("%s/app/%s.json", srv_basedir, id);
|
||||||
|
|
||||||
|
return unlink(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int token_add(const char *id, const xs_dict *token)
|
int token_add(const char *id, const xs_dict *token)
|
||||||
/* stores a token */
|
/* stores a token */
|
||||||
{
|
{
|
||||||
|
if (!xs_is_hex(id))
|
||||||
|
return 500;
|
||||||
|
|
||||||
int status = 201;
|
int status = 201;
|
||||||
xs *fn = xs_fmt("%s/token/", srv_basedir);
|
xs *fn = xs_fmt("%s/token/", srv_basedir);
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -98,6 +119,9 @@ int token_add(const char *id, const xs_dict *token)
|
||||||
xs_dict *token_get(const char *id)
|
xs_dict *token_get(const char *id)
|
||||||
/* gets a token */
|
/* gets a token */
|
||||||
{
|
{
|
||||||
|
if (!xs_is_hex(id))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
xs *fn = xs_fmt("%s/token/%s.json", srv_basedir, id);
|
xs *fn = xs_fmt("%s/token/%s.json", srv_basedir, id);
|
||||||
xs_dict *token = NULL;
|
xs_dict *token = NULL;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -116,6 +140,9 @@ xs_dict *token_get(const char *id)
|
||||||
int token_del(const char *id)
|
int token_del(const char *id)
|
||||||
/* deletes a token */
|
/* deletes a token */
|
||||||
{
|
{
|
||||||
|
if (!xs_is_hex(id))
|
||||||
|
return -1;
|
||||||
|
|
||||||
xs *fn = xs_fmt("%s/token/%s.json", srv_basedir, id);
|
xs *fn = xs_fmt("%s/token/%s.json", srv_basedir, id);
|
||||||
|
|
||||||
return unlink(fn);
|
return unlink(fn);
|
||||||
|
@ -324,6 +351,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
|
||||||
token_del(tokid);
|
token_del(tokid);
|
||||||
srv_debug(0, xs_fmt("oauth revoke: revoked token %s", tokid));
|
srv_debug(0, xs_fmt("oauth revoke: revoked token %s", tokid));
|
||||||
status = 200;
|
status = 200;
|
||||||
|
|
||||||
|
/* also delete the app, as it serves no purpose from now on */
|
||||||
|
app_del(cid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue