OBJ_DIR = $(OUT_DIR)/obj
endif
-OCLOGGER_DIR = logger
-OC_LOG_DIR = ../oc_logger
-OCRANDOM_DIR = ocrandom
-OCSOCKET_DIR = ocsocket
-LCOAP_DIR = libcoap-4.1.1
-OCCOAP_DIR = occoap
-OCTBSTACK_DIR = stack
-OCMALLOC_DIR = ocmalloc
-EXTLIBS_DIR = ../../extlibs
-CJSON_DIR = $(EXTLIBS_DIR)/cjson
+OCLOGGER_DIR = logger
+OC_LOG_DIR = ../oc_logger
+OCRANDOM_DIR = ocrandom
+OCSOCKET_DIR = ocsocket
+LCOAP_DIR = libcoap-4.1.1
+OCCOAP_DIR = occoap
+OCTBSTACK_DIR = stack
+OCMALLOC_DIR = ocmalloc
+EXTLIBS_DIR = ../../extlibs
+CJSON_DIR = $(EXTLIBS_DIR)/cjson
- TINYDTLS_DIR = tinydtls
+ TINYDTLS_DIR = $(EXTLIBS_DIR)/tinydtls
-
-OCCOAP_SRC = $(OCCOAP_DIR)/src
-OCTBSTACK_SRC = $(OCTBSTACK_DIR)/src
-OCMALLOC_SRC = $(OCMALLOC_DIR)/src
-CJSON_SRC = $(CJSON_DIR)
-
-OCLOGGER_INC = $(OCLOGGER_DIR)/include
-OC_LOG_INC = $(OC_LOG_DIR)/include
-OCRANDOM_INC = $(OCRANDOM_DIR)/include
-OCSOCKET_INC = $(OCSOCKET_DIR)/include
-LCOAP_INC = $(LCOAP_DIR)
-OCCOAP_INC = $(OCCOAP_DIR)/include
-OCTBSTACK_INC = $(OCTBSTACK_DIR)/include
-OCMALLOC_INC = $(OCMALLOC_DIR)/include
-CJSON_INC = $(CJSON_DIR)
+CONNECTIVITY_DIR = connectivity
+
+OCCOAP_SRC = $(OCCOAP_DIR)/src
+OCTBSTACK_SRC = $(OCTBSTACK_DIR)/src
+OCMALLOC_SRC = $(OCMALLOC_DIR)/src
+CJSON_SRC = $(CJSON_DIR)
+CONNECTIVITY_SRC = $(CONNECTIVITY_DIR)
+
+OCLOGGER_INC = $(OCLOGGER_DIR)/include
+OC_LOG_INC = $(OC_LOG_DIR)/include
+OCRANDOM_INC = $(OCRANDOM_DIR)/include
+OCSOCKET_INC = $(OCSOCKET_DIR)/include
+LCOAP_INC = $(LCOAP_DIR)
+OCCOAP_INC = $(OCCOAP_DIR)/include
+OCTBSTACK_INC = $(OCTBSTACK_DIR)/include
+OCMALLOC_INC = $(OCMALLOC_DIR)/include
+CJSON_INC = $(CJSON_DIR)
+CONNECTIVITY_INC = $(CONNECTIVITY_DIR)/inc
INC_DIRS := -I$(OCLOGGER_INC)
INC_DIRS += -I$(OC_LOG_INC)
--- /dev/null
+ //******************************************************************
+ //
+ // 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 OC_RESOURCEHANDLER_H
+ #define OC_RESOURCEHANDLER_H
+
+ #include "ocstack.h"
+ #include "ocstackinternal.h"
+ #include "ocserverrequest.h"
+
+ #define OC_RSRVD_OC "oc"
+ #define OC_RSRVD_PAYLOAD "payload"
+ #define OC_RSRVD_HREF "href"
+ #define OC_RSRVD_RESOURCE_TYPE "rt"
+ #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "core.presence"
+ #define OC_RSRVD_INTERFACE "if"
+ #define OC_RSRVD_INTERFACE_DEFAULT "oc.mi.def"
+ #define OC_RSRVD_INTERFACE_LL "oc.mi.ll"
+ #define OC_RSRVD_INTERFACE_BATCH "oc.mi.b"
+ #define OC_RSRVD_OBSERVABLE "obs"
+ #define OC_RSRVD_SECURE "sec"
+ #define OC_RSRVD_HOSTING_PORT "port"
++#define OC_RSRVD_SERVER_INSTANCE_ID "sid"
+
+ #define OC_JSON_PREFIX "{\"oc\":["
+ #define OC_JSON_PREFIX_LEN (sizeof(OC_JSON_PREFIX) - 1)
+ #define OC_JSON_SUFFIX "]}"
+ #define OC_JSON_SUFFIX_LEN (sizeof(OC_JSON_SUFFIX) - 1)
+ #define OC_JSON_SEPARATOR ','
+
+ #define OC_RESOURCE_OBSERVABLE 1
+ #define OC_RESOURCE_SECURE 1
+
+ typedef enum {
+ STACK_RES_DISCOVERY_NOFILTER = 0,
+ STACK_RES_DISCOVERY_IF_FILTER,
+ STACK_RES_DISCOVERY_RT_FILTER
+ } StackQueryTypes;
+
+ typedef enum {
+ OC_RESOURCE_VIRTUAL = 0,
+ OC_RESOURCE_NOT_COLLECTION_WITH_ENTITYHANDLER,
+ OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER,
+ OC_RESOURCE_COLLECTION_WITH_ENTITYHANDLER,
+ OC_RESOURCE_COLLECTION_DEFAULT_ENTITYHANDLER,
+ OC_RESOURCE_DEFAULT_DEVICE_ENTITYHANDLER,
+ OC_RESOURCE_NOT_SPECIFIED
+ } ResourceHandling;
+
+ OCEntityHandlerResult defaultResourceEHandler(OCEntityHandlerFlag flag,
+ OCEntityHandlerRequest * request);
+
+ const char * GetVirtualResourceUri( OCVirtualResources resource);
+ OCResource *FindResourceByUri(const char* resourceUri);
+ uint8_t IsVirtualResource(const char* resourceUri);
+
+ OCStackResult DetermineResourceHandling (OCServerRequest *request,
+ ResourceHandling *handling,
+ OCResource **resource);
+
+ OCStackResult
+ ProcessRequest(ResourceHandling resHandling, OCResource *resource, OCServerRequest *request);
+
+ OCStackResult
+ BuildVirtualResourceResponse(OCResource *resourcePtr, uint8_t filterOn,
+ char *filterValue, char * out, uint16_t *remaining);
+
+ OCStackResult EntityHandlerCodeToOCStackCode(OCEntityHandlerResult ehResult);
+
+ #endif //OC_RESOURCEHANDLER_H
//-----------------------------------------------------------------------------
// Internal function prototypes
//-----------------------------------------------------------------------------
-
- OCStackResult HandleStackRequests(OCRequest * request);
- OCStackResult SendPresenceNotification(OCResourceType *resourceType, OCQualityOfService qos);
+ OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
+ OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
void HandleStackResponses(OCResponse * response);
int ParseIPv4Address(unsigned char * ipAddrStr, uint8_t * ipAddr, uint16_t * port);
+ #ifdef WITH_PRESENCE
+ OCStackResult SendPresenceNotification(OCResourceType *resourceType);
+ #endif
+
+ OCStackResult BindResourceInterfaceToResource(OCResource* resource,
+ const char *resourceInterfaceName);
+
+ OCStackResult BindResourceTypeToResource(OCResource* resource,
+ const char *resourceTypeName);
+ OCResourceType *findResourceType(OCResourceType * resourceTypeList, const char * resourceTypeName);
+
+// returns the internal representation of the server instance ID.
+// Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
+// This is done automatically during the OCInit process (via the call to OCInitCoAP),
+// so ensure that this call is done after that.
+const ServerID OCGetServerInstanceID(void);
++
+// returns a string representation the server instance ID.
+// The memory is managed internal to this function, so freeing externally will result
+// in a compiler error
+// Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
+// This is done automatically during the OCInit process (via the call to OCInitCoAP),
+// so ensure that this call is done after that.
+const char* OCGetServerInstanceIDString(void);
#ifdef WITH_PRESENCE
//TODO: should the following function be public?
OCStackResult OCChangeResourceProperty(OCResourceProperty * inputProperty,
exit:
return OC_STACK_NO_MEMORY;
}
-
+
+const ServerID OCGetServerInstanceID(void)
+{
+ static bool generated = false;
+ static ServerID sid;
+
+ if(generated)
+ {
+ return sid;
+ }
+
+ sid = OCGetRandom();
+ generated = true;
+ return sid;
+}
+
+const char* OCGetServerInstanceIDString(void)
+{
+ // max printed length of a base 10
+ // uint32 is 10 characters, so 11 includes null.
+ // This will change as the representation gets switched
+ // to another value
+ static char buffer[11];
- }
+ int n = sprintf(buffer, "%u", OCGetServerInstanceID());
+ if (n < 0)
+ {
+ buffer[0]='\0';
+ }
+
+ return buffer;
++}