Skip to content

Commit

Permalink
Fix code formatting
Browse files Browse the repository at this point in the history
Fix code formatting
  • Loading branch information
parmi93 committed Aug 15, 2023
1 parent 77c25db commit f66a04c
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 333 deletions.
7 changes: 4 additions & 3 deletions core/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@
#define URI_REGISTRATION_SEGMENT_LEN 2
#define URI_BOOTSTRAP_SEGMENT "bs"
#define URI_BOOTSTRAP_SEGMENT_LEN 2
#define URI_SEND_SEGMENT "dp"
#define URI_SEND_SEGMENT_LEN 2
#define URI_SEND_SEGMENT "dp"
#define URI_SEND_SEGMENT_LEN 2

#define QUERY_STARTER "?"
#define QUERY_NAME "ep="
Expand Down Expand Up @@ -323,7 +323,8 @@ int object_getServers(lwm2m_context_t * contextP, bool checkOnly);
uint8_t object_createInstance(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, lwm2m_data_t * dataP);
uint8_t object_writeInstance(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, lwm2m_data_t * dataP);
#ifndef LWM2M_VERSION_1_0
uint8_t object_readCompositeData(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, size_t numUris, int * sizeP, lwm2m_data_t ** dataP);
uint8_t object_readCompositeData(lwm2m_context_t *contextP, lwm2m_uri_t *uriP, size_t numUris, int *sizeP,
lwm2m_data_t **dataP);
#endif

// defined in transaction.c
Expand Down
190 changes: 56 additions & 134 deletions core/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,125 +1234,86 @@ uint8_t object_writeInstance(lwm2m_context_t * contextP,
}

#ifndef LWM2M_VERSION_1_0
uint8_t object_readCompositeData(lwm2m_context_t * contextP,
lwm2m_uri_t * uriP,
size_t numUris,
int * sizeP,
lwm2m_data_t ** dataP)
{
uint8_t object_readCompositeData(lwm2m_context_t *contextP, lwm2m_uri_t *uriP, size_t numUris, int *sizeP,
lwm2m_data_t **dataP) {
size_t i;
int count;
uint8_t result = COAP_205_CONTENT;

*sizeP = 0;
*dataP = NULL;

for (i = 0; i < numUris; i++)
{
for (i = 0; i < numUris; i++) {
int partialSize = 0;
lwm2m_data_t *partialDataP = NULL;
uint8_t res;
if (uriP[i].objectId == LWM2M_SECURITY_OBJECT_ID
|| uriP[i].objectId == LWM2M_OSCORE_OBJECT_ID)
{
if (uriP[i].objectId == LWM2M_SECURITY_OBJECT_ID || uriP[i].objectId == LWM2M_OSCORE_OBJECT_ID) {
res = COAP_401_UNAUTHORIZED;
}
else
{
} else {
res = object_readData(contextP, uriP + i, &partialSize, &partialDataP);
}
if (res == COAP_205_CONTENT && partialSize > 0)
{
if (res == COAP_205_CONTENT && partialSize > 0) {
size_t *countP;
lwm2m_data_t **childrenP;
bool finished = false;
lwm2m_data_t *parentP = NULL;
size_t j;

if (LWM2M_URI_IS_SET_OBJECT(uriP + i))
{
if (LWM2M_URI_IS_SET_OBJECT(uriP + i)) {
// Find the object
for (j = 0; (int)j < *sizeP; j++)
{
if (uriP[i].objectId == (*dataP)[j].id)
{
if (LWM2M_URI_IS_SET_INSTANCE(uriP + i))
{
for (j = 0; (int)j < *sizeP; j++) {
if (uriP[i].objectId == (*dataP)[j].id) {
if (LWM2M_URI_IS_SET_INSTANCE(uriP + i)) {
parentP = (*dataP) + j;
}
else
{
} else {
// Duplicate or overlapping reads. Replace all instances.
lwm2m_data_free((*dataP)[j].value.asChildren.count,
(*dataP)[j].value.asChildren.array);
lwm2m_data_free((*dataP)[j].value.asChildren.count, (*dataP)[j].value.asChildren.array);
(*dataP)[j].value.asChildren.count = partialSize;
(*dataP)[j].value.asChildren.array = partialDataP;
finished = true;
}
break;
}
}
if ((int)j == *sizeP)
{
if ((int)j == *sizeP) {
// Need to add a new object
if (0 != lwm2m_data_append_one(sizeP,
dataP,
LWM2M_TYPE_OBJECT,
uriP[i].objectId))
{
if (0 != lwm2m_data_append_one(sizeP, dataP, LWM2M_TYPE_OBJECT, uriP[i].objectId)) {
parentP = *dataP + *sizeP - 1;

if (!LWM2M_URI_IS_SET_INSTANCE(uriP + i))
{
if (!LWM2M_URI_IS_SET_INSTANCE(uriP + i)) {
// Need to add the instances
parentP->value.asChildren.count = partialSize;
parentP->value.asChildren.array = partialDataP;
finished = true;
}
}
else
{
} else {
lwm2m_data_free(partialSize, partialDataP);
if (result == COAP_205_CONTENT)
{
if (result == COAP_205_CONTENT) {
result = COAP_400_BAD_REQUEST;
}
finished = true;
}
}
}
else
{
} else {
// Root level. Add objects
if (0 == lwm2m_data_append(sizeP,
dataP,
partialSize,
partialDataP))
{
if (0 == lwm2m_data_append(sizeP, dataP, partialSize, partialDataP)) {
lwm2m_data_free(partialSize, partialDataP);
if (result == COAP_205_CONTENT)
{
if (result == COAP_205_CONTENT) {
result = COAP_400_BAD_REQUEST;
}
}
finished = true;
}

if (!finished)
{
if (!finished) {
// Find the instance
countP = &parentP->value.asChildren.count;
childrenP = &parentP->value.asChildren.array;
for (j = 0; j < *countP; j++)
{
if (uriP[i].instanceId == (*childrenP)[j].id)
{
if (LWM2M_URI_IS_SET_RESOURCE(uriP + i))
{
for (j = 0; j < *countP; j++) {
if (uriP[i].instanceId == (*childrenP)[j].id) {
if (LWM2M_URI_IS_SET_RESOURCE(uriP + i)) {
parentP = (*childrenP) + j;
}
else
{
} else {
// Duplicate or overlapping reads. replace all resources.
lwm2m_data_free((*childrenP)[j].value.asChildren.count,
(*childrenP)[j].value.asChildren.array);
Expand All @@ -1363,65 +1324,48 @@ uint8_t object_readCompositeData(lwm2m_context_t * contextP,
break;
}
}
if (j == *countP)
{
if (j == *countP) {
// Need to add a new instance
count = parentP->value.asChildren.count;
if (0 != lwm2m_data_append_one(&count,
&parentP->value.asChildren.array,
LWM2M_TYPE_OBJECT_INSTANCE,
uriP[i].instanceId))
{
if (0 != lwm2m_data_append_one(&count, &parentP->value.asChildren.array, LWM2M_TYPE_OBJECT_INSTANCE,
uriP[i].instanceId)) {
parentP->value.asChildren.count = count;
parentP = parentP->value.asChildren.array + count - 1;

if (!LWM2M_URI_IS_SET_RESOURCE(uriP + i))
{
if (!LWM2M_URI_IS_SET_RESOURCE(uriP + i)) {
parentP->value.asChildren.count = partialSize;
parentP->value.asChildren.array = partialDataP;
finished = true;
}
}
else
{
} else {
lwm2m_data_free(partialSize, partialDataP);
if (result == COAP_205_CONTENT)
{
if (result == COAP_205_CONTENT) {
result = COAP_400_BAD_REQUEST;
}
finished = true;
}
}
}

if (!finished)
{
if (!finished) {
// Find the resource
countP = &parentP->value.asChildren.count;
childrenP = &parentP->value.asChildren.array;
for (j = 0; j < *countP; j++)
{
if (uriP[i].resourceId == (*childrenP)[j].id)
{
if (LWM2M_URI_IS_SET_RESOURCE_INSTANCE(uriP + i))
{
for (j = 0; j < *countP; j++) {
if (uriP[i].resourceId == (*childrenP)[j].id) {
if (LWM2M_URI_IS_SET_RESOURCE_INSTANCE(uriP + i)) {
parentP = (*childrenP) + j;
}
else
{
} else {
// Duplicate or overlapping reads.
if ((*childrenP)[j].type == LWM2M_TYPE_MULTIPLE_RESOURCE)
{
if ((*childrenP)[j].type == LWM2M_TYPE_MULTIPLE_RESOURCE) {
// Replace the resource instances
lwm2m_data_free((*childrenP)[j].value.asChildren.count,
(*childrenP)[j].value.asChildren.array);
(*childrenP)[j].value.asChildren.count = partialSize;
(*childrenP)[j].value.asChildren.array = partialDataP;
}
else
{
} else {
// Overwrite the value
memcpy((*childrenP)+j, partialDataP, sizeof(lwm2m_data_t));
memcpy((*childrenP) + j, partialDataP, sizeof(lwm2m_data_t));
// Shallow free
memset(partialDataP, 0, sizeof(lwm2m_data_t));
lwm2m_data_free(partialSize, partialDataP);
Expand All @@ -1431,15 +1375,11 @@ uint8_t object_readCompositeData(lwm2m_context_t * contextP,
break;
}
}
if (j == *countP)
{
if (j == *countP) {
// Need to add a new resource
count = parentP->value.asChildren.count;
if (0 != lwm2m_data_append_one(&count,
&parentP->value.asChildren.array,
LWM2M_TYPE_UNDEFINED,
uriP[i].instanceId))
{
if (0 != lwm2m_data_append_one(&count, &parentP->value.asChildren.array, LWM2M_TYPE_UNDEFINED,
uriP[i].instanceId)) {
parentP->value.asChildren.count = count;
parentP = parentP->value.asChildren.array + count - 1;

Expand All @@ -1448,76 +1388,58 @@ uint8_t object_readCompositeData(lwm2m_context_t * contextP,
memset(partialDataP, 0, sizeof(lwm2m_data_t));
lwm2m_data_free(partialSize, partialDataP);
finished = true;
}
else
{
} else {
lwm2m_data_free(partialSize, partialDataP);
if (result == COAP_205_CONTENT)
{
if (result == COAP_205_CONTENT) {
result = COAP_400_BAD_REQUEST;
}
finished = true;
}
}
}

if (!finished)
{
if (!finished) {
// Find the resource instance
countP = &parentP->value.asChildren.count;
childrenP = &parentP->value.asChildren.array;
for (j = 0; j < *countP; j++)
{
if (uriP[i].resourceInstanceId == (*childrenP)[j].id)
{
for (j = 0; j < *countP; j++) {
if (uriP[i].resourceInstanceId == (*childrenP)[j].id) {
// Duplicate or overlapping reads.
// Overwrite the value
memcpy((*childrenP)+j, partialDataP->value.asChildren.array, sizeof(lwm2m_data_t));
memcpy((*childrenP) + j, partialDataP->value.asChildren.array, sizeof(lwm2m_data_t));
// Shallow free
memset(partialDataP, 0, sizeof(lwm2m_data_t));
lwm2m_data_free(partialSize, partialDataP);
break;
}
}
if (j == *countP)
{
if (j == *countP) {
// Need to add a new resource instance
count = parentP->value.asChildren.count;
if (0 != lwm2m_data_append_one(&count,
&parentP->value.asChildren.array,
LWM2M_TYPE_UNDEFINED,
uriP[i].instanceId))
{
if (0 != lwm2m_data_append_one(&count, &parentP->value.asChildren.array, LWM2M_TYPE_UNDEFINED,
uriP[i].instanceId)) {
parentP->value.asChildren.count = count;
parentP = parentP->value.asChildren.array + count - 1;
memcpy(parentP, partialDataP->value.asChildren.array, sizeof(lwm2m_data_t));
// Shallow free
memset(partialDataP, 0, sizeof(lwm2m_data_t));
lwm2m_data_free(partialSize, partialDataP);
}
else
{
} else {
lwm2m_data_free(partialSize, partialDataP);
if (result == COAP_205_CONTENT)
{
if (result == COAP_205_CONTENT) {
result = COAP_400_BAD_REQUEST;
}
}
}
}
}
else if (result == COAP_205_CONTENT && res != COAP_404_NOT_FOUND)
{
} else if (result == COAP_205_CONTENT && res != COAP_404_NOT_FOUND) {
result = res;
}
}

if (*sizeP > 0)
{
if (*sizeP > 0) {
result = COAP_205_CONTENT;
}
else if (result == COAP_205_CONTENT)
{
} else if (result == COAP_205_CONTENT) {
result = COAP_404_NOT_FOUND;
}

Expand Down
Loading

0 comments on commit f66a04c

Please sign in to comment.