stegemr commented on code in PR #388: URL: https://github.com/apache/celix/pull/388#discussion_r1018074099
########## libs/framework/src/celix_framework_utils.c: ########## @@ -0,0 +1,283 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "celix_framework_utils.h" +#include "celix_framework_utils_private.h" + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <dlfcn.h> +#include <assert.h> + +#include "bundle_archive.h" +#include "celix_constants.h" +#include "celix_log.h" +#include "celix_properties.h" +#include "celix_file_utils.h" +#include "celix_utils.h" +#include "celix_bundle_context.h" +#include "framework_private.h" + +static const char * const EMBEDDED_BUNDLES_SYMBOL = "celix_embedded_bundles"; + +static const char * const EMBEDDED_BUNDLE_PREFIX = "celix_embedded_bundle_"; +static const char * const EMBEDDED_BUNDLE_START_POSTFIX = "_start"; +static const char * const EMBEDDED_BUNDLE_END_POSTFIX = "_end"; + +#define FW_LOG(level, ...) do { \ + if (fw) { \ + celix_framework_log(fw->logger, (level), __FUNCTION__ , __FILE__, __LINE__, __VA_ARGS__); \ + } else { \ + celix_framework_log(celix_frameworkLogger_globalLogger(), (level), __FUNCTION__ , __FILE__, __LINE__, __VA_ARGS__); \ + } \ +} while(0) + +static char* resolveFileBundleUrl(celix_framework_t* fw, const char* bundleLocation, bool silent) { + char *result = NULL; + + const char *bundlePath = NULL; + fw_getProperty(fw, CELIX_BUNDLES_PATH_NAME, CELIX_BUNDLES_PATH_DEFAULT, &bundlePath); + + if (!celix_utils_isStringNullOrEmpty(bundleLocation)) { + if (bundleLocation[0] == '/') { + //absolute path. + if (celix_utils_fileExists(bundleLocation)) { + result = celix_utils_strdup(bundleLocation); + } else if (!silent) { + FW_LOG(CELIX_LOG_LEVEL_ERROR, "Bundle location '%s' is not valid, file does not exist.", bundleLocation); + } + } else if (celix_utils_fileExists(bundleLocation)) { + //relative path to existing file. + result = celix_utils_strdup(bundleLocation); + } else { + //relative path to a non-existing file, check the bundle paths. + char *paths = celix_utils_strdup(bundlePath); + const char *sep = ":"; + char *savePtr = NULL; + + for (char *path = strtok_r(paths, sep, &savePtr); path != NULL; path = strtok_r(NULL, sep, &savePtr)){ + char *absPath = NULL; + asprintf(&absPath, "%s/%s", path, bundleLocation); + if (celix_utils_fileExists(absPath)) { + result = absPath; + break; + } else { + free(absPath); + } + } + free(paths); + + if (result == NULL && !silent) { + FW_LOG(CELIX_LOG_LEVEL_ERROR, "Bundle location '%s' is not valid. Relative path does not point to existing file taking into account the cwd and Celix bundle path '%s'.", bundleLocation, bundlePath); + } + } + } else if (!silent) { + FW_LOG(CELIX_LOG_LEVEL_ERROR, "Invalid bundle empty bundle path."); + } + return result; +} + +static bool isEmbeddedBundleUrlValid(celix_framework_t *fw, const char* bundleURL, bool silent) { + bool valid = true; + + char* startSymbol = NULL; + char* endSymbol = NULL; + //note +11 to remove the embedded:// part. + asprintf(&startSymbol, "%s%s%s", EMBEDDED_BUNDLE_PREFIX, bundleURL+11, EMBEDDED_BUNDLE_START_POSTFIX); Review Comment: sizeof instead of 11? -- 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. To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org