Merge branch 'master' into notification-service
authorHun-je Yeon <hunje.yeon@samsung.com>
Thu, 28 Jul 2016 09:44:15 +0000 (18:44 +0900)
committerHun-je Yeon <hunje.yeon@samsung.com>
Thu, 28 Jul 2016 10:08:19 +0000 (19:08 +0900)
Change-Id: I7888de55cc1ba0e1dc5e4a9350c67b6a2126beb0
Signed-off-by: Hun-je Yeon <hunje.yeon@samsung.com>
92 files changed:
android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java
build_common/SConscript
cloud/account/Github.jar
cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServer.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServerManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/MongoDB.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Github.jar [deleted file]
cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Github.java [new file with mode: 0644]
cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/OAuthServerFactory.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/token/TokenGenerator.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/token/TokenManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/token/TokenValidator.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/CloudInterfaceServer.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/DeviceServerSystem.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/DiResource.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/MessageQueue.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/Constants.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/MessageQueueServer.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/MessageQueueUtils.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaCommonWrapper.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaConsumerWrapper.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaProducerWrapper.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/resources/MQBrokerResource.java
cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/topic/Topic.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/ResourceDirectoryServer.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/rd/ResourceDirectoryResource.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/res/DiscoveryResource.java
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/presence/device/DevicePresenceResource.java
cloud/stack/pom.xml
cloud/stack/src/main/java/org/iotivity/cloud/base/ServerSystem.java
cloud/stack/src/main/java/org/iotivity/cloud/base/connector/CoapClient.java
cloud/stack/src/main/java/org/iotivity/cloud/base/device/CoapDevice.java
cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/MessageBuilder.java
cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/coap/CoapLogHandler.java
cloud/stack/src/main/java/org/iotivity/cloud/base/server/Server.java
cloud/stack/src/main/java/org/iotivity/cloud/util/Cbor.java
cloud/stack/src/main/java/org/iotivity/cloud/util/ErrorLogger.java [deleted file]
cloud/stack/src/main/java/org/iotivity/cloud/util/FileLogger.java [deleted file]
cloud/stack/src/main/java/org/iotivity/cloud/util/Log.java [moved from cloud/stack/src/main/java/org/iotivity/cloud/util/Logger.java with 68% similarity]
gbsbuild.sh
resource/csdk/SConscript
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/test/SConscript
resource/csdk/security/provisioning/sample/SConscript
resource/csdk/security/src/aclresource.c
resource/csdk/security/src/credresource.c
resource/csdk/security/src/doxmresource.c
resource/csdk/security/src/pstatresource.c
resource/csdk/stack/include/internal/ocresource.h
resource/csdk/stack/include/internal/ocstackinternal.h
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/include/octypes.h
resource/csdk/stack/include/oicresourcedirectory.h [new file with mode: 0644]
resource/csdk/stack/include/payload_logging.h
resource/csdk/stack/include/rdpayload.h
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/ocserverrequest.c
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/oicresourcedirectory.c [new file with mode: 0644]
resource/csdk/stack/src/rdpayload.c
resource/csdk/stack/test/rdtests.cpp [new file with mode: 0644]
resource/examples/SConscript
resource/examples/garageclient.cpp
resource/examples/rdclient.cpp [new file with mode: 0644]
resource/examples/simpleclient.cpp
resource/examples/simpleclientHQ.cpp
resource/examples/simpleclientserver.cpp
resource/examples/winuiclient.cpp
resource/include/IClientWrapper.h
resource/include/IServerWrapper.h
resource/include/InProcClientWrapper.h
resource/include/InProcServerWrapper.h
resource/include/OCApi.h
resource/include/OCPlatform.h
resource/include/OCPlatform_impl.h
resource/include/OCRepresentation.h
resource/include/OutOfProcClientWrapper.h
resource/include/StringConstants.h
resource/src/InProcClientWrapper.cpp
resource/src/InProcServerWrapper.cpp
resource/src/OCPlatform.cpp
resource/src/OCPlatform_impl.cpp
resource/src/OCRepresentation.cpp
resource/src/SConscript
resource/unit_tests.scons
resource/unittests/OCPlatformTest.cpp
service/SConscript
service/notification/src/common/NSCloudConnector.c

index d6a67c7..9f814d8 100644 (file)
@@ -85,6 +85,11 @@ public class SmokeTest extends InstrumentationTestCase {
                         }
                         signal.countDown();
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -157,6 +162,11 @@ public class SmokeTest extends InstrumentationTestCase {
                             assertTrue(false);
                         }
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -263,6 +273,11 @@ public class SmokeTest extends InstrumentationTestCase {
                         }
                         signal1.countDown();
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -430,6 +445,11 @@ public class SmokeTest extends InstrumentationTestCase {
                         }
                         signal1.countDown();
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -603,6 +623,11 @@ public class SmokeTest extends InstrumentationTestCase {
                         }
                         signal1.countDown();
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -731,6 +756,11 @@ public class SmokeTest extends InstrumentationTestCase {
                         }
                         signal1.countDown();
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -895,6 +925,11 @@ public class SmokeTest extends InstrumentationTestCase {
                         }
                         signal1.countDown();
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -1094,6 +1129,11 @@ public class SmokeTest extends InstrumentationTestCase {
             public void onResourceFound(OcResource resource) {
                 signal1.countDown();
             }
+
+            @Override
+            public void onFindResourceFailed(Throwable ex, String uri) {
+                Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+            }
         };
 
         OcPlatform.OnResourceFoundListener resourceFoundListener2 = new OcPlatform.OnResourceFoundListener() {
@@ -1101,6 +1141,11 @@ public class SmokeTest extends InstrumentationTestCase {
             public void onResourceFound(OcResource resource) {
                 signal2.countDown();
             }
+
+            @Override
+            public void onFindResourceFailed(Throwable ex, String uri) {
+                Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+            }
         };
 
         OcPlatform.OnResourceFoundListener resourceFoundListener3 = new OcPlatform.OnResourceFoundListener() {
@@ -1108,6 +1153,11 @@ public class SmokeTest extends InstrumentationTestCase {
             public void onResourceFound(OcResource resource) {
                 signal3.countDown();
             }
+
+            @Override
+            public void onFindResourceFailed(Throwable ex, String uri) {
+                Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+            }
         };
 
         OcPlatform.OnResourceFoundListener resourceFoundListener4 = new OcPlatform.OnResourceFoundListener() {
@@ -1115,6 +1165,11 @@ public class SmokeTest extends InstrumentationTestCase {
             public void onResourceFound(OcResource resource) {
                 signal4.countDown();
             }
+
+            @Override
+            public void onFindResourceFailed(Throwable ex, String uri) {
+                Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+            }
         };
 
         OcPlatform.OnResourceFoundListener resourceFoundListener5 = new OcPlatform.OnResourceFoundListener() {
@@ -1122,6 +1177,11 @@ public class SmokeTest extends InstrumentationTestCase {
             public void onResourceFound(OcResource resource) {
                 signal5.countDown();
             }
+
+            @Override
+            public void onFindResourceFailed(Throwable ex, String uri) {
+                Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+            }
         };
 
         OcPlatform.OnResourceFoundListener resourceFoundListener6 = new OcPlatform.OnResourceFoundListener() {
@@ -1129,6 +1189,11 @@ public class SmokeTest extends InstrumentationTestCase {
             public void onResourceFound(OcResource resource) {
                 signal6.countDown();
             }
+
+            @Override
+            public void onFindResourceFailed(Throwable ex, String uri) {
+                Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+            }
         };
 
         try {
@@ -1279,6 +1344,11 @@ public class SmokeTest extends InstrumentationTestCase {
 
                         signal.countDown();
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -1359,6 +1429,11 @@ public class SmokeTest extends InstrumentationTestCase {
                         }
                         signal.countDown();
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
 
         try {
@@ -1557,6 +1632,11 @@ public class SmokeTest extends InstrumentationTestCase {
                             }
                         }
                     }
+
+                    @Override
+                    public void onFindResourceFailed(Throwable ex, String uri) {
+                        Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage());
+                    }
                 };
         try {
             //server
index 9756ca0..ca26680 100644 (file)
@@ -87,8 +87,8 @@ help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map
 help_vars.Add(BoolVariable('WITH_RA', 'Build with Remote Access module', False))
 help_vars.Add(BoolVariable('WITH_TCP', 'Build with TCP adapter', False))
 help_vars.Add(ListVariable('WITH_MQ', 'Build with MQ publisher/broker', 'OFF', ['OFF', 'SUB', 'PUB', 'BROKER']))
-help_vars.Add(EnumVariable('WITH_RD', 'Build including Resource Directory', '0', allowed_values=('0', '1')))
 help_vars.Add(BoolVariable('WITH_CLOUD', 'Build including Cloud Connector and Cloud Client sample', False))
+help_vars.Add(ListVariable('RD_MODE', 'Resource Directory build mode', 'CLIENT', ['CLIENT', 'SERVER']))
 
 help_vars.Add(BoolVariable('SIMULATOR', 'Build with simulator module', False))
 
index c7b8f8a..5d6cce7 100644 (file)
Binary files a/cloud/account/Github.jar and b/cloud/account/Github.jar differ
index f9c00a9..8bc8039 100644 (file)
@@ -30,9 +30,7 @@ import org.iotivity.cloud.accountserver.resources.account.session.SessionResourc
 import org.iotivity.cloud.accountserver.resources.account.tokenrefresh.TokenRefreshResource;
 import org.iotivity.cloud.base.ServerSystem;
 import org.iotivity.cloud.base.server.CoapServer;
-import org.iotivity.cloud.util.ErrorLogger;
-import org.iotivity.cloud.util.FileLogger;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 /**
  *
@@ -42,18 +40,16 @@ import org.iotivity.cloud.util.Logger;
 public class AccountServer {
 
     public static void main(String[] args) throws Exception {
-        System.setOut(FileLogger.createLoggingProxy(System.out));
-
+        Log.Init();
+        
         System.out.println("-----Account SERVER-----");
 
         if (args.length != 2) {
-            Logger.e("coap server port and TLS mode required\n"
+            Log.e("coap server port and TLS mode required\n"
                     + "ex) 5685 0\n");
             return;
         }
 
-        ErrorLogger.Init();
-
         ServerSystem serverSystem = new ServerSystem();
 
         serverSystem.addResource(new AccountResource());
index 2214ebc..6a0f62f 100644 (file)
@@ -27,7 +27,7 @@ import org.iotivity.cloud.accountserver.db.AccountDBManager;
 import org.iotivity.cloud.accountserver.oauth.OAuthServerFactory;
 import org.iotivity.cloud.accountserver.token.Token;
 import org.iotivity.cloud.accountserver.token.TokenManager;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 /**
  *
@@ -41,7 +41,7 @@ public class AccountServerManager {
 
     /**
      * API for requesting user account
-     * 
+     *
      * @param userId
      *            user identifier
      * @param deviceId
@@ -62,7 +62,7 @@ public class AccountServerManager {
     /**
      * API for requesting user account and getting session code for registered
      * user.
-     * 
+     *
      * @param userId
      *            user identifier
      * @return String - session code for registered user
@@ -86,7 +86,7 @@ public class AccountServerManager {
     /**
      * API for requesting user identifier corresponding with authorization
      * information.
-     * 
+     *
      * @param authCode
      *            authorization code
      * @param authServer
@@ -105,7 +105,7 @@ public class AccountServerManager {
 
     /**
      * API for requesting user identifier corresponding with session code.
-     * 
+     *
      * @param sessionCode
      *            session code
      * @return String - user identifier
@@ -123,14 +123,14 @@ public class AccountServerManager {
 
     /**
      * API for getting devices corresponding with user identifier.
-     * 
+     *
      * @param userId
      *            user identifier
      * @return ArrayList<String> - list of devices
      */
     public ArrayList<String> requestAccountDevices(String userId) {
 
-        Logger.d("userId= " + userId);
+        Log.d("userId= " + userId);
 
         ArrayList<String> deviceList = AccountDBManager.getInstance()
                 .getDevices(userId);
index b86cc8b..6750b56 100644 (file)
@@ -28,7 +28,7 @@ import java.util.Date;
 
 import org.bson.Document;
 import org.iotivity.cloud.accountserver.Constants;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 import com.mongodb.MongoClient;
 import com.mongodb.client.MongoCollection;
@@ -48,7 +48,7 @@ public class MongoDB {
 
     /**
      * API creating MongoClient and initializing MongoDatabase
-     * 
+     *
      * @param dbname
      *            database name to create MongoDatabase
      * @throws Exception
@@ -62,7 +62,7 @@ public class MongoDB {
 
     /**
      * API creating collection
-     * 
+     *
      * @param tableName
      *            collection name
      */
@@ -73,7 +73,7 @@ public class MongoDB {
 
     /**
      * API deleting collection
-     * 
+     *
      * @param tableName
      *            collection name
      */
@@ -84,7 +84,7 @@ public class MongoDB {
 
     /**
      * API getting database object
-     * 
+     *
      */
     public MongoDatabase getMongoDatabase() {
 
@@ -113,7 +113,7 @@ public class MongoDB {
 
     /**
      * API for inserting device information of user
-     * 
+     *
      * @param UserDevice
      *            device information of user
      */
@@ -140,7 +140,7 @@ public class MongoDB {
     /**
      * API for getting user identifier corresponding with session code from
      * database
-     * 
+     *
      * @param sessionCode
      *            session code
      * @return String - user identifier
@@ -206,7 +206,7 @@ public class MongoDB {
 
     /**
      * API for getting devices corresponding with user identifier from database
-     * 
+     *
      * @param userId
      *            user identifier
      */
@@ -297,7 +297,7 @@ public class MongoDB {
             updateResource = true;
 
         } else {
-            Logger.e("UpdateResource failed!");
+            Log.e("UpdateResource failed!");
         }
 
         return updateResource;
@@ -338,42 +338,42 @@ public class MongoDB {
 
         ArrayList<UserDevice> dlist = readDeviceResources();
         int size = dlist.size();
-        
-        Logger.i("[" + Constants.DEVICE_TABLE + "]Table");
+
+        Log.i("[" + Constants.DEVICE_TABLE + "]Table");
         for (int i = 0; i < size; i++) {
 
             UserDevice item = dlist.get(i);
 
-            Logger.i("[" + i + "]" + item.getUserId() + ", "
+            Log.i("[" + i + "]" + item.getUserId() + ", "
                     + item.getDeviceId());
         }
 
         /*
          * ArrayList<UserSession> slist = readSessionResources(); size =
          * slist.size();
-         * 
-         * Logger.i("*Table: " + Constants.SESSION_TABLE);
-         * 
+         *
+         * Log.i("*Table: " + Constants.SESSION_TABLE);
+         *
          * for (int i = 0; i < size; i++) {
-         * 
+         *
          * UserSession item = slist.get(i);
-         * 
-         * Logger.i("[" + i + "]" + item.getUserId() + ", " +
+         *
+         * Log.i("[" + i + "]" + item.getUserId() + ", " +
          * item.getSessionCode());
-         * 
+         *
          * }
          */
 
         ArrayList<UserToken> tlist = readUserTokenResources();
         size = tlist.size();
 
-        Logger.i("[" + Constants.TOKEN_TABLE + "]Table");
+        Log.i("[" + Constants.TOKEN_TABLE + "]Table");
 
         for (int i = 0; i < size; i++) {
 
             UserToken item = tlist.get(i);
 
-            Logger.i("[" + i + "]" + item.getUserId() + "/"
+            Log.i("[" + i + "]" + item.getUserId() + "/"
                     + item.getAccessToken() + "/" + item.getRefreshToken() + "/"
                     + item.getIssuedTime());
 
@@ -417,7 +417,7 @@ public class MongoDB {
         String refreshToken = doc.getString(Constants.KEY_REFRESH_TOKEN);
         String issuedTime = doc.getString(Constants.KEY_ISSUED_TIME);
 
-        // Logger.d("issuedTime: " + issuedTime);
+        // Log.d("issuedTime: " + issuedTime);
         userToken.setUserToken(userId, accessToken, refreshToken);
         userToken.setIssuedTime(issuedTime);
 
diff --git a/cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Github.jar b/cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Github.jar
deleted file mode 100644 (file)
index c7b8f8a..0000000
Binary files a/cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Github.jar and /dev/null differ
diff --git a/cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Github.java b/cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Github.java
new file mode 100644 (file)
index 0000000..55205f6
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * //******************************************************************
+ * //
+ * // 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.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.cloud.accountserver.oauth;
+
+import java.util.HashMap;
+import org.apache.oltu.oauth2.client.OAuthClient;
+import org.apache.oltu.oauth2.client.URLConnectionClient;
+import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest;
+import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
+import org.apache.oltu.oauth2.client.response.GitHubTokenResponse;
+import org.apache.oltu.oauth2.client.response.OAuthResourceResponse;
+import org.apache.oltu.oauth2.common.OAuth;
+import org.apache.oltu.oauth2.common.OAuthProviderType;
+import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
+import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
+import org.apache.oltu.oauth2.common.message.types.GrantType;
+import org.iotivity.cloud.accountserver.Constants;
+import org.iotivity.cloud.util.JSONUtil;
+import org.iotivity.cloud.util.Log;
+
+/**
+ *
+ * This class provides a sample to make .jar that communicates with OAuth2
+ * provider.
+ *
+ */
+public class Github implements OAuthServer {
+
+    // do not use 'client_id' and 'secret' variables.
+    // should use values that are obtained from github.
+    final static private String client_id    = "ea9c18f540323b0213d0";
+    final static private String secret       = "4bc0cd9fe21269507eb8eba3a32664a0f598dbc9";
+    final static private String resource_url = "https://api.github.com/user";
+
+    @Override
+    public HashMap<String, String> requestAccessToken(String authCode,
+            String authServerUrl) {
+
+        HashMap<String, String> authServerInfo = new HashMap<String, String>();
+
+        try {
+
+            OAuthClientRequest request = OAuthClientRequest
+                    .tokenProvider(OAuthProviderType.GITHUB)
+                    .setGrantType(GrantType.AUTHORIZATION_CODE)
+                    .setClientId(client_id).setClientSecret(secret)
+                    .setCode(authCode).buildBodyMessage();
+
+            OAuthClient oAuthClient = new OAuthClient(
+                    new URLConnectionClient());
+            GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(request,
+                    GitHubTokenResponse.class);
+
+            authServerInfo.put(Constants.KEY_ACCESS_TOKEN_GH,
+                    oAuthResponse.getAccessToken());
+
+        } catch (OAuthSystemException | OAuthProblemException e) {
+            authServerInfo.put(Constants.ERROR_MESSAGE, e.getMessage());
+        }
+
+        return authServerInfo;
+    }
+
+    @Override
+    public HashMap<String, String> requestGetUserInfo(String accessToken,
+            String apiServerUrl) {
+
+        HashMap<String, String> authServerInfo = new HashMap<String, String>();
+
+        String userInfo = null;
+
+        if (accessToken == null) {
+            Log.w("accessToken is null!");
+            return null;
+        }
+
+        try {
+
+            OAuthClientRequest request = new OAuthBearerClientRequest(
+                    resource_url).setAccessToken(accessToken)
+                            .buildQueryMessage();
+
+            OAuthClient oAuthClient = new OAuthClient(
+                    new URLConnectionClient());
+            OAuthResourceResponse resourceResponse = oAuthClient.resource(
+                    request, OAuth.HttpMethod.GET, OAuthResourceResponse.class);
+
+            userInfo = resourceResponse.getBody();
+            Log.d("userInfo: " + userInfo);
+
+        } catch (OAuthSystemException | OAuthProblemException e) {
+            authServerInfo.put(Constants.ERROR_MESSAGE, e.getMessage());
+        }
+
+        String userIdKey = "login";
+        JSONUtil<HashMap<String, String>> util = new JSONUtil<HashMap<String, String>>();
+        HashMap<String, String> parsedData = util.parseJSON(userInfo,
+                HashMap.class);
+        String userId = parsedData.get(userIdKey);
+        authServerInfo.put(Constants.KEY_USER_ID, userId);
+
+        return authServerInfo;
+    }
+}
index 4f4977b..ee222ee 100644 (file)
@@ -29,7 +29,7 @@ import java.net.URLClassLoader;
 import java.util.HashMap;
 
 import org.iotivity.cloud.accountserver.Constants;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 /**
  *
@@ -53,7 +53,7 @@ public class OAuthServerFactory {
                     .invoke(authServerObj, authCode, authServerUrl);
             String errorMessage = authServerInfo.get(Constants.ERROR_MESSAGE);
             if (errorMessage != null) {
-                Logger.d("Exception Error Message from Auth Server : "
+                Log.d("Exception Error Message from Auth Server : "
                         + errorMessage);
             } else {
                 accessToken = authServerInfo.get(Constants.KEY_ACCESS_TOKEN_GH);
@@ -76,7 +76,7 @@ public class OAuthServerFactory {
                     .invoke(authServerObj, accessToken, apiServerUrl);
             String errorMessage = authServerInfo.get(Constants.ERROR_MESSAGE);
             if (errorMessage != null) {
-                Logger.d("Exception Error Message from Auth Server : "
+                Log.d("Exception Error Message from Auth Server : "
                         + errorMessage);
             } else {
                 userId = authServerInfo.get(Constants.KEY_USER_ID);
@@ -106,7 +106,7 @@ public class OAuthServerFactory {
         try {
             URL urls = new URL("jar:" + jarFile.toURI() + "!/");
 
-            Logger.d("urls: " + urls.toString());
+            Log.d("urls: " + urls.toString());
 
             classLoader = new URLClassLoader(new URL[] { urls });
             Class<?> gitHubClass = classLoader
index 88d7846..3218993 100644 (file)
@@ -40,7 +40,7 @@ import org.iotivity.cloud.base.protocols.enums.ContentFormat;
 import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
 import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 /**
  *
@@ -100,7 +100,7 @@ public class AccountResource extends Resource {
         String authProvider = payloadData.get(Constants.REQ_AUTH_PROVIDER)
                 .toString();
 
-        Logger.d("authCode: " + authCode);
+        Log.d("authCode: " + authCode);
 
         @SuppressWarnings("unchecked")
         HashMap<String, String> options = (HashMap<String, String>) payloadData
index dcea465..4c4682a 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.oltu.oauth2.as.issuer.MD5Generator;
 import org.apache.oltu.oauth2.as.issuer.OAuthIssuer;
 import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
 import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class TokenGenerator {
 
@@ -38,7 +38,7 @@ public class TokenGenerator {
         try {
 
             accessToken = oauthIssuerImpl.accessToken();
-            Logger.d("accessToken : " + accessToken);
+            Log.d("accessToken : " + accessToken);
 
         } catch (OAuthSystemException e) {
 
@@ -57,7 +57,7 @@ public class TokenGenerator {
         try {
 
             refreshToken = oauthIssuerImpl.refreshToken();
-            Logger.d("refreshToken : " + refreshToken);
+            Log.d("refreshToken : " + refreshToken);
 
         } catch (OAuthSystemException e) {
 
index 3a1676b..50d2421 100644 (file)
@@ -22,7 +22,7 @@
 package org.iotivity.cloud.accountserver.token;
 
 import org.iotivity.cloud.accountserver.db.AccountDBManager;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class TokenManager {
 
@@ -70,7 +70,7 @@ public class TokenManager {
         verifyRefreshToken = tokenValidator.verifyRefreshToken(token);
 
         if (!verifyRefreshToken) {
-            Logger.w("RefreshToken is not existed!");
+            Log.w("RefreshToken is not existed!");
             return null;
         }
 
index fcc12f7..e4bd704 100644 (file)
@@ -27,7 +27,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import org.iotivity.cloud.accountserver.db.AccountDBManager;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class TokenValidator {
 
@@ -38,14 +38,14 @@ public class TokenValidator {
         // check token existed
         valid = AccountDBManager.getInstance().hasAccessToken(token);
         if (!valid) {
-            Logger.w("accessToken is not existed..");
+            Log.w("accessToken is not existed..");
             return false;
         }
 
         // check token expired
         if (getElaspedSeconds(token) > TokenPolicy.EXPIRES_IN) {
 
-            Logger.w("accessToken is expired..");
+            Log.w("accessToken is expired..");
             return false;
         }
 
@@ -68,10 +68,10 @@ public class TokenValidator {
 
         long difference = currentTime.getTime() - issuedTime.getTime();
         long elaspedSeconds = difference / 1000;
-        // Logger.d("currentTime : " + currentTime.getTime());
-        // Logger.d("issuedTime : " + issuedTime.getTime());
-        // Logger.d("difference : " + difference);
-        Logger.d("accessToken elasped time: " + elaspedSeconds + "s");
+        // Log.d("currentTime : " + currentTime.getTime());
+        // Log.d("issuedTime : " + issuedTime.getTime());
+        // Log.d("difference : " + difference);
+        Log.d("accessToken elasped time: " + elaspedSeconds + "s");
 
         return elaspedSeconds;
     }
@@ -86,7 +86,7 @@ public class TokenValidator {
         // check token existed
         valid = AccountDBManager.getInstance().hasRefreshToken(token);
         if (!valid)
-            Logger.w("refreshToken is not existed..");
+            Log.w("refreshToken is not existed..");
 
         return valid;
     }
index cea7878..1f55c98 100644 (file)
@@ -35,20 +35,17 @@ import org.iotivity.cloud.ciserver.resources.proxy.MessageQueue;
 import org.iotivity.cloud.ciserver.resources.proxy.ResourceDirectory;
 import org.iotivity.cloud.ciserver.resources.proxy.ResourceFind;
 import org.iotivity.cloud.ciserver.resources.proxy.ResourcePresence;
-import org.iotivity.cloud.util.ErrorLogger;
-import org.iotivity.cloud.util.FileLogger;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class CloudInterfaceServer {
 
     public static void main(String[] args) throws Exception {
-
-        System.setOut(FileLogger.createLoggingProxy(System.out));
+        Log.Init();
 
         System.out.println("-----CI SERVER-------");
 
         if (args.length != 8) {
-            Logger.e(
+            Log.e(
                     "coap server port and RDServer_Address port AccountServer_Address Port MQBroker_Address Port and TLS mode required\n"
                             + "ex) 5683 127.0.0.1 5684 127.0.0.1 5685 127.0.0.1 5686 0\n");
             return;
@@ -66,8 +63,6 @@ public class CloudInterfaceServer {
                 new InetSocketAddress(args[5], Integer.parseInt(args[6])),
                 tlsMode);
 
-        ErrorLogger.Init();
-
         DeviceServerSystem deviceServer = new DeviceServerSystem();
 
         Account acHandler = new Account();
index 82d7ba7..c6e9d4b 100644 (file)
@@ -43,7 +43,7 @@ import org.iotivity.cloud.base.server.CoapServer;
 import org.iotivity.cloud.base.server.HttpServer;
 import org.iotivity.cloud.base.server.Server;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.ErrorLogger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.ChannelDuplexHandler;
 import io.netty.channel.ChannelHandler.Sharable;
@@ -103,7 +103,7 @@ public class DeviceServerSystem extends ServerSystem {
                             : ResponseStatus.BAD_REQUEST;
                     ctx.channel().writeAndFlush(MessageBuilder
                             .createResponse((CoapRequest) msg, responseStatus));
-                    ErrorLogger.write(ctx.channel(), t);
+                    Log.f(ctx.channel(), t);
                 }
             }
 
@@ -208,7 +208,7 @@ public class DeviceServerSystem extends ServerSystem {
                 ctx.writeAndFlush(msg);
 
             } catch (Throwable t) {
-                ErrorLogger.write(ctx.channel(), t);
+                Log.f(ctx.channel(), t);
                 ctx.writeAndFlush(msg);
                 ctx.close();
             }
@@ -270,7 +270,7 @@ public class DeviceServerSystem extends ServerSystem {
                         : ResponseStatus.UNAUTHORIZED;
                 ctx.channel().writeAndFlush(MessageBuilder
                         .createResponse((CoapRequest) msg, responseStatus));
-                ErrorLogger.write(ctx.channel(), t);
+                Log.f(ctx.channel(), t);
             }
         }
     }
index 84b8675..332fc28 100644 (file)
@@ -36,6 +36,7 @@ import org.iotivity.cloud.base.exception.ServerException.PreconditionFailedExcep
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
+import org.iotivity.cloud.base.protocols.coap.CoapResponse;
 import org.iotivity.cloud.base.protocols.enums.ContentFormat;
 import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
 import org.iotivity.cloud.base.resource.Resource;
@@ -92,6 +93,20 @@ public class DiResource extends Resource {
         return uriPath.toString();
     }
 
+    private IResponse convertReponseUri(IResponse response, String di) {
+
+        String convertedUri = new String();
+
+        CoapResponse coapResponse = (CoapResponse) response;
+
+        if (coapResponse.getUriPath().isEmpty() == false) {
+            convertedUri = "/di/" + di + "/" + coapResponse.getUriPath();
+        }
+
+        return MessageBuilder
+                .modifyResponse(response, convertedUri, null, null);
+    }
+
     class LinkInterfaceHandler implements IResponseEventHandler {
         private Cbor<List<HashMap<String, Object>>> mCbor      = new Cbor<>();
         private String                              mTargetDI  = null;
@@ -117,9 +132,11 @@ public class DiResource extends Resource {
                 convertHref(linkPayload);
             }
 
-            mSrcDevice.sendResponse(MessageBuilder.modifyResponse(response,
-                    ContentFormat.APPLICATION_CBOR, linkPayload != null
-                            ? mCbor.encodingPayloadToCbor(linkPayload) : null));
+            mSrcDevice.sendResponse(MessageBuilder.modifyResponse(
+                    convertReponseUri(response, mTargetDI),
+                    ContentFormat.APPLICATION_CBOR,
+                    linkPayload != null ? mCbor
+                            .encodingPayloadToCbor(linkPayload) : null));
         }
     }
 
@@ -133,12 +150,27 @@ public class DiResource extends Resource {
 
         String deviceId = request.getUriPathSegments().get(1);
 
-        requestChannel.sendRequest(
-                MessageBuilder.modifyRequest(request,
-                        extractTargetUriPath(request), null, null, null),
+        requestChannel.sendRequest(MessageBuilder.modifyRequest(request,
+                extractTargetUriPath(request), null, null, null),
                 new LinkInterfaceHandler(deviceId, srcDevice));
     }
 
+    class DefaultResponseHandler implements IResponseEventHandler {
+        private String mTargetDI  = null;
+        private Device mSrcDevice = null;
+
+        public DefaultResponseHandler(String targetDI, Device srcDevice) {
+            mTargetDI = targetDI;
+            mSrcDevice = srcDevice;
+        }
+
+        @Override
+        public void onResponseReceived(IResponse response) {
+
+            mSrcDevice.sendResponse(convertReponseUri(response, mTargetDI));
+        }
+    }
+
     // This is optional method for packet handling
     @Override
     public void onDefaultRequestReceived(Device srcDevice, IRequest request)
@@ -150,9 +182,11 @@ public class DiResource extends Resource {
             throw new NotFoundException();
         }
 
-        requestChannel.sendRequest(
-                MessageBuilder.modifyRequest(request,
-                        extractTargetUriPath(request), null, null, null),
-                srcDevice);
+        String deviceId = request.getUriPathSegments().get(1);
+
+        requestChannel.sendRequest(MessageBuilder.modifyRequest(request,
+                extractTargetUriPath(request), null, null, null),
+                new DefaultResponseHandler(deviceId, srcDevice));
     }
-}
+
+}
\ No newline at end of file
index a4153f9..0d0ca3c 100644 (file)
@@ -35,7 +35,8 @@ public class MessageQueue extends Resource {
     IRequestChannel mPSServer = null;
 
     public MessageQueue() {
-        super(Arrays.asList(Constants.PREFIX_OIC, Constants.MQ_BROKER_URI));
+        super(Arrays.asList(Constants.PREFIX_WELL_KNOWN, Constants.PREFIX_OCF,
+                Constants.MQ_BROKER_URI));
 
         mPSServer = ConnectorPool.getConnection("mq");
     }
index 23d6318..821a537 100644 (file)
@@ -25,13 +25,8 @@ import org.iotivity.cloud.base.OCFConstants;
 
 public class Constants extends OCFConstants {
 
-    public static final String MQ_TOPIC                = "topic";
-    public static final String MQ_LOCATION             = "location";
     public static final String MQ_TOPICLIST            = "topiclist";
 
-    public static final long   MIN_SEQ_NUM             = 5;
-    public static final long   MAX_SEQ_NUM             = 16777215;
-
     // For Kafka
     public static final int    KAFKA_SESSION_TIMEOUT   = 10000;
     public static final int    KAFKA_CONNECT_TIMEOUT   = 10000;
index 50dda52..79e32b9 100644 (file)
@@ -27,27 +27,23 @@ import java.util.Scanner;
 import org.iotivity.cloud.base.ServerSystem;
 import org.iotivity.cloud.base.server.CoapServer;
 import org.iotivity.cloud.mqserver.resources.MQBrokerResource;
-import org.iotivity.cloud.util.ErrorLogger;
-import org.iotivity.cloud.util.FileLogger;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class MessageQueueServer {
 
     public static void main(String[] args) throws Exception {
-        System.setOut(FileLogger.createLoggingProxy(System.out));
+        Log.Init();
 
         System.out.println("-----MQ SERVER-----");
 
         if (args.length != 6) {
-            Logger.e("coap server port, Kafka_zookeeper_Address port"
+            Log.e("coap server port, Kafka_zookeeper_Address port"
                     + " and Kafka_broker_Address Port and TLS mode required\n"
                     + "ex) 5686 127.0.0.1 2181 127.0.0.1 9092 0\n");
 
             return;
         }
 
-        ErrorLogger.Init();
-
         ServerSystem serverSystem = new ServerSystem();
 
         MQBrokerResource MQBroker = new MQBrokerResource();
index 19ba50a..7947944 100644 (file)
@@ -24,14 +24,14 @@ package org.iotivity.cloud.mqserver;
 import java.util.HashMap;
 
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class MessageQueueUtils {
 
     public static <T> T extractDataFromPayload(byte[] payload, String key) {
 
         if (payload == null || key.isEmpty()) {
-            Logger.e("payload or key is empty");
+            Log.e("payload or key is empty");
             return null;
         }
 
@@ -41,7 +41,7 @@ public class MessageQueueUtils {
         parsedData = cbor.parsePayloadFromCbor(payload, HashMap.class);
 
         if (parsedData == null || parsedData.containsKey(key) == false) {
-            Logger.e("payload doesn't contain " + key + " information");
+            Log.e("payload doesn't contain " + key + " information");
             return null;
         }
 
index 0e876bf..a67f8c1 100644 (file)
@@ -30,7 +30,7 @@ import kafka.utils.ZkUtils;
 import org.I0Itec.zkclient.ZkClient;
 import org.I0Itec.zkclient.ZkConnection;
 import org.iotivity.cloud.mqserver.Constants;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class KafkaCommonWrapper {
 
@@ -49,7 +49,7 @@ public class KafkaCommonWrapper {
 
     public boolean createTopic(String topic) {
 
-        Logger.d("kafka createTopic - " + topic);
+        Log.d("kafka createTopic - " + topic);
 
         topic = topic.replace('/', '.');
 
@@ -66,7 +66,7 @@ public class KafkaCommonWrapper {
 
     public boolean deleteTopic(String topic) {
 
-        Logger.d("kafka deleteTopic - " + topic);
+        Log.d("kafka deleteTopic - " + topic);
 
         topic = topic.replace('/', '.');
 
index 8c151c3..3ca503b 100644 (file)
@@ -52,7 +52,7 @@ import org.I0Itec.zkclient.ZkClient;
 import org.I0Itec.zkclient.ZkConnection;
 import org.iotivity.cloud.mqserver.Constants;
 import org.iotivity.cloud.mqserver.topic.Topic;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class KafkaConsumerWrapper {
 
@@ -95,7 +95,7 @@ public class KafkaConsumerWrapper {
     // TODO exception handling
     public boolean subscribeTopic() {
 
-        Logger.d("kafka subscribeTopic - " + mTopicName);
+        Log.d("kafka subscribeTopic - " + mTopicName);
 
         if (mConsumerStarted == true) {
             return true;
@@ -128,7 +128,7 @@ public class KafkaConsumerWrapper {
 
         for (final KafkaStream<byte[], byte[]> stream : streams) {
 
-            Logger.d("kafka subscribe complete");
+            Log.d("kafka subscribe complete");
 
             mConsumerExecutor.execute(new Runnable() {
 
@@ -150,7 +150,7 @@ public class KafkaConsumerWrapper {
 
     public boolean unsubscribeTopic() {
 
-        Logger.d("kafka unsubscribeTopic - " + mTopicName);
+        Log.d("kafka unsubscribeTopic - " + mTopicName);
 
         // remove consumer group info in zookeeper
         List<String> subscribers = mZkClient.getChildren(ZkUtils
@@ -168,15 +168,25 @@ public class KafkaConsumerWrapper {
         return true;
     }
 
+    public void closeConnection() {
+
+        if (mConsumerStarted == true) {
+            unsubscribeTopic();
+        }
+
+        mZkUtils.close();
+        mZkClient.close();
+    }
+
     public ArrayList<byte[]> getMessages() {
 
-        Logger.d("kafka get all messages - " + mTopicName);
+        Log.d("kafka get all messages - " + mTopicName);
 
         String brokerHost = mBroker.substring(0, mBroker.indexOf(':'));
         int brokerPort = Integer.parseInt(mBroker.substring(mBroker
                 .indexOf(':') + 1));
 
-        Logger.d("host " + brokerHost + ", port " + brokerPort);
+        Log.d("host " + brokerHost + ", port " + brokerPort);
 
         // TODO check options - Timeout: Int, bufferSize: Int
         SimpleConsumer simpleConsumer = new SimpleConsumer(brokerHost,
@@ -193,7 +203,7 @@ public class KafkaConsumerWrapper {
 
         if (fetchResponse == null || fetchResponse.hasError()) {
 
-            Logger.e("Error fetching data from the Broker");
+            Log.e("Error fetching data from the Broker");
             return null;
         }
 
@@ -207,7 +217,7 @@ public class KafkaConsumerWrapper {
 
                 long currentOffset = messageAndOffset.offset();
                 if (currentOffset < lastOffset) {
-                    Logger.e("Found an old offset: " + currentOffset
+                    Log.e("Found an old offset: " + currentOffset
                             + " Expecting: " + lastOffset);
                     continue;
                 }
@@ -224,7 +234,7 @@ public class KafkaConsumerWrapper {
 
         simpleConsumer.close();
 
-        Logger.d("kafka get all messages complete");
+        Log.d("kafka get all messages complete");
 
         return initialData;
     }
@@ -259,7 +269,7 @@ public class KafkaConsumerWrapper {
         OffsetResponse response = consumer.getOffsetsBefore(request);
 
         if (response == null || response.hasError()) {
-            Logger.e("Error fetching data Offset Data the Broker");
+            Log.e("Error fetching data Offset Data the Broker");
             return 0;
         }
 
index 903f046..9b3f2c1 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Properties;
 import org.apache.kafka.clients.producer.KafkaProducer;
 import org.apache.kafka.clients.producer.Producer;
 import org.apache.kafka.clients.producer.ProducerRecord;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class KafkaProducerWrapper {
 
@@ -47,7 +47,7 @@ public class KafkaProducerWrapper {
     // TODO handle exception
     public boolean publishMessage(byte[] message) {
 
-        Logger.d("kafka publishMessage - " + mTopicName);
+        Log.d("kafka publishMessage - " + mTopicName);
 
         ProducerRecord<byte[], byte[]> record = new ProducerRecord<>(
                 mTopicName, message);
@@ -58,6 +58,11 @@ public class KafkaProducerWrapper {
         return true;
     }
 
+    public void closeConnection() {
+
+        mProducer.close();
+    }
+
     private Properties buildPropertiesForPublish() {
 
         // TODO check property settings
index a137f75..4109b3a 100644 (file)
@@ -44,10 +44,8 @@ public class MQBrokerResource extends Resource {
     private TopicManager mTopicManager = new TopicManager();
 
     public MQBrokerResource() {
-        super(Arrays.asList(Constants.PREFIX_OIC, Constants.MQ_BROKER_URI));
-
-        // addQueryHandler(Arrays.asList("if=" + Constants.INTERFACE_DEFAULT),
-        // this::onDefaultInterfaceReceived);
+        super(Arrays.asList(Constants.PREFIX_WELL_KNOWN, Constants.PREFIX_OCF,
+                Constants.MQ_BROKER_URI));
     }
 
     public void setKafkaInformation(String zookeeper, String broker) {
@@ -82,8 +80,7 @@ public class MQBrokerResource extends Resource {
     private IResponse handleGetRequest(Device srcDevice, IRequest request) {
 
         // DISCOVER
-        if (request.getUriPathSegments().size() == getUriPathSegments()
-                .size()) {
+        if (request.getUriPathSegments().size() == getUriPathSegments().size()) {
             return discoverTopic(request);
         }
 
@@ -105,16 +102,22 @@ public class MQBrokerResource extends Resource {
                 ResponseStatus.BAD_REQUEST);
     }
 
-    // PUBLISH
+    // CREATE topic
     private IResponse handlePutRequest(IRequest request) {
 
-        return publishMessage(request);
+        if (request.getUriPathSegments().size() == getUriPathSegments().size()) {
+
+            return MessageBuilder.createResponse(request,
+                    ResponseStatus.BAD_REQUEST);
+        }
+
+        return createTopic(request);
     }
 
-    // CREATE topic
+    // PUBLISH
     private IResponse handlePostRequest(IRequest request) {
 
-        return createTopic(request);
+        return publishMessage(request);
     }
 
     // REMOVE topic
@@ -125,15 +128,15 @@ public class MQBrokerResource extends Resource {
 
     private IResponse createTopic(IRequest request) {
 
-        String uriPath = request.getUriPath();
-
         // main topic creation request
-        if (request.getUriPathSegments().size() == getUriPathSegments()
-                .size()) {
+        if (request.getUriPathSegments().size() == getUriPathSegments().size() + 1) {
             return createMainTopic(request);
         }
 
         // subtopic creation request
+        String uriPath = request.getUriPath();
+        uriPath = uriPath.substring(0, uriPath.lastIndexOf('/'));
+
         Topic targetTopic = mTopicManager.getTopic(uriPath);
 
         if (targetTopic == null) {
@@ -146,12 +149,6 @@ public class MQBrokerResource extends Resource {
 
     private IResponse removeTopic(IRequest request) {
 
-        String uriPath = request.getUriPath();
-
-        String parentName = uriPath.substring(0, uriPath.lastIndexOf('/'));
-        String targetName = request.getUriPathSegments()
-                .get(request.getUriPathSegments().size() - 1);
-
         // main topic removal request
         if (request.getUriPathSegments().size() - 1 == getUriPathSegments()
                 .size()) {
@@ -159,6 +156,12 @@ public class MQBrokerResource extends Resource {
         }
 
         // subtopic removal request
+        String uriPath = request.getUriPath();
+
+        String parentName = uriPath.substring(0, uriPath.lastIndexOf('/'));
+        String targetName = request.getUriPathSegments().get(
+                request.getUriPathSegments().size() - 1);
+
         Topic parentTopic = mTopicManager.getTopic(parentName);
 
         if (parentTopic == null) {
@@ -233,14 +236,14 @@ public class MQBrokerResource extends Resource {
         }
 
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
-                ContentFormat.APPLICATION_CBOR, MessageQueueUtils
-                        .buildPayload(Constants.MQ_TOPICLIST, topicList));
+                ContentFormat.APPLICATION_CBOR, MessageQueueUtils.buildPayload(
+                        Constants.MQ_TOPICLIST, topicList));
     }
 
     private IResponse createMainTopic(IRequest request) {
 
-        String topicName = MessageQueueUtils.extractDataFromPayload(
-                request.getPayload(), Constants.MQ_TOPIC);
+        String topicName = request.getUriPathSegments().get(
+                request.getUriPathSegments().size() - 1);
 
         String type = new String();
 
@@ -253,8 +256,17 @@ public class MQBrokerResource extends Resource {
                     ResponseStatus.BAD_REQUEST);
         }
 
-        topicName = "/" + Constants.PREFIX_OIC + "/" + Constants.MQ_BROKER_URI
-                + "/" + topicName;
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append("/");
+
+        for (String uri : getUriPathSegments()) {
+            stringBuilder.append(uri);
+            stringBuilder.append("/");
+        }
+
+        stringBuilder.append(topicName);
+
+        topicName = stringBuilder.toString();
 
         if (mTopicManager.getTopic(topicName) != null) {
             // Topic already exists
@@ -269,9 +281,7 @@ public class MQBrokerResource extends Resource {
                     ResponseStatus.INTERNAL_SERVER_ERROR);
         }
 
-        return MessageBuilder.createResponse(request, ResponseStatus.CREATED,
-                ContentFormat.APPLICATION_CBOR, MessageQueueUtils.buildPayload(
-                        Constants.MQ_LOCATION, newTopic.getName()));
+        return MessageBuilder.createResponse(request, ResponseStatus.CREATED);
     }
 
     private IResponse removeMainTopic(IRequest request) {
@@ -280,13 +290,14 @@ public class MQBrokerResource extends Resource {
 
         Topic targetTopic = mTopicManager.getTopic(topicName);
 
-        // TODO check error
         if (targetTopic == null) {
             // Topic doesn't exist
             return MessageBuilder.createResponse(request,
                     ResponseStatus.BAD_REQUEST);
         }
 
+        targetTopic.cleanup();
+
         if (mTopicManager.removeTopic(targetTopic) == false) {
             return MessageBuilder.createResponse(request,
                     ResponseStatus.INTERNAL_SERVER_ERROR);
index 3b004c1..2e5016e 100644 (file)
@@ -30,8 +30,6 @@ import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
 import org.iotivity.cloud.base.protocols.enums.ContentFormat;
 import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
-import org.iotivity.cloud.mqserver.Constants;
-import org.iotivity.cloud.mqserver.MessageQueueUtils;
 import org.iotivity.cloud.mqserver.kafka.KafkaConsumerWrapper;
 import org.iotivity.cloud.mqserver.kafka.KafkaProducerWrapper;
 
@@ -87,8 +85,8 @@ public class Topic {
 
     public IResponse handleCreateSubtopic(IRequest request) {
 
-        String newTopicName = MessageQueueUtils.extractDataFromPayload(
-                request.getPayload(), Constants.MQ_TOPIC);
+        String newTopicName = request.getUriPathSegments().get(
+                request.getUriPathSegments().size() - 1);
 
         String newTopicType = new String();
 
@@ -117,26 +115,23 @@ public class Topic {
 
         mSubtopics.put(newTopicName, newTopic);
 
-        return MessageBuilder.createResponse(
-                request,
-                ResponseStatus.CREATED,
-                ContentFormat.APPLICATION_CBOR,
-                MessageQueueUtils.buildPayload(Constants.MQ_LOCATION,
-                        newTopic.getName()));
+        return MessageBuilder.createResponse(request, ResponseStatus.CREATED);
     }
 
     public IResponse handleRemoveSubtopic(IRequest request, String topicName) {
 
         Topic targetTopic = getSubtopic(topicName);
 
-        // TODO check error
         if (targetTopic == null) {
             // topic doesn't exist
             return MessageBuilder.createResponse(request,
                     ResponseStatus.BAD_REQUEST);
         }
 
+        targetTopic.cleanup();
+
         if (mTopicManager.removeTopic(targetTopic) == false) {
+
             return MessageBuilder.createResponse(request,
                     ResponseStatus.INTERNAL_SERVER_ERROR);
         }
@@ -224,6 +219,12 @@ public class Topic {
                 ContentFormat.APPLICATION_CBOR, mLatestData);
     }
 
+    public void cleanup() {
+
+        mKafkaProducerOperator.closeConnection();
+        mKafkaConsumerOperator.closeConnection();
+    }
+
     // callback from Kafka Consumer
     public void onMessagePublished(byte[] message) {
 
@@ -232,7 +233,6 @@ public class Topic {
         notifyPublishedMessage();
     }
 
-    // TODO check
     private Topic getSubtopic(String topicName) {
 
         if (mSubtopics.containsKey(topicName) == false) {
@@ -245,6 +245,7 @@ public class Topic {
     private void notifyPublishedMessage() {
         synchronized (mSubscribers) {
             for (TopicSubscriber subscriber : mSubscribers.values()) {
+
                 subscriber.mSubscriber.sendResponse(MessageBuilder
                         .createResponse(subscriber.mRequest,
                                 ResponseStatus.CONTENT,
index 24dbb9a..16fccc3 100644 (file)
@@ -30,25 +30,21 @@ import org.iotivity.cloud.rdserver.resources.directory.rd.ResourceDirectoryResou
 import org.iotivity.cloud.rdserver.resources.directory.res.DiscoveryResource;
 import org.iotivity.cloud.rdserver.resources.presence.device.DevicePresenceResource;
 import org.iotivity.cloud.rdserver.resources.presence.resource.ResPresenceResource;
-import org.iotivity.cloud.util.ErrorLogger;
-import org.iotivity.cloud.util.FileLogger;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class ResourceDirectoryServer {
 
     public static void main(String[] args) throws Exception {
-        System.setOut(FileLogger.createLoggingProxy(System.out));
+        Log.Init();
 
         System.out.println("-----RD SERVER-----");
 
         if (args.length != 2) {
-            Logger.e("coap server port and TLS mode required\n"
+            Log.e("coap server port and TLS mode required\n"
                     + "ex) 5684 0\n");
             return;
         }
 
-        ErrorLogger.Init();
-
         ServerSystem serverSystem = new ServerSystem();
 
         serverSystem.addResource(new ResourceDirectoryResource());
index fbc5b50..0f5c2de 100644 (file)
@@ -42,7 +42,7 @@ import org.iotivity.cloud.rdserver.resources.presence.ResPresenceManager;
 import org.iotivity.cloud.rdserver.resources.presence.resource.ResPresencePayload;
 import org.iotivity.cloud.rdserver.util.TypeCastingManager;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class ResourceDirectoryResource extends Resource {
 
@@ -141,7 +141,7 @@ public class ResourceDirectoryResource extends Resource {
         }
         responseMap.put(Constants.LINKS, links);
 
-        Logger.i("publish response :" + responseMap.toString());
+        Log.i("publish response :" + responseMap.toString());
 
         byte[] encodedPaylod = mCbor.encodingPayloadToCbor(responseMap);
 
@@ -157,7 +157,7 @@ public class ResourceDirectoryResource extends Resource {
         if (payloadData == null) {
             throw new BadRequestException("payload is null");
         } else {
-            Logger.i("publish payload: " + payloadData.toString());
+            Log.i("publish payload: " + payloadData.toString());
         }
 
         PublishTags tags = new PublishTags();
index b99793c..1236c43 100644 (file)
@@ -40,7 +40,7 @@ import org.iotivity.cloud.rdserver.Constants;
 import org.iotivity.cloud.rdserver.db.DBManager;
 import org.iotivity.cloud.rdserver.util.TypeCastingManager;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class DiscoveryResource extends Resource {
     private Cbor<HashMap<Object, Object>>      mCbor                     = new Cbor<>();
@@ -167,7 +167,7 @@ public class DiscoveryResource extends Resource {
             responseMapList.add(responseSegment);
         }
 
-        Logger.i("discover payload :" + responseMapList.toString());
+        Log.i("discover payload :" + responseMapList.toString());
 
         byte[] encodedPaylod = mCbor.encodingPayloadToCbor(responseMapList);
 
index 4e4d669..6ed867d 100644 (file)
@@ -40,7 +40,7 @@ import org.iotivity.cloud.rdserver.Constants;
 import org.iotivity.cloud.rdserver.db.DBManager;
 import org.iotivity.cloud.rdserver.util.TypeCastingManager;
 import org.iotivity.cloud.util.Cbor;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 public class DevicePresenceResource extends Resource {
 
@@ -128,7 +128,7 @@ public class DevicePresenceResource extends Resource {
             getPayload.add(payloadSegment);
         }
 
-        Logger.i("Get observe response" + getPayload.toString());
+        Log.i("Get observe response" + getPayload.toString());
 
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
                 ContentFormat.APPLICATION_CBOR,
@@ -161,7 +161,7 @@ public class DevicePresenceResource extends Resource {
                     DBManager.getInstance().findDeviceState(deviceId));
             getPayload.add(payloadSegment);
         }
-        Logger.i("Get observe response" + getPayload.toString());
+        Log.i("Get observe response" + getPayload.toString());
 
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
                 ContentFormat.APPLICATION_CBOR,
index 80273b4..da32793 100644 (file)
                <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
-               <version>2.7.4</version>
+               <version>2.4.0</version>
                </dependency>
                <dependency>
                        <groupId>com.fasterxml.jackson.dataformat</groupId>
                        <artifactId>jackson-dataformat-cbor</artifactId>
-                       <version>2.7.4</version>
+                       <version>2.4.0</version>
                </dependency>
                <dependency>
             <groupId>log4j</groupId>
index 2c14d69..5ee5a06 100644 (file)
@@ -40,7 +40,7 @@ import org.iotivity.cloud.base.resource.ResourceManager;
 import org.iotivity.cloud.base.server.CoapServer;
 import org.iotivity.cloud.base.server.HttpServer;
 import org.iotivity.cloud.base.server.Server;
-import org.iotivity.cloud.util.ErrorLogger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.ChannelDuplexHandler;
 import io.netty.channel.ChannelHandler.Sharable;
@@ -95,11 +95,11 @@ public class ServerSystem extends ResourceManager {
             } catch (ServerException e) {
                 ctx.channel().writeAndFlush(MessageBuilder.createResponse(msg,
                         e.getErrorResponse()));
-                ErrorLogger.write(ctx.channel(), e);
+                Log.f(ctx.channel(), e);
             } catch (ClientException e) {
-                ErrorLogger.write(ctx.channel(), e);
+                Log.f(ctx.channel(), e);
             } catch (Throwable t) {
-                ErrorLogger.write(ctx.channel(), t);
+                Log.f(ctx.channel(), t);
                 if (msg instanceof CoapRequest) {
                     ctx.channel().writeAndFlush(MessageBuilder.createResponse(
                             msg, ResponseStatus.INTERNAL_SERVER_ERROR));
index dc3d47b..7b1d49e 100644 (file)
@@ -33,7 +33,7 @@ import org.iotivity.cloud.base.protocols.coap.CoapRequest;
 import org.iotivity.cloud.base.protocols.coap.CoapResponse;
 import org.iotivity.cloud.base.protocols.enums.Observe;
 import org.iotivity.cloud.util.Bytes;
-import org.iotivity.cloud.util.ErrorLogger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.Channel;
 
@@ -107,7 +107,7 @@ public class CoapClient implements IRequestChannel, IResponseEventHandler {
             mChannel.writeAndFlush(request);
 
         } catch (Exception e) {
-            ErrorLogger.write(mChannel, e);
+            Log.f(mChannel, e);
         }
     }
 
index 554f52d..134afa5 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Date;
 
 import org.iotivity.cloud.base.connector.CoapClient;
 import org.iotivity.cloud.base.protocols.IResponse;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.ChannelHandlerContext;
 
@@ -88,7 +88,7 @@ public class CoapDevice extends Device {
 
         if (remainTime < 0) {
 
-            Logger.w("accessToken is expired..");
+            Log.w("accessToken is expired..");
             return true;
         }
 
index c68954a..5a703b7 100644 (file)
@@ -44,6 +44,7 @@ public class MessageBuilder {
         if (request instanceof CoapRequest) {
             CoapRequest coapRequest = (CoapRequest) request;
             CoapResponse coapResponse = new CoapResponse(responseStatus);
+            coapResponse.setUriPath(coapRequest.getUriPath());
             coapResponse.setToken(coapRequest.getToken());
             if (payload != null) {
                 coapResponse.setContentFormat(format);
@@ -117,8 +118,17 @@ public class MessageBuilder {
     public static IResponse modifyResponse(IResponse orgResponse,
             ContentFormat contentFormat, byte[] payload) {
 
+        return modifyResponse(orgResponse, null, contentFormat, payload);
+    }
+
+    public static IResponse modifyResponse(IResponse orgResponse,
+            String uriPath, ContentFormat contentFormat, byte[] payload) {
+
         CoapResponse coapResponse = (CoapResponse) orgResponse;
 
+        if (uriPath != null) {
+            coapResponse.setUriPath(uriPath);
+        }
         if (payload != null) {
             coapResponse.setContentFormat(contentFormat);
             coapResponse.setPayload(payload);
index 7dbcf36..c6343f0 100644 (file)
@@ -21,7 +21,7 @@
  */
 package org.iotivity.cloud.base.protocols.coap;
 
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.channel.ChannelDuplexHandler;
 import io.netty.channel.ChannelHandler.Sharable;
@@ -41,7 +41,7 @@ public class CoapLogHandler extends ChannelDuplexHandler {
 
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        Logger.v(ctx.channel().id().asLongText().substring(26)
+        Log.v(ctx.channel().id().asLongText().substring(26)
                 + " Connected, Address: "
                 + ctx.channel().remoteAddress().toString());
 
@@ -51,7 +51,7 @@ public class CoapLogHandler extends ChannelDuplexHandler {
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         ctx.fireChannelInactive();
-        Logger.v(ctx.channel().id().asLongText().substring(26)
+        Log.v(ctx.channel().id().asLongText().substring(26)
                 + " Disconnected, Address: "
                 + ctx.channel().remoteAddress().toString());
     }
@@ -72,7 +72,7 @@ public class CoapLogHandler extends ChannelDuplexHandler {
                     (CoapResponse) msg);
         }
 
-        Logger.v(log);
+        Log.v(log);
 
         ctx.writeAndFlush(msg);
     }
@@ -93,7 +93,7 @@ public class CoapLogHandler extends ChannelDuplexHandler {
                     (CoapResponse) msg);
         }
 
-        Logger.v(log);
+        Log.v(log);
 
         ctx.fireChannelRead(msg);
     }
index 4f4ea70..9c1e6a4 100644 (file)
@@ -30,7 +30,7 @@ import java.util.List;
 import javax.net.ssl.SSLException;
 
 import org.iotivity.cloud.base.OCFConstants;
-import org.iotivity.cloud.util.Logger;
+import org.iotivity.cloud.util.Log;
 
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.ChannelHandler;
@@ -91,7 +91,7 @@ public abstract class Server {
             throws CertificateException, SSLException, InterruptedException {
 
         try {
-            Logger.i("[CoapServer]startServer with tlsMode! mode= " + tlsMode);
+            Log.i("[CoapServer]startServer with tlsMode! mode= " + tlsMode);
 
             if (tlsMode == true) {
 
index 94c8e8b..6957f78 100644 (file)
@@ -85,7 +85,7 @@ public class Cbor<T> {
                 throw new PreconditionFailedException("deviceId is null");
             }
 
-            Logger.i("deviceId : " + deviceId);
+            Log.i("deviceId : " + deviceId);
 
             return deviceId;
         }
diff --git a/cloud/stack/src/main/java/org/iotivity/cloud/util/ErrorLogger.java b/cloud/stack/src/main/java/org/iotivity/cloud/util/ErrorLogger.java
deleted file mode 100644 (file)
index af173e4..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.iotivity.cloud.util;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-
-import io.netty.channel.Channel;
-
-public class ErrorLogger extends Logger {
-
-    private static FileOutputStream fos = null;
-    private static PrintStream      ps  = null;
-
-    static public void Init() throws FileNotFoundException {
-        File dir = new File("..//errLog//");
-        if (!dir.isDirectory()) {
-            System.out.println("Is Not Folder");
-            dir.mkdirs();
-        }
-        fos = new FileOutputStream("../errLog/[" + getDate() + "] error.log",
-                true);
-        ps = new PrintStream(fos);
-    }
-
-    static public void write(Channel channel, Throwable t) {
-        String log = channel.id().asLongText().substring(26) + " "
-                + t.getMessage();
-        ps.println(getTime() + " " + log);
-        t.printStackTrace(ps);
-        Logger.v(log);
-    }
-
-    protected static String getDate() {
-        Calendar calendar = Calendar.getInstance();
-        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-        return dateFormat.format(calendar.getTime());
-    }
-}
diff --git a/cloud/stack/src/main/java/org/iotivity/cloud/util/FileLogger.java b/cloud/stack/src/main/java/org/iotivity/cloud/util/FileLogger.java
deleted file mode 100644 (file)
index 2c9a9d4..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * //******************************************************************
- * //
- * // 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.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-package org.iotivity.cloud.util;
-
-import java.io.PrintStream;
-
-import org.apache.log4j.Logger;
-
-public class FileLogger {
-    private final static Logger logger = Logger.getLogger(FileLogger.class);
-
-    public static PrintStream createLoggingProxy(
-            final PrintStream realPrintStream) {
-        // TODO Auto-generated method stub
-        return new PrintStream(realPrintStream) {
-            public void print(final String string) {
-                realPrintStream.print(string);
-                logger.fatal(string);
-            }
-        };
-    }
-
-}
  */
 package org.iotivity.cloud.util;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 
-public class Logger {
+import org.apache.log4j.Logger;
+
+import io.netty.channel.Channel;
+
+public class Log {
 
     public static final int VERBOSE  = 0;
     public static final int DEBUG    = 1;
@@ -34,6 +42,46 @@ public class Logger {
 
     private static int      logLevel = VERBOSE;
 
+    private static FileOutputStream fos = null;
+    private static PrintStream      ps  = null;
+
+    private final static Logger logger = Logger.getLogger(Log.class);
+
+    public static void Init() throws FileNotFoundException {
+        System.setOut(Log.createLoggingProxy(System.out));
+        createfile();
+    }
+
+    public static PrintStream createLoggingProxy(
+            final PrintStream realPrintStream) {
+        // TODO Auto-generated method stub
+        return new PrintStream(realPrintStream) {
+            public void print(final String string) {
+                realPrintStream.print(string);
+                logger.fatal(string);
+            }
+        };
+    }
+
+    public static void createfile() throws FileNotFoundException{
+        File dir = new File("..//errLog//");
+        if (!dir.isDirectory()) {
+            dir.mkdirs();
+        }
+        fos = new FileOutputStream("../errLog/[" + getDate() + "] error.log",
+                true);
+        ps = new PrintStream(fos);
+    }
+
+    static public void f(Channel channel, Throwable t) {
+        String log = channel.id().asLongText().substring(26) + " "
+                + t.getMessage();
+        ps.println(getTime() + " " + log);
+        t.printStackTrace(ps);
+        Log.v(log);
+    }
+
+
     public static void setLogLevel(int level) {
         logLevel = level;
     }
@@ -118,6 +166,12 @@ public class Logger {
         return dateFormat.format(calendar.getTime());
     }
 
+    protected static String getDate() {
+        Calendar calendar = Calendar.getInstance();
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        return dateFormat.format(calendar.getTime());
+    }
+
     private static String getLogLevelString(int level) {
 
         String res = "";
index 0a3cd39..84fe3ac 100755 (executable)
@@ -32,7 +32,7 @@ rm -rf $sourcedir/tmp/extlibs/tinycbor/tinycbor/.git
 cp -R ./extlibs/cjson $sourcedir/tmp/extlibs
 cp -R ./extlibs/gtest $sourcedir/tmp/extlibs
 cp -R ./extlibs/tinydtls $sourcedir/tmp/extlibs
-cp -R ./extlibs/sqlite3 $sourcedir/tmp/extlibs
+cp -LR ./extlibs/sqlite3 $sourcedir/tmp/extlibs
 cp -R ./extlibs/timer $sourcedir/tmp/extlibs
 cp -R ./extlibs/rapidxml $sourcedir/tmp/extlibs
 cp -R ./resource $sourcedir/tmp
index 9b31045..d3459d3 100644 (file)
@@ -29,6 +29,7 @@ SConscript('#resource/third_party_libs.scons', 'lib_env')
 liboctbstack_env = lib_env.Clone()
 
 target_os = env.get('TARGET_OS')
+rd_mode = env.get('RD_MODE')
 with_ra = env.get('WITH_RA')
 with_ra_ibb = env.get('WITH_RA_IBB')
 with_tcp = env.get('WITH_TCP')
@@ -121,12 +122,6 @@ if env.get('LOGGING'):
 if env.get('DTLS_WITH_X509') == '1':
        liboctbstack_env.AppendUnique(CPPDEFINES = ['__WITH_X509__'])
 
-if env.get('WITH_RD') == '1':
-       liboctbstack_env.PrependUnique(CPPPATH = ['../../service/resource-directory/include'])
-       liboctbstack_env.PrependUnique(LIBPATH = [env.get('BUILD_DIR') + 'service/resource-directory/include'])
-       liboctbstack_env.AppendUnique(CPPDEFINES = ['-DWITH_RD'])
-       liboctbstack_env.AppendUnique(LIBS = ['resource_directory'])
-
 liboctbstack_env.Append(LIBS = ['c_common'])
 
 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
@@ -148,10 +143,17 @@ liboctbstack_src = [
        OCTBSTACK_SRC + 'ocobserve.c',
        OCTBSTACK_SRC + 'ocserverrequest.c',
        OCTBSTACK_SRC + 'occollection.c',
-       OCTBSTACK_SRC + 'oicgroup.c',
-       OCTBSTACK_SRC + "rdpayload.c"
+       OCTBSTACK_SRC + 'oicgroup.c'
        ]
 
+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 with_tcp == True:
        liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
 
index 17b3a9b..8dea22a 100644 (file)
@@ -406,41 +406,50 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data)
     coap_list_t *options = NULL;
     coap_transport_type transport = coap_udp;
     CAResult_t res = CA_SEND_FAILED;
-    if (NULL != data->requestInfo)
+
+    if (!data->requestInfo && !data->responseInfo)
+    {
+        OIC_LOG(ERROR, TAG, "request or response info is empty");
+        return res;
+    }
+
+    if (data->requestInfo)
     {
         OIC_LOG(DEBUG, TAG, "requestInfo is available..");
 
         info = &data->requestInfo->info;
         pdu = CAGeneratePDU(CA_GET, info, data->remoteEndpoint, &options, &transport);
+    }
+    else if (data->responseInfo)
+    {
+        OIC_LOG(DEBUG, TAG, "responseInfo is available..");
 
-        if (NULL != pdu)
-        {
-#ifdef WITH_BWT
-            if (CAIsSupportedBlockwiseTransfer(data->remoteEndpoint->adapter))
-            {
-                // Blockwise transfer
-                res = CAAddBlockOption(&pdu, info, data->remoteEndpoint, &options);
-                if (CA_STATUS_OK != res)
-                {
-                    OIC_LOG(DEBUG, TAG, "CAAddBlockOption has failed");
-                    goto exit;
-                }
-            }
-#endif // WITH_BWT
-        }
-        else
-        {
-            OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
-            CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
-            return res;
-        }
+        info = &data->responseInfo->info;
+        pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint,
+                            &options, &transport);
     }
-    else
+
+    if (!pdu)
     {
-        OIC_LOG(ERROR, TAG, "not supported message type for multicast.");
+        OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
+        CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
+        coap_delete_list(options);
         return res;
     }
 
+#ifdef WITH_BWT
+    if (CAIsSupportedBlockwiseTransfer(data->remoteEndpoint->adapter))
+    {
+        // Blockwise transfer
+        res = CAAddBlockOption(&pdu, info, data->remoteEndpoint, &options);
+        if (CA_STATUS_OK != res)
+        {
+            OIC_LOG(DEBUG, TAG, "CAAddBlockOption has failed");
+            goto exit;
+        }
+    }
+#endif // WITH_BWT
+
     CALogPDUInfo(pdu, data->remoteEndpoint);
 
     OIC_LOG(DEBUG, TAG, "pdu to send :");
index 2b6a0d3..71dbdda 100644 (file)
@@ -50,9 +50,6 @@ if catest_env.get('SECURED') == '1':
        catest_env.AppendUnique(LIBS = ['tinydtls'])
        catest_env.AppendUnique(LIBS = ['timer'])
 
-if catest_env.get('WITH_RD') == '1':
-       catest_env.PrependUnique(LIBS = ['resource_directory'])
-
 if catest_env.get('LOGGING'):
        catest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
index e184494..191713d 100644 (file)
@@ -23,6 +23,7 @@ Import('env')
 import os.path
 
 provisioning_env = env.Clone()
+target_os = provisioning_env.get('TARGET_OS')
 
 ######################################################################
 # Build flags
@@ -74,6 +75,9 @@ if env.get('DTLS_WITH_X509') == '1':
 
 provisioning_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
+if target_os == 'tizen':
+    provisioning_env.AppendUnique(CPPDEFINES = ['__TIZEN__'])
+
 ######################################################################
 # Source files and Targets
 ######################################################################
index e3aef30..b6d148b 100644 (file)
@@ -1180,12 +1180,10 @@ exit:
     // A device should always have a default acl. Therefore, payload should never be NULL.
     ehRet = (payload ? OC_EH_OK : OC_EH_ERROR);
 
-    // Send response payload to request originator
-    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG(ERROR, TAG, "SendSRMResponse failed for HandleACLGetRequest");
-    }
+    //Send payload to request originator
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, payload, size)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
+
     OICFree(payload);
 
     OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
@@ -1229,12 +1227,9 @@ static OCEntityHandlerResult HandleACLPostRequest(const OCEntityHandlerRequest *
         DeleteACLList(newAcl);
     }
 
-    // Send payload to request originator
-    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleACLPostRequest");
-    }
+    //Send response to request originator
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
 
     OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
     return ehRet;
@@ -1260,12 +1255,9 @@ static OCEntityHandlerResult HandleACLDeleteRequest(const OCEntityHandlerRequest
     }
 
 exit:
-    // Send payload to request originator
-    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleACLDeleteRequest");
-    }
+    //Send response to request originator
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
 
     return ehRet;
 }
@@ -1301,8 +1293,8 @@ OCEntityHandlerResult ACLEntityHandler(OCEntityHandlerFlag flag, OCEntityHandler
                 break;
 
             default:
-                ehRet = OC_EH_ERROR;
-                SendSRMResponse(ehRequest, ehRet, NULL, 0);
+                ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                               OC_EH_OK : OC_EH_ERROR;
         }
     }
 
index 7bac5e1..724cde9 100644 (file)
@@ -981,6 +981,7 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh
     OCEntityHandlerResult ret = OC_EH_ERROR;
     OIC_LOG(DEBUG, TAG, "HandleCREDPostRequest IN");
 
+    static uint16_t previousMsgId = 0;
     //Get binary representation of cbor
     OicSecCred_t *cred  = NULL;
     uint8_t *payload = (((OCSecurityPayload*)ehRequest->payload)->securityData);
@@ -1088,8 +1089,21 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh
                   * If some error is occured while ownership transfer,
                   * ownership transfer related resource should be revert back to initial status.
                   */
-                RestoreDoxmToInitState();
-                RestorePstatToInitState();
+                const OicSecDoxm_t* doxm =  GetDoxmResourceData();
+                if(doxm)
+                {
+                    if(!doxm->owned && previousMsgId != ehRequest->messageID)
+                    {
+                        OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request,"\
+                                            "DOXM will be reverted.");
+                        RestoreDoxmToInitState();
+                        RestorePstatToInitState();
+                    }
+                }
+                else
+                {
+                    OIC_LOG(ERROR, TAG, "Invalid DOXM resource");
+                }
             }
         }
         else
@@ -1121,6 +1135,14 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh
         }
         FreeCred(cred);
     }
+    else
+    {
+        previousMsgId = ehRequest->messageID;
+    }
+    //Send response to request originator
+    ret = ((SendSRMResponse(ehRequest, ret, NULL, 0)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
+
     OIC_LOG(DEBUG, TAG, "HandleCREDPostRequest OUT");
     return ret;
 }
@@ -1143,12 +1165,10 @@ static OCEntityHandlerResult HandleGetRequest (const OCEntityHandlerRequest * eh
     // A device should always have a default cred. Therefore, payload should never be NULL.
     OCEntityHandlerResult ehRet = (res == OC_STACK_OK) ? OC_EH_OK : OC_EH_ERROR;
 
-    // Send response payload to request originator
-    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandlePstatGetRequest");
-    }
+
+    //Send payload to request originator
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, payload, size)) == OC_STACK_OK) ?
+                       OC_EH_OK : OC_EH_ERROR;
     OICFree(payload);
     return ehRet;
 }
@@ -1183,7 +1203,9 @@ static OCEntityHandlerResult HandleDeleteRequest(const OCEntityHandlerRequest *e
     {
         ehRet = OC_EH_RESOURCE_DELETED;
     }
-
+    //Send response to request originator
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
 exit:
     return ehRet;
 }
@@ -1216,15 +1238,11 @@ OCEntityHandlerResult CredEntityHandler(OCEntityHandlerFlag flag,
                 ret = HandleDeleteRequest(ehRequest);
                 break;
             default:
-                ret = OC_EH_ERROR;
+                ret = ((SendSRMResponse(ehRequest, ret, NULL, 0)) == OC_STACK_OK) ?
+                               OC_EH_OK : OC_EH_ERROR;
                 break;
         }
     }
-
-    //Send payload to request originator
-    ret = (SendSRMResponse(ehRequest, ret, NULL, 0) == OC_STACK_OK) ?
-                       ret : OC_EH_ERROR;
-
     return ret;
 }
 
index aa05845..cafdd22 100644 (file)
@@ -616,11 +616,8 @@ static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest
     OIC_LOG_BUFFER(DEBUG, TAG, payload, size);
 
     // Send response payload to request originator
-    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleDoxmGetRequest");
-    }
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, payload, size)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
 
     OICFree(payload);
 
@@ -862,8 +859,6 @@ exit:
         {
             if(!gDoxm->owned && previousMsgId != ehRequest->messageID)
             {
-                OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request,"\
-                                    "DOXM will be reverted.");
                 RestoreDoxmToInitState();
                 RestorePstatToInitState();
             }
@@ -879,11 +874,9 @@ exit:
     }
 
     //Send payload to request originator
-    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleDoxmPostRequest");
-    }
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
+
     DeleteDoxmBinData(newDoxm);
 
     return ehRet;
@@ -916,8 +909,8 @@ OCEntityHandlerResult DoxmEntityHandler(OCEntityHandlerFlag flag,
                 break;
 
             default:
-                ehRet = OC_EH_ERROR;
-                SendSRMResponse(ehRequest, ehRet, NULL, 0);
+                ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                               OC_EH_OK : OC_EH_ERROR;
                 break;
         }
     }
index 3d49a4b..4c71325 100644 (file)
@@ -416,11 +416,8 @@ static OCEntityHandlerResult HandlePstatGetRequest (const OCEntityHandlerRequest
     }
 
     // Send response payload to request originator
-    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandlePstatGetRequest");
-    }
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, payload, size)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
     OICFree(payload);
     return ehRet;
 }
@@ -532,13 +529,10 @@ static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest
          prevMsgId = ehRequest->messageID;
      }
 
+    // Send response payload to request originator
+    ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                   OC_EH_OK : OC_EH_ERROR;
 
-    //Send payload to request originator
-    if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
-    {
-        ehRet = OC_EH_ERROR;
-        OIC_LOG (ERROR, TAG, "SendSRMResponse failed in HandlePstatPostRequest");
-    }
     DeletePstatBinData(pstat);
     return ehRet;
 }
@@ -565,8 +559,8 @@ static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest
                 ehRet = HandlePstatPostRequest(ehRequest);
                 break;
             default:
-                ehRet = OC_EH_ERROR;
-                SendSRMResponse(ehRequest, ehRet, NULL, 0);
+                ehRet = ((SendSRMResponse(ehRequest, ehRet, NULL, 0)) == OC_STACK_OK) ?
+                               OC_EH_OK : OC_EH_ERROR;
                 break;
         }
     }
index 2113320..2740942 100755 (executable)
@@ -240,6 +240,17 @@ typedef struct OCResource {
 
     /** Pointer of ActionSet which to support group action.*/
     OCActionSet *actionsetHead;
+
+    /** 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;
+    };
 } OCResource;
 
 
index e4a2f29..7120951 100644 (file)
@@ -66,8 +66,8 @@ extern void* defaultDeviceHandlerCallbackParameter;
 /** The coap scheme */
 #define OC_COAP_SCHEME "coap://"
 
-/** the first outgoing sequence number will be 2*/
-#define OC_OFFSET_SEQUENCE_NUMBER (1)
+/** the first outgoing sequence number will be 1*/
+#define OC_OFFSET_SEQUENCE_NUMBER (0)
 
 /**
  * This structure will be created in occoap and passed up the stack on the server side.
index 72325a2..ea7daf8 100644 (file)
@@ -558,6 +558,37 @@ OC_EXPORT const OCDPDev_t* OCGetDirectPairedDevices();
  */
 OC_EXPORT OCStackResult OCDoDirectPairing(void *ctx, OCDPDev_t* peer, OCPrm_t pmSel, char *pinNumber,
                                                      OCDirectPairingCB resultCallback);
+
+#if defined(RD_CLIENT) || defined(RD_SERVER)
+/**
+ * This function binds an resource unique id to the resource.
+ *
+ * @param handle            Handle to the resource that the contained resource is to be bound.
+ * @param ins               Unique ID for resource.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OC_EXPORT OCStackResult OCBindResourceInsToResource(OCResourceHandle handle, uint8_t ins);
+
+/**
+ * This function gets the resource unique id for a resource.
+ *
+ * @param handle            Handle of resource.
+ * @param ins               Unique ID for resource.
+ *
+ * @return Ins if resource found or 0 resource not found.
+ */
+OC_EXPORT OCStackResult OCGetResourceIns(OCResourceHandle handle, uint8_t *ins);
+
+/**
+ * This function gets a resource handle by resource uri.
+ *
+ * @param uri   Uri of Resource to get Resource handle.
+ *
+ * @return Found  resource handle or NULL if not found.
+ */
+OC_EXPORT OCResourceHandle OCGetResourceHandleAtUri(const char *uri);
+#endif
 //#endif // DIRECT_PAIRING
 
 #ifdef __cplusplus
index b132d6e..6cc3335 100644 (file)
@@ -79,8 +79,10 @@ extern "C" {
 /** Presence URI through which the OIC devices advertise their presence.*/
 #define OC_RSRVD_PRESENCE_URI                 "/oic/ad"
 
+#ifdef WITH_CLOUD
 /** Presence URI through which the OCF devices advertise their device presence.*/
 #define OCF_RSRVD_DEVICE_PRESENCE_URI         "/.well-known/ocf/prs"
+#endif
 
 /** Sets the default time to live (TTL) for presence.*/
 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
@@ -166,6 +168,9 @@ extern "C" {
 /** To represent interface.*/
 #define OC_RSRVD_INTERFACE              "if"
 
+/** To indicate how long RD should publish this item.*/
+#define OC_RSRVD_DEVICE_TTL             "lt"
+
 /** To represent time to live.*/
 #define OC_RSRVD_TTL                    "ttl"
 
@@ -215,7 +220,7 @@ extern "C" {
 #define OC_RSRVD_HOSTING_PORT           "port"
 
 /** TCP Port. */
-#define OC_RSRVD_TCP_PORT               "tcp"
+#define OC_RSRVD_TCP_PORT               "x.org.iotivity.tcp"
 
 /** For Server instance ID.*/
 #define OC_RSRVD_SERVER_INSTANCE_ID     "sid"
@@ -312,7 +317,7 @@ extern "C" {
 #define MAC_ADDR_BLOCKS (6)
 
 /** Max identity size. */
-#define MAX_IDENTITY_SIZE (32)
+#define MAX_IDENTITY_SIZE (37)
 
 /** Universal unique identity size. */
 #define UUID_IDENTITY_SIZE (128/8)
@@ -347,10 +352,10 @@ extern "C" {
 #define OC_RSRVD_TITLE                   "title"
 
 /** Defines URI. */
-#define OC_RSRVD_URI                     "uri"
+#define OC_RSRVD_URI                     "anchor"
 
 /** Defines media type. */
-#define OC_RSRVD_MEDIA_TYPE              "mt"
+#define OC_RSRVD_MEDIA_TYPE              "type"
 
 /** To represent resource type with Publish RD.*/
 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
@@ -1191,20 +1196,20 @@ 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;
-    /** The relation of the target URI referenced by the link to the context URI;
-     * The default value is null. */
-    char *rel;
-    /** Specifies if the resource referenced by the target URIis observable or not. */
-    bool obs;
+    /** 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 *uri;
+    char *anchor;
     /** The instance identifier for this web link in an array of web links - used in links. */
     union
     {
@@ -1215,8 +1220,10 @@ typedef struct OCLinksPayload
         /** 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 *mt;
+    OCStringLL *type;
     /** Holding address of the next resource. */
     struct OCLinksPayload *next;
 } OCLinksPayload;
@@ -1228,30 +1235,8 @@ typedef struct
     OCDeviceInfo n;
     /** Device identifier. */
     OCIdentity di;
-    /** The base URI where the resources are hold. */
-    char *baseURI;
-    /** Bitmap holds observable, discoverable, secure option flag.*/
-    uint8_t bitmap;
-    /** Port set in case, the secure flag is set above. */
-    uint16_t port;
-    /** Id for each set of links i.e. tag. */
-    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;
-    };
-    /** Defines the list of allowable resource types (for Target and anchors) in links included
-     * in the collection; new links being created can only be from this list. */
-    char *rts;
-    /** When specified this is the default relationship to use when an OIC Link does not specify
-     * an explicit relationship with *rel* parameter. */
-    char *drel;
     /** Time to keep holding resource.*/
-    uint32_t ttl;
+    uint64_t ttl;
 } OCTagsPayload;
 
 /** Resource collection payload. */
@@ -1261,8 +1246,6 @@ typedef struct OCResourceCollectionPayload
     OCTagsPayload *tags;
     /** Array of links payload. */
     OCLinksPayload *setLinks;
-    /** Holding address of the next resource. */
-    struct OCResourceCollectionPayload *next;
 } OCResourceCollectionPayload;
 
 typedef struct OCDiscoveryPayload
diff --git a/resource/csdk/stack/include/oicresourcedirectory.h b/resource/csdk/stack/include/oicresourcedirectory.h
new file mode 100644 (file)
index 0000000..e6aa56c
--- /dev/null
@@ -0,0 +1,72 @@
+//******************************************************************
+//
+// 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_H_
+#define OC_RESOURCE_DIRECTORY_H_
+
+#include "octypes.h"
+#include "logger.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+#ifdef RD_CLIENT
+/**
+ * Publish RD resource to Resource Directory.
+ *
+ * @param host The address of the RD.
+ * @param connectivityType Type of connectivity indicating the interface.
+ * @param resourceHandles This is the resource handle which we need to register to RD.
+ * @param nHandles The counts of resource handle.
+ * @param cbData 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.
+ */
+OC_EXPORT OCStackResult OCRDPublish(const char *host, OCConnectivityType connectivityType,
+                                    OCResourceHandle resourceHandles[], uint8_t nHandles,
+                                    OCCallbackData *cbData, OCQualityOfService qos);
+
+/**
+ * Delete RD resource from Resource Directory.
+ *
+ * @param host The address of the RD.
+ * @param connectivityType Type of connectivity indicating the interface.
+ * @param resourceHandles This is the resource handle which we need to delete to RD.
+ * @param nHandles The counts of resource handle.
+ * @param cbData 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.
+ */
+OC_EXPORT OCStackResult OCRDDelete(const char *host, OCConnectivityType connectivityType,
+                                   OCResourceHandle resourceHandles[], uint8_t nHandles,
+                                   OCCallbackData *cbData, OCQualityOfService qos);
+#endif
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif /* OC_RESOURCE_DIRECTORY_H_ */
index 0939955..44371c7 100644 (file)
@@ -49,6 +49,93 @@ extern "C"
 OC_EXPORT const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
 OC_EXPORT 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 : %lld ",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);
+        }
+        OIC_LOG_V(level, PL_TAG, "   INS: %d", links->ins);
+        OIC_LOG_V(level, PL_TAG, "   TTL: %d", 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
 INLINE_API void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
 {
     OIC_LOG(level, (PL_TAG), "Payload Type: Representation");
@@ -310,6 +397,7 @@ INLINE_API void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
     OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
 }
 
+#if defined(RD_CLIENT) || defined(RD_SERVER)
 INLINE_API void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
 {
     if (!payload)
@@ -332,7 +420,7 @@ INLINE_API void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
         OCLinksLog(level, rdPublish->setLinks);
     }
 }
-
+#endif
 INLINE_API void OCPayloadLog(LogLevel level, OCPayload* payload)
 {
     if(!payload)
@@ -360,9 +448,11 @@ 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;
index d75cd8e..2afa320 100644 (file)
 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.
@@ -65,6 +71,21 @@ OCStackResult OCRDCborToPayload(const CborValue *cborPayload, OCPayload **outPay
  */
 OCRDPayload *OCRDPayloadCreate();
 
+#ifdef RD_CLIENT
+/**
+ * Initializes RD Publish payload structure.
+ *
+ * @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(OCResourceHandle resourceHandles[], uint8_t nHandles,
+                                      uint64_t ttl);
+#endif
+
 /**
  * Initializes RD Discovery payload structure and sets the bias factor.
  *
@@ -89,37 +110,33 @@ 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 baseURI baseURI pointing to the resource directory location.
- * @param bitmap The bitmap value include observe, discovery and secure bit set.
- * @param port The secure port in case above bitmap is set to secure.
- * @param ins Unique value per collection.
- * @param rts Defines allowed resource types.
- * @param drel Defines defaultr relationship.
+ * @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,
-    const char *baseURI, uint8_t bitmap, uint16_t port, uint8_t ins, const char *rts, const char *drel, uint32_t ttl);
+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 rel Relation
- * @param obs Whether to observe or not.
+ * @param p Whether to observe or not.
  * @param title Title
- * @param uri URI
+ * @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 OCLinksPayload or else NULL in case of error.
+ * @retun Allocated memory for OCLinksResource or else NULL in case of error.
  */
-OCLinksPayload* OCCopyLinksResources(const char *href, OCStringLL *rt, OCStringLL *itf,
-    const char *rel, bool obs, const char *title, const char *uri, uint8_t ins, OCStringLL *mt);
+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.
@@ -159,22 +176,6 @@ void OCFreeCollectionResource(OCResourceCollectionPayload *payload);
  */
 void OCDiscoveryCollectionPayloadDestroy(OCDiscoveryPayload* payload);
 
-/**
- * Prints tags payload.
- *
- * @param level LogLevel for the print.
- * @param tags Structure of the tags payload.
- */
-OC_EXPORT void OCTagsLog(const LogLevel level, const OCTagsPayload *tags);
-
-/**
- * Prints links payload.
- *
- * @param level LogLevel for the print.
- * @param tags Structure of the links payload.
- */
-OC_EXPORT void OCLinksLog(const LogLevel level, const OCLinksPayload *links);
-
 #ifdef __cplusplus
 }
 #endif // __cplusplus
index da1b517..b308c0f 100644 (file)
@@ -64,9 +64,11 @@ 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);
@@ -485,7 +487,7 @@ bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name)
 
     if (!val)
     {
-        return false;
+        return true;
     }
 
     return val->type == OCREP_PROP_NULL;
index e1edc0d..60c8807 100644 (file)
 #include "ocrandom.h"
 #include "ocresourcehandler.h"
 #include "cbor.h"
+
+#if defined(RD_CLIENT) || defined(RD_SERVER)
 #include "rdpayload.h"
+#endif
 
 #define TAG "OIC_RI_PAYLOADCONVERT"
 
@@ -155,8 +158,10 @@ 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 b53ef21..6121839 100644 (file)
 #include "ocpayloadcbor.h"
 #include "ocstackinternal.h"
 #include "payload_logging.h"
-#include "rdpayload.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);
@@ -86,9 +89,11 @@ 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;
@@ -101,8 +106,6 @@ exit:
     return result;
 }
 
-void OCFreeOCStringLL(OCStringLL* ll);
-
 static OCStackResult OCParseSecurityPayload(OCPayload** outPayload, const uint8_t *payload,
         size_t size)
 {
index 44a2135..6479069 100755 (executable)
@@ -29,7 +29,7 @@
 #ifdef WITH_STRING_H
 #include <string.h>
 #endif
-#ifdef WITH_STRINGS_H
+#ifdef WITH_STRING_H
 #include <strings.h>
 #endif
 
 #include "secureresourcemanager.h"
 #include "cacommon.h"
 #include "cainterface.h"
-#include "rdpayload.h"
 #include "ocpayload.h"
 
-#ifdef WITH_RD
-#include "rd_server.h"
-#endif
-
 #ifdef ROUTING_GATEWAY
 #include "routingmanager.h"
 #endif
@@ -617,102 +612,6 @@ OCStackResult SendNonPersistantDiscoveryResponse(OCServerRequest *request, OCRes
     return OCDoResponse(&response);
 }
 
-#ifdef WITH_RD
-static OCStackResult checkResourceExistsAtRD(const char *interfaceType, const char *resourceType,
-     OCResource **payload, OCDevAddr *devAddr)
-{
-    OCResourceCollectionPayload *repPayload;
-    if (!payload)
-    {
-        return OC_STACK_ERROR;
-    }
-    if (OCRDCheckPublishedResource(interfaceType, resourceType, &repPayload, devAddr) == OC_STACK_OK)
-    {
-        if (!repPayload)
-        {
-            return OC_STACK_ERROR;
-        }
-        OCResource *ptr = ((OCResource *) OICCalloc(1, sizeof(OCResource)));
-        if (!ptr)
-        {
-           return OC_STACK_NO_MEMORY;
-        }
-
-        ptr->uri = OICStrdup(repPayload->setLinks->href);
-        if (!ptr->uri)
-        {
-           return OC_STACK_NO_MEMORY;
-        }
-        OCStringLL *rt = repPayload->setLinks->rt;
-        while (rt)
-        {
-            OCResourceType *temp = (OCResourceType *) OICCalloc(1, sizeof(OCResourceType));
-            if(!temp)
-            {
-                OICFree(ptr->uri);
-                return OC_STACK_NO_MEMORY;
-            }
-            temp->next = NULL;
-            temp->resourcetypename = OICStrdup(rt->value);
-            if (!ptr->rsrcType)
-            {
-                ptr->rsrcType = temp;
-            }
-            else
-            {
-                OCResourceType *type = ptr->rsrcType;
-                while (type->next)
-                {
-                    type = type->next;
-                }
-                type->next = temp;
-            }
-            rt = rt->next;
-        }
-
-        OCStringLL *itf = repPayload->setLinks->itf;
-        while (itf)
-        {
-            OCResourceInterface *temp = (OCResourceInterface *) OICCalloc(1, sizeof(OCResourceInterface));
-            if (!temp)
-            {
-                OICFree(ptr->uri);
-
-                return OC_STACK_NO_MEMORY;
-            }
-            temp->next = NULL;
-            temp->name = OICStrdup(itf->value);
-            if (!ptr->rsrcInterface)
-            {
-                ptr->rsrcInterface = temp;
-            }
-            else
-            {
-                OCResourceInterface *type = ptr->rsrcInterface;
-                while (type->next)
-                {
-                    type = type->next;
-                }
-                type->next = temp;
-            }
-            itf = itf->next;
-        }
-
-        ptr->resourceProperties = (OCResourceProperty) repPayload->tags->bitmap;
-
-        OCFreeCollectionResource(repPayload);
-        *payload = ptr;
-        return OC_STACK_OK;
-    }
-    else
-    {
-        OIC_LOG_V(ERROR, TAG, "The resource type or interface type doe not exist \
-                             on the resource directory");
-    }
-    return OC_STACK_ERROR;
-}
-#endif
-
 static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource* resource)
 {
     if (!request || !resource)
@@ -816,42 +715,6 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
                     bool foundResourceAtRD = false;
                     for (;resource && discoveryResult == OC_STACK_OK; resource = resource->next)
                     {
-#ifdef WITH_RD
-                        if (strcmp(resource->uri, OC_RSRVD_RD_URI) == 0)
-                        {
-                            OCResource *resource1 = NULL;
-                            OCDevAddr devAddr;
-                            discoveryResult = checkResourceExistsAtRD(interfaceQuery,
-                                resourceTypeQuery, &resource1, &devAddr);
-                            if (discoveryResult != OC_STACK_OK)
-                            {
-                                 break;
-                            }
-                            discoveryResult = BuildVirtualResourceResponse(resource1,
-                                discPayload, &devAddr, true);
-                            if (payload)
-                            {
-                                discPayload->baseURI = OICStrdup(devAddr.addr);
-                            }
-                            OICFree(resource1->uri);
-                            for (OCResourceType *rsrcRt = resource1->rsrcType, *rsrcRtNext = NULL; rsrcRt; )
-                            {
-                                rsrcRtNext = rsrcRt->next;
-                                OICFree(rsrcRt->resourcetypename);
-                                OICFree(rsrcRt);
-                                rsrcRt = rsrcRtNext;
-                            }
-
-                            for (OCResourceInterface *rsrcPtr = resource1->rsrcInterface, *rsrcNext = NULL; rsrcPtr; )
-                            {
-                                rsrcNext = rsrcPtr->next;
-                                OICFree(rsrcPtr->name);
-                                OICFree(rsrcPtr);
-                                rsrcPtr = rsrcNext;
-                            }
-                            foundResourceAtRD = true;
-                        }
-#endif
                         if (!foundResourceAtRD && includeThisResourceInResponse(resource, interfaceQuery, resourceTypeQuery))
                         {
                             discoveryResult = BuildVirtualResourceResponse(resource,
@@ -1166,6 +1029,9 @@ HandleResourceWithEntityHandler (OCServerRequest *request,
         {
             OIC_LOG(INFO, TAG, "Removed observer successfully");
             request->observeResult = OC_STACK_OK;
+            // There should be no observe option header for de-registration response.
+            // Set as an invalid value here so we can detect it later and remove the field in response.
+            request->observationOption = MAX_SEQUENCE_NUMBER + 1;
         }
         else
         {
index d46f889..55a83d6 100644 (file)
@@ -22,6 +22,7 @@
 #include "ocstack.h"
 #include "ocserverrequest.h"
 #include "ocresourcehandler.h"
+#include "ocobserve.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
 #include "ocpayload.h"
@@ -556,8 +557,8 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
     memcpy(responseInfo.info.token, serverRequest->requestToken, serverRequest->tokenLength);
     responseInfo.info.tokenLength = serverRequest->tokenLength;
 
-    // De-register observe option should not be included in the response header
-    if((serverRequest->observeResult == OC_STACK_OK) && (serverRequest->observationOption != OC_OBSERVE_DEREGISTER))
+    if((serverRequest->observeResult == OC_STACK_OK)&&
+       (serverRequest->observationOption != MAX_SEQUENCE_NUMBER + 1))
     {
         responseInfo.info.numOptions = ehResponse->numSendVendorSpecificHeaderOptions + 1;
     }
index d3e8922..28f9645 100644 (file)
@@ -1266,7 +1266,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
 
             OCClientResponse response =
                 {.devAddr = {.adapter = OC_DEFAULT_ADAPTER}};
-            response.sequenceNumber = -1;
+            response.sequenceNumber = MAX_SEQUENCE_NUMBER + 1;
             CopyEndpointToDevAddr(endPoint, &response.devAddr);
             FixUpClientResponse(&response);
             response.resourceUri = responseInfo->info.resourceUri;
@@ -1418,6 +1418,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
 
             if (cbNode->method == OC_REST_OBSERVE &&
                 response.sequenceNumber > OC_OFFSET_SEQUENCE_NUMBER &&
+                cbNode->sequenceNumber <=  MAX_SEQUENCE_NUMBER &&
                 response.sequenceNumber <= cbNode->sequenceNumber)
             {
                 OIC_LOG_V(INFO, TAG, "Received stale notification. Number :%d",
@@ -4766,3 +4767,61 @@ bool OCResultToSuccess(OCStackResult ocResult)
             return false;
     }
 }
+
+#if defined(RD_CLIENT) || defined(RD_SERVER)
+OCStackResult OCBindResourceInsToResource(OCResourceHandle handle, uint8_t ins)
+{
+    VERIFY_NON_NULL(handle, ERROR, OC_STACK_INVALID_PARAM);
+
+    OCResource *resource = NULL;
+
+    resource = findResource((OCResource *) handle);
+    if (!resource)
+    {
+        OIC_LOG(ERROR, TAG, "Resource not found");
+        return OC_STACK_ERROR;
+    }
+
+    resource->ins = ins;
+
+    return OC_STACK_OK;
+}
+
+OCResourceHandle OCGetResourceHandleAtUri(const char *uri)
+{
+    if (!uri)
+    {
+        OIC_LOG(ERROR, TAG, "Resource uri is NULL");
+        return NULL;
+    }
+
+    OCResource *pointer = headResource;
+
+    while (pointer)
+    {
+        if (strncmp(uri, pointer->uri, MAX_URI_LENGTH) == 0)
+        {
+            OIC_LOG_V(DEBUG, TAG, "Found Resource %s", uri);
+            return pointer;
+        }
+        pointer = pointer->next;
+    }
+    return NULL;
+}
+
+OCStackResult OCGetResourceIns(OCResourceHandle handle, uint8_t *ins)
+{
+    OCResource *resource = NULL;
+
+    VERIFY_NON_NULL(handle, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NON_NULL(ins, ERROR, OC_STACK_INVALID_PARAM);
+
+    resource = findResource((OCResource *) handle);
+    if (resource)
+    {
+        *ins = resource->ins;
+        return OC_STACK_OK;
+    }
+    return OC_STACK_ERROR;
+}
+#endif
diff --git a/resource/csdk/stack/src/oicresourcedirectory.c b/resource/csdk/stack/src/oicresourcedirectory.c
new file mode 100644 (file)
index 0000000..a0c72bf
--- /dev/null
@@ -0,0 +1,109 @@
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include "oicresourcedirectory.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"
+
+#ifdef RD_CLIENT
+OCStackResult OCRDPublish(const char *host, OCConnectivityType connectivityType,
+                          OCResourceHandle resourceHandles[], uint8_t nHandles,
+                          OCCallbackData *cbData, OCQualityOfService qos)
+{
+    // Validate input parameters
+    if (!host || !cbData || !cbData->cb)
+    {
+        return OC_STACK_INVALID_CALLBACK;
+    }
+
+    OCResourceHandle *pubResHandle = resourceHandles;
+    uint8_t nPubResHandles = nHandles;
+
+    // if resource handles is null, "/oic/p" and "/oic/d" resource will be published to RD.
+    if (!pubResHandle && !nPubResHandles)
+    {
+        OCResourceHandle defaultResHandles[OIC_RD_DEFAULT_RESOURCE] = { 0 };
+
+        // get "/oic/d" resource handle from stack.
+        defaultResHandles[0] = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+        // get "/oic/p" resource handle from stack.
+        defaultResHandles[1] = OCGetResourceHandleAtUri(OC_RSRVD_PLATFORM_URI);
+
+        pubResHandle = defaultResHandles;
+        nPubResHandles = OIC_RD_DEFAULT_RESOURCE;
+    }
+
+    char targetUri[MAX_URI_LENGTH] = { 0 };
+    snprintf(targetUri, MAX_URI_LENGTH, "%s%s?rt=%s", host,
+             OC_RSRVD_RD_URI, OC_RSRVD_RESOURCE_TYPE_RDPUBLISH);
+    OIC_LOG_V(DEBUG, TAG, "Target URI: %s", targetUri);
+
+    OCPayload *rdPayload = (OCPayload *) OCRDPublishPayloadCreate(pubResHandle, nPubResHandles,
+                                                                  OIC_RD_PUBLISH_TTL);
+    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");
+
+    return OCDoResource(NULL, OC_REST_POST, targetUri, NULL, (OCPayload *)rdPayload,
+                        connectivityType, qos, cbData, NULL, 0);
+}
+
+OCStackResult OCRDDelete(const char *host, OCConnectivityType connectivityType,
+                         OCResourceHandle resourceHandles[], uint8_t nHandles,
+                         OCCallbackData *cbData, OCQualityOfService qos)
+{
+    // Validate input parameters
+    if (!host || !cbData || !cbData->cb)
+    {
+        return OC_STACK_INVALID_CALLBACK;
+    }
+
+    const unsigned char *id = (const unsigned char *) OCGetServerInstanceIDString();
+
+    char targetUri[MAX_URI_LENGTH] = { 0 };
+    snprintf(targetUri, MAX_URI_LENGTH, "%s%s?di=%s", host, OC_RSRVD_RD_URI, id);
+
+    char queryParam[MAX_URI_LENGTH] = { 0 };
+    for (uint8_t j = 0; j < nHandles; j++)
+    {
+        OCResource *handle = (OCResource *) resourceHandles[j];
+        snprintf(queryParam, MAX_URI_LENGTH, "&ins=%d", handle->ins);
+    }
+
+    OICStrcatPartial(targetUri, sizeof(targetUri), queryParam, strlen(queryParam));
+    OIC_LOG_V(DEBUG, TAG, "Target URI: %s", targetUri);
+
+    return OCDoResource(NULL, OC_REST_DELETE, targetUri, NULL, NULL, connectivityType,
+                        qos, cbData, NULL, 0);
+}
+#endif
index de38153..3cffbce 100644 (file)
@@ -31,7 +31,7 @@
 #define CBOR_ROOT_ARRAY_LENGTH 1
 
 static int64_t OCTagsPayloadToCbor(OCTagsPayload *tags, CborEncoder *setMap);
-static int64_t OCLinksPayloadToCbor(OCLinksPayload *rtPtr, 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);
@@ -40,10 +40,13 @@ static CborError OCLinksCborToPayload(CborValue *linksArray, OCLinksPayload **li
 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 = CborErrorIO;
+    int64_t cborEncoderResult = CborNoError;
     int flags = 0;
     CborEncoder encoder;
     VERIFY_PARAM_NON_NULL(TAG, rdPayload, "Invalid input parameter rdPayload");
@@ -76,21 +79,18 @@ int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, siz
     }
     else if (rdPayload->rdPublish)
     {
-        CborEncoder colArray;
-        cborEncoderResult |= cbor_encoder_create_array(&encoder, &colArray, CborIndefiniteLength);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create collection array");
+        CborEncoder collMap;
+        cborEncoderResult |= cbor_encoder_create_map(&encoder, &collMap, CborIndefiniteLength);
+        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create collection map");
 
         OCResourceCollectionPayload *rdPublish = rdPayload->rdPublish;
-        while (rdPublish)
-        {
-            cborEncoderResult |= OCTagsPayloadToCbor(rdPublish->tags, &colArray);
-            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding tags payload");
-            cborEncoderResult |= OCLinksPayloadToCbor(rdPublish->setLinks, &colArray);
-            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed adding setLinks payload");
-            rdPublish = rdPublish->next;
-        }
-        cborEncoderResult |= cbor_encoder_close_container(&encoder, &colArray);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing collection array");
+        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
     {
@@ -119,97 +119,89 @@ exit:
 
 static int64_t OCTagsPayloadToCbor(OCTagsPayload *tags, CborEncoder *setMap)
 {
-    CborEncoder tagsMap;
     int64_t cborEncoderResult = CborNoError;
-    cborEncoderResult |= cbor_encoder_create_map(setMap, &tagsMap, CborIndefiniteLength);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create tags map");
 
-    cborEncoderResult |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_DEVICE_NAME, tags->n.deviceName);
+    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(&tagsMap, OC_RSRVD_DEVICE_ID,
-            (char *)tags->di.id);
+    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 |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_RTS, tags->rts);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_RTS in tags map");
-
-    cborEncoderResult |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_DREL, tags->drel);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_DREL in tags map");
-
-    cborEncoderResult |= ConditionalAddTextStringToMap(&tagsMap, OC_RSRVD_BASE_URI, tags->baseURI);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_BASE_URI in tags map");
-
-    {
-        uint64_t value = tags->bitmap;
-        cborEncoderResult |= ConditionalAddIntToMap(&tagsMap, OC_RSRVD_BITMAP, &value);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_BITMAP in tags map");
-
-        value = tags->port;
-        cborEncoderResult |= ConditionalAddIntToMap(&tagsMap, OC_RSRVD_HOSTING_PORT, &value);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_HOSTING_PORT in tags map");
-
-        value = tags->ins;
-        cborEncoderResult |= ConditionalAddIntToMap(&tagsMap, OC_RSRVD_INS, &value);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_INS in tags map");
-
-        value = tags->ttl;
-        cborEncoderResult |= ConditionalAddIntToMap(&tagsMap, OC_RSRVD_TTL, &value);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TTL in tags map");
-    }
-
-    cborEncoderResult |= cbor_encoder_close_container(setMap, &tagsMap);
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to close container");
-
+    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 *rtPtr, CborEncoder *setMap)
+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 (rtPtr)
+    while (links)
     {
         CborEncoder linksMap;
         cborEncoderResult |= cbor_encoder_create_map(&linksArray, &linksMap, CborIndefiniteLength);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create Links map");
+        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create links map");
 
-        cborEncoderResult |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_HREF, rtPtr->href);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_HREF in 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, rtPtr->rel);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_REL 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 |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_TITLE, rtPtr->title);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_TITLE 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 |= ConditionalAddTextStringToMap(&linksMap, OC_RSRVD_URI, rtPtr->uri);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_URI 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");
 
-        cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_RESOURCE_TYPE, rtPtr->rt);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_RT 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");
 
-        cborEncoderResult |= AddStringLLToMap(&linksMap, OC_RSRVD_INTERFACE, rtPtr->itf);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_ITF in 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 |= AddStringLLToMap(&linksMap, OC_RSRVD_MEDIA_TYPE, rtPtr->mt);
-        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_MT in Links map");
+        cborEncoderResult |= cbor_encoder_close_container(&linksMap, &policyMap);
+        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing policy map");
 
-        {
-            uint64_t value = rtPtr->ins;
-            cborEncoderResult |= ConditionalAddIntToMap(&linksMap, OC_RSRVD_INS, &value);
-            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add OC_RSRVD_INS in Links 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");
+        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing links map");
 
-        rtPtr = rtPtr->next;
+        links = links->next;
     }
     cborEncoderResult |= cbor_encoder_close_container(setMap, &linksArray);
     VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed closing links array");
@@ -229,40 +221,33 @@ OCStackResult OCRDCborToPayload(const CborValue *cborPayload, OCPayload **outPay
 
     ret = OC_STACK_MALFORMED_RESPONSE;
 
-    if (cbor_value_is_array(rdCBORPayload))
+    if (cbor_value_is_map(rdCBORPayload))
     {
-        OCLinksPayload *linksPayload = NULL;
+        // 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.");
 
-        while (cbor_value_is_container(rdCBORPayload))
-        {
-            // enter tags map
-            CborValue tags;
-            cborFindResult = cbor_value_enter_container(rdCBORPayload, &tags);
-            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed entering tags container.");
-
-            cborFindResult= OCTagsCborToPayload(&tags, &tagsPayload);
-            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed parsing tags payload.");
-            OCTagsLog(DEBUG, tagsPayload);
-
-            cborFindResult = OCLinksCborToPayload(&tags, &linksPayload);
-            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed parsing links payload.");
-            OCLinksLog(DEBUG, linksPayload);
-
-            // 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);
+                                         &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);
@@ -335,14 +320,15 @@ static CborError FindStringLLInMap(const CborValue *linksMap, const char *tag, O
             VERIFY_PARAM_NON_NULL(TAG, llPtr, "Failed allocating OCStringLL");
             *links = llPtr;
         }
-        else if(llPtr)
+        else if (llPtr)
         {
             while (llPtr->next)
             {
                 llPtr = llPtr->next;
             }
             llPtr->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-            VERIFY_PARAM_NON_NULL(TAG, llPtr->next, "Failed allocating OCStringLL->next");
+            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");
@@ -363,16 +349,10 @@ static CborError OCTagsCborToPayload(CborValue *tagsMap, OCTagsPayload **tagsPay
     OCTagsPayload *tags = (OCTagsPayload *)OICCalloc(1, sizeof(OCTagsPayload));
     VERIFY_PARAM_NON_NULL(TAG, tags, "Failed allocating tags");
 
-    if (cbor_value_is_map(tagsMap))
+    cborFindResult = FindStringInMap(tagsMap, OC_RSRVD_DEVICE_NAME, &tags->n.deviceName);
+    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding deviceName");
+
     {
-        cborFindResult = FindStringInMap(tagsMap, OC_RSRVD_DEVICE_NAME, &tags->n.deviceName);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding deviceName");
-        cborFindResult = FindStringInMap(tagsMap, OC_RSRVD_DREL, &tags->drel);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding drel");
-        cborFindResult = FindStringInMap(tagsMap, OC_RSRVD_RTS, &tags->rts);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding rts");
-        cborFindResult = FindStringInMap(tagsMap, OC_RSRVD_BASE_URI, &tags->baseURI);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding baseURI");
         char *deviceId = NULL;
         cborFindResult = FindStringInMap(tagsMap, OC_RSRVD_DEVICE_ID, &deviceId);
         if (deviceId)
@@ -381,27 +361,11 @@ static CborError OCTagsCborToPayload(CborValue *tagsMap, OCTagsPayload **tagsPay
             OICFree(deviceId);
         }
         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding deviceId");
-        {
-            uint64_t value = 0;
-            cborFindResult = FindIntInMap(tagsMap, OC_RSRVD_HOSTING_PORT, &value);
-            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding port");
-            tags->port = value;
-            value = 0;
-            cborFindResult = FindIntInMap(tagsMap, OC_RSRVD_BITMAP, &value);
-            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding bitmap");
-            tags->bitmap = value;
-            value = 0;
-            cborFindResult = FindIntInMap(tagsMap, OC_RSRVD_INS, &value);
-            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding ins");
-            tags->ins = value;
-            value = 0;
-            cborFindResult = FindIntInMap(tagsMap, OC_RSRVD_TTL, &value);
-            tags->ttl = value;
-        }
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding ttl");
-        cborFindResult = cbor_value_advance(tagsMap);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed advancing bitmap");
     }
+
+    cborFindResult = FindIntInMap(tagsMap, OC_RSRVD_DEVICE_TTL, &tags->ttl);
+    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding ttl");
+
     *tagsPayload = tags;
     return cborFindResult;
 
@@ -410,11 +374,17 @@ exit:
     return cborFindResult;
 }
 
-static CborError OCLinksCborToPayload(CborValue *linksArray, OCLinksPayload **linksPayload)
+static CborError OCLinksCborToPayload(CborValue *links, OCLinksPayload **linksPayload)
 {
-    CborValue linksMap;
     OCLinksPayload *setLinks = NULL;
-    CborError cborFindResult = cbor_value_enter_container(linksArray, &linksMap);
+    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))
@@ -428,28 +398,36 @@ static CborError OCLinksCborToPayload(CborValue *linksArray, OCLinksPayload **li
         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->uri);
+        cborFindResult = FindStringInMap(&linksMap, OC_RSRVD_URI, &setLinks->anchor);
         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding uri value");
 
-        cborFindResult = FindStringLLInMap(&linksMap, OC_RSRVD_RESOURCE_TYPE, &setLinks->rt);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding rt value");
+        cborFindResult = FindIntInMap(&linksMap, OC_RSRVD_INS, (uint64_t *) &setLinks->ins);
+        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding ins value");
 
-        cborFindResult = FindStringLLInMap(&linksMap, OC_RSRVD_INTERFACE, &setLinks->itf);
-        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding itf 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->mt);
+        cborFindResult = FindStringLLInMap(&linksMap, OC_RSRVD_MEDIA_TYPE, &setLinks->type);
         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding mt value");
 
-        {
-            uint64_t value = 0;
-            cborFindResult = FindIntInMap(&linksMap, OC_RSRVD_INS, &value);
-            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed finding ins value");
-            setLinks->ins = value;
-        }
-
         if (!*linksPayload)
         {
             *linksPayload = setLinks;
@@ -506,6 +484,7 @@ static int64_t AddStringLLToMap(CborEncoder *map, const char *tag, const OCStrin
 {
     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);
@@ -532,6 +511,143 @@ exit:
     return rdPayload;
 }
 
+#ifdef RD_CLIENT
+OCRDPayload *OCRDPublishPayloadCreate(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;
+    }
+
+    const unsigned char *id = (const unsigned char *) OCGetServerInstanceIDString();
+    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));
@@ -574,35 +690,31 @@ void OCRDPayloadDestroy(OCRDPayload *payload)
 
     if (payload->rdPublish)
     {
-        for (OCResourceCollectionPayload *col = payload->rdPublish; col; )
+        OCResourceCollectionPayload *col = payload->rdPublish;
+
+        if (col->setLinks)
         {
-            if (col->setLinks)
-            {
-                OCFreeLinksResource(col->setLinks);
-            }
+            OCFreeLinksResource(col->setLinks);
+        }
 
-            if (col->tags)
-            {
-                OCFreeTagsResource(col->tags);
-            }
-            OCResourceCollectionPayload *temp = col->next;
-            OICFree(col);
-            col = temp;
+        if (col->tags)
+        {
+            OCFreeTagsResource(col->tags);
         }
+        OICFree(col);
     }
 
     OICFree(payload);
 }
 
-OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *id, const char *baseURI,
-        uint8_t bitmap, uint16_t port, uint8_t ins, const char *rts,const  char *drel, uint32_t ttl)
+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)
+    if (deviceName)
     {
         tags->n.deviceName = OICStrdup(deviceName);
         if (!tags->n.deviceName)
@@ -614,33 +726,6 @@ OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *
     {
         OICStrcpy((char*)tags->di.id, MAX_IDENTITY_SIZE, (char *)id);
     }
-    if (baseURI)
-    {
-        tags->baseURI = OICStrdup(baseURI);
-        if (!tags->baseURI)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    tags->bitmap = bitmap;
-    tags->port = port;
-    tags->ins = ins;
-    if (rts)
-    {
-        tags->rts = OICStrdup(rts);
-        if (!tags->rts)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    if (drel)
-    {
-        tags->drel = OICStrdup(drel);
-        if (!tags->drel)
-        {
-            goto memory_allocation_failed;
-        }
-    }
     tags->ttl = ttl;
     return tags;
 
@@ -650,8 +735,10 @@ memory_allocation_failed:
     return NULL;
 }
 
-OCLinksPayload* OCCopyLinksResources(const char *href, OCStringLL *rt, OCStringLL *itf,
-        const char *rel, bool obs, const char *title, const char *uri, uint8_t ins, OCStringLL *mt)
+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)
@@ -667,6 +754,14 @@ OCLinksPayload* OCCopyLinksResources(const char *href, OCStringLL *rt, OCStringL
             goto memory_allocation_failed;
         }
     }
+    if (rel)
+    {
+        links->rel = OICStrdup(rel);
+        if (!links->rel)
+        {
+            goto memory_allocation_failed;
+        }
+    }
     if (rt)
     {
         links->rt = CloneOCStringLL(rt);
@@ -683,15 +778,7 @@ OCLinksPayload* OCCopyLinksResources(const char *href, OCStringLL *rt, OCStringL
             goto memory_allocation_failed;
         }
     }
-    if (rel)
-    {
-        links->rel = OICStrdup(rel);
-        if (!links->rel)
-        {
-            goto memory_allocation_failed;
-        }
-    }
-    links->obs = obs;
+    links->p = p;
     if (title)
     {
         links->title = OICStrdup(title);
@@ -700,19 +787,20 @@ OCLinksPayload* OCCopyLinksResources(const char *href, OCStringLL *rt, OCStringL
             goto memory_allocation_failed;
         }
     }
-    if (uri)
+    if (anchor)
     {
-        links->uri = OICStrdup(uri);
-        if (!links->uri)
+        links->anchor = OICStrdup(anchor);
+        if (!links->anchor)
         {
             goto memory_allocation_failed;
         }
     }
     links->ins = ins;
+    links->ttl = ttl;
     if (mt)
     {
-        links->mt = CloneOCStringLL(mt);
-        if (!links->mt)
+        links->type = CloneOCStringLL(mt);
+        if (!links->type)
         {
             goto memory_allocation_failed;
         }
@@ -742,21 +830,21 @@ exit:
     return pl;
 }
 
-void OCFreeLinksResource(OCLinksPayload *payload)
+void OCFreeLinksResource(OCLinksPayload *links)
 {
-    if (!payload)
+    if (!links)
     {
         return;
     }
-    OICFree(payload->href);
-    OCFreeOCStringLL(payload->rt);
-    OCFreeOCStringLL(payload->itf);
-    OICFree(payload->rel);
-    OICFree(payload->title);
-    OICFree(payload->uri);
-    OCFreeOCStringLL(payload->mt);
-    OCFreeLinksResource(payload->next);
-    OICFree(payload);
+    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)
@@ -765,10 +853,7 @@ void OCFreeTagsResource(OCTagsPayload *payload)
     {
         return;
     }
-    OICFree(payload->n.deviceName);
-    OICFree(payload->baseURI);
-    OICFree(payload->rts);
-    OICFree(payload->drel);
+    OICFree(payload->n.deviceName);;
     OICFree(payload);
 }
 
@@ -786,99 +871,52 @@ void OCFreeCollectionResource(OCResourceCollectionPayload *payload)
     {
         OCFreeLinksResource(payload->setLinks);
     }
-    OCFreeCollectionResource(payload->next);
     OICFree(payload);
 }
 
-void OCTagsLog(const LogLevel level, const OCTagsPayload *tags)
+static OCStackResult CreateStringLL(uint8_t numElements, OCResourceHandle handle,
+                                    const char* (*getValue)(OCResourceHandle handle, uint8_t i),
+                                    OCStringLL **stringLL)
 {
-    if (tags)
+    for (uint8_t i = 0; i < numElements; ++i)
     {
-        if (tags->n.deviceName)
-        {
-            OIC_LOG_V(level, TAG, " Device Name : %s ",tags->n.deviceName);
-        }
-        if (tags->baseURI)
+        const char *value = getValue(handle, i);
+        OIC_LOG_V(ERROR, TAG, "value: %s", value);
+        if (!*stringLL)
         {
-            OIC_LOG_V(level, TAG, " Base URI : %s ",tags->baseURI);
-        }
-        OIC_LOG_V(level, TAG, " Device ID : %s ",tags->di.id);
-        OIC_LOG_V(level, TAG, " Bitmap : %d ",tags->bitmap);
-        OIC_LOG_V(level, TAG, " Port : %d ",tags->port);
-        OIC_LOG_V(level, TAG, " Ins : %d ",tags->ins);
-        OIC_LOG_V(level, TAG, " Ttl : %d ",tags->ttl);
-
-        if (tags->rts)
-        {
-            OIC_LOG_V(level, TAG, " RTS : %s ",tags->rts);
-        }
-        if (tags->drel)
-        {
-            OIC_LOG_V(level, TAG, " DREL : %s ",tags->drel);
-        }
-    }
-    else
-    {
-        (void) level;
-    }
-}
-
-void OCLinksLog(const LogLevel level, const OCLinksPayload *links)
-{
-    while (links)
-    {
-        if (links->href)
-        {
-            OIC_LOG_V(level, TAG, " href: %s ",links->href);
-        }
-        OIC_LOG(level, TAG, " RT: ");
-        OCStringLL *rt = links->rt;
-        while (rt)
-        {
-            if (rt->value)
+            *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
+            if (!*stringLL)
             {
-                OIC_LOG_V(level, TAG, "   %s", rt->value);
+                OIC_LOG(ERROR, TAG, "Failed allocating memory.");
+                return OC_STACK_NO_MEMORY;
             }
-            rt = rt->next;
-        }
-        OIC_LOG(level, TAG, " IF: ");
-        OCStringLL *itf = links->itf;
-        while (itf)
-        {
-            if (itf->value)
+            (*stringLL)->value = OICStrdup(value);
+            if (!(*stringLL)->value)
             {
-                OIC_LOG_V(level, TAG, "   %s", itf->value);
+                OIC_LOG(ERROR, TAG, "Failed copying to OCStringLL.");
+                return OC_STACK_NO_MEMORY;
             }
-            itf = itf->next;
         }
-        OIC_LOG(level, TAG, " MT: ");
-        OCStringLL *mt = links->mt;
-        while (mt)
+        else
         {
-            if (mt->value)
+            OCStringLL *cur = *stringLL;
+            while (cur->next)
             {
-                OIC_LOG_V(level, TAG, "   %s", mt->value);
+                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;
             }
-            mt = mt->next;
-        }
-        OIC_LOG_V(level, TAG, " INS: %d", links->ins);
-        OIC_LOG_V(level, TAG, " OBS: %d", links->obs);
-        if (links->rel)
-        {
-            OIC_LOG_V(level, TAG, " REL: %s", links->rel);
-        }
-        if (links->title)
-        {
-            OIC_LOG_V(level, TAG, " TITLE: %s", links->title);
-        }
-        if (links->uri)
-        {
-            OIC_LOG_V(level, TAG, " URI: %s", links->uri);
         }
-        links = links->next;
-    }
-    if (!links)
-    {
-        (void) level;
     }
+    return OC_STACK_OK;
 }
diff --git a/resource/csdk/stack/test/rdtests.cpp b/resource/csdk/stack/test/rdtests.cpp
new file mode 100644 (file)
index 0000000..38dbd84
--- /dev/null
@@ -0,0 +1,262 @@
+//******************************************************************
+//
+// 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 "rdpayload.h"
+    #include "oicresourcedirectory.h"
+    #include "ocstack.h"
+    #include "ocstackinternal.h"
+    #include "logger.h"
+    #include "oic_malloc.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[] = "RDTests";
+
+std::chrono::seconds const SHORT_TEST_TIMEOUT = std::chrono::seconds(5);
+
+//-----------------------------------------------------------------------------
+// Callback functions
+//-----------------------------------------------------------------------------
+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;
+}
+
+static OCStackApplicationResult handleDeleteCB(__attribute__((unused))void *ctx,
+                                               __attribute__((unused)) OCDoHandle handle,
+                                               __attribute__((unused))
+                                               OCClientResponse *clientResponse)
+{
+    OIC_LOG(DEBUG, TAG, "Successfully delete resources.");
+
+    return OC_STACK_DELETE_TRANSACTION;
+}
+
+//-----------------------------------------------------------------------------
+// Entity handler
+//-----------------------------------------------------------------------------
+OCEntityHandlerResult rdEntityHandler(OCEntityHandlerFlag /*flag*/,
+                                      OCEntityHandlerRequest * /*entityHandlerRequest*/,
+                                      void* /*callbackParam*/)
+{
+    OIC_LOG(INFO, TAG, "Entering entityHandler");
+
+    return OC_EH_OK;
+}
+
+//-----------------------------------------------------------------------------
+//  Tests
+//-----------------------------------------------------------------------------
+class RDTests : public testing::Test {
+    protected:
+    virtual void SetUp()
+    {
+        OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER);
+    }
+
+    virtual void TearDown()
+    {
+        OCStop();
+    }
+};
+
+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.
+    OCRDPayloadDestroy(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)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_INVALID_IP, OCRDPublish(0, CT_ADAPTER_IP, nullptr, 0, 0, OC_LOW_QOS));
+}
+
+TEST_F(RDTests, RDPublishResourceNullCB)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRDPublish("127.0.0.1", CT_ADAPTER_IP, nullptr,
+                                                     0, 0, OC_LOW_QOS));
+}
+
+TEST_F(RDTests, RDPublishResource)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+
+    OCCallbackData cbData;
+    cbData.cb = &handlePublishCB;
+    cbData.cd = NULL;
+    cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
+
+    OCResourceHandle handle;
+
+    EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle, "core.light",
+                                            "oic.if.baseline", "/a/light", rdEntityHandler,
+                                            NULL, (OC_DISCOVERABLE | OC_OBSERVABLE)));
+
+    EXPECT_EQ(OC_STACK_OK, OCRDPublish("127.0.0.1", CT_ADAPTER_IP, &handle,
+                                       1, &cbData, OC_LOW_QOS));
+}
+
+TEST_F(RDTests, RDPublishMultipleResources)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+
+    OCCallbackData cbData;
+    cbData.cb = &handlePublishCB;
+    cbData.cd = NULL;
+    cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
+
+    OCResourceHandle handles[2];
+    EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handles[0], "core.light",
+                                            "oic.if.baseline", "/a/light", rdEntityHandler,
+                                            NULL, (OC_DISCOVERABLE | OC_OBSERVABLE)));
+
+    EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handles[1], "core.light",
+                                            "oic.if.baseline", "/a/light2", rdEntityHandler,
+                                            NULL, (OC_DISCOVERABLE | OC_OBSERVABLE)));
+
+    EXPECT_EQ(OC_STACK_OK, OCRDPublish("127.0.0.1", CT_ADAPTER_IP, handles,
+                                       2, &cbData, OC_LOW_QOS));
+}
+
+TEST_F(RDTests, RDDeleteResourceNullAddr)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_INVALID_IP, OCRDDelete(0, CT_ADAPTER_IP, nullptr, 0, 0, OC_LOW_QOS));
+}
+
+TEST_F(RDTests, RDDeleteResourceNullCB)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRDDelete("127.0.0.1", CT_ADAPTER_IP, nullptr,
+                                                    0, 0, OC_LOW_QOS));
+}
+
+TEST_F(RDTests, RDDeleteAllResource)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+
+    OCCallbackData cbData;
+    cbData.cb = &handleDeleteCB;
+    cbData.cd = NULL;
+    cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
+
+    EXPECT_EQ(OC_STACK_OK, OCRDDelete("127.0.0.1", CT_ADAPTER_IP, nullptr, 0, &cbData,
+                                      OC_LOW_QOS));
+}
+
+TEST_F(RDTests, RDDeleteSpecificResource)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+
+    OCCallbackData cbData;
+    cbData.cb = &handleDeleteCB;
+    cbData.cd = NULL;
+    cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
+
+    OCResourceHandle handle;
+
+    EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle, "core.light",
+                                            "oic.if.baseline", "/a/light", rdEntityHandler,
+                                            NULL, OC_DISCOVERABLE | OC_OBSERVABLE));
+
+    EXPECT_EQ(OC_STACK_OK, OCRDDelete("127.0.0.1", CT_ADAPTER_IP, &handle,
+                                      1, &cbData, OC_LOW_QOS));
+}
index c85806d..ba49690 100644 (file)
@@ -79,6 +79,12 @@ if examples_env.get('WITH_CLOUD'):
 if target_os in ['msys_nt', 'windows']:
        examples_env.AppendUnique(LIBS = ['Comctl32', 'Gdi32', 'User32'])
 
+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")
 
@@ -103,7 +109,12 @@ if target_os not in ['windows', 'msys_nt']:
                'groupserver',
                'groupclient',
                'lightserver',
-               'threadingsample',
+               'threadingsample'
+               ]
+
+if 'CLIENT' in examples_env.get('RD_MODE'):
+       example_names += [
+               'rdclient'
                ]
 
 examples = map(make_single_file_cpp_program, example_names)
index 45e59b4..9fbc446 100644 (file)
@@ -164,7 +164,7 @@ void printRepresentation(const OCRepresentation& rep)
 // callback handler on PUT request
 void onPut(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
 {
-    if(eCode == SUCCESS_RESPONSE)
+    if(eCode == SUCCESS_RESPONSE || eCode == OC_STACK_RESOURCE_CHANGED)
     {
         std::cout << "PUT request was successful" << std::endl;
 
diff --git a/resource/examples/rdclient.cpp b/resource/examples/rdclient.cpp
new file mode 100644 (file)
index 0000000..9dd0750
--- /dev/null
@@ -0,0 +1,280 @@
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+#include <functional>
+#include <iostream>
+
+using namespace std;
+using namespace OC;
+
+string rdAddress;
+OCConnectivityType connectivityType = CT_ADAPTER_TCP;
+
+ResourceHandles m_publishedResourceHandles;
+
+static void onDelete(const int& eCode);
+static void onPublish(const OCRepresentation& rep, const int& eCode);
+
+class Resource
+{
+
+public:
+    std::string m_resourceUri;
+    OCResourceHandle m_resourceHandle;
+
+public:
+    /// This function internally calls registerResource API.
+    void registerResource()
+    {
+        string resourceURI;
+        string resourceTypeName;
+        string resourceInterface;
+
+        std::cout <<"   resourceURI: ";
+        std::cin >> resourceURI;
+        std::cout <<"   resourceTypeName: ";
+        std::cin >> resourceTypeName;
+        std::cout <<"   resourceInterface: ";
+        std::cin >> resourceInterface;
+
+        m_resourceUri = resourceURI;
+
+        OCPlatform::registerResource(m_resourceHandle, resourceURI, resourceTypeName,
+                                     resourceInterface,
+                                     nullptr,
+                                     OC_DISCOVERABLE);
+
+        m_publishedResourceHandles.push_back(m_resourceHandle);
+        cout << "registerResource is called." << endl;
+    }
+
+    void updateResource()
+    {
+        cout << "   1:: add resource type\n";
+        cout << "   2:: add resource interface\n";
+
+        int selectedMenu;
+        std::cin >> selectedMenu;
+
+        string inputString;
+        switch (selectedMenu)
+        {
+        case 1:
+            std::cout << "Add Resource Type" << std::endl;
+            std::cout <<"   resourceTypeName: ";
+            std::cin >> inputString;
+            OCPlatform::bindTypeToResource(m_resourceHandle, inputString);
+            break;
+        case 2:
+            std::cout << "Add Resource Interface" << std::endl;
+            std::cout <<"   resourceInterface: ";
+            std::cin >> inputString;
+            OCPlatform::bindInterfaceToResource(m_resourceHandle, inputString);
+            break;
+        default:
+            cout << "Invalid option" << endl;
+            return;
+        }
+    }
+
+    void publishResource()
+    {
+        /*
+         * Publish Resource of Resource-Server to RD.
+         */
+
+        OCStackResult result = OCPlatform::publishResourceToRD(rdAddress, connectivityType,
+                                                               m_publishedResourceHandles,
+                                                               &onPublish);
+        if (OC_STACK_OK != result)
+        {
+            cout << "Resource publish was unsuccessful\n";
+        }
+    }
+
+    void deleteResource()
+    {
+        /*
+         * Delete Resource with Resource Handle.
+         * Don't need to include resource handle,
+         * if resource-server want to delete all resources from RD.
+         * Ex.) OCPlatform::deleteResourceFromRD(rdAddress, connectivityType, &onDelete);
+         */
+        OCStackResult result = OCPlatform::deleteResourceFromRD(rdAddress, connectivityType,
+                                                                m_publishedResourceHandles,
+                                                                &onDelete);
+        if (OC_STACK_OK != result)
+        {
+            cout << "Resource delete was unsuccessful\n";
+        }
+    }
+};
+
+void onDelete(const int& eCode)
+{
+    cout << "Received Delete Resource Response From RD\n";
+    try
+    {
+        if (OC_STACK_RESOURCE_DELETED == eCode)
+        {
+            cout << "Resource delete was successful\n";
+        }
+        else
+        {
+            std::cout << "onDelete Response error: " << eCode << std::endl;
+            std::exit(-1);
+        }
+    }
+    catch(std::exception& e)
+    {
+        std::cout << "Exception: " << e.what() << " in onDelete" << std::endl;
+    }
+}
+
+void onPublish(const OCRepresentation& rep, const int& eCode)
+{
+    cout << endl <<"Received Publish Resource Response From RD\n";
+
+    try
+    {
+        if (OC_STACK_RESOURCE_CREATED == eCode)
+        {
+            cout << "=========== Published Resource ===========" << endl;
+            if (rep.hasAttribute("di"))
+            {
+                std::cout << " di: " << rep.getValue<std::string>("di") << std::endl;
+            }
+
+            // Published Resource is included as the child resource.
+            std::vector<OCRepresentation> children = rep.getChildren();
+
+            for (auto oit = children.begin(); oit != children.end(); ++oit)
+            {
+                std::string m_href;
+                oit->getValue("href", m_href);
+                cout << "   href : " << m_href << "\n";
+
+                cout << "   resource type : \n";
+                for(const std::string& type : oit->getResourceTypes())
+                {
+                    cout << "       " <<  type << "\n";
+                }
+
+                cout << "   resource interface : \n";
+                for(const std::string& type : oit->getResourceInterfaces())
+                {
+                    cout << "       " <<  type << "\n";
+                }
+
+                int m_ins;
+                oit->getValue("ins", m_ins);
+                cout << "   ins : " << m_ins << "\n";
+            }
+            cout << "=========================================" << endl;
+        }
+        else
+        {
+            std::cout << "onPublish Response error: " << eCode << std::endl;
+            std::exit(-1);
+        }
+    }
+    catch(std::exception& e)
+    {
+        std::cout << "Exception: " << e.what() << " in onPublish" << std::endl;
+    }
+}
+
+static void printUsage()
+{
+    std::cout<<"Usage: rdserver <coap+tcp://10.11.12.13:5683>\n";
+}
+
+int main(int argc, char* argv[])
+{
+    ostringstream requestURI;
+
+    if (argc == 2)
+    {
+        rdAddress = argv[1];
+    }
+    else
+    {
+        printUsage();
+        return -1;
+    }
+
+    PlatformConfig config
+    { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+
+    try
+    {
+        OCPlatform::Configure(config);
+
+        int selectedMenu;
+        bool isRun = true;
+
+        std::cout << "Register resources" << std::endl;
+        Resource myResource;
+        myResource.registerResource();
+
+        while (isRun)
+        {
+            cout << "================= MENU =================" << endl;
+            cout << "0 :: Quit" << endl;
+            cout << "1 :: UPDATE RESOURCE" << endl;
+            cout << "2 :: PUBLISH RESOURCE TO RD" << endl;
+            cout << "3 :: DELETE RESOURCE FROM RD" << endl;
+            cout << "========================================" << endl;
+            std::cin >> selectedMenu;
+
+            switch (selectedMenu)
+            {
+            case 0:
+                isRun = false;
+                break;
+            case 1:
+                std::cout << "Update resources" << std::endl;
+                myResource.updateResource();
+                break;
+            case 2:
+                std::cout << "Publish resources to RD" << std::endl;
+                myResource.publishResource();
+                break;
+            case 3:
+                std::cout << "Delete resources from RD" << std::endl;
+                myResource.deleteResource();
+                break;
+            default:
+                cout << "Invalid option" << endl;
+            }
+
+        }
+    }
+    catch (OCException& e)
+    {
+        oclog() << "Exception in main: "<< e.what();
+    }
+
+    return 0;
+}
+
index c4aff50..6f7b91d 100644 (file)
@@ -37,6 +37,8 @@
 #include "OCPlatform.h"
 #include "OCApi.h"
 
+#define maxSequenceNumber 0xFFFFFF
+
 using namespace OC;
 
 static const char* SVR_DB_FILE_NAME = "./oic_svr_db_client.dat";
@@ -73,7 +75,7 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& re
 {
     try
     {
-        if(eCode == OC_STACK_OK && sequenceNumber != -1)
+        if(eCode == OC_STACK_OK && sequenceNumber != maxSequenceNumber + 1)
         {
             if(sequenceNumber == OC_OBSERVE_REGISTER)
             {
@@ -126,7 +128,8 @@ void onPost2(const HeaderOptions& /*headerOptions*/,
 {
     try
     {
-        if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)
+        if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED
+                || eCode == OC_STACK_RESOURCE_CHANGED)
         {
             std::cout << "POST request was successful" << std::endl;
 
@@ -172,7 +175,8 @@ void onPost(const HeaderOptions& /*headerOptions*/,
 {
     try
     {
-        if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)
+        if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED
+                || eCode == OC_STACK_RESOURCE_CHANGED)
         {
             std::cout << "POST request was successful" << std::endl;
 
@@ -241,7 +245,7 @@ void onPut(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep,
 {
     try
     {
-        if(eCode == OC_STACK_OK)
+        if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
         {
             std::cout << "PUT request was successful" << std::endl;
 
index bb6283d..b8a571c 100644 (file)
@@ -119,7 +119,7 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& re
 
 void onPost2(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
 {
-    if(eCode == SUCCESS_RESPONSE)
+    if(eCode == SUCCESS_RESPONSE || eCode == OC_STACK_RESOURCE_CHANGED)
     {
         std::cout << "POST request was successful" << std::endl;
 
@@ -158,7 +158,7 @@ void onPost2(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep
 void onPost(const HeaderOptions& /*headerOptions*/,
         const OCRepresentation& rep, const int eCode)
 {
-    if(eCode == SUCCESS_RESPONSE)
+    if(eCode == SUCCESS_RESPONSE || eCode == OC_STACK_RESOURCE_CHANGED)
     {
         std::cout << "POST request was successful" << std::endl;
 
index 939e5f1..2c8f0ac 100644 (file)
@@ -51,7 +51,7 @@ private:
        std::cout <<"Clientside Put response to get was: "<<std::endl;
        std::cout <<"ErrorCode: "<<eCode <<std::endl;
 
-       if(eCode == 0)
+       if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
        {
             std::cout<<"Successful Put.  Attributes sent were: "<<std::endl;
 
index 59e5d21..87a7b6a 100644 (file)
@@ -241,7 +241,7 @@ void WinUIClientApp::onPut(const HeaderOptions& /*headerOptions*/, const OCRepre
 {\r
     try\r
     {\r
-        if (eCode == OC_STACK_OK)\r
+        if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)\r
         {\r
             std::cout << "PUT request was successful" << std::endl;\r
 \r
@@ -288,7 +288,8 @@ void WinUIClientApp::onPost(const HeaderOptions& /*headerOptions*/,
 {\r
     try\r
     {\r
-        if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)\r
+        if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED\r
+                || OC_STACK_RESOURCE_CHANGED)\r
         {\r
             std::cout << "POST request was successful" << std::endl;\r
 \r
index 43e52c1..e560219 100644 (file)
@@ -109,11 +109,13 @@ namespace OC
 
         virtual OCStackResult UnsubscribePresence(OCDoHandle handle) =0;
 
+#ifdef WITH_CLOUD
         virtual OCStackResult SubscribeDevicePresence(OCDoHandle* handle,
                                                       const std::string& host,
                                                       const QueryParamsList& queryParams,
                                                       OCConnectivityType connectivityType,
                                                       ObserveCallback& callback) = 0;
+#endif
 
         virtual OCStackResult GetDefaultQos(QualityOfService& qos) = 0;
 
index 62f878a..f422392 100644 (file)
@@ -74,6 +74,19 @@ namespace OC
         virtual OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler) = 0;
 
         virtual OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse) = 0;
+#ifdef RD_CLIENT
+        virtual OCStackResult publishResourceToRD(const std::string& host,
+                                                  OCConnectivityType connectivityType,
+                                                  ResourceHandles& resourceHandles,
+                                                  PublishResourceCallback& callback,
+                                                  OCQualityOfService qos) = 0;
+
+        virtual OCStackResult deleteResourceFromRD(const std::string& host,
+                                                   OCConnectivityType connectivityType,
+                                                   ResourceHandles& resourceHandles,
+                                                   DeleteResourceCallback& callback,
+                                                   OCQualityOfService qos) = 0;
+#endif
     };
 }
 
index e97c990..0cd2df4 100644 (file)
@@ -179,11 +179,13 @@ namespace OC
 
         virtual OCStackResult UnsubscribePresence(OCDoHandle handle);
 
+#ifdef WITH_CLOUD
         virtual OCStackResult SubscribeDevicePresence(OCDoHandle* handle,
                                                       const std::string& host,
                                                       const QueryParamsList& queryParams,
                                                       OCConnectivityType connectivityType,
                                                       ObserveCallback& callback);
+#endif
 
         OCStackResult GetDefaultQos(QualityOfService& QoS);
 
index 2e04e58..ad578dd 100644 (file)
 
 namespace OC
 {
+#ifdef RD_CLIENT
+    namespace ServerCallbackContext
+    {
+        struct PublishContext
+        {
+            PublishResourceCallback callback;
+            PublishContext(PublishResourceCallback cb) : callback(cb){}
+        };
+
+        struct DeleteContext
+        {
+            DeleteResourceCallback callback;
+            DeleteContext(DeleteResourceCallback cb) : callback(cb){}
+        };
+    }
+#endif
     class InProcServerWrapper : public IServerWrapper
     {
     public:
@@ -68,6 +84,19 @@ namespace OC
         virtual OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
 
         virtual OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
+#ifdef RD_CLIENT
+        virtual OCStackResult publishResourceToRD(const std::string& host,
+                                                  OCConnectivityType connectivityType,
+                                                  ResourceHandles& resourceHandles,
+                                                  PublishResourceCallback& callback,
+                                                  OCQualityOfService qos);
+
+        virtual OCStackResult deleteResourceFromRD(const std::string& host,
+                                                   OCConnectivityType connectivityType,
+                                                   ResourceHandles& resourceHandles,
+                                                   DeleteResourceCallback& callback,
+                                                   OCQualityOfService qos);
+#endif
     private:
         void processFunc();
         std::thread m_processThread;
index 1188db1..0af7727 100644 (file)
@@ -213,18 +213,21 @@ namespace OC
         Observe,
         ObserveAll
     };
-    //
-    // Typedef for header option vector
-    // OCHeaderOption class is in HeaderOption namespace
+
+    // Typedef for list of resource handles.
+    typedef std::vector<OCResourceHandle> ResourceHandles;
+
+    // Typedef for header option vector.
+    // OCHeaderOption class is in HeaderOption namespace.
     typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
 
-    // Typedef for query parameter map
+    // Typedef for query parameter map.
     typedef std::map<std::string, std::string> QueryParamsMap;
 
     // Typedef for query parameter map with Vector
     typedef std::map< std::string, std::vector<std::string> > QueryParamsList;
 
-    // Typedef for list of observation IDs
+    // Typedef for list of observation IDs.
     typedef std::vector<OCObservationId> ObservationIds;
 
     enum class ObserveAction
@@ -297,7 +300,11 @@ namespace OC
     typedef std::function<void(const HeaderOptions&,
                                const OCRepresentation&, const int,
                                std::shared_ptr<OCResource>)> MQCreateTopicCallback;
+#ifdef RD_CLIENT
+    typedef std::function<void(const OCRepresentation&, const int)> PublishResourceCallback;
 
+    typedef std::function<void(const int)> DeleteResourceCallback;
+#endif
 } // namespace OC
 
 #endif
index c3d540f..78742bf 100644 (file)
@@ -534,6 +534,7 @@ namespace OC
          */
         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
 
+#ifdef WITH_CLOUD
         /**
          * Subscribes to a server's device presence change events.
          *
@@ -555,6 +556,7 @@ namespace OC
                                               const QueryParamsList& queryParams,
                                               OCConnectivityType connectivityType,
                                               ObserveCallback callback);
+#endif
 
         /**
          * Creates a resource proxy object so that get/put/observe functionality
@@ -713,6 +715,99 @@ namespace OC
                                          OCConnectivityType connectivityType,
                                          PostCallback cloudConnectHandler);
 #endif // WITH_CLOUD
+#ifdef RD_CLIENT
+        /**
+         * API for Virtual Resource("/oic/d" and "/oic/p") Publish to Resource Directory.
+         * @note This API applies to resource server side only.
+         *
+         * @param host Host IP Address of a service to direct resource publish query.
+         * @param connectivityType ::OCConnectivityType type of connectivity.
+         * @param callback Handles callbacks, success states and failure states.
+         *
+         * @return Returns ::OC_STACK_OK if success.
+         */
+        OCStackResult publishResourceToRD(const std::string& host,
+                                          OCConnectivityType connectivityType,
+                                          PublishResourceCallback callback);
+
+        /**
+         * API for Resource Publish to Resource Directory.
+         * @note This API applies to resource server side only.
+         *
+         * @param host Host IP Address of a service to direct resource publish query.
+         * @param connectivityType ::OCConnectivityType type of connectivity.
+         * @param resourceHandle resource handle of the resource.
+         * @param callback Handles callbacks, success states and failure states.
+         *
+         * @return Returns ::OC_STACK_OK if success.
+         */
+        OCStackResult publishResourceToRD(const std::string& host,
+                                          OCConnectivityType connectivityType,
+                                          ResourceHandles& resourceHandles,
+                                          PublishResourceCallback callback);
+
+        /**
+         * @overload
+         *
+         * @param host Host IP Address of a service to direct resource publish query.
+         * @param connectivityType ::OCConnectivityType type of connectivity.
+         * @param resourceHandle resource handle of the resource.
+         * @param callback function to callback with published resources.
+         * @param QoS the quality of communication
+         * @see publishResourceToRD(const std::string&, OCConnectivityType, OCResourceHandle,
+         * uint8_t, PublishResourceCallback)
+         */
+        OCStackResult publishResourceToRD(const std::string& host,
+                                          OCConnectivityType connectivityType,
+                                          ResourceHandles& resourceHandles,
+                                          PublishResourceCallback callback, QualityOfService QoS);
+
+        /**
+         * API for published resource delete from Resource Directory.
+         * @note This API applies to resource server side only.
+         *
+         * @param host Host IP Address of a service to direct resource delete query.
+         * @param connectivityType ::OCConnectivityType type of connectivity.
+         * @param callback Handles callbacks, success states and failure states.
+         *
+         * @return Returns ::OC_STACK_OK if success.
+         */
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           DeleteResourceCallback callback);
+
+        /**
+         * @overload
+         *
+         * @param host Host IP Address of a service to direct resource delete query.
+         * @param connectivityType ::OCConnectivityType type of connectivity.
+         * @param resourceHandle resource handle of the resource.
+         * @param callback function to callback with published resources.
+         * @param QoS the quality of communication
+         * @see publishResourceToRD(const std::string&, OCConnectivityType, OCResourceHandle,
+         * uint8_t, PublishResourceCallback)
+         */
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           ResourceHandles& resourceHandles,
+                                           DeleteResourceCallback callback);
+
+        /**
+         * @overload
+         *
+         * @param host Host IP Address of a service to direct resource delete query.
+         * @param connectivityType ::OCConnectivityType type of connectivity.
+         * @param resourceHandle resource handle of the resource.
+         * @param callback function to callback with published resources.
+         * @param QoS the quality of communication
+         * @see publishResourceToRD(const std::string&, OCConnectivityType, OCResourceHandle,
+         * uint8_t, PublishResourceCallback)
+         */
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           ResourceHandles& resourceHandles,
+                                           DeleteResourceCallback callback, QualityOfService QoS);
+#endif
     }
 }
 
index 2beb4a3..b3d1aa3 100644 (file)
@@ -225,18 +225,44 @@ namespace OC
                         SubscribeCallback presenceHandler);
         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
 
+#ifdef WITH_CLOUD
         OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
                                               const std::string& host,
                                               const QueryParamsList& queryParams,
                                               OCConnectivityType connectivityType,
                                               ObserveCallback callback);
+#endif
 
         OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
                         OCConnectivityType connectivityType, bool isObservable,
                         const std::vector<std::string>& resourceTypes,
                         const std::vector<std::string>& interfaces);
         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
-
+#ifdef RD_CLIENT
+        OCStackResult publishResourceToRD(const std::string& host,
+                                          OCConnectivityType connectivityType,
+                                          ResourceHandles& resourceHandles,
+                                          PublishResourceCallback callback);
+
+        OCStackResult publishResourceToRD(const std::string& host,
+                                          OCConnectivityType connectivityType,
+                                          ResourceHandles& resourceHandles,
+                                          PublishResourceCallback callback, QualityOfService qos);
+
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           DeleteResourceCallback callback);
+
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           ResourceHandles& resourceHandles,
+                                           DeleteResourceCallback callback);
+
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           ResourceHandles& resourceHandles,
+                                           DeleteResourceCallback callback, QualityOfService qos);
+#endif
         std::weak_ptr<std::recursive_mutex> csdkLock();
 
         OCStackResult findDirectPairingDevices(unsigned short waittime,
index be9a117..c07974a 100644 (file)
@@ -66,7 +66,9 @@ 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;
@@ -464,6 +466,9 @@ 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;
index 513156d..982fbb3 100644 (file)
@@ -121,7 +121,7 @@ namespace OC
 
         virtual OCStackResult UnsubscribePresence(OCDoHandle /*handle*/)
             {return OC_STACK_NOTIMPL;}
-
+#ifdef WITH_CLOUD
         virtual OCStackResult SubscribeDevicePresence(
             OCDoHandle* /*handle*/,
             const std::string& /*host*/,
@@ -129,6 +129,7 @@ namespace OC
             OCConnectivityType /*connectivityType*/,
             ObserveCallback& /*callback*/)
             {return OC_STACK_NOTIMPL;}
+#endif
 
         virtual OCStackResult GetDefaultQos(QualityOfService& /*QoS*/)
             {return OC_STACK_NOTIMPL;}
index 0f3e397..44e1178 100644 (file)
@@ -124,6 +124,7 @@ namespace OC
         static const char DUPLICATE_UUID[]             = "Duplicate UUID in DB";
         static const char INCONSISTENT_DB[]            = "Data in provisioning DB is inconsistent";
         static const char AUTHENTICATION_FAILURE[]     = "Authentication failure";
+        static const char PUBLISH_RESOURCE_FAILED[]    = "Publish Resource failure";
     }
 
     namespace Error
index 8a892c6..196c822 100644 (file)
@@ -1024,10 +1024,7 @@ namespace OC
         std::thread exec(context->callback, serverHeaderOptions, attrs,
                     result, sequenceNumber);
         exec.detach();
-        if (sequenceNumber == OC_OBSERVE_DEREGISTER)
-        {
-            return OC_STACK_DELETE_TRANSACTION;
-        }
+
         return OC_STACK_KEEP_TRANSACTION;
     }
 
@@ -1197,6 +1194,7 @@ namespace OC
         return result;
     }
 
+#ifdef WITH_CLOUD
     OCStackResult InProcClientWrapper::SubscribeDevicePresence(OCDoHandle* handle,
                                                                const std::string& host,
                                                                const QueryParamsList& queryParams,
@@ -1240,6 +1238,7 @@ namespace OC
 
         return result;
     }
+#endif
 
     OCStackResult InProcClientWrapper::GetDefaultQos(QualityOfService& qos)
     {
index 2fd1c19..bd7639d 100644 (file)
 #include <OCPlatform.h>
 #include <OCUtilities.h>
 
+#ifdef RD_CLIENT
+#include <oicresourcedirectory.h>
+#endif
+
 using namespace std;
 using namespace OC;
 
@@ -595,7 +599,149 @@ namespace OC
             return result;
         }
     }
+#ifdef RD_CLIENT
+    OCRepresentation parseRDResponseCallback(OCClientResponse* clientResponse)
+    {
+        if (nullptr == clientResponse->payload ||
+                    PAYLOAD_TYPE_RD != clientResponse->payload->type)
+        {
+            return OCRepresentation();
+        }
+
+        MessageContainer oc;
+        oc.setPayload(clientResponse->payload);
+
+        std::vector<OCRepresentation>::const_iterator it = oc.representations().begin();
+        if (it == oc.representations().end())
+        {
+            return OCRepresentation();
+        }
 
+        // first one is considered the root, everything else is considered a child of this one.
+        OCRepresentation root = *it;
+        root.setDevAddr(clientResponse->devAddr);
+        root.setUri(clientResponse->resourceUri);
+        ++it;
+
+        std::for_each(it, oc.representations().end(),
+                [&root](const OCRepresentation& repItr)
+                {root.addChild(repItr);});
+        return root;
+
+    }
+
+    OCStackApplicationResult publishResourceToRDCallback(void* ctx, OCDoHandle /*handle*/,
+                                                         OCClientResponse* clientResponse)
+    {
+        ServerCallbackContext::PublishContext* context =
+        static_cast<ServerCallbackContext::PublishContext*>(ctx);
+
+        try
+        {
+            // Update resource unique id in stack.
+            if (clientResponse)
+            {
+                if (clientResponse->payload)
+                {
+                    OCRDPayload *rdPayload = (OCRDPayload *) clientResponse->payload;
+                    OCLinksPayload *links = rdPayload->rdPublish->setLinks;
+
+                    while (links)
+                    {
+                        OCResourceHandle handle = OCGetResourceHandleAtUri(links->href);
+                        OCBindResourceInsToResource(handle, links->ins);
+                        links = links->next;
+                    }
+
+                }
+            }
+
+            OCRepresentation rep = parseRDResponseCallback(clientResponse);
+            std::thread exec(context->callback, rep, clientResponse->result);
+            exec.detach();
+        }
+        catch (OC::OCException& e)
+        {
+            oclog() <<"Exception in publishResourceToRDCallback, ignoring response: "
+                <<e.what() <<std::flush;
+        }
+
+        return OC_STACK_KEEP_TRANSACTION;
+    }
+
+    OCStackResult InProcServerWrapper::publishResourceToRD(const std::string& host,
+                                                           OCConnectivityType connectivityType,
+                                                           ResourceHandles& resourceHandles,
+                                                           PublishResourceCallback& callback,
+                                                           OCQualityOfService qos)
+    {
+        ServerCallbackContext::PublishContext* ctx =
+            new ServerCallbackContext::PublishContext(callback);
+        OCCallbackData cbdata(
+                static_cast<void*>(ctx),
+                publishResourceToRDCallback,
+                [](void* c)
+                {delete static_cast<ServerCallbackContext::PublishContext*>(c);}
+                );
+
+        auto cLock = m_csdkLock.lock();
+        OCStackResult result = OC_STACK_ERROR;
+        if (cLock)
+        {
+            std::lock_guard<std::recursive_mutex> lock(*cLock);
+            result = OCRDPublish(host.c_str(), connectivityType, &resourceHandles[0],
+                                 resourceHandles.size(), &cbdata, qos);
+        }
+
+        if (OC_STACK_OK != result)
+        {
+            throw OCException(OC::Exception::PUBLISH_RESOURCE_FAILED, result);
+        }
+        return result;
+    }
+
+    OCStackApplicationResult deleteResourceFromRDCallback(void* ctx, OCDoHandle /*handle*/,
+                                                          OCClientResponse* clientResponse)
+    {
+        ServerCallbackContext::DeleteContext* context =
+        static_cast<ServerCallbackContext::DeleteContext*>(ctx);
+
+        std::thread exec(context->callback, clientResponse->result);
+        exec.detach();
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    OCStackResult InProcServerWrapper::deleteResourceFromRD(const std::string& host,
+                                                            OCConnectivityType connectivityType,
+                                                            ResourceHandles& resourceHandles,
+                                                            DeleteResourceCallback& callback,
+                                                            OCQualityOfService qos)
+    {
+        ServerCallbackContext::DeleteContext* ctx =
+            new ServerCallbackContext::DeleteContext(callback);
+        OCCallbackData cbdata(
+                static_cast<void*>(ctx),
+                deleteResourceFromRDCallback,
+                [](void* c)
+                {delete static_cast<ServerCallbackContext::DeleteContext*>(c);}
+                );
+
+        auto cLock = m_csdkLock.lock();
+        OCStackResult result = OC_STACK_ERROR;
+        if (cLock)
+        {
+            std::lock_guard<std::recursive_mutex> lock(*cLock);
+            result = OCRDDelete(host.c_str(), connectivityType, &resourceHandles[0],
+                                resourceHandles.size(), &cbdata, qos);
+        }
+
+        if (OC_STACK_OK != result)
+        {
+            throw OCException(OC::Exception::PUBLISH_RESOURCE_FAILED, result);
+        }
+        return result;
+    }
+#endif
     InProcServerWrapper::~InProcServerWrapper()
     {
         if(m_processThread.joinable())
index dd161e4..8373b23 100644 (file)
@@ -266,6 +266,7 @@ namespace OC
             return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
         }
 
+#ifdef WITH_CLOUD
         OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
                                               const std::string& host,
                                               const QueryParamsList& queryParams,
@@ -278,6 +279,7 @@ namespace OC
                                                                        connectivityType,
                                                                        callback);
         }
+#endif
 
         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse)
         {
@@ -341,6 +343,65 @@ namespace OC
                                                        connectivityType, cloudConnectHandler);
         }
 #endif // WITH_CLOUD
+#ifdef RD_CLIENT
+        OCStackResult publishResourceToRD(const std::string& host,
+                                          OCConnectivityType connectivityType,
+                                          PublishResourceCallback callback)
+        {
+            ResourceHandles resourceHandles;
+            return OCPlatform_impl::Instance().publishResourceToRD(host, connectivityType,
+                                                                   resourceHandles,
+                                                                   callback);
+        }
+
+        OCStackResult publishResourceToRD(const std::string& host,
+                                          OCConnectivityType connectivityType,
+                                          ResourceHandles& resourceHandles,
+                                          PublishResourceCallback callback)
+        {
+            return OCPlatform_impl::Instance().publishResourceToRD(host, connectivityType,
+                                                                   resourceHandles,
+                                                                   callback);
+        }
+
+        OCStackResult publishResourceToRD(const std::string& host,
+                                          OCConnectivityType connectivityType,
+                                          ResourceHandles& resourceHandles,
+                                          PublishResourceCallback callback, QualityOfService QoS)
+        {
+            return OCPlatform_impl::Instance().publishResourceToRD(host, connectivityType,
+                                                                   resourceHandles,
+                                                                   callback, QoS);
+        }
+
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           DeleteResourceCallback callback)
+        {
+            ResourceHandles resourceHandles;
+            return OCPlatform_impl::Instance().deleteResourceFromRD(host, connectivityType,
+                                                                    resourceHandles, callback);
+        }
+
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           ResourceHandles& resourceHandles,
+                                           DeleteResourceCallback callback)
+        {
+            return OCPlatform_impl::Instance().deleteResourceFromRD(host, connectivityType,
+                                                                    resourceHandles, callback);
+        }
+
+        OCStackResult deleteResourceFromRD(const std::string& host,
+                                           OCConnectivityType connectivityType,
+                                           ResourceHandles& resourceHandles,
+                                           DeleteResourceCallback callback, QualityOfService QoS)
+        {
+            return OCPlatform_impl::Instance().deleteResourceFromRD(host, connectivityType,
+                                                                    resourceHandles, callback,
+                                                                    QoS);
+        }
+#endif
     } // namespace OCPlatform
 } //namespace OC
 
index f40c14c..4c89788 100644 (file)
@@ -382,6 +382,7 @@ namespace OC
                              std::ref(presenceHandle));
     }
 
+#ifdef WITH_CLOUD
     OCStackResult OCPlatform_impl::subscribeDevicePresence(OCPresenceHandle& presenceHandle,
                                                            const std::string& host,
                                                            const QueryParamsList& queryParams,
@@ -391,13 +392,54 @@ namespace OC
         return checked_guard(m_client, &IClientWrapper::SubscribeDevicePresence,
                              &presenceHandle, host, queryParams, connectivityType, callback);
     }
+#endif
 
     OCStackResult OCPlatform_impl::sendResponse(const std::shared_ptr<OCResourceResponse> pResponse)
     {
         return checked_guard(m_server, &IServerWrapper::sendResponse,
                              pResponse);
     }
+#ifdef RD_CLIENT
+    OCStackResult OCPlatform_impl::publishResourceToRD(const std::string& host,
+                                                       OCConnectivityType connectivityType,
+                                                       ResourceHandles& resourceHandles,
+                                                       PublishResourceCallback callback)
+    {
+        return publishResourceToRD(host, connectivityType, resourceHandles,
+                                   callback, m_cfg.QoS);
+    }
+
+    OCStackResult OCPlatform_impl::publishResourceToRD(const std::string& host,
+                                                       OCConnectivityType connectivityType,
+                                                       ResourceHandles& resourceHandles,
+                                                       PublishResourceCallback callback,
+                                                       QualityOfService qos)
+    {
+        return checked_guard(m_server, &IServerWrapper::publishResourceToRD,
+                             host, connectivityType, resourceHandles, callback,
+                             static_cast<OCQualityOfService>(qos));
+    }
 
+    OCStackResult OCPlatform_impl::deleteResourceFromRD(const std::string& host,
+                                                        OCConnectivityType connectivityType,
+                                                        ResourceHandles& resourceHandles,
+                                                        DeleteResourceCallback callback)
+    {
+        return deleteResourceFromRD(host, connectivityType, resourceHandles, callback,
+                                    m_cfg.QoS);
+    }
+
+    OCStackResult OCPlatform_impl::deleteResourceFromRD(const std::string& host,
+                                                        OCConnectivityType connectivityType,
+                                                        ResourceHandles& resourceHandles,
+                                                        DeleteResourceCallback callback,
+                                                        QualityOfService qos)
+    {
+        return checked_guard(m_server, &IServerWrapper::deleteResourceFromRD,
+                             host, connectivityType, resourceHandles, callback,
+                             static_cast<OCQualityOfService>(qos));
+    }
+#endif
     std::weak_ptr<std::recursive_mutex> OCPlatform_impl::csdkLock()
     {
         return m_csdkLock;
index 06b2083..476d72b 100644 (file)
@@ -59,6 +59,11 @@ 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;
@@ -150,7 +155,7 @@ namespace OC
     void MessageContainer::setPayload(const OCRepPayload* payload)
     {
         const OCRepPayload* pl = payload;
-        while(pl)
+        while (pl)
         {
             OCRepresentation cur;
             cur.setPayload(pl);
@@ -159,7 +164,29 @@ 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;
@@ -657,7 +684,43 @@ 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 32ff64b..c5f10d2 100644 (file)
@@ -80,6 +80,11 @@ if target_os in ['msys_nt', 'windows']:
 if oclib_env.get('WITH_CLOUD'):
        oclib_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
 
+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'])
+
 ######################################################################
 # Source files and Targets
 ######################################################################
index b2d758d..40b1e79 100644 (file)
@@ -50,7 +50,8 @@ if target_os in ['linux']:
        SConscript('csdk/connectivity/test/SConscript')
 
        # Build Security Resource Manager unit tests
-       SConscript('csdk/security/unittest/SConscript')
+       if env.get('SECURED') == '1':
+               SConscript('csdk/security/unittest/SConscript')
 
        # Build C++ unit tests
        SConscript('unittests/SConscript')
@@ -70,7 +71,8 @@ elif target_os == 'windows' and env.get('TEST') == '1':
        SConscript('csdk/connectivity/test/SConscript')
 
        # Build Security Resource Manager unit tests
-       SConscript('csdk/security/unittest/SConscript')
+       if env.get('SECURED') == '1':
+               SConscript('csdk/security/unittest/SConscript')
 
        # Build Provisioning API unit test
        if env.get('SECURED') == '1':
index 2a18ad7..d7e2cf2 100644 (file)
@@ -62,9 +62,11 @@ namespace OCPlatformTest
     {
     }
 
+#ifdef WITH_CLOUD
     void onObserve(const HeaderOptions, const OCRepresentation&, const int&, const int&)
     {
     }
+#endif
 
     void directPairHandler(std::shared_ptr<OCDirectPairing> /*dev*/, OCStackResult /*res*/)
     {
@@ -837,6 +839,7 @@ namespace OCPlatformTest
         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
     }
 
+#ifdef WITH_CLOUD
     //SubscribeDevicePresence Test
     TEST(SubscribeDevicePresenceTest, DISABLED_SubscribeDevicePresenceWithValidParameters)
     {
@@ -877,6 +880,7 @@ namespace OCPlatformTest
                 hostAddress, queryParams, CT_DEFAULT, &onObserve));
         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
     }
+#endif
 
     TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
     {
index 8c956e0..2f92966 100755 (executable)
@@ -51,9 +51,9 @@ 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 resource directory project
+    #if env.get('WITH_RD') == '1':
+        #SConscript('resource-directory/SConscript')
 
 # Build EasySetup module
 if target_os in ['arduino', 'android', 'linux','tizen']:
index 34c122c..f2db819 100644 (file)
@@ -183,8 +183,7 @@ OCStackResult NSCloudPublish(const char *host, const char *query,
 
     const unsigned char *id = (unsigned char *)OCGetServerInstanceIDString();
     NS_LOG_V(DEBUG, "DeviceID: %s", id);
-    tagsPayload = OCCopyTagsResources(NULL, id,
-                                      NULL, OC_DISCOVERABLE, 0, 0, NULL, NULL, OC_RD_PUBLISH_TTL);
+    tagsPayload = OCCopyTagsResources(NULL, id, OC_RD_PUBLISH_TTL);
     if (!tagsPayload)
     {
         goto no_memory;
@@ -232,12 +231,15 @@ OCStackResult NSCloudPublish(const char *host, const char *query,
 
             if (!linksPayload)
             {
-                linksPayload = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL,
+                /* Need to update with Cloud Interface Implementation.
+                 *
+               linksPayload = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL,
                                                     NULL, j, mt);;
                 if (!linksPayload)
                 {
                     goto no_memory;
                 }
+                */
             }
             else
             {
@@ -246,12 +248,15 @@ OCStackResult NSCloudPublish(const char *host, const char *query,
                 {
                     temp = temp->next;
                 }
+                /* Need to update with Cloud Interface Implementation.
+                 *
                 temp->next = OCCopyLinksResources(uri, rt, itf, NULL, 0, NULL,
                                                   NULL, j, mt);
                 if (!temp->next)
                 {
                     goto no_memory;
                 }
+                */
             }
             OCFreeOCStringLL(rt);
             OCFreeOCStringLL(itf);