#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
+
#include <inttypes.h>
-#include "rdpayload.h"
+#include "oic_malloc.h"
+#include "ocpayload.h"
+#include "ocstack.h"
#ifdef __cplusplus
extern "C"
#ifdef TB_LOG
#define OIC_LOG_PAYLOAD(level, payload) OCPayloadLog((level),(payload))
#define UUID_SIZE (16)
+
+#ifdef WITH_PRESENCE
const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
+#endif
+
+INLINE_API void OCPayloadLogRep(LogLevel level, OCRepPayload* payload);
-static inline void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
+INLINE_API void OCPayloadLogRepValues(LogLevel level, OCRepPayloadValue* val)
+{
+ while (val)
+ {
+ switch(val->type)
+ {
+ case OCREP_PROP_NULL:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
+ break;
+ case OCREP_PROP_INT:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(int):%zd", val->name, val->i);
+ break;
+ case OCREP_PROP_DOUBLE:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
+ break;
+ case OCREP_PROP_BOOL:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
+ break;
+ case OCREP_PROP_STRING:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
+ break;
+ case OCREP_PROP_BYTE_STRING:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(binary):", val->name);
+ OIC_LOG_BUFFER(level, PL_TAG, val->ocByteStr.bytes, val->ocByteStr.len);
+ break;
+ case OCREP_PROP_OBJECT:
+ // Note: Only prints the URI (if available), to print further, you'll
+ // need to dig into the object better!
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(object):", val->name);
+ OCPayloadLogRep(level, val->obj);
+ break;
+ case OCREP_PROP_ARRAY:
+ switch(val->arr.type)
+ {
+ case OCREP_PROP_INT:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(int array):%zu x %zu x %zu: ",
+ val->name,
+ val->arr.dimensions[0], val->arr.dimensions[1],
+ val->arr.dimensions[2]);
+ OIC_LOG(level, PL_TAG, "\t\t Values:");
+ for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t\t %zd", val->arr.iArray[i]);
+ }
+ break;
+ case OCREP_PROP_DOUBLE:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(double array):%zu x %zu x %zu: ",
+ val->name,
+ val->arr.dimensions[0], val->arr.dimensions[1],
+ val->arr.dimensions[2]);
+ OIC_LOG(level, PL_TAG, "\t\t Values:");
+ for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t\t %lf", val->arr.dArray[i]);
+ }
+ break;
+ case OCREP_PROP_BOOL:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%zu x %zu x %zu: ",
+ val->name,
+ val->arr.dimensions[0], val->arr.dimensions[1],
+ val->arr.dimensions[2]);
+ OIC_LOG(level, PL_TAG, "\t\t Values:");
+ for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t\t %d", val->arr.bArray[i]);
+ }
+ break;
+ case OCREP_PROP_STRING:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(string array):%zu x %zu x %zu: ",
+ val->name,
+ val->arr.dimensions[0], val->arr.dimensions[1],
+ val->arr.dimensions[2]);
+ OIC_LOG(level, PL_TAG, "\t\t Values:");
+ for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t\t %s", val->arr.strArray[i]);
+ }
+ break;
+ case OCREP_PROP_BYTE_STRING:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(byte array):%zu x %zu x %zu: ",
+ val->name,
+ val->arr.dimensions[0], val->arr.dimensions[1],
+ val->arr.dimensions[2]);
+ OIC_LOG(level, PL_TAG, "\t\t Values:");
+ for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+ {
+ OIC_LOG_BUFFER(level, PL_TAG, val->arr.ocByteStrArray[i].bytes, val->arr.ocByteStrArray[i].len);
+ }
+ break;
+ case OCREP_PROP_OBJECT:
+ OIC_LOG_V(level, PL_TAG, "\t\t%s(object array):%zu x %zu x %zu: ",
+ val->name,
+ val->arr.dimensions[0], val->arr.dimensions[1],
+ val->arr.dimensions[2]);
+ OIC_LOG(level, PL_TAG, "\t\t Values:");
+
+ for (size_t i = 0; i < val->arr.dimensions[0]; i++)
+ {
+ OCPayloadLogRep(level, val->arr.objArray[i]);
+ }
+ break;
+ case OCREP_PROP_ARRAY: //Seems as nested arrays doesn't not supported in API
+ default:
+ OIC_LOG_V(ERROR, PL_TAG, "%s <-- Unknown/unsupported array type!",
+ val->name);
+ break;
+ }
+ break;
+ default:
+ OIC_LOG_V(ERROR, PL_TAG, "%s <-- Unknown type!", val->name);
+ break;
+ }
+ val = val -> next;
+ }
+}
+
+INLINE_API void OCPayloadLogRep(LogLevel level, OCRepPayload* payload)
{
OIC_LOG(level, (PL_TAG), "Payload Type: Representation");
- OCRepPayload* rep = payload;
int i = 1;
- while(rep)
+ for (OCRepPayload* rep = payload; rep; rep = rep->next, ++i)
{
OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
- OIC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
- OIC_LOG(level, PL_TAG, "\tResource Types:");
- OCStringLL* strll = rep->types;
- while(strll)
+ if (rep->uri)
{
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- strll = strll->next;
+ OIC_LOG_V(level, PL_TAG, "\tURI:%s", rep->uri);
}
- OIC_LOG(level, PL_TAG, "\tInterfaces:");
- strll = rep->interfaces;
- while(strll)
+ if (rep->types)
{
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- strll = strll->next;
+ OIC_LOG(level, PL_TAG, "\tResource Types:");
+ for (OCStringLL* strll = rep->types; strll; strll = strll->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ }
}
-
- // TODO Finish Logging: Values
- OCRepPayloadValue* val = rep->values;
-
- OIC_LOG(level, PL_TAG, "\tValues:");
-
- while(val)
+ if (rep->interfaces)
{
- switch(val->type)
+ OIC_LOG(level, PL_TAG, "\tInterfaces:");
+ for (OCStringLL* strll = rep->interfaces; strll; strll = strll->next)
{
- case OCREP_PROP_NULL:
- OIC_LOG_V(level, PL_TAG, "\t\t%s: NULL", val->name);
- break;
- case OCREP_PROP_INT:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(int):%zd", val->name, val->i);
- break;
- case OCREP_PROP_DOUBLE:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(double):%f", val->name, val->d);
- break;
- case OCREP_PROP_BOOL:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
- break;
- case OCREP_PROP_STRING:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(string):%s", val->name, val->str);
- break;
- case OCREP_PROP_BYTE_STRING:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(binary):", val->name);
- OIC_LOG_BUFFER(level, PL_TAG, val->ocByteStr.bytes, val->ocByteStr.len);
- break;
- case OCREP_PROP_OBJECT:
- // Note: Only prints the URI (if available), to print further, you'll
- // need to dig into the object better!
- OIC_LOG_V(level, PL_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
- break;
- case OCREP_PROP_ARRAY:
- switch(val->arr.type)
- {
- case OCREP_PROP_INT:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(int array):%zu x %zu x %zu",
- val->name,
- val->arr.dimensions[0], val->arr.dimensions[1],
- val->arr.dimensions[2]);
- break;
- case OCREP_PROP_DOUBLE:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(double array):%zu x %zu x %zu",
- val->name,
- val->arr.dimensions[0], val->arr.dimensions[1],
- val->arr.dimensions[2]);
- break;
- case OCREP_PROP_BOOL:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
- val->name,
- val->arr.dimensions[0], val->arr.dimensions[1],
- val->arr.dimensions[2]);
- break;
- case OCREP_PROP_STRING:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(string array):%zu x %zu x %zu",
- val->name,
- val->arr.dimensions[0], val->arr.dimensions[1],
- val->arr.dimensions[2]);
- break;
- case OCREP_PROP_BYTE_STRING:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(byte array):%zu x %zu x %zu",
- val->name,
- val->arr.dimensions[0], val->arr.dimensions[1],
- val->arr.dimensions[2]);
- break;
- case OCREP_PROP_OBJECT:
- OIC_LOG_V(level, PL_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
- val->name,
- val->arr.dimensions[0], val->arr.dimensions[1],
- val->arr.dimensions[2]);
- break;
- default:
- OIC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown/unsupported array type!",
- val->name);
- break;
- }
- break;
- default:
- OIC_LOG_V(ERROR, PL_TAG, "\t\t%s <-- Unknown type!", val->name);
- break;
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
}
- val = val -> next;
}
-
- ++i;
- rep = rep->next;
+ OIC_LOG(level, PL_TAG, "\tValues:");
+ OCPayloadLogRepValues(level, rep->values);
}
+}
+static void OCStringLLPrint(LogLevel level, OCStringLL *type)
+{
+ for (OCStringLL *strll = type; strll; strll = strll->next)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t %s", strll->value);
+ }
}
-static inline void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payload)
+INLINE_API void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* payload)
{
OIC_LOG(level, PL_TAG, "Payload Type: Discovery");
- int i = 1;
- if(!payload->resources)
+ while(payload && payload->resources)
{
- OIC_LOG(level, PL_TAG, "\tNO Resources");
- return;
- }
- OIC_LOG(level, PL_TAG, "\tSID:");
- OIC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
- OCResourcePayload* res = payload->resources;
+ OIC_LOG_V(level, PL_TAG, "\tDI: %s", payload->sid);
+ if (payload->baseURI)
+ {
+ OIC_LOG_V(level, PL_TAG, "\tBase URI:%s", payload->baseURI);
+ }
+ if (payload->name)
+ {
+ OIC_LOG_V(level, PL_TAG, "\tNAME: %s", payload->name);
+ }
- while(res)
- {
- OIC_LOG_V(level, PL_TAG, "\tResource #%d", i);
- OIC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
- OIC_LOG(level, PL_TAG, "\tResource Types:");
- OCStringLL* strll = res->types;
- while(strll)
+ if (payload->type)
{
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- strll = strll->next;
+ OIC_LOG(level, PL_TAG, "\tResource Type:");
+ OCStringLLPrint(level, payload->type);
}
- OIC_LOG(level, PL_TAG, "\tInterfaces:");
- strll = res->interfaces;
- while(strll)
+
+ if (payload->iface)
{
- OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
- strll = strll->next;
+ OIC_LOG(level, PL_TAG, "\tInterface:");
+ OCStringLLPrint(level, payload->iface);
}
- OIC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
- OIC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
- OIC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
- OIC_LOG(level, PL_TAG, "");
- res = res->next;
- ++i;
- }
-}
+ OCResourcePayload* res = payload->resources;
-static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
-{
- OIC_LOG(level, PL_TAG, "Payload Type: Device");
- OIC_LOG(level, PL_TAG, "\tSID:");
- OIC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
- OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
- OIC_LOG_V(level, PL_TAG, "\tSpec Version%s", payload->specVersion);
- OIC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
-}
+ int i = 1;
+ while(res)
+ {
+ OIC_LOG_V(level, PL_TAG, "\tLink#%d", i);
+ OIC_LOG_V(level, PL_TAG, "\tURI:%s", res->uri);
+ OIC_LOG(level, PL_TAG, "\tResource Types:");
+ OCStringLL* strll = res->types;
+ while(strll)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ strll = strll->next;
+ }
+ OIC_LOG(level, PL_TAG, "\tInterfaces:");
+ strll = res->interfaces;
+ while(strll)
+ {
+ OIC_LOG_V(level, PL_TAG, "\t\t%s", strll->value);
+ strll = strll->next;
+ }
-static inline void OCPayloadLogPlatform(LogLevel level, OCPlatformPayload* payload)
-{
- OIC_LOG(level, PL_TAG, "Payload Type: Platform");
- OIC_LOG_V(level, PL_TAG, "\tURI:%s", payload->uri);
- OIC_LOG_V(level, PL_TAG, "\tPlatform ID:%s", payload->info.platformID);
- OIC_LOG_V(level, PL_TAG, "\tMfg Name:%s", payload->info.manufacturerName);
- OIC_LOG_V(level, PL_TAG, "\tMfg URL:%s", payload->info.manufacturerUrl);
- OIC_LOG_V(level, PL_TAG, "\tModel Number:%s", payload->info.modelNumber);
- OIC_LOG_V(level, PL_TAG, "\tDate of Mfg:%s", payload->info.dateOfManufacture);
- OIC_LOG_V(level, PL_TAG, "\tPlatform Version:%s", payload->info.platformVersion);
- OIC_LOG_V(level, PL_TAG, "\tOS Version:%s", payload->info.operatingSystemVersion);
- OIC_LOG_V(level, PL_TAG, "\tHardware Version:%s", payload->info.hardwareVersion);
- OIC_LOG_V(level, PL_TAG, "\tFirmware Version:%s", payload->info.firmwareVersion);
- OIC_LOG_V(level, PL_TAG, "\tSupport URL:%s", payload->info.supportUrl);
- OIC_LOG_V(level, PL_TAG, "\tSystem Time:%s", payload->info.systemTime);
+ OIC_LOG_V(level, PL_TAG, "\tBitmap: %u", res->bitmap);
+ OIC_LOG_V(level, PL_TAG, "\tSecure?: %s", res->secure ? "true" : "false");
+ OIC_LOG_V(level, PL_TAG, "\tPort: %u", res->port);
+ OIC_LOG(level, PL_TAG, "");
+ res = res->next;
+ ++i;
+ }
+ payload = payload->next;
+ }
}
-static inline void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
+#ifdef WITH_PRESENCE
+INLINE_API void OCPayloadLogPresence(LogLevel level, OCPresencePayload* payload)
{
OIC_LOG(level, PL_TAG, "Payload Type: Presence");
OIC_LOG_V(level, PL_TAG, "\tSequence Number:%u", payload->sequenceNumber);
OIC_LOG_V(level, PL_TAG, "\tTrigger:%s", convertTriggerEnumToString(payload->trigger));
OIC_LOG_V(level, PL_TAG, "\tResource Type:%s", payload->resourceType);
}
+#endif // WITH_PRESENCE
-static inline void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
+INLINE_API void OCPayloadLogSecurity(LogLevel level, OCSecurityPayload* payload)
{
+ size_t payloadSize = payload->payloadSize;
OIC_LOG(level, PL_TAG, "Payload Type: Security");
- OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", payload->securityData);
-}
-static inline void OCRDPayloadLog(const LogLevel level, const OCRDPayload *payload)
-{
- if (!payload)
+ if (payloadSize > 0)
{
- return;
- }
+ // Add a zero-character string terminator.
+ char *securityData = (char *)OICMalloc(payloadSize + 1);
- if (payload->rdDiscovery)
- {
- OIC_LOG(level, PL_TAG, "RD Discovery");
- OIC_LOG_V(level, PL_TAG, " Device Name : %s", payload->rdDiscovery->n.deviceName);
- OIC_LOG_V(level, PL_TAG, " Device Identity : %s", payload->rdDiscovery->di.id);
- OIC_LOG_V(level, PL_TAG, " Bias: %d", payload->rdDiscovery->sel);
- }
- if (payload->rdPublish)
- {
- OIC_LOG(level, PL_TAG, "RD Publish");
- OCResourceCollectionPayload *rdPublish = payload->rdPublish;
- OCTagsLog(level, rdPublish->tags);
- OCLinksLog(level, rdPublish->setLinks);
+ if (securityData)
+ {
+ memcpy(securityData, payload->securityData, payloadSize);
+ // assert(securityData[payloadSize - 1] != '\0');
+ securityData[payloadSize] = '\0';
+ OIC_LOG_V(level, PL_TAG, "\tSecurity Data: %s", securityData);
+ OICFree(securityData);
+ }
}
}
-static inline void OCPayloadLog(LogLevel level, OCPayload* payload)
+INLINE_API void OCPayloadLog(LogLevel level, OCPayload* payload)
{
if(!payload)
{
case PAYLOAD_TYPE_DISCOVERY:
OCPayloadLogDiscovery(level, (OCDiscoveryPayload*)payload);
break;
- case PAYLOAD_TYPE_DEVICE:
- OCPayloadLogDevice(level, (OCDevicePayload*)payload);
- break;
- case PAYLOAD_TYPE_PLATFORM:
- OCPayloadLogPlatform(level, (OCPlatformPayload*)payload);
- break;
+#ifdef WITH_PRESENCE
case PAYLOAD_TYPE_PRESENCE:
OCPayloadLogPresence(level, (OCPresencePayload*)payload);
break;
+#endif
case PAYLOAD_TYPE_SECURITY:
OCPayloadLogSecurity(level, (OCSecurityPayload*)payload);
break;
- case PAYLOAD_TYPE_RD:
- OCRDPayloadLog(level, (OCRDPayload*)payload);
- break;
default:
OIC_LOG_V(level, PL_TAG, "Unknown Payload Type: %d", payload->type);
break;