Decode enrollment status JSON response
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include "storage.h"
|
||||
#include "http_client.h"
|
||||
#include "constants.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
|
||||
@ -46,6 +47,7 @@ enum DevEnrollmentStatus secure_api_get_device_enrollment_status()
|
||||
assert(storage_get_dev_name(uri + strlen(uri)) > 0);
|
||||
|
||||
char *res = process_secure_request(uri);
|
||||
|
||||
free(uri);
|
||||
|
||||
if (res == NULL)
|
||||
@ -54,9 +56,37 @@ enum DevEnrollmentStatus secure_api_get_device_enrollment_status()
|
||||
return DevEnrollError;
|
||||
}
|
||||
|
||||
// TODO : parse reponse
|
||||
printf("response = %s\n", res);
|
||||
enum DevEnrollmentStatus s = DevEnrollError;
|
||||
cJSON *root = cJSON_Parse(res);
|
||||
if (root == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to decode JSON response from server!");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cJSON *status = cJSON_GetObjectItem(root, "status");
|
||||
if (status == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Status missing in response from server!");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!strcmp(status->valuestring, "Unknown"))
|
||||
s = DevEnrollUnknown;
|
||||
else if (!strcmp(status->valuestring, "Pending"))
|
||||
s = DevEnrollPending;
|
||||
else if (!strcmp(status->valuestring, "Validated"))
|
||||
s = DevEnrollValidated;
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Unknown enrollment status: %s", status->valuestring);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fail:
|
||||
|
||||
cJSON_Delete(root);
|
||||
free(res);
|
||||
|
||||
return DevEnrollError;
|
||||
return s;
|
||||
}
|
Reference in New Issue
Block a user