d2d-manager: remove unnecessary files
authorsaerome.kim <saerome.kim@samsung.com>
Wed, 28 Mar 2018 12:59:10 +0000 (21:59 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:49 +0000 (19:38 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
92 files changed:
CMakeLists.txt
packaging/d2d-manager.spec [changed mode: 0644->0755]
packaging/fnm.service [deleted file]
packaging/net.fnm.service [deleted file]
src/companion-manager/CMakeLists.txt
src/companion-manager/src/comp_gdbus_group.c
src/companion-manager/src/comp_iot.cpp
src/include/cjson/cJSON.h [deleted file]
src/include/coap/address.h [deleted file]
src/include/coap/async.h [deleted file]
src/include/coap/bits.h [deleted file]
src/include/coap/block.h [deleted file]
src/include/coap/coap.h [deleted file]
src/include/coap/coap_list.h [deleted file]
src/include/coap/coap_time.h [deleted file]
src/include/coap/config.h [deleted file]
src/include/coap/debug.h [deleted file]
src/include/coap/encode.h [deleted file]
src/include/coap/hashkey.h [deleted file]
src/include/coap/mem.h [deleted file]
src/include/coap/net.h [deleted file]
src/include/coap/option.h [deleted file]
src/include/coap/pdu.h [deleted file]
src/include/coap/prng.h [deleted file]
src/include/coap/resource.h [deleted file]
src/include/coap/str.h [deleted file]
src/include/coap/subscribe.h [deleted file]
src/include/coap/t_list.h [deleted file]
src/include/coap/uri.h [deleted file]
src/include/coap/uthash.h [deleted file]
src/include/coap/utlist.h [deleted file]
src/include/hw_emul/hw_interface.h [deleted file]
src/include/hw_emul/ss_emul.h [deleted file]
src/include/security/base64.h [deleted file]
src/include/security/iotvticalendar.h [deleted file]
src/include/security/oxmverifycommon.h [deleted file]
src/include/security/pbkdf2.h [deleted file]
src/include/security/pinoxmcommon.h [deleted file]
src/include/security/pkix_interface.h [deleted file]
src/include/security/securevirtualresourcetypes.h [deleted file]
src/include/security/srmutility.h [deleted file]
src/mot-agent/CMakeLists.txt
src/mot-agent/ma-db.c [deleted file]
src/mot-agent/ma-db.h [deleted file]
src/mot-agent/ma-log.h [changed mode: 0755->0644]
src/mot-agent/ma-subowner.c
src/mot-agent/ma-util.c
src/mot-agent/ma-util.h
test/CMakeLists.txt [deleted file]
test/common.cpp [deleted file]
test/common.h [deleted file]
test/hw_interface.c [deleted file]
test/ocamsservice.cpp [deleted file]
test/ocserverbasicops.cpp [deleted file]
test/ocserverbasicops.h [deleted file]
test/oic_amss_db.dat [deleted file]
test/oic_amss_db.json [deleted file]
test/oic_svr_db_client.dat [deleted file]
test/oic_svr_db_client.json [deleted file]
test/oic_svr_db_client_devowner.dat [deleted file]
test/oic_svr_db_client_devowner.json [deleted file]
test/oic_svr_db_client_directpairing.dat [deleted file]
test/oic_svr_db_client_directpairing.json [deleted file]
test/oic_svr_db_client_nondevowner.dat [deleted file]
test/oic_svr_db_client_nondevowner.json [deleted file]
test/oic_svr_db_randompin_with_empty_deviceid.dat [deleted file]
test/oic_svr_db_randompin_with_empty_deviceid.json [deleted file]
test/oic_svr_db_server.dat [deleted file]
test/oic_svr_db_server.json [deleted file]
test/oic_svr_db_server_justworks.dat [deleted file]
test/oic_svr_db_server_justworks.json [deleted file]
test/oic_svr_db_server_justworks_default.dat [deleted file]
test/oic_svr_db_server_justworks_protectedDB_plain.dat [deleted file]
test/oic_svr_db_server_mfg.dat [deleted file]
test/oic_svr_db_server_mvjustworks.dat [deleted file]
test/oic_svr_db_server_mvjustworks.json [deleted file]
test/oic_svr_db_server_preconfpin.dat [deleted file]
test/oic_svr_db_server_preconfpin.json [deleted file]
test/oic_svr_db_server_randompin.dat [deleted file]
test/oic_svr_db_server_randompin.json [deleted file]
test/oic_svr_db_subowner_client.dat [deleted file]
test/oic_svr_db_subowner_client.json [deleted file]
test/provisioningclient.c [deleted file]
test/rootca.crt [deleted file]
test/sampleserver_justworks.cpp [deleted file]
test/sampleserver_justworks_protectedDB.cpp [deleted file]
test/sampleserver_mfg.cpp [deleted file]
test/sampleserver_mvjustworks.cpp [deleted file]
test/sampleserver_preconfpin.cpp [deleted file]
test/sampleserver_randompin.cpp [deleted file]
test/ss_emul.c [deleted file]
test/subownerclient.c [deleted file]

index 5eb9531..9f51414 100644 (file)
@@ -42,5 +42,4 @@ ADD_DEFINITIONS("-DTCP_ADAPTER")
 MESSAGE(" - Start building src directories")
 ADD_SUBDIRECTORY(src/mot-agent)
 ADD_SUBDIRECTORY(src/companion-manager)
-ADD_SUBDIRECTORY(test)
 ADD_SUBDIRECTORY(capi)
old mode 100644 (file)
new mode 100755 (executable)
index 84998fb..72842e8
@@ -108,8 +108,6 @@ cp %{SOURCE9} %{buildroot}%{_datadir}/dbus-1/system-services/net.ma.service
 mkdir -p %{buildroot}%{_unitdir}
 cp %{SOURCE8} %{buildroot}%{_unitdir}/ma.service
 
-cp test/oic_svr_db_client.dat oic_svr_db_subowner_client.dat
-
 %postun
 rm -rf %{NETWORK_FW_DATADIR}/*.db
 rm -rf %{NETWORK_FW_DATADIR}/*.db-journal
@@ -128,25 +126,6 @@ rm -rf %{NETWORK_FW_DATADIR}/*.db-journal
 
 %files devel
 %manifest %{name}-devel.manifest
-%defattr(-,network_fw,network_fw,-)
-#%{NETWORK_FW_DATADIR}/oic_amss_db.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_client_devowner.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_client_directpairing.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_client_nondevowner.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_randompin_with_empty_deviceid.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_server_justworks_default.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_server_justworks_protectedDB_plain.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_server_mfg.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_server_mvjustworks.dat
-#%{NETWORK_FW_DATADIR}/oic_svr_db_server_preconfpin.dat
-%{NETWORK_FW_DATADIR}/oic_svr_db_client.dat
-%{NETWORK_FW_DATADIR}/oic_svr_db_server.dat
-%{NETWORK_FW_DATADIR}/oic_svr_db_server_justworks.dat
-%{NETWORK_FW_DATADIR}/oic_svr_db_subowner_client.dat
-%attr(750,network_fw,network_fw) %{_sbindir}/ocserverbasicops
-%attr(750,network_fw,network_fw) %{_sbindir}/sampleserver_justworks
-%attr(750,network_fw,network_fw) %{_sbindir}/provisioningclient
-%attr(750,network_fw,network_fw) %{_sbindir}/subownerclient
 
 %files capi
 %manifest capi-network-companion.manifest
diff --git a/packaging/fnm.service b/packaging/fnm.service
deleted file mode 100644 (file)
index fdba735..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-[Unit]
-Description=OCF Familynet Manager
-After=feedbckd.service
-
-[Service]
-Type=dbus
-User=network_fw
-Group=network_fw
-BusName=net.fn.manager
-SmackProcessLabel=System
-ExecStart=/usr/bin/fn-manager
-
-[Install]
-WantedBy=multi-user.target
diff --git a/packaging/net.fnm.service b/packaging/net.fnm.service
deleted file mode 100644 (file)
index ef695d2..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-[D-BUS Service]
-Name=net.fn.enabler
-
-Exec=/bin/false
-User=network_fw
-Group=network_fw
-SystemdService=fnm.service
-
-[Install]
-WantedBy=multi-user.target
index 1718bb4..9eaee14 100644 (file)
@@ -3,7 +3,6 @@ MESSAGE("Building...companion-manager")
 MESSAGE("===================================================================")
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include/cjson)
 
 FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
 EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
index ff3b209..a66a5d8 100644 (file)
@@ -296,8 +296,8 @@ gboolean group_get_my_uuid(Group *group,
        return TRUE;
 }
 
-gboolean group_request_create_group(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid, gchar *group_name, gpointer user_data)
+gboolean group_request_create_group(Group *group, GDBusMethodInvocation
+       *invocation, gchar *uuid, gchar *group_name, gpointer user_data)
 {
        int ret = 0;
 
@@ -310,8 +310,8 @@ gboolean group_request_create_group(Group *group, GDBusMethodInvocation *invocat
        return TRUE;
 }
 
-gboolean group_request_invite(Group *group, GDBusMethodInvocation *invocation, gchar *uuid,
-       gchar *group_name, gchar *target_uuid, gchar *PIN, gpointer user_data)
+gboolean group_request_invite(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid, gchar *group_name, gchar *target_uuid, gchar *PIN, gpointer user_data)
 {
        int ret = 0;
 
@@ -324,8 +324,8 @@ gboolean group_request_invite(Group *group, GDBusMethodInvocation *invocation, g
        return TRUE;
 }
 
-gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation, gchar *uuid,
-       gchar *group_name, gchar *target_uuid, gpointer user_data)
+gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation,
+       gchar *uuid, gchar *group_name, gchar *target_uuid, gpointer user_data)
 {
        int ret = 0;
 
@@ -338,8 +338,8 @@ gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation, gc
        return TRUE;
 }
 
-gboolean group_request_delete_group(Group *group, GDBusMethodInvocation *invocation,
-       gchar *uuid, gchar *group_name, gpointer user_data)
+gboolean group_request_delete_group(Group *group,
+       GDBusMethodInvocation *invocation, gchar *uuid, gchar *group_name, gpointer user_data)
 {
        int ret = 0;
 
index e9bcac7..cc8c281 100644 (file)
 
 #include <utlist.h>
 #include <base64.h>
-#include <srmutility.h>
+
+#include <octypes.h>
+#include <pmtypes.h>
+#include <pmutility.h>
+#include <securevirtualresourcetypes.h>
+
 #include <iotivity_config.h>
 #include <platform_features.h>
 #include <ocprovisioningmanager.h>
@@ -49,6 +54,42 @@ using namespace std;
 int last_get_result;
 OCPersistentStorage ps;
 
+static int ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid)
+{
+       if(NULL == uuid || NULL == strUuid || NULL != *strUuid)
+       {
+               LOG_ERR("ConvertUuidToStr : Invalid param");
+               return OC_STACK_INVALID_PARAM;
+       }
+
+       size_t uuidIdx = 0;
+       size_t urnIdx = 0;
+       const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1;
+       char* convertedUrn = (char*)calloc(urnBufSize, sizeof(char));
+       if (NULL == convertedUrn) {
+               LOG_ERR("Memory Allocation Failed");
+               goto exit;
+       }
+
+       for(uuidIdx=0, urnIdx=0;  uuidIdx < UUID_LENGTH && urnIdx < urnBufSize; uuidIdx++, urnIdx+=2)
+       {
+               // canonical format for UUID has '8-4-4-4-12'
+               if(uuidIdx==4 || uuidIdx==6 || uuidIdx==8 || uuidIdx==10)
+               {
+                       snprintf(convertedUrn + urnIdx, 2, "%c", '-');
+                       urnIdx++;
+               }
+               snprintf(convertedUrn + urnIdx, 3, "%02x", (uint8_t)(uuid->id[uuidIdx]));
+       }
+       convertedUrn[urnBufSize - 1] = '\0';
+
+       *strUuid = convertedUrn;
+       return OC_STACK_OK;
+
+exit:
+       return OC_STACK_NO_MEMORY;
+}
+
 #define CASE_TO_STR(x) case x: return #x;
 
 static const char *command2string(comp_request_type_e command)
diff --git a/src/include/cjson/cJSON.h b/src/include/cjson/cJSON.h
deleted file mode 100644 (file)
index dbbb739..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
-  Copyright (c) 2009 Dave Gamble
-
-  Permission is hereby granted, free of charge, to any person obtaining a copy
-  of this software and associated documentation files (the "Software"), to deal
-  in the Software without restriction, including without limitation the rights
-  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-  copies of the Software, and to permit persons to whom the Software is
-  furnished to do so, subject to the following conditions:
-
-  The above copyright notice and this permission notice shall be included in
-  all copies or substantial portions of the Software.
-
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-  THE SOFTWARE.
-*/
-
-#ifndef cJSON__h
-#define cJSON__h
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include <stddef.h>
-
-/* cJSON Types: */
-#define cJSON_False  (1 << 0)
-#define cJSON_True   (1 << 1)
-#define cJSON_NULL   (1 << 2)
-#define cJSON_Number (1 << 3)
-#define cJSON_String (1 << 4)
-#define cJSON_Array  (1 << 5)
-#define cJSON_Object (1 << 6)
-
-#define cJSON_IsReference 256
-#define cJSON_StringIsConst 512
-
-/* The cJSON structure: */
-typedef struct cJSON
-{
-    /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
-    struct cJSON *next;
-    struct cJSON *prev;
-    /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
-    struct cJSON *child;
-
-    /* The type of the item, as above. */
-    int type;
-
-    /* The item's string, if type==cJSON_String */
-    char *valuestring;
-    /* The item's number, if type==cJSON_Number */
-    int valueint;
-    /* The item's number, if type==cJSON_Number */
-    double valuedouble;
-
-    /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
-    char *string;
-} cJSON;
-
-typedef struct cJSON_Hooks
-{
-      void *(*malloc_fn)(size_t sz);
-      void (*free_fn)(void *ptr);
-} cJSON_Hooks;
-
-/* Supply malloc, realloc and free functions to cJSON */
-extern void cJSON_InitHooks(cJSON_Hooks* hooks);
-
-
-/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
-extern cJSON *cJSON_Parse(const char *value);
-/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
-extern char  *cJSON_Print(const cJSON *item);
-/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
-extern char  *cJSON_PrintUnformatted(const cJSON *item);
-/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
-extern char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, int fmt);
-/* Delete a cJSON entity and all subentities. */
-extern void   cJSON_Delete(cJSON *c);
-
-/* Returns the number of items in an array (or object). */
-extern int       cJSON_GetArraySize(const cJSON *array);
-/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
-extern cJSON *cJSON_GetArrayItem(const cJSON *array, int item);
-/* Get item "string" from object. Case insensitive. */
-extern cJSON *cJSON_GetObjectItem(const cJSON *object, const char *string);
-extern int cJSON_HasObjectItem(const cJSON *object, const char *string);
-/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
-extern const char *cJSON_GetErrorPtr(void);
-
-/* These calls create a cJSON item of the appropriate type. */
-extern cJSON *cJSON_CreateNull(void);
-extern cJSON *cJSON_CreateTrue(void);
-extern cJSON *cJSON_CreateFalse(void);
-extern cJSON *cJSON_CreateBool(int b);
-extern cJSON *cJSON_CreateNumber(double num);
-extern cJSON *cJSON_CreateString(const char *string);
-extern cJSON *cJSON_CreateArray(void);
-extern cJSON *cJSON_CreateObject(void);
-
-/* These utilities create an Array of count items. */
-extern cJSON *cJSON_CreateIntArray(const int *numbers, int count);
-extern cJSON *cJSON_CreateFloatArray(const float *numbers, int count);
-extern cJSON *cJSON_CreateDoubleArray(const double *numbers, int count);
-extern cJSON *cJSON_CreateStringArray(const char **strings, int count);
-
-/* Append item to the specified array/object. */
-extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
-extern void    cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
-extern void    cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);        /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object */
-/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
-extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
-extern void    cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
-
-/* Remove/Detatch items from Arrays/Objects. */
-extern cJSON *cJSON_DetachItemFromArray(cJSON *array, int which);
-extern void   cJSON_DeleteItemFromArray(cJSON *array, int which);
-extern cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string);
-extern void   cJSON_DeleteItemFromObject(cJSON *object, const char *string);
-
-/* Update array items. */
-extern void cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
-extern void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
-extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
-
-/* Duplicate a cJSON item */
-extern cJSON *cJSON_Duplicate(const cJSON *item, int recurse);
-/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
-need to be released. With recurse!=0, it will duplicate any children connected to the item.
-The item->next and ->prev pointers are always zero on return from Duplicate. */
-
-/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
-/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error. If not, then cJSON_GetErrorPtr() does the job. */
-extern cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, int require_null_terminated);
-
-extern void cJSON_Minify(char *json);
-
-/* Macros for creating things quickly. */
-#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
-#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
-#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
-#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
-#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
-#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
-
-/* When assigning an integer value, it needs to be propagated to valuedouble too. */
-#define cJSON_SetIntValue(object,val) ((object) ? (object)->valueint = (object)->valuedouble = (val) : (val))
-#define cJSON_SetNumberValue(object,val) ((object) ? (object)->valueint = (object)->valuedouble = (val) : (val))
-
-/* Macro for iterating over an array */
-#define cJSON_ArrayForEach(pos, head) for(pos = (head)->child; pos != NULL; pos = pos->next)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/include/coap/address.h b/src/include/coap/address.h
deleted file mode 100644 (file)
index 65c4259..0000000
+++ /dev/null
@@ -1,227 +0,0 @@
-/* address.h -- representation of network addresses
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-/**
- * @file address.h
- * @brief representation of network addresses
- */
-
-#ifndef _COAP_ADDRESS_H_
-#define _COAP_ADDRESS_H_
-
-#include "config.h"
-
-#ifdef HAVE_ASSERT_H
-#include <assert.h>
-#else
-#ifndef assert
-#warning "assertions are disabled"
-#  define assert(x)
-#endif
-#endif
-
-#include <string.h>
-#include <stdint.h>
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <sys/socket.h>
-#endif
-
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-#endif
-
-#ifdef HAVE_WS2TCPIP_H
-#include <ws2tcpip.h>
-#endif
-
-#ifdef WITH_ARDUINO
-#define DEV_ADDR_SIZE_MAX (16)
-#endif
-
-#ifdef WITH_LWIP
-#include <lwip/ip_addr.h>
-
-typedef struct coap_address_t
-{
-    uint16_t port;
-    ip_addr_t addr;
-}coap_address_t;
-
-/* FIXME oversimplification: just assuming it's an ipv4 address instead of
- * looking up the appropraite lwip function */
-
-#define _coap_address_equals_impl(A, B) ((A)->addr.addr == (B)->addr.addr && A->port == B->port)
-
-/* FIXME sure there is something in lwip */
-
-#define _coap_is_mcast_impl(Address) 0
-
-#endif /* WITH_LWIP */
-#ifdef WITH_CONTIKI
-#include "uip.h"
-
-typedef struct coap_address_t
-{
-    unsigned char size;
-    uip_ipaddr_t addr;
-    unsigned short port;
-}coap_address_t;
-
-#define _coap_address_equals_impl(A,B)                         \
-  ((A)->size == (B)->size                                      \
-   && (A)->port == (B)->port                                   \
-   && uip_ipaddr_cmp(&((A)->addr),&((B)->addr)))
-
-#define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr))
-#endif /* WITH_CONTIKI */
-#if defined(WITH_POSIX) || defined(_WIN32)
-
-/** multi-purpose address abstraction */
-typedef struct coap_address_t
-{
-    socklen_t size; /**< size of addr */
-    union
-    {
-        struct sockaddr sa;
-        struct sockaddr_storage st;
-        struct sockaddr_in sin;
-        struct sockaddr_in6 sin6;
-    }addr;
-}coap_address_t;
-
-INLINE_API int
-_coap_address_equals_impl(const coap_address_t *a,
-        const coap_address_t *b)
-{
-    if (a->size != b->size || a->addr.sa.sa_family != b->addr.sa.sa_family)
-    return 0;
-
-    /* need to compare only relevant parts of sockaddr_in6 */
-    switch (a->addr.sa.sa_family)
-    {
-        case AF_INET:
-        return
-        a->addr.sin.sin_port == b->addr.sin.sin_port &&
-        memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr,
-                sizeof(struct in_addr)) == 0;
-        case AF_INET6:
-        return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port &&
-        memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr,
-                sizeof(struct in6_addr)) == 0;
-        default: /* fall through and signal error */
-        ;
-    }
-    return 0;
-}
-
-INLINE_API int
-_coap_is_mcast_impl(const coap_address_t *a)
-{
-    if (!a)
-    {
-        return 0;
-    }
-    switch (a->addr.sa.sa_family)
-    {
-        case AF_INET:
-        return IN_MULTICAST(a->addr.sin.sin_addr.s_addr);
-/* TODO - Enable this once IPv6 comes in TizenRT */
-#ifndef __TIZENRT__
-        case AF_INET6:
-        return IN6_IS_ADDR_MULTICAST(&a->addr.sin6.sin6_addr);
-#endif
-        default: /* fall through and signal error */
-        ;
-    }
-    return 0;
-}
-#endif /* WITH_POSIX */
-
-#ifdef WITH_ARDUINO
-typedef struct coap_address_t
-{
-    uint32_t     size;                    /**< length of the address stored in addr field. */
-    uint8_t      addr[DEV_ADDR_SIZE_MAX]; /**< device address. */
-} coap_address_t;
-
-INLINE_API int
-_coap_address_equals_impl(const coap_address_t *a,
-                          const coap_address_t *b)
-{
-    uint32_t i;
-
-    if ((a == NULL) || (b == NULL))
-        return 0;
-
-    if (a->size != b->size)
-        return 0;
-
-    for (i = 0; i < a->size; i++)
-    {
-        if (a->addr[i] != b->addr[i])
-            return 0;
-    }
-    return 1;
-}
-
-INLINE_API int
-_coap_is_mcast_impl(const coap_address_t *a)
-{
-    if (!a)
-        return 0;
-
-    /* TODO */
-    return 0;
-}
-
-#endif /* WITH_ARDUINO */
-
-/**
- * Resets the given coap_address_t object @p addr to its default
- * values.  In particular, the member size must be initialized to the
- * available size for storing addresses.
- *
- * @param addr The coap_address_t object to initialize.
- */
-INLINE_API void coap_address_init(coap_address_t *addr)
-{
-    assert(addr);
-    memset(addr, 0, sizeof(coap_address_t));
-#ifndef WITH_LWIP
-    /* lwip has constandt address sizes and doesn't need the .size part */
-    addr->size = sizeof(addr->addr);
-#endif
-}
-
-/**
- * Compares given address objects @p a and @p b. This function returns
- * @c 1 if addresses are equal, @c 0 otherwise. The parameters @p a
- * and @p b must not be @c NULL;
- */
-INLINE_API int coap_address_equals(const coap_address_t *a, const coap_address_t *b)
-{
-    assert(a);
-    assert(b);
-    return _coap_address_equals_impl(a, b);
-}
-
-/**
- * Checks if given address @p a denotes a multicast address.  This
- * function returns @c 1 if @p a is multicast, @c 0 otherwise.
- */
-INLINE_API int coap_is_mcast(const coap_address_t *a)
-{
-    return a && _coap_is_mcast_impl(a);
-}
-
-#endif /* _COAP_ADDRESS_H_ */
diff --git a/src/include/coap/async.h b/src/include/coap/async.h
deleted file mode 100644 (file)
index 0319827..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/* async.h -- state management for asynchronous messages
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-/**
- * @file async.h
- * @brief state management for asynchronous messages
- */
-
-#ifndef _COAP_ASYNC_H_
-#define _COAP_ASYNC_H_
-
-#include "config.h"
-#include "net.h"
-
-#ifndef WITHOUT_ASYNC
-
-/**
- * @defgroup coap_async Asynchronous Messaging
- * @{
- * Structure for managing asynchronous state of CoAP resources. A
- * coap_resource_t object holds a list of coap_async_state_t objects
- * that can be used to generate a separate response in case a result
- * of an operation cannot be delivered in time, or the resource has
- * been explicitly subscribed to with the option @c observe.
- */
-typedef struct coap_async_state_t
-{
-    unsigned char flags; /**< holds the flags to control behaviour */
-
-    /**
-     * Holds the internal time when the object was registered with a
-     * resource. This field will be updated whenever
-     * coap_register_async() is called for a specific resource.
-     */
-    coap_tick_t created;
-
-    /**
-     * This field can be used to register opaque application data with
-     * the asynchronous state object. */
-    void *appdata;
-
-    unsigned short message_id; /**< id of last message seen */
-    coap_tid_t id; /**< transaction id */
-
-    struct coap_async_state_t *next; /**< internally used for linking */
-
-    coap_address_t peer; /**< the peer to notify */
-    size_t tokenlen; /**< length of the token */
-    unsigned char token[]; /**< the token to use in a response */
-} coap_async_state_t;
-
-/* Definitions for Async Status Flags These flags can be used to
- * control the behaviour of asynchronous response generation. */
-#define COAP_ASYNC_CONFIRM   0x01 /**< send confirmable response */
-#define COAP_ASYNC_SEPARATE  0x02 /**< send separate response */
-#define COAP_ASYNC_OBSERVED  0x04 /**< the resource is being observed */
-
-/** release application data on destruction */
-#define COAP_ASYNC_RELEASE_DATA  0x08
-
-/**
- * Allocates a new coap_async_state_t object and fills its fields
- * according to the given @p request. The @p flags are used to control
- * generation of empty ACK responses to stop retransmissions and to
- * release registered @p data when the resource is deleted by
- * coap_free_async().  This function returns a pointer to the registered
- * coap_async_t object or @c NULL on error. Note that this function will
- * return @c NULL in case that an object with the same identifier is
- * already registered.
- *
- * @param context  The context to use.
- * @param peer     The remote peer that is to be asynchronously notified.
- * @param request  The request that is handled asynchronously.
- * @param flags    Flags to control state management.
- * @param data     Opaque application data to register. Note that the
- *                 storage occupied by @p data is released on destruction
- *                 only if flag COAP_ASYNC_RELEASE_DATA is set.
- *
- * @return A pointer to the registered coap_async_state_t object or
- * @c NULL in case of an error.
- */
-coap_async_state_t *
-coap_register_async(coap_context_t *context, coap_address_t *peer, coap_pdu_t *request,
-        unsigned char flags, void *data);
-
-/**
- * Removes the state object identified by @p id from @p context. The
- * removed object is returned in @p s, if found. Otherwise, @p s is
- * undefined. This function returns @c 1 if the object was removed, @c
- * 0 otherwise. Note that the storage allocated for the stored object
- * is not released by this functions. You will have to call
- * coap_free_async() to do so.
- *
- * @param context The context where the async object is registered.
- * @param id      The identifier of the asynchronous transaction.
- * @param s       Will be set to the object identified by @p id
- * after removal.
- *
- * @return @c 1 if object was removed and @p s updated, or @c 0 if no
- * object was found with the given id. @p s is valid only if the
- * return value is @c 1.
- */
-int coap_remove_async(coap_context_t *context, coap_tid_t id, coap_async_state_t **s);
-
-/**
- * Releases the memory that was allocated by coap_async_state_init()
- * for the object @p s. The registered application data will be
- * released automatically if COAP_ASYNC_RELEASE_DATA is set.
- *
- * @param s The object to delete.
- */
-void
-coap_free_async(coap_async_state_t *state);
-
-/**
- * Retrieves the object identified by @p id from the list of asynchronous
- * transactions that are registered with @p context. This function returns
- * a pointer to that object or @c NULL if not found.
- *
- * @param context The context where the asynchronous objects are
- * registered with.
- * @param id      The id of the object to retrieve.
- *
- * @return A pointer to the object identified by @p id or @c NULL if
- * not found.
- */
-coap_async_state_t *coap_find_async(coap_context_t *context, coap_tid_t id);
-
-/**
- * Updates the time stamp of @p s.
- *
- * @param s The state object to update.
- */
-INLINE_API void coap_touch_async(coap_async_state_t *s)
-{
-    coap_ticks(&s->created);
-}
-
-/** @} */
-
-#endif /*  WITHOUT_ASYNC */
-
-#endif /* _COAP_ASYNC_H_ */
diff --git a/src/include/coap/bits.h b/src/include/coap/bits.h
deleted file mode 100644 (file)
index 3ac7fe1..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * bits.h -- bit vector manipulation
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-/**
- * @file bits.h
- * @brief bit vector manipulation
- */
-
-#ifndef _BITS_H_
-#define _BITS_H_
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#include <stdint.h>
-
-/**
- * Sets the bit @p bit in bit-vector @p vec. This function returns @c
- * 1 if bit was set or @c -1 on error (i.e. when the given bit does
- * not fit in the vector).
- *
- * @param vec  The bit-vector to change.
- * @param size The size of @p vec in bytes.
- * @param bit  The bit to set in @p vec.
- *
- * @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
- */
-INLINE_API int bits_setb(uint8_t *vec, size_t size, uint8_t bit)
-{
-    if (size <= (size_t)(bit >> 3))
-        return -1;
-
-    *(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07));
-    return 1;
-}
-
-/**
- * Clears the bit @p bit from bit-vector @p vec. This function returns
- * @c 1 if bit was cleared or @c -1 on error (i.e. when the given bit
- * does not fit in the vector).
- *
- * @param vec  The bit-vector to change.
- * @param size The size of @p vec in bytes.
- * @param bit  The bit to clear from @p vec.
- *
- * @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
- */
-INLINE_API int bits_clrb(uint8_t *vec, size_t size, uint8_t bit)
-{
-    if (size <= (size_t)(bit >> 3))
-        return -1;
-
-    *(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07)));
-    return 1;
-}
-
-/**
- * Gets the status of bit @p bit from bit-vector @p vec. This function returns
- * @c 1 if the bit is set, @c 0 otherwise (even in case of an error)..
- *
- * @param vec  The bit-vector to read from..
- * @param size The size of @p vec in bytes.
- * @param bit  The bit to get from @p vec.
- *
- * @return @c 1 if the bit is set, @c 0 otherwise.
- */
-INLINE_API int bits_getb(const uint8_t *vec, size_t size, uint8_t bit)
-{
-    if (size <= (size_t)(bit >> 3))
-        return -1;
-
-    return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0;
-}
-
-#endif /* _BITS_H_ */
diff --git a/src/include/coap/block.h b/src/include/coap/block.h
deleted file mode 100644 (file)
index bd660ef..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/* block.h -- block transfer
- *
- * Copyright (C) 2010--2012,2014 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_BLOCK_H_
-#define _COAP_BLOCK_H_
-
-#include "option.h"
-#include "encode.h"
-#include "pdu.h"
-
-/**
- * @defgroup block Block Transfer
- * @{
- */
-
-#ifndef COAP_MAX_BLOCK_SZX
-/**
- * The largest value for the SZX component in a Block option. Note
- * that 1 << (COAP_MAX_BLOCK_SZX + 4) should not exceed
- * COAP_MAX_PDU_SIZE.
- */
-#define COAP_MAX_BLOCK_SZX      4
-#endif /* COAP_MAX_BLOCK_SZX */
-
-#if (COAP_MAX_PDU_SIZE - 6) < (1 << (COAP_MAX_BLOCK_SZX + 4))
-#error "COAP_MAX_BLOCK_SZX too large"
-#endif
-
-/**
- * Structure of Block options.
- */
-typedef struct
-{
-#ifdef WITH_ARDUINO
-    unsigned long int num : 20;
-#else
-    unsigned int num : 20;
-#endif
-    unsigned int m : 1; /**< 1 if more blocks follow, 0 otherwise */
-    unsigned int szx : 3; /**< block size */
-} coap_block_t;
-
-/**
- * Returns the value of the least significant byte of a Block option @p opt.
- * For zero-length options (i.e. num == m == szx == 0), COAP_OPT_BLOCK_LAST
- * returns @c NULL.
- */
-#define COAP_OPT_BLOCK_LAST(opt) \
-  (COAP_OPT_LENGTH(opt) ? (COAP_OPT_VALUE(opt) + (COAP_OPT_LENGTH(opt)-1)) : 0)
-
-/** Returns the value of the More-bit of a Block option @p opt. */
-#define COAP_OPT_BLOCK_MORE(opt) \
-  (COAP_OPT_LENGTH(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
-
-/** Returns the value of the SZX-field of a Block option @p opt. */
-#define COAP_OPT_BLOCK_SZX(opt)  \
-  (COAP_OPT_LENGTH(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
-
-/**
- * Returns the value of field @c num in the given block option @p
- * block_opt.
- */
-unsigned int coap_opt_block_num(const coap_opt_t *block_opt);
-
-/**
- * Checks if more than @p num blocks are required to deliver @p data_len
- * bytes of data for a block size of 1 << (@p szx + 4).
- */
-INLINE_API int coap_more_blocks(size_t data_len, unsigned int num, unsigned short szx)
-{
-    return ((num + 1) << (szx + 4)) < data_len;
-}
-
-/** Sets the More-bit in @p block_opt */
-INLINE_API void coap_opt_block_set_m(coap_opt_t *block_opt, int m)
-{
-    if (m)
-        *(COAP_OPT_VALUE(block_opt) + (COAP_OPT_LENGTH(block_opt) - 1)) |= 0x08;
-    else
-        *(COAP_OPT_VALUE(block_opt) + (COAP_OPT_LENGTH(block_opt) - 1)) &= ~0x08;
-}
-
-/**
- * Initializes @p block from @p pdu. @p type must be either COAP_OPTION_BLOCK1
- * or COAP_OPTION_BLOCK2. When option @p type was found in @p pdu, @p block
- * is initialized with values from this option and the function returns the
- * value @c 1. Otherwise, @c 0 is returned.
- *
- * @param pdu   The pdu to search for option @p type.
- * @param type  The option to search for (must be COAP_OPTION_BLOCK1 or
- *              COAP_OPTION_BLOCK2)
- * @param block The block structure to initilize.
- * @return @c 1 on success, @c 0 otherwise.
- */
-int coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block);
-
-/**
- * Writes a block option of type @p type to message @p pdu. If the
- * requested block size is too large to fit in @p pdu, it is reduced
- * accordingly. An exception is made for the final block when less
- * space is required. The actual length of the resource is specified
- * in @p data_length.
- *
- * This function may change *block to reflect the values written to
- * @p pdu. As the function takes into consideration the remaining space
- * @p pdu, no more options should be added after coap_write_block_opt()
- * has returned.
- *
- * @param block      The block structure to use. On return, this object
- *                   is updated according to the values that have been
- *                   written to @p pdu.
- * @param type       COAP_OPTION_BLOCK1 or COAP_OPTION_BLOCK2
- * @param pdu        The message where the block option should be
- *                   written.
- * @param data_length The length of the actual data that will be added
- *                   the @p pdu by calling coap_add_block().
- * @return @c 1 on success, or a negative value on error.
- */
-int coap_write_block_opt(coap_block_t *block, unsigned short type, coap_pdu_t *pdu,
-        size_t data_length);
-
-/**
- * Adds the @p block_num block of size 1 << (@p block_szx + 4) from
- * source @p data to @p pdu.
- *
- * @param pdu    The message to add the block
- * @param len    The length of @p data.
- * @param data   The source data to fill the block with
- * @param block_num The actual block number
- * @param block_szx Encoded size of block @p block_number
- * @return @c 1 on success, @c 0 otherwise.
- */
-int coap_add_block(coap_pdu_t *pdu, unsigned int len, const unsigned char *data,
-        unsigned int block_num, unsigned char block_szx);
-/**@}*/
-
-#endif /* _COAP_BLOCK_H_ */
diff --git a/src/include/coap/coap.h b/src/include/coap/coap.h
deleted file mode 100644 (file)
index 3ec274f..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/* coap.h -- main header file for CoAP stack
- *
- * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_H_
-#define _COAP_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "config.h"
-#include "debug.h"
-#include "mem.h"
-#include "coap_list.h"
-#include "pdu.h"
-#include "option.h"
-#include "net.h"
-#include "encode.h"
-#include "str.h"
-#include "uri.h"
-#include "async.h"
-#include "resource.h"
-#include "subscribe.h"
-#include "block.h"
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _COAP_H_ */
-
diff --git a/src/include/coap/coap_list.h b/src/include/coap/coap_list.h
deleted file mode 100644 (file)
index 22d8fba..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/* coap_list.h -- CoAP list structures
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_LIST_H_
-#define _COAP_LIST_H_
-
-struct coap_linkedlistnode
-{
-    struct coap_linkedlistnode *next;
-    void *data;
-
-    /**
-     * Callback function that is called from coap_delete to release
-     * additional memory allocated by data Set to NULL if you do not
-     * need this. Note that data is free'd automatically. */
-    void (*delete_func)(void *);
-};
-
-typedef struct coap_linkedlistnode coap_list_t;
-
-/**
- * Adds node to given queue, ordered by specified order function. Returns 1
- * when insert was successful, 0 otherwise.
- */
-int coap_insert(coap_list_t **queue, coap_list_t *node, int (*order)(void *, void *));
-
-/* destroys specified node */
-int coap_delete(coap_list_t *node);
-
-/* removes all items from given queue and frees the allocated storage */
-void coap_delete_list(coap_list_t *queue);
-
-/**
- * Creates a new list node and adds the given data object. The memory allocated
- * by data will be released by coap_delete() with the new node. Returns the
- * new list node.
- */
-coap_list_t *coap_new_listnode(void *data, void (*delete_func)(void *));
-
-#endif /* _COAP_LIST_H_ */
diff --git a/src/include/coap/coap_time.h b/src/include/coap/coap_time.h
deleted file mode 100644 (file)
index 64d1b26..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/* coap_time.h -- Clock Handling
- *
- * Copyright (C) 2010--2013 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-/**
- * @file coap_time.h
- * @brief Clock Handling
- */
-
-#ifndef _COAP_TIME_H_
-#define _COAP_TIME_H_
-
-/*
- ** Make sure we can call this stuff from C++.
- */
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "config.h"
-
-    /**
-     * @defgroup clock Clock Handling
-     * Default implementation of internal clock. You should redefine this if
-     * you do not have time() and gettimeofday().
-     * @{
-     */
-
-#ifdef HAVE_TIME_H
-#include <time.h>
-#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#ifdef WITH_LWIP
-
-#include <stdint.h>
-#include <lwip/sys.h>
-
-    /* lwIP provides ms in sys_now */
-#define COAP_TICKS_PER_SECOND 1000
-
-    typedef uint32_t coap_tick_t;
-
-    INLINE_API void coap_ticks_impl(coap_tick_t *t)
-    {
-        *t = sys_now();
-    }
-
-    INLINE_API void coap_clock_init_impl(void)
-    {
-    }
-
-#define coap_clock_init coap_clock_init_impl
-
-#define coap_ticks coap_ticks_impl
-
-#endif
-#ifdef WITH_CONTIKI
-#include "clock.h"
-
-    typedef clock_time_t coap_tick_t;
-
-    /**
-     * This data type is used to represent the difference between two
-     * clock_tick_t values. This data type must have the same size in
-     * memory as coap_tick_t to allow wrapping.
-     */
-    typedef int coap_tick_diff_t;
-
-#define COAP_TICKS_PER_SECOND CLOCK_SECOND
-
-    /** Set at startup to initialize the internal clock (time in seconds). */
-    extern clock_time_t clock_offset;
-
-    INLINE_API void
-    contiki_clock_init_impl(void)
-    {
-        clock_init();
-        clock_offset = clock_time();
-    }
-
-#define coap_clock_init contiki_clock_init_impl
-
-    INLINE_API void
-    contiki_ticks_impl(coap_tick_t *t)
-    {
-        *t = clock_time();
-    }
-
-#define coap_ticks contiki_ticks_impl
-
-#endif /* WITH_CONTIKI */
-#if defined(WITH_POSIX) || defined(_WIN32)
-    typedef unsigned int coap_tick_t;
-
-    /**
-     * This data type is used to represent the difference between two
-     * clock_tick_t values. This data type must have the same size in
-     * memory as coap_tick_t to allow wrapping.
-     */
-    typedef int coap_tick_diff_t;
-
-#define COAP_TICKS_PER_SECOND 1024
-
-    /** Set at startup to initialize the internal clock (time in seconds). */
-    extern time_t clock_offset;
-#endif /* WITH_POSIX || _WIN32 */
-
-#ifdef WITH_ARDUINO
-#include "Time.h"
-#ifdef ARDUINO_ARCH_SAM
-#include <sys/types.h>  // time_t is defined in sys/types.h for ARM compiler
-#else
-typedef unsigned long time_t; //AVR compiler doesnt define time_t
-#endif
-typedef time_t coap_tick_t;
-
-/**
- * This data type is used to represent the difference between two
- * clock_tick_t values. This data type must have the same size in
- * memory as coap_tick_t to allow wrapping.
- */
-typedef int coap_tick_diff_t;
-
-/* TODO: Ticks per second value for Arduino needs verification from
- * documentation */
-#define COAP_TICKS_PER_SECOND 1000
-
-extern time_t clock_offset;
-
-#endif /* WITH_ARDUINO */
-
-#ifndef coap_clock_init
-    INLINE_API void coap_clock_init_impl(void)
-    {
-#ifdef HAVE_TIME_H
-        clock_offset = time(NULL);
-#else
-#  ifdef WITH_ARDUINO
-#ifdef __AVR__
-    clock_offset = 1; //now();
-#else
-    clock_offset = now();
-#endif
-#  else
-#    ifdef __GNUC__
-    /* Issue a warning when using gcc. Other prepropressors do
-     *  not seem to have a similar feature. */
-#     warning "cannot initialize clock"
-#    endif
-    clock_offset = 0;
-#  endif /* WITH_ARDUINO */
-#endif /* HAVE_TIME */
-}
-#define coap_clock_init coap_clock_init_impl
-#endif /* coap_clock_init */
-
-#ifndef coap_ticks
-    INLINE_API void coap_ticks_impl(coap_tick_t *t)
-    {
-#ifdef HAVE_SYS_TIME_H
-        struct timeval tv;
-        gettimeofday(&tv, NULL);
-        *t = (tv.tv_sec - clock_offset) * COAP_TICKS_PER_SECOND
-                + (tv.tv_usec * COAP_TICKS_PER_SECOND / 1000000);
-#else
-#  ifdef WITH_ARDUINO
-    coap_tick_t tv;
-#ifdef __AVR__
-    tv = 1; //now();
-#else
-    tv = now();
-#endif
-    *t = (tv - clock_offset) * COAP_TICKS_PER_SECOND;
-#  else
-#ifdef HAVE_TIME_H
-    time_t tv = time(NULL);
-    *t = difftime(tv, clock_offset) * COAP_TICKS_PER_SECOND;
-#else
-#    error "clock not implemented"
-#endif /* HAVE_TIME_H */
-#  endif /* WITH_ARDUINO */
-#endif /* HAVE_SYS_TIME_H */
-}
-#define coap_ticks coap_ticks_impl
-#endif /* coap_ticks */
-
-    /**
-     * Returns @c 1 if and only if @p a is less than @p b where less is
-     * defined on a signed data type.
-     */
-    INLINE_API
-    int coap_time_lt(coap_tick_t a, coap_tick_t b)
-    {
-        return ((coap_tick_diff_t)(a - b)) < 0;
-    }
-
-    /**
-     * Returns @c 1 if and only if @p a is less than or equal @p b where
-     * less is defined on a signed data type.
-     */
-    INLINE_API
-    int coap_time_le(coap_tick_t a, coap_tick_t b)
-    {
-        return a == b || coap_time_lt(a, b);
-    }
-
-/** @} */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _COAP_TIME_H_ */
diff --git a/src/include/coap/config.h b/src/include/coap/config.h
deleted file mode 100644 (file)
index 5a27a31..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/* config.h.  Generated from config.h.in by configure.  */
-/* config.h.in.  Generated from configure.in by autoheader.  */
-
-/* Define if building universal (internal helper macro) */
-/* #undef AC_APPLE_UNIVERSAL_BUILD */
-
-/* Define to 1 if you have the <assert.h> header file. */
-#define HAVE_ASSERT_H 1
-
-/* Define to 1 if you have the `getaddrinfo' function. */
-#define HAVE_GETADDRINFO 1
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#define HAVE_INTTYPES_H 1
-
-/* Define to 1 if you have the `coap' library (-lcoap). */
-/* #undef HAVE_LIBCOAP */
-
-/* Define to 1 if you have the <limits.h> header file. */
-#define HAVE_LIMITS_H 1
-
-/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
- to 0 otherwise. */
-#define HAVE_MALLOC 1
-
-/* Define to 1 if you have the <memory.h> header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the `memset' function. */
-#define HAVE_MEMSET 1
-
-/* Define to 1 if you have the <netinet/in.h> header file. */
-#if !defined(WITH_ARDUINO) && !defined(_WIN32)
-#define HAVE_NETINET_IN_H 1
-#if defined (__TIZENRT__)
-#define HAVE_ARPA_INET_H 1
-#endif
-#endif
-
-/* Define to 1 if you have the `select' function. */
-#define HAVE_SELECT 1
-
-/* Define to 1 if you have the `socket' function. */
-#define HAVE_SOCKET 1
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#define HAVE_STDINT_H 1
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the `strcasecmp' function. */
-#define HAVE_STRCASECMP 1
-
-/* Define to 1 if you have the <strings.h> header file. */
-#define HAVE_STRINGS_H 1
-
-/* Define to 1 if you have the <string.h> header file. */
-#define HAVE_STRING_H 1
-
-/* Define to 1 if you have the `strnlen' function. */
-#define HAVE_STRNLEN 1
-
-/* Define to 1 if you have the `strrchr' function. */
-#define HAVE_STRRCHR 1
-
-/* Define to 1 if you have the <syslog.h> header file. */
-#if !defined(WITH_ARDUINO) && !defined(_WIN32)
-#define HAVE_SYSLOG_H 1
-#endif
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#if !defined(WITH_ARDUINO) && !defined(_WIN32)
-#define HAVE_SYS_TYPES_H 1
-#endif
-
-/* Define to 1 if you have the <sys/unistd.h> header file. */
-#if !defined(WITH_ARDUINO) && !defined(_WIN32)
-#define HAVE_SYS_UNISTD_H 1
-#endif
-
-/* Define to 1 if you have <Ws2tcpip.h> header file. */
-#if defined(_WIN32)
-#define HAVE_WS2TCPIP_H 1
-#endif
-
-/* Define to 1 if you have <Winsock2.h> header file. */
-#if defined(_WIN32)
-#define HAVE_WINSOCK2_H 1
-#endif
-
-/* Define to 1 if you have <Windows.h> header file. */
-#if defined(_WIN32)
-#define HAVE_WINDOWS_H 1
-#endif
-
-/* Define to 1 if you have the <time.h> header file. */
-#ifndef WITH_ARDUINO
-#define HAVE_TIME_H 1
-#endif
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#if !defined(WITH_ARDUINO) && !defined(_WIN32)
-#define HAVE_UNISTD_H 1
-#endif
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT ""
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME "libcoap"
-
-/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "libcoap 4.1.1"
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME "libcoap"
-
-/* Define to the home page for this package. */
-#define PACKAGE_URL ""
-
-/* Define to the version of this package. */
-#define PACKAGE_VERSION "4.1.1"
-
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
- significant byte first (like Motorola and SPARC, unlike Intel). */
-#if defined AC_APPLE_UNIVERSAL_BUILD
-# if defined __BIG_ENDIAN__
-#  define WORDS_BIGENDIAN 1
-# endif
-#else
-# if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
-#  define WORDS_BIGENDIAN 1
-# endif
-#endif
-
-#ifndef INLINE_API
-#  if defined(__cplusplus)
-#    define INLINE_API inline
-#  else
-#    ifdef _MSC_VER
-#      define INLINE_API static __inline
-#    else
-#      define INLINE_API static inline
-#    endif
-#  endif
-#endif
-
-/* Define to rpl_malloc if the replacement function should be used. */
-/* #undef malloc */
-
-/* Define to `unsigned int' if <sys/types.h> does not define. */
-/* #undef size_t */
-
-/* Define to `int' if <sys/types.h> does not define. */
-/* #undef ssize_t */
diff --git a/src/include/coap/debug.h b/src/include/coap/debug.h
deleted file mode 100644 (file)
index 4c55054..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/* debug.h -- debug utilities
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_DEBUG_H_
-#define _COAP_DEBUG_H_
-
-#include "config.h"
-
-#ifndef COAP_DEBUG_FD
-#define COAP_DEBUG_FD stdout
-#endif
-
-#ifndef COAP_ERR_FD
-#define COAP_ERR_FD stderr
-#endif
-
-#ifdef HAVE_SYSLOG_H
-#include <syslog.h>
-typedef short coap_log_t;
-#else
-/** Pre-defined log levels akin to what is used in \b syslog. */
-typedef enum
-{   LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARNING,
-    LOG_NOTICE, LOG_INFO, LOG_DEBUG
-}coap_log_t;
-#endif
-
-/** Returns the current log level. */
-coap_log_t coap_get_log_level();
-
-/** Sets the log level to the specified value. */
-void coap_set_log_level(coap_log_t level);
-
-/**
- * Writes the given text to @c COAP_ERR_FD (for @p level <= @c
- * LOG_CRIT) or @c COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The
- * text is output only when @p level is below or equal to the log
- * level that set by coap_set_log_level().
- */
-void coap_log_impl(coap_log_t level, const char *format, ...);
-
-#ifndef coap_log
-#define coap_log(...) coap_log_impl(__VA_ARGS__)
-#endif
-
-#ifndef NDEBUG
-
-/* A set of convenience macros for common log levels. */
-#define info(...) coap_log(LOG_INFO, __VA_ARGS__)
-#define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
-#define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
-
-#include "pdu.h"
-void coap_show_pdu(const coap_pdu_t *);
-
-struct coap_address_t;
-unsigned int print_readable(const unsigned char *data, unsigned int len, unsigned char *result,
-        unsigned int buflen, int encode_always);
-size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
-
-#else
-
-#define debug(...)
-#define info(...)
-#define warn(...)
-
-#define coap_show_pdu(x)
-#define coap_print_addr(...)
-
-#endif
-
-#endif /* _COAP_DEBUG_H_ */
diff --git a/src/include/coap/encode.h b/src/include/coap/encode.h
deleted file mode 100644 (file)
index 0ca2069..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/* encode.h -- encoding and decoding of CoAP data types
- *
- * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_ENCODE_H_
-#define _COAP_ENCODE_H_
-
-#if (BSD >= 199103) || defined(WITH_CONTIKI) || defined(__TIZENRT__)
-# include <string.h>
-#else
-#if !defined(WITH_ARDUINO) && !defined(_MSC_VER)
-# include <strings.h>
-#endif
-#endif
-
-#include "option.h"
-
-#define Nn 8  /* duplicate definition of N if built on sky motes */
-#define E 4
-#define HIBIT (1 << (Nn - 1))
-#define EMASK ((1 << E) - 1)
-#define MMASK ((1 << Nn) - 1 - EMASK)
-#define MAX_VALUE ( (1 << Nn) - (1 << E) ) * (1 << ((1 << E) - 1))
-
-#define COAP_PSEUDOFP_DECODE_8_4(r) (r < HIBIT ? r : (r & MMASK) << (r & EMASK))
-
-#ifndef HAVE_FLS
-/* include this only if fls() is not available */
-extern int coap_fls(unsigned int i);
-#else
-#define coap_fls(i) fls(i)
-#endif
-
-/* ls and s must be integer variables */
-#define COAP_PSEUDOFP_ENCODE_8_4_DOWN(v,ls) (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (v >> ls) & MMASK) + ls)
-#define COAP_PSEUDOFP_ENCODE_8_4_UP(v,ls,s) (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (s = (((v + ((1<<E<<ls)-1)) >> ls) & MMASK)), s == 0 ? HIBIT + ls + 1 : s + ls))
-
-/**
- * Decodes multiple-length byte sequences. buf points to an input byte
- * sequence of length len. Returns the decoded value.
- */
-unsigned int coap_decode_var_bytes(unsigned char *buf, unsigned int len);
-
-/**
- * Encodes multiple-length byte sequences. buf points to an output
- * buffer of sufficient length to store the encoded bytes. val is
- * the value to encode. Returns the number of bytes used to encode
- * val or 0 on error.
- */
-unsigned int coap_encode_var_bytes(unsigned char *buf, unsigned int val);
-
-/**
- * Tests whether the option definition has a type that allows variable byte encoding.
- * Returns true when supported, false when not supported.
- */
-bool coap_is_var_bytes(coap_option_def_t* def);
-
-#endif /* _COAP_ENCODE_H_ */
diff --git a/src/include/coap/hashkey.h b/src/include/coap/hashkey.h
deleted file mode 100644 (file)
index 5ed5e03..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/* hashkey.h -- definition of hash key type and helper functions
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-/**
- * @file hashkey.h
- * @brief definition of hash key type and helper functions
- */
-
-#ifndef _COAP_HASHKEY_H_
-#define _COAP_HASHKEY_H_
-
-#include "str.h"
-
-typedef unsigned char coap_key_t[4];
-
-#ifndef coap_hash
-/**
- * Calculates a fast hash over the given string @p s of length @p len
- * and stores the result into @p h. Depending on the exact
- * implementation, this function cannot be used as one-way function to
- * check message integrity or simlar.
- *
- * @param s   The string used for hash calculation.
- * @param len The length of @p s.
- * @param h   The result buffer to store the calculated hash key.
- */
-void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h);
-
-#define coap_hash(String,Length,Result) \
-  coap_hash_impl((String),(Length),(Result))
-
-/* This is used to control the pre-set hash-keys for resources. */
-#define __COAP_DEFAULT_HASH
-#else
-#undef __COAP_DEFAULT_HASH
-#endif /* coap_hash */
-
-/**
- * Calls coap_hash() with given @c str object as parameter.
- *
- * @param Str Must contain a pointer to a coap string object.
- * @param H   A coap_key_t object to store the result.
- *
- * @hideinitializer
- */
-#define coap_str_hash(Str,H) {          \
-    assert(Str);                \
-    memset((H), 0, sizeof(coap_key_t));     \
-    coap_hash((H), (Str)->s, (Str)->length);    \
-  }
-
-#endif /* _COAP_HASHKEY_H_ */
diff --git a/src/include/coap/mem.h b/src/include/coap/mem.h
deleted file mode 100644 (file)
index 475df6a..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/* mem.h -- CoAP memory handling
- *          Currently, this is just a dummy for malloc/free
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_MEM_H_
-#define _COAP_MEM_H_
-
-#include <stdlib.h>
-
-#define coap_malloc(size) malloc(size)
-#define coap_free(size) free(size)
-
-#endif /* _COAP_MEM_H_ */
diff --git a/src/include/coap/net.h b/src/include/coap/net.h
deleted file mode 100644 (file)
index a841279..0000000
+++ /dev/null
@@ -1,459 +0,0 @@
-/* net.h -- CoAP network interface
- *
- * Copyright (C) 2010--2013 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_NET_H_
-#define _COAP_NET_H_
-
-#ifdef WITH_ARDUINO
-#include "Time.h"
-#endif /* WITH_ARDUINO */
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "config.h"
-
-#ifdef HAVE_ASSERT_H
-#include <assert.h>
-#else
-#ifndef assert
-#warning "assertions are disabled"
-#  define assert(x)
-#endif
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_TIME_H
-#include <time.h>
-#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#ifdef WITH_LWIP
-#include <lwip/ip_addr.h>
-#endif
-
-#include "option.h"
-#include "address.h"
-#include "prng.h"
-#include "pdu.h"
-#include "coap_time.h"
-
-    struct coap_queue_t;
-
-    typedef struct coap_queue_t
-    {
-        struct coap_queue_t *next;
-
-        coap_tick_t t; /**< when to send PDU for the next time */
-        unsigned char retransmit_cnt; /**< retransmission counter, will be removed when zero */
-        unsigned int timeout; /**< the randomized timeout value */
-
-        coap_address_t local; /**< local address */
-        coap_address_t remote; /**< remote address */
-        coap_tid_t id; /**< unique transaction id */
-
-        coap_pdu_t *pdu; /**< the CoAP PDU to send */
-    } coap_queue_t;
-
-    /** Adds node to given queue, ordered by node->t. */
-    int coap_insert_node(coap_queue_t **queue, coap_queue_t *node);
-
-    /** Destroys specified node. */
-    int coap_delete_node(coap_queue_t *node);
-
-    /** Removes all items from given queue and frees the allocated storage. */
-    void coap_delete_all(coap_queue_t *queue);
-
-    /** Creates a new node suitable for adding to the CoAP sendqueue. */
-    coap_queue_t *coap_new_node();
-
-    struct coap_resource_t;
-    struct coap_context_t;
-#ifndef WITHOUT_ASYNC
-    struct coap_async_state_t;
-#endif
-
-    /** Message handler that is used as call-back in coap_context_t */
-    typedef void (*coap_response_handler_t)(struct coap_context_t *, const coap_address_t *remote,
-            coap_pdu_t *sent, coap_pdu_t *received, const coap_tid_t id);
-
-#define COAP_MID_CACHE_SIZE 3
-    typedef struct
-    {
-        unsigned char flags[COAP_MID_CACHE_SIZE];
-        coap_key_t item[COAP_MID_CACHE_SIZE];
-    } coap_mid_cache_t;
-
-    /** The CoAP stack's global state is stored in a coap_context_t object */
-    typedef struct coap_context_t
-    {
-        coap_opt_filter_t known_options;
-#ifndef WITH_CONTIKI
-        struct coap_resource_t *resources; /**< hash table or list of known resources */
-#endif /* WITH_CONTIKI */
-#ifndef WITHOUT_ASYNC
-        /** list of asynchronous transactions */
-        struct coap_async_state_t *async_state;
-#endif /* WITHOUT_ASYNC */
-    /**
-     * The time stamp in the first element of the sendqeue is relative
-     * to sendqueue_basetime. */
-    coap_tick_t sendqueue_basetime;
-    coap_queue_t *sendqueue, *recvqueue;
-#if defined(WITH_POSIX) || defined(WITH_ARDUINO) || defined(_WIN32)
-    int sockfd; /**< send/receive socket */
-#endif /* WITH_POSIX || WITH_ARDUINO */
-#ifdef WITH_CONTIKI
-        struct uip_udp_conn *conn; /**< uIP connection object */
-
-        struct etimer retransmit_timer; /**< fires when the next packet must be sent */
-        struct etimer notify_timer; /**< used to check resources periodically */
-#endif /* WITH_CONTIKI */
-#ifdef WITH_LWIP
-        struct udp_pcb *pcb; /**< the underlying lwIP UDP PCB */
-        struct pbuf *pending_package; /**< pbuf containing the last received package if not handled yet. This is only used to pass the package from the udp_recv callback into the coap_read function, which frees the pbuf and clears this field. */
-        ip_addr_t pending_address; /**< the address associated with pending_package */
-        u16_t pending_port; /**< the port associated with pending_package */
-
-        uint8_t timer_configured; /**< Set to 1 when a retransmission is scheduled using lwIP timers for this context, otherwise 0. */
-#endif /* WITH_LWIP */
-
-        /**
-         * The last message id that was used is stored in this field.  The
-         * initial value is set by coap_new_context() and is usually a
-         * random value. A new message id can be created with
-         * coap_new_message_id().
-         */
-        unsigned short message_id;
-
-        /**
-         * The next value to be used for Observe. This field is global for
-         * all resources and will be updated when notifications are created.
-         */
-        unsigned int observe;
-
-        coap_response_handler_t response_handler;
-    } coap_context_t;
-
-    /**
-     * Registers a new message handler that is called whenever a response
-     * was received that matches an ongoing transaction.
-     *
-     * @param context The context to register the handler for.
-     * @param handler The response handler to register.
-     */
-    INLINE_API void coap_register_response_handler(coap_context_t *context,
-            coap_response_handler_t handler)
-    {
-        context->response_handler = handler;
-    }
-
-    /**
-     * Registers the option type @p type with the given context object @p
-     * ctx.
-     *
-     * @param ctx  The context to use.
-     * @param type The option type to register.
-     */
-    INLINE_API void coap_register_option(coap_context_t *ctx, unsigned char type)
-    {
-        coap_option_setb(ctx->known_options, type);
-    }
-
-    /**
-     * Set sendqueue_basetime in the given context object @p ctx to @p
-     * now. This function returns the number of elements in the queue
-     * head that have timed out.
-     */
-    unsigned int coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now);
-
-    /** Returns the next pdu to send without removing from sendqeue. */
-    coap_queue_t *coap_peek_next(coap_context_t *context);
-
-    /** Returns the next pdu to send and removes it from the sendqeue. */
-    coap_queue_t *coap_pop_next(coap_context_t *context);
-
-    /** Creates a new coap_context_t object that will hold the CoAP stack status.  */
-    coap_context_t *coap_new_context(const coap_address_t *listen_addr);
-
-/**
- * Returns a new message id and updates @p context->message_id
- * accordingly. The message id is returned in network byte order
- * to make it easier to read in tracing tools.
- *
- * @param context the current coap_context_t object
- * @return incremented message id in network byte order
- */
-INLINE_API unsigned short coap_new_message_id(coap_context_t *context)
-{
-    ++(context->message_id);
-#if defined(WITH_ARDUINO)
-    return ((context->message_id << 8) | ((context->message_id >> 8) & (0xFF)));
-#elif defined(WITH_CONTIKI)
-    return uip_htons(context->message_id);
-#else /* WITH_CONTIKI */
-    return htons(context->message_id);
-#endif
-    }
-
-    /* CoAP stack context must be released with coap_free_context() */
-    void coap_free_context(coap_context_t *context);
-
-    /**
-     * Sends a confirmed CoAP message to given destination. The memory
-     * that is allocated by pdu will not be released by
-     * coap_send_confirmed(). The caller must release the memory.
-     *
-     * @param context The CoAP context to use.
-     * @param dst     The address to send to.
-     * @param pdu     The CoAP PDU to send.
-     * @return The message id of the sent message or @c COAP_INVALID_TID on error.
-     */
-    coap_tid_t coap_send_confirmed(coap_context_t *context, const coap_address_t *dst,
-            coap_pdu_t *pdu);
-
-    /**
-     * Creates a new ACK PDU with specified error @p code. The options
-     * specified by the filter expression @p opts will be copied from the
-     * original request contained in @p request.  Unless @c
-     * SHORT_ERROR_RESPONSE was defined at build time, the textual reason
-     * phrase for @p code will be added as payload, with Content-Type @c
-     * 0.  This function returns a pointer to the new response message, or
-     * @c NULL on error. The storage allocated for the new message must be
-     * relased with coap_free().
-     *
-     * @param request Specification of the received (confirmable) request.
-     * @param code The error code to set.
-     * @param opts An option filter that specifies which options to copy
-     *             from the original request in @p node.
-     *
-     * @return A pointer to the new message or @c NULL on error.
-     */
-    coap_pdu_t *coap_new_error_response(coap_pdu_t *request, unsigned char code,
-            coap_opt_filter_t opts);
-    /**
-     * Sends a non-confirmed CoAP message to given destination. The memory
-     * that is allocated by pdu will not be released by coap_send().
-     * The caller must release the memory.
-     *
-     * @param context The CoAP context to use.
-     * @param dst     The address to send to.
-     * @param pdu     The CoAP PDU to send.
-     * @return The message id of the sent message or @c COAP_INVALID_TID on error.
-     */
-    coap_tid_t coap_send(coap_context_t *context, const coap_address_t *dst, coap_pdu_t *pdu);
-
-    /**
-     * Sends an error response with code @p code for request @p request to
-     * @p dst.  @p opts will be passed to coap_new_error_response() to
-     * copy marked options from the request. This function returns the
-     * transaction id if the message was sent, or @c COAP_INVALID_TID
-     * otherwise.
-     *
-     * @param context The context to use.
-     * @param request The original request to respond to.
-     * @param dst     The remote peer that sent the request.
-     * @param code    The reponse code.
-     * @param opts    A filter that specifies the options to copy from the
-     *                @p request.
-     *
-     * @return The transaction id if the message was sent, or @c
-     * COAP_INVALID_TID otherwise.
-     */
-    coap_tid_t coap_send_error(coap_context_t *context, coap_pdu_t *request,
-            const coap_address_t *dst, unsigned char code, coap_opt_filter_t opts);
-
-    /**
-     * Helper funktion to create and send a message with @p type (usually
-     * ACK or RST).  This function returns @c COAP_INVALID_TID when the
-     * message was not sent, a valid transaction id otherwise.
-     *
-     * @param context The CoAP context.
-     * @param dst Where to send the context.
-     * @param request The request that should be responded to.
-     * @param type Which type to set
-     * @return transaction id on success or @c COAP_INVALID_TID otherwise.
-     */
-    coap_tid_t
-    coap_send_message_type(coap_context_t *context, const coap_address_t *dst, coap_pdu_t *request,
-            unsigned char type);
-    /**
-     * Sends an ACK message with code @c 0 for the specified @p request to
-     * @p dst. This function returns the corresponding transaction id if
-     * the message was sent or @c COAP_INVALID_TID on error.
-     *
-     * @param context The context to use.
-     * @param dst     The destination address.
-     * @param request The request to be acknowledged.
-     *
-     * @return The transaction id if ACK was sent or @c COAP_INVALID_TID
-     * on error.
-     */
-    coap_tid_t coap_send_ack(coap_context_t *context, const coap_address_t *dst,
-            coap_pdu_t *request);
-
-    /**
-     * Sends an RST message with code @c 0 for the specified @p request to
-     * @p dst. This function returns the corresponding transaction id if
-     * the message was sent or @c COAP_INVALID_TID on error.
-     *
-     * @param context The context to use.
-     * @param dst     The destination address.
-     * @param request The request to be reset.
-     *
-     * @return The transaction id if RST was sent or @c COAP_INVALID_TID
-     * on error.
-     */
-    INLINE_API coap_tid_t coap_send_rst(coap_context_t *context, const coap_address_t *dst,
-            coap_pdu_t *request)
-    {
-        return coap_send_message_type(context, dst, request, COAP_MESSAGE_RST);
-    }
-
-    /** Handles retransmissions of confirmable messages */
-    coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node);
-
-    /**
-     * Reads data from the network and tries to parse as CoAP PDU. On success, 0 is returned
-     * and a new node with the parsed PDU is added to the receive queue in the specified context
-     * object.
-     */
-    int coap_read(coap_context_t *context);
-
-    /**
-     * Calculates a unique transaction id from given arguments @p peer and
-     * @p pdu. The id is returned in @p id.
-     *
-     * @param peer The remote party who sent @p pdu.
-     * @param pdu  The message that initiated the transaction.
-     * @param id   Set to the new id.
-     */
-    void coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu, coap_tid_t *id);
-
-    /**
-     * This function removes the element with given @p id from the list
-     * given list. If @p id was found, @p node is updated to point to the
-     * removed element. Note that the storage allocated by @p node is
-     * @b not released. The caller must do this manually using
-     * coap_delete_node(). This function returns @c 1 if the element with
-     * id @p id was found, @c 0 otherwise. For a return value of @c 0,
-     * the contents of @p node is undefined.
-     *
-     * @param queue The queue to search for @p id.
-     * @param id    The node id to look for.
-     * @param node  If found, @p node is updated to point to the
-     *   removed node. You must release the storage pointed to by
-     *   @p node manually.
-     *
-     * @return @c 1 if @p id was found, @c 0 otherwise.
-     */
-    int coap_remove_from_queue(coap_queue_t **queue, coap_tid_t id, coap_queue_t **node);
-
-    /**
-     * Removes the transaction identified by @p id from given @p queue.
-     * This is a convenience function for coap_remove_from_queue() with
-     * automatic deletion of the removed node.
-     *
-     * @param queue The queue to search for @p id.
-     * @param id    The transaction id.
-     *
-     * @return @c 1 if node was found, removed and destroyed, @c 0 otherwise.
-     */
-    INLINE_API int coap_remove_transaction(coap_queue_t **queue, coap_tid_t id)
-    {
-        coap_queue_t *node;
-        if (!coap_remove_from_queue(queue, id, &node))
-            return 0;
-
-        coap_delete_node(node);
-        return 1;
-    }
-
-    /**
-     * Retrieves transaction from queue.
-     * @queue The transaction queue to be searched
-     * @id Unique key of the transaction to find.
-     * @return A pointer to the transaction object or NULL if not found
-     */
-    coap_queue_t *coap_find_transaction(coap_queue_t *queue, coap_tid_t id);
-
-    /**
-     * Cancels all outstanding messages for peer @p dst that have the
-     * specified token.
-     *
-     * @param context The context in use
-     * @param dst     Destination address of the messages to remove.
-     * @param token   Message token
-     * @param token_length Actual length of @p token
-     */
-    void coap_cancel_all_messages(coap_context_t *context, const coap_address_t *dst,
-            const unsigned char *token, size_t token_length);
-
-    /** Dispatches the PDUs from the receive queue in given context. */
-    void coap_dispatch(coap_context_t *context, const char* responseData);
-
-    /** Returns 1 if there are no messages to send or to dispatch in the context's queues. */
-    int coap_can_exit(coap_context_t *context);
-
-    /**
-     * Returns the current value of an internal tick counter. The counter
-     * counts \c COAP_TICKS_PER_SECOND ticks every second.
-     */
-    void coap_ticks(coap_tick_t *);
-
-    /**
-     * Verifies that @p pdu contains no unknown critical options. Options
-     * must be registered at @p ctx, using the function
-     * coap_register_option(). A basic set of options is registered
-     * automatically by coap_new_context(). This function returns @c 1 if
-     * @p pdu is ok, @c 0 otherwise. The given filter object @p unknown
-     * will be updated with the unknown options. As only @c COAP_MAX_OPT
-     * options can be signalled this way, remaining options must be
-     * examined manually.
-     *
-     * @code
-     coap_opt_filter_t f = COAP_OPT_NONE;
-     coap_opt_iterator_t opt_iter;
-
-     if (coap_option_check_critical(ctx, pdu, f) == 0) {
-     coap_option_iterator_init(pdu, &opt_iter, f);
-
-     while (coap_option_next(&opt_iter)) {
-     if (opt_iter.type & 0x01) {
-     ... handle unknown critical option in opt_iter ...
-     }
-     }
-     }
-     * @endcode
-     *
-     * @param ctx      The context where all known options are registered.
-     * @param pdu      The PDU to check.
-     * @param unknown  The output filter that will be updated to indicate the
-     *                 unknown critical options found in @p pdu.
-     *
-     * @return @c 1 if everything was ok, @c 0 otherwise.
-     */
-    int coap_option_check_critical(coap_context_t *ctx, coap_pdu_t *pdu, coap_opt_filter_t unknown);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _COAP_NET_H_ */
diff --git a/src/include/coap/option.h b/src/include/coap/option.h
deleted file mode 100644 (file)
index 6463afd..0000000
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * option.h -- helpers for handling options in CoAP PDUs
- *
- * Copyright (C) 2010-2013 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-/**
- * @file option.h
- * @brief helpers for handling options in CoAP PDUs
- */
-
-#ifndef _OPTION_H_
-#define _OPTION_H_
-
-#include "bits.h"
-#include "pdu.h"
-
-/**
- * Use byte-oriented access methods here because sliding a complex
- * struct coap_opt_t over the data buffer may cause bus error on
- * certain platforms.
- */
-typedef unsigned char coap_opt_t;
-#define PCHAR(p) ((coap_opt_t *)(p))
-
-/** Representation of CoAP options. */
-typedef struct
-{
-    unsigned short delta;
-    size_t length;
-    unsigned char *value;
-} coap_option_t;
-
-
-/** Representation of the association between a CoAP option key and its
- *  data type and valid data length ranges.
- */
-typedef struct
-{
-    unsigned short key;     /**< The ID of the option the following values apply to. */
-    unsigned char type;     /**< The type of the option: u=uint, s=string, o=opaque. */
-    unsigned int min;       /**< The minimum number of bytes allowed for the option data */
-    unsigned int max;       /**< The maximum number of bytes allowed for the option data */
-} coap_option_def_t;
-
-/**
- * Parses the option pointed to by @p opt into @p result. This
- * function returns the number of bytes that have been parsed, or @c 0
- * on error. An error is signaled when illegal delta or length values
- * are encountered or when option parsing would result in reading past
- * the option (i.e. beyond opt + length).
- *
- * @param opt    The beginning of the option to parse.
- * @param length The maximum length of @p opt.
- * @param result A pointer to the coap_option_t structure that is
- *               filled with actual values iff coap_opt_parse() > 0.
- * @return The number of bytes parsed or @c 0 on error.
- */
-size_t coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result);
-
-/**
- * Returns the size of the given option, taking into account a
- * possible option jump.
- *
- * @param opt An option jump or the beginning of the option.
- * @return The number of bytes between @p opt and the end of
- *         the option starting at @p opt. In case of an error,
- *         this function returns @c 0 as options need at least
- *         one byte storage space.
- */
-size_t coap_opt_size(const coap_opt_t *opt);
-
-/** @deprecated { Use coap_opt_size() instead. } */
-#define COAP_OPT_SIZE(opt) coap_opt_size(opt)
-
-/**
- * Calculates the beginning of the PDU's option section.
- *
- * @param pdu The PDU containing the options.
- * @return A pointer to the first option if available, or @c NULL otherwise.
- */
-coap_opt_t *options_start(coap_pdu_t *pdu, coap_transport_t transport);
-
-/**
- * Interprets @p opt as pointer to a CoAP option and advances to
- * the next byte past this option.
- * @hideinitializer
- */
-#define options_next(opt) \
-  ((coap_opt_t *)((unsigned char *)(opt) + COAP_OPT_SIZE(opt)))
-
-/**
- * @defgroup opt_filter Option Filters
- * @{
- */
-
-/**
- * Fixed-size bit-vector we use for option filtering. It is large
- * enough to hold the highest option number known at build time (20 in
- * the core spec).
- */
-typedef unsigned char coap_opt_filter_t[(COAP_MAX_OPT >> 3) + 1];
-
-/** Pre-defined filter that includes all options. */
-#define COAP_OPT_ALL NULL
-
-/**
- * Clears filter @p f.
- *
- * @param f The filter to clear.
- */
-INLINE_API void coap_option_filter_clear(coap_opt_filter_t f)
-{
-    memset(f, 0, sizeof(coap_opt_filter_t));
-}
-
-/**
- * Sets the corresponding bit for @p type in @p filter. This function
- * returns @c 1 if bit was set or @c -1 on error (i.e. when the given
- * type does not fit in the filter).
- *
- * @param filter The filter object to change.
- * @param type   The type for which the bit should be set.
- *
- * @return @c 1 if bit was set, @c -1 otherwise.
- */
-INLINE_API int coap_option_setb(coap_opt_filter_t filter, unsigned short type)
-{
-    return bits_setb((uint8_t *) filter, sizeof(coap_opt_filter_t), type);
-}
-
-/**
- * Clears the corresponding bit for @p type in @p filter. This function
- * returns @c 1 if bit was cleared or @c -1 on error (i.e. when the given
- * type does not fit in the filter).
- *
- * @param filter The filter object to change.
- * @param type   The type for which the bit should be cleared.
- *
- * @return @c 1 if bit was set, @c -1 otherwise.
- */
-INLINE_API int coap_option_clrb(coap_opt_filter_t filter, unsigned short type)
-{
-    return bits_clrb((uint8_t *) filter, sizeof(coap_opt_filter_t), type);
-}
-
-/**
- * Gets the corresponding bit for @p type in @p filter. This function
- * returns @c 1 if the bit is set @c 0 if not, or @c -1 on error (i.e.
- * when the given type does not fit in the filter).
- *
- * @param filter The filter object to read bit from..
- * @param type   The type for which the bit should be read.
- *
- * @return @c 1 if bit was set, @c 0 if not, @c -1 on error.
- */
-INLINE_API int coap_option_getb(const coap_opt_filter_t filter, unsigned short type)
-{
-    return bits_getb((uint8_t *) filter, sizeof(coap_opt_filter_t), type);
-}
-
-/**
- * Iterator to run through PDU options. This object must be
- * initialized with coap_option_iterator_init(). Call
- * coap_option_next() to walk through the list of options until
- * coap_option_next() returns @c NULL.
- *
- * @code
- * coap_opt_t *option;
- * coap_opt_iterator_t opt_iter;
- * coap_option_iterator_init(pdu, &opt_iter, COAP_OPT_ALL);
- *
- * while ((option = coap_option_next(&opt_iter))) {
- *   ... do something with option ...
- * }
- * @endcode
- */
-typedef struct
-{
-    size_t length; /**< remaining length of PDU */
-    unsigned short type; /**< decoded option type */
-    unsigned int bad :1; /**< iterator object is ok if not set */
-    unsigned int filtered :1; /**< denotes whether or not filter is used */
-    coap_opt_t *next_option; /**< pointer to the unparsed next option */
-    coap_opt_filter_t filter; /**< option filter */
-} coap_opt_iterator_t;
-
-/**
- * Initializes the given option iterator @p oi to point to the beginning of the
- * @p pdu's option list. This function returns @p oi on success, @c NULL
- * otherwise (i.e. when no options exist). Note that a length check on the
- * option list must be performed before coap_option_iterator_init() is called.
- *
- * @param pdu    The PDU the options of which should be walked through.
- * @param oi     An iterator object that will be initilized.
- * @param filter An optional option type filter.
- *               With @p type != @c COAP_OPT_ALL, coap_option_next()
- *               will return only options matching this bitmask.
- *               Fence-post options @c 14, @c 28, @c 42, ... are always
- *               skipped.
- *
- * @return       The iterator object @p oi on success, @c NULL otherwise.
- */
-coap_opt_iterator_t *coap_option_iterator_init(coap_pdu_t *pdu,
-                                               coap_opt_iterator_t *oi,
-                                               const coap_opt_filter_t filter);
-
-/**
- * Initializes the given option iterator @p oi to point to the
- * beginning of the @p pdu's option list. This function returns @p oi
- * on success, @c NULL otherwise (i.e. when no options exist).
- * Note that a length check on the option list must be performed before
- * coap_option_iterator_init() is called.
- *
- * @param pdu  The PDU the options of which should be walked through.
- * @param oi   An iterator object that will be initilized.
- * @param filter An optional option type filter.
- *               With @p type != @c COAP_OPT_ALL, coap_option_next()
- *               will return only options matching this bitmask.
- *               Fence-post options @c 14, @c 28, @c 42, ... are always
- *               skipped.
- *
- * @return The iterator object @p oi on success, @c NULL otherwise.
- */
-coap_opt_iterator_t *coap_option_iterator_init2(coap_pdu_t *pdu, coap_opt_iterator_t *oi,
-        const coap_opt_filter_t filter, coap_transport_t transport);
-
-/**
- * Updates the iterator @p oi to point to the next option. This
- * function returns a pointer to that option or @c NULL if no more
- * options exist. The contents of @p oi will be updated. In
- * particular, @c oi->n specifies the current option's ordinal number
- * (counted from @c 1), @c oi->type is the option's type code, and @c
- * oi->option points to the beginning of the current option
- * itself. When advanced past the last option, @c oi->option will be
- * @c NULL.
- *
- * Note that options are skipped whose corresponding bits in the
- * filter specified with coap_option_iterator_init() are @c 0. Options
- * with type codes that do not fit in this filter hence will always be
- * returned.
- *
- * @param oi The option iterator to update.
- *
- * @return The next option or @c NULL if no more options exist.
- */
-coap_opt_t *coap_option_next(coap_opt_iterator_t *oi);
-
-/**
- * Retrieves the first option of type @p type from @p pdu. @p oi must
- * point to a coap_opt_iterator_t object that will be initialized by
- * this function to filter only options with code @p type. This
- * function returns the first option with this type, or @c NULL if not
- * found.
- *
- * @param pdu  The PDU to parse for options.
- * @param type The option type code to search for.
- * @param oi   An iterator object to use.
- *
- * @return A pointer to the first option of type @p type, or @c NULL
- *         if not found.
- */
-coap_opt_t *coap_check_option(coap_pdu_t *pdu, unsigned char type, coap_opt_iterator_t *oi);
-
-/**
- * Encodes the given delta and length values into @p opt. This
- * function returns the number of bytes that were required to encode
- * @p delta and @p length or @c 0 on error. Note that the result
- * indicates by how many bytes @p opt must be advanced to encode the
- * option value.
- *
- * @param opt    The option buffer space where @p delta and @p length are
- *               written
- * @param maxlen The maximum length of @p opt
- * @param delta The actual delta value to encode.
- * @param length The actual length value to encode.
- * @return The number of bytes used or @c 0 on error.
- */
-size_t coap_opt_setheader(coap_opt_t *opt, size_t maxlen, unsigned short delta, size_t length);
-
-/**
- * Encodes option with given @p delta into @p opt. This function returns
- * the number of bytes written to @p opt or @c 0 on error. This happens
- * especially when @p opt does not provide sufficient space to store
- * the option value, delta, and option jumps when required.
- *
- * @param opt   The option buffer space where @p val is written
- * @param n     Maximum length of @p opt.
- * @param delta The option delta.
- * @param val   The option value to copy into @p opt.
- * @param len   The actual length of @p val.
- * @return The number of bytes that have been written to @p opt or
- *         @c 0 on error. The return value will always be less than @p n.
- */
-size_t coap_opt_encode(coap_opt_t *opt, size_t n, unsigned short delta, const unsigned char *val,
-        size_t length);
-
-/**
- * Decodes the delta value of the next option. This function returns
- * the number of bytes read or @c 0 on error. The caller of this
- * function must ensure that it does not read over the boundaries
- * of @p opt (e.g. by calling coap_opt_check_delta().
- *
- * @param opt The option to examine
- * @return The number of bytes read or @c 0 on error.
- */
-unsigned short coap_opt_delta(const coap_opt_t *opt);
-
-/** @deprecated { Use coap_opt_delta() instead. } */
-#define COAP_OPT_DELTA(opt) coap_opt_delta(opt)
-
-/** @deprecated { Use coap_opt_encode() instead. } */
-#ifndef WITH_TCP
-#define COAP_OPT_SETDELTA(opt,val)          \
-  coap_opt_encode((opt), COAP_MAX_PDU_SIZE, (val), NULL, 0)
-#endif
-/**
- * Returns the length of the given option. @p opt must point to an
- * option jump or the beginning of the option. This function returns
- * @c 0 when @p opt is not an option or the actual length of @p opt
- * (which can be @c 0 as well).
- *
- * @note {The rationale for using @c 0 in case of an error is that in
- * most contexts, the result of this function is used to skip the next
- * coap_opt_length() bytes. }
- *
- * @param opt  The option whose length should be returned.
- * @return The option's length or @c 0 when undefined.
- */
-unsigned short coap_opt_length(const coap_opt_t *opt);
-
-/** @deprecated { Use coap_opt_length() instead. } */
-#define COAP_OPT_LENGTH(opt) coap_opt_length(opt)
-
-/**
- * Returns a pointer to the value of the given option. @p opt must
- * point to an option jump or the beginning of the option. This
- * function returns @c NULL if @p opt is not a valid option.
- *
- * @param opt  The option whose value should be returned.
- * @return A pointer to the option value or @c NULL on error.
- */
-unsigned char *coap_opt_value(coap_opt_t *opt);
-
-/**
- * Returns a pointer to the coap option range definitions. @key
- * must be a valid option ID. This function returns @c NULL if
- * @p key is not a valid option ID.
- *
- * @param key The option ID whose definition should be returned.
- * @return A pointer to the option definition.
- */
-coap_option_def_t* coap_opt_def(unsigned short key);
-
-/** @deprecated { Use coap_opt_value() instead. } */
-#define COAP_OPT_VALUE(opt) coap_opt_value((coap_opt_t *)opt)
-
-/** @} */
-
-#endif /* _OPTION_H_ */
diff --git a/src/include/coap/pdu.h b/src/include/coap/pdu.h
deleted file mode 100644 (file)
index 417473f..0000000
+++ /dev/null
@@ -1,660 +0,0 @@
-/* pdu.h -- CoAP message structure
- *
- * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_PDU_H_
-#define _COAP_PDU_H_
-
-#include "config.h"
-#include "coap_list.h"
-#include "uri.h"
-
-#ifdef WITH_LWIP
-#include <lwip/pbuf.h>
-#endif
-
-/* pre-defined constants that reflect defaults for CoAP */
-
-#define COAP_DEFAULT_RESPONSE_TIMEOUT  2 /* response timeout in seconds */
-#define COAP_DEFAULT_MAX_RETRANSMIT    4 /* max number of retransmissions */
-#define COAP_DEFAULT_PORT           5683 /* CoAP default UDP port */
-#define COAP_DEFAULT_MAX_AGE          60 /* default maximum object lifetime in seconds */
-#ifndef COAP_MAX_PDU_SIZE
-#ifdef WITH_ARDUINO
-#define COAP_MAX_PDU_SIZE           320 /* maximum size of a CoAP PDU for embedded platforms*/
-#else
-#define COAP_MAX_PDU_SIZE           1400 /* maximum size of a CoAP PDU for big platforms*/
-#endif
-#endif /* COAP_MAX_PDU_SIZE */
-
-#define COAP_DEFAULT_VERSION           1 /* version of CoAP supported */
-#define COAP_DEFAULT_SCHEME        "coap" /* the default scheme for CoAP URIs */
-
-/** well-known resources URI */
-#define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
-
-#ifdef __COAP_DEFAULT_HASH
-/* pre-calculated hash key for the default well-known URI */
-#define COAP_DEFAULT_WKC_HASHKEY   "\345\130\144\245"
-#endif
-
-/* CoAP message types */
-
-#define COAP_MESSAGE_CON               0 /* confirmable message (requires ACK/RST) */
-#define COAP_MESSAGE_NON               1 /* non-confirmable message (one-shot message) */
-#define COAP_MESSAGE_ACK               2 /* used to acknowledge confirmable messages */
-#define COAP_MESSAGE_RST               3 /* indicates error in received messages */
-
-/* CoAP request methods */
-
-#define COAP_REQUEST_GET       1
-#define COAP_REQUEST_POST      2
-#define COAP_REQUEST_PUT       3
-#define COAP_REQUEST_DELETE    4
-
-/* CoAP option types (be sure to update check_critical when adding options */
-
-#define COAP_OPTION_IF_MATCH      1 /* C, opaque, 0-8 B, (none) */
-#define COAP_OPTION_URI_HOST      3 /* C, String, 1-255 B, destination address */
-#define COAP_OPTION_ETAG          4 /* E, opaque, 1-8 B, (none) */
-#define COAP_OPTION_IF_NONE_MATCH 5 /* empty, 0 B, (none) */
-#define COAP_OPTION_URI_PORT      7 /* C, uint, 0-2 B, destination port */
-#define COAP_OPTION_LOCATION_PATH 8 /* E, String, 0-255 B, - */
-#define COAP_OPTION_URI_PATH     11 /* C, String, 0-255 B, (none) */
-#define COAP_OPTION_CONTENT_FORMAT 12 /* E, uint, 0-2 B, (none) */
-#define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
-#define COAP_OPTION_MAXAGE       14 /* E, uint, 0--4 B, 60 Seconds */
-#define COAP_OPTION_URI_QUERY    15 /* C, String, 1-255 B, (none) */
-#define COAP_OPTION_ACCEPT       17 /* C, uint,   0-2 B, (none) */
-#define COAP_OPTION_LOCATION_QUERY 20 /* E, String,   0-255 B, (none) */
-#define COAP_OPTION_PROXY_URI    35 /* C, String, 1-1034 B, (none) */
-#define COAP_OPTION_PROXY_SCHEME 39 /* C, String, 1-255 B, (none) */
-#define COAP_OPTION_SIZE1        60 /* E, uint, 0-4 B, (none) */
-#define COAP_OPTION_SIZE2        28 /* E, uint, 0-4 B, (none) */
-
-/* option types from draft-ietf-coap-observe-09 */
-
-#define COAP_OPTION_OBSERVE       6 /* E, empty/uint, 0 B/0-3 B, (none) */
-#define COAP_OPTION_SUBSCRIPTION  COAP_OPTION_OBSERVE
-
-/* selected option types from draft-core-block-04 */
-
-#define COAP_OPTION_BLOCK2       23 /* C, uint, 0--3 B, (none) */
-#define COAP_OPTION_BLOCK1       27 /* C, uint, 0--3 B, (none) */
-
-#define COAP_MAX_OPT             63 /**< the highest option number we know */
-
-/* CoAP result codes (HTTP-Code / 100 * 40 + HTTP-Code % 100) */
-
-/* As of draft-ietf-core-coap-04, response codes are encoded to base
- * 32, i.e.  the three upper bits determine the response class while
- * the remaining five fine-grained information specific to that class.
- */
-#define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
-
-/* Determines the class of response code C */
-#define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF)
-
-#ifndef SHORT_ERROR_RESPONSE
-/**
- * Returns a human-readable response phrase for the specified CoAP response @p
- * code. This function returns @c NULL if not found.
- *
- * @param code The response code for which the literal phrase should be
- *             retrieved.
- *
- * @return     A zero-terminated string describing the error, or @c NULL if not
- *             found.
- */
-char *coap_response_phrase(unsigned char code);
-
-#define COAP_ERROR_PHRASE_LENGTH 32 /**< maximum length of error phrase */
-
-#else
-#define coap_response_phrase(x) ((char *)NULL)
-
-#define COAP_ERROR_PHRASE_LENGTH 0 /**< maximum length of error phrase */
-#endif /* SHORT_ERROR_RESPONSE */
-
-/* The following definitions exist for backwards compatibility */
-#if 0 /* this does not exist any more */
-#define COAP_RESPONSE_100      40 /* 100 Continue */
-#endif
-#define COAP_RESPONSE_200      COAP_RESPONSE_CODE(200)  /* 2.00 OK */
-#define COAP_RESPONSE_201      COAP_RESPONSE_CODE(201)  /* 2.01 Created */
-#define COAP_RESPONSE_304      COAP_RESPONSE_CODE(203)  /* 2.03 Valid */
-#define COAP_RESPONSE_400      COAP_RESPONSE_CODE(400)  /* 4.00 Bad Request */
-#define COAP_RESPONSE_404      COAP_RESPONSE_CODE(404)  /* 4.04 Not Found */
-#define COAP_RESPONSE_405      COAP_RESPONSE_CODE(405)  /* 4.05 Method Not Allowed */
-#define COAP_RESPONSE_415      COAP_RESPONSE_CODE(415)  /* 4.15 Unsupported Media Type */
-#define COAP_RESPONSE_500      COAP_RESPONSE_CODE(500)  /* 5.00 Internal Server Error */
-#define COAP_RESPONSE_501      COAP_RESPONSE_CODE(501)  /* 5.01 Not Implemented */
-#define COAP_RESPONSE_503      COAP_RESPONSE_CODE(503)  /* 5.03 Service Unavailable */
-#define COAP_RESPONSE_504      COAP_RESPONSE_CODE(504)  /* 5.04 Gateway Timeout */
-#if 0  /* these response codes do not have a valid code any more */
-#  define COAP_RESPONSE_X_240    240   /* Token Option required by server */
-#  define COAP_RESPONSE_X_241    241   /* Uri-Authority Option required by server */
-#endif
-#define COAP_RESPONSE_X_242    COAP_RESPONSE_CODE(402)  /* Critical Option not supported */
-
-/* CoAP media type encoding */
-
-#define COAP_MEDIATYPE_TEXT_PLAIN                     0 /* text/plain (UTF-8) */
-#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT       40 /* application/link-format */
-#define COAP_MEDIATYPE_APPLICATION_XML               41 /* application/xml */
-#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM      42 /* application/octet-stream */
-#define COAP_MEDIATYPE_APPLICATION_RDF_XML           43 /* application/rdf+xml */
-#define COAP_MEDIATYPE_APPLICATION_EXI               47 /* application/exi  */
-#define COAP_MEDIATYPE_APPLICATION_JSON              50 /* application/json  */
-#define COAP_MEDIATYPE_APPLICATION_CBOR              60 /* application/cbor  */
-
-/* Note that identifiers for registered media types are in the range 0-65535. We
- * use an unallocated type here and hope for the best. */
-#define COAP_MEDIATYPE_ANY                         0xff /* any media type */
-
-/**
-  * coap_tid_t is used to store CoAP transaction id, i.e. a hash value
-  * built from the remote transport address and the message id of a
-  * CoAP PDU.  Valid transaction ids are greater or equal zero.
-  */
-typedef int coap_tid_t;
-
-/** Indicates an invalid transaction id. */
-#define COAP_INVALID_TID -1
-
-#define COAP_TCP_HEADER_NO_FIELD    2
-#define COAP_TCP_HEADER_8_BIT       3
-#define COAP_TCP_HEADER_16_BIT      4
-#define COAP_TCP_HEADER_32_BIT      6
-
-#define COAP_TCP_LENGTH_FIELD_8_BIT      13
-#define COAP_TCP_LENGTH_FIELD_16_BIT     269
-#define COAP_TCP_LENGTH_FIELD_32_BIT     65805
-
-#define COAP_TCP_LENGTH_LIMIT_8_BIT      13
-#define COAP_TCP_LENGTH_LIMIT_16_BIT     256
-#define COAP_TCP_LENGTH_LIMIT_32_BIT     65536
-
-#define COAP_TCP_LENGTH_FIELD_NUM_8_BIT      13
-#define COAP_TCP_LENGTH_FIELD_NUM_16_BIT     14
-#define COAP_TCP_LENGTH_FIELD_NUM_32_BIT     15
-
-#define COAP_OPTION_FIELD_8_BIT      12
-#define COAP_OPTION_FIELD_16_BIT     256
-#define COAP_OPTION_FIELD_32_BIT     65536
-
-typedef enum {
-    COAP_UDP = 0,
-    COAP_TCP,
-    COAP_TCP_8BIT,
-    COAP_TCP_16BIT,
-    COAP_TCP_32BIT
-} coap_transport_t;
-
-#ifdef WORDS_BIGENDIAN
-typedef struct {
-  unsigned short version:2;      /* protocol version */
-  unsigned short type:2;         /* type flag */
-  unsigned short token_length:4; /* length of Token */
-  unsigned short code:8;         /* request method (value 1--10) or response
-                                    code (value 40-255) */
-  unsigned short id;             /* message id */
-  unsigned char token[];         /* the actual token, if any */
-} coap_hdr_udp_t;
-#else
-typedef struct {
-  unsigned short token_length:4; /* length of Token */
-  unsigned short type:2;         /* type flag */
-  unsigned short version:2;      /* protocol version */
-  unsigned short code:8;         /* request method (value 1--10) or response
-                                    code (value 40-255) */
-  unsigned short id;             /* transaction id (network byte order!) */
-  unsigned char token[];         /* the actual token, if any */
-} coap_hdr_udp_t;
-#endif
-
-typedef struct {
-  unsigned char header_data[COAP_TCP_HEADER_NO_FIELD];
-  unsigned char token[]; /* the actual token, if any */
-} coap_hdr_tcp_t;
-
-typedef struct {
-  unsigned char header_data[COAP_TCP_HEADER_8_BIT];
-  unsigned char token[]; /* the actual token, if any */
-} coap_hdr_tcp_8bit_t;
-
-typedef struct {
-  unsigned char header_data[COAP_TCP_HEADER_16_BIT];
-  unsigned char token[]; /* the actual token, if any */
-} coap_hdr_tcp_16bit_t;
-
-typedef struct {
-  unsigned char header_data[6];
-  unsigned char token[]; /* the actual token, if any */
-} coap_hdr_tcp_32bit_t;
-
-typedef union {
-  coap_hdr_udp_t udp;
-  coap_hdr_tcp_t tcp;
-  coap_hdr_tcp_8bit_t tcp_8bit;
-  coap_hdr_tcp_16bit_t tcp_16bit;
-  coap_hdr_tcp_32bit_t tcp_32bit;
-} coap_hdr_transport_t;
-
-// Typedef for backwards compatibility.
-typedef coap_hdr_udp_t coap_hdr_t;
-
-#define COAP_MESSAGE_IS_EMPTY(MSG)    ((MSG).code == 0)
-#define COAP_MESSAGE_IS_REQUEST(MSG)  (!COAP_MESSAGE_IS_EMPTY(MSG)  \
-                       && ((MSG).code < 32))
-#define COAP_MESSAGE_IS_RESPONSE(MSG) ((MSG).code >= 64 && (MSG).code <= 191)
-
-#define COAP_OPT_LONG 0x0F  /* OC == 0b1111 indicates that the option list
-                             * in a CoAP message is limited by 0b11110000
-                             * marker */
-
-#define COAP_OPT_END 0xF0   /* end marker */
-
-#define COAP_PAYLOAD_START 0xFF /* payload marker */
-
-/**
- * Structures for more convenient handling of options. (To be used with ordered
- * coap_list_t.) The option's data will be added to the end of the coap_option
- * structure (see macro COAP_OPTION_DATA).
- */
-typedef struct {
-    unsigned short key; /* the option key (no delta coding) */
-    unsigned int length;
-} coap_option;
-
-#define COAP_OPTION_KEY(option) (option).key
-#define COAP_OPTION_LENGTH(option) (option).length
-#define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
-
-/**
- * Header structure for CoAP PDUs
- */
-
-typedef struct {
-    size_t max_size; /**< allocated storage for options and data */
-
-    union {
-        coap_hdr_t *hdr;          /**< Address of the first byte of the CoAP message.
-                                   *   This may or may not equal (coap_hdr_t*)(pdu+1)
-                                   *   depending on the memory management
-                                   *   implementation. */
-        coap_hdr_transport_t *transport_hdr; /**< Address of the first byte of the CoAP message.
-                                               *   This may or may not equal (coap_hdr_t*)(pdu+1)
-                                               *   depending on the memory management
-                                               *   implementation. */
-    };
-    unsigned short max_delta; /**< highest option number */
-    unsigned int length; /**< PDU length (including header, options, data)  */
-    unsigned char *data; /**< payload */
-
-#ifdef WITH_LWIP
-    struct pbuf *pbuf;        /**< lwIP PBUF. The package data will always reside
-                               *    inside the pbuf's payload, but this pointer
-                               *    has to be kept because no exact offset can be
-                               *    given. This field must not be accessed from
-                               *    outside, because the pbuf's reference count
-                               *    is checked to be 1 when the pbuf is assigned
-                               *    to the pdu, and the pbuf stays exclusive to
-                               *    this pdu. */
-#endif
-
-} coap_pdu_t;
-
-/**
- * Options in coap_pdu_t are accessed with the macro COAP_OPTION.
- */
-#define COAP_OPTION(node) ((coap_option *)(node)->options)
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-#ifdef WITH_LWIP
-/**
- * Creates a CoAP PDU from an lwIP @p pbuf, whose reference is passed on to this
- * function.
- *
- * The pbuf is checked for being contiguous, for having enough head space for
- * the PDU struct (which is located directly in front of the data, overwriting
- * the old other headers), and for having only one reference. The reference is
- * stored in the PDU and will be freed when the PDU is freed.
- *
- * (For now, these are fatal errors; in future, a new pbuf might be allocated,
- * the data copied and the passed pbuf freed).
- *
- * This behaves like coap_pdu_init(0, 0, 0, pbuf->tot_len), and afterwards
- * copying the contents of the pbuf to the pdu.
- *
- * @return A pointer to the new PDU object or @c NULL on error.
- */
-coap_pdu_t * coap_pdu_from_pbuf(struct pbuf *pbuf);
-#endif
-
-/**
- * Creates a new CoAP PDU of given @p size (must be large enough to hold the
- * basic CoAP message header (coap_hdr_t). The function returns a pointer to the
- * node coap_pdu_t object on success, or @c NULL on error. The storage allocated
- * for the result must be released with coap_delete_pdu().
- *
- * @param type The type of the PDU (one of COAP_MESSAGE_CON, COAP_MESSAGE_NON,
- *             COAP_MESSAGE_ACK, COAP_MESSAGE_RST).
- * @param code The message code.
- * @param id   The message id to set or COAP_INVALID_TID if unknown.
- * @param size The number of bytes to allocate for the actual message.
- *
- * @return A pointer to the new PDU object or @c NULL on error.
- */
-coap_pdu_t *
-coap_pdu_init(unsigned char type,
-              unsigned char code,
-              unsigned short id,
-              size_t size);
-
-/**
- * Creates a new CoAP PDU of given @p size (must be large enough to hold the
- * basic CoAP message header (coap_hdr_t). The function returns a pointer to
- * the node coap_pdu_t object on success, or @c NULL on error. The storage
- * allocated for the result must be released with coap_delete_pdu().
- *
- * @param type The type of the PDU (one of COAP_MESSAGE_CON,
- *             COAP_MESSAGE_NON, COAP_MESSAGE_ACK, COAP_MESSAGE_RST).
- * @param code The message code.
- * @param id   The message id to set or COAP_INVALID_TID if unknown.
- * @param size The number of bytes to allocate for the actual message.
- * @param transport The transport type.
- *
- * @return A pointer to the new PDU object or @c NULL on error.
- */
-coap_pdu_t *
-coap_pdu_init2(unsigned char type, unsigned char code, unsigned short id,
-               size_t size, coap_transport_t transport);
-
-/**
- * Clears any contents from @p pdu and resets @c version field, @c
- * length and @c data pointers. @c max_size is set to @p size, any
- * other field is set to @c 0. Note that @p pdu must be a valid
- * pointer to a coap_pdu_t object created e.g. by coap_pdu_init().
- */
-void coap_pdu_clear(coap_pdu_t *pdu, size_t size);
-
-/**
- * Clears any contents from @p pdu and resets @c version field, @c
- * length and @c data pointers. @c max_size is set to @p size, any
- * other field is set to @c 0. Note that @p pdu must be a valid
- * pointer to a coap_pdu_t object created e.g. by coap_pdu_init().
- */
-void coap_pdu_clear2(coap_pdu_t *pdu, size_t size, coap_transport_t transport,
-                     unsigned int length);
-
-/**
- * Creates a new CoAP PDU.
- * The object is created on the heap and must be released using
- * coap_delete_pdu();
- *
- * @deprecated This function allocates the maximum storage for each
- * PDU. Use coap_pdu_init() instead.
- */
-coap_pdu_t *coap_new_pdu(void);
-
-/**
- * Creates a new CoAP PDU. The object is created on the heap and must be released
- * using coap_delete_pdu();
- *
- * @deprecated This function allocates the maximum storage for each
- * PDU. Use coap_pdu_init2() instead.
- */
-coap_pdu_t *coap_new_pdu2(coap_transport_t transport, unsigned int size);
-
-void coap_delete_pdu(coap_pdu_t *);
-
-/**
- * Parses @p data into the CoAP PDU structure given in @p result.
- * This function returns @c 0 on error or a number greater than zero on success.
- *
- * @param data   The raw data to parse as CoAP PDU
- * @param length The actual size of @p data
- * @param result The PDU structure to fill. Note that the structure must
- *               provide space for at least @p length bytes to hold the
- *               entire CoAP PDU.
- *
- * @return A value greater than zero on success or @c 0 on error.
- */
-int coap_pdu_parse(unsigned char *data,
-                   size_t length,
-                   coap_pdu_t *result);
-
-/**
- * Parses @p data into the CoAP PDU structure given in @p result.
- * This function returns @c 0 on error or a number greater than zero on success.
- *
- * @param data   The raw data to parse as CoAP PDU
- * @param length The actual size of @p data
- * @param result The PDU structure to fill. Note that the structure must
- *               provide space for at least @p length bytes to hold the
- *               entire CoAP PDU.
- * @param transport The transport type.
- * @return A value greater than zero on success or @c 0 on error.
- */
-int coap_pdu_parse2(unsigned char *data, size_t length, coap_pdu_t *pdu,
-                    coap_transport_t transport);
-
-#ifdef WITH_TCP
-/**
- * Get total pdu size including header + option + payload (with marker) from pdu data.
- *
- * @param data   The raw data to parse as CoAP PDU.
- * @param size   payload size of pdu.
- * @return Total message length.
- */
-size_t coap_get_total_message_length(const unsigned char *data, size_t size);
-
-/**
- * Get transport type of coap header for coap over tcp
- * through payload size(including payload marker) + option size.
- *
- * @param size   payload size of pdu.
- * @return The transport type.
- */
-coap_transport_t coap_get_tcp_header_type_from_size(unsigned int size);
-
-/**
- * Get transport type of coap header for coap over tcp
- * through first nibble(0~E) of init-byte .
- *
- * @param legnth   length value of init byte.
-* @return The transport type.
- */
-coap_transport_t coap_get_tcp_header_type_from_initbyte(unsigned int length);
-
-/**
- * Add length of option/payload into 'Len+ byte...' field of coap header
- * for coap over tcp.
- *
- * @param pdu  The pdu pointer.
- * @param transport The transport type.
- * @param length  length value of init byte.
- */
-void coap_add_length(const coap_pdu_t *pdu, coap_transport_t transport,
-                     unsigned int length);
-
-/**
- * Get the length of option/payload field of coap header for coap over tcp.
- *
- * @param pdu  The pdu pointer.
- * @param transport The transport type.
- * @return length value of init byte.
- */
-unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_t transport);
-
-/**
- * Get the length of option/payload field of coap header for coap over tcp.
- *
- * @param header   The header to parse.
- * @return transport The transport type.
- */
-unsigned int coap_get_length_from_header(const unsigned char *header,
-                                         coap_transport_t transport);
-
-/**
- * Get length of header including len, TKL, Len+bytes, Code, token bytes for coap over tcp.
- *
- * @param data   The raw data to parse as CoAP PDU
- * @return header length + token length
- */
-unsigned int coap_get_tcp_header_length(unsigned char *data);
-
-/**
- * Get length of header including len, TKL, Len+bytes, Code
- * without token bytes for coap over tcp.
- *
- * @param transport The transport type.
- * @return header length.
- */
-unsigned int coap_get_tcp_header_length_for_transport(coap_transport_t transport);
-
-/**
- * Get option length.
- *
- * @param key      delta of option
- * @param length   length of option
- * @return total option length
- */
-size_t coap_get_opt_header_length(unsigned short key, size_t length);
-#endif /* WITH_TCP */
-
-/**
- * Add code in coap header.
- *
- * @param pdu  The pdu pointer.
- * @param transport The transport type.
- * @param code  The message code.
- */
-void coap_add_code(const coap_pdu_t *pdu, coap_transport_t transport,
-                   unsigned int code);
-
-/**
- * Get message code from coap header
- *
- * @param pdu  The pdu pointer.
- * @param transport The transport type.
- * @return The message code.
- */
-unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_t transport);
-
-/**
- * Adds token of length @p len to @p pdu.
- * Adding the token destroys any following contents of the pdu. Hence options
- * and data must be added after coap_add_token() has been called. In @p pdu,
- * length is set to @p len + @c 4, and max_delta is set to @c 0.  This funtion
- * returns @c 0 on error or a value greater than zero on success.
- *
- * @param pdu  The PDU where the token is to be added.
- * @param len  The length of the new token.
- * @param data The token to add.
- *
- * @return A value greater than zero on success, or @c 0 on error.
- */
-int coap_add_token(coap_pdu_t *pdu,
-                   size_t len,
-                   const unsigned char *data);
-
-/**
- * Adds token of length @p len to @p pdu. Adding the token destroys
- * any following contents of the pdu. Hence options and data must be
- * added after coap_add_token2() has been called. In @p pdu, length is
- * set to @p len + @c 4, and max_delta is set to @c 0.  This funtion
- * returns @c 0 on error or a value greater than zero on success.
- *
- * @param pdu  The pdu pointer.
- * @param len  The length of the new token.
- * @param data The token to add.
- * @param transport The transport type.
- * @return A value greater than zero on success, or @c 0 on error.
- */
-int coap_add_token2(coap_pdu_t *pdu, size_t len, const unsigned char *data,
-                    coap_transport_t transport);
-
-/**
- * Get token from coap header
- *
- * @param pdu_hdr  The header pointer of PDU.
- * @param token  out parameter to get token.
- * @param token_length  out parameter to get token length.
- */
-void coap_get_token(const coap_hdr_t *pdu_hdr,
-                    unsigned char **token, unsigned int *token_length);
-
-/**
- * Get token from coap header based on transport type
- *
- * @param pdu_hdr  The header pointer of PDU.
- * @param transport The transport type.
- * @param token  out parameter to get token.
- * @param token_length  out parameter to get token length.
- */
-void coap_get_token2(const coap_hdr_transport_t *pdu_hdr, coap_transport_t transport,
-                     unsigned char **token, unsigned int *token_length);
-
-/**
- * Adds option of given type to pdu that is passed as first parameter. 
- * coap_add_option() destroys the PDU's data, so coap_add_data() must be called
- * after all options have been added. As coap_add_token() destroys the options
- * following the token, the token must be added before coap_add_option() is
- * called. This function returns the number of bytes written or @c 0 on error.
- */
-size_t coap_add_option(coap_pdu_t *pdu,
-                       unsigned short type,
-                       unsigned int len,
-                       const unsigned char *data);
-
-/**
- * Adds option of given type to pdu that is passed as first
- * parameter. coap_add_option2() destroys the PDU's data, so
- * coap_add_data() must be called after all options have been added.
- * As coap_add_token2() destroys the options following the token,
- * the token must be added before coap_add_option2() is called.
- * This function returns the number of bytes written or @c 0 on error.
- */
-size_t coap_add_option2(coap_pdu_t *pdu, unsigned short type, unsigned int len,
-                        const unsigned char *data, coap_transport_t transport);
-
-/**
- * Adds option of given type to pdu that is passed as first parameter, but does
- * not write a value. It works like coap_add_option with respect to calling
- * sequence (i.e. after token and before data). This function returns a memory
- * address to which the option data has to be written before the PDU can be
- * sent, or @c NULL on error.
- */
-unsigned char *coap_add_option_later(coap_pdu_t *pdu,
-                                     unsigned short type,
-                                     unsigned int len);
-
-/**
- * Adds given data to the pdu that is passed as first parameter. Note that the
- * PDU's data is destroyed by coap_add_option(). coap_add_data() must be called
- * only once per PDU, otherwise the result is undefined.
- */
-int coap_add_data(coap_pdu_t *pdu,
-                  unsigned int len,
-                  const unsigned char *data);
-
-/**
- * Retrieves the length and data pointer of specified PDU. Returns 0 on error or
- * 1 if *len and *data have correct values. Note that these values are destroyed
- * with the pdu.
- */
-int coap_get_data(const coap_pdu_t *pdu,
-                  size_t *len,
-                  unsigned char **data);
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-#endif /* _COAP_PDU_H_ */
diff --git a/src/include/coap/prng.h b/src/include/coap/prng.h
deleted file mode 100644 (file)
index 8e2b85b..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/* prng.h -- Pseudo Random Numbers
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-/**
- * @file prng.h
- * @brief Pseudo Random Numbers
- */
-
-#ifndef _COAP_PRNG_H_
-#define _COAP_PRNG_H_
-
-#include "config.h"
-
-/**
- * @defgroup prng Pseudo Random Numbers
- * @{
- */
-
-#ifndef WITH_CONTIKI
-#include <stdlib.h>
-
-/**
- * Fills \p buf with \p len random bytes. This is the default
- * implementation for prng().  You might want to change prng() to use
- * a better PRNG on your specific platform.
- */
-INLINE_API int coap_prng_impl(unsigned char *buf, size_t len)
-{
-    while (len--)
-        *buf++ = rand() & 0xFF;
-    return 1;
-}
-#else /* WITH_CONTIKI */
-#include <string.h>
-
-/**
- * Fills \p buf with \p len random bytes. This is the default
- * implementation for prng().  You might want to change prng() to use
- * a better PRNG on your specific platform.
- */
-INLINE_API int
-contiki_prng_impl(unsigned char *buf, size_t len)
-{
-    unsigned short v = random_rand();
-    while (len > sizeof(v))
-    {
-        memcpy(buf, &v, sizeof(v));
-        len -= sizeof(v);
-        buf += sizeof(v);
-        v = random_rand();
-    }
-
-    memcpy(buf, &v, len);
-    return 1;
-}
-
-#define prng(Buf,Length) contiki_prng_impl((Buf), (Length))
-#define prng_init(Value) random_init((unsigned short)(Value))
-#endif /* WITH_CONTIKI */
-
-#ifndef prng
-/**
- * Fills \p Buf with \p Length bytes of random data.
- *
- * @hideinitializer
- */
-#define prng(Buf,Length) coap_prng_impl((Buf), (Length))
-#endif
-
-#ifndef prng_init
-/**
- * Called to set the PRNG seed. You may want to re-define this to
- * allow for a better PRNG.
- *
- * @hideinitializer
- */
-#define prng_init(Value) srand((unsigned long)(Value))
-#endif
-
-/** @} */
-
-#endif /* _COAP_PRNG_H_ */
diff --git a/src/include/coap/resource.h b/src/include/coap/resource.h
deleted file mode 100644 (file)
index 2349be1..0000000
+++ /dev/null
@@ -1,318 +0,0 @@
-/* resource.h -- generic resource handling
- *
- * Copyright (C) 2010,2011,2014 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-/**
- * @file resource.h
- * @brief generic resource handling
- */
-
-#ifndef _COAP_RESOURCE_H_
-#define _COAP_RESOURCE_H_
-
-#include "config.h"
-#include "t_list.h"
-
-#if defined(HAVE_ASSERT_H) && !defined(assert)
-# include <assert.h>
-#endif
-
-#ifndef COAP_RESOURCE_CHECK_TIME
-/** The interval in seconds to check if resources have changed. */
-#define COAP_RESOURCE_CHECK_TIME 2
-#endif /* COAP_RESOURCE_CHECK_TIME */
-
-#ifndef WITH_CONTIKI
-#  ifdef COAP_RESOURCES_NOHASH
-#    include "utlist.h"
-#  else
-#    include "uthash.h"
-#  endif
-#else /* WITH_CONTIKI */
-#endif /* WITH_CONTIKI */
-#include "hashkey.h"
-#include "async.h"
-#include "str.h"
-#include "pdu.h"
-#include "net.h"
-#include "subscribe.h"
-
-/** Definition of message handler function (@sa coap_resource_t). */
-typedef void (*coap_method_handler_t)(coap_context_t *, struct coap_resource_t *, coap_address_t *,
-        coap_pdu_t *, str * /* token */, coap_pdu_t * /* response */);
-
-#define COAP_ATTR_FLAGS_RELEASE_NAME  0x1
-#define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
-
-typedef struct coap_attr_t
-{
-    struct coap_attr_t *next;
-    str name;
-    str value;
-    int flags;
-} coap_attr_t;
-
-#define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
-
-typedef struct coap_resource_t
-{
-    unsigned int dirty :1; /**< set to 1 if resource has changed */
-    unsigned int partiallydirty :1; /**< set to 1 if some subscribers have not yet been notified of the last change */
-    unsigned int observable :1; /**< can be observed */
-    unsigned int cacheable :1; /**< can be cached */
-
-    /**
-     * Used to store handlers for the four coap methods @c GET, @c POST,
-     * @c PUT, and @c DELETE. coap_dispatch() will pass incoming
-     * requests to the handler that corresponds to its request method or
-     * generate a 4.05 response if no handler is available.
-     */
-    coap_method_handler_t handler[4];
-
-    coap_key_t key; /**< the actual key bytes for this resource */
-
-#ifndef WITH_CONTIKI
-#ifdef COAP_RESOURCES_NOHASH
-    struct coap_resource_t *next;
-#else
-    UT_hash_handle hh;
-#endif
-#endif /* WITH_CONTIKI */
-
-#ifndef WITH_CONTIKI
-    coap_attr_t *link_attr; /**< attributes to be included with the link format */
-#else /* WITH_CONTIKI */
-    LIST_STRUCT(link_attr); /**< attributes to be included with the link format */
-#endif /* WITH_CONTIKI */
-    LIST_STRUCT(subscribers); /**< list of observers for this resource */
-
-    /**
-     * Request URI for this resource. This field will point into the
-     * static memory. */
-    str uri;
-    int flags;
-
-} coap_resource_t;
-
-/**
- * Creates a new resource object and initializes the link field to the
- * string of length @p len.  This function returns the
- * new coap_resource_t object.
- *
- * @param uri    The URI path of the new resource.
- * @param len    The length of @p uri.
- * @param flags  Flags for memory management (in particular release of memory)
- *
- * @return A pointer to the new object or @c NULL on error.
- */
-coap_resource_t *coap_resource_init(const unsigned char *uri, size_t len, int flags);
-
-/**
- * Registers the given @p resource for @p context. The resource must
- * have been created by coap_resource_init(), the storage allocated
- * for the resource will be released by coap_delete_resource().
- *
- * @param context  The context to use.
- * @param resource The resource to store.
- */
-void coap_add_resource(coap_context_t *context, coap_resource_t *resource);
-
-/**
- * Deletes a resource identified by @p key. The storage allocated for
- * that resource is freed.
- *
- * @param context  The context where the resources are stored.
- * @param key      The unique key for the resource to delete.
- *
- * @return @c 1 if the resource was found (and destroyed), @c 0 otherwise.
- */
-int coap_delete_resource(coap_context_t *context, coap_key_t key);
-
-/**
- * Registers a new attribute with the given @p resource. As the
- * attributes str fields will point to @p name and @p val the
- * caller must ensure that these pointers are valid during the
- * attribute's lifetime.
- *
- * @param resource  The resource to register the attribute with.
- * @param name      The attribute's name.
- * @param nlen      Length of @p name.
- * @param val       The attribute's value or @c NULL if none.
- * @param vlen      Length of @p val if specified.
- * @param flags     Flags for memory management (in particular release of memory)
- *
- * @return A pointer to the new attribute or @c NULL on error.
- */
-coap_attr_t *coap_add_attr(coap_resource_t *resource, const unsigned char *name, size_t nlen,
-        const unsigned char *val, size_t vlen, int flags);
-
-/**
- * Returns @p resource's coap_attr_t object with given @p name if
- * found, @c NULL otherwise.
- *
- * @param resource  The resource to search for attribute @p name.
- * @param name      Name of the requested attribute.
- * @param nlen      Actual length of @p name.
- * @return The first attribute with specified @p name or @c NULL if
- *         none was found.
- */
-coap_attr_t *coap_find_attr(coap_resource_t *resource, const unsigned char *name, size_t nlen);
-
-/**
- * Deletes an attribute
- *
- * @param attr  Pointer to a previously created attribute
- *
- */
-void coap_delete_attr(coap_attr_t *attr);
-
-/**
- * Status word to encode the result of conditional print or copy
- * operations such as coap_print_link(). The lower 28 bits of
- * coap_print_status_t are used to encode the number of characters
- * that has actually been printed, bits 28 to 31 encode the status.
- * When COAP_PRINT_STATUS_ERROR is set, an error occurred during
- * output. In this case, the other bits are undefined.
- * COAP_PRINT_STATUS_TRUNC indicates that the output is truncated,
- * i.e. the printing would have exceeded the current buffer.
- */
-typedef unsigned int coap_print_status_t;
-
-#define COAP_PRINT_STATUS_MASK  0xF0000000u
-#define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK)
-#define COAP_PRINT_STATUS_ERROR 0x80000000u
-#define COAP_PRINT_STATUS_TRUNC 0x40000000u
-
-/**
- * Writes a description of this resource in link-format to given text
- * buffer. @p len must be initialized to the maximum length of @p buf
- * and will be set to the number of characters actually written if
- * successful.  This function returns @c 1 on success or @c 0 on
- * error.
- *
- * @param resource The resource to describe.
- * @param buf      The output buffer to write the description to.
- * @param len      Must be initialized to the length of @p buf and
- *                 will be set to the length of the printed link description.
- * @param offset   The offset within the resource description where to
- *                 start writing into @p buf. This is useful for dealing
- *                 with the Block2 option. @p offset is updated during
- *                 output as it is consumed.
- *
- * @return If COAP_PRINT_STATUS_ERROR is set, an error occured. Otherwise,
- *         the lower 28 bits will indicate the number of characters that
- *         have actually been output into @p buffer. The flag
- *         COAP_PRINT_STATUS_TRUNC indicates that the output has been
- *         truncated.
- */
-coap_print_status_t coap_print_link(const coap_resource_t *resource, unsigned char *buf,
-        size_t *len, size_t *offset);
-
-/**
- * Registers the specified @p handler as message handler for the request type
- * @p method
- *
- * @param resource The resource for which the handler shall be registered.
- * @param method   The CoAP request method to handle.
- * @param handler  The handler to register with @p resource.
- */
-INLINE_API void coap_register_handler(coap_resource_t *resource, unsigned char method,
-        coap_method_handler_t handler)
-{
-    assert(resource);
-    assert(
-            method > 0
-                    && (size_t)(method - 1)
-                            < sizeof(resource->handler) / sizeof(coap_method_handler_t));
-    resource->handler[method - 1] = handler;
-}
-
-/**
- * Returns the resource identified by the unique string @p key. If no
- * resource was found, this function returns @c NULL.
- *
- * @param context  The context to look for this resource.
- * @param key      The unique key of the resource.
- *
- * @return A pointer to the resource or @c NULL if not found.
- */
-coap_resource_t *coap_get_resource_from_key(coap_context_t *context, coap_key_t key);
-
-/**
- * Calculates the hash key for the resource requested by the
- * Uri-Options of @p request.  This function calls coap_hash() for
- * every path segment.
- *
- * @param request The requesting pdu.
- * @param key     The resulting hash is stored in @p key
- */
-void coap_hash_request_uri(const coap_pdu_t *request, coap_key_t key);
-
-/**
- * @addtogroup observe
- */
-
-/**
- * Adds the specified peer as observer for @p resource. The
- * subscription is identified by the given @p token. This function
- * returns the registered subscription information if the @p observer
- * has been added, or @c NULL on error.
- *
- * @param resource The observed resource.
- * @param observer The remote peer that wants to received status updates.
- * @param token The token that identifies this subscription.
- * @param token_length The actual length of @p token. Must be @c 0 when
- *        @p token is @c NULL.
- * @return A pointer to the added/updated subscription information or
- *        @c NULL on error.
- */
-coap_subscription_t *coap_add_observer(coap_resource_t *resource, const coap_address_t *observer,
-        const str *token);
-
-/**
- * Returns a subscription object for given @p peer.
- *
- * @param resource The observed resource.
- * @param peer The address to search for.
- * @param token The token that identifies this subscription or @c NULL for any
- *              token.
- * @return A valid subscription if exists or @c NULL otherwise.
- */
-coap_subscription_t *coap_find_observer(coap_resource_t *resource, const coap_address_t *peer,
-        const str *token);
-
-/**
- * Marks an observer as alive.
- *
- * @param context  The CoAP context to use
- * @param observer The transport address of the observer
- * @param token    The corresponding token that has been used for
- *   the subscription
- */
-void coap_touch_observer(coap_context_t *context, const coap_address_t *observer, const str *token);
-
-/**
- * Removes any subscription for @p observer from @p resource and releases
- * the allocated storage.
- *
- * @param resource The observed resource.
- * @param observer The observer's address.
- * @param token    The token that identifies this subscription or @c NULL for any
- *                 token.
- */
-void coap_delete_observer(coap_resource_t *resource, const coap_address_t *observer,
-        const str *token);
-
-/**
- * Checks for all known resources, if they are dirty and notifies
- * subscribed observers.
- */
-void coap_check_notify(coap_context_t *context);
-
-/** @} */
-
-#endif /* _COAP_RESOURCE_H_ */
diff --git a/src/include/coap/str.h b/src/include/coap/str.h
deleted file mode 100644 (file)
index 0a96686..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/* str.h -- strings to be used in the CoAP library
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_STR_H_
-#define _COAP_STR_H_
-
-#include <string.h>
-
-typedef struct
-{
-    size_t length; /* length of string */
-    unsigned char *s; /* string data */
-} str;
-
-#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
-
-/**
- * Returns a new string object with at least size bytes storage
- * allocated.  The string must be released using coap_delete_string();
- */
-str *coap_new_string(size_t size);
-
-/** Deletes the given string and releases any memory allocated. */
-void coap_delete_string(str *);
-
-#endif /* _COAP_STR_H_ */
diff --git a/src/include/coap/subscribe.h b/src/include/coap/subscribe.h
deleted file mode 100644 (file)
index eb76151..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/* subscribe.h -- subscription handling for CoAP
- *                see draft-hartke-coap-observe-03
- *
- * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_SUBSCRIBE_H_
-#define _COAP_SUBSCRIBE_H_
-
-#include "config.h"
-#include "address.h"
-
-/**
- * @defgroup observe Resource observation
- * @{
- */
-
-#ifndef COAP_OBS_MAX_NON
-/**
- * Number of notifications that may be sent non-confirmable before a
- * confirmable message is sent to detect if observers are alive. The
- * maximum allowed value here is @c 15.
- */
-#define COAP_OBS_MAX_NON   5
-#endif /* COAP_OBS_MAX_NON */
-
-#ifndef COAP_OBS_MAX_FAIL
-/**
- * Number of confirmable notifications that may fail (i.e. time out
- * without being ACKed) before an observer is removed. The maximum
- * value for COAP_OBS_MAX_FAIL is @c 3.
- */
-#define COAP_OBS_MAX_FAIL  3
-#endif /* COAP_OBS_MAX_FAIL */
-
-/** Subscriber information */
-typedef struct coap_subscription_t
-{
-    struct coap_subscription_t *next; /**< next element in linked list */
-    coap_address_t subscriber; /**< address and port of subscriber */
-
-    unsigned int non :1; /**< send non-confirmable notifies if @c 1  */
-    unsigned int non_cnt :4; /**< up to 15 non-confirmable notifies allowed */
-    unsigned int fail_cnt :2; /**< up to 3 confirmable notifies can fail */
-    unsigned int dirty :1; /**< set if the notification temporarily could not be sent (in that case, the resource's partiallydirty flag is set too) */
-
-    size_t token_length; /**< actual length of token */
-    unsigned char token[8]; /**< token used for subscription */
-    /* @todo CON/NON flag, block size */
-} coap_subscription_t;
-
-void coap_subscription_init(coap_subscription_t *);
-
-#if 0
-#include "uthash.h"
-#include "uri.h"
-#include "list.h"
-#include "pdu.h"
-#include "net.h"
-
-#if 0
-typedef unsigned long coap_key_t;
-
-/** Used to indicate that a hashkey is invalid. */
-#define COAP_INVALID_HASHKEY ((coap_key_t)-1)
-
-typedef struct
-{
-    coap_uri_t *uri; /* unique identifier; memory is released by coap_delete_resource() */
-    UT_hash_handle hh; /**< hash handle (for internal use only) */
-    str *name; /* display name of the resource */
-    unsigned char mediatype; /* media type for resource representation */
-    unsigned int dirty:1; /* set to 1 if resource has changed */
-    unsigned int writable:1; /* set to 1 if resource can be changed using PUT */
-
-    /* cache-control */
-    unsigned char etag[4]; /* version identifier for this resource
-     * (zero terminated, first byte is zero if not set). */
-    unsigned int maxage; /* maximum cache time (zero means no Max-age option) */
-
-    /**
-     * Callback function that copies the resource representation into the provided data
-     * buffer (PDU payload). finished is set to 1 to indicate that this was the last block
-     * of buflen data for this resource representation, 0 means that data is not finished
-     * and a subsequent call with offset updated by buflen would yield more data (i.e.
-     * the M-bit of CoAP's block option must be set if offset and buflen are selected
-     * accordingly.
-     * When called, buflen must be set to the maximum length of buf that is to be filled
-     * with the mediatype representation of the resource identified by uri.
-     * The mediatype must be set to the requested mediatype of COAP_MEDIATYPE_ANY if
-     * none was given. On return, the mediatype will be set to the type that is
-     * actually used.
-     * The return value indicates the result code that should be used in a response to
-     * this function.
-     */
-    int (*data)(coap_uri_t *uri, unsigned char *mediatype, unsigned int offset, unsigned char *buf, unsigned int *buflen, int *finished);
-}coap_resource_t;
-#endif
-
-typedef struct
-{
-    coap_key_t resource; /* hash key for subscribed resource */
-    time_t expires; /* expiry time of subscription */
-
-    coap_address_t subscriber; /**< subscriber's address */
-
-    str token; /**< subscription token */
-}coap_subscription_t;
-
-#define COAP_RESOURCE(node) ((coap_resource_t *)(node)->data)
-#define COAP_SUBSCRIPTION(node) ((coap_subscription_t *)(node)->data)
-
-/** Checks subscribed resources for updates and notifies subscribers of changes. */
-void coap_check_resource_list(coap_context_t *context);
-
-/** Removes expired subscriptions. */
-void coap_check_subscriptions(coap_context_t *context);
-
-#if 0
-/**
- * Adds specified resource to the resource observation list. Returns a
- * unique key for the resource. The alloceted memory is released when
- * the resource is destroyed with coap_delete_resource().
- */
-coap_key_t coap_add_resource(coap_context_t *context, coap_resource_t *);
-
-/**
- * Deletes the resource that is identified by key. Returns 1 if the resource was
- * removed, 0 on error (e.g. if no such resource exists).
- */
-int coap_delete_resource(coap_context_t *context, coap_key_t key);
-#endif
-/**
- * Creates a new subscription object filled with the given data. The storage
- * allocated for this object must be released using coap_free(). */
-coap_subscription_t *coap_new_subscription(coap_context_t *context,
-        const coap_uri_t *resource,
-        const struct sockaddr *subscriber,
-        socklen_t addrlen,
-        time_t expiry);
-
-/**
- * Adds the given subsription object to the observer list.
- * @param context The CoAP context
- * @param subscription A new subscription oobject created with coap_new_subscription()
- * @return A unique hash key for this resource or COAP_INVALID_HASHKEY on error.
- * The storage allocated for the subscription object is released when it is
- * removed from the subscription list, unless the function has returned
- * COAP_INVALID_HASHKEY. In this case, the storage must be released by the
- * caller of this function.
- */
-coap_key_t coap_add_subscription(coap_context_t *context,
-        coap_subscription_t *subscription);
-
-/**
- * Returns the subscription from subscriber for the resource identified
- * by hashkey. When token is not NULL the subscription must have the
- * same token.
- * @param context The CoAP context
- * @param hashkey The unique key that identifies the subscription
- * @param subscriber The subscriber's transport address
- * @param token If not NULL, this specifies a token given by the
- *              subscriber to identify its subscription.
- * @return The requested subscription object or NULL when not found.
- */
-coap_subscription_t * coap_find_subscription(coap_context_t *context,
-        coap_key_t hashkey,
-        struct sockaddr *subscriber,
-        str *token);
-/**
- * Removes a subscription from the subscription list stored in context and
- * releases the storage that was allocated for this subscription.
- * @param context The CoAP context.
- * @param haskey The unique key that identifies the subscription to remove.
- * @return 1 if a subscription was removed, 0 otherwise.
- */
-int coap_delete_subscription(coap_context_t *context,
-        coap_key_t hashkey,
-        struct sockaddr *subscriber);
-
-/** Returns a unique hash for the specified URI or COAP_INVALID_HASHKEY on error. */
-coap_key_t coap_uri_hash(const coap_uri_t *uri);
-
-/** Returns a unique hash for the specified subscription or COAP_INVALID_HASHKEY on error. */
-coap_key_t coap_subscription_hash(coap_subscription_t *subscription);
-#if 0
-/** Returns the resource identified by key or NULL if not found. */
-coap_resource_t *coap_get_resource_from_key(coap_context_t *ctx, coap_key_t key);
-
-/** Returns the resource identified by uri or NULL if not found. */
-coap_resource_t *coap_get_resource(coap_context_t *ctx, coap_uri_t *uri);
-#endif
-
-#endif
-
-/** @} */
-
-#endif /* _COAP_SUBSCRIBE_H_ */
diff --git a/src/include/coap/t_list.h b/src/include/coap/t_list.h
deleted file mode 100644 (file)
index 60fb972..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/* t_list -- tinydtls lists
- *
- * Copyright (C) 2012 Olaf Bergmann <bergmann@tzi.org>
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-/**
- * @file t_list.h
- * @brief Wrappers for list structures and functions
- */
-
-#ifndef _DTLS_LIST_H_
-#define _DTLS_LIST_H_
-
-#ifndef WITH_CONTIKI
-#include "uthash.h"
-#include "utlist.h"
-
-/* We define list structures and utility functions to be compatible
- * with Contiki list structures. The Contiki list API is part of the
- * Contiki operating system, and therefore the following licensing
- * terms apply (taken from contiki/core/lib/list.h):
- *
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $ Id: list.h,v 1.5 2010/09/13 13:31:00 adamdunkels Exp $
- */
-
-typedef void **list_t;
-struct list
-{
-    struct list *next;
-};
-
-#define LIST_CONCAT(s1, s2) s1##s2
-
-#define LIST_STRUCT(name)           \
-  void *LIST_CONCAT(name, _list);       \
-  list_t name
-
-#define LIST_STRUCT_INIT(struct_ptr, name)  {               \
-    (struct_ptr)->name = &((struct_ptr)->LIST_CONCAT(name,_list));  \
-    (struct_ptr)->LIST_CONCAT(name,_list) = NULL;           \
-  }
-
-INLINE_API void *
-list_head(list_t the_list)
-{
-    return *the_list;
-}
-
-INLINE_API void list_remove(list_t the_list, void *item)
-{
-    if (list_head(the_list))
-        LL_DELETE(*(struct list **)the_list, (struct list *)item);
-}
-
-INLINE_API void list_add(list_t the_list, void *item)
-{
-    list_remove(the_list, item);
-    LL_APPEND(*(struct list **)the_list, (struct list *)item);
-}
-
-INLINE_API void list_push(list_t the_list, void *item)
-{
-    LL_PREPEND(*(struct list **)the_list, (struct list *)item);
-}
-
-INLINE_API void *
-list_pop(list_t the_list)
-{
-    struct list *l;
-    l = (struct list*) *the_list;
-    if (l)
-        list_remove(the_list, l);
-
-    return l;
-}
-
-INLINE_API void list_insert(list_t the_list, void *previtem, void *newitem)
-{
-    if (previtem == NULL)
-    {
-        list_push(the_list, newitem);
-    }
-    else
-    {
-        ((struct list *) newitem)->next = ((struct list *) previtem)->next;
-        ((struct list *) previtem)->next = (struct list*) newitem;
-    }
-}
-
-INLINE_API void *
-list_item_next(void *item)
-{
-    return item == NULL ? NULL : ((struct list *) item)->next;
-}
-
-#else /* WITH_CONTIKI */
-#include "list.h"
-#endif /* WITH_CONTIKI */
-
-#endif /* _DTLS_LIST_H_ */
-
diff --git a/src/include/coap/uri.h b/src/include/coap/uri.h
deleted file mode 100644 (file)
index 24e23a4..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/* uri.h -- helper functions for URI treatment
- *
- * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
- *
- * This file is part of the CoAP library libcoap. Please see
- * README for terms of use.
- */
-
-#ifndef _COAP_URI_H_
-#define _COAP_URI_H_
-
-#include "hashkey.h"
-#include "str.h"
-#include <stdbool.h>
-
-///Separtor for multiple query string
-#define OC_QUERY_SEPARATOR                "&;"
-
-/** Representation of parsed URI. Components may be filled from a
- * string with coap_split_uri() and can be used as input for
- * option-creation functions. */
-typedef struct
-{
-    str host; /**< host part of the URI */
-    unsigned short port; /**< The port in host byte order */
-    str path; /**< Beginning of the first path segment.
-     Use coap_split_path() to create Uri-Path options */
-    str query; /**<  The query part if present */
-} coap_uri_t;
-
-/**
- * Creates a new coap_uri_t object from the specified URI. Returns the new
- * object or NULL on error. The memory allocated by the new coap_uri_t
- * must be released using coap_free().
- * @param uri The URI path to copy.
- * @para length The length of uri.
- *
- * @return New URI object or NULL on error.
- */
-coap_uri_t *coap_new_uri(const unsigned char *uri, unsigned int length);
-
-/**
- * Clones the specified coap_uri_t object. Thie function allocates sufficient
- * memory to hold the coap_uri_t structure and its contents. The object must
- * be released with coap_free(). */
-coap_uri_t *coap_clone_uri(const coap_uri_t *uri);
-
-/**
- * Calculates a hash over the given path and stores the result in
- * @p key. This function returns @c 0 on error or @c 1 on success.
- *
- * @param path The URI path to generate hash for.
- * @param len  The length of @p path.
- * @param key  The output buffer.
- *
- * @return @c 1 if @p key was set, @c 0 otherwise.
- */
-int coap_hash_path(const unsigned char *path, size_t len, coap_key_t key);
-
-/**
- * @defgroup uri_parse URI Parsing Functions
- *
- * CoAP PDUs contain normalized URIs with their path and query split into
- * multiple segments. The functions in this module help splitting strings.
- * @{
- */
-
-/**
- * Iterator to for tokenizing a URI path or query. This structure must
- * be initialized with coap_parse_iterator_init(). Call
- * coap_parse_next() to walk through the tokens.
- *
- * @code
- * unsigned char *token;
- * coap_parse_iterator_t pi;
- * coap_parse_iterator_init(uri.path.s, uri.path.length, "/", "?#", 2, &pi);
- *
- * while ((token = coap_parse_next(&pi))) {
- *   ... do something with token ...
- * }
- * @endcode
- */
-typedef struct
-{
-    size_t n; /**< number of remaining characters in buffer */
-    unsigned char *separator; /**< segment separators */
-    unsigned char *delim; /**< delimiters where to split the string */
-    size_t dlen; /**< length of separator */
-    unsigned char *pos; /**< current position in buffer */
-    size_t segment_length; /**< length of current segment */
-} coap_parse_iterator_t;
-
-/**
- * Initializes the given iterator @p pi.
- *
- * @param s         The string to tokenize.
- * @param n         The length of @p s.
- * @param separator The separator character that delimits tokens.
- * @param delim     A set of characters that delimit @s.
- * @param dlen      The length of @p delim.
- * @param pi        The iterator object to initialize.
- *
- * @return The initialized iterator object @p pi.
- */
-coap_parse_iterator_t *
-coap_parse_iterator_init(unsigned char *s, size_t n, unsigned char *separator, unsigned char *delim,
-        size_t dlen, coap_parse_iterator_t *pi);
-
-/**
- * Updates the iterator @p pi to point to the next token. This
- * function returns a pointer to that token or @c NULL if no more
- * tokens exist. The contents of @p pi will be updated. In particular,
- * @c pi->segment_length specifies the length of the current token, @c
- * pi->pos points to its beginning.
- *
- * @param pi The iterator to update.
- *
- * @return The next token or @c NULL if no more tokens exist.
- */
-unsigned char *coap_parse_next(coap_parse_iterator_t *pi);
-
-/**
- * Parses a given string into URI components. The identified syntactic
- * components are stored in the result parameter @p uri. Optional URI
- * components that are not specified will be set to { 0, 0 }, except
- * for the port which is set to @c COAP_DEFAULT_PORT. This function
- * returns @p 0 if parsing succeeded, a value less than zero
- * otherwise.
- *
- * @param str_var The string to split up.
- * @param len     The actual length of @p str_var
- * @param uri     The coap_uri_t object to store the result.
- * @return @c 0 on success, or < 0 on error.
- *
- * @note The host name part will be converted to lower case by this
- * function.
- */
-int
-coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri);
-
-/**
- * Splits the given URI path into segments. Each segment is preceded
- * by an option pseudo-header with delta-value 0 and the actual length
- * of the respective segment after percent-decoding.
- *
- * @param s      The path string to split.
- * @param length The actual length of @p s.
- * @param buf    Result buffer for parsed segments.
- * @param buflen Maximum length of @p buf. Will be set to the actual number
- * of bytes written into buf on success.
- *
- * @return The number of segments created or @c -1 on error.
- */
-int coap_split_path(const unsigned char *s, size_t length, unsigned char *buf, size_t *buflen);
-
-/**
- * Splits the given URI query into segments. Each segment is preceded
- * by an option pseudo-header with delta-value 0 and the actual length
- * of the respective query term.
- *
- * @param s      The query string to split.
- * @param length The actual length of @p s.
- * @param buf    Result buffer for parsed segments.
- * @param buflen Maximum length of @p buf. Will be set to the actual number
- * of bytes written into buf on success.
- *
- * @return The number of segments created or @c -1 on error.
- *
- * @bug This function does not reserve additional space for delta > 12.
- */
-int coap_split_query(const unsigned char *s, size_t length, unsigned char *buf, size_t *buflen);
-
-/** @} */
-#endif /* _COAP_URI_H_ */
diff --git a/src/include/coap/uthash.h b/src/include/coap/uthash.h
deleted file mode 100644 (file)
index be8f2bd..0000000
+++ /dev/null
@@ -1,974 +0,0 @@
-/*
- Copyright (c) 2003-2010, Troy D. Hanson     http://uthash.sourceforge.net
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef UTHASH_H
-#define UTHASH_H
-
-#include <string.h>   /* memcmp,strlen */
-#include <stddef.h>   /* ptrdiff_t */
-
-/* These macros use decltype or the earlier __typeof GNU extension.
- As decltype is only available in newer compilers (VS2010 or gcc 4.3+
- when compiling c++ source) this code uses whatever method is needed
- or, for VS2008 where neither is available, uses casting workarounds. */
-#ifdef _MSC_VER         /* MS compiler */
-#if _MSC_VER >= 1600 && defined(__cplusplus)  /* VS2010 or newer in C++ mode */
-#define DECLTYPE(x) (decltype(x))
-#else                   /* VS2008 or older (or VS2010 in C mode) */
-#define NO_DECLTYPE
-#define DECLTYPE(x)
-#endif
-#else                   /* GNU, Sun and other compilers */
-#define DECLTYPE(x) (__typeof(x))
-#endif
-
-#ifdef NO_DECLTYPE
-#define DECLTYPE_ASSIGN(dst,src)                                                 \
-do {                                                                             \
-  char **_da_dst = (char**)(&(dst));                                             \
-  *_da_dst = (char*)(src);                                                       \
-} while(0)
-#else
-#define DECLTYPE_ASSIGN(dst,src)                                                 \
-do {                                                                             \
-  (dst) = DECLTYPE(dst)(src);                                                    \
-} while(0)
-#endif
-
-/* a number of the hash function use uint32_t which isn't defined on win32 */
-#ifdef _MSC_VER
-typedef unsigned int uint32_t;
-#else
-#include <inttypes.h>   /* uint32_t */
-#endif
-
-#define UTHASH_VERSION 1.9.3
-
-#ifndef uthash_fatal
-#define uthash_fatal(msg) exit(-1)        /* fatal error (out of memory,etc) */
-#endif
-#define uthash_malloc(sz) malloc(sz)      /* malloc fcn                      */
-#define uthash_free(ptr,sz) free(ptr)     /* free fcn                        */
-
-#define uthash_noexpand_fyi(tbl)          /* can be defined to log noexpand  */
-#define uthash_expand_fyi(tbl)            /* can be defined to log expands   */
-
-/* initial number of buckets */
-#define HASH_INITIAL_NUM_BUCKETS 32      /* initial number of buckets        */
-#define HASH_INITIAL_NUM_BUCKETS_LOG2 5  /* lg2 of initial number of buckets */
-#define HASH_BKT_CAPACITY_THRESH 10      /* expand when bucket count reaches */
-
-/* calculate the element whose hash handle address is hhe */
-#define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho)))
-
-#define HASH_FIND(hh,head,keyptr,keylen,out)                                     \
-do {                                                                             \
-  unsigned _hf_bkt,_hf_hashv;                                                    \
-  out=NULL;                                                                      \
-  if (head) {                                                                    \
-     HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt);   \
-     if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) {                           \
-       HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ],  \
-                        keyptr,keylen,out);                                      \
-     }                                                                           \
-  }                                                                              \
-} while (0)
-
-#ifdef HASH_BLOOM
-#define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM)
-#define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0)
-#define HASH_BLOOM_MAKE(tbl)                                                     \
-do {                                                                             \
-  (tbl)->bloom_nbits = HASH_BLOOM;                                               \
-  (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN);                 \
-  if (!((tbl)->bloom_bv))  { uthash_fatal( "out of memory"); }                   \
-  memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN);                                \
-  (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE;                                       \
-} while (0);
-
-#define HASH_BLOOM_FREE(tbl)                                                     \
-do {                                                                             \
-  uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN);                              \
-} while (0);
-
-#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8)))
-#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8)))
-
-#define HASH_BLOOM_ADD(tbl,hashv)                                                \
-  HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
-
-#define HASH_BLOOM_TEST(tbl,hashv)                                               \
-  HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
-
-#else
-#define HASH_BLOOM_MAKE(tbl)
-#define HASH_BLOOM_FREE(tbl)
-#define HASH_BLOOM_ADD(tbl,hashv)
-#define HASH_BLOOM_TEST(tbl,hashv) (1)
-#endif
-
-#define HASH_MAKE_TABLE(hh,head)                                                 \
-do {                                                                             \
-  (head)->hh.tbl = (UT_hash_table*)uthash_malloc(                                \
-                  sizeof(UT_hash_table));                                        \
-  if (!((head)->hh.tbl))  { uthash_fatal( "out of memory"); }                    \
-  memset((head)->hh.tbl, 0, sizeof(UT_hash_table));                              \
-  (head)->hh.tbl->tail = &((head)->hh);                                          \
-  (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS;                        \
-  (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2;              \
-  (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head);                    \
-  (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc(                      \
-          HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket));               \
-  if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); }             \
-  memset((head)->hh.tbl->buckets, 0,                                             \
-          HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket));               \
-  HASH_BLOOM_MAKE((head)->hh.tbl);                                               \
-  (head)->hh.tbl->signature = HASH_SIGNATURE;                                    \
-} while(0)
-
-#define HASH_ADD(hh,head,fieldname,keylen_in,add)                                \
-        HASH_ADD_KEYPTR(hh,head,&add->fieldname,keylen_in,add)
-
-#define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add)                            \
-do {                                                                             \
- unsigned _ha_bkt;                                                               \
- (add)->hh.next = NULL;                                                          \
- (add)->hh.key = (char*)keyptr;                                                  \
- (add)->hh.keylen = keylen_in;                                                   \
- if (!(head)) {                                                                  \
-    head = (add);                                                                \
-    (head)->hh.prev = NULL;                                                      \
-    HASH_MAKE_TABLE(hh,head);                                                    \
- } else {                                                                        \
-    (head)->hh.tbl->tail->next = (add);                                          \
-    (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail);         \
-    (head)->hh.tbl->tail = &((add)->hh);                                         \
- }                                                                               \
- (head)->hh.tbl->num_items++;                                                    \
- (add)->hh.tbl = (head)->hh.tbl;                                                 \
- HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets,                         \
-         (add)->hh.hashv, _ha_bkt);                                              \
- HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh);                   \
- HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv);                                 \
- HASH_EMIT_KEY(hh,head,keyptr,keylen_in);                                        \
- HASH_FSCK(hh,head);                                                             \
-} while(0)
-
-#define HASH_TO_BKT( hashv, num_bkts, bkt )                                      \
-do {                                                                             \
-  bkt = ((hashv) & ((num_bkts) - 1));                                            \
-} while(0)
-
-/* delete "delptr" from the hash table.
- * "the usual" patch-up process for the app-order doubly-linked-list.
- * The use of _hd_hh_del below deserves special explanation.
- * These used to be expressed using (delptr) but that led to a bug
- * if someone used the same symbol for the head and deletee, like
- *  HASH_DELETE(hh,users,users);
- * We want that to work, but by changing the head (users) below
- * we were forfeiting our ability to further refer to the deletee (users)
- * in the patch-up process. Solution: use scratch space to
- * copy the deletee pointer, then the latter references are via that
- * scratch pointer rather than through the repointed (users) symbol.
- */
-#define HASH_DELETE(hh,head,delptr)                                              \
-do {                                                                             \
-    unsigned _hd_bkt;                                                            \
-    struct UT_hash_handle *_hd_hh_del;                                           \
-    if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) )  {         \
-        uthash_free((head)->hh.tbl->buckets,                                     \
-                    (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \
-        HASH_BLOOM_FREE((head)->hh.tbl);                                         \
-        uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                      \
-        head = NULL;                                                             \
-    } else {                                                                     \
-        _hd_hh_del = &((delptr)->hh);                                            \
-        if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) {     \
-            (head)->hh.tbl->tail =                                               \
-                (UT_hash_handle*)((char*)((delptr)->hh.prev) +                   \
-                (head)->hh.tbl->hho);                                            \
-        }                                                                        \
-        if ((delptr)->hh.prev) {                                                 \
-            ((UT_hash_handle*)((char*)((delptr)->hh.prev) +                      \
-                    (head)->hh.tbl->hho))->next = (delptr)->hh.next;             \
-        } else {                                                                 \
-            DECLTYPE_ASSIGN(head,(delptr)->hh.next);                             \
-        }                                                                        \
-        if (_hd_hh_del->next) {                                                  \
-            ((UT_hash_handle*)((char*)_hd_hh_del->next +                         \
-                    (head)->hh.tbl->hho))->prev =                                \
-                    _hd_hh_del->prev;                                            \
-        }                                                                        \
-        HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt);   \
-        HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del);        \
-        (head)->hh.tbl->num_items--;                                             \
-    }                                                                            \
-    HASH_FSCK(hh,head);                                                          \
-} while (0)
-
-/* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */
-#define HASH_FIND_STR(head,findstr,out)                                          \
-    HASH_FIND(hh,head,findstr,strlen(findstr),out)
-#define HASH_ADD_STR(head,strfield,add)                                          \
-    HASH_ADD(hh,head,strfield,strlen(add->strfield),add)
-#define HASH_FIND_INT(head,findint,out)                                          \
-    HASH_FIND(hh,head,findint,sizeof(int),out)
-#define HASH_ADD_INT(head,intfield,add)                                          \
-    HASH_ADD(hh,head,intfield,sizeof(int),add)
-#define HASH_FIND_PTR(head,findptr,out)                                          \
-    HASH_FIND(hh,head,findptr,sizeof(void *),out)
-#define HASH_ADD_PTR(head,ptrfield,add)                                          \
-    HASH_ADD(hh,head,ptrfield,sizeof(void *),add)
-#define HASH_DEL(head,delptr)                                                    \
-    HASH_DELETE(hh,head,delptr)
-
-/* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined.
- * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.
- */
-#ifdef HASH_DEBUG
-#define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0)
-#define HASH_FSCK(hh,head)                                                       \
-do {                                                                             \
-    unsigned _bkt_i;                                                             \
-    unsigned _count, _bkt_count;                                                 \
-    char *_prev;                                                                 \
-    struct UT_hash_handle *_thh;                                                 \
-    if (head) {                                                                  \
-        _count = 0;                                                              \
-        for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) {       \
-            _bkt_count = 0;                                                      \
-            _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head;                      \
-            _prev = NULL;                                                        \
-            while (_thh) {                                                       \
-               if (_prev != (char*)(_thh->hh_prev)) {                            \
-                   HASH_OOPS("invalid hh_prev %p, actual %p\n",                  \
-                    _thh->hh_prev, _prev );                                      \
-               }                                                                 \
-               _bkt_count++;                                                     \
-               _prev = (char*)(_thh);                                            \
-               _thh = _thh->hh_next;                                             \
-            }                                                                    \
-            _count += _bkt_count;                                                \
-            if ((head)->hh.tbl->buckets[_bkt_i].count !=  _bkt_count) {          \
-               HASH_OOPS("invalid bucket count %d, actual %d\n",                 \
-                (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count);              \
-            }                                                                    \
-        }                                                                        \
-        if (_count != (head)->hh.tbl->num_items) {                               \
-            HASH_OOPS("invalid hh item count %d, actual %d\n",                   \
-                (head)->hh.tbl->num_items, _count );                             \
-        }                                                                        \
-        /* traverse hh in app order; check next/prev integrity, count */         \
-        _count = 0;                                                              \
-        _prev = NULL;                                                            \
-        _thh =  &(head)->hh;                                                     \
-        while (_thh) {                                                           \
-           _count++;                                                             \
-           if (_prev !=(char*)(_thh->prev)) {                                    \
-              HASH_OOPS("invalid prev %p, actual %p\n",                          \
-                    _thh->prev, _prev );                                         \
-           }                                                                     \
-           _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh);                    \
-           _thh = ( _thh->next ?  (UT_hash_handle*)((char*)(_thh->next) +        \
-                                  (head)->hh.tbl->hho) : NULL );                 \
-        }                                                                        \
-        if (_count != (head)->hh.tbl->num_items) {                               \
-            HASH_OOPS("invalid app item count %d, actual %d\n",                  \
-                (head)->hh.tbl->num_items, _count );                             \
-        }                                                                        \
-    }                                                                            \
-} while (0)
-#else
-#define HASH_FSCK(hh,head)
-#endif
-
-/* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to
- * the descriptor to which this macro is defined for tuning the hash function.
- * The app can #include <unistd.h> to get the prototype for write(2). */
-#ifdef HASH_EMIT_KEYS
-#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)                                   \
-do {                                                                             \
-    unsigned _klen = fieldlen;                                                   \
-    write(HASH_EMIT_KEYS, &_klen, sizeof(_klen));                                \
-    write(HASH_EMIT_KEYS, keyptr, fieldlen);                                     \
-} while (0)
-#else
-#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)
-#endif
-
-/* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */
-#ifdef HASH_FUNCTION
-#define HASH_FCN HASH_FUNCTION
-#else
-#define HASH_FCN HASH_JEN
-#endif
-
-/* The Bernstein hash function, used in Perl prior to v5.6 */
-#define HASH_BER(key,keylen,num_bkts,hashv,bkt)                                  \
-do {                                                                             \
-  unsigned _hb_keylen=keylen;                                                    \
-  char *_hb_key=(char*)(key);                                                    \
-  (hashv) = 0;                                                                   \
-  while (_hb_keylen--)  { (hashv) = ((hashv) * 33) + *_hb_key++; }               \
-  bkt = (hashv) & (num_bkts-1);                                                  \
-} while (0)
-
-/* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at
- * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */
-#define HASH_SAX(key,keylen,num_bkts,hashv,bkt)                                  \
-do {                                                                             \
-  unsigned _sx_i;                                                                \
-  char *_hs_key=(char*)(key);                                                    \
-  hashv = 0;                                                                     \
-  for(_sx_i=0; _sx_i < keylen; _sx_i++)                                          \
-      hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i];                     \
-  bkt = hashv & (num_bkts-1);                                                    \
-} while (0)
-
-#define HASH_FNV(key,keylen,num_bkts,hashv,bkt)                                  \
-do {                                                                             \
-  unsigned _fn_i;                                                                \
-  char *_hf_key=(char*)(key);                                                    \
-  hashv = 2166136261UL;                                                          \
-  for(_fn_i=0; _fn_i < keylen; _fn_i++)                                          \
-      hashv = (hashv * 16777619) ^ _hf_key[_fn_i];                               \
-  bkt = hashv & (num_bkts-1);                                                    \
-} while(0);
-
-#define HASH_OAT(key,keylen,num_bkts,hashv,bkt)                                  \
-do {                                                                             \
-  unsigned _ho_i;                                                                \
-  char *_ho_key=(char*)(key);                                                    \
-  hashv = 0;                                                                     \
-  for(_ho_i=0; _ho_i < keylen; _ho_i++) {                                        \
-      hashv += _ho_key[_ho_i];                                                   \
-      hashv += (hashv << 10);                                                    \
-      hashv ^= (hashv >> 6);                                                     \
-  }                                                                              \
-  hashv += (hashv << 3);                                                         \
-  hashv ^= (hashv >> 11);                                                        \
-  hashv += (hashv << 15);                                                        \
-  bkt = hashv & (num_bkts-1);                                                    \
-} while(0)
-
-#define HASH_JEN_MIX(a,b,c)                                                      \
-do {                                                                             \
-  a -= b; a -= c; a ^= ( c >> 13 );                                              \
-  b -= c; b -= a; b ^= ( a << 8 );                                               \
-  c -= a; c -= b; c ^= ( b >> 13 );                                              \
-  a -= b; a -= c; a ^= ( c >> 12 );                                              \
-  b -= c; b -= a; b ^= ( a << 16 );                                              \
-  c -= a; c -= b; c ^= ( b >> 5 );                                               \
-  a -= b; a -= c; a ^= ( c >> 3 );                                               \
-  b -= c; b -= a; b ^= ( a << 10 );                                              \
-  c -= a; c -= b; c ^= ( b >> 15 );                                              \
-} while (0)
-
-#define HASH_JEN(key,keylen,num_bkts,hashv,bkt)                                  \
-do {                                                                             \
-  unsigned _hj_i,_hj_j,_hj_k;                                                    \
-  char *_hj_key=(char*)(key);                                                    \
-  hashv = 0xfeedbeef;                                                            \
-  _hj_i = _hj_j = 0x9e3779b9;                                                    \
-  _hj_k = keylen;                                                                \
-  while (_hj_k >= 12) {                                                          \
-    _hj_i +=    (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 )                      \
-        + ( (unsigned)_hj_key[2] << 16 )                                         \
-        + ( (unsigned)_hj_key[3] << 24 ) );                                      \
-    _hj_j +=    (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 )                      \
-        + ( (unsigned)_hj_key[6] << 16 )                                         \
-        + ( (unsigned)_hj_key[7] << 24 ) );                                      \
-    hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 )                         \
-        + ( (unsigned)_hj_key[10] << 16 )                                        \
-        + ( (unsigned)_hj_key[11] << 24 ) );                                     \
-                                                                                 \
-     HASH_JEN_MIX(_hj_i, _hj_j, hashv);                                          \
-                                                                                 \
-     _hj_key += 12;                                                              \
-     _hj_k -= 12;                                                                \
-  }                                                                              \
-  hashv += keylen;                                                               \
-  switch ( _hj_k ) {                                                             \
-     case 11: hashv += ( (unsigned)_hj_key[10] << 24 );                          \
-     case 10: hashv += ( (unsigned)_hj_key[9] << 16 );                           \
-     case 9:  hashv += ( (unsigned)_hj_key[8] << 8 );                            \
-     case 8:  _hj_j += ( (unsigned)_hj_key[7] << 24 );                           \
-     case 7:  _hj_j += ( (unsigned)_hj_key[6] << 16 );                           \
-     case 6:  _hj_j += ( (unsigned)_hj_key[5] << 8 );                            \
-     case 5:  _hj_j += _hj_key[4];                                               \
-     case 4:  _hj_i += ( (unsigned)_hj_key[3] << 24 );                           \
-     case 3:  _hj_i += ( (unsigned)_hj_key[2] << 16 );                           \
-     case 2:  _hj_i += ( (unsigned)_hj_key[1] << 8 );                            \
-     case 1:  _hj_i += _hj_key[0];                                               \
-  }                                                                              \
-  HASH_JEN_MIX(_hj_i, _hj_j, hashv);                                             \
-  bkt = hashv & (num_bkts-1);                                                    \
-} while(0)
-
-/* The Paul Hsieh hash function */
-#undef get16bits
-#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__)             \
-  || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
-#define get16bits(d) (*((const uint16_t *) (d)))
-#endif
-
-#if !defined (get16bits)
-#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)             \
-                       +(uint32_t)(((const uint8_t *)(d))[0]) )
-#endif
-#define HASH_SFH(key,keylen,num_bkts,hashv,bkt)                                  \
-do {                                                                             \
-  char *_sfh_key=(char*)(key);                                                   \
-  uint32_t _sfh_tmp, _sfh_len = keylen;                                          \
-                                                                                 \
-  int _sfh_rem = _sfh_len & 3;                                                   \
-  _sfh_len >>= 2;                                                                \
-  hashv = 0xcafebabe;                                                            \
-                                                                                 \
-  /* Main loop */                                                                \
-  for (;_sfh_len > 0; _sfh_len--) {                                              \
-    hashv    += get16bits (_sfh_key);                                            \
-    _sfh_tmp       = (get16bits (_sfh_key+2) << 11) ^ hashv;                     \
-    hashv     = (hashv << 16) ^ _sfh_tmp;                                        \
-    _sfh_key += 2*sizeof (uint16_t);                                             \
-    hashv    += hashv >> 11;                                                     \
-  }                                                                              \
-                                                                                 \
-  /* Handle end cases */                                                         \
-  switch (_sfh_rem) {                                                            \
-    case 3: hashv += get16bits (_sfh_key);                                       \
-            hashv ^= hashv << 16;                                                \
-            hashv ^= _sfh_key[sizeof (uint16_t)] << 18;                          \
-            hashv += hashv >> 11;                                                \
-            break;                                                               \
-    case 2: hashv += get16bits (_sfh_key);                                       \
-            hashv ^= hashv << 11;                                                \
-            hashv += hashv >> 17;                                                \
-            break;                                                               \
-    case 1: hashv += *_sfh_key;                                                  \
-            hashv ^= hashv << 10;                                                \
-            hashv += hashv >> 1;                                                 \
-  }                                                                              \
-                                                                                 \
-    /* Force "avalanching" of final 127 bits */                                  \
-    hashv ^= hashv << 3;                                                         \
-    hashv += hashv >> 5;                                                         \
-    hashv ^= hashv << 4;                                                         \
-    hashv += hashv >> 17;                                                        \
-    hashv ^= hashv << 25;                                                        \
-    hashv += hashv >> 6;                                                         \
-    bkt = hashv & (num_bkts-1);                                                  \
-} while(0);
-
-#ifdef HASH_USING_NO_STRICT_ALIASING
-/* The MurmurHash exploits some CPU's (e.g. x86) tolerance for unaligned reads.
- * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error.
- * So MurmurHash comes in two versions, the faster unaligned one and the slower
- * aligned one. We only use the faster one on CPU's where we know it's safe.
- *
- * Note the preprocessor built-in defines can be emitted using:
- *
- *   gcc -m64 -dM -E - < /dev/null                  (on gcc)
- *   cc -## a.c (where a.c is a simple test file)   (Sun Studio)
- */
-#if (defined(__i386__) || defined(__x86_64__))
-#define HASH_MUR HASH_MUR_UNALIGNED
-#else
-#define HASH_MUR HASH_MUR_ALIGNED
-#endif
-
-/* Appleby's MurmurHash fast version for unaligned-tolerant archs like i386 */
-#define HASH_MUR_UNALIGNED(key,keylen,num_bkts,hashv,bkt)                        \
-do {                                                                             \
-  const unsigned int _mur_m = 0x5bd1e995;                                        \
-  const int _mur_r = 24;                                                         \
-  hashv = 0xcafebabe ^ keylen;                                                   \
-  char *_mur_key = (char *)(key);                                                \
-  uint32_t _mur_tmp, _mur_len = keylen;                                          \
-                                                                                 \
-  for (;_mur_len >= 4; _mur_len-=4) {                                            \
-    _mur_tmp = *(uint32_t *)_mur_key;                                            \
-    _mur_tmp *= _mur_m;                                                          \
-    _mur_tmp ^= _mur_tmp >> _mur_r;                                              \
-    _mur_tmp *= _mur_m;                                                          \
-    hashv *= _mur_m;                                                             \
-    hashv ^= _mur_tmp;                                                           \
-    _mur_key += 4;                                                               \
-  }                                                                              \
-                                                                                 \
-  switch(_mur_len)                                                               \
-  {                                                                              \
-    case 3: hashv ^= _mur_key[2] << 16;                                          \
-    case 2: hashv ^= _mur_key[1] << 8;                                           \
-    case 1: hashv ^= _mur_key[0];                                                \
-            hashv *= _mur_m;                                                     \
-  };                                                                             \
-                                                                                 \
-  hashv ^= hashv >> 13;                                                          \
-  hashv *= _mur_m;                                                               \
-  hashv ^= hashv >> 15;                                                          \
-                                                                                 \
-  bkt = hashv & (num_bkts-1);                                                    \
-} while(0)
-
-/* Appleby's MurmurHash version for alignment-sensitive archs like Sparc */
-#define HASH_MUR_ALIGNED(key,keylen,num_bkts,hashv,bkt)                          \
-do {                                                                             \
-  const unsigned int _mur_m = 0x5bd1e995;                                        \
-  const int _mur_r = 24;                                                         \
-  hashv = 0xcafebabe ^ (keylen);                                                 \
-  char *_mur_key = (char *)(key);                                                \
-  uint32_t _mur_len = keylen;                                                    \
-  int _mur_align = (int)_mur_key & 3;                                            \
-                                                                                 \
-  if (_mur_align && (_mur_len >= 4)) {                                           \
-    unsigned _mur_t = 0, _mur_d = 0;                                             \
-    switch(_mur_align) {                                                         \
-      case 1: _mur_t |= _mur_key[2] << 16;                                       \
-      case 2: _mur_t |= _mur_key[1] << 8;                                        \
-      case 3: _mur_t |= _mur_key[0];                                             \
-    }                                                                            \
-    _mur_t <<= (8 * _mur_align);                                                 \
-    _mur_key += 4-_mur_align;                                                    \
-    _mur_len -= 4-_mur_align;                                                    \
-    int _mur_sl = 8 * (4-_mur_align);                                            \
-    int _mur_sr = 8 * _mur_align;                                                \
-                                                                                 \
-    for (;_mur_len >= 4; _mur_len-=4) {                                          \
-      _mur_d = *(unsigned *)_mur_key;                                            \
-      _mur_t = (_mur_t >> _mur_sr) | (_mur_d << _mur_sl);                        \
-      unsigned _mur_k = _mur_t;                                                  \
-      _mur_k *= _mur_m;                                                          \
-      _mur_k ^= _mur_k >> _mur_r;                                                \
-      _mur_k *= _mur_m;                                                          \
-      hashv *= _mur_m;                                                           \
-      hashv ^= _mur_k;                                                           \
-      _mur_t = _mur_d;                                                           \
-      _mur_key += 4;                                                             \
-    }                                                                            \
-    _mur_d = 0;                                                                  \
-    if(_mur_len >= _mur_align) {                                                 \
-      switch(_mur_align) {                                                       \
-        case 3: _mur_d |= _mur_key[2] << 16;                                     \
-        case 2: _mur_d |= _mur_key[1] << 8;                                      \
-        case 1: _mur_d |= _mur_key[0];                                           \
-      }                                                                          \
-      unsigned _mur_k = (_mur_t >> _mur_sr) | (_mur_d << _mur_sl);               \
-      _mur_k *= _mur_m;                                                          \
-      _mur_k ^= _mur_k >> _mur_r;                                                \
-      _mur_k *= _mur_m;                                                          \
-      hashv *= _mur_m;                                                           \
-      hashv ^= _mur_k;                                                           \
-      _mur_k += _mur_align;                                                      \
-      _mur_len -= _mur_align;                                                    \
-                                                                                 \
-      switch(_mur_len)                                                           \
-      {                                                                          \
-        case 3: hashv ^= _mur_key[2] << 16;                                      \
-        case 2: hashv ^= _mur_key[1] << 8;                                       \
-        case 1: hashv ^= _mur_key[0];                                            \
-                hashv *= _mur_m;                                                 \
-      }                                                                          \
-    } else {                                                                     \
-      switch(_mur_len)                                                           \
-      {                                                                          \
-        case 3: _mur_d ^= _mur_key[2] << 16;                                     \
-        case 2: _mur_d ^= _mur_key[1] << 8;                                      \
-        case 1: _mur_d ^= _mur_key[0];                                           \
-        case 0: hashv ^= (_mur_t >> _mur_sr) | (_mur_d << _mur_sl);              \
-        hashv *= _mur_m;                                                         \
-      }                                                                          \
-    }                                                                            \
-                                                                                 \
-    hashv ^= hashv >> 13;                                                        \
-    hashv *= _mur_m;                                                             \
-    hashv ^= hashv >> 15;                                                        \
-  } else {                                                                       \
-    for (;_mur_len >= 4; _mur_len-=4) {                                          \
-      unsigned _mur_k = *(unsigned*)_mur_key;                                    \
-      _mur_k *= _mur_m;                                                          \
-      _mur_k ^= _mur_k >> _mur_r;                                                \
-      _mur_k *= _mur_m;                                                          \
-      hashv *= _mur_m;                                                           \
-      hashv ^= _mur_k;                                                           \
-      _mur_key += 4;                                                             \
-    }                                                                            \
-    switch(_mur_len)                                                             \
-    {                                                                            \
-      case 3: hashv ^= _mur_key[2] << 16;                                        \
-      case 2: hashv ^= _mur_key[1] << 8;                                         \
-      case 1: hashv ^= _mur_key[0];                                              \
-      hashv *= _mur_m;                                                           \
-    }                                                                            \
-                                                                                 \
-    hashv ^= hashv >> 13;                                                        \
-    hashv *= _mur_m;                                                             \
-    hashv ^= hashv >> 15;                                                        \
-  }                                                                              \
-  bkt = hashv & (num_bkts-1);                                                    \
-} while(0)
-#endif  /* HASH_USING_NO_STRICT_ALIASING */
-
-/* key comparison function; return 0 if keys equal */
-#define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
-
-/* iterate over items in a known bucket to find desired item */
-#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out)                       \
-do {                                                                             \
- if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head));          \
- else out=NULL;                                                                  \
- while (out) {                                                                   \
-    if (out->hh.keylen == keylen_in) {                                           \
-        if ((HASH_KEYCMP(out->hh.key,keyptr,keylen_in)) == 0) break;             \
-    }                                                                            \
-    if (out->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,out->hh.hh_next)); \
-    else out = NULL;                                                             \
- }                                                                               \
-} while(0)
-
-/* add an item to a bucket  */
-#define HASH_ADD_TO_BKT(head,addhh)                                              \
-do {                                                                             \
- head.count++;                                                                   \
- (addhh)->hh_next = head.hh_head;                                                \
- (addhh)->hh_prev = NULL;                                                        \
- if (head.hh_head) { (head).hh_head->hh_prev = (addhh); }                        \
- (head).hh_head=addhh;                                                           \
- if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH)             \
-     && (addhh)->tbl->noexpand != 1) {                                           \
-       HASH_EXPAND_BUCKETS((addhh)->tbl);                                        \
- }                                                                               \
-} while(0)
-
-/* remove an item from a given bucket */
-#define HASH_DEL_IN_BKT(hh,head,hh_del)                                          \
-    (head).count--;                                                              \
-    if ((head).hh_head == hh_del) {                                              \
-      (head).hh_head = hh_del->hh_next;                                          \
-    }                                                                            \
-    if (hh_del->hh_prev) {                                                       \
-        hh_del->hh_prev->hh_next = hh_del->hh_next;                              \
-    }                                                                            \
-    if (hh_del->hh_next) {                                                       \
-        hh_del->hh_next->hh_prev = hh_del->hh_prev;                              \
-    }
-
-/* Bucket expansion has the effect of doubling the number of buckets
- * and redistributing the items into the new buckets. Ideally the
- * items will distribute more or less evenly into the new buckets
- * (the extent to which this is true is a measure of the quality of
- * the hash function as it applies to the key domain).
- *
- * With the items distributed into more buckets, the chain length
- * (item count) in each bucket is reduced. Thus by expanding buckets
- * the hash keeps a bound on the chain length. This bounded chain
- * length is the essence of how a hash provides constant time lookup.
- *
- * The calculation of tbl->ideal_chain_maxlen below deserves some
- * explanation. First, keep in mind that we're calculating the ideal
- * maximum chain length based on the *new* (doubled) bucket count.
- * In fractions this is just n/b (n=number of items,b=new num buckets).
- * Since the ideal chain length is an integer, we want to calculate
- * ceil(n/b). We don't depend on floating point arithmetic in this
- * hash, so to calculate ceil(n/b) with integers we could write
- *
- *      ceil(n/b) = (n/b) + ((n%b)?1:0)
- *
- * and in fact a previous version of this hash did just that.
- * But now we have improved things a bit by recognizing that b is
- * always a power of two. We keep its base 2 log handy (call it lb),
- * so now we can write this with a bit shift and logical AND:
- *
- *      ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0)
- *
- */
-#define HASH_EXPAND_BUCKETS(tbl)                                                 \
-do {                                                                             \
-    unsigned _he_bkt;                                                            \
-    unsigned _he_bkt_i;                                                          \
-    struct UT_hash_handle *_he_thh, *_he_hh_nxt;                                 \
-    UT_hash_bucket *_he_new_buckets, *_he_newbkt;                                \
-    _he_new_buckets = (UT_hash_bucket*)uthash_malloc(                            \
-             2 * tbl->num_buckets * sizeof(struct UT_hash_bucket));              \
-    if (!_he_new_buckets) { uthash_fatal( "out of memory"); }                    \
-    memset(_he_new_buckets, 0,                                                   \
-            2 * tbl->num_buckets * sizeof(struct UT_hash_bucket));               \
-    tbl->ideal_chain_maxlen =                                                    \
-       (tbl->num_items >> (tbl->log2_num_buckets+1)) +                           \
-       ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0);                    \
-    tbl->nonideal_items = 0;                                                     \
-    for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++)                \
-    {                                                                            \
-        _he_thh = tbl->buckets[ _he_bkt_i ].hh_head;                             \
-        while (_he_thh) {                                                        \
-           _he_hh_nxt = _he_thh->hh_next;                                        \
-           HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt);            \
-           _he_newbkt = &(_he_new_buckets[ _he_bkt ]);                           \
-           if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) {                \
-             tbl->nonideal_items++;                                              \
-             _he_newbkt->expand_mult = _he_newbkt->count /                       \
-                                        tbl->ideal_chain_maxlen;                 \
-           }                                                                     \
-           _he_thh->hh_prev = NULL;                                              \
-           _he_thh->hh_next = _he_newbkt->hh_head;                               \
-           if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev =               \
-                _he_thh;                                                         \
-           _he_newbkt->hh_head = _he_thh;                                        \
-           _he_thh = _he_hh_nxt;                                                 \
-        }                                                                        \
-    }                                                                            \
-    uthash_free( tbl->buckets, tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \
-    tbl->num_buckets *= 2;                                                       \
-    tbl->log2_num_buckets++;                                                     \
-    tbl->buckets = _he_new_buckets;                                              \
-    tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ?         \
-        (tbl->ineff_expands+1) : 0;                                              \
-    if (tbl->ineff_expands > 1) {                                                \
-        tbl->noexpand=1;                                                         \
-        uthash_noexpand_fyi(tbl);                                                \
-    }                                                                            \
-    uthash_expand_fyi(tbl);                                                      \
-} while(0)
-
-/* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */
-/* Note that HASH_SORT assumes the hash handle name to be hh.
- * HASH_SRT was added to allow the hash handle name to be passed in. */
-#define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn)
-#define HASH_SRT(hh,head,cmpfcn)                                                 \
-do {                                                                             \
-  unsigned _hs_i;                                                                \
-  unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize;               \
-  struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail;            \
-  if (head) {                                                                    \
-      _hs_insize = 1;                                                            \
-      _hs_looping = 1;                                                           \
-      _hs_list = &((head)->hh);                                                  \
-      while (_hs_looping) {                                                      \
-          _hs_p = _hs_list;                                                      \
-          _hs_list = NULL;                                                       \
-          _hs_tail = NULL;                                                       \
-          _hs_nmerges = 0;                                                       \
-          while (_hs_p) {                                                        \
-              _hs_nmerges++;                                                     \
-              _hs_q = _hs_p;                                                     \
-              _hs_psize = 0;                                                     \
-              for ( _hs_i = 0; _hs_i  < _hs_insize; _hs_i++ ) {                  \
-                  _hs_psize++;                                                   \
-                  _hs_q = (UT_hash_handle*)((_hs_q->next) ?                      \
-                          ((void*)((char*)(_hs_q->next) +                        \
-                          (head)->hh.tbl->hho)) : NULL);                         \
-                  if (! (_hs_q) ) break;                                         \
-              }                                                                  \
-              _hs_qsize = _hs_insize;                                            \
-              while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) {           \
-                  if (_hs_psize == 0) {                                          \
-                      _hs_e = _hs_q;                                             \
-                      _hs_q = (UT_hash_handle*)((_hs_q->next) ?                  \
-                              ((void*)((char*)(_hs_q->next) +                    \
-                              (head)->hh.tbl->hho)) : NULL);                     \
-                      _hs_qsize--;                                               \
-                  } else if ( (_hs_qsize == 0) || !(_hs_q) ) {                   \
-                      _hs_e = _hs_p;                                             \
-                      _hs_p = (UT_hash_handle*)((_hs_p->next) ?                  \
-                              ((void*)((char*)(_hs_p->next) +                    \
-                              (head)->hh.tbl->hho)) : NULL);                     \
-                      _hs_psize--;                                               \
-                  } else if ((                                                   \
-                      cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \
-                             DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \
-                             ) <= 0) {                                           \
-                      _hs_e = _hs_p;                                             \
-                      _hs_p = (UT_hash_handle*)((_hs_p->next) ?                  \
-                              ((void*)((char*)(_hs_p->next) +                    \
-                              (head)->hh.tbl->hho)) : NULL);                     \
-                      _hs_psize--;                                               \
-                  } else {                                                       \
-                      _hs_e = _hs_q;                                             \
-                      _hs_q = (UT_hash_handle*)((_hs_q->next) ?                  \
-                              ((void*)((char*)(_hs_q->next) +                    \
-                              (head)->hh.tbl->hho)) : NULL);                     \
-                      _hs_qsize--;                                               \
-                  }                                                              \
-                  if ( _hs_tail ) {                                              \
-                      _hs_tail->next = ((_hs_e) ?                                \
-                            ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL);          \
-                  } else {                                                       \
-                      _hs_list = _hs_e;                                          \
-                  }                                                              \
-                  _hs_e->prev = ((_hs_tail) ?                                    \
-                     ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL);              \
-                  _hs_tail = _hs_e;                                              \
-              }                                                                  \
-              _hs_p = _hs_q;                                                     \
-          }                                                                      \
-          _hs_tail->next = NULL;                                                 \
-          if ( _hs_nmerges <= 1 ) {                                              \
-              _hs_looping=0;                                                     \
-              (head)->hh.tbl->tail = _hs_tail;                                   \
-              DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list));      \
-          }                                                                      \
-          _hs_insize *= 2;                                                       \
-      }                                                                          \
-      HASH_FSCK(hh,head);                                                        \
- }                                                                               \
-} while (0)
-
-/* This function selects items from one hash into another hash.
- * The end result is that the selected items have dual presence
- * in both hashes. There is no copy of the items made; rather
- * they are added into the new hash through a secondary hash
- * hash handle that must be present in the structure. */
-#define HASH_SELECT(hh_dst, dst, hh_src, src, cond)                              \
-do {                                                                             \
-  unsigned _src_bkt, _dst_bkt;                                                   \
-  void *_last_elt=NULL, *_elt;                                                   \
-  UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL;                         \
-  ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst));                 \
-  if (src) {                                                                     \
-    for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) {     \
-      for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head;                \
-          _src_hh;                                                               \
-          _src_hh = _src_hh->hh_next) {                                          \
-          _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh);                       \
-          if (cond(_elt)) {                                                      \
-            _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho);               \
-            _dst_hh->key = _src_hh->key;                                         \
-            _dst_hh->keylen = _src_hh->keylen;                                   \
-            _dst_hh->hashv = _src_hh->hashv;                                     \
-            _dst_hh->prev = _last_elt;                                           \
-            _dst_hh->next = NULL;                                                \
-            if (_last_elt_hh) { _last_elt_hh->next = _elt; }                     \
-            if (!dst) {                                                          \
-              DECLTYPE_ASSIGN(dst,_elt);                                         \
-              HASH_MAKE_TABLE(hh_dst,dst);                                       \
-            } else {                                                             \
-              _dst_hh->tbl = (dst)->hh_dst.tbl;                                  \
-            }                                                                    \
-            HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt);    \
-            HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh);            \
-            (dst)->hh_dst.tbl->num_items++;                                      \
-            _last_elt = _elt;                                                    \
-            _last_elt_hh = _dst_hh;                                              \
-          }                                                                      \
-      }                                                                          \
-    }                                                                            \
-  }                                                                              \
-  HASH_FSCK(hh_dst,dst);                                                         \
-} while (0)
-
-#define HASH_CLEAR(hh,head)                                                      \
-do {                                                                             \
-  if (head) {                                                                    \
-    uthash_free((head)->hh.tbl->buckets,                                         \
-                (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket));      \
-    uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                          \
-    (head)=NULL;                                                                 \
-  }                                                                              \
-} while(0)
-
-#ifdef NO_DECLTYPE
-#define HASH_ITER(hh,head,el,tmp)                                                \
-for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL);       \
-  el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL))
-#else
-#define HASH_ITER(hh,head,el,tmp)                                                \
-for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL);                 \
-  el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL))
-#endif
-
-/* obtain a count of items in the hash */
-#define HASH_COUNT(head) HASH_CNT(hh,head)
-#define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0)
-
-typedef struct UT_hash_bucket
-{
-    struct UT_hash_handle *hh_head;
-    unsigned count;
-
-    /* expand_mult is normally set to 0. In this situation, the max chain length
-     * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If
-     * the bucket's chain exceeds this length, bucket expansion is triggered).
-     * However, setting expand_mult to a non-zero value delays bucket expansion
-     * (that would be triggered by additions to this particular bucket)
-     * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH.
-     * (The multiplier is simply expand_mult+1). The whole idea of this
-     * multiplier is to reduce bucket expansions, since they are expensive, in
-     * situations where we know that a particular bucket tends to be overused.
-     * It is better to let its chain length grow to a longer yet-still-bounded
-     * value, than to do an O(n) bucket expansion too often.
-     */
-    unsigned expand_mult;
-
-} UT_hash_bucket;
-
-/* random signature used only to find hash tables in external analysis */
-#define HASH_SIGNATURE 0xa0111fe1
-#define HASH_BLOOM_SIGNATURE 0xb12220f2
-
-typedef struct UT_hash_table
-{
-    UT_hash_bucket *buckets;
-    unsigned num_buckets, log2_num_buckets;
-    unsigned num_items;
-    struct UT_hash_handle *tail; /* tail hh in app order, for fast append    */
-    ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */
-
-    /* in an ideal situation (all buckets used equally), no bucket would have
-     * more than ceil(#items/#buckets) items. that's the ideal chain length. */
-    unsigned ideal_chain_maxlen;
-
-    /* nonideal_items is the number of items in the hash whose chain position
-     * exceeds the ideal chain maxlen. these items pay the penalty for an uneven
-     * hash distribution; reaching them in a chain traversal takes >ideal steps */
-    unsigned nonideal_items;
-
-    /* ineffective expands occur when a bucket doubling was performed, but
-     * afterward, more than half the items in the hash had nonideal chain
-     * positions. If this happens on two consecutive expansions we inhibit any
-     * further expansion, as it's not helping; this happens when the hash
-     * function isn't a good fit for the key domain. When expansion is inhibited
-     * the hash will still work, albeit no longer in constant time. */
-    unsigned ineff_expands, noexpand;
-
-    uint32_t signature; /* used only to find hash tables in external analysis */
-#ifdef HASH_BLOOM
-    uint32_t bloom_sig; /* used only to test bloom exists in external analysis */
-    uint8_t *bloom_bv;
-    char bloom_nbits;
-#endif
-
-} UT_hash_table;
-
-typedef struct UT_hash_handle
-{
-    struct UT_hash_table *tbl;
-    void *prev; /* prev element in app order      */
-    void *next; /* next element in app order      */
-    struct UT_hash_handle *hh_prev; /* previous hh in bucket order    */
-    struct UT_hash_handle *hh_next; /* next hh in bucket order        */
-    void *key; /* ptr to enclosing struct's key  */
-    unsigned keylen; /* enclosing struct's key len     */
-    unsigned hashv; /* result of hash-fcn(key)        */
-} UT_hash_handle;
-
-#endif /* UTHASH_H */
diff --git a/src/include/coap/utlist.h b/src/include/coap/utlist.h
deleted file mode 100644 (file)
index 1889a8e..0000000
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- Copyright (c) 2007-2010, Troy D. Hanson   http://uthash.sourceforge.net
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef UTLIST_H
-#define UTLIST_H
-
-#define UTLIST_VERSION 1.9.1
-
-/*
- * This file contains macros to manipulate singly and doubly-linked lists.
- *
- * 1. LL_ macros:  singly-linked lists.
- * 2. DL_ macros:  doubly-linked lists.
- * 3. CDL_ macros: circular doubly-linked lists.
- *
- * To use singly-linked lists, your structure must have a "next" pointer.
- * To use doubly-linked lists, your structure must "prev" and "next" pointers.
- * Either way, the pointer to the head of the list must be initialized to NULL.
- *
- * ----------------.EXAMPLE -------------------------
- * struct item {
- *      int id;
- *      struct item *prev, *next;
- * }
- *
- * struct item *list = NULL:
- *
- * int main() {
- *      struct item *item;
- *      ... allocate and populate item ...
- *      DL_APPEND(list, item);
- * }
- * --------------------------------------------------
- *
- * For doubly-linked lists, the append and delete macros are O(1)
- * For singly-linked lists, append and delete are O(n) but prepend is O(1)
- * The sort macro is O(n log(n)) for all types of single/double/circular lists.
- */
-
-/* These macros use decltype or the earlier __typeof GNU extension.
- As decltype is only available in newer compilers (VS2010 or gcc 4.3+
- when compiling c++ code), this code uses whatever method is needed
- or, for VS2008 where neither is available, uses casting workarounds. */
-#ifdef _MSC_VER            /* MS compiler */
-#if (_MSC_VER >= 1600) && (defined(__cplusplus) && (__cplusplus >= 201103L))  /* VS2010 and newer in C++ mode */
-#define LDECLTYPE(x) decltype(x)
-#else                     /* VS2008 or older (or VS2010 in C mode) */
-#define NO_DECLTYPE
-#define LDECLTYPE(x) char*
-#endif
-#else                      /* GNU, Sun and other compilers */
-#define LDECLTYPE(x) __typeof(x)
-#endif
-
-/* for VS2008 we use some workarounds to get around the lack of decltype,
- * namely, we always reassign our tmp variable to the list head if we need
- * to dereference its prev/next pointers, and save/restore the real head.*/
-#ifdef NO_DECLTYPE
-#define _SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); }
-#define _NEXT(elt,list) ((char*)((list)->next))
-#define _NEXTASGN(elt,list,to) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); }
-#define _PREV(elt,list) ((char*)((list)->prev))
-#define _PREVASGN(elt,list,to) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); }
-#define _RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; }
-#define _CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); }
-#else
-#define _SV(elt,list)
-#define _NEXT(elt,list) ((elt)->next)
-#define _NEXTASGN(elt,list,to) ((elt)->next)=(to)
-#define _PREV(elt,list) ((elt)->prev)
-#define _PREVASGN(elt,list,to) ((elt)->prev)=(to)
-#define _RS(list)
-#define _CASTASGN(a,b) (a)=(b)
-#endif
-
-/******************************************************************************
- * The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort    *
- * Unwieldy variable names used here to avoid shadowing passed-in variables.  *
- *****************************************************************************/
-#define LL_SORT(list, cmp)                                                                     \
-do {                                                                                           \
-  LDECLTYPE(list) _ls_p;                                                                       \
-  LDECLTYPE(list) _ls_q;                                                                       \
-  LDECLTYPE(list) _ls_e;                                                                       \
-  LDECLTYPE(list) _ls_tail;                                                                    \
-  LDECLTYPE(list) _ls_oldhead;                                                                 \
-  LDECLTYPE(list) _tmp;                                                                        \
-  int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping;                       \
-  if (list) {                                                                                  \
-    _ls_insize = 1;                                                                            \
-    _ls_looping = 1;                                                                           \
-    while (_ls_looping) {                                                                      \
-      _CASTASGN(_ls_p,list);                                                                   \
-      _CASTASGN(_ls_oldhead,list);                                                             \
-      list = NULL;                                                                             \
-      _ls_tail = NULL;                                                                         \
-      _ls_nmerges = 0;                                                                         \
-      while (_ls_p) {                                                                          \
-        _ls_nmerges++;                                                                         \
-        _ls_q = _ls_p;                                                                         \
-        _ls_psize = 0;                                                                         \
-        for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) {                                         \
-          _ls_psize++;                                                                         \
-          _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list);                               \
-          if (!_ls_q) break;                                                                   \
-        }                                                                                      \
-        _ls_qsize = _ls_insize;                                                                \
-        while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) {                                    \
-          if (_ls_psize == 0) {                                                                \
-            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
-          } else if (_ls_qsize == 0 || !_ls_q) {                                               \
-            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
-          } else if (cmp(_ls_p,_ls_q) <= 0) {                                                  \
-            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
-          } else {                                                                             \
-            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
-          }                                                                                    \
-          if (_ls_tail) {                                                                      \
-            _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list);                     \
-          } else {                                                                             \
-            _CASTASGN(list,_ls_e);                                                             \
-          }                                                                                    \
-          _ls_tail = _ls_e;                                                                    \
-        }                                                                                      \
-        _ls_p = _ls_q;                                                                         \
-      }                                                                                        \
-      _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list);                            \
-      if (_ls_nmerges <= 1) {                                                                  \
-        _ls_looping=0;                                                                         \
-      }                                                                                        \
-      _ls_insize *= 2;                                                                         \
-    }                                                                                          \
-  } else _tmp=NULL; /* quiet gcc unused variable warning */                                    \
-} while (0)
-
-#define DL_SORT(list, cmp)                                                                     \
-do {                                                                                           \
-  LDECLTYPE(list) _ls_p;                                                                       \
-  LDECLTYPE(list) _ls_q;                                                                       \
-  LDECLTYPE(list) _ls_e;                                                                       \
-  LDECLTYPE(list) _ls_tail;                                                                    \
-  LDECLTYPE(list) _ls_oldhead;                                                                 \
-  LDECLTYPE(list) _tmp;                                                                        \
-  int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping;                       \
-  if (list) {                                                                                  \
-    _ls_insize = 1;                                                                            \
-    _ls_looping = 1;                                                                           \
-    while (_ls_looping) {                                                                      \
-      _CASTASGN(_ls_p,list);                                                                   \
-      _CASTASGN(_ls_oldhead,list);                                                             \
-      list = NULL;                                                                             \
-      _ls_tail = NULL;                                                                         \
-      _ls_nmerges = 0;                                                                         \
-      while (_ls_p) {                                                                          \
-        _ls_nmerges++;                                                                         \
-        _ls_q = _ls_p;                                                                         \
-        _ls_psize = 0;                                                                         \
-        for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) {                                         \
-          _ls_psize++;                                                                         \
-          _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list);                               \
-          if (!_ls_q) break;                                                                   \
-        }                                                                                      \
-        _ls_qsize = _ls_insize;                                                                \
-        while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) {                                    \
-          if (_ls_psize == 0) {                                                                \
-            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
-          } else if (_ls_qsize == 0 || !_ls_q) {                                               \
-            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
-          } else if (cmp(_ls_p,_ls_q) <= 0) {                                                  \
-            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
-          } else {                                                                             \
-            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
-          }                                                                                    \
-          if (_ls_tail) {                                                                      \
-            _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list);                     \
-          } else {                                                                             \
-            _CASTASGN(list,_ls_e);                                                             \
-          }                                                                                    \
-          _SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list);                          \
-          _ls_tail = _ls_e;                                                                    \
-        }                                                                                      \
-        _ls_p = _ls_q;                                                                         \
-      }                                                                                        \
-      _CASTASGN(list->prev, _ls_tail);                                                         \
-      _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list);                            \
-      if (_ls_nmerges <= 1) {                                                                  \
-        _ls_looping=0;                                                                         \
-      }                                                                                        \
-      _ls_insize *= 2;                                                                         \
-    }                                                                                          \
-  } else _tmp=NULL; /* quiet gcc unused variable warning */                                    \
-} while (0)
-
-#define CDL_SORT(list, cmp)                                                                    \
-do {                                                                                           \
-  LDECLTYPE(list) _ls_p;                                                                       \
-  LDECLTYPE(list) _ls_q;                                                                       \
-  LDECLTYPE(list) _ls_e;                                                                       \
-  LDECLTYPE(list) _ls_tail;                                                                    \
-  LDECLTYPE(list) _ls_oldhead;                                                                 \
-  LDECLTYPE(list) _tmp;                                                                        \
-  LDECLTYPE(list) _tmp2;                                                                       \
-  int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping;                       \
-  if (list) {                                                                                  \
-    _ls_insize = 1;                                                                            \
-    _ls_looping = 1;                                                                           \
-    while (_ls_looping) {                                                                      \
-      _CASTASGN(_ls_p,list);                                                                   \
-      _CASTASGN(_ls_oldhead,list);                                                             \
-      list = NULL;                                                                             \
-      _ls_tail = NULL;                                                                         \
-      _ls_nmerges = 0;                                                                         \
-      while (_ls_p) {                                                                          \
-        _ls_nmerges++;                                                                         \
-        _ls_q = _ls_p;                                                                         \
-        _ls_psize = 0;                                                                         \
-        for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) {                                         \
-          _ls_psize++;                                                                         \
-          _SV(_ls_q,list);                                                                     \
-          if (_NEXT(_ls_q,list) == _ls_oldhead) {                                              \
-            _ls_q = NULL;                                                                      \
-          } else {                                                                             \
-            _ls_q = _NEXT(_ls_q,list);                                                         \
-          }                                                                                    \
-          _RS(list);                                                                           \
-          if (!_ls_q) break;                                                                   \
-        }                                                                                      \
-        _ls_qsize = _ls_insize;                                                                \
-        while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) {                                    \
-          if (_ls_psize == 0) {                                                                \
-            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
-            if (_ls_q == _ls_oldhead) { _ls_q = NULL; }                                        \
-          } else if (_ls_qsize == 0 || !_ls_q) {                                               \
-            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
-            if (_ls_p == _ls_oldhead) { _ls_p = NULL; }                                        \
-          } else if (cmp(_ls_p,_ls_q) <= 0) {                                                  \
-            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
-            if (_ls_p == _ls_oldhead) { _ls_p = NULL; }                                        \
-          } else {                                                                             \
-            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
-            if (_ls_q == _ls_oldhead) { _ls_q = NULL; }                                        \
-          }                                                                                    \
-          if (_ls_tail) {                                                                      \
-            _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list);                     \
-          } else {                                                                             \
-            _CASTASGN(list,_ls_e);                                                             \
-          }                                                                                    \
-          _SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list);                          \
-          _ls_tail = _ls_e;                                                                    \
-        }                                                                                      \
-        _ls_p = _ls_q;                                                                         \
-      }                                                                                        \
-      _CASTASGN(list->prev,_ls_tail);                                                          \
-      _CASTASGN(_tmp2,list);                                                                   \
-      _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_tmp2); _RS(list);                           \
-      if (_ls_nmerges <= 1) {                                                                  \
-        _ls_looping=0;                                                                         \
-      }                                                                                        \
-      _ls_insize *= 2;                                                                         \
-    }                                                                                          \
-  } else _tmp=NULL; /* quiet gcc unused variable warning */                                    \
-} while (0)
-
-/******************************************************************************
- * singly linked list macros (non-circular)                                   *
- *****************************************************************************/
-#define LL_PREPEND(head,add)                                                                   \
-do {                                                                                           \
-  (add)->next = head;                                                                          \
-  head = add;                                                                                  \
-} while (0)
-
-#define LL_APPEND(head,add)                                                                    \
-do {                                                                                           \
-  LDECLTYPE(head) _tmp;                                                                        \
-  (add)->next=NULL;                                                                            \
-  if (head) {                                                                                  \
-    _tmp = head;                                                                               \
-    while (_tmp->next) { _tmp = _tmp->next; }                                                  \
-    _tmp->next=(add);                                                                          \
-  } else {                                                                                     \
-    (head)=(add);                                                                              \
-  }                                                                                            \
-} while (0)
-
-#define LL_DELETE(head,del)                                                                    \
-do {                                                                                           \
-  LDECLTYPE(head) _tmp;                                                                        \
-  if ((head) == (del)) {                                                                       \
-    (head)=(head)->next;                                                                       \
-  } else {                                                                                     \
-    _tmp = head;                                                                               \
-    while (_tmp->next && (_tmp->next != (del))) {                                              \
-      _tmp = _tmp->next;                                                                       \
-    }                                                                                          \
-    if (_tmp->next) {                                                                          \
-      _tmp->next = ((del)->next);                                                              \
-    }                                                                                          \
-  }                                                                                            \
-} while (0)
-
-/* Here are VS2008 replacements for LL_APPEND and LL_DELETE */
-#define LL_APPEND_VS2008(head,add)                                                             \
-do {                                                                                           \
-  if (head) {                                                                                  \
-    (add)->next = head;     /* use add->next as a temp variable */                             \
-    while ((add)->next->next) { (add)->next = (add)->next->next; }                             \
-    (add)->next->next=(add);                                                                   \
-  } else {                                                                                     \
-    (head)=(add);                                                                              \
-  }                                                                                            \
-  (add)->next=NULL;                                                                            \
-} while (0)
-
-#define LL_DELETE_VS2008(head,del)                                                             \
-do {                                                                                           \
-  if ((head) == (del)) {                                                                       \
-    (head)=(head)->next;                                                                       \
-  } else {                                                                                     \
-    char *_tmp = (char*)(head);                                                                \
-    while ((head)->next && ((head)->next != (del))) {                                          \
-      (head) = (head)->next;                                                                   \
-    }                                                                                          \
-    if ((head)->next) {                                                                        \
-      (head)->next = ((del)->next);                                                            \
-    }                                                                                          \
-    {                                                                                          \
-      char **_head_alias = (char**)&(head);                                                    \
-      *_head_alias = _tmp;                                                                     \
-    }                                                                                          \
-  }                                                                                            \
-} while (0)
-#ifdef NO_DECLTYPE
-#undef LL_APPEND
-#define LL_APPEND LL_APPEND_VS2008
-#undef LL_DELETE
-#define LL_DELETE LL_DELETE_VS2008
-#endif
-/* end VS2008 replacements */
-
-#define LL_FOREACH(head,el)                                                                    \
-    for(el=head;el;el=el->next)
-
-#define LL_FOREACH_SAFE(head,el,tmp)                                                           \
-  for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
-
-#define LL_SEARCH_SCALAR(head,out,field,val)                                                   \
-do {                                                                                           \
-    LL_FOREACH(head,out) {                                                                     \
-      if ((out)->field == (val)) break;                                                        \
-    }                                                                                          \
-} while(0)
-
-#define LL_SEARCH(head,out,elt,cmp)                                                            \
-do {                                                                                           \
-    LL_FOREACH(head,out) {                                                                     \
-      if ((cmp(out,elt))==0) break;                                                            \
-    }                                                                                          \
-} while(0)
-
-/******************************************************************************
- * doubly linked list macros (non-circular)                                   *
- *****************************************************************************/
-#define DL_PREPEND(head,add)                                                                   \
-do {                                                                                           \
- (add)->next = head;                                                                           \
- if (head) {                                                                                   \
-   (add)->prev = (head)->prev;                                                                 \
-   (head)->prev = (add);                                                                       \
- } else {                                                                                      \
-   (add)->prev = (add);                                                                        \
- }                                                                                             \
- (head) = (add);                                                                               \
-} while (0)
-
-#define DL_APPEND(head,add)                                                                    \
-do {                                                                                           \
-  if (head) {                                                                                  \
-      (add)->prev = (head)->prev;                                                              \
-      (head)->prev->next = (add);                                                              \
-      (head)->prev = (add);                                                                    \
-      (add)->next = NULL;                                                                      \
-  } else {                                                                                     \
-      (head)=(add);                                                                            \
-      (head)->prev = (head);                                                                   \
-      (head)->next = NULL;                                                                     \
-  }                                                                                            \
-} while (0);
-
-#define DL_DELETE(head,del)                                                                    \
-do {                                                                                           \
-  if ((del)->prev == (del)) {                                                                  \
-      (head)=NULL;                                                                             \
-  } else if ((del)==(head)) {                                                                  \
-      (del)->next->prev = (del)->prev;                                                         \
-      (head) = (del)->next;                                                                    \
-  } else {                                                                                     \
-      (del)->prev->next = (del)->next;                                                         \
-      if ((del)->next) {                                                                       \
-          (del)->next->prev = (del)->prev;                                                     \
-      } else {                                                                                 \
-          (head)->prev = (del)->prev;                                                          \
-      }                                                                                        \
-  }                                                                                            \
-} while (0);
-
-#define DL_FOREACH(head,el)                                                                    \
-    for(el=head;el;el=el->next)
-
-/* this version is safe for deleting the elements during iteration */
-#define DL_FOREACH_SAFE(head,el,tmp)                                                           \
-  for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
-
-/* these are identical to their singly-linked list counterparts */
-#define DL_SEARCH_SCALAR LL_SEARCH_SCALAR
-#define DL_SEARCH LL_SEARCH
-
-/******************************************************************************
- * circular doubly linked list macros                                         *
- *****************************************************************************/
-#define CDL_PREPEND(head,add)                                                                  \
-do {                                                                                           \
- if (head) {                                                                                   \
-   (add)->prev = (head)->prev;                                                                 \
-   (add)->next = (head);                                                                       \
-   (head)->prev = (add);                                                                       \
-   (add)->prev->next = (add);                                                                  \
- } else {                                                                                      \
-   (add)->prev = (add);                                                                        \
-   (add)->next = (add);                                                                        \
- }                                                                                             \
-(head)=(add);                                                                                  \
-} while (0)
-
-#define CDL_DELETE(head,del)                                                                   \
-do {                                                                                           \
-  if ( ((head)==(del)) && ((head)->next == (head))) {                                          \
-      (head) = 0L;                                                                             \
-  } else {                                                                                     \
-     (del)->next->prev = (del)->prev;                                                          \
-     (del)->prev->next = (del)->next;                                                          \
-     if ((del) == (head)) (head)=(del)->next;                                                  \
-  }                                                                                            \
-} while (0);
-
-#define CDL_FOREACH(head,el)                                                                   \
-    for(el=head;el;el=(el->next==head ? 0L : el->next))
-
-#define CDL_FOREACH_SAFE(head,el,tmp1,tmp2)                                                    \
-  for((el)=(head), ((tmp1)=(head)?((head)->prev):NULL);                                        \
-      (el) && ((tmp2)=(el)->next, 1);                                                          \
-      ((el) = (((el)==(tmp1)) ? 0L : (tmp2))))
-
-#define CDL_SEARCH_SCALAR(head,out,field,val)                                                  \
-do {                                                                                           \
-    CDL_FOREACH(head,out) {                                                                    \
-      if ((out)->field == (val)) break;                                                        \
-    }                                                                                          \
-} while(0)
-
-#define CDL_SEARCH(head,out,elt,cmp)                                                           \
-do {                                                                                           \
-    CDL_FOREACH(head,out) {                                                                    \
-      if ((cmp(out,elt))==0) break;                                                            \
-    }                                                                                          \
-} while(0)
-
-#endif /* UTLIST_H */
-
diff --git a/src/include/hw_emul/hw_interface.h b/src/include/hw_emul/hw_interface.h
deleted file mode 100644 (file)
index 8a7befe..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/* *****************************************************************\r
- *\r
- * Copyright 2017 Samsung Electronics 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
-#ifndef HW_INTERFACE_H\r
-#define HW_INTERFACE_H\r
-\r
-#include <mbedtls/ssl.h>\r
-#include "ss_emul.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-\r
-/**\r
- * Error-definition for hw interface\r
- */\r
-\r
-typedef enum HwifResult\r
-{\r
-    HWIF_ERR_INVALID_PARAM    = -100, /**< Invalid Paramter */\r
-    HWIF_ERR_OUT_OF_MEMORY   = -99,  /**< Out of memory */\r
-    HWIF_ERR_NO_DATA                = -98,  /**< No data found */\r
-    HWIF_ERROR         = -1,  /**< Internal Error */\r
-    HWIF_SUCCESS     = 0,    /**< No Error */\r
-} HwifResult_t;\r
-\r
-\r
-/**\r
- * This callback will be invoked to get a key context based on specific name indication\r
- * (service name, key usage, key type). The key context may be same with the alias name.\r
- *\r
- * @param[in] service  service name indicates first category name\r
- * @param[in] usage  usage name indicates sub-category name\r
- * @param[in] keytype  (optional) key type name indication if any, otherwise it usually will be NULL\r
- * @return  void type pointer value on success, otherwise NULL\r
- */\r
-void* HWGetKeyContext(const char* service, const char* usage, const char* keytype);\r
-\r
-/**\r
- * This callback will deallocate the key context that was retrieved from TZ\r
- * by calling GetHwKeyContext callback.\r
- *\r
- * @param[in] keyContext  key context object to be deallocated,\r
- *                   which was obtained from GetHwKeyContext callback function\r
- * @return  0 on success, otherwise a negative value\r
- */\r
-int HWFreeKeyContext(void* keyContext);\r
-\r
-/**\r
- * This callback will be invoked to load own(i.e., pre-injected) certificate from HW(e.g., TZ, eSE)\r
- *\r
- * @param[in] keyContext  key context object that identifies proper certificate chain\r
- * @param[out] cert_chain  certificate chain in binary\r
- * @param[out] cert_chain_len  total length of certificate chain\r
- * @return  0 on success, otherwise a negative value\r
- */\r
-int HWGetOwnCertificateChain(const void* keyContext,\r
-                    unsigned char** cert_chain, size_t* cert_chain_len);\r
-\r
-/**\r
- * This callback should provide setting up alternative functions (e.g., rsa_sign, key_len, etc)\r
- * of which HW(e.g., TZ, eSE) management library to the specified mbedtls context\r
- * that will be used during handshake.\r
- *\r
- * @param[in] ctx  pointer of pk context of mbedtls\r
- * @param[in] keyContext  key context object that identifies proper public/private key\r
- * @return  0 on success, otherwise a negative value\r
- */\r
-int HWSetupPkContext(mbedtls_pk_context* ctx, void* key_context);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif // HW_INTERFACE_H\r
-\r
diff --git a/src/include/hw_emul/ss_emul.h b/src/include/hw_emul/ss_emul.h
deleted file mode 100644 (file)
index f1c1e06..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/* *****************************************************************\r
- *\r
- * Copyright 2017 Samsung Electronics 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
-#ifndef SS_EMUL_H\r
-#define SS_EMUL_H\r
-\r
-#include <mbedtls/ssl.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-/**\r
- * Type define\r
- */\r
- enum SSE_KEY_TYPE\r
- {\r
-     KEYTYPE_NONE = -1,\r
-     KEYTYPE_RSA,\r
-     KEYTYPE_ECC\r
- };\r
-\r
-/**\r
- * This function set own certificate file and key file path to use hw emulation\r
- *\r
- * @param[in] cert_filepath  path for own certificate file\r
- * @param[in] key_filepath  path for private key file\r
- * @param[in] pwd  password for private key file\r
- * @return  0 on success, otherwise a negative value\r
- */\r
-int SSemulSetCertkeyFilepath(const char* cert_filepath,\r
-                                            const char* key_filepath, const char* pwd);\r
-\r
-/**\r
- * This function get type of stored key from hw emulation\r
- *\r
- * @param[in] keyContext  key context object that identifies proper certificate chain\r
- * @return  SSE_KEY_TYPE\r
- */\r
-int SSemulGetKeytype(const void* keyContext);\r
-\r
-/**\r
- * This function load own certificate data from hw emulation\r
- *\r
- * @param[in] keyContext  key context object that identifies proper certificate chain\r
- * @param[out] cert_chain  certificate chain in binary\r
- * @param[out] cert_chain_len  total length of certificate chain\r
- * @return  0 on success, otherwise a negative value\r
- */\r
-int SSemulLoadOwncert(const void* keyContext,\r
-                                           uint8_t** cert_chain, size_t* cert_chain_len);\r
-\r
-/**\r
- * This function get private key length from hw emulation\r
- *\r
- * @param[in] keyContext  key context object that identifies proper certificate chain\r
- * @return  positive value on success, otherwise a negative value or zero\r
- */\r
-int SSemulGetKeylen(const void* keyContext);\r
-\r
-/**\r
- * This function sign hash data with RSA private key from hw emulation\r
- *\r
- * @param[in] keyContext  key context object that identifies proper certificate chain\r
- * @param[in] f_rng  RNG function\r
- * @param[in] p_rng  RNG parameter\r
- * @param[in] mode  RSA key mode\r
- * @param[in] md_alg  md algorithm\r
- * @param[in] hashlen  length of hash\r
- * @param[in] hash  hash data to be signed\r
- * @param[in] sig  signature of hash\r
- * @return  0 on success, otherwise a negative value\r
- */\r
-int SSemulRsaSign(const void *keyContext,\r
-                            int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,\r
-                            int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,\r
-                            const unsigned char *hash, unsigned char *sig );\r
-\r
-/**\r
- * This function sign hash data with ECC private key from hw emulation\r
- *\r
- * @param[in] ctx  key context poniter of mbedtls_pk_context\r
- * @param[in] md_alg  md algorithm\r
- * @param[in] hash  hash data to be signed\r
- * @param[in] hashlen  length of hash\r
- * @param[in] sig  signature of hash\r
- * @param[in] sig_len  length of signature\r
- * @param[in] f_rng  RNG function\r
- * @param[in] p_rng  RNG parameter\r
- * @return  0 on success, otherwise a negative value\r
- */\r
-int SSemulEcdsaSign( void *ctx, mbedtls_md_type_t md_alg,\r
-                   const unsigned char *hash, size_t hash_len,\r
-                   unsigned char *sig, size_t *sig_len,\r
-                   int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif // SS_EMUL_H\r
-\r
-\r
diff --git a/src/include/security/base64.h b/src/include/security/base64.h
deleted file mode 100644 (file)
index a983f1e..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef _IOTVT_B64_H_
-#define _IOTVT_B64_H_
-
-#include <stdint.h>
-#include <stdio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Macro to calculate the size of 'output' buffer required for
- * a 'input' buffer of length x during Base64 encoding operation.
- */
-#define B64ENCODE_OUT_SAFESIZE(x) ((((x) + 3 - 1)/3) * 4 + 1)
-
-/**
- * Macro to calculate the size of 'output' buffer required for
- * a 'input' buffer of length x during Base64 decoding operation.
- */
-#define B64DECODE_OUT_SAFESIZE(x) (((x)*3)/4)
-
-/**
- * Result code of base64 functions.
- */
-typedef enum
-{
-    B64_OK = 0,
-    B64_INVALID_PARAM,
-    B64_OUTPUT_BUFFER_TOO_SMALL,
-    B64_ERROR
-} B64Result;
-
-/**
- * Encode the plain message in base64.
- *
- * @param in is the plain message to be converted.
- * @param inLen is the byte length of plain message.
- * @param outBuf is the output buffer containing Base64 encoded message.
- * @note outBuf adds a NULL to the string configuration.
- * @param outBufSize is the size of output buffer.
- * @param outLen is the byte length of encoded message.
- *
- * @return ::B64_OK for Success, otherwise some error value.
- */
-B64Result b64Encode(const uint8_t* in, const size_t inLen,
-               char* outBuf, const size_t outBufSize, uint32_t *outLen);
-
-/**
- * Decode the encoded message in base64.
- *
- * @param in is the Base64 encoded message to be converted.
- * @param inLen is the byte length of the encoded message.
- * @param outBuf is the output buffer containing decoded message.
- * @note outBuf adds a NULL to the string configuration.
- * @param outBufSize is the size of output buffer.
- * @param outLen is the byte length of decoded message.
- *
- * @return ::B64_OK for Success, otherwise some error value.
- */
-B64Result b64Decode(const char* in, const size_t inLen,
-               uint8_t* outBuf, size_t outBufSize, uint32_t *outLen);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif  //IOTVT_B64_H
diff --git a/src/include/security/iotvticalendar.h b/src/include/security/iotvticalendar.h
deleted file mode 100644 (file)
index 1fec23e..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef IOTVT_ICALENDAR_H
-#define IOTVT_ICALENDAR_H
-
-//Not supported on Arduino due lack of absolute time need to implement iCalendar
-#ifndef WITH_ARDUINO
-
-#include <stdint.h> // for uint8_t typedef
-#include <stdbool.h>
-#include <time.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define FREQ_DAILY (1)
-#define MAX_BYDAY_SIZE (7)     //7 days of week
-#define TM_YEAR_OFFSET (1900)  //tm_year field of c-lang tm date-time struct
-                               //represents number of years since 1900.
-#define TM_DST_OFFSET (1)      //c-lang tm struct Daylight Saving Time offset.
-#define TOTAL_HOURS (24)       //Total hours in a day.
-
-typedef struct IotvtICalRecur IotvtICalRecur_t;
-typedef struct IotvtICalPeriod IotvtICalPeriod_t;
-
-/**
- *  date-time  = date "T" time.
- *
- *  date               = date-value
- *  date-value         = date-fullyear date-month date-mday
- *  date-fullyear      = 4DIGIT
- *  date-month         = 2DIGIT        ;01-12
- *  date-mday          = 2DIGIT        ;01-28, 01-29, 01-30, 01-31
- *                                     ;based on month/year
- *
- *  time               = time-hour time-minute time-second [time-utc]
- *  time-hour          = 2DIGIT        ;00-23
- *  time-minute        = 2DIGIT        ;00-59
- *  time-second        = 2DIGIT        ;00-60
- *                                     ;The "60" value is used to account for "leap" seconds.
- *
- *  Date-Time Forms:
- *  1. Date with Local time
- *      20150626T150000
- */
-typedef struct tm IotvtICalDateTime_t; //c-lang tm date-time struct
-
-/**
- * Bit mask for weekdays.
- */
-typedef enum
-{
-    NO_WEEKDAY  = 0X0,
-    SUNDAY      = (0x1 << 0),
-    MONDAY      = (0x1 << 1),
-    TUESDAY     = (0x1 << 2),
-    WEDNESDAY   = (0x1 << 3),
-    THURSDAY    = (0x1 << 4),
-    FRIDAY      = (0x1 << 5),
-    SATURDAY    = (0x1 << 6)
-} IotvtICalWeekdayBM_t;
-
-/**
- * Result code for IotvtICalendar.
- */
-typedef enum
-{
-    IOTVTICAL_SUCCESS = 0,       /**< successfully completed operation. */
-    IOTVTICAL_VALID_ACCESS,      /**< access is within allowable time. */
-    IOTVTICAL_INVALID_ACCESS,    /**< access is not within allowable time. */
-    IOTVTICAL_INVALID_PARAMETER, /**< invalid method parameter. */
-    IOTVTICAL_INVALID_RRULE,     /**< rrule is not well form, missing FREQ. */
-    IOTVTICAL_INVALID_PERIOD,    /**< period is not well form, start-datetime is after end-datetime. */
-    IOTVTICAL_ERROR              /**< encounter error. */
-} IotvtICalResult_t;
-
-/**
- *  Grammar for iCalendar data type PERIOD.
- *
- *  period = date-time "/" date-time  ; start-time / end-time.
- *                                    ;The start-time MUST be before the end-time.
- *
- */
-struct IotvtICalPeriod
-{
-    IotvtICalDateTime_t startDateTime;
-    IotvtICalDateTime_t endDateTime;
-};
-
-/*
- * Grammar for iCalendar data type RECUR.
- *
- * recur      = "FREQ"=freq *(
- *            ( ";" "UNTIL" "=" enddate ) /
- *            ( ";" "BYDAY" "=" bywdaylist ) /
- *            )
- *
- * freq       = "DAILY"
- * enddate    = date
- * bywdaylist = weekday/ ( weekday *("," weekday) )
- * weekday    = "SU" / "MO" / "TU" / "WE" / "TH" / "FR" / "SA"
- *
- * Example:
- * 1."Allow access on every Monday, Wednesday & Friday between 3pm to 5pm"
- *      PERIOD:20150626T150000/20150626T170000
- *      RRULE: FREQ=DAILY; BYDAY=MO, WE, FR
- * 2."Allow access every Monday, Wednesday & Friday from 3pm to 5pm until
- *    July 3rd, 2015"
- *      PERIOD:20150626T150000/20150626T170000
- *      RRULE: FREQ=DAILY; UNTIL=20150703; BYDAY=MO, WE, FR
- */
-struct IotvtICalRecur
-{
-    uint16_t                freq;
-    IotvtICalDateTime_t     until;
-    IotvtICalWeekdayBM_t    byDay;
-};
-
-/**
- * This API is used by policy engine to checks if the
- * request to access resource is within valid time.
- *
- * @param period string representing period.
- * @param recur string representing recurrence rule
- *
- * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period
- * ::IOTVTICAL_INVALID_ACCESS, if the request is not within valid time period
- * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid
- * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format
- * ::IOTVTICAL_INVALID_RRULE, if rrule string has invalid format.
- *
- *Eg: if(IOTVTICAL_VALID_ACCESS == IsRequestWithinValidTime(period, recur))
- *    {
- *       //Access within allowable time
- *    }
- *    else
- *    {
- *      //Access is not within allowable time.
- *    }
- */
-IotvtICalResult_t IsRequestWithinValidTime(const char *period, const char *recur);
-
-/**
- * Parses periodStr and populate struct IotvtICalPeriod_t.
- *
- * @param periodStr string to be parsed.
- * @param period IotvtICalPeriod_t struct to be populated.
- *
- * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period
- * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid
- * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format
- * ::IOTVTICAL_INVALID_SUCCESS, if no error while parsing.
- */
-IotvtICalResult_t ParsePeriod(const char *periodStr, IotvtICalPeriod_t *period);
-
-/**
- * Parses recurStr and populate struct IotvtICalRecur_t.
- *
- * @param recurStr string to be parsed.
- * @param recur is the IotvtICalPeriod_t struct to be populated.
- *
- * @return ::IOTVTICAL_VALID_ACCESS, if the request is within valid time period
- * ::IOTVTICAL_INVALID_PARAMETER, if parameter are invalid
- * ::IOTVTICAL_INVALID_PERIOD, if period string has invalid format
- * ::IOTVTICAL_INVALID_RRULE, if rrule string has invalid format.
- */
-IotvtICalResult_t ParseRecur(const char *recurStr, IotvtICalRecur_t *recur);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
-#endif //IOTVT_ICALENDAR_H
diff --git a/src/include/security/oxmverifycommon.h b/src/include/security/oxmverifycommon.h
deleted file mode 100644 (file)
index c26852b..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-//******************************************************************
-//
-// Copyright 2016 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef _OXM_VERIFY_COMMON_
-#define _OXM_VERIFY_COMMON_
-
-#include "securevirtualresourcetypes.h"
-#include "casecurityinterface.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif // __cplusplus
-
-/** Verification Number Length */
-#define MUTUAL_VERIF_NUM_LEN (3)
-
-/** Label Length */
-#define LABEL_LEN (30)
-
-/**
- * Verification Method Option definition
- * This type supports multiple bit set.
- */
- typedef enum VerifyOptionBitmask
-{
-    NOT_APPLICABLE              = 0x0,
-    DISPLAY_NUM                 = (0x1 << 0),
-    USER_CONFIRM                = (0x1 << 1)
-} VerifyOptionBitmask_t;
-
-/**
- * Function pointer to display verification PIN
- */
-typedef OCStackResult (*DisplayNumCallback)(void * ctx, uint8_t verifNum[MUTUAL_VERIF_NUM_LEN]);
-
-/**
- * Function pointer to get user confirmation
- */
-typedef OCStackResult (*UserConfirmCallback)(void * ctx);
-
-/**
- * Function pointer to notify user input state
- */
-typedef OCStackResult (*InputStateCallback)(void * ctx);
-
-/**
- * Context for displaying verification PIN
- */
-typedef struct DisplayNumContext
-{
-    DisplayNumCallback callback;
-    void * context;
-} DisplayNumContext_t;
-
-/**
- * Context for getting user confirmation
- */
-typedef struct UserConfirmContext
-{
-    UserConfirmCallback callback;
-    void * context;
-} UserConfirmContext_t;
-
-/**
- * Context for notifying user input state
- */
-typedef struct InputStateContext
-{
-    InputStateCallback callback;
-    void * context;
-} InputStateContext_t;
-
-/**
- * Set Callback for displaying verification PIN
- */
-void SetDisplayNumCB(void * ptr, DisplayNumCallback displayNumCB);
-
-/**
- * Unset Callback for displaying verification PIN
- */
-void* UnsetDisplayNumCB();
-
-/**
- * Set Callback for getting user confirmation
- */
-void SetUserConfirmCB(void * ptr, UserConfirmCallback userConfirmCB);
-
-/**
- * Unset Callback for getting user confirmation
- */
-void* UnsetUserConfirmCB();
-
-/**
- * Set Callback for notifying user input state
- */
-void SetInputStateCB(void * ptr, UserConfirmCallback userConfirmCB);
-
-/**
- * Unset Callback for notifying user input state
- */
-void* UnsetInputStateCB();
-
-/**
- * Set verification method option.
- * The default is both display PIN and get user confirmation.
- */
-void SetVerifyOption(VerifyOptionBitmask_t verifyOption);
-
-/**
- * Call the Callback for Verifying Ownership Transfer process.
- */
-OCStackResult VerifyOwnershipTransfer(uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN],
-                                VerifyOptionBitmask_t verifyOption);
-
-/**
- * Call the Callback for notifying user input state
- */
-OCStackResult NotifyInputState(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/src/include/security/pbkdf2.h b/src/include/security/pbkdf2.h
deleted file mode 100644 (file)
index 2957db8..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef _PBKDF2_H
-#define _PBKDF2_H
-
-#include <stdio.h>
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/**
- * The number of iterations desired to derived key.
- * (Recommened by RFC 2898)
- */
-#define PBKDF_ITERATIONS 1000
-
-/**
- * Function to derive cryptographic key from the password. (RFC 2898)
- * In this implementation, HMAC with SHA2 is considered as a pseudorandom function
- *
- * @param passwd is the master password from which a derived key is generated.
- * @param pLen is the byte size of the passwd.
- * @param salt is a cryptographic salt.
- * @param saltlen is the byte size of the salt.
- * @param iteration is the number of iterations desired.
- * @param keyLen is the desired byte size of the derived key. (should be the same as
- *       derivedKey size)
- * @param derivedKey is the generated derived key
- *
- * @return  0 on success
- */
-int DeriveCryptoKeyFromPassword(const unsigned char* passwd, size_t pLen,
-                                const uint8_t* salt, const size_t saltLen,
-                                const size_t iterations,
-                                const size_t keyLen, uint8_t* derivedKey);
-
-#ifdef __cplusplus
-}
-#endif
-#endif // _PBKDF2_H
-
diff --git a/src/include/security/pinoxmcommon.h b/src/include/security/pinoxmcommon.h
deleted file mode 100644 (file)
index 5b75684..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 Samsung Electronics All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef PIN_CALLBACK_DEF_H_
-#define PIN_CALLBACK_DEF_H_
-
-#include "securevirtualresourcetypes.h"
-#include "casecurityinterface.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif // __cplusplus
-
-#define OXM_RANDOM_PIN_DEFAULT_SIZE (8)
-#define OXM_RANDOM_PIN_DEFAULT_PIN_TYPE (NUM_PIN | LOWERCASE_CHAR_PIN | UPPERCASE_CHAR_PIN)
-#define OXM_RANDOM_PIN_MIN_SIZE (4)
-#define OXM_RANDOM_PIN_MAX_SIZE (32)
-#define OXM_PRECONFIG_PIN_MAX_SIZE (OXM_RANDOM_PIN_MAX_SIZE)
-
-/** Number of PIN type */
-#define OXM_PIN_TYPE_COUNT 3
-
-/**
- * PIN type definition.
- * This type supports multiple bit set.
- * e.g.) NUM_PIN | UPPERCASE_CHAR_PIN
- */
-typedef enum OicSecPinType{
-    NUM_PIN            = (0x1 << 0),    //Numeric PIN
-    UPPERCASE_CHAR_PIN = (0x1 << 1),    //uppercase character PIN
-    LOWERCASE_CHAR_PIN = (0x1 << 2)     //lowercase character PIN
-}OicSecPinType_t;
-
-/**
- * Function pointer to print pin code.
- */
-typedef void (*GeneratePinCallback)(char* pinData, size_t pinSize);
-
-/**
- * Function pointer to input pin code.
- */
-typedef void (*InputPinCallback)(char* pinBuf, size_t bufSize);
-
-/**
- * Function pointer to close the displied PIN.
- */
-typedef void (*ClosePinDisplayCallback)(void);
-
-/**
- * Function to setting generate PIN callback from user.
- *
- * @param pinCB implementation of generate PIN callback.
- */
-void SetGeneratePinCB(GeneratePinCallback pinCB);
-
-/**
- * Function to setting input PIN callback from user.
- *
- * @param pinCB implementation of input PIN callback.
- */
-void SetInputPinCB(InputPinCallback pinCB);
-
-/**
- * Function to set the close PIN callback
- * This callback will be invoked when PIN based OTM is finished.
- *
- * @param closeCB implementation of close PIN callback.
- */
-void SetClosePinDisplayCB(ClosePinDisplayCallback closeCB);
-
-/**
- * Function to unset the input PIN callback.
- * NOTE : Do not call this function while PIN based ownership transfer.
- */
-void UnsetInputPinCB();
-
-/**
- * Function to unset the PIN generation callback.
- * NOTE : Do not call this function while PIN based ownership transfer.
- */
-void UnsetGeneratePinCB();
-
-/**
- * Function to unset the PIN close callback.
- * NOTE : Do not call this function while PIN based ownership transfer is in progress.
- */
-void UnsetClosePinCB();
-
-/**
- * Function to generate random PIN.
- * This function will send generated PIN to user via callback.
- *
- * @param pinBuffer is the reference to the buffer to store the generated PIN data.
- * @param bufferSize is the size of buffer.
- *
- * @return ::OC_STACK_OK in case of success or other value in case of error.
- */
-OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize);
-
-/**
- * Function to input PIN callback via input callback.
- *
- * @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data.
- * @param[in] bufferSize is the size of buffer.
- *
- * @return ::OC_STACK_OK in case of success or other value in ccase of error.
- */
-OCStackResult InputPin(char* pinBuffer, size_t bufferSize);
-
-/**
- * Function to invoke the callback for close a PIN dispaly.
- * NOTE : This function will be invoked from SRM while OTM
- */
-void ClosePinDisplay();
-
-#ifdef MULTIPLE_OWNER
-/**
- * Function to save the Pre-configured PIN.
- *
- * @param[in] pinBuffer PIN data
- * @param[in] pinLength byte length of PIN
- *
- * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
- */
-OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength);
-#endif
-
-/**
- * Function to setting the policy for random PIN generation
- *
- * @param[in] pinSize Byte length of random PIN
- * @param[in] pinType Type of random PIN (ref OicSecPinType)
- *
- * @return ::OC_STACK_OK in case of success or other value in case of error.
- */
-OCStackResult SetRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType);
-
-#ifdef __WITH_DTLS__
-
-/**
- * This function is used by OTM and SRM to
- * register device UUID is required to derive the temporal PSK.
- */
-void SetUuidForPinBasedOxm(const OicUuid_t* uuid);
-
-/**
- * This internal callback is used while Random PIN based OTM.
- * This callback will be used to establish a temporary secure session according to
- * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
- *
- * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
- * @param[in]  UNUSED1 UNUSED.
- * @param[in]  UNUSED2 UNUSED.
- * @param[out] result  Must be filled with the requested information.
- * @param[in]  result_length  Maximum size of @p result.
- *
- * @return The number of bytes written to @p result or a value
- *         less than zero on error.
- */
-int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
-              const unsigned char *UNUSED1, size_t UNUSED2,
-              unsigned char *result, size_t result_length);
-
-#ifdef MULTIPLE_OWNER
-/**
- * This internal callback is used while Random PIN based MOT.
- * This callback will be used to establish a temporary secure session according to
- * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
- *
- * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
- * @param[in]  UNUSED1 UNUSED.
- * @param[in]  UNUSED2 UNUSED.
- * @param[out] result  Must be filled with the requested information.
- * @param[in]  result_length  Maximum size of @p result.
- *
- * @return The number of bytes written to @p result or a value
- *         less than zero on error.
- */
-int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
-              const unsigned char *UNUSED1, size_t UNUSED2,
-              unsigned char *result, size_t result_length);
-
-
-/**
- * This internal callback is used while Preconfigured-PIN OTM.
- * This callback will be used to establish a temporary secure session according to
- * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
- *
- * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
- * @param[in]  UNUSED1 UNUSED.
- * @param[in]  UNUSED2 UNUSED.
- * @param[out] result  Must be filled with the requested information.
- * @param[in]  result_length  Maximum size of @p result.
- *
- * @return The number of bytes written to @p result or a value
- *         less than zero on error.
- */
-int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
-              const unsigned char *UNUSED1, size_t UNUSED2,
-              unsigned char *result, size_t result_length);
-
-
-/**
- * This internal callback is used while Preconfigured-PIN MOT.
- * This callback will be used to establish a temporary secure session according to
- * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
- *
- * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
- * @param[in]  UNUSED1 UNUSED.
- * @param[in]  UNUSED2 UNUSED.
- * @param[out] result  Must be filled with the requested information.
- * @param[in]  result_length  Maximum size of @p result.
- *
- * @return The number of bytes written to @p result or a value
- *         less than zero on error.
- */
-int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
-              const unsigned char *UNUSED1, size_t UNUSED2,
-              unsigned char *result, size_t result_length);
-
-#endif //MULTIPLE_OWNER
-
-/**
- * API to derive the PSK based on PIN and new device's UUID.
- * New device's UUID should be set through SetUuidForPinBasedOxm() API before this API is invoked.
- *
- * @param[out] result generated PSK
- *
- * @return 0 for success, otherwise error.
- */
-int DerivePSKUsingPIN(uint8_t* result);
-
-#endif //__WITH_DTLS__
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //PIN_CALLBACK_DEF_H_
diff --git a/src/include/security/pkix_interface.h b/src/include/security/pkix_interface.h
deleted file mode 100644 (file)
index 34aec27..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/******************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#ifndef PKIX_INTERFACE_H
-#define PKIX_INTERFACE_H
-
-#include "cainterface.h"
-#ifdef HW_PKIX
-#include "mbedtls/ssl.h"
-#endif //HW_PKIX
-
-//<-- KSR
-#include "mbedtls/pk.h"
-#include "mbedtls/x509_crt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Pre-Definition for key context
- */
-// IoTivity service name for HW key context query
-#define HWKEY_SVC_IOTIVITY "iotivity"
-
-// Default usage name for HW key context query
-#define HWKEY_USAGE_PRIMARY "primary"
-
-
-/**
- * Callback function for HW
- */
-//this callback will be invoked to get key context based on key usage
-typedef void* (*GetHwKeyContext)(const char* service, const char* usage, const char* keytype);
-
-//this callback will free key context that was retreived from TZ
-typedef int (*FreeHwKeyContext)(void* keyContext);
-
-//this callback will be invoked to load own certificate in case of TZ
-typedef int (*GetOwnCertFromHwCallback)(const void* keyContext, uint8_t** certChain, size_t* certChainLen);
-
-//this callback will be invoked to load private key in case of TZ
-typedef int (*SetupPkContextFromHwCallback)(mbedtls_pk_context* ctx, void* keyContext);
-
-typedef struct HWPkixContext {
-    GetHwKeyContext getHwKeyContext;
-    FreeHwKeyContext freeHwKeyContext;
-    GetOwnCertFromHwCallback getOwnCertCb;
-    SetupPkContextFromHwCallback setupPkContextCb;
-    void* hwKeyCtx;
-}HWPkixContext_t;
-
-/**
- * API to seting callbacks which is requried to use H/W based PKI
- *
- * @param[in] getHwKeyContext callback to get hw key context
- * @param[in] freeHwKeyContext callback to free hw key context
- * @param[in] getOwnCertCb callback to load certificate chain
- * @param[in] setupPkContextCb callback to setup PK context
- *
- * return 0 on success
- */
-int SetHwPkixCallbacks(GetHwKeyContext getHwKeyContext,
-                        FreeHwKeyContext freeHwKeyContext,
-                        GetOwnCertFromHwCallback getOwnCertCb,
-                        SetupPkContextFromHwCallback setupPkContextCb);
-
-/**
- * API to invoke the callback for setup PK context with H/W based PKI
- *
- * @param[in] pkCtx mbedtls's PK context
- *
- * return 0 on success
- */
-int SetupHwPkContext(mbedtls_pk_context* pkCtx);
-
-/**
- * This method is used by mbedTLS/SRM to retrieve PKIX related info
- *
- * @param[out] inf structure with certificate, private key and crl to be filled.
- *
- */
-void GetPkixInfo(PkiInfo_t * inf);
-/**
- * This method is used by mbedTLS/SRM to retrieve manufacturer PKIX related info
- *
- * @param[out] inf structure with certificate, private key and crl to be filled.
- *
- */
-void GetManufacturerPkixInfo(PkiInfo_t * inf);
-
-/**
- * Used by CA to retrieve credential types
- *
- * @param[out] list TLS suites boolean map.
- */
-void InitCipherSuiteList(bool * list);
-
-/**
- * Used by CA to retrieve manufacturer credential types
- *
- * @param[out] list TLS suites boolean map.
- */
-void InitManufacturerCipherSuiteList(bool * list);
-#ifdef __cplusplus
-}
-#endif
-
-#endif //PKIX_INTERFACE_H
diff --git a/src/include/security/securevirtualresourcetypes.h b/src/include/security/securevirtualresourcetypes.h
deleted file mode 100644 (file)
index f6de36c..0000000
+++ /dev/null
@@ -1,647 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * Data type definitions for all oic.sec.* types defined in the
- * OIC Security Specification.
- *
- * Note that throughout, ptrs are used rather than arrays.  There
- * are two primary reasons for this:
- * 1) The Spec defines many structures with optional fields, so pre-
- *    allocating these would be wasteful.
- * 2) There are in many cases arrays of Strings or arrays of Structs,
- *    which could not be defined as variable length arrays (e.g. array[])
- *    without breaking from the structure order and definition in the Spec.
- *
- * The primary drawback to this decision is that marshalling functions
- * will have to be written by hand to marshal these structures (e.g. to/from
- * Persistent Storage, or across memory boundaries).
- *
- * TODO reconcile against latest OIC Security Spec to ensure all fields correct.
- * (Last checked against v0.95)
- */
-
-#ifndef OC_SECURITY_RESOURCE_TYPES_H
-#define OC_SECURITY_RESOURCE_TYPES_H
-
-#include "iotivity_config.h"
-
-#include <stdint.h> // for uint8_t typedef
-#include <stdbool.h>
-#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
-#include "byte_array.h"
-#endif /* __WITH_DTLS__  or __WITH_TLS__*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Values used to create bit-maskable enums for single-value response with
- * embedded code.
- */
-#define ACCESS_GRANTED_DEF            (1 << 0)
-#define ACCESS_DENIED_DEF             (1 << 1)
-#define INSUFFICIENT_PERMISSION_DEF   (1 << 2)
-#define SUBJECT_NOT_FOUND_DEF         (1 << 3)
-#define RESOURCE_NOT_FOUND_DEF        (1 << 4)
-#define POLICY_ENGINE_ERROR_DEF       (1 << 5)
-#define INVALID_PERIOD_DEF            (1 << 6)
-#define ACCESS_WAITING_DEF            (1 << 7)
-#define AMS_SERVICE_DEF               (1 << 8)
-#define REASON_MASK_DEF               (INSUFFICIENT_PERMISSION_DEF | \
-                                       INVALID_PERIOD_DEF | \
-                                       SUBJECT_NOT_FOUND_DEF | \
-                                       RESOURCE_NOT_FOUND_DEF | \
-                                       POLICY_ENGINE_ERROR_DEF)
-
-
-/**
- * Access policy in least significant bits (from Spec):
- * 1st lsb:  C (Create)
- * 2nd lsb:  R (Read, Observe, Discover)
- * 3rd lsb:  U (Write, Update)
- * 4th lsb:  D (Delete)
- * 5th lsb:  N (Notify)
- */
-#define PERMISSION_CREATE       (1 << 0)
-#define PERMISSION_READ         (1 << 1)
-#define PERMISSION_WRITE        (1 << 2)
-#define PERMISSION_DELETE       (1 << 3)
-#define PERMISSION_NOTIFY       (1 << 4)
-#define PERMISSION_FULL_CONTROL (PERMISSION_CREATE | \
-                                 PERMISSION_READ | \
-                                 PERMISSION_WRITE | \
-                                 PERMISSION_DELETE | \
-                                 PERMISSION_NOTIFY)
-
-/**
- * @brief   Response type for all Action requests from CA layer;
- *          may include a reason code.
- *
- * To extract codes use GetReasonCode function on SRMAccessResponse:
- *
- * SRMAccessResponse_t response = SRMRequestHandler(obj, info);
- * if(SRM_TRUE == IsAccessGranted(response)) {
- *     SRMAccessResponseReasonCode_t reason = GetReasonCode(response);
- *     switch(reason) {
- *         case INSUFFICIENT_PERMISSION:
- *         ...etc.
- *     }
- * }
- */
-typedef enum
-{
-    ACCESS_GRANTED = ACCESS_GRANTED_DEF,
-    ACCESS_DENIED = ACCESS_DENIED_DEF,
-    ACCESS_DENIED_INVALID_PERIOD = ACCESS_DENIED_DEF
-        | INVALID_PERIOD_DEF,
-    ACCESS_DENIED_INSUFFICIENT_PERMISSION = ACCESS_DENIED_DEF
-        | INSUFFICIENT_PERMISSION_DEF,
-    ACCESS_DENIED_SUBJECT_NOT_FOUND = ACCESS_DENIED_DEF
-        | SUBJECT_NOT_FOUND_DEF,
-    ACCESS_DENIED_RESOURCE_NOT_FOUND = ACCESS_DENIED_DEF
-        | RESOURCE_NOT_FOUND_DEF,
-    ACCESS_DENIED_POLICY_ENGINE_ERROR = ACCESS_DENIED_DEF
-        | POLICY_ENGINE_ERROR_DEF,
-    ACCESS_WAITING_FOR_AMS = ACCESS_WAITING_DEF
-        | AMS_SERVICE_DEF,
-    ACCESS_DENIED_AMS_SERVICE_ERROR = ACCESS_DENIED
-        | AMS_SERVICE_DEF
-} SRMAccessResponse_t;
-
-/**
- * Reason code for SRMAccessResponse.
- */
-typedef enum
-{
-    NO_REASON_GIVEN = 0,
-    INSUFFICIENT_PERMISSION = INSUFFICIENT_PERMISSION_DEF,
-    SUBJECT_NOT_FOUND = SUBJECT_NOT_FOUND_DEF,
-    RESOURCE_NOT_FOUND = RESOURCE_NOT_FOUND_DEF,
-} SRMAccessResponseReasonCode_t;
-
-/**
- * Extract Reason Code from Access Response.
- */
-INLINE_API SRMAccessResponseReasonCode_t GetReasonCode(
-    SRMAccessResponse_t response)
-{
-    SRMAccessResponseReasonCode_t reason =
-        (SRMAccessResponseReasonCode_t)(response & REASON_MASK_DEF);
-    return reason;
-}
-
-/**
- * Returns 'true' iff request should be passed on to RI layer.
- */
-INLINE_API bool IsAccessGranted(SRMAccessResponse_t response)
-{
-    if(ACCESS_GRANTED == (response & ACCESS_GRANTED))
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
-}
-
-typedef struct OicSecRsrc OicSecRsrc_t;
-
-typedef struct OicSecValidity OicSecValidity_t;
-
-typedef struct OicSecAce OicSecAce_t;
-
-typedef struct OicSecAcl OicSecAcl_t;
-
-typedef struct OicSecAmacl OicSecAmacl_t;
-
-typedef struct OicSecCred OicSecCred_t;
-
-/**
- * Aid for assigning/testing vals with OicSecCredType_t.
- * Example:
- *  OicSecCredType_t ct = PIN_PASSWORD | ASYMMETRIC_KEY;
- *  if((ct & PIN_PASSWORD) == PIN_PASSWORD)
- *  {
- *      // ct contains PIN_PASSWORD flag.
- *  }
- */
-typedef enum OSCTBitmask
-{
-    NO_SECURITY_MODE                = 0x0,
-    SYMMETRIC_PAIR_WISE_KEY         = (0x1 << 0),
-    SYMMETRIC_GROUP_KEY             = (0x1 << 1),
-    ASYMMETRIC_KEY                  = (0x1 << 2),
-    SIGNED_ASYMMETRIC_KEY           = (0x1 << 3),
-    PIN_PASSWORD                    = (0x1 << 4),
-    ASYMMETRIC_ENCRYPTION_KEY       = (0x1 << 5),
-} OSCTBitmask_t;
-
-/**
- * /oic/sec/credtype (Credential Type) data type.
- * Derived from OIC Security Spec /oic/sec/cred; see Spec for details.
- *              0:  no security mode
- *              1:  symmetric pair-wise key
- *              2:  symmetric group key
- *              4:  asymmetric key
- *              8:  signed asymmetric key (aka certificate)
- *              16: PIN /password
- */
-typedef OSCTBitmask_t OicSecCredType_t;
-
-typedef struct OicSecDoxm OicSecDoxm_t;
-
-typedef enum OicSecDpm
-{
-    NORMAL                          = 0x0,
-    RESET                           = (0x1 << 0),
-    TAKE_OWNER                      = (0x1 << 1),
-    BOOTSTRAP_SERVICE               = (0x1 << 2),
-    SECURITY_MANAGEMENT_SERVICES    = (0x1 << 3),
-    PROVISION_CREDENTIALS           = (0x1 << 4),
-    PROVISION_ACLS                  = (0x1 << 5),
-#ifdef MULTIPLE_OWNER
-    TAKE_SUB_OWNER                  = (0x1 << 6),
-#endif
-    // << 7 THROUGH 15 RESERVED
-} OicSecDpm_t;
-
-// These types are taken from the Security Spec v1.1.12 /pstat resource definition
-// Note that per the latest spec, there is NO definition for Multiple Service Client Directed
-// provisioning mode, so that enum value has been removed.
-typedef enum OicSecDpom
-{
-    MULTIPLE_SERVICE_SERVER_DRIVEN    = (0x1 << 0),
-    SINGLE_SERVICE_SERVER_DRIVEN      = (0x1 << 1),
-    SINGLE_SERVICE_CLIENT_DRIVEN      = (0x1 << 2),
-} OicSecDpom_t;
-
-//TODO: Need more clarification on deviceIDFormat field type.
-#if 0
-typedef enum
-{
-    URN = 0x0
-}OicSecDvcIdFrmt_t;
-#endif
-
-typedef enum
-{
-    OIC_R_ACL_TYPE = 0,
-    OIC_R_AMACL_TYPE,
-    OIC_R_CRED_TYPE,
-    OIC_R_CRL_TYPE,
-    OIC_R_DOXM_TYPE,
-    OIC_R_DPAIRING_TYPE,
-    OIC_R_PCONF_TYPE,
-    OIC_R_PSTAT_TYPE,
-    OIC_R_SACL_TYPE,
-    OIC_SEC_SVR_TYPE_COUNT, //define the value to number of SVR
-    NOT_A_SVR_RESOURCE = 99
-}OicSecSvrType_t;
-
-typedef enum
-{
-    OIC_JUST_WORKS                          = 0x0,
-    OIC_RANDOM_DEVICE_PIN                   = 0x1,
-    OIC_MANUFACTURER_CERTIFICATE            = 0x2,
-    OIC_DECENTRALIZED_PUBLIC_KEY            = 0x3,
-    OIC_OXM_COUNT,
-#ifdef MULTIPLE_OWNER
-    OIC_PRECONFIG_PIN                       = 0xFF00,
-#endif //MULTIPLE_OWNER
-    OIC_MV_JUST_WORKS                       = 0xFF01,
-    OIC_CON_MFG_CERT                        = 0xFF02,
-}OicSecOxm_t;
-
-typedef enum
-{
-    OIC_ENCODING_UNKNOW = 0,
-    OIC_ENCODING_RAW = 1,
-    OIC_ENCODING_BASE64 = 2,
-    OIC_ENCODING_PEM = 3,
-    OIC_ENCODING_DER = 4
-}OicEncodingType_t;
-
-#ifdef MULTIPLE_OWNER
-typedef enum
-{
-    MOT_STATUS_READY = 0,
-    MOT_STATUS_IN_PROGRESS = 1,
-    MOT_STATUS_DONE = 2,
-}MotStatus_t;
-#endif //MULTIPLE_OWNER
-
-/*
- * oic.sec.mom type definition
- * TODO: This type will be included to OIC Security Spec.
- * 0 : Disable multiple owner
- * 1 : Enable multiple owner (Always on)
- * 2 : Timely multiple owner enable
- */
-typedef enum
-{
-    OIC_MULTIPLE_OWNER_DISABLE = 0,
-    OIC_MULTIPLE_OWNER_ENABLE = 1,
-    OIC_MULTIPLE_OWNER_TIMELY_ENABLE = 2,
-    OIC_NUMBER_OF_MOM_TYPE = 3
-}OicSecMomType_t;
-
-typedef struct OicSecKey OicSecKey_t;
-
-typedef struct OicSecOpt OicSecOpt_t;
-
-typedef struct OicSecPstat OicSecPstat_t;
-
-typedef struct OicSecRole OicSecRole_t;
-
-typedef struct OicSecSacl OicSecSacl_t;
-
-typedef char *OicUrn_t; //TODO is URN type defined elsewhere?
-
-typedef struct OicUuid OicUuid_t; //TODO is UUID type defined elsewhere?
-
-#ifdef MULTIPLE_OWNER
-typedef struct OicSecSubOwner OicSecSubOwner_t;
-typedef struct OicSecMom OicSecMom_t;
-#endif //MULTIPLE_OWNER
-
-
-#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
-typedef struct OicSecCrl OicSecCrl_t;
-typedef ByteArray_t OicSecCert_t;
-#else
-typedef void OicSecCert_t;
-#endif /* __WITH_DTLS__ or __WITH_TLS__*/
-
-/**
- * /oic/uuid (Universal Unique Identifier) data type.
- */
-#define UUID_LENGTH 128/8 // 128-bit GUID length
-//TODO: Confirm the length and type of ROLEID.
-#define ROLEID_LENGTH 128/8 // 128-bit ROLEID length
-#define OWNER_PSK_LENGTH_128 128/8 //byte size of 128-bit key size
-#define OWNER_PSK_LENGTH_256 256/8 //byte size of 256-bit key size
-
-struct OicUuid
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    //TODO fill in unless this is defined elsewhere?
-    uint8_t             id[UUID_LENGTH];
-};
-
-/**
- * /oic/sec/jwk (JSON Web Key) data type.
- * See JSON Web Key (JWK)  draft-ietf-jose-json-web-key-41
- */
-#define JWK_LENGTH 256/8 // 256 bit key length
-struct OicSecKey
-{
-    uint8_t                *data;
-    size_t                  len;
-
-    // TODO: This field added as workaround. Will be replaced soon.
-    OicEncodingType_t encoding;
-
-};
-
-struct OicSecOpt
-{
-    uint8_t                *data;
-    size_t                  len;
-
-    OicEncodingType_t encoding;
-    bool                revstat;
-};
-
-struct OicSecRsrc
-{
-    char *href; // 0:R:S:Y:String
-    char *rel; // 1:R:S:N:String
-    char** types; // 2:R:S:N:String Array
-    size_t typeLen; // the number of elts in types
-    char** interfaces; // 3:R:S:N:String Array
-    size_t interfaceLen; // the number of elts in interfaces
-    OicSecRsrc_t *next;
-};
-
-struct OicSecValidity
-{
-    char* period; // 0:R:S:Y:String
-    char** recurrences; // 1:R:M:Y:Array of String
-    size_t recurrenceLen; // the number of elts in recurrence
-    OicSecValidity_t *next;
-};
-
-struct OicSecAce
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    OicUuid_t subjectuuid;              // 0:R:S:Y:uuid
-    OicSecRsrc_t *resources;            // 1:R:M:Y:Resource
-    uint16_t permission;                // 2:R:S:Y:UINT16
-    OicSecValidity_t *validities;       // 3:R:M:N:Time-interval
-#ifdef MULTIPLE_OWNER
-    OicUuid_t* eownerID;                //4:R:S:N:oic.uuid
-#endif
-    OicSecAce_t *next;
-};
-
-/**
- * /oic/sec/acl (Access Control List) data type.
- * Derived from OIC Security Spec; see Spec for details.
- */
-struct OicSecAcl
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    OicUuid_t           rownerID;        // 0:R:S:Y:oic.uuid
-    OicSecAce_t         *aces; // 1:R:M:N:ACE
-};
-
-/**
- * /oic/sec/amacl (Access Manager Service Accesss Control List) data type.
- * Derived from OIC Security Spec; see Spec for details.
- */
-struct OicSecAmacl
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    size_t              resourcesLen;   // the number of elts in Resources
-    char                **resources;    // 0:R:M:Y:String
-    size_t              amssLen;        // the number of elts in Amss
-    OicUuid_t           *amss;          // 1:R:M:Y:acl
-    OicUuid_t           rownerID;        // 2:R:S:Y:oic.uuid
-    OicSecAmacl_t         *next;
-};
-
-/**
- * /oic/sec/cred (Credential) data type.
- * Derived from OIC Security Spec; see Spec for details.
- */
-struct OicSecCred
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    uint16_t            credId;         // 0:R:S:Y:UINT16
-    OicUuid_t           subject;        // 1:R:S:Y:oic.uuid
-    //Note: Need further clarification on roleID data type
-    //NOTE: Need further clarification on roleId datatype.
-    //size_t              roleIdsLen;     // the number of elts in RoleIds
-    //OicSecRole_t        *roleIds;       // 2:R:M:N:oic.sec.role
-    OicSecCredType_t    credType;       // 3:R:S:Y:oic.sec.credtype
-#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
-    OicSecKey_t         publicData;     // own cerificate chain
-    char            *credUsage;            // 4:R:S:N:String
-    OicSecOpt_t        optionalData;   // CA's cerificate chain
-#endif /* __WITH_DTLS__  or __WITH_TLS__*/
-    OicSecKey_t         privateData;    // 6:R:S:N:oic.sec.key
-    char                *period;        // 7:R:S:N:String
-    OicUuid_t           rownerID;       // 8:R:S:Y:oic.uuid
-#ifdef MULTIPLE_OWNER
-    OicUuid_t           *eownerID;      //9:R:S:N:oic.uuid
-#endif //MULTIPLE_OWNER
-    OicSecCred_t        *next;
-};
-
-#ifdef MULTIPLE_OWNER
-struct OicSecSubOwner {
-    OicUuid_t uuid;
-    MotStatus_t status;
-    OicSecSubOwner_t* next;
-};
-
-struct OicSecMom{
-    OicSecMomType_t mode;
-};
-#endif //MULTIPLE_OWNER
-
-/**
- * /oic/sec/doxm (Device Owner Transfer Methods) data type
- * Derived from OIC Security Spec; see Spec for details.
- */
-struct OicSecDoxm
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    OicUrn_t            *oxmType;       // 0:R:M:N:URN
-    size_t              oxmTypeLen;     // the number of elts in OxmType
-    OicSecOxm_t         *oxm;           // 1:R:M:N:UINT16
-    size_t              oxmLen;         // the number of elts in Oxm
-    OicSecOxm_t         oxmSel;         // 2:R/W:S:Y:UINT16
-    OicSecCredType_t    sct;            // 3:R:S:Y:oic.sec.credtype
-    bool                owned;          // 4:R:S:Y:Boolean
-    //TODO: Need more clarification on deviceIDFormat field type.
-    //OicSecDvcIdFrmt_t   deviceIDFormat; // 5:R:S:Y:UINT8
-    OicUuid_t           deviceID;       // 6:R:S:Y:oic.uuid
-    bool                dpc;            // 7:R:S:Y:Boolean
-    OicUuid_t           owner;          // 8:R:S:Y:oic.uuid
-#ifdef MULTIPLE_OWNER
-    OicSecSubOwner_t* subOwners;        //9:R/W:M:N:oic.uuid
-    OicSecMom_t *mom;                   //10:R/W:S:N:oic.sec.mom
-#endif //MULTIPLE_OWNER
-    OicUuid_t           rownerID;       // 11:R:S:Y:oic.uuid
-};
-
-/**
- * /oic/sec/pstat (Provisioning Status) data type.
- */
-struct OicSecPstat
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    bool                isOp;           // 0:R:S:Y:Boolean
-    OicSecDpm_t         cm;             // 1:R:S:Y:oic.sec.dpm
-    OicSecDpm_t         tm;             // 2:RW:S:Y:oic.sec.dpm
-    OicUuid_t           deviceID;       // 3:R:S:Y:oic.uuid
-    OicSecDpom_t        om;             // 4:RW:M:Y:oic.sec.dpom
-    size_t              smLen;          // the number of elts in Sm
-    OicSecDpom_t        *sm;            // 5:R:M:Y:oic.sec.dpom
-    uint16_t            commitHash;     // 6:R:S:Y:oic.sec.sha256
-    OicUuid_t           rownerID;       // 7:R:S:Y:oic.uuid
-};
-
-/**
- * /oic/sec/role (Role) data type.
- * Derived from OIC Security Spec; see Spec for details.
- */
-struct OicSecRole
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    //TODO fill in with Role definition
-    uint8_t             id[ROLEID_LENGTH];
-};
-
-/**
- * /oic/sec/sacl (Signed Access Control List) data type.
- * Derived from OIC Security Spec; see Spec for details.
- */
-struct OicSecSacl
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    //TODO fill in from OIC Security Spec
-#if defined(_MSC_VER)
-    uint8_t unused; // VS doesn't like empty structs
-#endif
-};
-
-#if defined(__WITH_DTLS__) ||  defined(__WITH_TLS__)
-struct OicSecCrl
-{
-    uint16_t CrlId;
-    ByteArray_t ThisUpdate;
-    OicSecKey_t CrlData;
-};
-#endif /* __WITH_DTLS__ or __WITH_TLS__ */
-
-/**
- * @brief   direct pairing data type
- */
-typedef struct OicPin OicDpPin_t;
-
-typedef struct OicSecPdAcl OicSecPdAcl_t;
-
-typedef struct OicSecPconf OicSecPconf_t;
-
-typedef struct OicSecDpairing OicSecDpairing_t;
-
-#define DP_PIN_LENGTH 8 // temporary length
-
-/**
- * @brief   /oic/sec/prmtype (Pairing Method Type) data type.
- *              0:  not allowed
- *              1:  pre-configured pin
- *              2:  random pin
- */
-typedef enum PRMBitmask
-{
-    PRM_NOT_ALLOWED             = 0x0,
-    PRM_PRE_CONFIGURED        = (0x1 << 0),
-    PRM_RANDOM_PIN               = (0x1 << 1),
-} PRMBitmask_t;
-
-typedef PRMBitmask_t OicSecPrm_t;
-
-
-struct OicPin
-{
-    uint8_t             val[DP_PIN_LENGTH];
-};
-
-/**
- * @brief   oic.sec.dpacltype (Device Pairing Access Control List) data type.
- */
-struct OicSecPdAcl
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    char                  **resources;        // 0:R:M:Y:String
-    size_t                resourcesLen;      // the number of elts in Resources
-    uint16_t             permission;        // 1:R:S:Y:UINT16
-    char                  **periods;            // 2:R:M*:N:String (<--M*; see Spec)
-    char                  **recurrences;    // 3:R:M:N:String
-    size_t                prdRecrLen;         // the number of elts in Periods/Recurrences
-    OicSecPdAcl_t    *next;
-};
-
-/**
- * @brief   /oic/sec/pconf (Pairing Configuration) data type
- */
-struct OicSecPconf
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    bool                  edp;                // 0:W:S:M:Boolean
-    OicSecPrm_t      *prm;              // 1:R:M:N:UINT16
-    size_t                prmLen;          // the number of elts in Prm
-    OicDpPin_t          pin;               // 2:R:S:Y:String
-    OicSecPdAcl_t    *pdacls;         // 3:R:M:Y:oic.sec.pdacltype
-    OicUuid_t           *pddevs;        // 4:R:M:Y:oic.uuid
-    size_t                 pddevLen;     // the number of elts in pddev
-    OicUuid_t           deviceID;       // 5:R:S:Y:oic.uuid
-    OicUuid_t           rownerID;          // 6:R:S:Y:oic.uuid
-};
-
-/**
- * @brief   /oic/sec/dpairing (Device Pairing) data type
- */
-struct OicSecDpairing
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    OicSecPrm_t      spm;               // 0:R/W:S:Y:UINT16
-    OicUuid_t           pdeviceID;     // 1:R:S:Y:oic.uuid
-    OicUuid_t           rownerID;          // 2:R:S:Y:oic.uuid
-};
-
-#define OIC_SEC_MAX_VER_LEN 16 // Security Version length. i.e., 00.00.000 + reserved space
-
-/**
- * @brief   security version data type
- */
-typedef struct OicSecVer OicSecVer_t;
-
-/**
- * @brief   /oic/sec/ver (Security Version) data type
- */
-struct OicSecVer
-{
-    // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
-    char              secv[OIC_SEC_MAX_VER_LEN];          // 0:R:S:Y:String
-    OicUuid_t       deviceID;     // 1:R:S:Y:oic.uuid
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //OC_SECURITY_RESOURCE_TYPES_H
diff --git a/src/include/security/srmutility.h b/src/include/security/srmutility.h
deleted file mode 100644 (file)
index 52f8c9c..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-//******************************************************************
-//
-// Copyright 2015 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef IOTVT_SRM_UTILITY_H
-#define IOTVT_SRM_UTILITY_H
-
-#include "ocstack.h"
-#if defined (__TIZENRT__)
-#include <apps/netutils/cJSON.h>
-#else
-#include "cjson/cJSON.h"
-#endif
-#include "securevirtualresourcetypes.h"
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-#include <coap/uri.h>
-#ifdef __cplusplus
-}
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-typedef struct OicParseQueryIter OicParseQueryIter_t;
-
-/**
- * OicRestQueryIter data structure is used for book-keeping
- * sub-REST query's attribute's and value's, starting location &
- * length between calls to GetNextQuery(). This struct needs
- * to be first initialized with ParseQueryIterInit().
- *
- */
-struct OicParseQueryIter
-{
-    unsigned char * attrPos;    /**< stating location of attribute. */
-    size_t attrLen;             /**< length of the attribute. */
-    unsigned char * valPos;     /**< starting location of value. */
-    size_t valLen;              /**< length of the value. */
-    coap_parse_iterator_t pi;   /**< coap struct for tokenizing the query.*/
-};
-
-typedef enum OicSecOtmEvent{
-    OIC_OTM_READY = 0,
-    OIC_OTM_STARTED = 1,
-    OIC_OTM_DONE = 2,
-    OIC_OTM_ERROR = 3
-}OicSecOtmEvent_t;
-
-/**
- * Callback function to recevie the OTM event on server side.
- *
- * @param addr PT's address (address can be NULL in case of init state)
- * @param port PT's port (It is meaningless in case of init state & BLE)
- * @param uuid PT's UUID (UUID can be NULL in case of init state & coap reqest)
- * @param event OTM state (@ref OicSecOtmEvent_t)
- */
-typedef void (*OicSecOtmEventHandler_t)(const char* addr, uint16_t port,
-                                        const char* uuid, int event);
-
-/**
- * Macro to verify success of operation.
- * eg: VERIFY_SUCCESS(TAG, OC_STACK_OK == foo(), ERROR);
- * @note Invoking function must define "exit:" label for goto functionality to work correctly.
- */
-#define VERIFY_SUCCESS(tag, op, logLevel) do{ if (!(op)) \
-            {OIC_LOG((logLevel), tag, #op " failed!!"); goto exit; } }while(0)
-
-/**
- * Macro to verify argument is not equal to NULL.
- * eg: VERIFY_NON_NULL(TAG, ptrData, ERROR);
- * @note Invoking function must define "exit:" label for goto functionality to work correctly.
- */
-#define VERIFY_NON_NULL(tag, arg, logLevel) do{ if (NULL == (arg)) \
-            { OIC_LOG((logLevel), tag, #arg " is NULL"); goto exit; } }while(0)
-
-/**
- * This method initializes the @ref OicParseQueryIter_t struct.
- *
- * @param query is the REST query, to be parsed.
- * @param parseIter is the @ref OicParseQueryIter_t struct, to be initialized based on the query.
- */
-void ParseQueryIterInit(const unsigned char * query, OicParseQueryIter_t * parseIter);
-
-/**
- * This method fills the @ref OicParseQueryIter_t struct with next REST query's
- * attribute's and value's information.
- *
- * @param parseIter is the @ref OicParseQueryIter_t struct, has next query's attribute's
- *  & value's info.
- *
- * @return reference to the @ref OicParseQueryIter_t if it has parsed query info, else
- * NULL if it has no query to parse.
- */
-OicParseQueryIter_t * GetNextQuery(OicParseQueryIter_t * parseIter);
-
-/**
- * This method acts as a helper function for JSON unmarshalling by various SVR's.
- *
- * @param jsonRoot point to the root JSON node containing the OicUuid array.
- * @param arrayItem is the name of the JSON OicUuid array item.
- * @param numUuids is the pointer to the number of OicUuid's available in JSON array.
- * @param uuids is the pointer to the array of OicUuid's.
- *
- * @return ::OC_STACK_OK on success, some other value upon failure.
- */
-OCStackResult AddUuidArray(const cJSON* jsonRoot, const char* arrayItem,
-                           size_t *numUuids, OicUuid_t** uuids);
-
-/**
- * Function to getting string of ownership transfer method
- *
- * @prarm oxmType ownership transfer method
- *
- * @return string value of ownership transfer method
- */
-const char* GetOxmString(OicSecOxm_t oxmType);
-
-/*
- * This method converts UUID to canonical format string.
- *
- * @param uuid Device UUID
- * @param strUuid converted UUID in canonical format
- * @return OC_STACK_OK for success.
- *
- * @note Caller needs to invoke OICFree after done using the return pointer
- */
-OCStackResult ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid);
-
-
-/*
- * This method converts string UUID to OicUuid_t.
- *
- * @param strUuid Device UUID in string format
- * @param uuid converted UUID in OicUuid_t format
- * @return OC_STACK_OK for success.
- *
- */
-OCStackResult ConvertStrToUuid(const char* strUuid, OicUuid_t* uuid);
-
-
-#if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
-/**
- * API to save the seed value to generate device UUID.
- *
- * @param seed buffer of seed value.
- * @param seedSize byte length of seed
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult SetDeviceIdSeed(const uint8_t* seed, size_t seedSize);
-
-/**
- * API to register OTM event handler
- *
- * @param otmEventHandler implementation of OTM event handler (@ref OicSecOtmEventHandler_t)
- */
-void SetOtmEventHandler(OicSecOtmEventHandler_t otmEventHandler);
-
-/**
- * Invoke OTM event handler to notify the OTM state.
- *
- * @param addr PT's address (address can be NULL in case of init state)
- * @param port PT's port (It is meaningless in case of init state & BLE)
- * @param uuid PT's UUID (UUID can be NULL in case of init state & coap reqest)
- * @param event OTM state (@ref OicSecOtmEvent_t)
- * @param result OTM result code
- */
-void InvokeOtmEventHandler(const char* addr, uint16_t port,
-                           const OicUuid_t* uuid, OicSecOtmEvent_t event);
-#endif
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif //IOTVT_SRM_UTILITY_H
index 80d7124..b475e20 100644 (file)
@@ -2,8 +2,6 @@ MESSAGE("===================================================================")
 MESSAGE("Building...MOT client")
 MESSAGE("===================================================================")
 
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include/cjson)
-
 SET(INTROSPECTION_PATH ${CMAKE_CURRENT_SOURCE_DIR}/introspection)
 ADD_CUSTOM_COMMAND(
        OUTPUT dbus1
diff --git a/src/mot-agent/ma-db.c b/src/mot-agent/ma-db.c
deleted file mode 100644 (file)
index a3d20eb..0000000
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include "iotivity_config.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <glib.h>
-#include <gio/gio.h>
-#include <sqlite3.h>
-
-#include "oic_malloc.h"
-#include "oic_string.h"
-#include "ocprovisioningmanager.h"
-
-#include <tzplatform_config.h>
-
-#include "ma.h"
-#include "ma-log.h"
-#include "ma-util.h"
-
-#define MAX_FILE_PATH_LEN 1024
-
-static const char* PRVN_DB_FILE_NAME = "oic_pdm_ma.db"; /**< Provisining DB file */
-
-#define UUID_LENGTH 128/8 /**< 128-bit GUID length */
-
-typedef enum PdmDeviceState {
-    PDM_DEVICE_ACTIVE = 0,
-    PDM_DEVICE_STALE = 1,
-    PDM_DEVICE_INIT = 2,
-    PDM_DEVICE_UNKNOWN = 99
-} PdmDeviceState_t;
-
-#define PDM_FIRST_INDEX 0
-#define PDM_SECOND_INDEX 1
-
-#define PDM_BIND_INDEX_FIRST 1
-#define PDM_BIND_INDEX_SECOND 2
-#define PDM_BIND_INDEX_THIRD 3
-
-#define PDM_CREATE_T_DEVICE_LIST "create table T_DEVICE_LIST(ID INTEGER PRIMARY KEY AUTOINCREMENT,\
-                                  UUID BLOB NOT NULL UNIQUE, STATE INT NOT NULL);"
-
-#define PDM_CREATE_T_DEVICE_LINK  "create table T_DEVICE_LINK_STATE(ID INT NOT NULL, ID2 INT NOT \
-                                   NULL,STATE INT NOT NULL, PRIMARY KEY (ID, ID2));"
-
-#define PDM_VERIFY_SQLITE_OK(arg, logLevel, retValue) do{ if (SQLITE_OK != (arg)) \
-            { MA_LOGE("Error in " #arg ", Error Message: %s", \
-               sqlite3_errmsg(g_db)); return retValue; }}while(0)
-
-#define PDM_SQLITE_TRANSACTION_BEGIN "BEGIN TRANSACTION;"
-#define PDM_SQLITE_TRANSACTION_COMMIT "COMMIT;"
-#define PDM_SQLITE_TRANSACTION_ROLLBACK "ROLLBACK;"
-#define PDM_SQLITE_GET_STALE_INFO "SELECT ID,ID2 FROM T_DEVICE_LINK_STATE WHERE STATE = ?"
-#define PDM_SQLITE_INSERT_T_DEVICE_LIST "INSERT INTO T_DEVICE_LIST VALUES(?,?,?)"
-#define PDM_SQLITE_GET_ID "SELECT ID FROM T_DEVICE_LIST WHERE UUID like ?"
-#define PDM_SQLITE_INSERT_LINK_DATA "INSERT INTO T_DEVICE_LINK_STATE VALUES(?,?,?)"
-#define PDM_SQLITE_DELETE_LINK "DELETE FROM T_DEVICE_LINK_STATE WHERE ID = ? and ID2 = ?"
-#define PDM_SQLITE_DELETE_DEVICE_LINK "DELETE FROM T_DEVICE_LINK_STATE WHERE ID = ? or ID2 = ?"
-#define PDM_SQLITE_DELETE_DEVICE "DELETE FROM T_DEVICE_LIST  WHERE ID = ?"
-#define PDM_SQLITE_DELETE_DEVICE_WITH_STATE "DELETE FROM T_DEVICE_LIST  WHERE STATE= ?"
-#define PDM_SQLITE_UPDATE_LINK "UPDATE T_DEVICE_LINK_STATE SET STATE = ?  WHERE ID = ? and ID2 = ?"
-#define PDM_SQLITE_LIST_ALL_UUID "SELECT UUID FROM T_DEVICE_LIST WHERE STATE = 0"
-#define PDM_SQLITE_GET_UUID "SELECT UUID,STATE FROM T_DEVICE_LIST WHERE ID = ?"
-#define PDM_SQLITE_GET_LINKED_DEVICES "SELECT ID,ID2 FROM T_DEVICE_LINK_STATE WHERE \
-                                           (ID = ? or ID2 = ?) and state = 0"
-#define PDM_SQLITE_GET_DEVICE_LINKS "SELECT ID,ID2 FROM T_DEVICE_LINK_STATE WHERE \
-                                          ID = ? and ID2 = ? and state = 0"
-#define PDM_SQLITE_UPDATE_DEVICE "UPDATE T_DEVICE_LIST SET STATE = ?  WHERE UUID like ?"
-#define PDM_SQLITE_GET_DEVICE_STATUS "SELECT STATE FROM T_DEVICE_LIST WHERE UUID like ?"
-#define PDM_SQLITE_UPDATE_LINK_STALE_FOR_STALE_DEVICE "UPDATE T_DEVICE_LINK_STATE SET STATE = 1\
-                                                          WHERE ID = ? or ID2 = ?"
-
-#define ASCENDING_ORDER(id1, id2) do{if( (id1) > (id2) )\
-  { int temp; temp = id1; id1 = id2; id2 = temp; }}while(0)
-
-#define CHECK_PDM_INIT() do{if(true != gInit)\
-  { MA_LOGE("PDB is not initialized"); \
-    return OC_STACK_PDM_IS_NOT_INITIALIZED; }}while(0)
-
-static sqlite3 *g_db = NULL;
-static bool gInit = false;  /* Only if we can open sqlite db successfully, gInit is true. */
-
-static OCStackResult begin()
-{
-       int res = 0;
-       res = sqlite3_exec(g_db, PDM_SQLITE_TRANSACTION_BEGIN, NULL, NULL, NULL);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-       return OC_STACK_OK;
-}
-
-static OCStackResult commit()
-{
-       int res = 0;
-       res = sqlite3_exec(g_db, PDM_SQLITE_TRANSACTION_COMMIT, NULL, NULL, NULL);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-       return OC_STACK_OK;
-}
-
-static OCStackResult rollback()
-{
-       int res = 0;
-       res = sqlite3_exec(g_db, PDM_SQLITE_TRANSACTION_ROLLBACK, NULL, NULL, NULL);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-       return OC_STACK_OK;
-}
-
-int ma_open_db()
-{
-       int result = 0;
-       char path[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(path, MAX_FILE_PATH_LEN, "%s/network/%s",
-                       "/opt/usr/data", PRVN_DB_FILE_NAME);
-
-       result = sqlite3_open_v2(path, &g_db, SQLITE_OPEN_READWRITE, NULL);
-       PDM_VERIFY_SQLITE_OK(result, ERROR, OC_STACK_ERROR);
-
-       gInit = true;
-
-       return OC_STACK_OK;
-}
-
-int ma_close_db()
-{
-       CHECK_PDM_INIT();
-       int res = 0;
-       res = sqlite3_close(g_db);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-       return OC_STACK_OK;
-}
-
-#ifdef IOTIVITY_DB_TEST
-static OCStackResult getUUIDforId(int id, OicUuid_t *uid, bool *result)
-{
-       sqlite3_stmt *stmt = 0;
-       int res = 0;
-       res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_UUID,
-                               strlen(PDM_SQLITE_GET_UUID) + 1, &stmt, NULL);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       while (SQLITE_ROW == sqlite3_step(stmt))
-       {
-               const void *ptr = sqlite3_column_blob(stmt, PDM_FIRST_INDEX);
-               memcpy(uid, ptr, sizeof(OicUuid_t));
-
-               int temp = sqlite3_column_int(stmt, PDM_SECOND_INDEX);
-               if(PDM_DEVICE_STALE == temp)
-               {
-                       if(result)
-                       {
-                               *result = true;
-                       }
-               }
-               else
-               {
-                       if(result)
-                       {
-                               *result = false;
-                       }
-               }
-               sqlite3_finalize(stmt);
-               return OC_STACK_OK;
-       }
-       sqlite3_finalize(stmt);
-
-       return OC_STACK_INVALID_PARAM;
-}
-#endif
-static OCStackResult getIdForUUID(const OicUuid_t *UUID , int *id)
-{
-       sqlite3_stmt *stmt = 0;
-       int res = 0;
-       res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_ID, strlen(PDM_SQLITE_GET_ID) + 1, &stmt, NULL);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       res = sqlite3_bind_blob(stmt, PDM_BIND_INDEX_FIRST, UUID, UUID_LENGTH, SQLITE_STATIC);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       MA_LOGD("Binding Done");
-       while (SQLITE_ROW == sqlite3_step(stmt))
-       {
-               int tempId = sqlite3_column_int(stmt, PDM_FIRST_INDEX);
-               MA_LOGD("ID is %d", tempId);
-               *id = tempId;
-               sqlite3_finalize(stmt);
-               return OC_STACK_OK;
-       }
-       sqlite3_finalize(stmt);
-       return OC_STACK_INVALID_PARAM;
-}
-
-static OCStackResult removeFromDeviceList(int id)
-{
-       sqlite3_stmt *stmt = 0;
-       int res = 0;
-       res = sqlite3_prepare_v2(g_db, PDM_SQLITE_DELETE_DEVICE,
-                                 strlen(PDM_SQLITE_DELETE_DEVICE) + 1, &stmt, NULL);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       if (sqlite3_step(stmt) != SQLITE_DONE)
-       {
-               MA_LOGE("Error message: %s", sqlite3_errmsg(g_db));
-               sqlite3_finalize(stmt);
-               return OC_STACK_ERROR;
-       }
-       sqlite3_finalize(stmt);
-
-       return OC_STACK_OK;
-}
-
-int ma_delete_device(const OicUuid_t *UUID)
-{
-       CHECK_PDM_INIT();
-       if (NULL == UUID)
-       {
-               return OC_STACK_INVALID_PARAM;
-       }
-       int id = 0;
-       if (OC_STACK_OK != getIdForUUID(UUID, &id))
-       {
-               MA_LOGE("Requested value not found");
-               return OC_STACK_INVALID_PARAM;
-       }
-       begin();
-       if(OC_STACK_OK != removeFromDeviceList(id))
-       {
-               rollback();
-               MA_LOGE("Requested value not found");
-               return OC_STACK_ERROR;
-       }
-       commit();
-       return OC_STACK_OK;
-}
-
-static OCStackResult removeLink(int id1, int id2)
-{
-       int res = 0;
-       sqlite3_stmt *stmt = 0;
-       res = sqlite3_prepare_v2(g_db, PDM_SQLITE_DELETE_LINK, strlen(PDM_SQLITE_DELETE_LINK) + 1, &stmt, NULL);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id1);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_SECOND, id2);
-       PDM_VERIFY_SQLITE_OK(res, ERROR, OC_STACK_ERROR);
-
-       if (SQLITE_DONE != sqlite3_step(stmt))
-       {
-               MA_LOGE("Error message: %s", sqlite3_errmsg(g_db));
-               sqlite3_finalize(stmt);
-               return OC_STACK_ERROR;
-       }
-       sqlite3_finalize(stmt);
-       return OC_STACK_OK;
-}
-
-int ma_unlink_devices(const OicUuid_t *UUID1, const OicUuid_t *UUID2)
-{
-       CHECK_PDM_INIT();
-       if (NULL == UUID1 || NULL == UUID2)
-       {
-               MA_LOGE("Invalid PARAM");
-               return  OC_STACK_INVALID_PARAM;
-       }
-
-       int id1 = 0;
-       if (OC_STACK_OK != getIdForUUID(UUID1, &id1))
-       {
-               MA_LOGE("Requested value not found");
-               return OC_STACK_INVALID_PARAM;
-       }
-
-       int id2 = 0;
-       if (OC_STACK_OK != getIdForUUID(UUID2, &id2))
-       {
-               MA_LOGE("Requested value not found");
-               return OC_STACK_INVALID_PARAM;
-       }
-       ASCENDING_ORDER(id1, id2);
-       return removeLink(id1, id2);
-}
\ No newline at end of file
diff --git a/src/mot-agent/ma-db.h b/src/mot-agent/ma-db.h
deleted file mode 100644 (file)
index 9b9b5f2..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __MAGENT_DB_H__
-#define __MAGENT_DB_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int ma_open_db();
-int ma_close_db();
-int ma_delete_device(const OicUuid_t *UUID);
-int ma_unlink_devices(const OicUuid_t *UUID1, const OicUuid_t *UUID2);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MAGENT_DB_H__ */
old mode 100755 (executable)
new mode 100644 (file)
index 8e1b3ef..097334a 100644 (file)
 #include <glib.h>
 #include <gio/gio.h>
 
-#include <iotivity_config.h>
-#include <platform_features.h>
 #include <utlist.h>
 #include <oic_malloc.h>
-#include <ocprovisioningmanager.h>
 #include <oxmjustworks.h>
 #include <oxmrandompin.h>
-#include <srmutility.h>
+#include <iotivity_config.h>
+#include <platform_features.h>
+#include <ocprovisioningmanager.h>
 #include <securevirtualresourcetypes.h>
-#include <security/srmutility.h>
 
 #include "ma.h"
 #include "ma-log.h"
@@ -41,7 +39,6 @@
 #include "ma-subowner.h"
 #include "ma-service-interface.h"
 #include "ma-generated-code.h"
-#include "ma-db.h"
 
 #define MAX_FILE_PATH_LEN 1024 /**< Max. file path length */
 #define ACL_RESRC_MAX_LEN 128 /**< '128' is ACL_RESRC_MAX_LEN */
@@ -721,39 +718,39 @@ static OicSecAcl_t* _create_target_acl(const OicUuid_t* target, const OicUuid_t*
        MA_LOGD("rsrc_interface = %s", rsrc_interface);
        MA_LOGD("permission = %d", permission);
 #endif
-       acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
+       acl = (OicSecAcl_t*)calloc(1, sizeof(OicSecAcl_t));
        if (!acl) {
-               MA_LOGE("acl : OICCalloc failed = %d", errno);
+               MA_LOGE("acl : calloc failed = %d", errno);
                return NULL;
        }
-       ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
+       ace = (OicSecAce_t*) calloc(1, sizeof(OicSecAce_t));
        if (!ace) {
-               MA_LOGE("ace : OICCalloc failed = %d", errno);
+               MA_LOGE("ace : calloc failed = %d", errno);
                return NULL;
        }
        LL_APPEND(acl->aces, ace);
        memcpy(ace->subjectuuid.id, subject->id, sizeof(subject->id));
 
        /* fill the href */
-       rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
+       rsrc = (OicSecRsrc_t*)calloc(1, sizeof(OicSecRsrc_t));
        if (!rsrc) {
-               MA_LOGE("rsrc: OICCalloc failed = %d", errno);
+               MA_LOGE("rsrc: calloc failed = %d", errno);
                goto CREATE_ACL_ERROR;
        }
 
        len = strlen(rsrc_uri)+1;  // '1' for null termination
-       rsrc->href = (char*) OICCalloc(len, sizeof(char));
+       rsrc->href = (char*) calloc(len, sizeof(char));
        if (!rsrc->href) {
-               MA_LOGE("rsrc->href: OICCalloc failed = %d", errno);
+               MA_LOGE("rsrc->href: calloc failed = %d", errno);
                goto CREATE_ACL_ERROR;
        }
        memcpy(rsrc->href, rsrc_uri, len);
 
        /* Fill the resource type (rt) */
        rsrc->typeLen = 1;
-       rsrc->types = (char**)OICCalloc(1, sizeof(char*));
+       rsrc->types = (char**)calloc(1, sizeof(char*));
        if (!rsrc->types) {
-               MA_LOGE("rsrc->types: OICCalloc failed = %d", errno);
+               MA_LOGE("rsrc->types: calloc failed = %d", errno);
                goto CREATE_ACL_ERROR;
        }
        rsrc->types[0] = g_strdup(rsrc_type);
@@ -764,9 +761,9 @@ static OicSecAcl_t* _create_target_acl(const OicUuid_t* target, const OicUuid_t*
 
        /* Fill the interface (if) */
        rsrc->interfaceLen = 1;
-       rsrc->interfaces = (char**)OICCalloc(1, sizeof(char*));
+       rsrc->interfaces = (char**)calloc(1, sizeof(char*));
        if (!rsrc->interfaces) {
-               MA_LOGE("rsrc->interfaces: OICCalloc failed = %d", errno);
+               MA_LOGE("rsrc->interfaces: calloc failed = %d", errno);
                goto CREATE_ACL_ERROR;
        }
        rsrc->interfaces[0] = g_strdup(rsrc_interface);
@@ -780,9 +777,9 @@ static OicSecAcl_t* _create_target_acl(const OicUuid_t* target, const OicUuid_t*
        /* Fill permission for the reource */
        ace->permission = permission;
 
-       ace->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t));
+       ace->eownerID = (OicUuid_t*)calloc(1, sizeof(OicUuid_t));
        if (NULL == ace->eownerID) {
-               MA_LOGE("ace->eownerID : OICCalloc failed = %d", errno);
+               MA_LOGE("ace->eownerID : calloc failed = %d", errno);
                goto CREATE_ACL_ERROR;
        }
        memcpy(ace->eownerID->id, subject->id, sizeof(subject->id));
@@ -1963,9 +1960,9 @@ static int _init_provision_client(void)
                MA_LOGE("OCRegisterPersistentStorageHandler error = %d", ret);
                return ret;
        }
-
+#if 0
        ma_set_device_id_seed();
-
+#endif
        /* initialize OC stack and provisioning manager */
        g_mutex_lock(&g_client->iotivity_mutex);
        ret = OCInit(NULL, 0, OC_CLIENT_SERVER);
index be337d4..4813748 100644 (file)
@@ -256,6 +256,7 @@ int ma_print_result_list(const OCProvisionResult_t* rslt_lst, const int rslt_cnt
        return lst_cnt;
 }
 
+#if 0
 int ma_set_device_id_seed(void)
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
@@ -295,6 +296,8 @@ int ma_set_device_id_seed(void)
        wifi_manager_deinitialize(wifi_handle);
        return  ret;
 }
+#endif
+
 #if 0
 static OCProvisionDev_t* _clone_ocprovision_dev(const OCProvisionDev_t* src)
 {
@@ -364,3 +367,39 @@ static OCProvisionDev_t* _clone_ocprovision_dev(const OCProvisionDev_t* src)
        return newDev;
 }
 #endif
+
+int ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid)
+{
+       if(NULL == uuid || NULL == strUuid || NULL != *strUuid)
+       {
+               MA_LOGE("ConvertUuidToStr : Invalid param");
+               return OC_STACK_INVALID_PARAM;
+       }
+
+       size_t uuidIdx = 0;
+       size_t urnIdx = 0;
+       const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1;
+       char* convertedUrn = (char*)calloc(urnBufSize, sizeof(char));
+       if (NULL == convertedUrn) {
+               MA_LOGE("Memory Allocation Failed");
+               goto exit;
+       }
+
+       for(uuidIdx=0, urnIdx=0;  uuidIdx < UUID_LENGTH && urnIdx < urnBufSize; uuidIdx++, urnIdx+=2)
+       {
+               // canonical format for UUID has '8-4-4-4-12'
+               if(uuidIdx==4 || uuidIdx==6 || uuidIdx==8 || uuidIdx==10)
+               {
+                       snprintf(convertedUrn + urnIdx, 2, "%c", '-');
+                       urnIdx++;
+               }
+               snprintf(convertedUrn + urnIdx, 3, "%02x", (uint8_t)(uuid->id[uuidIdx]));
+       }
+       convertedUrn[urnBufSize - 1] = '\0';
+
+       *strUuid = convertedUrn;
+       return OC_STACK_OK;
+
+exit:
+       return OC_STACK_NO_MEMORY;
+}
\ No newline at end of file
index fca0b62..c8de9ef 100644 (file)
@@ -27,7 +27,6 @@
 #include <octypes.h>
 #include <pmtypes.h>
 #include <pmutility.h>
-#include <srmutility.h>
 #include <securevirtualresourcetypes.h>
 
 #include "ma-log.h"
@@ -68,5 +67,6 @@ int ma_set_device_id_seed(void);
 #if 0
 static OCProvisionDev_t* _clone_ocprovision_dev(const OCProvisionDev_t* src);
 #endif
+int ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid);
 
 #endif /* __MA_UTIL_H__ */
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
deleted file mode 100644 (file)
index 7de1a42..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#MESSAGE(" - Include header files")
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include/cjson)
-
-MESSAGE(" - Build executable")
-
-SET(SERVER_BASIC_OPS "ocserverbasicops")
-SET(SERVER_BASIC_OPS_SRCS
-    ocserverbasicops.cpp
-       common.cpp)
-
-SET(SAMPLESERVER_JUSTWORKS "sampleserver_justworks")
-SET(SAMPLESERVER_JUSTWORKS_SRCS
-    sampleserver_justworks.cpp)
-
-SET(PROVISIONING_CLIENT "provisioningclient")
-SET(PROVISIONING_CLIENT_SRCS
-    provisioningclient.c
-    hw_interface.c
-    ss_emul.c)
-
-SET(SUBOWNER_CLIENT "subownerclient")
-SET(SUBOWNER_CLIENT_SRCS
-    subownerclient.c)
-
-#MESSAGE(" - Check cmake packagesion")
-#pkg_check_modules(test_pkgs REQUIRED iotivity uuid libtzplatform-config)
-
-ADD_EXECUTABLE(${SERVER_BASIC_OPS} ${SERVER_BASIC_OPS_SRCS})
-TARGET_LINK_LIBRARIES(${SERVER_BASIC_OPS} ${daemon_pkgs_LIBRARIES})
-INSTALL(TARGETS ${SERVER_BASIC_OPS} DESTINATION ${SBIN_DIR})
-INSTALL(FILES oic_svr_db_server.dat DESTINATION ${NETWORK_FW_DATADIR})
-
-ADD_EXECUTABLE(${SAMPLESERVER_JUSTWORKS} ${SAMPLESERVER_JUSTWORKS_SRCS})
-TARGET_LINK_LIBRARIES(${SAMPLESERVER_JUSTWORKS} ${daemon_pkgs_LIBRARIES} )
-INSTALL(TARGETS ${SAMPLESERVER_JUSTWORKS} DESTINATION ${SBIN_DIR})
-INSTALL(FILES oic_svr_db_server_justworks.dat DESTINATION ${NETWORK_FW_DATADIR})
-
-#INSTALL(FILES oic_amss_db.dat DESTINATION ${NETWORK_FW_DATADIR})
-#NSTALL(FILES oic_svr_db_client_devowner.dat DESTINATION ${NETWORK_FW_DATADIR})
-#INSTALL(FILES oic_svr_db_client_directpairing.dat DESTINATION ${NETWORK_FW_DATADIR})
-#INSTALL(FILES oic_svr_db_client_nondevowner.dat DESTINATION ${NETWORK_FW_DATADIR})
-#INSTALL(FILES oic_svr_db_randompin_with_empty_deviceid.dat DESTINATION ${NETWORK_FW_DATADIR})
-#INSTALL(FILES oic_svr_db_server_justworks_default.dat DESTINATION ${NETWORK_FW_DATADIR})
-#INSTALL(FILES oic_svr_db_server_justworks_protectedDB_plain.dat DESTINATION ${NETWORK_FW_DATADIR})
-#INSTALL(FILES oic_svr_db_server_mfg.dat DESTINATION ${NETWORK_FW_DATADIR})
-#INSTALL(FILES oic_svr_db_server_mvjustworks.dat DESTINATION ${NETWORK_FW_DATADIR})
-#INSTALL(FILES oic_svr_db_server_preconfpin.dat DESTINATION ${NETWORK_FW_DATADIR})
-
-ADD_EXECUTABLE(${PROVISIONING_CLIENT} ${PROVISIONING_CLIENT_SRCS})
-TARGET_LINK_LIBRARIES(${PROVISIONING_CLIENT} ${daemon_pkgs_LIBRARIES} -lmbedtls)
-INSTALL(TARGETS ${PROVISIONING_CLIENT} DESTINATION ${SBIN_DIR})
-INSTALL(FILES oic_svr_db_client.dat DESTINATION ${NETWORK_FW_DATADIR})
-
-
-ADD_EXECUTABLE(${SUBOWNER_CLIENT} ${SUBOWNER_CLIENT_SRCS})
-TARGET_LINK_LIBRARIES(${SUBOWNER_CLIENT} ${daemon_pkgs_LIBRARIES})
-INSTALL(TARGETS ${SUBOWNER_CLIENT} DESTINATION ${SBIN_DIR})
-INSTALL(FILES oic_svr_db_subowner_client.dat DESTINATION ${NETWORK_FW_DATADIR})
diff --git a/test/common.cpp b/test/common.cpp
deleted file mode 100644 (file)
index 6eb7521..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include "common.h"
-
-#include "ocstack.h"
-#include "logger.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#define TAG "sample-common"
-
-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_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";
-    #ifdef WITH_PRESENCE
-    case OC_STACK_PRESENCE_STOPPED:
-        return "OC_STACK_PRESENCE_STOPPED";
-    #endif
-    case OC_STACK_ERROR:
-        return "OC_STACK_ERROR";
-    default:
-        return "UNKNOWN";
-    }
-}
-
-void StripNewLineChar(char* str) {
-    int i = 0;
-    if (str)
-    {
-        while( str[i])
-        {
-            if (str[i] == '\n')
-                str[i] = '\0';
-            i++;
-        }
-    }
-}
-
diff --git a/test/common.h b/test/common.h
deleted file mode 100644 (file)
index fe1ff51..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef OCSAMPLE_COMMON_H_
-#define OCSAMPLE_COMMON_H_
-
-#include "ocstack.h"
-
-/** Security Database persistent store name(dat).*/
-#define OC_SECURITY_DB_DAT_FILE_NAME    "oic_svr_db.dat"
-
-/* Get the result in string format. */
-const char *getResult(OCStackResult result);
-
-/* Removes the new line character from a NULL terminated C string. */
-void StripNewLineChar(char* str);
-
-#endif //OCSAMPLE_COMMON_H_
-
-
diff --git a/test/hw_interface.c b/test/hw_interface.c
deleted file mode 100644 (file)
index 9da5886..0000000
+++ /dev/null
@@ -1,347 +0,0 @@
-/* *****************************************************************\r
- *\r
- * Copyright 2017 Samsung Electronics 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
-#include <stdio.h>\r
-#include <string.h>\r
-\r
-#include "ocstack.h"\r
-#include "oic_malloc.h"\r
-#include "logger.h"\r
-#include "mbedtls/pk_internal.h"\r
-#include "hw_emul/hw_interface.h"\r
-\r
-#include <d2d-log.h>\r
-\r
-#define HWIF_KEY_DEFAULT_ALIAS "HW_KEY_DEFAULT"\r
-#define HWIF_KEY_CONTEXT HWIF_KEY_DEFAULT_ALIAS\r
-#define HWIF_RSA_ALIAS HWIF_KEY_DEFAULT_ALIAS\r
-\r
-// own cert chain cache\r
-uint8_t* g_ownCert = NULL;\r
-size_t g_ownCertLen = 0;\r
-\r
-/********************************************\r
- * RSA alternative functions\r
- */\r
-\r
-static int RsaDecryptAlt(void *ctx, int mode, size_t *olen,\r
-                                    const unsigned char *input, unsigned char *output,\r
-                                    size_t output_max_len )\r
-{\r
-    (void)ctx;\r
-    (void)mode;\r
-    (void)olen;\r
-    (void)input;\r
-    (void)output;\r
-    (void)output_max_len;\r
-\r
-    D2D_LOGI( "In %s", __func__);\r
-    D2D_LOGI( "Out %s", __func__);\r
-    return 0;\r
-}\r
-\r
-static int RsaSignAlt(void *ctx,\r
-                                    int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,\r
-                                    int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,\r
-                                    const unsigned char *hash, unsigned char *sig )\r
-{\r
-    D2D_LOGD("In %s", __func__);\r
-\r
-    if(!ctx || 0 != strncmp((const char*)(ctx), HWIF_RSA_ALIAS, strlen(HWIF_RSA_ALIAS)))\r
-    {\r
-        D2D_LOGE("Invalid paramters, ctx must has same key id");\r
-        D2D_LOGD("Out %s", __func__);\r
-        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;\r
-    }\r
-\r
-    if(mode != MBEDTLS_RSA_PRIVATE)\r
-    {\r
-        D2D_LOGE("Invalid mode requested");\r
-        D2D_LOGD("Out %s", __func__);\r
-        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;\r
-    }\r
-\r
-    // RSA encryption with hw stored private key\r
-    int ret = SSemulRsaSign(ctx, f_rng, p_rng, mode, md_alg, hashlen, hash, sig);\r
-    if(0 != ret )\r
-    {\r
-        D2D_LOGD("Fail to RSA sign [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-    D2D_LOGD("Success to RSA sign");\r
-\r
-exit:\r
-    D2D_LOGD("Out %s", __func__);\r
-    return ret;\r
-}\r
-\r
-static size_t RsaKeyLen( void *ctx )\r
-{\r
-    D2D_LOGD( "In %s", __func__);\r
-\r
-    if(!ctx || 0 != strncmp((const char*)(ctx), HWIF_RSA_ALIAS, strlen(HWIF_RSA_ALIAS)))\r
-    {\r
-        D2D_LOGE("Invalid paramters, ctx must has same key id");\r
-        D2D_LOGD("Out %s", __func__);\r
-        return 0;\r
-    }\r
-\r
-    // Load private key length from HW Secure Storage\r
-    int ret = SSemulGetKeylen(ctx);\r
-    if (0 >= ret)\r
-    {\r
-        D2D_LOGD("Fail to load key length [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-\r
-    D2D_LOGD("key length : %d", ret);\r
-\r
-exit:\r
-    D2D_LOGD("Out %s", __func__);\r
-    return (size_t)ret;\r
-}\r
-\r
-\r
-/********************************************\r
- * ECDSA alternative functions\r
- */\r
-\r
-static int EcdsaSignAlt( void *ctx, mbedtls_md_type_t md_alg,\r
-                   const unsigned char *hash, size_t hash_len,\r
-                   unsigned char *sig, size_t *sig_len,\r
-                   int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )\r
-{\r
-    (void)ctx;\r
-    D2D_LOGD("In %s", __func__);\r
-\r
-    D2D_LOGD("hash_len : %zu md_alg : %d", hash_len, md_alg);\r
-\r
-    // ECDSA signing with hw stored private key\r
-    int ret = SSemulEcdsaSign(ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng);\r
-    if(0 != ret )\r
-    {\r
-        D2D_LOGD("Fail to ECDSA sign [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-    D2D_LOGD("Success to ECDSA sign");\r
-\r
-    D2D_LOGD("# [hash - %zu bytes] #", hash_len);\r
-    D2D_LOGD("%s %s", hash, hash_len);\r
-    D2D_LOGD("# [signature - %zu bytes] #", *sig_len);\r
-    D2D_LOGD("%s %s", sig, *sig_len);\r
-\r
-exit:\r
-    D2D_LOGD( "Out %s", __func__);\r
-    return ret;\r
-}\r
-\r
-\r
-/********************************************\r
- * mbedtls pk setup fucntions\r
- */\r
-\r
-int SetupRSAContext(mbedtls_pk_context* ctx, void* key_context)\r
-{\r
-    D2D_LOGD("In %s", __func__);\r
-    int ret = HWIF_SUCCESS;\r
-\r
-    if(NULL == ctx || NULL == key_context)\r
-    {\r
-        D2D_LOGE("Invalid input parameters.");\r
-        ret = HWIF_ERR_INVALID_PARAM;\r
-        goto exit;\r
-    }\r
-\r
-    ret = mbedtls_pk_setup_rsa_alt( ctx, HWIF_RSA_ALIAS,\r
-                            RsaDecryptAlt, RsaSignAlt, RsaKeyLen);\r
-    if(0 != ret)\r
-    {\r
-        D2D_LOGD("Failed to setup rsa alt [%d]", ret);\r
-        ret = HWIF_ERROR;\r
-        goto exit;\r
-    }\r
-\r
-    D2D_LOGE("Success to setup RSA alt");\r
-\r
-exit:\r
-    D2D_LOGD("Out %s", __func__);\r
-    return ret;\r
-}\r
-\r
-int SetupECDSAContext(mbedtls_pk_context* ctx, void* key_context)\r
-{\r
-    D2D_LOGD("In %s", __func__);\r
-    int ret = HWIF_SUCCESS;\r
-\r
-    if(NULL == ctx || NULL == key_context)\r
-    {\r
-        D2D_LOGE("Invalid input parameters.");\r
-        ret = HWIF_ERR_INVALID_PARAM;\r
-        goto exit;\r
-    }\r
-\r
-    // get mbedtls ecdsa structure\r
-    const mbedtls_pk_info_t *mbedtls_ec_info;\r
-    static mbedtls_pk_info_t ec_info;\r
-\r
-    mbedtls_ec_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY);\r
-    if (NULL == mbedtls_ec_info)\r
-    {\r
-        D2D_LOGE("mbedtls_pk_info_from_type error");\r
-        ret = HWIF_ERROR;\r
-        goto exit;\r
-    }\r
-\r
-    // set hw sign function\r
-    ec_info = *mbedtls_ec_info;\r
-    ec_info.sign_func = EcdsaSignAlt;\r
-    if (0 != mbedtls_pk_setup(ctx, &ec_info))\r
-    {\r
-        D2D_LOGE("mbedtls_pk_setup error");\r
-        ret = HWIF_ERROR;\r
-        goto exit;\r
-    }\r
-\r
-    D2D_LOGE("Success to setup ECDSA alt");\r
-\r
-exit:\r
-    D2D_LOGD("Out %s", __func__);\r
-    return ret;\r
-}\r
-\r
-/********************************************\r
- * HW interface callback functions\r
- */\r
-\r
-void* HWGetKeyContext(const char* service, const char* usage, const char* keytype)\r
-{\r
-    (void)keytype;\r
-\r
-    D2D_LOGD("In %s", __func__);\r
-    if(NULL == service || NULL == usage)\r
-    {\r
-        D2D_LOGE("Invalid input parameters. service and usage should be not NULL.");\r
-        return NULL;\r
-    }\r
-\r
-    // Implementation should return allocated key context depend on hw library\r
-    // key context is related to service, usage and keytype(optional), which is same with alias name.\r
-    // As for now, Iotivity stack is defining following the service and the usage as a default.\r
-    // Refer to pkix_interface.h file\r
-      // #define HWKEY_SVC_IOTIVITY "iotivity"\r
-      // #define HWKEY_USAGE_PRIMARY "primary"\r
-\r
-    D2D_LOGD("Out %s", __func__);\r
-    return (void*)HWIF_KEY_CONTEXT;\r
-}\r
-\r
-int HWFreeKeyContext(void* keyContext)\r
-{\r
-    D2D_LOGD("In %s", __func__);\r
-    if(NULL == keyContext)\r
-    {\r
-        D2D_LOGE("key context value is NULL.");\r
-        return HWIF_ERR_INVALID_PARAM;\r
-    }\r
-\r
-    // Implementation should free key context memory if allocated\r
-    if (g_ownCert)\r
-    {\r
-        OICFree(g_ownCert);\r
-        g_ownCert = NULL;\r
-    }\r
-    g_ownCertLen = 0;\r
-\r
-    D2D_LOGD("Out %s", __func__);\r
-    return HWIF_SUCCESS;\r
-}\r
-\r
-int HWGetOwnCertificateChain(const void* keyContext,\r
-                    uint8_t** cert_chain, size_t* cert_chain_len)\r
-{\r
-    D2D_LOGD("In %s", __func__);\r
-    int ret = HWIF_SUCCESS;\r
-\r
-    if(NULL == keyContext || NULL == cert_chain || NULL == cert_chain_len)\r
-    {\r
-        D2D_LOGE( "Invalid input parameters.");\r
-        ret = HWIF_ERR_INVALID_PARAM;\r
-        goto exit;\r
-    }\r
-\r
-    if (g_ownCert && 0 < g_ownCertLen)\r
-    {\r
-        // Load own certificate from cache\r
-        *cert_chain = g_ownCert;\r
-        *cert_chain_len = g_ownCertLen;\r
-        D2D_LOGE("Load from the cache");\r
-    }\r
-    else\r
-    {\r
-        // Load own certificate from HW Secure Storage\r
-        ret = SSemulLoadOwncert(keyContext, cert_chain, cert_chain_len);\r
-        if (0 != ret)\r
-        {\r
-            D2D_LOGE("Failed to load the own certificate from Secure Storage");\r
-            ret = HWIF_ERROR;\r
-            goto exit;\r
-        }\r
-\r
-        // Save to cache\r
-        g_ownCert = *cert_chain;\r
-        g_ownCertLen = *cert_chain_len;\r
-    }\r
-\r
-    D2D_LOGD("cert chain size : %zu", *cert_chain_len);\r
-\r
-exit:\r
-    D2D_LOGD("Out %s", __func__);\r
-    return ret;\r
-}\r
-\r
-int HWSetupPkContext(mbedtls_pk_context* ctx, void* key_context)\r
-{\r
-    D2D_LOGD("In %s", __func__);\r
-    int ret = HWIF_SUCCESS;\r
-\r
-    if(NULL == ctx || NULL == key_context)\r
-    {\r
-        D2D_LOGE( "Invalid input parameters.");\r
-        ret = HWIF_ERR_INVALID_PARAM;\r
-        goto exit;\r
-    }\r
-\r
-    int keytype = SSemulGetKeytype(key_context);\r
-    if (KEYTYPE_RSA == keytype)\r
-    {\r
-        ret = SetupRSAContext(ctx, key_context);\r
-    }\r
-    else if (KEYTYPE_ECC == keytype)\r
-    {\r
-        ret = SetupECDSAContext(ctx, key_context);\r
-    }\r
-\r
-exit:\r
-    D2D_LOGD("Out %s", __func__);\r
-    return ret;\r
-}\r
-\r
-\r
-\r
diff --git a/test/ocamsservice.cpp b/test/ocamsservice.cpp
deleted file mode 100644 (file)
index 270f1da..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <signal.h>
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#include "ocstack.h"
-#include "experimental/logger.h"
-#include "common.h"
-
-#define TAG  PCF("SRM-AMSS")
-
-int gQuitFlag = 0;
-
-//AMS service database, hold AMS service Identity and
-//the PSK credentials of trusted devices
-static char AMSS_DB_FILE[] = "oic_amss_db.dat";
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-FILE* service_fopen(const char *path, const char *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*/[])
-{
-    struct timespec timeout;
-
-    D2D_LOGE( "OCAMS service is starting...");
-
-    // Initialize Persistent Storage for SVR database
-    OCPersistentStorage ps = { service_fopen, fread, fwrite, fclose, unlink };
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack init error");
-        return 0;
-    }
-
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    // Break from loop with Ctrl-C
-    D2D_LOGE( "Entering ocamsservice main loop...");
-    signal(SIGINT, handleSigInt);
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            return 0;
-        }
-        nanosleep(&timeout, NULL);
-    }
-
-    D2D_LOGE( "Exiting ocamsservice main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack process error");
-    }
-
-    return 0;
-}
diff --git a/test/ocserverbasicops.cpp b/test/ocserverbasicops.cpp
deleted file mode 100644 (file)
index 445de1f..0000000
+++ /dev/null
@@ -1,408 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-#endif
-#include <signal.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#include "ocstack.h"
-#include "logger.h"
-#include "ocpayload.h"
-#include "ocserverbasicops.h"
-#include "common.h"
-
-#include <d2d-log.h>
-
-//<-- For Tizen
-#include <tzplatform_config.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-int gQuitFlag = 0;
-
-static LEDResource LED;
-// This variable determines instance number of the LED resource.
-// Used by POST method to create a new instance of LED resource.
-static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE  2
-static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
-
-char *gResourceUri= (char *)"/a/led";
-
-//Secure Virtual Resource database for Iotivity Server
-//It contains Server's Identity and the PSK credentials
-//of other devices which the server trusts
-static char CRED_FILE[] = "oic_svr_db_server.dat";
-
-OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if(!payload)
-    {
-        D2D_LOGE( PCF("Failed to allocate Payload"));
-        return nullptr;
-    }
-
-    OCRepPayloadSetUri(payload, uri);
-    OCRepPayloadSetPropBool(payload, "state", state);
-    OCRepPayloadSetPropInt(payload, "power", power);
-
-    return payload;
-}
-
-//This function takes the request as an input and returns the response
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest)
-{
-    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        D2D_LOGE( PCF("Incoming payload not a representation"));
-        return nullptr;
-    }
-
-    OCRepPayload* input = reinterpret_cast<OCRepPayload*>(ehRequest->payload);
-
-    LEDResource *currLEDResource = &LED;
-
-    if (ehRequest->resource == gLedInstance[0].handle)
-    {
-        currLEDResource = &gLedInstance[0];
-        gResourceUri = (char *) "/a/led/0";
-    }
-    else if (ehRequest->resource == gLedInstance[1].handle)
-    {
-        currLEDResource = &gLedInstance[1];
-        gResourceUri = (char *) "/a/led/1";
-    }
-
-    if(OC_REST_PUT == ehRequest->method
-        || OC_REST_POST == ehRequest->method)
-    {
-        // Get pointer to query
-        int64_t pow;
-        if(OCRepPayloadGetPropInt(input, "power", &pow))
-        {
-            currLEDResource->power = pow;
-        }
-
-        bool state;
-        if(OCRepPayloadGetPropBool(input, "state", &state))
-        {
-            currLEDResource->state = state;
-        }
-    }
-
-    return getPayload(gResourceUri, currLEDResource->power, currLEDResource->state);
-}
-
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-
-    if(getResp)
-    {
-        *payload = getResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *putResp = constructResponse(ehRequest);
-
-    if(putResp)
-    {
-        *payload = putResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, OCRepPayload **payload)
-{
-    OCRepPayload *respPLPost_led = nullptr;
-    OCEntityHandlerResult ehResult = OC_EH_OK;
-
-    /*
-     * The entity handler determines how to process a POST request.
-     * Per the REST paradigm, POST can also be used to update representation of existing
-     * resource or create a new resource.
-     * In the sample below, if the POST is for /a/led then a new instance of the LED
-     * resource is created with default representation (if representation is included in
-     * POST payload it can be used as initial values) as long as the instance is
-     * lesser than max new instance count. Once max instance count is reached, POST on
-     * /a/led updated the representation of /a/led.
-     */
-
-    if (ehRequest->resource == LED.handle)
-    {
-        if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
-        {
-            // Create new LED instance
-            char newLedUri[15] = "/a/led/";
-            size_t newLedUriLength = strlen(newLedUri);
-            snprintf((newLedUri + newLedUriLength), (sizeof(newLedUri) - newLedUriLength), "%d", gCurrLedInstance);
-
-            respPLPost_led = OCRepPayloadCreate();
-            OCRepPayloadSetUri(respPLPost_led, gResourceUri);
-            OCRepPayloadSetPropString(respPLPost_led, "createduri", newLedUri);
-
-            if (0 == createLEDResource (newLedUri, &gLedInstance[gCurrLedInstance], false, 0))
-            {
-                D2D_LOGE ( "Created new LED instance");
-                gLedInstance[gCurrLedInstance].state = 0;
-                gLedInstance[gCurrLedInstance].power = 0;
-                gCurrLedInstance++;
-                strncpy ((char *)response->resourceUri, newLedUri, MAX_URI_LENGTH);
-                ehResult = OC_EH_RESOURCE_CREATED;
-            }
-        }
-        else
-        {
-            respPLPost_led = constructResponse(ehRequest);
-        }
-    }
-    else
-    {
-        for (int i = 0; i < SAMPLE_MAX_NUM_POST_INSTANCE; i++)
-        {
-            if (ehRequest->resource == gLedInstance[i].handle)
-            {
-                if (i == 0)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                    break;
-                }
-                else if (i == 1)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                }
-            }
-        }
-    }
-
-    if (respPLPost_led != NULL)
-    {
-        *payload = respPLPost_led;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        D2D_LOGD ( "Payload was NULL");
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* /*callbackParam*/)
-{
-    D2D_LOGD ( "Inside entity handler - flags: 0x%x", flag);
-
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-    OCEntityHandlerResponse response = { 0, 0, OC_EH_ERROR, 0, 0, { },{ 0 }, false };
-    // Validate pointer
-    if (!entityHandlerRequest)
-    {
-        D2D_LOGE ( "Invalid request pointer");
-        return OC_EH_ERROR;
-    }
-
-    OCRepPayload* payload = nullptr;
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        D2D_LOGE ( "Flag includes OC_REQUEST_FLAG");
-        if (entityHandlerRequest)
-        {
-            if (OC_REST_GET == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_GET from client");
-                ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_PUT == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_PUT from client");
-                ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_POST == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_POST from client");
-                ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
-            }
-            else
-            {
-                D2D_LOGD ( "Received unsupported method %d from client",
-                        entityHandlerRequest->method);
-                ehResult = OC_EH_ERROR;
-            }
-
-            if (ehResult == OC_EH_OK && ehResult != OC_EH_FORBIDDEN)
-            {
-                // Format the response.  Note this requires some info about the request
-                response.requestHandle = entityHandlerRequest->requestHandle;
-                response.ehResult = ehResult;
-                response.payload = reinterpret_cast<OCPayload*>(payload);
-                response.numSendVendorSpecificHeaderOptions = 0;
-                memset(response.sendVendorSpecificHeaderOptions, 0, sizeof response.sendVendorSpecificHeaderOptions);
-                memset(response.resourceUri, 0, sizeof(response.resourceUri));
-                // Indicate that response is NOT in a persistent buffer
-                response.persistentBufferFlag = 0;
-
-                // Send the response
-                if (OCDoResponse(&response) != OC_STACK_OK)
-                {
-                    D2D_LOGE( "Error sending response");
-                    ehResult = OC_EH_ERROR;
-                }
-            }
-        }
-    }
-
-    OCRepPayloadDestroy(payload);
-    return ehResult;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-FILE* server_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
-    {
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), CRED_FILE);
-    }
-    else
-    {
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), path);
-    }
-
-        return fopen(data_dir, mode);
-}
-
-int main(int /*argc*/, char* /*argv*/[])
-{
-    struct timespec timeout;
-
-    D2D_LOGE( "OCServer is starting...");
-
-    // Initialize Persistent Storage for SVR database
-    OCPersistentStorage ps = { server_fopen, fread, fwrite, fclose, unlink };
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack init error");
-        return 0;
-    }
-
-    /*
-     * Declare and create the example resource: LED
-     */
-    createLEDResource(gResourceUri, &LED, false, 0);
-
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    // Break from loop with Ctrl-C
-    D2D_LOGE( "Entering ocserver main loop...");
-    signal(SIGINT, handleSigInt);
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            return 0;
-        }
-        nanosleep(&timeout, NULL);
-    }
-
-    D2D_LOGE( "Exiting ocserver main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack process error");
-    }
-
-    return 0;
-}
-
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower)
-{
-    if (!uri)
-    {
-        D2D_LOGE( "Resource URI cannot be NULL");
-        return -1;
-    }
-
-    ledResource->state = resourceState;
-    ledResource->power= resourcePower;
-    OCStackResult res = OCCreateResource(&(ledResource->handle),
-            "core.led",
-            OC_RSRVD_INTERFACE_DEFAULT,
-            uri,
-            OCEntityHandlerCb,
-            NULL,
-            OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
-    D2D_LOGD( "Created LED resource with result: %s", getResult(res));
-
-    return 0;
-}
-
diff --git a/test/ocserverbasicops.h b/test/ocserverbasicops.h
deleted file mode 100644 (file)
index 52a595c..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef OCSERVER_BASICOPS_H_
-#define OCSERVER_BASICOPS_H_
-
-#include "ocstack.h"
-
-//-----------------------------------------------------------------------------
-// Defines
-//-----------------------------------------------------------------------------
-#define TAG "ocserverbasicops"
-
-//-----------------------------------------------------------------------------
-// Typedefs
-//-----------------------------------------------------------------------------
-
-/* Structure to represent a LED resource */
-typedef struct LEDRESOURCE{
-    OCResourceHandle handle;
-    bool state;
-    int64_t power;
-} LEDResource;
-
-//-----------------------------------------------------------------------------
-// Function prototype
-//-----------------------------------------------------------------------------
-
-/* Function that creates a new LED resource by calling the
- * OCCreateResource() method.
- */
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int64_t resourcePower);
-
-/* This method converts the payload to JSON format */
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest);
-
-/* Following methods process the PUT, GET, POST
- * requests
- */
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-                                        OCEntityHandlerResponse *response,
-                                        OCRepPayload **payload);
-
-//-----------------------------------------------------------------------------
-// Callback functions
-//-----------------------------------------------------------------------------
-
-/* Entity Handler callback functions */
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest);
-
-#endif
diff --git a/test/oic_amss_db.dat b/test/oic_amss_db.dat
deleted file mode 100644 (file)
index 32938ed..0000000
Binary files a/test/oic_amss_db.dat and /dev/null differ
diff --git a/test/oic_amss_db.json b/test/oic_amss_db.json
deleted file mode 100644 (file)
index b28d4eb..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist2": [\r
-            {\r
-                "aceid": 1,\r
-                "subject": { "conntype": "anon-clear" },\r
-                "resources": [\r
-                    { "href": "/oic/res" },\r
-                    { "href": "/oic/d" },\r
-                    { "href": "/oic/p" },\r
-                    { "href": "/oic/sec/doxm" }\r
-                ],\r
-                "permission": 2\r
-            },\r
-            {\r
-                "aceid": 2,\r
-                "subject": { "conntype": "auth-crypt" },\r
-                "resources": [\r
-                    { "href": "/oic/res" },\r
-                    { "href": "/oic/d" },\r
-                    { "href": "/oic/p" },\r
-                    { "href": "/oic/sec/doxm" }\r
-                ],\r
-                "permission": 2\r
-            }\r
-        ],\r
-        "rowneruuid" : "31393139-3139-3139-3139-313931393139"\r
-    },\r
-    "pstat": {\r
-        "dos": {"s": 3, "p": false},\r
-        "isop": true,\r
-        "rowneruuid": "31393139-3139-3139-3139-313931393139",\r
-        "cm": 0,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4\r
-        },\r
-    "doxm": {\r
-        "oxms": [0],\r
-        "oxmsel": 0,\r
-        "sct": 9,\r
-        "owned": true,\r
-        "deviceuuid": "31393139-3139-3139-3139-313931393139",\r
-        "devowneruuid": "61646D69-6E44-6576-6963-655555494430",\r
-        "rowneruuid": "31393139-3139-3139-3139-313931393139"\r
-    },\r
-    "cred": {\r
-        "creds": [\r
-            {\r
-                "credid": 1,\r
-                "subjectuuid": "31313131-3131-3131-3131-313131313131",\r
-                "credtype": 1,\r
-                "privatedata": {\r
-                    "data": "BBBBBBBBBBBBBBBB",\r
-                    "encoding": "oic.sec.encoding.raw"\r
-                }\r
-            }\r
-        ],\r
-        "rowneruuid": "32323232-3232-3232-3232-323232323232"\r
-    }\r
-}
\ No newline at end of file
diff --git a/test/oic_svr_db_client.dat b/test/oic_svr_db_client.dat
deleted file mode 100644 (file)
index c47fe43..0000000
Binary files a/test/oic_svr_db_client.dat and /dev/null differ
diff --git a/test/oic_svr_db_client.json b/test/oic_svr_db_client.json
deleted file mode 100644 (file)
index 1da8e2d..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist": {\r
-            "aces": [\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/res",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.res"],\r
-                            "if": ["oic.if.ll"]\r
-                        },{\r
-                            "href": "/oic/d",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.d"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },{\r
-                            "href": "/oic/p",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.p"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/doxm",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.doxm"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/pstat",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pstat"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                }\r
-            ]\r
-        },\r
-        "rowneruuid" : "61646D69-6E44-6576-6963-655575696430"\r
-    },\r
-    "pstat": {\r
-        "isop": true,\r
-        "cm": 0,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4,\r
-        "deviceuuid": "61646D69-6E44-6576-6963-655575696430",\r
-        "rowneruuid": "61646D69-6E44-6576-6963-655575696430"\r
-    },\r
-    "doxm": {\r
-        "oxms": [0],\r
-        "oxmsel": 0,\r
-        "sct": 1,\r
-        "owned": true,\r
-        "deviceuuid": "61646D69-6E44-6576-6963-655575696430",\r
-        "devowneruuid": "61646D69-6E44-6576-6963-655575696430",\r
-        "rowneruuid": "61646D69-6E44-6576-6963-655575696430"\r
-    }\r
-}\r
diff --git a/test/oic_svr_db_client_devowner.dat b/test/oic_svr_db_client_devowner.dat
deleted file mode 100644 (file)
index 58eb07a..0000000
Binary files a/test/oic_svr_db_client_devowner.dat and /dev/null differ
diff --git a/test/oic_svr_db_client_devowner.json b/test/oic_svr_db_client_devowner.json
deleted file mode 100644 (file)
index 286428b..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist2": [\r
-            {\r
-                "aceid": 1,\r
-                "subject": { "conntype": "anon-clear" },\r
-                "resources": [\r
-                    { "href": "/oic/res" },\r
-                    { "href": "/oic/d" },\r
-                    { "href": "/oic/p" },\r
-                    { "href": "/oic/sec/doxm" }\r
-                ],\r
-                "permission": 2\r
-            },\r
-            {\r
-                "aceid": 2,\r
-                "subject": { "conntype": "auth-crypt" },\r
-                "resources": [\r
-                    { "href": "/oic/res" },\r
-                    { "href": "/oic/d" },\r
-                    { "href": "/oic/p" },\r
-                    { "href": "/oic/sec/doxm" }\r
-                ],\r
-                "permission": 2\r
-            }\r
-        ],\r
-        "rowneruuid" : "32323232-3232-3232-3232-323232323232"\r
-    },\r
-    "pstat": {\r
-        "dos": {"s": 3, "p": false},\r
-        "isop": true,\r
-        "rowneruuid": "32323232-3232-3232-3232-323232323232",\r
-        "cm": 0,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4\r
-        },\r
-    "doxm": {\r
-        "oxms": [0],\r
-        "oxmsel": 0,\r
-        "sct": 9,\r
-        "owned": true,\r
-        "deviceuuid": "32323232-3232-3232-3232-323232323232",\r
-        "devowneruuid": "32323232-3232-3232-3232-323232323232",\r
-        "rowneruuid": "32323232-3232-3232-3232-323232323232"\r
-    },\r
-    "cred": {\r
-        "creds": [\r
-            {\r
-                "credid": 1,\r
-                "subjectuuid": "31313131-3131-3131-3131-313131313131",\r
-                "credtype": 1,\r
-                "privatedata": {\r
-                    "data": "AAAAAAAAAAAAAAAA",\r
-                    "encoding": "oic.sec.encoding.raw"\r
-                }\r
-            }\r
-        ],\r
-        "rowneruuid": "32323232-3232-3232-3232-323232323232"\r
-    }\r
-}\r
diff --git a/test/oic_svr_db_client_directpairing.dat b/test/oic_svr_db_client_directpairing.dat
deleted file mode 100644 (file)
index a037092..0000000
Binary files a/test/oic_svr_db_client_directpairing.dat and /dev/null differ
diff --git a/test/oic_svr_db_client_directpairing.json b/test/oic_svr_db_client_directpairing.json
deleted file mode 100644 (file)
index dfb5e14..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-{
-    "acl": {
-        "aclist2": [
-            {
-                "aceid": 1,
-                "subject": { "conntype": "anon-clear" },
-                "resources": [
-                    { "href": "/oic/res" },
-                    { "href": "/oic/d" },
-                    { "href": "/oic/p"}
-                ],
-                "permission": 2
-            },
-            {
-                "aceid": 2,
-                "subject": { "conntype": "auth-crypt" },
-                "resources": [
-                    { "href": "/oic/res" },
-                    { "href": "/oic/d" },
-                    { "href": "/oic/p"}
-                ],
-                "permission": 2
-            },
-            {
-                "aceid": 3,
-                "subject": { "conntype": "anon-clear" },
-                "resources": [
-                    { "href": "/oic/sec/doxm" }
-                ],
-                "permission": 14
-            },
-            {
-                "aceid": 4,
-                "subject": { "conntype": "auth-crypt" },
-                "resources": [
-                    { "href": "/oic/sec/doxm" },
-                    { "href": "/oic/sec/roles" }
-                ],
-                "permission": 14
-            }
-        ],
-        "rowneruuid" : "64697265-6374-7061-6972-696e67446576"
-    },
-    "pstat": {
-        "dos": {"s": 1, "p": false},
-        "isop": false,
-        "deviceuuid": "64697265-6374-7061-6972-696e67446576",
-        "rowneruuid": "64697265-6374-7061-6972-696e67446576",
-        "cm": 2,
-        "tm": 0,
-        "om": 4,
-        "sm": 4
-        },
-    "doxm": {
-        "oxms": [0],
-        "oxmsel": 0,
-        "sct": 9,
-        "owned": false,
-        "deviceuuid": "64697265-6374-7061-6972-696e67446576",
-        "devowneruuid": "",
-        "rowneruuid": "64697265-6374-7061-6972-696e67446576"
-    }
-}
diff --git a/test/oic_svr_db_client_nondevowner.dat b/test/oic_svr_db_client_nondevowner.dat
deleted file mode 100644 (file)
index 6606754..0000000
Binary files a/test/oic_svr_db_client_nondevowner.dat and /dev/null differ
diff --git a/test/oic_svr_db_client_nondevowner.json b/test/oic_svr_db_client_nondevowner.json
deleted file mode 100644 (file)
index 54aecee..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist2": [\r
-            {\r
-                "aceid": 1,\r
-                "subject": { "conntype": "anon-clear" },\r
-                "resources": [\r
-                    { "href": "/oic/res" },\r
-                    { "href": "/oic/d" },\r
-                    { "href": "/oic/p" },\r
-                    { "href": "/oic/sec/doxm" }\r
-                ],\r
-                "permission": 2\r
-            },\r
-            {\r
-                "aceid": 2,\r
-                "subject": { "conntype": "auth-crypt" },\r
-                "resources": [\r
-                    { "href": "/oic/res" },\r
-                    { "href": "/oic/d" },\r
-                    { "href": "/oic/p" },\r
-                    { "href": "/oic/sec/doxm" }\r
-                ],\r
-                "permission": 2\r
-            }\r
-        ],\r
-        "rowneruuid" : "31393139-3139-3139-3139-313931393139"\r
-    },\r
-    "pstat": {\r
-        "dos": {"s": 3, "p": false},\r
-        "isop": true,\r
-        "rowneruuid": "31393139-3139-3139-3139-313931393139",\r
-        "cm": 0,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4\r
-        },\r
-    "doxm": {\r
-        "oxms": [0],\r
-        "oxmsel": 0,\r
-        "sct": 9,\r
-        "owned": true,\r
-        "deviceuuid": "31393139-3139-3139-3139-313931393139",\r
-        "devowneruuid": "31393139-3139-3139-3139-313931393139",\r
-        "rowneruuid": "31393139-3139-3139-3139-313931393139"\r
-    },\r
-    "cred": {\r
-        "creds": [\r
-            {\r
-                "credid": 1,\r
-                "subjectuuid": "31313131-3131-3131-3131-313131313131",\r
-                "credtype": 1,\r
-                "privatedata": {\r
-                    "data": "BBBBBBBBBBBBBBBB",\r
-                    "encoding": "oic.sec.encoding.raw"\r
-                }\r
-            }\r
-        ],\r
-        "rowneruuid": "31393139-3139-3139-3139-313931393139"\r
-    }\r
-}\r
diff --git a/test/oic_svr_db_randompin_with_empty_deviceid.dat b/test/oic_svr_db_randompin_with_empty_deviceid.dat
deleted file mode 100644 (file)
index 0951580..0000000
Binary files a/test/oic_svr_db_randompin_with_empty_deviceid.dat and /dev/null differ
diff --git a/test/oic_svr_db_randompin_with_empty_deviceid.json b/test/oic_svr_db_randompin_with_empty_deviceid.json
deleted file mode 100644 (file)
index 244ee83..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-{
-    "acl": {
-        "aclist": {
-            "aces": [
-                {
-                    "subjectuuid": "*",
-                    "resources": [
-                        {
-                            "href": "/oic/res",
-                            "rel": "",
-                            "rt": ["oic.wk.res"],
-                            "if": ["oic.if.ll"]
-                        },{
-                            "href": "/oic/d",
-                            "rel": "",
-                            "rt": ["oic.wk.d"],
-                            "if": ["oic.if.baseline", "oic.if.r"]
-                        },{
-                            "href": "/oic/p",
-                            "rel": "",
-                            "rt": ["oic.wk.p"],
-                            "if": ["oic.if.baseline", "oic.if.r"]
-                        }
-                    ],
-                    "permission": 2
-                },
-                {
-                    "subjectuuid": "*",
-                    "resources": [
-                        {
-                            "href": "/oic/sec/doxm",
-                            "rel": "",
-                            "rt": ["oic.r.doxm"],
-                            "if": ["oic.if.baseline"]
-                        },
-                        {
-                            "href": "/oic/sec/pstat",
-                            "rel": "",
-                            "rt": ["oic.r.pstat"],
-                            "if": ["oic.if.baseline"]
-                        },
-                        {
-                            "href": "/oic/sec/cred",
-                            "rel": "",
-                            "rt": ["oic.r.cred"],
-                            "if": ["oic.if.baseline"]
-                        }
-                    ],
-                    "permission": 6
-                }
-            ]
-        },
-        "rowneruuid" : ""
-    },
-    "pstat": {
-        "isop": false,
-        "deviceuuid": "",
-        "rowneruuid": "",
-        "cm": 2,
-        "tm": 0,
-        "om": 4,
-        "sm": 4
-        },
-    "doxm": {
-        "oxms": [0, 1],
-        "oxmsel": 0,
-        "sct": 1,
-        "owned": false,
-        "deviceuuid": "",
-        "devowneruuid": "",
-        "rowneruuid": ""
-    }
-}
diff --git a/test/oic_svr_db_server.dat b/test/oic_svr_db_server.dat
deleted file mode 100644 (file)
index eabca5e..0000000
Binary files a/test/oic_svr_db_server.dat and /dev/null differ
diff --git a/test/oic_svr_db_server.json b/test/oic_svr_db_server.json
deleted file mode 100644 (file)
index 3a8ea10..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist2": [\r
-            {\r
-                "aceid": 1,\r
-                "subject": { "conntype": "anon-clear" },\r
-                "resources": [\r
-                    { "href": "/oic/res" },\r
-                    { "href": "/oic/d" },\r
-                    { "href": "/oic/p" },\r
-                    { "href": "/oic/sec/doxm" }\r
-                ],\r
-                "permission": 2\r
-            },\r
-            {\r
-                "aceid": 2,\r
-                "subject": { "conntype": "auth-crypt" },\r
-                "resources": [\r
-                    { "href": "/oic/res" },\r
-                    { "href": "/oic/d" },\r
-                    { "href": "/oic/p" },\r
-                    { "href": "/oic/sec/doxm" }\r
-                ],\r
-                "permission": 2\r
-            },\r
-            {\r
-                "aceid": 3,\r
-                "subject": { "uuid": "32323232-3232-3232-3232-323232323232" },\r
-                "resources": [{ "wc": "*" }],\r
-                "permission": 7\r
-            },\r
-            {\r
-                "aceid": 4,\r
-                "subject": { "uuid": "31393139-3139-3139-3139-313931393139" },\r
-                "resources": [{ "href": "/a/led" }],\r
-                "permission": 7\r
-            },\r
-            {\r
-                "aceid": 5,\r
-                "subject": { "uuid": "37373737-3737-3737-3737-373737373737" },\r
-                "resources": [{ "href": "/a/led" }],\r
-                "permission": 6\r
-            }\r
-        ],\r
-        "rowneruuid" : "31313131-3131-3131-3131-313131313131"\r
-    },\r
-    "pstat": {\r
-        "dos": {"s": 3, "p": false},\r
-        "isop": true,\r
-        "rowneruuid": "31313131-3131-3131-3131-313131313131",\r
-        "cm": 0,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4\r
-        },\r
-    "doxm": {\r
-        "oxms": [0],\r
-        "oxmsel": 0,\r
-        "sct": 9,\r
-        "owned": true,\r
-        "deviceuuid": "31313131-3131-3131-3131-313131313131",\r
-        "devowneruuid": "32323232-3232-3232-3232-323232323232",\r
-        "rowneruuid": "31313131-3131-3131-3131-313131313131"\r
-    },\r
-    "cred": {\r
-        "creds": [\r
-            {\r
-                "credid": 1,\r
-                "subjectuuid": "32323232-3232-3232-3232-323232323232",\r
-                "credtype": 1,\r
-                "period": "20150630T060000/20990920T220000",\r
-                "privatedata": {\r
-                    "data": "AAAAAAAAAAAAAAAA",\r
-                    "encoding": "oic.sec.encoding.raw"\r
-                }\r
-            },\r
-            {\r
-                "credid": 2,\r
-                "subjectuuid": "31393139-3139-3139-3139-313931393139",\r
-                "credtype": 1,\r
-                "period": "20150630T060000/20990920T220000",\r
-                "privatedata": {\r
-                    "data": "BBBBBBBBBBBBBBBB",\r
-                    "encoding": "oic.sec.encoding.raw"\r
-                }\r
-            }\r
-        ],\r
-        "rowneruuid": "32323232-3232-3232-3232-323232323232"\r
-    }\r
-}\r
diff --git a/test/oic_svr_db_server_justworks.dat b/test/oic_svr_db_server_justworks.dat
deleted file mode 100644 (file)
index d4e46c2..0000000
Binary files a/test/oic_svr_db_server_justworks.dat and /dev/null differ
diff --git a/test/oic_svr_db_server_justworks.json b/test/oic_svr_db_server_justworks.json
deleted file mode 100644 (file)
index d86b341..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-{
-    "cred":{
-        "creds": [
-            {
-                "credid": 1,
-                "subjectuuid": "*",
-                "credtype": 16,
-                "privatedata": {
-                    "encoding": "oic.sec.encoding.raw",
-                    "data": "12341234"
-                }
-            }
-        ],
-        "rowneruuid": "00000000-0000-0000-0000-000000000000"
-    },
-    "acl": {
-        "aclist": {
-            "aces": [
-                {
-                    "subjectuuid": "*",
-                    "resources": [
-                        {
-                            "href": "/oic/res",
-                            "rel": "",
-                            "rt": ["oic.wk.res"],
-                            "if": ["oic.if.ll"]
-                        },{
-                            "href": "/oic/d",
-                            "rel": "",
-                            "rt": ["oic.wk.d"],
-                            "if": ["oic.if.baseline", "oic.if.r"]
-                        },{
-                            "href": "/oic/p",
-                            "rel": "",
-                            "rt": ["oic.wk.p"],
-                            "if": ["oic.if.baseline", "oic.if.r"]
-                        }
-                    ],
-                    "permission": 2
-                },
-                {
-                    "subjectuuid": "*",
-                    "resources": [
-                        {
-                            "href": "/oic/sec/doxm",
-                            "rel": "",
-                            "rt": ["oic.r.doxm"],
-                            "if": ["oic.if.baseline"]
-                        },
-                        {
-                            "href": "/oic/sec/pstat",
-                            "rel": "",
-                            "rt": ["oic.r.pstat"],
-                            "if": ["oic.if.baseline"]
-                        },
-                        {
-                            "href": "/oic/sec/cred",
-                            "rel": "",
-                            "rt": ["oic.r.cred"],
-                            "if": ["oic.if.baseline"]
-                        }
-                    ],
-                    "permission": 6
-                }
-            ]
-        },
-        "rowneruuid": "00000000-0000-0000-0000-000000000000"
-    },
-    "pstat": {
-        "isop": false,
-        "deviceuuid": "00000000-0000-0000-0000-000000000000",
-        "rowneruuid": "00000000-0000-0000-0000-000000000000",
-        "cm": 2,
-        "tm": 0,
-        "om": 4,
-        "sm": 4
-     },
-    "doxm": {
-        "oxms": [0, 65280],
-        "oxmsel": 65280,
-        "sct": 17,
-        "owned": false,
-        "x.org.iotivity.mom": 1,
-        "deviceuuid": "00000000-0000-0000-0000-000000000000",
-        "devowneruuid": "",
-        "rowneruuid": "00000000-0000-0000-0000-000000000000"
-    }
-}
diff --git a/test/oic_svr_db_server_justworks_default.dat b/test/oic_svr_db_server_justworks_default.dat
deleted file mode 100644 (file)
index e02d465..0000000
Binary files a/test/oic_svr_db_server_justworks_default.dat and /dev/null differ
diff --git a/test/oic_svr_db_server_justworks_protectedDB_plain.dat b/test/oic_svr_db_server_justworks_protectedDB_plain.dat
deleted file mode 100644 (file)
index e02d465..0000000
Binary files a/test/oic_svr_db_server_justworks_protectedDB_plain.dat and /dev/null differ
diff --git a/test/oic_svr_db_server_mfg.dat b/test/oic_svr_db_server_mfg.dat
deleted file mode 100644 (file)
index 7ba8c26..0000000
Binary files a/test/oic_svr_db_server_mfg.dat and /dev/null differ
diff --git a/test/oic_svr_db_server_mvjustworks.dat b/test/oic_svr_db_server_mvjustworks.dat
deleted file mode 100644 (file)
index 2391448..0000000
Binary files a/test/oic_svr_db_server_mvjustworks.dat and /dev/null differ
diff --git a/test/oic_svr_db_server_mvjustworks.json b/test/oic_svr_db_server_mvjustworks.json
deleted file mode 100644 (file)
index dd811fb..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist": {\r
-            "aces": [\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/res",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.res"],\r
-                            "if": ["oic.if.ll"]\r
-                        },{\r
-                            "href": "/oic/d",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.d"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },{\r
-                            "href": "/oic/p",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.p"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/doxm",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.doxm"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/pstat",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pstat"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/cred",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.cred"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 6\r
-                }\r
-            ]\r
-        },\r
-        "rowneruuid" : "6D766A75-7374-776F-726B-735575696430"\r
-    },\r
-    "pstat": {\r
-        "isop": false,\r
-        "deviceuuid": "6D766A75-7374-776F-726B-735575696430",\r
-        "rowneruuid": "6D766A75-7374-776F-726B-735575696430",\r
-        "cm": 2,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4\r
-        },\r
-    "doxm": {\r
-        "oxms": [0, 65281],\r
-        "oxmsel": 0,\r
-        "sct": 1,\r
-        "owned": false,\r
-        "deviceuuid": "6D766A75-7374-776F-726B-735575696430",\r
-        "devowneruuid": "",\r
-        "rowneruuid": "6D766A75-7374-776F-726B-735575696430"\r
-    }\r
-}\r
diff --git a/test/oic_svr_db_server_preconfpin.dat b/test/oic_svr_db_server_preconfpin.dat
deleted file mode 100644 (file)
index 472ef8e..0000000
Binary files a/test/oic_svr_db_server_preconfpin.dat and /dev/null differ
diff --git a/test/oic_svr_db_server_preconfpin.json b/test/oic_svr_db_server_preconfpin.json
deleted file mode 100644 (file)
index 89b960c..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist": {\r
-            "aces": [\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/res",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.res"],\r
-                            "if": ["oic.if.ll"]\r
-                        },{\r
-                            "href": "/oic/d",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.d"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },{\r
-                            "href": "/oic/p",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.p"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/doxm",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.doxm"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/pstat",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pstat"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/cred",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.cred"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 6\r
-                }\r
-            ]\r
-        },\r
-        "rowneruuid" : "50726563-6F6E-6669-6775-72656450494E"\r
-    },\r
-    "pstat": {\r
-        "isop": false,\r
-        "deviceuuid": "50726563-6F6E-6669-6775-72656450494E",\r
-        "rowneruuid": "50726563-6F6E-6669-6775-72656450494E",\r
-        "cm": 2,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4\r
-        },\r
-    "doxm": {\r
-        "oxms": [0, 65280],\r
-        "oxmsel": 0,\r
-        "sct": 1,\r
-        "owned": false,\r
-        "deviceuuid": "50726563-6F6E-6669-6775-72656450494E",\r
-        "devowneruuid": "",\r
-        "rowneruuid": "50726563-6F6E-6669-6775-72656450494E"\r
-    }\r
-}\r
diff --git a/test/oic_svr_db_server_randompin.dat b/test/oic_svr_db_server_randompin.dat
deleted file mode 100644 (file)
index e2a16d7..0000000
Binary files a/test/oic_svr_db_server_randompin.dat and /dev/null differ
diff --git a/test/oic_svr_db_server_randompin.json b/test/oic_svr_db_server_randompin.json
deleted file mode 100644 (file)
index 90863b1..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist": {\r
-            "aces": [\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/res",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.res"],\r
-                            "if": ["oic.if.ll"]\r
-                        },{\r
-                            "href": "/oic/d",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.d"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },{\r
-                            "href": "/oic/p",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.p"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/doxm",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.doxm"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/pstat",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pstat"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/cred",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.cred"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 6\r
-                }\r
-            ]\r
-        },\r
-        "rowneruuid" : "72616E64-5069-6E44-6576-557569643030"\r
-    },\r
-    "pstat": {\r
-        "isop": false,\r
-        "deviceuuid": "72616E64-5069-6E44-6576-557569643030",\r
-        "rowneruuid": "72616E64-5069-6E44-6576-557569643030",\r
-        "cm": 2,\r
-        "tm": 0,\r
-        "om": 4,\r
-        "sm": 4\r
-        },\r
-    "doxm": {\r
-        "oxms": [0, 1],\r
-        "oxmsel": 0,\r
-        "sct": 1,\r
-        "owned": false,\r
-        "deviceuuid": "72616E64-5069-6E44-6576-557569643030",\r
-        "devowneruuid": "",\r
-        "rowneruuid": "72616E64-5069-6E44-6576-557569643030"\r
-    }\r
-}\r
diff --git a/test/oic_svr_db_subowner_client.dat b/test/oic_svr_db_subowner_client.dat
deleted file mode 100644 (file)
index ae130bc..0000000
Binary files a/test/oic_svr_db_subowner_client.dat and /dev/null differ
diff --git a/test/oic_svr_db_subowner_client.json b/test/oic_svr_db_subowner_client.json
deleted file mode 100644 (file)
index eba0cdd..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-{\r
-    "acl": {\r
-        "aclist": {\r
-            "aces": [\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/res",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.res"],\r
-                            "if": ["oic.if.ll"]\r
-                        },{\r
-                            "href": "/oic/d",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.d"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        },{\r
-                            "href": "/oic/p",\r
-                            "rel": "",\r
-                            "rt": ["oic.wk.p"],\r
-                            "if": ["oic.if.baseline", "oic.if.r"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/doxm",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.doxm"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/pstat",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pstat"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                },\r
-                {\r
-                    "subjectuuid": "*",\r
-                    "resources": [\r
-                        {\r
-                            "href": "/oic/sec/pconf",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.pconf"],\r
-                            "if": ["oic.if.baseline"]\r
-                        },\r
-                        {\r
-                            "href": "/oic/sec/dpairing",\r
-                            "rel": "",\r
-                            "rt": ["oic.r.dpairing"],\r
-                            "if": ["oic.if.baseline"]\r
-                        }\r
-                    ],\r
-                    "permission": 2\r
-                }\r
-            ]\r
-        },\r
-        "rowneruuid" : "5375624F-776E-6572-436C-69656E743030"\r
-    },\r
-    "pstat": {\r
-        "isop": true,\r
-        "cm": 0,\r
-        "tm": 0,\r
-        "om": 3,\r
-        "sm": 3,\r
-        "deviceuuid": "5375624F-776E-6572-436C-69656E743030",\r
-        "rowneruuid": "5375624F-776E-6572-436C-69656E743030"\r
-    },\r
-    "doxm": {\r
-        "oxms": [0],\r
-        "oxmsel": 0,\r
-        "sct": 1,\r
-        "owned": true,\r
-        "deviceuuid": "5375624F-776E-6572-436C-69656E743030",\r
-        "devowneruuid": "5375624F-776E-6572-436C-69656E743030",\r
-        "rowneruuid": "5375624F-776E-6572-436C-69656E743030"\r
-    }\r
-}\r
diff --git a/test/provisioningclient.c b/test/provisioningclient.c
deleted file mode 100644 (file)
index 0425adc..0000000
+++ /dev/null
@@ -1,2708 +0,0 @@
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *****************************************************************/
-
-#include "iotivity_config.h"
-
-#include <stdio.h>
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "utlist.h"
-#include "logger.h"
-#include "oic_malloc.h"
-#include "oic_string.h"
-#include "ocprovisioningmanager.h"
-#include "oxmjustworks.h"
-#include "oxmrandompin.h"
-#include "securevirtualresourcetypes.h"
-#include "security/srmutility.h"
-#include "pmtypes.h"
-#include "oxmverifycommon.h"
-#include "security/pkix_interface.h"
-#include "hw_emul/hw_interface.h"
-#include "mbedtls/x509_crt.h"
-#include "casecurityinterface.h"
-
-#include <d2d-log.h>
-
-//<-- For Tizen
-#include <tzplatform_config.h>
-#define MAX_FILE_PATH_LEN 1024
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif //__cplusplus
-
-// declaration(s) for provisioning client using C-level provisioning API
-// user input definition for main loop on provisioning client
-#define _10_DISCOV_ALL_DEVS_            10
-#define _11_DISCOV_UNOWN_DEVS_          11
-#define _12_DISCOV_OWN_DEVS_            12
-#ifdef MULTIPLE_OWNER
-#define _13_MOT_DISCOV_DEV_             13
-#endif //MULTIPLE_OWNER
-#define _20_REGIST_DEVS_                20
-#define _30_PROVIS_PAIR_DEVS_           30
-#define _31_PROVIS_CRED_                31
-#define _32_PROVIS_ACL_                 32
-#define _33_PROVIS_DP_                  33
-#define _34_CHECK_LINK_STATUS_          34
-#define _35_SAVE_ACL_                   35
-#define _40_UNLINK_PAIR_DEVS_           40
-#define _50_REMOVE_SELEC_DEV_           50
-#define _51_REMOVE_DEV_WITH_UUID_       51
-#define _52_RESET_SELEC_DEV_            52
-#define _53_RESET_SVR_DB_               53
-#define _60_GET_CRED_                   60
-#define _61_GET_ACL_                    61
-#ifdef MULTIPLE_OWNER
-#define _70_MOT_CHANGE_MOM_             70
-#define _71_MOT_PROV_PRECONF_PIN_       71
-#define _72_MOT_OXM_SEL_                72
-#define _73_MOT_REMOVE_SUBOWNER_        73
-#define _74_MOT_REMOVE_ALL_SUBOWNER_        74
-#endif //MULTIPLE_OWNER
-#define _80_SELECT_PROTOCOL_            80
-#define _81_SELECT_VERIF_METHOD_        81
-#define _82_SECURE_STORAGE_HW_EMULATION_    82
-#define _99_EXIT_PRVN_CLT_              99
-
-#define ACL_RESRC_MAX_NUM   16
-#define ACL_RESRC_ARRAY_SIZE   3 //This value is used only for sample (not OCF spec)
-#define ACL_RESRC_MAX_LEN   128
-#define ACL_PEMISN_CNT      5
-#define DISCOVERY_TIMEOUT   10  // 10 sec
-#define CALLBACK_TIMEOUT    60  // 1 min
-#define TAG "provisioningclient"
-
-static const char* ACL_PEMISN[5] = {"CREATE", "READ", "WRITE", "DELETE", "NOTIFY"};
-static const char* SVR_DB_FILE_NAME = "/opt/usr/data/network/oic_svr_db_client.dat";
-        // '_' for separaing from the same constant variable in |srmresourcestrings.c|
-static const char* PRVN_DB_FILE_NAME = "/opt/usr/data/network/oic_prvn_mng.db";
-static const OicSecPrm_t  SUPPORTED_PRMS[1] =
-{
-    PRM_PRE_CONFIGURED,
-};
-
-// |g_ctx| means provision manager application context and
-// the following, includes |un/own_list|, could be variables, which |g_ctx| has,
-// for accessing all function(s) for these, they are declared on global domain
-static const char* g_ctx = "Provision Manager Client Application Context";
-static char* g_svr_fname;
-static char* g_prvn_fname;
-static OCProvisionDev_t* g_own_list;
-static OCProvisionDev_t* g_unown_list;
-static int g_own_cnt;
-static int g_unown_cnt;
-#ifdef MULTIPLE_OWNER
-static OCProvisionDev_t* g_mot_enable_list;
-static int g_mot_enable_cnt;
-#endif //MULTIPLE_OWNER
-
-static bool g_doneCB;
-#ifdef __WITH_TLS__
-static int secure_protocol = 1;
-static void setDevProtocol(OCProvisionDev_t* dev_lst);
-#endif
-// function declaration(s) for calling them before implementing
-static OicSecAcl_t* createAcl(const int);
-static OicSecAcl_t* createSimpleAcl(const OicUuid_t uuid);
-static OicSecPdAcl_t* createPdAcl(const int);
-static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
-static int printDevList(const OCProvisionDev_t*);
-static size_t printUuidList(const OCUuidList_t*);
-static int printResultList(const OCProvisionResult_t*, const int);
-static void printUuid(const OicUuid_t*);
-static FILE* fopen_prvnMng(const char*, const char*);
-static int waitCallbackRet(void);
-static int selectTwoDiffNum(int*, int*, const int, const char*);
-
-// callback function(s) for provisioning client using C-level provisioning API
-static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Provision Pairwise SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Provision Pairwise FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Provision Credential FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Provision ACL FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "getCredCB SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "getCredCB FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "getAclCB SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "getAclCB FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Provision Direct-Pairing SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Provision Direct-Pairing FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Unlink Devices SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Unlink Devices FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Remove Device SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Remove Device FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Sync Device SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Sync Device FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-#ifdef MULTIPLE_OWNER
-static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "POST 'doxm'  FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void deleteDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "DELETE 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "DELETE 'doxm'  FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-#endif //MULTIPLE_OWNER
-
-static void inputPinCB(char* pin, size_t len)
-{
-    if(!pin || OXM_RANDOM_PIN_MIN_SIZE > len)
-    {
-        D2D_LOGE( "inputPinCB invalid parameters");
-        return;
-    }
-
-    printf("   > INPUT PIN: ");
-    for(int ret=0; 1!=ret; )
-    {
-        ret = scanf("%32s", pin);
-        for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                    // '0x20<=code' is character region
-    }
-}
-
-// function(s) for provisioning client using C-level provisioning API
-static int initProvisionClient(void)
-{
-    // initialize persistent storage for SVR DB
-    static OCPersistentStorage pstStr =
-    {
-        .open = fopen_prvnMng,
-        .read = fread,
-        .write = fwrite,
-        .close = fclose,
-        .unlink = unlink
-    };
-    if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr))
-    {
-        D2D_LOGE( "OCRegisterPersistentStorageHandler error");
-        return -1;
-    }
-
-    // initialize OC stack and provisioning manager
-    if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
-    {
-        D2D_LOGE( "OCStack init error");
-        return -1;
-    }
-
-    if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
-    {
-        printf("************************************************************\n");
-        printf("************Provisioning DB file already exists.************\n");
-        printf("************************************************************\n");
-    }
-    else
-    {
-        printf("*************************************************************\n");
-        printf("************No provisioning DB file, creating new************\n");
-        printf("*************************************************************\n");
-    }
-
-    if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
-    {
-        D2D_LOGE( "OC_PM init error");
-        return -1;
-    }
-
-    SetInputPinCB(inputPinCB);
-
-    return 0;
-}
-
-static int discoverAllDevices(void)
-{
-    // delete un/owned device lists before updating them
-    if(g_own_list)
-    {
-        OCDeleteDiscoveredDevices(g_own_list);
-        g_own_list = NULL;
-    }
-    if(g_unown_list)
-    {
-        OCDeleteDiscoveredDevices(g_unown_list);
-        g_unown_list = NULL;
-    }
-
-    // call |OCGetDevInfoFromNetwork| API actually
-    printf("   Discovering All Un/Owned Devices on Network..\n");
-    if(OC_STACK_OK != OCGetDevInfoFromNetwork(DISCOVERY_TIMEOUT, &g_own_list, &g_unown_list))
-    {
-        D2D_LOGE( "OCGetDevInfoFromNetwork API error");
-        return -1;
-    }
-
-    // display the discovered un/owned lists
-    printf("   > Discovered Owned Devices\n");
-    g_own_cnt = printDevList(g_own_list);
-    printf("   > Discovered Unowned Devices\n");
-    g_unown_cnt = printDevList(g_unown_list);
-#ifdef __WITH_TLS__
-    setDevProtocol(g_own_list);
-    setDevProtocol(g_unown_list);
-#endif
-    return 0;
-}
-
-
-static int discoverUnownedDevices(void)
-{
-    // delete unowned device list before updating it
-    if(g_unown_list)
-    {
-        OCDeleteDiscoveredDevices(g_unown_list);
-        g_unown_list = NULL;
-    }
-
-    // call |OCDiscoverUnownedDevices| API actually
-    printf("   Discovering Only Unowned Devices on Network..\n");
-    if(OC_STACK_OK != OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unown_list))
-    {
-        D2D_LOGE( "OCDiscoverUnownedDevices API error");
-        return -1;
-    }
-
-    // display the discovered unowned list
-    printf("   > Discovered Unowned Devices\n");
-    g_unown_cnt = printDevList(g_unown_list);
-#ifdef __WITH_TLS__
-    setDevProtocol(g_unown_list);
-#endif
-    return 0;
-}
-
-static int discoverOwnedDevices(void)
-{
-    // delete owned device list before updating it
-    if(g_own_list)
-    {
-        OCDeleteDiscoveredDevices(g_own_list);
-        g_own_list = NULL;
-    }
-
-    // call |OCDiscoverOwnedDevices| API actually
-    printf("   Discovering Only Owned Devices on Network..\n");
-    if(OC_STACK_OK != OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_own_list))
-    {
-        D2D_LOGE( "OCDiscoverOwnedDevices API error");
-        return -1;
-    }
-
-    // display the discovered owned list
-    printf("   > Discovered Owned Devices\n");
-    g_own_cnt = printDevList(g_own_list);
-#ifdef __WITH_TLS__
-    setDevProtocol(g_own_list);
-#endif
-    return 0;
-}
-
-#ifdef MULTIPLE_OWNER
-static int discoverMOTEnabledDevices(void)
-{
-    // delete owned device list before updating it
-    if(g_mot_enable_list)
-    {
-        OCDeleteDiscoveredDevices(g_mot_enable_list);
-        g_mot_enable_list = NULL;
-    }
-
-    // call |OCDiscoverOwnedDevices| API actually
-    printf("   Discovering Multiple Ownership Transfer Enabled Devices on Network..\n");
-    if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_mot_enable_list))
-    {
-        D2D_LOGE( "OCDiscoverMultipleOwnerEnalbedDevices API error");
-        return -1;
-    }
-
-    // display the discovered owned list
-    printf("   > Discovered Multiple Ownership Transfer Enabled Devices\n");
-    g_mot_enable_cnt = printDevList(g_mot_enable_list);
-
-    return 0;
-}
-#endif //MULTIPLE_OWNER
-
-static int registerDevices(void)
-{
-    // check |unown_list| for registering devices
-    if(!g_unown_list || 0>=g_unown_cnt)
-    {
-        printf("   > Unowned Device List, to Register Devices, is Empty\n");
-        printf("   > Please Discover Unowned Devices first, with [10|11] Menu\n");
-        return 0;  // normal case
-    }
-
-    // call |OCDoOwnershipTransfer| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    printf("   Registering All Discovered Unowned Devices..\n");
-    OCStackResult rst = OCDoOwnershipTransfer((void*) g_ctx, g_unown_list, ownershipTransferCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCDoOwnershipTransfer API error: %d", rst);
-        return -1;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        return -1;
-    }
-
-    // display the registered result
-    printf("   > Registered Discovered Unowned Devices\n");
-    printf("   > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
-
-    return 0;
-}
-
-static int provisionPairwise(void)
-{
-    // check |own_list| for provisioning pairwise devices
-    if(!g_own_list || 2>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Provision the Pairwise, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select two devices for provisioning pairwise devices
-    int dev_num[2] = {0};
-    if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking Devices"))
-    {
-        D2D_LOGE( "selectTwoDiffNum error return");
-        return -1;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-
-    // create ACL(s) for each selected device
-    OicSecAcl_t* acl[2] = {0};
-    for(int i=0; 2>i; ++i)
-    {
-        acl[i] = createAcl(dev_num[i]);
-        if(!acl[i])
-        {
-            D2D_LOGE( "createAcl error return");
-            goto PVPWS_ERROR;
-        }
-    }
-
-    // call |OCProvisionPairwiseDevices| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    printf("   Provisioning Selected Pairwise Devices..\n");
-    OCStackResult rst =
-            OCProvisionPairwiseDevices((void*) g_ctx,
-                    SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
-                    getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]), acl[0],
-                    getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]), acl[1],
-                    provisionPairwiseCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCProvisionPairwiseDevices API error: %d", rst);
-        goto PVPWS_ERROR;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        goto PVPWS_ERROR;
-    }
-    OCDeleteACLList(acl[0]);
-    OCDeleteACLList(acl[1]);
-
-    // display the pairwise-provisioned result
-    printf("   > Provisioned Selected Pairwise Devices\n");
-    printf("   > Please Check Device's Status for the Linked Result, with [33] Menu\n");
-
-    return 0;
-
-PVPWS_ERROR:
-    OCDeleteACLList(acl[0]);
-    OCDeleteACLList(acl[1]);
-    return -1;
-}
-
-static int provisionCred(void)
-{
-    // check |own_list| for provisioning pairwise credentials
-    if(!g_own_list || 2>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Provision Credentials, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select two devices for provisioning pairwise credentials
-    int dev_num[2] = {0};
-    if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking CRED(s)"))
-    {
-        D2D_LOGE( "selectTwoDiffNum error return");
-        return -1;
-    }
-
-    printf("   Select PSK length..\n");
-    printf("   1 - 128bit(Default)\n");
-    printf("   2 - 256bit\n");
-    int sizeOption = 0;
-
-    for(int ret=0; 1!=ret; )
-    {
-         ret = scanf("%d",&sizeOption);
-         for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                    // '0x20<=code' is character region
-    }
-    size_t size = 0;
-
-    switch(sizeOption)
-    {
-        case 1:
-        {
-            size = OWNER_PSK_LENGTH_128;
-            break;
-        }
-        case 2:
-        {
-            size = OWNER_PSK_LENGTH_256;
-            break;
-        }
-        default:
-        {
-            size = OWNER_PSK_LENGTH_128;
-            break;
-        }
-    }
-
-
-    // call |OCProvisionCredentials| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    printf("   Provisioning Selected Pairwise Credentials..\n");
-    OCStackResult rst =
-            OCProvisionCredentials((void*) g_ctx,
-                    SYMMETRIC_PAIR_WISE_KEY, size,
-                    getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
-                    getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
-                    provisionCredCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCProvisionCredentials API error: %d", rst);
-        return -1;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        return -1;
-    }
-
-    // display the CRED-provisioned result
-    printf("   > Provisioned Selected Pairwise Crendentials\n");
-    printf("   > Please Check Device's Status for the Linked Result, with [34] Menu\n");
-
-    return 0;
-}
-
-static int provisionAcl(void)
-{
-    // check |own_list| for provisioning access control list
-    if(!g_own_list || 1>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Provision ACL, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for provisioning access control list
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for Provisioning ACL: ");
-        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 && g_own_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    // create ACL for selected device
-    OicSecAcl_t* acl = NULL;
-    acl = createAcl(dev_num);
-    if(!acl)
-    {
-        D2D_LOGE( "createAcl error return");
-        goto PVACL_ERROR;
-    }
-
-    // call |OCProvisionACL| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    printf("   Provisioning Selected ACL..\n");
-    OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
-    if(!dev)
-    {
-        D2D_LOGE( "provisionAcl: device instance empty");
-        goto PVACL_ERROR;
-    }
-    OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCProvisionACL API error: %d", rst);
-        goto PVACL_ERROR;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        goto PVACL_ERROR;
-    }
-    OCDeleteACLList(acl);  // after here |acl| points nothing
-
-    // display the ACL-provisioned result
-    printf("   > Provisioned Selected ACL\n");
-
-    return 0;
-
-PVACL_ERROR:
-    OCDeleteACLList(acl);  // after here |acl| points nothing
-    return -1;
-}
-
-static int provisionDirectPairing(void)
-{
-    // check |own_list| for provisioning direct-pairing
-    if(!g_own_list || 1>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Provision ACL, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for provisioning direct-pairing
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for Provisioning Direct-Pairing: ");
-        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 && g_own_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    // create Direct-Pairing Configuration(PIN, PDACL) for selected device
-    // TODO: default acl -> input from user !
-    OicSecPconf_t pconf;
-    memset(&pconf, 0, sizeof(OicSecPconf_t));
-
-    // set enable dp
-    pconf.edp = true;
-
-    // set default supported PRM types
-    pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
-    pconf.prm = (OicSecPrm_t *)OICCalloc(pconf.prmLen, sizeof(OicSecPrm_t));
-    if(pconf.prm)
-    {
-        for (size_t i=0; i<pconf.prmLen; i++)
-        {
-            pconf.prm[i] = SUPPORTED_PRMS[i];
-        }
-    }
-    else
-    {
-        D2D_LOGE( "create prm error return");
-        goto PVDP_ERROR;
-    }
-
-    // set default pin
-    const char DP_DEFAULT_PIN[] = "00000000";
-    memcpy(pconf.pin.val, DP_DEFAULT_PIN, DP_PIN_LENGTH);
-
-    // set default pdacl
-    pconf.pdacls = createPdAcl(dev_num);
-    if(!pconf.pdacls)
-    {
-        D2D_LOGE( "createPdAcl error return");
-        goto PVDP_ERROR;
-    }
-
-    // call |OCProvisionDirectPairing| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    printf("   Atempt Direct-Pairing Provisioning (PIN : [%s])..\n", (char*)pconf.pin.val);
-    OCStackResult rst = OCProvisionDirectPairing((void*) g_ctx,
-                                       getDevInst((const OCProvisionDev_t*) g_own_list, dev_num),
-                                       &pconf, provisionDPCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCProvisionDirectPairing API error: %d", rst);
-        if (OC_STACK_UNAUTHORIZED_REQ == rst)
-        {
-            D2D_LOGE( "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
-        }
-        goto PVDP_ERROR;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        goto PVDP_ERROR;
-    }
-    OCDeletePdAclList(pconf.pdacls);
-
-    // display the PCONF-provisioned result
-    printf("   > SUCCESS to provision Direct-Pairing !!\n");
-
-    return 0;
-
-PVDP_ERROR:
-    OCDeletePdAclList(pconf.pdacls);  // after here |acl| points nothing
-    return -1;
-}
-
-static int checkLinkedStatus(void)
-{
-    // check |own_list| for checking selected link status on PRVN DB
-    if(!g_own_list || 1>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for checking selected link status on PRVN DB
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for Checking Linked Status on PRVN DB: ");
-        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 && g_own_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    // call |OCGetLinkedStatus| API actually
-    printf("   Checking Selected Link Status on PRVN DB..\n");
-    OCUuidList_t* dvid_lst = NULL;
-    size_t dvid_cnt = 0;
-    OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, dev_num);
-    if(!dev || !dev->doxm)
-    {
-        D2D_LOGE( "checkLinkedStatus: device instance empty");
-        goto CKLST_ERROR;
-    }
-
-    if(OC_STACK_OK !=
-            OCGetLinkedStatus(
-                    &dev->doxm->deviceID,
-                    &dvid_lst, &dvid_cnt))  // allow empty list
-    {
-        D2D_LOGE( "OCGetLinkedStatus API error");
-        goto CKLST_ERROR;
-    }
-
-    // display the linked status result
-    printf("   > Checked Selected Link Status on PRVN DB\n");
-    if(!dvid_lst || !dvid_cnt)  // |size_t| is unsigned
-    {
-        printf("     Linked Device List is Empty..\n");
-        return 0;  // normal case
-    }
-    if(dvid_cnt != printUuidList((const OCUuidList_t*) dvid_lst))
-    {
-        D2D_LOGE( "printUuidList error return");
-        goto CKLST_ERROR;
-    }
-    OCDeleteUuidList(dvid_lst);
-
-    return 0;
-
-CKLST_ERROR:
-    OCDeleteUuidList(dvid_lst);
-    return -1;
-}
-
-static int saveAcl(void)
-{
-    // create ACL to save into local SVR DB
-    OicSecAcl_t* acl = NULL;
-    OicUuid_t uuid =   {.id={0}};
-    char strUuid[64] = {0};
-
-    printf("[1] Use a test UUID [11111111-2222-3333-4444-555555555555]\n");
-    printf("[2] Use a user input\n");
-    int sel_num = 0;
-    for( ; ; )
-    {
-        printf("   > Select Number, for Subject UUID of new ACE: ");
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &sel_num);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        if(1 == sel_num)
-        {
-            OICStrcpy(strUuid, sizeof(strUuid), "11111111-2222-3333-4444-555555555555");
-            break;
-        }
-        else if(2 == sel_num)
-        {
-            printf("   > Input the UUID : ");
-            for(int ret=0; 1!=ret; )
-            {
-                ret = scanf("%64s", strUuid);
-                for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-            }
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-
-    printf("Selected Subject UUID : %s\n", strUuid);
-    OCStackResult rst = ConvertStrToUuid(strUuid, &uuid);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "ConvertStrToUuid API error: %d", rst);
-        goto SVACL_ERROR;
-    }
-
-    acl = createSimpleAcl(uuid);
-    if(!acl)
-    {
-        D2D_LOGE( "createAcl error return");
-        goto SVACL_ERROR;
-    }
-
-    // call |OCSaveACL| API actually
-    rst = OCSaveACL(acl);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCSaveACL API error: %d", rst);
-        goto SVACL_ERROR;
-    }
-    OCDeleteACLList(acl);  // after here |acl| points nothing
-
-    // display the ACL-provisioned result
-    printf("   > Saved Selected ACL\n");
-
-    return 0;
-
-SVACL_ERROR:
-    OCDeleteACLList(acl);  // after here |acl| points nothing
-    return -1;
-}
-
-static int getCred(void)
-{
-    // check |own_list| for checking selected link status on PRVN DB
-    if(!g_own_list || 1>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for checking selected link status on PRVN DB
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for Checking Linked Status on PRVN DB: ");
-        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 && g_own_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    // call |getDevInst| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
-    if(!dev)
-    {
-        D2D_LOGE( "getDevInst: device instance empty");
-        goto PVACL_ERROR;
-    }
-    OCStackResult rst = OCGetCredResource((void*) g_ctx, dev, getCredCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCGetCred API error: %d", rst);
-        goto PVACL_ERROR;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCGetCredResource callback error");
-        goto PVACL_ERROR;
-    }
-
-    // display the result of get credential
-    printf("   > Get Cred SUCCEEDED\n");
-
-    return 0;
-
-PVACL_ERROR:
-    return -1;
-}
-
-static int getAcl(void)
-{
-    // check |own_list| for checking selected link status on PRVN DB
-    if(!g_own_list || 1>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for checking selected link status on PRVN DB
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for Checking Linked Status on PRVN DB: ");
-        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 && g_own_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    // call |getDevInst| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
-    if(!dev)
-    {
-        D2D_LOGE( "getDevInst: device instance empty");
-        goto PVACL_ERROR;
-    }
-    OCStackResult rst = OCGetACLResource((void*) g_ctx, dev, getAclCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCGetACLResource API error: %d", rst);
-
-        goto PVACL_ERROR;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCGetACLResource callback error");
-        goto PVACL_ERROR;
-    }
-
-    // display the result of get credential
-    printf("   > Get ACL SUCCEEDED\n");
-
-    return 0;
-
-PVACL_ERROR:
-    return -1;
-}
-
-static int unlinkPairwise(void)
-{
-    // check |own_list| for unlinking pairwise devices
-    if(!g_own_list || 2>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Unlink the Pairwise, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select two devices for unlinking pairwise devices
-    int dev_num[2] = {0};
-    if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Unlinking Devices"))
-    {
-        D2D_LOGE( "selectTwoDiffNum error return");
-        return -1;
-    }
-
-    // call |OCUnlinkDevices| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    printf("   Unlinking Selected Pairwise Devices..\n");
-    OCStackResult rst =
-            OCUnlinkDevices((void*) g_ctx,
-                    getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
-                    getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
-                    unlinkDevicesCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCUnlinkDevices API error: %d", rst);
-        return -1;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        return -1;
-    }
-
-    // display the pairwise-unlinked result
-    printf("   > Unlinked Selected Pairwise Devices\n");
-    printf("   > Please Check Device's Status for the Unlinked Result, with [33] Menu\n");
-
-    return 0;
-}
-
-static int removeDevice(void)
-{
-    // check |own_list| for removing device
-    if(!g_own_list || 1>g_own_cnt)
-    {
-        printf("   > Owned Device List, to Remove Device, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for removing it
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for Removing Device: ");
-        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 && g_own_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    // call |OCRemoveDevice| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    printf("   Removing Selected Owned Device..\n");
-    OCStackResult rst =
-            OCRemoveDevice((void*) g_ctx, DISCOVERY_TIMEOUT,
-                    getDevInst((const OCProvisionDev_t*) g_own_list, dev_num), removeDeviceCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCRemoveDevice API error: %d", rst);
-        return -1;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        return -1;
-    }
-
-    // display the removed result
-    printf("   > Removed Selected Owned Device\n");
-    printf("   > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
-
-    return 0;
-}
-
-static int removeDeviceWithUuid(void)
-{
-    char strUuid[64] = {0};
-    OicUuid_t revUuid;
-    printf("Input the UUID : ");
-    for(int ret=0; 1!=ret; )
-    {
-        ret = scanf("%63s", strUuid);
-        for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                    // '0x20<=code' is character region
-    }
-    OCStackResult rst = ConvertStrToUuid(strUuid, &revUuid);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "ConvertStrToUuid API error: %d", rst);
-        return -1;
-    }
-
-    g_doneCB = false;
-    rst = OCRemoveDeviceWithUuid("RemoveDeviceWithUUID", DISCOVERY_TIMEOUT, &revUuid, removeDeviceCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCRemoveDeviceWithUuid API error: %d", rst);
-        return -1;
-    }
-
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCRemoveDeviceWithUuid callback error");
-        return -1;
-    }
-
-    // display the removed result
-    printf("   > Removed %s Device\n", strUuid);
-    printf("   > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
-
-    return 0;
-}
-
-OCStackResult displayNumCB(void * ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN])
-{
-    D2D_LOGE( "IN displayMutualVerifNumCB");
-    OC_UNUSED(ctx);
-    if (NULL != mutualVerifNum)
-    {
-        D2D_LOGE( "############ mutualVerifNum ############");
-        //D2D_LOGD( mutualVerifNum, MUTUAL_VERIF_NUM_LEN);
-        D2D_LOGE( "############ mutualVerifNum ############");
-        D2D_LOGE( "OUT displayMutualVerifNumCB");
-    }
-    else
-    {
-        D2D_LOGE( "############ Confirm on the Server side ############");
-    }
-    return OC_STACK_OK;
-}
-
-OCStackResult confirmNumCB(void * ctx)
-{
-    OC_UNUSED(ctx);
-    for (;;)
-    {
-        int userConfirm;
-
-        printf("   > Press 1 if the mutual verification numbers are the same\n");
-        printf("   > Press 0 if the mutual verification numbers are not the same\n");
-
-        for (int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &userConfirm);
-            for (; 0x20<=getchar(); );  // for removing overflow garbage
-                                        // '0x20<=code' is character region
-        }
-        if (1 == userConfirm)
-        {
-            break;
-        }
-        else if (0 == userConfirm)
-        {
-            return OC_STACK_USER_DENIED_REQ;
-        }
-        printf("   Entered Wrong Number. Please Enter Again\n");
-    }
-    return OC_STACK_OK;
-}
-
-OCStackResult notifyInputStateCB(void * ctx)
-{
-    OC_UNUSED(ctx);
-
-    D2D_LOGE( "IN notifyInputStateCB");
-    D2D_LOGE( "User input Callback in progress");
-    D2D_LOGE( "OUT notifyInputStateCB");
-
-    return OC_STACK_OK;
-}
-
-#ifdef MULTIPLE_OWNER
-static int changeMultipleOwnershipTrnasferMode(void)
-{
-    // check |own_list| for removing device
-    if(!g_own_list || 1>g_own_cnt)
-    {
-        printf("   > Owned Device List is Empty\n");
-        printf("   > Please Discover the Owned Devices, with [12] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for removing it
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for MOT Device: ");
-        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 && g_own_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    int mom = 0;
-    for( ; ; )
-    {
-        printf("   0. Disable Multuple Ownership Transfer\n");
-        printf("   1. Enable Multuple Ownership Transfer\n");
-        printf("   2. (Not Supported yet) Timely Enable Multuple Ownership Transfer\n");
-        printf("   > Enter Mode of Multuple Ownership Transfer : ");
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &mom);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        if(0 <= dev_num && OIC_NUMBER_OF_MOM_TYPE > dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* motDev = getDevInst(g_own_list, dev_num);
-    if(OC_STACK_OK == OCChangeMOTMode(NULL, motDev, (OicSecMomType_t)dev_num, updateDoxmForMOTCB))
-    {
-        g_doneCB = false;
-    }
-    else
-    {
-        D2D_LOGE( "OCChangeMOTMode API error");
-        return -1;
-    }
-
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "waitCallbackRet callback error");
-        return -1;
-    }
-
-    return 0;
-}
-
-static int selectMultipleOwnershipTrnasferMethod(void)
-{
-    // check |own_list| for removing device
-    if(!g_mot_enable_list || 1>g_mot_enable_cnt)
-    {
-        printf("   > Multiple Ownership Transfer Enabled Device List is Empty\n");
-        printf("   > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for removing it
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for MOT Device: ");
-        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 && g_mot_enable_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    int oxm = 0;
-    for( ; ; )
-    {
-        printf("   %d. (Not Supported)\n", OIC_JUST_WORKS);
-        printf("   %d. Random PIN OxM\n", OIC_RANDOM_DEVICE_PIN);
-        printf("   %d. (Not Supported)\n", OIC_MANUFACTURER_CERTIFICATE);
-        printf("   %d. (Not Supported)\n", OIC_DECENTRALIZED_PUBLIC_KEY);
-        printf("   %d. Pre-Configured PIN OxM\n", OIC_PRECONFIG_PIN);
-        printf("   > Enter Number of  OxM for Multiple Ownership Transfer : ");
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &oxm);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        if(OIC_PRECONFIG_PIN == oxm || OIC_RANDOM_DEVICE_PIN == oxm)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
-    if(OC_STACK_OK ==  OCSelectMOTMethod(NULL, motDev, (OicSecOxm_t)oxm, updateDoxmForMOTCB))
-    {
-        g_doneCB = false;
-    }
-    else
-    {
-        D2D_LOGE( "OCSelectMOTMethod API error");
-        return -1;
-    }
-
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "waitCallbackRet callback error");
-        return -1;
-    }
-
-    return 0;
-}
-
-static int provisionPreconfigPIN()
-{
-    // check |own_list| for removing device
-    if(!g_mot_enable_list || 1>g_mot_enable_cnt)
-    {
-        printf("   > Multiple Ownership Transfer Enabled Device List is Empty\n");
-        printf("   > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select device for removing it
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for MOT Device: ");
-        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 && g_mot_enable_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    char preconfigPin[9] = {0};
-    printf("   > Input the PreconfigPin (e.g. 12341234) : ");
-    for(int ret=0; 1!=ret; )
-    {
-        ret = scanf("%8s", preconfigPin);
-        for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                    // '0x20<=code' is character region
-    }
-
-    OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
-    if(OC_STACK_OK == OCProvisionPreconfigPin(NULL, motDev, preconfigPin, strlen(preconfigPin), provisionCredCB))
-    {
-        g_doneCB = false;
-    }
-    else
-    {
-        D2D_LOGE( "OCProvisionPreconfigPin API error");
-        return -1;
-    }
-
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "waitCallbackRet callback error");
-        return -1;
-    }
-
-    return 0;
-}
-
-static int removeSubOwner(void)
-{
-    // check |g_mot_enable_list| for removing sub-owner
-    if (!g_mot_enable_list || 1 > g_mot_enable_cnt)
-    {
-        printf("   > Multiple Ownership Transfer Enabled Device List is Empty\n");
-        printf("   > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select resource server for removing sub-owner
-    int dev_num = 0;
-    for ( ; ; )
-    {
-        printf("   > Enter Device Number to remove sub-owner: ");
-        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 && g_mot_enable_cnt >= dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
-    if (motDev && motDev->doxm && motDev->doxm->subOwners)
-    {
-        OicSecSubOwner_t* subOwner = motDev->doxm->subOwners;
-        int so_cnt = 0;
-        while(subOwner)
-        {
-            printf("     [%zu] ", ++so_cnt);
-            printUuid(&subOwner->uuid);
-            printf("\n");
-            subOwner = subOwner->next;
-        }
-
-        int so_num = 0;
-        for ( ; ; )
-        {
-            printf("   > Enter SubOwner Number to be removed : ");
-            for (int ret = 0; 1 != ret; )
-            {
-                ret = scanf("%d", &so_num);
-                for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                            // '0x20<=code' is character region
-            }
-            if (0 < so_num && so_cnt >= so_num)
-            {
-                int target_num = 0;
-                subOwner = motDev->doxm->subOwners;
-                while (subOwner)
-                {
-                    if(so_num == ++target_num)
-                    {
-                        if (OC_STACK_OK != OCRemoveSubOwner(NULL, motDev, &subOwner->uuid, deleteDoxmForMOTCB))
-                        {
-                            return -1;
-                        }
-
-                        g_doneCB = false;
-
-                        if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-                        {
-                            D2D_LOGE( "waitCallbackRet callback error");
-                            return -1;
-                        }
-                        return 0;
-                    }
-                    subOwner = subOwner->next;
-                }
-                break;
-            }
-            printf("     Entered Wrong Number. Please Enter Again\n");
-        }
-    }
-    else
-    {
-        printf("     SubOwner list is empty.\n");
-    }
-
-    return 0;
-}
-
-static int removeAllSubOwner(void)
-{
-    // check |g_mot_enable_list| for removing sub-owner
-    if (!g_mot_enable_list || 1 > g_mot_enable_cnt)
-    {
-        printf("   > Multiple Ownership Transfer Enabled Device List is Empty\n");
-        printf("   > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
-        return 0;  // normal case
-    }
-
-    // select resource server for removing sub-owner
-    int dev_num = 0;
-    for ( ; ; )
-    {
-        printf("   > Enter Device Number to remove sub-owner: ");
-        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 && g_mot_enable_cnt >= dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
-    if (motDev && motDev->doxm && motDev->doxm->subOwners)
-    {
-        if (OC_STACK_OK != OCRemoveAllSubOwner(NULL, motDev, deleteDoxmForMOTCB))
-        {
-            return -1;
-        }
-
-        g_doneCB = false;
-
-        if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-        {
-            D2D_LOGE( "waitCallbackRet callback error");
-            return -1;
-        }
-        return 0;
-    }
-    else
-    {
-        printf("     SubOwner list is empty.\n");
-    }
-
-    return 0;
-}
-
-#endif //MULTIPLE_OWNER
-
-static int resetDevice(void)
-{
-    // check |own_list| for removing device
-    if (!g_own_list || 1 > g_own_cnt)
-    {
-        printf("   > Owned Device List, to Reset Device, is Empty\n");
-        printf("   > Please Register Unowned Devices first, with [20] Menu\n");
-        return 0;
-    }
-
-    // select device for removing it
-    int dev_num = 0;
-    for ( ; ; )
-    {
-        printf("   > Enter Device Number, for Resetting Device: ");
-        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 && g_own_cnt >= dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    g_doneCB = false;
-    printf("   Resetting Selected Owned Device..\n");
-
-    OCStackResult rst = OCResetDevice((void *) g_ctx, DISCOVERY_TIMEOUT,
-                   getDevInst((const OCProvisionDev_t *) g_own_list, dev_num), syncDeviceCB);
-    if (OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCResetDevice API error: %d", rst);
-        return -1;
-    }
-
-    if (waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        return -1;
-    }
-
-    // display the removed result
-    printf("   > Reset Selected Owned Device SUCCEEDED\n");
-    printf("   > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
-
-    return 0;
-}
-
-static int resetSVRDB(void)
-{
-    printf("   Resetting SVR DB..\n");
-    OCStackResult rst = OCResetSVRDB();
-    if (OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCResetSVRDB API error: %d", rst);
-        return -1;
-    }
-    return 0;
-}
-
-static OicSecAcl_t* createAcl(const int dev_num)
-{
-    if(0>=dev_num || g_own_cnt<dev_num)
-    {
-        D2D_LOGE( "createAcl invalid parameters");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-
-    // allocate memory for |acl| struct
-    printf("   **** Create ACL for the Selected Device[%d]\n", dev_num);
-    OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
-    if(!acl)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-    OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
-    if(!ace)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-    LL_APPEND(acl->aces, ace);
-
-    // enter |subject| device number
-    int num = 0;
-    for( ; ; )
-    {
-        printf("   > [A] Enter Subject Device Number: ");
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &num);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        if(0<num && g_own_cnt>=num && dev_num!=num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, num);
-    if(!dev || !dev->doxm)
-    {
-        D2D_LOGE( "createAcl: device instance empty");
-        goto CRACL_ERROR;
-    }
-    memcpy(&ace->subjectuuid, &dev->doxm->deviceID, UUID_LENGTH);
-
-    // enter number of |resources| in 'accessed' device
-    for( ; ; )
-    {
-        printf("   > [B] Enter Number of Accessed Resources (under 16): ");
-                // '16' is |ACL_RESRC_MAX_NUM|
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &num);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        if(0<num && ACL_RESRC_MAX_NUM>=num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter under 16 Again\n");
-                // '16' is |ACL_RESRC_MAX_NUM|
-    }
-
-    // enter actually each 'accessed' |resources| name
-    printf("         Enter Each Accessed Resource Name (each under 128 char)\n");
-            // '128' is ACL_RESRC_MAX_LEN
-
-    char rsrc_in[ACL_RESRC_MAX_LEN+1] = {0};  // '1' for null termination
-    for(int i = 0; num > i; ++i)
-    {
-        OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
-        if(!rsrc)
-        {
-            D2D_LOGE( "createAcl: OICCalloc error return");
-            goto CRACL_ERROR;
-        }
-
-        printf("         Enter Accessed Resource[%d] Name: (e.g. /a/led)", i+1);
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%128s", rsrc_in);  // '128' is ACL_RESRC_MAX_LEN
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        size_t len = strlen(rsrc_in)+1;  // '1' for null termination
-        rsrc->href = (char*) OICCalloc(len, sizeof(char));
-        if(!rsrc->href)
-        {
-            D2D_LOGE( "createAcl: OICCalloc error return");
-            goto CRACL_ERROR;
-        }
-        OICStrcpy(rsrc->href, len, rsrc_in);
-
-        size_t arrLen = 0;
-        while(1)
-        {
-            printf("         Enter Number of resource type for [%s] : ", rsrc->href);
-            for(int ret=0; 1!=ret; )
-            {
-                ret = scanf("%zu", &arrLen);
-                for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                            // '0x20<=code' is character region
-            }
-            if(ACL_RESRC_ARRAY_SIZE >= arrLen)
-            {
-                break;
-            }
-            printf("     Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
-        }
-
-        rsrc->typeLen = arrLen;
-        rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
-        if(!rsrc->types)
-        {
-            D2D_LOGE( "createAcl: OICCalloc error return");
-            goto CRACL_ERROR;
-        }
-
-        for(size_t i = 0; i < arrLen; i++)
-        {
-            printf("         Enter ResourceType[%zu] Name (e.g. core.led): ", i+1);
-            for(int ret=0; 1!=ret; )
-            {
-                ret = scanf("%128s", rsrc_in);  // '128' is ACL_RESRC_MAX_LEN
-                for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                            // '0x20<=code' is character region
-            }
-            rsrc->types[i] = OICStrdup(rsrc_in);
-            if(!rsrc->types[i])
-            {
-                D2D_LOGE( "createAcl: OICStrdup error return");
-                goto CRACL_ERROR;
-            }
-        }
-
-        while(1)
-        {
-            printf("         Enter Number of interface for [%s]: ", rsrc->href);
-            for(int ret=0; 1!=ret; )
-            {
-                ret = scanf("%zu", &arrLen);
-                for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                            // '0x20<=code' is character region
-            }
-            if(ACL_RESRC_ARRAY_SIZE >= arrLen)
-            {
-                break;
-            }
-            printf("     Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
-        }
-
-        rsrc->interfaceLen = arrLen;
-        rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
-        if(!rsrc->interfaces)
-        {
-            D2D_LOGE( "createAcl: OICCalloc error return");
-            goto CRACL_ERROR;
-        }
-
-        for(size_t i = 0; i < arrLen; i++)
-        {
-            printf("         Enter Interface[%zu] Name (e.g. oic.if.baseline): ", i+1);
-            for(int ret=0; 1!=ret; )
-            {
-                ret = scanf("%128s", rsrc_in);  // '128' is ACL_RESRC_MAX_LEN
-                for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                            // '0x20<=code' is character region
-            }
-            rsrc->interfaces[i] = OICStrdup(rsrc_in);
-            if(!rsrc->interfaces[i])
-            {
-                D2D_LOGE( "createAcl: OICStrdup error return");
-                goto CRACL_ERROR;
-            }
-        }
-
-        LL_APPEND(ace->resources, rsrc);
-    }
-
-    // enter |permission| for this access
-    printf("   > [C] Enter Permission for This Access\n");
-    uint16_t pmsn = PERMISSION_FULL_CONTROL;  // default full permission
-    uint16_t pmsn_msk = PERMISSION_CREATE;  // default permission mask
-    for(int i=0; ACL_PEMISN_CNT>i; ++i)
-    {
-        char ans = 0;
-        for( ; ; )
-        {
-            printf("         Enter %s Permission (y/n): ", ACL_PEMISN[i]);
-            for(int ret=0; 1!=ret; )
-            {
-                ret = scanf("%c", &ans);
-                for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                            // '0x20<=code' is character region
-            }
-            if('y'==ans || 'Y'==ans || 'n'==ans|| 'N'==ans)
-            {
-                ans &= ~0x20;  // for masking lower case, 'y/n'
-                break;
-            }
-            printf("         Entered Wrong Answer. Please Enter 'y/n' Again\n");
-        }
-        if('N' == ans)  // masked lower case, 'n'
-        {
-            pmsn -= pmsn_msk;
-        }
-        pmsn_msk <<= 1;
-    }
-    ace->permission = pmsn;
-
-    return acl;
-
-CRACL_ERROR:
-    OCDeleteACLList(acl);  // after here |acl| points nothing
-    return NULL;
-}
-
-static OicSecAcl_t* createSimpleAcl(const OicUuid_t uuid)
-{
-    D2D_LOGE( "createSimpleAcl IN");
-
-    // allocate memory for |acl| struct
-    OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
-    if(!acl)
-    {
-        D2D_LOGE( "OICCalloc error return");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-    OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
-    if(!ace)
-    {
-        D2D_LOGE(  "OICCalloc error return");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-    LL_APPEND(acl->aces, ace);
-
-    memcpy(&ace->subjectuuid, &uuid, UUID_LENGTH);
-
-    OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
-    if(!rsrc)
-    {
-        D2D_LOGE( "OICCalloc error return");
-        OCDeleteACLList(acl);
-        return NULL;
-    }
-
-    char href[] = "*";
-    size_t len = strlen(href)+1;  // '1' for null termination
-    rsrc->href = (char*) OICCalloc(len, sizeof(char));
-    if(!rsrc->href)
-    {
-        D2D_LOGE(  "OICCalloc error return");
-        OCDeleteACLList(acl);
-        return NULL;
-    }
-    OICStrcpy(rsrc->href, len, href);
-
-    size_t arrLen = 1;
-    rsrc->typeLen = arrLen;
-    rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
-    if(!rsrc->types)
-    {
-        D2D_LOGE(  "OICCalloc error return");
-        OCDeleteACLList(acl);
-        return NULL;
-    }
-    rsrc->types[0] = OICStrdup("");   // ignore
-
-    rsrc->interfaceLen = 1;
-    rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
-    if(!rsrc->interfaces)
-    {
-        D2D_LOGE(  "OICCalloc error return");
-        OCDeleteACLList(acl);
-        return NULL;
-    }
-    rsrc->interfaces[0] = OICStrdup("oic.if.baseline");  // ignore
-
-    LL_APPEND(ace->resources, rsrc);
-
-    ace->permission = 31;   // R/W/U/D
-
-    D2D_LOGE( "createSimpleAcl OUT");
-
-    return acl;
-}
-
-static OicSecPdAcl_t* createPdAcl(const int dev_num)
-{
-    if(0>=dev_num || g_own_cnt<dev_num)
-    {
-        D2D_LOGE( "createAcl invalid parameters");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-
-    // allocate memory for |pdacl| struct
-    printf("   **** Create PDACL for the Selected Device[%d]\n", dev_num);
-    OicSecPdAcl_t* pdAcl = (OicSecPdAcl_t*) OICCalloc(1, sizeof(OicSecPdAcl_t));
-    if(!pdAcl)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-
-
-    // number of resources
-    char rsrc_in[][ACL_RESRC_MAX_LEN+1] = {"*", "/rsrc/*"};
-    pdAcl->resourcesLen = 1;
-
-    // resource
-    int num = pdAcl->resourcesLen;
-    pdAcl->resources = (char**) OICCalloc(num, sizeof(char*));
-    if(!pdAcl->resources)
-    {
-        D2D_LOGE( "createPdAcl: OICCalloc error return");
-        goto CRPDACL_ERROR;
-    }
-    for(int i=0; num>i; ++i)
-    {
-        size_t len = strlen(rsrc_in[i])+1;  // '1' for null termination
-        char* rsrc = (char*) OICCalloc(len, sizeof(char));
-        if(!rsrc)
-        {
-            D2D_LOGE( "createPdAcl: OICCalloc error return");
-            goto CRPDACL_ERROR;
-        }
-        OICStrcpy(rsrc, len, rsrc_in[i]);
-        pdAcl->resources[i] = rsrc;  // after here, |rsrc| points nothing
-    }
-
-    // permission
-    pdAcl->permission = PERMISSION_FULL_CONTROL;
-
-    return pdAcl;
-
-CRPDACL_ERROR:
-    OCDeletePdAclList(pdAcl);
-    return NULL;
-}
-
-static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
-{
-    if(!dev_lst || 0>=dev_num)
-    {
-        printf("     Device List is Empty..\n");
-        return NULL;
-    }
-
-    OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
-    for(int i=0; lst; )
-    {
-        if(dev_num == ++i)
-        {
-            return lst;
-        }
-        lst = lst->next;
-    }
-
-    return NULL;  // in here |lst| is always |NULL|
-}
-
-static int printDevList(const OCProvisionDev_t* dev_lst)
-{
-    if(!dev_lst)
-    {
-        printf("     Device List is Empty..\n\n");
-        return 0;
-    }
-
-    OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
-    int lst_cnt = 0;
-    for( ; lst; )
-    {
-        printf("     [%d] ", ++lst_cnt);
-        printUuid((const OicUuid_t*) &lst->doxm->deviceID);
-        printf("\n");
-        lst = lst->next;
-    }
-    printf("\n");
-
-    return lst_cnt;
-}
-
-static size_t printUuidList(const OCUuidList_t* uid_lst)
-{
-    if(!uid_lst)
-    {
-        printf("     Device List is Empty..\n\n");
-        return 0;
-    }
-
-    OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
-    size_t lst_cnt = 0;
-    for( ; lst; )
-    {
-        printf("     [%zu] ", ++lst_cnt);
-        printUuid((const OicUuid_t*) &lst->dev);
-        printf("\n");
-        lst = lst->next;
-    }
-    printf("\n");
-
-    return lst_cnt;
-}
-
-static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
-{
-    if(!rslt_lst || 0>=rslt_cnt)
-    {
-        printf("     Device List is Empty..\n\n");
-        return 0;
-    }
-
-    int lst_cnt = 0;
-    for( ; rslt_cnt>lst_cnt; ++lst_cnt)
-    {
-        printf("     [%d] ", lst_cnt+1);
-        printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
-        printf(" - result: %d\n", rslt_lst[lst_cnt].res);
-    }
-    printf("\n");
-
-    return lst_cnt;
-}
-
-static void printUuid(const OicUuid_t* uid)
-{
-    for(int i=0; i<UUID_LENGTH; )
-    {
-        printf("%02X", (*uid).id[i++]);
-        if(i==4 || i==6 || i==8 || i==10)  // canonical format for UUID has '8-4-4-4-12'
-        {
-            printf("-");
-        }
-    }
-}
-
-static FILE* fopen_prvnMng(const char* path, const char* mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), SVR_DB_FILE_NAME);
-
-       (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(data_dir, mode);
-}
-
-static int peerCertCallback(void *ctx, const mbedtls_x509_crt *cert, int depth)
-{
-    (void)ctx;
-
-    D2D_LOGD( "Depth : %d", depth);
-    D2D_LOGD( "IN %s", __func__);
-    D2D_LOGE( "***** Serial number of certificate is below *****");
-    //D2D_LOGD( cert->serial.p, cert->serial.len);
-    D2D_LOGE( "***** Serial number of certificate is above *****");
-    D2D_LOGD( "OUT%s", __func__);
-
-    return 0;
-}
-
-static int waitCallbackRet(void)
-{
-    for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
-    {
-        sleep(1);
-        if(OC_STACK_OK != OCProcess())
-        {
-            D2D_LOGE( "OCStack process error");
-            return -1;
-        }
-    }
-
-    if(!g_doneCB)
-    {
-        OCPDMCleanupForTimeout();
-    }
-
-    return 0;
-}
-
-static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
-{
-    if(!a || !b || 2>max || !str)
-    {
-        return -1;
-    }
-
-    for( ; ; )
-    {
-        for(int i=0; 2>i; ++i)
-        {
-            int* num = 0==i?a:b;
-            for( ; ; )
-            {
-                printf("   > Enter Device[%d] Number, %s: ", i+1, str);
-                for(int ret=0; 1!=ret; )
-                {
-                    ret = scanf("%d", num);
-                    for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                                // '0x20<=code' is character region
-                }
-                if(0<*num && max>=*num)
-                {
-                    break;
-                }
-                printf("     Entered Wrong Number. Please Enter Again\n");
-            }
-        }
-        if(*a != *b)
-        {
-            printf("\n");
-            return 0;
-        }
-    }
-
-    return -1;
-}
-
-#ifdef __WITH_TLS__
-
-static void setDevProtocol(OCProvisionDev_t* lst)
-{
-    if(!lst)
-    {
-        printf("     Device List is Empty..\n\n");
-        return;
-    }
-
-    for( ; lst; )
-    {
-        if(2 == secure_protocol)
-        {
-            lst->connType &= ~CT_ADAPTER_IP; //reset IP flag
-            lst->connType |= CT_ADAPTER_TCP; //set TCP flag
-            lst->endpoint.adapter = OC_ADAPTER_TCP;
-            lst->endpoint.port = lst->tcpPort;
-            lst->securePort = lst->tcpPort;
-        }
-        lst = lst->next;
-    }
-}
-
-static void selectSecureProtocol()
-{
-    printf("   Select protocol\n");
-    printf("   1 - DTLS(Default)\n");
-    printf("   2 - TLS\n");
-
-    for(int ret=0; 1!=ret; )
-    {
-        ret = scanf("%d",&secure_protocol);
-        for( ; 0x20<=getchar(); );  // for removing overflow garbages
-        // '0x20<=code' is character region
-    }
-
-    if(0 >= secure_protocol || 2 < secure_protocol)
-    {
-        secure_protocol = 1;
-    }
-
-    setDevProtocol(g_own_list);
-    setDevProtocol(g_unown_list);
-}
-#endif
-
-static void secureStorageHwEmulation()
-{
-    printf("   Enable Secure Storage HW Emulation\n");
-
-    printf("         Enter Own Certificate File Path[~4095]: ");
-    char cert_filepath[4096] = {0,};
-    for(int ret=0; 1!=ret; )
-    {
-        ret = scanf("%255s", cert_filepath);
-        for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                    // '0x20<=code' is character region
-    }
-
-    printf("         Enter Private Key File Path[~4095]: ");
-    char key_filepath[4096] = {0,};
-    for(int ret=0; 1!=ret; )
-    {
-        ret = scanf("%255s", key_filepath);
-        for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                    // '0x20<=code' is character region
-    }
-
-    printf("         Enter Password for Key Password[~31][Press (Enter) to not set]: ");
-    char pwd[32] = {0,};
-    for(int i=0; i < 31; i++)
-    {
-        pwd[i] = (char)getchar();
-        if (0x20 <= pwd[i])
-        {
-            pwd[i--] = '\0';
-            continue;
-        }
-        if (0x0A == pwd[i])
-        {
-            pwd[i] = '\0';
-            break;
-        }
-    }
-
-    if (0 != SSemulSetCertkeyFilepath(cert_filepath, key_filepath, pwd))
-    {
-        printf("    Fail to set cert/key file path");
-        return;
-    }
-
-    if (0 != SetHwPkixCallbacks(HWGetKeyContext,
-                                                  HWFreeKeyContext,
-                                                  HWGetOwnCertificateChain,
-                                                  HWSetupPkContext))
-    {
-        printf("    Fail to regist HW Pkix Callbacks");
-        return;
-    }
-    printf("    Success to regist HW Pkix Callbacks");
-}
-
-static void selectVerifMethod()
-{
-    int option;
-    printf("   Select verification method for ownership transfer\n");
-    printf("   0 - No verification\n");
-    printf("   1 - Display only\n");
-    printf("   2 - Confirm only\n");
-    printf("   3 - Both Display and Confirm\n");
-
-    for(int ret=0; 1!=ret; )
-    {
-        ret = scanf("%d",&option);
-        for( ; 0x20<=getchar(); );  // for removing overflow garbages
-        // '0x20<=code' is character region
-    }
-
-    if(0 > option || 3 < option)
-    {
-        printf("Invalid option!");
-    }
-    SetVerifyOption((VerifyOptionBitmask_t) option);
-    printf("Option %d chosen!", option);
-}
-
-static void printMenu(void)
-{
-    printf("************************************************************\n");
-    printf("****** OIC Provisioning Client with using C-level API ******\n");
-    printf("************************************************************\n\n");
-
-    printf("** [A] DISCOVER DEVICES ON NETWORK\n");
-    printf("** 10. Discover All Un/Owned Devices on Network\n");
-    printf("** 11. Discover Only Unowned Devices on Network\n");
-#ifdef MULTIPLE_OWNER
-    printf("** 12. Discover Only Owned Devices on Network\n");
-    printf("** 13. Discover Multiple Ownership Transfer Enabled Devices on Network\n\n");
-#else
-    printf("** 12. Discover Only Owned Devices on Network\n\n");
-#endif //MULTIPLE_OWNER
-
-    printf("** [B] REGISTER/OWN ALL DISCOVERED UNOWNED DEVICES\n");
-    printf("** 20. Register/Own All Discovered Unowned Devices\n\n");
-
-    printf("** [C] PROVISION/LINK PAIRWISE THINGS\n");
-    printf("** 30. Provision/Link Pairwise Things\n");
-    printf("** 31. Provision Credentials for Pairwise Things\n");
-    printf("** 32. Provision the Selected Access Control List(ACL)\n");
-    printf("** 33. Provision Direct-Pairing Configuration\n");
-    printf("** 34. Check Linked Status of the Selected Device on PRVN DB\n");
-    printf("** 35. Save the Selected Access Control List(ACL) into local SVR DB\n\n");
-
-    printf("** [D] UNLINK PAIRWISE THINGS\n");
-    printf("** 40. Unlink Pairwise Things\n\n");
-
-    printf("** [E] REMOVE THE SELECTED DEVICE\n");
-    printf("** 50. Remove the Selected Device\n");
-    printf("** 51. Remove Device with UUID (UUID input is required)\n");
-    printf("** 52. Reset the Selected Device\n");
-    printf("** 53. Reset SVR DB\n\n");
-
-    printf("** [F] GET SECURITY RESOURCE FOR DEBUGGING ONLY\n");
-    printf("** 60. Get the Credential resources of the Selected Device\n");
-    printf("** 61. Get the ACL resources of the Selected Device\n\n");
-
-#ifdef MULTIPLE_OWNER
-    printf("** [G] UPDATE THE MULTIPLE OWNERSHIP TRANSFER RELATED VALUE\n");
-    printf("** 70. Change the Multiple Ownership transfer MODE(update mom)\n");
-    printf("** 71. Provision Preconfigured PIN\n");
-    printf("** 72. Change the Multiple Ownership transfer METHOD(update oxmsel)\n");
-    printf("** 73. Remove Sub-Owner from Resource Server\n");
-    printf("** 74. Remove All Sub-Owner from Resource Server\n\n");
-#endif //MULTIPLE_OWNER
-
-#ifdef __WITH_TLS__
-    printf("** [H] SELECT SECURE PROTOCOL DTLS/TLS AND OTHERS\n");
-    printf("** 80. Select secure protocol(default DTLS)\n");
-    printf("** 81. Select verification method\n");
-    printf("** 82. Enable secure storage hw emulation\n\n");
-#else
-    printf("** [H] SELECT VERIFICATION OPTION\n");
-    printf("** 81. Select verification method\n\n");
-#endif
-    printf("** [I] EXIT PROVISIONING CLIENT\n");
-
-    printf("** 99. Exit Provisionong Client\n\n");
-
-    printf("************************************************************\n\n");
-}
-
-#if 0 // Code for enabling path configuration for PDB and SVR DBf
-static void printUsage(void)
-{
-    printf("\n");
-    printf("OIC Provisioning Client with using C-level API\n");
-    printf("Usage: provisioningclient [option]...\n");
-    printf("\n");
-    printf("  -h                           print help for this provisioning client\n");
-    printf("  -p=[prvn_db_file_path/name]  input PRVN DB file path and name\n");
-    printf("                               if not exists, will load default DB file\n");
-    printf("                               (default: |oic_prvn_mng.db| on working dir)\n");
-    printf("                               (ex. -p=oic_prvn_mng.db)\n");
-    printf("  -s=[svr_db_file_path/name]   input SVR DB file path and name\n");
-    printf("                               if not exists, will load default DB file\n");
-    printf("                               (default: |oic_svr_db_client.json| on working dir)\n");
-    printf("                               (ex. -s=oic_svr_db_client.json)\n");
-    printf("\n");
-}
-#endif
-
-/**
- * Sample implementation of Export key block and master secret
- *
- * @param[in] p_expkey  Context for the callback
- * @aram[in] ms        Pointer to master secret (fixed length: 48 bytes)
- * @param[in] kb        Pointer to key block, see RFC 5246 section 6.3
- *                  (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
- * @param[in] maclen    MAC length
- * @param[in] keylen    Key length
- * @param[in] ivlen     IV length
- */
-static void SslExportKeysCallback(const unsigned char* masterSecret,
-                                  const unsigned char* keyBlock,
-                                  size_t macLen, size_t keyLen, size_t ivLen)
-{
-    D2D_LOGD("In %s ", __func__);
-
-    D2D_LOGE("[MASTER SECRET] : ");
-    //D2D_LOGD("%s %d", masterSecret, 48);
-
-    D2D_LOGE("[KEY BLOCK] : ");
-    //D2D_LOGD("%s %d", keyBlock, (2 * macLen) + (2 * keyLen) + (2 * ivLen));
-
-    D2D_LOGD("Mac Length = %zu, Key Length = %zu, IV Length = %zu",
-            macLen, keyLen, ivLen);
-
-    D2D_LOGD("Out %s ", __func__);
-}
-
-// main function for provisioning client using C-level provisioning API
-int main()
-{
-    // initialize provisioning client
-    if(initProvisionClient())
-    {
-        D2D_LOGE( "ProvisionClient init error");
-        goto PMCLT_ERROR;
-    }
-
-    if (CA_STATUS_OK !=
-        CASetSslExportKeysCallback(SslExportKeysCallback, CA_SSL_EKCB_DTLS, CA_SSL_EKCB_CLIENT))
-    {
-        D2D_LOGE( "Failed to register the (D)TLS export Key Callback!");
-        goto PMCLT_ERROR;
-    }
-
-    // Client can choose a allowed/not-allowed OxM method.
-    if(OC_STACK_OK != OCSetOxmAllowStatus(OIC_DECENTRALIZED_PUBLIC_KEY, false))
-    {
-        D2D_LOGE( "Failed to disable OIC_DECENTRALIZED_PUBLIC_KEY OxM");
-    }
-
-    // set callbacks for verification options
-    SetDisplayNumCB(NULL, displayNumCB);
-    SetUserConfirmCB(NULL, confirmNumCB);
-    SetInputStateCB(NULL, notifyInputStateCB);
-
-    // set callback for checking peer certificate information
-    OCSetPeerCertCallback(NULL, peerCertCallback);
-
-#ifdef MULTIPLE_OWNER
-    SetPreconfigPin("12341234", 8);
-#endif //MULTIPLE_OWNER
-
-    // main loop for provisioning manager
-    int mn_num = 0;
-    for( ; ; )
-    {
-        printf("\n");
-        printMenu();
-        printf(">> Enter Menu Number: ");
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &mn_num);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        printf("\n");
-        switch(mn_num)
-        {
-        case _10_DISCOV_ALL_DEVS_:
-            if(discoverAllDevices())
-            {
-                D2D_LOGE( "_10_DISCOV_ALL_DEVS_: error");
-            }
-            break;
-        case _11_DISCOV_UNOWN_DEVS_:
-            if(discoverUnownedDevices())
-            {
-                D2D_LOGE( "_11_DISCOV_UNOWN_DEVS_: error");
-            }
-            break;
-        case _12_DISCOV_OWN_DEVS_:
-            if(discoverOwnedDevices())
-            {
-                D2D_LOGE( "_12_DISCOV_OWN_DEVS_: error");
-            }
-            break;
-#ifdef MULTIPLE_OWNER
-        case _13_MOT_DISCOV_DEV_:
-            if(discoverMOTEnabledDevices())
-            {
-                D2D_LOGE( "_13_MOT_DISCOV_DEV_: error");
-            }
-            break;
-#endif //MULTIPLE_OWNER
-        case _20_REGIST_DEVS_:
-            if(registerDevices())
-            {
-                D2D_LOGE( "_20_REGIST_DEVS_: error");
-            }
-            break;
-        case _30_PROVIS_PAIR_DEVS_:
-            if(provisionPairwise())
-            {
-                D2D_LOGE( "_30_PROVIS_PAIR_DEVS_: error");
-            }
-            break;
-        case _31_PROVIS_CRED_:
-            if(provisionCred())
-            {
-                D2D_LOGE( "_31_PROVIS_CRED_: error");
-            }
-            break;
-        case _32_PROVIS_ACL_:
-            if(provisionAcl())
-            {
-                D2D_LOGE( "_32_PROVIS_ACL_: error");
-            }
-            break;
-        case _33_PROVIS_DP_:
-            if(provisionDirectPairing())
-            {
-                D2D_LOGE( "_33_PROVIS_DP_: error");
-            }
-            break;
-        case _34_CHECK_LINK_STATUS_:
-            if(checkLinkedStatus())
-            {
-                D2D_LOGE( "_34_CHECK_LINK_STATUS_: error");
-            }
-            break;
-        case _35_SAVE_ACL_:
-            if(saveAcl())
-            {
-                D2D_LOGE( "_35_SAVE_ACL_: error");
-            }
-            break;
-        case _40_UNLINK_PAIR_DEVS_:
-            if(unlinkPairwise())
-            {
-                D2D_LOGE( "_40_UNLINK_PAIR_DEVS_: error");
-            }
-            break;
-        case _50_REMOVE_SELEC_DEV_:
-            if(removeDevice())
-            {
-                D2D_LOGE( "_50_REMOVE_SELEC_DEV_: error");
-            }
-            break;
-        case _51_REMOVE_DEV_WITH_UUID_:
-            if(removeDeviceWithUuid())
-            {
-                D2D_LOGE( "_51_REMOVE_DEV_WITH_UUID_: error");
-            }
-            break;
-        case _52_RESET_SELEC_DEV_:
-            if(resetDevice())
-            {
-                D2D_LOGE( "_52_RESET_SELEC_DEV_: error");
-            }
-            break;
-        case _53_RESET_SVR_DB_:
-            if(resetSVRDB())
-            {
-                D2D_LOGE( "_53_RESET_SVR_DB_: error");
-            }
-            break;
-        case _60_GET_CRED_:
-            if(getCred())
-            {
-                D2D_LOGE( "_60_GET_CRED_: error");
-            }
-            break;
-        case _61_GET_ACL_:
-            if(getAcl())
-            {
-                D2D_LOGE( "_61_GET_ACL_: error");
-            }
-            break;
-#ifdef MULTIPLE_OWNER
-        case _70_MOT_CHANGE_MOM_:
-            if(changeMultipleOwnershipTrnasferMode())
-            {
-                D2D_LOGE( "_70_MOT_CHANGE_MOM_: error");
-            }
-            break;
-        case _71_MOT_PROV_PRECONF_PIN_:
-            if(provisionPreconfigPIN())
-            {
-                D2D_LOGE( "_71_MOT_PROV_PRECONF_PIN_: error");
-            }
-            break;
-        case _72_MOT_OXM_SEL_:
-            if(selectMultipleOwnershipTrnasferMethod())
-            {
-                D2D_LOGE( "_72_MOT_OXM_SEL_: error");
-            }
-            break;
-        case _73_MOT_REMOVE_SUBOWNER_:
-            if(removeSubOwner())
-            {
-                D2D_LOGE( "_73_MOT_REMOVE_SUBOWNER_ : error");
-            }
-            break;
-        case _74_MOT_REMOVE_ALL_SUBOWNER_:
-            if(removeAllSubOwner())
-            {
-                D2D_LOGE( "_74_MOT_REMOVE_ALL_SUBOWNER_ : error");
-            }
-            break;
-#endif //MULTIPLE_OWNER
-#ifdef __WITH_TLS__
-        case  _80_SELECT_PROTOCOL_:
-            selectSecureProtocol();
-            break;
-#endif
-        case _81_SELECT_VERIF_METHOD_:
-            selectVerifMethod();
-            break;
-        case _82_SECURE_STORAGE_HW_EMULATION_:
-            secureStorageHwEmulation();
-            break;
-        case _99_EXIT_PRVN_CLT_:
-            goto PMCLT_ERROR;
-        default:
-            printf(">> Entered Wrong Number. Please Enter Again\n\n");
-            break;
-        }
-    }
-
-PMCLT_ERROR:
-    if(OC_STACK_OK != OCStop())
-    {
-        D2D_LOGE( "OCStack stop error");
-    }
-    OCDeleteDiscoveredDevices(g_own_list);  // after here |g_own_list| points nothing
-    OCDeleteDiscoveredDevices(g_unown_list);  // after here |g_unown_list| points nothing
-#ifdef MULTIPLE_OWNER
-    OCDeleteDiscoveredDevices(g_mot_enable_list);  // after here |g_motdev_list| points nothing
-#endif //MULTIPLE_OWNER
-
-    if(g_svr_fname)
-    {
-        OICFree(g_svr_fname);  // after here |g_svr_fname| points nothing
-    }
-    if(g_prvn_fname)
-    {
-        OICFree(g_prvn_fname);  // after here |g_prvn_fname| points nothing
-    }
-    return 0;  // always return normal case
-}
-
-#ifdef __cplusplus
-}
-#endif //__cplusplus
diff --git a/test/rootca.crt b/test/rootca.crt
deleted file mode 100644 (file)
index ee80fa4..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDjDCCAnQCAQEwDQYJKoZIhvcNAQELBQAwgYsxCzAJBgNVBAYTAktSMQ4wDAYD
-VQQIDAVTZW91bDEPMA0GA1UEBwwGVW15ZW9uMREwDwYDVQQKDAhTYW1zdW5nIDEU
-MBIGA1UECwwLT0NGIFJvb3QgQ0ExMjAwBgNVBAMMKXV1aWQ6MzEzMTMxMzEtMzEz
-MS0zMTMxLTMxMzEtMzEzMTMxMzEzMTMxMB4XDTE2MTAyODA0MjEyMloXDTI2MTAy
-NjA0MjEyMlowgYsxCzAJBgNVBAYTAktSMQ4wDAYDVQQIDAVTZW91bDEPMA0GA1UE
-BwwGVW15ZW9uMREwDwYDVQQKDAhTYW1zdW5nIDEUMBIGA1UECwwLT0NGIFJvb3Qg
-Q0ExMjAwBgNVBAMMKXV1aWQ6MzEzMTMxMzEtMzEzMS0zMTMxLTMxMzEtMzEzMTMx
-MzEzMTMxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3EJwn+NfeW9Y
-RLDoOUSg45AvkqsMeNBv8ZTqWyY5nAeyESQsDejacm6dSpzMP/p5y1KBWYszKOXr
-CUtrkch8VxOtt4egiv3Tschl16W1W7ril8EEbX8zoEcuExfoLdPZhDtRl8ROdG3t
-NE0r/Fv5ubTEwW0K3JgIwykB4OAsO2aQtCuZ32cZlg5UcW3LAXpxJ7cEkMR2xhcN
-xbg0dgbyy5BiWit3grXXJBkopq/ADCRUIVzpLjxeFTVshWw9+AA1IUZaG64fkbLG
-pzdYFVsuRvMlyEwWrMm23/hT8x0eywvPX5k/N1s6I0KiE8FitVi5bgUph3iCNLE/
-1a/oLrtWyQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQDHq9X9YofW3IN8R61r0raN
-tacYMumZFZfPOEcHHGvTkPrMygUNfTM+g6XEzOvlBB4dd6UE5EsVnRkQP0wvaaJx
-3Js/zQMkAXeVRzDg/YowynuG+t4VvoQl/1uNDUKjU9z+yv+vQjNctzeKhvAJxWGO
-ZtpgIslUhMtGBjWQDNd2APf8yOcD50yVwUpcp4WGbqaaKxn+rixu8jk1NEas0EHD
-XBytAgEdOeBQplv6W+W1fG3j0PMolkWaPIvjSvMk0m11h4GR5Kyx3gRQS74gurG/
-DboAZ+DJMe7hMh4coOwnOuS8euPtxEPD3IkYVAT4aFPIvTkiri0EYimgtQd+M45f
------END CERTIFICATE-----
diff --git a/test/sampleserver_justworks.cpp b/test/sampleserver_justworks.cpp
deleted file mode 100644 (file)
index 8f6e1d9..0000000
+++ /dev/null
@@ -1,537 +0,0 @@
-/******************************************************************
-*
-* Copyright 2015 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-///////////////////////////////////////////////////////////////////////
-//NOTE :  This sample server is generated based on ocserverbasicops.cpp
-///////////////////////////////////////////////////////////////////////
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#include <signal.h>
-#include "ocstack.h"
-#include "ocpayload.h"
-#include "pinoxmcommon.h"
-#include "srmutility.h"
-
-#include <tzplatform_config.h>
-#include <d2d-log.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-/** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */
-#ifdef ERROR
-#undef ERROR
-#endif //ERROR
-#endif //HAVE_WINDOWS_H
-#include "platform_features.h"
-#include "logger.h"
-
-
-#define TAG "SAMPLE_JUSTWORKS"
-
-int gQuitFlag = 0;
-
-/* Structure to represent a LED resource */
-typedef struct LEDRESOURCE{
-    OCResourceHandle handle;
-    bool state;
-    int power;
-} LEDResource;
-
-static LEDResource LED;
-// This variable determines instance number of the LED resource.
-// Used by POST method to create a new instance of LED resource.
-static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE  2
-static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
-
-char *gResourceUri= (char *)"/a/led";
-
-//Secure Virtual Resource database for Iotivity Server
-//It contains Server's Identity and the PSK credentials
-//of other devices which the server trusts
-static char CRED_FILE[] = "oic_svr_db_server_justworks.dat";
-
-/* Function that creates a new LED resource by calling the
- * OCCreateResource() method.
- */
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower);
-
-/* This method converts the payload to JSON format */
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest);
-
-/* Following methods process the PUT, GET, POST
- * requests
- */
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-                                        OCEntityHandlerResponse *response,
-                                        OCRepPayload **payload);
-
-/* Entity Handler callback functions */
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam);
-
-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_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";
-    #ifdef WITH_PRESENCE
-    case OC_STACK_PRESENCE_STOPPED:
-        return "OC_STACK_PRESENCE_STOPPED";
-    #endif
-    case OC_STACK_ERROR:
-        return "OC_STACK_ERROR";
-    default:
-        return "UNKNOWN";
-    }
-}
-
-OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if(!payload)
-    {
-        D2D_LOGE( "Failed to allocate Payload");
-        return NULL;
-    }
-
-    OCRepPayloadSetUri(payload, uri);
-    OCRepPayloadSetPropBool(payload, "state", state);
-    OCRepPayloadSetPropInt(payload, "power", power);
-
-    return payload;
-}
-
-//This function takes the request as an input and returns the response
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest)
-{
-    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        D2D_LOGE( "Incoming payload not a representation");
-        return NULL;
-    }
-
-    OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
-
-    LEDResource *currLEDResource = &LED;
-
-    if (ehRequest->resource == gLedInstance[0].handle)
-    {
-        currLEDResource = &gLedInstance[0];
-        gResourceUri = (char *) "/a/led/0";
-    }
-    else if (ehRequest->resource == gLedInstance[1].handle)
-    {
-        currLEDResource = &gLedInstance[1];
-        gResourceUri = (char *) "/a/led/1";
-    }
-
-    if(OC_REST_PUT == ehRequest->method)
-    {
-        // Get pointer to query
-        int64_t pow;
-        if(OCRepPayloadGetPropInt(input, "power", &pow))
-        {
-            currLEDResource->power =pow;
-        }
-
-        bool state;
-        if(OCRepPayloadGetPropBool(input, "state", &state))
-        {
-            currLEDResource->state = state;
-        }
-    }
-
-    return getPayload(gResourceUri, currLEDResource->power, currLEDResource->state);
-}
-
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-
-    if(getResp)
-    {
-        *payload = getResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *putResp = constructResponse(ehRequest);
-
-    if(putResp)
-    {
-        *payload = putResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, OCRepPayload **payload)
-{
-    OCRepPayload *respPLPost_led = NULL;
-    OCEntityHandlerResult ehResult = OC_EH_OK;
-
-    /*
-     * The entity handler determines how to process a POST request.
-     * Per the REST paradigm, POST can also be used to update representation of existing
-     * resource or create a new resource.
-     * In the sample below, if the POST is for /a/led then a new instance of the LED
-     * resource is created with default representation (if representation is included in
-     * POST payload it can be used as initial values) as long as the instance is
-     * lesser than max new instance count. Once max instance count is reached, POST on
-     * /a/led updated the representation of /a/led (just like PUT)
-     */
-
-    if (ehRequest->resource == LED.handle)
-    {
-        if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
-        {
-            // Create new LED instance
-            char newLedUri[15] = "/a/led/";
-            int newLedUriLength = strlen(newLedUri);
-            snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance);
-
-            respPLPost_led = OCRepPayloadCreate();
-            OCRepPayloadSetUri(respPLPost_led, gResourceUri);
-            OCRepPayloadSetPropString(respPLPost_led, "createduri", newLedUri);
-
-            if (0 == createLEDResource (newLedUri, &gLedInstance[gCurrLedInstance], false, 0))
-            {
-                D2D_LOGE ( "Created new LED instance");
-                gLedInstance[gCurrLedInstance].state = 0;
-                gLedInstance[gCurrLedInstance].power = 0;
-                gCurrLedInstance++;
-                strncpy ((char *)response->resourceUri, newLedUri, sizeof(response->resourceUri));
-                ehResult = OC_EH_RESOURCE_CREATED;
-            }
-        }
-        else
-        {
-            respPLPost_led = constructResponse(ehRequest);
-        }
-    }
-    else
-    {
-        for (int i = 0; i < SAMPLE_MAX_NUM_POST_INSTANCE; i++)
-        {
-            if (ehRequest->resource == gLedInstance[i].handle)
-            {
-                if (i == 0)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                    break;
-                }
-                else if (i == 1)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                }
-            }
-        }
-    }
-
-    if (respPLPost_led != NULL)
-    {
-        *payload = respPLPost_led;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        D2D_LOGD ( "Payload was NULL");
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam)
-{
-    D2D_LOGD ( "Inside entity handler - flags: 0x%x", flag);
-    (void)callbackParam;
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
-    OCEntityHandlerResponse response;
-    memset(&response, 0, sizeof(response));
-
-    // Validate pointer
-    if (!entityHandlerRequest)
-    {
-        D2D_LOGE ( "Invalid request pointer");
-        return OC_EH_ERROR;
-    }
-
-    OCRepPayload* payload = NULL;
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        D2D_LOGE ( "Flag includes OC_REQUEST_FLAG");
-        if (entityHandlerRequest)
-        {
-            if (OC_REST_GET == entityHandlerRequest->method)
-            {
-                D2D_LOGE( "Received OC_REST_GET from client");
-                ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_PUT == entityHandlerRequest->method)
-            {
-                D2D_LOGE( "Received OC_REST_PUT from client");
-                ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_POST == entityHandlerRequest->method)
-            {
-                D2D_LOGE( "Received OC_REST_POST from client");
-                ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
-            }
-            else
-            {
-                D2D_LOGD( "Received unsupported method %d from client",
-                        entityHandlerRequest->method);
-                ehResult = OC_EH_ERROR;
-            }
-
-            if (ehResult == OC_EH_OK && ehResult != OC_EH_FORBIDDEN)
-            {
-                // Format the response.  Note this requires some info about the request
-                response.requestHandle = entityHandlerRequest->requestHandle;
-                response.resourceHandle = entityHandlerRequest->resource;
-                response.ehResult = ehResult;
-                response.payload = (OCPayload*)(payload);
-                response.numSendVendorSpecificHeaderOptions = 0;
-                memset(response.sendVendorSpecificHeaderOptions, 0,
-                       sizeof(response.sendVendorSpecificHeaderOptions));
-                memset(response.resourceUri, 0, sizeof(response.resourceUri));
-                // Indicate that response is NOT in a persistent buffer
-                response.persistentBufferFlag = 0;
-
-                // Send the response
-                if (OCDoResponse(&response) != OC_STACK_OK)
-                {
-                    D2D_LOGE( "Error sending response");
-                    ehResult = OC_EH_ERROR;
-                }
-            }
-        }
-    }
-
-    OCPayloadDestroy(response.payload);
-    return ehResult;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-FILE* server_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), CRED_FILE);
-
-       (void)path;
-
-       D2D_LOGE("fopen %s", data_dir);
-
-    return fopen(data_dir, mode);
-}
-
-static void OtmEventHandler(void *ctx, const char *addr, uint16_t port,
-        const char* ownerId, OCOtmEvent_t event)
-{
-    (void)ctx;
-    printf("--------------------------------------\n");
-    printf("Get OTM event.\n");
-    printf("Address : %s\n", addr);
-    printf("Port : %d\n", port);
-    printf("Owner ID : %s\n", ownerId);
-
-    switch (event)
-    {
-        case OIC_OTM_READY:
-            printf("State : OIC_OTM_READY\n");
-            break;
-        case OIC_OTM_STARTED:
-            printf("State : OIC_OTM_STARTED\n");
-            break;
-        case OIC_OTM_DONE:
-            printf("State : OIC_OTM_DONE\n");
-            break;
-        case OIC_OTM_ERROR:
-            printf("State : OIC_OTM_ERROR\n");
-            break;
-        default:
-            printf("State : Unknown state.\n");
-            break;
-    }
-    printf("--------------------------------------\n");
-}
-
-#include <ocprovisioningmanager.h>
-
-int main()
-{
-       const uint8_t seed[6] = {0x00, 0x12, 0x34, 0x11, 0x22, 0x33};
-    struct timespec timeout;
-
-    D2D_LOGE( "OCServer is starting...");
-
-       SetDeviceIdSeed(seed, 6);
-
-    //This function should be invoked before invoke OCInit
-    OCSetOtmEventHandler(NULL, OtmEventHandler);
-
-    // Initialize Persistent Storage for SVR database
-    OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink, NULL, NULL};
-
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack init error");
-        return 0;
-    }
-
-       OCConfigSelfOwnership();
-
-    /*
-     * Declare and create the example resource: LED
-     */
-    createLEDResource(gResourceUri, &LED, false, 0);
-
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    // Break from loop with Ctrl-C
-    D2D_LOGE( "Entering ocserver main loop...");
-    signal(SIGINT, handleSigInt);
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            return 0;
-        }
-        nanosleep(&timeout, NULL);
-    }
-
-    D2D_LOGE( "Exiting ocserver main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack process error");
-    }
-
-    return 0;
-}
-
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower)
-{
-    if (!uri)
-    {
-        D2D_LOGE( "Resource URI cannot be NULL");
-        return -1;
-    }
-
-    ledResource->state = resourceState;
-    ledResource->power= resourcePower;
-    OCStackResult res = OCCreateResource(&(ledResource->handle),
-            "core.led",
-            OC_RSRVD_INTERFACE_DEFAULT,
-            uri,
-            OCEntityHandlerCb,
-            NULL,
-            OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
-    D2D_LOGD( "Created LED resource with result: %s", getResult(res));
-
-    return 0;
-}
diff --git a/test/sampleserver_justworks_protectedDB.cpp b/test/sampleserver_justworks_protectedDB.cpp
deleted file mode 100644 (file)
index 4f8cd25..0000000
+++ /dev/null
@@ -1,540 +0,0 @@
-/******************************************************************
-*
-* Copyright 2015 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-///////////////////////////////////////////////////////////////////////
-//NOTE :  This sample server is generated based on ocserverbasicops.cpp
-///////////////////////////////////////////////////////////////////////
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#include <signal.h>
-#include "ocstack.h"
-#include "ocpayload.h"
-#include "pinoxmcommon.h"
-
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-/** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */
-#ifdef ERROR
-#undef ERROR
-#endif //ERROR
-#endif //HAVE_WINDOWS_H
-#include "platform_features.h"
-#include "logger.h"
-
-
-#define TAG "SAMPLE_JUSTWORKS"
-
-int gQuitFlag = 0;
-
-/* Structure to represent a LED resource */
-typedef struct LEDRESOURCE{
-    OCResourceHandle handle;
-    bool state;
-    int power;
-} LEDResource;
-
-static LEDResource LED;
-// This variable determines instance number of the LED resource.
-// Used by POST method to create a new instance of LED resource.
-static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE  2
-static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
-
-char *gResourceUri= (char *)"/a/led";
-
-//Secure Virtual Resource database for Iotivity Server
-//It contains Server's Identity and the PSK credentials
-//of other devices which the server trusts
-//static char CRED_FILE[] = "oic_svr_db_server_justworks_protectedDB.dat";
-static char RESCUE_FILE[] = "oic_svr_db_server_justworks_default.dat";
-static char SVR_DB_PLAIN_FILE[] = "oic_svr_db_server_justworks_protectedDB_plain.dat";
-static char SVR_DB_ENCRYPTED_FILE[] = "oic_svr_db_server_justworks_protectedDB_encrypted.dat";
-
-/* Function that creates a new LED resource by calling the
- * OCCreateResource() method.
- */
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower);
-
-/* This method converts the payload to JSON format */
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest);
-
-/* Following methods process the PUT, GET, POST
- * requests
- */
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-                                        OCEntityHandlerResponse *response,
-                                        OCRepPayload **payload);
-// Initialize Persistent Storage for SVR database
-OCPersistentStorage *ps = NULL;
-
-
-/* Entity Handler callback functions */
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam);
-
-unsigned char key[32] =  { 0xa5, 0x84, 0x99, 0x8d, 0x0d, 0xbd, 0xb1, 0x54,
-                           0xbb, 0xc5, 0x4f, 0xed, 0x86, 0x9a, 0x66, 0x11,
-                           0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda,
-                           0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5
-                         };
-
-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_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";
-    #ifdef WITH_PRESENCE
-    case OC_STACK_PRESENCE_STOPPED:
-        return "OC_STACK_PRESENCE_STOPPED";
-    #endif
-    case OC_STACK_ERROR:
-        return "OC_STACK_ERROR";
-    default:
-        return "UNKNOWN";
-    }
-}
-
-OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if(!payload)
-    {
-        D2D_LOGE( "Failed to allocate Payload");
-        return NULL;
-    }
-
-    OCRepPayloadSetUri(payload, uri);
-    OCRepPayloadSetPropBool(payload, "state", state);
-    OCRepPayloadSetPropInt(payload, "power", power);
-
-    return payload;
-}
-
-//This function takes the request as an input and returns the response
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest)
-{
-    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        D2D_LOGE( "Incoming payload not a representation");
-        return NULL;
-    }
-
-    OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
-
-    LEDResource *currLEDResource = &LED;
-
-    if (ehRequest->resource == gLedInstance[0].handle)
-    {
-        currLEDResource = &gLedInstance[0];
-        gResourceUri = (char *) "/a/led/0";
-    }
-    else if (ehRequest->resource == gLedInstance[1].handle)
-    {
-        currLEDResource = &gLedInstance[1];
-        gResourceUri = (char *) "/a/led/1";
-    }
-
-    if(OC_REST_PUT == ehRequest->method)
-    {
-        // Get pointer to query
-        int64_t pow;
-        if(OCRepPayloadGetPropInt(input, "power", &pow))
-        {
-            currLEDResource->power =pow;
-        }
-
-        bool state;
-        if(OCRepPayloadGetPropBool(input, "state", &state))
-        {
-            currLEDResource->state = state;
-        }
-    }
-
-    return getPayload(gResourceUri, currLEDResource->power, currLEDResource->state);
-}
-
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-
-    if(getResp)
-    {
-        *payload = getResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *putResp = constructResponse(ehRequest);
-
-    if(putResp)
-    {
-        *payload = putResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, OCRepPayload **payload)
-{
-    OCRepPayload *respPLPost_led = NULL;
-    OCEntityHandlerResult ehResult = OC_EH_OK;
-
-    /*
-     * The entity handler determines how to process a POST request.
-     * Per the REST paradigm, POST can also be used to update representation of existing
-     * resource or create a new resource.
-     * In the sample below, if the POST is for /a/led then a new instance of the LED
-     * resource is created with default representation (if representation is included in
-     * POST payload it can be used as initial values) as long as the instance is
-     * lesser than max new instance count. Once max instance count is reached, POST on
-     * /a/led updated the representation of /a/led (just like PUT)
-     */
-
-    if (ehRequest->resource == LED.handle)
-    {
-        if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
-        {
-            // Create new LED instance
-            char newLedUri[15] = "/a/led/";
-            int newLedUriLength = strlen(newLedUri);
-            snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance);
-
-            respPLPost_led = OCRepPayloadCreate();
-            OCRepPayloadSetUri(respPLPost_led, gResourceUri);
-            OCRepPayloadSetPropString(respPLPost_led, "createduri", newLedUri);
-
-            if (0 == createLEDResource (newLedUri, &gLedInstance[gCurrLedInstance], false, 0))
-            {
-                D2D_LOGE ( "Created new LED instance");
-                gLedInstance[gCurrLedInstance].state = 0;
-                gLedInstance[gCurrLedInstance].power = 0;
-                gCurrLedInstance++;
-                strncpy ((char *)response->resourceUri, newLedUri, sizeof(response->resourceUri));
-                ehResult = OC_EH_RESOURCE_CREATED;
-            }
-        }
-        else
-        {
-            respPLPost_led = constructResponse(ehRequest);
-        }
-    }
-    else
-    {
-        for (int i = 0; i < SAMPLE_MAX_NUM_POST_INSTANCE; i++)
-        {
-            if (ehRequest->resource == gLedInstance[i].handle)
-            {
-                if (i == 0)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                    break;
-                }
-                else if (i == 1)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                }
-            }
-        }
-    }
-
-    if (respPLPost_led != NULL)
-    {
-        *payload = respPLPost_led;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        D2D_LOGD ( "Payload was NULL");
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam)
-{
-    D2D_LOGD ( "Inside entity handler - flags: 0x%x", flag);
-    (void)callbackParam;
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
-    OCEntityHandlerResponse response;
-    memset(&response, 0, sizeof(response));
-
-    // Validate pointer
-    if (!entityHandlerRequest)
-    {
-        D2D_LOGE ( "Invalid request pointer");
-        return OC_EH_ERROR;
-    }
-
-    OCRepPayload* payload = NULL;
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        D2D_LOGE ( "Flag includes OC_REQUEST_FLAG");
-        if (entityHandlerRequest)
-        {
-            if (OC_REST_GET == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_GET from client");
-                ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_PUT == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_PUT from client");
-                ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_POST == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_POST from client");
-                ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
-            }
-            else
-            {
-                D2D_LOGD ( "Received unsupported method %d from client",
-                        entityHandlerRequest->method);
-                ehResult = OC_EH_ERROR;
-            }
-
-            if (ehResult == OC_EH_OK && ehResult != OC_EH_FORBIDDEN)
-            {
-                // Format the response.  Note this requires some info about the request
-                response.requestHandle = entityHandlerRequest->requestHandle;
-                response.resourceHandle = entityHandlerRequest->resource;
-                response.ehResult = ehResult;
-                response.payload = (OCPayload*)(payload);
-                response.numSendVendorSpecificHeaderOptions = 0;
-                memset(response.sendVendorSpecificHeaderOptions, 0,
-                       sizeof(response.sendVendorSpecificHeaderOptions));
-                memset(response.resourceUri, 0, sizeof(response.resourceUri));
-                // Indicate that response is NOT in a persistent buffer
-                response.persistentBufferFlag = 0;
-
-                // Send the response
-                if (OCDoResponse(&response) != OC_STACK_OK)
-                {
-                    D2D_LOGE( "Error sending response");
-                    ehResult = OC_EH_ERROR;
-                }
-            }
-        }
-    }
-
-    OCPayloadDestroy(response.payload);
-    return ehResult;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-FILE* plain_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), SVR_DB_PLAIN_FILE);
-
-       (void)path;
-
-    return fopen(data_dir, mode);
-}
-
-int plain_unlink(const char *path)
-{
-    D2D_LOGE( "plain DB is removed");
-    (void)path;
-    return unlink(SVR_DB_PLAIN_FILE);
-}
-
-FILE* encrypted_fopen(const char *path, const char *mode)
-{
-    (void)path;
-    return fopen(SVR_DB_ENCRYPTED_FILE, mode);
-}
-
-FILE* rescue_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), RESCUE_FILE);
-
-       (void)path;
-
-    return fopen(data_dir, mode);
-}
-
-int main()
-{
-    OCStackResult ret;
-    struct timespec timeout;
-
-    D2D_LOGE( "OCServer is starting...");
-
-    OCPersistentStorage psPlain = {plain_fopen, fread, NULL, fclose, plain_unlink, NULL, NULL};
-    OCPersistentStorage psEnc = {encrypted_fopen, fread, fwrite, fclose,
-        unlink, OCEncrypt, OCDecrypt};
-    OCPersistentStorage psRescue = {rescue_fopen, fread, NULL, fclose, NULL, NULL, NULL};
-
-    ret = OCSetSecurePSI(key, &psPlain, &psEnc, &psRescue);
-    if (OC_STACK_OK != ret)
-    {
-        D2D_LOGE( "OCSetSecurePSI() error");
-        return 1;
-    }
-
-    ret = OCRegisterPersistentStorageHandler(&psEnc);
-    if (OC_STACK_OK != ret)
-    {
-        D2D_LOGE( "OCRegisterPersistentStorageHandler() error");
-        return 1;
-    }
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack init error");
-        return 1;
-    }
-
-    /*
-     * Declare and create the example resource: LED
-     */
-    createLEDResource(gResourceUri, &LED, false, 0);
-
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    // Break from loop with Ctrl-C
-    D2D_LOGE( "Entering ocserver main loop...");
-    signal(SIGINT, handleSigInt);
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            return 1;
-        }
-        nanosleep(&timeout, NULL);
-    }
-
-    D2D_LOGE( "Exiting ocserver main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack process error");
-    }
-
-    return 0;
-}
-
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower)
-{
-    if (!uri)
-    {
-        D2D_LOGE( "Resource URI cannot be NULL");
-        return -1;
-    }
-
-    ledResource->state = resourceState;
-    ledResource->power= resourcePower;
-    OCStackResult res = OCCreateResource(&(ledResource->handle),
-            "core.led",
-            OC_RSRVD_INTERFACE_DEFAULT,
-            uri,
-            OCEntityHandlerCb,
-            NULL,
-            OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
-    D2D_LOGD( "Created LED resource with result: %s", getResult(res));
-
-    return 0;
-}
diff --git a/test/sampleserver_mfg.cpp b/test/sampleserver_mfg.cpp
deleted file mode 100644 (file)
index 4c12072..0000000
+++ /dev/null
@@ -1,575 +0,0 @@
-/******************************************************************
-*
-* Copyright 2016 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-///////////////////////////////////////////////////////////////////////
-//NOTE :  This sample server is generated based on ocserverbasicops.cpp
-///////////////////////////////////////////////////////////////////////
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#include <signal.h>
-#include "ocstack.h"
-#include "ocpayload.h"
-
-#include <tzplatform_config.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-/** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */
-#ifdef ERROR
-#undef ERROR
-#endif //ERROR
-#endif //HAVE_WINDOWS_H
-#include "platform_features.h"
-#include "logger.h"
-#include "pkix_interface.h"
-#include "hw_emul/hw_interface.h"
-#include "oxmverifycommon.h"
-
-#define TAG "SAMPLE_MANUFACTURER_CERT"
-
-int gQuitFlag = 0;
-
-/* Structure to represent a LED resource */
-typedef struct LEDRESOURCE{
-    OCResourceHandle handle;
-    bool state;
-    int power;
-} LEDResource;
-
-static LEDResource LED;
-// This variable determines instance number of the LED resource.
-// Used by POST method to create a new instance of LED resource.
-static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE  2
-static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
-
-char *gResourceUri= (char *)"/a/led";
-
-//Secure Virtual Resource database for Iotivity Server
-//It contains Server's Identity and the manufacturer certificate
-static char CRED_FILE[] = "oic_svr_db_server_mfg.dat";
-
-/* Function that creates a new LED resource by calling the
- * OCCreateResource() method.
- */
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower);
-
-/* This method converts the payload to JSON format */
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest);
-
-/* Following methods process the PUT, GET, POST
- * requests
- */
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-                                        OCEntityHandlerResponse *response,
-                                        OCRepPayload **payload);
-
-/* Entity Handler callback functions */
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam);
-
-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_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";
-    #ifdef WITH_PRESENCE
-    case OC_STACK_PRESENCE_STOPPED:
-        return "OC_STACK_PRESENCE_STOPPED";
-    #endif
-    case OC_STACK_ERROR:
-        return "OC_STACK_ERROR";
-    default:
-        return "UNKNOWN";
-    }
-}
-
-OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if(!payload)
-    {
-        D2D_LOGE( "Failed to allocate Payload");
-        return NULL;
-    }
-
-    OCRepPayloadSetUri(payload, uri);
-    OCRepPayloadSetPropBool(payload, "state", state);
-    OCRepPayloadSetPropInt(payload, "power", power);
-
-    return payload;
-}
-
-//This function takes the request as an input and returns the response
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest)
-{
-    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        D2D_LOGE( "Incoming payload not a representation");
-        return NULL;
-    }
-
-    OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
-
-    LEDResource *currLEDResource = &LED;
-
-    if (ehRequest->resource == gLedInstance[0].handle)
-    {
-        currLEDResource = &gLedInstance[0];
-        gResourceUri = (char *) "/a/led/0";
-    }
-    else if (ehRequest->resource == gLedInstance[1].handle)
-    {
-        currLEDResource = &gLedInstance[1];
-        gResourceUri = (char *) "/a/led/1";
-    }
-
-    if(OC_REST_PUT == ehRequest->method)
-    {
-        // Get pointer to query
-        int64_t pow;
-        if(OCRepPayloadGetPropInt(input, "power", &pow))
-        {
-            currLEDResource->power =pow;
-        }
-
-        bool state;
-        if(OCRepPayloadGetPropBool(input, "state", &state))
-        {
-            currLEDResource->state = state;
-        }
-    }
-
-    return getPayload(gResourceUri, currLEDResource->power, currLEDResource->state);
-}
-
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-
-    if(getResp)
-    {
-        *payload = getResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *putResp = constructResponse(ehRequest);
-
-    if(putResp)
-    {
-        *payload = putResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, OCRepPayload **payload)
-{
-    OCRepPayload *respPLPost_led = NULL;
-    OCEntityHandlerResult ehResult = OC_EH_OK;
-
-    /*
-     * The entity handler determines how to process a POST request.
-     * Per the REST paradigm, POST can also be used to update representation of existing
-     * resource or create a new resource.
-     * In the sample below, if the POST is for /a/led then a new instance of the LED
-     * resource is created with default representation (if representation is included in
-     * POST payload it can be used as initial values) as long as the instance is
-     * lesser than max new instance count. Once max instance count is reached, POST on
-     * /a/led updated the representation of /a/led (just like PUT)
-     */
-
-    if (ehRequest->resource == LED.handle)
-    {
-        if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
-        {
-            // Create new LED instance
-            char newLedUri[15] = "/a/led/";
-            int newLedUriLength = strlen(newLedUri);
-            snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance);
-
-            respPLPost_led = OCRepPayloadCreate();
-            OCRepPayloadSetUri(respPLPost_led, gResourceUri);
-            OCRepPayloadSetPropString(respPLPost_led, "createduri", newLedUri);
-
-            if (0 == createLEDResource (newLedUri, &gLedInstance[gCurrLedInstance], false, 0))
-            {
-                D2D_LOGE ( "Created new LED instance");
-                gLedInstance[gCurrLedInstance].state = 0;
-                gLedInstance[gCurrLedInstance].power = 0;
-                gCurrLedInstance++;
-                strncpy ((char *)response->resourceUri, newLedUri, MAX_URI_LENGTH);
-                ehResult = OC_EH_RESOURCE_CREATED;
-            }
-        }
-        else
-        {
-            respPLPost_led = constructResponse(ehRequest);
-        }
-    }
-    else
-    {
-        for (int i = 0; i < SAMPLE_MAX_NUM_POST_INSTANCE; i++)
-        {
-            if (ehRequest->resource == gLedInstance[i].handle)
-            {
-                if (i == 0)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                    break;
-                }
-                else if (i == 1)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                }
-            }
-        }
-    }
-
-    if (respPLPost_led != NULL)
-    {
-        *payload = respPLPost_led;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        D2D_LOGD ( "Payload was NULL");
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam)
-{
-    D2D_LOGD ( "Inside entity handler - flags: 0x%x", flag);
-    (void)callbackParam;
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
-    OCEntityHandlerResponse response;
-    memset(&response, 0, sizeof(response));
-
-    // Validate pointer
-    if (!entityHandlerRequest)
-    {
-        D2D_LOGE ( "Invalid request pointer");
-        return OC_EH_ERROR;
-    }
-
-    OCRepPayload* payload = NULL;
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        D2D_LOGE ( "Flag includes OC_REQUEST_FLAG");
-        if (entityHandlerRequest)
-        {
-            if (OC_REST_GET == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_GET from client");
-                ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_PUT == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_PUT from client");
-                ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_POST == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_POST from client");
-                ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
-            }
-            else
-            {
-                D2D_LOGD ( "Received unsupported method %d from client",
-                        entityHandlerRequest->method);
-                ehResult = OC_EH_ERROR;
-            }
-
-            if (ehResult == OC_EH_OK && ehResult != OC_EH_FORBIDDEN)
-            {
-                // Format the response.  Note this requires some info about the request
-                response.requestHandle = entityHandlerRequest->requestHandle;
-                response.resourceHandle = entityHandlerRequest->resource;
-                response.ehResult = ehResult;
-                response.payload = (OCPayload*)(payload);
-                response.numSendVendorSpecificHeaderOptions = 0;
-                memset(response.sendVendorSpecificHeaderOptions, 0,
-                       sizeof(response.sendVendorSpecificHeaderOptions));
-                memset(response.resourceUri, 0, sizeof(response.resourceUri));
-                // Indicate that response is NOT in a persistent buffer
-                response.persistentBufferFlag = 0;
-
-                // Send the response
-                if (OCDoResponse(&response) != OC_STACK_OK)
-                {
-                    D2D_LOGE( "Error sending response");
-                    ehResult = OC_EH_ERROR;
-                }
-            }
-        }
-    }
-
-    OCPayloadDestroy(response.payload);
-    return ehResult;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-OCStackResult confirmCB(void * ctx)
-{
-    OC_UNUSED(ctx);
-    for (;;)
-    {
-        int userConfirm;
-
-        printf("   > Press 1 for confirmation\n");
-        printf("   > Press 0 otherwise\n");
-
-        for (int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &userConfirm);
-            for (; 0x20<=getchar(); );  // for removing overflow garbage
-                                        // '0x20<=code' is character region
-        }
-        if (1 == userConfirm)
-        {
-            break;
-        }
-        else if (0 == userConfirm)
-        {
-            return OC_STACK_USER_DENIED_REQ;
-        }
-        printf("   Entered Wrong Number. Please Enter Again\n");
-    }
-    return OC_STACK_OK;
-}
-
-FILE* server_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), CRED_FILE);
-
-       (void)path;
-
-       return fopen(data_dir, mode);
-}
-
-int main(int argc, char **argv)
-{
-    struct timespec timeout;
-
-    D2D_LOGE( "OCServer is starting...");
-
-    int opt;
-    char cert_file[4096] = {0,};
-    char key_file[4096] = {0,};
-    char key_pass[32] = {0,};
-
-    // Set options
-    while ((opt = getopt(argc, argv, "c:k:p:")) != -1)
-    {
-        switch (opt)
-        {
-            case 'c':
-                strncpy(cert_file, optarg, sizeof(cert_file) - 1);
-                printf("Set own certificate file : %s\n", cert_file);
-                break;
-            case 'k':
-                strncpy(key_file, optarg, sizeof(key_file) - 1);
-                printf("Set private key file : %s\n", key_file);
-                break;
-            case 'p':
-                strncpy(key_pass, optarg, sizeof(key_pass) - 1);
-                printf("Set private key password : %s\n", key_pass);
-                break;
-            default:
-                printf("Not set any options\n");
-        }
-    }
-
-    // Initialize Persistent Storage for SVR database
-    OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink, NULL, NULL};
-
-    SetUserConfirmCB(NULL, confirmCB);
-
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack init error");
-        return 0;
-    }
-
-    // Register HW secure storage callback
-    if (0 < strlen(cert_file) && 0 < strlen(key_file))
-    {
-        if (0 == SSemulSetCertkeyFilepath(cert_file, key_file, key_pass))
-        {
-            if (0 != SetHwPkixCallbacks(HWGetKeyContext,
-                                                          HWFreeKeyContext,
-                                                          HWGetOwnCertificateChain,
-                                                          HWSetupPkContext))
-            {
-                printf("Fail to regist HW Pkix Callbacks");
-            }
-        }
-        else
-        {
-            printf("Fail to set cert/key file path");
-        }
-    }
-    else
-    {
-        printf("\n    [ Not set any mfg cert options ]\n");
-        printf("    Possible options: %s [-c certificate file path]"
-                " [-k key file path] [-p key password]\n\n", argv[0]);
-    }
-
-    /*
-     * Declare and create the example resource: LED
-     */
-    createLEDResource(gResourceUri, &LED, false, 0);
-
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    // Break from loop with Ctrl-C
-    D2D_LOGE( "Entering ocserver main loop...");
-    signal(SIGINT, handleSigInt);
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            return 0;
-        }
-        nanosleep(&timeout, NULL);
-    }
-
-    D2D_LOGE( "Exiting ocserver main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack process error");
-    }
-
-    return 0;
-}
-
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower)
-{
-    if (!uri)
-    {
-        D2D_LOGE( "Resource URI cannot be NULL");
-        return -1;
-    }
-
-    ledResource->state = resourceState;
-    ledResource->power= resourcePower;
-    OCStackResult res = OCCreateResource(&(ledResource->handle),
-            "core.led",
-            OC_RSRVD_INTERFACE_DEFAULT,
-            uri,
-            OCEntityHandlerCb,
-            NULL,
-            OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
-    D2D_LOGD( "Created LED resource with result: %s", getResult(res));
-
-    return 0;
-}
diff --git a/test/sampleserver_mvjustworks.cpp b/test/sampleserver_mvjustworks.cpp
deleted file mode 100644 (file)
index b67e533..0000000
+++ /dev/null
@@ -1,540 +0,0 @@
-/******************************************************************
-*
-* Copyright 2015 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-///////////////////////////////////////////////////////////////////////
-//NOTE :  This sample server is generated based on ocserverbasicops.cpp
-///////////////////////////////////////////////////////////////////////
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#include <signal.h>
-#include "ocstack.h"
-#include "ocpayload.h"
-#include "pinoxmcommon.h"
-#include "oxmverifycommon.h"
-
-#include <tzplatform_config.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-/** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */
-#ifdef ERROR
-#undef ERROR
-#endif //ERROR
-#endif //HAVE_WINDOWS_H
-#include "platform_features.h"
-#include "logger.h"
-
-#include <d2d-log.h>
-
-int gQuitFlag = 0;
-
-/* Structure to represent a LED resource */
-typedef struct LEDRESOURCE{
-    OCResourceHandle handle;
-    bool state;
-    int power;
-} LEDResource;
-
-static LEDResource LED;
-// This variable determines instance number of the LED resource.
-// Used by POST method to create a new instance of LED resource.
-static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE  2
-static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
-
-char *gResourceUri= (char *)"/a/led";
-
-//Secure Virtual Resource database for Iotivity Server
-//It contains Server's Identity and the PSK credentials
-//of other devices which the server trusts
-static char CRED_FILE[] = "oic_svr_db_server_mvjustworks.dat";
-
-/* Function that creates a new LED resource by calling the
- * OCCreateResource() method.
- */
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower);
-
-/* This method converts the payload to JSON format */
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest);
-
-/* Following methods process the PUT, GET, POST
- * requests
- */
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-                                        OCEntityHandlerResponse *response,
-                                        OCRepPayload **payload);
-
-/* Entity Handler callback functions */
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam);
-
-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_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";
-    #ifdef WITH_PRESENCE
-    case OC_STACK_PRESENCE_STOPPED:
-        return "OC_STACK_PRESENCE_STOPPED";
-    #endif
-    case OC_STACK_ERROR:
-        return "OC_STACK_ERROR";
-    default:
-        return "UNKNOWN";
-    }
-}
-
-OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if(!payload)
-    {
-        D2D_LOGE( "Failed to allocate Payload");
-        return NULL;
-    }
-
-    OCRepPayloadSetUri(payload, uri);
-    OCRepPayloadSetPropBool(payload, "state", state);
-    OCRepPayloadSetPropInt(payload, "power", power);
-
-    return payload;
-}
-
-//This function takes the request as an input and returns the response
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest)
-{
-    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        D2D_LOGE( "Incoming payload not a representation");
-        return NULL;
-    }
-
-    OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
-
-    LEDResource *currLEDResource = &LED;
-
-    if (ehRequest->resource == gLedInstance[0].handle)
-    {
-        currLEDResource = &gLedInstance[0];
-        gResourceUri = (char *) "/a/led/0";
-    }
-    else if (ehRequest->resource == gLedInstance[1].handle)
-    {
-        currLEDResource = &gLedInstance[1];
-        gResourceUri = (char *) "/a/led/1";
-    }
-
-    if(OC_REST_PUT == ehRequest->method)
-    {
-        // Get pointer to query
-        int64_t pow;
-        if(OCRepPayloadGetPropInt(input, "power", &pow))
-        {
-            currLEDResource->power =pow;
-        }
-
-        bool state;
-        if(OCRepPayloadGetPropBool(input, "state", &state))
-        {
-            currLEDResource->state = state;
-        }
-    }
-
-    return getPayload(gResourceUri, currLEDResource->power, currLEDResource->state);
-}
-
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-
-    if(getResp)
-    {
-        *payload = getResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *putResp = constructResponse(ehRequest);
-
-    if(putResp)
-    {
-        *payload = putResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, OCRepPayload **payload)
-{
-    OCRepPayload *respPLPost_led = NULL;
-    OCEntityHandlerResult ehResult = OC_EH_OK;
-
-    /*
-     * The entity handler determines how to process a POST request.
-     * Per the REST paradigm, POST can also be used to update representation of existing
-     * resource or create a new resource.
-     * In the sample below, if the POST is for /a/led then a new instance of the LED
-     * resource is created with default representation (if representation is included in
-     * POST payload it can be used as initial values) as long as the instance is
-     * lesser than max new instance count. Once max instance count is reached, POST on
-     * /a/led updated the representation of /a/led (just like PUT)
-     */
-
-    if (ehRequest->resource == LED.handle)
-    {
-        if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
-        {
-            // Create new LED instance
-            char newLedUri[15] = "/a/led/";
-            int newLedUriLength = strlen(newLedUri);
-            snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance);
-
-            respPLPost_led = OCRepPayloadCreate();
-            OCRepPayloadSetUri(respPLPost_led, gResourceUri);
-            OCRepPayloadSetPropString(respPLPost_led, "createduri", newLedUri);
-
-            if (0 == createLEDResource (newLedUri, &gLedInstance[gCurrLedInstance], false, 0))
-            {
-                D2D_LOGE ( "Created new LED instance");
-                gLedInstance[gCurrLedInstance].state = 0;
-                gLedInstance[gCurrLedInstance].power = 0;
-                gCurrLedInstance++;
-                strncpy ((char *)response->resourceUri, newLedUri, MAX_URI_LENGTH);
-                ehResult = OC_EH_RESOURCE_CREATED;
-            }
-        }
-        else
-        {
-            respPLPost_led = constructResponse(ehRequest);
-        }
-    }
-    else
-    {
-        for (int i = 0; i < SAMPLE_MAX_NUM_POST_INSTANCE; i++)
-        {
-            if (ehRequest->resource == gLedInstance[i].handle)
-            {
-                if (i == 0)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                    break;
-                }
-                else if (i == 1)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                }
-            }
-        }
-    }
-
-    if (respPLPost_led != NULL)
-    {
-        *payload = respPLPost_led;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        D2D_LOGD ( "Payload was NULL");
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam)
-{
-    D2D_LOGD ( "Inside entity handler - flags: 0x%x", flag);
-    (void)callbackParam;
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
-    OCEntityHandlerResponse response;
-    memset(&response, 0, sizeof(response));
-
-    // Validate pointer
-    if (!entityHandlerRequest)
-    {
-        D2D_LOGE ( "Invalid request pointer");
-        return OC_EH_ERROR;
-    }
-
-    OCRepPayload* payload = NULL;
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        D2D_LOGE ( "Flag includes OC_REQUEST_FLAG");
-        if (entityHandlerRequest)
-        {
-            if (OC_REST_GET == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_GET from client");
-                ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_PUT == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_PUT from client");
-                ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_POST == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_POST from client");
-                ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
-            }
-            else
-            {
-                D2D_LOGD ( "Received unsupported method %d from client",
-                        entityHandlerRequest->method);
-                ehResult = OC_EH_ERROR;
-            }
-
-            if (ehResult == OC_EH_OK && ehResult != OC_EH_FORBIDDEN)
-            {
-                // Format the response.  Note this requires some info about the request
-                response.requestHandle = entityHandlerRequest->requestHandle;
-                response.resourceHandle = entityHandlerRequest->resource;
-                response.ehResult = ehResult;
-                response.payload = (OCPayload*)(payload);
-                response.numSendVendorSpecificHeaderOptions = 0;
-                memset(response.sendVendorSpecificHeaderOptions, 0,
-                       sizeof(response.sendVendorSpecificHeaderOptions));
-                memset(response.resourceUri, 0, sizeof(response.resourceUri));
-                // Indicate that response is NOT in a persistent buffer
-                response.persistentBufferFlag = 0;
-
-                // Send the response
-                if (OCDoResponse(&response) != OC_STACK_OK)
-                {
-                    D2D_LOGE( "Error sending response");
-                    ehResult = OC_EH_ERROR;
-                }
-            }
-        }
-    }
-
-    OCPayloadDestroy(response.payload);
-    return ehResult;
-}
-
-OCStackResult displayNumCB(void * ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN])
-{
-    OC_UNUSED(ctx);
-    D2D_LOGE( "IN displayNumCB");
-    D2D_LOGE( "############ mutualVerifNum ############");
-    D2D_LOGD( mutualVerifNum, MUTUAL_VERIF_NUM_LEN);
-    D2D_LOGE( "############ mutualVerifNum ############");
-    D2D_LOGE( "OUT displayNumCB");
-    return OC_STACK_OK;
-}
-
-OCStackResult confirmNumCB(void * ctx)
-{
-    OC_UNUSED(ctx);
-    for (;;)
-    {
-        int userConfirm;
-
-        printf("   > Press 1 for confirmation\n");
-        printf("   > Press 0 otherwise\n");
-
-        for (int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &userConfirm);
-            for (; 0x20<=getchar(); );  // for removing overflow garbage
-                                        // '0x20<=code' is character region
-        }
-        if (1 == userConfirm)
-        {
-            break;
-        }
-        else if (0 == userConfirm)
-        {
-            return OC_STACK_ERROR;
-        }
-        printf("   Entered Wrong Number. Please Enter Again\n");
-    }
-    return OC_STACK_OK;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-FILE* server_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), CRED_FILE);
-
-       (void)path;
-
-       return fopen(data_dir, mode);
-}
-
-int main()
-{
-    struct timespec timeout;
-
-    D2D_LOGE( "OCServer is starting...");
-
-    // Set callbacks for verification
-    SetDisplayNumCB(NULL, displayNumCB);
-    SetUserConfirmCB(NULL, confirmNumCB);
-
-    // Set Verification Option for ownership transfer
-    // Currently, BOTH display AND confirm
-    SetVerifyOption((VerifyOptionBitmask_t)(DISPLAY_NUM | USER_CONFIRM));
-
-    // Initialize Persistent Storage for SVR database
-    OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink, NULL, NULL};
-
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack init error");
-        return 0;
-    }
-
-    /*
-     * Declare and create the example resource: LED
-     */
-    createLEDResource(gResourceUri, &LED, false, 0);
-
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    // Break from loop with Ctrl-C
-    D2D_LOGE( "Entering ocserver main loop...");
-    signal(SIGINT, handleSigInt);
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            return 0;
-        }
-        nanosleep(&timeout, NULL);
-    }
-
-    D2D_LOGE( "Exiting ocserver main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack process error");
-    }
-
-    return 0;
-}
-
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower)
-{
-    if (!uri)
-    {
-        D2D_LOGE( "Resource URI cannot be NULL");
-        return -1;
-    }
-
-    ledResource->state = resourceState;
-    ledResource->power= resourcePower;
-    OCStackResult res = OCCreateResource(&(ledResource->handle),
-            "core.led",
-            OC_RSRVD_INTERFACE_DEFAULT,
-            uri,
-            OCEntityHandlerCb,
-            NULL,
-            OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
-    D2D_LOGD( "Created LED resource with result: %s", getResult(res));
-
-    return 0;
-}
diff --git a/test/sampleserver_preconfpin.cpp b/test/sampleserver_preconfpin.cpp
deleted file mode 100644 (file)
index 138ed6c..0000000
+++ /dev/null
@@ -1,491 +0,0 @@
-/******************************************************************
-*
-* Copyright 2015 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-///////////////////////////////////////////////////////////////////////
-//NOTE :  This sample server is generated based on ocserverbasicops.cpp
-///////////////////////////////////////////////////////////////////////
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#include <signal.h>
-#include "ocstack.h"
-#include "ocpayload.h"
-#include "pinoxmcommon.h"
-
-#include <tzplatform_config.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-/** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */
-#ifdef ERROR
-#undef ERROR
-#endif //ERROR
-#endif //HAVE_WINDOWS_H
-#include "platform_features.h"
-#include "logger.h"
-
-
-#define TAG "SAMPLE_PRECONF_PIN"
-
-int gQuitFlag = 0;
-
-/* Structure to represent a LED resource */
-typedef struct LEDRESOURCE{
-    OCResourceHandle handle;
-    bool state;
-    int power;
-} LEDResource;
-
-static LEDResource LED;
-// This variable determines instance number of the LED resource.
-// Used by POST method to create a new instance of LED resource.
-static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE  2
-static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
-
-char *gResourceUri= (char *)"/a/led";
-
-//Secure Virtual Resource database for Iotivity Server
-//It contains Server's Identity and the PSK credentials
-//of other devices which the server trusts
-static char CRED_FILE[] = "oic_svr_db_server_preconfpin.dat";
-
-/* Function that creates a new LED resource by calling the
- * OCCreateResource() method.
- */
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower);
-
-/* This method converts the payload to JSON format */
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest);
-
-/* Following methods process the PUT, GET, POST
- * requests
- */
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-                                        OCEntityHandlerResponse *response,
-                                        OCRepPayload **payload);
-
-/* Entity Handler callback functions */
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam);
-
-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_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";
-    #ifdef WITH_PRESENCE
-    case OC_STACK_PRESENCE_STOPPED:
-        return "OC_STACK_PRESENCE_STOPPED";
-    #endif
-    case OC_STACK_ERROR:
-        return "OC_STACK_ERROR";
-    default:
-        return "UNKNOWN";
-    }
-}
-
-OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if(!payload)
-    {
-        D2D_LOGE( "Failed to allocate Payload");
-        return NULL;
-    }
-
-    OCRepPayloadSetUri(payload, uri);
-    OCRepPayloadSetPropBool(payload, "state", state);
-    OCRepPayloadSetPropInt(payload, "power", power);
-
-    return payload;
-}
-
-//This function takes the request as an input and returns the response
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest)
-{
-    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        D2D_LOGE( "Incoming payload not a representation");
-        return NULL;
-    }
-
-    OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
-
-    LEDResource *currLEDResource = &LED;
-
-    if (ehRequest->resource == gLedInstance[0].handle)
-    {
-        currLEDResource = &gLedInstance[0];
-        gResourceUri = (char *) "/a/led/0";
-    }
-    else if (ehRequest->resource == gLedInstance[1].handle)
-    {
-        currLEDResource = &gLedInstance[1];
-        gResourceUri = (char *) "/a/led/1";
-    }
-
-    if(OC_REST_PUT == ehRequest->method)
-    {
-        // Get pointer to query
-        int64_t pow;
-        if(OCRepPayloadGetPropInt(input, "power", &pow))
-        {
-            currLEDResource->power =pow;
-        }
-
-        bool state;
-        if(OCRepPayloadGetPropBool(input, "state", &state))
-        {
-            currLEDResource->state = state;
-        }
-    }
-
-    return getPayload(gResourceUri, currLEDResource->power, currLEDResource->state);
-}
-
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-
-    if(getResp)
-    {
-        *payload = getResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *putResp = constructResponse(ehRequest);
-
-    if(putResp)
-    {
-        *payload = putResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, OCRepPayload **payload)
-{
-    OCRepPayload *respPLPost_led = NULL;
-    OCEntityHandlerResult ehResult = OC_EH_OK;
-
-    /*
-     * The entity handler determines how to process a POST request.
-     * Per the REST paradigm, POST can also be used to update representation of existing
-     * resource or create a new resource.
-     * In the sample below, if the POST is for /a/led then a new instance of the LED
-     * resource is created with default representation (if representation is included in
-     * POST payload it can be used as initial values) as long as the instance is
-     * lesser than max new instance count. Once max instance count is reached, POST on
-     * /a/led updated the representation of /a/led (just like PUT)
-     */
-
-    if (ehRequest->resource == LED.handle)
-    {
-        if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
-        {
-            // Create new LED instance
-            char newLedUri[15] = "/a/led/";
-            int newLedUriLength = strlen(newLedUri);
-            snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance);
-
-            respPLPost_led = OCRepPayloadCreate();
-            OCRepPayloadSetUri(respPLPost_led, gResourceUri);
-            OCRepPayloadSetPropString(respPLPost_led, "createduri", newLedUri);
-
-            if (0 == createLEDResource (newLedUri, &gLedInstance[gCurrLedInstance], false, 0))
-            {
-                D2D_LOGE ( "Created new LED instance");
-                gLedInstance[gCurrLedInstance].state = 0;
-                gLedInstance[gCurrLedInstance].power = 0;
-                gCurrLedInstance++;
-                strncpy ((char *)response->resourceUri, newLedUri, sizeof(response->resourceUri));
-                ehResult = OC_EH_RESOURCE_CREATED;
-            }
-        }
-        else
-        {
-            respPLPost_led = constructResponse(ehRequest);
-        }
-    }
-    else
-    {
-        for (int i = 0; i < SAMPLE_MAX_NUM_POST_INSTANCE; i++)
-        {
-            if (ehRequest->resource == gLedInstance[i].handle)
-            {
-                if (i == 0)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                    break;
-                }
-                else if (i == 1)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                }
-            }
-        }
-    }
-
-    if (respPLPost_led != NULL)
-    {
-        *payload = respPLPost_led;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        D2D_LOGD ( "Payload was NULL");
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam)
-{
-    D2D_LOGD ( "Inside entity handler - flags: 0x%x", flag);
-    (void)callbackParam;
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
-    OCEntityHandlerResponse response;
-    memset(&response, 0, sizeof(response));
-
-    // Validate pointer
-    if (!entityHandlerRequest)
-    {
-        D2D_LOGE ( "Invalid request pointer");
-        return OC_EH_ERROR;
-    }
-
-    OCRepPayload* payload = NULL;
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        D2D_LOGE ( "Flag includes OC_REQUEST_FLAG");
-        if (entityHandlerRequest)
-        {
-            if (OC_REST_GET == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_GET from client");
-                ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_PUT == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_PUT from client");
-                ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_POST == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_POST from client");
-                ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
-            }
-            else
-            {
-                D2D_LOGD ( "Received unsupported method %d from client",
-                        entityHandlerRequest->method);
-                ehResult = OC_EH_ERROR;
-            }
-
-            if (ehResult == OC_EH_OK && ehResult != OC_EH_FORBIDDEN)
-            {
-                // Format the response.  Note this requires some info about the request
-                response.requestHandle = entityHandlerRequest->requestHandle;
-                response.resourceHandle = entityHandlerRequest->resource;
-                response.ehResult = ehResult;
-                response.payload = (OCPayload*)(payload);
-                response.numSendVendorSpecificHeaderOptions = 0;
-                memset(response.sendVendorSpecificHeaderOptions, 0,
-                       sizeof(response.sendVendorSpecificHeaderOptions));
-                memset(response.resourceUri, 0, sizeof(response.resourceUri));
-                // Indicate that response is NOT in a persistent buffer
-                response.persistentBufferFlag = 0;
-
-                // Send the response
-                if (OCDoResponse(&response) != OC_STACK_OK)
-                {
-                    D2D_LOGE( "Error sending response");
-                    ehResult = OC_EH_ERROR;
-                }
-            }
-        }
-    }
-
-    OCPayloadDestroy(response.payload);
-    return ehResult;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-FILE* server_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), CRED_FILE);
-    (void)path;
-
-    return fopen(data_dir, mode);
-}
-
-int main()
-{
-    struct timespec timeout;
-
-    D2D_LOGE( "OCServer is starting...");
-
-    // Initialize Persistent Storage for SVR database
-    OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink};
-
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack init error");
-        return 0;
-    }
-
-    /*
-     * Declare and create the example resource: LED
-     */
-    createLEDResource(gResourceUri, &LED, false, 0);
-
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    // Break from loop with Ctrl-C
-    D2D_LOGE( "Entering ocserver main loop...");
-    signal(SIGINT, handleSigInt);
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            return 0;
-        }
-        nanosleep(&timeout, NULL);
-    }
-
-    D2D_LOGE( "Exiting ocserver main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack process error");
-    }
-
-    return 0;
-}
-
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower)
-{
-    if (!uri)
-    {
-        D2D_LOGE( "Resource URI cannot be NULL");
-        return -1;
-    }
-
-    ledResource->state = resourceState;
-    ledResource->power= resourcePower;
-    OCStackResult res = OCCreateResource(&(ledResource->handle),
-            "core.led",
-            OC_RSRVD_INTERFACE_DEFAULT,
-            uri,
-            OCEntityHandlerCb,
-            NULL,
-            OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
-    D2D_LOGD( "Created LED resource with result: %s", getResult(res));
-
-    return 0;
-}
diff --git a/test/sampleserver_randompin.cpp b/test/sampleserver_randompin.cpp
deleted file mode 100644 (file)
index b68994e..0000000
+++ /dev/null
@@ -1,592 +0,0 @@
-/******************************************************************
-*
-* Copyright 2015 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-///////////////////////////////////////////////////////////////////////
-//NOTE :  This sample server is generated based on ocserverbasicops.cpp
-///////////////////////////////////////////////////////////////////////
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_TIME_H
-#include <time.h>
-#endif
-#include <signal.h>
-#include "ocstack.h"
-#include "ocpayload.h"
-#include "pinoxmcommon.h"
-
-#include <tzplatform_config.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-/** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */
-#ifdef ERROR
-#undef ERROR
-#endif //ERROR
-#endif //HAVE_WINDOWS_H
-#include "platform_features.h"
-#include "logger.h"
-
-#define TAG "SAMPLE_RANDOMPIN"
-
-int gQuitFlag = 0;
-
-/* Structure to represent a LED resource */
-typedef struct LEDRESOURCE{
-    OCResourceHandle handle;
-    bool state;
-    int power;
-} LEDResource;
-
-static LEDResource LED;
-// This variable determines instance number of the LED resource.
-// Used by POST method to create a new instance of LED resource.
-static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE  2
-static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
-
-char *gResourceUri= (char *)"/a/led";
-
-//Secure Virtual Resource database for Iotivity Server
-//It contains Server's Identity and the PSK credentials
-//of other devices which the server trusts
-static char CRED_FILE[] = "oic_svr_db_server_randompin.dat";
-
-/* Function that creates a new LED resource by calling the
- * OCCreateResource() method.
- */
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower);
-
-/* This method converts the payload to JSON format */
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest);
-
-/* Following methods process the PUT, GET, POST
- * requests
- */
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-                                        OCEntityHandlerResponse *response,
-                                        OCRepPayload **payload);
-
-/* Entity Handler callback functions */
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam);
-
-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_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";
-    #ifdef WITH_PRESENCE
-    case OC_STACK_PRESENCE_STOPPED:
-        return "OC_STACK_PRESENCE_STOPPED";
-    #endif
-    case OC_STACK_ERROR:
-        return "OC_STACK_ERROR";
-    default:
-        return "UNKNOWN";
-    }
-}
-
-#ifdef MULTIPLE_OWNER
-
-#include <assert.h>
-#include <thread>
-#include <chrono>
-
-static bool volatile g_LoopFlag;
-static std::thread* oc_process_thread;
-
-static void oc_process_loop()
-{
-    while(g_LoopFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            g_LoopFlag = false;
-            break;
-        }
-        std::this_thread::sleep_for(std::chrono::milliseconds(100));
-    }
-}
-
-static void StartOCProcessThread()
-{
-    g_LoopFlag = true;
-    oc_process_thread = new std::thread(oc_process_loop);
-}
-
-static void StopOCProcessThread()
-{
-    assert(oc_process_thread->joinable() == true);
-    g_LoopFlag = false;
-    oc_process_thread->join();
-}
-#endif //MULTIPLE_OWNER
-
-OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if(!payload)
-    {
-        D2D_LOGE( "Failed to allocate Payload");
-        return NULL;
-    }
-
-    OCRepPayloadSetUri(payload, uri);
-    OCRepPayloadSetPropBool(payload, "state", state);
-    OCRepPayloadSetPropInt(payload, "power", power);
-
-    return payload;
-}
-
-//This function takes the request as an input and returns the response
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest)
-{
-    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        D2D_LOGE( "Incoming payload not a representation");
-        return NULL;
-    }
-
-    OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
-
-    LEDResource *currLEDResource = &LED;
-
-    if (ehRequest->resource == gLedInstance[0].handle)
-    {
-        currLEDResource = &gLedInstance[0];
-        gResourceUri = (char *) "/a/led/0";
-    }
-    else if (ehRequest->resource == gLedInstance[1].handle)
-    {
-        currLEDResource = &gLedInstance[1];
-        gResourceUri = (char *) "/a/led/1";
-    }
-
-    if(OC_REST_PUT == ehRequest->method)
-    {
-        // Get pointer to query
-        int64_t pow;
-        if(OCRepPayloadGetPropInt(input, "power", &pow))
-        {
-            currLEDResource->power =pow;
-        }
-
-        bool state;
-        if(OCRepPayloadGetPropBool(input, "state", &state))
-        {
-            currLEDResource->state = state;
-        }
-    }
-
-    return getPayload(gResourceUri, currLEDResource->power, currLEDResource->state);
-}
-
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-
-    if(getResp)
-    {
-        *payload = getResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *putResp = constructResponse(ehRequest);
-
-    if(putResp)
-    {
-        *payload = putResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, OCRepPayload **payload)
-{
-    OCRepPayload *respPLPost_led = NULL;
-    OCEntityHandlerResult ehResult = OC_EH_OK;
-
-    /*
-     * The entity handler determines how to process a POST request.
-     * Per the REST paradigm, POST can also be used to update representation of existing
-     * resource or create a new resource.
-     * In the sample below, if the POST is for /a/led then a new instance of the LED
-     * resource is created with default representation (if representation is included in
-     * POST payload it can be used as initial values) as long as the instance is
-     * lesser than max new instance count. Once max instance count is reached, POST on
-     * /a/led updated the representation of /a/led (just like PUT)
-     */
-
-    if (ehRequest->resource == LED.handle)
-    {
-        if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
-        {
-            // Create new LED instance
-            char newLedUri[15] = "/a/led/";
-            int newLedUriLength = strlen(newLedUri);
-            snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance);
-
-            respPLPost_led = OCRepPayloadCreate();
-            OCRepPayloadSetUri(respPLPost_led, gResourceUri);
-            OCRepPayloadSetPropString(respPLPost_led, "createduri", newLedUri);
-
-            if (0 == createLEDResource (newLedUri, &gLedInstance[gCurrLedInstance], false, 0))
-            {
-                D2D_LOGE ( "Created new LED instance");
-                gLedInstance[gCurrLedInstance].state = 0;
-                gLedInstance[gCurrLedInstance].power = 0;
-                gCurrLedInstance++;
-                strncpy ((char *)response->resourceUri, newLedUri, sizeof(response->resourceUri));
-                ehResult = OC_EH_RESOURCE_CREATED;
-            }
-        }
-        else
-        {
-            respPLPost_led = constructResponse(ehRequest);
-        }
-    }
-    else
-    {
-        for (int i = 0; i < SAMPLE_MAX_NUM_POST_INSTANCE; i++)
-        {
-            if (ehRequest->resource == gLedInstance[i].handle)
-            {
-                if (i == 0)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                    break;
-                }
-                else if (i == 1)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                }
-            }
-        }
-    }
-
-    if (respPLPost_led != NULL)
-    {
-        *payload = respPLPost_led;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        D2D_LOGD ( "Payload was NULL");
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam)
-{
-    D2D_LOGD ( "Inside entity handler - flags: 0x%x", flag);
-    (void)callbackParam;
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
-    OCEntityHandlerResponse response;
-    memset(&response, 0, sizeof(response));
-
-    // Validate pointer
-    if (!entityHandlerRequest)
-    {
-        D2D_LOGE ( "Invalid request pointer");
-        return OC_EH_ERROR;
-    }
-
-    OCRepPayload* payload = NULL;
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        D2D_LOGE ( "Flag includes OC_REQUEST_FLAG");
-        if (entityHandlerRequest)
-        {
-            if (OC_REST_GET == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_GET from client");
-                ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_PUT == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_PUT from client");
-                ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_POST == entityHandlerRequest->method)
-            {
-                D2D_LOGE ( "Received OC_REST_POST from client");
-                ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
-            }
-            else
-            {
-                D2D_LOGD ( "Received unsupported method %d from client",
-                        entityHandlerRequest->method);
-                ehResult = OC_EH_ERROR;
-            }
-
-            if (ehResult == OC_EH_OK && ehResult != OC_EH_FORBIDDEN)
-            {
-                // Format the response.  Note this requires some info about the request
-                response.requestHandle = entityHandlerRequest->requestHandle;
-                response.resourceHandle = entityHandlerRequest->resource;
-                response.ehResult = ehResult;
-                response.payload = (OCPayload*)(payload);
-                response.numSendVendorSpecificHeaderOptions = 0;
-                memset(response.sendVendorSpecificHeaderOptions, 0,
-                       sizeof(response.sendVendorSpecificHeaderOptions));
-                memset(response.resourceUri, 0, sizeof(response.resourceUri));
-                // Indicate that response is NOT in a persistent buffer
-                response.persistentBufferFlag = 0;
-
-                // Send the response
-                if (OCDoResponse(&response) != OC_STACK_OK)
-                {
-                    D2D_LOGE( "Error sending response");
-                    ehResult = OC_EH_ERROR;
-                }
-            }
-        }
-    }
-
-    OCPayloadDestroy(response.payload);
-    return ehResult;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-FILE* server_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), CRED_FILE);
-    (void)path;
-
-    return fopen(data_dir, mode);
-}
-
-void GeneratePinCB(char* pin, size_t pinSize)
-{
-    if(NULL == pin || pinSize <= 0)
-    {
-        D2D_LOGE( "Invalid PIN");
-        return;
-    }
-
-    D2D_LOGE( "============================");
-    D2D_LOGD( "    PIN CODE : %s", pin);
-    D2D_LOGE( "============================");
-}
-
-void ClosePinDisplayCB(void)
-{
-    D2D_LOGE( "============================");
-    D2D_LOGE( "    PIN DISPLAY CLOSED.");
-    D2D_LOGE( "============================");
-}
-
-int main()
-{
-    D2D_LOGE( "OCServer is starting...");
-
-    // Initialize Persistent Storage for SVR database
-    OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink, NULL, NULL};
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack init error");
-        return 0;
-    }
-
-   /**
-     * If server supported random pin based ownership transfer,
-     * callback of print PIN should be registered before runing server.
-     */
-    SetGeneratePinCB(GeneratePinCB);
-
-    /**
-     * If ther server supports random pin based OTM,
-     * the callback to close PIN display can be registered.
-     * This callback will be invoked when random PIN based OTM is done.
-     */
-    SetClosePinDisplayCB(ClosePinDisplayCB);
-
-    /**
-     * Random PIN generation policy can be changed through SetRandomPinPolicy() API.
-     * first param : byte length of random PIN ( 4 <= first param <= 32)
-     * second param : PIN type (This is bitmask)
-     */
-    if(OC_STACK_OK != SetRandomPinPolicy(8, NUM_PIN))
-    {
-        D2D_LOGE( "Failed to setting PIN policy");
-        return 0;
-    }
-
-    /*
-     * Declare and create the example resource: LED
-     */
-    createLEDResource(gResourceUri, &LED, false, 0);
-
-    // Break from loop with Ctrl-C
-    D2D_LOGE( "Entering ocserver main loop...");
-    signal(SIGINT, handleSigInt);
-
-#ifdef MULTIPLE_OWNER
-    StartOCProcessThread();
-
-    while(!gQuitFlag)
-    {
-        printf("Press 'G' to generate random PIN...\n");
-        printf("Press 'E' to exit...\n");
-        char in = getchar();
-        if('G' == in || 'g' == in)
-        {
-            char ranPin[OXM_RANDOM_PIN_MAX_SIZE + 1] = {0};
-            GeneratePin(ranPin, sizeof(ranPin));
-        }
-        if('E' == in || 'e' == in)
-        {
-            break;
-        }
-    }
-
-    StopOCProcessThread();
-#else
-    struct timespec timeout;
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            D2D_LOGE( "OCStack process error");
-            return 0;
-        }
-        nanosleep(&timeout, NULL);
-    }
-#endif //MULTIPLE_OWNER
-
-    D2D_LOGE( "Exiting ocserver main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        D2D_LOGE( "OCStack process error");
-    }
-
-    return 0;
-}
-
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower)
-{
-    if (!uri)
-    {
-        D2D_LOGE( "Resource URI cannot be NULL");
-        return -1;
-    }
-
-    ledResource->state = resourceState;
-    ledResource->power= resourcePower;
-    OCStackResult res = OCCreateResource(&(ledResource->handle),
-            "core.led",
-            OC_RSRVD_INTERFACE_DEFAULT,
-            uri,
-            OCEntityHandlerCb,
-            NULL,
-            OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
-    D2D_LOGD( "Created LED resource with result: %s", getResult(res));
-
-    return 0;
-}
diff --git a/test/ss_emul.c b/test/ss_emul.c
deleted file mode 100644 (file)
index 3f3564f..0000000
+++ /dev/null
@@ -1,364 +0,0 @@
-/* *****************************************************************\r
- *\r
- * Copyright 2017 Samsung Electronics 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
-#include <stdio.h>\r
-#include <string.h>\r
-\r
-#include "oic_malloc.h"\r
-#include "logger.h"\r
-#include "hw_emul/ss_emul.h"\r
-#include <d2d-log.h>\r
-\r
-#define HWIF_MAXPATH (4096)\r
-static char HWIF_OWNCERT_FILE_NAME[HWIF_MAXPATH] = {0,};\r
-static char HWIF_KEY_FILE_NAME[HWIF_MAXPATH] = {0,};\r
-static char HWIF_KEY_PASS[HWIF_MAXPATH] = {0,};\r
-\r
-\r
-/********************************************\r
- * utility functions\r
- */\r
-\r
-int LoadCertFile(const char* filepath, uint8_t** cert_chain, size_t* cert_chain_len)\r
-{\r
-    if (NULL == filepath || NULL == cert_chain || NULL == cert_chain_len)\r
-    {\r
-        D2D_LOGE("Invalid parameters");\r
-        return -1;\r
-    }\r
-\r
-    uint8_t *certchain;\r
-    size_t certLen;\r
-\r
-    FILE *fp = fopen(filepath, "rb");\r
-    if (fp)\r
-    {\r
-        char buffer[1024];\r
-        size_t fsize = 0;\r
-        size_t bytesRead = 0;\r
-        do\r
-        {\r
-            bytesRead = fread(buffer, 1, sizeof(buffer), fp);\r
-            fsize += bytesRead;\r
-        } while (bytesRead);\r
-\r
-        if (!fsize)\r
-        {\r
-            D2D_LOGE("File is empty");\r
-            fclose(fp);\r
-            return -1;\r
-        }\r
-\r
-        certchain = (uint8_t*)OICCalloc(1, fsize);\r
-        certLen = fsize;\r
-        if (NULL == certchain)\r
-        {\r
-            D2D_LOGE("Failed to allocate memory");\r
-            fclose(fp);\r
-            return -1;\r
-        }\r
-\r
-        rewind(fp);\r
-        if (fsize != fread(certchain, 1, fsize, fp))\r
-        {\r
-            D2D_LOGE("Certiface was not read completely");\r
-        }\r
-        fclose(fp);\r
-    }\r
-    else\r
-    {\r
-        D2D_LOGD("Failed to open cert file : %s", filepath);\r
-        return -1;\r
-    }\r
-\r
-    *cert_chain = certchain;\r
-    *cert_chain_len = certLen;\r
-\r
-    D2D_LOGD("Loading cert success [%s]", filepath);\r
-    D2D_LOGD("%s %s",certchain, certLen);\r
-    return 0;\r
-}\r
-\r
-\r
-int LoadKeyFile(mbedtls_pk_context *pkey, const char* filepath, const char* password)\r
-{\r
-    if(!filepath)\r
-    {\r
-        D2D_LOGE("Invalid key file path" );\r
-        return -1;\r
-    }\r
-\r
-    int ret = mbedtls_pk_parse_keyfile(pkey, filepath, password);\r
-    if( ret != 0 )\r
-    {\r
-        D2D_LOGD("Faile to parse key file [0x%x]", ret );\r
-        return ret;\r
-    }\r
-\r
-    D2D_LOGD( "Loading key success [%s]", filepath);\r
-    return ret;\r
-}\r
-\r
-\r
-/********************************************\r
- * HW Secure Storage emulation functions\r
- */\r
-int SSemulSetCertkeyFilepath(const char* cert_filepath,\r
-                                            const char* key_filepath, const char* pwd)\r
-{\r
-    if (NULL == cert_filepath || NULL == key_filepath)\r
-    {\r
-        D2D_LOGE("Invalid parameters");\r
-        return -1;\r
-    }\r
-\r
-    if (HWIF_MAXPATH <= strlen(cert_filepath) || !strlen(cert_filepath)\r
-        || HWIF_MAXPATH <= strlen(key_filepath) || !strlen(key_filepath)\r
-        || (pwd && (HWIF_MAXPATH <= strlen(pwd))))\r
-    {\r
-        D2D_LOGE( "Invalid large path length");\r
-        return -1;\r
-    }\r
-\r
-    memset(HWIF_OWNCERT_FILE_NAME, 0, HWIF_MAXPATH);\r
-    memset(HWIF_KEY_FILE_NAME, 0, HWIF_MAXPATH);\r
-    memset(HWIF_KEY_PASS, 0, HWIF_MAXPATH);\r
-\r
-    strncpy(HWIF_OWNCERT_FILE_NAME, cert_filepath, strlen(cert_filepath));\r
-    strncpy(HWIF_KEY_FILE_NAME, key_filepath, strlen(key_filepath));\r
-    if (pwd)\r
-    {\r
-        strncpy(HWIF_KEY_PASS, pwd, strlen(pwd) + 1);\r
-    }\r
-\r
-    D2D_LOGE("[Configure Secure Storage Emulation files]");\r
-    D2D_LOGD("OwnCert file[%zu]: %s", strlen(cert_filepath), cert_filepath);\r
-    D2D_LOGD("Key file[%zu]: %s", strlen(key_filepath), key_filepath);\r
-    if (pwd)\r
-    {\r
-        D2D_LOGD("Password[%zu]: %s", strlen(pwd), pwd);\r
-    }\r
-    return 0;\r
-}\r
-\r
-int SSemulGetKeytype(const void* keyContext)\r
-{\r
-    (void)keyContext;\r
-    if (0 == strlen(HWIF_KEY_FILE_NAME))\r
-    {\r
-        D2D_LOGE("Need to set key file name");\r
-        return KEYTYPE_NONE;\r
-    }\r
-\r
-    int ret = KEYTYPE_NONE;\r
-    mbedtls_pk_context pk;\r
-    mbedtls_pk_init(&pk);\r
-\r
-    // 1. load key\r
-    const char* key_file = HWIF_KEY_FILE_NAME;\r
-    const char* key_pass = !strlen(HWIF_KEY_PASS) ? NULL : HWIF_KEY_PASS;\r
-    if (0 > LoadKeyFile(&pk, key_file, key_pass))\r
-    {\r
-        D2D_LOGE("Fail to load key file");\r
-        goto exit;\r
-    }\r
-\r
-    // 2. get key type\r
-    mbedtls_pk_type_t keytype = mbedtls_pk_get_type(&pk);\r
-    if(MBEDTLS_PK_RSA == keytype)\r
-    {\r
-        ret = KEYTYPE_RSA;\r
-    }\r
-    else if(MBEDTLS_PK_ECKEY == keytype ||\r
-               MBEDTLS_PK_ECKEY_DH == keytype)\r
-    {\r
-        ret = KEYTYPE_ECC;\r
-    }\r
-\r
-exit:\r
-    mbedtls_pk_free(&pk);\r
-    return ret;\r
-}\r
-\r
-int SSemulLoadOwncert(const void* keyContext,\r
-                                           uint8_t** cert_chain, size_t* cert_chain_len)\r
-{\r
-    (void)keyContext;\r
-    if (0 == strlen(HWIF_OWNCERT_FILE_NAME))\r
-    {\r
-        D2D_LOGE("Need to set owncert file name");\r
-        return -1;\r
-    }\r
-\r
-    if (0 != LoadCertFile(HWIF_OWNCERT_FILE_NAME, cert_chain, cert_chain_len))\r
-    {\r
-        D2D_LOGE("Faile to load the own certificate file");\r
-        return -1;\r
-    }\r
-\r
-    return 0;\r
-}\r
-\r
-int SSemulGetKeylen(const void* keyContext)\r
-{\r
-    (void)keyContext;\r
-    if (0 == strlen(HWIF_KEY_FILE_NAME))\r
-    {\r
-        D2D_LOGE( "Need to set private key file name");\r
-        return -1;\r
-    }\r
-\r
-    int ret = -1;\r
-    size_t key_len = 0;\r
-    mbedtls_pk_context pk;\r
-    mbedtls_pk_init(&pk);\r
-\r
-    // 1. load key\r
-    const char* key_file = HWIF_KEY_FILE_NAME;\r
-    const char* key_pass = !strlen(HWIF_KEY_PASS) ? NULL : HWIF_KEY_PASS;\r
-    ret = LoadKeyFile(&pk, key_file, key_pass);\r
-    if (0 > ret)\r
-    {\r
-        D2D_LOGD("Fail to load key file [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-\r
-    key_len = ( 8 * ((const mbedtls_rsa_context *) pk.pk_ctx)->len );\r
-    if(0 >= key_len)\r
-    {\r
-        D2D_LOGE("Invalid key length");\r
-        goto exit;\r
-    }\r
-\r
-exit:\r
-    mbedtls_pk_free(&pk);\r
-    return key_len;\r
-}\r
-\r
-int SSemulRsaSign(const void *keyContext,\r
-                            int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,\r
-                            int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,\r
-                            const unsigned char *hash, unsigned char *sig )\r
-{\r
-    if (0 == strlen(HWIF_KEY_FILE_NAME))\r
-    {\r
-        D2D_LOGE("Need to set private key file name");\r
-        return -1;\r
-    }\r
-\r
-    // workaround for test under sw - 1. load key, 2. sign\r
-\r
-    int ret;\r
-    size_t key_len;\r
-    mbedtls_pk_context pk;\r
-    mbedtls_pk_init(&pk);\r
-\r
-    // 1. load key\r
-    const char* key_file = HWIF_KEY_FILE_NAME;\r
-    const char* key_pass = !strlen(HWIF_KEY_PASS) ? NULL : HWIF_KEY_PASS;\r
-    ret = LoadKeyFile(&pk, key_file, key_pass);\r
-    if (0 > ret)\r
-    {\r
-        D2D_LOGD("Fail to load key file [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-\r
-    key_len = ( 8 * ((const mbedtls_rsa_context *) pk.pk_ctx)->len );\r
-    if(0 >= key_len)\r
-    {\r
-        D2D_LOGE("Invalid key length");\r
-        ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA;\r
-        goto exit;\r
-    }\r
-    D2D_LOGD( "key name : %s, mode : %d hashlen : %u md_alg : %d keylen : %zu",\r
-            (const char*)(keyContext), mode, hashlen, md_alg, key_len);\r
-\r
-    // 2. sign\r
-    ret = mbedtls_rsa_pkcs1_sign( (mbedtls_rsa_context *)pk.pk_ctx, f_rng, p_rng,\r
-                        MBEDTLS_RSA_PRIVATE, md_alg, (unsigned int) hashlen, hash, sig);\r
-    if(0 != ret )\r
-    {\r
-        D2D_LOGD("Fail to sign [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-\r
-exit:\r
-    mbedtls_pk_free(&pk);\r
-    return ret;\r
-}\r
-\r
-int SSemulEcdsaSign( void *ctx, mbedtls_md_type_t md_alg,\r
-                   const unsigned char *hash, size_t hash_len,\r
-                   unsigned char *sig, size_t *sig_len,\r
-                   int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )\r
-{\r
-    (void)ctx;\r
-    if (0 == strlen(HWIF_KEY_FILE_NAME))\r
-    {\r
-        D2D_LOGE("Need to set private key file name");\r
-        return -1;\r
-    }\r
-\r
-    // workaround for test under sw  - 1. load key, 2. set temp ctx, 3.sign\r
-\r
-    int ret;\r
-    mbedtls_pk_context pk;\r
-    mbedtls_ecdsa_context ecdsa;\r
-    mbedtls_ecp_keypair *eckey;\r
-    mbedtls_pk_init(&pk);\r
-    mbedtls_ecdsa_init( &ecdsa );\r
-\r
-    // 1. load key\r
-    const char* key_file = HWIF_KEY_FILE_NAME;\r
-    const char* key_pass = !strlen(HWIF_KEY_PASS) ? NULL : HWIF_KEY_PASS;\r
-    ret = LoadKeyFile(&pk, key_file, key_pass);\r
-    if (0 > ret)\r
-    {\r
-        D2D_LOGD("Fail to load key file [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-\r
-    // 2. set temp ctx\r
-    eckey = (mbedtls_ecp_keypair*)pk.pk_ctx;\r
-    ret = mbedtls_ecdsa_from_keypair(&ecdsa, eckey);\r
-    if(0 != ret )\r
-    {\r
-        D2D_LOGD("Fail to copy key pair [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-\r
-    // 3. sign\r
-    ret = mbedtls_ecdsa_write_signature( (mbedtls_ecdsa_context *) &ecdsa,\r
-                md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng );\r
-    if(0 != ret )\r
-    {\r
-        D2D_LOGD("Fail to sign [0x%x]", ret);\r
-        goto exit;\r
-    }\r
-    D2D_LOGD("Success to sign");\r
-\r
-exit:\r
-    mbedtls_ecdsa_free( &ecdsa );\r
-    mbedtls_pk_free(&pk);\r
-    D2D_LOGD( "Out %s", __func__);\r
-    return ret;\r
-}\r
-\r
-\r
diff --git a/test/subownerclient.c b/test/subownerclient.c
deleted file mode 100644 (file)
index 9f15523..0000000
+++ /dev/null
@@ -1,1061 +0,0 @@
-/******************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *****************************************************************/
-#include "iotivity_config.h"
-
-#include <stdio.h>
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "platform_features.h"
-#include "utlist.h"
-#include "logger.h"
-#include "oic_malloc.h"
-#include "oic_string.h"
-#include "ocprovisioningmanager.h"
-#include "oxmjustworks.h"
-#include "oxmrandompin.h"
-#include "securevirtualresourcetypes.h"
-#include "security/srmutility.h"
-//#include "srmutility.h"
-#include "pmtypes.h"
-#include "pmutility.h"
-
-#include <tzplatform_config.h>
-#include <d2d-log.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif //__cplusplus
-
-// declaration(s) for provisioning client using C-level provisioning API
-// user input definition for main loop on provisioning client
-#define _10_DISCOV_MOT_ENABLED_DEV_         10
-#define _11_DISCOV_MULTIPLE_OWNED_DEV_         11
-#define _20_PERFORM_MOT_        20
-#define _30_GET_LED_RESOURCE_  30
-#define _31_PUT_LED_RESOURCE_  31
-#define _40_PROVISION_ACL_  40
-#define _41_PROVISION_CRED_  41
-#define _99_EXIT_PRVN_CLT_          99
-
-#define ACL_RESRC_MAX_NUM   16
-#define ACL_RESRC_ARRAY_SIZE   3 //This value is used only for sample (not OCF spec)
-#define ACL_RESRC_MAX_LEN   128
-#define ACL_PEMISN_CNT      5
-#define DISCOVERY_TIMEOUT   5 // 5 sec
-#define CALLBACK_TIMEOUT    3  // 1 min
-#define TAG "subownerclient"
-
-static const char* SVR_DB_FILE_NAME = "oic_svr_db_subowner_client.dat";
-        // '_' for separaing from the same constant variable in |srmresourcestrings.c|
-static const char* PRVN_DB_FILE_NAME = "oic_pdm_subowner.db";
-/*
-static const OicSecPrm_t  SUPPORTED_PRMS[1] =
-{
-    PRM_PRE_CONFIGURED,
-};
-*/
-
-// |g_ctx| means provision manager application context and
-// the following, includes |un/own_list|, could be variables, which |g_ctx| has,
-// for accessing all function(s) for these, they are declared on global domain
-static char *g_ctx = "SubOwner Client Application Context";
-static char* g_svr_fname;
-static char* g_prvn_fname;
-static OCProvisionDev_t* g_own_list;
-static OCProvisionDev_t* g_unown_list;
-static OCProvisionDev_t* g_motdev_list;
-static OCProvisionDev_t* g_mowned_list;
-//static int g_own_cnt;
-//static int g_unown_cnt;
-static int g_motdev_cnt;
-static int g_mowned_cnt;
-static bool g_doneCB;
-
-// function declaration(s) for calling them before implementing
-static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
-static int printDevList(const OCProvisionDev_t*);
-//static size_t printUuidList(const OCUuidList_t*);
-static int printResultList(const OCProvisionResult_t*, const int);
-static void printUuid(const OicUuid_t*);
-static FILE* fopen_prvnMng(const char*, const char*);
-static int waitCallbackRet(void);
-//static int selectTwoDiffNum(int*, int*, const int, const char*);
-
-// callback function(s) for provisioning client using C-level provisioning API
-static void multipleOwnershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Multiple Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Multiple Ownership Transfer FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-#if 0
-// callback function(s) for provisioning client using C-level provisioning API
-static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "POST 'doxm'  FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Provision Credential FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-#endif
-
-static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
-    if(!hasError)
-    {
-        D2D_LOGD( "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
-    }
-    else
-    {
-        D2D_LOGD( "Provision ACL FAILED - ctx: %s", (char*) ctx);
-        printResultList((const OCProvisionResult_t*) arr, nOfRes);
-    }
-    g_doneCB = true;
-}
-
-// response handler for LED requests.
-static OCStackApplicationResult LedCB(void *ctx, OCDoHandle UNUSED,
-                                    OCClientResponse *clientResponse)
-{
-    if(clientResponse)
-    {
-        if(OC_STACK_OK == clientResponse->result)
-        {
-            printf("Received OC_STACK_OK from server\n");
-            if(clientResponse->payload)
-            {
-                printf("Response ===================> %d\n",
-                                          clientResponse->payload->type);
-            }
-        }
-        else if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
-        {
-            printf("Received OC_STACK_RESOURCE_CHANGED from server\n");
-        }
-        else
-        {
-            printf("Error in response : %d\n", clientResponse->result);
-        }
-    }
-    else
-    {
-        printf("Hit the response callback but can not find response data\n");
-    }
-
-    g_doneCB = true;
-
-    return OC_STACK_DELETE_TRANSACTION;
-}
-
-static void inputPinCB(char* pin, size_t len)
-{
-    if(!pin || OXM_RANDOM_PIN_MAX_SIZE>=len)
-    {
-        D2D_LOGE( "inputPinCB invalid parameters");
-        return;
-    }
-
-    printf("   > INPUT PIN: ");
-    for(int ret=0; 1!=ret; )
-    {
-        ret = scanf("%32s", pin);
-        for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                    // '0x20<=code' is character region
-    }
-}
-
-// function(s) for provisioning client using C-level provisioning API
-static int initProvisionClient(void)
-{
-   char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-   snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), PRVN_DB_FILE_NAME);
-    // initialize persistent storage for SVR DB
-    static OCPersistentStorage ps = {fopen_prvnMng, fread, fwrite, fclose, unlink};
-    if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&ps))
-    {
-        D2D_LOGE( "OCRegisterPersistentStorageHandler error");
-        return -1;
-    }
-
-    // initialize OC stack and provisioning manager
-    if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
-    {
-        D2D_LOGE( "OCStack init error");
-        return -1;
-    }
-
-    if (access(data_dir, F_OK) != -1)
-    {
-        printf("************************************************************\n");
-        printf("************Provisioning DB file already exists.************\n");
-        printf("************************************************************\n");
-    }
-    else
-    {
-        printf("*************************************************************\n");
-        printf("************No provisioning DB file, creating new************\n");
-        printf("*************************************************************\n");
-    }
-
-    if(OC_STACK_OK != OCInitPM(data_dir))
-    {
-        D2D_LOGE( "OC_PM init error");
-        return -1;
-    }
-
-    SetInputPinCB(inputPinCB);
-
-    return 0;
-}
-
-static int discoverMotSupportedDevices(void)
-{
-    // delete un/owned device lists before updating them
-    if(g_motdev_list)
-    {
-        OCDeleteDiscoveredDevices(g_motdev_list);
-        g_motdev_list = NULL;
-    }
-
-    // call |OCDiscoverMultipleOwnerEnabledDevices| API actually
-    printf("   Discovering Multiple Ownership Transfer enabled Devices on Network..\n");
-    if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_motdev_list))
-    {
-        D2D_LOGE( "OCDiscoverMultipleOwnerEnalbedDevices API error");
-        return -1;
-    }
-
-    // display the discovered device lists
-    printf("   > Discovered Multiple Ownership Transfer Enabled Devices\n");
-    g_motdev_cnt = printDevList(g_motdev_list);
-
-    return 0;
-}
-
-static int discoverSubOwnerDevices()
-{
-    // delete un/owned device lists before updating them
-    if(g_mowned_list)
-    {
-        OCDeleteDiscoveredDevices(g_mowned_list);
-        g_mowned_list = NULL;
-    }
-
-    // call |OCDiscoverMultipleOwnedDevices| API actually
-    printf("   Discovering Multiple Owned Devices on Network..\n");
-    if(OC_STACK_OK != OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_mowned_list))
-    {
-        D2D_LOGE( "OCDiscoverMultipleOwnerEnabledDevices API error");
-        return -1;
-    }
-
-    // display the discovered device lists
-    printf("   > Discovered Multiple Owned Devices\n");
-    g_mowned_cnt = printDevList(g_mowned_list);
-
-    return 0;
-}
-
-static int multipleOwnershipTransfer(void)
-{
-    // check |unown_list| for registering devices
-    if(!g_motdev_list || 0 >=g_motdev_cnt)
-    {
-        printf("   > MultipleOwnershipTransfer Enabled Device List is Empty\n");
-        printf("   > Please Discover Devices first, with [10] Menu\n");
-        return 0;  // normal case
-    }
-
-    // call |getDevInst| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-
-#ifdef MULTIPLE_OWNER
-    OCProvisionDev_t* dev = NULL;
-    LL_FOREACH(g_motdev_list, dev)
-    {
-        if(OIC_PRECONFIG_PIN == dev->doxm->oxmSel)
-        {
-            //Pre-Configured PIN initialization
-            const char* testPreconfigPin = "12341234";
-            if(OC_STACK_OK != OCAddPreconfigPin(dev, testPreconfigPin, strlen(testPreconfigPin)))
-            {
-                printf("\n\n\n*** %60s ***\n", "WARNNING : Failed to save the pre-configured PIN");
-                printf("*** %60s ***\n\n\n", "WARNNING : You can't use the pre-configured PIN OxM for MOT");
-                return -1;
-            }
-        }
-    }
-#endif //MULTIPLE_OWNER
-
-    if(OC_STACK_OK != OCDoMultipleOwnershipTransfer(g_ctx, g_motdev_list, multipleOwnershipTransferCB))
-    {
-        D2D_LOGE( "_20_PERFORM_MOT_: error");
-        return -1;
-    }
-
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        return -1;
-    }
-
-    // display the registered result
-    printf("   > Registered Discovered Devices\n");
-
-    return 0;
-}
-
-static int sendGetLed()
-{
-    int selDevNum;
-    char query[256] = {0};
-    OCCallbackData cbData;
-    cbData.cb = &LedCB;
-    cbData.context = NULL;
-    cbData.cd = NULL;
-
-    printDevList(g_mowned_list);
-
-    // select device for provisioning access control list
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for sending GET LED request: ");
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &selDevNum);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        if(0<selDevNum && g_mowned_cnt>=selDevNum)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* selDev = getDevInst(g_mowned_list, selDevNum);
-    if(NULL == selDev)
-    {
-        printf("Failed to getDevInst()\n");
-        return -1;
-    }
-
-    if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
-                       query, sizeof(query), "/a/led"))
-    {
-        g_doneCB = false;
-        printf("query=%s\n", query);
-        if(OC_STACK_OK != OCDoResource(NULL, OC_REST_GET, query, NULL, NULL, selDev->connType,
-                                       OC_HIGH_QOS, &cbData, NULL, 0))
-        {
-            printf("********************************\n");
-            printf("Failed to send GET request to %s\n", query);
-            printf("********************************\n");
-            g_doneCB = true;
-            return -1;
-        }
-
-        waitCallbackRet();
-    }
-    else
-    {
-        printf("Failed to generate GET request for /a/led\n");
-        return -1;
-    }
-
-    return 0;
-}
-
-static int sendPutLed()
-{
-    int selDevNum;
-    char query[256] = {0};
-    OCCallbackData cbData;
-    cbData.cb = &LedCB;
-    cbData.context = NULL;
-    cbData.cd = NULL;
-
-    printDevList(g_mowned_list);
-    // select device for provisioning access control list
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for sending PUT LED request: ");
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &selDevNum);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        if(0<selDevNum && g_mowned_cnt>=selDevNum)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* selDev = getDevInst(g_mowned_list, selDevNum);
-    if(NULL == selDev)
-    {
-        printf("Failed to getDevInst()\n");
-        return -1;
-    }
-
-    if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
-                       query, sizeof(query), "/a/led"))
-    {
-        g_doneCB = false;
-        printf("query=%s\n", query);
-        if(OC_STACK_OK != OCDoResource(NULL, OC_REST_PUT, query, NULL, NULL, selDev->connType,
-                                       OC_LOW_QOS, &cbData, NULL, 0))
-        {
-            printf("********************************\n");
-            printf("Failed to send PUT request to %s\n", query);
-            printf("********************************\n");
-            g_doneCB = true;
-            return -1;
-        }
-
-        waitCallbackRet();
-    }
-    else
-    {
-        printf("Failed to generate PUT request for /a/led\n");
-        return -1;
-    }
-
-    return 0;
-}
-
-
-static OicSecAcl_t* createAclForLEDAccess(const OicUuid_t* subject)
-{
-    if(NULL == subject)
-    {
-        D2D_LOGE( "createAcl: Invalid paramters");
-        return NULL;
-    }
-    // allocate memory for |acl| struct
-    OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
-    if(!acl)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-    OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
-    if(!ace)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
-    }
-    LL_APPEND(acl->aces, ace);
-    memcpy(ace->subjectuuid.id, subject->id, sizeof(subject->id));
-
-    // fill the href
-    char* rsrc_in = "/a/led";  // '1' for null termination
-    OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
-    if(!rsrc)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        goto CRACL_ERROR;
-    }
-
-    size_t len = strlen(rsrc_in)+1;  // '1' for null termination
-    rsrc->href = (char*) OICCalloc(len, sizeof(char));
-    if(!rsrc->href)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        goto CRACL_ERROR;
-    }
-    OICStrcpy(rsrc->href, len, rsrc_in);
-
-    //fill the resource type (rt)
-    rsrc->typeLen = 1;
-    rsrc->types = (char**)OICCalloc(1, sizeof(char*));
-    if(!rsrc->types)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        goto CRACL_ERROR;
-    }
-    rsrc->types[0] = OICStrdup("oic.r.core");
-    if(!rsrc->types[0])
-    {
-        D2D_LOGE( "createAcl: OICStrdup error return");
-        goto CRACL_ERROR;
-    }
-
-    //fill the interface (if)
-    rsrc->interfaceLen = 1;
-    rsrc->interfaces = (char**)OICCalloc(1, sizeof(char*));
-    if(!rsrc->interfaces)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        goto CRACL_ERROR;
-    }
-    rsrc->interfaces[0] = OICStrdup("oic.if.baseline");
-    if(!rsrc->interfaces[0])
-    {
-        D2D_LOGE( "createAcl: OICStrdup error return");
-        goto CRACL_ERROR;
-    }
-
-    LL_APPEND(ace->resources, rsrc);
-
-    // full permission for /a/led
-    ace->permission = PERMISSION_FULL_CONTROL;
-
-    ace->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t));
-    if(NULL == ace->eownerID)
-    {
-        D2D_LOGE( "createAcl: OICCalloc error return");
-        goto CRACL_ERROR;
-    }
-
-    memcpy(ace->eownerID->id, subject->id, sizeof(subject->id));
-
-    return acl;
-
-CRACL_ERROR:
-    OCDeleteACLList(acl);  // after here |acl| points nothing
-    return NULL;
-}
-
-static int provisionAclForLed()
-{
-    OicSecAcl_t* acl = NULL;
-
-    // check |own_list| for provisioning access control list
-    if(!g_mowned_list || 1> g_mowned_cnt)
-    {
-        printf("   > MOT Device List is Empty\n");
-        printf("   > Please Perform MOT first, with [12|21] Menu\n");
-        return 0;  // normal case
-    }
-
-    // display the MOT dev list
-    printf("   > MOT Devices\n");
-    g_mowned_cnt = printDevList(g_mowned_list);
-
-    // select device for provisioning access control list
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Device Number, for Provisioning LED's ACL: ");
-        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 && g_mowned_cnt >= dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    g_doneCB = false;
-    printf("   Provisioning Selected ACL..\n");
-    OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_mowned_list, dev_num);
-    if(!dev)
-    {
-        D2D_LOGE( "provisionAcl: device instance empty");
-        goto PVACL_ERROR;
-    }
-
-    acl = createAclForLEDAccess(&dev->doxm->subOwners->uuid);
-    if(NULL == acl)
-    {
-        D2D_LOGE( "provisionAcl: Failed to create ACL for LED");
-        return -1;
-    }
-
-    OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCProvisionACL API error: %d", rst);
-        goto PVACL_ERROR;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        goto PVACL_ERROR;
-    }
-    // display the ACL-provisioned result
-    printf("   > Provisioned Selected ACL\n");
-
-    OCDeleteACLList(acl);  // after here |acl| points nothing
-    return 0;
-
-PVACL_ERROR:
-    OCDeleteACLList(acl);
-    return -1;
-}
-
-#if 0
-static int provisionCred()
-{
-    // check |unown_list| for registering devices
-    if(!g_mowned_list|| 0 >=g_mowned_cnt)
-    {
-        printf("   > Multiple Owned Device List is Empty\n");
-        printf("   > Please Discover Devices first, with [13] Menu\n");
-        return 0;  // normal case
-    }
-
-    // display the MOT dev list
-    printf("   > Multiple Owned Devices\n");
-    g_mowned_cnt = printDevList(g_mowned_list);
-
-    int dev_num = 0;
-    for( ; ; )
-    {
-        printf("   > Enter Multiple Owned Device Number to link : ");
-        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 && g_mowned_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* motDev = getDevInst(g_mowned_list, dev_num);
-    if(NULL == motDev)
-    {
-        D2D_LOGE( "Failed to getDevInst()");
-        return -1;
-    }
-
-    // display the MOT dev list
-    printf("   > Owned Devices\n");
-    g_own_cnt = printDevList(g_own_list);
-
-    for( ; ; )
-    {
-        printf("   > Enter Owned Device Number to link : ");
-        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 && g_own_cnt>=dev_num)
-        {
-            break;
-        }
-        printf("     Entered Wrong Number. Please Enter Again\n");
-    }
-
-    OCProvisionDev_t* ownDev = getDevInst(g_own_list, dev_num);
-    if(NULL == ownDev)
-    {
-        D2D_LOGE( "Failed to getDevInst()");
-        return -1;
-    }
-
-    // call |OCProvisionCredentials| API actually
-    // calling this API with callback actually acts like blocking
-    // for error checking, the return value saved and printed
-    g_doneCB = false;
-    printf("   Provisioning Selected Pairwise Devices..\n");
-    OCStackResult rst = OCProvisionCredentials((void*) g_ctx,
-                    SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
-                    ownDev, motDev, provisionCredCB);
-    if(OC_STACK_OK != rst)
-    {
-        D2D_LOGD( "OCProvisionPairwiseDevices API error: %d", rst);
-        goto PVPWS_ERROR;
-    }
-    if(waitCallbackRet())  // input |g_doneCB| flag implicitly
-    {
-        D2D_LOGE( "OCProvisionCredentials callback error");
-        goto PVPWS_ERROR;
-    }
-
-    // display the pairwise-provisioned result
-    printf("   > Provisioned Selected Pairwise Devices\n");
-
-    return 0;
-
-PVPWS_ERROR:
-    return -1;
-}
-#endif
-
-static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
-{
-    if(!dev_lst || 0>=dev_num)
-    {
-        printf("     Device List is Empty..\n");
-        return NULL;
-    }
-
-    OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
-    for(int i=0; lst; )
-    {
-        if(dev_num == ++i)
-        {
-            return lst;
-        }
-        lst = lst->next;
-    }
-
-    return NULL;  // in here |lst| is always |NULL|
-}
-
-static int printDevList(const OCProvisionDev_t* dev_lst)
-{
-    if(!dev_lst)
-    {
-        printf("     Device List is Empty..\n\n");
-        return 0;
-    }
-
-    OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
-    int lst_cnt = 0;
-    for( ; lst; )
-    {
-        printf("     [%d] ", ++lst_cnt);
-        printUuid((const OicUuid_t*) &lst->doxm->deviceID);
-        printf("\n");
-        lst = lst->next;
-    }
-    printf("\n");
-
-    return lst_cnt;
-}
-
-#if 0
-static size_t printUuidList(const OCUuidList_t* uid_lst)
-{
-    if(!uid_lst)
-    {
-        printf("     Device List is Empty..\n\n");
-        return 0;
-    }
-
-    OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
-    size_t lst_cnt = 0;
-    for( ; lst; )
-    {
-        printf("     [%zu] ", ++lst_cnt);
-        printUuid((const OicUuid_t*) &lst->dev);
-        printf("\n");
-        lst = lst->next;
-    }
-    printf("\n");
-
-    return lst_cnt;
-}
-#endif
-
-static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
-{
-    if(!rslt_lst || 0>=rslt_cnt)
-    {
-        printf("     Device List is Empty..\n\n");
-        return 0;
-    }
-
-    int lst_cnt = 0;
-    for( ; rslt_cnt>lst_cnt; ++lst_cnt)
-    {
-        printf("     [%d] ", lst_cnt+1);
-        printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
-        printf(" - result: %d\n", rslt_lst[lst_cnt].res);
-    }
-    printf("\n");
-
-    return lst_cnt;
-}
-
-static void printUuid(const OicUuid_t* uid)
-{
-    for(int i=0; i<UUID_LENGTH; )
-    {
-        printf("%02X", (*uid).id[i++]);
-        if(i==4 || i==6 || i==8 || i==10)  // canonical format for UUID has '8-4-4-4-12'
-        {
-            printf("-");
-        }
-    }
-}
-
-static FILE* fopen_prvnMng(const char* path, const char* mode)
-{
-    // 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 data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), SVR_DB_FILE_NAME);
-    (void)path;  // unused |path| parameter
-
-    return fopen(data_dir, mode);
-}
-
-static int waitCallbackRet(void)
-{
-    for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
-    {
-        sleep(1);
-       printf( "waitCallbackRet : [%d]", i);
-        if(OC_STACK_OK != OCProcess())
-        {
-            D2D_LOGE( "OCStack process error");
-            return -1;
-        }
-    }
-
-    if(!g_doneCB)
-    {
-        OCPDMCleanupForTimeout();
-    }
-
-    return 0;
-}
-
-#if 0
-static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
-{
-    if(!a || !b || 2>max || !str)
-    {
-        return -1;
-    }
-
-    for( ; ; )
-    {
-        for(int i=0; 2>i; ++i)
-        {
-            int* num = 0==i?a:b;
-            for( ; ; )
-            {
-                printf("   > Enter Device[%d] Number, %s: ", i+1, str);
-                for(int ret=0; 1!=ret; )
-                {
-                    ret = scanf("%d", num);
-                    for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                                // '0x20<=code' is character region
-                }
-                if(0<*num && max>=*num)
-                {
-                    break;
-                }
-                printf("     Entered Wrong Number. Please Enter Again\n");
-            }
-        }
-        if(*a != *b)
-        {
-            printf("\n");
-            return 0;
-        }
-    }
-
-    return -1;
-}
-#endif
-
-static void printMenu(void)
-{
-    printf("************************************************************\n");
-    printf("****** OIC Provisioning Client with using C-level API ******\n");
-    printf("************************************************************\n\n");
-
-    printf("** [A] DISCOVER DEVICES ON NETWORK\n");
-    printf("** 10. Discover Multiple Ownership Transfer Enabled Devices on Network\n");
-    printf("** 11. Discover Multiple Owned Devices on Network\n\n");
-
-    printf("** [B] PERFORM MULTIPLE OWNERSHIP TRANSFER\n");
-    printf("** 20. Perform the Multiple Ownership Transfer for ALL discovered dievices\n\n");
-
-    printf("** [C] Get/Put Request for APPLICATION RESOURCE\n");
-    printf("** 30. Get LED resource\n");
-    printf("** 31. Put LED resource\n\n");
-
-    printf("** [D] LINK DEVICES\n");
-    printf("** 40. Provision ACL for LED Resource\n");
-    printf("** 41. Provison Credential\n\n");
-
-    printf("** [F] EXIT PROVISIONING CLIENT\n");
-    printf("** 99. Exit Provisionong Client\n\n");
-
-    printf("************************************************************\n\n");
-}
-
-// main function for provisioning client using C-level provisioning API
-int main()
-{
-    // initialize provisioning client
-    if(initProvisionClient())
-    {
-        D2D_LOGE( "ProvisionClient init error");
-        goto PMCLT_ERROR;
-    }
-
-    // main loop for provisioning manager
-    int mnNum = 0;
-    for( ; ; )
-    {
-        printf("\n");
-        printMenu();
-        printf(">> Enter Menu Number: ");
-        for(int ret=0; 1!=ret; )
-        {
-            ret = scanf("%d", &mnNum);
-            for( ; 0x20<=getchar(); );  // for removing overflow garbages
-                                        // '0x20<=code' is character region
-        }
-        printf("\n");
-        switch(mnNum)
-        {
-        case _10_DISCOV_MOT_ENABLED_DEV_:
-            if(discoverMotSupportedDevices())
-            {
-                D2D_LOGE( "_12_MOT_DISCOV_DEV_: error");
-            }
-            break;
-        case _11_DISCOV_MULTIPLE_OWNED_DEV_:
-            if(discoverSubOwnerDevices())
-            {
-                D2D_LOGE( "_13_DISCOV_MULTIPLE_OWNED_DEV_: error");
-            }
-            break;
-        case _20_PERFORM_MOT_:
-            if(multipleOwnershipTransfer())
-            {
-                D2D_LOGE( "_21_PERFORM_MOT_: error");
-            }
-            break;
-        case _30_GET_LED_RESOURCE_:
-            if(sendGetLed())
-            {
-                D2D_LOGE( "_30_GET_LED_RESOURCE_: error");
-            }
-            break;
-        case _31_PUT_LED_RESOURCE_:
-            if(sendPutLed())
-            {
-                D2D_LOGE( "_31_PUT_LED_RESOURCE_: error");
-            }
-            break;
-        case _40_PROVISION_ACL_:
-            if(provisionAclForLed())
-            {
-                D2D_LOGE( "_40_PROVISION_ACL_: error");
-            }
-            break;
-        case _41_PROVISION_CRED_:
-            D2D_LOGE( "NOT SUPPORTED YET.");
-            break;
-            /*
-            if(provisionCred())
-            {
-                D2D_LOGE( "_41_PROVISION_CRED_: error");
-            }
-            break;
-            */
-        case _99_EXIT_PRVN_CLT_:
-            goto PMCLT_ERROR;
-        default:
-            printf(">> Entered Wrong Number. Please Enter Again\n\n");
-            break;
-        }
-    }
-
-PMCLT_ERROR:
-    if(OC_STACK_OK != OCStop())
-    {
-        D2D_LOGE( "OCStack stop error");
-    }
-    OCDeleteDiscoveredDevices(g_own_list);  // after here |g_own_list| points nothing
-    OCDeleteDiscoveredDevices(g_unown_list);  // after here |g_unown_list| points nothing
-    OCDeleteDiscoveredDevices(g_motdev_list);  // after here |g_motdev_list| points nothing
-
-    if(g_svr_fname)
-    {
-        OICFree(g_svr_fname);  // after here |g_svr_fname| points nothing
-    }
-    if(g_prvn_fname)
-    {
-        OICFree(g_prvn_fname);  // after here |g_prvn_fname| points nothing
-    }
-    return 0;  // always return normal case
-}
-
-#ifdef __cplusplus
-}
-#endif //__cplusplus