} CAAdapterState_t;
/**
+ * Format indicating which encoding has been used on the payload.
+ */
+typedef enum
+{
+ CA_FORMAT_UNDEFINED, /**< Undefined enoding format */
+ CA_FORMAT_UNSUPPORTED, /**< Unsupported encoding format */
+ CA_FORMAT_CBOR /**< CBOR encoding format */
+} CAPayloadFormat_t;
+
+/**
* Header options structure to be filled
*
* This structure is used to hold header information.
uint8_t numOptions; /**< Number of Header options */
CAPayload_t payload; /**< payload of the request */
size_t payloadSize; /**< size in bytes of the payload */
+ CAPayloadFormat_t payloadFormat; /**< format of the payload */
CAURI_t resourceUri; /**< Resource URI information **/
CARemoteId_t identity; /**< endpoint identity */
} CAInfo_t;
#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. */
unsigned int 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_t;
+} coap_hdr_t;
#else
typedef struct
{
}
}
+ // insert one extra header with the payload format if applicable.
+ if (CA_FORMAT_UNDEFINED != info->payloadFormat)
+ {
+ coap_list_t* node = NULL;
+ uint8_t buf[3] = {0};
+ switch (info->payloadFormat) {
+ case CA_FORMAT_CBOR:
+ node = CACreateNewOptionNode(
+ COAP_OPTION_CONTENT_FORMAT,
+ coap_encode_var_bytes(buf, (uint16_t)COAP_MEDIATYPE_APPLICATION_CBOR),
+ (char *)buf);
+ break;
+ default:
+ OIC_LOG_V(ERROR, TAG, "format option:[%d] not supported", info->payloadFormat);
+ }
+ if (!node)
+ {
+ OIC_LOG(ERROR, TAG, "format option not created");
+ return CA_STATUS_INVALID_PARAM;
+ }
+ int ret = coap_insert(optlist, node, CAOrderOpts);
+ if (ret <= 0)
+ {
+ coap_delete(node);
+ OIC_LOG(ERROR, TAG, "format option not inserted in header");
+ return CA_STATUS_INVALID_PARAM;
+ }
+ }
+
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
{
if (COAP_OPTION_URI_PATH != opt_iter.type && COAP_OPTION_URI_QUERY != opt_iter.type
&& COAP_OPTION_BLOCK1 != opt_iter.type && COAP_OPTION_BLOCK2 != opt_iter.type
- && COAP_OPTION_SIZE1 != opt_iter.type && COAP_OPTION_SIZE2 != opt_iter.type)
+ && COAP_OPTION_SIZE1 != opt_iter.type && COAP_OPTION_SIZE2 != opt_iter.type
+ && COAP_OPTION_CONTENT_FORMAT != opt_iter.type)
{
count++;
}
// set message id
outInfo->messageId = pdu->hdr->id;
+ outInfo->payloadFormat = CA_FORMAT_UNDEFINED;
if (count > 0)
{
{
OIC_LOG_V(DEBUG, TAG, "option[%d] will be filtering", opt_iter.type);
}
+ else if (COAP_OPTION_CONTENT_FORMAT == opt_iter.type)
+ {
+ if (1 == COAP_OPT_LENGTH(option) && COAP_MEDIATYPE_APPLICATION_CBOR == buf[0])
+ {
+ outInfo->payloadFormat = CA_FORMAT_CBOR;
+ }
+ else
+ {
+ outInfo->payloadFormat = CA_FORMAT_UNSUPPORTED;
+ }
+ OIC_LOG_V(DEBUG, TAG, "option[%d] has format [%d]", opt_iter.type, (uint8_t)buf[0]);
+ }
else
{
if (idx < count)
OICFree(responseInfo.info.options);
return result;
}
+ /** @todo FIXME: this should really be set according to directives from OCConverPayload. */
+ responseInfo.info.payloadFormat = CA_FORMAT_CBOR;
}
else
{
responseInfo.isMulticast = false;
responseInfo.info.payload = NULL;
responseInfo.info.payloadSize = 0;
+ responseInfo.info.payloadFormat = CA_FORMAT_UNDEFINED;
}
#ifdef WITH_PRESENCE