示例#1
0
static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest * ehRequest)
{
    char* jsonStr = NULL;
    OCEntityHandlerResult ehRet = OC_EH_OK;

    OIC_LOG (DEBUG, TAG, "Doxm EntityHandle processing GET request");

    //Checking if Get request is a query.
    if(ehRequest->query)
    {
        OIC_LOG (DEBUG, TAG, "HandleDoxmGetRequest processing query");
        if(!ValidateQuery(ehRequest->query))
        {
            ehRet = OC_EH_ERROR;
        }
    }

    /*
     * For GET or Valid Query request return doxm resource json payload.
     * For non-valid query return NULL json payload.
     * A device will 'always' have a default Doxm, so BinToDoxmJSON will
     * return valid doxm resource json.
     */

    jsonStr = (ehRet == OC_EH_OK) ? BinToDoxmJSON(gDoxm) : NULL;

    // Send response payload to request originator
    if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, jsonStr))
    {
        OIC_LOG (ERROR, TAG, "SendSRMResponse failed in HandleDoxmGetRequest");
    }

    OICFree(jsonStr);

    return ehRet;
}
示例#2
0
OCStackResult DefaultCollectionEntityHandler (OCEntityHandlerFlag flag,
                                              OCEntityHandlerRequest *ehRequest)
{
    if (!ehRequest || !ehRequest->query)
    {
        return OC_STACK_INVALID_PARAM;
    }

    OC_LOG_V(INFO, TAG, "DefaultCollectionEntityHandler with query %s", ehRequest->query);

    if (flag != OC_REQUEST_FLAG)
    {
        return OC_STACK_ERROR;
    }

    OCStackIfTypes ifQueryParam = STACK_IF_INVALID;
    char *rtQueryParam = NULL;
    OCStackResult result = ValidateQuery (ehRequest->query,
                                          ehRequest->resource, &ifQueryParam, &rtQueryParam);

    if (result != OC_STACK_OK)
    {
        return result;
    }

    switch (ehRequest->method)
    {
        case OC_REST_GET:
            switch (ifQueryParam)
            {
                case STACK_IF_DEFAULT:
                    // Get attributes of collection resource and properties of contained resources
                    // M1 release does not support attributes for collection resource, so the GET
                    // operation is same as the GET on LL interface.
                    OC_LOG(INFO, TAG, "STACK_IF_DEFAULT");
                    return HandleLinkedListInterface(ehRequest, STACK_RES_DISCOVERY_NOFILTER, NULL);

                case STACK_IF_LL:
                    OC_LOG(INFO, TAG, "STACK_IF_LL");
                    return HandleLinkedListInterface(ehRequest, STACK_RES_DISCOVERY_NOFILTER, NULL);

                case STACK_IF_BATCH:
                    OC_LOG(INFO, TAG, "STACK_IF_BATCH");
                    ((OCServerRequest *)ehRequest->requestHandle)->ehResponseHandler =
                                                                            HandleAggregateResponse;

                    ((OCServerRequest *)ehRequest->requestHandle)->numResponses =
                            GetNumOfResourcesInCollection((OCResource *)ehRequest->resource) + 1;

                    return HandleBatchInterface(ehRequest);

                case STACK_IF_GROUP:
                    return BuildCollectionGroupActionCBORResponse(OC_REST_GET/*flag*/,
                            (OCResource *) ehRequest->resource, ehRequest);

                default:
                    return OC_STACK_ERROR;
            }

        case OC_REST_PUT:
            switch (ifQueryParam)
            {
                case STACK_IF_DEFAULT:
                    // M1 release does not support PUT on default interface
                    return OC_STACK_ERROR;

                case STACK_IF_LL:
                    // LL interface only supports GET
                    return OC_STACK_ERROR;

                case STACK_IF_BATCH:
                    ((OCServerRequest *)ehRequest->requestHandle)->ehResponseHandler =
                                                                            HandleAggregateResponse;
                    ((OCServerRequest *)ehRequest->requestHandle)->numResponses =
                            GetNumOfResourcesInCollection((OCResource *)ehRequest->resource) + 1;
                    return HandleBatchInterface(ehRequest);

                case STACK_IF_GROUP:
                    OC_LOG(INFO, TAG, "IF_COLLECTION PUT with request ::\n");
                    OC_LOG_PAYLOAD(INFO, ehRequest->payload);
                    return BuildCollectionGroupActionCBORResponse(OC_REST_PUT/*flag*/,
                            (OCResource *) ehRequest->resource, ehRequest);

                default:
                    return OC_STACK_ERROR;
            }

        case OC_REST_POST:
            switch (ifQueryParam)
            {
                case STACK_IF_DEFAULT:
                    // M1 release does not support POST on default interface
                    return OC_STACK_ERROR;

                case STACK_IF_LL:
                    // LL interface only supports GET
                    return OC_STACK_ERROR;

                case STACK_IF_BATCH:
                    ((OCServerRequest *)ehRequest->requestHandle)->ehResponseHandler =
                                                                            HandleAggregateResponse;
                    ((OCServerRequest *)ehRequest->requestHandle)->numResponses =
                            GetNumOfResourcesInCollection((OCResource *)ehRequest->resource) + 1;
                    return HandleBatchInterface(ehRequest);

                case STACK_IF_GROUP:
                    OC_LOG(INFO, TAG, "IF_COLLECTION POST with request ::\n");
                    OC_LOG_PAYLOAD(INFO, ehRequest->payload);
                    return BuildCollectionGroupActionCBORResponse(OC_REST_POST/*flag*/,
                            (OCResource *) ehRequest->resource, ehRequest);

                default:
                    return OC_STACK_ERROR;
            }

        case OC_REST_DELETE:
            // TODO implement DELETE accordingly to the desired behavior
            return OC_STACK_ERROR;

        default:
            return OC_STACK_ERROR;
    }
}