Пример #1
0
const char *get_res_type(struct things_resource_s *res, int index)
{
	const char *resourcType = OCGetResourceTypeName((OCResourceHandle) res->resource_handle, index);
	THINGS_LOG_D(TAG, "=====>  RH : %x cnt : %d", res->resource_handle, index);
	THINGS_LOG_D(TAG, "=====>  RT : %s ", resourcType);

	return resourcType;
}
Пример #2
0
void /*OCRepPayload */ *create_payload(struct things_resource_s *res, char *query)
{
	//    To provide identical pattern for handling the result
	//       allocating new memory for the payload to delete later
	OCRepPayload *payload = OCRepPayloadClone((OCRepPayload *)(res->rep->payload));
	THINGS_LOG_D(TAG, "Query : %s", query);

	if (query == NULL || (query != NULL && strlen(query) < 1)
		|| strstr(query, OIC_INTERFACE_ACTUATOR) != NULL || strstr(query, OIC_INTERFACE_SENSOR) != NULL) {
		THINGS_LOG_D(TAG, "Including properties & its values only");
		// Do nothing..
	} else if (strstr(query, OIC_INTERFACE_BASELINE)) {
		THINGS_LOG_D(TAG, "Including all the properties & its values");

		uint8_t index = 0;
		uint8_t number_of_interfaces = 0;
		uint8_t number_of_resource_type = 0;

		OCGetNumberOfResourceInterfaces((OCResourceHandle) res->resource_handle, &number_of_interfaces);

		THINGS_LOG_D(TAG, "@@  IF # : %d ", number_of_interfaces);
		//2.a Find interface type(s) & insert it/them into payload
		for (index = 0; index < number_of_interfaces; index++) {
			const char *interface = OCGetResourceInterfaceName((OCResourceHandle) res->resource_handle, index);
			THINGS_LOG_D(TAG, "=====>  IF : %s ", interface);
			OCRepPayloadAddInterface(payload, interface);
		}

		//3.a Find resource type & insert it into payload
		OCGetNumberOfResourceTypes((OCResourceHandle) res->resource_handle, &number_of_resource_type);
		THINGS_LOG_D(TAG, "@@  RT # : %d ", number_of_resource_type);
		for (index = 0; index < number_of_resource_type; index++) {
			const char *rt = OCGetResourceTypeName((OCResourceHandle) res->resource_handle, index);
			THINGS_LOG_D(TAG, "=====>  RT : %s ", rt);
			OCRepPayloadAddResourceType(payload, rt);
		}
	} else if (strstr(query, OC_RSRVD_INTERFACE_BATCH)) {
		THINGS_LOG_D(TAG, "Batch only supported by Collection Resource");
	} else if (strstr(query, OC_RSRVD_INTERFACE_LL)) {
		THINGS_LOG_D(TAG, "Link-List only supported by Collection Resource");
	} else {
		THINGS_LOG_D(TAG, "Not supporting Interface type : %s", query);
	}

	return payload;
}
Пример #3
0
bool is_supporting_resource_type(struct things_resource_s *res, char *query)
{
	THINGS_LOG_D(TAG, THINGS_FUNC_ENTRY);
	bool result = false;
	uint8_t number_of_resource_type = 0;

	OCGetNumberOfResourceTypes((OCResourceHandle) res->resource_handle, &number_of_resource_type);

	THINGS_LOG_D(TAG, "@@  RT # : %d ", number_of_resource_type);
	//2.a Find resource type(s) & insert it/them into payload
	for (uint8_t index = 0; index < number_of_resource_type; index++) {
		const char *rtype = OCGetResourceTypeName((OCResourceHandle) res->resource_handle, index);

		// THINGS_LOG_D(TAG, "Supporting rtype :: %s(%s)", query, rtype);
		if (strstr(query, rtype) != NULL) {
			// THINGS_LOG_D(TAG, "Confirm rtype.");
			result = true;
			break;
		}
	}
	THINGS_LOG_D(TAG, THINGS_FUNC_EXIT);
	return result;
}
Пример #4
0
static OCStackResult
ValidateQuery (const char *query, OCResourceHandle resource,
               OCStackIfTypes *ifParam, char **rtParam)
{
    uint8_t numFields = 0;
    uint8_t numParam;

    //TODO: Query and URL validation is being done for virtual resource case
    // using ValidateUrlQuery function. We should be able to merge it with this
    // function.
    OC_LOG(INFO, TAG, "Entering ValidateQuery");

    if (!query)
    {
        return OC_STACK_ERROR;
    }

    if (!ifParam || !rtParam)
    {
        return OC_STACK_INVALID_PARAM;
    }

    if (!(*query))
    {
        // Query string is empty
        OC_LOG(INFO, TAG, "Empty query string, use default IF and RT");
        *ifParam = STACK_IF_DEFAULT;
        *rtParam = (char *) OCGetResourceTypeName (resource, 0);
        return OC_STACK_OK;
    }

    // Break the query string to validate it and determine IF and RT parameters
    // Validate there are atmost 2 parameters in string and that one is 'if' and other 'rt'
    // separated by token '&' or ';'. Stack will accept both the versions.

    char *endStr, *ifPtr = NULL, *rtPtr = NULL;
    char *token = strtok_r ((char *)query, OC_QUERY_SEPARATOR , &endStr);

    // External loop breaks query string into fields using the & separator
    while (token != NULL)
    {
        numFields++;
        char *endToken;
        char *innerToken = strtok_r (token, "=", &endToken);
        numParam = 0;

        // Internal loop parses the field to extract values (parameters) assigned to each field
        while (innerToken != NULL)
        {
            numParam++;
            if (strncmp (innerToken, OC_RSRVD_INTERFACE, sizeof(OC_RSRVD_INTERFACE)) == 0)
            {
                // Determine the value of IF parameter
                innerToken = strtok_r (NULL, "=", &endToken);
                ifPtr = innerToken;
            }
            else if (strcmp (innerToken, OC_RSRVD_RESOURCE_TYPE) == 0)
            {
                // Determine the value of RT parameter
                innerToken = strtok_r (NULL, "=", &endToken);
                rtPtr = innerToken;
            }
            else
            {
                innerToken = strtok_r (NULL, "=", &endToken);
            }
        }
        if (numParam != NUM_PARAM_IN_QUERY)
        {
            // Query parameter should be of the form if=<string>. String should not have & or =
            return OC_STACK_INVALID_QUERY;
        }
        token = strtok_r (NULL, OC_QUERY_SEPARATOR, &endStr);
    }

    if (numFields > NUM_FIELDS_IN_QUERY)
    {
        // current release supports one IF value, one RT value and no other params
        return OC_STACK_INVALID_QUERY;
    }

    if (ifPtr)
    {
        if (CheckIFParamSupport((OCResource *)resource, ifPtr) != OC_STACK_OK)
        {
            return OC_STACK_INVALID_QUERY;
        }
        if (strcmp (ifPtr, OC_RSRVD_INTERFACE_DEFAULT) == 0)
        {
            *ifParam = STACK_IF_DEFAULT;
        }
        else if (strcmp (ifPtr, OC_RSRVD_INTERFACE_LL) == 0)
        {
            *ifParam = STACK_IF_LL;
        }
        else if (strcmp (ifPtr, OC_RSRVD_INTERFACE_BATCH) == 0)
        {
            *ifParam = STACK_IF_BATCH;
        }
        else if (strcmp (ifPtr, OC_RSRVD_INTERFACE_GROUP) == 0)
        {
            *ifParam = STACK_IF_GROUP;
        }
        else
        {
            return OC_STACK_ERROR;
        }
    }
    else
    {
        // IF not specified in query, use default IF
        *ifParam = STACK_IF_DEFAULT;
    }

    if (rtPtr)
    {
        if (CheckRTParamSupport((OCResource *)resource, rtPtr) == OC_STACK_OK)
        {
            *rtParam = rtPtr;
        }
        else
        {
            return OC_STACK_INVALID_QUERY;
        }
    }
    else
    {
        // RT not specified in query. Use the first resource type for the resource as default.
        *rtParam = (char *) OCGetResourceTypeName (resource, 0);
    }
    OC_LOG_V(INFO, TAG, "Query params: IF = %d, RT = %s", *ifParam, *rtParam);

    return OC_STACK_OK;
}