You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2014/06/06 11:43:48 UTC
svn commit: r1600834 - in /incubator/celix/trunk: framework/private/include/
framework/private/src/ framework/public/include/ utils/private/src/
utils/public/include/
Author: abroekhuis
Date: Fri Jun 6 09:43:47 2014
New Revision: 1600834
URL: http://svn.apache.org/r1600834
Log:
CELIX-119: Removed APR usage from the bundle cache, archive and revisions.
Modified:
incubator/celix/trunk/framework/private/include/bundle_cache.h
incubator/celix/trunk/framework/private/include/bundle_cache_private.h
incubator/celix/trunk/framework/private/src/bundle.c
incubator/celix/trunk/framework/private/src/bundle_archive.c
incubator/celix/trunk/framework/private/src/bundle_cache.c
incubator/celix/trunk/framework/private/src/bundle_revision.c
incubator/celix/trunk/framework/private/src/framework.c
incubator/celix/trunk/framework/private/src/manifest.c
incubator/celix/trunk/framework/public/include/bundle_archive.h
incubator/celix/trunk/framework/public/include/bundle_revision.h
incubator/celix/trunk/framework/public/include/manifest.h
incubator/celix/trunk/utils/private/src/celix_threads.c
incubator/celix/trunk/utils/public/include/celix_threads.h
Modified: incubator/celix/trunk/framework/private/include/bundle_cache.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle_cache.h?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle_cache.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle_cache.h Fri Jun 6 09:43:47 2014
@@ -54,7 +54,7 @@ typedef struct bundleCache *bundle_cache
* - CELIX_ILLEGAL_ARGUMENT If <code>bundle_cache</code> not is null.
* - CELIX_ENOMEM If allocating memory for <code>bundle_cache</code> failed.
*/
-celix_status_t bundleCache_create(properties_pt configurationMap, apr_pool_t *mp, framework_logger_pt logger, bundle_cache_pt *bundle_cache);
+celix_status_t bundleCache_create(properties_pt configurationMap, framework_logger_pt logger, bundle_cache_pt *bundle_cache);
/**
* Recreates and retrieves the list of archives for the given bundle cache.
@@ -69,7 +69,7 @@ celix_status_t bundleCache_create(proper
* - CELIX_ENOMEM If allocating memory for <code>archives</code> failed.
* - CELIX_FILE_IO_EXCEPTION If the cache cannot be opened or read.
*/
-celix_status_t bundleCache_getArchives(bundle_cache_pt cache, apr_pool_t *pool, array_list_pt *archives);
+celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *archives);
/**
* Creates a new archive for the given bundle (using the id and location). The archive is created on the supplied bundlePool.
@@ -86,7 +86,7 @@ celix_status_t bundleCache_getArchives(b
* - CELIX_ILLEGAL_ARGUMENT If <code>bundle_archive</code> not is null.
* - CELIX_ENOMEM If allocating memory for <code>bundle_archive</code> failed.
*/
-celix_status_t bundleCache_createArchive(bundle_cache_pt cache, apr_pool_t *bundlePool, long id, char * location, char *inputFile, bundle_archive_pt *archive);
+celix_status_t bundleCache_createArchive(bundle_cache_pt cache, long id, char * location, char *inputFile, bundle_archive_pt *archive);
/**
* Deletes the entire bundle cache.
Modified: incubator/celix/trunk/framework/private/include/bundle_cache_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle_cache_private.h?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle_cache_private.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle_cache_private.h Fri Jun 6 09:43:47 2014
@@ -33,7 +33,6 @@
struct bundleCache {
properties_pt configurationMap;
char * cacheDir;
- apr_pool_t *mp;
framework_logger_pt logger;
};
Modified: incubator/celix/trunk/framework/private/src/bundle.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle.c?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle.c Fri Jun 6 09:43:47 2014
@@ -50,7 +50,7 @@ celix_status_t bundle_create(bundle_pt *
if (*bundle == NULL) {
return CELIX_ENOMEM;
}
- status = bundleArchive_createSystemBundleArchive(mp, logger, &archive);
+ status = bundleArchive_createSystemBundleArchive(logger, &archive);
if (status == CELIX_SUCCESS) {
module_pt module;
apr_status_t apr_status;
Modified: incubator/celix/trunk/framework/private/src/bundle_archive.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_archive.c?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Fri Jun 6 09:43:47 2014
@@ -27,9 +27,9 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-
-#include <apr_file_io.h>
-#include <apr_strings.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
#include "bundle_archive.h"
#include "bundle_revision.h"
@@ -40,7 +40,7 @@
struct bundleArchive {
long id;
char * location;
- apr_dir_t * archiveRootDir;
+ DIR *archiveRootDir;
char * archiveRoot;
linked_list_pt revisions;
long refreshCount;
@@ -48,18 +48,14 @@ struct bundleArchive {
framework_logger_pt logger;
bundle_state_e persistentState;
-
- apr_pool_t *mp;
};
-static apr_status_t bundleArchive_destroy(void *archiveP);
-
static celix_status_t bundleArchive_getRevisionLocation(bundle_archive_pt archive, long revNr, char **revision_location);
static celix_status_t bundleArchive_setRevisionLocation(bundle_archive_pt archive, char * location, long revNr);
static celix_status_t bundleArchive_initialize(bundle_archive_pt archive);
-static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, char * directory, apr_pool_t *mp);
+static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, char * directory);
static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt archive, char *location, char *inputFile, long revNr, bundle_revision_pt *bundle_revision);
static celix_status_t bundleArchive_reviseInternal(bundle_archive_pt archive, bool isReload, long revNr, char * location, char *inputFile);
@@ -67,25 +63,23 @@ static celix_status_t bundleArchive_revi
static celix_status_t bundleArchive_readLastModified(bundle_archive_pt archive, time_t *time);
static celix_status_t bundleArchive_writeLastModified(bundle_archive_pt archive);
-celix_status_t bundleArchive_createSystemBundleArchive(apr_pool_t *mp, framework_logger_pt logger, bundle_archive_pt *bundle_archive) {
+celix_status_t bundleArchive_createSystemBundleArchive(framework_logger_pt logger, bundle_archive_pt *bundle_archive) {
celix_status_t status = CELIX_SUCCESS;
char *error = NULL;
bundle_archive_pt archive;
- if (mp == NULL || *bundle_archive != NULL) {
+ if (*bundle_archive != NULL) {
status = CELIX_ILLEGAL_ARGUMENT;
error = "Missing required arguments and/or incorrect values";
} else {
- archive = (bundle_archive_pt) apr_palloc(mp, sizeof(*archive));
+ archive = (bundle_archive_pt) malloc(sizeof(*archive));
if (archive == NULL) {
status = CELIX_ENOMEM;
} else {
- apr_pool_pre_cleanup_register(mp, archive, bundleArchive_destroy);
status = linkedList_create(&archive->revisions);
if (status == CELIX_SUCCESS) {
archive->id = 0l;
archive->location = "System Bundle";
- archive->mp = mp;
archive->archiveRoot = NULL;
archive->archiveRootDir = NULL;
archive->refreshCount = -1;
@@ -103,21 +97,19 @@ celix_status_t bundleArchive_createSyste
return status;
}
-celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRoot, long id, char * location, char *inputFile, apr_pool_t *mp, bundle_archive_pt *bundle_archive) {
+celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRoot, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive) {
celix_status_t status = CELIX_SUCCESS;
char *error = NULL;
- apr_pool_t *revisions_pool;
bundle_archive_pt archive;
if (*bundle_archive != NULL) {
status = CELIX_ILLEGAL_ARGUMENT;
error = "bundle_archive_pt must be NULL";
} else {
- archive = (bundle_archive_pt) apr_pcalloc(mp, sizeof(*archive));
+ archive = (bundle_archive_pt) malloc(sizeof(*archive));
if (archive == NULL) {
status = CELIX_ENOMEM;
} else {
- apr_pool_pre_cleanup_register(mp, archive, bundleArchive_destroy);
status = linkedList_create(&archive->revisions);
if (status == CELIX_SUCCESS) {
archive->id = id;
@@ -128,8 +120,6 @@ celix_status_t bundleArchive_create(fram
archive->logger = logger;
time(&archive->lastModified);
- archive->mp = mp;
-
bundleArchive_initialize(archive);
bundleArchive_revise(archive, location, inputFile);
@@ -144,9 +134,8 @@ celix_status_t bundleArchive_create(fram
return status;
}
-static apr_status_t bundleArchive_destroy(void *archiveP) {
- apr_status_t status = APR_SUCCESS;
- bundle_archive_pt archive = archiveP;
+celix_status_t bundleArchive_destroy(bundle_archive_pt archive) {
+ celix_status_t status = CELIX_SUCCESS;
if (archive->revisions != NULL) {
linkedList_destroy(archive->revisions);
@@ -158,39 +147,38 @@ static apr_status_t bundleArchive_destro
return status;
}
-celix_status_t bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp, bundle_archive_pt *bundle_archive) {
+celix_status_t bundleArchive_recreate(char * archiveRoot, bundle_archive_pt *bundle_archive) {
celix_status_t status = CELIX_SUCCESS;
char *errpr = NULL;
bundle_archive_pt archive;
- archive = (bundle_archive_pt) apr_pcalloc(mp, sizeof(*archive));
+ archive = (bundle_archive_pt) malloc(sizeof(*archive));
if (archive == NULL) {
status = CELIX_ENOMEM;
} else {
- apr_dir_t *dir;
- apr_pool_pre_cleanup_register(mp, archive, bundleArchive_destroy);
status = linkedList_create(&archive->revisions);
if (status == CELIX_SUCCESS) {
archive->archiveRoot = archiveRoot;
- apr_dir_open(&archive->archiveRootDir, archiveRoot, mp);
+ archive->archiveRootDir = NULL;
archive->id = -1;
archive->persistentState = -1;
archive->location = NULL;
- archive->mp = mp;
archive->refreshCount = -1;
archive->lastModified = (time_t) NULL;
}
- status = CELIX_DO_IF(status, apr_dir_open(&dir, archiveRoot, mp));
- if (status == CELIX_SUCCESS) {
- apr_finfo_t dp;
+ archive->archiveRootDir = opendir(archiveRoot);
+ if (archive->archiveRootDir == NULL) {
+ status = CELIX_FRAMEWORK_EXCEPTION;
+ } else {
+ struct dirent *dent;
long idx = 0;
char *location;
- while ((apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
- if (dp.filetype == APR_DIR && (strncmp(dp.name, "version", 7) == 0)) {
- sscanf(dp.name, "version%*d.%ld", &idx);
+ while ((dent = readdir(archive->archiveRootDir)) != NULL) {
+ if (dent->d_type == DT_DIR && (strncmp(dent->d_name, "version", 7) == 0)) {
+ sscanf(dent->d_name, "version%*d.%ld", &idx);
}
}
@@ -202,7 +190,7 @@ celix_status_t bundleArchive_recreate(ch
}
}
- framework_logIfError(archive->logger, status, NULL, "Could not create archive");
+ framework_logIfError(logger, status, NULL, "Could not create archive");
return status;
}
@@ -211,36 +199,22 @@ celix_status_t bundleArchive_getId(bundl
celix_status_t status = CELIX_SUCCESS;
if (archive->id < 0) {
- apr_file_t *bundleIdFile;
- char * bundleId = NULL;
+ FILE *bundleIdFile;
char id[256];
- apr_pool_t *subpool = NULL;
- status = CELIX_DO_IF(status, apr_pool_create(&subpool, archive->mp));
- if (status == CELIX_SUCCESS) {
- bundleId = (char *)apr_palloc(subpool, strlen(archive->archiveRoot) + 11);
- if (bundleId == NULL) {
- status = CELIX_ENOMEM;
- }
- }
- if (status == CELIX_SUCCESS) {
- strcpy(bundleId, archive->archiveRoot);
- strcat(bundleId, "/bundle.id");
- }
- status = CELIX_DO_IF(status, apr_file_open(&bundleIdFile, bundleId, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp));
- status = CELIX_DO_IF(status, apr_file_gets(id, sizeof(id), bundleIdFile));
- status = CELIX_DO_IF(status, apr_file_close(bundleIdFile));
- if (status == CELIX_SUCCESS) {
- sscanf(id, "%ld", &archive->id);
- }
+ char bundleId[512];
+ snprintf(bundleId, sizeof(bundleId), "%s/bundle.id", archive->archiveRoot);
- apr_pool_destroy(subpool);
+ bundleIdFile = fopen(bundleId, "r");
+ fgets(id, sizeof(id), bundleIdFile);
+ fclose(bundleIdFile);
+ sscanf(id, "%ld", &archive->id);
}
if (status == CELIX_SUCCESS) {
*id = archive->id;
}
- framework_logIfError(archive->logger, status, NULL, "Could not get archive id");
+ framework_logIfError(logger, status, NULL, "Could not get archive id");
return status;
}
@@ -248,36 +222,23 @@ celix_status_t bundleArchive_getId(bundl
celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, char **location) {
celix_status_t status = CELIX_SUCCESS;
if (archive->location == NULL) {
- apr_file_t *bundleLocationFile;
- apr_status_t rv;
- char * bundleLocation = NULL;
- apr_pool_t *subpool = NULL;
- status = CELIX_DO_IF(status, apr_pool_create(&subpool, archive->mp));
- if (status == CELIX_SUCCESS) {
- char location[256];
- bundleLocation = (char *)apr_palloc(subpool, strlen(archive->archiveRoot) + 17);
- if (bundleLocation == NULL) {
- status = CELIX_ENOMEM;
- }
-
- strcpy(bundleLocation,archive->archiveRoot);
- strcat(bundleLocation, "/bundle.location");
-
- status = CELIX_DO_IF(status, apr_file_open(&bundleLocationFile, bundleLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp));
- status = CELIX_DO_IF(status, apr_file_gets (location , sizeof(location) , bundleLocationFile));
- status = CELIX_DO_IF(status, apr_file_close(bundleLocationFile));
- if (status == CELIX_SUCCESS) {
- archive->location = apr_pstrdup(archive->mp, location);
- }
- apr_pool_destroy(subpool);
- }
+ FILE *bundleLocationFile;
+ char bundleLocation[512];
+ char location[256];
+
+ snprintf(bundleLocation, sizeof(bundleLocation), "%s/bundle.location", archive->archiveRoot);
+
+ bundleLocationFile = fopen(bundleLocation, "r");
+ fgets(location, sizeof(location), bundleLocationFile);
+ fclose(bundleLocationFile);
+ archive->location = strdup(location);
}
if (status == CELIX_SUCCESS) {
*location = archive->location;
}
- framework_logIfError(archive->logger, status, NULL, "Could not get archive location");
+ framework_logIfError(logger, status, NULL, "Could not get archive location");
return status;
}
@@ -295,7 +256,7 @@ celix_status_t bundleArchive_getCurrentR
status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
status = CELIX_DO_IF(status, bundleRevision_getNumber(revision, revisionNumber));
- framework_logIfError(archive->logger, status, NULL, "Could not get current revision number");
+ framework_logIfError(logger, status, NULL, "Could not get current revision number");
return status;
}
@@ -312,94 +273,78 @@ celix_status_t bundleArchive_getRevision
celix_status_t bundleArchive_getPersistentState(bundle_archive_pt archive, bundle_state_e *state) {
celix_status_t status = CELIX_SUCCESS;
- apr_status_t apr_status;
if (archive->persistentState != OSGI_FRAMEWORK_BUNDLE_UNKNOWN) {
*state = archive->persistentState;
} else {
- apr_file_t *persistentStateLocationFile;
- char * persistentStateLocation = NULL;
- apr_pool_t *subpool;
- status = CELIX_DO_IF(status, apr_pool_create(&subpool, archive->mp));
- if (status == CELIX_SUCCESS) {
- persistentStateLocation = apr_palloc(subpool, strlen(archive->archiveRoot) + 14);
- if (persistentStateLocation == NULL) {
- status = CELIX_ENOMEM;
- } else {
- char stateString[256];
- strcpy(persistentStateLocation, archive->archiveRoot);
- strcat(persistentStateLocation, "/bundle.state");
-
- status = CELIX_DO_IF(status, apr_file_open(&persistentStateLocationFile, persistentStateLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp));
- status = CELIX_DO_IF(status, apr_file_gets(stateString , sizeof(stateString) , persistentStateLocationFile));
- status = CELIX_DO_IF(status, apr_file_close(persistentStateLocationFile));
-
- if (status == CELIX_SUCCESS) {
- if (stateString != NULL && (strcmp(stateString, "active") == 0)) {
- archive->persistentState = OSGI_FRAMEWORK_BUNDLE_ACTIVE;
- } else if (stateString != NULL && (strcmp(stateString, "starting") == 0)) {
- archive->persistentState = OSGI_FRAMEWORK_BUNDLE_STARTING;
- } else if (stateString != NULL && (strcmp(stateString, "uninstalled") == 0)) {
- archive->persistentState = OSGI_FRAMEWORK_BUNDLE_UNINSTALLED;
- } else {
- archive->persistentState = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
- }
+ FILE *persistentStateLocationFile;
+ char persistentStateLocation[512];
+ char stateString[256];
+ snprintf(persistentStateLocation, sizeof(persistentStateLocation), "%s/bundle.state", archive->archiveRoot);
+
+ persistentStateLocationFile = fopen(persistentStateLocation, "r");
+ if (persistentStateLocationFile == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ if (fgets(stateString, sizeof(stateString), persistentStateLocationFile) == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ }
+ fclose(persistentStateLocationFile);
+ }
- *state = archive->persistentState;
- }
- }
- apr_pool_destroy(subpool);
+ if (status == CELIX_SUCCESS) {
+ if (stateString != NULL && (strcmp(stateString, "active") == 0)) {
+ archive->persistentState = OSGI_FRAMEWORK_BUNDLE_ACTIVE;
+ } else if (stateString != NULL && (strcmp(stateString, "starting") == 0)) {
+ archive->persistentState = OSGI_FRAMEWORK_BUNDLE_STARTING;
+ } else if (stateString != NULL && (strcmp(stateString, "uninstalled") == 0)) {
+ archive->persistentState = OSGI_FRAMEWORK_BUNDLE_UNINSTALLED;
+ } else {
+ archive->persistentState = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
+ }
+
+ *state = archive->persistentState;
}
}
- framework_logIfError(archive->logger, status, NULL, "Could not get persistent state");
+ framework_logIfError(logger, status, NULL, "Could not get persistent state");
return status;
}
celix_status_t bundleArchive_setPersistentState(bundle_archive_pt archive, bundle_state_e state) {
celix_status_t status = CELIX_SUCCESS;
- char * persistentStateLocation = NULL;
- apr_file_t *persistentStateLocationFile;
- apr_pool_t *subpool = NULL;
+ char persistentStateLocation[512];
+ FILE *persistentStateLocationFile;
- status = CELIX_DO_IF(status, apr_pool_create(&subpool, archive->mp));
- if (status == CELIX_SUCCESS) {
- persistentStateLocation = (char *)apr_palloc(subpool, strlen(archive->archiveRoot) + 14);
- if (persistentStateLocation == NULL) {
- status = CELIX_ENOMEM;
- } else {
- strcpy(persistentStateLocation, archive->archiveRoot);
- strcat(persistentStateLocation, "/bundle.state");
+ snprintf(persistentStateLocation, sizeof(persistentStateLocation), "%s/bundle.state", archive->archiveRoot);
- status = CELIX_DO_IF(status, apr_file_open(&persistentStateLocationFile, persistentStateLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp));
- if (status == CELIX_SUCCESS) {
- char * s;
- switch (state) {
- case OSGI_FRAMEWORK_BUNDLE_ACTIVE:
- s = "active";
- break;
- case OSGI_FRAMEWORK_BUNDLE_STARTING:
- s = "starting";
- break;
- case OSGI_FRAMEWORK_BUNDLE_UNINSTALLED:
- s = "uninstalled";
- break;
- default:
- s = "installed";
- break;
- }
- apr_file_printf(persistentStateLocationFile, "%s", s);
- status = CELIX_DO_IF(status, apr_file_close(persistentStateLocationFile));
- if (status == CELIX_SUCCESS) {
- archive->persistentState = state;
- }
- }
- }
- apr_pool_destroy(subpool);
+ persistentStateLocationFile = fopen(persistentStateLocation, "w");
+ if (persistentStateLocationFile == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ char * s;
+ switch (state) {
+ case OSGI_FRAMEWORK_BUNDLE_ACTIVE:
+ s = "active";
+ break;
+ case OSGI_FRAMEWORK_BUNDLE_STARTING:
+ s = "starting";
+ break;
+ case OSGI_FRAMEWORK_BUNDLE_UNINSTALLED:
+ s = "uninstalled";
+ break;
+ default:
+ s = "installed";
+ break;
+ }
+ fprintf(persistentStateLocationFile, "%s", s);
+ if (fclose(persistentStateLocationFile) == 0) {
+ archive->persistentState = state;
+ }
}
- framework_logIfError(archive->logger, status, NULL, "Could not set persistent state");
+ framework_logIfError(logger, status, NULL, "Could not set persistent state");
return status;
}
@@ -408,71 +353,51 @@ celix_status_t bundleArchive_getRefreshC
celix_status_t status = CELIX_SUCCESS;
if (archive->refreshCount == -1) {
- apr_file_t * refreshCounterFile;
- apr_status_t rv = APR_SUCCESS;
- apr_pool_t *subpool = NULL;
- char *refreshCounter = NULL;
-
- status = CELIX_DO_IF(status, apr_pool_create(&subpool, archive->mp));
- if (status == CELIX_SUCCESS) {
- refreshCounter = (char *) apr_palloc(subpool, strlen(archive->archiveRoot) + 17);
- if (refreshCounter == NULL) {
- status = CELIX_ENOMEM;
- } else {
- strcpy(refreshCounter,archive->archiveRoot);
- strcat(refreshCounter, "/refresh.counter");
-
- status = CELIX_DO_IF(status, apr_file_open(&refreshCounterFile, refreshCounter, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp));
- if (status != CELIX_SUCCESS) {
- archive->refreshCount = 0;
- status = CELIX_SUCCESS;
- } else {
- char counterStr[256];
- status = CELIX_DO_IF(status, apr_file_gets(counterStr , sizeof(counterStr) , refreshCounterFile));
- status = CELIX_DO_IF(status, apr_file_close(refreshCounterFile));
-
- if (status != CELIX_SUCCESS) {
- sscanf(counterStr, "%ld", &archive->refreshCount);
- }
- }
+ FILE *refreshCounterFile;
+ char refreshCounter[512];
+ snprintf(refreshCounter, sizeof(refreshCounter), "%s/refresh.counter", archive->archiveRoot);
+
+ refreshCounterFile = fopen(refreshCounter, "r");
+ if (refreshCounterFile == NULL) {
+ archive->refreshCount = 0;
+ } else {
+ char counterStr[256];
+ if (fgets(counterStr, sizeof(counterStr), refreshCounterFile) == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
}
- apr_pool_destroy(subpool);
- }
+ fclose(refreshCounterFile);
+ if (status == CELIX_SUCCESS) {
+ sscanf(counterStr, "%ld", &archive->refreshCount);
+ }
+ }
}
if (status == CELIX_SUCCESS) {
*refreshCount = archive->refreshCount;
}
- framework_logIfError(archive->logger, status, NULL, "Could not get refresh count");
+ framework_logIfError(logger, status, NULL, "Could not get refresh count");
return status;
}
celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive) {
- apr_file_t * refreshCounterFile;
- apr_status_t apr_status;
+ FILE *refreshCounterFile;
celix_status_t status = CELIX_SUCCESS;
- apr_pool_t *subpool;
- char * refreshCounter = NULL;
+ char refreshCounter[512];
- status = CELIX_DO_IF(status, apr_pool_create(&subpool, archive->mp));
- if (status == CELIX_SUCCESS) {
- refreshCounter = (char *) apr_palloc(subpool, strlen(archive->archiveRoot) + 17);
- if (refreshCounter == NULL) {
- status = CELIX_ENOMEM;
- } else {
- strcpy(refreshCounter, archive->archiveRoot);
- strcat(refreshCounter, "/refresh.counter");
-
- status = CELIX_DO_IF(status, apr_file_open(&refreshCounterFile, refreshCounter, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp));
- apr_file_printf(refreshCounterFile, "%ld", archive->refreshCount);
- status = CELIX_DO_IF(status, apr_file_close(refreshCounterFile));
- }
- apr_pool_destroy(subpool);
- }
+ snprintf(refreshCounter, sizeof(refreshCounter), "%s/bundle.state", archive->archiveRoot);
+
+ refreshCounterFile = fopen(refreshCounter, "w");
+ if (refreshCounterFile == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ fprintf(refreshCounterFile, "%ld", archive->refreshCount);
+ if (fclose(refreshCounterFile) == 0) {
+ }
+ }
- framework_logIfError(archive->logger, status, NULL, "Could not set refresh count");
+ framework_logIfError(logger, status, NULL, "Could not set refresh count");
return status;
}
@@ -488,7 +413,7 @@ celix_status_t bundleArchive_getLastModi
*lastModified = archive->lastModified;
}
- framework_logIfError(archive->logger, status, NULL, "Could not get last modified");
+ framework_logIfError(logger, status, NULL, "Could not get last modified");
return status;
}
@@ -499,82 +424,66 @@ celix_status_t bundleArchive_setLastModi
archive->lastModified = lastModifiedTime;
status = CELIX_DO_IF(status, bundleArchive_writeLastModified(archive));
- framework_logIfError(archive->logger, status, NULL, "Could not set last modified");
+ framework_logIfError(logger, status, NULL, "Could not set last modified");
return status;
}
static celix_status_t bundleArchive_readLastModified(bundle_archive_pt archive, time_t *time) {
- char timeStr[20];
- apr_file_t *lastModifiedFile;
- char *lastModified = NULL;
+ FILE *lastModifiedFile;
+ char lastModified[512];
celix_status_t status = CELIX_SUCCESS;
- apr_pool_t *subpool = NULL;
- status = CELIX_DO_IF(status, apr_pool_create(&subpool, archive->mp));
+ snprintf(lastModified, sizeof(lastModified), "%s/bundle.lastmodified", archive->archiveRoot);
- lastModified = (char *)apr_palloc(subpool, strlen(archive->archiveRoot) + 21);
- if (lastModified == NULL) {
- status = CELIX_ENOMEM;
- } else {
- sprintf(lastModified, "%s/bundle.lastmodified", archive->archiveRoot);
-
- status = CELIX_DO_IF(status, apr_file_open(&lastModifiedFile, lastModified, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp));
- if (status == APR_SUCCESS) {
- int year, month, day, hours, minutes, seconds;
- struct tm tm_time;
-
- status = CELIX_DO_IF(status, apr_file_gets(timeStr, sizeof(timeStr), lastModifiedFile));
- status = CELIX_DO_IF(status, apr_file_close(lastModifiedFile));
-
- if (status == CELIX_SUCCESS) {
- sscanf(timeStr, "%d %d %d %d:%d:%d", &year, &month, &day, &hours, &minutes, &seconds);
- tm_time.tm_year = year - 1900;
- tm_time.tm_mon = month - 1;
- tm_time.tm_mday = day;
- tm_time.tm_hour = hours;
- tm_time.tm_min = minutes;
- tm_time.tm_sec = seconds;
+ lastModifiedFile = fopen(lastModified, "r");
+ if (lastModifiedFile == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ char timeStr[20];
+ int year, month, day, hours, minutes, seconds;
+ struct tm tm_time;
- *time = mktime(&tm_time);
- }
+ if (fgets(timeStr, sizeof(timeStr), lastModifiedFile) == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
}
+ fclose(lastModifiedFile);
+ if (status == CELIX_SUCCESS) {
+ sscanf(timeStr, "%d %d %d %d:%d:%d", &year, &month, &day, &hours, &minutes, &seconds);
+ tm_time.tm_year = year - 1900;
+ tm_time.tm_mon = month - 1;
+ tm_time.tm_mday = day;
+ tm_time.tm_hour = hours;
+ tm_time.tm_min = minutes;
+ tm_time.tm_sec = seconds;
- apr_pool_destroy(subpool);
- }
+ *time = mktime(&tm_time);
+ }
+ }
- framework_logIfError(archive->logger, status, NULL, "Could not read last modified");
+ framework_logIfError(logger, status, NULL, "Could not read last modified");
return status;
}
static celix_status_t bundleArchive_writeLastModified(bundle_archive_pt archive) {
celix_status_t status = CELIX_SUCCESS;
- apr_file_t *lastModifiedFile;
- char timeStr[20];
- char * lastModified = NULL;
- apr_pool_t *subpool = NULL;
- apr_status_t apr_status;
-
- apr_pool_create(&subpool, archive->mp);
+ FILE *lastModifiedFile;
+ char lastModified[512];
- lastModified = (char *)apr_palloc(subpool, strlen(archive->archiveRoot) + 21);
-
-
- sprintf(lastModified, "%s/bundle.lastmodified", archive->archiveRoot);
- strftime(timeStr, 20, "%Y %m %d %H:%M:%S", localtime(&archive->lastModified));
+ snprintf(lastModified, sizeof(lastModified), "%s/bundle.lastmodified", archive->archiveRoot);
+ lastModifiedFile = fopen(lastModified, "w");
+ if (lastModifiedFile == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ char timeStr[20];
+ strftime(timeStr, 20, "%Y %m %d %H:%M:%S", localtime(&archive->lastModified));
+ fprintf(lastModifiedFile, "%s", timeStr);
+ fclose(lastModifiedFile);
+ }
- apr_status = apr_file_open(&lastModifiedFile, lastModified, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
- apr_pool_destroy(subpool);
- if (apr_status != APR_SUCCESS) {
- status = CELIX_FILE_IO_EXCEPTION;
- } else {
- apr_file_printf(lastModifiedFile, "%s", timeStr);
- apr_file_close(lastModifiedFile);
- }
-
- framework_logIfError(archive->logger, status, NULL, "Could not write last modified");
+ framework_logIfError(logger, status, NULL, "Could not write last modified");
return status;
}
@@ -591,7 +500,7 @@ celix_status_t bundleArchive_revise(bund
status = bundleArchive_reviseInternal(archive, false, revNr, location, inputFile);
}
- framework_logIfError(archive->logger, status, NULL, "Could not revise bundle archive");
+ framework_logIfError(logger, status, NULL, "Could not revise bundle archive");
return status;
}
@@ -614,7 +523,7 @@ static celix_status_t bundleArchive_revi
linkedList_addElement(archive->revisions, revision);
}
- framework_logIfError(archive->logger, status, NULL, "Could not revise bundle archive");
+ framework_logIfError(logger, status, NULL, "Could not revise bundle archive");
return status;
}
@@ -632,25 +541,16 @@ static celix_status_t bundleArchive_crea
status = bundleArchive_getRefreshCount(archive, &refreshCount);
if (status == CELIX_SUCCESS) {
bundle_revision_pt revision = NULL;
- apr_pool_t *pool = NULL;
sprintf(root, "%s/version%ld.%ld", archive->archiveRoot, refreshCount, revNr);
- if (apr_pool_create(&pool, archive->mp) == APR_SUCCESS) {
- status = bundleRevision_create(pool, archive->logger, root, location, revNr, inputFile, &revision);
-
- if (status != CELIX_SUCCESS) {
- apr_pool_destroy(pool);
- }
- } else {
- status = CELIX_ENOMEM;
- }
+ status = bundleRevision_create(logger, root, location, revNr, inputFile, &revision);
if (status == CELIX_SUCCESS) {
*bundle_revision = revision;
}
}
- framework_logIfError(archive->logger, status, NULL, "Could not create revision [location=%s,inputFile=%s]", location, inputFile);
+ framework_logIfError(logger, status, NULL, "Could not create revision [location=%s,inputFile=%s]", location, inputFile);
return status;
}
@@ -662,16 +562,17 @@ static celix_status_t bundleArchive_getR
status = bundleArchive_getRefreshCount(archive, &refreshCount);
if (status == CELIX_SUCCESS) {
- apr_file_t * revisionLocationFile;
+ FILE *revisionLocationFile;
- sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, refreshCount, revNr);
+ snprintf(revisionLocation, sizeof(revisionLocation), "%s/version%ld.%ld/revision.location", archive->archiveRoot, refreshCount, revNr);
- if (apr_file_open(&revisionLocationFile, revisionLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp) == APR_SUCCESS) {
+ revisionLocationFile = fopen(revisionLocation, "r");
+ if (revisionLocationFile != NULL) {
char location[256];
- apr_file_gets (location , sizeof(location) , revisionLocationFile);
- apr_file_close(revisionLocationFile);
+ fgets(location , sizeof(location) , revisionLocationFile);
+ fclose(revisionLocationFile);
- *revision_location = apr_pstrdup(archive->mp, location);
+ *revision_location = strdup(location);
status = CELIX_SUCCESS;
} else {
// revision file not found
@@ -681,7 +582,7 @@ static celix_status_t bundleArchive_getR
}
- framework_logIfError(archive->logger, status, NULL, "Failed to get revision location");
+ framework_logIfError(logger, status, NULL, "Failed to get revision location");
return status;
}
@@ -694,19 +595,20 @@ static celix_status_t bundleArchive_setR
status = bundleArchive_getRefreshCount(archive, &refreshCount);
if (status == CELIX_SUCCESS) {
- apr_file_t * revisionLocationFile;
+ FILE * revisionLocationFile;
- sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, refreshCount, revNr);
+ snprintf(revisionLocation, sizeof(revisionLocation), "%s/version%ld.%ld/revision.location", archive->archiveRoot, refreshCount, revNr);
- if (apr_file_open(&revisionLocationFile, revisionLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp) != APR_SUCCESS) {
+ revisionLocationFile = fopen(revisionLocation, "w");
+ if (revisionLocationFile == NULL) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
- apr_file_printf(revisionLocationFile, "%s", location);
- apr_file_close(revisionLocationFile);
+ fprintf(revisionLocationFile, "%s", location);
+ fclose(revisionLocationFile);
}
}
- framework_logIfError(archive->logger, status, NULL, "Failed to set revision location");
+ framework_logIfError(logger, status, NULL, "Failed to set revision location");
return status;
}
@@ -722,10 +624,10 @@ celix_status_t bundleArchive_closeAndDel
status = bundleArchive_close(archive);
if (status == CELIX_SUCCESS) {
- status = bundleArchive_deleteTree(archive, archive->archiveRoot, archive->mp);
+ status = bundleArchive_deleteTree(archive, archive->archiveRoot);
}
- framework_logIfError(archive->logger, status, NULL, "Failed to close and delete archive");
+ framework_logIfError(logger, status, NULL, "Failed to close and delete archive");
return status;
}
@@ -734,108 +636,88 @@ static celix_status_t bundleArchive_init
celix_status_t status = CELIX_SUCCESS;
if (archive->archiveRootDir == NULL) {
- if (apr_dir_make(archive->archiveRoot, APR_UREAD|APR_UWRITE|APR_UEXECUTE, archive->mp) != APR_SUCCESS) {
+ if (mkdir(archive->archiveRoot, S_IRWXU) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
- apr_pool_t *spool = NULL;
-
- apr_pool_create(&spool, archive->mp);
- apr_status_t apr_status = apr_dir_open(&archive->archiveRootDir, archive->archiveRoot, spool);
- if (apr_status != APR_SUCCESS) {
+ archive->archiveRootDir = opendir(archive->archiveRoot);
+ if (archive->archiveRootDir == NULL) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
- apr_file_t *bundleIdFile;
- apr_status_t apr_status;
- char *bundleId = NULL;
+ FILE *bundleIdFile;
+ char bundleId[512];
- bundleId = (char *)apr_palloc(spool, sizeof(*bundleId) * (strlen(archive->archiveRoot) + 11));
- bundleId = apr_pstrcat(spool, archive->archiveRoot, "/bundle.id", NULL);
+ snprintf(bundleId, sizeof(bundleId), "%s/bundle.id", archive->archiveRoot);
+ bundleIdFile = fopen(bundleId, "w");
- apr_status = apr_file_open(&bundleIdFile, bundleId, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, spool);
- if (apr_status != APR_SUCCESS) {
+ if (bundleIdFile == NULL) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
- char * bundleLocation;
- apr_file_t *bundleLocationFile;
+ FILE *bundleLocationFile;
+ char bundleLocation[512];
- apr_file_printf(bundleIdFile, "%ld", archive->id);
+ fprintf(bundleIdFile, "%ld", archive->id);
// Ignore close status, let it fail if needed again
- apr_file_close(bundleIdFile);
+ fclose(bundleIdFile);
- bundleLocation = (char *) apr_palloc(spool, strlen(archive->archiveRoot) + 17);
- bundleLocation = apr_pstrcat(spool, archive->archiveRoot, "/bundle.location", NULL);
+ snprintf(bundleLocation, sizeof(bundleLocation), "%s/bundle.location", archive->archiveRoot);
+ bundleLocationFile = fopen(bundleLocation, "w");
- apr_status = apr_file_open(&bundleLocationFile, bundleLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, spool);
- if (apr_status != APR_SUCCESS) {
+ if (bundleLocationFile == NULL) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
- apr_file_printf(bundleLocationFile, "%s", archive->location);
+ fprintf(bundleLocationFile, "%s", archive->location);
// Ignore close status, let it fail if needed again
- apr_file_close(bundleLocationFile);
+ fclose(bundleLocationFile);
status = bundleArchive_writeLastModified(archive);
}
}
- status = apr_dir_close(archive->archiveRootDir);
+ closedir(archive->archiveRootDir);
}
- apr_pool_destroy(spool);
}
}
- framework_logIfError(archive->logger, status, NULL, "Failed to initialize archive");
+ framework_logIfError(logger, status, NULL, "Failed to initialize archive");
return status;
}
-static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, char * directory, apr_pool_t *mp) {
- apr_dir_t *dir;
+static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, char * directory) {
+ DIR *dir;
celix_status_t status = CELIX_SUCCESS;
- apr_status_t stat = apr_dir_open(&dir, directory, mp);
- if (stat != APR_SUCCESS) {
+ dir = opendir(directory);
+ if (dir == NULL) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
- apr_finfo_t dp;
- apr_status_t apr_status;
- while ((apr_status = apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
- if ((strcmp((dp.name), ".") != 0) && (strcmp((dp.name), "..") != 0)) {
- apr_pool_t *subpool;
- char * subdir = NULL;
-
- apr_pool_create(&subpool, mp);
-
- subdir = (char *) apr_palloc(subpool, strlen(directory) + strlen(dp.name) + 2);
-
- strcpy(subdir, directory);
- strcat(subdir, "/");
- strcat(subdir, dp.name);
+ struct dirent *dp;
+ while ((dp = readdir(dir)) != NULL) {
+ if ((strcmp((dp->d_name), ".") != 0) && (strcmp((dp->d_name), "..") != 0)) {
+ apr_pool_t *subpool;
+ char subdir[512];
+ snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp->d_name);
- if (dp.filetype == APR_DIR) {
- status = bundleArchive_deleteTree(archive, subdir, mp);
- } else {
- if (apr_file_remove(subdir, mp) != APR_SUCCESS) {
- status = CELIX_FILE_IO_EXCEPTION;
- free(subdir);
- break;
- }
- }
- apr_pool_destroy(subpool);
- }
- }
- if (apr_status != APR_SUCCESS && apr_status != APR_ENOENT) {
- status = CELIX_FILE_IO_EXCEPTION;
+ if (dp->d_type == DT_DIR) {
+ status = bundleArchive_deleteTree(archive, subdir);
+ } else {
+ if (rmdir(subdir) != 0) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ break;
+ }
+ }
+ }
}
- apr_status = apr_dir_close(dir);
- if (apr_status != APR_SUCCESS) {
+
+ if (closedir(dir) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
}
if (status == CELIX_SUCCESS) {
- if (apr_dir_remove(directory, mp) != APR_SUCCESS) {
+ if (rmdir(directory) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
}
}
}
- framework_logIfError(archive->logger, status, NULL, "Failed to delete tree");
+ framework_logIfError(logger, status, NULL, "Failed to delete tree");
return status;
}
Modified: incubator/celix/trunk/framework/private/src/bundle_cache.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_cache.c?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_cache.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_cache.c Fri Jun 6 09:43:47 2014
@@ -23,42 +23,35 @@
* \author <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/
-#ifndef _WIN32
-#include <dirent.h>
-#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
-
-#include <apr_file_io.h>
-#include <apr_strings.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
#include "bundle_cache_private.h"
#include "bundle_archive.h"
#include "constants.h"
#include "celix_log.h"
-static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * directory, apr_pool_t *mp);
-static apr_status_t bundleCache_destroy(void *cacheP);
+static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * directory);
-celix_status_t bundleCache_create(properties_pt configurationMap, apr_pool_t *mp, framework_logger_pt logger, bundle_cache_pt *bundle_cache) {
+celix_status_t bundleCache_create(properties_pt configurationMap, framework_logger_pt logger, bundle_cache_pt *bundle_cache) {
celix_status_t status;
bundle_cache_pt cache;
- cache = (bundle_cache_pt) apr_palloc(mp, (sizeof(*cache)));
+ cache = (bundle_cache_pt) malloc((sizeof(*cache)));
if (cache == NULL) {
status = CELIX_ENOMEM;
} else {
- apr_pool_pre_cleanup_register(mp, cache, bundleCache_destroy);
-
- if (configurationMap != NULL && mp != NULL && *bundle_cache == NULL) {
+ if (configurationMap != NULL && *bundle_cache == NULL) {
char * cacheDir = properties_get(configurationMap, (char *) OSGI_FRAMEWORK_FRAMEWORK_STORAGE);
cache->configurationMap = configurationMap;
if (cacheDir == NULL) {
cacheDir = ".cache";
}
cache->cacheDir = cacheDir;
- cache->mp = mp;
cache->logger = logger;
*bundle_cache = cache;
@@ -73,58 +66,50 @@ celix_status_t bundleCache_create(proper
return status;
}
-apr_status_t bundleCache_destroy(void *cacheP) {
- bundle_cache_pt cache = (bundle_cache_pt) cacheP;
+celix_status_t bundleCache_destroy(bundle_cache_pt *cache) {
return CELIX_SUCCESS;
}
celix_status_t bundleCache_delete(bundle_cache_pt cache) {
- return bundleCache_deleteTree(cache, cache->cacheDir, cache->mp);
+ return bundleCache_deleteTree(cache, cache->cacheDir);
}
-celix_status_t bundleCache_getArchives(bundle_cache_pt cache, apr_pool_t *pool, array_list_pt *archives) {
+celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *archives) {
celix_status_t status = CELIX_SUCCESS;
- apr_dir_t *dir;
- apr_status_t aprStatus = apr_dir_open(&dir, cache->cacheDir, pool);
+ DIR *dir;
+ dir = opendir(cache->cacheDir);
- if (APR_STATUS_IS_ENOENT(aprStatus)) {
- apr_dir_make(cache->cacheDir, APR_UREAD|APR_UWRITE|APR_UEXECUTE, cache->mp);
- aprStatus = apr_dir_open(&dir, cache->cacheDir, pool);
+ if (dir == NULL && errno == ENOENT) {
+ mkdir(cache->cacheDir, S_IRWXU);
+ dir = opendir(cache->cacheDir);
}
- if (aprStatus == APR_SUCCESS) {
+ if (dir != NULL) {
array_list_pt list = NULL;
- apr_finfo_t dp;
+ struct dirent *dp;
arrayList_create(&list);
- while ((apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
- apr_pool_t *subpool = NULL;
- char *archiveRoot = NULL;
-
- apr_pool_create(&subpool, pool);
- archiveRoot = (char *)apr_palloc(subpool, strlen(cache->cacheDir) + strlen(dp.name) + 2);
-
- strcpy(archiveRoot, cache->cacheDir);
- strcat(archiveRoot, "/");
- strcat(archiveRoot, dp.name);
-
- if (dp.filetype == APR_DIR
- && (strcmp((dp.name), ".") != 0)
- && (strcmp((dp.name), "..") != 0)
- && (strncmp(dp.name, "bundle", 6) == 0)
- && (strcmp(dp.name, "bundle0") != 0)) {
+ while ((dp = readdir(dir)) != NULL) {
+ char archiveRoot[512];
+
+ snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s", cache->cacheDir, dp->d_name);
+
+ if (dp->d_type == DT_DIR
+ && (strcmp((dp->d_name), ".") != 0)
+ && (strcmp((dp->d_name), "..") != 0)
+ && (strncmp(dp->d_name, "bundle", 6) == 0)
+ && (strcmp(dp->d_name, "bundle0") != 0)) {
bundle_archive_pt archive = NULL;
- status = bundleArchive_recreate(apr_pstrdup(cache->mp, archiveRoot), cache->mp, &archive);
+ status = bundleArchive_recreate(strdup(archiveRoot), &archive);
if (status == CELIX_SUCCESS) {
arrayList_add(list, archive);
}
}
- apr_pool_destroy(subpool);
}
- apr_dir_close(dir);
+ closedir(dir);
*archives = list;
@@ -138,13 +123,13 @@ celix_status_t bundleCache_getArchives(b
return status;
}
-celix_status_t bundleCache_createArchive(bundle_cache_pt cache, apr_pool_t *bundlePool, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive) {
+celix_status_t bundleCache_createArchive(bundle_cache_pt cache, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive) {
celix_status_t status = CELIX_SUCCESS;
- char *archiveRoot = NULL;
+ char archiveRoot[512];
- if (cache && location && bundlePool) {
- archiveRoot = apr_psprintf(bundlePool, "%s/bundle%ld", cache->cacheDir, id);
- status = bundleArchive_create(cache->logger, archiveRoot, id, location, inputFile, bundlePool, bundle_archive);
+ if (cache && location) {
+ snprintf(archiveRoot, sizeof(archiveRoot), "%s/bundle%ld", cache->cacheDir, id);
+ status = bundleArchive_create(cache->logger, strdup(archiveRoot), id, location, inputFile, bundle_archive);
}
framework_logIfError(cache->logger, status, NULL, "Failed to create archive");
@@ -152,37 +137,42 @@ celix_status_t bundleCache_createArchive
return status;
}
-static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * directory, apr_pool_t *mp) {
+static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * directory) {
+ DIR *dir;
celix_status_t status = CELIX_SUCCESS;
- apr_dir_t *dir;
-
- if (directory && mp) {
- if (apr_dir_open(&dir, directory, mp) == APR_SUCCESS) {
- apr_finfo_t dp;
- while ((apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
- if ((strcmp((dp.name), ".") != 0) && (strcmp((dp.name), "..") != 0)) {
- char *subdir = (char *) apr_palloc(mp, sizeof(*subdir) * (strlen(directory) + strlen(dp.name) + 2));
- strcpy(subdir, directory);
- strcat(subdir, "/");
- strcat(subdir, dp.name);
-
- if (dp.filetype == APR_DIR) {
- bundleCache_deleteTree(cache, subdir, mp);
- } else {
- apr_file_remove(subdir, mp);
+ dir = opendir(directory);
+ if (dir == NULL) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ struct dirent *dp;
+ while ((dp = readdir(dir)) != NULL) {
+ if ((strcmp((dp->d_name), ".") != 0) && (strcmp((dp->d_name), "..") != 0)) {
+ apr_pool_t *subpool;
+ char subdir[512];
+ snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp->d_name);
+
+ if (dp->d_type == DT_DIR) {
+ status = bundleCache_deleteTree(cache, subdir);
+ } else {
+ if (rmdir(subdir) != 0) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ break;
}
}
}
- apr_dir_close(dir);
- apr_dir_remove(directory, mp);
- } else {
+ }
+
+ if (closedir(dir) != 0) {
status = CELIX_FILE_IO_EXCEPTION;
}
- } else {
- status = CELIX_ILLEGAL_ARGUMENT;
- }
+ if (status == CELIX_SUCCESS) {
+ if (rmdir(directory) != 0) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ }
+ }
+ }
- framework_logIfError(cache->logger, status, NULL, "Failed to delete tree");
+ framework_logIfError(logger, status, NULL, "Failed to delete tree");
- return status;
+ return status;
}
Modified: incubator/celix/trunk/framework/private/src/bundle_revision.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_revision.c?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_revision.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_revision.c Fri Jun 6 09:43:47 2014
@@ -26,28 +26,25 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <apr_strings.h>
-#include <apr_file_io.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
#include "bundle_revision_private.h"
#include "archive.h"
#include "celix_log.h"
-static apr_status_t bundleRevision_destroy(void *revisionP);
-
-celix_status_t bundleRevision_create(apr_pool_t *pool, framework_logger_pt loggera, char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision) {
+celix_status_t bundleRevision_create(framework_logger_pt loggera, char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision) {
celix_status_t status = CELIX_SUCCESS;
bundle_revision_pt revision = NULL;
- revision = (bundle_revision_pt) apr_pcalloc(pool, sizeof(*revision));
+ revision = (bundle_revision_pt) malloc(sizeof(*revision));
if (!revision) {
status = CELIX_ENOMEM;
} else {
- apr_status_t apr_status;
- apr_pool_pre_cleanup_register(pool, revision, bundleRevision_destroy);
// TODO: This overwrites an existing revision, is this supposed to happen?
- apr_status = apr_dir_make(root, APR_UREAD|APR_UWRITE|APR_UEXECUTE, pool);
- if ((apr_status != APR_SUCCESS) && (!APR_STATUS_IS_EEXIST(apr_status))) {
+ int state = mkdir(root, S_IRWXU);
+ if ((state != 0) && (errno != EEXIST)) {
status = CELIX_FILE_IO_EXCEPTION;
} else {
if (inputFile != NULL) {
@@ -61,16 +58,17 @@ celix_status_t bundleRevision_create(apr
status = CELIX_DO_IF(status, arrayList_create(&(revision->libraryHandles)));
if (status == CELIX_SUCCESS) {
revision->revisionNr = revisionNr;
- revision->root = apr_pstrdup(pool, root);
- revision->location = apr_pstrdup(pool, location);
+ revision->root = strdup(root);
+ revision->location = strdup(location);
revision->logger = loggera;
arrayList_create(&(revision->libraryHandles));
*bundle_revision = revision;
- char *manifest = apr_pstrcat(pool, revision->root, "/META-INF/MANIFEST.MF", NULL);
- status = manifest_createFromFile(pool, manifest, &revision->manifest);
+ char manifest[512];
+ snprintf(manifest, sizeof(manifest), "%s/META-INF/MANIFEST.MF", revision->root);
+ status = manifest_createFromFile(manifest, &revision->manifest);
}
}
}
@@ -80,8 +78,7 @@ celix_status_t bundleRevision_create(apr
return status;
}
-apr_status_t bundleRevision_destroy(void *revisionP) {
- bundle_revision_pt revision = revisionP;
+celix_status_t bundleRevision_destroy(celix_status_t *revision) {
return CELIX_SUCCESS;
}
Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Fri Jun 6 09:43:47 2014
@@ -31,7 +31,7 @@
#include "celixbool.h"
#include <math.h>
#include <apr_general.h>
-#include <apr_strings.h>
+//#include <apr_strings.h>
#include <apr_uuid.h>
#ifdef _WIN32
#include <winbase.h>
@@ -175,15 +175,14 @@ celix_status_t framework_create(framewor
*framework = (framework_pt) apr_palloc(memoryPool, sizeof(**framework));
if (*framework != NULL) {
- apr_status_t apr_status = APR_SUCCESS;
- apr_status = CELIX_DO_IF(apr_status, apr_pool_create(&(*framework)->mp, memoryPool));
- apr_status = CELIX_DO_IF(apr_status, celixThreadCondition_init(&(*framework)->condition, NULL));
- apr_status = CELIX_DO_IF(apr_status, celixThreadMutex_create(&(*framework)->mutex, NULL));
- apr_status = CELIX_DO_IF(apr_status, celixThreadMutex_create(&(*framework)->bundleLock, NULL));
- apr_status = CELIX_DO_IF(apr_status, celixThreadMutex_create(&(*framework)->installRequestLock, NULL));
- apr_status = CELIX_DO_IF(apr_status, celixThreadMutex_create(&(*framework)->dispatcherLock, NULL));
- apr_status = CELIX_DO_IF(apr_status, celixThreadCondition_init(&(*framework)->dispatcher, NULL));
- if (apr_status == APR_SUCCESS) {
+ status = CELIX_DO_IF(status, apr_pool_create(&(*framework)->mp, memoryPool));
+ status = CELIX_DO_IF(status, celixThreadCondition_init(&(*framework)->condition, NULL));
+ status = CELIX_DO_IF(status, celixThreadMutex_create(&(*framework)->mutex, NULL));
+ status = CELIX_DO_IF(status, celixThreadMutex_create(&(*framework)->bundleLock, NULL));
+ status = CELIX_DO_IF(status, celixThreadMutex_create(&(*framework)->installRequestLock, NULL));
+ status = CELIX_DO_IF(status, celixThreadMutex_create(&(*framework)->dispatcherLock, NULL));
+ status = CELIX_DO_IF(status, celixThreadCondition_init(&(*framework)->dispatcher, NULL));
+ if (status == CELIX_SUCCESS) {
(*framework)->bundle = NULL;
(*framework)->installedBundleMap = NULL;
(*framework)->registry = NULL;
@@ -320,7 +319,7 @@ celix_status_t fw_init(framework_pt fram
if (status == CELIX_SUCCESS) {
if ((state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) || (state == OSGI_FRAMEWORK_BUNDLE_RESOLVED)) {
bundle_state_e state;
- status = CELIX_DO_IF(status, bundleCache_create(framework->configurationMap, framework->mp, framework->logger, &framework->cache));
+ status = CELIX_DO_IF(status, bundleCache_create(framework->configurationMap, framework->logger, &framework->cache));
status = CELIX_DO_IF(status, bundle_getState(framework->bundle, &state));
if (status == CELIX_SUCCESS) {
if (state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) {
@@ -359,7 +358,7 @@ celix_status_t fw_init(framework_pt fram
}
}
- status = CELIX_DO_IF(status, bundleCache_getArchives(framework->cache, framework->mp, &archives));
+ status = CELIX_DO_IF(status, bundleCache_getArchives(framework->cache, &archives));
if (status == CELIX_SUCCESS) {
unsigned int arcIdx;
for (arcIdx = 0; arcIdx < arrayList_size(archives); arcIdx++) {
@@ -401,7 +400,7 @@ celix_status_t fw_init(framework_pt fram
status = CELIX_DO_IF(status, bundle_setContext(framework->bundle, context));
if (status == CELIX_SUCCESS) {
activator_pt activator = NULL;
- activator = (activator_pt) apr_palloc(framework->mp, (sizeof(*activator)));
+ activator = (activator_pt) malloc((sizeof(*activator)));
if (activator != NULL) {
bundle_context_pt context = NULL;
void * userData = NULL;
@@ -527,7 +526,7 @@ celix_status_t fw_installBundle2(framewo
apr_pool_create(&bundlePool, framework->mp);
if (archive == NULL) {
id = framework_getNextBundleId(framework);
- status = CELIX_DO_IF(status, bundleCache_createArchive(framework->cache, bundlePool, id, location, inputFile, &archive));
+ status = CELIX_DO_IF(status, bundleCache_createArchive(framework->cache, id, location, inputFile, &archive));
} else {
// purge revision
// multiple revisions not yet implemented
@@ -573,18 +572,20 @@ celix_status_t framework_getBundleEntry(
status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
status = CELIX_DO_IF(status, bundleRevision_getRoot(revision, &root));
if (status == CELIX_SUCCESS) {
- char *e = NULL;
- apr_status_t ret;
- apr_finfo_t info;
if ((strlen(name) > 0) && (name[0] == '/')) {
name++;
}
- apr_filepath_merge(&e, root, name, APR_FILEPATH_NOTABOVEROOT, framework->mp);
- ret = apr_stat(&info, e, APR_FINFO_DIRENT|APR_FINFO_TYPE, framework->mp);
- if (ret == APR_ENOENT) {
+ char e[strlen(name) + strlen(root) + 2];
+ strcpy(e, root);
+ strcat(e, "/");
+ strcat(e, name);
+
+ struct stat info;
+
+ if (stat(e, &info) == 0) {
+ (*entry) = strdup(e);
+ } else {
(*entry) = NULL;
- } else if (ret == APR_SUCCESS || ret == APR_INCOMPLETE) {
- (*entry) = apr_pstrdup(pool, e);
}
}
@@ -599,7 +600,6 @@ celix_status_t fw_startBundle(framework_
bundle_state_e state;
module_pt module = NULL;
activator_pt activator = NULL;
- apr_pool_t *bundlePool = NULL;
char *error = NULL;
char *name = NULL;
@@ -646,10 +646,9 @@ celix_status_t fw_startBundle(framework_
module_getSymbolicName(module, &name);
status = CELIX_DO_IF(status, bundleContext_create(framework, framework->logger, bundle, &context));
status = CELIX_DO_IF(status, bundle_setContext(bundle, context));
- status = CELIX_DO_IF(status, bundle_getMemoryPool(bundle, &bundlePool));
if (status == CELIX_SUCCESS) {
- activator = (activator_pt) apr_palloc(bundlePool, (sizeof(*activator)));
+ activator = (activator_pt) malloc((sizeof(*activator)));
if (activator == NULL) {
status = CELIX_ENOMEM;
} else {
@@ -1181,27 +1180,22 @@ celix_status_t fw_registerService(framew
if (strcmp(serviceName, OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME) == 0) {
unsigned int i;
array_list_pt infos = NULL;
- apr_pool_t *subpool;
service_reference_pt ref = NULL;
listener_hook_service_pt hook;
- apr_pool_t *pool = NULL;
- status = CELIX_DO_IF(status, bundle_getMemoryPool(bundle, &pool));
status = CELIX_DO_IF(status, arrayList_create(&infos));
if (status == CELIX_SUCCESS) {
celix_status_t subs = CELIX_SUCCESS;
for (i = 0; i < arrayList_size(framework->serviceListeners); i++) {
fw_service_listener_pt listener =(fw_service_listener_pt) arrayList_get(framework->serviceListeners, i);
- apr_pool_t *pool = NULL;
bundle_context_pt context = NULL;
listener_hook_info_pt info = NULL;
bundle_context_pt lContext = NULL;
subs = CELIX_DO_IF(subs, bundle_getContext(bundle, &context));
- subs = CELIX_DO_IF(subs, bundleContext_getMemoryPool(context, &pool));
if (subs == CELIX_SUCCESS) {
- info = (listener_hook_info_pt) apr_palloc(pool, sizeof(*info));
+ info = (listener_hook_info_pt) malloc(sizeof(*info));
if (info == NULL) {
subs = CELIX_ENOMEM;
}
@@ -1224,8 +1218,6 @@ celix_status_t fw_registerService(framew
bool ungetResult = false;
- status = CELIX_DO_IF(status, apr_pool_create(&subpool, pool));
-
status = CELIX_DO_IF(status, serviceRegistry_createServiceReference(framework->registry, *registration, &ref));
status = CELIX_DO_IF(status, fw_getService(framework,framework->bundle, ref, (void **) &hook));
if (status == CELIX_SUCCESS) {
@@ -1234,7 +1226,12 @@ celix_status_t fw_registerService(framew
status = CELIX_DO_IF(status, serviceRegistry_ungetService(framework->registry, framework->bundle, ref, &ungetResult));
status = CELIX_DO_IF(status, serviceRegistry_removeReference(ref)); //NOTE: should this not be done in the serviceRegistry_ungetService??
- apr_pool_destroy(subpool);
+ int i = 0;
+ for (i = 0; i < arrayList_size(infos); i++) {
+ listener_hook_info_pt info = arrayList_get(infos, i);
+ free(info);
+ }
+ arrayList_destroy(infos);
}
}
}
@@ -1269,13 +1266,9 @@ celix_status_t fw_getServiceReferences(f
filter_pt filter = NULL;
unsigned int refIdx = 0;
- apr_pool_t *pool = NULL;
- status = CELIX_DO_IF(status, bundle_getMemoryPool(bundle, &pool));
- if (status == CELIX_SUCCESS) {
- if (sfilter != NULL) {
- filter = filter_create(sfilter);
- }
+ if (sfilter != NULL) {
+ filter = filter_create(sfilter);
}
status = CELIX_DO_IF(status, serviceRegistry_getServiceReferences(framework->registry, serviceName, filter, references));
@@ -1326,24 +1319,13 @@ celix_status_t framework_ungetService(fr
}
void fw_addServiceListener(framework_pt framework, bundle_pt bundle, service_listener_pt listener, char * sfilter) {
-// apr_pool_t *pool;
-// apr_pool_t *bpool;
-// bundle_context_pt context;
-// bundle_getContext(bundle, &context);
-// bundleContext_getMemoryPool(context, &bpool);
-// apr_pool_create(&pool, bpool);
array_list_pt listenerHooks = NULL;
- apr_pool_t *subpool;
listener_hook_info_pt info;
unsigned int i;
fw_service_listener_pt fwListener = (fw_service_listener_pt) malloc(sizeof(*fwListener));
- apr_pool_t *pool = NULL;
-
bundle_context_pt context = NULL;
- bundle_getMemoryPool(bundle, &pool);
-
fwListener->bundle = bundle;
if (sfilter != NULL) {
filter_pt filter = filter_create(sfilter);
@@ -1354,16 +1336,15 @@ void fw_addServiceListener(framework_pt
fwListener->listener = listener;
arrayList_add(framework->serviceListeners, fwListener);
- apr_pool_create(&subpool, listener->pool);
serviceRegistry_getListenerHooks(framework->registry, &listenerHooks);
- info = (listener_hook_info_pt) apr_palloc(subpool, sizeof(*info));
+ info = (listener_hook_info_pt) malloc(sizeof(*info));
bundle_getContext(bundle, &context);
info->context = context;
info->removed = false;
- info->filter = sfilter == NULL ? NULL : apr_pstrdup(subpool, sfilter);
+ info->filter = sfilter == NULL ? NULL : strdup(sfilter);
for (i = 0; i < arrayList_size(listenerHooks); i++) {
service_reference_pt ref = (service_reference_pt) arrayList_get(listenerHooks, i);
@@ -1379,26 +1360,25 @@ void fw_addServiceListener(framework_pt
serviceRegistry_ungetService(framework->registry, framework->bundle, ref, &ungetResult);
}
+ free(info);
+
arrayList_destroy(listenerHooks);
- apr_pool_destroy(subpool);
}
void fw_removeServiceListener(framework_pt framework, bundle_pt bundle, service_listener_pt listener) {
listener_hook_info_pt info = NULL;
- apr_pool_t *pool;
unsigned int i;
fw_service_listener_pt element;
bundle_context_pt context;
bundle_getContext(bundle, &context);
- bundleContext_getMemoryPool(context, &pool);
for (i = 0; i < arrayList_size(framework->serviceListeners); i++) {
element = (fw_service_listener_pt) arrayList_get(framework->serviceListeners, i);
if (element->listener == listener && element->bundle == bundle) {
bundle_context_pt lContext = NULL;
- info = (listener_hook_info_pt) apr_palloc(pool, sizeof(*info));
+ info = (listener_hook_info_pt) malloc(sizeof(*info));
bundle_getContext(element->bundle, &context);
info->context = lContext;
@@ -1444,12 +1424,9 @@ void fw_removeServiceListener(framework_
celix_status_t fw_addBundleListener(framework_pt framework, bundle_pt bundle, bundle_listener_pt listener) {
celix_status_t status = CELIX_SUCCESS;
-
- apr_pool_t *pool = NULL;
fw_bundle_listener_pt bundleListener = NULL;
- apr_pool_create(&pool, framework->mp);
- bundleListener = (fw_bundle_listener_pt) apr_palloc(pool, sizeof(*bundleListener));
+ bundleListener = (fw_bundle_listener_pt) malloc(sizeof(*bundleListener));
if (!bundleListener) {
status = CELIX_ENOMEM;
} else {
@@ -1474,6 +1451,10 @@ celix_status_t fw_removeBundleListener(f
bundleListener = (fw_bundle_listener_pt) arrayList_get(framework->bundleListeners, i);
if (bundleListener->listener == listener && bundleListener->bundle == bundle) {
arrayList_remove(framework->bundleListeners, i);
+
+ bundleListener->bundle = NULL;
+ bundleListener->listener = NULL;
+ free(bundleListener);
}
}
@@ -1484,12 +1465,9 @@ celix_status_t fw_removeBundleListener(f
celix_status_t fw_addFrameworkListener(framework_pt framework, bundle_pt bundle, framework_listener_pt listener) {
celix_status_t status = CELIX_SUCCESS;
-
- apr_pool_t *pool = NULL;
fw_framework_listener_pt frameworkListener = NULL;
- apr_pool_create(&pool, framework->mp);
- frameworkListener = (fw_framework_listener_pt) apr_palloc(pool, sizeof(*frameworkListener));
+ frameworkListener = (fw_framework_listener_pt) malloc(sizeof(*frameworkListener));
if (!frameworkListener) {
status = CELIX_ENOMEM;
} else {
@@ -1514,6 +1492,10 @@ celix_status_t fw_removeFrameworkListene
frameworkListener = (fw_framework_listener_pt) arrayList_get(framework->frameworkListeners, i);
if (frameworkListener->listener == listener && frameworkListener->bundle == bundle) {
arrayList_remove(framework->frameworkListeners, i);
+
+ frameworkListener->bundle = NULL;
+ frameworkListener->listener = NULL;
+ free(frameworkListener);
}
}
@@ -1540,10 +1522,8 @@ void fw_serviceChanged(framework_pt fram
if (matched) {
service_reference_pt reference = NULL;
service_event_pt event;
- apr_pool_t *spool = NULL;
- apr_pool_create(&spool, element->listener->pool);
- event = (service_event_pt) apr_palloc(spool, sizeof(*event));
+ event = (service_event_pt) malloc(sizeof(*event));
serviceRegistry_createServiceReference(framework->registry, registration, &reference);
@@ -2292,15 +2272,15 @@ static celix_status_t framework_loadLibr
celix_status_t status = CELIX_SUCCESS;
char *last;
- char *token = apr_strtok(libraries, ",", &last);
+ char *token = strtok_r(libraries, ",", &last);
while (token != NULL) {
void *handle = NULL;
char lib[strlen(token)];
char *path;
- char *pathToken = apr_strtok(token, ";", &path);
+ char *pathToken = strtok_r(token, ";", &path);
strcpy(lib, pathToken);
- pathToken = apr_strtok(NULL, ";", &path);
+ pathToken = strtok_r(NULL, ";", &path);
while (pathToken != NULL) {
if (strncmp(pathToken, "version", 7) == 0) {
@@ -2312,7 +2292,7 @@ static celix_status_t framework_loadLibr
strcat(lib, "-");
strcat(lib, version);
}
- pathToken = apr_strtok(NULL, ";", &path);
+ pathToken = strtok_r(NULL, ";", &path);
}
status = framework_loadLibrary(framework, lib, archive, &handle);
@@ -2325,7 +2305,7 @@ static celix_status_t framework_loadLibr
}
}
- token = apr_strtok(NULL, ",", &last);
+ token = strtok_r(NULL, ",", &last);
}
framework_logIfError(framework->logger, status, NULL, "Could not load all libraries");
Modified: incubator/celix/trunk/framework/private/src/manifest.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/manifest.c?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/manifest.c (original)
+++ incubator/celix/trunk/framework/private/src/manifest.c Fri Jun 6 09:43:47 2014
@@ -34,17 +34,14 @@
int fpeek(FILE *stream);
celix_status_t manifest_readAttributes(manifest_pt manifest, properties_pt properties, FILE *file);
-apr_status_t manifest_destroy(void *manifestP);
-celix_status_t manifest_create(apr_pool_t *pool, manifest_pt *manifest) {
+celix_status_t manifest_create(manifest_pt *manifest) {
celix_status_t status = CELIX_SUCCESS;
- *manifest = apr_palloc(pool, sizeof(**manifest));
+ *manifest = malloc(sizeof(**manifest));
if (!*manifest) {
status = CELIX_ENOMEM;
} else {
- apr_pool_pre_cleanup_register(pool, *manifest, manifest_destroy);
- (*manifest)->pool = pool;
(*manifest)->mainAttributes = properties_create();
(*manifest)->attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
}
@@ -54,8 +51,7 @@ celix_status_t manifest_create(apr_pool_
return status;
}
-apr_status_t manifest_destroy(void *manifestP) {
- manifest_pt manifest = manifestP;
+celix_status_t manifest_destroy(manifest_pt manifest) {
if (manifest != NULL) {
properties_destroy(manifest->mainAttributes);
hashMap_destroy(manifest->attributes, false, false);
@@ -66,10 +62,10 @@ apr_status_t manifest_destroy(void *mani
return APR_SUCCESS;
}
-celix_status_t manifest_createFromFile(apr_pool_t *pool, char *filename, manifest_pt *manifest) {
+celix_status_t manifest_createFromFile(char *filename, manifest_pt *manifest) {
celix_status_t status = CELIX_SUCCESS;
- status = manifest_create(pool, manifest);
+ status = manifest_create(manifest);
if (status == CELIX_SUCCESS) {
manifest_read(*manifest, filename);
}
@@ -99,14 +95,12 @@ celix_status_t manifest_read(manifest_pt
if (file != NULL) {
char lbuf[512];
int len;
- char * name = NULL;
+ char name[512];
bool skipEmptyLines = true;
- char * lastline = NULL;
- apr_pool_t *subpool;
+ char lastline[512];
manifest_readAttributes(manifest, manifest->mainAttributes, file);
- apr_pool_create(&subpool, manifest->pool);
while (fgets(lbuf, sizeof(lbuf), file) != NULL ) {
properties_pt attributes;
@@ -123,14 +117,13 @@ celix_status_t manifest_read(manifest_pt
}
skipEmptyLines = false;
- if (name == NULL) {
+ if (strlen(name) == 0) {
if ((tolower(lbuf[0]) == 'n') && (tolower(lbuf[1]) == 'a') &&
(tolower(lbuf[2]) == 'm') && (tolower(lbuf[3]) == 'e') &&
(lbuf[4] == ':') && (lbuf[5] == ' ')) {
- name = (char *) apr_palloc(subpool, (len + 1) - 6);
name[0] = '\0';
- name = strncpy(name, lbuf+6, len - 6);
+ strncpy(name, lbuf+6, len - 6);
name[len - 6] = '\0';
} else {
printf("MANIFEST: Invalid manifest format\n");
@@ -139,15 +132,14 @@ celix_status_t manifest_read(manifest_pt
if (fpeek(file) == ' ') {
int newlen = len - 6;
- lastline = (char *) apr_palloc(subpool, newlen + 1);
lastline[0] = '\0';
- lastline = strncpy(lastline, lbuf+6, len - 6);
+ strncpy(lastline, lbuf+6, len - 6);
lastline[newlen] = '\0';
continue;
}
} else {
int newlen = strlen(lastline) + len;
- char * buf = (char *) apr_palloc(subpool, newlen);
+ char buf[512];
buf[0] = '\0';
strcpy(buf, lastline);
strncat(buf, lbuf+1, len - 1);
@@ -155,16 +147,13 @@ celix_status_t manifest_read(manifest_pt
if (fpeek(file) == ' ') {
// lastline = realloc(lastline, strlen(buf) + 1);
- lastline = (char *) apr_palloc(subpool, strlen(buf) + 1);
lastline[0] = '\0';
- lastline = strcpy(lastline, buf);
+ strcpy(lastline, buf);
continue;
}
- name = (char *) apr_palloc(subpool, strlen(buf) + 1);
name[0] = '\0';
- name = strcpy(name, buf);
+ strcpy(name, buf);
name[strlen(buf)] = '\0';
- lastline = NULL;
}
attributes = hashMap_get(manifest->attributes, name);
@@ -174,10 +163,8 @@ celix_status_t manifest_read(manifest_pt
}
manifest_readAttributes(manifest, attributes, file);
- name = NULL;
skipEmptyLines = true;
}
- apr_pool_destroy(subpool);
fclose(file);
} else {
status = CELIX_FILE_IO_EXCEPTION;
@@ -205,14 +192,12 @@ int fpeek(FILE *stream) {
}
celix_status_t manifest_readAttributes(manifest_pt manifest, properties_pt properties, FILE *file) {
- char *name = NULL;
- char *value = NULL;
- char *lastLine = NULL;
+ char name[512];
+ char value[512];
+ char lastLine[512];
char lbuf[512];
int len;
- apr_pool_t *subpool;
- apr_pool_create(&subpool, manifest->pool);
while (fgets(lbuf, sizeof(lbuf), file ) != NULL ) {
bool lineContinued = false;
@@ -231,7 +216,7 @@ celix_status_t manifest_readAttributes(m
if (lbuf[0] == ' ') {
int newlen = strlen(lastLine) + len;
- char * buf = (char *) apr_palloc(subpool, newlen);
+ char buf[512];
buf[0] = '\0';
// Line continued
@@ -246,15 +231,12 @@ celix_status_t manifest_readAttributes(m
if (fpeek(file) == ' ') {
// lastLine = realloc(lastLine, strlen(buf) + 1);
- lastLine = (char *) apr_palloc(subpool, strlen(buf) + 1);
lastLine[0] = '\0';
- lastLine = strcpy(lastLine, buf);
+ strcpy(lastLine, buf);
continue;
}
- value = (char *) apr_palloc(subpool, strlen(buf) + 1);
value[0] = '\0';
- value = strcpy(value, buf);
- lastLine = NULL;
+ strcpy(value, buf);
} else {
while (lbuf[i++] != ':') {
if (i >= len) {
@@ -266,29 +248,25 @@ celix_status_t manifest_readAttributes(m
printf("MANIFEST: Invalid header\n");
return CELIX_FILE_IO_EXCEPTION;
}
- name = (char *) apr_palloc(subpool, (i + 1) - 2);
name[0] = '\0';
- name = strncpy(name, lbuf, i - 2);
+ strncpy(name, lbuf, i - 2);
name[i - 2] = '\0';
if (fpeek(file) == ' ') {
int newlen = len - i;
- lastLine = (char *) apr_palloc(subpool, newlen + 1);
lastLine[0] = '\0';
- lastLine = strncpy(lastLine, lbuf+i, len -i);
+ strncpy(lastLine, lbuf+i, len -i);
lastLine[newlen] = '\0';
continue;
}
- value = (char *) apr_palloc(subpool, (len + 1) - i);
value[0] = '\0';
- value = strncpy(value, lbuf+i, len - i);
+ strncpy(value, lbuf+i, len - i);
value[len - i] = '\0';
}
- if ((properties_set(properties, name, value) != NULL) && (!lineContinued)) {
+ if ((properties_set(properties, strdup(name), strdup(value)) != NULL) && (!lineContinued)) {
printf("Duplicate entry: %s", name);
}
}
- apr_pool_destroy(subpool);
return CELIX_SUCCESS;
}
Modified: incubator/celix/trunk/framework/public/include/bundle_archive.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/bundle_archive.h?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/bundle_archive.h (original)
+++ incubator/celix/trunk/framework/public/include/bundle_archive.h Fri Jun 6 09:43:47 2014
@@ -27,8 +27,6 @@
#ifndef BUNDLE_ARCHIVE_H_
#define BUNDLE_ARCHIVE_H_
-#include <apr_general.h>
-
#include "bundle_revision.h"
#include "bundle_state.h"
#include "celix_errno.h"
@@ -38,9 +36,11 @@
typedef struct bundleArchive * bundle_archive_pt;
-celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRoot, long id, char * location, char *inputFile, apr_pool_t *mp, bundle_archive_pt *bundle_archive);
-celix_status_t bundleArchive_createSystemBundleArchive(apr_pool_t *mp, framework_logger_pt logger, bundle_archive_pt *bundle_archive);
-celix_status_t bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp, bundle_archive_pt *bundle_archive);
+celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRoot, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive);
+celix_status_t bundleArchive_createSystemBundleArchive(framework_logger_pt logger, bundle_archive_pt *bundle_archive);
+celix_status_t bundleArchive_recreate(char * archiveRoot, bundle_archive_pt *bundle_archive);
+
+celix_status_t bundleArchive_destroy(bundle_archive_pt archive);
FRAMEWORK_EXPORT celix_status_t bundleArchive_getId(bundle_archive_pt archive, long *id);
FRAMEWORK_EXPORT celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, char **location);
Modified: incubator/celix/trunk/framework/public/include/bundle_revision.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/bundle_revision.h?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/bundle_revision.h (original)
+++ incubator/celix/trunk/framework/public/include/bundle_revision.h Fri Jun 6 09:43:47 2014
@@ -63,7 +63,7 @@ typedef struct bundleRevision * bundle_r
* - CELIX_SUCCESS when no errors are encountered.
* - CELIX_ENOMEM If allocating memory for <code>bundle_revision</code> failed.
*/
-celix_status_t bundleRevision_create(apr_pool_t *pool, framework_logger_pt logger, char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision);
+celix_status_t bundleRevision_create(framework_logger_pt logger, char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision);
/**
* Retrieves the revision number of the given revision.
Modified: incubator/celix/trunk/framework/public/include/manifest.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/manifest.h?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/manifest.h (original)
+++ incubator/celix/trunk/framework/public/include/manifest.h Fri Jun 6 09:43:47 2014
@@ -34,15 +34,14 @@
#include "framework_exports.h"
struct manifest {
- apr_pool_t *pool;
properties_pt mainAttributes;
hash_map_pt attributes;
};
typedef struct manifest * manifest_pt;
-FRAMEWORK_EXPORT celix_status_t manifest_create(apr_pool_t *pool, manifest_pt *manifest);
-FRAMEWORK_EXPORT celix_status_t manifest_createFromFile(apr_pool_t *pool, char *filename, manifest_pt *manifest);
+FRAMEWORK_EXPORT celix_status_t manifest_create(manifest_pt *manifest);
+FRAMEWORK_EXPORT celix_status_t manifest_createFromFile(char *filename, manifest_pt *manifest);
FRAMEWORK_EXPORT void manifest_clear(manifest_pt manifest);
FRAMEWORK_EXPORT properties_pt manifest_getMainAttributes(manifest_pt manifest);
Modified: incubator/celix/trunk/utils/private/src/celix_threads.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/private/src/celix_threads.c?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/utils/private/src/celix_threads.c (original)
+++ incubator/celix/trunk/utils/private/src/celix_threads.c Fri Jun 6 09:43:47 2014
@@ -80,10 +80,10 @@ celix_status_t celixThreadMutexAttr_sett
celix_status_t status = CELIX_SUCCESS;
switch(type) {
case CELIX_THREAD_MUTEX_NORMAL :
- status =pthread_mutexattr_settype(attr, PTHREAD_MUTEX_NORMAL);
+ status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_NORMAL);
break;
case CELIX_THREAD_MUTEX_RECURSIVE :
- status= pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
+ status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
break;
case CELIX_THREAD_MUTEX_ERRORCHECK :
status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_ERRORCHECK);
@@ -93,7 +93,9 @@ celix_status_t celixThreadMutexAttr_sett
break;
default:
status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_DEFAULT);
- }
+ break;
+ }
+ return status;
}
celix_status_t celixThreadCondition_init(celix_thread_cond_t *condition, celix_thread_condattr_t *attr) {
Modified: incubator/celix/trunk/utils/public/include/celix_threads.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/utils/public/include/celix_threads.h?rev=1600834&r1=1600833&r2=1600834&view=diff
==============================================================================
--- incubator/celix/trunk/utils/public/include/celix_threads.h (original)
+++ incubator/celix/trunk/utils/public/include/celix_threads.h Fri Jun 6 09:43:47 2014
@@ -64,7 +64,6 @@ celix_status_t celixThreadMutexAttr_crea
celix_status_t celixThreadMutexAttr_destroy(celix_thread_mutexattr_t *attr);
celix_status_t celixThreadMutexAttr_settype(celix_thread_mutexattr_t *attr, int type);
-
typedef pthread_cond_t celix_thread_cond_t;
typedef pthread_condattr_t celix_thread_condattr_t;