IoTivity-Lite
oc_ri.h File Reference
#include "oc_config.h"
#include "oc_endpoint.h"
#include "oc_enums.h"
#include "oc_rep.h"
#include "oc_uuid.h"
#include "util/oc_etimer.h"

Data Structures

struct  oc_event_callback_s
 event callback More...
 
struct  oc_properties_cb_t
 properties callback structure More...
 
struct  oc_request_handler_s
 request handler type More...
 
struct  oc_request_t
 request information structure More...
 
struct  oc_resource_s
 resource structure More...
 
struct  oc_response_t
 response type More...
 

Macros

#define OC_NUM_CORE_RESOURCES_PER_DEVICE   (1 + OCF_D)
 
#define oc_ri_add_timed_event_callback_seconds(cb_data, event_callback, seconds)
 add timed event callback in seconds

More...
 

Typedefs

typedef struct oc_collection_s oc_collection_t
 
typedef struct oc_event_callback_s oc_event_callback_t
 event callback More...
 
typedef void(* oc_get_properties_cb_t) (oc_resource_t *, oc_interface_mask_t, void *)
 get properties callback More...
 
typedef struct oc_link_s oc_link_t
 
typedef struct oc_properties_cb_t oc_properties_cb_t
 properties callback structure More...
 
typedef void(* oc_request_callback_t) (oc_request_t *, oc_interface_mask_t, void *)
 request callback More...
 
typedef struct oc_request_handler_s oc_request_handler_t
 request handler type More...
 
typedef struct oc_request_t oc_request_t
 request information structure More...
 
typedef struct oc_resource_defaults_data_t oc_resource_defaults_data_t
 
typedef struct oc_resource_s oc_resource_t
 
typedef struct oc_response_buffer_s oc_response_buffer_t
 reponse buffer type More...
 
typedef struct oc_response_t oc_response_t
 response type More...
 
typedef struct oc_separate_response_s oc_separate_response_t
 seperate response type More...
 
typedef bool(* oc_set_properties_cb_t) (oc_resource_t *, oc_rep_t *, void *)
 set properties callback More...
 
typedef oc_event_callback_retval_t(* oc_trigger_t) (void *)
 

Enumerations

enum  oc_content_format_t {
  TEXT_PLAIN = 0, TEXT_XML = 1, TEXT_CSV = 2, TEXT_HTML = 3,
  IMAGE_GIF = 21, IMAGE_JPEG = 22, IMAGE_PNG = 23, IMAGE_TIFF = 24,
  AUDIO_RAW = 25, VIDEO_RAW = 26, APPLICATION_LINK_FORMAT = 40, APPLICATION_XML = 41,
  APPLICATION_OCTET_STREAM = 42, APPLICATION_RDF_XML = 43, APPLICATION_SOAP_XML = 44, APPLICATION_ATOM_XML = 45,
  APPLICATION_XMPP_XML = 46, APPLICATION_EXI = 47, APPLICATION_FASTINFOSET = 48, APPLICATION_SOAP_FASTINFOSET = 49,
  APPLICATION_JSON = 50, APPLICATION_X_OBIX_BINARY = 51, APPLICATION_CBOR = 60, APPLICATION_SENML_JSON = 110,
  APPLICATION_SENSML_JSON = 111, APPLICATION_SENML_CBOR = 112, APPLICATION_SENSML_CBOR = 113, APPLICATION_SENML_EXI = 114,
  APPLICATION_SENSML_EXI = 115, APPLICATION_PKCS7_SGK, APPLICATION_PKCS7_CO = 281, APPLICATION_PKCS7_CMC_REQUEST,
  APPLICATION_PKCS7_CMC_RESPONSE, APPLICATION_PKCS8 = 284, APPLICATION_CRATTRS = 285, APPLICATION_PKCS10 = 286,
  APPLICATION_PKIX_CERT = 287, APPLICATION_VND_OCF_CBOR = 10000, APPLICATION_OSCORE = 10001, APPLICATION_VND_OMA_LWM2M_TLV = 11542,
  APPLICATION_VND_OMA_LWM2M_JSON = 11543, APPLICATION_VND_OMA_LWM2M_CBOR = 11544
}
 payload content formats More...
 
enum  oc_core_resource_t {
  OCF_P = 0, OCF_CON, OCF_INTROSPECTION_WK, OCF_INTROSPECTION_DATA,
  OCF_RES, OCF_MNT, OCF_COAPCLOUDCONF, OCF_SW_UPDATE,
  OCF_SEC_DOXM, OCF_SEC_PSTAT, OCF_SEC_ACL, OCF_SEC_AEL,
  OCF_SEC_CRED, OCF_SEC_SDI, OCF_SEC_SP, OCF_SEC_CSR,
  OCF_SEC_ROLES, OCF_D
}
 
enum  oc_event_callback_retval_t { OC_EVENT_DONE = 0, OC_EVENT_CONTINUE }
 
enum  oc_interface_mask_t {
  OC_IF_BASELINE = 1 << 1, OC_IF_LL = 1 << 2, OC_IF_B = 1 << 3, OC_IF_R = 1 << 4,
  OC_IF_RW = 1 << 5, OC_IF_A = 1 << 6, OC_IF_S = 1 << 7, OC_IF_CREATE = 1 << 8,
  OC_IF_W = 1 << 9, OC_IF_STARTUP = 1 << 10, OC_IF_STARTUP_REVERT = 1 << 11
}
 interface masks More...
 
enum  oc_method_t {
  OC_GET = 1, OC_POST, OC_PUT, OC_DELETE,
  OC_FETCH
}
 CoAP methods. More...
 
enum  oc_resource_properties_t {
  OC_DISCOVERABLE = (1 << 0), OC_OBSERVABLE = (1 << 1), OC_SECURE = (1 << 4), OC_PERIODIC = (1 << 6),
  OC_SECURE_MCAST = (1 << 8)
}
 resource properties (bit mask) More...
 
enum  oc_status_t {
  OC_STATUS_OK = 0, OC_STATUS_CREATED, OC_STATUS_CHANGED, OC_STATUS_DELETED,
  OC_STATUS_NOT_MODIFIED, OC_STATUS_BAD_REQUEST, OC_STATUS_UNAUTHORIZED, OC_STATUS_BAD_OPTION,
  OC_STATUS_FORBIDDEN, OC_STATUS_NOT_FOUND, OC_STATUS_METHOD_NOT_ALLOWED, OC_STATUS_NOT_ACCEPTABLE,
  OC_STATUS_REQUEST_ENTITY_TOO_LARGE, OC_STATUS_UNSUPPORTED_MEDIA_TYPE, OC_STATUS_INTERNAL_SERVER_ERROR, OC_STATUS_NOT_IMPLEMENTED,
  OC_STATUS_BAD_GATEWAY, OC_STATUS_SERVICE_UNAVAILABLE, OC_STATUS_GATEWAY_TIMEOUT, OC_STATUS_PROXYING_NOT_SUPPORTED,
  __NUM_OC_STATUS_CODES__, OC_IGNORE, OC_PING_TIMEOUT
}
 response status can be translated to HTTP or CoAP. More...
 

Functions

bool oc_ri_add_resource (oc_resource_t *resource)
 add resource to the system More...
 
void oc_ri_add_timed_event_callback_ticks (void *cb_data, oc_trigger_t event_callback, oc_clock_time_t ticks)
 add timed event callback More...
 
oc_resource_toc_ri_alloc_resource (void)
 allocate a resource strucutre More...
 
bool oc_ri_delete_resource (oc_resource_t *resource)
 remove the resource from the list of application resources More...
 
void oc_ri_free_resource_properties (oc_resource_t *resource)
 free the properties of the resource More...
 
oc_resource_toc_ri_get_app_resource_by_uri (const char *uri, size_t uri_len, size_t device)
 retrieve the resource by uri and device indes More...
 
oc_resource_toc_ri_get_app_resources (void)
 retrieve list of resources More...
 
oc_interface_mask_t oc_ri_get_interface_mask (char *iface, size_t if_len)
 retrieve the interface mask from the interface name More...
 
int oc_ri_get_query_nth_key_value (const char *query, size_t query_len, char **key, size_t *key_len, char **value, size_t *value_len, size_t n)
 retrieve the query value at the nth position More...
 
int oc_ri_get_query_value (const char *query, size_t query_len, const char *key, char **value)
 retrieve the value of the query parameter "key" More...
 
void oc_ri_init (void)
 initialize the resource implementation handler More...
 
bool oc_ri_is_app_resource_valid (oc_resource_t *resource)
 checks if the resource is valid More...
 
int oc_ri_query_exists (const char *query, size_t query_len, const char *key)
 checks if key exist in query More...
 
int oc_ri_query_nth_key_exists (const char *query, size_t query_len, char **key, size_t *key_len, size_t n)
 check if the nth key exists More...
 
void oc_ri_remove_timed_event_callback (void *cb_data, oc_trigger_t event_callback)
 remove the timed event callback More...
 
void oc_ri_shutdown (void)
 shut down the resource implementation handler More...
 
int oc_status_code (oc_status_t key)
 convert the status code to integer More...
 

Macro Definition Documentation

◆ oc_ri_add_timed_event_callback_seconds

#define oc_ri_add_timed_event_callback_seconds (   cb_data,
  event_callback,
  seconds 
)
Value:
do { \
oc_ri_add_timed_event_callback_ticks( \
cb_data, event_callback, \
(oc_clock_time_t)seconds *(oc_clock_time_t)OC_CLOCK_SECOND); \
} while (0)

add timed event callback in seconds

Parameters
cb_datathe timed event callback info
event_callbackthe callback
secondstime in seconds

Typedef Documentation

◆ oc_event_callback_t

event callback

◆ oc_get_properties_cb_t

typedef void(* oc_get_properties_cb_t) (oc_resource_t *, oc_interface_mask_t, void *)

get properties callback

◆ oc_properties_cb_t

properties callback structure

◆ oc_request_callback_t

typedef void(* oc_request_callback_t) (oc_request_t *, oc_interface_mask_t, void *)

request callback

◆ oc_request_handler_t

request handler type

◆ oc_request_t

typedef struct oc_request_t oc_request_t

request information structure

◆ oc_response_buffer_t

typedef struct oc_response_buffer_s oc_response_buffer_t

reponse buffer type

◆ oc_response_t

typedef struct oc_response_t oc_response_t

response type

◆ oc_separate_response_t

typedef struct oc_separate_response_s oc_separate_response_t

seperate response type

◆ oc_set_properties_cb_t

typedef bool(* oc_set_properties_cb_t) (oc_resource_t *, oc_rep_t *, void *)

set properties callback

Enumeration Type Documentation

◆ oc_content_format_t

payload content formats

https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#rd-parameters

Enumerator
TEXT_PLAIN 

text/plain

TEXT_XML 

text/xml

TEXT_CSV 

text/csv

TEXT_HTML 

text/html

IMAGE_GIF 

image/gif - not used

IMAGE_JPEG 

image/jpeg - not used

IMAGE_PNG 

image/png - not used

IMAGE_TIFF 

image/tiff - not used

AUDIO_RAW 

audio/raw - not used

VIDEO_RAW 

video/raw - not used

APPLICATION_LINK_FORMAT 

application/link-format

APPLICATION_XML 

application/xml

APPLICATION_OCTET_STREAM 

application/octet-stream

APPLICATION_RDF_XML 

application - not used

APPLICATION_SOAP_XML 

application/soap - not used

APPLICATION_ATOM_XML 

application - not used

APPLICATION_XMPP_XML 

application - not used

APPLICATION_EXI 

application/exi

APPLICATION_FASTINFOSET 

application

APPLICATION_SOAP_FASTINFOSET 

application

APPLICATION_JSON 

application/json

APPLICATION_X_OBIX_BINARY 

application - not used

APPLICATION_CBOR 

application/cbor

APPLICATION_SENML_JSON 

application/senml+json

APPLICATION_SENSML_JSON 

application/sensml+json

APPLICATION_SENML_CBOR 

application/senml+cbor

APPLICATION_SENSML_CBOR 

application/sensml+cbor

APPLICATION_SENML_EXI 

application/senml-exi

APPLICATION_SENSML_EXI 

application/sensml-exi

APPLICATION_PKCS7_SGK 

application/pkcs7-mime; smime-type=server-generated-key

APPLICATION_PKCS7_CO 

application/pkcs7-mime; smime-type=certs-only

APPLICATION_PKCS7_CMC_REQUEST 

application/pkcs7-mime; smime-type=CMC-Request

APPLICATION_PKCS7_CMC_RESPONSE 

application/pkcs7-mime; smime-type=CMC-Response

APPLICATION_PKCS8 

application/pkcs8

APPLICATION_CRATTRS 

application/csrattrs

APPLICATION_PKCS10 

application/pkcs10

APPLICATION_PKIX_CERT 

application/pkix-cert

APPLICATION_VND_OCF_CBOR 

application/vnd.ocf+cbor

APPLICATION_OSCORE 

application/oscore

APPLICATION_VND_OMA_LWM2M_TLV 

application/vnd.oma.lwm2m+tlv

APPLICATION_VND_OMA_LWM2M_JSON 

application/vnd.oma.lwm2m+json

APPLICATION_VND_OMA_LWM2M_CBOR 

application/vnd.oma.lwm2m+cbor

◆ oc_interface_mask_t

interface masks

Enumerator
OC_IF_BASELINE 

oic.if.baseline

OC_IF_LL 

oic.if.ll

OC_IF_B 

oic.if.b

OC_IF_R 

oic.if.r

OC_IF_RW 

oic.if.rw

OC_IF_A 

oic.if.a

OC_IF_S 

oic.if.s

OC_IF_CREATE 

oic.if.create

OC_IF_W 

oic.if.w

OC_IF_STARTUP 

oic.if.startup

OC_IF_STARTUP_REVERT 

oic.if.startup.revert

◆ oc_method_t

CoAP methods.

Enumerator
OC_GET 

GET.

OC_POST 

POST.

OC_PUT 

PUT.

OC_DELETE 

DELETE.

OC_FETCH 

FETCH.

◆ oc_resource_properties_t

resource properties (bit mask)

Enumerator
OC_DISCOVERABLE 

discoverable

OC_OBSERVABLE 

observable

OC_SECURE 

secure

OC_PERIODIC 

periodiacal update

OC_SECURE_MCAST 

secure multicast (oscore)

◆ oc_status_t

response status can be translated to HTTP or CoAP.

Enumerator
OC_STATUS_OK 

OK.

OC_STATUS_CREATED 

Created.

OC_STATUS_CHANGED 

Changed.

OC_STATUS_DELETED 

Deleted.

OC_STATUS_NOT_MODIFIED 

Not Modified.

OC_STATUS_BAD_REQUEST 

Bad Request.

OC_STATUS_UNAUTHORIZED 

Unauthorized.

OC_STATUS_BAD_OPTION 

Bad Option.

OC_STATUS_FORBIDDEN 

Forbidden.

OC_STATUS_NOT_FOUND 

Not Found.

OC_STATUS_METHOD_NOT_ALLOWED 

Method Not Allowed.

OC_STATUS_NOT_ACCEPTABLE 

Not Acceptable.

OC_STATUS_REQUEST_ENTITY_TOO_LARGE 

Request Entity Too Large.

OC_STATUS_UNSUPPORTED_MEDIA_TYPE 

Unsupported Media Type.

OC_STATUS_INTERNAL_SERVER_ERROR 

Internal Server Error.

OC_STATUS_NOT_IMPLEMENTED 

Not Implemented.

OC_STATUS_BAD_GATEWAY 

Bad Gateway.

OC_STATUS_SERVICE_UNAVAILABLE 

Service Unavailable.

OC_STATUS_GATEWAY_TIMEOUT 

Gateway Timeout.

OC_STATUS_PROXYING_NOT_SUPPORTED 

Proxying not supported.

OC_IGNORE 

Ignore: do not respond to request.

OC_PING_TIMEOUT 

Ping Time out.

Function Documentation

◆ oc_ri_add_resource()

bool oc_ri_add_resource ( oc_resource_t resource)

add resource to the system

Parameters
resourcethe resource to be added to the list of application resources
Returns
true success
false failure

◆ oc_ri_add_timed_event_callback_ticks()

void oc_ri_add_timed_event_callback_ticks ( void *  cb_data,
oc_trigger_t  event_callback,
oc_clock_time_t  ticks 
)

add timed event callback

Parameters
cb_datathe timed event callback info
event_callbackthe callback
tickstime in ticks

◆ oc_ri_alloc_resource()

oc_resource_t* oc_ri_alloc_resource ( void  )

allocate a resource strucutre

Returns
oc_resource_t*

◆ oc_ri_delete_resource()

bool oc_ri_delete_resource ( oc_resource_t resource)

remove the resource from the list of application resources

Parameters
resourcethe resource to be removed from the list of application resources
Returns
true success
false failure

◆ oc_ri_free_resource_properties()

void oc_ri_free_resource_properties ( oc_resource_t resource)

free the properties of the resource

Parameters
resourcethe resource

◆ oc_ri_get_app_resource_by_uri()

oc_resource_t* oc_ri_get_app_resource_by_uri ( const char *  uri,
size_t  uri_len,
size_t  device 
)

retrieve the resource by uri and device indes

Parameters
urithe uri of the resource
uri_lenthe lenght of the uri
devicethe device index
Returns
oc_resource_t* the resource structure

◆ oc_ri_get_app_resources()

oc_resource_t* oc_ri_get_app_resources ( void  )

retrieve list of resources

Returns
oc_resource_t* the resource list

◆ oc_ri_get_interface_mask()

oc_interface_mask_t oc_ri_get_interface_mask ( char *  iface,
size_t  if_len 
)

retrieve the interface mask from the interface name

Parameters
ifacethe interface (e.g. "if=oic.if.s")
if_lenthe interface lenght
Returns
oc_interface_mask_t the mask value of the interface

◆ oc_ri_get_query_nth_key_value()

int oc_ri_get_query_nth_key_value ( const char *  query,
size_t  query_len,
char **  key,
size_t *  key_len,
char **  value,
size_t *  value_len,
size_t  n 
)

retrieve the query value at the nth position

Parameters
querythe input query
query_lenthe query lenght
keythe key
key_lenthe lenght of the key
valuethe value belonging to the key
value_lenthe lenght of the value
nthe posiition to query
Returns
int the position of the next key value pair in the query or NULL

◆ oc_ri_get_query_value()

int oc_ri_get_query_value ( const char *  query,
size_t  query_len,
const char *  key,
char **  value 
)

retrieve the value of the query parameter "key"

Parameters
querythe input query
query_lenthe query lenght
keythe wanted key
valuethe returned value
Returns
int the lenght of the value

◆ oc_ri_init()

void oc_ri_init ( void  )

initialize the resource implementation handler

◆ oc_ri_is_app_resource_valid()

bool oc_ri_is_app_resource_valid ( oc_resource_t resource)

checks if the resource is valid

Parameters
resourceresource to be tested
Returns
true valid
false not valid

◆ oc_ri_query_exists()

int oc_ri_query_exists ( const char *  query,
size_t  query_len,
const char *  key 
)

checks if key exist in query

Parameters
[in]querythe query to inspect
[in]query_lenthe lenght of the query
[in]keythe key to be checked if exist, key is null terminated
Returns
int -1 = not exist

◆ oc_ri_query_nth_key_exists()

int oc_ri_query_nth_key_exists ( const char *  query,
size_t  query_len,
char **  key,
size_t *  key_len,
size_t  n 
)

check if the nth key exists

Parameters
querythe query to inspect
query_lenthe lenght of the query
keythe key to be checked if exist, key is not null terminated
key_lenthe key length
n
Returns
int

◆ oc_ri_remove_timed_event_callback()

void oc_ri_remove_timed_event_callback ( void *  cb_data,
oc_trigger_t  event_callback 
)

remove the timed event callback

Parameters
cb_datathe timed event callback info
event_callbackthe callback

◆ oc_ri_shutdown()

void oc_ri_shutdown ( void  )

shut down the resource implementation handler

◆ oc_status_code()

int oc_status_code ( oc_status_t  key)

convert the status code to integer

Parameters
keythe application level key of the code
Returns
int the CoAP status code