forked from Telodendria/Telodendria
Convert RegTokenInfo
to a j2s
Schema. #1
5 changed files with 17 additions and 13 deletions
|
@ -238,6 +238,7 @@ RegTokenCreate(Db * db, char *name, char *owner, UInt64 expires, Int64 uses, int
|
||||||
ret->uses = uses;
|
ret->uses = uses;
|
||||||
ret->created_on = timestamp;
|
ret->created_on = timestamp;
|
||||||
ret->expires_on = expires;
|
ret->expires_on = expires;
|
||||||
|
/* TODO: #37 type mismatch: UserEncodePrivileges() returns a JsonValue */
|
||||||
ret->grants = UserEncodePrivileges(privileges);
|
ret->grants = UserEncodePrivileges(privileges);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -98,15 +98,15 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
||||||
switch (HttpRequestMethodGet(args->context))
|
switch (HttpRequestMethodGet(args->context))
|
||||||
{
|
{
|
||||||
case HTTP_POST:
|
case HTTP_POST:
|
||||||
privileges = UserDecodePrivileges(JsonValueAsArray(val));
|
privileges = UserDecodePrivileges(val);
|
||||||
break;
|
break;
|
||||||
case HTTP_PUT:
|
case HTTP_PUT:
|
||||||
privileges = UserGetPrivileges(user);
|
privileges = UserGetPrivileges(user);
|
||||||
privileges |= UserDecodePrivileges(JsonValueAsArray(val));
|
privileges |= UserDecodePrivileges(val);
|
||||||
break;
|
break;
|
||||||
case HTTP_DELETE:
|
case HTTP_DELETE:
|
||||||
privileges = UserGetPrivileges(user);
|
privileges = UserGetPrivileges(user);
|
||||||
privileges &= ~UserDecodePrivileges(JsonValueAsArray(val));
|
privileges &= ~UserDecodePrivileges(val);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Impossible */
|
/* Impossible */
|
||||||
|
@ -124,7 +124,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
case HTTP_GET:
|
case HTTP_GET:
|
||||||
response = HashMapCreate();
|
response = HashMapCreate();
|
||||||
HashMapSet(response, "privileges", JsonValueArray(UserEncodePrivileges(UserGetPrivileges(user))));
|
HashMapSet(response, "privileges", UserEncodePrivileges(UserGetPrivileges(user)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||||
|
|
|
@ -276,6 +276,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
||||||
|
|
||||||
if (info)
|
if (info)
|
||||||
{
|
{
|
||||||
|
/* TODO: #37 type mismatch: info->grants is a string array. */
|
||||||
UserSetPrivileges(user, UserDecodePrivileges(info->grants));
|
UserSetPrivileges(user, UserDecodePrivileges(info->grants));
|
||||||
RegTokenClose(info);
|
RegTokenClose(info);
|
||||||
RegTokenFree(info);
|
RegTokenFree(info);
|
||||||
|
|
16
src/User.c
16
src/User.c
|
@ -749,7 +749,7 @@ UserGetPrivileges(User * user)
|
||||||
return USER_NONE;
|
return USER_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return UserDecodePrivileges(JsonValueAsArray(HashMapGet(DbJson(user->ref), "privileges")));
|
return UserDecodePrivileges(HashMapGet(DbJson(user->ref), "privileges"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -768,7 +768,7 @@ UserSetPrivileges(User * user, int privileges)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
val = JsonValueArray(UserEncodePrivileges(privileges));
|
val = UserEncodePrivileges(privileges);
|
||||||
if (!val)
|
if (!val)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -779,17 +779,19 @@ UserSetPrivileges(User * user, int privileges)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
UserDecodePrivileges(Array * arr)
|
UserDecodePrivileges(JsonValue * val)
|
||||||
{
|
{
|
||||||
int privileges = USER_NONE;
|
int privileges = USER_NONE;
|
||||||
|
Array *arr;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!arr)
|
if (!val || JsonValueType(val) != JSON_ARRAY)
|
||||||
{
|
{
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arr = JsonValueAsArray(val);
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(arr); i++)
|
for (i = 0; i < ArraySize(arr); i++)
|
||||||
{
|
{
|
||||||
JsonValue *val = ArrayGet(arr, i);
|
JsonValue *val = ArrayGet(arr, i);
|
||||||
|
@ -846,7 +848,7 @@ UserDecodePrivilege(const char *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Array *
|
JsonValue *
|
||||||
UserEncodePrivileges(int privileges)
|
UserEncodePrivileges(int privileges)
|
||||||
{
|
{
|
||||||
Array *arr = ArrayCreate();
|
Array *arr = ArrayCreate();
|
||||||
|
@ -878,7 +880,7 @@ UserEncodePrivileges(int privileges)
|
||||||
#undef A
|
#undef A
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
return arr;
|
return JsonValueArray(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserId *
|
UserId *
|
||||||
|
|
|
@ -286,13 +286,13 @@ extern int UserSetPrivileges(User *, int);
|
||||||
* Decode the JSON that represents the user privileges into a packed
|
* Decode the JSON that represents the user privileges into a packed
|
||||||
* bit field for simple manipulation.
|
* bit field for simple manipulation.
|
||||||
*/
|
*/
|
||||||
extern int UserDecodePrivileges(Array *);
|
extern int UserDecodePrivileges(JsonValue *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode the packed bit field that represents user privileges as a
|
* Encode the packed bit field that represents user privileges as a
|
||||||
* JSON value.
|
* JSON value.
|
||||||
*/
|
*/
|
||||||
extern Array *UserEncodePrivileges(int);
|
extern JsonValue *UserEncodePrivileges(int);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a string privilege into its bit in the bit field. This is
|
* Convert a string privilege into its bit in the bit field. This is
|
||||||
|
|
Loading…
Reference in a new issue