removed duplicated code in Sample app
authorjihwan.seo <jihwan.seo@samsung.com>
Tue, 23 Jun 2015 08:06:24 +0000 (17:06 +0900)
committerErich Keane <erich.keane@intel.com>
Tue, 23 Jun 2015 16:18:38 +0000 (16:18 +0000)
- Target Platform : Android, Linux

Change-Id: I7035a138cb9b83a6e653c213aaa4fc349b57545d
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1395
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c
resource/csdk/connectivity/samples/linux/sample_main.c

index 58fb784..2aa8c70 100644 (file)
 #define OPTION_INFO_LENGTH 1024
 #define NETWORK_INFO_LENGTH 1024
 
-#define COAP_PREFIX          "coap://"
-#define COAP_PREFIX_LEN      7
-#define COAPS_PREFIX         "coaps://"
-#define COAPS_PREFIX_LEN     8
-
 uint16_t g_localSecurePort = SECURE_DEFAULT_PORT;
 
 void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestInfo);
@@ -50,11 +45,15 @@ CATransportAdapter_t g_selectedNwType = CA_ADAPTER_IP;
 static CAToken_t g_lastRequestToken = NULL;
 static uint8_t g_lastRequestTokenLength;
 
-static const char SECURE_COAPS_PREFIX[] = "coaps://";
+static const char COAP_PREFIX[] =  "coap://";
+static const char COAPS_PREFIX[] = "coaps://";
+static const uint16_t COAP_PREFIX_LEN = sizeof(COAP_PREFIX) - 1;
+static const uint16_t COAPS_PREFIX_LEN = sizeof(COAPS_PREFIX) - 1;
 
 static const char SECURE_INFO_DATA[]
                                    = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
-                                     "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
+                                     "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":"
+                                     "%d}}]}";
 static const char NORMAL_INFO_DATA[]
                                    = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
                                      "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
@@ -954,7 +953,7 @@ void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestI
             char *uri = NULL;
             uint32_t length = 0;
 
-            length = sizeof(SECURE_COAPS_PREFIX) - 1; //length of "coaps://"
+            length = COAPS_PREFIX_LEN; //length of "coaps://"
             // length of "ipaddress:port"
             length += strlen(object->addr) + PORT_LENGTH;
             length += strlen(requestInfo->info.resourceUri) + 1;
@@ -966,7 +965,7 @@ void request_handler(const CAEndpoint_t* object, const CARequestInfo_t* requestI
                 free(uri);
                 return;
             }
-            sprintf(uri, "%s%s:%d/%s", SECURE_COAPS_PREFIX, object->addr,
+            sprintf(uri, "%s%s:%d/%s", COAPS_PREFIX, object->addr,
                     securePort, requestInfo->info.resourceUri);
 
             CAEndpoint_t *endpoint = NULL;
index a8e0df1..f3ef50e 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "cacommon.h"
 #include "cainterface.h"
-#include "oic_malloc.h"
 #ifdef __WITH_DTLS__
 #include "ocsecurityconfig.h"
 #endif
 #define SYSTEM_INVOKE_ERROR 127
 #define SYSTEM_ERROR -1
 
-#define COAP_PREFIX          "coap://"
-#define COAP_PREFIX_LEN      7
-#define COAPS_PREFIX         "coaps://"
-#define COAPS_PREFIX_LEN     8
-
 /**
  * @def RS_IDENTITY
  * @brief
@@ -96,7 +90,12 @@ int get_address_set(const char *pAddress, addressSet_t* outAddress);
 void parsing_coap_uri(const char* uri, addressSet_t* address);
 
 static CAToken_t g_last_request_token = NULL;
-static const char SECURE_COAPS_PREFIX[] = "coaps://";
+
+static const char COAP_PREFIX[] =  "coap://";
+static const char COAPS_PREFIX[] = "coaps://";
+static const uint16_t COAP_PREFIX_LEN = sizeof(COAP_PREFIX) - 1;
+static const uint16_t COAPS_PREFIX_LEN = sizeof(COAPS_PREFIX) - 1;
+
 static const char SECURE_INFO_DATA[] =
                                     "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
                                      "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":"
@@ -524,7 +523,7 @@ void send_secure_request()
     {
         return;
     }
-    snprintf(uri, MAX_BUF_LEN, "%s%s:5684/a/light", SECURE_COAPS_PREFIX, ipv4addr);
+    snprintf(uri, MAX_BUF_LEN, "%s%s:5684/a/light", COAPS_PREFIX, ipv4addr);
 
     // create remote endpoint
     CAEndpoint_t *endpoint = NULL;
@@ -964,7 +963,7 @@ void request_handler(const CAEndpoint_t *object, const CARequestInfo_t *requestI
             printf("This is secure resource...\n");
 
             //length of "coaps://"
-            size_t length = sizeof(SECURE_COAPS_PREFIX) - 1;
+            size_t length = COAPS_PREFIX_LEN;
 
             // length of "ipaddress:port"
             length += strlen(object->addr) + PORT_LENGTH;
@@ -976,7 +975,7 @@ void request_handler(const CAEndpoint_t *object, const CARequestInfo_t *requestI
                 printf("Failed to create new uri\n");
                 return;
             }
-            sprintf(uri, "%s%s:%d/", SECURE_COAPS_PREFIX, object->addr,
+            sprintf(uri, "%s%s:%d/", COAPS_PREFIX, object->addr,
                     object->port);
 
             CAEndpoint_t *endpoint = NULL;