You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/12/18 21:56:49 UTC

[21/50] incubator-mynewt-core git commit: oic; don't automatically decode incoming payload to a tree of allocated objects. Make handlers do the decoding, allowing them to use stack-only construct.

oic; don't automatically decode incoming payload to a tree of
allocated objects. Make handlers do the decoding, allowing them
to use stack-only construct.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3657169a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3657169a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3657169a

Branch: refs/heads/sensors_branch
Commit: 3657169a4e3190f317c768f8423fd6a7c6eb2ff1
Parents: a372c10
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 12:18:08 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Sun Dec 18 13:56:16 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_rep.h         |  2 +
 net/oic/include/oic/oc_ri.h          |  4 +-
 net/oic/src/api/oc_discovery.c       | 66 +++++++++++++++----------------
 net/oic/src/api/oc_rep.c             |  4 ++
 net/oic/src/api/oc_ri.c              | 26 +-----------
 net/oic/src/messaging/coap/observe.c |  1 -
 6 files changed, 40 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3657169a/net/oic/include/oic/oc_rep.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_rep.h b/net/oic/include/oic/oc_rep.h
index 4ccaa20..72ae7fc 100644
--- a/net/oic/include/oic/oc_rep.h
+++ b/net/oic/include/oic/oc_rep.h
@@ -190,6 +190,7 @@ int oc_rep_finalize(void);
     g_err |= cbor_encoder_close_container(&object##_map, &key##_value_array);  \
   } while (0)
 
+#ifdef OC_CLIENT
 typedef enum {
   NIL = 0,
   INT = 0x01,
@@ -229,6 +230,7 @@ uint16_t oc_parse_rep(const uint8_t *payload, uint16_t payload_size,
                       oc_rep_t **value_list);
 
 void oc_free_rep(oc_rep_t *rep);
+#endif
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3657169a/net/oic/include/oic/oc_ri.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_ri.h b/net/oic/include/oic/oc_ri.h
index c501f46..9f07d5f 100644
--- a/net/oic/include/oic/oc_ri.h
+++ b/net/oic/include/oic/oc_ri.h
@@ -97,13 +97,11 @@ typedef enum {
 
 typedef struct oc_resource oc_resource_t;
 
-typedef struct
-{
+typedef struct {
   oc_endpoint_t *origin;
   oc_resource_t *resource;
   const char *query;
   int query_len;
-  oc_rep_t *request_payload;
   oc_response_t *response;
   void *packet;
 } oc_request_t;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3657169a/net/oic/src/api/oc_discovery.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_discovery.c b/net/oic/src/api/oc_discovery.c
index 29311b7..be5be0c 100644
--- a/net/oic/src/api/oc_discovery.c
+++ b/net/oic/src/api/oc_discovery.c
@@ -127,45 +127,43 @@ process_device_object(CborEncoder *device, const char *uuid, const char *rt,
 }
 
 static void
-oc_core_discovery_handler(oc_request_t *request, oc_interface_mask_t interface)
+oc_core_discovery_handler(oc_request_t *req, oc_interface_mask_t interface)
 {
-  char *rt = NULL;
-  int rt_len = 0, matches = 0;
-  if (request->query_len) {
-    rt_len =
-      oc_ri_get_query_value(request->query, request->query_len, "rt", &rt);
-  }
+    char *rt = NULL;
+    int rt_len = 0, matches = 0;
+    char uuid[37];
 
-  char uuid[37];
-  oc_uuid_to_str(oc_core_get_device_id(0), uuid, 37);
+    rt_len = oc_ri_get_query_value(req->query, req->query_len, "rt", &rt);
 
-  switch (interface) {
-  case OC_IF_LL: {
-    oc_rep_start_links_array();
-    matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len);
-    oc_rep_end_links_array();
-  } break;
-  case OC_IF_BASELINE: {
-    oc_rep_start_root_object();
-    oc_process_baseline_interface(request->resource);
-    oc_rep_set_array(root, links);
-    matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len);
-    oc_rep_close_array(root, links);
-    oc_rep_end_root_object();
-  } break;
-  default:
-    break;
-  }
+    oc_uuid_to_str(oc_core_get_device_id(0), uuid, sizeof(uuid));
 
-  int response_length = oc_rep_finalize();
+    switch (interface) {
+    case OC_IF_LL: {
+        oc_rep_start_links_array();
+        matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len);
+        oc_rep_end_links_array();
+    } break;
+    case OC_IF_BASELINE: {
+        oc_rep_start_root_object();
+        oc_process_baseline_interface(req->resource);
+        oc_rep_set_array(root, links);
+        matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len);
+        oc_rep_close_array(root, links);
+        oc_rep_end_root_object();
+    } break;
+    default:
+        break;
+    }
 
-  if (matches && response_length > 0) {
-    request->response->response_buffer->response_length = response_length;
-    request->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
-  } else {
-    /* There were rt/if selections and there were no matches, so ignore */
-    request->response->response_buffer->code = OC_IGNORE;
-  }
+    int response_length = oc_rep_finalize();
+
+    if (matches && response_length > 0) {
+        req->response->response_buffer->response_length = response_length;
+        req->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
+    } else {
+        /* There were rt/if selections and there were no matches, so ignore */
+        req->response->response_buffer->code = OC_IGNORE;
+    }
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3657169a/net/oic/src/api/oc_rep.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_rep.c b/net/oic/src/api/oc_rep.c
index 4ef7161..20a133a 100644
--- a/net/oic/src/api/oc_rep.c
+++ b/net/oic/src/api/oc_rep.c
@@ -25,9 +25,11 @@
 #include <tinycbor/cbor_buf_writer.h>
 #include <tinycbor/cbor_buf_reader.h>
 
+#ifdef OC_CLIENT
 static struct os_mempool oc_rep_objects;
 static uint8_t oc_rep_objects_area[OS_MEMPOOL_BYTES(EST_NUM_REP_OBJECTS,
       sizeof(oc_rep_t))];
+#endif
 
 static const CborEncoder g_empty;
 static uint8_t *g_buf;
@@ -61,6 +63,7 @@ oc_rep_reset(void)
     g_encoder = g_empty;
 }
 
+#ifdef OC_CLIENT
 static oc_rep_t *
 _alloc_rep(void)
 {
@@ -321,3 +324,4 @@ oc_rep_init(void)
     os_mempool_init(&oc_rep_objects, EST_NUM_REP_OBJECTS,
       sizeof(oc_rep_t), oc_rep_objects_area, "oc_rep_o");
 }
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3657169a/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index d240193..36d3cbb 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -229,8 +229,8 @@ oc_ri_init(void)
   SLIST_INIT(&oc_client_cbs);
   os_mempool_init(&oc_client_cb_pool, MAX_NUM_CONCURRENT_REQUESTS,
     sizeof(oc_client_cb_t), oc_client_cb_area, "oc_cl_cbs");
-#endif
   oc_rep_init();
+#endif
   oc_buffer_init();
 
   start_processes();
@@ -393,7 +393,6 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
   response_obj.response_buffer = &response_buffer;
 
   request_obj.response = &response_obj;
-  request_obj.request_payload = 0;
   request_obj.query_len = 0;
   request_obj.resource = 0;
   request_obj.origin = endpoint;
@@ -422,22 +421,6 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
     }
   }
 
-  /* Obtain handle to buffer containing the serialized payload */
-  const uint8_t *payload;
-  int payload_len = coap_get_payload(request, &payload);
-  if (payload_len) {
-    /* Attempt to parse request payload using tinyCBOR via oc_rep helper
-     * functions. The result of this parse is a tree of oc_rep_t structures
-     * which will reflect the schema of the payload.
-     * Any failures while parsing the payload is viewed as an erroneous
-     * request and results in a 4.00 response being sent.
-     */
-    if (oc_parse_rep(payload, payload_len, &request_obj.request_payload) != 0) {
-      OC_LOG_ERROR("ocri: error parsing request payload\n");
-      bad_request = true;
-    }
-  }
-
   oc_resource_t *resource, *cur_resource = NULL;
 
   /* If there were no errors thus far, attempt to locate the specific
@@ -530,13 +513,6 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
     }
   }
 
-  if (payload_len) {
-    /* To the extent that the request payload was parsed, free the
-     * payload structure (and return its memory to the pool).
-     */
-    oc_free_rep(request_obj.request_payload);
-  }
-
   if (bad_request) {
     OC_LOG_ERROR("ocri: Bad request\n");
     /* Return a 4.00 response */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3657169a/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
index 73d70e8..1b7404d 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -214,7 +214,6 @@ coap_notify_observers(oc_resource_t *resource,
         response.response_buffer = &response_buffer;
         request.resource = resource;
         request.response = &response;
-        request.request_payload = NULL;
         oc_rep_new(buffer, COAP_MAX_BLOCK_SIZE);
         resource->get_handler(&request, resource->default_interface);
         response_buf = &response_buffer;