Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 891CF200D64 for ; Mon, 20 Nov 2017 21:33:04 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 87D8C160C1D; Mon, 20 Nov 2017 20:33:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 445A1160C0D for ; Mon, 20 Nov 2017 21:33:02 +0100 (CET) Received: (qmail 60737 invoked by uid 500); 20 Nov 2017 20:33:01 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 59565 invoked by uid 99); 20 Nov 2017 20:32:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Nov 2017 20:32:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C27E9F5F7A; Mon, 20 Nov 2017 20:32:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pnoltes@apache.org To: commits@celix.apache.org Date: Mon, 20 Nov 2017 20:33:22 -0000 Message-Id: <02cc16864bdb4e199a97cf0346c0e129@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [25/46] celix git commit: CELIX-417: Initial refactoring for CMake usage archived-at: Mon, 20 Nov 2017 20:33:04 -0000 http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/include/service_registration_private.h ---------------------------------------------------------------------- diff --git a/framework/private/include/service_registration_private.h b/framework/private/include/service_registration_private.h deleted file mode 100644 index ca0cb67..0000000 --- a/framework/private/include/service_registration_private.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -/* - * service_registration_private.h - * - * \date Feb 11, 2013 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - - -#ifndef SERVICE_REGISTRATION_PRIVATE_H_ -#define SERVICE_REGISTRATION_PRIVATE_H_ - -#include "registry_callback_private.h" -#include "service_registration.h" - -struct serviceRegistration { - registry_callback_t callback; - - char * className; - bundle_pt bundle; - properties_pt properties; - const void * svcObj; - unsigned long serviceId; - - bool isUnregistering; - - bool isServiceFactory; - const void *serviceFactory; - - struct service *services; - int nrOfServices; - - size_t refCount; //protected by mutex - - celix_thread_rwlock_t lock; -}; - -service_registration_pt serviceRegistration_create(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId, const void * serviceObject, properties_pt dictionary); -service_registration_pt serviceRegistration_createServiceFactory(registry_callback_t callback, bundle_pt bundle, const char* serviceName, unsigned long serviceId, const void * serviceObject, properties_pt dictionary); - -void serviceRegistration_retain(service_registration_pt registration); -void serviceRegistration_release(service_registration_pt registration); - -bool serviceRegistration_isValid(service_registration_pt registration); -void serviceRegistration_invalidate(service_registration_pt registration); - -celix_status_t serviceRegistration_getService(service_registration_pt registration, bundle_pt bundle, const void **service); -celix_status_t serviceRegistration_ungetService(service_registration_pt registration, bundle_pt bundle, const void **service); - -celix_status_t serviceRegistration_getBundle(service_registration_pt registration, bundle_pt *bundle); -celix_status_t serviceRegistration_getServiceName(service_registration_pt registration, const char **serviceName); - -#endif /* SERVICE_REGISTRATION_PRIVATE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/include/service_registry_private.h ---------------------------------------------------------------------- diff --git a/framework/private/include/service_registry_private.h b/framework/private/include/service_registry_private.h deleted file mode 100644 index d68fe11..0000000 --- a/framework/private/include/service_registry_private.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -/* - * service_registry_private.h - * - * \date Feb 7, 2013 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - - -#ifndef SERVICE_REGISTRY_PRIVATE_H_ -#define SERVICE_REGISTRY_PRIVATE_H_ - -#include "registry_callback_private.h" -#include "service_registry.h" - -struct serviceRegistry { - framework_pt framework; - registry_callback_t callback; - - hash_map_pt serviceRegistrations; //key = bundle (reg owner), value = list ( registration ) - hash_map_pt serviceReferences; //key = bundle, value = map (key = serviceId, value = reference) - - bool checkDeletedReferences; //If enabled. check if provided service references are still valid - hash_map_pt deletedServiceReferences; //key = ref pointer, value = bool - - serviceChanged_function_pt serviceChanged; - unsigned long currentServiceId; - - array_list_pt listenerHooks; - - celix_thread_rwlock_t lock; -}; - -typedef enum reference_status_enum { - REF_ACTIVE, - REF_DELETED, - REF_UNKNOWN -} reference_status_t; - -struct usageCount { - unsigned int count; - service_reference_pt reference; - void * service; - service_registration_pt registration; -}; - -typedef struct usageCount * usage_count_pt; - -#endif /* SERVICE_REGISTRY_PRIVATE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/include/service_tracker_customizer_private.h ---------------------------------------------------------------------- diff --git a/framework/private/include/service_tracker_customizer_private.h b/framework/private/include/service_tracker_customizer_private.h deleted file mode 100644 index 61fb52f..0000000 --- a/framework/private/include/service_tracker_customizer_private.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -/* - * service_tracker_customizer_private.h - * - * \date Feb 7, 2013 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - - -#ifndef SERVICE_TRACKER_CUSTOMIZER_PRIVATE_H_ -#define SERVICE_TRACKER_CUSTOMIZER_PRIVATE_H_ - -#include "service_reference.h" - -#include "service_tracker_customizer.h" - - -struct serviceTrackerCustomizer { - void * handle; - celix_status_t (*addingService)(void * handle, service_reference_pt reference, void **service); - celix_status_t (*addedService)(void * handle, service_reference_pt reference, void * service); - celix_status_t (*modifiedService)(void * handle, service_reference_pt reference, void * service); - - /*TODO rename to removingService. because it is invoke during remove not after!*/ - celix_status_t (*removedService)(void * handle, service_reference_pt reference, void * service); - - /*TODO add removed function ? invoked after the remove ?? */ -}; - - -#endif /* SERVICE_TRACKER_CUSTOMIZER_PRIVATE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/include/service_tracker_private.h ---------------------------------------------------------------------- diff --git a/framework/private/include/service_tracker_private.h b/framework/private/include/service_tracker_private.h deleted file mode 100644 index 1d80ba1..0000000 --- a/framework/private/include/service_tracker_private.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -/* - * service_tracker_private.h - * - * \date Feb 6, 2013 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - - -#ifndef SERVICE_TRACKER_PRIVATE_H_ -#define SERVICE_TRACKER_PRIVATE_H_ - -#include "service_tracker.h" - -struct serviceTracker { - bundle_context_pt context; - char * filter; - - service_tracker_pt tracker; - service_tracker_customizer_pt customizer; - service_listener_pt listener; - - celix_thread_rwlock_t lock; //projects trackedServices - array_list_pt trackedServices; -}; - -struct tracked { - service_reference_pt reference; - void * service; -}; - -typedef struct tracked * tracked_pt; - -#endif /* SERVICE_TRACKER_PRIVATE_H_ */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/include/unzip.h ---------------------------------------------------------------------- diff --git a/framework/private/include/unzip.h b/framework/private/include/unzip.h deleted file mode 100644 index 3183968..0000000 --- a/framework/private/include/unzip.h +++ /dev/null @@ -1,437 +0,0 @@ -/* unzip.h -- IO for uncompress .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - --------------------------------------------------------------------------------- - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - --------------------------------------------------------------------------------- - - Changes - - See header of unzip64.c - -*/ - -#ifndef _unz64_H -#define _unz64_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#ifdef HAVE_BZIP2 -#include "bzlib.h" -#endif - -#define Z_BZIP2ED 12 - -#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagunzFile__ { int unused; } unzFile__; -typedef unzFile__ *unzFile; -#else -typedef voidp unzFile; -#endif - - -#define UNZ_OK (0) -#define UNZ_END_OF_LIST_OF_FILE (-100) -#define UNZ_ERRNO (Z_ERRNO) -#define UNZ_EOF (0) -#define UNZ_PARAMERROR (-102) -#define UNZ_BADZIPFILE (-103) -#define UNZ_INTERNALERROR (-104) -#define UNZ_CRCERROR (-105) - -/* tm_unz contain date/time info */ -typedef struct tm_unz_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_unz; - -/* unz_global_info structure contain global data about the ZIPfile - These data comes from the end of central dir */ -typedef struct unz_global_info64_s -{ - ZPOS64_T number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info64; - -typedef struct unz_global_info_s -{ - uLong number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info; - -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_info64_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - ZPOS64_T compressed_size; /* compressed size 8 bytes */ - ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info64; - -typedef struct unz_file_info_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - uLong compressed_size; /* compressed size 4 bytes */ - uLong uncompressed_size; /* uncompressed size 4 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info; - -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) -*/ - - -extern unzFile ZEXPORT unzOpen OF((const char *path)); -extern unzFile ZEXPORT unzOpen64 OF((const void *path)); -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer - "zlib/zlib113.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. - the "64" function take a const void* pointer, because the path is just the - value passed to the open64_file_func callback. - Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path - is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* - does not describe the reality -*/ - - -extern unzFile ZEXPORT unzOpen2 OF((const char *path, - zlib_filefunc_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unzOpen, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, - zlib_filefunc64_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unz64Open, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -extern int ZEXPORT unzClose OF((unzFile file)); -/* - Close a ZipFile opened with unzipOpen. - If there is files inside the .Zip opened with unzOpenCurrentFile (see later), - these files MUST be closed with unzipCloseCurrentFile before call unzipClose. - return UNZ_OK if there is no problem. */ - -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); - -extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, - unz_global_info64 *pglobal_info)); -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ - - -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ - - -/***************************************************************************/ -/* Unzip package allow you browse the directory of the zipfile */ - -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ - -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ - - -/* ****************************************** */ -/* Ryan supplied functions */ -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_pos_s -{ - uLong pos_in_zip_directory; /* offset in zip file directory */ - uLong num_of_file; /* # of file */ -} unz_file_pos; - -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos); - -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos); - -typedef struct unz64_file_pos_s -{ - ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ - ZPOS64_T num_of_file; /* # of file */ -} unz64_file_pos; - -extern int ZEXPORT unzGetFilePos64( - unzFile file, - unz64_file_pos* file_pos); - -extern int ZEXPORT unzGoToFilePos64( - unzFile file, - const unz64_file_pos* file_pos); - -/* ****************************************** */ - -extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); -/* - Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about - the current file - if szFileName!=NULL, the filemane string will be copied in szFileName - (fileNameBufferSize is the size of the buffer) - if extraField!=NULL, the extra field information will be copied in extraField - (extraFieldBufferSize is the size of the buffer). - This is the Central-header version of the extra field - if szComment!=NULL, the comment string of the file will be copied in szComment - (commentBufferSize is the size of the buffer) -*/ - - -/** Addition for GDAL : START */ - -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); - -/** Addition for GDAL : END */ - - -/***************************************************************************/ -/* for reading the content of the current zipfile, you can open it, read data - from it, and close it (you can close it before reading all the file) - */ - -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); -/* - Open for reading data the current file in the zipfile. - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, - const char* password)); -/* - Open for reading data the current file in the zipfile. - password is a crypting password - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, - int* method, - int* level, - int raw)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - -extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, - int* method, - int* level, - int raw, - const char* password)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - - -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ - -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read bytes from the current file (opened by unzOpenCurrentFile) - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ - -extern z_off_t ZEXPORT unztell OF((unzFile file)); - -extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); -/* - Give the current position in uncompressed data -*/ - -extern int ZEXPORT unzeof OF((unzFile file)); -/* - return 1 if the end of file was reached, 0 elsewhere -*/ - -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ - -/***************************************************************************/ - -/* Get the current file offset */ -extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); -extern uLong ZEXPORT unzGetOffset (unzFile file); - -/* Set the current file offset */ -extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); -extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); - - - -#ifdef __cplusplus -} -#endif - -#endif /* _unz64_H */ http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/attribute.c ---------------------------------------------------------------------- diff --git a/framework/private/src/attribute.c b/framework/private/src/attribute.c deleted file mode 100644 index 318d8f5..0000000 --- a/framework/private/src/attribute.c +++ /dev/null @@ -1,71 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -/* - * attribute.c - * - * \date Jul 27, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include - -#include "attribute_private.h" -#include "celix_log.h" - -celix_status_t attribute_create(char * key, char * value, attribute_pt *attribute) { - celix_status_t status = CELIX_SUCCESS; - char *error = NULL; - - if (key == NULL || value == NULL || *attribute != NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - error = "Missing required arguments and/or values"; - } else { - attribute_pt attr = malloc(sizeof(*attr)); - if (!attr) { - status = CELIX_ENOMEM; - } else { - attr->key = key; - attr->value = value; - - *attribute = attr; - } - } - - framework_logIfError(logger, status, error, "Could not create attribute: [key=%s;value=%s]", key, value); - - return status; -} - -celix_status_t attribute_destroy(attribute_pt attribute) { - free(attribute->key); - free(attribute->value); - free(attribute); - return CELIX_SUCCESS; -} - -celix_status_t attribute_getKey(attribute_pt attribute, char **key) { - *key = attribute->key; - return CELIX_SUCCESS; -} - -celix_status_t attribute_getValue(attribute_pt attribute, char **value) { - *value = attribute->value; - return CELIX_SUCCESS; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/bundle.c ---------------------------------------------------------------------- diff --git a/framework/private/src/bundle.c b/framework/private/src/bundle.c deleted file mode 100644 index a0e6b3d..0000000 --- a/framework/private/src/bundle.c +++ /dev/null @@ -1,695 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -/* - * bundle.c - * - * \date Mar 23, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include - -#include "framework_private.h" -#include "bundle_private.h" -#include "resolver.h" -#include "utils.h" - -celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module); -celix_status_t bundle_closeRevisions(bundle_pt bundle); - -celix_status_t bundle_create(bundle_pt * bundle) { - celix_status_t status; - bundle_archive_pt archive = NULL; - - *bundle = (bundle_pt) malloc(sizeof(**bundle)); - if (*bundle == NULL) { - return CELIX_ENOMEM; - } - status = bundleArchive_createSystemBundleArchive(&archive); - if (status == CELIX_SUCCESS) { - module_pt module; - - (*bundle)->archive = archive; - (*bundle)->activator = NULL; - (*bundle)->context = NULL; - (*bundle)->framework = NULL; - (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED; - (*bundle)->modules = NULL; - arrayList_create(&(*bundle)->modules); - (*bundle)->handle = NULL; - (*bundle)->manifest = NULL; - - module = module_createFrameworkModule((*bundle)); - bundle_addModule(*bundle, module); - - status = celixThreadMutex_create(&(*bundle)->lock, NULL); - if (status != CELIX_SUCCESS) { - status = CELIX_ILLEGAL_STATE; - } else { - (*bundle)->lockCount = 0; - (*bundle)->lockThread = celix_thread_default; - } - } - framework_logIfError(logger, status, NULL, "Failed to create bundle"); - - return status; -} - -celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt framework, bundle_archive_pt archive) { - module_pt module; - - celix_status_t status; - - *bundle = (bundle_pt) malloc(sizeof(**bundle)); - if (*bundle == NULL) { - return CELIX_ENOMEM; - } - (*bundle)->archive = archive; - (*bundle)->activator = NULL; - (*bundle)->context = NULL; - (*bundle)->handle = NULL; - (*bundle)->manifest = NULL; - (*bundle)->framework = framework; - (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED; - (*bundle)->modules = NULL; - arrayList_create(&(*bundle)->modules); - - status = bundle_createModule(*bundle, &module); - if (status == CELIX_SUCCESS) { - bundle_addModule(*bundle, module); - status = celixThreadMutex_create(&(*bundle)->lock, NULL); - if (status != CELIX_SUCCESS) { - status = CELIX_ILLEGAL_STATE; - } else { - (*bundle)->lockCount = 0; - (*bundle)->lockThread = celix_thread_default; - } - } else { - status = CELIX_FILE_IO_EXCEPTION; - } - - framework_logIfError(logger, status, NULL, "Failed to create bundle"); - - return status; -} - -celix_status_t bundle_destroy(bundle_pt bundle) { - array_list_iterator_pt iter = arrayListIterator_create(bundle->modules); - while (arrayListIterator_hasNext(iter)) { - module_pt module = arrayListIterator_next(iter); - module_destroy(module); - } - arrayListIterator_destroy(iter); - arrayList_destroy(bundle->modules); - celixThreadMutex_destroy(&bundle->lock); - - free(bundle); - - return CELIX_SUCCESS; -} - -celix_status_t bundle_getArchive(bundle_pt bundle, bundle_archive_pt *archive) { - celix_status_t status = CELIX_SUCCESS; - - if (bundle != NULL && *archive == NULL) { - *archive = bundle->archive; - } else { - status = CELIX_ILLEGAL_ARGUMENT; - } - - framework_logIfError(logger, status, NULL, "Failed to get bundle archive"); - - return status; -} - -celix_status_t bundle_getCurrentModule(bundle_pt bundle, module_pt *module) { - celix_status_t status = CELIX_SUCCESS; - - if (bundle == NULL || arrayList_size(bundle->modules)==0 ) { - status = CELIX_ILLEGAL_ARGUMENT; - } else { - *module = arrayList_get(bundle->modules, arrayList_size(bundle->modules) - 1); - } - - return status; -} - -array_list_pt bundle_getModules(bundle_pt bundle) { - return bundle->modules; -} - -void * bundle_getHandle(bundle_pt bundle) { - return bundle->handle; -} - -void bundle_setHandle(bundle_pt bundle, void * handle) { - bundle->handle = handle; -} - -activator_pt bundle_getActivator(bundle_pt bundle) { - return bundle->activator; -} - -celix_status_t bundle_setActivator(bundle_pt bundle, activator_pt activator) { - bundle->activator = activator; - return CELIX_SUCCESS; -} - -celix_status_t bundle_getContext(bundle_pt bundle, bundle_context_pt *context) { - *context = bundle->context; - return CELIX_SUCCESS; -} - -celix_status_t bundle_setContext(bundle_pt bundle, bundle_context_pt context) { - bundle->context = context; - return CELIX_SUCCESS; -} - -celix_status_t bundle_getEntry(bundle_pt bundle, const char* name, char** entry) { - return framework_getBundleEntry(bundle->framework, bundle, name, entry); -} - -celix_status_t bundle_getState(bundle_pt bundle, bundle_state_e *state) { - if(bundle==NULL){ - *state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN; - return CELIX_BUNDLE_EXCEPTION; - } - *state = bundle->state; - return CELIX_SUCCESS; -} - -celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) { - bundle->state = state; - return CELIX_SUCCESS; -} - -celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) { - celix_status_t status = CELIX_SUCCESS; - bundle_archive_pt archive = NULL; - bundle_revision_pt revision = NULL; - manifest_pt headerMap = NULL; - - status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive)); - status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); - status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &headerMap)); - if (status == CELIX_SUCCESS) { - long bundleId = 0; - status = bundleArchive_getId(bundle->archive, &bundleId); - if (status == CELIX_SUCCESS) { - int revision = 0; - char moduleId[512]; - - snprintf(moduleId, sizeof(moduleId), "%ld.%d", bundleId, revision); - *module = module_create(headerMap, moduleId, bundle); - - if (*module != NULL) { - version_pt bundleVersion = module_getVersion(*module); - const char * symName = NULL; - status = module_getSymbolicName(*module, &symName); - if (status == CELIX_SUCCESS) { - array_list_pt bundles = framework_getBundles(bundle->framework); - unsigned int i; - for (i = 0; i < arrayList_size(bundles); i++) { - bundle_pt check = (bundle_pt) arrayList_get(bundles, i); - - long id; - if (bundleArchive_getId(check->archive, &id) == CELIX_SUCCESS) { - if (id != bundleId) { - module_pt mod = NULL; - const char * sym = NULL; - version_pt version; - int cmp; - status = bundle_getCurrentModule(check, &mod); - status = module_getSymbolicName(mod, &sym); - - version = module_getVersion(mod); - version_compareTo(bundleVersion, version, &cmp); - if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) && - !cmp) { - char *versionString = NULL; - version_toString(version, &versionString); - printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, versionString); - free(versionString); - status = CELIX_BUNDLE_EXCEPTION; - break; - } - } - } - } - arrayList_destroy(bundles); - } - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to create module"); - - return status; -} - -celix_status_t bundle_start(bundle_pt bundle) { - return bundle_startWithOptions(bundle, 0); -} - -celix_status_t bundle_startWithOptions(bundle_pt bundle, int options) { - celix_status_t status = CELIX_SUCCESS; - if (bundle != NULL) { - bool systemBundle = false; - status = bundle_isSystemBundle(bundle, &systemBundle); - if (status == CELIX_SUCCESS) { - if (systemBundle) { - framework_start(bundle->framework); - } else { - status = fw_startBundle(bundle->framework, bundle, options); - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to start bundle"); - - return status; -} - -celix_status_t bundle_update(bundle_pt bundle, const char *inputFile) { - celix_status_t status = CELIX_SUCCESS; - if (bundle != NULL) { - bool systemBundle = false; - status = bundle_isSystemBundle(bundle, &systemBundle); - if (status == CELIX_SUCCESS) { - if (systemBundle) { - // #TODO: Support framework update - status = CELIX_BUNDLE_EXCEPTION; - } else { - status = framework_updateBundle(bundle->framework, bundle, inputFile); - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to update bundle"); - - return status; -} - -celix_status_t bundle_stop(bundle_pt bundle) { - return bundle_stopWithOptions(bundle, 0); -} - -celix_status_t bundle_stopWithOptions(bundle_pt bundle, int options) { - celix_status_t status = CELIX_SUCCESS; - if (bundle != NULL) { - bool systemBundle = false; - status = bundle_isSystemBundle(bundle, &systemBundle); - if (status == CELIX_SUCCESS) { - if (systemBundle) { - framework_stop(bundle->framework); - } else { - status = fw_stopBundle(bundle->framework, bundle, options); - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to stop bundle"); - - return status; -} - -celix_status_t bundle_uninstall(bundle_pt bundle) { - celix_status_t status = CELIX_SUCCESS; - if (bundle != NULL) { - bool systemBundle = false; - status = bundle_isSystemBundle(bundle, &systemBundle); - if (status == CELIX_SUCCESS) { - if (systemBundle) { - status = CELIX_BUNDLE_EXCEPTION; - } else { - status = fw_uninstallBundle(bundle->framework, bundle); - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to uninstall bundle"); - - return status; -} - -celix_status_t bundle_setPersistentStateInactive(bundle_pt bundle) { - celix_status_t status; - bool systemBundle; - - status = bundle_isSystemBundle(bundle, &systemBundle); - if (status == CELIX_SUCCESS) { - if (!systemBundle) { - status = bundleArchive_setPersistentState(bundle->archive, OSGI_FRAMEWORK_BUNDLE_INSTALLED); - } - } - - framework_logIfError(logger, status, NULL, "Failed to set persistent state to inactive"); - - return status; -} - -celix_status_t bundle_setPersistentStateUninstalled(bundle_pt bundle) { - celix_status_t status; - bool systemBundle; - - status = bundle_isSystemBundle(bundle, &systemBundle); - if (status == CELIX_SUCCESS) { - if (!systemBundle) { - status = bundleArchive_setPersistentState(bundle->archive, OSGI_FRAMEWORK_BUNDLE_UNINSTALLED); - } - } - - framework_logIfError(logger, status, NULL, "Failed to set persistent state to uninstalled"); - - return status; -} - -celix_status_t bundle_revise(bundle_pt bundle, const char * location, const char *inputFile) { - celix_status_t status; - - bundle_archive_pt archive = NULL; - status = bundle_getArchive(bundle, &archive); - if (status == CELIX_SUCCESS) { - status = bundleArchive_revise(archive, location, inputFile); - if (status == CELIX_SUCCESS) { - module_pt module; - status = bundle_createModule(bundle, &module); - if (status == CELIX_SUCCESS) { - status = bundle_addModule(bundle, module); - } else { - bool rolledback; - status = bundleArchive_rollbackRevise(archive, &rolledback); - if (status == CELIX_SUCCESS) { - status = CELIX_BUNDLE_EXCEPTION; - } - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to revise bundle"); - - return status; -} - -//bool bundle_rollbackRevise(bundle_pt bundle) { -// module_pt module = arrayList_remove(bundle->modules, arrayList_set(bundle->modules) - 1); -// return resolver_removeModule(module); -//} - -celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) { - arrayList_add(bundle->modules, module); - resolver_addModule(module); - return CELIX_SUCCESS; -} - -celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool *systemBundle) { - celix_status_t status; - long bundleId; - bundle_archive_pt archive = NULL; - - status = bundle_getArchive(bundle, &archive); - if (status == CELIX_SUCCESS) { - status = bundleArchive_getId(archive, &bundleId); - if (status == CELIX_SUCCESS) { - *systemBundle = (bundleId == 0); - } - } - - framework_logIfError(logger, status, NULL, "Failed to check if bundle is the systembundle"); - - return status; -} - -celix_status_t bundle_isLockable(bundle_pt bundle, bool *lockable) { - celix_status_t status; - - status = celixThreadMutex_lock(&bundle->lock); - if (status != CELIX_SUCCESS) { - status = CELIX_BUNDLE_EXCEPTION; - } else { - bool equals; - status = thread_equalsSelf(bundle->lockThread, &equals); - if (status == CELIX_SUCCESS) { - *lockable = (bundle->lockCount == 0) || (equals); - } - - status = celixThreadMutex_unlock(&bundle->lock); - if (status != CELIX_SUCCESS) { - status = CELIX_BUNDLE_EXCEPTION; - } - } - - framework_logIfError(logger, status, NULL, "Failed to check if bundle is lockable"); - - return status; -} - -celix_status_t bundle_getLockingThread(bundle_pt bundle, celix_thread_t *thread) { - celix_status_t status; - - status = celixThreadMutex_lock(&bundle->lock); - if (status != CELIX_SUCCESS) { - status = CELIX_BUNDLE_EXCEPTION; - } else { - *thread = bundle->lockThread; - - status = celixThreadMutex_unlock(&bundle->lock); - if (status != CELIX_SUCCESS) { - status = CELIX_BUNDLE_EXCEPTION; - } - } - - framework_logIfError(logger, status, NULL, "Failed to get locking thread"); - - return status; -} - -celix_status_t bundle_lock(bundle_pt bundle, bool *locked) { - celix_status_t status; - bool equals; - - celixThreadMutex_lock(&bundle->lock); - - status = thread_equalsSelf(bundle->lockThread, &equals); - if (status == CELIX_SUCCESS) { - if ((bundle->lockCount > 0) && !equals) { - *locked = false; - } else { - bundle->lockCount++; - bundle->lockThread = celixThread_self(); - *locked = true; - } - } - - celixThreadMutex_unlock(&bundle->lock); - - framework_logIfError(logger, status, NULL, "Failed to lock bundle"); - - return status; -} - -celix_status_t bundle_unlock(bundle_pt bundle, bool *unlocked) { - celix_status_t status = CELIX_SUCCESS; - - bool equals; - - celixThreadMutex_lock(&bundle->lock); - - if (bundle->lockCount == 0) { - *unlocked = false; - } else { - status = thread_equalsSelf(bundle->lockThread, &equals); - if (status == CELIX_SUCCESS) { - if ((bundle->lockCount > 0) && !equals) { - *unlocked = false; - } - else{ - bundle->lockCount--; - if (bundle->lockCount == 0) { - bundle->lockThread = celix_thread_default; - } - *unlocked = true; - } - } - } - - celixThreadMutex_unlock(&bundle->lock); - - framework_logIfError(logger, status, NULL, "Failed to unlock bundle"); - - return status; -} - -celix_status_t bundle_close(bundle_pt bundle) { - bundle_archive_pt archive = NULL; - - celix_status_t status; - - bundle_closeModules(bundle); - bundle_closeRevisions(bundle); - status = bundle_getArchive(bundle, &archive); - if (status == CELIX_SUCCESS) { - bundleArchive_close(archive); - } - - framework_logIfError(logger, status, NULL, "Failed to close bundle"); - - return status; -} - -celix_status_t bundle_closeAndDelete(bundle_pt bundle) { - celix_status_t status; - - bundle_archive_pt archive = NULL; - - bundle_closeModules(bundle); - bundle_closeRevisions(bundle); - status = bundle_getArchive(bundle, &archive); - if (status == CELIX_SUCCESS) { - bundleArchive_closeAndDelete(archive); - } - - framework_logIfError(logger, status, NULL, "Failed to close and delete bundle"); - - return status; -} - -celix_status_t bundle_closeRevisions(bundle_pt bundle) { - celix_status_t status = CELIX_SUCCESS; - - // TODO implement this - return status; -} - -celix_status_t bundle_closeModules(bundle_pt bundle) { - celix_status_t status = CELIX_SUCCESS; - - unsigned int i = 0; - for (i = 0; i < arrayList_size(bundle->modules); i++) { - module_pt module = (module_pt) arrayList_get(bundle->modules, i); - resolver_removeModule(module); - module_setWires(module, NULL); - } - - return status; -} - -celix_status_t bundle_refresh(bundle_pt bundle) { - celix_status_t status; - module_pt module; - - status = bundle_closeModules(bundle); - if (status == CELIX_SUCCESS) { - arrayList_clear(bundle->modules); - status = bundle_createModule(bundle, &module); - if (status == CELIX_SUCCESS) { - status = bundle_addModule(bundle, module); - if (status == CELIX_SUCCESS) { - bundle->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED; - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to refresh bundle"); - - return status; -} - -celix_status_t bundle_getBundleId(bundle_pt bundle, long *id) { - celix_status_t status; - bundle_archive_pt archive = NULL; - status = bundle_getArchive(bundle, &archive); - if (status == CELIX_SUCCESS) { - status = bundleArchive_getId(archive, id); - } - - framework_logIfError(logger, status, NULL, "Failed to get bundle id"); - - return status; -} - -celix_status_t bundle_getRegisteredServices(bundle_pt bundle, array_list_pt *list) { - celix_status_t status; - - status = fw_getBundleRegisteredServices(bundle->framework, bundle, list); - - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get registered services"); - - return status; -} - -celix_status_t bundle_getServicesInUse(bundle_pt bundle, array_list_pt *list) { - celix_status_t status; - - status = fw_getBundleServicesInUse(bundle->framework, bundle, list); - - framework_logIfError(logger, status, NULL, "Failed to get in use services"); - - return status; -} - -celix_status_t bundle_setFramework(bundle_pt bundle, framework_pt framework) { - celix_status_t status = CELIX_SUCCESS; - - if (bundle != NULL && framework != NULL) { - bundle->framework = framework; - } else { - status = CELIX_ILLEGAL_ARGUMENT; - } - - framework_logIfError(logger, status, NULL, "Failed to set framework"); - - return status; -} - -celix_status_t bundle_getFramework(bundle_pt bundle, framework_pt *framework) { - celix_status_t status = CELIX_SUCCESS; - - if (bundle != NULL && *framework == NULL) { - *framework = bundle->framework; - } else { - status = CELIX_ILLEGAL_ARGUMENT; - } - - framework_logIfError(logger, status, NULL, "Failed to get framework"); - - return status; -} - -celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char **location){ - - celix_status_t status; - - bundle_archive_pt archive = NULL; - - status = bundle_getArchive(bundle, &archive); - if (status != CELIX_SUCCESS){ - printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchive) \n"); - return status; - } - - status = bundleArchive_getLocation(archive, location); - if (status != CELIX_SUCCESS){ - printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchiveLocation) \n"); - return status; - } - - return CELIX_SUCCESS; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/bundle_archive.c ---------------------------------------------------------------------- diff --git a/framework/private/src/bundle_archive.c b/framework/private/src/bundle_archive.c deleted file mode 100644 index cde727e..0000000 --- a/framework/private/src/bundle_archive.c +++ /dev/null @@ -1,792 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -/* - * bundle_archive.c - * - * \date Aug 8, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bundle_archive.h" -#include "linked_list_iterator.h" - -struct bundleArchive { - long id; - char * location; - DIR *archiveRootDir; - char * archiveRoot; - linked_list_pt revisions; - long refreshCount; - time_t lastModified; - - bundle_state_e persistentState; -}; - -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, const char * location, long revNr); - -static celix_status_t bundleArchive_initialize(bundle_archive_pt archive); - -static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, const char * directory); - -static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt archive, const char *location, const char *inputFile, long revNr, bundle_revision_pt *bundle_revision); -static celix_status_t bundleArchive_reviseInternal(bundle_archive_pt archive, bool isReload, long revNr, const char * location, const char *inputFile); - -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(bundle_archive_pt *bundle_archive) { - celix_status_t status = CELIX_SUCCESS; - char *error = NULL; - bundle_archive_pt archive = NULL; - - if (*bundle_archive != NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - error = "Missing required arguments and/or incorrect values"; - } else { - archive = (bundle_archive_pt) calloc(1,sizeof(*archive)); - if (archive == NULL) { - status = CELIX_ENOMEM; - } else { - status = linkedList_create(&archive->revisions); - if (status == CELIX_SUCCESS) { - archive->id = 0l; - archive->location = strdup("System Bundle"); - archive->archiveRoot = NULL; - archive->archiveRootDir = NULL; - archive->refreshCount = -1; - archive->persistentState = OSGI_FRAMEWORK_BUNDLE_UNKNOWN; - time(&archive->lastModified); - - *bundle_archive = archive; - } - } - } - - if(status != CELIX_SUCCESS && archive != NULL){ - bundleArchive_destroy(archive); - } - - framework_logIfError(logger, status, error, "Could not create archive"); - - return status; -} - -celix_status_t bundleArchive_create(const char *archiveRoot, long id, const char * location, const char *inputFile, bundle_archive_pt *bundle_archive) { - celix_status_t status = CELIX_SUCCESS; - char *error = NULL; - bundle_archive_pt archive = NULL; - - if (*bundle_archive != NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - error = "bundle_archive_pt must be NULL"; - } else { - archive = (bundle_archive_pt) calloc(1,sizeof(*archive)); - if (archive == NULL) { - status = CELIX_ENOMEM; - } else { - status = linkedList_create(&archive->revisions); - if (status == CELIX_SUCCESS) { - archive->id = id; - archive->location = strdup(location); - archive->archiveRootDir = NULL; - archive->archiveRoot = strdup(archiveRoot); - archive->refreshCount = -1; - time(&archive->lastModified); - - status = bundleArchive_initialize(archive); - if (status == CELIX_SUCCESS) { - status = bundleArchive_revise(archive, location, inputFile); - - if (status == CELIX_SUCCESS) { - *bundle_archive = archive; - } - else{ - bundleArchive_closeAndDelete(archive); - } - } - } - } - } - - if(status != CELIX_SUCCESS && archive != NULL){ - bundleArchive_destroy(archive); - } - - framework_logIfError(logger, status, error, "Could not create archive"); - - return status; -} - -celix_status_t bundleArchive_destroy(bundle_archive_pt archive) { - celix_status_t status = CELIX_SUCCESS; - - if(archive != NULL){ - if (archive->revisions != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(archive->revisions, 0); - while(linkedListIterator_hasNext(iter)) { - bundle_revision_pt rev = linkedListIterator_next(iter); - bundleRevision_destroy(rev); - } - linkedListIterator_destroy(iter); - linkedList_destroy(archive->revisions); - } - if (archive->archiveRoot != NULL) { - free(archive->archiveRoot); - } - if (archive->location != NULL) { - free(archive->location); - } - - free(archive); - archive = NULL; - } - - framework_logIfError(logger, status, NULL, "Could not create archive"); - - return status; -} - -celix_status_t bundleArchive_recreate(const char * archiveRoot, bundle_archive_pt *bundle_archive) { - celix_status_t status = CELIX_SUCCESS; - - bundle_archive_pt archive = NULL; - - archive = (bundle_archive_pt) calloc(1,sizeof(*archive)); - if (archive == NULL) { - status = CELIX_ENOMEM; - } else { - status = linkedList_create(&archive->revisions); - if (status == CELIX_SUCCESS) { - archive->archiveRoot = strdup(archiveRoot); - archive->archiveRootDir = NULL; - archive->id = -1; - archive->persistentState = -1; - archive->location = NULL; - archive->refreshCount = -1; - archive->lastModified = (time_t) NULL; - - archive->archiveRootDir = opendir(archiveRoot); - if (archive->archiveRootDir == NULL) { - status = CELIX_FRAMEWORK_EXCEPTION; - } else { - - long idx = 0; - long highestId = -1; - char *location = NULL; - - struct dirent *dent = NULL; - struct stat st; - - errno = 0; - dent = readdir(archive->archiveRootDir); - while (errno == 0 && dent != NULL) { - char subdir[512]; - snprintf(subdir, 512, "%s/%s", archiveRoot, dent->d_name); - int rv = stat(subdir, &st); - if (rv == 0 && S_ISDIR(st.st_mode) && (strncmp(dent->d_name, "version", 7) == 0)) { - sscanf(dent->d_name, "version%*d.%ld", &idx); - if (idx > highestId) { - highestId = idx; - } - } - errno = 0; - dent = readdir(archive->archiveRootDir); - } - - status = CELIX_DO_IF(status, bundleArchive_getRevisionLocation(archive, 0, &location)); - status = CELIX_DO_IF(status, bundleArchive_reviseInternal(archive, true, highestId, location, NULL)); - if (location) { - free(location); - } - if (status == CELIX_SUCCESS) { - *bundle_archive = archive; - } - closedir(archive->archiveRootDir); - } - } - } - - if(status != CELIX_SUCCESS && archive != NULL){ - bundleArchive_destroy(archive); - } - - framework_logIfError(logger, status, NULL, "Could not create archive"); - - return status; -} - -celix_status_t bundleArchive_getId(bundle_archive_pt archive, long *id) { - celix_status_t status = CELIX_SUCCESS; - - if (archive->id < 0) { - FILE *bundleIdFile; - char id[256]; - char bundleId[512]; - snprintf(bundleId, sizeof(bundleId), "%s/bundle.id", archive->archiveRoot); - - bundleIdFile = fopen(bundleId, "r"); - if(bundleIdFile!=NULL){ - fgets(id, sizeof(id), bundleIdFile); - fclose(bundleIdFile); - sscanf(id, "%ld", &archive->id); - } - else{ - status = CELIX_FILE_IO_EXCEPTION; - } - } - - if (status == CELIX_SUCCESS) { - *id = archive->id; - } - - framework_logIfError(logger, status, NULL, "Could not get archive id"); - - return status; -} - -celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, const char **location) { - celix_status_t status = CELIX_SUCCESS; - if (archive->location == NULL) { - FILE *bundleLocationFile; - char bundleLocation[512]; - char loc[256]; - - snprintf(bundleLocation, sizeof(bundleLocation), "%s/bundle.location", archive->archiveRoot); - - bundleLocationFile = fopen(bundleLocation, "r"); - if(bundleLocationFile!=NULL){ - fgets(loc, sizeof(loc), bundleLocationFile); - fclose(bundleLocationFile); - archive->location = strdup(loc); - } - else{ - status = CELIX_FILE_IO_EXCEPTION; - } - } - - if (status == CELIX_SUCCESS) { - *location = archive->location; - } - - framework_logIfError(logger, status, NULL, "Could not get archive location"); - - return status; -} - -celix_status_t bundleArchive_getArchiveRoot(bundle_archive_pt archive, const char **archiveRoot) { - *archiveRoot = archive->archiveRoot; - return CELIX_SUCCESS; -} - -celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, long *revisionNumber) { - celix_status_t status = CELIX_SUCCESS; - bundle_revision_pt revision; - *revisionNumber = -1; - - status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); - status = CELIX_DO_IF(status, bundleRevision_getNumber(revision, revisionNumber)); - - framework_logIfError(logger, status, NULL, "Could not get current revision number"); - - return status; -} - -celix_status_t bundleArchive_getCurrentRevision(bundle_archive_pt archive, bundle_revision_pt *revision) { - *revision = linkedList_isEmpty(archive->revisions) ? NULL : linkedList_getLast(archive->revisions); - return CELIX_SUCCESS; -} - -celix_status_t bundleArchive_getRevision(bundle_archive_pt archive, long revNr, bundle_revision_pt *revision) { - *revision = linkedList_get(archive->revisions, revNr); - return CELIX_SUCCESS; -} - -celix_status_t bundleArchive_getPersistentState(bundle_archive_pt archive, bundle_state_e *state) { - celix_status_t status = CELIX_SUCCESS; - - if (archive->persistentState != OSGI_FRAMEWORK_BUNDLE_UNKNOWN) { - *state = archive->persistentState; - } else { - 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); - } - - if (status == CELIX_SUCCESS) { - if (strncmp(stateString, "active", 256) == 0) { - archive->persistentState = OSGI_FRAMEWORK_BUNDLE_ACTIVE; - } else if (strncmp(stateString, "starting", 256) == 0) { - archive->persistentState = OSGI_FRAMEWORK_BUNDLE_STARTING; - } else if (strncmp(stateString, "uninstalled", 256) == 0) { - archive->persistentState = OSGI_FRAMEWORK_BUNDLE_UNINSTALLED; - } else { - archive->persistentState = OSGI_FRAMEWORK_BUNDLE_INSTALLED; - } - - *state = archive->persistentState; - } - } - - 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[512]; - FILE *persistentStateLocationFile; - - snprintf(persistentStateLocation, sizeof(persistentStateLocation), "%s/bundle.state", archive->archiveRoot); - - 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(logger, status, NULL, "Could not set persistent state"); - - return status; -} - -celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount) { - celix_status_t status = CELIX_SUCCESS; - - if (archive->refreshCount == -1) { - 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; - } - fclose(refreshCounterFile); - if (status == CELIX_SUCCESS) { - sscanf(counterStr, "%ld", &archive->refreshCount); - } - } - } - - if (status == CELIX_SUCCESS) { - *refreshCount = archive->refreshCount; - } - - framework_logIfError(logger, status, NULL, "Could not get refresh count"); - - return status; -} - -celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive) { - FILE *refreshCounterFile; - celix_status_t status = CELIX_SUCCESS; - char refreshCounter[512]; - - snprintf(refreshCounter, sizeof(refreshCounter), "%s/refresh.counter", 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(logger, status, NULL, "Could not set refresh count"); - - return status; -} - -celix_status_t bundleArchive_getLastModified(bundle_archive_pt archive, time_t *lastModified) { - celix_status_t status = CELIX_SUCCESS; - - if (archive->lastModified == (time_t) NULL) { - status = CELIX_DO_IF(status, bundleArchive_readLastModified(archive, &archive->lastModified)); - } - - if (status == CELIX_SUCCESS) { - *lastModified = archive->lastModified; - } - - framework_logIfError(logger, status, NULL, "Could not get last modified"); - - return status; -} - -celix_status_t bundleArchive_setLastModified(bundle_archive_pt archive, time_t lastModifiedTime) { - celix_status_t status = CELIX_SUCCESS; - - archive->lastModified = lastModifiedTime; - status = CELIX_DO_IF(status, bundleArchive_writeLastModified(archive)); - - 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) { - FILE *lastModifiedFile; - char lastModified[512]; - - celix_status_t status = CELIX_SUCCESS; - - snprintf(lastModified, sizeof(lastModified), "%s/bundle.lastmodified", archive->archiveRoot); - - 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; - memset(&tm_time,0,sizeof(struct tm)); - - 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; - - *time = mktime(&tm_time); - } - } - - 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; - FILE *lastModifiedFile; - char lastModified[512]; - - 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); - } - - framework_logIfError(logger, status, NULL, "Could not write last modified"); - - return status; -} - -celix_status_t bundleArchive_revise(bundle_archive_pt archive, const char * location, const char *inputFile) { - celix_status_t status = CELIX_SUCCESS; - long revNr = 0l; - if (!linkedList_isEmpty(archive->revisions)) { - long revisionNr; - status = bundleRevision_getNumber(linkedList_getLast(archive->revisions), &revisionNr); - revNr = revisionNr + 1; - } - if (status == CELIX_SUCCESS) { - status = bundleArchive_reviseInternal(archive, false, revNr, location, inputFile); - } - - framework_logIfError(logger, status, NULL, "Could not revise bundle archive"); - - return status; -} - -static celix_status_t bundleArchive_reviseInternal(bundle_archive_pt archive, bool isReload, long revNr, const char * location, const char *inputFile) { - celix_status_t status = CELIX_SUCCESS; - bundle_revision_pt revision = NULL; - - if (inputFile != NULL) { - location = "inputstream:"; - } - - status = bundleArchive_createRevisionFromLocation(archive, location, inputFile, revNr, &revision); - - if (status == CELIX_SUCCESS) { - if (!isReload) { - status = bundleArchive_setRevisionLocation(archive, location, revNr); - } - - linkedList_addElement(archive->revisions, revision); - } - - framework_logIfError(logger, status, NULL, "Could not revise bundle archive"); - - return status; -} - -celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool *rolledback) { - *rolledback = true; - return CELIX_SUCCESS; -} - -static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt archive, const char *location, const char *inputFile, long revNr, bundle_revision_pt *bundle_revision) { - celix_status_t status = CELIX_SUCCESS; - char root[256]; - long refreshCount; - - status = bundleArchive_getRefreshCount(archive, &refreshCount); - if (status == CELIX_SUCCESS) { - bundle_revision_pt revision = NULL; - - sprintf(root, "%s/version%ld.%ld", archive->archiveRoot, refreshCount, revNr); - status = bundleRevision_create(root, location, revNr, inputFile, &revision); - - if (status == CELIX_SUCCESS) { - *bundle_revision = revision; - } - } - - framework_logIfError(logger, status, NULL, "Could not create revision [location=%s,inputFile=%s]", location, inputFile); - - return status; -} - -static celix_status_t bundleArchive_getRevisionLocation(bundle_archive_pt archive, long revNr, char **revision_location) { - celix_status_t status = CELIX_SUCCESS; - char revisionLocation[256]; - long refreshCount; - - status = bundleArchive_getRefreshCount(archive, &refreshCount); - if (status == CELIX_SUCCESS) { - FILE *revisionLocationFile; - - snprintf(revisionLocation, sizeof(revisionLocation), "%s/version%ld.%ld/revision.location", archive->archiveRoot, refreshCount, revNr); - - revisionLocationFile = fopen(revisionLocation, "r"); - if (revisionLocationFile != NULL) { - char location[256]; - fgets(location , sizeof(location) , revisionLocationFile); - fclose(revisionLocationFile); - - *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; - } - } - - - framework_logIfError(logger, status, NULL, "Failed to get revision location"); - - return status; -} - -static celix_status_t bundleArchive_setRevisionLocation(bundle_archive_pt archive, const char * location, long revNr) { - celix_status_t status = CELIX_SUCCESS; - - char revisionLocation[256]; - long refreshCount; - - status = bundleArchive_getRefreshCount(archive, &refreshCount); - if (status == CELIX_SUCCESS) { - FILE * revisionLocationFile; - - snprintf(revisionLocation, sizeof(revisionLocation), "%s/version%ld.%ld/revision.location", archive->archiveRoot, refreshCount, revNr); - - revisionLocationFile = fopen(revisionLocation, "w"); - if (revisionLocationFile == NULL) { - status = CELIX_FILE_IO_EXCEPTION; - } else { - fprintf(revisionLocationFile, "%s", location); - fclose(revisionLocationFile); - } - } - - framework_logIfError(logger, status, NULL, "Failed to set revision location"); - - return status; -} - -celix_status_t bundleArchive_close(bundle_archive_pt archive) { - // close revision - // not yet needed/possible - return CELIX_SUCCESS; -} - -celix_status_t bundleArchive_closeAndDelete(bundle_archive_pt archive) { - celix_status_t status = CELIX_SUCCESS; - - status = bundleArchive_close(archive); - if (status == CELIX_SUCCESS) { - status = bundleArchive_deleteTree(archive, archive->archiveRoot); - } - - framework_logIfError(logger, status, NULL, "Failed to close and delete archive"); - - return status; -} - -static celix_status_t bundleArchive_initialize(bundle_archive_pt archive) { - celix_status_t status = CELIX_SUCCESS; - - if (archive->archiveRootDir == NULL) { - int err = mkdir(archive->archiveRoot, S_IRWXU) ; - if (err != 0) { - char *errmsg = strerror(errno); - fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error mkdir: %s\n", errmsg); - status = CELIX_FILE_IO_EXCEPTION; - } else { - archive->archiveRootDir = opendir(archive->archiveRoot); - if (archive->archiveRootDir == NULL) { - status = CELIX_FILE_IO_EXCEPTION; - } else { - FILE *bundleIdFile; - char bundleId[512]; - - snprintf(bundleId, sizeof(bundleId), "%s/bundle.id", archive->archiveRoot); - bundleIdFile = fopen(bundleId, "w"); - - if (bundleIdFile == NULL) { - status = CELIX_FILE_IO_EXCEPTION; - } else { - FILE *bundleLocationFile; - char bundleLocation[512]; - - fprintf(bundleIdFile, "%ld", archive->id); - // Ignore close status, let it fail if needed again - fclose(bundleIdFile); - - snprintf(bundleLocation, sizeof(bundleLocation), "%s/bundle.location", archive->archiveRoot); - bundleLocationFile = fopen(bundleLocation, "w"); - - if (bundleLocationFile == NULL) { - status = CELIX_FILE_IO_EXCEPTION; - } else { - fprintf(bundleLocationFile, "%s", archive->location); - // Ignore close status, let it fail if needed again - fclose(bundleLocationFile); - - status = bundleArchive_writeLastModified(archive); - } - } - closedir(archive->archiveRootDir); - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to initialize archive"); - - return status; -} - -static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, const char * directory) { - DIR *dir; - celix_status_t status = CELIX_SUCCESS; - dir = opendir(directory); - if (dir == NULL) { - status = CELIX_FILE_IO_EXCEPTION; - } else { - - struct dirent* dent = NULL; - - errno = 0; - dent = readdir(dir); - while (errno == 0 && dent != NULL) { - if ((strcmp((dent->d_name), ".") != 0) && (strcmp((dent->d_name), "..") != 0)) { - char subdir[512]; - snprintf(subdir, 512, "%s/%s", directory, dent->d_name); - - struct stat st; - if (stat(subdir, &st) == 0) { - if (S_ISDIR (st.st_mode)) { - status = bundleArchive_deleteTree(archive, subdir); - } else { - if (remove(subdir) != 0) { - status = CELIX_FILE_IO_EXCEPTION; - break; - } - } - } - } - errno = 0; - dent = readdir(dir); - } - - if (errno != 0) { - status = CELIX_FILE_IO_EXCEPTION; - } else if (closedir(dir) != 0) { - status = CELIX_FILE_IO_EXCEPTION; - } else if (status == CELIX_SUCCESS) { - if (rmdir(directory) != 0) { - status = CELIX_FILE_IO_EXCEPTION; - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to delete tree"); - - return status; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/bundle_cache.c ---------------------------------------------------------------------- diff --git a/framework/private/src/bundle_cache.c b/framework/private/src/bundle_cache.c deleted file mode 100644 index 39875b5..0000000 --- a/framework/private/src/bundle_cache.c +++ /dev/null @@ -1,218 +0,0 @@ -/** - *Licensed to the Apache Software Foundation (ASF) under one - *or more contributor license agreements. See the NOTICE file - *distributed with this work for additional information - *regarding copyright ownership. The ASF licenses this file - *to you under the Apache License, Version 2.0 (the - *"License"); you may not use this file except in compliance - *with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - *Unless required by applicable law or agreed to in writing, - *software distributed under the License is distributed on an - *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - *specific language governing permissions and limitations - *under the License. - */ -/* - * bundle_cache.c - * - * \date Aug 6, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ -#include -#include -#include -#include -#include -#include - -#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); - -celix_status_t bundleCache_create(properties_pt configurationMap, bundle_cache_pt *bundle_cache) { - celix_status_t status; - bundle_cache_pt cache; - - if (configurationMap == NULL || *bundle_cache != NULL) { - return CELIX_ILLEGAL_ARGUMENT; - } - - cache = (bundle_cache_pt) calloc(1, sizeof(*cache)); - if (cache == NULL) { - status = CELIX_ENOMEM; - } else { - char* cacheDir = (char*)properties_get(configurationMap, (char *) OSGI_FRAMEWORK_FRAMEWORK_STORAGE); - cache->configurationMap = configurationMap; - if (cacheDir == NULL) { - cacheDir = ".cache"; - } - cache->cacheDir = cacheDir; - - *bundle_cache = cache; - status = CELIX_SUCCESS; - } - - framework_logIfError(logger, status, NULL, "Failed to create bundle cache"); - - return status; -} - -celix_status_t bundleCache_destroy(bundle_cache_pt *cache) { - - free(*cache); - *cache = NULL; - - return CELIX_SUCCESS; -} - -celix_status_t bundleCache_delete(bundle_cache_pt cache) { - return bundleCache_deleteTree(cache, cache->cacheDir); -} - -celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *archives) { - celix_status_t status = CELIX_SUCCESS; - - DIR *dir; - struct stat st; - - dir = opendir(cache->cacheDir); - - if (dir == NULL && errno == ENOENT) { - if(mkdir(cache->cacheDir, S_IRWXU) == 0 ){ - dir = opendir(cache->cacheDir); - } - } - - if (dir != NULL) { - array_list_pt list = NULL; - arrayList_create(&list); - - struct dirent* dent = NULL; - - errno = 0; - dent = readdir(dir); - while (errno == 0 && dent != NULL) { - char archiveRoot[512]; - - snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s", cache->cacheDir, dent->d_name); - - if (stat (archiveRoot, &st) == 0) { - if (S_ISDIR (st.st_mode) - && (strcmp((dent->d_name), ".") != 0) - && (strcmp((dent->d_name), "..") != 0) - && (strncmp(dent->d_name, "bundle", 6) == 0) - && (strcmp(dent->d_name, "bundle0") != 0)) { - - bundle_archive_pt archive = NULL; - status = bundleArchive_recreate(archiveRoot, &archive); - if (status == CELIX_SUCCESS) { - arrayList_add(list, archive); - } - } - } - - errno = 0; - dent = readdir(dir); - } - - if (errno != 0) { - fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error reading dir"); - status = CELIX_FILE_IO_EXCEPTION; - } else { - status = CELIX_SUCCESS; - } - - closedir(dir); - - if (status == CELIX_SUCCESS) { - *archives = list; - } - else{ - int idx = 0; - for(;idxcacheDir, id); - status = bundleArchive_create(archiveRoot, id, location, inputFile, bundle_archive); - } - - framework_logIfError(logger, status, NULL, "Failed to create archive"); - - return status; -} - -static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * directory) { - DIR *dir; - celix_status_t status = CELIX_SUCCESS; - struct stat st; - - errno = 0; - dir = opendir(directory); - if (dir == NULL) { - status = CELIX_FILE_IO_EXCEPTION; - } else { - struct dirent* dent = NULL; - dent = readdir(dir); - while (errno == 0 && dent != NULL) { - if ((strcmp((dent->d_name), ".") != 0) && (strcmp((dent->d_name), "..") != 0)) { - char subdir[512]; - snprintf(subdir, sizeof(subdir), "%s/%s", directory, dent->d_name); - - if (stat(subdir, &st) == 0) { - if (S_ISDIR (st.st_mode)) { - status = bundleCache_deleteTree(cache, subdir); - } else { - if (remove(subdir) != 0) { - status = CELIX_FILE_IO_EXCEPTION; - break; - } - } - } - } - errno = 0; - dent = readdir(dir); - } - - if (errno != 0) { - status = CELIX_FILE_IO_EXCEPTION; - } - else if (closedir(dir) != 0) { - status = CELIX_FILE_IO_EXCEPTION; - } - if (status == CELIX_SUCCESS) { - if (rmdir(directory) != 0) { - status = CELIX_FILE_IO_EXCEPTION; - } - } - } - - framework_logIfError(logger, status, NULL, "Failed to delete tree at dir '%s'", directory); - - return status; -}