mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [2/3] incubator-mynewt-core git commit: net/oic; oc_endpoint size is different depending on transport type. Take this into account when comparing them.
Date Sun, 26 Mar 2017 23:43:30 GMT
net/oic; oc_endpoint size is different depending on transport type.
Take this into account when comparing them.


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

Branch: refs/heads/develop
Commit: 4393af41e3938601972ffe8be7e859c67cf57785
Parents: 0df95ce
Author: Marko Kiiskila <marko@runtime.io>
Authored: Sun Mar 26 16:41:44 2017 -0700
Committer: Marko Kiiskila <marko@runtime.io>
Committed: Sun Mar 26 16:41:44 2017 -0700

----------------------------------------------------------------------
 net/oic/src/api/oc_ri.c              |  2 +-
 net/oic/src/messaging/coap/observe.c | 14 ++++++++------
 net/oic/src/port/oc_connectivity.h   | 14 ++++++++++++++
 net/oic/src/security/oc_dtls.c       |  2 +-
 4 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4393af41/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 d5779e5..c03458b 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -809,7 +809,7 @@ oc_ri_get_client_cb(const char *uri, oc_server_handle_t *server,
         if (oc_string_len(cb->uri) == strlen(uri) &&
           strncmp(oc_string(cb->uri), uri, strlen(uri)) == 0 &&
           memcmp(&cb->server.endpoint, &server->endpoint,
-            sizeof(oc_endpoint_t)) == 0 &&
+                 oc_endpoint_size(&cb->server.endpoint)) == 0 &&
           cb->method == method) {
             return cb;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4393af41/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 3d45e03..4369360 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -111,7 +111,7 @@ coap_remove_observer_by_client(oc_endpoint_t *endpoint)
     obs = SLIST_FIRST(&oc_observers);
     while (obs) {
         next = SLIST_NEXT(obs, next);
-        if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0) {
+        if (memcmp(&obs->endpoint, endpoint, oc_endpoint_size(endpoint)) == 0) {
             obs->resource->num_observers--;
             coap_remove_observer(obs);
             removed++;
@@ -131,7 +131,7 @@ coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,
     obs = SLIST_FIRST(&oc_observers);
     while (obs) {
         next = SLIST_NEXT(obs, next);
-        if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0 &&
+        if (memcmp(&obs->endpoint, endpoint, oc_endpoint_size(endpoint)) == 0 &&
           obs->token_len == token_len &&
           memcmp(obs->token, token, token_len) == 0) {
             obs->resource->num_observers--;
@@ -153,7 +153,8 @@ coap_remove_observer_by_uri(oc_endpoint_t *endpoint, const char *uri)
     obs = SLIST_FIRST(&oc_observers);
     while (obs) {
         next = SLIST_NEXT(obs, next);
-        if (((memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0)) &&
+        if (((memcmp(&obs->endpoint, endpoint,
+                     oc_endpoint_size(endpoint)) == 0)) &&
           (obs->url == uri || memcmp(obs->url, uri, strlen(obs->url)) == 0)) {
             obs->resource->num_observers--;
             coap_remove_observer(obs);
@@ -173,7 +174,7 @@ coap_remove_observer_by_mid(oc_endpoint_t *endpoint, uint16_t mid)
     obs = SLIST_FIRST(&oc_observers);
     while (obs) {
         next = SLIST_NEXT(obs, next);
-        if (memcmp(&obs->endpoint, endpoint, sizeof(*endpoint)) == 0 &&
+        if (memcmp(&obs->endpoint, endpoint, oc_endpoint_size(endpoint)) == 0 &&
           obs->last_mid == mid) {
             obs->resource->num_observers--;
             coap_remove_observer(obs);
@@ -233,8 +234,9 @@ coap_notify_observers(oc_resource_t *resource,
     /* iterate over observers */
     for (obs = SLIST_FIRST(&oc_observers); obs; obs = SLIST_NEXT(obs, next)) {
         /* skip if neither resource nor endpoint match */
-        if (resource != obs->resource &&
-            0 != memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t))) {
+        if ((resource && resource != obs->resource) ||
+            (endpoint && memcmp(&obs->endpoint, endpoint,
+                                oc_endpoint_size(endpoint)) != 0)) {
             continue;
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4393af41/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index a7cce39..787fbf2 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -83,6 +83,20 @@ typedef struct oc_endpoint {
     };
 } oc_endpoint_t;
 
+static inline int
+oc_endpoint_size(struct oc_endpoint *oe)
+{
+    if (oe->oe.flags & (IP | IP4)) {
+        return sizeof (struct oc_endpoint_ip);
+    } else if (oe->oe.flags & GATT) {
+        return sizeof (struct oc_endpoint_ble);
+    } else if (oe->oe.flags & SERIAL) {
+        return sizeof (struct oc_endpoint_plain);
+    } else {
+        return sizeof (struct oc_endpoint);
+    }
+}
+
 #define OC_MBUF_ENDPOINT(m)                                            \
     ((struct oc_endpoint *)((uint8_t *)m + sizeof(struct os_mbuf) +    \
                             sizeof(struct os_mbuf_pkthdr)))

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4393af41/net/oic/src/security/oc_dtls.c
----------------------------------------------------------------------
diff --git a/net/oic/src/security/oc_dtls.c b/net/oic/src/security/oc_dtls.c
index fdd0249..a904d79 100644
--- a/net/oic/src/security/oc_dtls.c
+++ b/net/oic/src/security/oc_dtls.c
@@ -37,7 +37,7 @@ oc_sec_dtls_get_peer(oc_endpoint_t *endpoint)
 {
   oc_sec_dtls_peer_t *peer = oc_list_head(dtls_peers);
   while (peer != NULL) {
-    if (memcmp(&peer->session.addr, endpoint, sizeof(oc_endpoint_t)) == 0)
+    if (memcmp(&peer->session.addr, endpoint, oc_endpoint_size(endpoint)) == 0)
       break;
     peer = oc_list_item_next(peer);
   }


Mime
View raw message