http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/ioapi.c ---------------------------------------------------------------------- diff --git a/framework/private/src/ioapi.c b/framework/private/src/ioapi.c deleted file mode 100644 index 49958f6..0000000 --- a/framework/private/src/ioapi.c +++ /dev/null @@ -1,235 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - 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 for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - -*/ - -#if (defined(_WIN32)) - #define _CRT_SECURE_NO_WARNINGS -#endif - -#include "ioapi.h" - -voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) -{ - if (pfilefunc->zfile_func64.zopen64_file != NULL) - return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); - else - { - return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); - } -} - -long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) -{ - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); - else - { - uLong offsetTruncated = (uLong)offset; - if (offsetTruncated != offset) - return -1; - else - return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); - } -} - -ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) -{ - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); - else - { - uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); - if ((tell_uLong) == ((uLong)-1)) - return (ZPOS64_T)-1; - else - return tell_uLong; - } -} - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) -{ - p_filefunc64_32->zfile_func64.zopen64_file = NULL; - p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; - p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; - p_filefunc64_32->zfile_func64.ztell64_file = NULL; - p_filefunc64_32->zfile_func64.zseek64_file = NULL; - p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; - p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; - p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; -} - - - -static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); -static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); -static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); -static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); -static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); - -static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - file = fopen(filename, mode_fopen); - return file; -} - -static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - file = fopen64((const char*)filename, mode_fopen); - return file; -} - - -static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) -{ - uLong ret; - ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) -{ - uLong ret; - ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) -{ - long ret; - ret = ftell((FILE *)stream); - return ret; -} - - -static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) -{ - ZPOS64_T ret; - ret = ftello64((FILE *)stream); - return ret; -} - -static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) -{ - int fseek_origin=0; - long ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - ret = 0; - if (fseek((FILE *)stream, offset, fseek_origin) != 0) - ret = -1; - return ret; -} - -static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) -{ - int fseek_origin=0; - long ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - ret = 0; - - if(fseeko64((FILE *)stream, offset, fseek_origin) != 0) - ret = -1; - - return ret; -} - - -static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) -{ - int ret; - ret = fclose((FILE *)stream); - return ret; -} - -static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) -{ - int ret; - ret = ferror((FILE *)stream); - return ret; -} - -void fill_fopen_filefunc (pzlib_filefunc_def) - zlib_filefunc_def* pzlib_filefunc_def; -{ - pzlib_filefunc_def->zopen_file = fopen_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell_file = ftell_file_func; - pzlib_filefunc_def->zseek_file = fseek_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} - -void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = fopen64_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell64_file = ftell64_file_func; - pzlib_filefunc_def->zseek64_file = fseek64_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -}
http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/iowin32.c ---------------------------------------------------------------------- diff --git a/framework/private/src/iowin32.c b/framework/private/src/iowin32.c deleted file mode 100644 index 6a2a883..0000000 --- a/framework/private/src/iowin32.c +++ /dev/null @@ -1,389 +0,0 @@ -/* iowin32.c -- IO base function header for compress/uncompress .zip - 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 for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - -*/ - -#include <stdlib.h> - -#include "zlib.h" -#include "ioapi.h" -#include "iowin32.h" - -#ifndef INVALID_HANDLE_VALUE -#define INVALID_HANDLE_VALUE (0xFFFFFFFF) -#endif - -#ifndef INVALID_SET_FILE_POINTER -#define INVALID_SET_FILE_POINTER ((DWORD)-1) -#endif - -voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); -uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream)); -long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream)); -int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream)); - -typedef struct -{ - HANDLE hf; - int error; -} WIN32FILE_IOWIN; - - -static void win32_translate_open_mode(int mode, - DWORD* lpdwDesiredAccess, - DWORD* lpdwCreationDisposition, - DWORD* lpdwShareMode, - DWORD* lpdwFlagsAndAttributes) -{ - *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0; - - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - { - *lpdwDesiredAccess = GENERIC_READ; - *lpdwCreationDisposition = OPEN_EXISTING; - *lpdwShareMode = FILE_SHARE_READ; - } - else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - { - *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; - *lpdwCreationDisposition = OPEN_EXISTING; - } - else if (mode & ZLIB_FILEFUNC_MODE_CREATE) - { - *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; - *lpdwCreationDisposition = CREATE_ALWAYS; - } -} - -static voidpf win32_build_iowin(HANDLE hFile) -{ - voidpf ret=NULL; - - if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) - { - WIN32FILE_IOWIN w32fiow; - w32fiow.hf = hFile; - w32fiow.error = 0; - ret = malloc(sizeof(WIN32FILE_IOWIN)); - - if (ret==NULL) - CloseHandle(hFile); - else - *((WIN32FILE_IOWIN*)ret) = w32fiow; - } - return ret; -} - -voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode) -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = NULL; - - win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); - - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); - - return win32_build_iowin(hFile); -} - - -voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = NULL; - - win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); - - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); - - return win32_build_iowin(hFile); -} - - -voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode) -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = NULL; - - win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); - - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); - - return win32_build_iowin(hFile); -} - - -voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode) -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = NULL; - - win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); - - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); - - return win32_build_iowin(hFile); -} - - -uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size) -{ - uLong ret=0; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - - if (hFile != NULL) - { - if (!ReadFile(hFile, buf, size, &ret, NULL)) - { - DWORD dwErr = GetLastError(); - if (dwErr == ERROR_HANDLE_EOF) - dwErr = 0; - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - } - } - - return ret; -} - - -uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size) -{ - uLong ret=0; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - - if (hFile != NULL) - { - if (!WriteFile(hFile, buf, size, &ret, NULL)) - { - DWORD dwErr = GetLastError(); - if (dwErr == ERROR_HANDLE_EOF) - dwErr = 0; - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - } - } - - return ret; -} - -long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) -{ - long ret=-1; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - if (hFile != NULL) - { - DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); - if (dwSet == INVALID_SET_FILE_POINTER) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = -1; - } - else - ret=(long)dwSet; - } - return ret; -} - -ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) -{ - ZPOS64_T ret= (ZPOS64_T)-1; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream)->hf; - - if (hFile) - { - LARGE_INTEGER li; - li.QuadPart = 0; - li.u.LowPart = SetFilePointer(hFile, li.u.LowPart, &li.u.HighPart, FILE_CURRENT); - if ( (li.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR)) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = (ZPOS64_T)-1; - } - else - ret=li.QuadPart; - } - return ret; -} - - -long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin) -{ - DWORD dwMoveMethod=0xFFFFFFFF; - HANDLE hFile = NULL; - - long ret=-1; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - dwMoveMethod = FILE_CURRENT; - break; - case ZLIB_FILEFUNC_SEEK_END : - dwMoveMethod = FILE_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - dwMoveMethod = FILE_BEGIN; - break; - default: return -1; - } - - if (hFile != NULL) - { - DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); - if (dwSet == INVALID_SET_FILE_POINTER) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = -1; - } - else - ret=0; - } - return ret; -} - -long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin) -{ - DWORD dwMoveMethod=0xFFFFFFFF; - HANDLE hFile = NULL; - long ret=-1; - - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream)->hf; - - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - dwMoveMethod = FILE_CURRENT; - break; - case ZLIB_FILEFUNC_SEEK_END : - dwMoveMethod = FILE_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - dwMoveMethod = FILE_BEGIN; - break; - default: return -1; - } - - if (hFile) - { - LARGE_INTEGER* li = (LARGE_INTEGER*)&offset; - DWORD dwSet = SetFilePointer(hFile, li->u.LowPart, &li->u.HighPart, dwMoveMethod); - if (dwSet == INVALID_SET_FILE_POINTER) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = -1; - } - else - ret=0; - } - return ret; -} - -int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream) -{ - int ret=-1; - - if (stream!=NULL) - { - HANDLE hFile; - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - if (hFile != NULL) - { - CloseHandle(hFile); - ret=0; - } - free(stream); - } - return ret; -} - -int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream) -{ - int ret=-1; - if (stream!=NULL) - { - ret = ((WIN32FILE_IOWIN*)stream) -> error; - } - return ret; -} - -void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen_file = win32_open_file_func; - pzlib_filefunc_def->zread_file = win32_read_file_func; - pzlib_filefunc_def->zwrite_file = win32_write_file_func; - pzlib_filefunc_def->ztell_file = win32_tell_file_func; - pzlib_filefunc_def->zseek_file = win32_seek_file_func; - pzlib_filefunc_def->zclose_file = win32_close_file_func; - pzlib_filefunc_def->zerror_file = win32_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} - -void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = win32_open64_file_func; - pzlib_filefunc_def->zread_file = win32_read_file_func; - pzlib_filefunc_def->zwrite_file = win32_write_file_func; - pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; - pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; - pzlib_filefunc_def->zclose_file = win32_close_file_func; - pzlib_filefunc_def->zerror_file = win32_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} - - -void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA; - pzlib_filefunc_def->zread_file = win32_read_file_func; - pzlib_filefunc_def->zwrite_file = win32_write_file_func; - pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; - pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; - pzlib_filefunc_def->zclose_file = win32_close_file_func; - pzlib_filefunc_def->zerror_file = win32_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} - - -void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW; - pzlib_filefunc_def->zread_file = win32_read_file_func; - pzlib_filefunc_def->zwrite_file = win32_write_file_func; - pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; - pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; - pzlib_filefunc_def->zclose_file = win32_close_file_func; - pzlib_filefunc_def->zerror_file = win32_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/manifest.c ---------------------------------------------------------------------- diff --git a/framework/private/src/manifest.c b/framework/private/src/manifest.c deleted file mode 100644 index 29b155a..0000000 --- a/framework/private/src/manifest.c +++ /dev/null @@ -1,271 +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. - */ -/* - * manifest.c - * - * \date Jul 5, 2010 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "celixbool.h" - -#include "manifest.h" -#include "utils.h" -#include "celix_log.h" - -int fpeek(FILE *stream); -celix_status_t manifest_readAttributes(manifest_pt manifest, properties_pt properties, FILE *file); - -celix_status_t manifest_create(manifest_pt *manifest) { - celix_status_t status = CELIX_SUCCESS; - - *manifest = malloc(sizeof(**manifest)); - if (!*manifest) { - status = CELIX_ENOMEM; - } else { - (*manifest)->mainAttributes = properties_create(); - (*manifest)->attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - } - - framework_logIfError(logger, status, NULL, "Cannot create manifest"); - - return status; -} - -celix_status_t manifest_destroy(manifest_pt manifest) { - if (manifest != NULL) { - properties_destroy(manifest->mainAttributes); - hashMap_destroy(manifest->attributes, true, false); - manifest->mainAttributes = NULL; - manifest->attributes = NULL; - free(manifest); - manifest = NULL; - } - return CELIX_SUCCESS; -} - -celix_status_t manifest_createFromFile(const char *filename, manifest_pt *manifest) { - celix_status_t status; - - status = manifest_create(manifest); - - if (status == CELIX_SUCCESS) { - manifest_read(*manifest, filename); - } - - framework_logIfError(logger, status, NULL, "Cannot create manifest from file"); - - return status; -} - -void manifest_clear(manifest_pt manifest) { - -} - -properties_pt manifest_getMainAttributes(manifest_pt manifest) { - return manifest->mainAttributes; -} - -celix_status_t manifest_getEntries(manifest_pt manifest, hash_map_pt *map) { - *map = manifest->attributes; - return CELIX_SUCCESS; -} - -celix_status_t manifest_read(manifest_pt manifest, const char *filename) { - celix_status_t status = CELIX_SUCCESS; - - FILE *file = fopen ( filename, "r" ); - if (file != NULL) { - char lbuf[512]; - char name[512]; - bool skipEmptyLines = true; - char lastline[512]; - memset(lbuf,0,512); - memset(name,0,512); - memset(lastline,0,512); - - manifest_readAttributes(manifest, manifest->mainAttributes, file); - - while (status==CELIX_SUCCESS && fgets(lbuf, sizeof(lbuf), file) != NULL) { - properties_pt attributes; - int len = strlen(lbuf); - - if (lbuf[--len] != '\n') { - status = CELIX_FILE_IO_EXCEPTION; - framework_logIfError(logger, status, NULL, "Manifest '%s' line too long", filename); - break; - } - if (len > 0 && lbuf[len - 1] == '\r') { - --len; - } - if (len == 0 && skipEmptyLines) { - continue; - } - skipEmptyLines = false; - - if (strlen(name) == 0) { - - if ((tolower(lbuf[0]) == 'n') && (tolower(lbuf[1]) == 'a') && - (tolower(lbuf[2]) == 'm') && (tolower(lbuf[3]) == 'e') && - (lbuf[4] == ':') && (lbuf[5] == ' ')) { - name[0] = '\0'; - strncpy(name, lbuf+6, len - 6); - name[len - 6] = '\0'; - } else { - status = CELIX_FILE_IO_EXCEPTION; - framework_logIfError(logger, status, NULL, "Manifest '%s' invalid format", filename); - break; - } - - if (fpeek(file) == ' ') { - int newlen = len - 6; - lastline[0] = '\0'; - strncpy(lastline, lbuf+6, len - 6); - lastline[newlen] = '\0'; - continue; - } - } else { - int newlen = strlen(lastline) + len; - char buf[512]; - buf[0] = '\0'; - strcpy(buf, lastline); - strncat(buf, lbuf+1, len - 1); - buf[newlen] = '\0'; - - if (fpeek(file) == ' ') { -// lastline = realloc(lastline, strlen(buf) + 1); - lastline[0] = '\0'; - strcpy(lastline, buf); - continue; - } - name[0] = '\0'; - strcpy(name, buf); - name[strlen(buf)] = '\0'; - } - - attributes = hashMap_get(manifest->attributes, name); - if (attributes == NULL) { - attributes = properties_create(); - hashMap_put(manifest->attributes, strdup(name), attributes); - } - manifest_readAttributes(manifest, attributes, file); - - name[0] = '\0'; - skipEmptyLines = true; - } - fclose(file); - } else { - status = CELIX_FILE_IO_EXCEPTION; - } - - framework_logIfError(logger, status, NULL, "Cannot read manifest"); - - return status; -} - -void manifest_write(manifest_pt manifest, const char * filename) { - -} - -const char* manifest_getValue(manifest_pt manifest, const char* name) { - const char* val = properties_get(manifest->mainAttributes, name); - bool isEmpty = utils_isStringEmptyOrNull(val); - return isEmpty ? NULL : val; -} - -int fpeek(FILE *stream) { - int c; - c = fgetc(stream); - ungetc(c, stream); - return c; -} - -celix_status_t manifest_readAttributes(manifest_pt manifest, properties_pt properties, FILE *file) { - char name[512]; memset(name,0,512); - char value[512]; memset(value,0,512); - char lastLine[512]; memset(lastLine,0,512); - char lbuf[512]; memset(lbuf,0,512); - - - while (fgets(lbuf, sizeof(lbuf), file ) != NULL ) { - int len = strlen(lbuf); - - if (lbuf[--len] != '\n') { - printf("MANIFEST: Line too long\n"); - return CELIX_FILE_IO_EXCEPTION; - } - if (len > 0 && lbuf[len - 1] == '\r') { - --len; - } - if (len == 0) { - break; - } - - if (lbuf[0] == ' ') { - char buf[512]; - buf[0] = '\0'; - - // Line continued - strcat(buf, lastLine); - strncat(buf, lbuf+1, len - 1); - - if (fpeek(file) == ' ') { -// lastLine = realloc(lastLine, strlen(buf) + 1); - lastLine[0] = '\0'; - strcpy(lastLine, buf); - continue; - } - value[0] = '\0'; - strcpy(value, buf); - } else { - int i = 0; - while (lbuf[i++] != ':') { - if (i >= len) { - printf("MANIFEST: Invalid header\n"); - return CELIX_FILE_IO_EXCEPTION; - } - } - if (lbuf[i++] != ' ') { - printf("MANIFEST: Invalid header\n"); - return CELIX_FILE_IO_EXCEPTION; - } - name[0] = '\0'; - strncpy(name, lbuf, i - 2); - name[i - 2] = '\0'; - if (fpeek(file) == ' ') { - int newlen = len - i; - lastLine[0] = '\0'; - strncpy(lastLine, lbuf+i, len -i); - lastLine[newlen] = '\0'; - continue; - } - value[0] = '\0'; - strncpy(value, lbuf+i, len - i); - value[len - i] = '\0'; - } - - properties_set(properties, name, value); - } - - return CELIX_SUCCESS; -} - http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/manifest_parser.c ---------------------------------------------------------------------- diff --git a/framework/private/src/manifest_parser.c b/framework/private/src/manifest_parser.c deleted file mode 100644 index 07b40a8..0000000 --- a/framework/private/src/manifest_parser.c +++ /dev/null @@ -1,490 +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. - */ -/* - * manifest_parser.c - * - * \date Jul 12, 2010 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ -#include <stdlib.h> -#include <string.h> - -#include "utils.h" -#include "constants.h" -#include "manifest_parser.h" -#include "capability.h" -#include "requirement.h" -#include "attribute.h" -#include "hash_map.h" -#include "celix_errno.h" -#include "linked_list_iterator.h" -#include "celix_log.h" - -//FIXME the manifest parser has no destroy function and as result contains memory leaks. - -struct manifestParser { - module_pt owner; - manifest_pt manifest; - - version_pt bundleVersion; - char * bundleSymbolicName; - linked_list_pt capabilities; - linked_list_pt requirements; -}; - -static linked_list_pt manifestParser_parseImportHeader(const char* header); -static linked_list_pt manifestParser_parseExportHeader(module_pt module, const char* header); -static linked_list_pt manifestParser_parseDelimitedString(const char* value, const char* delim); -static linked_list_pt manifestParser_parseStandardHeaderClause(const char* clauseString); -static linked_list_pt manifestParser_parseStandardHeader(const char* header); - -celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, manifest_parser_pt *manifest_parser) { - celix_status_t status; - manifest_parser_pt parser; - - status = CELIX_SUCCESS; - parser = (manifest_parser_pt) malloc(sizeof(*parser)); - if (parser) { - const char * bundleVersion = NULL; - const char * bundleSymbolicName = NULL; - parser->manifest = manifest; - parser->owner = owner; - - bundleVersion = manifest_getValue(manifest, OSGI_FRAMEWORK_BUNDLE_VERSION); - if (bundleVersion != NULL) { - parser->bundleVersion = NULL; - version_createVersionFromString(bundleVersion, &parser->bundleVersion); - } else { - parser->bundleVersion = NULL; - version_createEmptyVersion(&parser->bundleVersion); - } - bundleSymbolicName = manifest_getValue(manifest, OSGI_FRAMEWORK_BUNDLE_SYMBOLICNAME); - if (bundleSymbolicName != NULL) { - parser->bundleSymbolicName = (char*)bundleSymbolicName; - } - - parser->capabilities = manifestParser_parseExportHeader(owner, manifest_getValue(manifest, OSGI_FRAMEWORK_EXPORT_LIBRARY)); - parser->requirements = manifestParser_parseImportHeader(manifest_getValue(manifest, OSGI_FRAMEWORK_IMPORT_LIBRARY)); - - *manifest_parser = parser; - - status = CELIX_SUCCESS; - } else { - status = CELIX_ENOMEM; - } - - framework_logIfError(logger, status, NULL, "Cannot create manifest parser"); - - return status; -} - -celix_status_t manifestParser_destroy(manifest_parser_pt mp) { - linkedList_destroy(mp->capabilities); - mp->capabilities = NULL; - linkedList_destroy(mp->requirements); - mp->requirements = NULL; - mp->bundleSymbolicName = NULL; - version_destroy(mp->bundleVersion); - mp->bundleVersion = NULL; - mp->manifest = NULL; - mp->owner = NULL; - - free(mp); - - return CELIX_SUCCESS; -} - -static linked_list_pt manifestParser_parseDelimitedString(const char * value, const char * delim) { - linked_list_pt list; - - if (linkedList_create(&list) == CELIX_SUCCESS) { - if (value != NULL) { - int CHAR = 1; - int DELIMITER = 2; - int STARTQUOTE = 4; - int ENDQUOTE = 8; - - char buffer[512]; - int expecting = (CHAR | DELIMITER | STARTQUOTE); - unsigned int i; - - buffer[0] = '\0'; - - for (i = 0; i < strlen(value); i++) { - char c = value[i]; - - bool isDelimiter = (strchr(delim, c) != NULL); - bool isQuote = (c == '"'); - - if (isDelimiter && ((expecting & DELIMITER) > 0)) { - linkedList_addElement(list, strdup(buffer)); - buffer[0] = '\0'; - expecting = (CHAR | DELIMITER | STARTQUOTE); - } else if (isQuote && ((expecting & STARTQUOTE) > 0)) { - char tmp[2]; - tmp[0] = c; - tmp[1] = '\0'; - strcat(buffer, tmp); - expecting = CHAR | ENDQUOTE; - } else if (isQuote && ((expecting & ENDQUOTE) > 0)) { - char tmp[2]; - tmp[0] = c; - tmp[1] = '\0'; - strcat(buffer, tmp); - expecting = (CHAR | STARTQUOTE | DELIMITER); - } else if ((expecting & CHAR) > 0) { - char tmp[2]; - tmp[0] = c; - tmp[1] = '\0'; - strcat(buffer, tmp); - } else { - linkedList_destroy(list); - return NULL; - } - } - - if (strlen(buffer) > 0) { - linkedList_addElement(list, strdup(utils_stringTrim(buffer))); - } - } - } - - return list; -} - -static linked_list_pt manifestParser_parseStandardHeaderClause(const char * clauseString) { - linked_list_pt paths = NULL; - linked_list_pt clause = NULL; - linked_list_pt pieces = NULL; - - if(linkedList_create(&paths) != CELIX_SUCCESS){ - return NULL; - } - - pieces = manifestParser_parseDelimitedString(clauseString, ";"); - - if (pieces != NULL) { - int pathCount = 0; - int pieceIdx; - hash_map_pt dirsMap = NULL; - hash_map_pt attrsMap = NULL; - char * sep; - - for (pieceIdx = 0; pieceIdx < linkedList_size(pieces); pieceIdx++) { - char * piece = linkedList_get(pieces, pieceIdx); - if (strchr(piece, '=') != NULL) { - break; - } else { - linkedList_addElement(paths, strdup(piece)); - pathCount++; - } - } - - if (pathCount != 0) { - - dirsMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - attrsMap = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - - bool failure = false; - char *key = NULL; - char *value = NULL; - - for (pieceIdx = pathCount; pieceIdx < linkedList_size(pieces) && !failure ; pieceIdx++) { - char * sepPtr; - char * DIRECTIVE_SEP = ":="; - char * ATTRIBUTE_SEP = "="; - char * piece = linkedList_get(pieces, pieceIdx); - if ((sepPtr = strstr(piece, DIRECTIVE_SEP)) != NULL) { - sep = DIRECTIVE_SEP; - } else if ((sepPtr = strstr(piece, ATTRIBUTE_SEP)) != NULL) { - sep = ATTRIBUTE_SEP; - } else { - failure=true; - break; - } - - if (strcmp(sep, DIRECTIVE_SEP) == 0) { - // Not implemented - } - else { - - key = string_ndup(piece, sepPtr - piece); - value = strdup(sepPtr+strlen(sep)); - - if (value[0] == '"' && value[strlen(value) -1] == '"') { - char * oldV = strdup(value); - int len = strlen(oldV) - 2; - value = (char *) realloc(value, (sizeof(char) * len+1)); - value[0] = '\0'; - value = strncpy(value, oldV+1, strlen(oldV) - 2); - value[len] = '\0'; - //check if correct - free(oldV); - } - - attribute_pt attr = NULL; - if (hashMap_containsKey(attrsMap, key)) { - failure=true; - break; - } - - if (attribute_create(key, value, &attr) == CELIX_SUCCESS) { - hashMap_put(attrsMap, key, attr); - } - } - } - - if(linkedList_create(&clause) != CELIX_SUCCESS){ - failure=true; - } - - if(failure){ - hashMap_destroy(dirsMap,false,false); - - hash_map_iterator_pt attrIter = hashMapIterator_create(attrsMap); - while(hashMapIterator_hasNext(attrIter)){ - hash_map_entry_pt entry = hashMapIterator_nextEntry(attrIter); - char *mkey = (char*)hashMapEntry_getKey(entry); - attribute_pt mattr = (attribute_pt)hashMapEntry_getValue(entry); - free(mkey); - attribute_destroy(mattr); - } - hashMapIterator_destroy(attrIter); - hashMap_destroy(attrsMap,false,false); - - if(key!=NULL){ - free(key); - } - if(value!=NULL){ - free(value); - } - - linked_list_iterator_pt piter = linkedListIterator_create(paths,0); - while(linkedListIterator_hasNext(piter)){ - free(linkedListIterator_next(piter)); - } - linkedListIterator_destroy(piter); - linkedList_destroy(paths); - - if(clause!=NULL){ - linkedList_destroy(clause); - clause = NULL; - } - } - else{ - linkedList_addElement(clause, paths); - linkedList_addElement(clause, dirsMap); - linkedList_addElement(clause, attrsMap); - } - - } - else{ - linkedList_destroy(paths); - } - - for(int listIdx = 0; listIdx < linkedList_size(pieces); listIdx++){ - void * element = linkedList_get(pieces, listIdx); - free(element); - } - linkedList_destroy(pieces); - } - else{ - linkedList_destroy(paths); - } - - return clause; -} - -static linked_list_pt manifestParser_parseStandardHeader(const char * header) { - linked_list_pt clauseStrings = NULL; - linked_list_pt completeList = NULL; - - if(header != NULL && strlen(header)==0){ - return NULL; - } - - if (linkedList_create(&completeList) == CELIX_SUCCESS) { - if(header!=NULL){ - char *hdr = strdup(header); - clauseStrings = manifestParser_parseDelimitedString(hdr, ","); - free(hdr); - if (clauseStrings != NULL) { - int i; - for (i = 0; i < linkedList_size(clauseStrings); i++) { - char *clauseString = (char *) linkedList_get(clauseStrings, i); - linkedList_addElement(completeList, manifestParser_parseStandardHeaderClause(clauseString)); - free(clauseString); - } - linkedList_destroy(clauseStrings); - } - } - - } - - return completeList; -} - -static linked_list_pt manifestParser_parseImportHeader(const char * header) { - linked_list_pt clauses = NULL; - linked_list_pt requirements = NULL; - bool failure = false; - - int clauseIdx; - linked_list_iterator_pt iter; - clauses = manifestParser_parseStandardHeader(header); - linkedList_create(&requirements); - - for (clauseIdx = 0; clauseIdx < linkedList_size(clauses) && !failure ; clauseIdx++) { - linked_list_pt clause = linkedList_get(clauses, clauseIdx); - - linked_list_pt paths = linkedList_get(clause, 0); - hash_map_pt directives = linkedList_get(clause, 1); - hash_map_pt attributes = linkedList_get(clause, 2); - - int pathIdx; - for (pathIdx = 0; pathIdx < linkedList_size(paths) && !failure ; pathIdx++) { - attribute_pt name = NULL; - requirement_pt req = NULL; - char * path = (char *) linkedList_get(paths, pathIdx); - if (strlen(path) == 0) { - failure = true; - break; - } - - if (attribute_create(strdup("service"), path, &name) == CELIX_SUCCESS) { - char *key = NULL; - attribute_getKey(name, &key); - hashMap_put(attributes, key, name); - } - - requirement_create(directives, attributes, &req); - linkedList_addElement(requirements, req); - } - } - - if(!failure){ - iter = linkedListIterator_create(clauses, 0); - while(linkedListIterator_hasNext(iter)) { - linked_list_pt clause = linkedListIterator_next(iter); - - linked_list_pt paths = linkedList_get(clause, 0); - linkedList_destroy(paths); - - linkedListIterator_remove(iter); - linkedList_destroy(clause); - } - linkedListIterator_destroy(iter); - } - - linkedList_destroy(clauses); - - if(failure){ - linkedList_destroy(requirements); - requirements = NULL; - } - - return requirements; -} - -static linked_list_pt manifestParser_parseExportHeader(module_pt module, const char * header) { - linked_list_pt clauses = NULL; - linked_list_pt capabilities = NULL; - int clauseIdx; - linked_list_iterator_pt iter; - bool failure = false; - - clauses = manifestParser_parseStandardHeader(header); - linkedList_create(&capabilities); - - for (clauseIdx = 0; clauseIdx < linkedList_size(clauses) && !failure ; clauseIdx++) { - linked_list_pt clause = linkedList_get(clauses, clauseIdx); - - linked_list_pt paths = linkedList_get(clause, 0); - hash_map_pt directives = linkedList_get(clause, 1); - hash_map_pt attributes = linkedList_get(clause, 2); - - int pathIdx; - for (pathIdx = 0; pathIdx < linkedList_size(paths) && !failure ; pathIdx++) { - char * path = (char *) linkedList_get(paths, pathIdx); - attribute_pt name = NULL; - capability_pt cap = NULL; - if (strlen(path) == 0) { - failure=true; - break; - } - - if (attribute_create(strdup("service"), path, &name) == CELIX_SUCCESS) { - char *key = NULL; - attribute_getKey(name, &key); - hashMap_put(attributes, key, name); - } - - capability_create(module, directives, attributes, &cap); - linkedList_addElement(capabilities, cap); - } - } - - if(!failure){ - iter = linkedListIterator_create(clauses, 0); - while(linkedListIterator_hasNext(iter)) { - linked_list_pt clause = linkedListIterator_next(iter); - - linked_list_pt paths = linkedList_get(clause, 0); - linkedList_destroy(paths); - - linkedListIterator_remove(iter); - linkedList_destroy(clause); - } - linkedListIterator_destroy(iter); - } - - linkedList_destroy(clauses); - if(failure){ - linkedList_destroy(capabilities); - capabilities = NULL; - } - - return capabilities; -} - -celix_status_t manifestParser_getAndDuplicateSymbolicName(manifest_parser_pt parser, char **symbolicName) { - *symbolicName = strndup(parser->bundleSymbolicName, 1024*10); - return CELIX_SUCCESS; -} - -celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, version_pt *version) { - return version_clone(parser->bundleVersion, version); -} - -celix_status_t manifestParser_getCapabilities(manifest_parser_pt parser, linked_list_pt *capabilities) { - celix_status_t status; - - status = linkedList_clone(parser->capabilities, capabilities); - - return status; -} - -celix_status_t manifestParser_getRequirements(manifest_parser_pt parser, linked_list_pt *requirements) { - celix_status_t status; - - status = linkedList_clone(parser->requirements, requirements); - - return status; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/miniunz.c ---------------------------------------------------------------------- diff --git a/framework/private/src/miniunz.c b/framework/private/src/miniunz.c deleted file mode 100644 index c3a9bd1..0000000 --- a/framework/private/src/miniunz.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - miniunz.c - Version 1.1, February 14h, 2010 - sample 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 ) -*/ - -#ifndef _WIN32 - #ifndef __USE_FILE_OFFSET64 - #define __USE_FILE_OFFSET64 - #endif - #ifndef __USE_LARGEFILE64 - #define __USE_LARGEFILE64 - #endif - #ifndef _LARGEFILE64_SOURCE - #define _LARGEFILE64_SOURCE - #endif - #ifndef _FILE_OFFSET_BIT - #define _FILE_OFFSET_BIT 64 - #endif -#endif - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <errno.h> -#include <fcntl.h> - -#ifdef _WIN32 -#include <sys/utime.h> -#else -#include <utime.h> -#endif -#include <sys/stat.h> - -#include "unzip.h" -#include "archive.h" - -#define CASESENSITIVITY (0) -#define WRITEBUFFERSIZE (8192) -#define MAXFILENAME (256) - -#ifdef _WIN32 -#define USEWIN32IOAPI -#include "iowin32.h" -#include <direct.h> -#endif -/* - mini unzip, demo of unzip package - - usage : - Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] - - list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT - if it exists -*/ - - -/* change_file_date : change the date/time of a file - filename : the filename of the file where date/time must be modified - dosdate : the new date at the MSDos format (4 bytes) - tmu_date : the SAME new date at the tm_unz format */ -void change_file_date(const char *filename, uLong dosdate, tm_unz tmu_date) -{ -#ifdef _WIN32 - HANDLE hFile; - FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; - - hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, - 0,NULL,OPEN_EXISTING,0,NULL); - GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); - DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); - LocalFileTimeToFileTime(&ftLocal,&ftm); - SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); - CloseHandle(hFile); -#else -#if defined(unix) || defined(__APPLE__) - struct utimbuf ut; - struct tm newdate; - newdate.tm_sec = tmu_date.tm_sec; - newdate.tm_min=tmu_date.tm_min; - newdate.tm_hour=tmu_date.tm_hour; - newdate.tm_mday=tmu_date.tm_mday; - newdate.tm_mon=tmu_date.tm_mon; - if (tmu_date.tm_year > 1900) - newdate.tm_year=tmu_date.tm_year - 1900; - else - newdate.tm_year=tmu_date.tm_year ; - newdate.tm_isdst=-1; - - ut.actime=ut.modtime=mktime(&newdate); - utime(filename,&ut); -#endif -#endif -} - - -/* mymkdir and change_file_date are not 100 % portable - As I don't know well Unix, I wait feedback for the unix portion */ - -int mymkdir(const char *dirname) -{ - int ret=0; -#ifdef _WIN32 - ret = _mkdir(dirname); -#else -#if defined unix || defined __APPLE__ - ret = mkdir(dirname,0775); -#endif -#endif - return ret; -} - -int makedir (char *newdir) -{ - char *buffer ; - char *p; - int len = (int)strlen(newdir); - - if (len <= 0) - return 0; - - buffer = (char*)malloc(len+1); - if (buffer==NULL) - { - printf("Error allocating memory\n"); - return UNZ_INTERNALERROR; - } - strcpy(buffer,newdir); - - if (buffer[len-1] == '/') { - buffer[len-1] = '\0'; - } - if (mymkdir(buffer) == 0) - { - free(buffer); - return 1; - } - - p = buffer+1; - while (1) - { - char hold; - - while(*p && *p != '\\' && *p != '/') - p++; - hold = *p; - *p = 0; - if ((mymkdir(buffer) == -1) && (errno == ENOENT)) - { - printf("couldn't create directory %s\n",buffer); - free(buffer); - return 0; - } - if (hold == 0) - break; - *p++ = hold; - } - free(buffer); - return 1; -} - -int do_extract_currentfile(unzFile uf, char * revisionRoot) { - char filename_inzip[256]; - char* filename_withoutpath; - char* p; - int err=UNZ_OK; - FILE *fout=NULL; - void* buf; - uInt size_buf; - - unz_file_info64 file_info; - err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); - - if (err!=UNZ_OK) - { - printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); - return err; - } - - size_buf = WRITEBUFFERSIZE; - buf = (void*)malloc(size_buf); - if (buf==NULL) - { - printf("Error allocating memory\n"); - return UNZ_INTERNALERROR; - } - - p = filename_withoutpath = filename_inzip; - while ((*p) != '\0') - { - if (((*p)=='/') || ((*p)=='\\')) - filename_withoutpath = p+1; - p++; - } - - if ((*filename_withoutpath)=='\0') { - char * dir; - dir = (char *)malloc(strlen(revisionRoot) + strlen(filename_inzip) + 2); - strcpy(dir, revisionRoot); - strcat(dir, "/"); - strcat(dir, filename_inzip); - mymkdir(dir); - free(dir); - } - else - { - const char* write_filename; - int skip=0; - int length; - char * fWFN; - write_filename = filename_inzip; - - length = strlen(write_filename) + strlen(revisionRoot) + 2; - fWFN = (char *)malloc(length); - strcpy(fWFN, revisionRoot); - strcat(fWFN, "/"); - strcat(fWFN, write_filename); - - err = unzOpenCurrentFile(uf); - if (err!=UNZ_OK) - { - printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); - } - - if ((skip==0) && (err==UNZ_OK)) - { - fout=fopen64(fWFN,"wb"); - - /* some zipfile don't contain directory alone before file */ - if ((fout==NULL) && (filename_withoutpath!=(char*)filename_inzip)) - { - char * dir; - int length; - char c=*(filename_withoutpath-1); - *(filename_withoutpath-1)='\0'; - length = strlen(write_filename) + strlen(revisionRoot) + 2; - dir = (char *)malloc(length); - strcpy(dir, revisionRoot); - strcat(dir, "/"); - strcat(dir, write_filename); - makedir(dir); - *(filename_withoutpath-1)=c; - free(dir); - fout=fopen64(fWFN,"wb"); - } - - if (fout==NULL) - { - printf("error opening %s\n",write_filename); - } - } - - if (fout!=NULL) - { - do - { - err = unzReadCurrentFile(uf,buf,size_buf); - if (err<0) - { - printf("error %d with zipfile in unzReadCurrentFile\n",err); - break; - } - if (err>0) - if (fwrite(buf,err,1,fout)!=1) - { - printf("error in writing extracted file\n"); - err=UNZ_ERRNO; - break; - } - } - while (err>0); - if (fout) - fclose(fout); - - if (err==0) - change_file_date(fWFN,file_info.dosDate, - file_info.tmu_date); - } - - if (err==UNZ_OK) - { - err = unzCloseCurrentFile (uf); - if (err!=UNZ_OK) - { - printf("error %d with zipfile in unzCloseCurrentFile\n",err); - } - } - else - unzCloseCurrentFile(uf); /* don't lose the error */ - - free(fWFN); - } - - free(buf); - return err; -} - - -int do_extract(unzFile uf, char * revisionRoot) { - uLong i; - unz_global_info64 gi; - int err; - - err = unzGetGlobalInfo64(uf,&gi); - if (err!=UNZ_OK) - printf("error %d with zipfile in unzGetGlobalInfo \n",err); - - for (i=0;i<gi.number_entry;i++) - { - if (do_extract_currentfile(uf, revisionRoot) != UNZ_OK) - break; - - if ((i+1)<gi.number_entry) - { - err = unzGoToNextFile(uf); - if (err!=UNZ_OK) - { - printf("error %d with zipfile in unzGoToNextFile\n",err); - break; - } - } - } - - return 0; -} - -celix_status_t extractBundle(const char* bundleName, const char* revisionRoot) { - celix_status_t status = CELIX_SUCCESS; - char filename_try[MAXFILENAME+16] = ""; - unzFile uf=NULL; - - if (bundleName!=NULL) - { - -# ifdef USEWIN32IOAPI - zlib_filefunc64_def ffunc; -# endif - - strncpy(filename_try, bundleName,MAXFILENAME-1); - /* strncpy doesnt append the trailing NULL, of the string is too long. */ - filename_try[ MAXFILENAME ] = '\0'; - -# ifdef USEWIN32IOAPI - fill_win32_filefunc64A(&ffunc); - uf = unzOpen2_64(bundleName,&ffunc); -# else - uf = unzOpen64(bundleName); -# endif - if (uf==NULL) - { - strcat(filename_try,".zip"); -# ifdef USEWIN32IOAPI - uf = unzOpen2_64(filename_try,&ffunc); -# else - uf = unzOpen64(filename_try); -# endif - } - } - - if (uf==NULL) - { - printf("Cannot open %s or %s.zip\n",bundleName,bundleName); - status = CELIX_FILE_IO_EXCEPTION; - } else { - if (do_extract(uf, (char*)revisionRoot) != 0) { - status = CELIX_FILE_IO_EXCEPTION; - } - - unzClose(uf); - } - - return status; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/module.c ---------------------------------------------------------------------- diff --git a/framework/private/src/module.c b/framework/private/src/module.c deleted file mode 100644 index e81a1ee..0000000 --- a/framework/private/src/module.c +++ /dev/null @@ -1,281 +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. - */ -/* - * module.c - * - * \date Jul 19, 2010 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "module.h" -#include "manifest_parser.h" -#include "linked_list_iterator.h" - -struct module { - linked_list_pt capabilities; - linked_list_pt requirements; - linked_list_pt wires; - - array_list_pt dependentImporters; - - version_pt version; - char * symbolicName; - bool resolved; - - manifest_pt headerMap; - char * id; - - struct bundle * bundle; -}; - -module_pt module_create(manifest_pt headerMap, const char * moduleId, bundle_pt bundle) { - module_pt module = NULL; - manifest_parser_pt mp; - - if (headerMap != NULL) { - module = (module_pt) malloc(sizeof(*module)); - module->headerMap = headerMap; - module->id = strdup(moduleId); - module->bundle = bundle; - module->resolved = false; - - module->dependentImporters = NULL; - arrayList_create(&module->dependentImporters); - - if (manifestParser_create(module, headerMap, &mp) == CELIX_SUCCESS) { - module->symbolicName = NULL; - manifestParser_getAndDuplicateSymbolicName(mp, &module->symbolicName); - - module->version = NULL; - manifestParser_getBundleVersion(mp, &module->version); - - module->capabilities = NULL; - manifestParser_getCapabilities(mp, &module->capabilities); - - module->requirements = NULL; - manifestParser_getRequirements(mp, &module->requirements); - - module->wires = NULL; - - manifestParser_destroy(mp); - } - } - - return module; -} - -module_pt module_createFrameworkModule(bundle_pt bundle) { - module_pt module; - - module = (module_pt) malloc(sizeof(*module)); - if (module) { - module->id = strdup("0"); - module->symbolicName = strdup("framework"); - module->version = NULL; - version_createVersion(1, 0, 0, "", &module->version); - - linkedList_create(&module->capabilities); - linkedList_create(&module->requirements); - module->dependentImporters = NULL; - arrayList_create(&module->dependentImporters); - module->wires = NULL; - module->headerMap = NULL; - module->resolved = false; - module->bundle = bundle; - } - return module; -} - -void module_destroy(module_pt module) { - arrayList_destroy(module->dependentImporters); - - version_destroy(module->version); - - if (module->wires != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(module->wires, 0); - while (linkedListIterator_hasNext(iter)) { - wire_pt next = linkedListIterator_next(iter); - linkedListIterator_remove(iter); - wire_destroy(next); - } - linkedListIterator_destroy(iter); - linkedList_destroy(module->wires); - } - - if (module->requirements != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(module->requirements, 0); - while (linkedListIterator_hasNext(iter)) { - requirement_pt next = linkedListIterator_next(iter); - linkedListIterator_remove(iter); - requirement_destroy(next); - } - linkedListIterator_destroy(iter); - linkedList_destroy(module->requirements); - } - - if (module->capabilities != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(module->capabilities, 0); - while (linkedListIterator_hasNext(iter)) { - capability_pt next = linkedListIterator_next(iter); - linkedListIterator_remove(iter); - capability_destroy(next); - } - linkedListIterator_destroy(iter); - linkedList_destroy(module->capabilities); - } - - module->headerMap = NULL; - - free(module->id); - free(module->symbolicName); - free(module); -} - -wire_pt module_getWire(module_pt module, const char * serviceName) { - wire_pt wire = NULL; - if (module->wires != NULL) { - linked_list_iterator_pt iterator = linkedListIterator_create(module->wires, 0); - while (linkedListIterator_hasNext(iterator)) { - const char* name; - wire_pt next = linkedListIterator_next(iterator); - capability_pt cap = NULL; - wire_getCapability(next, &cap); - capability_getServiceName(cap, &name); - if (strcasecmp(name, serviceName) == 0) { - wire = next; - } - } - linkedListIterator_destroy(iterator); - } - return wire; -} - -version_pt module_getVersion(module_pt module) { - return module->version; -} - -celix_status_t module_getSymbolicName(module_pt module, const char **symbolicName) { - celix_status_t status = CELIX_SUCCESS; - - if (module == NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - } else { - *symbolicName = module->symbolicName; - } - - return status; -} - -char * module_getId(module_pt module) { - return module->id; -} - -linked_list_pt module_getWires(module_pt module) { - return module->wires; -} - -void module_setWires(module_pt module, linked_list_pt wires) { - int i = 0; - for (i = 0; (module->wires != NULL) && (i < linkedList_size(module->wires)); i++) { - wire_pt wire = (wire_pt) linkedList_get(module->wires, i); - module_pt exporter = NULL; - wire_getExporter(wire, &exporter); - module_removeDependentImporter(exporter, module); - } - - if (module->wires != NULL) { - linked_list_iterator_pt iter = linkedListIterator_create(module->wires, 0); - while (linkedListIterator_hasNext(iter)) { - wire_pt next = linkedListIterator_next(iter); - linkedListIterator_remove(iter); - wire_destroy(next); - } - linkedListIterator_destroy(iter); - linkedList_destroy(module->wires); - } - - module->wires = wires; - - for (i = 0; (module->wires != NULL) && (i < linkedList_size(module->wires)); i++) { - wire_pt wire = (wire_pt) linkedList_get(module->wires, i); - module_pt exporter = NULL; - wire_getExporter(wire, &exporter); - module_addDependentImporter(exporter, module); - } -} - -bool module_isResolved(module_pt module) { - return module->resolved; -} - -void module_setResolved(module_pt module) { - module->resolved = true; -} - -bundle_pt module_getBundle(module_pt module) { - return module->bundle; -} - -linked_list_pt module_getRequirements(module_pt module) { - return module->requirements; -} - -linked_list_pt module_getCapabilities(module_pt module) { - return module->capabilities; -} - -array_list_pt module_getDependentImporters(module_pt module) { - return module->dependentImporters; -} - -void module_addDependentImporter(module_pt module, module_pt importer) { - if (!arrayList_contains(module->dependentImporters, importer)) { - arrayList_add(module->dependentImporters, importer); - } -} - -void module_removeDependentImporter(module_pt module, module_pt importer) { - arrayList_removeElement(module->dependentImporters, importer); -} - -//---------------------------------------------------- -//TODO add implementation (functions not implemented but already exported) -array_list_pt module_getDependentRequirers(module_pt module) { - return NULL; -} - -void module_addDependentRequirer(module_pt module, module_pt requirer) { -} - -void module_removeDependentRequirer(module_pt module, module_pt requirer) { -} -//---------------------------------------------------- - -array_list_pt module_getDependents(module_pt module) { - array_list_pt dependents = NULL; - arrayList_create(&dependents); - - arrayList_addAll(dependents, module->dependentImporters); - - return dependents; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/requirement.c ---------------------------------------------------------------------- diff --git a/framework/private/src/requirement.c b/framework/private/src/requirement.c deleted file mode 100644 index 7ce585c..0000000 --- a/framework/private/src/requirement.c +++ /dev/null @@ -1,114 +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. - */ -/* - * requirement.c - * - * \date Jul 12, 2010 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ -#include <stdlib.h> - -#include "requirement_private.h" -#include "version_range.h" -#include "attribute.h" -#include "celix_log.h" - -celix_status_t requirement_create(hash_map_pt directives, hash_map_pt attributes, requirement_pt *requirement) { - celix_status_t status; - - *requirement = (requirement_pt) malloc(sizeof(**requirement)); - if (!*requirement) { - status = CELIX_ENOMEM; - } else { - attribute_pt serviceAttribute = NULL; - attribute_pt versionAttribute = NULL; - - (*requirement)->attributes = attributes; - (*requirement)->directives = directives; - (*requirement)->versionRange = NULL; - - serviceAttribute = (attribute_pt) hashMap_get(attributes, "service"); - status = attribute_getValue(serviceAttribute, &(*requirement)->targetName); - if (status == CELIX_SUCCESS) { - versionAttribute = (attribute_pt) hashMap_get(attributes, "version"); - if (versionAttribute != NULL) { - char *versionStr = NULL; - attribute_getValue(versionAttribute, &versionStr); - status = versionRange_parse(versionStr, &(*requirement)->versionRange); - } else { - status = versionRange_createInfiniteVersionRange(&(*requirement)->versionRange); - } - } - } - - framework_logIfError(logger, status, NULL, "Cannot create requirement"); - - return status; -} - -celix_status_t requirement_destroy(requirement_pt requirement) { - hash_map_iterator_pt attrIter = hashMapIterator_create(requirement->attributes); - while (hashMapIterator_hasNext(attrIter)) { - attribute_pt attr = hashMapIterator_nextValue(attrIter); - hashMapIterator_remove(attrIter); - attribute_destroy(attr); - } - hashMapIterator_destroy(attrIter); - hashMap_destroy(requirement->attributes, false, false); - hashMap_destroy(requirement->directives, false, false); - - requirement->attributes = NULL; - requirement->directives = NULL; - - versionRange_destroy(requirement->versionRange); - requirement->versionRange = NULL; - - free(requirement); - - return CELIX_SUCCESS; -} - -celix_status_t requirement_getVersionRange(requirement_pt requirement, version_range_pt *range) { - *range = requirement->versionRange; - return CELIX_SUCCESS; -} - -celix_status_t requirement_getTargetName(requirement_pt requirement, const char **targetName) { - *targetName = requirement->targetName; - return CELIX_SUCCESS; -} - -celix_status_t requirement_isSatisfied(requirement_pt requirement, capability_pt capability, bool *inRange) { - celix_status_t status; - version_pt version = NULL; - version_range_pt range = NULL; - - status = capability_getVersion(capability, &version); - if (status == CELIX_SUCCESS) { - status = requirement_getVersionRange(requirement, &range); - if (status == CELIX_SUCCESS) { - status = versionRange_isInRange(range, version, inRange); - } - } - - framework_logIfError(logger, status, NULL, "Cannot check if requirement is satisfied"); - - return status; -} http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/framework/private/src/resolver.c ---------------------------------------------------------------------- diff --git a/framework/private/src/resolver.c b/framework/private/src/resolver.c deleted file mode 100644 index 256eff5..0000000 --- a/framework/private/src/resolver.c +++ /dev/null @@ -1,495 +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. - */ -/* - * resolver.c - * - * \date Jul 13, 2010 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - -#include "resolver.h" -#include "linked_list_iterator.h" -#include "bundle.h" -#include "celix_log.h" - -struct capabilityList { - char * serviceName; - linked_list_pt capabilities; -}; - -typedef struct capabilityList * capability_list_pt; - -struct candidateSet { - module_pt module; - requirement_pt requirement; - linked_list_pt candidates; -}; - -typedef struct candidateSet * candidate_set_pt; - -// List containing module_ts -linked_list_pt m_modules = NULL; -// List containing capability_t_LISTs -linked_list_pt m_unresolvedServices = NULL; -// List containing capability_t_LISTs -linked_list_pt m_resolvedServices = NULL; - -int resolver_populateCandidatesMap(hash_map_pt candidatesMap, module_pt targetModule); -capability_list_pt resolver_getCapabilityList(linked_list_pt list, const char* name); -void resolver_removeInvalidCandidate(module_pt module, hash_map_pt candidates, linked_list_pt invalid); -linked_list_pt resolver_populateWireMap(hash_map_pt candidates, module_pt importer, linked_list_pt wireMap); - -linked_list_pt resolver_resolve(module_pt root) { - hash_map_pt candidatesMap = NULL; - linked_list_pt wireMap = NULL; - linked_list_pt resolved = NULL; - hash_map_iterator_pt iter = NULL; - - if (module_isResolved(root)) { - return NULL; - } - - candidatesMap = hashMap_create(NULL, NULL, NULL, NULL); - - if (resolver_populateCandidatesMap(candidatesMap, root) != 0) { - hash_map_iterator_pt iter = hashMapIterator_create(candidatesMap); - while (hashMapIterator_hasNext(iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); - linked_list_pt value = hashMapEntry_getValue(entry); - hashMapIterator_remove(iter); - if (value != NULL) { - linked_list_iterator_pt candSetIter = linkedListIterator_create(value, 0); - while (linkedListIterator_hasNext(candSetIter)) { - candidate_set_pt set = linkedListIterator_next(candSetIter); - linkedList_destroy(set->candidates); - free(set); - linkedListIterator_remove(candSetIter); - } - linkedListIterator_destroy(candSetIter); - linkedList_destroy(value); - } - } - hashMapIterator_destroy(iter); - hashMap_destroy(candidatesMap, false, false); - return NULL; - } - - linkedList_create(&wireMap); - resolved = resolver_populateWireMap(candidatesMap, root, wireMap); - iter = hashMapIterator_create(candidatesMap); - while (hashMapIterator_hasNext(iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); - linked_list_pt value = hashMapEntry_getValue(entry); - hashMapIterator_remove(iter); - if (value != NULL) { - linked_list_iterator_pt candSetIter = linkedListIterator_create(value, 0); - while (linkedListIterator_hasNext(candSetIter)) { - candidate_set_pt set = linkedListIterator_next(candSetIter); - linkedList_destroy(set->candidates); - free(set); - linkedListIterator_remove(candSetIter); - } - linkedListIterator_destroy(candSetIter); - linkedList_destroy(value); - } - } - hashMapIterator_destroy(iter); - hashMap_destroy(candidatesMap, false, false); - return resolved; -} - -int resolver_populateCandidatesMap(hash_map_pt candidatesMap, module_pt targetModule) { - linked_list_pt candSetList; - linked_list_pt candidates; - linked_list_pt invalid; - - if (hashMap_containsKey(candidatesMap, targetModule)) { - return 0; - } - - hashMap_put(candidatesMap, targetModule, NULL); - - if (linkedList_create(&candSetList) == CELIX_SUCCESS) { - int i; - for (i = 0; i < linkedList_size(module_getRequirements(targetModule)); i++) { - capability_list_pt capList; - requirement_pt req; - const char *targetName = NULL; - req = (requirement_pt) linkedList_get(module_getRequirements(targetModule), i); - requirement_getTargetName(req, &targetName); - capList = resolver_getCapabilityList(m_resolvedServices, targetName); - - if (linkedList_create(&candidates) == CELIX_SUCCESS) { - int c; - for (c = 0; (capList != NULL) && (c < linkedList_size(capList->capabilities)); c++) { - capability_pt cap = (capability_pt) linkedList_get(capList->capabilities, c); - bool satisfied = false; - requirement_isSatisfied(req, cap, &satisfied); - if (satisfied) { - linkedList_addElement(candidates, cap); - } - } - capList = resolver_getCapabilityList(m_unresolvedServices, targetName); - for (c = 0; (capList != NULL) && (c < linkedList_size(capList->capabilities)); c++) { - capability_pt cap = (capability_pt) linkedList_get(capList->capabilities, c); - bool satisfied = false; - requirement_isSatisfied(req, cap, &satisfied); - if (satisfied) { - linkedList_addElement(candidates, cap); - } - } - - if (linkedList_size(candidates) > 0) { - linked_list_iterator_pt iterator = NULL; - for (iterator = linkedListIterator_create(candidates, 0); linkedListIterator_hasNext(iterator);) { - capability_pt candidate = (capability_pt) linkedListIterator_next(iterator); - module_pt module = NULL; - capability_getModule(candidate, &module); - if (!module_isResolved(module)) { - if (resolver_populateCandidatesMap(candidatesMap, module) != 0) { - linkedListIterator_remove(iterator); - } - } - } - linkedListIterator_destroy(iterator); - } - - if (linkedList_size(candidates) == 0) { - if (linkedList_create(&invalid) == CELIX_SUCCESS) { - const char *name = NULL; - resolver_removeInvalidCandidate(targetModule, candidatesMap, invalid); - - module_getSymbolicName(targetModule, &name); - - linkedList_destroy(invalid); - fw_log(logger, OSGI_FRAMEWORK_LOG_INFO, "Unable to resolve: %s, %s\n", name, targetName); - } - linkedList_destroy(candidates); - linkedList_destroy(candSetList); - return -1; - } else if (linkedList_size(candidates) > 0) { - candidate_set_pt cs = (candidate_set_pt) malloc(sizeof(*cs)); - cs->candidates = candidates; - cs->module = targetModule; - cs->requirement = req; - linkedList_addElement(candSetList, cs); - } - - } - } - hashMap_put(candidatesMap, targetModule, candSetList); - } - return 0; -} - -void resolver_removeInvalidCandidate(module_pt invalidModule, hash_map_pt candidates, linked_list_pt invalid) { - hash_map_iterator_pt iterator; - hashMap_remove(candidates, invalidModule); - - for (iterator = hashMapIterator_create(candidates); hashMapIterator_hasNext(iterator);) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator); - linked_list_pt candSetList = (linked_list_pt) hashMapEntry_getValue(entry); - if (candSetList != NULL) { - linked_list_iterator_pt itCandSetList; - for (itCandSetList = linkedListIterator_create(candSetList, 0); linkedListIterator_hasNext(itCandSetList);) { - candidate_set_pt set = (candidate_set_pt) linkedListIterator_next(itCandSetList); - linked_list_iterator_pt candIter; - for (candIter = linkedListIterator_create(set->candidates, 0); linkedListIterator_hasNext(candIter);) { - capability_pt candCap = (capability_pt) linkedListIterator_next(candIter); - module_pt module = NULL; - capability_getModule(candCap, &module); - if (module == invalidModule) { - linkedListIterator_remove(candIter); - if (linkedList_size(set->candidates) == 0) { - linkedListIterator_remove(itCandSetList); - if (module != invalidModule && linkedList_contains(invalid, module)) { - linkedList_addElement(invalid, module); - } - } - break; - } - } - linkedListIterator_destroy(candIter); - } - linkedListIterator_destroy(itCandSetList); - } - } - hashMapIterator_destroy(iterator); - - if (linkedList_size(invalid) > 0) { - while (!linkedList_isEmpty(invalid)) { - module_pt m = (module_pt) linkedList_removeIndex(invalid, 0); - resolver_removeInvalidCandidate(m, candidates, invalid); - } - } -} - -void resolver_addModule(module_pt module) { - - if (m_modules == NULL) { - linkedList_create(&m_modules); - linkedList_create(&m_unresolvedServices); - linkedList_create(&m_resolvedServices); - } - - if (m_modules != NULL && m_unresolvedServices != NULL) { - int i; - - linkedList_addElement(m_modules, module); - - for (i = 0; i < linkedList_size(module_getCapabilities(module)); i++) { - const char *serviceName = NULL; - capability_list_pt list = NULL; - capability_pt cap; - - cap = (capability_pt) linkedList_get(module_getCapabilities(module), i); - capability_getServiceName(cap, &serviceName); - list = resolver_getCapabilityList(m_unresolvedServices, serviceName); - if (list == NULL) { - list = (capability_list_pt) malloc(sizeof(*list)); - if (list != NULL) { - list->serviceName = strdup(serviceName); - if (linkedList_create(&list->capabilities) == CELIX_SUCCESS) { - linkedList_addElement(m_unresolvedServices, list); - } - else{ - free(list->serviceName); - free(list); - list=NULL; - } - } - } - if(list != NULL){ - linkedList_addElement(list->capabilities, cap); - } - } - } -} - -void resolver_removeModule(module_pt module) { - linked_list_pt caps = NULL; - linkedList_removeElement(m_modules, module); - caps = module_getCapabilities(module); - if (caps != NULL) { - int i = 0; - for (i = 0; i < linkedList_size(caps); i++) { - capability_pt cap = (capability_pt) linkedList_get(caps, i); - const char *serviceName = NULL; - capability_list_pt list; - capability_getServiceName(cap, &serviceName); - list = resolver_getCapabilityList(m_unresolvedServices, serviceName); - if (list != NULL) { - linkedList_removeElement(list->capabilities, cap); - - if (linkedList_isEmpty(list->capabilities)) { - linkedList_removeElement(m_unresolvedServices, list); - linkedList_destroy(list->capabilities); - free(list->serviceName); - free(list); - } - } - list = resolver_getCapabilityList(m_resolvedServices, serviceName); - if (list != NULL) { - linkedList_removeElement(list->capabilities, cap); - - if (linkedList_isEmpty(list->capabilities)) { - linkedList_removeElement(m_resolvedServices, list); - linkedList_destroy(list->capabilities); - free(list->serviceName); - free(list); - } - } - } - } - if (linkedList_isEmpty(m_modules)) { - linkedList_destroy(m_modules); - m_modules = NULL; - - if (!linkedList_isEmpty(m_unresolvedServices)) { - // #TODO: Something is wrong, not all modules have been removed from the resolver - fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Unexpected entries in unresolved module list"); - } - linkedList_destroy(m_unresolvedServices); - m_unresolvedServices = NULL; - if (!linkedList_isEmpty(m_resolvedServices)) { - // #TODO: Something is wrong, not all modules have been removed from the resolver - fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Unexpected entries in resolved module list"); - } - linkedList_destroy(m_resolvedServices); - m_resolvedServices = NULL; - } -} - -void resolver_moduleResolved(module_pt module) { - - if (module_isResolved(module)) { - linked_list_pt capsCopy = NULL; - - if (linkedList_create(&capsCopy) == CELIX_SUCCESS) { - linked_list_pt wires = NULL; - int capIdx; - - for (capIdx = 0; (module_getCapabilities(module) != NULL) && (capIdx < linkedList_size(module_getCapabilities(module))); capIdx++) { - capability_pt cap = (capability_pt) linkedList_get(module_getCapabilities(module), capIdx); - const char *serviceName = NULL; - capability_list_pt list; - capability_getServiceName(cap, &serviceName); - list = resolver_getCapabilityList(m_unresolvedServices, serviceName); - if(list != NULL){ - linkedList_removeElement(list->capabilities, cap); - } - - linkedList_addElement(capsCopy, cap); - } - - wires = module_getWires(module); - for (capIdx = 0; (capsCopy != NULL) && (capIdx < linkedList_size(capsCopy)); capIdx++) { - capability_pt cap = linkedList_get(capsCopy, capIdx); - - int wireIdx = 0; - for (wireIdx = 0; (wires != NULL) && (wireIdx < linkedList_size(wires)); wireIdx++) { - wire_pt wire = (wire_pt) linkedList_get(wires, wireIdx); - requirement_pt req = NULL; - bool satisfied = false; - wire_getRequirement(wire, &req); - requirement_isSatisfied(req, cap, &satisfied); - if (satisfied) { - linkedList_set(capsCopy, capIdx, NULL); - break; - } - } - } - - for (capIdx = 0; (capsCopy != NULL) && (capIdx < linkedList_size(capsCopy)); capIdx++) { - capability_pt cap = linkedList_get(capsCopy, capIdx); - - if (cap != NULL) { - const char *serviceName = NULL; - capability_list_pt list = NULL; - capability_getServiceName(cap, &serviceName); - - list = resolver_getCapabilityList(m_resolvedServices, serviceName); - if (list == NULL) { - list = (capability_list_pt) malloc(sizeof(*list)); - if (list != NULL) { - list->serviceName = strdup(serviceName); - if (linkedList_create(&list->capabilities) == CELIX_SUCCESS) { - linkedList_addElement(m_resolvedServices, list); - } - else{ - free(list->serviceName); - free(list); - list=NULL; - } - } - } - if(list != NULL){ - linkedList_addElement(list->capabilities, cap); - } - } - } - - linkedList_destroy(capsCopy); - } - } -} - -capability_list_pt resolver_getCapabilityList(linked_list_pt list, const char * name) { - capability_list_pt capabilityList = NULL; - linked_list_iterator_pt iterator = linkedListIterator_create(list, 0); - while (linkedListIterator_hasNext(iterator)) { - capability_list_pt services = (capability_list_pt) linkedListIterator_next(iterator); - if (strcmp(services->serviceName, name) == 0) { - capabilityList = services; - break; - } - } - linkedListIterator_destroy(iterator); - return capabilityList; -} - -linked_list_pt resolver_populateWireMap(hash_map_pt candidates, module_pt importer, linked_list_pt wireMap) { - linked_list_pt serviceWires; - - if (candidates && importer && wireMap) { - linked_list_pt candSetList = NULL; - bool resolved = false; - - if (module_isResolved(importer)) { - // already resolved - resolved = true; - } - if (!resolved) { - bool self = false; - linked_list_iterator_pt wit = linkedListIterator_create(wireMap, 0); - while (linkedListIterator_hasNext(wit)) { - importer_wires_pt iw = linkedListIterator_next(wit); - if (iw->importer == importer) { - // Do not resolve yourself - self = true; - break; - } - } - linkedListIterator_destroy(wit); - - if (!self) { - candSetList = (linked_list_pt) hashMap_get(candidates, importer); - - if (linkedList_create(&serviceWires) == CELIX_SUCCESS) { -// if (linkedList_create(&emptyWires) == CELIX_SUCCESS) { - int candSetIdx = 0; - - // hashMap_put(wireMap, importer, emptyWires); - - const char *mname = NULL; - module_getSymbolicName(importer, &mname); - - importer_wires_pt importerWires = malloc(sizeof(*importerWires)); - importerWires->importer = importer; - importerWires->wires = NULL; - linkedList_addElement(wireMap, importerWires); - - for (candSetIdx = 0; candSetIdx < linkedList_size(candSetList); candSetIdx++) { - candidate_set_pt cs = (candidate_set_pt) linkedList_get(candSetList, candSetIdx); - - module_pt module = NULL; - capability_getModule(((capability_pt) linkedList_get(cs->candidates, 0)), &module); - if (importer != module) { - wire_pt wire = NULL; - wire_create(importer, cs->requirement, module, ((capability_pt) linkedList_get(cs->candidates, 0)), &wire); - linkedList_addElement(serviceWires, wire); - } - - wireMap = resolver_populateWireMap(candidates, module, wireMap); - } - - importerWires->wires = serviceWires; - // hashMap_put(wireMap, importer, serviceWires); -// } - } - } - } - } - - return wireMap; -}
