OCStackResult OCParsePayload(OCPayload** outPayload, OCPayloadType payloadType,
                             const uint8_t* payload, size_t payloadSize)
{
    CborParser parser;
    CborValue rootValue;
    bool err = false;

    OC_LOG_V(INFO, TAG, "CBOR Parsing size: %d", payloadSize);
    if((err = cbor_parser_init(payload, payloadSize, 0, &parser, &rootValue)) != false)
    {
        OC_LOG_V(ERROR, TAG, "CBOR Parser init failed: %d", err);
        return OC_STACK_ERROR;
    }

    OCStackResult result = OC_STACK_ERROR;
    switch(payloadType)
    {
    case PAYLOAD_TYPE_DISCOVERY:
        result = OCParseDiscoveryPayload(outPayload, &rootValue);
        break;
    case PAYLOAD_TYPE_DEVICE:
        result = OCParseDevicePayload(outPayload, &rootValue);
        break;
    case PAYLOAD_TYPE_PLATFORM:
        result = OCParsePlatformPayload(outPayload, &rootValue);
        break;
    case PAYLOAD_TYPE_REPRESENTATION:
        result = OCParseRepPayload(outPayload, &rootValue);
        break;
    case PAYLOAD_TYPE_PRESENCE:
        result = OCParsePresencePayload(outPayload, &rootValue);
        break;
    case PAYLOAD_TYPE_SECURITY:
        result = OCParseSecurityPayload(outPayload, &rootValue);
        break;
    case PAYLOAD_TYPE_RD:
        result = OCRDCborToPayload(&rootValue, outPayload);
        break;
    default:
        OC_LOG_V(ERROR, TAG, "ParsePayload Type default: %d", payloadType);
        result = OC_STACK_ERROR;
        break;
    }

    if(result != OC_STACK_OK)
    {
        OC_LOG_V(INFO, TAG, "Finished parse payload, result is %d", result);
    }

    return result;
}
Example #2
0
OCStackResult OCParsePayload(OCPayload **outPayload, OCPayloadType payloadType,
        const uint8_t *payload, size_t payloadSize)
{
    OCStackResult result = OC_STACK_MALFORMED_RESPONSE;
    CborError err;

    VERIFY_PARAM_NON_NULL(TAG, outPayload, "Conversion of outPayload failed");
    VERIFY_PARAM_NON_NULL(TAG, payload, "Invalid cbor payload value");

    OIC_LOG_V(INFO, TAG, "CBOR Parsing size: %zu", payloadSize);

    CborParser parser;
    CborValue rootValue;

    err = cbor_parser_init(payload, payloadSize, 0, &parser, &rootValue);
    VERIFY_CBOR_SUCCESS(TAG, err, "Failed initializing init value")

    switch(payloadType)
    {
        case PAYLOAD_TYPE_DISCOVERY:
            result = OCParseDiscoveryPayload(outPayload, &rootValue);
            break;
        case PAYLOAD_TYPE_DEVICE:
            result = OCParseDevicePayload(outPayload, &rootValue);
            break;
        case PAYLOAD_TYPE_PLATFORM:
            result = OCParsePlatformPayload(outPayload, &rootValue);
            break;
        case PAYLOAD_TYPE_REPRESENTATION:
            result = OCParseRepPayload(outPayload, &rootValue);
            break;
        case PAYLOAD_TYPE_PRESENCE:
            result = OCParsePresencePayload(outPayload, &rootValue);
            break;
        case PAYLOAD_TYPE_SECURITY:
            result = OCParseSecurityPayload(outPayload, &rootValue);
            break;
        case PAYLOAD_TYPE_RD:
            result = OCRDCborToPayload(&rootValue, outPayload);
            break;
        default:
            OIC_LOG_V(ERROR, TAG, "ParsePayload Type default: %d", payloadType);
            result = OC_STACK_INVALID_PARAM;
            break;
    }

    OIC_LOG_V(INFO, TAG, "Finished parse payload, result is %d", result);

exit:
    return result;
}