diff --git a/src/discovery.c b/src/discovery.c index ea1e041c..c8ceb820 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -288,7 +288,6 @@ static DPS_Status DecodeDiscoveryPayload(DPS_DiscoveryService* service, uint8_t DPS_DiscoveryService* DPS_CreateDiscoveryService(DPS_Node* node, const char* serviceId) { - static const int noWildcard = DPS_TRUE; DPS_DiscoveryService* service; DPS_Status ret; @@ -325,7 +324,7 @@ DPS_DiscoveryService* DPS_CreateDiscoveryService(DPS_Node* node, const char* ser if (ret != DPS_OK) { goto Exit; } - ret = DPS_InitPublication(service->pub, (const char**)&service->topic, 1, noWildcard, OnAck); + ret = DPS_InitPublication(service->pub, (const char**)&service->topic, 1, DPS_FALSE, OnAck); if (ret != DPS_OK) { goto Exit; } diff --git a/src/topics.c b/src/topics.c index 8989203f..f99f584c 100644 --- a/src/topics.c +++ b/src/topics.c @@ -144,12 +144,13 @@ DPS_Status DPS_AddTopic(DPS_BitVector* bf, const char* topic, const char* separa tp = topic + strcspn(topic, separators); if (!wc) { DPS_BitVectorBloomInsert(bf, (const uint8_t*)topic, tlen); - if (topicType != DPS_PubTopic) { - return DPS_OK; - } } else if (wc != topic) { DPS_BitVectorBloomInsert(bf, (const uint8_t*)topic, wc - topic); } + if (topicType == DPS_PubNoWild) { + return DPS_OK; + } + segment = malloc(tlen + 1); if (!segment) { return DPS_ERR_RESOURCES; @@ -157,7 +158,7 @@ DPS_Status DPS_AddTopic(DPS_BitVector* bf, const char* topic, const char* separa while (*tp) { size_t len; segment[prefix++] = *tp++; - if (topicType == DPS_PubTopic) { + if (wc != topic) { DPS_BitVectorBloomInsert(bf, (const uint8_t*)topic, tp - topic); } len = strcspn(tp, separators); @@ -176,14 +177,12 @@ DPS_Status DPS_AddTopic(DPS_BitVector* bf, const char* topic, const char* separa tp += len; } if (ret == DPS_OK) { - if (topicType == DPS_PubTopic) { - segment[prefix] = INFIX_WILDC; + segment[prefix] = INFIX_WILDC; + DPS_BitVectorBloomInsert(bf, (uint8_t*)segment, prefix + 1); + while (prefix >= 0) { + segment[prefix] = FINAL_WILDC; DPS_BitVectorBloomInsert(bf, (uint8_t*)segment, prefix + 1); - while (prefix >= 0) { - segment[prefix] = FINAL_WILDC; - DPS_BitVectorBloomInsert(bf, (uint8_t*)segment, prefix + 1); - --prefix; - } + --prefix; } } free(segment);