Skip to content

Commit

Permalink
Take qualifier into account when create LDAP filter for version range.
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZheng committed Aug 25, 2023
1 parent 777b2e9 commit cef01ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 11 additions & 0 deletions libs/utils/gtest/src/VersionRangeTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "version.h"
#include "version_range.h" //NOTE testing celix_version_range through the deprecated version_range api.
#include "celix_stdlib_cleanup.h"
#include "celix_version_range.h"
#include "version_private.h"

Expand Down Expand Up @@ -415,3 +416,13 @@ TEST_F(VersionRangeTestSuite, createLdapFilterInPlaceInfiniteHigh) {

versionRange_destroy(range);
}

TEST_F(VersionRangeTestSuite, createLdapFilterWithQualifier) {
celix_autoptr(celix_version_t) low = celix_version_createVersion(1, 2, 2, "0");
celix_autoptr(celix_version_t) high = celix_version_createVersion(1, 2, 2, "0");

celix_autoptr(celix_version_range_t) range = celix_versionRange_createVersionRange(celix_steal_ptr(low), true,
celix_steal_ptr(high), true);
celix_autofree char* filter = celix_versionRange_createLDAPFilter(range, "service.version");
EXPECT_STREQ(filter, "(&(service.version>=1.2.2.0)(service.version<=1.2.2.0))");
}
14 changes: 10 additions & 4 deletions libs/utils/src/version_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,21 @@ char* celix_versionRange_createLDAPFilter(const celix_version_range_t* range, co

int ret = -1;
if(range->high == NULL) {
ret = asprintf(&output, "(&(%s%s%i.%i.%i))",
ret = asprintf(&output, "(&(%s%s%i.%i.%i%s%s))",
serviceVersionAttributeName, range->isLowInclusive ? ">=" : ">", range->low->major,
range->low->minor, range->low->micro);
range->low->minor, range->low->micro,
range->low->qualifier ? "." : "",
range->low->qualifier ? range->low->qualifier : "");
} else {
ret = asprintf(&output, "(&(%s%s%i.%i.%i)(%s%s%i.%i.%i))",
ret = asprintf(&output, "(&(%s%s%i.%i.%i%s%s)(%s%s%i.%i.%i%s%s))",
serviceVersionAttributeName, range->isLowInclusive ? ">=" : ">", range->low->major,
range->low->minor, range->low->micro,
range->low->qualifier ? "." : "",
range->low->qualifier ? range->low->qualifier : "",
serviceVersionAttributeName, range->isHighInclusive ? "<=" : "<", range->high->major,
range->high->minor, range->high->micro);
range->high->minor, range->high->micro,
range->high->qualifier ? "." : "",
range->high->qualifier ? range->high->qualifier : "");
}

if (ret < 0) {
Expand Down

0 comments on commit cef01ef

Please sign in to comment.