Fixes to send the correct sender info when a presence notification is sent
authorSashi Penta <sashi.kumar.penta@intel.com>
Thu, 25 Dec 2014 08:05:48 +0000 (00:05 -0800)
committerSashi Penta <sashi.kumar.penta@intel.com>
Thu, 25 Dec 2014 08:12:36 +0000 (00:12 -0800)
Change-Id: Id903483a5f329692fc57275076af2c36d0d1adf0
Signed-off-by: Sashi Penat <sashi.kumar.penta@intel.com>
resource/csdk/stack/src/ocstack.c

index 1108663..1a09e35 100644 (file)
@@ -238,6 +238,17 @@ OCStackResult CAToOCStackResult(CAResponseResult_t caCode)
     return ret;
 }
 
+// update response.addr appropriately from endPoint.addressInfo
+void UpdateResponseAddr(OCClientResponse *response, const CARemoteEndpoint_t* endPoint)
+{
+    struct sockaddr_in sa;
+    inet_pton(AF_INET, endPoint->addressInfo.IP.ipAddress, &(sa.sin_addr));
+    sa.sin_port = htons(endPoint->addressInfo.IP.port);
+    static OCDevAddr address;
+    memcpy((void*)&address.addr, &(sa), sizeof(sa));
+    response->addr = &address;
+}
+
 void HandlePresenceResponse(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_t* responseInfo)
 {
     OCStackApplicationResult cbResult = OC_STACK_DELETE_TRANSACTION;
@@ -247,6 +258,8 @@ void HandlePresenceResponse(const CARemoteEndpoint_t* endPoint, const CAResponse
     char * bufRes = responseInfo->info.payload;
     OCClientResponse *response = (OCClientResponse *) OCMalloc(sizeof(OCClientResponse));
 
+    UpdateResponseAddr(response, endPoint);
+
     if(!bufRes)
     {
         goto exit;
@@ -321,16 +334,10 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_
     {
         OC_LOG(INFO, TAG, PCF("Calling into application address space"));
         OCClientResponse response;
-        struct sockaddr_in sa;
 
-        inet_pton(AF_INET, endPoint->addressInfo.IP.ipAddress, &(sa.sin_addr));
-        sa.sin_port = htons(endPoint->addressInfo.IP.port);
-        static OCDevAddr address;
-        memcpy((void*)&address.addr, &(sa), sizeof(sa));
-        response.addr = &address;
-        #ifdef CA_INT
+        UpdateResponseAddr(&response, endPoint);
         response.connType = endPoint->connectivityType;
-        #endif
+
         response.result = CAToOCStackResult(responseInfo->result);
         response.resJSONPayload = (unsigned char*)responseInfo->info.payload;
         response.numRcvdVendorSpecificHeaderOptions = 0;