Introspection support
authorSrikrishna Gurugubelli <srikguru@microsoft.com>
Fri, 13 Jan 2017 23:23:04 +0000 (15:23 -0800)
committerMike Fenelon <mike.fenelon@microsoft.com>
Thu, 19 Jan 2017 23:08:57 +0000 (23:08 +0000)
Change-Id: Ic1524b10e7ab44831ee09503b5a2bb69ad3ff0b8
Signed-off-by: Srikrishna Gurugubelli <srikguru@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16405
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Alex Kelley <alexke@microsoft.com>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
Reviewed-by: Mike Fenelon <mike.fenelon@microsoft.com>
59 files changed:
cloud/samples/client/airconditioner/aircon_controlee.cpp
cloud/samples/client/airconditioner/aircon_controller.cpp
cloud/samples/client/group_invite/group_light_share.cpp
cloud/samples/client/messagequeue/mq_publisher.cpp
cloud/samples/client/messagequeue/mq_subscriber.cpp
cloud/samples/client/thin_light/thin_room_light.cpp
java/jni/JniOcSecurity.cpp
resource/csdk/include/octypes.h
resource/csdk/security/provisioning/sample/cloud/cloudCommon.c
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp
resource/csdk/security/provisioning/sample/sampleserver_mfg.cpp
resource/csdk/security/provisioning/sample/sampleserver_mvjustworks.cpp
resource/csdk/security/provisioning/sample/sampleserver_preconfpin.cpp
resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp
resource/csdk/security/provisioning/sample/subownerclient.c
resource/csdk/security/provisioning/unittest/otmunittest.cpp
resource/csdk/security/provisioning/unittest/sampleserver1.cpp
resource/csdk/security/provisioning/unittest/sampleserver2.cpp
resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp
resource/csdk/security/src/secureresourcemanager.c
resource/csdk/security/src/srmresourcestrings.c
resource/csdk/stack/include/internal/ocresourcehandler.h
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/samples/linux/SimpleClientServer/SConscript
resource/csdk/stack/samples/linux/SimpleClientServer/introspection.json [new file with mode: 0644]
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp
resource/csdk/stack/samples/linux/secure/ocamsservice.cpp
resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp
resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp
resource/csdk/stack/samples/linux/secure/ocserverbasicops.cpp
resource/csdk/stack/src/ocpayloadconvert.c
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c
resource/examples/SConscript
resource/examples/directpairingclient.cpp
resource/examples/light_introspection.json [new file with mode: 0644]
resource/examples/lightserver.cpp
resource/examples/mediaserver.cpp
resource/examples/rdclient.cpp
resource/examples/simpleclient.cpp
resource/examples/simpleserver.cpp
resource/examples/winuiclientgui.cpp
resource/provisioning/examples/cloudClient.cpp
resource/provisioning/examples/provisioningclient.cpp
resource/provisioning/examples/subownerclient.cpp
resource/unittests/OCPlatformTest.cpp
service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c
service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator.cpp
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/submediator.cpp
service/notification/cpp-wrapper/examples/linux/notificationserviceconsumer.cpp
service/notification/examples/linux/notificationconsumer.c
service/notification/examples/linux/notificationprovider.c
service/resource-container/examples/ContainerSampleClient.cpp
service/resource-encapsulation/examples/linux/secureResourceExample/SampleAuthorizedClient.cpp
service/resource-encapsulation/examples/linux/secureResourceExample/SampleSecureServer.cpp

index a18f1fd..e5d33af 100644 (file)
@@ -495,9 +495,16 @@ void handleLoginoutCB(const HeaderOptions &,
     g_callbackLock.notify_all();
 }
 
-static FILE *client_open(const char * /*path*/, const char *mode)
+static FILE *client_open(const char *path, const char *mode)
 {
-    return fopen("./aircon_controlee.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./aircon_controlee.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 OCStackResult SetDeviceInfo()
index 087a631..e5e43b4 100644 (file)
@@ -267,9 +267,16 @@ void presenceDevice(OCStackResult , const unsigned int i, const string &str)
     cout << "Presence received, i=" << i << " str=" << str << endl;
 }
 
-static FILE *client_open(const char * /*path*/, const char *mode)
+static FILE *client_open(const char *path, const char *mode)
 {
-    return fopen("./aircon_controller.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./aircon_controller.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int argc, char *argv[])
index 02c223c..da91c3d 100644 (file)
@@ -319,12 +319,19 @@ void handleLoginoutCB(const HeaderOptions &, const OCRepresentation &rep, const
 
 string g_option;
 
-static FILE *client_open(const char * /*path*/, const char *mode)
+static FILE *client_open(const char *path, const char *mode)
 {
-    string option = "./";
-    option += g_option;
-    option += ".dat";
-    return fopen(option.c_str(), mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        string option = "./";
+        option += g_option;
+        option += ".dat";
+        return fopen(option.c_str(), mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int argc, char **argv)
index 743b794..ad8afdc 100644 (file)
@@ -143,9 +143,16 @@ void handleLoginoutCB(const HeaderOptions &,
     g_callbackLock.notify_all();
 }
 
-static FILE *client_open(const char * /*path*/, const char *mode)
+static FILE *client_open(const char *path, const char *mode)
 {
-    return fopen("./mq_publisher.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./mq_publisher.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int argc, char *argv[])
index fbebe6e..9b876d5 100644 (file)
@@ -157,9 +157,16 @@ void handleLoginoutCB(const HeaderOptions &,
     g_callbackLock.notify_all();
 }
 
-static FILE *client_open(const char * /*path*/, const char *mode)
+static FILE *client_open(const char *path, const char *mode)
 {
-    return fopen("./mq_subscriber.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./mq_subscriber.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int argc, char *argv[])
index d8df6d0..a54e72b 100644 (file)
@@ -636,9 +636,16 @@ void PrintUsage()
 
 }
 
-static FILE *client_open(const char * /*path*/, const char *mode)
+static FILE *client_open(const char *path, const char *mode)
 {
-    return fopen("./thin_resource_server.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./thin_resource_server.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int argc, char *argv[])
index 54821ee..a0d8dae 100644 (file)
@@ -54,7 +54,14 @@ namespace OC {
 
     FILE* JniOcSecurity::client_open(const char *path, const char *mode)
     {
-        LOGI("Opening SVR Database file '%s' with mode '%s'\n", store_path().c_str(), mode);
-        return fopen(store_path().c_str(), mode);
+        if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+        {
+            LOGI("Opening SVR Database file '%s' with mode '%s'\n", store_path().c_str(), mode);
+            return fopen(store_path().c_str(), mode); 
+        }
+        else
+        {
+            return fopen(path, mode);
+        }
     }
 }
index 481db4c..3083503 100755 (executable)
@@ -75,6 +75,11 @@ extern "C" {
 /** KeepAlive URI.*/
 #define OC_RSRVD_KEEPALIVE_URI                "/oic/ping"
 
+/** Introspection URI.*/
+#define OC_RSRVD_INTROSPECTION_URI            "/oic/introspection"
+
+/** Introspection payload URI.*/
+#define OC_RSRVD_INTROSPECTION_PAYLOAD_URI    "/oic/introspection/payload"
 
 /** Presence */
 
@@ -167,6 +172,11 @@ extern "C" {
 /** To represent content type with MQ Topic.*/
 #define OC_RSRVD_RESOURCE_TYPE_MQ_TOPIC  "oic.wk.ps.topic"
 
+/** To represent resource type with introspection.*/
+#define OC_RSRVD_RESOURCE_TYPE_INTROSPECTION "oic.wk.introspection"
+
+/** To represent resource type with introspection payload.*/
+#define OC_RSRVD_RESOURCE_TYPE_INTROSPECTION_PAYLOAD "oic.wk.introspection.payload"
 
 /** To represent interface.*/
 #define OC_RSRVD_INTERFACE              "if"
@@ -225,6 +235,12 @@ extern "C" {
 /** For security.*/
 #define OC_RSRVD_SECURE                 "sec"
 
+/** Security Database persistent store name(json).*/
+#define OC_SECURITY_DB_FILE_NAME        "oic_svr_db.json"
+
+/** Security Database persistent store name(dat).*/
+#define OC_SECURITY_DB_DAT_FILE_NAME    "oic_svr_db.dat"
+
 /** Port. */
 #define OC_RSRVD_HOSTING_PORT           "port"
 
@@ -311,6 +327,42 @@ extern "C" {
 #define OC_RSRVD_PROTOCOL_INDEPENDENT_ID "piid"
 
 /**
+*  Introspection.
+*/
+/** Name.*/
+#define OC_RSRVD_INTROSPECTION_NAME     "name"
+
+/** Value of name.*/
+#define OC_RSRVD_INTROSPECTION_NAME_VALUE "Introspection"
+
+/** Url info Object.*/
+#define OC_RSRVD_INTROSPECTION_URL_INFO "urlInfo"
+
+/** Url property.*/
+#define OC_RSRVD_INTROSPECTION_URL      "url"
+
+/** Protocol property.*/
+#define OC_RSRVD_INTROSPECTION_PROTOCOL    "protocol"
+
+/** Content-Type property.*/
+#define OC_RSRVD_INTROSPECTION_CONTENT_TYPE "content-type"
+
+/** Content-Type property value.*/
+#define OC_RSRVD_INTROSPECTION_CONTENT_TYPE_VALUE "application/cbor"
+
+/** Version property.*/
+#define OC_RSRVD_INTROSPECTION_VERSION    "version"
+
+/** Version property value.*/
+#define OC_RSRVD_INTROSPECTION_VERSION_VALUE 1
+
+/** Introspection payload data property name.*/
+#define OC_RSRVD_INTROSPECTION_DATA_NAME  "data"
+
+/** Introspection persistent store name.*/
+#define OC_INTROSPECTION_FILE_NAME      "introspection.json"
+
+/**
  *  These provide backward compatibility - their use is deprecated.
  */
 #ifndef GOING_AWAY
index c0223b2..fd32c48 100644 (file)
@@ -598,8 +598,14 @@ static void userRequests(void *data)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    OC_UNUSED(path);
-    return fopen(fname, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(fname, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 /**
index b84ae26..e2266cf 100644 (file)
@@ -25,7 +25,7 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-
+#include <payload_logging.h>
 #include "utlist.h"
 #include "logger.h"
 #include "oic_malloc.h"
@@ -73,6 +73,8 @@ extern "C"
 #endif //MULTIPLE_OWNER
 #define _80_SELECT_PROTOCOL_        80
 #define _81_SELECT_VERIF_METHOD_    81
+#define _91_SELECT_INTROSPECTION_METHOD_    91
+#define _92_SELECT_INTROSPECTION_PAYLOAD_METHOD_    92
 #define _99_EXIT_PRVN_CLT_          99
 
 #define ACL_RESRC_MAX_NUM   16
@@ -1992,6 +1994,218 @@ static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_c
     return lst_cnt;
 }
 
+const char* getResult(OCStackResult result)
+{
+    switch (result)
+    {
+    case OC_STACK_OK:
+        return "OC_STACK_OK";
+    case OC_STACK_RESOURCE_CREATED:
+        return "OC_STACK_RESOURCE_CREATED";
+    case OC_STACK_RESOURCE_DELETED:
+        return "OC_STACK_RESOURCE_DELETED";
+    case OC_STACK_RESOURCE_CHANGED:
+        return "OC_STACK_RESOURCE_CHANGED";
+    case OC_STACK_INVALID_URI:
+        return "OC_STACK_INVALID_URI";
+    case OC_STACK_INVALID_QUERY:
+        return "OC_STACK_INVALID_QUERY";
+    case OC_STACK_INVALID_IP:
+        return "OC_STACK_INVALID_IP";
+    case OC_STACK_INVALID_PORT:
+        return "OC_STACK_INVALID_PORT";
+    case OC_STACK_INVALID_CALLBACK:
+        return "OC_STACK_INVALID_CALLBACK";
+    case OC_STACK_INVALID_METHOD:
+        return "OC_STACK_INVALID_METHOD";
+    case OC_STACK_NO_MEMORY:
+        return "OC_STACK_NO_MEMORY";
+    case OC_STACK_COMM_ERROR:
+        return "OC_STACK_COMM_ERROR";
+    case OC_STACK_INVALID_PARAM:
+        return "OC_STACK_INVALID_PARAM";
+    case OC_STACK_NOTIMPL:
+        return "OC_STACK_NOTIMPL";
+    case OC_STACK_NO_RESOURCE:
+        return "OC_STACK_NO_RESOURCE";
+    case OC_STACK_RESOURCE_ERROR:
+        return "OC_STACK_RESOURCE_ERROR";
+    case OC_STACK_SLOW_RESOURCE:
+        return "OC_STACK_SLOW_RESOURCE";
+    case OC_STACK_NO_OBSERVERS:
+        return "OC_STACK_NO_OBSERVERS";
+    case OC_STACK_UNAUTHORIZED_REQ:
+        return "OC_STACK_UNAUTHORIZED_REQ";
+    case OC_STACK_ERROR:
+        return "OC_STACK_ERROR";
+    default:
+        return "UNKNOWN";
+    }
+}
+
+OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle,
+    OCClientResponse* clientResponse)
+{
+    if (clientResponse == NULL)
+    {
+        OIC_LOG(INFO, TAG, "getReqCB received NULL clientResponse");
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    OIC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
+    OIC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
+    OIC_LOG_V(INFO, TAG, "Payload Size: %d", 
+              ((OCRepPayload*)clientResponse->payload)->values->str);
+    OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
+    OIC_LOG(INFO, TAG, ("=============> Get Response"));
+
+    if (clientResponse->numRcvdVendorSpecificHeaderOptions > 0)
+    {
+        OIC_LOG(INFO, TAG, "Received vendor specific options");
+        uint8_t i = 0;
+        OCHeaderOption* rcvdOptions = clientResponse->rcvdVendorSpecificHeaderOptions;
+        for (i = 0; i < clientResponse->numRcvdVendorSpecificHeaderOptions; i++)
+        {
+            if ((rcvdOptions[i]).protocolID == OC_COAP_ID)
+            {
+                OIC_LOG_V(INFO, TAG, "Received option with OC_COAP_ID and ID %u with",
+                    (rcvdOptions[i]).optionID);
+
+                OIC_LOG_BUFFER(INFO, TAG, rcvdOptions[i].optionData,
+                    MAX_HEADER_OPTION_DATA_LENGTH);
+            }
+        }
+    }
+    g_doneCB = true; // flag done
+    return OC_STACK_DELETE_TRANSACTION;
+}
+
+int obtainUserSelectionForDeviceNumber(int numDevices)
+{
+    int dev_num = -1;
+    for (; ; )
+    {
+        printf("   > Enter Device Number: ");
+        for (int ret = 0; 1 != ret; )
+        {
+            ret = scanf("%d", &dev_num);
+            for (; 0x20 <= getchar(); );  // for removing overflow garbages
+                                          // '0x20<=code' is character region
+        }
+        if ((0 < dev_num) && (numDevices >= dev_num))
+        {
+            break;
+        }
+        printf("     Entered Wrong Number. Please Enter Again\n");
+    }
+    return dev_num;
+}
+
+void selectIntrospectionMethod()
+{
+    OCStackResult ret;
+    OCCallbackData cbData;
+    OCDoHandle handle;
+    static OCDevAddr serverAddr;
+    cbData.cb = &getReqCB;
+    int dev_num = 1;
+    OCProvisionDev_t *device = NULL;
+
+    // check |own_list| for devices that can be used for introspection
+    if (!g_own_list || (1 > g_own_cnt))
+    {
+        printf("   > Owned Device List, to do introspection, is Empty\n");
+        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
+        return;
+    }
+
+    if (g_own_cnt != 1)
+    {
+        // we have more than one option - ask user to select one
+        printf("   > Multiple devices found - select a device for Introspection\n");
+        dev_num = obtainUserSelectionForDeviceNumber(g_own_cnt);
+    }
+
+    device = getDevInst(g_own_list, dev_num); 
+    if (device)
+    {
+        serverAddr = device->endpoint;
+        cbData.context = NULL;
+        cbData.cd = NULL;
+        OIC_LOG_V(INFO, TAG, "Performing Introspection");
+        g_doneCB = false;
+
+        ret = OCDoResource(&handle, OC_REST_GET, OC_RSRVD_INTROSPECTION_URI, &serverAddr,
+            NULL,
+            CT_ADAPTER_IP, OC_LOW_QOS, &cbData, NULL, 0);
+
+        if (ret != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, TAG, "OCDoResource returned error %d with method", ret);
+        }
+        if (waitCallbackRet())  // input |g_doneCB| flag implicitly
+        {
+            OIC_LOG(ERROR, TAG, "selectIntrospectionMethod callback error");
+        }
+    }
+    else
+    {
+        OIC_LOG(ERROR, TAG, "Selected device does not exist");
+    }
+}
+
+void selectIntrospectionPayloadMethod()
+{
+    OCStackResult ret;
+    OCCallbackData cbData;
+    OCDoHandle handle;
+    static OCDevAddr serverAddr;
+    cbData.cb = &getReqCB;
+    int dev_num = 1;
+    OCProvisionDev_t *device = NULL;
+
+    // check |own_list| for devices that can be used for introspection payload
+    if (!g_own_list || (1 > g_own_cnt))
+    {
+        printf("   > Owned Device List, to get introspection payload, is Empty\n");
+        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
+        return;
+    }
+
+    if (g_own_cnt != 1)
+    {
+        // we have more than one option - ask user to select one
+        printf("   > Multiple devices found - select a device for Introspection payload\n");
+        dev_num = obtainUserSelectionForDeviceNumber(g_own_cnt);
+    }
+
+    device = getDevInst(g_own_list, dev_num);
+    if (device)
+    {
+        serverAddr = device->endpoint;
+        cbData.context = g_ctx;
+        cbData.cd = NULL;
+        OIC_LOG_V(INFO, TAG, "Performing Introspection Payload");
+        g_doneCB = false;
+        ret = OCDoResource(&handle, OC_REST_GET, OC_RSRVD_INTROSPECTION_PAYLOAD_URI, &serverAddr,
+            NULL,
+            CT_ADAPTER_IP, OC_LOW_QOS, &cbData, NULL, 0);
+
+        if (ret != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, TAG, "OCDoResource returned error %d with method", ret);
+        }
+        if (waitCallbackRet())  // input |g_doneCB| flag implicitly
+        {
+            OIC_LOG(ERROR, TAG, "selectIntrospectionPayloadMethod callback error");
+        }
+    }
+    else
+    {
+        OIC_LOG(ERROR, TAG, "Selected device does not exist");
+    }
+}
+
 static void printUuid(const OicUuid_t* uid)
 {
     for(int i=0; i<UUID_LENGTH; )
@@ -2006,12 +2220,17 @@ static void printUuid(const OicUuid_t* uid)
 
 static FILE* fopen_prvnMng(const char* path, const char* mode)
 {
-    (void)path;  // unused |path| parameter
-
-    // input |g_svr_db_fname| internally by force, not using |path| parameter
-    // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
-    // with its own |SVR_DB_FILE_NAME|
-    return fopen(SVR_DB_FILE_NAME, mode);
+    if (0 == strncmp(path, OC_SECURITY_DB_DAT_FILE_NAME, strlen(OC_SECURITY_DB_DAT_FILE_NAME)))
+    {
+        // input |g_svr_db_fname| internally by force, not using |path| parameter
+        // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
+        // with its own |SVR_DB_FILE_NAME|
+        return fopen(SVR_DB_FILE_NAME, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 static int waitCallbackRet(void)
@@ -2194,8 +2413,12 @@ static void printMenu(void)
     printf("** [H] SELECT VERIFICATION OPTION\n");
     printf("** 81. Select verification method\n\n");
 #endif
-    printf("** [I] EXIT PROVISIONING CLIENT\n");
 
+    printf("** [I] SELECT INTROSPECTION OPTION\n");
+    printf("** 91. Select Get Introspection Resource\n");
+    printf("** 92. Select Get Introspection Payload\n\n");
+
+    printf("** [J] EXIT PROVISIONING CLIENT\n");
     printf("** 99. Exit Provisionong Client\n\n");
 
     printf("************************************************************\n\n");
@@ -2405,6 +2628,12 @@ int main()
         case _81_SELECT_VERIF_METHOD_:
             selectVerifMethod();
             break;
+        case _91_SELECT_INTROSPECTION_METHOD_:
+            selectIntrospectionMethod();
+            break;
+        case _92_SELECT_INTROSPECTION_PAYLOAD_METHOD_:
+            selectIntrospectionPayloadMethod();
+            break;
         case _99_EXIT_PRVN_CLT_:
             goto PMCLT_ERROR;
         default:
index 94d79d0..6b7c9ed 100644 (file)
@@ -407,8 +407,14 @@ void handleSigInt(int signum)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(CRED_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index c347a42..775deb6 100644 (file)
@@ -405,8 +405,14 @@ void handleSigInt(int signum)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(CRED_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index c45fb2d..77233e1 100644 (file)
@@ -446,8 +446,14 @@ void handleSigInt(int signum)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(CRED_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index 0e315ec..8d91882 100644 (file)
@@ -407,8 +407,14 @@ void handleSigInt(int signum)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(CRED_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index c52456e..00f025f 100644 (file)
@@ -443,8 +443,15 @@ void handleSigInt(int signum)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(CRED_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);
+    }
+    else
+    {
+        // unknown file request - try to open it by the given name
+        return fopen(path, mode);
+    }
 }
 
 void DisplayPinCB(char *pin, size_t pinSize, void *context)
index 7751e84..8fd6020 100644 (file)
@@ -831,12 +831,17 @@ static void printUuid(const OicUuid_t* uid)
 
 static FILE* fopen_prvnMng(const char* path, const char* mode)
 {
-    (void)path;  // unused |path| parameter
-
-    // input |g_svr_db_fname| internally by force, not using |path| parameter
-    // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
-    // with its own |SVR_DB_FILE_NAME|
-    return fopen(SVR_DB_FILE_NAME, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        // input |g_svr_db_fname| internally by force, not using |path| parameter
+        // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
+        // with its own |SVR_DB_FILE_NAME|
+        return fopen(SVR_DB_FILE_NAME, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 static int waitCallbackRet(void)
index 1bbcfa7..83a4d6a 100644 (file)
@@ -272,16 +272,21 @@ static void GetCurrentWorkingDirectory(char* buf, size_t bufsize)
 
 static FILE* fopen_prvnMng(const char* path, const char* mode)
 {
-    (void)path;  // unused |path| parameter
-
-    // input |g_svr_db_fname| internally by force, not using |path| parameter
-    // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
-    // with its own |SVR_DB_FILE_NAME|
-    char cwd[1024] = {0};
-    char svr_db_path[1024] = {0};
-    GetCurrentWorkingDirectory(cwd, sizeof(cwd));
-    snprintf(svr_db_path, sizeof(svr_db_path), "%s%s", cwd, SVR_DB_PATH);
-    return fopen(svr_db_path, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        // input |g_svr_db_fname| internally by force, not using |path| parameter
+        // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
+        // with its own |SVR_DB_FILE_NAME|
+        char cwd[1024] = { 0 };
+        char svr_db_path[1024] = { 0 };
+        GetCurrentWorkingDirectory(cwd, sizeof(cwd));
+        snprintf(svr_db_path, sizeof(svr_db_path), "%s%s", cwd, SVR_DB_PATH);
+        return fopen(svr_db_path, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 // callback function(s) for provisioning client using C-level provisioning API
index 5b1fc82..6849a28 100644 (file)
@@ -499,12 +499,18 @@ static void GetCurrentWorkingDirectory(char* buf, size_t bufsize)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    char cwd[1024] = {0};
-    char cred_path[1024] = {0};
-    GetCurrentWorkingDirectory(cwd, sizeof(cwd));
-    snprintf(cred_path, sizeof(cred_path), "%s%s", cwd, CRED_FILE);
-    return fopen(cred_path, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        char cwd[1024] = { 0 };
+        char cred_path[1024] = { 0 };
+        GetCurrentWorkingDirectory(cwd, sizeof(cwd));
+        snprintf(cred_path, sizeof(cred_path), "%s%s", cwd, CRED_FILE);
+        return fopen(cred_path, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index bb70573..7c176d2 100644 (file)
@@ -499,12 +499,18 @@ static void GetCurrentWorkingDirectory(char* buf, size_t bufsize)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    char cwd[1024] = {0};
-    char cred_path[1024] = {0};
-    GetCurrentWorkingDirectory(cwd, sizeof(cwd));
-    snprintf(cred_path, sizeof(cred_path), "%s%s", cwd, CRED_FILE);
-    return fopen(cred_path, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        char cwd[1024] = { 0 };
+        char cred_path[1024] = { 0 };
+        GetCurrentWorkingDirectory(cwd, sizeof(cwd));
+        snprintf(cred_path, sizeof(cred_path), "%s%s", cwd, CRED_FILE);
+        return fopen(cred_path, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index 686cecf..5a0ef46 100644 (file)
@@ -174,9 +174,16 @@ TEST(SRPProvisionDirectPairingTest, Nullcallback)
 const char *SECURE_RESOURCE_PROVIDER_TEST_FILE_NAME = "secureresourceprovider.dat";
 OCPersistentStorage ps = { NULL, NULL, NULL, NULL, NULL};
 
-static FILE* TestFopen(const char * /*path*/, const char *mode)
+static FILE* TestFopen(const char *path, const char *mode)
 {
-    return fopen(SECURE_RESOURCE_PROVIDER_TEST_FILE_NAME, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(SECURE_RESOURCE_PROVIDER_TEST_FILE_NAME, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 void SetPersistentHandler(OCPersistentStorage *ps)
index 32427cb..a8cd632 100644 (file)
@@ -45,8 +45,6 @@ static CARequestCallback gRequestHandler = NULL;
 static CAResponseCallback gResponseHandler = NULL;
 //Error Callback handler
 static CAErrorCallback gErrorHandler = NULL;
-//Persistent Storage callback handler for open/read/write/close/unlink
-static OCPersistentStorage *gPersistentStorageHandler =  NULL;
 //Provisioning response callback
 static SPResponseCallback gSPResponseHandler = NULL;
 
@@ -342,18 +340,12 @@ OCStackResult SRMRegisterHandler(CARequestCallback reqHandler,
 OCStackResult SRMRegisterPersistentStorageHandler(OCPersistentStorage* persistentStorageHandler)
 {
     OIC_LOG(DEBUG, TAG, "SRMRegisterPersistentStorageHandler !!");
-    if(!persistentStorageHandler)
-    {
-        OIC_LOG(ERROR, TAG, "The persistent storage handler is invalid");
-        return OC_STACK_INVALID_PARAM;
-    }
-    gPersistentStorageHandler = persistentStorageHandler;
-    return OC_STACK_OK;
+    return OCRegisterPersistentStorageHandler(persistentStorageHandler);
 }
 
 OCPersistentStorage* SRMGetPersistentStorageHandler()
 {
-    return gPersistentStorageHandler;
+    return OCGetPersistentStorageHandler();
 }
 
 OCStackResult SRMInitSecureResources()
index 09ca213..4f82686 100644 (file)
@@ -22,8 +22,8 @@
 #include "securevirtualresourcetypes.h"
 #include "octypes.h"
 
-const char * SVR_DB_FILE_NAME = "oic_svr_db.json";
-const char * SVR_DB_DAT_FILE_NAME = "oic_svr_db.dat";
+const char * SVR_DB_FILE_NAME = OC_SECURITY_DB_FILE_NAME;
+const char * SVR_DB_DAT_FILE_NAME = OC_SECURITY_DB_DAT_FILE_NAME;
 
 //AMACL
 const char * OIC_RSRC_TYPE_SEC_AMACL = "oic.r.amacl";
index 5d2ac03..7515caa 100644 (file)
@@ -86,6 +86,12 @@ typedef enum
     OC_KEEPALIVE_RESOURCE_URI,
 #endif
 
+    /** "/oic/introspection" .*/
+    OC_INTROSPECTION_URI,
+
+    /** "/oic/introspection/payload" .*/
+    OC_INTROSPECTION_PAYLOAD_URI,
+
     /** Max items in the list */
     OC_MAX_VIRTUAL_RESOURCES    //<s Max items in the list
 
index 92d9e0a..cbc01c8 100644 (file)
@@ -778,6 +778,14 @@ OCStackResult OCSetPropertyValue(OCPayloadType type, const char *propName, const
  */
 OCStackResult OCGetPropertyValue(OCPayloadType type, const char *propName, void **value);
 
+/**
+* Get the registered persistent storage handler. All modules must use this to obtain access to 
+* persistent storage.
+*
+* @return pointer to OCPersistentStorage structure on success and NULL otherwise.
+*/
+OCPersistentStorage *OCGetPersistentStorageHandler();
+
 #ifdef __cplusplus
 }
 #endif // __cplusplus
index 8e6a94a..8a9699d 100644 (file)
-#******************************************************************
-#
-# Copyright 2014 Intel Mobile Communications GmbH 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.
-#
-#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-thread_env = SConscript('#build_common/thread.scons')
-samples_env = thread_env.Clone()
-target_os = samples_env.get('TARGET_OS')
-with_ra = samples_env.get ('WITH_RA')
-
-######################################################################
-# Build flags
-######################################################################
-with_upstream_libcoap = samples_env.get('WITH_UPSTREAM_LIBCOAP')
-if with_upstream_libcoap == '1':
-       # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.
-       samples_env.AppendUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include'])
-else:
-       # For bring up purposes only, the forked version will live here.
-       samples_env.AppendUnique(CPPPATH = ['../../../../../connectivity/lib/libcoap-4.1.1/include'])
-
-samples_env.PrependUnique(CPPPATH = [
-               '../../../../logger/include',
-               '../../../../include',
-               '../../../../stack/include',
-               '../../../../security/include',
-               '../../../../../../extlibs/boost/boost',
-               '../../../../../oc_logger/include',
-               ])
-
-compiler = samples_env.get('CXX')
-if 'g++' in compiler:
-       samples_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
-
-samples_env.AppendUnique(RPATH = [samples_env.get('BUILD_DIR')])
-samples_env.AppendUnique(LIBPATH = [samples_env.get('BUILD_DIR')])
-
-samples_env.PrependUnique(LIBS = ['octbstack', 'ocsrm', 'connectivity_abstraction', 'coap'])
-
-if target_os not in ['arduino', 'windows', 'darwin', 'ios', 'msys_nt']:
-       samples_env.AppendUnique(LIBS = ['rt'])
-
-if target_os not in ['windows']:
-       samples_env.PrependUnique(LIBS = ['m'])
-
-if samples_env.get('SECURED') == '1':
-       samples_env.AppendUnique(LIBS = ['tinydtls'])
-
-if target_os in ['windows']:
-       samples_env.AppendUnique(LIBS = ['ws2_32'])
-
-samples_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-
-######################################################################
-# Source files and Targets
-######################################################################
-ocserver         = samples_env.Program('ocserver', ['ocserver.cpp', 'common.cpp'])
-if samples_env.get('ROUTING') == 'GW':
-       ocrouting        = samples_env.Program('ocrouting', ['ocrouting.cpp', 'common.cpp'])
-occlient         = samples_env.Program('occlient', ['occlient.cpp', 'common.cpp'])
-ocserverslow     = samples_env.Program('ocserverslow', ['ocserverslow.cpp', 'common.cpp'])
-occlientslow     = samples_env.Program('occlientslow', ['occlientslow.cpp', 'common.cpp'])
-ocservercoll     = samples_env.Program('ocservercoll', ['ocservercoll.cpp', 'common.cpp'])
-occlientcoll     = samples_env.Program('occlientcoll', ['occlientcoll.cpp', 'common.cpp'])
-ocserverbasicops = samples_env.Program('ocserverbasicops', ['ocserverbasicops.cpp', 'common.cpp'])
-occlientbasicops = samples_env.Program('occlientbasicops', ['occlientbasicops.cpp', 'common.cpp'])
-if with_ra:
-       ocremoteaccessclient = samples_env.Program('ocremoteaccessclient',
-                                               ['ocremoteaccessclient.cpp','common.cpp'])
-
-list_of_samples = [ocserver, occlient,
-                               ocservercoll, occlientcoll,
-                               ocserverbasicops, occlientbasicops,
-                               ocserverslow, occlientslow
-                ]
-if with_ra:
-       list_of_samples.append (ocremoteaccessclient)
-Alias("samples", list_of_samples)
-
-samples_env.AppendTarget('samples')
+#******************************************************************\r
+#\r
+# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.\r
+#\r
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+#      http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+#\r
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+thread_env = SConscript('#build_common/thread.scons')\r
+samples_env = thread_env.Clone()\r
+target_os = samples_env.get('TARGET_OS')\r
+with_ra = samples_env.get ('WITH_RA')\r
+\r
+######################################################################\r
+# Build flags\r
+######################################################################\r
+with_upstream_libcoap = samples_env.get('WITH_UPSTREAM_LIBCOAP')\r
+if with_upstream_libcoap == '1':\r
+       # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.\r
+       samples_env.AppendUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include'])\r
+else:\r
+       # For bring up purposes only, the forked version will live here.\r
+       samples_env.AppendUnique(CPPPATH = ['../../../../../connectivity/lib/libcoap-4.1.1/include'])\r
+\r
+samples_env.PrependUnique(CPPPATH = [\r
+               '../../../../logger/include',\r
+               '../../../../include',\r
+               '../../../../stack/include',\r
+               '../../../../security/include',\r
+               '../../../../../../extlibs/boost/boost',\r
+               '../../../../../oc_logger/include',\r
+               ])\r
+\r
+compiler = samples_env.get('CXX')\r
+if 'g++' in compiler:\r
+       samples_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])\r
+\r
+samples_env.AppendUnique(RPATH = [samples_env.get('BUILD_DIR')])\r
+samples_env.AppendUnique(LIBPATH = [samples_env.get('BUILD_DIR')])\r
+\r
+samples_env.PrependUnique(LIBS = ['octbstack', 'ocsrm', 'connectivity_abstraction', 'coap'])\r
+\r
+if target_os not in ['arduino', 'windows', 'darwin', 'ios', 'msys_nt']:\r
+       samples_env.AppendUnique(LIBS = ['rt'])\r
+\r
+if target_os not in ['windows']:\r
+       samples_env.PrependUnique(LIBS = ['m'])\r
+\r
+if samples_env.get('SECURED') == '1':\r
+       samples_env.AppendUnique(LIBS = ['tinydtls'])\r
+\r
+if target_os in ['windows']:\r
+       samples_env.AppendUnique(LIBS = ['ws2_32'])\r
+\r
+samples_env.AppendUnique(CPPDEFINES = ['TB_LOG'])\r
+\r
+src_dir = samples_env.get('SRC_DIR')\r
+sample_src_dir = src_dir + '/resource/csdk/stack/samples/linux/SimpleClientServer/'\r
+sample_build_dir = samples_env.get('BUILD_DIR') +'/resource/csdk/stack/samples/linux/SimpleClientServer/'\r
+\r
+\r
+introspectionJson = samples_env.Install(sample_build_dir,\r
+                                        sample_src_dir + 'introspection.json')\r
+\r
+\r
+######################################################################\r
+# Source files and Targets\r
+######################################################################\r
+ocserver         = samples_env.Program('ocserver', ['ocserver.cpp', 'common.cpp'])\r
+if samples_env.get('ROUTING') == 'GW':\r
+       ocrouting        = samples_env.Program('ocrouting', ['ocrouting.cpp', 'common.cpp'])\r
+occlient         = samples_env.Program('occlient', ['occlient.cpp', 'common.cpp'])\r
+ocserverslow     = samples_env.Program('ocserverslow', ['ocserverslow.cpp', 'common.cpp'])\r
+occlientslow     = samples_env.Program('occlientslow', ['occlientslow.cpp', 'common.cpp'])\r
+ocservercoll     = samples_env.Program('ocservercoll', ['ocservercoll.cpp', 'common.cpp'])\r
+occlientcoll     = samples_env.Program('occlientcoll', ['occlientcoll.cpp', 'common.cpp'])\r
+ocserverbasicops = samples_env.Program('ocserverbasicops', ['ocserverbasicops.cpp', 'common.cpp'])\r
+occlientbasicops = samples_env.Program('occlientbasicops', ['occlientbasicops.cpp', 'common.cpp'])\r
+if with_ra:\r
+       ocremoteaccessclient = samples_env.Program('ocremoteaccessclient',\r
+                                               ['ocremoteaccessclient.cpp','common.cpp'])\r
+\r
+list_of_samples = [ocserver, occlient,\r
+                               ocservercoll, occlientcoll,\r
+                               ocserverbasicops, occlientbasicops,\r
+                               ocserverslow, occlientslow\r
+                ]\r
+if with_ra:\r
+       list_of_samples.append (ocremoteaccessclient)\r
+Alias("samples", list_of_samples)\r
+\r
+samples_env.AppendTarget('samples')\r
diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/introspection.json b/resource/csdk/stack/samples/linux/SimpleClientServer/introspection.json
new file mode 100644 (file)
index 0000000..baab37f
--- /dev/null
@@ -0,0 +1,272 @@
+{\r
+    "swagger": "2.0",\r
+    "info": {\r
+      "title": "my_example_device",\r
+      "version": "my device version"\r
+    },\r
+\r
+\r
+    "schemes": [\r
+        "http"\r
+    ],\r
+    "consumes": [\r
+        "application/json"\r
+    ],\r
+    "produces": [\r
+        "application/json"\r
+    ],\r
+    "paths": {\r
+       "/switch": {\r
+\r
+          "get": {\r
+\r
+\r
+            "parameters": [\r
+               {\r
+                 "name": "if",\r
+                 "in": "query",\r
+                 "description": "",\r
+                 "enum": [ "oic.if.a","oic.if.baseline" ],\r
+\r
+                 "type": "string"\r
+                }\r
+            ],\r
+            "responses": {\r
+              "200" : {\r
+                  "description" : "",\r
+                  "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/BinarySwitch"\r
+                  }\r
+               }\r
+            }\r
+\r
+           },\r
+\r
+          "post": {\r
+\r
+\r
+            "parameters": [\r
+               {\r
+                 "name": "if",\r
+                 "in": "query",\r
+                 "description": "",\r
+                 "enum": [ "oic.if.a","oic.if.baseline" ],\r
+\r
+                 "type": "string"\r
+                }\r
+                 ,{\r
+                  "name": "body",\r
+                  "in": "body",\r
+                  "required": false,\r
+                   "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/BinarySwitch"\r
+                  }\r
+\r
+                }\r
+            ],\r
+            "responses": {\r
+              "200" : {\r
+                  "description" : "",\r
+                   "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/BinarySwitch"\r
+                  }\r
+\r
+               }\r
+            }\r
+          }\r
+        },\r
+       "/brightness": {\r
+\r
+          "get": {\r
+\r
+\r
+            "parameters": [\r
+               {\r
+                 "name": "if",\r
+                 "in": "query",\r
+                 "description": "",\r
+                 "enum": [ "oic.if.a","oic.if.baseline" ],\r
+\r
+                 "type": "string"\r
+                }\r
+            ],\r
+            "responses": {\r
+              "200" : {\r
+                  "description" : "",\r
+                 "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/Brightness"\r
+                  }\r
+               }\r
+            }\r
+\r
+           },\r
+\r
+          "post": {\r
+\r
+\r
+            "parameters": [\r
+               {\r
+                 "name": "if",\r
+                 "in": "query",\r
+                 "description": "",\r
+                 "enum": [ "oic.if.a","oic.if.baseline" ],\r
+\r
+                 "type": "string"\r
+                }\r
+                 ,{\r
+                  "name": "body",\r
+                  "in": "body",\r
+                  "required": false,\r
+                 "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/Brightness"\r
+                  }\r
+                }\r
+            ],\r
+            "responses": {\r
+              "200" : {\r
+                  "description" : "",\r
+                 "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/Brightness"\r
+                  }\r
+\r
+               }\r
+            }\r
+\r
+          }\r
+        }\r
+    },\r
+    "definitions":\r
+    {\r
+        "BinarySwitch": {\r
+           "type": "object",\r
+           "required": [\r
+             "id"\r
+           ],\r
+           "properties":  {\r
+               "value": {\r
+                  "type": "boolean",\r
+                  "description": "Status of the switch"\r
+                },\r
+                "rt": {\r
+                "type": "array",\r
+                "items" : [\r
+                  {\r
+                    "type" : "string",\r
+                    "maxLength": 64\r
+                  }\r
+                ],\r
+                "minItems" : 1,\r
+                "description": "Resource Type",\r
+                "readOnly" : true,\r
+                "default" : [ "oic.r.switch.binary" ]\r
+                },\r
+                "if": {\r
+                    "type": "array",\r
+                    "description": "The interface set supported by this resource",\r
+                    "readOnly" : true,\r
+                    "items": {\r
+                        "type": "string",\r
+                        "enum": [\r
+                            "oic.if.baseline",\r
+                            "oic.if.a"\r
+                        ]\r
+                    }\r
+                },\r
+                "p": {\r
+                    "type": "integer",\r
+                    "description": "Bitmap indicating observable and discoverable",\r
+                    "readOnly" : true\r
+                },\r
+                "n": {\r
+                    "type": "string",\r
+                    "description": "Friendly name of the resource",\r
+                    "readOnly" : true\r
+                },\r
+                "id": {\r
+                    "type": "string",\r
+                    "description": "Instance ID of this specific resource",\r
+                    "readOnly" : true\r
+                },\r
+                "range": {\r
+                    "type": "array",\r
+                    "description": "The valid range for the value Property",\r
+                    "readOnly" : true,\r
+                    "minItems": 2,\r
+                    "maxItems": 2,\r
+                    "items": {\r
+                        "type": "number"\r
+                    }\r
+                }\r
+            }\r
+        },\r
+        "Brightness": {\r
+           "type": "object",\r
+           "required": [\r
+             "id"\r
+           ],\r
+           "properties":  {\r
+               "brighness": {\r
+                  "type": "integer",\r
+                  "description": "Current sensed or set value for Brightness"\r
+                },\r
+                "rt": {\r
+                "type": "array",\r
+                "items" : [\r
+                  {\r
+                    "type" : "string",\r
+                    "maxLength": 64\r
+                  }\r
+                ],\r
+                "minItems" : 1,\r
+                "description": "Resource Type",\r
+                "readOnly" : true,\r
+                "default" : [ "oic.r.light.brightness" ]\r
+                },\r
+                "if": {\r
+                    "type": "array",\r
+                    "description": "The interface set supported by this resource",\r
+                    "readOnly" : true,\r
+                    "items": {\r
+                        "type": "string",\r
+                        "enum": [\r
+                            "oic.if.baseline",\r
+                            "oic.if.a"\r
+                        ]\r
+                    }\r
+                },\r
+                "p": {\r
+                    "type": "integer",\r
+                    "description": "Bitmap indicating observable and discoverable",\r
+                    "readOnly" : true\r
+                },\r
+                "n": {\r
+                    "type": "string",\r
+                    "description": "Friendly name of the resource",\r
+                    "readOnly" : true\r
+                },\r
+                "id": {\r
+                    "type": "string",\r
+                    "description": "Instance ID of this specific resource",\r
+                    "readOnly" : true\r
+                },\r
+                "range": {\r
+                    "type": "array",\r
+                    "description": "The valid range for the value Property",\r
+                    "readOnly" : true,\r
+                    "minItems": 2,\r
+                    "maxItems": 2,\r
+                    "items": {\r
+                        "type": "number"\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
index 09321f2..63245e6 100644 (file)
 static int UnicastDiscovery = 0;
 static int TestCase = 0;
 static int Connectivity = 0;
+static int Introspection = 0;
 
 static const char *DEVICE_DISCOVERY_QUERY = "%s/oic/d";
 static const char *PLATFORM_DISCOVERY_QUERY = "%s/oic/p";
 static const char *RESOURCE_DISCOVERY_QUERY = "%s/oic/res";
+static const char *INTROSPECTION_DISCOVERY_QUERY = "%s" OC_RSRVD_INTROSPECTION_URI;
 
 //The following variable determines the interface protocol (IPv4, IPv6, etc)
 //to be used for sending unicast messages. Default set to IP dual stack.
@@ -65,6 +67,7 @@ static OCConnectivityType ConnType = CT_ADAPTER_IP;
 static OCDevAddr serverAddr;
 static char discoveryAddr[100];
 static std::string coapServerResource = "/a/light";
+static std::string coapIntrospectionResource = OC_RSRVD_INTROSPECTION_URI;
 
 #ifdef WITH_PRESENCE
 // The handle for observe registration
@@ -105,7 +108,7 @@ OCPayload* putPayload()
 
 static void PrintUsage()
 {
-    OIC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..20> -c <0|1>");
+    OIC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..20> -c <0|1> -i<0|1>");
     OIC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
     OIC_LOG(INFO, TAG, "-c 0 : Use Default connectivity(IP)");
     OIC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type");
@@ -145,7 +148,7 @@ static void PrintUsage()
             "using server's endpoints information");
     OIC_LOG(INFO, TAG, "-t 23 :  Discover Resources and Perform Get Requests by IPv4 + COAP + TCP "\
             "using server's endpoints information");
-
+    OIC_LOG(INFO, TAG, "-t 24 :  Discover Introspection Resources and Perform Get Request");
 }
 
 OCStackResult InvokeOCDoResource(std::ostringstream &query,
@@ -492,6 +495,9 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle /*handle*/,
             case TEST_GET_REQ_TCP:
                 InitGetRequestWithCoap(payload, false);
                 break;
+            case TEST_INTROSPECTION:
+                InitIntrospection(payload);
+                break;
             default:
                 PrintUsage();
                 break;
@@ -598,13 +604,22 @@ int InitGetRequestToUnavailableResource(OCQualityOfService qos)
             getReqCB, NULL, 0));
 }
 
+int InitIntrospection(OCDiscoveryPayload* dis)
+{
+    std::ostringstream query;
+    query << coapIntrospectionResource;
+    OIC_LOG_V(INFO, TAG, "\nExecuting %s with query %s", __func__, query.str().c_str());
+    return (InvokeOCDoResource(query, &serverAddr, OC_REST_GET, OC_LOW_QOS,
+            getReqCB, NULL, 0));
+}
+
 int InitObserveRequest(OCQualityOfService qos)
 {
     std::ostringstream query;
     query << coapServerResource;
     OIC_LOG_V(INFO, TAG, "\nExecuting %s with query %s", __func__, query.str().c_str());
     return (InvokeOCDoResource(query, &serverAddr, OC_REST_OBSERVE,
-              (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS, obsReqCB, NULL, 0));
+            (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS, obsReqCB, NULL, 0));
 }
 
 int InitPutRequest(OCQualityOfService qos)
@@ -809,6 +824,31 @@ int InitDeviceDiscovery(OCQualityOfService qos)
     return ret;
 }
 
+int InitIntrospectionDiscovery(OCQualityOfService qos)
+{
+    OIC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
+
+    OCStackResult ret;
+    OCCallbackData cbData;
+    char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
+
+    snprintf(szQueryUri, sizeof(szQueryUri) - 1, INTROSPECTION_DISCOVERY_QUERY, discoveryAddr);
+
+    cbData.cb = DeviceDiscoveryReqCB;
+    cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
+    cbData.cd = NULL;
+
+    ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT,
+        (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS,
+        &cbData, NULL, 0);
+    if (ret != OC_STACK_OK)
+    {
+        OIC_LOG(ERROR, TAG, "OCStack device error");
+    }
+
+    return ret;
+}
+
 int InitDiscovery(OCQualityOfService qos)
 {
     OCStackResult ret;
@@ -923,11 +963,17 @@ void showEndpointsInfo(OCResourcePayload* res)
     }
 }
 
+static FILE* server_fopen(const char* path, const char* mode)
+{
+    return fopen(path, mode);
+}
+
 int main(int argc, char* argv[])
 {
     int opt;
+    OCPersistentStorage ps{ server_fopen, fread, fwrite, fclose, unlink };
 
-    while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
+    while ((opt = getopt(argc, argv, "u:t:c:i:")) != -1)
     {
         switch(opt)
         {
@@ -940,6 +986,9 @@ int main(int argc, char* argv[])
             case 'c':
                 Connectivity = atoi(optarg);
                 break;
+            case 'i':
+                Introspection = atoi(optarg);
+                break;
             default:
                 PrintUsage();
                 return -1;
@@ -954,12 +1003,20 @@ int main(int argc, char* argv[])
         return -1;
     }
 
-    if (OCInit1(OC_CLIENT, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
+    if (OCInit1(OC_CLIENT_SERVER, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
     {
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
     }
 
+    if (Introspection != 0)
+    {
+        if (OC_STACK_OK != OCRegisterPersistentStorageHandler(&ps))
+        {
+            OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler");
+        }
+    }
+
 #ifdef ROUTING_GATEWAY
     /*
      * Before invoking Discover resource, we process the gateway requests
index dfe3acb..c96fa0c 100644 (file)
@@ -68,6 +68,7 @@ typedef enum {
     TEST_DISCOVER_REQ_SHOW_EPS,
     TEST_GET_REQ_UDP,
     TEST_GET_REQ_TCP,
+    TEST_INTROSPECTION,
     MAX_TESTS
 } CLIENT_TEST;
 
@@ -116,6 +117,7 @@ int InitDeviceDiscovery(OCQualityOfService qos);
 int InitPlatformDiscovery(OCQualityOfService qos);
 int InitDiscovery(OCQualityOfService qos);
 int InitGetRequestWithCoap(OCDiscoveryPayload* dis, bool isUdp);
+int InitIntrospection(OCDiscoveryPayload* dis);
 
 /* Call delete operation on already deleted resource */
 void* RequestDeleteDeathResourceTask(void* myqos);
index 2e8f9fe..b68bfc6 100644 (file)
@@ -119,6 +119,12 @@ OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
     return payload;
 }
 
+static FILE* server_fopen(const char* path, const char* mode)
+{
+    OIC_LOG_V(DEBUG, TAG, "Got file open call for %s",path);
+    return fopen(path, mode);
+}
+
 //This function takes the request as an input and returns the response
 OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
 {
@@ -1116,7 +1122,20 @@ int main(int argc, char* argv[])
     OCSetRAInfo(&rainfo);
 #endif
 
+    
     OIC_LOG(DEBUG, TAG, "OCServer is starting...");
+    OCPersistentStorage pstStr {
+        server_fopen,
+        fread,
+        fwrite,
+        fclose,
+        unlink
+    };
+    if (OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr))
+    {
+        OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler error");
+        return -1;
+    }
 
     if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
     {
index e7262a8..819c059 100644 (file)
@@ -36,8 +36,14 @@ void handleSigInt(int signum)
 
 FILE* service_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(AMSS_DB_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(AMSS_DB_FILE, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int /*argc*/, char* /*argv*/[])
index cfd3fc8..005e386 100644 (file)
@@ -338,14 +338,26 @@ int InitDiscovery()
 
 FILE* client_fopen_devowner(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(CRED_FILE_DEVOWNER, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE_DEVOWNER, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 FILE* client_fopen_nondevowner(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(CRED_FILE_NONDEVOWNER, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE_NONDEVOWNER, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 int main(int argc, char* argv[])
 {
index 5ae096b..4442997 100644 (file)
@@ -412,8 +412,14 @@ OCStackResult SendGetRequest(OCDPDev_t* peer)
 \r
 FILE* client_fopen(const char *path, const char *mode)\r
 {\r
-    (void)path;\r
-    return fopen(CRED_FILE, mode);\r
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);\r
+    }
+    else
+    {
+        return fopen(path, mode);
+    }\r
 }\r
 \r
 void *CLInterface(void *data)\r
index 9e161ef..745c280 100644 (file)
@@ -316,8 +316,14 @@ void handleSigInt(int signum)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen(CRED_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int /*argc*/, char* /*argv*/[])
index 1a361a1..aab39d3 100755 (executable)
@@ -121,7 +121,8 @@ OCStackResult OCConvertPayload(OCPayload* payload, uint8_t** outPayload, size_t*
 
     if (err == CborNoError)
     {
-        if (curSize < INIT_SIZE && PAYLOAD_TYPE_SECURITY != payload->type)
+        if ((curSize < INIT_SIZE) && 
+            (PAYLOAD_TYPE_SECURITY != payload->type))
         {
             uint8_t *out2 = (uint8_t *)OICRealloc(out, curSize);
             VERIFY_PARAM_NON_NULL(TAG, out2, "Failed to increase payload size");
index 614c1ac..2cd0681 100755 (executable)
@@ -61,6 +61,9 @@
 /// Module Name
 #define TAG "OIC_RI_RESOURCE"
 
+// using 1k as block size since most persistent storage implementations use a power of 2.
+#define INTROSPECTION_FILE_SIZE_BLOCK 1024
+
 #define VERIFY_SUCCESS(op) { if (op != (OC_STACK_OK)) \
             {OIC_LOG_V(FATAL, TAG, "%s failed!!", #op); goto exit;} }
 
@@ -259,6 +262,14 @@ static OCVirtualResources GetTypeOfVirtualURI(const char *uriInRequest)
     {
         return OC_RESOURCE_TYPES_URI;
     }
+    else if (strcmp(uriInRequest, OC_RSRVD_INTROSPECTION_URI) == 0)
+    {
+        return OC_INTROSPECTION_URI;
+    }
+    else if (strcmp(uriInRequest, OC_RSRVD_INTROSPECTION_PAYLOAD_URI) == 0)
+    {
+        return OC_INTROSPECTION_PAYLOAD_URI;
+    }
 #ifdef ROUTING_GATEWAY
     else if (0 == strcmp(uriInRequest, OC_RSRVD_GATEWAY_URI))
     {
@@ -475,6 +486,400 @@ OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
     return OC_STACK_OK;
 }
 
+static size_t GetIntrospectionDataSize(const OCPersistentStorage *ps)
+{
+    size_t size = 0;
+    char buffer[INTROSPECTION_FILE_SIZE_BLOCK];
+    FILE *fp;
+
+    if (!ps)
+    {
+        return 0;
+    }
+
+    fp = ps->open(OC_INTROSPECTION_FILE_NAME, "rb");
+    if (fp)\r
+    {\r
+        size_t bytesRead = 0;\r
+        do\r
+        {\r
+            bytesRead = ps->read(buffer, 1, INTROSPECTION_FILE_SIZE_BLOCK, fp);\r
+            size += bytesRead;\r
+        } while (bytesRead);\r
+        ps->close(fp);\r
+    }
+    return size;
+}
+
+OCStackResult GetIntrospectionDataFromPS(char **data, size_t *size)
+{
+    OIC_LOG(DEBUG, TAG, "GetIntrospectionDataFromPS IN");
+
+    FILE *fp = NULL;
+    uint8_t *fsData = NULL;
+    size_t fileSize = 0;
+    OCStackResult ret = OC_STACK_ERROR;
+    OCPersistentStorage *ps = NULL;
+    
+    if (!data || *data || !size)
+    {
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    ps = OCGetPersistentStorageHandler();
+    if (!ps)
+    {
+        OIC_LOG(ERROR, TAG, "Persistent Storage handler is NULL");
+        goto exit;
+    }
+
+    fileSize = GetIntrospectionDataSize(ps);
+    OIC_LOG_V(DEBUG, TAG, "File Read Size: %zu", fileSize);
+    if (fileSize)
+    {
+        // allocate one more byte to accomodate null terminator for string we are reading.
+        fsData = (uint8_t *)OICCalloc(1, fileSize + 1); 
+        if (!fsData)
+        {
+            OIC_LOG(ERROR, TAG, "Could not allocate memory for introspection data");
+            goto exit;
+        }
+
+        fp = ps->open(OC_INTROSPECTION_FILE_NAME, "rb");
+        if (!fp)
+        {
+            OIC_LOG(ERROR, TAG, "Could not open persistent storage file for introspection data");
+            goto exit;
+        }
+        if (ps->read(fsData, 1, fileSize, fp) == fileSize)
+        {
+            *size = fileSize;
+            fsData[fileSize] = '\0';
+            *data = (char *)fsData;
+            fsData = NULL;
+            ret = OC_STACK_OK;
+        }
+    }
+    OIC_LOG(DEBUG, TAG, "GetIntrospectionDataFromPS OUT");
+
+exit:
+    if (fp)
+    {
+        ps->close(fp);
+    }
+    if (fsData)
+    {
+        OICFree(fsData);
+    }
+    return ret;
+}
+
+OCStackResult BuildIntrospectionPayloadResponse(const OCResource *resourcePtr,
+    OCRepPayload** payload, OCDevAddr *devAddr)
+{
+    OCRepPayload *tempPayload = NULL;
+    OCStackResult ret;
+    char *introspectionData = NULL;
+    size_t size = 0;
+    ret = GetIntrospectionDataFromPS(&introspectionData, &size);
+    if (OC_STACK_OK == ret)
+    {
+        OCRepPayload *tempPayload = OCRepPayloadCreate();
+        if (tempPayload)
+        {
+            if (OCRepPayloadSetPropStringAsOwner(tempPayload, OC_RSRVD_INTROSPECTION_DATA_NAME, introspectionData))
+            {
+                *payload = tempPayload;
+            }
+        }
+        else
+        {
+            ret = OC_STACK_NO_MEMORY;
+        }
+    }
+    if (ret != OC_STACK_OK)
+    {
+        OICFree(introspectionData);
+        OCRepPayloadDestroy(tempPayload);
+    }
+
+    return ret;
+}
+
+OCRepPayload *BuildUrlInfoWithProtocol(const char *protocol)
+{
+    OCStackResult result = OC_STACK_OK;
+    OCRepPayload *urlInfoPayload = OCRepPayloadCreate();
+    if (!urlInfoPayload)
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to create a new RepPayload");
+        result = OC_STACK_NO_MEMORY;
+        goto exit;
+    }
+
+    if (!OCRepPayloadSetPropString(urlInfoPayload, OC_RSRVD_INTROSPECTION_URL, OC_RSRVD_INTROSPECTION_PAYLOAD_URI))
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to add url");
+        result = OC_STACK_ERROR;
+        goto exit;
+    }
+    if (!OCRepPayloadSetPropString(urlInfoPayload, OC_RSRVD_INTROSPECTION_PROTOCOL, protocol))
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to add protocol");
+        result = OC_STACK_ERROR;
+        goto exit;
+    }
+    if (!OCRepPayloadSetPropString(urlInfoPayload, OC_RSRVD_INTROSPECTION_CONTENT_TYPE, OC_RSRVD_INTROSPECTION_CONTENT_TYPE_VALUE))
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to add content type");
+        result = OC_STACK_ERROR;
+        goto exit;
+    }
+    if (!OCRepPayloadSetPropInt(urlInfoPayload, OC_RSRVD_INTROSPECTION_VERSION, OC_RSRVD_INTROSPECTION_VERSION_VALUE))
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to add version");
+        result = OC_STACK_ERROR;
+        goto exit;
+    }
+    
+exit:
+    if (result != OC_STACK_OK)
+    {
+        OCRepPayloadDestroy(urlInfoPayload);
+        urlInfoPayload = NULL;
+    }
+    return urlInfoPayload;
+}
+
+OCStackResult AddProtocolToLL(OCStringLL **protoLL, const char *protocol)
+{
+    OCStringLL* cur = *protoLL;
+    // Check if protocol is already in list
+    while (cur)
+    {
+        if (strcmp(cur->value, protocol) == 0)
+        {
+            break;
+        }
+        cur = cur->next;
+    }
+    if (cur)
+    {
+        // The intent of the protocol list is to collect all unique protocols available on this 
+        // endpoint. Set an error that can be used to skip processing this protocol further as 
+        // it already exists in the list.
+        return OC_STACK_INVALID_PARAM;
+    }
+    else
+    {
+        cur = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
+        if (!cur)
+        {
+            return OC_STACK_NO_MEMORY;
+        }
+    }
+
+    cur->value = OICStrdup(protocol);
+    if (!cur->value)
+    {
+        OICFree(cur);
+        return OC_STACK_NO_MEMORY;
+    }
+
+    cur->next = *protoLL;
+    *protoLL = cur;
+    return OC_STACK_OK;
+}
+
+void FreeProtocolLL(OCStringLL *protoLL)
+{
+    OCStringLL* cur = protoLL;
+    while (cur)
+    {
+        OCStringLL *temp = cur;
+        cur = cur->next;
+        OICFree(temp->value);
+        OICFree(temp);
+    }
+}
+
+OCStackResult BuildIntrospectionResponseRepresentation(const OCResource *resourcePtr,
+    OCRepPayload** payload, OCDevAddr *devAddr)
+{
+    size_t dimensions[3] = { 0, 0, 0 };
+    OCRepPayload *tempPayload = NULL;
+    OCRepPayload **urlInfoPayload = NULL;
+    OCStringLL *protoLL = NULL;
+    OCStackResult ret = OC_STACK_OK;
+    OCResourceType *resType = NULL;
+    OCResourceInterface *resInterface = NULL;
+
+    if (!resourcePtr)
+    {
+        ret = OC_STACK_INVALID_PARAM;
+        goto exit;
+    }
+
+    tempPayload = OCRepPayloadCreate();
+    if (!tempPayload)
+    {
+        ret = OC_STACK_NO_MEMORY;
+        goto exit;
+    }
+
+    if (!OCRepPayloadSetUri(tempPayload, resourcePtr->uri))
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to set payload URI");
+        ret = OC_STACK_ERROR;
+        goto exit;
+    }
+
+    resType = resourcePtr->rsrcType;
+    while (resType)
+    {
+        if (!OCRepPayloadAddResourceType(tempPayload, resType->resourcetypename))
+        {
+            OIC_LOG_V(ERROR, TAG, "Failed at add resource type");
+            ret = OC_STACK_ERROR;
+            goto exit;
+        }
+        resType = resType->next;
+    }
+
+    resInterface = resourcePtr->rsrcInterface;
+    while (resInterface)
+    {
+        if (!OCRepPayloadAddInterface(tempPayload, resInterface->name))
+        {
+            OIC_LOG_V(ERROR, TAG, "Failed to add interface");
+            ret = OC_STACK_ERROR;
+            goto exit;
+        }
+        resInterface = resInterface->next;
+    }
+    if (!OCRepPayloadSetPropString(tempPayload, OC_RSRVD_INTROSPECTION_NAME, OC_RSRVD_INTROSPECTION_NAME_VALUE))
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to set Name property.");
+        ret = OC_STACK_ERROR;
+        goto exit;
+    }
+
+    // figure out which protocols this endpoint supports
+    if (resourcePtr->endpointType | OC_COAP)
+    {
+        if (OC_STACK_OK == AddProtocolToLL(&protoLL, COAP_STR))
+        {
+            dimensions[0]++;
+        }
+    }
+    if (resourcePtr->endpointType | OC_COAPS)
+    {
+        if (OC_STACK_OK == AddProtocolToLL(&protoLL, COAPS_STR))
+        {
+            dimensions[0]++;
+        }
+    }
+#ifdef TCP_ADAPTER
+    if (resourcePtr->endpointType | OC_COAP_TCP)
+    {
+        if (OC_STACK_OK == AddProtocolToLL(&protoLL, COAP_STR))
+        {
+            dimensions[0]++;
+        }
+    }
+    if (resourcePtr->endpointType | OC_COAPS_TCP)
+    {
+        if (OC_STACK_OK == AddProtocolToLL(&protoLL, COAPS_STR))
+        {
+            dimensions[0]++;
+        }
+    }
+#endif
+#ifdef HTTP_ADAPTER
+    if (resourcePtr->endpointType | OC_HTTP)
+    {
+        if (OC_STACK_OK == AddProtocolToLL(&protoLL, HTTP_STR))
+        {
+            dimensions[0]++;
+        }
+    }
+    if (resourcePtr->endpointType | OC_HTTPS)
+    {
+        if (OC_STACK_OK == AddProtocolToLL(&protoLL, HTTPS_STR))
+        {
+            dimensions[0]++;
+        }
+    }
+#endif
+#ifdef EDR_ADAPTER
+    if (resourcePtr->endpointType | OC_COAP_RFCOMM)
+    {
+        if (OC_STACK_OK == AddProtocolToLL(&protoLL, COAP_STR))
+        {
+            dimensions[0]++;
+        }
+    }
+#endif
+    // Add a urlInfo object for each protocol supported
+    if (dimensions[0] >= 0)
+    {
+        urlInfoPayload = (OCRepPayload **)OICMalloc(dimensions[0] * sizeof(OCRepPayload));
+        if (urlInfoPayload)
+        {
+            OCStringLL *proto = protoLL;
+            size_t i = 0;
+            while (proto)
+            {
+                urlInfoPayload[i] = BuildUrlInfoWithProtocol(proto->value);
+                if (!urlInfoPayload[i])
+                {
+                    OIC_LOG_V(ERROR, TAG, "Unable to build urlInfo object for protocol");
+                    ret = OC_STACK_ERROR;
+                    goto exit;
+                }
+                proto = proto->next;
+                i++;
+            }
+            if (!OCRepPayloadSetPropObjectArrayAsOwner(tempPayload, 
+                                                       OC_RSRVD_INTROSPECTION_URL_INFO, 
+                                                       urlInfoPayload, 
+                                                       dimensions))
+            {
+                OIC_LOG_V(ERROR, TAG, "Unable to add urlInfo object to introspection payload ");
+                ret = OC_STACK_ERROR;
+                goto exit;
+            }
+        }
+        else
+        {
+            OIC_LOG_V(ERROR, TAG, "Unable to allocate memory for urlInfo ");
+            ret = OC_STACK_NO_MEMORY;
+            goto exit;
+        }
+    }
+
+    if (!*payload)
+    {
+        *payload = tempPayload;
+    }
+    else
+    {
+        OCRepPayloadAppend(*payload, tempPayload);
+    }
+exit:
+    if (ret != OC_STACK_OK)
+    {
+        OCRepPayloadDestroy(tempPayload);
+        if (urlInfoPayload)
+        {
+            OICFree(urlInfoPayload);
+        }
+    }
+    FreeProtocolLL(protoLL);
+    
+    return OC_STACK_OK;
+}
+
 OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
                                            OCDiscoveryPayload *payload,
                                            OCDevAddr *devAddr,
@@ -1076,7 +1481,22 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
         discoveryResult = RMHandleGatewayRequest(request, resource);
     }
 #endif
-
+    else if (OC_INTROSPECTION_URI == virtualUriInRequest)
+    {
+        // Received request for introspection
+        OCResource *resourcePtr = FindResourceByUri(OC_RSRVD_INTROSPECTION_URI);
+        VERIFY_PARAM_NON_NULL(TAG, resourcePtr, "Introspection URI not found.");
+        discoveryResult = BuildIntrospectionResponseRepresentation(resourcePtr, (OCRepPayload **)&payload, &request->devAddr);
+        OIC_LOG(INFO, TAG, "Request is for Introspection");
+    }
+    else if (OC_INTROSPECTION_PAYLOAD_URI == virtualUriInRequest)
+    {
+        // Received request for introspection payload
+        OCResource *resourcePtr = FindResourceByUri(OC_RSRVD_INTROSPECTION_PAYLOAD_URI);
+        VERIFY_PARAM_NON_NULL(TAG, resourcePtr, "Introspection Payload URI not found.");
+        discoveryResult = BuildIntrospectionPayloadResponse(resourcePtr, (OCRepPayload **)&payload, &request->devAddr);
+        OIC_LOG(INFO, TAG, "Request is for Introspection Payload");
+    }
     /**
      * Step 2: Send the discovery response
      *
index 0ef6c1a..36a7508 100644 (file)
@@ -120,6 +120,8 @@ OCResource *headResource = NULL;
 static OCResource *tailResource = NULL;
 static OCResourceHandle platformResource = {0};
 static OCResourceHandle deviceResource = {0};
+static OCResourceHandle introspectionResource = {0};
+static OCResourceHandle introspectionPayloadResource = {0};
 #ifdef MQ_BROKER
 static OCResourceHandle brokerResource = {0};
 #endif
@@ -144,6 +146,8 @@ static const char CORESPEC[] = "core";
 
 CAAdapterStateChangedCB g_adapterHandler = NULL;
 CAConnectionStateChangedCB g_connectionHandler = NULL;
+// Persistent Storage callback handler for open/read/write/close/unlink
+static OCPersistentStorage *g_PersistentStorageHandler = NULL;
 
 //-----------------------------------------------------------------------------
 // Macros
@@ -1346,7 +1350,14 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
                     {
                         type = PAYLOAD_TYPE_REPRESENTATION;
                     }
-
+                    else if (strcmp(cbNode->requestUri, OC_RSRVD_INTROSPECTION_URI) == 0)
+                    {
+                        type = PAYLOAD_TYPE_REPRESENTATION;
+                    }
+                    else if (strcmp(cbNode->requestUri, OC_RSRVD_INTROSPECTION_PAYLOAD_URI) == 0)
+                    {
+                        type = PAYLOAD_TYPE_REPRESENTATION;
+                    }
 #ifdef ROUTING_GATEWAY
                     else if (strcmp(cbNode->requestUri, OC_RSRVD_GATEWAY_URI) == 0)
                     {
@@ -3054,7 +3065,13 @@ OCStackResult OCRegisterPersistentStorageHandler(OCPersistentStorage* persistent
             return OC_STACK_INVALID_PARAM;
         }
     }
-    return SRMRegisterPersistentStorageHandler(persistentStorageHandler);
+    g_PersistentStorageHandler = persistentStorageHandler;
+    return OC_STACK_OK;
+}
+
+OCPersistentStorage *OCGetPersistentStorageHandler()
+{
+    return g_PersistentStorageHandler;
 }
 
 #ifdef WITH_PRESENCE
@@ -4346,6 +4363,38 @@ OCStackResult initResources()
         }
     }
 
+    if (result == OC_STACK_OK)
+    {
+        result = OCCreateResource(&introspectionResource,
+                                  OC_RSRVD_RESOURCE_TYPE_INTROSPECTION,
+                                  OC_RSRVD_INTERFACE_DEFAULT,
+                                  OC_RSRVD_INTROSPECTION_URI,
+                                  NULL,
+                                  NULL,
+                                  OC_DISCOVERABLE);
+        if (result == OC_STACK_OK)
+        {
+            result = BindResourceInterfaceToResource((OCResource *)introspectionResource,
+                                                     OC_RSRVD_INTERFACE_READ);
+        }
+    }
+
+    if (result == OC_STACK_OK)
+    {
+        result = OCCreateResource(&introspectionPayloadResource,
+                                  OC_RSRVD_RESOURCE_TYPE_INTROSPECTION_PAYLOAD,
+                                  OC_RSRVD_INTERFACE_DEFAULT,
+                                  OC_RSRVD_INTROSPECTION_PAYLOAD_URI,
+                                  NULL,
+                                  NULL,
+                                  OC_OBSERVABLE);
+        if (result == OC_STACK_OK)
+        {
+            result = BindResourceInterfaceToResource((OCResource *)introspectionPayloadResource,
+                                                     OC_RSRVD_INTERFACE_READ);
+        }
+    }
+
     return result;
 }
 
index f8b3999..59d9564 100644 (file)
@@ -122,6 +122,9 @@ clientjson = examples_env.Install(examples_env.get('BUILD_DIR') + '/resource/exa
                                examples_env.get('SRC_DIR') + '/resource/examples/' + 'oic_svr_db_client.dat')
 serverjson = examples_env.Install(examples_env.get('BUILD_DIR') + '/resource/examples/',
                                examples_env.get('SRC_DIR') + '/resource/examples/' + 'oic_svr_db_server.dat')
+light_introspection_json = examples_env.Install(examples_env.get('BUILD_DIR') + '/resource/examples/',
+                               examples_env.get('SRC_DIR') + '/resource/examples/' + 'light_introspection.json')
+
 directpairingdat = examples_env.Install(examples_env.get('BUILD_DIR') + '/resource/examples/',
                                examples_env.get('SRC_DIR') + '/resource/examples/' + 'oic_svr_db_client_directpairing.dat')
 
index 46b36a6..703c378 100644 (file)
@@ -64,9 +64,16 @@ using namespace OC;
 static int ask = 1;
 static PairedDevices discoveredDeviceList, pairedDeviceList;
 
-static FILE* client_open(const char* /*fileName*/, const char *mode)
+static FILE* client_open(const char* path, const char* mode)
 {
-    return fopen(DAT_DB_PATH, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(DAT_DB_PATH, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 
diff --git a/resource/examples/light_introspection.json b/resource/examples/light_introspection.json
new file mode 100644 (file)
index 0000000..baab37f
--- /dev/null
@@ -0,0 +1,272 @@
+{\r
+    "swagger": "2.0",\r
+    "info": {\r
+      "title": "my_example_device",\r
+      "version": "my device version"\r
+    },\r
+\r
+\r
+    "schemes": [\r
+        "http"\r
+    ],\r
+    "consumes": [\r
+        "application/json"\r
+    ],\r
+    "produces": [\r
+        "application/json"\r
+    ],\r
+    "paths": {\r
+       "/switch": {\r
+\r
+          "get": {\r
+\r
+\r
+            "parameters": [\r
+               {\r
+                 "name": "if",\r
+                 "in": "query",\r
+                 "description": "",\r
+                 "enum": [ "oic.if.a","oic.if.baseline" ],\r
+\r
+                 "type": "string"\r
+                }\r
+            ],\r
+            "responses": {\r
+              "200" : {\r
+                  "description" : "",\r
+                  "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/BinarySwitch"\r
+                  }\r
+               }\r
+            }\r
+\r
+           },\r
+\r
+          "post": {\r
+\r
+\r
+            "parameters": [\r
+               {\r
+                 "name": "if",\r
+                 "in": "query",\r
+                 "description": "",\r
+                 "enum": [ "oic.if.a","oic.if.baseline" ],\r
+\r
+                 "type": "string"\r
+                }\r
+                 ,{\r
+                  "name": "body",\r
+                  "in": "body",\r
+                  "required": false,\r
+                   "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/BinarySwitch"\r
+                  }\r
+\r
+                }\r
+            ],\r
+            "responses": {\r
+              "200" : {\r
+                  "description" : "",\r
+                   "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/BinarySwitch"\r
+                  }\r
+\r
+               }\r
+            }\r
+          }\r
+        },\r
+       "/brightness": {\r
+\r
+          "get": {\r
+\r
+\r
+            "parameters": [\r
+               {\r
+                 "name": "if",\r
+                 "in": "query",\r
+                 "description": "",\r
+                 "enum": [ "oic.if.a","oic.if.baseline" ],\r
+\r
+                 "type": "string"\r
+                }\r
+            ],\r
+            "responses": {\r
+              "200" : {\r
+                  "description" : "",\r
+                 "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/Brightness"\r
+                  }\r
+               }\r
+            }\r
+\r
+           },\r
+\r
+          "post": {\r
+\r
+\r
+            "parameters": [\r
+               {\r
+                 "name": "if",\r
+                 "in": "query",\r
+                 "description": "",\r
+                 "enum": [ "oic.if.a","oic.if.baseline" ],\r
+\r
+                 "type": "string"\r
+                }\r
+                 ,{\r
+                  "name": "body",\r
+                  "in": "body",\r
+                  "required": false,\r
+                 "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/Brightness"\r
+                  }\r
+                }\r
+            ],\r
+            "responses": {\r
+              "200" : {\r
+                  "description" : "",\r
+                 "schema" :\r
+                  {\r
+                    "$ref": "#/definitions/Brightness"\r
+                  }\r
+\r
+               }\r
+            }\r
+\r
+          }\r
+        }\r
+    },\r
+    "definitions":\r
+    {\r
+        "BinarySwitch": {\r
+           "type": "object",\r
+           "required": [\r
+             "id"\r
+           ],\r
+           "properties":  {\r
+               "value": {\r
+                  "type": "boolean",\r
+                  "description": "Status of the switch"\r
+                },\r
+                "rt": {\r
+                "type": "array",\r
+                "items" : [\r
+                  {\r
+                    "type" : "string",\r
+                    "maxLength": 64\r
+                  }\r
+                ],\r
+                "minItems" : 1,\r
+                "description": "Resource Type",\r
+                "readOnly" : true,\r
+                "default" : [ "oic.r.switch.binary" ]\r
+                },\r
+                "if": {\r
+                    "type": "array",\r
+                    "description": "The interface set supported by this resource",\r
+                    "readOnly" : true,\r
+                    "items": {\r
+                        "type": "string",\r
+                        "enum": [\r
+                            "oic.if.baseline",\r
+                            "oic.if.a"\r
+                        ]\r
+                    }\r
+                },\r
+                "p": {\r
+                    "type": "integer",\r
+                    "description": "Bitmap indicating observable and discoverable",\r
+                    "readOnly" : true\r
+                },\r
+                "n": {\r
+                    "type": "string",\r
+                    "description": "Friendly name of the resource",\r
+                    "readOnly" : true\r
+                },\r
+                "id": {\r
+                    "type": "string",\r
+                    "description": "Instance ID of this specific resource",\r
+                    "readOnly" : true\r
+                },\r
+                "range": {\r
+                    "type": "array",\r
+                    "description": "The valid range for the value Property",\r
+                    "readOnly" : true,\r
+                    "minItems": 2,\r
+                    "maxItems": 2,\r
+                    "items": {\r
+                        "type": "number"\r
+                    }\r
+                }\r
+            }\r
+        },\r
+        "Brightness": {\r
+           "type": "object",\r
+           "required": [\r
+             "id"\r
+           ],\r
+           "properties":  {\r
+               "brighness": {\r
+                  "type": "integer",\r
+                  "description": "Current sensed or set value for Brightness"\r
+                },\r
+                "rt": {\r
+                "type": "array",\r
+                "items" : [\r
+                  {\r
+                    "type" : "string",\r
+                    "maxLength": 64\r
+                  }\r
+                ],\r
+                "minItems" : 1,\r
+                "description": "Resource Type",\r
+                "readOnly" : true,\r
+                "default" : [ "oic.r.light.brightness" ]\r
+                },\r
+                "if": {\r
+                    "type": "array",\r
+                    "description": "The interface set supported by this resource",\r
+                    "readOnly" : true,\r
+                    "items": {\r
+                        "type": "string",\r
+                        "enum": [\r
+                            "oic.if.baseline",\r
+                            "oic.if.a"\r
+                        ]\r
+                    }\r
+                },\r
+                "p": {\r
+                    "type": "integer",\r
+                    "description": "Bitmap indicating observable and discoverable",\r
+                    "readOnly" : true\r
+                },\r
+                "n": {\r
+                    "type": "string",\r
+                    "description": "Friendly name of the resource",\r
+                    "readOnly" : true\r
+                },\r
+                "id": {\r
+                    "type": "string",\r
+                    "description": "Instance ID of this specific resource",\r
+                    "readOnly" : true\r
+                },\r
+                "range": {\r
+                    "type": "array",\r
+                    "description": "The valid range for the value Property",\r
+                    "readOnly" : true,\r
+                    "minItems": 2,\r
+                    "maxItems": 2,\r
+                    "items": {\r
+                        "type": "number"\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
index 2baf79f..127b858 100644 (file)
@@ -387,15 +387,31 @@ OCStackResult SetDeviceInfo()
     return OC_STACK_OK;
 }
 
+FILE* server_fopen(const char* path, const char* mode)
+{
+    if (0 == strcmp(path, OC_INTROSPECTION_FILE_NAME))
+    {
+        return fopen("light_introspection.json", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
+}
+
+
 int main(int /*argc*/, char** /*argv[]*/)
 {
+    // Create persistent storage handlers
+    OCPersistentStorage ps{server_fopen, fread, fwrite, fclose, unlink};
     // Create PlatformConfig object
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Server,
         "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
         0,         // Uses randomly available port
-        OC::QualityOfService::LowQos
+        OC::QualityOfService::LowQos,
+        &ps
     };
 
     OCPlatform::Configure(cfg);
index 457349b..0f07e86 100644 (file)
@@ -525,9 +525,16 @@ void PrintUsage()
     cout << "    4 - Non-secure resource, GET slow response, notify all observers\n";
 }
 
-static FILE* client_open(const char* /*path*/, const char* mode)
+static FILE* client_open(const char* path, const char* mode)
 {
-    return fopen("./oic_svr_db_server.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./oic_svr_db_server.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 void playPause()
index 4368f6b..5960fa2 100644 (file)
@@ -218,9 +218,16 @@ static void printUsage()
     std::cout<<"Usage: rdserver <coap+tcp://10.11.12.13:5683>\n";
 }
 
-static FILE* client_open(const char* /*path*/, const char *mode)
+static FILE* client_open(const char* path, const char* mode)
 {
-    return fopen(SVR_DB_FILE_NAME, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(SVR_DB_FILE_NAME, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int argc, char* argv[])
index 924e88c..885d9aa 100644 (file)
@@ -468,9 +468,16 @@ void checkTransportValue(int value)
     }
 }
 
-static FILE* client_open(const char* /*path*/, const char *mode)
+static FILE* client_open(const char* path, const char* mode)
 {
-    return fopen(SVR_DB_FILE_NAME, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(SVR_DB_FILE_NAME, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int argc, char* argv[]) {
index 6185e3d..79b83d4 100644 (file)
@@ -617,9 +617,16 @@ void PrintUsage()
     std::cout << "    4 - Non-secure resource, GET slow response, notify all observers\n";
 }
 
-static FILE* client_open(const char* /*path*/, const char *mode)
+static FILE* client_open(const char* path, const char* mode)
 {
-    return fopen(SVR_DB_FILE_NAME, mode);
+    if (strcmp(path, OC_INTROSPECTION_FILE_NAME) == 0)
+    {
+        return fopen("light_introspection.json", mode);
+    }
+    else
+    {
+        return fopen(SVR_DB_FILE_NAME, mode);
+    }
 }
 
 int main(int argc, char* argv[])
index 596bb4e..c6921ce 100644 (file)
@@ -48,9 +48,16 @@ HWND WINAPI CreateTrackbar(HWND parent, int x, int y, int w, int h,UINT iMin, UI
 HWND WINAPI CreateLabel(HWND parent, LPCTSTR lpText, int x, int y, int w, int h);
 HWND WINAPI CreateButton(HWND parent, UINT_PTR id, LPCTSTR caption, int x, int y, int w, int h);
 
-FILE* client_open(const char* /*path*/, const char *mode)
+FILE* client_open(const char* path, const char* mode)
 {
-    return fopen("./oic_svr_db_client.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./oic_svr_db_client.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
index 642fe81..9ea5f2c 100644 (file)
@@ -427,8 +427,14 @@ static void userRequests(void *data)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    OC_UNUSED(path);
-    return fopen(fname, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(fname, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 /**
index 6a4e9f5..1b6905a 100644 (file)
@@ -70,10 +70,16 @@ static int transferDevIdx, ask = 1;
 static OicSecPconf_t g_pconf;
 static uint16_t g_credId = 0;
 
-static FILE* client_open(const char *UNUSED_PARAM, const char *mode)
+static FILE* client_open(const char *path, const char *mode)
 {
-    (void)UNUSED_PARAM;
-    return fopen(DAT_DB_PATH, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(DAT_DB_PATH, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 void printMenu()
index f662526..cf6f036 100644 (file)
@@ -63,10 +63,16 @@ using namespace OC;
 DeviceList_t pMOwnedDeviceList, pMOTEnabledDeviceList;
 static int transferDevIdx, ask = 1;
 
-static FILE* client_open(const char *UNUSED_PARAM, const char *mode)
+static FILE* client_open(const char *path, const char *mode)
 {
-    (void)UNUSED_PARAM;
-    return fopen(DAT_DB_PATH, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(DAT_DB_PATH, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 void printMenu()
index 5a26944..63ffecc 100644 (file)
@@ -35,11 +35,18 @@ namespace OCPlatformTest
     OCResourceHandle resourceHandle;
 
     //OCPersistent Storage Handlers
-    static FILE* client_open(const char * /*path*/, const char *mode)
+    static FILE* client_open(const char *path, const char *mode)
     {
-        std::cout << "<===Opening SVR DB file = './oic_svr_db_client.dat' with mode = '" << mode
+        if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+        {
+            std::cout << "<===Opening SVR DB file = './oic_svr_db_client.dat' with mode = '" << mode
                 << "' " << std::endl;
-        return fopen(SVR_DB_FILE_NAME, mode);
+            return fopen(SVR_DB_FILE_NAME, mode);
+        }
+        else
+        {
+            return fopen(path, mode);
+        }
     }
     OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
 
index 2f0c6f2..9caada0 100755 (executable)
@@ -133,8 +133,14 @@ ESProvisioningCallbacks gCallbacks = {
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void) path;
-    return fopen(CRED_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 void EnableSecurity()
index 83c2fc7..ce8d673 100755 (executable)
@@ -145,8 +145,14 @@ ESProvisioningCallbacks gCallbacks = {
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void) path;
-    return fopen(CRED_FILE, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(CRED_FILE, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 void EnableSecurity()
index 54beb20..47313f1 100755 (executable)
@@ -417,10 +417,16 @@ void DisplayMenu()
     };
 }
 
-static FILE* client_open(const char *UNUSED_PARAM, const char *mode)
+static FILE* client_open(const char *path, const char *mode)
 {
-    (void)UNUSED_PARAM;
-    return fopen(JSON_DB_PATH, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(JSON_DB_PATH, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index 2737f06..dc181e1 100755 (executable)
@@ -418,10 +418,16 @@ void DisplayMenu()
     };
 }
 
-static FILE* client_open(const char *UNUSED_PARAM, const char *mode)
+static FILE* client_open(const char *path, const char *mode)
 {
-    (void)UNUSED_PARAM;
-    return fopen(JSON_DB_PATH, mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(JSON_DB_PATH, mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index cdf20f3..b6eb079 100755 (executable)
@@ -39,8 +39,14 @@ uint64_t mainMessageId = 0;
 \r
 FILE *server_fopen(const char *path, const char *mode)\r
 {\r
-    (void)path;\r
-    return fopen("oic_ns_provider_db.dat", mode);\r
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("oic_ns_provider_db.dat", mode);\r
+    }
+    else
+    {
+        return fopen(path, mode);
+    }\r
 }\r
 \r
 void onNotificationPostedCb(OIC::Service::NSMessage *notification)\r
index 8c14cd3..9fe1559 100644 (file)
@@ -48,8 +48,14 @@ NSTopicLL * g_topicLL = NULL;
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen("oic_ns_provider_db.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("oic_ns_provider_db.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 void printProviderTopicList(NSTopicLL * topics)
index 221013a..534973a 100644 (file)
@@ -97,8 +97,14 @@ void syncCallback(NSSyncInfo *sync)
 
 FILE* server_fopen(const char *path, const char *mode)
 {
-    (void)path;
-    return fopen("oic_ns_provider_db.dat", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("oic_ns_provider_db.dat", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 void printTopics(NSTopicLL * topics)
index d4d2729..f239415 100644 (file)
@@ -644,9 +644,14 @@ void checkObserverValue(int value)
 
 static FILE *client_open(const char *path, const char *mode)
 {
-    (void)path;
-
-    return fopen("./oic_svr_db_client.json", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./oic_svr_db_client.json", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(int argc, char *argv[])
index 5b53677..1302101 100644 (file)
@@ -314,9 +314,16 @@ void runDiscovery()
     g_currentRun = runResourceSelection;
 }
 
-static FILE *client_open(const char * /*path*/, const char *mode)
+static FILE *client_open(const char *path, const char *mode)
 {
-    return fopen("./oic_svr_db_client.json", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./oic_svr_db_client.json", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main()
index 2457bb0..415df43 100644 (file)
@@ -204,9 +204,16 @@ void runPresenceSelection()
     g_currentRun = runResourceModeSelection;
 }
 
-static FILE *client_open(const char * /*path*/, const char *mode)
+static FILE *client_open(const char *path, const char *mode)
 {
-    return fopen("./oic_svr_db_server.json", mode);
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen("./oic_svr_db_server.json", mode);
+    }
+    else
+    {
+        return fopen(path, mode);
+    }
 }
 
 int main(void)