forked from mirrors/lpac
add cJSON_AddStringOrNullToObject to make datastruct stable
This commit is contained in:
parent
88ed7b2521
commit
09bbc3ed00
11 changed files with 60 additions and 42 deletions
13
cjson/cJSON_ex.c
Normal file
13
cjson/cJSON_ex.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "cJSON_ex.h"
|
||||
|
||||
CJSON_PUBLIC(cJSON *) cJSON_AddStringOrNullToObject(cJSON *const object, const char *const name, const char *const string)
|
||||
{
|
||||
if (string)
|
||||
{
|
||||
return cJSON_AddStringToObject(object, name, string);
|
||||
}
|
||||
else
|
||||
{
|
||||
return cJSON_AddNullToObject(object, name);
|
||||
}
|
||||
}
|
5
cjson/cJSON_ex.h
Normal file
5
cjson/cJSON_ex.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
CJSON_PUBLIC(cJSON *) cJSON_AddStringOrNullToObject(cJSON *const object, const char *const name, const char *const string);
|
|
@ -4,7 +4,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <cjson/cJSON_ex.h>
|
||||
|
||||
static const char *lpa_header[] = {
|
||||
"User-Agent: gsma-rsp-lpad",
|
||||
|
@ -99,7 +99,7 @@ static int es9p_trans_json(struct euicc_ctx *ctx, const char *smdp, const char *
|
|||
|
||||
for (int i = 0; ikey[i] != NULL; i++)
|
||||
{
|
||||
if (!cJSON_AddStringToObject(sjroot, ikey[i], idata[i]))
|
||||
if (!cJSON_AddStringOrNullToObject(sjroot, ikey[i], idata[i]))
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include <euicc/interface.h>
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <cjson/cJSON_ex.h>
|
||||
|
||||
#define INTERFACE_SELECT_ENV "DRIVER_IFID"
|
||||
|
||||
|
@ -274,7 +274,7 @@ static int json_print(cJSON *jpayload)
|
|||
goto err;
|
||||
}
|
||||
|
||||
if (cJSON_AddStringToObject(jroot, "type", "driver") == NULL)
|
||||
if (cJSON_AddStringOrNullToObject(jroot, "type", "driver") == NULL)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
@ -371,12 +371,12 @@ static int pcsc_list_iter(int index, const char *reader, void *userdata)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!cJSON_AddStringToObject(jreader, "env", index_str))
|
||||
if (!cJSON_AddStringOrNullToObject(jreader, "env", index_str))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!cJSON_AddStringToObject(jreader, "name", reader))
|
||||
if (!cJSON_AddStringOrNullToObject(jreader, "name", reader))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ EUICC_SHARED_EXPORT int libapduinterface_main(int argc, char **argv)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!cJSON_AddStringToObject(payload, "env", INTERFACE_SELECT_ENV))
|
||||
if (!cJSON_AddStringOrNullToObject(payload, "env", INTERFACE_SELECT_ENV))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <cjson/cJSON_ex.h>
|
||||
|
||||
#include <euicc/interface.h>
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <cjson/cJSON_ex.h>
|
||||
|
||||
#include <euicc/interface.h>
|
||||
|
||||
|
@ -152,7 +152,7 @@ static int json_print(cJSON *jpayload)
|
|||
goto err;
|
||||
}
|
||||
|
||||
if (cJSON_AddStringToObject(jroot, "type", "http") == NULL)
|
||||
if (cJSON_AddStringOrNullToObject(jroot, "type", "http") == NULL)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
@ -206,11 +206,11 @@ static int json_request(const char *url, const uint8_t *tx, uint32_t tx_len, con
|
|||
{
|
||||
goto err;
|
||||
}
|
||||
if (cJSON_AddStringToObject(jpayload, "url", url) == NULL)
|
||||
if (cJSON_AddStringOrNullToObject(jpayload, "url", url) == NULL)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
if (cJSON_AddStringToObject(jpayload, "tx", tx_hex) == NULL)
|
||||
if (cJSON_AddStringOrNullToObject(jpayload, "tx", tx_hex) == NULL)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
|
|
@ -32,18 +32,18 @@ static int applet_main(int argc, char **argv)
|
|||
}
|
||||
|
||||
jdata = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(jdata, "eid", eid);
|
||||
cJSON_AddStringToObject(jdata, "default_smds", default_smds);
|
||||
cJSON_AddStringToObject(jdata, "default_smdp", default_smdp);
|
||||
cJSON_AddStringOrNullToObject(jdata, "eid", eid);
|
||||
cJSON_AddStringOrNullToObject(jdata, "default_smds", default_smds);
|
||||
cJSON_AddStringOrNullToObject(jdata, "default_smdp", default_smdp);
|
||||
if (jeuiccinfo2)
|
||||
{
|
||||
cJSON_AddStringToObject(jeuiccinfo2, "profile_version", euiccinfo2.profile_version);
|
||||
cJSON_AddStringToObject(jeuiccinfo2, "sgp22_version", euiccinfo2.sgp22_version);
|
||||
cJSON_AddStringToObject(jeuiccinfo2, "euicc_firmware_version", euiccinfo2.euicc_firmware_version);
|
||||
cJSON_AddStringToObject(jeuiccinfo2, "uicc_firmware_version", euiccinfo2.uicc_firmware_version);
|
||||
cJSON_AddStringToObject(jeuiccinfo2, "global_platform_version", euiccinfo2.global_platform_version);
|
||||
cJSON_AddStringToObject(jeuiccinfo2, "protection_profile_version", euiccinfo2.pp_version);
|
||||
cJSON_AddStringToObject(jeuiccinfo2, "sas_accreditation_number", euiccinfo2.sas_accreditation_number);
|
||||
cJSON_AddStringOrNullToObject(jeuiccinfo2, "profile_version", euiccinfo2.profile_version);
|
||||
cJSON_AddStringOrNullToObject(jeuiccinfo2, "sgp22_version", euiccinfo2.sgp22_version);
|
||||
cJSON_AddStringOrNullToObject(jeuiccinfo2, "euicc_firmware_version", euiccinfo2.euicc_firmware_version);
|
||||
cJSON_AddStringOrNullToObject(jeuiccinfo2, "uicc_firmware_version", euiccinfo2.uicc_firmware_version);
|
||||
cJSON_AddStringOrNullToObject(jeuiccinfo2, "global_platform_version", euiccinfo2.global_platform_version);
|
||||
cJSON_AddStringOrNullToObject(jeuiccinfo2, "protection_profile_version", euiccinfo2.pp_version);
|
||||
cJSON_AddStringOrNullToObject(jeuiccinfo2, "sas_accreditation_number", euiccinfo2.sas_accreditation_number);
|
||||
cJSON_AddNumberToObject(jeuiccinfo2, "free_nvram", euiccinfo2.free_nvram);
|
||||
cJSON_AddNumberToObject(jeuiccinfo2, "free_ram", euiccinfo2.free_ram);
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ static int applet_main(int argc, char **argv)
|
|||
|
||||
jnotification = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(jnotification, "seqNumber", notifications[i].seqNumber);
|
||||
cJSON_AddStringToObject(jnotification, "profileManagementOperation", notifications[i].profileManagementOperation);
|
||||
cJSON_AddStringToObject(jnotification, "notificationAddress", notifications[i].notificationAddress);
|
||||
cJSON_AddStringToObject(jnotification, "iccid", notifications[i].iccid);
|
||||
cJSON_AddStringOrNullToObject(jnotification, "profileManagementOperation", notifications[i].profileManagementOperation);
|
||||
cJSON_AddStringOrNullToObject(jnotification, "notificationAddress", notifications[i].notificationAddress);
|
||||
cJSON_AddStringOrNullToObject(jnotification, "iccid", notifications[i].iccid);
|
||||
|
||||
cJSON_AddItemToArray(jdata, jnotification);
|
||||
}
|
||||
|
|
|
@ -23,15 +23,15 @@ static int applet_main(int argc, char **argv)
|
|||
cJSON *jprofile = NULL;
|
||||
|
||||
jprofile = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(jprofile, "iccid", profiles[i].iccid);
|
||||
cJSON_AddStringToObject(jprofile, "isdpAid", profiles[i].isdpAid);
|
||||
cJSON_AddStringToObject(jprofile, "profileState", profiles[i].profileState);
|
||||
cJSON_AddStringToObject(jprofile, "profileNickname", profiles[i].profileNickname);
|
||||
cJSON_AddStringToObject(jprofile, "serviceProviderName", profiles[i].serviceProviderName);
|
||||
cJSON_AddStringToObject(jprofile, "profileName", profiles[i].profileName);
|
||||
cJSON_AddStringToObject(jprofile, "iconType", profiles[i].iconType);
|
||||
cJSON_AddStringToObject(jprofile, "icon", profiles[i].icon);
|
||||
cJSON_AddStringToObject(jprofile, "profileClass", profiles[i].profileClass);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "iccid", profiles[i].iccid);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "isdpAid", profiles[i].isdpAid);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "profileState", profiles[i].profileState);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "profileNickname", profiles[i].profileNickname);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "serviceProviderName", profiles[i].serviceProviderName);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "profileName", profiles[i].profileName);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "iconType", profiles[i].iconType);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "icon", profiles[i].icon);
|
||||
cJSON_AddStringOrNullToObject(jprofile, "profileClass", profiles[i].profileClass);
|
||||
cJSON_AddItemToArray(jdata, jprofile);
|
||||
}
|
||||
es10c_profile_info_free_all(profiles, profiles_count);
|
||||
|
|
14
src/jprint.c
14
src/jprint.c
|
@ -16,11 +16,11 @@ void jprint_error(const char *function_name, const char *detail)
|
|||
}
|
||||
|
||||
jroot = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(jroot, "type", "lpa");
|
||||
cJSON_AddStringOrNullToObject(jroot, "type", "lpa");
|
||||
jpayload = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(jpayload, "code", -1);
|
||||
cJSON_AddStringToObject(jpayload, "message", function_name);
|
||||
cJSON_AddStringToObject(jpayload, "data", detail);
|
||||
cJSON_AddStringOrNullToObject(jpayload, "message", function_name);
|
||||
cJSON_AddStringOrNullToObject(jpayload, "data", detail);
|
||||
cJSON_AddItemToObject(jroot, "payload", jpayload);
|
||||
|
||||
jstr = cJSON_PrintUnformatted(jroot);
|
||||
|
@ -37,10 +37,10 @@ void jprint_progress(const char *function_name)
|
|||
char *jstr = NULL;
|
||||
|
||||
jroot = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(jroot, "type", "progress");
|
||||
cJSON_AddStringOrNullToObject(jroot, "type", "progress");
|
||||
jpayload = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(jpayload, "code", 0);
|
||||
cJSON_AddStringToObject(jpayload, "message", function_name);
|
||||
cJSON_AddStringOrNullToObject(jpayload, "message", function_name);
|
||||
cJSON_AddNullToObject(jpayload, "data");
|
||||
cJSON_AddItemToObject(jroot, "payload", jpayload);
|
||||
|
||||
|
@ -58,10 +58,10 @@ void jprint_success(cJSON *jdata)
|
|||
char *jstr = NULL;
|
||||
|
||||
jroot = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(jroot, "type", "lpa");
|
||||
cJSON_AddStringOrNullToObject(jroot, "type", "lpa");
|
||||
jpayload = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(jpayload, "code", 0);
|
||||
cJSON_AddStringToObject(jpayload, "message", "success");
|
||||
cJSON_AddStringOrNullToObject(jpayload, "message", "success");
|
||||
if (jdata)
|
||||
{
|
||||
cJSON_AddItemToObject(jpayload, "data", jdata);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <cjson/cJSON.h>
|
||||
#include <cjson/cJSON_ex.h>
|
||||
|
||||
void jprint_error(const char *function_name, const char *detail);
|
||||
void jprint_progress(const char *function_name);
|
||||
|
|
Loading…
Add table
Reference in a new issue