Skip to content

Commit

Permalink
Merge pull request #625 from apache/hotfix/version-range-ldap
Browse files Browse the repository at this point in the history
Hotfix/LDAP filter for Version Range
  • Loading branch information
PengZheng committed Aug 26, 2023
2 parents 27a2539 + cef01ef commit e3e5416
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 3 additions & 2 deletions bundles/shell/shell/src/dm_shell_list_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "celix_bundle_context.h"
#include "celix_dependency_manager.h"
#include "celix_dm_component.h"
#include "std_commands.h"

static void parseCommandLine(const char*line, celix_array_list_t **requestedBundleIds, bool *fullInfo, bool *wtf, FILE *err) {
*fullInfo = false;
Expand All @@ -49,7 +50,7 @@ static void parseCommandLine(const char*line, celix_array_list_t **requestedBund
free (str);
}

celix_status_t dmListCommand_execute(void* handle, char * line, FILE *out, FILE *err) {
bool dmListCommand_execute(void* handle, const char* line, FILE *out, FILE *err) {
celix_bundle_context_t *ctx = handle;
celix_dependency_manager_t *mng = celix_bundleContext_getDependencyManager(ctx);

Expand Down Expand Up @@ -91,5 +92,5 @@ celix_status_t dmListCommand_execute(void* handle, char * line, FILE *out, FILE

celix_arrayList_destroy(bundleIds);

return CELIX_SUCCESS;
return true;
}
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 e3e5416

Please sign in to comment.