forked from Telodendria/Telodendria
[ADD] Finish off a test version of #26, fix a short NULL guard
This commit is contained in:
parent
6edacc8b32
commit
30c3f837d4
2 changed files with 27 additions and 2 deletions
|
@ -205,6 +205,11 @@ RegTokenJSON(RegTokenInfo * info)
|
|||
{
|
||||
TokenInfo tokinfo;
|
||||
|
||||
if (!info)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tokinfo.name = info->name;
|
||||
tokinfo.created_on = info->created;
|
||||
tokinfo.expires_on = info->expires;
|
||||
|
|
|
@ -61,9 +61,9 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
|
|||
Int64 maxuses;
|
||||
Int64 lifetime;
|
||||
|
||||
if (method != HTTP_GET && method != HTTP_POST)
|
||||
if (method != HTTP_GET && method != HTTP_POST && method != HTTP_DELETE)
|
||||
{
|
||||
msg = "Route only supports GET and POST for now.";
|
||||
msg = "Route only supports GET, POST, and DELETE";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
}
|
||||
|
@ -123,6 +123,13 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
|
|||
break;
|
||||
}
|
||||
info = RegTokenGetInfo(db, ArrayGet(path, 0));
|
||||
if (!info)
|
||||
{
|
||||
msg = "Token doesn't exist.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, msg);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
response = RegTokenJSON(info);
|
||||
|
||||
|
@ -183,6 +190,19 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
|
|||
TokenRequestFree(req);
|
||||
Free(req);
|
||||
break;
|
||||
case HTTP_DELETE:
|
||||
if (ArraySize(path) == 0)
|
||||
{
|
||||
msg = "No registration token given to DELETE /tokens/[token].";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, msg);
|
||||
goto finish;
|
||||
}
|
||||
info = RegTokenGetInfo(db, ArrayGet(path, 0));
|
||||
RegTokenDelete(info);
|
||||
/* As this is a No Content, let's not set any data in the
|
||||
* response */
|
||||
HttpResponseStatus(args->context, HTTP_NO_CONTENT);
|
||||
default:
|
||||
/* Fallthrough, as those are naturally kept out beforehand */
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue