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 2011/05/27 10:38:33 UTC

svn commit: r1128195 - in /incubator/celix/trunk: framework/private/include/ framework/private/src/ shell/

Author: abroekhuis
Date: Fri May 27 08:38:32 2011
New Revision: 1128195

URL: http://svn.apache.org/viewvc?rev=1128195&view=rev
Log:
Applied patch from CELIX-3 with update for installing a non existent bundle. Fixed several memory leaks and unneeded free calls.

Modified:
    incubator/celix/trunk/framework/private/include/archive.h
    incubator/celix/trunk/framework/private/include/bundle_archive.h
    incubator/celix/trunk/framework/private/include/bundle_revision.h
    incubator/celix/trunk/framework/private/include/framework.h
    incubator/celix/trunk/framework/private/include/manifest.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/private/src/miniunz.c
    incubator/celix/trunk/framework/private/src/module.c
    incubator/celix/trunk/shell/shell.c

Modified: incubator/celix/trunk/framework/private/include/archive.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/archive.h?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/archive.h (original)
+++ incubator/celix/trunk/framework/private/include/archive.h Fri May 27 08:38:32 2011
@@ -26,6 +26,8 @@
 #ifndef ARCHIVE_H_
 #define ARCHIVE_H_
 
-int extractBundle(char * bundleName, char * revisionRoot);
+#include "celix_errno.h"
+
+celix_status_t extractBundle(char * bundleName, char * revisionRoot);
 
 #endif /* ARCHIVE_H_ */

Modified: incubator/celix/trunk/framework/private/include/bundle_archive.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle_archive.h?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle_archive.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle_archive.h Fri May 27 08:38:32 2011
@@ -34,10 +34,10 @@
 
 typedef struct bundleArchive * BUNDLE_ARCHIVE;
 
-BUNDLE_ARCHIVE bundleArchive_create(char * archiveRoot, long id, char * location, apr_pool_t *mp);
+celix_status_t bundleArchive_create(char * archiveRoot, long id, char * location, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive);
 celix_status_t bundleArchive_destroy(BUNDLE_ARCHIVE archive);
 BUNDLE_ARCHIVE bundleArchive_createSystemBundleArchive(apr_pool_t *mp);
-BUNDLE_ARCHIVE bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp);
+celix_status_t bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive);
 long bundleArchive_getId(BUNDLE_ARCHIVE archive);
 char * bundleArchive_getLocation(BUNDLE_ARCHIVE archive);
 char * bundleArchive_getArchiveRoot(BUNDLE_ARCHIVE archive);

Modified: incubator/celix/trunk/framework/private/include/bundle_revision.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle_revision.h?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle_revision.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle_revision.h Fri May 27 08:38:32 2011
@@ -9,10 +9,13 @@
 #define BUNDLE_REVISION_H_
 
 #include <stdio.h>
+#include <apr_pools.h>
+
+#include "celix_errno.h"
 
 typedef struct bundleRevision * BUNDLE_REVISION;
 
-BUNDLE_REVISION bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile);
+celix_status_t bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile, apr_pool_t *pool, BUNDLE_REVISION *bundle_revision);
 void bundleRevision_destroy(BUNDLE_REVISION revision);
 long bundleRevision_getNumber(BUNDLE_REVISION revision);
 char * bundleRevision_getLocation(BUNDLE_REVISION revision);

Modified: incubator/celix/trunk/framework/private/include/framework.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/framework.h?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/framework.h (original)
+++ incubator/celix/trunk/framework/private/include/framework.h Fri May 27 08:38:32 2011
@@ -59,7 +59,7 @@ void fw_serviceChanged(SERVICE_EVENT eve
 
 //BUNDLE_ARCHIVE fw_createArchive(long id, char * location);
 //void revise(BUNDLE_ARCHIVE archive, char * location);
-MANIFEST getManifest(BUNDLE_ARCHIVE archive);
+celix_status_t getManifest(BUNDLE_ARCHIVE archive, MANIFEST *manifest);
 
 BUNDLE findBundle(BUNDLE_CONTEXT context);
 SERVICE_REGISTRATION findRegistration(SERVICE_REFERENCE reference);

Modified: incubator/celix/trunk/framework/private/include/manifest.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/manifest.h?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/manifest.h (original)
+++ incubator/celix/trunk/framework/private/include/manifest.h Fri May 27 08:38:32 2011
@@ -27,6 +27,7 @@
 #define MANIFEST_H_
 
 #include "properties.h"
+#include "celix_errno.h"
 
 struct manifest {
 	PROPERTIES mainAttributes;
@@ -37,7 +38,7 @@ typedef struct manifest * MANIFEST;
 void manifest_clear(MANIFEST manifest);
 PROPERTIES manifest_getMainAttributes(MANIFEST manifest);
 
-MANIFEST manifest_read(char * filename);
+celix_status_t manifest_read(char *filename, MANIFEST *manifest);
 void manifest_write(MANIFEST manifest, char * filename);
 
 char * manifest_getValue(MANIFEST manifest, const char * name);

Modified: incubator/celix/trunk/framework/private/src/bundle.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle.c?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle.c Fri May 27 08:38:32 2011
@@ -67,7 +67,9 @@ celix_status_t bundle_create(BUNDLE * bu
 }
 
 celix_status_t bundle_createFromArchive(BUNDLE * bundle, FRAMEWORK framework, BUNDLE_ARCHIVE archive, apr_pool_t *bundlePool) {
-	*bundle = (BUNDLE) malloc(sizeof(**bundle));
+    celix_status_t status = CELIX_SUCCESS;
+
+    *bundle = (BUNDLE) apr_pcalloc(bundlePool, sizeof(**bundle));
 	if (*bundle == NULL) {
 		return CELIX_ENOMEM;
 	}
@@ -80,16 +82,19 @@ celix_status_t bundle_createFromArchive(
 	(*bundle)->modules = arrayList_create();
 
 	MODULE module = bundle_createModule(*bundle);
-	bundle_addModule(*bundle, module);
-	// (*bundle)->module = module;
+	if (module != NULL) {
+        bundle_addModule(*bundle, module);
 
-	pthread_mutex_init(&(*bundle)->lock, NULL);
-	(*bundle)->lockCount = 0;
-	(*bundle)->lockThread = NULL;
+        pthread_mutex_init(&(*bundle)->lock, NULL);
+        (*bundle)->lockCount = 0;
+        (*bundle)->lockThread = NULL;
 
-	resolver_addModule(module);
+        resolver_addModule(module);
+	} else {
+	    status = CELIX_FILE_IO_EXCEPTION;
+	}
 
-	return CELIX_SUCCESS;
+	return status;
 }
 
 celix_status_t bundle_destroy(BUNDLE bundle) {
@@ -100,7 +105,6 @@ celix_status_t bundle_destroy(BUNDLE bun
 	}
 	arrayListIterator_destroy(iter);
 	arrayList_destroy(bundle->modules);
-	free(bundle);
 	return CELIX_SUCCESS;
 }
 
@@ -161,37 +165,42 @@ void bundle_setManifest(BUNDLE bundle, M
 }
 
 MODULE bundle_createModule(BUNDLE bundle) {
-	MANIFEST headerMap = getManifest(bundle->archive);
-	long bundleId = bundleArchive_getId(bundle->archive);
-	int revision = 0;
-	char moduleId[sizeof(bundleId) + sizeof(revision) + 2];
-	sprintf(moduleId, "%ld.%d", bundleId, revision);
-
-	MODULE module = module_create(headerMap, strdup(moduleId), bundle);
-
-
-	VERSION bundleVersion = module_getVersion(module);
-	char * symName = module_getSymbolicName(module);
-
-	ARRAY_LIST bundles = framework_getBundles(bundle->framework);
-	int i;
-	for (i = 0; i < arrayList_size(bundles); i++) {
-		BUNDLE check = (BUNDLE) arrayList_get(bundles, i);
-
-		long id = bundleArchive_getId(check->archive);
-		if (id != bundleArchive_getId(bundle->archive)) {
-			char * sym = module_getSymbolicName(bundle_getCurrentModule(check));
-			VERSION version = module_getVersion(bundle_getCurrentModule(check));
-			if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) &&
-					!version_compareTo(bundleVersion, version)) {
-				printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, version_toString(version));
-				return NULL;
-			}
-		}
+	MANIFEST headerMap = NULL;
+	if (getManifest(bundle->archive, &headerMap) == CELIX_SUCCESS) {
+        long bundleId = bundleArchive_getId(bundle->archive);
+        int revision = 0;
+        char moduleId[sizeof(bundleId) + sizeof(revision) + 2];
+        sprintf(moduleId, "%ld.%d", bundleId, revision);
+
+        MODULE module = module_create(headerMap, strdup(moduleId), bundle);
+
+        if (module != NULL) {
+            VERSION bundleVersion = module_getVersion(module);
+            char * symName = module_getSymbolicName(module);
+
+            ARRAY_LIST bundles = framework_getBundles(bundle->framework);
+            int i;
+            for (i = 0; i < arrayList_size(bundles); i++) {
+                BUNDLE check = (BUNDLE) arrayList_get(bundles, i);
+
+                long id = bundleArchive_getId(check->archive);
+                if (id != bundleArchive_getId(bundle->archive)) {
+                    char * sym = module_getSymbolicName(bundle_getCurrentModule(check));
+                    VERSION version = module_getVersion(bundle_getCurrentModule(check));
+                    if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) &&
+                            !version_compareTo(bundleVersion, version)) {
+                        printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, version_toString(version));
+                        return NULL;
+                    }
+                }
+            }
+            arrayList_destroy(bundles);
+        }
+
+        return module;
+	} else {
+	    return NULL;
 	}
-	arrayList_destroy(bundles);
-
-	return module;
 }
 
 void startBundle(BUNDLE bundle, int options) {

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=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Fri May 27 08:38:32 2011
@@ -62,36 +62,45 @@ BUNDLE_ARCHIVE bundleArchive_createSyste
 	return archive;
 }
 
-char * bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long revNr);
+celix_status_t bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long revNr, char **revision_location);
 void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location, long revNr);
 
 void bundleArchive_initialize(BUNDLE_ARCHIVE archive);
 
 void bundleArchive_deleteTree(char * directory, apr_pool_t *mp);
 
-BUNDLE_REVISION bundleArchive_createRevisionFromLocation(BUNDLE_ARCHIVE archive, char *location, char *inputFile, long revNr);
+celix_status_t bundleArchive_createRevisionFromLocation(BUNDLE_ARCHIVE archive, char *location, char *inputFile, long revNr, BUNDLE_REVISION *bundle_revision);
 void bundleArchive_reviseInternal(BUNDLE_ARCHIVE archive, bool isReload, long revNr, char * location, char *inputFile);
 
 time_t bundleArchive_readLastModified(BUNDLE_ARCHIVE archive);
 void bundleArchive_writeLastModified(BUNDLE_ARCHIVE archive);
 
-BUNDLE_ARCHIVE bundleArchive_create(char * archiveRoot, long id, char * location, apr_pool_t *mp) {
-	BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) malloc(sizeof(*archive));
-	archive->id = id;
-	archive->location = location;
-	archive->archiveRootDir = NULL;
-	archive->archiveRoot = archiveRoot;
-	archive->revisions = linkedList_create();
-	archive->refreshCount = -1;
-	time(&archive->lastModified);
+celix_status_t bundleArchive_create(char * archiveRoot, long id, char * location, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive) {
+	celix_status_t status = CELIX_SUCCESS;
 
-	archive->mp = mp;
+    BUNDLE_ARCHIVE archive = NULL;
+    archive = (BUNDLE_ARCHIVE) apr_pcalloc(mp, sizeof(*archive));
+    if (archive != NULL) {
+        archive->id = id;
+        archive->location = location;
+        archive->archiveRootDir = NULL;
+        archive->archiveRoot = archiveRoot;
+        archive->revisions = linkedList_create();
+        archive->refreshCount = -1;
+        time(&archive->lastModified);
+
+        archive->mp = mp;
+
+        bundleArchive_initialize(archive);
+
+        bundleArchive_revise(archive, location, NULL);
+
+        *bundle_archive = archive;
+    } else {
+        status = CELIX_ENOMEM;
+    }
 
-	bundleArchive_initialize(archive);
-
-	bundleArchive_revise(archive, location, NULL);
-
-	return archive;
+	return status;
 }
 
 celix_status_t bundleArchive_destroy(BUNDLE_ARCHIVE archive) {
@@ -112,37 +121,51 @@ celix_status_t bundleArchive_destroy(BUN
 		linkedList_destroy(archive->revisions);
 	}
 
-	free(archive);
 	archive = NULL;
 	return CELIX_SUCCESS;
 }
 
-BUNDLE_ARCHIVE bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp) {
-	BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) malloc(sizeof(*archive));
-	archive->archiveRoot = archiveRoot;
-	apr_dir_open(&archive->archiveRootDir, archiveRoot, mp);
-	archive->id = -1;
-	archive->persistentState = -1;
-	archive->location = NULL;
-	archive->revisions = linkedList_create();
-	archive->mp = mp;
-	archive->refreshCount = -1;
-	archive->lastModified = (time_t) NULL;
-
-	apr_dir_t *dir;
-	apr_status_t status = apr_dir_open(&dir, archiveRoot, mp);
-	apr_finfo_t dp;
-	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)) {
-			long idx;
-			sscanf(dp.name, "version%*d.%ld", &idx);
-		}
+celix_status_t bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive) {
+    celix_status_t status = CELIX_SUCCESS;
+	BUNDLE_ARCHIVE archive = NULL;
+	archive = (BUNDLE_ARCHIVE) apr_pcalloc(mp, sizeof(*archive));
+	if (archive != NULL) {
+        archive->archiveRoot = archiveRoot;
+        apr_dir_open(&archive->archiveRootDir, archiveRoot, mp);
+        archive->id = -1;
+        archive->persistentState = -1;
+        archive->location = NULL;
+        archive->revisions = linkedList_create();
+        archive->mp = mp;
+        archive->refreshCount = -1;
+        archive->lastModified = (time_t) NULL;
+
+        apr_dir_t *dir;
+        if (apr_dir_open(&dir, archiveRoot, mp) == APR_SUCCESS) {
+            apr_finfo_t dp;
+            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)) {
+                    long idx;
+                    sscanf(dp.name, "version%*d.%ld", &idx);
+                }
+            }
+
+            char *location;
+            status = bundleArchive_getRevisionLocation(archive, 0, &location);
+            if (status == CELIX_SUCCESS) {
+                bundleArchive_revise(archive, location, NULL);
+
+                *bundle_archive = archive;
+            }
+            free(location);
+        } else {
+            status = CELIX_FILE_IO_EXCEPTION;
+        }
+	} else {
+	    status = CELIX_ENOMEM;
 	}
 
-	char * location = bundleArchive_getRevisionLocation(archive, 0);
-	bundleArchive_revise(archive, location, NULL);
-
-	return archive;
+	return status;
 }
 
 long bundleArchive_getId(BUNDLE_ARCHIVE archive) {
@@ -346,43 +369,73 @@ void bundleArchive_revise(BUNDLE_ARCHIVE
 }
 
 void bundleArchive_reviseInternal(BUNDLE_ARCHIVE archive, bool isReload, long revNr, char * location, char *inputFile) {
-	if (inputFile != NULL) {
+    celix_status_t status;
+    BUNDLE_REVISION revision = NULL;
+
+    if (inputFile != NULL) {
 		location = "inputstream:";
 	}
 
-	BUNDLE_REVISION revision = bundleArchive_createRevisionFromLocation(archive, location, inputFile, revNr);
+	status = bundleArchive_createRevisionFromLocation(archive, location, inputFile, revNr, &revision);
 
-	if (!isReload) {
-		bundleArchive_setRevisionLocation(archive, location, revNr);
-	}
+	if (status == CELIX_SUCCESS) {
+        if (!isReload) {
+            bundleArchive_setRevisionLocation(archive, location, revNr);
+        }
 
-	linkedList_addElement(archive->revisions, revision);
+        linkedList_addElement(archive->revisions, revision);
+	}
 }
 
 bool bundleArchive_rollbackRevise(BUNDLE_ARCHIVE archive) {
 	return true;
 }
 
-BUNDLE_REVISION bundleArchive_createRevisionFromLocation(BUNDLE_ARCHIVE archive, char *location, char *inputFile, long revNr) {
-	char root[256];
+celix_status_t bundleArchive_createRevisionFromLocation(BUNDLE_ARCHIVE archive, char *location, char *inputFile, long revNr, BUNDLE_REVISION *bundle_revision) {
+    celix_status_t status = CELIX_SUCCESS;
+    char root[256];
 	sprintf(root, "%s/version%ld.%ld", archive->archiveRoot, bundleArchive_getRefreshCount(archive), revNr);
 
 	// TODO create revision using optional FILE *fp;
-	BUNDLE_REVISION revision = bundleRevision_create(root, location, revNr, inputFile);
-	return revision;
+	BUNDLE_REVISION revision = NULL;
+	apr_pool_t *pool = NULL;
+	if (apr_pool_create(&pool, archive->mp) == APR_SUCCESS) {
+	    status = bundleRevision_create(root, location, revNr, inputFile, pool, &revision);
+
+	    if (status != CELIX_SUCCESS) {
+	        apr_pool_destroy(pool);
+	    }
+	} else {
+	    status = CELIX_ENOMEM;
+	}
+
+	if (status == CELIX_SUCCESS) {
+	    *bundle_revision = revision;
+	}
+
+	return status;
 }
 
-char * bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long revNr) {
+celix_status_t bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long revNr, char **revision_location) {
+    celix_status_t status;
 	char revisionLocation[256];
 	sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, bundleArchive_getRefreshCount(archive), revNr);
 
 	apr_file_t * revisionLocationFile;
-	apr_file_open(&revisionLocationFile, revisionLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp);
-	char location[256];
-	apr_file_gets (location , sizeof(location) , revisionLocationFile);
-	apr_file_close(revisionLocationFile);
+	if (apr_file_open(&revisionLocationFile, revisionLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp) == APR_SUCCESS) {
+        char location[256];
+        apr_file_gets (location , sizeof(location) , revisionLocationFile);
+        apr_file_close(revisionLocationFile);
 
-	return strdup(location);
+        *revision_location = strdup(location);
+        status = CELIX_SUCCESS;
+	} else {
+	    // revision file not found
+	    printf("Failed to open revision file at: %s\n", revisionLocation);
+	    status = CELIX_FILE_IO_EXCEPTION;
+	}
+
+	return status;
 }
 
 void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location, long revNr) {

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=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_cache.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_cache.c Fri May 27 08:38:32 2011
@@ -123,8 +123,11 @@ celix_status_t bundleCache_getArchives(B
                     && (strncmp(dp.name, "bundle", 6) == 0)
                     && (strcmp(dp.name, "bundle0") != 0)) {
 
-                BUNDLE_ARCHIVE archive = bundleArchive_recreate(strdup(archiveRoot), cache->mp);
-                arrayList_add(list, archive);
+                BUNDLE_ARCHIVE archive = NULL;
+                status = bundleArchive_recreate(strdup(archiveRoot), cache->mp, &archive);
+                if (status == CELIX_SUCCESS) {
+                    arrayList_add(list, archive);
+                }
             }
         }
 
@@ -149,9 +152,7 @@ celix_status_t bundleCache_createArchive
 	if (cache && location && bundlePool) {
         sprintf(archiveRoot, "%s/bundle%ld",  cache->cacheDir, id);
 
-        *bundle_archive = bundleArchive_create(strdup(archiveRoot), id, location, bundlePool);
-
-        status = CELIX_SUCCESS;
+        status = bundleArchive_create(strdup(archiveRoot), id, location, bundlePool, bundle_archive);
 	}
 
 	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=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_revision.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_revision.c Fri May 27 08:38:32 2011
@@ -15,29 +15,40 @@ struct bundleRevision {
 	char *location;
 };
 
-BUNDLE_REVISION bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile) {
-	BUNDLE_REVISION revision = malloc(sizeof(*revision));
+celix_status_t bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile, apr_pool_t *pool, BUNDLE_REVISION *bundle_revision) {
+    celix_status_t status = CELIX_SUCCESS;
+	BUNDLE_REVISION revision = NULL;
+
+	revision = (BUNDLE_REVISION) apr_pcalloc(pool, sizeof(*revision));
+    if (revision != NULL) {
+        mkdir(root, 0755);
+
+        if (inputFile != NULL) {
+            status = extractBundle(inputFile, root);
+        } else {
+            status = extractBundle(location, root);
+        }
+
+        if (status == CELIX_SUCCESS) {
+            revision->revisionNr = revisionNr;
+            revision->root = strdup(root);
+            revision->location = strdup(location);
+            *bundle_revision = revision;
+        }
+    }
 
-	mkdir(root, 0755);
-
-	if (inputFile != NULL) {
-		int e = extractBundle(inputFile, root);
-	} else {
-		int e = extractBundle(location, root);
-	}
-
-	revision->revisionNr = revisionNr;
-	revision->root = strdup(root);
-	revision->location = location;
-
-	return revision;
+	return status;
 }
 
 void bundleRevision_destroy(BUNDLE_REVISION revision) {
-	free(revision);
+    free(revision->root);
+    free(revision->location);
 }
 
 long bundleRevision_getNumber(BUNDLE_REVISION revision) {
+    if (revision == NULL) {
+        return -1L;
+    }
 	return revision->revisionNr;
 }
 

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Fri May 27 08:38:32 2011
@@ -128,6 +128,7 @@ celix_status_t framework_create(FRAMEWOR
 	(*framework)->globalLockCount = 0;
 	(*framework)->globalLockThread = NULL;
 	(*framework)->nextBundleId = 1l;
+	(*framework)->cache = NULL;
 
 	m_installRequestMap = hashMap_create(string_hash, string_hash, string_equals, string_equals);
 
@@ -137,8 +138,9 @@ celix_status_t framework_create(FRAMEWOR
 celix_status_t framework_destroy(FRAMEWORK framework) {
 	HASH_MAP_ITERATOR iterator = hashMapIterator_create(framework->installedBundleMap);
 	while (hashMapIterator_hasNext(iterator)) {
-		BUNDLE bundle = hashMapIterator_nextValue(iterator);
-		char * location = hashMapIterator_nextKey(iterator);
+	    HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iterator);
+		BUNDLE bundle = hashMapEntry_getValue(entry);
+		char * location = hashMapEntry_getKey(entry);
 
 		// for each installed bundle, clean up memory
 		LINKED_LIST wires = module_getWires(bundle_getCurrentModule(bundle));
@@ -325,6 +327,7 @@ celix_status_t fw_installBundle2(FRAMEWO
 		id = framework_getNextBundleId(framework);
 		status = bundleCache_createArchive(framework->cache, id, location, bundlePool, &bundle_archive);
 		if (status != CELIX_SUCCESS) {
+		    framework_releaseInstallLock(framework, location);
 		    return status;
 		} else {
 		    archive = bundle_archive;
@@ -337,19 +340,22 @@ celix_status_t fw_installBundle2(FRAMEWO
 	bool locked = framework_acquireGlobalLock(framework);
 	if (!locked) {
 		printf("Unable to acquire the global lock to install the bundle\n");
-		apr_pool_destroy(bundlePool);
-		framework_releaseInstallLock(framework, location);
-		return CELIX_BUNDLE_EXCEPTION;
+		status = CELIX_BUNDLE_EXCEPTION;
+	} else {
+	    status = bundle_createFromArchive(bundle, framework, archive, bundlePool);
 	}
 
-	celix_status_t rv = bundle_createFromArchive(bundle, framework, archive, bundlePool);
-	framework_releaseGlobalLock(framework);
-
-	hashMap_put(framework->installedBundleMap, location, *bundle);
-
-  	framework_releaseInstallLock(framework, location);
+    framework_releaseGlobalLock(framework);
+	if (status == CELIX_SUCCESS) {
+        hashMap_put(framework->installedBundleMap, location, *bundle);
+	} else {
+	    printf("Unable to install bundle\n");
+	    bundleArchive_closeAndDelete(bundle_archive);
+	    apr_pool_destroy(bundlePool);
+	}
+    framework_releaseInstallLock(framework, location);
 
-  	return CELIX_SUCCESS;
+  	return status;
 }
 
 celix_status_t framework_getBundleEntry(FRAMEWORK framework, BUNDLE bundle, char *name, char **entry) {
@@ -413,7 +419,7 @@ celix_status_t fw_startBundle(FRAMEWORK 
                 }
                 framework_markResolvedModules(framework, wires);
 		    }
-			//hashMap_destroy(wires, false, false);
+			hashMap_destroy(wires, false, false);
 			// no break
 		case BUNDLE_RESOLVED:
 			if (bundleContext_create(framework, bundle, &context) != CELIX_SUCCESS) {
@@ -421,9 +427,12 @@ celix_status_t fw_startBundle(FRAMEWORK 
 			}
 			bundle_setContext(bundle, context);
 
-			MANIFEST manifest = getManifest(bundle_getArchive(bundle));
-			bundle_setManifest(bundle, manifest);
-			char * library = manifest_getValue(manifest, HEADER_LIBRARY);
+			MANIFEST manifest = NULL;
+			char *library;
+			if (getManifest(bundle_getArchive(bundle), &manifest) == CELIX_SUCCESS) {
+                bundle_setManifest(bundle, manifest);
+                library = manifest_getValue(manifest, HEADER_LIBRARY);
+			}
 
 	#ifdef __linux__
 			 char * library_prefix = "lib";
@@ -579,7 +588,7 @@ void fw_stopBundle(FRAMEWORK framework, 
 		activator->destroy(activator->userData, bundle_getContext(bundle));
 	}
 
-	if (module_getId(bundle_getCurrentModule(bundle)) != 0) {
+	if (strcmp(module_getId(bundle_getCurrentModule(bundle)), "0") != 0) {
 		activator->start = NULL;
 		activator->stop = NULL;
 		activator->userData = NULL;
@@ -923,23 +932,14 @@ void fw_serviceChanged(SERVICE_EVENT eve
 	}
 }
 
-MANIFEST getManifest(BUNDLE_ARCHIVE archive) {
-	char manifest[256];
-	sprintf(manifest, "%s/version%ld.%ld/MANIFEST/MANIFEST.MF",
+celix_status_t getManifest(BUNDLE_ARCHIVE archive, MANIFEST *manifest) {
+	char mf[256];
+	sprintf(mf, "%s/version%ld.%ld/MANIFEST/MANIFEST.MF",
 			bundleArchive_getArchiveRoot(archive),
 			bundleArchive_getRefreshCount(archive),
 			bundleArchive_getCurrentRevisionNumber(archive)
 			);
-
-//	char * root = bundleArchive_getArchiveRoot(archive);
-//	char manifest[256];
-//	strcpy(manifest, root);
-//	strcat(manifest, "/version");
-//	strcat(manifest, bundleArchive_getRefreshCount(archive));
-//	strcat(manifest, ".");
-//	strcat(manifest, bundleArchive_getCurrentRevisionNumber(archive));
-//	strcat(manifest, "/MANIFEST/MANIFEST.MF");
-	return manifest_read(manifest);
+	return manifest_read(mf, manifest);
 }
 
 long framework_getNextBundleId(FRAMEWORK framework) {
@@ -1197,6 +1197,7 @@ static void * framework_shutdown(void * 
 	while (hashMapIterator_hasNext(iterator)) {
 		BUNDLE bundle = hashMapIterator_nextValue(iterator);
 		if (bundle_getState(bundle) == BUNDLE_ACTIVE || bundle_getState(bundle) == BUNDLE_STARTING) {
+		    printf("stop bundle: %s\n", bundleArchive_getLocation(bundle_getArchive(bundle)));
 			fw_stopBundle(fw, bundle, 0);
 		}
 	}

Modified: incubator/celix/trunk/framework/private/src/manifest.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/manifest.c?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/manifest.c (original)
+++ incubator/celix/trunk/framework/private/src/manifest.c Fri May 27 08:38:32 2011
@@ -39,91 +39,99 @@ PROPERTIES manifest_getMainAttributes(MA
 	return manifest->mainAttributes;
 }
 
-MANIFEST manifest_read(char * filename) {
-	MANIFEST mf = (MANIFEST) malloc(sizeof(*mf));
-	PROPERTIES mainAttributes = properties_create();
-
-	mf->mainAttributes = mainAttributes;
-
-	FILE *file = fopen ( filename, "r" );
-	if (file != NULL) {
-		char lbuf [ 512 ];
-		char * lastline;
-		char * name = NULL;
-		char * value = NULL;
-
-		while ( fgets ( lbuf, sizeof lbuf, file ) != NULL ) {
-			bool lineContinued = false;
-			int len = strlen(lbuf);
-
-			if (lbuf[--len] != '\n') {
-				return NULL;
-			}
-
-			if (len > 0 && lbuf[len-1] == '\r') {
-				--len;
-			}
-
-			if (len == 0) {
-				break;
-		    }
-
-			int i = 0;
-			if (lbuf[0] == ' ') {
-				// continuation of previous line
-				if (name == NULL) {
-					return NULL;
-				}
-				lineContinued = true;
-				int newlen = strlen(lastline) + len - 1;
-				char buf [newlen];
-				strcpy(buf, lastline);
-				strncat(buf, lbuf+1, len - 1);
-
-				if (fpeek(file) == ' ') {
-					lastline = strcpy(lastline, buf);
-					continue;
-				}
-				value = (char *) malloc(strlen(buf) + 1);
-				value = strcpy(value, buf);
-				value[strlen(buf)] = '\0';
-				lastline = NULL;
-			} else {
-				while (lbuf[i++] != ':') {
-					if (i >= len) {
-//						throw new IOException("invalid header field");
-						return NULL;
-					}
-				}
-				if (lbuf[i++] != ' ') {
-//					throw new IOException("invalid header field");
-					return NULL;
-				}
-				name = (char *) malloc((i + 1) - 2);
-				name = strncpy(name, lbuf, i - 2);
-				name[i - 2] = '\0';
-				if (fpeek(file) == ' ') {
-					int newlen = len - i;
-					lastline = (char *) malloc(newlen + 1);
-					lastline = strncpy(lastline, lbuf+i, len -i);
-					continue;
-				}
-				value = (char *) malloc((len + 1) - i);
-				value = strncpy(value, lbuf+i, len - i);
-				value[len - i] = '\0';
-			}
-
-			if ((properties_set(mainAttributes, name, value) != NULL) && (!lineContinued)) {
-				printf("Duplicate entry: %s", name);
-			}
-			free(name);
-			free(value);
-		}
-		fclose(file);
-		return mf;
+celix_status_t manifest_read(char *filename, MANIFEST *manifest) {
+    celix_status_t status = CELIX_SUCCESS;
+	MANIFEST mf = NULL;
+
+	mf = (MANIFEST) malloc(sizeof(*mf));
+	if (mf != NULL) {
+		PROPERTIES mainAttributes = properties_create();
+
+        mf->mainAttributes = mainAttributes;
+
+        FILE *file = fopen ( filename, "r" );
+        if (file != NULL) {
+            char lbuf [ 512 ];
+            char * lastline;
+            char * name = NULL;
+            char * value = NULL;
+
+            while ( fgets ( lbuf, sizeof lbuf, file ) != NULL ) {
+                bool lineContinued = false;
+                int len = strlen(lbuf);
+
+                if (lbuf[--len] != '\n') {
+                    return CELIX_INVALID_SYNTAX;
+                }
+
+                if (len > 0 && lbuf[len-1] == '\r') {
+                    --len;
+                }
+
+                if (len == 0) {
+                    break;
+                }
+
+                int i = 0;
+                if (lbuf[0] == ' ') {
+                    // continuation of previous line
+                    if (name == NULL) {
+                        return CELIX_INVALID_SYNTAX;
+                    }
+                    lineContinued = true;
+                    int newlen = strlen(lastline) + len - 1;
+                    char buf [newlen];
+                    strcpy(buf, lastline);
+                    strncat(buf, lbuf+1, len - 1);
+
+                    if (fpeek(file) == ' ') {
+                        lastline = strcpy(lastline, buf);
+                        continue;
+                    }
+                    value = (char *) malloc(strlen(buf) + 1);
+                    value = strcpy(value, buf);
+                    value[strlen(buf)] = '\0';
+                    lastline = NULL;
+                } else {
+                    while (lbuf[i++] != ':') {
+                        if (i >= len) {
+    //						throw new IOException("invalid header field");
+                            return CELIX_INVALID_SYNTAX;
+                        }
+                    }
+                    if (lbuf[i++] != ' ') {
+    //					throw new IOException("invalid header field");
+                        return CELIX_INVALID_SYNTAX;
+                    }
+                    name = (char *) malloc((i + 1) - 2);
+                    name = strncpy(name, lbuf, i - 2);
+                    name[i - 2] = '\0';
+                    if (fpeek(file) == ' ') {
+                        int newlen = len - i;
+                        lastline = (char *) malloc(newlen + 1);
+                        lastline = strncpy(lastline, lbuf+i, len -i);
+                        continue;
+                    }
+                    value = (char *) malloc((len + 1) - i);
+                    value = strncpy(value, lbuf+i, len - i);
+                    value[len - i] = '\0';
+                }
+
+                if ((properties_set(mainAttributes, name, value) != NULL) && (!lineContinued)) {
+                    printf("Duplicate entry: %s", name);
+                }
+                free(name);
+                free(value);
+            }
+            fclose(file);
+
+            *manifest = mf;
+        }
+	} else {
+	    status = CELIX_ENOMEM;
 	}
 
-	return NULL;
+	return status;
 }
 
 void manifest_destroy(MANIFEST manifest) {

Modified: incubator/celix/trunk/framework/private/src/miniunz.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/miniunz.c?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/miniunz.c (original)
+++ incubator/celix/trunk/framework/private/src/miniunz.c Fri May 27 08:38:32 2011
@@ -326,9 +326,9 @@ int do_extract(unzFile uf, char * revisi
     return 0;
 }
 
-int extractBundle(char * bundleName, char * revisionRoot) {
+celix_status_t extractBundle(char * bundleName, char * revisionRoot) {
+    celix_status_t status = CELIX_SUCCESS;
     char filename_try[MAXFILENAME+16] = "";
-    int ret_value=0;
     unzFile uf=NULL;
 
     if (bundleName!=NULL)
@@ -362,11 +362,14 @@ int extractBundle(char * bundleName, cha
     if (uf==NULL)
     {
         printf("Cannot open %s or %s.zip\n",bundleName,bundleName);
-        return 1;
-    }
-    ret_value = do_extract(uf, revisionRoot);
+        status = CELIX_FILE_IO_EXCEPTION;
+    } else {
+        if (do_extract(uf, revisionRoot) != 0) {
+            status = CELIX_FILE_IO_EXCEPTION;
+        }
 
-    unzClose(uf);
+        unzClose(uf);
+    }
 
-    return ret_value;
+    return status;
 }

Modified: incubator/celix/trunk/framework/private/src/module.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/module.c?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/module.c (original)
+++ incubator/celix/trunk/framework/private/src/module.c Fri May 27 08:38:32 2011
@@ -50,24 +50,28 @@ struct module {
 };
 
 MODULE module_create(MANIFEST headerMap, char * moduleId, BUNDLE bundle) {
-	MODULE module = (MODULE) malloc(sizeof(*module));
-	module->headerMap = headerMap;
-	module->id = moduleId;
-	module->bundle = bundle;
-	module->resolved = false;
-
-	module->dependentImporters = arrayList_create();
-
-	MANIFEST_PARSER mp = manifestParser_createManifestParser(module, headerMap);
-	module->symbolicName = mp->bundleSymbolicName;
-	module->version = mp->bundleVersion;
-	module->capabilities = mp->capabilities;
-	module->requirements = mp->requirements;
-	manifestParser_destroy(mp);
-
-	module->wires = NULL;
-
-	return module;
+    if (headerMap != NULL) {
+        MODULE module = (MODULE) malloc(sizeof(*module));
+        module->headerMap = headerMap;
+        module->id = moduleId;
+        module->bundle = bundle;
+        module->resolved = false;
+
+        module->dependentImporters = arrayList_create();
+
+        MANIFEST_PARSER mp = manifestParser_createManifestParser(module, headerMap);
+        module->symbolicName = strdup(mp->bundleSymbolicName);
+        module->version = mp->bundleVersion;
+        module->capabilities = mp->capabilities;
+        module->requirements = mp->requirements;
+        manifestParser_destroy(mp);
+
+        module->wires = NULL;
+
+        return module;
+    } else {
+        return NULL;
+    }
 }
 
 MODULE module_createFrameworkModule() {
@@ -77,6 +81,7 @@ MODULE module_createFrameworkModule() {
 	module->version = version_createVersion(1, 0, 0, "");
 	module->capabilities = linkedList_create();
 	module->requirements = linkedList_create();
+	module->dependentImporters = arrayList_create();
 	module->wires = NULL;
 	module->headerMap = NULL;
 	module->resolved = false;
@@ -102,6 +107,8 @@ void module_destroy(MODULE module) {
 	linkedList_destroy(module->capabilities);
 	linkedList_destroy(module->requirements);
 
+	arrayList_destroy(module->dependentImporters);
+
 	version_destroy(module->version);
 
 	if (module->headerMap != NULL) {
@@ -109,6 +116,7 @@ void module_destroy(MODULE module) {
 	}
 	module->headerMap = NULL;
 
+	free(module->symbolicName);
 	free(module->id);
 	free(module);
 }

Modified: incubator/celix/trunk/shell/shell.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/shell.c?rev=1128195&r1=1128194&r2=1128195&view=diff
==============================================================================
--- incubator/celix/trunk/shell/shell.c (original)
+++ incubator/celix/trunk/shell/shell.c Fri May 27 08:38:32 2011
@@ -233,6 +233,7 @@ celix_status_t bundleActivator_stop(void
         startCommand_destroy(activator->startCmd);
         stopCommand_destroy(activator->stopCmd);
         installCommand_destroy(activator->installCmd);
+        uninstallCommand_destroy(activator->uninstallCmd);
         updateCommand_destroy(activator->updateCmd);
 
         free(activator->shellService);