Commit 344a35de authored by Veeraj Khokale's avatar Veeraj Khokale Committed by Uze Choi

Fix for Jira [IOT-1424]

1. Modified CHPGetOCContentType() and CHPGetOptionID() to
internally duplicate the string parameter passed and
work on this copy, thereby maintaining const correctness.
2. Also modified unit test to pass "application/cbor" as
http content type.

Change-Id: Ic0ea5704ddff20dc67086296e54775ef8d677d69
Signed-off-by: default avatarVeeraj Khokale <veeraj.sk@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13013Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarAshok Babu Channa <ashok.channa@samsung.com>
(cherry picked from commit cac65bc7)
Reviewed-on: https://gerrit.iotivity.org/gerrit/15275Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarPhil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: default avatarKevin Kane <kkane@microsoft.com>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
parent 7fedb4f4
......@@ -29,38 +29,47 @@
#define TAG "CHPMap"
int CHPGetOptionID(const char *httpOptionName)
int CHPGetOptionID(const char *httpOptionNameStr)
{
if (!httpOptionName)
if (!httpOptionNameStr)
{
OIC_LOG(ERROR, TAG, "HTTP option name is NULL");
return 0;
}
OICStringToLower((char *)httpOptionName);
char *httpOptionName = OICStrdup(httpOptionNameStr);
if (NULL == httpOptionName)
{
OIC_LOG(ERROR, TAG, "Could not duplicate HTTP option name");
return 0;
}
OICStringToLower(httpOptionName);
int ret = 0;
if (0 == strcmp(httpOptionName, HTTP_OPTION_CACHE_CONTROL) ||
0 == strcmp(httpOptionName, HTTP_OPTION_EXPIRES))
{
return COAP_OPTION_MAXAGE;
ret = COAP_OPTION_MAXAGE;
}
else if (0 == strcmp(httpOptionName, HTTP_OPTION_IF_MATCH))
{
return COAP_OPTION_IF_MATCH;
ret = COAP_OPTION_IF_MATCH;
}
else if (0 == strcmp(httpOptionName, HTTP_OPTION_IF_NONE_MATCH))
{
return COAP_OPTION_IF_NONE_MATCH;
ret = COAP_OPTION_IF_NONE_MATCH;
}
else if (0 == strcmp(httpOptionName, HTTP_OPTION_ETAG))
{
return COAP_OPTION_ETAG;
ret = COAP_OPTION_ETAG;
}
else
{
OIC_LOG_V(ERROR, TAG, "No Mapping found for %s", httpOptionName);
}
return 0;
OICFree(httpOptionName);
return ret;
}
OCStackResult CHPGetOCCode(const HttpResponseResult_t httpCode, const OCMethod method,
......@@ -156,22 +165,31 @@ OCStackResult CHPGetOCOption(const HttpHeaderOption_t *httpOption, OCHeaderOptio
return OC_STACK_OK;
}
OCPayloadFormat CHPGetOCContentType(const char *httpContentType)
OCPayloadFormat CHPGetOCContentType(const char *httpContentTypeStr)
{
OIC_LOG_V(DEBUG, TAG, "%s IN", __func__);
OICStringToLower((char *)httpContentType);
char *httpContentType = OICStrdup(httpContentTypeStr);
if (NULL == httpContentType)
{
OIC_LOG(ERROR, TAG, "Could not duplicate HTTP content type");
return OC_FORMAT_UNSUPPORTED;
}
OICStringToLower(httpContentType);
OCPayloadFormat ret = OC_FORMAT_UNSUPPORTED;
if (strstr(httpContentType, CBOR_CONTENT_TYPE))
{
return OC_FORMAT_CBOR;
ret = OC_FORMAT_CBOR;
}
else if (strstr(httpContentType, JSON_CONTENT_TYPE))
{
return OC_FORMAT_JSON;
ret = OC_FORMAT_JSON;
}
OICFree(httpContentType);
OIC_LOG_V(DEBUG, TAG, "%s OUT", __func__);
return OC_FORMAT_UNSUPPORTED;
return ret;
}
OCStackResult CHPGetHttpMethod(const OCMethod method, HttpMethod_t *httpMethod)
......
......@@ -102,8 +102,7 @@ TEST_F(CoApHttpTest, CHPGetOCOption)
TEST_F(CoApHttpTest, CHPGetOCContentType)
{
HttpResponse_t httpResponse;
//char *httpContentType = "OC_FORMAT_CBOR";
char *httpContentType = "CBOR_CONTENT_TYPE";
const char *httpContentType = CBOR_CONTENT_TYPE;
EXPECT_EQ(OC_FORMAT_CBOR, (CHPGetOCContentType(httpContentType)));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment