celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [celix] pnoltes commented on a change in pull request #313: Feature/refactor c dep man service trackers
Date Tue, 09 Feb 2021 10:50:07 GMT

pnoltes commented on a change in pull request #313:
URL: https://github.com/apache/celix/pull/313#discussion_r572783249



##########
File path: libs/utils/src/version_range.c
##########
@@ -182,61 +108,139 @@ celix_status_t versionRange_isHighInclusive(version_range_pt versionRange,
bool
 
 
 celix_status_t versionRange_parse(const char * rangeStr, version_range_pt *range) {
-    celix_status_t status;
-    if (strchr(rangeStr, ',') != NULL) {
-            int vlowL = strcspn(rangeStr+1, ",");
-            char * vlow = (char *) malloc(sizeof(char) * (vlowL + 1));
-            if (!vlow) {
-                status = CELIX_ENOMEM;
-            } else {
-                int vhighL;
-                char * vhigh;
-                vlow = strncpy(vlow, rangeStr+1, vlowL);
-                vlow[vlowL] = '\0';
-                vhighL = strlen(rangeStr+1) - vlowL - 2;
-                vhigh = (char *) malloc(sizeof(char) * (vhighL+1));
-                if (!vhigh) {
-                    status = CELIX_ENOMEM;
-                } else {                    
-                    version_pt versionLow = NULL;
-                    int rangeL = strlen(rangeStr);
-                    char start = rangeStr[0];
-                    char end = rangeStr[rangeL-1];
-
-                    vhigh = strncpy(vhigh, rangeStr+vlowL+2, vhighL);
-                    vhigh[vhighL] = '\0';
-                    status = version_createVersionFromString(vlow, &versionLow);
-                    if (status == CELIX_SUCCESS) {
-                        version_pt versionHigh = NULL;
-                        status = version_createVersionFromString(vhigh, &versionHigh);
-                        if (status == CELIX_SUCCESS) {
-                            status = versionRange_createVersionRange(
-                                    versionLow,
-                                    start == '[',
-                                    versionHigh,
-                                    end ==']',
-                                    range
-                                );
-                        }
-                    }
-                    free(vhigh);
-                }
-                free(vlow);
+    *range = celix_versionRange_parse(rangeStr);
+    if (*range == NULL) {
+        return CELIX_ILLEGAL_ARGUMENT;
+    } else {
+        return CELIX_SUCCESS;
+    }
+}
 
+char* versionRange_createLDAPFilter(version_range_pt range, const char *serviceVersionAttributeName)
{
+    return celix_versionRange_createLDAPFilter(range, serviceVersionAttributeName);
+}
+
+
+
+bool versionRange_createLDAPFilterInPlace(version_range_pt range, const char *serviceVersionAttributeName,
char* buffer, size_t bufferLength) {
+    return celix_versionRange_createLDAPFilterInPlace(range, serviceVersionAttributeName,
buffer, bufferLength);
+}
+
+celix_version_range_t* celix_versionRange_createVersionRange(celix_version_t* low, bool isLowInclusive,
celix_version_t* high, bool isHighInclusive) {
+    assert(low != high);
+    celix_version_range_t* range = malloc(sizeof(*range));
+    range->low = low;
+    range->isLowInclusive = isLowInclusive;
+    range->high = high;
+    range->isHighInclusive = isHighInclusive;
+    return range;
+}
+
+
+celix_version_range_t* celix_versionRange_createInfiniteVersionRange() {
+    return celix_versionRange_createVersionRange(celix_version_createEmptyVersion(), true,
NULL, true);
+}
+
+void celix_versionRange_destroy(celix_version_range_t* range) {
+    if (range->high != NULL) {
+        celix_version_destroy(range->high);
+    }
+    if (range->low != NULL) {
+        celix_version_destroy(range->low);
+    }
+    free(range);
+}
+
+
+bool celix_versionRange_isInRange(const celix_version_range_t* versionRange, const celix_version_t*
version) {
+    bool inRange = false;
+    int high;
+    int low;

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message