in src/utils/config_utils/src/config_utils.c [78:153]
static bool ADUC_AgentInfo_Init(ADUC_AgentInfo* agent, const JSON_Object* agent_obj)
{
bool success = false;
if (agent == NULL || agent_obj == NULL)
{
return false;
}
memset(agent, 0, sizeof(*agent));
const char* name = json_object_get_string(agent_obj, CONFIG_NAME);
const char* runas = json_object_get_string(agent_obj, CONFIG_RUN_AS);
const char* manufacturer = json_object_get_string(agent_obj, CONFIG_MANUFACTURER);
const char* model = json_object_get_string(agent_obj, CONFIG_MODEL);
JSON_Object* connection_source = json_object_get_object(agent_obj, CONFIG_CONNECTION_SOURCE);
const char* connection_type = NULL;
const char* connection_data = NULL;
if (connection_source == NULL)
{
return false;
}
connection_type = json_object_get_string(connection_source, CONFIG_CONNECTION_TYPE);
connection_data = json_object_get_string(connection_source, CONFIG_CONNECTION_DATA);
// As these fields are mandatory, if any of the fields doesn't exist, the agent will fail to be constructed.
if (name == NULL || runas == NULL || connection_type == NULL || connection_data == NULL || manufacturer == NULL
|| model == NULL)
{
goto done;
}
if (mallocAndStrcpy_s(&(agent->name), name) != 0)
{
goto done;
}
if (mallocAndStrcpy_s(&(agent->runas), runas) != 0)
{
goto done;
}
if (mallocAndStrcpy_s(&(agent->connectionType), connection_type) != 0)
{
goto done;
}
if (mallocAndStrcpy_s(&(agent->connectionData), connection_data) != 0)
{
goto done;
}
if (mallocAndStrcpy_s(&(agent->manufacturer), manufacturer) != 0)
{
goto done;
}
if (mallocAndStrcpy_s(&(agent->model), model) != 0)
{
goto done;
}
agent->additionalDeviceProperties = json_object_get_object(agent_obj, CONFIG_ADDITIONAL_DEVICE_PROPERTIES);
success = true;
done:
if (!success)
{
ADUC_AgentInfo_Free(agent);
}
return success;
}