Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CCB0D200C52 for ; Mon, 27 Mar 2017 01:43:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CB54D160B87; Sun, 26 Mar 2017 23:43:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E7DA5160B92 for ; Mon, 27 Mar 2017 01:43:48 +0200 (CEST) Received: (qmail 49707 invoked by uid 500); 26 Mar 2017 23:43:48 -0000 Mailing-List: contact commits-help@mynewt.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mynewt.incubator.apache.org Delivered-To: mailing list commits@mynewt.incubator.apache.org Received: (qmail 49698 invoked by uid 99); 26 Mar 2017 23:43:48 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Mar 2017 23:43:48 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B86FB185E69 for ; Sun, 26 Mar 2017 23:43:47 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.222 X-Spam-Level: X-Spam-Status: No, score=-4.222 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 2DKH2fJny6Yv for ; Sun, 26 Mar 2017 23:43:46 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id D17B35FB48 for ; Sun, 26 Mar 2017 23:43:45 +0000 (UTC) Received: (qmail 49304 invoked by uid 99); 26 Mar 2017 23:43:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Mar 2017 23:43:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B8287DF99D; Sun, 26 Mar 2017 23:43:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: marko@apache.org To: commits@mynewt.incubator.apache.org Date: Sun, 26 Mar 2017 23:43:30 -0000 Message-Id: <3025fbedcdec496e811d7c13c58aca20@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer 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. archived-at: Sun, 26 Mar 2017 23:43:50 -0000 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 Authored: Sun Mar 26 16:41:44 2017 -0700 Committer: Marko Kiiskila 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); }