Convert RegTokenInfo to a j2s Schema. #1

Closed
jordan wants to merge 14 commits from Telodendria:pull-37 into implement-26
3 changed files with 19 additions and 39 deletions
Showing only changes of commit f87cce0f4c - Show all commits

View file

@ -1,4 +1,5 @@
{
"guard": "TELODENDRIA_SCHEMA_FILTER_H",
"header": "Schema\/Filter.h",
"types": {
"FilterRoom": {
@ -116,6 +117,5 @@
},
"type": "struct"
}
},
"guard": "TELODENDRIA_SCHEMA_FILTER_H"
}
}

View file

@ -1,23 +1,10 @@
{
"guard": "TELODENDRIA_SCHEMA_REGTOKEN_H",
"header": "Schema\/RegToken.h",
"include": [
"Cytoplasm\/Db.h"
],
"types": {
"RegTokenAdminRequest": {
"fields": {
"name": {
"type": "string"
},
"max_uses": {
"type": "integer"
},
"lifetime": {
"type": "integer"
}
},
"type": "struct"
},
"Db *": {
"type": "extern"
},
@ -58,6 +45,5 @@
},
"type": "struct"
}
},
"guard": "TELODENDRIA_ADMINTOKEN_H"
}
}

View file

@ -38,8 +38,6 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
HashMap *response = NULL;
char *token;
char *username;
char *name;
char *msg;
Db *db = args->matrixArgs->db;
@ -53,13 +51,10 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
RegTokenInfo *info;
RegTokenAdminRequest *req;
RegTokenInfo *req;
size_t i;
Int64 maxuses;
Int64 lifetime;
if (method != HTTP_GET && method != HTTP_POST && method != HTTP_DELETE)
{
msg = "Route only supports GET, POST, and DELETE";
@ -120,6 +115,7 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
DbListFree(tokens);
break;
}
info = RegTokenGetInfo(db, ArrayGet(path, 0));
if (!info)
{
@ -142,14 +138,13 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
response = MatrixErrorCreate(M_NOT_JSON, NULL);
goto finish;
}
req = Malloc(sizeof(RegTokenAdminRequest));
req->max_uses = Int64Neg(Int64Create(0, 1));
req->lifetime = Int64Create(0, 0);
req->name = NULL;
if (!RegTokenAdminRequestFromJson(request, req, &msg))
req = Malloc(sizeof(RegTokenInfo));
memset(req, 0, sizeof(RegTokenInfo));
if (!RegTokenInfoFromJson(request, req, &msg))
{
RegTokenAdminRequestFree(req);
RegTokenInfoFree(req);
Free(req);
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
@ -163,29 +158,28 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
req->name = StrRandom(16);
}
username = UserGetName(user);
name = req->name;
maxuses = req->max_uses;
lifetime = req->lifetime;
info = RegTokenCreate(db, name, username, maxuses, lifetime, 0);
/* Create the actual token that will be stored. */
info = RegTokenCreate(db, req->name, UserGetName(user),
req->expires_on, req->uses,
UserDecodePrivileges(req->grants));
if (!info)
{
RegTokenClose(info);
RegTokenFree(info);
RegTokenAdminRequestFree(req);
RegTokenInfoFree(req);
Free(req);
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
msg = "Cannot create token";
msg = "Cannot create token.";
response = MatrixErrorCreate(M_INVALID_PARAM, msg);
goto finish;
}
response = RegTokenInfoToJson(info);
RegTokenClose(info);
RegTokenFree(info);
RegTokenAdminRequestFree(req);
RegTokenInfoFree(req);
Free(req);
break;
case HTTP_DELETE: