Update catcpserver.c 23/201723/1
authorh.marappa@samsung.com <h.marappa@samsung.com>
Wed, 13 Mar 2019 14:03:43 +0000 (19:33 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 19 Mar 2019 05:03:25 +0000 (14:03 +0900)
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/commit/40206f09f18e1d2f01efe3f449a24f69703e7718
(cherry picked from 40206f09f18e1d2f01efe3f449a24f69703e7718)

Change-Id: I28bf6c8d266ccd4334aea89f58431a704625c588
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index d65d266abd86c6cc90c7ad6b268a15587af69d7f..c8c87c3601e4534b33394bbad1f97c7e1d98f74b 100644 (file)
@@ -848,7 +848,8 @@ static CAResult_t CATCPConvertNameToAddr(int family, const char *host, uint16_t
     return CA_STATUS_OK;
 }
 
-static int __get_status_code_from_response(char * response) {
+#if defined(__TIZEN__)
+static int CAGetHTTPStatusCode(char * response) {
     char *resp, *code_plus, *ptrSave;
     int ret = -1;
 
@@ -860,6 +861,7 @@ static int __get_status_code_from_response(char * response) {
     free(resp);
     return ret;
 }
+#endif
 
 static CAResult_t CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem)
 {
@@ -868,11 +870,6 @@ static CAResult_t CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem)
     OIC_LOG_V(INFO, TAG, "try to connect with [%s:%u]",
               svritem->sep.endpoint.addr, svritem->sep.endpoint.port);
 
-#if defined(__TIZEN__)
-    char *proxy_addr = CAGetCloudAddressForProxy();
-    OIC_LOG_V(INFO, TAG, "Proxy : '%s'", proxy_addr ? proxy_addr : "(nil)");
-#endif
-
     // #1. create tcp socket.
     int fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
     if (-1 == fd)
@@ -931,19 +928,20 @@ static CAResult_t CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem)
     // #5. Send HTTP CONNECT to proxy if proxy
 
     const char *cloud_address = CAGetCloudAddressForProxy();
+    OIC_LOG_V(INFO, TAG, "Proxy : '%s'", cloud_address ? cloud_address : "(nil)");
 
-    if(cloud_address && *cloud_address) {
+    if(cloud_address && *cloud_address)
+    {
         char message[4096];
         int len = sprintf(message,
                 "CONNECT %s HTTP/1.1\r\n"
                 "Host: %s\r\n\r\n", cloud_address, cloud_address
         );
 
-
-
         ssize_t l = send(fd, message, len, 0);
-        if(l != len) {
-            OIC_LOG_V(INFO, TAG, "failed to send HTTP CONNECT data (expected %d bytes, ret %d)", len, l);
+        if(l != len)
+       {
+            OIC_LOG_V(ERROR, TAG, "failed to send HTTP CONNECT data (expected %d bytes, ret %d)", len, l);
             close(fd);
             svritem->fd = -1;
             return CA_SOCKET_OPERATION_FAILED;
@@ -960,11 +958,12 @@ static CAResult_t CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem)
         OIC_LOG_V(INFO, TAG, "Received data : '%s'", message);
         OIC_LOG_V(INFO, TAG, "Received len = %d", l);
 
-        int status_code = __get_status_code_from_response(message);
+        int status_code = CAGetHTTPStatusCode(message);
 
         OIC_LOG_V(INFO, TAG, "HTTP status_code : %d", status_code);
-        if(status_code < 200 || status_code > 299) {
-            OIC_LOG_V(ERROR, TAG, "Error, __get_status_code_from_response => %d", status_code);
+        if(status_code < 200 || status_code > 299)
+       {
+            OIC_LOG_V(ERROR, TAG, "Error, Wrong status code", status_code);
             close(fd);
             svritem->fd = -1;
             return CA_SOCKET_OPERATION_FAILED;