From 47a3210e1b99fe8c1c8d80cd3febcababb7b411e Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 27 Aug 2024 10:11:27 +0200 Subject: [PATCH] properly extract publisher keyexpr id for interests --- include/zenoh-pico/protocol/keyexpr.h | 2 +- src/api/api.c | 10 ++-------- src/net/filtering.c | 5 +++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/zenoh-pico/protocol/keyexpr.h b/include/zenoh-pico/protocol/keyexpr.h index 89f87b560..c423236b9 100644 --- a/include/zenoh-pico/protocol/keyexpr.h +++ b/include/zenoh-pico/protocol/keyexpr.h @@ -32,7 +32,7 @@ _z_keyexpr_t _z_keyexpr_duplicate(_z_keyexpr_t src); _z_keyexpr_t _z_keyexpr_alias(_z_keyexpr_t src); /// Returns either keyexpr defined by id + mapping with null suffix if try_declared is true and id is non-zero, /// or keyexpr defined by its suffix only, with 0 id and no mapping. This is to be used only when forwarding -/// keyexpr in user api to properly separate declard keyexpr from its suffix. +/// keyexpr in user api to properly separate declared keyexpr from its suffix. _z_keyexpr_t _z_keyexpr_alias_from_user_defined(_z_keyexpr_t src, _Bool try_declared); _z_keyexpr_t _z_keyexpr_steal(_Z_MOVE(_z_keyexpr_t) src); static inline _z_keyexpr_t _z_keyexpr_null(void) { diff --git a/src/api/api.c b/src/api/api.c index 009e8d5aa..6beddcaa0 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -1154,10 +1154,7 @@ int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload encoding = _z_encoding_steal(&opt.encoding->_this._val); } // Remove potentially redundant ke suffix - _z_keyexpr_t pub_keyexpr = _z_keyexpr_alias(pub->_key); - if (pub_keyexpr._id != Z_RESOURCE_ID_NONE) { - pub_keyexpr._suffix = _z_string_null(); - } + _z_keyexpr_t pub_keyexpr = _z_keyexpr_alias_from_user_defined(pub->_key, true); // Check if write filter is active before writing if (!_z_write_filter_active(pub)) { @@ -1186,10 +1183,7 @@ int8_t z_publisher_delete(const z_loaned_publisher_t *pub, const z_publisher_del opt.timestamp = options->timestamp; } // Remove potentially redundant ke suffix - _z_keyexpr_t pub_keyexpr = _z_keyexpr_alias(pub->_key); - if (pub_keyexpr._id != Z_RESOURCE_ID_NONE) { - pub_keyexpr._suffix = _z_string_null(); - } + _z_keyexpr_t pub_keyexpr = _z_keyexpr_alias_from_user_defined(pub->_key, true); return _z_write(_Z_RC_IN_VAL(&pub->_zn), pub_keyexpr, _z_bytes_null(), NULL, Z_SAMPLE_KIND_DELETE, pub->_congestion_control, pub->_priority, pub->_is_express, opt.timestamp, _z_bytes_null()); diff --git a/src/net/filtering.c b/src/net/filtering.c index 282881a84..0787c462b 100644 --- a/src/net/filtering.c +++ b/src/net/filtering.c @@ -84,8 +84,9 @@ int8_t _z_write_filter_create(_z_publisher_t *pub) { ctx->decl_id = 0; pub->_filter.ctx = ctx; - pub->_filter._interest_id = _z_add_interest(_Z_RC_IN_VAL(&pub->_zn), _z_keyexpr_alias(pub->_key), - _z_write_filter_callback, flags, (void *)ctx); + pub->_filter._interest_id = + _z_add_interest(_Z_RC_IN_VAL(&pub->_zn), _z_keyexpr_alias_from_user_defined(pub->_key, true), + _z_write_filter_callback, flags, (void *)ctx); if (pub->_filter._interest_id == 0) { z_free(ctx); return _Z_ERR_GENERIC;