2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_token_request_spec.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_token_request_spec_t *v1_token_request_spec_create(
|
|
|
|
|
list_t *audiences,
|
|
|
|
|
v1_bound_object_reference_t *bound_object_ref,
|
|
|
|
|
long expiration_seconds
|
|
|
|
|
) {
|
|
|
|
|
v1_token_request_spec_t *v1_token_request_spec_local_var = malloc(sizeof(v1_token_request_spec_t));
|
|
|
|
|
if (!v1_token_request_spec_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_token_request_spec_local_var->audiences = audiences;
|
|
|
|
|
v1_token_request_spec_local_var->bound_object_ref = bound_object_ref;
|
|
|
|
|
v1_token_request_spec_local_var->expiration_seconds = expiration_seconds;
|
|
|
|
|
|
|
|
|
|
return v1_token_request_spec_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void v1_token_request_spec_free(v1_token_request_spec_t *v1_token_request_spec) {
|
|
|
|
|
if(NULL == v1_token_request_spec){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_token_request_spec->audiences) {
|
|
|
|
|
list_ForEach(listEntry, v1_token_request_spec->audiences) {
|
|
|
|
|
free(listEntry->data);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_token_request_spec->audiences);
|
2021-01-05 15:42:34 +08:00
|
|
|
v1_token_request_spec->audiences = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_token_request_spec->bound_object_ref) {
|
|
|
|
|
v1_bound_object_reference_free(v1_token_request_spec->bound_object_ref);
|
|
|
|
|
v1_token_request_spec->bound_object_ref = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
free(v1_token_request_spec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_token_request_spec_convertToJSON(v1_token_request_spec_t *v1_token_request_spec) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_token_request_spec->audiences
|
|
|
|
|
if (!v1_token_request_spec->audiences) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON *audiences = cJSON_AddArrayToObject(item, "audiences");
|
|
|
|
|
if(audiences == NULL) {
|
|
|
|
|
goto fail; //primitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *audiencesListEntry;
|
|
|
|
|
list_ForEach(audiencesListEntry, v1_token_request_spec->audiences) {
|
|
|
|
|
if(cJSON_AddStringToObject(audiences, "", (char*)audiencesListEntry->data) == NULL)
|
|
|
|
|
{
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_token_request_spec->bound_object_ref
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_token_request_spec->bound_object_ref) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *bound_object_ref_local_JSON = v1_bound_object_reference_convertToJSON(v1_token_request_spec->bound_object_ref);
|
|
|
|
|
if(bound_object_ref_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "boundObjectRef", bound_object_ref_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_token_request_spec->expiration_seconds
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_token_request_spec->expiration_seconds) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddNumberToObject(item, "expirationSeconds", v1_token_request_spec->expiration_seconds) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_token_request_spec_t *v1_token_request_spec_parseFromJSON(cJSON *v1_token_request_specJSON){
|
|
|
|
|
|
|
|
|
|
v1_token_request_spec_t *v1_token_request_spec_local_var = NULL;
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
// define the local list for v1_token_request_spec->audiences
|
|
|
|
|
list_t *audiencesList = NULL;
|
|
|
|
|
|
2021-11-05 14:13:35 +08:00
|
|
|
// define the local variable for v1_token_request_spec->bound_object_ref
|
|
|
|
|
v1_bound_object_reference_t *bound_object_ref_local_nonprim = NULL;
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_token_request_spec->audiences
|
|
|
|
|
cJSON *audiences = cJSON_GetObjectItemCaseSensitive(v1_token_request_specJSON, "audiences");
|
|
|
|
|
if (!audiences) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *audiences_local = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
if(!cJSON_IsArray(audiences)) {
|
|
|
|
|
goto end;//primitive container
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
audiencesList = list_createList();
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(audiences_local, audiences)
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsString(audiences_local))
|
|
|
|
|
{
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
list_addElement(audiencesList , strdup(audiences_local->valuestring));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_token_request_spec->bound_object_ref
|
|
|
|
|
cJSON *bound_object_ref = cJSON_GetObjectItemCaseSensitive(v1_token_request_specJSON, "boundObjectRef");
|
|
|
|
|
if (bound_object_ref) {
|
|
|
|
|
bound_object_ref_local_nonprim = v1_bound_object_reference_parseFromJSON(bound_object_ref); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_token_request_spec->expiration_seconds
|
|
|
|
|
cJSON *expiration_seconds = cJSON_GetObjectItemCaseSensitive(v1_token_request_specJSON, "expirationSeconds");
|
|
|
|
|
if (expiration_seconds) {
|
|
|
|
|
if(!cJSON_IsNumber(expiration_seconds))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_token_request_spec_local_var = v1_token_request_spec_create (
|
|
|
|
|
audiencesList,
|
|
|
|
|
bound_object_ref ? bound_object_ref_local_nonprim : NULL,
|
|
|
|
|
expiration_seconds ? expiration_seconds->valuedouble : 0
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_token_request_spec_local_var;
|
|
|
|
|
end:
|
2022-03-29 10:12:05 +08:00
|
|
|
if (audiencesList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, audiencesList) {
|
|
|
|
|
free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(audiencesList);
|
|
|
|
|
audiencesList = NULL;
|
|
|
|
|
}
|
2021-01-11 12:15:24 +08:00
|
|
|
if (bound_object_ref_local_nonprim) {
|
|
|
|
|
v1_bound_object_reference_free(bound_object_ref_local_nonprim);
|
|
|
|
|
bound_object_ref_local_nonprim = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|