*/
static OCStackResult ExtractFiltersFromQuery(char *query, char **filterOne, char **filterTwo)
{
-
char *key = NULL;
char *value = NULL;
+ char *queryDup = NULL;
char *restOfQuery = NULL;
+ char *keyValuePair = NULL;
int numKeyValuePairsParsed = 0;
*filterOne = NULL;
*filterTwo = NULL;
- OIC_LOG_V(INFO, TAG, "Extracting params from %s", query);
+ queryDup = OICStrdup(query);
+ if (NULL == queryDup)
+ {
+ OIC_LOG_V(ERROR, TAG, "Creating duplicate string failed!");
+ return OC_STACK_NO_MEMORY;
+ }
+
+ OIC_LOG_V(INFO, TAG, "Extracting params from %s", queryDup);
- if (strnlen(query, MAX_QUERY_LENGTH) >= MAX_QUERY_LENGTH)
+ OCStackResult eCode = OC_STACK_INVALID_QUERY;
+ if (strnlen(queryDup, MAX_QUERY_LENGTH) >= MAX_QUERY_LENGTH)
{
OIC_LOG(ERROR, TAG, "Query exceeds maximum length.");
- return OC_STACK_INVALID_QUERY;
+ goto exit;
}
- char *keyValuePair = strtok_r (query, OC_QUERY_SEPARATOR, &restOfQuery);
+ keyValuePair = strtok_r (queryDup, OC_QUERY_SEPARATOR, &restOfQuery);
while(keyValuePair)
{
if (numKeyValuePairsParsed >= 2)
{
OIC_LOG(ERROR, TAG, "More than 2 queries params in URI.");
- return OC_STACK_INVALID_QUERY;
+ goto exit;
}
key = strtok_r(keyValuePair, OC_KEY_VALUE_DELIMITER, &value);
if (!key || !value)
{
- return OC_STACK_INVALID_QUERY;
+ goto exit;
}
else if (strncasecmp(key, OC_RSRVD_INTERFACE, sizeof(OC_RSRVD_INTERFACE) - 1) == 0)
{
else
{
OIC_LOG_V(ERROR, TAG, "Unsupported query key: %s", key);
- return OC_STACK_INVALID_QUERY;
+ goto exit;
}
++numKeyValuePairsParsed;
keyValuePair = strtok_r(NULL, OC_QUERY_SEPARATOR, &restOfQuery);
}
+ if (*filterOne)
+ {
+ *filterOne = OICStrdup(*filterOne);
+ if (NULL == *filterOne)
+ {
+ OIC_LOG_V(ERROR, TAG, "Creating duplicate string failed!");
+ eCode = OC_STACK_NO_MEMORY;
+ goto exit;
+ }
+ }
+
+ if (*filterTwo)
+ {
+ *filterTwo = OICStrdup(*filterTwo);
+ if (NULL == *filterTwo)
+ {
+ OIC_LOG_V(ERROR, TAG, "Creating duplicate string failed!");
+ OICFree(*filterOne);
+ eCode = OC_STACK_NO_MEMORY;
+ goto exit;
+ }
+ }
+
+ OICFree(queryDup);
OIC_LOG_V(INFO, TAG, "Extracted params if: %s and rt: %s.", *filterOne, *filterTwo);
return OC_STACK_OK;
+
+exit:
+ *filterOne = NULL;
+ *filterTwo = NULL;
+ OICFree(queryDup);
+ return eCode;
}
static OCVirtualResources GetTypeOfVirtualURI(const char *uriInRequest)
{
OIC_LOG_V(ERROR, TAG, "Error (%d) parsing query.", discoveryResult);
}
- if (interfaceQueryAllocated)
+
+ if (interfaceQuery)
{
OICFree(interfaceQuery);
}
+
+ if (resourceTypeQuery)
+ {
+ OICFree(resourceTypeQuery);
+ }
}
else if (virtualUriInRequest == OC_DEVICE_URI)
{