RD updates 19/11519/28
authorHabib Virji <habib.virji@samsung.com>
Wed, 7 Sep 2016 15:49:21 +0000 (16:49 +0100)
committerUze Choi <uzchoi@samsung.com>
Wed, 5 Oct 2016 15:33:56 +0000 (15:33 +0000)
- [Server] Includes a new functionality to store RD details in the database.
- [Server] Use SQLite to store details Published details in the database.
- [UnitTest] Added rdtest to be built as a unittest
- [Service] Moved Client code from resource/csdk/stack/src to
  resource/csdk.
- [Build] Updated auto_build to use RD_MODE flag instead of WITH_RD flag.
- [Cleaning] Removed all RD types in the octypes.h
- [PayloadHandling] rdpayload handling is removed from ocpayload.
- [PayloadHandling] All payload is created in services/resource-directory.
- [PayloadHandling] Uses OCRepPayload to create RD Payload.

Change-Id: I0a32c01ca6b5db1ad36141667e1ee94e545be290
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11519
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
55 files changed:
android/android_api/base/jni/Android.mk
auto_build.py
build_common/external_libs.scons
cloud/samples/client/SConscript
cloud/samples/client/airconditioner/aircon_controlee.cpp
cloud/samples/client/thin_light/thin_room_light.cpp
resource/SConscript
resource/csdk/SConscript
resource/csdk/octbstack_product.def
resource/csdk/resource-directory/SConscript [moved from service/resource-directory/SConscript with 63% similarity]
resource/csdk/resource-directory/include/rd_client.h [moved from resource/csdk/stack/include/oicresourcedirectory.h with 83% similarity]
resource/csdk/resource-directory/include/rd_database.h [new file with mode: 0644]
resource/csdk/resource-directory/include/rd_server.h [moved from service/resource-directory/include/rd_server.h with 95% similarity]
resource/csdk/resource-directory/samples/SConscript [moved from service/resource-directory/samples/SConscript with 69% similarity]
resource/csdk/resource-directory/samples/oic_svr_db_server.dat [new file with mode: 0644]
resource/csdk/resource-directory/samples/rd_main.c [moved from service/resource-directory/samples/rd_main.c with 98% similarity]
resource/csdk/resource-directory/samples/rd_publishingClient.cpp [moved from service/resource-directory/samples/rd_publishingClient.cpp with 66% similarity]
resource/csdk/resource-directory/samples/rd_queryClient.cpp [moved from service/resource-directory/samples/rd_queryClient.cpp with 99% similarity]
resource/csdk/resource-directory/samples/rdclient.cpp [moved from resource/examples/rdclient.cpp with 99% similarity]
resource/csdk/resource-directory/src/internal/rd_database.c [new file with mode: 0644]
resource/csdk/resource-directory/src/rd_client.c [moved from resource/csdk/stack/src/oicresourcedirectory.c with 53% similarity]
resource/csdk/resource-directory/src/rd_server.c [moved from service/resource-directory/src/rd_server.c with 55% similarity]
resource/csdk/resource-directory/unittests/SConscript [new file with mode: 0644]
resource/csdk/resource-directory/unittests/rddatabase.cpp [new file with mode: 0644]
resource/csdk/resource-directory/unittests/rdtests.cpp [moved from resource/csdk/stack/test/rdtests.cpp with 72% similarity]
resource/csdk/stack/include/ocpayload.h
resource/csdk/stack/include/octypes.h
resource/csdk/stack/include/payload_logging.h
resource/csdk/stack/include/rdpayload.h [deleted file]
resource/csdk/stack/samples/tizen/build/packaging/com.oic.ri.spec
resource/csdk/stack/src/ocpayload.c
resource/csdk/stack/src/ocpayloadconvert.c
resource/csdk/stack/src/ocpayloadparse.c
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/rdpayload.c [deleted file]
resource/docs/c-doc/Doxyfile
resource/examples/SConscript
resource/include/OCRepresentation.h
resource/include/OCSerialization.h
resource/src/InProcServerWrapper.cpp
resource/src/OCRepresentation.cpp
resource/src/SConscript
service/SConscript
service/notification/SConscript
service/notification/examples/linux/SConscript
service/notification/examples/linux/cloud_connector.c
service/notification/src/provider/NSProviderResource.c
service/resource-directory/include/rd_client.h [deleted file]
service/resource-directory/include/rd_payload.h [deleted file]
service/resource-directory/src/internal/rd_storage.c [deleted file]
service/resource-directory/src/internal/rd_storage.h [deleted file]
service/resource-directory/src/rd_client.c [deleted file]
service/resource-encapsulation/src/common/SConscript
service/simulator/src/common/simulator_utils.cpp

index 182513d..276b504 100644 (file)
@@ -162,6 +162,7 @@ LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/ocsocket/include
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/oc_logger/include\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/boost/boost_1_58_0\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/cjson\r
+LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/tinycbor/tinycbor/src\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../build_common/android/compatibility\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include\r
 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/oxm/\r
index d5c49ae..977a133 100644 (file)
@@ -134,7 +134,7 @@ def build_linux_unsecured_with_rd(flag, extra_option_str):
     print ("*********** Build for linux With Resource Directory *************")
     build_options = {
                         'RELEASE':flag,
-                        'WITH_RD':1,
+                        'RD_MODE':'all',
                     }
     call_scons(build_options, extra_option_str)
 
@@ -142,7 +142,7 @@ def build_linux_secured_with_rd(flag, extra_option_str):
     print ("*********** Build for linux With Resource Directory & Security ************")
     build_options = {
                         'RELEASE':flag,
-                        'WITH_RD':1,
+                        'RD_MODE':'all',
                         'SECURED':1,
                     }
     call_scons(build_options, extra_option_str)
@@ -433,7 +433,7 @@ def build_windows(flag, extra_option_str):
                         'BUILD_SAMPLE':'ON',
                         'LOGGING':'off',
                         'TEST':1,
-                        'WITH_RD':1,
+                        'RD_MODE':'all',
                     }
     call_scons(build_options, extra_option_str)
 
@@ -452,7 +452,7 @@ def build_msys(flag, extra_option_str):
                         'BUILD_SAMPLE':'ON',
                         'LOGGING':'off',
                         'TEST':1,
-                        'WITH_RD':1,
+                        'RD_MODE':'all',
                     }
     call_scons(build_options, extra_option_str)
 
index 06d3e0f..eaa78c2 100644 (file)
@@ -28,6 +28,7 @@ Import('env')
 
 target_os = env.get('TARGET_OS')
 target_arch = env.get('TARGET_ARCH')
+rd_mode = env.get('RD_MODE')
 
 # for android, doesn't distinguish 'armeabi-v7a-hard' and 'armeabi-v7a' library
 if target_os == 'android':
@@ -142,3 +143,6 @@ env.AddMethod(__install_lib, "InstallLib")
 
 if env.get('SECURED') == '1' and target_os != 'tizen':
        SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'sqlite3', 'SConscript'))
+
+if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
+       SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'sqlite3', 'SConscript'))
index 23cfaef..b9335c1 100644 (file)
@@ -33,6 +33,7 @@ cc_sample_app_env = lib_env.Clone()
 ######################################################################
 cc_sample_app_env.AppendUnique(CPPPATH = [
         '../../../resource/include/',
+        '../../../resource/csdk/resource-directory/include',
         '../../../resource/csdk/stack/include',
         '../../../resource/c_common/ocrandom/include',
         '../../../resource/csdk/logger/include',
@@ -100,4 +101,4 @@ if mqOption[0] is not 'OFF':
 group_invite_src = [
         'group_invite/group_invite.cpp'
         ]
-cc_sample_app_env.Program('group_invite_sample', group_invite_src)
\ No newline at end of file
+cc_sample_app_env.Program('group_invite_sample', group_invite_src)
index 6b53aea..0a1a2dd 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "ocstack.h"
 #include "ocpayload.h"
-#include "oicresourcedirectory.h"
+#include "rd_client.h"
 
 #include <OCApi.h>
 #include <OCPlatform.h>
index 69ff36c..9f2104e 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "ocstack.h"
 #include "ocpayload.h"
-#include "oicresourcedirectory.h"
+#include "rd_client.h"
 
 using namespace std;
 
index ab14110..4b09744 100644 (file)
@@ -47,6 +47,11 @@ if env.get('ROUTING') in ['GW', 'EP']:
        # Build Routing
        SConscript('csdk/routing/SConscript')
 
+if target_os in ['linux', 'android']:
+    rd_mode = env.get('RD_MODE')
+    if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
+        SConscript('csdk/resource-directory/SConscript')
+
 # Build libocsrm
 SConscript('csdk/security/SConscript')
 
index 0e0022e..13781fd 100644 (file)
@@ -92,7 +92,7 @@ liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap'])
 
 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
-    liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
+       liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
 
 if env.get('SECURED') == '1':
        liboctbstack_env.AppendUnique(LIBS = ['tinydtls'])
@@ -138,7 +138,7 @@ if target_os in ['darwin', 'ios']:
 if target_os not in ['arduino', 'windows']:
        liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
 if target_os == 'android':
-    liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
+       liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
 
 if env.get('LOGGING'):
        liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
@@ -171,12 +171,14 @@ liboctbstack_src = [
        ]
 
 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
-       liboctbstack_src.append(OCTBSTACK_SRC + 'rdpayload.c')
-       liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
        if 'CLIENT' in rd_mode:
                liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
        if 'SERVER' in rd_mode:
                liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
+       if target_os in ['linux', 'android']:
+               liboctbstack_env.Prepend(LIBS = ['resource_directory'])
+               liboctbstack_env.PrependUnique(CPPPATH = [env.get('BUILD_DIR') + 'resource/csdk/resource-directory/include'])
+               liboctbstack_env.PrependUnique(LIBPATH = [env.get('BUILD_DIR') + 'resource/csdk/resource-directory/include'])
 
 if with_tcp == True:
        liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
index 841b1bb..3747389 100644 (file)
@@ -67,10 +67,6 @@ OCPayloadDestroy
 OCPlatformPayloadCreate
 OCPresencePayloadCreate
 OCProcess
-OCRDDelete
-OCRDDeleteWithDeviceId
-OCRDPublish
-OCRDPublishWithDeviceId
 OCRegisterPersistentStorageHandler
 OCRepPayloadAddInterface
 OCRepPayloadAddResourceType
similarity index 63%
rename from service/resource-directory/SConscript
rename to resource/csdk/resource-directory/SConscript
index f5258d6..83d809b 100755 (executable)
@@ -30,13 +30,18 @@ if rd_env.get('LOGGING'):
 
 target_os = env.get('TARGET_OS')
 src_dir = env.get('SRC_DIR')
+rd_mode = env.get('RD_MODE')
 
 ######################################################################
 # Build flags
 ######################################################################
-rd_env.AppendUnique(CPPPATH = ['include'])
-rd_env.AppendUnique(CPPPATH = ['src/internal'])
-rd_env.AppendUnique(CPPPATH = ['../../resource/csdk/stack/include'])
+rd_env.AppendUnique(CPPPATH = ['include', 'src/internal', '../stack/include'])
+
+if 'CLIENT' in rd_mode:
+    rd_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
+if 'SERVER' in rd_mode:
+    rd_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
+
 rd_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap'])
 
 if target_os not in ['windows']:
@@ -52,15 +57,24 @@ if target_os == 'android':
     if not env.get('RELEASE'):
         rd_env.AppendUnique(LIBS = ['log'])
 
+if target_os in ['tizen']:
+    rd_env.ParseConfig('pkg-config --cflags --libs sqlite3')
+else:
+    rd_env.AppendUnique(CPPPATH = ['../../../extlibs/sqlite3'])
+
 ######################################################################
 # Source files and Targets
 ######################################################################
 RD_SRC_DIR = 'src/'
-rd_src = [
-        RD_SRC_DIR + 'internal/rd_storage.c',
-        RD_SRC_DIR + 'rd_server.c',
-        RD_SRC_DIR + 'rd_client.c',
-         ]
+rd_src = []
+if 'SERVER' in rd_mode:
+    rd_src += [
+            '../../../extlibs/sqlite3/sqlite3.c',
+            RD_SRC_DIR + 'internal/rd_database.c',
+            RD_SRC_DIR + 'rd_server.c',
+            ]
+if 'CLIENT' in rd_mode:
+    rd_src += [RD_SRC_DIR + 'rd_client.c',]
 
 if target_os in ['tizen'] :
     rdsdk = rd_env.SharedLibrary('resource_directory', rd_src)
@@ -69,11 +83,21 @@ else :
 
 rd_env.InstallTarget(rdsdk, 'resource_directory')
 rd_env.UserInstallTargetLib(rdsdk, 'resource_directory')
-rd_env.UserInstallTargetHeader('include/rd_client.h', 'service/resource-directory', 'rd_client.h')
-rd_env.UserInstallTargetHeader('include/rd_server.h', 'service/resource-directory', 'rd_server.h')
+if 'CLIENT' in rd_mode:
+    rd_env.UserInstallTargetHeader('include/rd_client.h', 'service/resource-directory', 'rd_client.h')
+
+if 'SERVER' in rd_mode:
+    rd_env.UserInstallTargetHeader('include/rd_server.h', 'service/resource-directory', 'rd_server.h')
+    rd_env.UserInstallTargetHeader('include/rd_database.h', 'service/resource-directory', 'rd_database.h')
 
 ######################################################################
 # Samples for the resource directory
 ######################################################################
-if target_os not in ['windows']:
+if target_os in ['linux']:
     SConscript('samples/SConscript')
+
+######################################################################
+# Build UnitTests Things Manager
+################################################ ######################
+if target_os in ['linux']:
+    SConscript('unittests/SConscript')
@@ -1,6 +1,6 @@
 //******************************************************************
 //
-// Copyright 2016 Samsung Electronics All Rights Reserved.
+// Copyright 2015 Samsung Electronics All Rights Reserved.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 //
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#ifndef OC_RESOURCE_DIRECTORY_H_
-#define OC_RESOURCE_DIRECTORY_H_
+#ifndef _RESOURCE_DIRECTORY_CLIENT_H_
+#define _RESOURCE_DIRECTORY_CLIENT_H_
 
-#include "octypes.h"
-#include "logger.h"
+// Iotivity Base CAPI
+#include "ocstack.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif // __cplusplus
 
-#ifdef RD_CLIENT
+#define OIC_RD_PUBLISH_TTL 86400
+
+#define OIC_RD_DEFAULT_RESOURCE 2
+
+#define DEFAULT_MESSAGE_TYPE "application/json"
+
+/**
+ * Discover Local RD across the network.
+ *
+ * @param connectivityType Type of connectivity indicating the interface.
+ * @param cbBiasFactor Asynchronous callback function that is invoked by the stack when
+ *                     response is received. The callback is generated for each response
+ *                     received.
+ * @param qos Quality of service.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult OCRDDiscover(OCConnectivityType connectivityType, OCCallbackData *cbBiasFactor,
+                           OCQualityOfService qos);
+
 /**
  * Publish RD resource to Resource Directory.
  *
@@ -104,9 +123,9 @@ OCStackResult OCRDDeleteWithDeviceId(const char *host, const unsigned char *id,
                                      OCConnectivityType connectivityType,
                                      OCResourceHandle *resourceHandles, uint8_t nHandles,
                                      OCCallbackData *cbData, OCQualityOfService qos);
-#endif
+
 #ifdef __cplusplus
 }
 #endif // __cplusplus
 
-#endif /* OC_RESOURCE_DIRECTORY_H_ */
+#endif //_RESOURCE_DIRECTORY_CLIENT_H_
diff --git a/resource/csdk/resource-directory/include/rd_database.h b/resource/csdk/resource-directory/include/rd_database.h
new file mode 100644 (file)
index 0000000..3f82f58
--- /dev/null
@@ -0,0 +1,93 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef OC_RESOURCE_DIRECTORY_DATABASE_H_
+#define OC_RESOURCE_DIRECTORY_DATABASE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+#ifdef RD_SERVER
+
+/**
+ * Opens the RD publish database.
+ *
+ * @param path to the database file.
+ *
+ * @return ::OC_STACK_OK in case of success or else other value.
+ */
+OCStackResult OCRDDatabaseInit(const char *path);
+
+/**
+ * Stores in database the published resource.
+ *
+ * @param payload is the the published resource payload.
+ * @param address provide information about endpoint connectivity details.
+ *
+ * @return ::OC_STACK_OK in case of success or else other value.
+ */
+OCStackResult OCRDDatabaseStoreResources(const OCRepPayload *payload, const OCDevAddr *address);
+
+/**
+ * Search the RD database for queries.
+ *
+ * @param interfaceType is the interface type that is queried.
+ * @param resourceType is the resource type that is queried.
+ * @param discPayload is NULL if no resource found or else OCDiscoveryPayload with the details
+ * about the resource.
+ *
+ * @return ::OC_STACK_OK in case of success or else other value.
+ */
+OCStackResult OCRDDatabaseCheckResources(const char *interfaceType, const char *resourceType,
+    OCDiscoveryPayload *discPayload);
+
+/**
+ * Updates the RD resource
+ *
+ * @param deviceId of the device for which resources will be update.
+ *
+ * @return ::OC_STACK_OK in case of success or else other value.
+ */
+OCStackResult OCRDDatabaseUpdateDevice(const char *deviceId);
+
+/**
+ * Delete the RD resource
+ *
+ * @param deviceId of the device for which resources will be deleted.
+ *
+ * @return ::OC_STACK_OK in case of success or else other value.
+ */
+OCStackResult OCRDDatabaseDeleteDevice(const char *deviceId);
+
+/**
+ * Close the RD publish database.
+ *
+ * @return ::OC_STACK_OK in case of success or else other value.
+ */
+OCStackResult OCRDDatabaseClose();
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
@@ -51,13 +51,12 @@ OCStackResult OCRDStop();
  * @param interfaceType a interface type that is being queried.
  * @param resourceType a resource type that is being queried.
  * @param payload A payload of the matching resource type or interface type or NULL.
- * @param addr A device address.
  *
  * @return ::OC_STACK_OK upon success, ::OC_STACK_ERROR is returned except
  * the case that OC_STACK_SUCCESS is returned.
  */
 OCStackResult OCRDCheckPublishedResource(const char *interfaceType, const char *resourceType,
-        OCResourceCollectionPayload **payload, OCDevAddr *addr);
+        OCDiscoveryPayload **payload);
 
 #ifdef __cplusplus
 }
@@ -44,13 +44,28 @@ rd_sample_app_env.PrependUnique(LIBS = ['resource_directory', 'oc', 'octbstack']
 if env.get('SECURED') == '1':
     rd_sample_app_env.AppendUnique(LIBS = ['tinydtls'])
 
+if env.get('LOGGING'):
+    rd_sample_app_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+if rd_sample_app_env.get('RD_MODE'):
+    rd_mode = rd_sample_app_env.get('RD_MODE')
+    if 'CLIENT' in rd_mode:
+        rd_sample_app_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
+    if 'SERVER' in rd_mode:
+        rd_sample_app_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
+
 ####################################################################
 # Source files and Targets
 ######################################################################
-rd_server = rd_sample_app_env.Program('rd_server', 'rd_main.c')
-rd_publishingClient = rd_sample_app_env.Program('rd_publishingClient', 'rd_publishingClient.cpp')
 rd_queryClient = rd_sample_app_env.Program('rd_queryClient', 'rd_queryClient.cpp')
 
-Alias("resource_directory", [rd_server, rd_publishingClient])
+if 'SERVER' in rd_sample_app_env.get('RD_MODE'):
+    rd_server = rd_sample_app_env.Program('rd_server', 'rd_main.c')
+    Alias("resource_directory", [rd_server, rd_queryClient])
+
+if 'CLIENT' in rd_sample_app_env.get('RD_MODE'):
+    rd_publishingClient = rd_sample_app_env.Program('rd_publishingClient', 'rd_publishingClient.cpp')
+    rd_client = rd_sample_app_env.Program('rd_client', 'rdclient.cpp')
+    Alias("resource_directory", [rd_publishingClient, rd_client, rd_queryClient])
 
 env.AppendTarget('resource_directory')
diff --git a/resource/csdk/resource-directory/samples/oic_svr_db_server.dat b/resource/csdk/resource-directory/samples/oic_svr_db_server.dat
new file mode 100644 (file)
index 0000000..a6b3fae
Binary files /dev/null and b/resource/csdk/resource-directory/samples/oic_svr_db_server.dat differ
@@ -48,7 +48,7 @@ int main()
         return 0;
     }
 
-    printf("OCRDStart successfully...\n");
+    printf("RD created successfully...\n");
 
     signal(SIGINT, handleSigInt);
     while (!g_quitFlag)
 #include "oic_string.h"
 
 #include "rd_client.h"
+#include "payload_logging.h"
+
+#define TAG ("RD_PublishClient")
+#define DEFAULT_CONTEXT_VALUE 0x99
 
 using namespace OC;
 
-OCResourceHandle g_curResource_t = NULL;
-OCResourceHandle g_curResource_l = NULL;
-char rdAddress[MAX_ADDR_STR_SIZE];
-uint16_t rdPort;
+OCResourceHandle handles[2];
+std::ostringstream rdAddress;
+
 
 void registerLocalResources()
 {
@@ -41,7 +44,7 @@ void registerLocalResources()
     std::string resourceInterface = DEFAULT_INTERFACE;
     uint8_t resourceProperty = OC_DISCOVERABLE;
 
-    OCStackResult result = OCPlatform::registerResource(g_curResource_t,
+    OCStackResult result = OCPlatform::registerResource(handles[0],
                            resourceURI_thermostat,
                            resourceTypeName_thermostat,
                            resourceInterface,
@@ -54,7 +57,7 @@ void registerLocalResources()
             std::string("Device Resource failed to start") + std::to_string(result));
     }
 
-    result = OCPlatform::registerResource(g_curResource_l,
+    result = OCPlatform::registerResource(handles[1],
                                           resourceURI_light,
                                           resourceTypeName_light,
                                           resourceInterface,
@@ -81,12 +84,24 @@ void printHelp()
     std::cout << std::endl;
 }
 
-int biasFactorCB(char addr[MAX_ADDR_STR_SIZE], uint16_t port)
+static OCStackApplicationResult handleDiscoveryCB(__attribute__((unused))void *ctx,
+                                                  __attribute__((unused)) OCDoHandle handle,
+                                                  __attribute__((unused))
+                                                  OCClientResponse *clientResponse)
 {
-    OICStrcpy(rdAddress, MAX_ADDR_STR_SIZE, addr);
-    rdPort = port;
-    std::cout << "RD Address is : " <<  addr << ":" << port << std::endl;
-    return 0;
+    OIC_LOG(DEBUG, TAG, "Successfully found RD.");
+    rdAddress << clientResponse->devAddr.addr << ":" << clientResponse->devAddr.port;
+    std::cout << "RD Address is : " <<  rdAddress.str() << std::endl;
+    return OC_STACK_DELETE_TRANSACTION;
+}
+
+static OCStackApplicationResult handlePublishCB(__attribute__((unused))void *ctx,
+                                                  __attribute__((unused)) OCDoHandle handle,
+                                                  __attribute__((unused))
+                                                  OCClientResponse *clientResponse)
+{
+    OIC_LOG(DEBUG, TAG, "Successfully published resources.");
+    return OC_STACK_DELETE_TRANSACTION;
 }
 
 int main()
@@ -111,7 +126,7 @@ int main()
     {
         sleep(2);
 
-        if (g_curResource_t == NULL || g_curResource_l == NULL)
+        if (handles[0] == NULL || handles[1] == NULL)
         {
             continue;
         }
@@ -133,11 +148,25 @@ int main()
             switch ((int)in)
             {
                 case 1:
-                    OCRDDiscover(biasFactorCB);
+                {
+                    OCCallbackData cbData;
+                    cbData.cb = &handleDiscoveryCB;;
+                    cbData.cd = NULL;
+                    cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
+                    OCRDDiscover(CT_ADAPTER_IP, &cbData, OC_LOW_QOS);
                     break;
+                }
                 case 2:
-                    OCRDPublish(rdAddress, rdPort, 2, g_curResource_t, g_curResource_l);
+                {
+                    OCCallbackData cbData;
+                    cbData.cb = &handlePublishCB;
+                    cbData.cd = NULL;
+                    cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
+                    std::string address = rdAddress.str();
+                    OCRDPublish(address.c_str(), CT_ADAPTER_IP, handles,
+                                2, &cbData, OC_LOW_QOS);
                     break;
+                }
                 case 3:
                     break;
                 default:
@@ -21,6 +21,7 @@
 #include "OCPlatform.h"
 
 bool g_foundResource = true;
+using namespace OC;
 
 void foundResource(std::shared_ptr< OC::OCResource > resource)
 {
similarity index 99%
rename from resource/examples/rdclient.cpp
rename to resource/csdk/resource-directory/samples/rdclient.cpp
index 9d82dc4..ef6a0c3 100644 (file)
@@ -280,9 +280,8 @@ int main(int argc, char* argv[])
     }
     catch (OCException& e)
     {
-        oclog() << "Exception in main: "<< e.what();
+        cerr << "Exception in main: "<< e.what();
     }
 
     return 0;
 }
-
diff --git a/resource/csdk/resource-directory/src/internal/rd_database.c b/resource/csdk/resource-directory/src/internal/rd_database.c
new file mode 100644 (file)
index 0000000..c16cec8
--- /dev/null
@@ -0,0 +1,560 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License a
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "sqlite3.h"
+#include "logger.h"
+#include "ocpayload.h"
+#include "octypes.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+
+#ifdef RD_SERVER
+
+#define TAG "RD_DATABASE"
+#define RD_PATH "RD.db"
+
+static sqlite3 *gRDDB = NULL;
+
+static const uint8_t device_index = 2;
+static const uint8_t ttl_index = 3;
+static const uint8_t address_index = 4;
+
+static const uint8_t uri_index = 2;
+static const uint8_t p_index = 5;
+static const uint8_t mt_index = 7;
+static const uint8_t d_index = 8;
+
+static const uint8_t rt_value_index = 1;
+static const uint8_t rt_link_id_index = 2;
+
+static const uint8_t if_value_index = 1;
+static const uint8_t if_link_id_index = 2;
+
+#define VERIFY_SQLITE(arg) \
+    if (SQLITE_OK != (arg)) \
+    { \
+        OIC_LOG_V(ERROR, TAG, "Error in " #arg ", Error Message: %s",  sqlite3_errmsg(gRDDB)); \
+        sqlite3_exec(gRDDB, "ROLLBACK", NULL, NULL, NULL); \
+        return OC_STACK_ERROR; \
+    }
+
+#define CHECK_DATABASE_INIT \
+    if (!gRDDB) \
+    { \
+        OIC_LOG(ERROR, TAG, "Database is not initialized."); \
+        return OC_STACK_ERROR; \
+    }
+
+#define STR(a) #a
+#define XSTR(a) STR(a)
+
+#define RD_TABLE \
+    "create table RD_DEVICE_LIST(ID INTEGER PRIMARY KEY AUTOINCREMENT, " \
+    XSTR(OC_RSRVD_DEVICE_ID) " UNIQUE NOT NULL, " \
+    XSTR(OC_RSRVD_TTL) " NOT NULL, " \
+    "ADDRESS NOT NULL);"
+
+#define RD_LL_TABLE  \
+    "create table RD_DEVICE_LINK_LIST("XSTR(OC_RSRVD_INS)" INTEGER PRIMARY KEY AUTOINCREMENT, " \
+    XSTR(OC_RSRVD_HREF)  "," \
+    XSTR(OC_RSRVD_REL)   ","  \
+    XSTR(OC_RSRVD_TITLE) "," \
+    XSTR(OC_RSRVD_BITMAP)"," \
+    XSTR(OC_RSRVD_TTL)   "," \
+    XSTR(OC_RSRVD_MEDIA_TYPE) "," \
+    "DEVICE_ID INT NOT NULL, " \
+    "FOREIGN KEY(DEVICE_ID) REFERENCES RD_DEVICE_LIST(ID) ON DELETE CASCADE );"
+
+#define RD_RT_TABLE \
+    "create table RD_LINK_RT(" XSTR(OC_RSRVD_RESOURCE_TYPE) " NOT NULL, " \
+    "LINK_ID INT NOT NULL, "\
+    "FOREIGN KEY("XSTR(LINK_ID)") REFERENCES RD_DEVICE_LINK_LIST("XSTR(OC_RSRVD_INS)") " \
+    "ON DELETE CASCADE);"
+
+#define RD_IF_TABLE \
+    "create table RD_LINK_IF(" XSTR(OC_RSRVD_INTERFACE) " NOT NULL, " \
+    "LINK_ID INT NOT NULL, "\
+    "FOREIGN KEY("XSTR(LINK_ID)") REFERENCES RD_DEVICE_LINK_LIST("XSTR(OC_RSRVD_INS)") " \
+    "ON DELETE CASCADE);"
+
+static void errorCallback(void *arg, int errCode, const char *errMsg)
+{
+    OC_UNUSED(arg);
+    OC_UNUSED(errCode);
+    OC_UNUSED(errMsg);
+    OIC_LOG_V(ERROR, TAG, "SQLLite Error: %s : %d", errMsg, errCode);
+}
+
+OCStackResult OCRDDatabaseInit(const char *path)
+{
+    if (SQLITE_OK == sqlite3_config(SQLITE_CONFIG_LOG, errorCallback))
+    {
+        OIC_LOG_V(INFO, TAG, "SQLite debugging log initialized.");
+    }
+
+    int sqlRet;
+    sqlRet = sqlite3_open_v2(!path ? RD_PATH : path, &gRDDB, SQLITE_OPEN_READWRITE, NULL);
+    if (SQLITE_OK != sqlRet)
+    {
+        OIC_LOG(DEBUG, TAG, "RD database file did not open, as no table exists.");
+        OIC_LOG(DEBUG, TAG, "RD creating new table.");
+        sqlRet = sqlite3_open_v2(!path ? RD_PATH : path, &gRDDB,
+                                 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
+        if (SQLITE_OK == sqlRet)
+        {
+            VERIFY_SQLITE(sqlite3_exec(gRDDB, RD_TABLE, NULL, NULL, NULL));
+            OIC_LOG(DEBUG, TAG, "RD created RD_DEVICE_LIST table.");
+
+            VERIFY_SQLITE(sqlite3_exec(gRDDB, RD_LL_TABLE, NULL, NULL, NULL));
+            OIC_LOG(DEBUG, TAG, "RD created RD_DEVICE_LINK_LIST table.");
+
+            VERIFY_SQLITE(sqlite3_exec(gRDDB, RD_RT_TABLE, NULL, NULL, NULL));
+            OIC_LOG(DEBUG, TAG, "RD created RD_LINK_RT table.");
+
+            VERIFY_SQLITE(sqlite3_exec(gRDDB, RD_IF_TABLE, NULL, NULL, NULL));
+            OIC_LOG(DEBUG, TAG, "RD created RD_LINK_IF table.");
+            sqlRet = SQLITE_OK;
+        }
+    }
+
+    if (sqlRet == SQLITE_OK)
+    {
+        sqlite3_stmt *stmt = 0;
+        VERIFY_SQLITE(sqlite3_prepare_v2 (gRDDB, "PRAGMA foreign_keys = ON;", -1, &stmt, NULL));
+
+        if (sqlite3_step(stmt) != SQLITE_DONE)
+        {
+            sqlite3_finalize(stmt);
+            return OC_STACK_ERROR;
+        }
+
+        VERIFY_SQLITE(sqlite3_finalize(stmt));
+    }
+
+    return OC_STACK_OK;
+}
+
+OCStackResult OCRDDatabaseClose()
+{
+    CHECK_DATABASE_INIT;
+    VERIFY_SQLITE(sqlite3_close_v2(gRDDB));
+    return OC_STACK_OK;
+}
+
+static int storeResourceType(char **link, size_t size, uint8_t rowid)
+{
+    int res = 1;
+    VERIFY_SQLITE(sqlite3_exec(gRDDB, "BEGIN TRANSACTION", NULL, NULL, NULL));
+
+    const char *insertRT = "INSERT INTO RD_LINK_RT VALUES(?, ?)";
+    sqlite3_stmt *stmtRT = 0;
+
+    for (size_t i = 0; i < size; i++)
+    {
+        VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, insertRT, strlen(insertRT) + 1, &stmtRT, NULL));
+        if (link[i])
+        {
+            VERIFY_SQLITE(sqlite3_bind_text(stmtRT, rt_value_index, link[i],
+                    strlen(link[i])+1, SQLITE_STATIC));
+
+            VERIFY_SQLITE(sqlite3_bind_int(stmtRT, rt_link_id_index, rowid));
+        }
+        if (sqlite3_step(stmtRT) != SQLITE_DONE)
+        {
+            sqlite3_finalize(stmtRT);
+            return res;
+        }
+    }
+
+    VERIFY_SQLITE(sqlite3_finalize(stmtRT));
+
+    VERIFY_SQLITE(sqlite3_exec(gRDDB, "COMMIT", NULL, NULL, NULL));
+    res = SQLITE_OK;
+
+    return res;
+}
+
+
+static int storeInterfaceType(char **link, size_t size, uint8_t rowid)
+{
+    int res = 1;
+
+    VERIFY_SQLITE(sqlite3_exec(gRDDB, "BEGIN TRANSACTION", NULL, NULL, NULL));
+
+    const char *insertIF = "INSERT INTO RD_LINK_IF VALUES(?, ?)";
+    sqlite3_stmt *stmtIF = 0;
+
+    for (size_t i = 0; i < size; i++)
+    {
+        VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, insertIF, strlen(insertIF) + 1, &stmtIF, NULL));
+
+        if (link[i])
+        {
+            VERIFY_SQLITE(sqlite3_bind_text(stmtIF, if_value_index, link[i], strlen(link[i])+1, SQLITE_STATIC));
+            VERIFY_SQLITE(sqlite3_bind_int(stmtIF, if_link_id_index, rowid));
+        }
+        if (sqlite3_step(stmtIF) != SQLITE_DONE)
+        {
+            res = sqlite3_finalize(stmtIF);
+            return res;
+        }
+    }
+    VERIFY_SQLITE(sqlite3_finalize(stmtIF));
+
+    VERIFY_SQLITE(sqlite3_exec(gRDDB, "COMMIT", NULL, NULL, NULL));
+    res = SQLITE_OK;
+
+    return res;
+}
+
+static int storeLinkPayload(OCRepPayload *rdPayload, int64_t rowid)
+{
+    OCRepPayload **links = NULL;
+    size_t dimensions[MAX_REP_ARRAY_DEPTH];
+    int res = 1 ;
+    size_t j = 0;
+
+    if (OCRepPayloadGetPropObjectArray(rdPayload, OC_RSRVD_LINKS, &links, dimensions))
+    {
+        const char *insertDeviceLLList = "INSERT INTO RD_DEVICE_LINK_LIST VALUES(?,?,?,?,?,?,?,?)";
+        sqlite3_stmt *stmt = 0;
+
+        for (size_t i = 0; i < dimensions[0]; i++)
+        {
+            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, insertDeviceLLList, strlen(insertDeviceLLList) + 1, &stmt, NULL));
+            VERIFY_SQLITE(sqlite3_exec(gRDDB, "BEGIN TRANSACTION", NULL, NULL, NULL));
+
+            OCRepPayload *link = links[i];
+            char *uri = NULL;
+            if (OCRepPayloadGetPropString(link, OC_RSRVD_HREF, &uri))
+            {
+                VERIFY_SQLITE(sqlite3_bind_text(stmt, uri_index, uri, strlen(uri), SQLITE_STATIC));
+            }
+
+            OCRepPayload *p = NULL;
+            if (OCRepPayloadGetPropObject(link, OC_RSRVD_POLICY, &p))
+            {
+                int64_t bm = 0;
+                if (OCRepPayloadGetPropInt(p, OC_RSRVD_BITMAP, &bm))
+                {
+                    VERIFY_SQLITE(sqlite3_bind_int(stmt, p_index, bm));
+                }
+            }
+
+            size_t mtDim[MAX_REP_ARRAY_DEPTH] = {0};
+            char **mediaType = NULL;
+            if (OCRepPayloadGetStringArray(link, OC_RSRVD_MEDIA_TYPE, &mediaType, mtDim))
+            {
+                VERIFY_SQLITE(sqlite3_bind_text(stmt, mt_index, mediaType[0], mtDim[0], SQLITE_STATIC));
+            }
+
+            VERIFY_SQLITE(sqlite3_bind_int(stmt, d_index, rowid));
+
+            size_t rtDim[MAX_REP_ARRAY_DEPTH] = {0};
+            char **rt = NULL;
+            OCRepPayloadGetStringArray(link, OC_RSRVD_RESOURCE_TYPE, &rt, rtDim);
+
+            size_t itfDim[MAX_REP_ARRAY_DEPTH] = {0};
+            char **itf = NULL;
+            OCRepPayloadGetStringArray(link, OC_RSRVD_INTERFACE, &itf, itfDim);
+
+            if (sqlite3_step(stmt) != SQLITE_DONE)
+            {
+                sqlite3_finalize(stmt);
+                return res;
+            }
+            VERIFY_SQLITE(sqlite3_exec(gRDDB, "COMMIT", NULL, NULL, NULL));
+
+            int64_t ins = sqlite3_last_insert_rowid(gRDDB);
+            VERIFY_SQLITE(storeResourceType(rt, rtDim[0], ins));
+            VERIFY_SQLITE(storeInterfaceType(itf, itfDim[0], ins));
+            OICFree(uri);
+            OCPayloadDestroy((OCPayload *)p);
+            for (j = 0; j < mtDim[0]; j++)
+            {
+                OICFree(mediaType[j]);
+            }
+            OICFree(mediaType);
+
+            for (j = 0; j < rtDim[0]; j++)
+            {
+                OICFree(rt[j]);
+            }
+            OICFree(rt);
+
+            for (j = 0; j < itfDim[0]; j++)
+            {
+                OICFree(itf[j]);
+            }
+            OICFree(itf);
+
+        }
+
+        VERIFY_SQLITE(sqlite3_finalize(stmt));
+        res = SQLITE_OK;
+    }
+    return res;
+}
+
+OCStackResult OCRDDatabaseStoreResources(OCRepPayload *payload, const OCDevAddr *address)
+{
+    CHECK_DATABASE_INIT;
+
+    VERIFY_SQLITE(sqlite3_exec(gRDDB, "BEGIN TRANSACTION", NULL, NULL, NULL));
+    const char *insertDeviceList = "INSERT INTO RD_DEVICE_LIST VALUES(?,?,?,?)";
+    sqlite3_stmt *stmt = 0;
+    VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, insertDeviceList, strlen(insertDeviceList) + 1, &stmt, NULL));
+
+    char *deviceid = NULL;
+    if (OCRepPayloadGetPropString(payload, OC_RSRVD_DEVICE_ID, &deviceid))
+    {
+        VERIFY_SQLITE(sqlite3_bind_text(stmt, device_index, deviceid, strlen(deviceid) + 1, SQLITE_STATIC));
+    }
+
+    int64_t ttl = 0;
+    if (OCRepPayloadGetPropInt(payload, OC_RSRVD_DEVICE_TTL, &ttl))
+    {
+        VERIFY_SQLITE(sqlite3_bind_int(stmt, ttl_index, ttl));
+    }
+
+    char rdAddress[MAX_URI_LENGTH];
+    snprintf(rdAddress, MAX_URI_LENGTH, "%s:%d", address->addr, address->port);
+    OIC_LOG_V(DEBUG, TAG, "Address: %s", rdAddress);
+    VERIFY_SQLITE(sqlite3_bind_text(stmt, address_index, rdAddress, strlen(rdAddress) + 1, SQLITE_STATIC));
+
+    if (sqlite3_step(stmt) != SQLITE_DONE)
+    {
+        sqlite3_finalize(stmt);
+        return OC_STACK_ERROR;
+    }
+    VERIFY_SQLITE(sqlite3_finalize(stmt));
+
+    VERIFY_SQLITE(sqlite3_exec(gRDDB, "COMMIT", NULL, NULL, NULL));
+
+    int64_t rowid = sqlite3_last_insert_rowid(gRDDB);
+    VERIFY_SQLITE(storeLinkPayload(payload, rowid));
+
+    OICFree(deviceid);
+    return OC_STACK_OK;
+}
+
+OCStackResult OCRDDatabaseDeleteDevice(const char *deviceId)
+{
+    CHECK_DATABASE_INIT;
+    VERIFY_SQLITE(sqlite3_exec(gRDDB, "BEGIN TRANSACTION", NULL, NULL, NULL));
+
+    sqlite3_stmt *stmt = 0;
+    char *delDevice = "DELETE FROM RD_DEVICE_LIST WHERE "XSTR(OC_RSRVD_DEVICE_ID)" = ?";
+    VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, delDevice, strlen(delDevice) + 1, &stmt, NULL));
+
+    VERIFY_SQLITE(sqlite3_bind_text(stmt, 1, deviceId, strlen(deviceId) + 1, SQLITE_STATIC));
+
+    if (sqlite3_step(stmt) != SQLITE_DONE)
+    {
+        sqlite3_exec(gRDDB, "ROLLBACK", NULL, NULL, NULL);
+        sqlite3_finalize(stmt);
+        return OC_STACK_ERROR;
+    }
+    VERIFY_SQLITE(sqlite3_finalize(stmt));
+    VERIFY_SQLITE(sqlite3_exec(gRDDB, "COMMIT", NULL, NULL, NULL));
+
+    return OC_STACK_OK;
+}
+
+static OCStackResult appendStringLL(OCStringLL **type, const unsigned char *value)
+{
+    OCStringLL *temp= (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
+    if (!temp)
+    {
+        return OC_STACK_NO_MEMORY;
+    }
+    temp->value = OICStrdup((char *)value);
+    if (!temp->value)
+    {
+        return OC_STACK_NO_MEMORY;
+    }
+    temp->next = NULL;
+
+    if (!*type)
+    {
+        *type = temp;
+    }
+    else
+    {
+        for (OCStringLL *tmp = *type; tmp->next; tmp = tmp->next);
+        tmp->next = temp;
+    }
+    return OC_STACK_OK;
+}
+
+OCStackResult OCRDDatabaseCheckResources(const char *interfaceType, const char *resourceType, OCDiscoveryPayload *discPayload)
+{
+    CHECK_DATABASE_INIT;
+    if (!interfaceType && !resourceType)
+    {
+        return OC_STACK_INVALID_QUERY;
+    }
+    OCResourcePayload *resourcePayload = (OCResourcePayload *)OICCalloc(1, sizeof(OCResourcePayload));
+    if (!resourcePayload)
+    {
+        return OC_STACK_NO_MEMORY;
+    }
+
+    if (resourceType)
+    {
+        sqlite3_stmt *stmt = 0;
+        const char *input = "SELECT * FROM RD_DEVICE_LINK_LIST INNER JOIN RD_LINK_RT ON " \
+        "RD_DEVICE_LINK_LIST.INS=RD_LINK_RT.LINK_ID WHERE RD_LINK_RT.rt LIKE ? ";
+
+        VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, input, -1, &stmt, NULL));
+        VERIFY_SQLITE(sqlite3_bind_text(stmt, 1, resourceType, strlen(resourceType) + 1, SQLITE_STATIC));
+
+        int res = sqlite3_step (stmt);
+        if (res == SQLITE_ROW || res == SQLITE_DONE)
+        {
+            int id = sqlite3_column_int(stmt, 0);
+            const unsigned char *uri = sqlite3_column_text(stmt, uri_index - 1);
+            int bitmap = sqlite3_column_int(stmt, p_index - 1);
+            int deviceId = sqlite3_column_int(stmt, d_index - 1);
+            OIC_LOG_V(DEBUG, TAG, " %s %d", uri, deviceId);
+            resourcePayload->uri = OICStrdup((char *)uri);
+            if (!resourcePayload->uri)
+            {
+                OCDiscoveryResourceDestroy(resourcePayload);
+                return OC_STACK_NO_MEMORY;
+            }
+            res = sqlite3_reset(stmt);
+            VERIFY_SQLITE(res);
+
+            sqlite3_stmt *stmtRT = 0;
+            const char *rt = "SELECT rt FROM RD_LINK_RT WHERE LINK_ID=?";
+            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, rt, -1, &stmtRT, NULL));
+            VERIFY_SQLITE(sqlite3_bind_int(stmtRT, 1, id));
+            while (SQLITE_ROW == sqlite3_step(stmtRT))
+            {
+                const unsigned char *rt1 = sqlite3_column_text(stmtRT, (rt_value_index - 1));
+                appendStringLL(&resourcePayload->types, rt1);
+            }
+
+            sqlite3_stmt *stmtIF = 0;
+            const char *itf = "SELECT if FROM RD_LINK_IF WHERE LINK_ID=?";
+            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, itf, -1, &stmtIF, NULL));
+            VERIFY_SQLITE(sqlite3_bind_int(stmtIF, 1, id));
+            while (SQLITE_ROW == sqlite3_step(stmtIF))
+            {
+                const unsigned char *itf = sqlite3_column_text(stmtIF, (if_value_index - 1));
+                appendStringLL(&resourcePayload->interfaces, itf);
+            }
+
+            resourcePayload->bitmap = bitmap & (OC_OBSERVABLE | OC_DISCOVERABLE);
+            resourcePayload->secure = (bitmap & OC_SECURE) != 0;
+
+            const char *address = "SELECT di, address FROM RD_DEVICE_LIST INNER JOIN RD_DEVICE_LINK_LIST ON " \
+            "RD_DEVICE_LINK_LIST.DEVICE_ID = RD_DEVICE_LIST.ID WHERE RD_DEVICE_LINK_LIST.DEVICE_ID=?";
+
+            sqlite3_stmt *stmt1 = 0;
+            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, address, -1, &stmt1, NULL));
+            VERIFY_SQLITE(sqlite3_bind_int(stmt1, 1, deviceId));
+            // TODO: Right now, we have a bug where discovery payload can only send one device information.
+            res = sqlite3_step(stmt1);
+            if (res == SQLITE_ROW || res == SQLITE_DONE)
+            {
+                const unsigned char *di = sqlite3_column_text(stmt1, 0);
+                const unsigned char *address = sqlite3_column_text(stmt1, 1);
+                OIC_LOG_V(DEBUG, TAG, " %s %s", di, address);
+                (discPayload)->baseURI = OICStrdup((char *)address);
+                (discPayload)->sid = OICStrdup((char *)di);
+            }
+            OCDiscoveryPayloadAddNewResource(discPayload, resourcePayload);
+        }
+    }
+    if (interfaceType)
+    {
+        sqlite3_stmt *stmt = 0;
+        const char *input = "SELECT * FROM RD_DEVICE_LINK_LIST INNER JOIN RD_LINK_IF ON " \
+        "RD_DEVICE_LINK_LIST.INS=RD_LINK_IF.LINK_ID WHERE RD_LINK_IF.if LIKE ? ";
+
+        VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, input, -1, &stmt, NULL));
+        VERIFY_SQLITE(sqlite3_bind_text(stmt, 1, interfaceType, strlen(interfaceType) + 1, SQLITE_STATIC));
+
+        int res = sqlite3_step (stmt);
+        if (res == SQLITE_ROW || res == SQLITE_DONE)
+        {
+            int id = sqlite3_column_int(stmt, 0);
+            const unsigned char *uri = sqlite3_column_text(stmt, uri_index - 1);
+            int bitmap = sqlite3_column_int(stmt, p_index - 1);
+            int deviceId = sqlite3_column_int(stmt, d_index - 1);
+            OIC_LOG_V(DEBUG, TAG, " %s %d", uri, deviceId);
+            resourcePayload->uri = OICStrdup((char *)uri);
+            if (!resourcePayload->uri)
+            {
+                OCDiscoveryResourceDestroy(resourcePayload);
+                return OC_STACK_NO_MEMORY;
+            }
+            VERIFY_SQLITE(sqlite3_reset(stmt));
+
+            sqlite3_stmt *stmtRT = 0;
+            const char *rt = "SELECT rt FROM RD_LINK_RT WHERE LINK_ID=?";
+            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, rt, -1, &stmtRT, NULL));
+            VERIFY_SQLITE(sqlite3_bind_int(stmtRT, 1, id));
+            while (SQLITE_ROW == sqlite3_step(stmtRT))
+            {
+                const unsigned char *rt1 = sqlite3_column_text(stmtRT, (rt_value_index - 1));
+                appendStringLL(&resourcePayload->types, rt1);
+            }
+
+            sqlite3_stmt *stmtIF = 0;
+            const char *itf = "SELECT if FROM RD_LINK_IF WHERE LINK_ID=?";
+            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, itf, -1, &stmtIF, NULL));
+            VERIFY_SQLITE(sqlite3_bind_int(stmtIF, 1, id));
+            while (SQLITE_ROW == sqlite3_step (stmtIF))
+            {
+                const unsigned char *itf = sqlite3_column_text(stmtIF, (if_value_index - 1));
+                appendStringLL(&resourcePayload->interfaces, itf);
+            }
+
+            resourcePayload->bitmap = bitmap & (OC_OBSERVABLE | OC_DISCOVERABLE);
+            resourcePayload->secure = ((bitmap & OC_SECURE) != 0);
+
+            const char *address = "SELECT di, address FROM RD_DEVICE_LIST INNER JOIN RD_DEVICE_LINK_LIST ON " \
+            "RD_DEVICE_LINK_LIST.DEVICE_ID = RD_DEVICE_LIST.ID WHERE RD_DEVICE_LINK_LIST.DEVICE_ID=?";
+
+            sqlite3_stmt *stmt1 = 0;
+            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, address, -1, &stmt1, NULL));
+            VERIFY_SQLITE(sqlite3_bind_int(stmt1, 1, deviceId));
+
+            res = sqlite3_step(stmt1);
+            if (res == SQLITE_ROW || res == SQLITE_DONE)
+            {
+                const unsigned char *di = sqlite3_column_text(stmt1, 0);
+                const unsigned char *address = sqlite3_column_text(stmt1, 1);
+                OIC_LOG_V(DEBUG, TAG, " %s %s", di, address);
+                (discPayload)->baseURI = OICStrdup((char *)address);
+                (discPayload)->sid = OICStrdup((char *)di);
+            }
+            OCDiscoveryPayloadAddNewResource(discPayload, resourcePayload);
+        }
+    }
+    return OC_STACK_OK;
+}
+#endif
@@ -6,7 +6,7 @@
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// You may obtain a copy of the License a
 //
 //      http://www.apache.org/licenses/LICENSE-2.0
 //
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include "iotivity_config.h"
-#include "oicresourcedirectory.h"
+#include "rd_client.h"
 
-#include "rdpayload.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
 #include "octypes.h"
 #include "ocstack.h"
 #include "ocpayload.h"
-#include "rdpayload.h"
-#include "ocresource.h"
 #include "payload_logging.h"
 
-#define TAG "OIC_RI_RESOURCE_DIRECTORY"
+#define TAG "RD_CLIENT"
 
 #ifdef RD_CLIENT
+
+OCStackResult OCRDDiscover(OCConnectivityType connectivityType, OCCallbackData *cbBiasFactor,
+                           OCQualityOfService qos)
+{
+    if (!cbBiasFactor || !cbBiasFactor->cb)
+    {
+        OIC_LOG(DEBUG, TAG, "No callback function specified.");
+        return OC_STACK_INVALID_CALLBACK;
+    }
+
+    /* Start a discovery query*/
+    char queryUri[MAX_URI_LENGTH] = { '\0' };
+    snprintf(queryUri, MAX_URI_LENGTH, "coap://%s%s", OC_MULTICAST_PREFIX, OC_RSRVD_RD_URI);
+    OIC_LOG_V(DEBUG, TAG, "Querying RD: %s\n", queryUri);
+
+    return OCDoResource(NULL, OC_REST_DISCOVER, queryUri, NULL, NULL, connectivityType, qos,
+                        cbBiasFactor, NULL, 0);
+}
+
 OCStackResult OCRDPublish(const char *host, OCConnectivityType connectivityType,
                           OCResourceHandle *resourceHandles, uint8_t nHandles,
                           OCCallbackData *cbData, OCQualityOfService qos)
 {
     // Validate input parameters.
-    if (!host || !cbData || !cbData->cb)
+    if (!host)
+    {
+        return OC_STACK_INVALID_IP;
+    }
+
+    if (!cbData || !cbData->cb)
     {
         return OC_STACK_INVALID_CALLBACK;
     }
@@ -93,16 +113,96 @@ OCStackResult OCRDPublishWithDeviceId(const char *host, const unsigned char *id,
              OC_RSRVD_RD_URI, OC_RSRVD_RESOURCE_TYPE_RDPUBLISH);
     OIC_LOG_V(DEBUG, TAG, "Target URI: %s", targetUri);
 
-    OCPayload *rdPayload = (OCPayload *) OCRDPublishPayloadCreate(id, pubResHandle, nPubResHandles,
-                                                                  OIC_RD_PUBLISH_TTL);
+    OCRepPayload *rdPayload =  (OCRepPayload *)OCRepPayloadCreate();
     if (!rdPayload)
     {
-        OIC_LOG_V(ERROR, TAG, "Failed to create RD Payload");
         return OC_STACK_NO_MEMORY;
     }
 
-    OIC_LOG(DEBUG, TAG, "Create RD payload successfully");
+    const char *deviceId = OCGetServerInstanceIDString();
+    if (deviceId)
+    {
+        OCRepPayloadSetPropString(rdPayload, OC_RSRVD_DEVICE_ID, deviceId);
+    }
+    OCRepPayloadSetPropInt(rdPayload, OC_RSRVD_DEVICE_TTL, OIC_RD_PUBLISH_TTL);
+
+    const OCRepPayload *linkArr[nPubResHandles];
+    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {nPubResHandles, 0, 0};
+
+    for (uint8_t j = 0; j < nPubResHandles; j++)
+    {
+        OCResourceHandle handle = pubResHandle[j];
+        if (handle)
+        {
+            OCRepPayload *link = OCRepPayloadCreate();
+
+            const char *uri = OCGetResourceUri(handle);
+            if (uri)
+            {
+                OCRepPayloadSetPropString(link, OC_RSRVD_HREF, uri);
+            }
+
+            uint8_t numElement = 0;
+            if (OC_STACK_OK == OCGetNumberOfResourceTypes(handle, &numElement))
+            {
+                size_t rtDim[MAX_REP_ARRAY_DEPTH] = {numElement, 0, 0};
+                char **rt = (char **)OICMalloc(sizeof(char *) * numElement);
+                for (uint8_t i = 0; i < numElement; ++i)
+                {
+                    const char *value = OCGetResourceTypeName(handle, i);
+                    OIC_LOG_V(DEBUG, TAG, "value: %s", value);
+                    rt[i] = OICStrdup(value);
+                }
+                OCRepPayloadSetStringArray(link, OC_RSRVD_RESOURCE_TYPE, (const char **)rt, rtDim);
+            }
+
+            numElement = 0;
+            if (OC_STACK_OK == OCGetNumberOfResourceInterfaces(handle, &numElement))
+            {
+                size_t ifDim[MAX_REP_ARRAY_DEPTH] = {numElement, 0, 0};
+                char **itf = (char **)OICMalloc(sizeof(char *) * numElement);
+                for (uint8_t i = 0; i < numElement; ++i)
+                {
+                    const char *value = OCGetResourceInterfaceName(handle, i);
+                    OIC_LOG_V(DEBUG, TAG, "value: %s", value);
+                    itf[i] = OICStrdup(value);
+                }
+                OCRepPayloadSetStringArray(link, OC_RSRVD_INTERFACE, (const char **)itf, ifDim);
+            }
+
+            uint8_t ins = 0;
+            if (OCGetResourceIns(handle, &ins))
+            {
+                OCRepPayloadSetPropInt(link, OC_RSRVD_INS, ins);
+            }
+
+            size_t mtDim[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
+            char **mediaType = (char **)OICMalloc(sizeof(char *) * 1);
+            mediaType[0] = OICStrdup(DEFAULT_MESSAGE_TYPE);
+            OCRepPayloadSetStringArray(link, OC_RSRVD_MEDIA_TYPE, (const char **)mediaType,
+            mtDim);
+
+            OCResourceProperty p = OCGetResourceProperties(handle);
+            p = (OCResourceProperty) ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE));
+            OCRepPayload *policy = OCRepPayloadCreate();
+            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP, p);
+            OCRepPayloadSetPropObjectAsOwner(link, OC_RSRVD_POLICY, policy);
+
+            linkArr[j] = link;
+        }
+    }
+
+    OCRepPayloadSetPropObjectArray(rdPayload, OC_RSRVD_LINKS, linkArr, dimensions);
+    OIC_LOG_PAYLOAD(DEBUG, (OCPayload *) rdPayload);
 
+    if (OC_STACK_OK == OCStopMulticastServer())
+    {
+        OIC_LOG_V(DEBUG, TAG, "Stopped receiving the multicast traffic.");
+    }
+    else
+    {
+        OIC_LOG_V(DEBUG, TAG, "Failed stopping the multicast traffic.");
+    }
     return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)rdPayload,
                         connectivityType, qos, cbData, NULL, 0);
 }
@@ -112,7 +212,12 @@ OCStackResult OCRDDelete(const char *host, OCConnectivityType connectivityType,
                          OCCallbackData *cbData, OCQualityOfService qos)
 {
     // Validate input parameters
-    if (!host || !cbData || !cbData->cb)
+    if (!host)
+    {
+        return OC_STACK_INVALID_IP;
+    }
+
+    if (!cbData || !cbData->cb)
     {
         return OC_STACK_INVALID_CALLBACK;
     }
@@ -143,7 +248,9 @@ OCStackResult OCRDDeleteWithDeviceId(const char *host, const unsigned char *id,
     for (uint8_t j = 0; j < nHandles; j++)
     {
         OCResource *handle = (OCResource *) resourceHandles[j];
-        snprintf(queryParam, MAX_URI_LENGTH, "&ins=%d", handle->ins);
+        uint8_t ins = 0;
+        OCGetResourceIns(handle, &ins);
+        snprintf(queryParam, MAX_URI_LENGTH, "&ins=%u", ins);
     }
 
     OICStrcatPartial(targetUri, sizeof(targetUri), queryParam, strlen(queryParam));
@@ -152,4 +259,5 @@ OCStackResult OCRDDeleteWithDeviceId(const char *host, const unsigned char *id,
     return OCDoResource(NULL, OC_REST_DELETE, targetUri, NULL, NULL, connectivityType,
                         qos, cbData, NULL, 0);
 }
+
 #endif
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 #include "rd_server.h"
 
-#include "rd_storage.h"
+#include "rd_database.h"
 
-#include "rdpayload.h"
 #include "payload_logging.h"
+#include "ocpayload.h"
+#include "octypes.h"
 
 #define TAG  PCF("RDServer")
 
+#ifdef RD_SERVER
+
 // This is temporary hardcoded value for bias factor.
-#define OC_RD_DISC_SEL 100
+static const int OC_RD_DISC_SEL = 100;
+
+static OCResourceHandle rdHandle;
 
-static OCStackResult sendResponse(const OCEntityHandlerRequest *ehRequest, OCRDPayload *rdPayload)
+static OCStackResult sendResponse(const OCEntityHandlerRequest *ehRequest, OCRepPayload *rdPayload,
+    OCEntityHandlerResult ehResult)
 {
     OCEntityHandlerResponse response = { 0 };
     response.requestHandle = ehRequest->requestHandle;
     response.resourceHandle = ehRequest->resource;
-    response.ehResult = OC_EH_OK;
+    response.ehResult = ehResult;
     response.payload = (OCPayload*)(rdPayload);
     return OCDoResponse(&response);
 }
@@ -54,22 +60,27 @@ static OCEntityHandlerResult handleGetRequest(const OCEntityHandlerRequest *ehRe
     OCEntityHandlerResult ehResult = OC_EH_OK;
     OIC_LOG_V(DEBUG, TAG, "Received OC_REST_GET from client with query: %s.", ehRequest->query);
 
-    OCRDPayload *rdPayload = OCRDPayloadCreate();
+    OCRepPayload *rdPayload =  (OCRepPayload *)OCRepPayloadCreate();
     if (!rdPayload)
     {
         return OC_STACK_NO_MEMORY;
     }
 
-    rdPayload->rdDiscovery = OCRDDiscoveryPayloadCreate(NULL, OCGetServerInstanceIDString(), OC_RD_DISC_SEL);
-    if (!rdPayload->rdDiscovery)
+    const char *id = OCGetServerInstanceIDString();
+    if (id)
     {
-        OCRDPayloadDestroy(rdPayload);
-        return OC_STACK_NO_MEMORY;
+        OCRepPayloadSetPropString(rdPayload, OC_RSRVD_DEVICE_ID, id);
     }
+    OCRepPayloadSetPropInt(rdPayload, OC_RSRVD_RD_DISCOVERY_SEL, OC_RD_DISC_SEL);
+
+    OCRepPayloadAddResourceType(rdPayload, OC_RSRVD_RESOURCE_TYPE_RD);
+    OCRepPayloadAddResourceType(rdPayload, OC_RSRVD_RESOURCE_TYPE_RDPUBLISH);
+
+    OCRepPayloadAddInterface(rdPayload, OC_RSRVD_INTERFACE_DEFAULT);
 
     OIC_LOG_PAYLOAD(DEBUG, (OCPayload *) rdPayload);
 
-    if (sendResponse(ehRequest, rdPayload) != OC_STACK_OK)
+    if (sendResponse(ehRequest, rdPayload, OC_EH_OK) != OC_STACK_OK)
     {
         OIC_LOG(ERROR, TAG, "Sending response failed.");
         ehResult = OC_EH_ERROR;
@@ -94,27 +105,43 @@ static OCEntityHandlerResult handlePublishRequest(const OCEntityHandlerRequest *
 
     OIC_LOG_V(DEBUG, TAG, "Received OC_REST_PUT from client with query: %s.", ehRequest->query);
 
-    OCRDPayload *payload = (OCRDPayload *)ehRequest->payload;
-    if (payload && payload->rdPublish)
+    OCRepPayload *payload = (OCRepPayload *)ehRequest->payload;
+    OCRepPayload *resPayload = NULL;
+    if (payload)
     {
-        OCRDStorePublishedResources(payload->rdPublish, &ehRequest->devAddr);
-    }
+        OIC_LOG_PAYLOAD(DEBUG, (OCPayload *) payload);
+        if (OCRDDatabaseInit(NULL) == OC_STACK_OK)
+        {
+            if (OCRDDatabaseStoreResources(payload, &ehRequest->devAddr) == OC_STACK_OK)
+            {
+                OIC_LOG_V(DEBUG, TAG, "Stored resources.");
+                resPayload = payload;
+                ehResult = OC_EH_OK;
+            }
+            else
+            {
+                resPayload = (OCRepPayload *)OCRepPayloadCreate();
+                ehResult = OC_EH_ERROR;
+            }
+        }
 
-    OCRDPayload *rdPayload = OCRDPayloadCreate();
-    if (!rdPayload)
-    {
-        OIC_LOG(ERROR, TAG, "Failed allocating memory.");
-        return OC_STACK_NO_MEMORY;
+        // Send Response
+        if (sendResponse(ehRequest, resPayload, ehResult) != OC_STACK_OK)
+        {
+            OIC_LOG(ERROR, TAG, "Sending response failed.");
+        }
     }
 
-    OIC_LOG_PAYLOAD(DEBUG, (OCPayload *) rdPayload);
+    return ehResult;
+}
 
-    if (sendResponse(ehRequest, rdPayload) != OC_STACK_OK)
-    {
-        OIC_LOG(ERROR, TAG, "Sending response failed.");
-        ehResult = OC_EH_ERROR;
-    }
+static OCEntityHandlerResult handleDeleteRequest(const OCEntityHandlerRequest *ehRequest)
+{
+    OIC_LOG(DEBUG, TAG, "handleDeleteRequest - IN");
 
+    (void) ehRequest;  // eliminates release warning
+
+    OCEntityHandlerResult ehResult = OC_EH_OK;
     return ehResult;
 }
 
@@ -144,8 +171,10 @@ static OCEntityHandlerResult rdEntityHandler(OCEntityHandlerFlag flag,
             case OC_REST_POST:
                 handlePublishRequest(ehRequest);
                 break;
-            case OC_REST_PUT:
             case OC_REST_DELETE:
+                ehRet = handleDeleteRequest(ehRequest);
+                break;
+            case OC_REST_PUT:
             case OC_REST_OBSERVE:
             case OC_REST_OBSERVE_ALL:
             case OC_REST_PRESENCE:
@@ -162,27 +191,32 @@ static OCEntityHandlerResult rdEntityHandler(OCEntityHandlerFlag flag,
  */
 OCStackResult OCRDStart()
 {
-    OCResourceHandle rdHandle = NULL;
+    OCStackResult result = OCCreateResource(&rdHandle,
+                                OC_RSRVD_RESOURCE_TYPE_RD,
+                                OC_RSRVD_INTERFACE_DEFAULT,
+                                OC_RSRVD_RD_URI,
+                                rdEntityHandler,
+                                NULL,
+                                (OC_ACTIVE | OC_DISCOVERABLE | OC_OBSERVABLE));
 
-    OCStackResult result = OCRDInitializeStorage();
     if (result == OC_STACK_OK)
     {
-        result = OCCreateResource(&rdHandle,
-                                  OC_RSRVD_RESOURCE_TYPE_RD,
-                                  OC_RSRVD_INTERFACE_DEFAULT,
-                                  OC_RSRVD_RD_URI,
-                                  rdEntityHandler,
-                                  NULL,
-                                  (OC_ACTIVE | OC_DISCOVERABLE | OC_OBSERVABLE));
+        OIC_LOG(DEBUG, TAG, "Resource Directory resource created.");
+    }
+    else
+    {
+        OIC_LOG(ERROR, TAG, "Failed creating Resource Directory resource.");
+        return result;
     }
+    result = OCBindResourceTypeToResource(rdHandle,
+                    OC_RSRVD_RESOURCE_TYPE_RDPUBLISH);
     if (result == OC_STACK_OK)
     {
-        OIC_LOG(DEBUG, TAG, "Resource Directory Started.");
+        OIC_LOG(DEBUG, TAG, "Resource Directory resource Publish created.");
     }
     else
     {
-        OCRDTerminateStorage();
-        OIC_LOG(ERROR, TAG, "Failed starting Resource Directory.");
+        OIC_LOG(ERROR, TAG, "Failed creating Resource Directory Publish resource.");
     }
 
     return result;
@@ -193,17 +227,24 @@ OCStackResult OCRDStart()
  */
 OCStackResult OCRDStop()
 {
-    OCRDTerminateStorage();
+    if (!rdHandle)
+    {
+        OIC_LOG(ERROR, TAG, "Resource Directory resource handle is not initialized.");
+        return OC_STACK_NO_RESOURCE;
+    }
 
-    OCStackResult result = OCStop();
+    OCStackResult result = OCDeleteResource(rdHandle);
 
     if (result == OC_STACK_OK)
     {
-        OIC_LOG(DEBUG, TAG, "Resource Directory Stopped.");
+      OIC_LOG(DEBUG, TAG, "Resource Directory resource deleted.");
     }
     else
     {
-        OIC_LOG(ERROR, TAG, "Failed stopping Resource Directory.");
+      OIC_LOG(ERROR, TAG, "Resource Directory resource not deleted.");
     }
+
     return result;
 }
+
+#endif
diff --git a/resource/csdk/resource-directory/unittests/SConscript b/resource/csdk/resource-directory/unittests/SConscript
new file mode 100644 (file)
index 0000000..ba5bc2b
--- /dev/null
@@ -0,0 +1,93 @@
+#******************************************************************
+#
+# Copyright 2016 Samsung Electronics All Rights Reserved.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# ResourceDirectory Unit Test build script
+##
+# SConscript file for Local PKI google tests
+gtest_env = SConscript('#extlibs/gtest/SConscript')
+lib_env = gtest_env.Clone()
+target_os = lib_env.get('TARGET_OS')
+
+if lib_env.get('RELEASE'):
+    lib_env.AppendUnique(CCFLAGS = ['-Os'])
+    lib_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+    lib_env.AppendUnique(CCFLAGS = ['-g'])
+
+if lib_env.get('LOGGING'):
+    lib_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+# Add third party libraries
+SConscript('#service/third_party_libs.scons', 'lib_env')
+
+if target_os in ['linux']:
+    # Verify that 'hippomocks' mocking code is installed.  If not,
+    # get it and install it
+    SConscript('#extlibs/hippomocks.scons')
+
+rd_test_env = lib_env.Clone()
+
+######################################################################
+#unit test setting
+######################################################################
+src_dir = lib_env.get('SRC_DIR')
+
+######################################################################
+# Build flags
+######################################################################
+rd_test_env.AppendUnique(
+        CPPPATH = [
+                src_dir + '/extlibs/hippomocks-master',
+                '../include',
+                '../../stack/test/',
+        ])
+
+rd_test_env.PrependUnique(LIBS = [
+    'connectivity_abstraction',
+    'oc_logger',
+    'oc_logger_core',
+    'octbstack',
+    'oc',
+    'resource_directory'])
+
+if rd_test_env.get('RD_MODE'):
+    rd_mode = rd_test_env.get('RD_MODE')
+    if 'CLIENT' in rd_mode:
+        rd_test_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
+    if 'SERVER' in rd_mode:
+        rd_test_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
+
+######################################################################
+# Build Test
+######################################################################
+rd_test_src = ['rdtests.cpp']
+if 'SERVER' in rd_test_env.get('RD_MODE'):
+    rd_test_src += ['rddatabase.cpp']
+
+rd_client_test = rd_test_env.Program('rdtests', rd_test_src)
+Alias("rd_client_test", rd_client_test)
+rd_test_env.AppendTarget('rd_client_test')
+
+if rd_test_env.get('TEST') == '1':
+    target_os = rd_test_env.get('TARGET_OS')
+    if target_os in ['linux']:
+        from tools.scons.RunTest import *
+        run_test(rd_test_env, '', 'resource/csdk/resource-directory/unittests/rdtests')
diff --git a/resource/csdk/resource-directory/unittests/rddatabase.cpp b/resource/csdk/resource-directory/unittests/rddatabase.cpp
new file mode 100644 (file)
index 0000000..148295f
--- /dev/null
@@ -0,0 +1,172 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+extern "C"
+{
+    #include "rd_server.h"
+    #include "rd_client.h"
+    #include "rd_database.h"
+    #include "ocstack.h"
+    #include "logger.h"
+    #include "oic_malloc.h"
+    #include "oic_string.h"
+    #include "ocpayload.h"
+    #include "payload_logging.h"
+}
+
+#include "gtest/gtest.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+//-----------------------------------------------------------------------------
+// Includes
+//-----------------------------------------------------------------------------
+#include <stdio.h>
+#include <string.h>
+
+#include <iostream>
+#include <stdint.h>
+
+#include "gtest_helper.h"
+
+using namespace std;
+
+namespace itst = iotivity::test;
+
+#define DEFAULT_CONTEXT_VALUE 0x99
+
+//-----------------------------------------------------------------------------
+// Private variables
+//-----------------------------------------------------------------------------
+static const char TAG[] = "RDDatabaseTests";
+
+std::chrono::seconds const SHORT_TEST_TIMEOUT = std::chrono::seconds(5);
+
+//-----------------------------------------------------------------------------
+// Callback functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+//  Tests
+//-----------------------------------------------------------------------------
+class RDDatabaseTests : public testing::Test {
+    protected:
+    virtual void SetUp()
+    {
+        OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER);
+    }
+
+    virtual void TearDown()
+    {
+        OCStop();
+    }
+};
+
+TEST_F(RDDatabaseTests, CreateDatabase)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseInit(NULL));
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseClose());
+}
+
+TEST_F(RDDatabaseTests, PublishDatabase)
+{
+    // itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseInit(NULL));
+    OCRepPayload *repPayload = OCRepPayloadCreate();
+    EXPECT_TRUE(repPayload != NULL);
+    const char *deviceId = OCGetServerInstanceIDString();
+    EXPECT_TRUE(deviceId != NULL);
+    EXPECT_TRUE(OCRepPayloadSetPropString(repPayload, OC_RSRVD_DEVICE_ID, deviceId));
+    EXPECT_TRUE(OCRepPayloadSetPropInt(repPayload, OC_RSRVD_DEVICE_TTL, 86400));
+    OCDevAddr address;
+    address.port = 54321;
+    OICStrcpy(address.addr,MAX_ADDR_STR_SIZE, "192.168.1.1");
+
+    std::string resourceURI_thermostat = "/a/thermostat";
+    std::string resourceTypeName_thermostat = "core.thermostat";
+    std::string resourceURI_light = "/a/light";
+    std::string resourceTypeName_light = "core.light";
+
+    const OCRepPayload *linkArr[2];
+    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
+
+    OCRepPayload *link = OCRepPayloadCreate();
+    OCRepPayloadSetPropString(link, OC_RSRVD_HREF, resourceURI_thermostat.c_str());
+    size_t rtDim[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
+    char **rt = (char **)OICMalloc(sizeof(char *) * 1);
+    rt[0] = OICStrdup(resourceTypeName_thermostat.c_str());
+    OCRepPayloadSetStringArray(link, OC_RSRVD_RESOURCE_TYPE, (const char **)rt,
+                               rtDim);
+
+    size_t itfDim[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
+    char **itf = (char **)OICMalloc(sizeof(char *) * 1);
+    itf[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
+    OCRepPayloadSetStringArray(link, OC_RSRVD_INTERFACE, (const char **)itf,
+                              itfDim);
+    OCRepPayloadSetPropInt(link, OC_RSRVD_INS, 0);
+    size_t mtDim[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
+    char **mt = (char **)OICMalloc(sizeof(char *) * 1);
+    mt[0] = OICStrdup(DEFAULT_MESSAGE_TYPE);
+    OCRepPayloadSetStringArray(link, OC_RSRVD_MEDIA_TYPE, (const char **)mt,
+                               mtDim);
+    OCRepPayload *policy = OCRepPayloadCreate();
+    OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP, OC_DISCOVERABLE);
+    OCRepPayloadSetPropObjectAsOwner(link, OC_RSRVD_POLICY, policy);
+    linkArr[0] = link;
+
+    OCRepPayload *link1 = OCRepPayloadCreate();
+    OCRepPayloadSetPropString(link1, OC_RSRVD_HREF, resourceURI_light.c_str());
+    char **rt1 = (char **)OICMalloc(sizeof(char *) * 1);
+    rt1[0] = OICStrdup(resourceTypeName_light.c_str());
+    OCRepPayloadSetStringArray(link1, OC_RSRVD_RESOURCE_TYPE, (const char **)rt1,
+                               rtDim);
+    OCRepPayloadSetStringArray(link1, OC_RSRVD_INTERFACE, (const char **)itf,
+                              itfDim);
+    OCRepPayloadSetPropInt(link1, OC_RSRVD_INS, 1);
+    OCRepPayloadSetStringArray(link1, OC_RSRVD_MEDIA_TYPE, (const char **)mt,
+                               mtDim);
+    OCRepPayloadSetPropObjectAsOwner(link1, OC_RSRVD_POLICY, policy);
+    linkArr[1] = link1;
+    OCRepPayloadSetPropObjectArray(repPayload, OC_RSRVD_LINKS, linkArr, dimensions);
+
+    OIC_LOG_PAYLOAD(DEBUG, (OCPayload *)repPayload);
+
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseStoreResources(repPayload, &address));
+    OCDiscoveryPayload *discPayload = OCDiscoveryPayloadCreate();
+    EXPECT_TRUE(discPayload != NULL);
+    EXPECT_EQ(discPayload->base.type, PAYLOAD_TYPE_DISCOVERY);
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseCheckResources(NULL, "core.light", discPayload));
+    OCDiscoveryPayloadDestroy(discPayload);
+    OCDiscoveryPayload *discPayload1 = OCDiscoveryPayloadCreate();
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseCheckResources(OC_RSRVD_INTERFACE_DEFAULT, NULL, discPayload1));
+    OCDiscoveryPayloadDestroy(discPayload1);
+    OCDiscoveryPayload *discPayload2 = OCDiscoveryPayloadCreate();
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseCheckResources(NULL, "core.light", discPayload2));
+    OCDiscoveryPayloadDestroy(discPayload2);
+    OCDiscoveryPayload *discPayload3 = OCDiscoveryPayloadCreate();
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseCheckResources(OC_RSRVD_INTERFACE_DEFAULT, "core.light", discPayload3));
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseDeleteDevice(deviceId));
+    EXPECT_EQ(OC_STACK_OK, OCRDDatabaseClose());
+}
 
 extern "C"
 {
-    #include "rdpayload.h"
-    #include "oicresourcedirectory.h"
+    #include "rd_server.h"
+    #include "rd_client.h"
     #include "ocstack.h"
-    #include "ocstackinternal.h"
     #include "logger.h"
     #include "oic_malloc.h"
 }
@@ -63,6 +62,19 @@ std::chrono::seconds const SHORT_TEST_TIMEOUT = std::chrono::seconds(5);
 //-----------------------------------------------------------------------------
 // Callback functions
 //-----------------------------------------------------------------------------
+#ifdef RD_SERVER
+static OCStackApplicationResult handleDiscoveryCB(__attribute__((unused))void *ctx,
+                                                  __attribute__((unused)) OCDoHandle handle,
+                                                  __attribute__((unused))
+                                                  OCClientResponse *clientResponse)
+{
+    OIC_LOG(DEBUG, TAG, "Successfully found RD.");
+
+    return OC_STACK_DELETE_TRANSACTION;
+}
+#endif
+
+#ifdef RD_CLIENT
 static OCStackApplicationResult handlePublishCB(__attribute__((unused))void *ctx,
                                                 __attribute__((unused)) OCDoHandle handle,
                                                 __attribute__((unused))
@@ -82,6 +94,7 @@ static OCStackApplicationResult handleDeleteCB(__attribute__((unused))void *ctx,
 
     return OC_STACK_DELETE_TRANSACTION;
 }
+#endif
 
 //-----------------------------------------------------------------------------
 // Entity handler
@@ -111,56 +124,74 @@ class RDTests : public testing::Test {
     }
 };
 
-TEST_F(RDTests, CreateRDPayload)
+#ifdef RD_SERVER
+TEST_F(RDTests, CreateRDResource)
 {
     itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_OK, OCRDStart());
 
-    OCResourceHandle handle;
-    EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle, "core.light",
-                                            "oic.if.baseline", "/a/light", rdEntityHandler,
-                                            NULL, OC_DISCOVERABLE | OC_OBSERVABLE));
+    OCCallbackData cbData;
+    cbData.cb = &handleDiscoveryCB;;
+    cbData.cd = NULL;
+    cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
 
-    // Create RD Publish Payload.
-    OCRDPayload *rdPayload = (OCRDPayload *) OCRDPublishPayloadCreate(&handle, 1, 86400);
-    EXPECT_TRUE(rdPayload != NULL);
+    EXPECT_EQ(OC_STACK_OK, OCRDDiscover(CT_ADAPTER_IP, &cbData, OC_LOW_QOS));
 
-    // Cleanup.
-    OCRDPayloadDestroy(rdPayload);
+    EXPECT_EQ(OC_STACK_OK, OCRDStop());
 }
+#endif
 
-TEST_F(RDTests, ConvertParseRDPayload)
-{
-    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
-
-    OCResourceHandle handle;
-    EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle, "core.light",
-                                            "oic.if.baseline", "/a/light", rdEntityHandler,
-                                            NULL, OC_DISCOVERABLE | OC_OBSERVABLE));
-
-    // Create RD Publish Payload.
-    OCRDPayload *rdPayload = (OCRDPayload *) OCRDPublishPayloadCreate(&handle, 1, 86400);
-    EXPECT_TRUE(rdPayload != NULL);
-
-    if (rdPayload)
-    {
-        // Convert RD Publish Payload to CBOR.
-        size_t curSize = 255;
-        uint8_t *outPayload = (uint8_t *)OICCalloc(1, curSize);
-        OCRDPayloadToCbor(rdPayload, outPayload, &curSize);
-
-        // Parse CBOR back to RD Publish Payload.
-        CborParser parser;
-        CborValue rootValue;
-        cbor_parser_init(outPayload, curSize, 0, &parser, &rootValue);
-
-        OCRDPayload *rdPayload = NULL;
-        EXPECT_EQ(OC_STACK_OK, OCRDCborToPayload(&rootValue, (OCPayload**) &rdPayload));
-
-        // Cleanup.
-        OICFree(outPayload);
-    }
-    OCRDPayloadDestroy(rdPayload);
-}
+#ifdef RD_CLIENT
+// TEST_F(RDTests, CreateRDPayload)
+// {
+//     itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+//
+//     OCResourceHandle handle;
+//     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle, "core.light",
+//                                             "oic.if.baseline", "/a/light", rdEntityHandler,
+//                                             NULL, OC_DISCOVERABLE | OC_OBSERVABLE));
+//
+//     // Create RD Publish Payload.
+//     // OCRDPayload *rdPayload = (OCRDPayload *) OCRDPublishPayloadCreate(&handle, 1, 86400);
+//     // EXPECT_TRUE(rdPayload != NULL);
+//
+//     // Cleanup.
+//     // OCPayloadDestroy(rdPayload);
+// }
+//
+// TEST_F(RDTests, ConvertParseRDPayload)
+// {
+//     itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+//
+//     OCResourceHandle handle;
+//     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle, "core.light",
+//                                             "oic.if.baseline", "/a/light", rdEntityHandler,
+//                                             NULL, OC_DISCOVERABLE | OC_OBSERVABLE));
+//
+//     // Create RD Publish Payload.
+//     OCRDPayload *rdPayload = (OCRDPayload *) OCRDPublishPayloadCreate(&handle, 1, 86400);
+//     EXPECT_TRUE(rdPayload != NULL);
+//
+//     if (rdPayload)
+//     {
+//         // Convert RD Publish Payload to CBOR.
+//         size_t curSize = 255;
+//         uint8_t *outPayload = (uint8_t *)OICCalloc(1, curSize);
+//         OCRDPayloadToCbor(rdPayload, outPayload, &curSize);
+//
+//         // Parse CBOR back to RD Publish Payload.
+//         CborParser parser;
+//         CborValue rootValue;
+//         cbor_parser_init(outPayload, curSize, 0, &parser, &rootValue);
+//
+//         OCRDPayload *rdPayload = NULL;
+//         EXPECT_EQ(OC_STACK_OK, OCRDCborToPayload(&rootValue, (OCPayload**) &rdPayload));
+//
+//         // Cleanup.
+//         OICFree(outPayload);
+//     }
+//     OCRDPayloadDestroy(rdPayload);
+// }
 
 TEST_F(RDTests, RDPublishResourceNullAddr)
 {
@@ -260,3 +291,4 @@ TEST_F(RDTests, RDDeleteSpecificResource)
     EXPECT_EQ(OC_STACK_OK, OCRDDelete("127.0.0.1", CT_ADAPTER_IP, &handle,
                                       1, &cbData, OC_LOW_QOS));
 }
+#endif
index 7a7c4a0..ad703c5 100644 (file)
 #ifndef __STDC_LIMIT_MACROS
 #define __STDC_LIMIT_MACROS
 #endif
+
 #include <stdbool.h>
 #include <inttypes.h>
 #include "octypes.h"
+#include <cbor.h>
 
 #ifdef __WITH_TLS__
 #include "securevirtualresourcetypes.h"
index 1cb7845..6c96945 100644 (file)
@@ -1236,9 +1236,7 @@ typedef enum
     /** The payload is an OCSecurityPayload */
     PAYLOAD_TYPE_SECURITY,
     /** The payload is an OCPresencePayload */
-    PAYLOAD_TYPE_PRESENCE,
-    /** The payload is an OCRDPayload */
-    PAYLOAD_TYPE_RD,
+    PAYLOAD_TYPE_PRESENCE
 } OCPayloadType;
 
 /**
@@ -1342,66 +1340,6 @@ typedef struct OCResourcePayload
     struct OCResourcePayload* next;
 } OCResourcePayload;
 
-/**
- * Structure holding Links Payload. It is a sub-structure used in
- * OCResourceCollectionPayload.
- */
-typedef struct OCLinksPayload
-{
-    /** This is the target relative URI. */
-    char *href;
-    /** The relation of the target URI referenced by the link to the context URI;
-     * The default value is null. */
-    char *rel;
-    /** Resource Type - A standard OIC specified or vendor defined resource
-     * type of the resource referenced by the target URI. */
-    OCStringLL *rt;
-    /** Interface - The interfaces supported by the resource referenced by the target URI. */
-    OCStringLL *itf;
-    /** Bitmap - The bitmap holds observable, discoverable, secure option flag. */
-    uint8_t p;
-    /** A title for the link relation. Can be used by the UI to provide a context. */
-    char *title;
-    /** This is used to override the context URI e.g. override the URI of the containing collection. */
-    char *anchor;
-    /** The instance identifier for this web link in an array of web links - used in links. */
-    union
-    {
-        /** An ordinal number that is not repeated - must be unique in the collection context. */
-        uint8_t ins;
-        /** Any unique string including a URI. */
-        char *uniqueStr;
-        /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
-        OCIdentity uniqueUUID;
-    };
-    /** Time to keep holding resource.*/
-    uint64_t ttl;
-    /** A hint of the media type of the representation of the resource referenced by the target URI. */
-    OCStringLL *type;
-    /** Holding address of the next resource. */
-    struct OCLinksPayload *next;
-} OCLinksPayload;
-
-/** Structure holding tags value of the links payload. */
-typedef struct
-{
-    /** Name of tags. */
-    OCDeviceInfo n;
-    /** Device identifier. */
-    OCIdentity di;
-    /** Time to keep holding resource.*/
-    uint64_t ttl;
-} OCTagsPayload;
-
-/** Resource collection payload. */
-typedef struct OCResourceCollectionPayload
-{
-    /** Collection tags payload.*/
-    OCTagsPayload *tags;
-    /** Array of links payload. */
-    OCLinksPayload *setLinks;
-} OCResourceCollectionPayload;
-
 typedef struct OCDiscoveryPayload
 {
     OCPayload base;
@@ -1432,31 +1370,6 @@ typedef struct OCDiscoveryPayload
 
 } OCDiscoveryPayload;
 
-/**
- * Structure holding discovery payload.
- */
-typedef struct
-{
-    /** Device Name. */
-    OCDeviceInfo n;
-    /** Device Identity. */
-    OCIdentity di;
-    /** Value holding the bias factor of the RD. */
-    uint8_t sel;
-} OCRDDiscoveryPayload;
-
-/**
- * RD Payload that will be transmitted over the wire.
- */
-typedef struct
-{
-    OCPayload base;
-    /** Pointer to the discovery response payload.*/
-    OCRDDiscoveryPayload *rdDiscovery;
-    /** Pointer to the publish payload.*/
-    OCResourceCollectionPayload *rdPublish;
-} OCRDPayload;
-
 typedef struct
 {
     OCPayload base;
index 5f3a8c1..7a21fd9 100644 (file)
 #ifndef __STDC_LIMIT_MACROS
 #define __STDC_LIMIT_MACROS
 #endif
+
 #include <inttypes.h>
-#include "rdpayload.h"
 #include "oic_malloc.h"
 #include "ocpayload.h"
+#include "ocstack.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -48,173 +49,120 @@ extern "C"
 #ifdef TB_LOG
     #define OIC_LOG_PAYLOAD(level, payload) OCPayloadLog((level),(payload))
     #define UUID_SIZE (16)
+
 const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
 OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
 
-#if defined(RD_CLIENT) || defined(RD_SERVER)
-INLINE_API void OCTagsLog(const LogLevel level, const OCTagsPayload *tags)
-{
-    if (tags)
-    {
-        if (tags->n.deviceName)
-        {
-            OIC_LOG_V(level, PL_TAG, " Device Name : %s ", tags->n.deviceName);
-        }
-        if (tags->di.id)
-        {
-            OIC_LOG_V(level, PL_TAG, " Device ID : %s ", tags->di.id);
-        }
-        OIC_LOG_V(level, PL_TAG, " lt : %" PRIu64 ,tags->ttl);
-    }
-    else
-    {
-        (void) level;
-    }
-}
-
-INLINE_API void OCLinksLog(const LogLevel level, const OCLinksPayload *links)
-{
-    if (!links)
-    {
-        return;
-    }
-
-    while (links)
-    {
-        if (links->href)
-        {
-            OIC_LOG_V(level, PL_TAG, "   href: %s ",links->href);
-        }
-        OIC_LOG(level, PL_TAG, "   RT: ");
-        OCStringLL *rt = links->rt;
-        while (rt)
-        {
-            if (rt->value)
-            {
-                OIC_LOG_V(level, PL_TAG, "   %s", rt->value);
-            }
-            rt = rt->next;
-        }
-        OIC_LOG(level, PL_TAG, "   IF: ");
-        OCStringLL *itf = links->itf;
-        while (itf)
-        {
-            if (itf->value)
-            {
-                OIC_LOG_V(level, PL_TAG, "   %s", itf->value);
-            }
-            itf = itf->next;
-        }
-        OIC_LOG(level, PL_TAG, "   MT: ");
-        OCStringLL *mt = links->type;
-        while (mt)
-        {
-            if (mt->value)
-            {
-                OIC_LOG_V(level, PL_TAG, "   %s", mt->value);
-            }
-            mt = mt->next;
-        }
-        if (links->type)
-        {
-            OIC_LOG_V(level, PL_TAG, "   %s", links->type->value);
-        }
-        OIC_LOG_V(level, PL_TAG, "   INS: %d", links->ins);
-        OIC_LOG_V(level, PL_TAG, "   TTL: %" PRIu64 , links->ttl);
-        OIC_LOG_V(level, PL_TAG, "   P: %d", links->p);
-        if (links->rel)
-        {
-            OIC_LOG_V(level, PL_TAG, "   REL: %s", links->rel);
-        }
-        if (links->title)
-        {
-            OIC_LOG_V(level, PL_TAG, "   TITLE: %s", links->title);
-        }
-        if (links->anchor)
-        {
-            OIC_LOG_V(level, PL_TAG, "   URI: %s", links->anchor);
-        }
-        links = links->next;
-    }
-}
-#endif
-
-//forward declaration required because function below is recursive
 INLINE_API void OCPayloadLogRep(LogLevel level, OCRepPayload* payload);
 
 INLINE_API void OCPayloadLogRepValues(LogLevel level, OCRepPayloadValue* val)
 {
-    while(val)
+    while (val)
     {
         switch(val->type)
         {
             case OCREP_PROP_NULL:
-                OIC_LOG_V(level, PL_TAG, "%s: NULL", val->name);
+                OIC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
                 break;
             case OCREP_PROP_INT:
-                OIC_LOG_V(level, PL_TAG, "%s(int):%zd", val->name, val->i);
+                OIC_LOG_V(level, PL_TAG, "\t\t%s(int):%zd", val->name, val->i);
                 break;
             case OCREP_PROP_DOUBLE:
-                OIC_LOG_V(level, PL_TAG, "%s(double):%f", val->name, val->d);
+                OIC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
                 break;
             case OCREP_PROP_BOOL:
-                OIC_LOG_V(level, PL_TAG, "%s(bool):%s", val->name, val->b ? "true" : "false");
+                OIC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
                 break;
             case OCREP_PROP_STRING:
-                OIC_LOG_V(level, PL_TAG, "%s(string):%s", val->name, val->str);
+                OIC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
                 break;
             case OCREP_PROP_BYTE_STRING:
-                OIC_LOG_V(level, PL_TAG, "%s(binary):", val->name);
+                OIC_LOG_V(level, PL_TAG, "\t\t%s(binary):", val->name);
                 OIC_LOG_BUFFER(level, PL_TAG, val->ocByteStr.bytes, val->ocByteStr.len);
                 break;
             case OCREP_PROP_OBJECT:
-                OIC_LOG_V(level, PL_TAG, "%s(OCRep):%s", val->name, val->obj->uri);
+                // Note: Only prints the URI (if available), to print further, you'll
+                // need to dig into the object better!
+                OIC_LOG_V(level, PL_TAG, "\t\t%s(object):", val->name);
                 OCPayloadLogRep(level, val->obj);
                 break;
             case OCREP_PROP_ARRAY:
-            {
-                size_t len = calcDimTotal(val->arr.dimensions);
-
-                OIC_LOG_V(level, PL_TAG, "%s(array): length = %zu", val->name, len);
-
-                for (size_t i = 0; i < len; i++)
+                switch(val->arr.type)
                 {
-                    OIC_LOG_V(level, PL_TAG, "%s[%zu]:", val->name, i);
-                    char *indent = (char *)"\t\t";
-
-                    switch(val->arr.type)
-                    {
-                        case OCREP_PROP_INT:
-                            OIC_LOG_V(level, PL_TAG, "%s%zd", indent, val->arr.iArray[i]);
-                            break;
-                        case OCREP_PROP_DOUBLE:
-                            OIC_LOG_V(level, PL_TAG, "%s%f", indent, val->arr.dArray[i]);
-                            break;
-                        case OCREP_PROP_BOOL:
-                            OIC_LOG_V(level, PL_TAG, "%s%s", indent, val->arr.bArray[i] ? "true" : "false");
-                            break;
-                        case OCREP_PROP_STRING:
-                            OIC_LOG_V(level, PL_TAG, "%s%s", indent, val->arr.strArray[i]);
-                            break;
-                        case OCREP_PROP_BYTE_STRING:
+                    case OCREP_PROP_INT:
+                        OIC_LOG_V(level, PL_TAG, "\t\t%s(int array):%zu x %zu x %zu: ",
+                                val->name,
+                                val->arr.dimensions[0], val->arr.dimensions[1],
+                                val->arr.dimensions[2]);
+                        OIC_LOG(level, PL_TAG, "\t\t Values:");
+                        for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+                        {
+                            OIC_LOG_V(level, PL_TAG, "\t\t\t %zd", val->arr.iArray[i]);
+                        }
+                        break;
+                    case OCREP_PROP_DOUBLE:
+                        OIC_LOG_V(level, PL_TAG, "\t\t%s(double array):%zu x %zu x %zu: ",
+                                val->name,
+                                val->arr.dimensions[0], val->arr.dimensions[1],
+                                val->arr.dimensions[2]);
+                        OIC_LOG(level, PL_TAG, "\t\t Values:");
+                        for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+                        {
+                            OIC_LOG_V(level, PL_TAG, "\t\t\t %lf", val->arr.dArray[i]);
+                        }
+                        break;
+                    case OCREP_PROP_BOOL:
+                        OIC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%zu x %zu x %zu: ",
+                                val->name,
+                                val->arr.dimensions[0], val->arr.dimensions[1],
+                                val->arr.dimensions[2]);
+                        OIC_LOG(level, PL_TAG, "\t\t Values:");
+                        for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+                        {
+                            OIC_LOG_V(level, PL_TAG, "\t\t\t %d", val->arr.bArray[i]);
+                        }
+                        break;
+                    case OCREP_PROP_STRING:
+                        OIC_LOG_V(level, PL_TAG, "\t\t%s(string array):%zu x %zu x %zu: ",
+                                val->name,
+                                val->arr.dimensions[0], val->arr.dimensions[1],
+                                val->arr.dimensions[2]);
+                        OIC_LOG(level, PL_TAG, "\t\t Values:");
+                        for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+                        {
+                            OIC_LOG_V(level, PL_TAG, "\t\t\t %s", val->arr.strArray[i]);
+                        }
+                        break;
+                    case OCREP_PROP_BYTE_STRING:
+                        OIC_LOG_V(level, PL_TAG, "\t\t%s(byte array):%zu x %zu x %zu: ",
+                                val->name,
+                                val->arr.dimensions[0], val->arr.dimensions[1],
+                                val->arr.dimensions[2]);
+                        OIC_LOG(level, PL_TAG, "\t\t Values:");
+                        for (size_t i = 0; i < val->arr.dimensions[0]; i++)
                         {
-                            OCByteString* data = &val->arr.ocByteStrArray[i];
-                            OIC_LOG_V(level, PL_TAG, "%s binary string, it's len = %zu, bytes:", indent, data->len);
-                            OIC_LOG_BUFFER(level, PL_TAG, data->bytes, data->len);
+                            OIC_LOG_BUFFER(level, PL_TAG, val->arr.ocByteStrArray[i].bytes, val->arr.ocByteStrArray[i].len);
                         }
-                            break;
-                        case OCREP_PROP_OBJECT:
+                        break;
+                    case OCREP_PROP_OBJECT:
+                        OIC_LOG_V(level, PL_TAG, "\t\t%s(object array):%zu x %zu x %zu: ",
+                                val->name,
+                                val->arr.dimensions[0], val->arr.dimensions[1],
+                                val->arr.dimensions[2]);
+                        OIC_LOG(level, PL_TAG, "\t\t Values:");
+
+                        for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+                        {
                             OCPayloadLogRep(level, val->arr.objArray[i]);
-                            break;
-                        case OCREP_PROP_ARRAY: //Seems as nested arrays doesn't not supported in API
-                        default:
-                            OIC_LOG_V(ERROR, PL_TAG, "%s <-- Unknown/unsupported array type!",
-                                    val->name);
-                            break;
-                    }
+                        }
+                        break;
+                    case OCREP_PROP_ARRAY: //Seems as nested arrays doesn't not supported in API
+                    default:
+                        OIC_LOG_V(ERROR, PL_TAG, "%s <-- Unknown/unsupported array type!",
+                                val->name);
+                        break;
                 }
                 break;
-            }
             default:
                 OIC_LOG_V(ERROR, PL_TAG, "%s <-- Unknown type!", val->name);
                 break;
@@ -225,28 +173,33 @@ INLINE_API void OCPayloadLogRepValues(LogLevel level, OCRepPayloadValue* val)
 
 INLINE_API void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
 {
-    OCRepPayload* rep = payload;
+    OIC_LOG(level, (PL_TAG), "Payload Type: Representation");
     int i = 1;
-    while(rep)
+    for (OCRepPayload* rep = payload; rep; rep = rep->next, ++i)
     {
-        OCStringLL* strll =  rep->types;
-        while(strll)
+        OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
+        if (rep->uri)
         {
-            strll = strll->next;
+            OIC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
         }
-        strll =  rep->interfaces;
-        while(strll)
+        if (rep->types)
         {
-            strll = strll->next;
+            OIC_LOG(level, PL_TAG, "\tResource Types:");
+            for (OCStringLL* strll = rep->types; strll; strll = strll->next)
+            {
+                OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+            }
         }
-
-        // TODO Finish Logging: Values
-        OCRepPayloadValue* val = rep->values;
-
-        OCPayloadLogRepValues(level, val);
-
-        ++i;
-        rep = rep->next;
+        if (rep->interfaces)
+        {
+            OIC_LOG(level, PL_TAG, "\tInterfaces:");
+            for (OCStringLL* strll = rep->interfaces; strll; strll = strll->next)
+            {
+                OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+            }
+        }
+        OIC_LOG(level, PL_TAG, "\tValues:");
+        OCPayloadLogRepValues(level, rep->values);
     }
 }
 
@@ -403,7 +356,7 @@ INLINE_API void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
         if (securityData)
         {
             memcpy(securityData, payload->securityData, payloadSize);
-            assert(securityData[payloadSize - 1] != '\0');
+            // assert(securityData[payloadSize - 1] != '\0');
             securityData[payloadSize] = '\0';
             OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", securityData);
             OICFree(securityData);
@@ -411,30 +364,6 @@ INLINE_API void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
     }
 }
 
-#if defined(RD_CLIENT) || defined(RD_SERVER)
-INLINE_API void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
-{
-    if (!payload)
-    {
-        return;
-    }
-
-    if (payload->rdDiscovery)
-    {
-        OIC_LOG(level, PL_TAG, "RD Discovery");
-        OIC_LOG_V(level, PL_TAG, "  Device Name : %s", payload->rdDiscovery->n.deviceName);
-        OIC_LOG_V(level, PL_TAG, "  Device Identity : %s", payload->rdDiscovery->di.id);
-        OIC_LOG_V(level, PL_TAG, "  Bias: %d", payload->rdDiscovery->sel);
-    }
-    if (payload->rdPublish)
-    {
-        OIC_LOG(level, PL_TAG, "RD Publish");
-        OCResourceCollectionPayload *rdPublish = payload->rdPublish;
-        OCTagsLog(level, rdPublish->tags);
-        OCLinksLog(level, rdPublish->setLinks);
-    }
-}
-#endif
 INLINE_API void OCPayloadLog(LogLevel level, OCPayload* payload)
 {
     if(!payload)
@@ -462,11 +391,6 @@ INLINE_API void OCPayloadLog(LogLevel level, OCPayload* payload)
         case PAYLOAD_TYPE_SECURITY:
             OCPayloadLogSecurity(level, (OCSecurityPayload*)payload);
             break;
-#if defined(RD_CLIENT) || defined(RD_SERVER)
-        case PAYLOAD_TYPE_RD:
-            OCRDPayloadLog(level, (OCRDPayload*)payload);
-            break;
-#endif
         default:
             OIC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
             break;
diff --git a/resource/csdk/stack/include/rdpayload.h b/resource/csdk/stack/include/rdpayload.h
deleted file mode 100644 (file)
index 766a44b..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef OC_RDPAYLOAD_H_
-#define OC_RDPAYLOAD_H_
-
-#include <cbor.h>
-#include "octypes.h"
-#include "logger.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-#define OIC_RD_PUBLISH_TTL 86400
-
-#define OIC_RD_DEFAULT_RESOURCE 2
-
-#define DEFAULT_MESSAGE_TYPE "application/json"
-
-/**
- * Converts RD payload from structure to CBOR format. It creates the outPayload
- * which is then transmitted over the wire.
- *
- * @param rdPayload Contains structure holding values of OCRDPayload.
- * @param outPayload The payload in the CBOR format converting OCRDPayload
- * structure.
- * @param size Length of the payload.
- *
- * @return ::CborNoError returns if successful and other Cbor error in  case of error.
- * failed in creating CBOR.
- */
-int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, size_t *size);
-
-/**
- * Converts CBOR to OCRDPayload.
- *
- * @param rdCBORPayload Payload received from other end in CBOR format.
- * @param outPayload Parsing the values from CBOR into OCRDPayload structure.
- *
- * @return ::OC_STACK_OK returns if successful and OC_STACK_ERROR returns if
- * failed in parsing CBOR.
- */
-OCStackResult OCRDCborToPayload(const CborValue *cborPayload, OCPayload **outPayload);
-
-/**
- * Initializes RD payload structure.
- *
- * @param payloadType Defines whether payload is RD_PAYLOAD_TYPE_DISCOVERY or
- * RD_PAYLOAD_TYPE_PUBLISH.
- *
- * @return Allocated memory for the OCRDPayload and NULL in case if failed to
- * allocate memory
- */
-OCRDPayload *OCRDPayloadCreate();
-
-#ifdef RD_CLIENT
-/**
- * Initializes RD Publish payload structure.
- *
- * @param id An unique identifier of publishing device.
- * @param resourceHandles The handle of registered resource.
- * @param nHandles The number of registered resource handles.
- * @param ttl Time to live of the published resource.
- *
- * @return Allocated memory for the OCRDPayload and NULL in case if
- * failed to allocate memory.
- */
-OCRDPayload *OCRDPublishPayloadCreate(const unsigned char *id,
-                                      OCResourceHandle *resourceHandles, uint8_t nHandles,
-                                      uint64_t ttl);
-#endif
-
-/**
- * Initializes RD Discovery payload structure and sets the bias factor.
- *
- * @param name Name of the discovery device payload.
- * @param identity Device identity of the discovery device.
- * @param biasFactor Value specifies the selection factor. It is weigthage of
- * CPU, Memory, Network, Load and Power capability of the RD server.
- *
- * @return Allocated memory for the OCRDDiscoveryPayload and NULL in case if
- * failed to allocate memory.
- */
-OCRDDiscoveryPayload *OCRDDiscoveryPayloadCreate(const char *name, const char *identity, int biasFactor);
-
-/**
- * Free memory allocation of the RDPayload and its internal structure.
- *
- * @param payload Pointer to already allocated memory for OCRDPayload.
- */
-void OCRDPayloadDestroy(OCRDPayload *payload);
-
-/**
- * Copies tag paramter to creates OCTagsPayload.
- *
- * @param deviceName The device name as set during enrollment.
- * @param id The device UUID.
- * @param ttl Time to leave for the . Used only in resource directory.
- *
- * @retun Allocated memory for OCTagsPayload or else NULL in case of error.
- */
-OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *id, uint64_t ttl);
-
-/**
- * Copies link resource to create LinksPayload.
- *
- * @param href URI of the resource
- * @param rel Relation
- * @param rt Array of String pointing to resource types.
- * @param itf Array of String pointing to interface
- * @param p Whether to observe or not.
- * @param title Title
- * @param anchor URI
- * @param ins Unique value per link.
- * @param ttl Time to live for this link.
- * @param mt Media Type
-
- * @retun Allocated memory for OCLinksResource or else NULL in case of error.
- */
-OCLinksPayload* OCCopyLinksResources(const char *href, const char *rel, OCStringLL *rt,
-                                     OCStringLL *itf, uint8_t p, const char *title,
-                                     const char *anchor, uint8_t ins, uint64_t ttl,
-                                     OCStringLL *mt);
-
-/**
- * Creates a resource collection object.
- *
- * @param tags Pointer pointing to tags payload.
- * @param links Pointer pointing to links payload.
- *
- * @return Memory allocation for OCResourceCollectionPayload, else NULL.
- */
-OCResourceCollectionPayload* OCCopyCollectionResource(OCTagsPayload *tags, OCLinksPayload *links);
-
-/**
- * Destroys tags payload including internal structure allocated
- *
- * @param tags - Allocated memory of the tags payload.
- */
-void OCFreeTagsResource(OCTagsPayload *tags);
-
-/**
- * Destroys allocated links payload including internal structure allocated.
- *
- * @param links - Allocated memory to the links payload.
- */
-void OCFreeLinksResource(OCLinksPayload *links);
-
-/**
- * ResourceCollection payload destroy. Includes free up tags and links structure.
- *
- * @param payload Pointer pointing to allocated memroy of ResourceCollection.
- */
-void OCFreeCollectionResource(OCResourceCollectionPayload *payload);
-
-/**
- * Discovery collection payload destroy includes internal structure OCResourceCollectionPayload.
- *
- * @param payload Pointer pointing to allocated memory of OCDiscoveryPayload.
- */
-void OCDiscoveryCollectionPayloadDestroy(OCDiscoveryPayload* payload);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif /* OC_RDPAYLOAD_H_ */
index 352f95d..7ed5135 100644 (file)
@@ -75,7 +75,6 @@ cp resource/c_common/platform_features.h %{DEST_INC_DIR}
 cp resource/c_common/iotivity_config.h %{DEST_INC_DIR}
 cp resource/c_common/*/include/*.h %{DEST_INC_DIR}
 cp resource/csdk/stack/include/payload_logging.h %{DEST_INC_DIR}
-cp resource/csdk/stack/include/rdpayload.h %{DEST_INC_DIR}
 cp extlibs/tinycbor/tinycbor/src/cbor.h %{DEST_INC_DIR}
 cp extlibs/cjson/cJSON.h %{DEST_INC_DIR}
 cp -rf %{ROOTDIR}/com.oic.ri.pc %{DEST_LIB_DIR}/pkgconfig/
@@ -87,4 +86,3 @@ cp -rf %{ROOTDIR}/com.oic.ri.pc %{DEST_LIB_DIR}/pkgconfig/
 %{_libdir}/lib*.a*
 %{_includedir}/OICHeaders/*
 %{_libdir}/pkgconfig/*.pc
-
index 2b17fdd..9a22c3c 100644 (file)
@@ -31,7 +31,6 @@
 #include "ocstackinternal.h"
 #include "ocresource.h"
 #include "logger.h"
-#include "rdpayload.h"
 
 #define TAG "OIC_RI_PAYLOAD"
 #define CSV_SEPARATOR ','
@@ -65,11 +64,6 @@ void OCPayloadDestroy(OCPayload* payload)
         case PAYLOAD_TYPE_SECURITY:
             OCSecurityPayloadDestroy((OCSecurityPayload*)payload);
             break;
-#if defined(RD_CLIENT) || defined(RD_SERVER)
-        case PAYLOAD_TYPE_RD:
-           OCRDPayloadDestroy((OCRDPayload*)payload);
-           break;
-#endif
         default:
             OIC_LOG_V(ERROR, TAG, "Unsupported payload type in destroy: %d", payload->type);
             OICFree(payload);
index cf5442f..ba948df 100644 (file)
 #include "ocresourcehandler.h"
 #include "cbor.h"
 
-#if defined(RD_CLIENT) || defined(RD_SERVER)
-#include "rdpayload.h"
-#endif
-
 #define TAG "OIC_RI_PAYLOADCONVERT"
 
 // Arbitrarily chosen size that seems to contain the majority of packages
@@ -162,10 +158,6 @@ static int64_t OCConvertPayloadHelper(OCPayload* payload, uint8_t* outPayload, s
             return OCConvertPresencePayload((OCPresencePayload*)payload, outPayload, size);
         case PAYLOAD_TYPE_SECURITY:
             return OCConvertSecurityPayload((OCSecurityPayload*)payload, outPayload, size);
-#if defined(RD_CLIENT) || defined(RD_SERVER)
-        case PAYLOAD_TYPE_RD:
-            return OCRDPayloadToCbor((OCRDPayload*)payload, outPayload, size);
-#endif
         default:
             OIC_LOG_V(INFO,TAG, "ConvertPayload default %d", payload->type);
             return CborErrorUnknownType;
index e27f7ba..6f8170e 100644 (file)
@@ -26,6 +26,7 @@
 // Refer http://pubs.opengroup.org/onlinepubs/009695399/
 // Required for strok_r
 #define _POSIX_C_SOURCE 200112L
+
 #include <string.h>
 #include <stdlib.h>
 #include "oic_string.h"
 #include "payload_logging.h"
 #include "platform_features.h"
 
-#if defined(RD_CLIENT) || defined(RD_SERVER)
-#include "rdpayload.h"
-#endif
-
 #define TAG "OIC_RI_PAYLOADPARSE"
 
 static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *arrayVal);
@@ -89,11 +86,6 @@ OCStackResult OCParsePayload(OCPayload **outPayload, OCPayloadType payloadType,
         case PAYLOAD_TYPE_SECURITY:
             result = OCParseSecurityPayload(outPayload, payload, payloadSize);
             break;
-#if defined(RD_CLIENT) || defined(RD_SERVER)
-        case PAYLOAD_TYPE_RD:
-            result = OCRDCborToPayload(&rootValue, outPayload);
-            break;
-#endif
         default:
             OIC_LOG_V(ERROR, TAG, "ParsePayload Type default: %d", payloadType);
             result = OC_STACK_INVALID_PARAM;
index e2f572e..2f1a964 100755 (executable)
 #include "routingmanager.h"
 #endif
 
+#ifdef RD_SERVER
+#include "rd_database.h"
+#endif
+
 /// Module Name
 #define TAG "OIC_RI_RESOURCE"
 
@@ -75,8 +79,7 @@ static OCDeviceInfo savedDeviceInfo = {0};
  */
 static OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
                                                   OCDiscoveryPayload* payload,
-                                                  OCDevAddr *endpoint,
-                                                  bool rdResponse);
+                                                  OCDevAddr *endpoint);
 
 //-----------------------------------------------------------------------------
 // Default resource entity handler function
@@ -323,7 +326,7 @@ OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
 }
 
 OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
-                        OCDiscoveryPayload *payload, OCDevAddr *devAddr, bool rdResponse)
+                        OCDiscoveryPayload *payload, OCDevAddr *devAddr)
 {
     if (!resourcePtr || !payload)
     {
@@ -338,11 +341,6 @@ OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
        }
     }
 
-    if (rdResponse)
-    {
-        securePort = devAddr->port;
-    }
-
 #ifdef TCP_ADAPTER
     uint16_t tcpPort = 0;
     if (GetTCPPortInfo(devAddr, &tcpPort) != OC_STACK_OK)
@@ -664,14 +662,7 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
             if (payload)
             {
                 OCDiscoveryPayload *discPayload = (OCDiscoveryPayload *)payload;
-                discPayload->sid = (char *)OICCalloc(1, UUID_STRING_SIZE);
-                VERIFY_NON_NULL(discPayload->sid, ERROR, OC_STACK_NO_MEMORY);
-
-                const char* uid = OCGetServerInstanceIDString();
-                if (uid)
-                {
-                    memcpy(discPayload->sid, uid, UUID_STRING_SIZE);
-                }
+                bool foundResourceAtRD = false;
 
                 if (!resourceTypeQuery && interfaceQuery && (0 == strcmp(interfaceQuery, OC_RSRVD_INTERFACE_LL)))
                 {
@@ -685,17 +676,20 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
 
                     for (; resource && discoveryResult == OC_STACK_OK; resource = resource->next)
                     {
-                        bool result = false;
-
-                        if (resource->resourceProperties & prop)
+                        foundResourceAtRD = false;
+#ifdef RD_SERVER
+                        if (strcmp(resource->uri, OC_RSRVD_RD_URI) == 0)
                         {
-                            result = true;
+                            if (OC_STACK_OK == OCRDDatabaseCheckResources(interfaceQuery, resourceTypeQuery, discPayload))
+                            {
+                                foundResourceAtRD = true;
+                                discoveryResult = OC_STACK_OK;
+                            }
                         }
-
-                        if (result)
+#endif
+                        if (!foundResourceAtRD && (resource->resourceProperties & prop))
                         {
-                            discoveryResult = BuildVirtualResourceResponse(resource,
-                            discPayload, &request->devAddr, false);
+                            discoveryResult = BuildVirtualResourceResponse(resource, discPayload, &request->devAddr);
                         }
                     }
                 }
@@ -718,13 +712,21 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
                         OCResourcePayloadAddStringLL(&discPayload->iface, OC_RSRVD_INTERFACE_DEFAULT);
                         VERIFY_NON_NULL(discPayload->iface, ERROR, OC_STACK_NO_MEMORY);
                     }
-                    bool foundResourceAtRD = false;
                     for (;resource && discoveryResult == OC_STACK_OK; resource = resource->next)
                     {
+#ifdef RD_SERVER
+                        if (strcmp(resource->uri, OC_RSRVD_RD_URI) == 0)
+                        {
+                            if (OC_STACK_OK == OCRDDatabaseCheckResources(interfaceQuery, resourceTypeQuery, discPayload))
+                            {
+                                foundResourceAtRD = true;
+                                discoveryResult = OC_STACK_OK;
+                            }
+                        }
+#endif
                         if (!foundResourceAtRD && includeThisResourceInResponse(resource, interfaceQuery, resourceTypeQuery))
                         {
-                            discoveryResult = BuildVirtualResourceResponse(resource,
-                                discPayload, &request->devAddr, false);
+                            discoveryResult = BuildVirtualResourceResponse(resource, discPayload, &request->devAddr);
                         }
                     }
                     // Set discoveryResult appropriately if no 'valid' resources are available
@@ -733,11 +735,23 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
                         discoveryResult = OC_STACK_NO_RESOURCE;
                     }
                 }
+                if (discoveryResult == OC_STACK_OK && foundResourceAtRD == false)
+                {
+                    discPayload->sid = (char *)OICCalloc(1, UUID_STRING_SIZE);
+                    VERIFY_NON_NULL(discPayload->sid, ERROR, OC_STACK_NO_MEMORY);
+
+                    const char* uid = OCGetServerInstanceIDString();
+                    if (uid)
+                    {
+                        memcpy(discPayload->sid, uid, UUID_STRING_SIZE);
+                    }
+                }
             }
             else
             {
                 discoveryResult = OC_STACK_NO_MEMORY;
             }
+
         }
         else
         {
@@ -946,11 +960,6 @@ HandleResourceWithEntityHandler (OCServerRequest *request,
 
     }
 
-    if (request && strcmp(request->resourceUrl, OC_RSRVD_RD_URI) == 0)
-    {
-        type = PAYLOAD_TYPE_RD;
-    }
-
     result = FormOCEntityHandlerRequest(&ehRequest,
                                         (OCRequestHandle)request,
                                         request->method,
index bad08d8..bab1f21 100644 (file)
@@ -1366,7 +1366,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
 #endif
                     else if (strcmp(cbNode->requestUri, OC_RSRVD_RD_URI) == 0)
                     {
-                        type = PAYLOAD_TYPE_RD;
+                        type = PAYLOAD_TYPE_REPRESENTATION ;
                     }
 #ifdef TCP_ADAPTER
                     else if (strcmp(cbNode->requestUri, KEEPALIVE_RESOURCE_URI) == 0)
@@ -1390,14 +1390,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
                 {
                     if (cbNode->requestUri)
                     {
-                        char targetUri[MAX_URI_LENGTH];
-                        snprintf(targetUri, MAX_URI_LENGTH, "%s?rt=%s", OC_RSRVD_RD_URI,
-                                OC_RSRVD_RESOURCE_TYPE_RDPUBLISH);
-                        if (strcmp(targetUri, cbNode->requestUri) == 0)
-                        {
-                            type = PAYLOAD_TYPE_RD;
-                        }
-                        else if (strcmp(OC_RSRVD_PLATFORM_URI, cbNode->requestUri) == 0)
+                        if (strcmp(OC_RSRVD_PLATFORM_URI, cbNode->requestUri) == 0)
                         {
                             type = PAYLOAD_TYPE_PLATFORM;
                         }
diff --git a/resource/csdk/stack/src/rdpayload.c b/resource/csdk/stack/src/rdpayload.c
deleted file mode 100644 (file)
index f265df2..0000000
+++ /dev/null
@@ -1,926 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#ifdef ARDUINO
-#define __STDC_LIMIT_MACROS
-#endif
-
-#include "rdpayload.h"
-
-#include "oic_malloc.h"
-#include "oic_string.h"
-#include "octypes.h"
-#include "ocstack.h"
-#include "ocpayload.h"
-#include "payload_logging.h"
-
-#define TAG "OIC_RI_RDPAYLOAD"
-
-#define CBOR_ROOT_ARRAY_LENGTH 1
-
-static int64_t OCTagsPayloadToCbor(OCTagsPayload *tags, CborEncoder *setMap);
-static int64_t OCLinksPayloadToCbor(OCLinksPayload *links, CborEncoder *setMap);
-static int64_t ConditionalAddTextStringToMap(CborEncoder* map, const char* key, const char *value);
-static int64_t ConditionalAddIntToMap(CborEncoder *map, const char *tags, const uint64_t *value);
-static int64_t AddStringLLToMap(CborEncoder *map, const char *tag, const OCStringLL *value);
-static CborError OCTagsCborToPayload(CborValue *tagsMap, OCTagsPayload **tagsPayload);
-static CborError OCLinksCborToPayload(CborValue *linksArray, OCLinksPayload **linksPayload);
-static CborError FindStringInMap(const CborValue *map, const char *tags, char **value);
-static CborError FindIntInMap(const CborValue *map, const char *tags, uint64_t *value);
-static CborError FindStringLLInMap(const CborValue *linksMap, const char *tag, OCStringLL **links);
-static OCStackResult CreateStringLL(uint8_t numElements, OCResourceHandle handle,
-                                    const char* (*getValue)(OCResourceHandle handle, uint8_t i),
-                                    OCStringLL **stringLL);
-
-int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, size_t *size)
-{
-    int64_t cborEncoderResult = CborNoError;
-    int flags = 0;
-    CborEncoder encoder;
-    VERIFY_PARAM_NON_NULL(TAG, rdPayload, "Invalid input parameter rdPayload");
-    VERIFY_PARAM_NON_NULL(TAG, outPayload, "Invalid input parameter outPayload");
-    VERIFY_PARAM_NON_NULL(TAG, size, "Invalid input parameter size");
-
-    cbor_encoder_init(&encoder, outPayload, *size, flags);
-
-    if (rdPayload->rdDiscovery)
-    {
-        CborEncoder map;
-        cborEncoderResult |= cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create discovery map");
-
-        cborEncoderResult |= ConditionalAddTextStringToMap(&map, OC_RSRVD_DEVICE_NAME,
-            rdPayload->rdDiscovery->n.deviceName);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_NAME in map");
-
-        cborEncoderResult |= ConditionalAddTextStringToMap(&map, OC_RSRVD_DEVICE_ID,
-            (char *)rdPayload->rdDiscovery->di.id);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_ID in map");
-
-        {
-            uint64_t value = rdPayload->rdDiscovery->sel;
-            cborEncoderResult |= ConditionalAddIntToMap(&map, OC_RSRVD_RD_DISCOVERY_SEL, &value);
-            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add RD_DISCOVERY_SEL in map");
-        }
-        cborEncoderResult |= cbor_encoder_close_container(&encoder, &map);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing discovery map");
-    }
-    else if (rdPayload->rdPublish)
-    {
-        CborEncoder collMap;
-        cborEncoderResult |= cbor_encoder_create_map(&encoder, &collMap, CborIndefiniteLength);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create collection map");
-
-        OCResourceCollectionPayload *rdPublish = rdPayload->rdPublish;
-        cborEncoderResult |= OCTagsPayloadToCbor(rdPublish->tags, &collMap);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding tags payload");
-        cborEncoderResult |= OCLinksPayloadToCbor(rdPublish->setLinks, &collMap);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding setLinks payload");
-
-        cborEncoderResult |= cbor_encoder_close_container(&encoder, &collMap);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing collection map");
-    }
-    else
-    {
-        CborEncoder map;
-        cborEncoderResult |= cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed entering discovery map");
-        cborEncoderResult |= cbor_encoder_close_container(&encoder, &map);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing discovery map");
-    }
-
-    if (cborEncoderResult == CborErrorOutOfMemory)
-    {
-        *size += encoder.ptr - encoder.end;
-    }
-    else
-    {
-        *size = encoder.ptr - outPayload;
-    }
-
-    return cborEncoderResult;
-
-exit:
-    OICFree(outPayload);
-    return cborEncoderResult;
-}
-
-static int64_t OCTagsPayloadToCbor(OCTagsPayload *tags, CborEncoder *setMap)
-{
-    int64_t cborEncoderResult = CborNoError;
-
-    cborEncoderResult |= ConditionalAddTextStringToMap(setMap, OC_RSRVD_DEVICE_NAME,
-        tags->n.deviceName);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_NAME in tags map");
-
-    cborEncoderResult |= ConditionalAddTextStringToMap(setMap, OC_RSRVD_DEVICE_ID,
-        (char *)tags->di.id);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DEVICE_ID in tags map");
-
-    cborEncoderResult |= ConditionalAddIntToMap(setMap, OC_RSRVD_DEVICE_TTL, &tags->ttl);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TTL in tags map");
-exit:
-    return cborEncoderResult;
-}
-
-static int64_t OCLinksPayloadToCbor(OCLinksPayload *links, CborEncoder *setMap)
-{
-    CborEncoder linksArray;
-    int64_t cborEncoderResult = CborNoError;
-
-    cborEncoderResult |= cbor_encode_text_string(setMap, OC_RSRVD_LINKS,
-        sizeof(OC_RSRVD_LINKS) - 1);
-
-    cborEncoderResult |= cbor_encoder_create_array(setMap, &linksArray, CborIndefiniteLength);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create Links array");
-
-    while (links)
-    {
-        CborEncoder linksMap;
-        cborEncoderResult |= cbor_encoder_create_map(&linksArray, &linksMap, CborIndefiniteLength);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create links map");
-
-        cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_HREF, links->href);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_HREF in links map");
-
-        cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_REL, links->rel);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_REL in links map");
-
-        cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_RESOURCE_TYPE, links->rt);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_RT in links map");
-
-        cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_INTERFACE, links->itf);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_ITF in links map");
-
-        // Policy
-        CborEncoder policyMap;
-        cborEncoderResult |= cbor_encode_text_string(&linksMap, OC_RSRVD_POLICY,
-            sizeof(OC_RSRVD_POLICY) - 1);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding policy tag to links map");
-        cborEncoderResult |= cbor_encoder_create_map(&linksMap, &policyMap, CborIndefiniteLength);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding policy map to links map");
-
-        // Bitmap
-        cborEncoderResult |= cbor_encode_text_string(&policyMap, OC_RSRVD_BITMAP,
-            sizeof(OC_RSRVD_BITMAP) - 1);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding bitmap tag to policy map");
-        cborEncoderResult |= cbor_encode_uint(&policyMap, links->p);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding bitmap value to policy map");
-
-        cborEncoderResult |= cbor_encoder_close_container(&linksMap, &policyMap);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing policy map");
-
-        cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_TITLE, links->title);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TITLE in links map");
-
-        cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_URI, links->anchor);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_URI in links map");
-
-        cborEncoderResult |= ConditionalAddIntToMap(&linksMap, OC_RSRVD_INS, (uint64_t *) &links->ins);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_INS in links map");
-
-        cborEncoderResult |= ConditionalAddIntToMap(&linksMap, OC_RSRVD_TTL, &links->ttl);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TTL in links map");
-
-        cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_MEDIA_TYPE, links->type);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_MT in links map");
-
-        // Finsihed encoding a resource, close the map.
-        cborEncoderResult |= cbor_encoder_close_container(&linksArray, &linksMap);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing links map");
-
-        links = links->next;
-    }
-    cborEncoderResult |= cbor_encoder_close_container(setMap, &linksArray);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing links array");
-
-exit:
-    return cborEncoderResult;
-}
-
-OCStackResult OCRDCborToPayload(const CborValue *cborPayload, OCPayload **outPayload)
-{
-    CborValue *rdCBORPayload = (CborValue *)cborPayload;
-    OCStackResult ret = OC_STACK_NO_MEMORY;
-    CborError cborFindResult;
-
-    OCRDPayload *rdPayload = OCRDPayloadCreate();
-    VERIFY_PARAM_NON_NULL(TAG, rdPayload, "Failed allocating rdPayload");
-
-    ret = OC_STACK_MALFORMED_RESPONSE;
-
-    if (cbor_value_is_map(rdCBORPayload))
-    {
-        // rdCBORPayload is already inside the main root map.
-        OCTagsPayload *tagsPayload = NULL;
-        OCLinksPayload *linksPayload = NULL;
-
-        cborFindResult = OCTagsCborToPayload(rdCBORPayload, &tagsPayload);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed parsing tags payload.");
-
-        cborFindResult = OCLinksCborToPayload(rdCBORPayload, &linksPayload);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed parsing links payload.");
-
-        // Move from tags payload to links array.
-        cborFindResult = cbor_value_advance(rdCBORPayload);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed advancing rdCborPayload.");
-
-        rdPayload->rdPublish = OCCopyCollectionResource(tagsPayload, linksPayload);
-        VERIFY_PARAM_NON_NULL(TAG, rdPayload->rdPublish, "Failed allocating rdPayload->rdPublish");
-    }
-    // TODO: This logic needs to be modified to check the payload type exactly..
-    else if (cbor_value_is_map(rdCBORPayload))
-    {
-        rdPayload->rdDiscovery = (OCRDDiscoveryPayload *)OICCalloc(1, sizeof(OCRDDiscoveryPayload));
-        VERIFY_PARAM_NON_NULL(TAG, rdPayload->rdDiscovery, "Failed allocating discoveryPayload");
-
-        cborFindResult = FindStringInMap(rdCBORPayload, OC_RSRVD_DEVICE_NAME,
-                                         &rdPayload->rdDiscovery->n.deviceName);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding OC_RSRVD_DEVICE_NAME.");
-        char *deviceId = NULL;
-        cborFindResult = FindStringInMap(rdCBORPayload, OC_RSRVD_DEVICE_ID, &deviceId);
-        if (deviceId)
-        {
-            memcpy(rdPayload->rdDiscovery->di.id, deviceId, strlen(deviceId));
-            OICFree(deviceId);
-        }
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding OC_RSRVD_DEVICE_ID.");
-
-        {
-            uint64_t value = 0;
-            cborFindResult = FindIntInMap(rdCBORPayload, OC_RSRVD_RD_DISCOVERY_SEL, &value);
-            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding OC_RSRVD_RD_DISCOVERY_SEL.");
-            rdPayload->rdDiscovery->sel = value;
-        }
-
-        cborFindResult =  cbor_value_advance(rdCBORPayload);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed advancing rdCBORPayload.");
-    }
-    OIC_LOG_PAYLOAD(DEBUG, (OCPayload *) rdPayload);
-    *outPayload = (OCPayload *)rdPayload;
-    return OC_STACK_OK;
-
-exit:
-    OCRDPayloadDestroy(rdPayload);
-    return ret;
-}
-
-static CborError FindStringInMap(const CborValue *map, const char *tags, char **value)
-{
-    CborValue curVal;
-    CborError cborFindResult = cbor_value_map_find_value(map, tags, &curVal);
-    if (CborNoError == cborFindResult && cbor_value_is_text_string(&curVal))
-    {
-        size_t len = 0;
-        cborFindResult = cbor_value_dup_text_string(&curVal, value, &len, NULL);
-    }
-    return cborFindResult;
-}
-
-static CborError FindIntInMap(const CborValue *map, const char *tags, uint64_t *value)
-{
-    CborValue curVal;
-    CborError cborFindResult = cbor_value_map_find_value(map, tags, &curVal);
-    if (CborNoError == cborFindResult && cbor_value_is_unsigned_integer(&curVal))
-    {
-        cborFindResult = cbor_value_get_uint64(&curVal, value);
-    }
-    return cborFindResult;
-}
-
-static CborError FindStringLLInMap(const CborValue *linksMap, const char *tag, OCStringLL **links)
-{
-    size_t len;
-    CborValue rtArray;
-    OCStringLL* llPtr = *links;
-    CborError cborFindResult = cbor_value_map_find_value(linksMap, tag, &rtArray);
-    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding tag");
-
-    CborValue rtVal;
-    cborFindResult = cbor_value_enter_container(&rtArray, &rtVal);
-    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed entering container");
-
-    while (cbor_value_is_text_string(&rtVal))
-    {
-        if (llPtr == NULL)
-        {
-            llPtr = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            VERIFY_PARAM_NON_NULL(TAG, llPtr, "Failed allocating OCStringLL");
-            *links = llPtr;
-        }
-        else if (llPtr)
-        {
-            while (llPtr->next)
-            {
-                llPtr = llPtr->next;
-            }
-            llPtr->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            llPtr = llPtr->next;
-            VERIFY_PARAM_NON_NULL(TAG, llPtr, "Failed allocating OCStringLL->next");
-        }
-        cborFindResult = cbor_value_dup_text_string(&rtVal, &(llPtr->value), &len, NULL);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed duplicating value");
-        cborFindResult = cbor_value_advance(&rtVal);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed advancing OCStringLL");
-    }
-
-    cborFindResult = cbor_value_leave_container(&rtArray, &rtVal);
-    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed leaving container");
-
-exit:
-    return cborFindResult;
-}
-
-static CborError OCTagsCborToPayload(CborValue *tagsMap, OCTagsPayload **tagsPayload)
-{
-    CborError cborFindResult = CborErrorOutOfMemory;
-    OCTagsPayload *tags = (OCTagsPayload *)OICCalloc(1, sizeof(OCTagsPayload));
-    VERIFY_PARAM_NON_NULL(TAG, tags, "Failed allocating tags");
-
-    cborFindResult = FindStringInMap(tagsMap, OC_RSRVD_DEVICE_NAME, &tags->n.deviceName);
-    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding deviceName");
-
-    {
-        char *deviceId = NULL;
-        cborFindResult = FindStringInMap(tagsMap, OC_RSRVD_DEVICE_ID, &deviceId);
-        if (deviceId)
-        {
-            memcpy(tags->di.id, deviceId, strlen(deviceId));
-            OICFree(deviceId);
-        }
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding deviceId");
-    }
-
-    cborFindResult = FindIntInMap(tagsMap, OC_RSRVD_DEVICE_TTL, &tags->ttl);
-    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding ttl");
-
-    *tagsPayload = tags;
-    return cborFindResult;
-
-exit:
-    OCFreeTagsResource(tags);
-    return cborFindResult;
-}
-
-static CborError OCLinksCborToPayload(CborValue *links, OCLinksPayload **linksPayload)
-{
-    OCLinksPayload *setLinks = NULL;
-    CborValue linksMap;
-    CborValue linksArray;
-    CborError cborFindResult = CborErrorOutOfMemory;
-
-    cborFindResult = cbor_value_map_find_value(links, OC_RSRVD_LINKS, &linksArray);
-    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding links array");
-
-    cborFindResult = cbor_value_enter_container(&linksArray, &linksMap);
-    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed entering links map container");
-
-    while (cbor_value_is_map(&linksMap))
-    {
-        setLinks = (OCLinksPayload *)OICCalloc(1, sizeof(OCLinksPayload));
-        VERIFY_PARAM_NON_NULL(TAG, setLinks, "Failed allocating setLinks");
-
-        cborFindResult = FindStringInMap(&linksMap, OC_RSRVD_HREF, &setLinks->href);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding href value");
-
-        cborFindResult = FindStringInMap(&linksMap, OC_RSRVD_REL, &setLinks->rel);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding rel value");
-
-        cborFindResult = FindStringLLInMap(&linksMap, OC_RSRVD_RESOURCE_TYPE, &setLinks->rt);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding rt value");
-
-        cborFindResult = FindStringLLInMap(&linksMap, OC_RSRVD_INTERFACE, &setLinks->itf);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding itf value");
-
-        // Policy
-        CborValue policyMap;
-        cborFindResult = cbor_value_map_find_value(&linksMap, OC_RSRVD_POLICY, &policyMap);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "to find policy tag");
-
-        // Bitmap
-        cborFindResult = FindIntInMap(&policyMap, OC_RSRVD_BITMAP, (uint64_t *) &setLinks->p);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding bitmap value");
-
-        cborFindResult = FindStringInMap(&linksMap, OC_RSRVD_TITLE, &setLinks->title);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding title value");
-
-        cborFindResult = FindStringInMap(&linksMap, OC_RSRVD_URI, &setLinks->anchor);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding uri value");
-
-        cborFindResult = FindIntInMap(&linksMap, OC_RSRVD_INS, (uint64_t *) &setLinks->ins);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding ins value");
-
-        cborFindResult = FindIntInMap(&linksMap, OC_RSRVD_TTL, &setLinks->ttl);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding ttl");
-
-        cborFindResult = FindStringLLInMap(&linksMap, OC_RSRVD_MEDIA_TYPE, &setLinks->type);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding mt value");
-
-        if (!*linksPayload)
-        {
-            *linksPayload = setLinks;
-        }
-        else
-        {
-            OCLinksPayload *temp = *linksPayload;
-            while (temp->next)
-            {
-                temp = temp->next;
-            }
-            temp->next = setLinks;
-        }
-        cborFindResult = cbor_value_advance(&linksMap);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed advancing links map");
-    }
-
-    return cborFindResult;
-
-exit:
-    OCFreeLinksResource(*linksPayload);
-    OCFreeLinksResource(setLinks);
-    return cborFindResult;
-}
-
-static int64_t AddTextStringToMap(CborEncoder* map, const char* key, const char* value)
-{
-    int64_t err = cbor_encode_text_string(map, key, strlen(key));
-    VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting key value");
-    err |= cbor_encode_text_string(map, value, strlen(value));
-exit:
-    return err;
-}
-
-static int64_t ConditionalAddTextStringToMap(CborEncoder* map, const char* key, const char* value)
-{
-    return value ? AddTextStringToMap(map, key, value) : CborNoError;
-}
-
-static int64_t ConditionalAddIntToMap(CborEncoder *map, const char *tags, const uint64_t *value)
-{
-    int64_t err = CborNoError;
-    if (value)
-    {
-        err |= cbor_encode_text_string(map, tags, strlen(tags));
-        VERIFY_CBOR_SUCCESS(TAG, err, "failed setting value");
-        err |= cbor_encode_uint(map, *value);
-    }
-exit:
-    return err;
-}
-
-static int64_t AddStringLLToMap(CborEncoder *map, const char *tag, const OCStringLL *strType)
-{
-    CborEncoder array;
-    int64_t cborEncoderResult = CborNoError;
-
-    cborEncoderResult |= cbor_encode_text_string(map, tag, strlen(tag));
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed encoding string tag name");
-    cborEncoderResult |= cbor_encoder_create_array(map, &array, CborIndefiniteLength);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed creating stringLL array");
-    while (strType)
-    {
-        cborEncoderResult |= cbor_encode_text_string(&array, strType->value, strlen(strType->value));
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed encoding string value");
-        strType = strType->next;
-    }
-    cborEncoderResult |= cbor_encoder_close_container(map, &array);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing string array");
-exit:
-    return cborEncoderResult;
-}
-
-OCRDPayload *OCRDPayloadCreate()
-{
-    OCRDPayload *rdPayload = (OCRDPayload *)OICCalloc(1, sizeof(OCRDPayload));
-    VERIFY_PARAM_NON_NULL(TAG, rdPayload, "Failed allocating rdPayload");
-    rdPayload->base.type = PAYLOAD_TYPE_RD;
-
-exit:
-    return rdPayload;
-}
-
-#ifdef RD_CLIENT
-OCRDPayload *OCRDPublishPayloadCreate(const unsigned char *id,
-                                      OCResourceHandle *resourceHandles, uint8_t nHandles,
-                                      uint64_t ttl)
-{
-    OCTagsPayload *tagsPayload = NULL;
-    OCLinksPayload *linksPayload = NULL;
-    OCStringLL *rt = NULL;
-    OCStringLL *itf = NULL;
-    OCStringLL *mt = NULL;
-    OCResourceProperty p = OC_RES_PROP_NONE;
-    uint8_t ins = 0;
-
-    OCRDPayload *rdPayload = OCRDPayloadCreate();
-    if (!rdPayload)
-    {
-        return NULL;
-    }
-
-    tagsPayload = OCCopyTagsResources(NULL, id, ttl);
-    if (!tagsPayload)
-    {
-        goto exit;
-    }
-
-    for (uint8_t j = 0; j < nHandles; j++)
-    {
-        OCResourceHandle handle = resourceHandles[j];
-        if (handle)
-        {
-            rt = NULL;
-            itf = NULL;
-            mt = NULL;
-            ins = 0;
-            const char *uri = OCGetResourceUri(handle);
-            uint8_t numElement = 0;
-            if (OC_STACK_OK == OCGetNumberOfResourceTypes(handle, &numElement))
-            {
-                OCStackResult res = CreateStringLL(numElement, handle, OCGetResourceTypeName, &rt);
-                if (OC_STACK_OK != res || !rt)
-                {
-                    goto exit;
-                }
-            }
-
-            if (OC_STACK_OK == OCGetNumberOfResourceInterfaces(handle, &numElement))
-            {
-                OCStackResult res = CreateStringLL(numElement, handle, OCGetResourceInterfaceName,
-                                                   &itf);
-                if (OC_STACK_OK != res || !itf)
-                {
-                    goto exit;
-                }
-            }
-
-            p = OCGetResourceProperties(handle);
-            p = (OCResourceProperty) ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE));
-
-            OCStackResult res = OCGetResourceIns(handle, &ins);
-            if (OC_STACK_OK != res)
-            {
-                goto exit;
-            }
-
-            mt = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!mt)
-            {
-                goto exit;
-            }
-            mt->value = OICStrdup(DEFAULT_MESSAGE_TYPE);
-            if (!mt->value)
-            {
-                goto exit;
-            }
-
-            if (!linksPayload)
-            {
-                linksPayload = OCCopyLinksResources(uri, NULL, rt, itf, p, NULL,
-                                                    NULL, ins, ttl, mt);;
-                if (!linksPayload)
-                {
-                    goto exit;
-                }
-            }
-            else
-            {
-                OCLinksPayload *temp = linksPayload;
-                while (temp->next)
-                {
-                    temp = temp->next;
-                }
-                temp->next = OCCopyLinksResources(uri, NULL, rt, itf, p, NULL,
-                                                  NULL, ins, ttl, mt);
-                if (!temp->next)
-                {
-                    goto exit;
-                }
-            }
-            OCFreeOCStringLL(rt);
-            OCFreeOCStringLL(itf);
-            OCFreeOCStringLL(mt);
-        }
-    }
-
-    rdPayload->rdPublish = OCCopyCollectionResource(tagsPayload, linksPayload);
-    if (!rdPayload->rdPublish)
-    {
-        goto exit;
-    }
-
-    return rdPayload;
-
-exit:
-    if (rt)
-    {
-        OCFreeOCStringLL(rt);
-    }
-    if (itf)
-    {
-        OCFreeOCStringLL(itf);
-    }
-    if (mt)
-    {
-        OCFreeOCStringLL(mt);
-    }
-    if (tagsPayload)
-    {
-        OCFreeTagsResource(tagsPayload);
-    }
-    if (linksPayload)
-    {
-        OCFreeLinksResource(linksPayload);
-    }
-    OCRDPayloadDestroy(rdPayload);
-    return NULL;
-}
-#endif
-OCRDDiscoveryPayload *OCRDDiscoveryPayloadCreate(const char *deviceName, const char *id, int biasFactor)
-{
-    OCRDDiscoveryPayload *discoveryPayload = (OCRDDiscoveryPayload *)OICCalloc(1, sizeof(OCRDDiscoveryPayload));
-    VERIFY_PARAM_NON_NULL(TAG, discoveryPayload, "Failed allocating memory for discovery payload");
-
-    if (deviceName)
-    {
-        discoveryPayload->n.deviceName = OICStrdup(deviceName);
-        VERIFY_PARAM_NON_NULL(TAG, discoveryPayload->n.deviceName,
-                "Failed allocating memory for discovery device name");
-    }
-    if (id)
-    {
-        OICStrcpy((char*)discoveryPayload->di.id, MAX_IDENTITY_SIZE, id);
-    }
-
-    discoveryPayload->sel = biasFactor;
-    return discoveryPayload;
-exit:
-    OICFree(discoveryPayload);
-    discoveryPayload = NULL;
-    return discoveryPayload;
-}
-
-void OCRDPayloadDestroy(OCRDPayload *payload)
-{
-    if (!payload)
-    {
-        return;
-    }
-
-    if (payload->rdDiscovery)
-    {
-        if (payload->rdDiscovery->n.deviceName)
-        {
-            OICFree(payload->rdDiscovery->n.deviceName);
-        }
-        OICFree(payload->rdDiscovery);
-    }
-
-    if (payload->rdPublish)
-    {
-        OCResourceCollectionPayload *col = payload->rdPublish;
-
-        if (col->setLinks)
-        {
-            OCFreeLinksResource(col->setLinks);
-        }
-
-        if (col->tags)
-        {
-            OCFreeTagsResource(col->tags);
-        }
-        OICFree(col);
-    }
-
-    OICFree(payload);
-}
-
-OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *id, uint64_t ttl)
-{
-    OCTagsPayload *tags = (OCTagsPayload *)OICCalloc(1, sizeof(OCTagsPayload));
-    if (!tags)
-    {
-        return NULL;
-    }
-    if (deviceName)
-    {
-        tags->n.deviceName = OICStrdup(deviceName);
-        if (!tags->n.deviceName)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    if (id)
-    {
-        OICStrcpy((char*)tags->di.id, MAX_IDENTITY_SIZE, (char *)id);
-    }
-    tags->ttl = ttl;
-    return tags;
-
-memory_allocation_failed:
-    OIC_LOG(ERROR, TAG, "Memory allocation failed.");
-    OCFreeTagsResource(tags);
-    return NULL;
-}
-
-OCLinksPayload* OCCopyLinksResources(const char *href, const char *rel, OCStringLL *rt,
-                                     OCStringLL *itf, uint8_t p, const char *title,
-                                     const char *anchor, uint8_t ins, uint64_t ttl,
-                                     OCStringLL *mt)
-{
-    OCLinksPayload *links = (OCLinksPayload *)OICCalloc(1, sizeof(OCLinksPayload));
-    if (!links)
-    {
-        OIC_LOG(ERROR, TAG, "Failed allocating memory.");
-        return NULL;
-    }
-    if (href)
-    {
-        links->href = OICStrdup(href);
-        if (!links->href)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    if (rel)
-    {
-        links->rel = OICStrdup(rel);
-        if (!links->rel)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    if (rt)
-    {
-        links->rt = CloneOCStringLL(rt);
-        if (!links->rt)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    if (itf)
-    {
-        links->itf = CloneOCStringLL(itf);
-        if (!links->itf)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    links->p = p;
-    if (title)
-    {
-        links->title = OICStrdup(title);
-        if (!links->title)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    if (anchor)
-    {
-        links->anchor = OICStrdup(anchor);
-        if (!links->anchor)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    links->ins = ins;
-    links->ttl = ttl;
-    if (mt)
-    {
-        links->type = CloneOCStringLL(mt);
-        if (!links->type)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    links->next = NULL;
-    return links;
-
-memory_allocation_failed:
-    OIC_LOG(ERROR, TAG, "Memory allocation failed.");
-    OCFreeLinksResource(links);
-    return NULL;
-}
-
-OCResourceCollectionPayload* OCCopyCollectionResource(OCTagsPayload *tags, OCLinksPayload *links)
-{
-    OCResourceCollectionPayload *pl =  NULL;
-    VERIFY_PARAM_NON_NULL(TAG, tags, "Invalid param tags");
-    VERIFY_PARAM_NON_NULL(TAG, links, "Invalid param links");
-
-    pl = (OCResourceCollectionPayload *)OICCalloc(1, sizeof(OCResourceCollectionPayload));
-    VERIFY_PARAM_NON_NULL(TAG, pl, "Failed allocating memory for the OCResourceCollectionPayload");
-
-    pl->tags = tags;
-    pl->setLinks = links;
-
-exit:
-    return pl;
-}
-
-void OCFreeLinksResource(OCLinksPayload *links)
-{
-    if (!links)
-    {
-        return;
-    }
-    OICFree(links->href);
-    OICFree(links->rel);
-    OCFreeOCStringLL(links->rt);
-    OCFreeOCStringLL(links->itf);
-    OICFree(links->title);
-    OICFree(links->anchor);
-    OCFreeOCStringLL(links->type);
-    OCFreeLinksResource(links->next);
-    OICFree(links);
-}
-
-void OCFreeTagsResource(OCTagsPayload *payload)
-{
-    if (!payload)
-    {
-        return;
-    }
-    OICFree(payload->n.deviceName);;
-    OICFree(payload);
-}
-
-void OCFreeCollectionResource(OCResourceCollectionPayload *payload)
-{
-    if (!payload)
-    {
-        return;
-    }
-    if (payload->tags)
-    {
-        OCFreeTagsResource(payload->tags);
-    }
-    if (payload->setLinks)
-    {
-        OCFreeLinksResource(payload->setLinks);
-    }
-    OICFree(payload);
-}
-
-static OCStackResult CreateStringLL(uint8_t numElements, OCResourceHandle handle,
-                                    const char* (*getValue)(OCResourceHandle handle, uint8_t i),
-                                    OCStringLL **stringLL)
-{
-    for (uint8_t i = 0; i < numElements; ++i)
-    {
-        const char *value = getValue(handle, i);
-        OIC_LOG_V(ERROR, TAG, "value: %s", value);
-        if (!*stringLL)
-        {
-            *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!*stringLL)
-            {
-                OIC_LOG(ERROR, TAG, "Failed allocating memory.");
-                return OC_STACK_NO_MEMORY;
-            }
-            (*stringLL)->value = OICStrdup(value);
-            if (!(*stringLL)->value)
-            {
-                OIC_LOG(ERROR, TAG, "Failed copying to OCStringLL.");
-                return OC_STACK_NO_MEMORY;
-            }
-        }
-        else
-        {
-            OCStringLL *cur = *stringLL;
-            while (cur->next)
-            {
-                cur = cur->next;
-            }
-            cur->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!cur->next)
-            {
-                OIC_LOG(ERROR, TAG, "Failed allocating memory.");
-                return OC_STACK_NO_MEMORY;
-            }
-            cur->next->value = OICStrdup(value);
-            if (!cur->next->value)
-            {
-                OIC_LOG(ERROR, TAG, "Failed copying to OCStringLL.");
-                return OC_STACK_NO_MEMORY;
-            }
-        }
-    }
-    return OC_STACK_OK;
-}
index c8cc507..cf80e57 100644 (file)
@@ -660,38 +660,37 @@ WARN_LOGFILE           = ./doxygen.log
 # with spaces.
 
 INPUT                  = . \
-                        ../../csdk/security/provisioning/include/ocprovisioningmanager.h \
-                        ../../csdk/security/provisioning/include/pmtypes.h \
-                        ../../csdk/security/provisioning/include/pmutility.h \
-                        ../../csdk/stack/include/ocstack.h \
-                        ../../csdk/stack/include/octypes.h \
-                        ../../csdk/stack/include/ocpayload.h \
-                        ../../csdk/stack/include/ocpresence.h \
-                        ../../csdk/stack/include/rdpayload.h \
-                        ../../csdk/stack/include/payload_logging.h \
-                         ../../csdk/stack/include/ocstackconfig.h \
-                         ../../csdk/stack/include/internal/occlientcb.h \
-                         ../../csdk/stack/include/internal/occollection.h \
-                         ../../csdk/stack/include/internal/ocobserve.h \
-                         ../../csdk/stack/include/internal/ocpayloadcbor.h \
-                         ../../csdk/stack/include/internal/ocresource.h \
-                         ../../csdk/stack/include/internal/ocresourcehandler.h \
-                         ../../csdk/stack/include/internal/ocserverrequest.h \
-                         ../../csdk/stack/include/internal/ocstackinternal.h \
-                         ../../csdk/stack/include/internal/oicgroup.h \
-                         ../../csdk/stack/include/internal/oickeepalive.h \
-                         guides \
-                         ../../csdk/security/include \
-                         ../../csdk/security/include\internal \
-                         ../../csdk/security/provisioning/include \
-                         ../../csdk/security/provisioning/include/internal \
-                         ../../csdk/security/provisioning/include/oxm \
-                         ../../csdk/security/provisioning/include/cloud \
-                         ../../csdk/security/provisioning/sample/cloudAuth.h \
-                         ../../csdk/security/provisioning/sample/cloudWrapper.h \
-                         ../../../service/easy-setup/inc \
-                         ../../../service/easy-setup/enrollee/inc \
-                         ../../../service/resource-directory/include \
+             ../../csdk/security/provisioning/include/ocprovisioningmanager.h
+             ../../csdk/security/provisioning/include/pmtypes.h
+             ../../csdk/security/provisioning/include/pmutility.h
+             ../../csdk/stack/include/ocstack.h
+             ../../csdk/stack/include/octypes.h
+             ../../csdk/stack/include/ocpayload.h
+             ../../csdk/stack/include/ocpresence.h \
+             ../../csdk/stack/include/payload_logging.h \
+             ../../csdk/stack/include/ocstackconfig.h \
+             ../../csdk/stack/include/internal/occlientcb.h \
+             ../../csdk/stack/include/internal/occollection.h \
+             ../../csdk/stack/include/internal/ocobserve.h \
+             ../../csdk/stack/include/internal/ocpayloadcbor.h \
+             ../../csdk/stack/include/internal/ocresource.h \
+             ../../csdk/stack/include/internal/ocresourcehandler.h \
+             ../../csdk/stack/include/internal/ocserverrequest.h \
+             ../../csdk/stack/include/internal/ocstackinternal.h \
+             ../../csdk/stack/include/internal/oicgroup.h \
+             ../../csdk/stack/include/internal/oickeepalive.h \
+             guides \
+             ../../csdk/security/include \
+             ../../csdk/security/include\internal \
+             ../../csdk/security/provisioning/include \
+             ../../csdk/security/provisioning/include/internal \
+             ../../csdk/security/provisioning/include/oxm \
+             ../../csdk/security/provisioning/include/cloud \
+             ../../csdk/security/provisioning/sample/cloudAuth.h \
+             ../../csdk/security/provisioning/sample/cloudWrapper.h \
+             ../../../service/easy-setup/inc \
+             ../../../service/easy-setup/enrollee/inc \
+             ../../../service/resource-directory/include \
 
 
 # This tag can be used to specify the character encoding of the source files
index 5dc7ff5..8c23c83 100644 (file)
@@ -70,9 +70,6 @@ if target_os == 'android':
 if target_os in ['darwin', 'ios']:
        examples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
 
-if examples_env.get('LOGGING'):
-       examples_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-
 if examples_env.get('WITH_CLOUD'):
        examples_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
 
@@ -82,9 +79,6 @@ if target_os in ['msys_nt', 'windows']:
 if examples_env.get('LOGGING'):
        examples_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
-if 'CLIENT' in examples_env.get('RD_MODE'):
-       examples_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
-
 def make_single_file_cpp_program(program_name):
        return examples_env.Program(program_name, program_name + ".cpp")
 
@@ -112,11 +106,6 @@ if target_os not in ['windows', 'msys_nt']:
                'threadingsample'
                ]
 
-if 'CLIENT' in examples_env.get('RD_MODE'):
-       example_names += [
-               'rdclient'
-               ]
-
 examples = map(make_single_file_cpp_program, example_names)
 
 ######################################################################
index 1e025eb..6e89258 100644 (file)
@@ -66,9 +66,7 @@ namespace OC
             void setPayload(const OCPlatformPayload* rep);
 
             void setPayload(const OCRepPayload* rep);
-#ifdef RD_CLIENT
-            void setPayload(const OCRDPayload* rep);
-#endif
+
             OCRepPayload* getPayload() const;
 
             const std::vector<OCRepresentation>& representations() const;
@@ -470,9 +468,6 @@ namespace OC
             template<typename T>
             T payload_array_helper_copy(size_t index, const OCRepPayloadValue* pl);
             void setPayload(const OCRepPayload* payload);
-#ifdef RD_CLIENT
-            void setPayload(const OCLinksPayload* payload);
-#endif
             void setPayloadArray(const OCRepPayloadValue* pl);
             void getPayloadArray(OCRepPayload* payload,
                     const OCRepresentation::AttributeItem& item) const;
@@ -519,4 +514,3 @@ namespace OC
 
 
 #endif // OC_REPRESENTATION_H_
-
index 693f546..b7ba781 100644 (file)
@@ -63,8 +63,14 @@ namespace OC
                         if (payload->baseURI)
                         {
                             OCDevAddr rdPubAddr = m_devAddr;
-                            OICStrcpy(rdPubAddr.addr, sizeof(rdPubAddr.addr), payload->baseURI);
-                            rdPubAddr.port = res->port;
+
+                            std::string baseURI = std::string(payload->baseURI);
+                            size_t len = baseURI.length();
+                            int addressLen = baseURI.find_first_of(":");
+                            std::string ipaddress = baseURI.substr(0, addressLen);
+                            int port = atoi(baseURI.substr(addressLen + 1, len).c_str());
+                            OICStrcpy(rdPubAddr.addr, addressLen + 1, ipaddress.c_str());
+                            rdPubAddr.port = port;
                             m_resources.push_back(std::shared_ptr<OC::OCResource>(
                                         new OC::OCResource(m_clientWrapper, rdPubAddr,
                                             std::string(res->uri),
index af1e51d..88ea41f 100644 (file)
 #include <OCResourceRequest.h>
 #include <OCResourceResponse.h>
 #include <ocstack.h>
+#include <ocpayload.h>
+
 #include <OCApi.h>
 #include <oic_malloc.h>
 #include <OCPlatform.h>
 #include <OCUtilities.h>
 
 #ifdef RD_CLIENT
-#include <oicresourcedirectory.h>
+#include <rd_client.h>
 #endif
 
 using namespace std;
@@ -327,7 +329,7 @@ namespace OC
         return result;
     }
 
-     OCStackResult InProcServerWrapper::registerPlatformInfo(const OCPlatformInfo platformInfo)
+    OCStackResult InProcServerWrapper::registerPlatformInfo(const OCPlatformInfo platformInfo)
     {
         auto cLock = m_csdkLock.lock();
         OCStackResult result = OC_STACK_ERROR;
@@ -599,11 +601,12 @@ namespace OC
             return result;
         }
     }
+
 #ifdef RD_CLIENT
     OCRepresentation parseRDResponseCallback(OCClientResponse* clientResponse)
     {
         if (nullptr == clientResponse || nullptr == clientResponse->payload ||
-                    PAYLOAD_TYPE_RD != clientResponse->payload->type)
+            PAYLOAD_TYPE_REPRESENTATION != clientResponse->payload->type)
         {
             return OCRepresentation();
         }
@@ -643,16 +646,20 @@ namespace OC
             {
                 if (clientResponse->payload)
                 {
-                    OCRDPayload *rdPayload = (OCRDPayload *) clientResponse->payload;
-                    OCLinksPayload *links = rdPayload->rdPublish->setLinks;
+                    OCRepPayload *rdPayload = (OCRepPayload *) clientResponse->payload;
+                    OCRepPayload **links = NULL;
 
-                    while (links)
+                    size_t dimensions[MAX_REP_ARRAY_DEPTH];
+                    OCRepPayloadGetPropObjectArray(rdPayload, OC_RSRVD_LINKS, &links, dimensions);
+                    for(size_t i = 0; i < dimensions[0]; i++)
                     {
-                        OCResourceHandle handle = OCGetResourceHandleAtUri(links->href);
-                        OCBindResourceInsToResource(handle, links->ins);
-                        links = links->next;
+                        char *uri = NULL;
+                        OCRepPayloadGetPropString(links[i], OC_RSRVD_HREF, &uri);
+                        OCResourceHandle handle = OCGetResourceHandleAtUri(uri);
+                        int64_t ins = 0;
+                        OCRepPayloadGetPropInt(links[i], OC_RSRVD_INS, &ins);
+                        OCBindResourceInsToResource(handle, ins);
                     }
-
                 }
                 OCRepresentation rep = parseRDResponseCallback(clientResponse);
                 std::thread exec(context->callback, rep, clientResponse->result);
@@ -741,6 +748,7 @@ namespace OC
         return result;
     }
 #endif
+
     InProcServerWrapper::~InProcServerWrapper()
     {
         if(m_processThread.joinable())
@@ -752,4 +760,3 @@ namespace OC
         OCStop();
     }
 }
-
index 8fe41d5..e891116 100644 (file)
@@ -60,11 +60,6 @@ namespace OC
             case PAYLOAD_TYPE_PLATFORM:
                 setPayload(reinterpret_cast<const OCPlatformPayload*>(rep));
                 break;
-#ifdef RD_CLIENT
-            case PAYLOAD_TYPE_RD:
-                setPayload(reinterpret_cast<const OCRDPayload*>(rep));
-                break;
-#endif
             default:
                 throw OC::OCException("Invalid Payload type in setPayload");
                 break;
@@ -165,29 +160,7 @@ namespace OC
             this->addRepresentation(cur);
         }
     }
-#ifdef RD_CLIENT
-    void MessageContainer::setPayload(const OCRDPayload* payload)
-    {
-        OCRepresentation rep;
-        rep[OC_RSRVD_DEVICE_ID] = (payload->rdPublish->tags->di.id) ?
-            std::string(reinterpret_cast<const char*>(payload->rdPublish->tags->di.id)) :
-            std::string();
-        rep[OC_RSRVD_DEVICE_NAME] = (payload->rdPublish->tags->n.deviceName) ?
-            std::string(payload->rdPublish->tags->n.deviceName) :
-            std::string();
-        this->addRepresentation(rep);
-
-        const OCLinksPayload* pl = payload->rdPublish->setLinks;
-        while (pl)
-        {
-            OCRepresentation cur;
-            cur.setPayload(pl);
 
-            pl = pl->next;
-            this->addRepresentation(cur);
-        }
-    }
-#endif
     OCRepPayload* MessageContainer::getPayload() const
     {
         OCRepPayload* root = nullptr;
@@ -726,43 +699,7 @@ namespace OC
             val = val->next;
         }
     }
-#ifdef RD_CLIENT
-    void OCRepresentation::setPayload(const OCLinksPayload* pl)
-    {
-        if (pl->href)
-        {
-            setValue<std::string>(OC_RSRVD_HREF, pl->href);
-        }
-        if (pl->rel)
-        {
-            setValue<std::string>(OC_RSRVD_REL, pl->rel);
-        }
-        OCStringLL* ll = pl->rt;
-        while (ll)
-        {
-            addResourceType(ll->value);
-            ll = ll->next;
-        }
-        ll = pl->itf;
-        while (ll)
-        {
-            addResourceInterface(ll->value);
-            ll = ll->next;
-        }
 
-        setValue<int>(OC_RSRVD_POLICY, pl->p);
-        setValue<int>(OC_RSRVD_INS, pl->ins);
-        setValue<int>(OC_RSRVD_TTL, pl->ttl);
-        if (pl->title)
-        {
-            setValue<std::string>(OC_RSRVD_TITLE, pl->title);
-        }
-        if (pl->anchor)
-        {
-            setValue<std::string>(OC_RSRVD_URI, pl->anchor);
-        }
-    }
-#endif
     void OCRepresentation::addChild(const OCRepresentation& rep)
     {
         m_children.push_back(rep);
index e0106c5..514b0b5 100644 (file)
@@ -99,10 +99,17 @@ if 'PUB' in with_mq:
 if 'BROKER' in with_mq:
        oclib_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
 
-if 'CLIENT' in oclib_env.get('RD_MODE'):
-       oclib_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
-if 'SERVER' in oclib_env.get('RD_MODE'):
-       oclib_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
+if target_os in ['linux', 'android'] and oclib_env.get('RD_MODE'):
+       rd_mode = oclib_env.get('RD_MODE')
+       oclib_env.AppendUnique(LIBPATH = [os.path.join(oclib_env.get('BUILD_DIR'), 'resource', 'csdk','resource-directory')])
+       oclib_env.AppendUnique(CPPPATH = ['../csdk/resource-directory/include'])
+       oclib_env.AppendUnique(LIBS=['resource_directory'])
+
+       if 'CLIENT' in rd_mode:
+               oclib_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
+
+       if 'SERVER' in rd_mode:
+               oclib_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
 
 ######################################################################
 # Source files and Targets
index 18af8c3..b955025 100755 (executable)
@@ -43,7 +43,7 @@ if target_os not in ['arduino','darwin', 'ios', 'windows']:
     if target_os in ['linux']:
         SConscript('scene-manager/SConscript')
 
-    # Build notification-service project    
+    # Build notification-service project
     if target_os in ['linux','android']:
         SConscript('notification/SConscript')
 
@@ -51,10 +51,6 @@ if target_os not in ['arduino','darwin', 'ios', 'windows']:
     if target_os in ['linux'] and env.get('SIMULATOR', False):
         SConscript('simulator/SConscript')
 
-    # Build resource directory project
-    #if env.get('WITH_RD') == '1':
-        #SConscript('resource-directory/SConscript')
-
     # Build coap-http-proxy project
     if target_os in ['linux', 'tizen'] and env.get('WITH_PROXY', False):
         SConscript('coap-http-proxy/SConscript')
@@ -62,4 +58,3 @@ if target_os not in ['arduino','darwin', 'ios', 'windows']:
 # Build EasySetup module
 if target_os in ['arduino', 'android', 'linux','tizen']:
     SConscript('easy-setup/SConscript')
-
index 407c53c..24cc8b7 100755 (executable)
@@ -47,13 +47,15 @@ notification_env.AppendUnique(CPPPATH = ['src/common'])
 notification_env.AppendUnique(CPPPATH = ['src/provider'])
 notification_env.AppendUnique(CPPPATH = ['src/consumer'])
 notification_env.AppendUnique(CPPPATH = ['../../resource/csdk/stack/include'])
+notification_env.AppendUnique(CPPPATH = ['../../resource/csdk/resource-directory/include'])
 notification_env.AppendUnique(CPPPATH = ['../../resource/csdk/connectivity/api'])
 
 notification_env.PrependUnique(LIBS = [
        'octbstack',
        'oc_logger',
        'connectivity_abstraction',
-       'libcoap'
+       'libcoap',
+       'resource_directory'
        ])
 
 if target_os not in ['windows', 'winrt']:
@@ -73,17 +75,17 @@ if target_os == 'android':
                notification_env.AppendUnique(LIBS = ['log'])
 
 if not env.get('RELEASE'):
-    notification_env.PrependUnique(LIBS = ['gcov'])
-    notification_env.AppendUnique(CCFLAGS = ['--coverage'])
+       notification_env.PrependUnique(LIBS = ['gcov'])
+       notification_env.AppendUnique(CCFLAGS = ['--coverage'])
 
 if 'CLIENT' in notification_env.get('RD_MODE'):
-        notification_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
-    
-if env.get('WITH_CLOUD') == True:      
+       notification_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
+
+if env.get('WITH_CLOUD') == True:
        notification_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
 
 if env.get('SECURED') == '1':
-       notification_env.AppendUnique(CPPDEFINES = ['SECURED']) 
+       notification_env.AppendUnique(CPPDEFINES = ['SECURED'])
 
 ######################################################################
 # Source files and Targets
index 790caca..826e60f 100644 (file)
@@ -16,6 +16,7 @@ notification_sample_env.AppendUnique(CPPPATH = ['../../include'])
 notification_sample_env.AppendUnique(CPPPATH = ['../../src/common'])
 notification_sample_env.AppendUnique(CPPPATH = ['../../src/provider'])
 notification_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/stack/include'])
+notification_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/resource-directory/include'])
 notification_sample_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/connectivity/api'])
 
 notification_sample_env.PrependUnique(LIBS = [
index c5e5f8c..2fcdf09 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "ocstack.h"
 #include "ocpayload.h"
-#include "oicresourcedirectory.h"
+#include "rd_client.h"
 #include "cloud_connector.h"
 
 static bool isCloudLoggedin = false;
index dbac395..098035f 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "NSProviderResource.h"
 #include <string.h>
+#include "rd_client.h"
 
 NSNotificationResource NotificationResource;
 NSMessageResource NotificationMessageResource;
diff --git a/service/resource-directory/include/rd_client.h b/service/resource-directory/include/rd_client.h
deleted file mode 100644 (file)
index da55d5b..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef _RESOURCE_DIRECTORY_CLIENT_H_
-#define _RESOURCE_DIRECTORY_CLIENT_H_
-
-// Iotivity Base CAPI
-#include "ocstack.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-/** Callback function for returning RDDiscovery Result. */
-typedef int (* OCRDBiasFactorCB)(char addr[MAX_ADDR_STR_SIZE], uint16_t port);
-
-/** Context structure used sending it as part of the callback context. */
-typedef struct
-{
-    /** Stores the context value of the message sent. */
-    void *context;
-    /** Pointing to the callback function that OCRDDiscover() received. */
-    OCRDBiasFactorCB cbFunc;
-} OCRDClientContextCB;
-
-/**
- * Discovers the resource directory.
- * This function searches a RD server and obtain the bias factor.
- *
- * @param cbBiasFactor callback function invoked when bias factor is returned by
- *                     the Resource Directory Server
- *
- * @return ::OC_STACK_OK upon success, ::OC_STACK_ERROR in case of error.
- */
-OCStackResult OCRDDiscover(OCRDBiasFactorCB cbBiasFactor);
-
-/**
- * Publish resource on the RD.
- *
- * @param addr The IP address of the RD, it could be either retrieved via OCRDDiscover().
- * @param port The port of the RD.
- * @param num This denotes the number of registered resource handles being passed
- *            for the remaining arguments.
- *
- * @returns ::OC_STACK_OK when successful and OC_STACK_ERROR when query failed.
- */
-OCStackResult OCRDPublish(char *addr, uint16_t port, int num, ...);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif //_RESOURCE_DIRECTORY_CLIENT_H_
diff --git a/service/resource-directory/include/rd_payload.h b/service/resource-directory/include/rd_payload.h
deleted file mode 100644 (file)
index 4a6b7df..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef _RESOURCE_DIRECTORY_PAYLOAD_H_
-#define _RESOURCE_DIRECTORY_PAYLOAD_H_
-
-#include <cbor.h>
-
-#include "rd_types.h"
-#include "logger.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-/**
- * Converts RD payload from structure to CBOR format. It creates the outPayload
- * which is then transmitted over the wire.
- *
- * @param rdPayload Contains structure holding values of OCRDPayload.
- * @param outPayload The payload in the CBOR format converting OCRDPayload
- * structure.
- * @param size Length of the payload.
- *
- * @return ::OC_STACK_OK returns if successful and OC_STACK_ERROR returns if
- * failed in creating CBOR.
- */
-OCStackResult OCRDPayloadToCbor(const OCRDPayload *rdPayload,
-                                uint8_t *outPayload, size_t *size);
-
-/**
- * Converts CBOR to OCRDPayload.
- *
- * @param rdCBORPayload Payload received from other end in CBOR format.
- * @param outPayload Parsing the values from CBOR into OCRDPayload structure.
- *
- * @return ::OC_STACK_OK returns if successful and OC_STACK_ERROR returns if
- * failed in parsing CBOR.
- */
-OCStackResult OCRDCborToPayload(const CborValue *rdCBORPayload, OCPayload **outPayload);
-
-/**
- * Initializes RD payload structure.
- *
- * @param payloadType Defines whether payload is RD_PAYLOAD_TYPE_DISCOVERY or
- * RD_PAYLOAD_TYPE_PUBLISH.
- *
- * @return Allocated memory for the OCRDPayload and NULL in case if failed to
- * allocate memory
- */
-OCRDPayload *OCRDPayloadCreate(OCRDPayloadType payloadType);
-
-/**
- * Initializes RD Discovery payload structure and sets the bias factor.
- *
- * @param biasFactor Value specifies the selection factor. It is weigthage of
- * CPU, Memory, Network, Load and Power capability of the RD server.
- *
- * @return Allocated memory for the OCRDDiscoveryPayload and NULL in case if
- * failed to allocate memory.
- */
-OCRDDiscoveryPayload *OCRDDiscoveryPayloadCreate(int biasFactor);
-
-/**
- * Creates the links payload, which is then embedded inside OCRDPublishPayload.
- *
- * @param uri  The Web Link Address of the resource.
- * @param rt   The resource type of the published resource.
- * @param itf  The interface type of the published resource.
- * @param linkPayload The address of the allocated memory or NULL in case if failed
- *                    to allocate memory.
- */
-void OCRDLinksPayloadCreate(const char *uri, const char *rt, const char *itf,
-        OCRDLinksPayload **linkPayload);
-
-/**
- * Creates the links payload, which is then embedded inside OCRDPublishPayload.
- *
- * @param ttl  Time to live of the published resource..
- * @param linkPayload  The link payload with uri, rt and itf.
- *
- * @return  Allocated memory of OCRDPublishPayload or NULL in case if failed
- *          to allocate memory.
- */
-OCRDPublishPayload *OCRDPublishPayloadCreate(const int ttl,
-        OCRDLinksPayload *linkPayload);
-
-/**
- * Free memory allocation of the RDPayload and its internal structure.
- *
- * @param payload Pointer to already allocated memory for OCRDPayload.
- */
-void OCRDPayloadDestroy(OCRDPayload *payload);
-
-/**
- * Logs the content of the OCRDPayload.
- *
- * @param level Log level DEBUG or INFO or ERROR.
- * @param tag File specific tag to use.
- * @param payload Pointer to already allocated memory for OCRDPayload.
- */
-void OCRDPayloadLog(LogLevel level, const char *tag, const OCRDPayload *payload);
-
-/**
- * Logs the subset of the OCRDPayload, prints separately OCRDPublish.
- *
- * @param level Log level DEBUG or INFO or ERROR.
- * @param tag File specific tag to use.
- * @param payload Pointer to already allocated memory for OCRDPublish.
- */
-void OCRDPublishPayloadLog(LogLevel level, const char *tag,
-        const OCRDPublishPayload *payload);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif
diff --git a/service/resource-directory/src/internal/rd_storage.c b/service/resource-directory/src/internal/rd_storage.c
deleted file mode 100644 (file)
index 8c4eec1..0000000
+++ /dev/null
@@ -1,266 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include "rd_storage.h"
-#include <string.h>
-
-#include "payload_logging.h"
-#include "oic_malloc.h"
-#include "octypes.h"
-
-#include "rdpayload.h"
-
-#define TAG  PCF("RDStorage")
-
-oc_mutex g_storageMutex = NULL;
-
-
-static OCRDStorePublishResources *g_rdStorage = NULL;
-
-static void printStoragedResources(OCRDStorePublishResources *payload)
-{
-    OIC_LOG(DEBUG, TAG, "Print Storage Resources ... ");
-    for (OCRDStorePublishResources *temp = payload; temp; temp = temp->next)
-    {
-        if (temp->publishedResource)
-        {
-            OCTagsLog(DEBUG, temp->publishedResource->tags);
-            OCLinksLog(DEBUG, temp->publishedResource->setLinks);
-        }
-    }
-}
-
-OCStackResult OCRDStorePublishedResources(const OCResourceCollectionPayload *payload, const OCDevAddr *address)
-{
-    OCResourceCollectionPayload *storeResource = (OCResourceCollectionPayload *)OICCalloc(1, sizeof(OCResourceCollectionPayload));
-    if (!storeResource)
-    {
-        OIC_LOG(ERROR, TAG, "Failed allocating memory for OCRDStorePublishResources.");
-        return OC_STACK_NO_MEMORY;
-    }
-
-    OIC_LOG_V(DEBUG, TAG, "Storing Resources for %s:%u", address->addr, address->port);
-
-    OCTagsPayload *tags = payload->tags;
-    storeResource->tags = OCCopyTagsResources(tags->n.deviceName, tags->di.id, tags->baseURI,
-        tags->bitmap, address->port, tags->ins, tags->rts, tags->drel, tags->ttl);
-    if (!storeResource->tags)
-    {
-        OIC_LOG(ERROR, TAG, "Failed allocating memory for tags.");
-        OCFreeCollectionResource(storeResource);
-        return OC_STACK_NO_MEMORY;
-    }
-
-    for (OCLinksPayload *links = payload->setLinks; links; links = links->next)
-    {
-        if (!storeResource->setLinks)
-        {
-            storeResource->setLinks = OCCopyLinksResources(links->href, links->rt, links->itf,
-                links->rel, links->obs, links->title, links->uri, links->ins, links->mt);
-            if (!storeResource->setLinks)
-            {
-                OIC_LOG(ERROR, TAG, "Failed allocating memory for links.");
-                OCFreeCollectionResource(storeResource);
-                return OC_STACK_NO_MEMORY;
-            }
-        }
-        else
-        {
-            OCLinksPayload *temp = storeResource->setLinks;
-            while (temp->next)
-            {
-                temp = temp->next;
-            }
-            temp->next = OCCopyLinksResources(links->href, links->rt, links->itf, links->rel,
-                links->obs, links->title, links->uri, links->ins, links->mt);
-            if (!temp->next)
-            {
-                OIC_LOG(ERROR, TAG, "Failed allocating memory for links.");
-                OCFreeCollectionResource(storeResource);
-                return OC_STACK_NO_MEMORY;
-            }
-        }
-
-    }
-    storeResource->next = NULL;
-    OCRDStorePublishResources *resources = (OCRDStorePublishResources *)OICCalloc(1, sizeof(OCRDStorePublishResources));
-    if (!resources)
-    {
-        OCFreeCollectionResource(storeResource);
-        return OC_STACK_NO_MEMORY;
-    }
-    resources->publishedResource = storeResource;
-    resources->devAddr = *address;
-
-    oc_mutex_lock(g_storageMutex);
-    if (g_rdStorage)
-    {
-        OCRDStorePublishResources *temp = g_rdStorage;
-        while (temp->next)
-        {
-            temp = temp->next;
-        }
-        temp->next = resources;
-    }
-    else
-    {
-        g_rdStorage = resources;
-    }
-    oc_mutex_unlock(g_storageMutex);
-
-    printStoragedResources(g_rdStorage);
-    return OC_STACK_OK;
-}
-
-OCStackResult OCRDCheckPublishedResource(const char *interfaceType, const char *resourceType,
-        OCResourceCollectionPayload **payload, OCDevAddr *devAddr)
-{
-    // ResourceType and InterfaceType if both are NULL it will return. If either is
-    // not null it will continue execution.
-    if (!resourceType && !interfaceType)
-    {
-        OIC_LOG(DEBUG, TAG, "Missing resource type or interace type.");
-        return OC_STACK_INVALID_PARAM;
-    }
-
-    OIC_LOG(DEBUG, TAG, "Check Resource in RD");
-    if (g_rdStorage && g_rdStorage->publishedResource)
-    {
-        for (OCRDStorePublishResources *pResource = g_rdStorage;
-                pResource; pResource = pResource->next)
-        {
-            if (pResource->publishedResource->setLinks)
-            {
-                for (OCLinksPayload *tLinks = pResource->publishedResource->setLinks; tLinks; tLinks = tLinks->next)
-                {
-                    // If either rt or itf are NULL, it should skip remaining code execution.
-                    if (!tLinks->rt || !tLinks->itf)
-                    {
-                        OIC_LOG(DEBUG, TAG, "Either resource type or interface type is missing.");
-                        continue;
-                    }
-                    if (resourceType)
-                    {
-                        OCStringLL *temp = tLinks->rt;
-                        while(temp)
-                        {
-                            OIC_LOG_V(DEBUG, TAG, "Resource Type: %s %s", resourceType, temp->value);
-                            if (strcmp(resourceType, temp->value) == 0)
-                            {
-                                OCTagsPayload *tag = pResource->publishedResource->tags;
-                                OCTagsPayload *tags = OCCopyTagsResources(tag->n.deviceName, tag->di.id, tag->baseURI,
-                                    tag->bitmap, tag->port, tag->ins, tag->rts, tag->drel, tag->ttl);
-                                if (!tags)
-                                {
-                                    return OC_STACK_NO_MEMORY;
-                                }
-                                OCLinksPayload *links = OCCopyLinksResources(tLinks->href, tLinks->rt, tLinks->itf,
-                                    tLinks->rel, tLinks->obs, tLinks->title, tLinks->uri, tLinks->ins, tLinks->mt);
-                                if (!links)
-                                {
-                                    OCFreeTagsResource(tags);
-                                    return OC_STACK_NO_MEMORY;
-                                }
-                                *payload = OCCopyCollectionResource(tags, links);
-                                if (!*payload)
-                                {
-                                    OCFreeTagsResource(tags);
-                                    OCFreeLinksResource(links);
-                                    return OC_STACK_NO_MEMORY;
-                                }
-                                memcpy(devAddr, &pResource->devAddr, sizeof(*devAddr));
-                                return OC_STACK_OK;
-                            }
-                            temp = temp->next;
-                        }
-                    }
-                    if (interfaceType)
-                    {
-                        OCStringLL *temp = tLinks->itf;
-                        while (temp)
-                        {
-                            OIC_LOG_V(DEBUG, TAG, "Interface Type: %s %s", interfaceType, temp->value);
-                            if (strcmp(interfaceType, temp->value) == 0)
-                            {
-                                OCTagsPayload *tag = pResource->publishedResource->tags;
-                                OCTagsPayload *tags = OCCopyTagsResources(tag->n.deviceName, tag->di.id, tag->baseURI,
-                                    tag->bitmap, tag->port, tag->ins, tag->rts, tag->drel, tag->ttl);
-                                if (!tags)
-                                {
-                                    return OC_STACK_NO_MEMORY;
-                                }
-                                OCLinksPayload *links = OCCopyLinksResources(tLinks->uri, tLinks->rt, tLinks->itf,
-                                    tLinks->rel, tLinks->obs, tLinks->title, tLinks->uri, tLinks->ins, tLinks->mt);
-                                if (!links)
-                                {
-                                    OCFreeTagsResource(tags);
-                                    return OC_STACK_NO_MEMORY;
-                                }
-                                *payload = OCCopyCollectionResource(tags, links);
-                                if (!*payload)
-                                {
-                                    OCFreeTagsResource(tags);
-                                    OCFreeLinksResource(links);
-                                    return OC_STACK_NO_MEMORY;
-                                }
-                                devAddr = &pResource->devAddr;
-                                return OC_STACK_OK;
-                            }
-                            temp = temp->next;
-                        }
-                    }
-                }
-            }
-        }
-    }
-    return OC_STACK_ERROR;
-}
-
-/**
- * Initializes the publish resources.
- *
- * @return ::OC_STACK_OK upon success, ::OC_STACK_ERROR in case of error.
- */
-OCStackResult OCRDInitializeStorage()
-{
-    assert(g_storageMutex == NULL);
-
-    g_storageMutex = oc_mutex_new();
-    if (g_storageMutex == NULL)
-    {
-        return OC_STACK_ERROR;
-    }
-
-    g_rdStorage = NULL;
-    return OC_STACK_OK;
-}
-
-/**
- * Cleans up the publish resources.
- */
-void OCRDTerminateStorage()
-{
-    assert(g_rdStorage == NULL);
-
-    if (g_storageMutex != NULL)
-    {
-        oc_mutex_free(g_storageMutex);
-        g_storageMutex = NULL;
-    }
-}
diff --git a/service/resource-directory/src/internal/rd_storage.h b/service/resource-directory/src/internal/rd_storage.h
deleted file mode 100644 (file)
index f60c791..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#ifndef _RESOURCE_DIRECTORY_SERVER_STORAGE_H_
-#define _RESOURCE_DIRECTORY_SERVER_STORAGE_H_
-
-#include "octypes.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-/** Stucture holding Published Resources on the Resource Directory. */
-typedef struct OCRDStorePublishResources
-{
-    OCDevAddr devAddr;
-    /** Publish resource. */
-    OCResourceCollectionPayload *publishedResource;
-    /** Linked list pointing to next published resource. */
-    struct OCRDStorePublishResources *next;
-} OCRDStorePublishResources;
-
-/**
- * Stores the publish resources.
- *
- * @param payload RDPublish payload sent from the remote device.
- * @param address The address of the device publishing resources.
- *
- * @return ::OC_STACK_OK upon success, ::OC_STACK_ERROR in case of error.
- */
-OCStackResult OCRDStorePublishedResources(const OCResourceCollectionPayload *payload, const OCDevAddr *address);
-
-/**
- * Initializes the publish resources.
- *
- * @return ::OC_STACK_OK upon success, ::OC_STACK_ERROR in case of error.
- */
-OCStackResult OCRDInitializeStorage();
-
-/**
- * Cleans up the publish resources.
- */
-void OCRDTerminateStorage();
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif //_RESOURCE_DIRECTORY_SERVER_STORAGE_H_
diff --git a/service/resource-directory/src/rd_client.c b/service/resource-directory/src/rd_client.c
deleted file mode 100644 (file)
index d444431..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include "rd_client.h"
-
-#include <stdarg.h>
-
-#include "oic_string.h"
-#include "oic_malloc.h"
-#include "payload_logging.h"
-#include "platform_features.h"
-
-#include "rdpayload.h"
-#include "ocpayload.h"
-
-#define DEFAULT_CONTEXT_VALUE 0x99
-#define OC_RD_PUBLISH_TTL 86400
-
-#define TAG  PCF("RDClient")
-
-static OCStackResult sendRequest(OCMethod method, char *uri, OCDevAddr *addr,
-        OCPayload *payload, OCCallbackData cbData)
-{
-    OCDoHandle handle;
-    OCStackResult result;
-
-    result = OCDoResource(&handle,
-        method,
-        uri,
-        addr,
-        payload,
-        CT_ADAPTER_IP,
-        OC_LOW_QOS,
-        &cbData,
-        NULL,
-        0);
-
-    if (result == OC_STACK_OK)
-    {
-        OIC_LOG(DEBUG, TAG, "Resource Directory send successful...");
-    }
-    else
-    {
-        OIC_LOG(ERROR, TAG, "Resource Directory send failed...");
-    }
-
-    return result;
-}
-
-static OCStackApplicationResult handlePublishCB(OC_ANNOTATE_UNUSED void *ctx,
-        OC_ANNOTATE_UNUSED OCDoHandle handle,
-        OC_ANNOTATE_UNUSED OCClientResponse *clientResponse)
-{
-    OCStackApplicationResult ret = OC_STACK_DELETE_TRANSACTION;
-    OIC_LOG(DEBUG, TAG, "Successfully published resources.");
-
-    if (OC_STACK_OK == OCStopMulticastServer())
-    {
-        OIC_LOG_V(DEBUG, TAG, "Stopped receiving the multicast traffic.");
-    }
-    else
-    {
-        OIC_LOG_V(DEBUG, TAG, "Failed stopping the multicast traffic.");
-    }
-
-    return ret;
-}
-
-static void retreiveRDDetails(OCClientResponse *clientResponse, OCRDBiasFactorCB clientCB)
-{
-    OIC_LOG_V(DEBUG, TAG, "\tAddress of the RD: %s:%d", clientResponse->devAddr.addr,
-            clientResponse->devAddr.port);
-
-    OIC_LOG_PAYLOAD(DEBUG, clientResponse->payload);
-
-    // TODO: Multiple Resource Directory will have different biasFactor,
-    // needs to cache here detail
-    // and after certain timeout then decide based on the biasFactor.
-    //if (biasFactor > 75)
-    if (clientCB)
-    {
-        clientCB(clientResponse->devAddr.addr, clientResponse->devAddr.port);
-    }
-}
-
-static OCStackApplicationResult handleDiscoverCB(void *ctx,
-        OC_ANNOTATE_UNUSED OCDoHandle handle, OCClientResponse *clientResponse)
-{
-    OIC_LOG(DEBUG, TAG, "Found Resource Directory");
-    OCStackApplicationResult ret = OC_STACK_DELETE_TRANSACTION;
-
-    OCRDClientContextCB *cb = (OCRDClientContextCB *)ctx;
-    if (!cb)
-    {
-        OIC_LOG(ERROR, TAG, "RD Context Invalid Parameters.");
-        return ret;
-    }
-
-    if (cb->context != (void *) DEFAULT_CONTEXT_VALUE)
-    {
-        OIC_LOG(ERROR, TAG, "RD Context Invalid Context Value Parameters.");
-        return ret;
-    }
-
-    if (clientResponse)
-    {
-        OIC_LOG_V(DEBUG, TAG, "Callback Context for DISCOVER query received successfully :%d.", clientResponse->result);
-        if (clientResponse->result == OC_STACK_OK)
-        {
-            retreiveRDDetails(clientResponse, cb->cbFunc);
-        }
-        else
-        {
-            OIC_LOG(ERROR, TAG, "Discovery of RD Failed");
-        }
-    }
-    else
-    {
-        OIC_LOG(ERROR, TAG, "No client response.");
-    }
-
-    OICFree(cb);
-
-    return ret;
-}
-
-OCStackResult OCRDDiscover(OCRDBiasFactorCB cbBiasFactor)
-{
-    if (!cbBiasFactor)
-    {
-        OIC_LOG(DEBUG, TAG, "No callback function specified.");
-        return OC_STACK_INVALID_CALLBACK;
-    }
-
-    /* Start a discovery query*/
-    char queryUri[MAX_URI_LENGTH] = { '\0' };
-    snprintf(queryUri, MAX_URI_LENGTH, "coap://%s%s", OC_MULTICAST_PREFIX, OC_RSRVD_RD_URI);
-
-    OIC_LOG_V(DEBUG, TAG, "Querying RD: %s\n", queryUri);
-
-    OCRDClientContextCB *cbContext = (OCRDClientContextCB *)OICCalloc(1, sizeof(OCRDClientContextCB));
-    if (!cbContext)
-    {
-        OIC_LOG(ERROR, TAG, "Failed allocating memory.");
-        return OC_STACK_NO_MEMORY;
-    }
-
-    cbContext->context = (void *)DEFAULT_CONTEXT_VALUE;
-    cbContext->cbFunc = cbBiasFactor;
-
-    OCCallbackData cbData;
-    cbData.cb = handleDiscoverCB;
-    cbData.context = (void *)(cbContext);
-    cbData.cd = NULL;
-
-    return sendRequest(OC_REST_DISCOVER, queryUri, NULL, NULL, cbData);
-}
-
-static OCStackResult createStringLL(uint8_t numElements, OCResourceHandle handle,
-    const char* (*getValue)(OCResourceHandle handle, uint8_t i), OCStringLL **stringLL)
-{
-    for (uint8_t i = 0; i < numElements; ++i)
-    {
-        const char *value = getValue(handle, i);
-        if (!*stringLL)
-        {
-            *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!*stringLL)
-            {
-                OIC_LOG(ERROR, TAG, "Failed allocating memory.");
-                return OC_STACK_NO_MEMORY;
-            }
-            (*stringLL)->value = OICStrdup(value);
-            if (!(*stringLL)->value)
-            {
-                OIC_LOG(ERROR, TAG, "Failed copying to OCStringLL.");
-                return OC_STACK_NO_MEMORY;
-            }
-        }
-        else
-        {
-            OCStringLL *cur = *stringLL;
-            while (cur->next)
-            {
-                cur = cur->next;
-            }
-            cur->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!cur->next)
-            {
-                OIC_LOG(ERROR, TAG, "Failed allocating memory.");
-                return OC_STACK_NO_MEMORY;
-            }
-            cur->next->value = OICStrdup(value);
-            if (!cur->next->value)
-            {
-                OIC_LOG(ERROR, TAG, "Failed copying to OCStringLL.");
-                return OC_STACK_NO_MEMORY;
-            }
-        }
-    }
-    return OC_STACK_OK;
-}
-
-OCStackResult OCRDPublish(char *addr, uint16_t port, int numArg, ... )
-{
-    if (!addr)
-    {
-        OIC_LOG(ERROR, TAG, "RD address not specified.");
-        return OC_STACK_INVALID_PARAM;
-    }
-
-    char targetUri[MAX_URI_LENGTH];
-    snprintf(targetUri, MAX_URI_LENGTH, "coap://%s:%d%s?rt=%s", addr, port,
-            OC_RSRVD_RD_URI, OC_RSRVD_RESOURCE_TYPE_RDPUBLISH);
-    OIC_LOG_V(DEBUG, TAG, "Target URI : %s", targetUri);
-
-    // Gather all resources locally and do publish
-    OCCallbackData cbData = { 0 };
-    cbData.cb = &handlePublishCB;
-    cbData.cd = NULL;
-    cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
-
-    OCTagsPayload *tagsPayload = NULL;
-    OCLinksPayload *linksPayload = NULL;
-    OCStringLL *rt = NULL;
-    OCStringLL *itf = NULL;
-    OCStringLL *mt = NULL;
-
-    OCRDPayload *rdPayload = OCRDPayloadCreate();
-    if (!rdPayload)
-    {
-        goto no_memory;
-    }
-
-    const unsigned char *id = (unsigned char*) OCGetServerInstanceIDString();
-    tagsPayload = OCCopyTagsResources(NULL, id,
-            NULL, OC_DISCOVERABLE, 0, 0, NULL, NULL, OC_RD_PUBLISH_TTL);
-    if (!tagsPayload)
-    {
-        goto no_memory;
-    }
-
-    va_list arguments;
-    va_start (arguments, numArg);
-
-    for (int j = 0 ; j < numArg; j++)
-    {
-        OCResourceHandle handle = va_arg(arguments, OCResourceHandle);
-        if (handle)
-        {
-            rt = itf = mt = NULL;
-            const char *uri = OCGetResourceUri(handle);
-            uint8_t numElement;
-            if (OC_STACK_OK == OCGetNumberOfResourceTypes(handle, &numElement))
-            {
-                OCStackResult res = createStringLL(numElement, handle, OCGetResourceTypeName, &rt);
-                if (res != OC_STACK_OK || !rt)
-                {
-                    goto no_memory;
-                }
-            }
-
-            if (OC_STACK_OK == OCGetNumberOfResourceTypes(handle, &numElement))
-            {
-                OCStackResult res = createStringLL(numElement, handle, OCGetResourceInterfaceName, &itf);
-                if (res != OC_STACK_OK || !itf)
-                {
-                    goto no_memory;
-                }
-            }
-
-            mt = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            if (!mt)
-            {
-                goto no_memory;
-            }
-            mt->value = OICStrdup("application/json");
-            if (!mt->value)
-            {
-                goto no_memory;
-            }
-
-            if (!linksPayload)
-            {
-                linksPayload = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL,
-                        NULL, j, mt);;
-                if (!linksPayload)
-                {
-                    goto no_memory;
-                }
-            }
-            else
-            {
-                OCLinksPayload *temp = linksPayload;
-                while (temp->next)
-                {
-                    temp = temp->next;
-                }
-                temp->next = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL,
-                        NULL, j, mt);
-                if (!temp->next)
-                {
-                    goto no_memory;
-                }
-            }
-            OCFreeOCStringLL(rt);
-            OCFreeOCStringLL(itf);
-            OCFreeOCStringLL(mt);
-        }
-    }
-    va_end(arguments);
-
-    rdPayload->rdPublish = OCCopyCollectionResource(tagsPayload, linksPayload);
-    if (!rdPayload->rdPublish)
-    {
-        goto no_memory;
-    }
-
-    OCTagsLog(DEBUG, rdPayload->rdPublish->tags);
-    OCLinksLog(DEBUG, rdPayload->rdPublish->setLinks);
-
-    OCDevAddr rdAddr = { 0 };
-    OICStrcpy(rdAddr.addr, MAX_ADDR_STR_SIZE, addr);
-    rdAddr.port = port;
-
-    OIC_LOG_PAYLOAD(DEBUG, (OCPayload *) rdPayload);
-
-    return sendRequest(OC_REST_POST, targetUri, &rdAddr, (OCPayload *)rdPayload, cbData);
-
-no_memory:
-    OIC_LOG(ERROR, TAG, "Failed allocating memory.");
-    va_end(arguments);
-    if (rt)
-    {
-        OCFreeOCStringLL(rt);
-    }
-    if (itf)
-    {
-        OCFreeOCStringLL(itf);
-    }
-    if (mt)
-    {
-        OCFreeOCStringLL(mt);
-    }
-    if (tagsPayload)
-    {
-        OCFreeTagsResource(tagsPayload);
-    }
-    if (linksPayload)
-    {
-        OCFreeLinksResource(linksPayload);
-    }
-    OCRDPayloadDestroy(rdPayload);
-    return OC_STACK_NO_MEMORY;
-}
index 0aa829f..72ab45e 100644 (file)
@@ -75,13 +75,13 @@ TIMER_SRC_DIR = 'expiryTimer/src/'
 RESOURCE_SRC = 'primitiveResource/src/'
 rcs_common_src = [
         TIMER_SRC_DIR + 'ExpiryTimerImpl.cpp',
-               TIMER_SRC_DIR + 'ExpiryTimer.cpp',
-               RESOURCE_SRC + 'PresenceSubscriber.cpp',
-               RESOURCE_SRC + 'PrimitiveResource.cpp',
-               RESOURCE_SRC + 'RCSException.cpp',
-               RESOURCE_SRC + 'RCSAddress.cpp',
-               RESOURCE_SRC + 'RCSResourceAttributes.cpp',
-               RESOURCE_SRC + 'RCSRepresentation.cpp'
+        TIMER_SRC_DIR + 'ExpiryTimer.cpp',
+        RESOURCE_SRC + 'PresenceSubscriber.cpp',
+        RESOURCE_SRC + 'PrimitiveResource.cpp',
+        RESOURCE_SRC + 'RCSException.cpp',
+        RESOURCE_SRC + 'RCSAddress.cpp',
+        RESOURCE_SRC + 'RCSResourceAttributes.cpp',
+        RESOURCE_SRC + 'RCSRepresentation.cpp'
         ]
 
 rcs_common_static = rcs_common_env.StaticLibrary('rcs_common', rcs_common_src)
index b512d22..e6aac6e 100644 (file)
@@ -129,9 +129,6 @@ std::string getPayloadTypeString(OCPayloadType type)
         case PAYLOAD_TYPE_PRESENCE:
             typeStr = "PAYLOAD_TYPE_PRESENCE";
             break;
-        case PAYLOAD_TYPE_RD:
-            typeStr = "PAYLOAD_TYPE_RD";
-            break;
     }
     return typeStr;
 }