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

[3/3] incubator-mynewt-core git commit: oic; move the check for use of tcp-style headers to take place inside coap_serialize_message().

oic; move the check for use of tcp-style headers to take place
inside coap_serialize_message().


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/a3775fd3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a3775fd3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a3775fd3

Branch: refs/heads/develop
Commit: a3775fd3976f68790dff59fbcb939659d583bb12
Parents: 0b7a6b9
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Dec 9 10:11:23 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Dec 9 10:11:23 2016 -0800

----------------------------------------------------------------------
 net/oic/src/api/oc_client_api.c       | 16 ++++++++++------
 net/oic/src/api/oc_ri.c               |  7 +++++--
 net/oic/src/api/oc_server_api.c       |  8 +++++---
 net/oic/src/messaging/coap/coap.c     |  5 ++++-
 net/oic/src/messaging/coap/coap.h     |  2 +-
 net/oic/src/messaging/coap/engine.c   | 19 +++++++++++--------
 net/oic/src/messaging/coap/observe.c  | 11 ++++++-----
 net/oic/src/messaging/coap/separate.c |  3 +--
 8 files changed, 43 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3775fd3/net/oic/src/api/oc_client_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_client_api.c b/net/oic/src/api/oc_client_api.c
index bc681ec..c15e412 100644
--- a/net/oic/src/api/oc_client_api.c
+++ b/net/oic/src/api/oc_client_api.c
@@ -38,10 +38,12 @@ dispatch_coap_request(void)
                 coap_set_payload(request, rsp->data, response_length);
                 coap_set_header_content_format(request, APPLICATION_CBOR);
             }
-            coap_serialize_message(request, message,
-                               oc_endpoint_use_tcp(OC_MBUF_ENDPOINT(message)));
+            if (!coap_serialize_message(request, message)) {
+                coap_send_message(message, 0);
+            } else {
+                os_mbuf_free_chain(message);
+            }
             oc_message_unref(rsp);
-            coap_send_message(message, 0);
             message = NULL;
             return true;
         }
@@ -50,10 +52,12 @@ dispatch_coap_request(void)
             coap_set_payload(request, transaction->m, response_length);
             coap_set_header_content_format(request, APPLICATION_CBOR);
         }
-        coap_serialize_message(request, transaction->m,
-                         oc_endpoint_use_tcp(OC_MBUF_ENDPOINT(transaction->m)));
+        if (!coap_serialize_message(request, transaction->m)) {
+            coap_send_transaction(transaction);
+        } else {
+            coap_clear_transaction(transaction);
+        }
         oc_message_unref(rsp);
-        coap_send_transaction(transaction);
         transaction = NULL;
         return true;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3775fd3/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 64ce1f3..9c84e01 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -704,8 +704,11 @@ oc_ri_send_rst(oc_endpoint_t *endpoint, uint8_t *token, uint8_t token_len,
     coap_set_token(rst, token, token_len);
     m = oc_allocate_mbuf(endpoint);
     if (m) {
-        coap_serialize_message(rst, m, oc_endpoint_use_tcp(endpoint));
-        coap_send_message(m, 0);
+        if (!coap_serialize_message(rst, m)) {
+            coap_send_message(m, 0);
+        } else {
+            os_mbuf_free_chain(m);
+        }
         return true;
     }
     return false;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3775fd3/net/oic/src/api/oc_server_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_server_api.c b/net/oic/src/api/oc_server_api.c
index 50b7fdc..071bf40 100644
--- a/net/oic/src/api/oc_server_api.c
+++ b/net/oic/src/api/oc_server_api.c
@@ -259,9 +259,11 @@ oc_send_separate_response(oc_separate_response_t *handle,
                       response_buffer.response_length);
                 }
                 t->type = response->type;
-                coap_serialize_message(response, t->m,
-                                       oc_endpoint_use_tcp(&cur->endpoint));
-                coap_send_transaction(t);
+                if (!coap_serialize_message(response, t->m)) {
+                    coap_send_transaction(t);
+                } else {
+                    coap_clear_transaction(t);
+                }
             }
             coap_separate_clear(handle, cur);
         } else {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3775fd3/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index cb9cada..2cea8c4 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -316,7 +316,7 @@ coap_init_message(coap_packet_t *pkt, coap_message_type_t type,
 /*---------------------------------------------------------------------------*/
 
 int
-coap_serialize_message(coap_packet_t *pkt, struct os_mbuf *m, int tcp_hdr)
+coap_serialize_message(coap_packet_t *pkt, struct os_mbuf *m)
 {
     struct coap_udp_hdr *cuh;
     struct coap_tcp_hdr0 *cth0;
@@ -324,6 +324,7 @@ coap_serialize_message(coap_packet_t *pkt, struct os_mbuf *m, int tcp_hdr)
     struct coap_tcp_hdr16 *cth16;
     struct coap_tcp_hdr32 *cth32;
     unsigned int current_number = 0;
+    int tcp_hdr;
     int len, data_len;
 
     /* Initialize */
@@ -331,6 +332,8 @@ coap_serialize_message(coap_packet_t *pkt, struct os_mbuf *m, int tcp_hdr)
 
     LOG("-Serializing message %u to 0x%x, ", pkt->mid, (unsigned)m);
 
+    tcp_hdr = oc_endpoint_use_tcp(OC_MBUF_ENDPOINT(m));
+
     /*
      * Move data pointer, leave enough space to insert coap header and
      * token before options.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3775fd3/net/oic/src/messaging/coap/coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.h b/net/oic/src/messaging/coap/coap.h
index 5c0d9de..586310c 100644
--- a/net/oic/src/messaging/coap/coap.h
+++ b/net/oic/src/messaging/coap/coap.h
@@ -230,7 +230,7 @@ uint16_t coap_tcp_msg_size(uint8_t *hdr, int datalen);
 
 void coap_init_message(coap_packet_t *, coap_message_type_t type,
                        uint8_t code, uint16_t mid);
-int coap_serialize_message(coap_packet_t *, struct os_mbuf *m, int tcp_hdr);
+int coap_serialize_message(coap_packet_t *, struct os_mbuf *m);
 void coap_send_message(struct os_mbuf *m, int dup);
 coap_status_t coap_parse_message(coap_packet_t *request, uint8_t *data,
                                  uint16_t data_len, int tcp_hdr);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3775fd3/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index e4b700c..0e95dae 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -240,8 +240,7 @@ coap_receive(oc_message_t *msg)
             /* serialize response */
         }
         if (erbium_status_code == NO_ERROR) {
-            if (coap_serialize_message(response, transaction->m,
-                oc_endpoint_use_tcp(&msg->endpoint))) {
+            if (coap_serialize_message(response, transaction->m)) {
                 erbium_status_code = PACKET_SERIALIZATION_ERROR;
             }
             transaction->type = response->type;
@@ -295,9 +294,11 @@ out:
         coap_init_message(message, COAP_TYPE_ACK, 0, message->mid);
         struct os_mbuf *response = oc_allocate_mbuf(&msg->endpoint);
         if (response) {
-            coap_serialize_message(message, response,
-                                          oc_endpoint_use_tcp(&msg->endpoint));
-            coap_send_message(response, 0);
+            if (!coap_serialize_message(message, response)) {
+                coap_send_message(response, 0);
+            } else {
+                os_mbuf_free_chain(response);
+            }
         }
     }
 #endif /* OC_CLIENT */
@@ -312,9 +313,11 @@ out:
 
         struct os_mbuf *response = oc_allocate_mbuf(&msg->endpoint);
         if (response) {
-            coap_serialize_message(message, response,
-                                   oc_endpoint_use_tcp(&msg->endpoint));
-            coap_send_message(response, 0);
+            if (!coap_serialize_message(message, response)) {
+                coap_send_message(response, 0);
+            } else {
+                os_mbuf_free_chain(response);
+            }
         }
     }
 #endif /* OC_SERVER */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3775fd3/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 01907b8..65bf85a 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -293,11 +293,12 @@ coap_notify_observers(oc_resource_t *resource,
                 }
                 coap_set_token(notification, obs->token, obs->token_len);
 
-                coap_serialize_message(notification, transaction->m,
-                                       oc_endpoint_use_tcp(&obs->endpoint));
-                transaction->type = notification->type;
-
-                coap_send_transaction(transaction);
+                if (!coap_serialize_message(notification, transaction->m)) {
+                    transaction->type = notification->type;
+                    coap_send_transaction(transaction);
+                } else {
+                    coap_clear_transaction(transaction);
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a3775fd3/net/oic/src/messaging/coap/separate.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.c b/net/oic/src/messaging/coap/separate.c
index be6c7f4..7588866 100644
--- a/net/oic/src/messaging/coap/separate.c
+++ b/net/oic/src/messaging/coap/separate.c
@@ -102,8 +102,7 @@ coap_separate_accept(coap_packet_t *coap_req,
         }
         coap_set_token(ack, coap_req->token, coap_req->token_len);
         struct os_mbuf *message = oc_allocate_mbuf(endpoint); /* XXXX? */
-        if (message != NULL) {
-            coap_serialize_message(ack, message, oc_endpoint_use_tcp(endpoint));
+        if (message != NULL && coap_serialize_message(ack, message) == 0) {
             coap_send_message(message, 0);
         } else {
             coap_separate_clear(separate_response, separate_store);