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()
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[])
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)
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[])
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[])
}
-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[])
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);
+ }
}
}
/** 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 */
/** 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"
/** 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"
#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
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);
+ }
}
/**
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-
+#include <payload_logging.h>
#include "utlist.h"
#include "logger.h"
#include "oic_malloc.h"
#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
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; )
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)
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");
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:
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()
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()
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()
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()
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)
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)
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
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()
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()
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)
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;
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()
#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";
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
*/
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
-#******************************************************************
-#
-# 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
--- /dev/null
+{\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
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.
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
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");
"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,
case TEST_GET_REQ_TCP:
InitGetRequestWithCoap(payload, false);
break;
+ case TEST_INTROSPECTION:
+ InitIntrospection(payload);
+ break;
default:
PrintUsage();
break;
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)
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;
}
}
+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)
{
case 'c':
Connectivity = atoi(optarg);
break;
+ case 'i':
+ Introspection = atoi(optarg);
+ break;
default:
PrintUsage();
return -1;
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
TEST_DISCOVER_REQ_SHOW_EPS,
TEST_GET_REQ_UDP,
TEST_GET_REQ_TCP,
+ TEST_INTROSPECTION,
MAX_TESTS
} CLIENT_TEST;
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);
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)
{
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)
{
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*/[])
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[])
{
\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
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*/[])
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");
/// 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;} }
{
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))
{
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,
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
*
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
CAAdapterStateChangedCB g_adapterHandler = NULL;
CAConnectionStateChangedCB g_connectionHandler = NULL;
+// Persistent Storage callback handler for open/read/write/close/unlink
+static OCPersistentStorage *g_PersistentStorageHandler = NULL;
//-----------------------------------------------------------------------------
// Macros
{
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)
{
return OC_STACK_INVALID_PARAM;
}
}
- return SRMRegisterPersistentStorageHandler(persistentStorageHandler);
+ g_PersistentStorageHandler = persistentStorageHandler;
+ return OC_STACK_OK;
+}
+
+OCPersistentStorage *OCGetPersistentStorageHandler()
+{
+ return g_PersistentStorageHandler;
}
#ifdef WITH_PRESENCE
}
}
+ 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;
}
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')
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);
+ }
}
--- /dev/null
+{\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
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);
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()
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[])
}
}
-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[]) {
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[])
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,
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);
+ }
}
/**
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()
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()
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 };
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()
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()
};
}
-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()
};
}
-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()
\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
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)
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)
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[])
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()
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)