55json_object_get_by_index (
68 if (!payload || !json_is_object (payload->json)) {
72 members = json_object_get (payload->json,
"Members");
73 count = json_object_get (payload->json,
"Members@odata.count");
74 return ((members !=
NULL) && (count !=
NULL));
85 if (!payload || !json_is_object (payload->json)) {
89 members = json_object_get (payload->json,
"Members");
90 count = json_object_get (payload->json,
"Members@odata.count");
91 if (!members || !count) {
95 return (
size_t)json_integer_value (count);
103 if (!payload || !json_is_array (payload->json)) {
123 flags = JSON_INDENT (2);
126 return json_dumps (payload->json, flags);
130createRedfishPayload (
138 if (payload !=
NULL) {
139 payload->json = value;
140 payload->service = service;
147getPayloadByNodeName (
149 const char *nodeName,
157 if (!payload || !nodeName || (StatusCode ==
NULL)) {
163 value = json_object_get (payload->json, nodeName);
169 if (json_object_size (value) == 1) {
170 odataId = json_object_get (value,
"@odata.id");
171 if (odataId !=
NULL) {
172 json_incref (odataId);
173 uri = json_string_value (odataId);
175 value = getUriFromService (payload->service, uri, StatusCode);
176 json_decref (odataId);
177 if ((value ==
NULL) || (*StatusCode ==
NULL)) {
183 if ((*StatusCode ==
NULL) || ((**StatusCode >= HTTP_STATUS_200_OK) && (**StatusCode <= HTTP_STATUS_206_PARTIAL_CONTENT))) {
184 if (json_is_string (value)) {
185 odataId = json_object ();
186 json_object_set (odataId, nodeName, value);
192 return createRedfishPayload (value, payload->service);
202 json_t *value =
NULL;
205 BOOLEAN FromServerFlag =
FALSE;
207 if (!payload || (StatusCode ==
NULL)) {
213 if (isPayloadCollection (payload)) {
214 redfishPayload *members = getPayloadByNodeName (payload,
"Members", StatusCode);
215 if (((*StatusCode ==
NULL) && (members ==
NULL)) ||
216 ((*StatusCode !=
NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
221 if (*StatusCode !=
NULL) {
227 FromServerFlag =
TRUE;
230 redfishPayload *ret = getPayloadByIndex (members, index, StatusCode);
231 if ((*StatusCode ==
NULL) && (ret !=
NULL) && FromServerFlag) {
237 if (*StatusCode ==
NULL) {
240 **StatusCode = HTTP_STATUS_200_OK;
244 cleanupPayload (members);
248 if (json_is_array (payload->json)) {
252 value = json_array_get (payload->json, index);
253 }
else if (json_is_object (payload->json)) {
254 value = json_object_get_by_index (payload->json, index);
262 if (json_object_size (value) == 1) {
263 odataId = json_object_get (value,
"@odata.id");
264 if (odataId !=
NULL) {
265 uri = json_string_value (odataId);
267 value = getUriFromService (payload->service, uri, StatusCode);
274 return createRedfishPayload (value, payload->service);
287 if (!payload || !redpath || (StatusCode ==
NULL)) {
292 BOOLEAN FromServerFlag =
FALSE;
294 if (redpath->nodeName) {
295 ret = getPayloadByNodeName (payload, redpath->nodeName, StatusCode);
296 if (((*StatusCode ==
NULL) && (ret ==
NULL)) ||
297 ((*StatusCode !=
NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
304 }
else if (redpath->isIndex) {
305 ASSERT (redpath->index >= 1);
306 ret = getPayloadByIndex (payload, redpath->index - 1, StatusCode);
307 if (((*StatusCode ==
NULL) && (ret ==
NULL)) ||
308 ((*StatusCode !=
NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
315 }
else if (redpath->op) {
316 ret = getOpResult (payload, redpath->propName, redpath->op, redpath->value, StatusCode);
317 if (((*StatusCode ==
NULL) && (ret ==
NULL)) ||
318 ((*StatusCode !=
NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
329 if ((redpath->next ==
NULL) || (ret ==
NULL)) {
332 if (*StatusCode !=
NULL) {
335 FromServerFlag =
TRUE;
338 tmp = getPayloadForPath (ret, redpath->next, StatusCode);
339 if ((*StatusCode ==
NULL) && (tmp !=
NULL) && FromServerFlag) {
345 if (*StatusCode ==
NULL) {
348 **StatusCode = HTTP_STATUS_200_OK;
352 cleanupPayload (ret);
358getPayloadForPathString (
367 if (!
string || (StatusCode ==
NULL)) {
373 redpath = parseRedPath (
string);
374 if (redpath ==
NULL) {
378 ret = getPayloadForPath (payload, redpath, StatusCode);
379 cleanupRedPath (redpath);
394 if (!target || !payload || (StatusCode ==
NULL)) {
400 json = json_object_get (target->json,
"@odata.id");
405 uri =
strdup (json_string_value (json));
407 content = json_dumps (payload->json, 0);
410 json = patchUriFromService (target->service, uri, content, StatusCode);
417 return createRedfishPayload (json, target->service);
421postContentToPayload (
425 const char *contentType,
432 if (!target || !data || (StatusCode ==
NULL)) {
438 json = json_object_get (target->json,
"@odata.id");
440 json = json_object_get (target->json,
"target");
446 uri =
strdup (json_string_value (json));
447 json = postUriFromService (target->service, uri, data, dataSize, contentType, StatusCode);
453 return createRedfishPayload (json, target->service);
466 if (!target || !payload || (StatusCode ==
NULL)) {
472 if (!json_is_object (payload->json)) {
476 content = payloadToString (payload,
false);
477 ret = postContentToPayload (target, content, strlen (content),
NULL, StatusCode);
491 json_decref (payload->json);
499 const char *propName,
509 long long intVal, intPropVal;
512 if (isPayloadCollection (payload)) {
513 return collectionEvalOp (payload, propName, op, value, StatusCode);
516 if (isPayloadArray (payload)) {
517 return arrayEvalOp (payload, propName, op, value, StatusCode);
520 prop = getPayloadByNodeName (payload, propName, StatusCode);
521 if (((*StatusCode ==
NULL) && (prop ==
NULL)) ||
522 ((*StatusCode !=
NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
527 stringProp = prop->json;
531 stringProp = json_object_get (prop->json, propName);
533 if (strcmp (op,
"=") == 0) {
534 propStr = json_string_value (stringProp);
535 if (propStr ==
NULL) {
536 cleanupPayload (prop);
540 ret = (strcmp (propStr, value) == 0);
541 }
else if (strcmp (op,
"~") == 0) {
542 propStr = json_string_value (stringProp);
543 if (propStr ==
NULL) {
544 cleanupPayload (prop);
548 ret = (strcasecmp (propStr, value) == 0);
553 if (strcmp (op,
"=") == 0) {
554 ret = (strcmp (value,
"true") == 0);
559 if (strcmp (op,
"=") == 0) {
560 ret = (strcmp (value,
"false") == 0);
565 intPropVal = json_integer_value (prop->json);
567 if (strcmp (op,
"=") == 0) {
568 ret = (intPropVal == intVal);
569 }
else if (strcmp (op,
"<") == 0) {
570 ret = (intPropVal < intVal);
571 }
else if (strcmp (op,
">") == 0) {
572 ret = (intPropVal > intVal);
573 }
else if (strcmp (op,
"<=") == 0) {
574 ret = (intPropVal <= intVal);
575 }
else if (strcmp (op,
">=") == 0) {
576 ret = (intPropVal >= intVal);
584 cleanupPayload (prop);
595 const char *propName,
606 size_t validCount = 0;
609 validMax = getCollectionSize (payload);
620 members = getPayloadByNodeName (payload,
"Members", StatusCode);
621 if (((*StatusCode ==
NULL) && (members ==
NULL)) ||
622 ((*StatusCode !=
NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
628 for (i = 0; i < validMax; i++) {
629 if (*StatusCode !=
NULL) {
634 tmp = getPayloadByIndex (members, i, StatusCode);
635 if (((*StatusCode ==
NULL) && (tmp ==
NULL)) ||
636 ((*StatusCode !=
NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
642 if (*StatusCode !=
NULL) {
647 valid[validCount] = getOpResult (tmp, propName, op, value, StatusCode);
655 if (valid[validCount] !=
NULL) {
658 cleanupPayload (tmp);
662 cleanupPayload (members);
663 if (validCount == 0) {
665 }
else if (validCount == 1) {
668 ret = createCollection (payload->service, validCount, valid);
678 const char *propName,
688 size_t validCount = 0;
691 validMax = json_array_size (payload->json);
701 for (i = 0; i < validMax; i++) {
702 if (*StatusCode !=
NULL) {
707 tmp = getPayloadByIndex (payload, i, StatusCode);
708 if (((*StatusCode ==
NULL) && (tmp ==
NULL)) ||
709 ((*StatusCode !=
NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT))))
714 if (*StatusCode !=
NULL) {
719 valid[validCount] = getOpResult (tmp, propName, op, value, StatusCode);
728 if (valid[validCount] !=
NULL) {
731 cleanupPayload (tmp);
735 if (validCount == 0) {
740 if (validCount == 1) {
745 ret = createCollection (payload->service, validCount, valid);
759 json_t *collectionJson = json_object ();
760 json_t *jcount = json_integer ((json_int_t)count);
761 json_t *members = json_array ();
764 if (!collectionJson) {
769 json_decref (collectionJson);
773 json_object_set (collectionJson,
"Members@odata.count", jcount);
774 json_decref (jcount);
775 for (i = 0; i < count; i++) {
776 json_array_append (members, payloads[i]->json);
777 cleanupPayload (payloads[i]);
780 json_object_set (collectionJson,
"Members", members);
781 json_decref (members);
783 ret = createRedfishPayload (collectionJson, service);
788json_object_get_by_index (
796 iter = json_object_iter (json);
797 for (i = 0; i < index; i++) {
798 iter = json_object_iter_next (json, iter);
808 return json_object_iter_value (iter);
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EDKII_JSON_TYPE EFIAPI JsonGetType(IN EDKII_JSON_VALUE JsonValue)
char * strdup(const char *str)
long long strtoll(const char *nptr, char **endptr, int base)