[riot-notifications] [RIOT-OS/RIOT] pkg/wakaama: add get set functions and cleanup client connection (#16203)

José Alamos notifications at github.com
Thu Jun 17 12:16:51 CEST 2021


@jia200x requested changes on this pull request.

Some minor comments

> +        *(bool *)out = data->value.asBoolean;
+        break;
+
+    case LWM2M_TYPE_OBJECT_LINK:
+    {
+        _objlink_t *_out = (_objlink_t *)out;
+        *_out->object_id = data->value.asObjLink.objectId;
+        *_out->instance_id = data->value.asObjLink.objectInstanceId;
+        break;
+    }
+
+    case LWM2M_TYPE_STRING:
+    case LWM2M_TYPE_OPAQUE:
+        if (data->value.asBuffer.length > out_len) {
+            DEBUG("[lwm2m:get_data] not enough space in buffer\n");
+            result = -1;

```suggestion
            result = -ENOMEM;
```

> +static int _get_resource_data(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri,
+                              lwm2m_data_type_t expected_type, void *out, size_t out_len)
+{
+    assert(client_data);
+    assert(uri);
+    assert(out);
+
+    int result = 0;
+    int data_num = 1;
+    lwm2m_data_t *data = NULL;
+
+    /* try to find the requested object */
+    lwm2m_object_t *object = lwm2m_get_object_by_id(client_data, uri->objectId);
+    if (!object || !object->readFunc) {
+        DEBUG("[lwm2m:get_data] could not find object with ID %d\n", uri->objectId);
+        result = -1;

```suggestion
        result = -ENOENT;
```

> +    /* try to find the requested object */
+    lwm2m_object_t *object = lwm2m_get_object_by_id(client_data, uri->objectId);
+    if (!object || !object->readFunc) {
+        DEBUG("[lwm2m:get_data] could not find object with ID %d\n", uri->objectId);
+        result = -1;
+        goto out;
+    }
+
+    /* prepare a new data structure */
+    data = lwm2m_data_new(1);
+    data->id = uri->resourceId;
+
+    /* read the resource from the specified instance */
+    uint8_t res = object->readFunc(uri->instanceId, &data_num, &data, object);
+    if (res != COAP_205_CONTENT || data->type != expected_type) {
+        result = -1;

```suggestion
        result = -EINVAL;
```

> + * @param[out] out               Pointer where to store the data.
+ * @param[in]  out_len           Length of @p out.
+ *
+ * @return 0 on success
+ * @return <0 otherwise
+ */
+static int _get_resource_data_by_path(lwm2m_client_data_t *client_data, const char *path,
+                                      size_t path_len, lwm2m_data_type_t expected_type, void *out,
+                                      size_t out_len)
+{
+    assert(path);
+
+    lwm2m_uri_t uri;
+    if (!lwm2m_stringToUri(path, path_len, &uri)) {
+        DEBUG("[lwm2m:get_resource] malformed path\n");
+        return -1;

```suggestion
        return -EINVAL;
```

> +    }
+
+    case LWM2M_TYPE_STRING:
+    case LWM2M_TYPE_OPAQUE:
+        if (data->value.asBuffer.length > out_len) {
+            DEBUG("[lwm2m:get_data] not enough space in buffer\n");
+            result = -1;
+        }
+        else {
+            memcpy(out, data->value.asBuffer.buffer, data->value.asBuffer.length);
+        }
+        break;
+
+    default:
+        DEBUG("[lwm2m:get_data] not supported type\n");
+        result = -1;

```suggestion
        result = -ENOTSUP;
```

> +
+static int _set_resource_data(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri,
+                              lwm2m_data_type_t type, void *in, size_t in_len)
+{
+    assert(client_data);
+    assert(uri);
+    assert(in);
+
+    int result = 0;
+    lwm2m_data_t *data = NULL;
+
+    /* try to find the requested object */
+    lwm2m_object_t *object = lwm2m_get_object_by_id(client_data, uri->objectId);
+    if (!object || !object->writeFunc) {
+        DEBUG("[lwm2m:get_data] could not find object with ID %d\n", uri->objectId);
+        result = -1;

```suggestion
        result = -ENOENT;
```

> +    {
+        _objlink_t *_in = (_objlink_t *)in;
+        data->value.asObjLink.objectId = *_in->object_id;
+        data->value.asObjLink.objectInstanceId = *_in->instance_id;
+        break;
+    }
+
+    case LWM2M_TYPE_STRING:
+    case LWM2M_TYPE_OPAQUE:
+        data->value.asBuffer.length = in_len;
+        data->value.asBuffer.buffer = in;
+        break;
+
+    default:
+        DEBUG("[lwm2m:get_data] not supported type\n");
+        result = -1;

```suggestion
        result = -ENOTSUP;
```

> +    case LWM2M_TYPE_OPAQUE:
+        data->value.asBuffer.length = in_len;
+        data->value.asBuffer.buffer = in;
+        break;
+
+    default:
+        DEBUG("[lwm2m:get_data] not supported type\n");
+        result = -1;
+        goto free_out;
+        break;
+    }
+
+    /* write the resource of the specified instance */
+    uint8_t res = object->writeFunc(uri->instanceId, 1, data, object);
+    if (res != COAP_204_CHANGED) {
+        result = -1;

```suggestion
        result = -EINVAL;
```

> + * @param[in]  in               Pointer where to store the data.
+ * @param[in]  in_len           Length of @p out.
+ *
+ * @return 0 on success
+ * @return <0 otherwise
+ */
+static int _set_resource_data_by_path(lwm2m_client_data_t *client_data, const char *path,
+                                      size_t path_len, lwm2m_data_type_t type, void *in,
+                                      size_t in_len)
+{
+    assert(path);
+
+    lwm2m_uri_t uri;
+    if (!lwm2m_stringToUri(path, path_len, &uri)) {
+        DEBUG("[lwm2m:set_resource] malformed path\n");
+        return -1;

```suggestion
        return -EINVAL;
```

> +
+    case LWM2M_TYPE_STRING:
+    case LWM2M_TYPE_OPAQUE:
+        if (data->value.asBuffer.length > out_len) {
+            DEBUG("[lwm2m:get_data] not enough space in buffer\n");
+            result = -1;
+        }
+        else {
+            memcpy(out, data->value.asBuffer.buffer, data->value.asBuffer.length);
+        }
+        break;
+
+    default:
+        DEBUG("[lwm2m:get_data] not supported type\n");
+        result = -1;
+        break;

Just in case someone else adds code right after the switch-case
```suggestion
        goto free_out;
        break;
```

> +        break;
+
+    case LWM2M_TYPE_OBJECT_LINK:
+    {
+        _objlink_t *_out = (_objlink_t *)out;
+        *_out->object_id = data->value.asObjLink.objectId;
+        *_out->instance_id = data->value.asObjLink.objectInstanceId;
+        break;
+    }
+
+    case LWM2M_TYPE_STRING:
+    case LWM2M_TYPE_OPAQUE:
+        if (data->value.asBuffer.length > out_len) {
+            DEBUG("[lwm2m:get_data] not enough space in buffer\n");
+            result = -1;
+        }

```suggestion
        goto free_out;
        }
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16203#pullrequestreview-686090356
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210617/ab2d1c21/attachment.htm>


More information about the notifications mailing list