Commit a3579380 authored by koushik.girijala's avatar koushik.girijala Committed by Nathan Heldt-Sheller

Fix for connecting to TCP IPv6 socket

Change-Id: I87700d134585a6088e21e5f33d5049ffd62f4fa8
Signed-off-by: default avatarkoushik.girijala <g.koushik@samsung.com>
parent 2affdfd8
......@@ -869,6 +869,11 @@ static OCStackApplicationResult handleCloudSignInResponse(void *ctx,
OicCloud_t *cloud = (OicCloud_t *)ctx;
char *ipv6End = NULL;
char *percentChar = NULL;
char *cis = NULL;
char *ipv6Intf = NULL;
VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_DELETE_TRANSACTION);
VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
......@@ -916,6 +921,31 @@ static OCStackApplicationResult handleCloudSignInResponse(void *ctx,
if (OC_CLOUD_SIGNIN == cloud->stat)
{
// find the IPv6 address end bracket
ipv6End = strchr(cloud->cis, ']');
if (NULL != ipv6End)
{
ipv6Intf = strchr(cloud->cis, '%');
if (ipv6Intf == NULL)
{
// find the interface name from UDP address of sender
percentChar = strchr(response->devAddr.addr, '%');
size_t ifLen = strlen(percentChar);
size_t addrLen = strlen(cloud->cis);
size_t cisLen = addrLen + ifLen + 3;
// fill the cloud uri with interface name inserted
cis = (char *)OICMalloc(sizeof(char) * cisLen);
OICStrcpy(cis, ipv6End - cloud->cis + 1, cloud->cis);
OICStrcat(cis, cisLen, "%25");
OICStrcat(cis, cisLen, percentChar + 1);
OICStrcat(cis, cisLen, ipv6End);
OICFree(cloud->cis);
cloud->cis = cis;
}
}
OCThreadResult_t res = OC_THREAD_SUCCESS;
res = oc_thread_new(&cloud->pid, CloudTokenRefresh, cloud);
if (OC_THREAD_SUCCESS != res)
......@@ -1141,6 +1171,12 @@ static OCStackApplicationResult handleCloudSignUpResponse(void *ctx,
OCStackApplicationResult ret = OC_STACK_DELETE_TRANSACTION;
OicCloud_t *cloud = (OicCloud_t *)ctx;
char *ipv6End = NULL;
char *percentChar = NULL;
char *redirectUri = NULL;
char *cis = NULL;
char *ipv6Intf = NULL;
VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_DELETE_TRANSACTION);
......@@ -1201,6 +1237,31 @@ static OCStackApplicationResult handleCloudSignUpResponse(void *ctx,
if (ValidCloud(cloud))
{
// find the IPv6 address end bracket
ipv6End = strchr(cloud->redirectUri, ']');
if (NULL != ipv6End)
{
ipv6Intf = strchr(cloud->redirectUri, '%');
if (ipv6Intf == NULL)
{
// find the interface name from UDP address of sender
percentChar = strchr(response->devAddr.addr, '%');
size_t ifLen = strlen(percentChar);
size_t addrLen = strlen(cloud->redirectUri);
size_t uriLen = addrLen + ifLen + 3;
// fill the cloud uri with interface name inserted
redirectUri = (char *)OICMalloc(sizeof(char) * uriLen);
OICStrcpy(redirectUri, ipv6End - cloud->redirectUri + 1, cloud->redirectUri);
OICStrcat(redirectUri, uriLen, "%25");
OICStrcat(redirectUri, uriLen, percentChar + 1);
OICStrcat(redirectUri, uriLen, ipv6End);
OICFree(cloud->redirectUri);
cloud->redirectUri = redirectUri;
}
}
if (!strCopy(cloud->redirectUri, &cloud->cis))
{
OIC_LOG_V(ERROR, TAG, "%s: copy redirect uri", __func__);
......@@ -1211,6 +1272,31 @@ static OCStackApplicationResult handleCloudSignUpResponse(void *ctx,
}
else
{
// find the IPv6 address end bracket
ipv6End = strchr(cloud->cis, ']');
if (NULL != ipv6End)
{
ipv6Intf = strchr(cloud->cis, '%');
if (ipv6Intf == NULL)
{
// find the interface name from UDP address of sender
percentChar = strchr(response->devAddr.addr, '%');
size_t ifLen = strlen(percentChar);
size_t addrLen = strlen(cloud->cis);
size_t uriLen = addrLen + ifLen + 3;
// fill the cloud uri with interface name inserted
cis = (char *)OICMalloc(sizeof(char) * uriLen);
OICStrcpy(cis, ipv6End - cloud->cis + 1, cloud->cis);
OICStrcat(cis, uriLen, "%25");
OICStrcat(cis, uriLen, percentChar + 1);
OICStrcat(cis, uriLen, ipv6End);
OICFree(cloud->cis);
cloud->cis = cis;
}
}
OIC_LOG_V(ERROR, TAG, "%s: cannot redirect", __func__);
}
}
......
......@@ -38,6 +38,7 @@
#include "resourcemanager.h"
#include "cloud/cloudresource.h"
#include "cloud/auth.h"
#include "oic_string.h"
#define TAG "OIC_CLOUD_RESOURCE"
......@@ -168,6 +169,10 @@ static OCEntityHandlerResult HandleCloudPostRequest(OCEntityHandlerRequest *ehRe
OCRepPayload *payload = NULL;
bool isDeviceOwned = false;
OicCloud_t *xCloud = NULL;
char *ipv6End = NULL;
char *percentChar = NULL;
char *cis = NULL;
char *ipv6Intf = NULL;
VERIFY_NOT_NULL(TAG, ehRequest, ERROR);
VERIFY_NOT_NULL(TAG, ehRequest->payload, ERROR);
......@@ -222,6 +227,31 @@ static OCEntityHandlerResult HandleCloudPostRequest(OCEntityHandlerRequest *ehRe
goto exit;
}
// find the IPv6 address end bracket
ipv6End = strchr(newCloud->cis, ']');
if (NULL != ipv6End)
{
ipv6Intf = strchr(newCloud->cis, '%');
if (ipv6Intf == NULL)
{
// find the interface name from UDP address of sender
percentChar = strchr(ehRequest->devAddr.addr, '%');
size_t ifLen = strlen(percentChar);
size_t addrLen = strlen(newCloud->cis);
size_t cisLen = addrLen + ifLen + 3;
// fill the cloud uri with interface name inserted
cis = (char *)OICMalloc(sizeof(char) * cisLen);
OICStrcpy(cis, ipv6End - newCloud->cis + 1, newCloud->cis);
OICStrcat(cis, cisLen, "%25");
OICStrcat(cis, cisLen, percentChar + 1);
OICStrcat(cis, cisLen, ipv6End);
OICFree(newCloud->cis);
newCloud->cis = cis;
}
}
xCloud = CloudFind(gCloud, newCloud);
if (xCloud)
{
......
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