Skip to content

Commit

Permalink
Merge pull request #28 from DMTF/GetPayloadUri
Browse files Browse the repository at this point in the history
Add getPayloadUri()
  • Loading branch information
mraineri authored Sep 27, 2018
2 parents edef9b9 + 72cbc4f commit b25bb44
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
10 changes: 10 additions & 0 deletions include/redfishPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ REDFISH_EXPORT char* getPayloadBody(redfishPayload* payload);
*/
REDFISH_EXPORT char* getPayloadContentType(redfishPayload* payload);

/**
* @brief Get the payload uri
*
* Get the payload uri (the @odata.id)
*
* @param payload The payload to return the URI of
* @return The uri
*/
REDFISH_EXPORT char* getPayloadUri(redfishPayload* payload);

/**
* @brief Get the string value for the payload
*
Expand Down
46 changes: 28 additions & 18 deletions src/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ char* getPayloadContentType(redfishPayload* payload)
return "application/json";
}

char* getPayloadUri(redfishPayload* payload)
{
json_t* json;

if(!payload)
{
return NULL;
}

json = json_object_get(payload->json, "@odata.id");
if(json == NULL)
{
json = json_object_get(payload->json, "target");
if(json == NULL)
{
return NULL;
}
}
return strdup(json_string_value(json));
}

char* getPayloadStringValue(redfishPayload* payload)
{
json_t* tmp;
Expand Down Expand Up @@ -388,13 +409,11 @@ redfishPayload* patchPayloadStringProperty(redfishPayload* payload, const char*
{
return NULL;
}

json = json_object_get(payload->json, "@odata.id");
if(json == NULL)
uri = getPayloadUri(payload);
if(uri == NULL)
{
return NULL;
}
uri = strdup(json_string_value(json));

json = json_object();
json2 = json_string(value);
Expand Down Expand Up @@ -422,16 +441,11 @@ redfishPayload* postContentToPayload(redfishPayload* target, const char* data, s
{
return NULL;
}
json = json_object_get(target->json, "@odata.id");
if(json == NULL)
uri = getPayloadUri(target);
if(uri == NULL)
{
json = json_object_get(target->json, "target");
if(json == NULL)
{
return NULL;
}
return NULL;
}
uri = strdup(json_string_value(json));
json = postUriFromService(target->service, uri, data, dataSize, contentType);
free(uri);
if(json == NULL)
Expand Down Expand Up @@ -463,22 +477,18 @@ redfishPayload* postPayload(redfishPayload* target, redfishPayload* payload)

bool deletePayload(redfishPayload* payload)
{
json_t* json;
char* uri;
bool ret;

if(!payload)
{
return false;
}

json = json_object_get(payload->json, "@odata.id");
if(json == NULL)
uri = getPayloadUri(payload);
if(uri == NULL)
{
return false;
}
uri = strdup(json_string_value(json));

ret = deleteUriFromService(payload->service, uri);
free(uri);
return ret;
Expand Down

0 comments on commit b25bb44

Please sign in to comment.