Return-Path: X-Original-To: apmail-corinthia-commits-archive@minotaur.apache.org Delivered-To: apmail-corinthia-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D3F3A105B4 for ; Thu, 1 Jan 2015 13:19:10 +0000 (UTC) Received: (qmail 92472 invoked by uid 500); 1 Jan 2015 13:19:11 -0000 Delivered-To: apmail-corinthia-commits-archive@corinthia.apache.org Received: (qmail 92455 invoked by uid 500); 1 Jan 2015 13:19:11 -0000 Mailing-List: contact commits-help@corinthia.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@corinthia.incubator.apache.org Delivered-To: mailing list commits@corinthia.incubator.apache.org Received: (qmail 92446 invoked by uid 99); 1 Jan 2015 13:19:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jan 2015 13:19:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 01 Jan 2015 13:18:48 +0000 Received: (qmail 90646 invoked by uid 99); 1 Jan 2015 13:17:30 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jan 2015 13:17:30 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id D350DA3BCB7; Thu, 1 Jan 2015 13:17:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jani@apache.org To: commits@corinthia.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-corinthia git commit: changed from array to dyn. alloc. Date: Thu, 1 Jan 2015 13:17:29 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-corinthia Updated Branches: refs/heads/RTC_platform b159258cf -> f9c5ca137 changed from array to dyn. alloc. Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/f9c5ca13 Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/f9c5ca13 Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/f9c5ca13 Branch: refs/heads/RTC_platform Commit: f9c5ca137f9a079e49a6118f4ad0fcbf0db3cb7e Parents: b159258 Author: jani Authored: Thu Jan 1 14:16:55 2015 +0100 Committer: jani Committed: Thu Jan 1 14:16:55 2015 +0100 ---------------------------------------------------------------------- DocFormats/core/src/lib/DFZipFile.c | 32 +++++----- DocFormats/platform/headers/DFPlatform.h | 20 +++--- DocFormats/platform/src/Wrapper.c | 87 +++++++++++++-------------- 3 files changed, 71 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f9c5ca13/DocFormats/core/src/lib/DFZipFile.c ---------------------------------------------------------------------- diff --git a/DocFormats/core/src/lib/DFZipFile.c b/DocFormats/core/src/lib/DFZipFile.c index 73b3fef..451934e 100644 --- a/DocFormats/core/src/lib/DFZipFile.c +++ b/DocFormats/core/src/lib/DFZipFile.c @@ -34,27 +34,27 @@ static int zipError(DFError **error, const char *format, ...) int DFUnzip(const char *zipFilename, DFStorage *storage, DFError **error) { - char entryName[4096]; - int zipId; + char entryName[4096]; + DFextZipHandleP zipHandle; - zipId = DFextZipOpen(zipFilename, 1); - if (zipId < 0) + zipHandle = DFextZipOpen(zipFilename, 1); + if (!zipHandle) return zipError(error,"Cannot open file"); int ret; - for (; (ret = DFextZipOpenNextFile(zipId, entryName, sizeof(entryName))) > 0;) { + for (; (ret = DFextZipOpenNextFile(zipHandle, entryName, sizeof(entryName))) > 0;) { DFBuffer *content = DFBufferNew(); unsigned char buf[4096]; int r; - while (0 < (r = DFextZipReadCurrentFile(zipId, buf, sizeof(buf)))) + while (0 < (r = DFextZipReadCurrentFile(zipHandle, buf, sizeof(buf)))) DFBufferAppendData(content,(void *)buf,r); if (0 > r) { DFBufferRelease(content); return zipError(error,"%s: decompression failed",entryName); } - if (DFextZipCloseFile(zipId) < 0) { + if (DFextZipCloseFile(zipHandle) < 0) { DFBufferRelease(content); return zipError(error,"%s: decompression failed",entryName); } @@ -69,20 +69,20 @@ int DFUnzip(const char *zipFilename, DFStorage *storage, DFError **error) if (ret < 0) return zipError(error,"Zip directory is corrupt"); - DFextZipClose(zipId); + DFextZipClose(zipHandle); return 1; } -static int zipAddFile(int zipId, const char *dest, DFBuffer *content, DFError **error) +static int zipAddFile(DFextZipHandleP zipHandle, const char *dest, DFBuffer *content, DFError **error) { - if (DFextZipOpenNextFile(zipId, dest, 0) < 0) + if (DFextZipOpenNextFile(zipHandle, dest, 0) < 0) return zipError(error,"%s: Cannot create entry in zip file",dest); - if (DFextZipWriteCurrentFile(zipId, content->data, (unsigned int)content->len) < 0) + if (DFextZipWriteCurrentFile(zipHandle, content->data, (unsigned int)content->len) < 0) return zipError(error,"%s: Error writing to entry in zip file",dest); - if (DFextZipCloseFile(zipId) <0) + if (DFextZipCloseFile(zipHandle) <0) return zipError(error,"%s: Error closing entry in zip file",dest); return 1; } @@ -94,10 +94,10 @@ int DFZip(const char *zipFilename, DFStorage *storage, DFError **error) const char **allPaths = NULL; DFBuffer *content = NULL; int ok = 0; - int zipId; + DFextZipHandleP zipHandle; allPaths = DFStorageList(storage,error); - if (allPaths == NULL || (zipId = DFextZipOpen(zipFilename, 0)) < 0) + if (allPaths == NULL || !(zipHandle = DFextZipOpen(zipFilename, 0))) { DFErrorFormat(error,"Cannot create file"); } @@ -113,7 +113,7 @@ int DFZip(const char *zipFilename, DFStorage *storage, DFError **error) goto end; } - if (!zipAddFile(zipId, path, content, error)) + if (!zipAddFile(zipHandle, path, content, error)) goto end; } @@ -123,6 +123,6 @@ int DFZip(const char *zipFilename, DFStorage *storage, DFError **error) end: DFBufferRelease(content); free(allPaths); - DFextZipClose(zipId); + DFextZipClose(zipHandle); return ok; } http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f9c5ca13/DocFormats/platform/headers/DFPlatform.h ---------------------------------------------------------------------- diff --git a/DocFormats/platform/headers/DFPlatform.h b/DocFormats/platform/headers/DFPlatform.h index 7196906..3d379d4 100755 --- a/DocFormats/platform/headers/DFPlatform.h +++ b/DocFormats/platform/headers/DFPlatform.h @@ -35,13 +35,19 @@ typedef void (*DFOnceFunction)(void); void DFInitOnce(DFOnce *once, DFOnceFunction fun); // Zip functions -#define MAX_ZIP_OPEN 10 -int DFextZipOpen(const char *zipFilename, int doUnzip); -int DFextZipClose(int zipId); +typedef struct { + void *handle; + int zipFlag; + int zipFirst; + } DFextZipHandle; +typedef DFextZipHandle * DFextZipHandleP; -int DFextZipOpenNextFile(int zipId, char *entryName, const int maxName); -int DFextZipCloseFile(zipId); +DFextZipHandleP DFextZipOpen(const char *zipFilename, int doUnzip); +int DFextZipClose(DFextZipHandleP zipHandle); -int DFextZipReadCurrentFile(int zipId, char *buf, const int maxLen); -int DFextZipWriteCurrentFile(int zipId, char *buf, const int len); +int DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName, const int maxName); +int DFextZipCloseFile(DFextZipHandleP zipHandle); + +int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, char *buf, const int maxLen); +int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, char *buf, const int len); #endif http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f9c5ca13/DocFormats/platform/src/Wrapper.c ---------------------------------------------------------------------- diff --git a/DocFormats/platform/src/Wrapper.c b/DocFormats/platform/src/Wrapper.c index 49a4121..d27be99 100644 --- a/DocFormats/platform/src/Wrapper.c +++ b/DocFormats/platform/src/Wrapper.c @@ -12,94 +12,91 @@ // See the License for the specific language governing permissions and // limitations under the License. #include +#include #include "DFPlatform.h" #include "unzip.h" #include "zip.h" -// This file contains functions to isolate external libraries -static struct { - unzFile myZipFile; - int myZipFlag; - int myZipFirst; -} myZipStorage[MAX_ZIP_OPEN]; - - -int DFextZipOpen(const char *zipFilename, int doUnzip) { - int zipId; - - // find an empty slot - for (zipId = 0; zipId < MAX_ZIP_OPEN && myZipStorage[zipId].myZipFile; ++zipId) ; - if (zipId >= MAX_ZIP_OPEN) - return -1; +DFextZipHandleP DFextZipOpen(const char *zipFilename, int doUnzip) { + DFextZipHandleP zipHandle = malloc(sizeof(DFextZipHandle)); + + // no more memory + if (!zipHandle) + return NULL; // Open file - myZipStorage[zipId].myZipFirst = 1; - myZipStorage[zipId].myZipFlag = doUnzip; + zipHandle->zipFirst = 1; + zipHandle->zipFlag = doUnzip; if (doUnzip) - myZipStorage[zipId].myZipFile = unzOpen(zipFilename); + zipHandle->handle = unzOpen(zipFilename); else - myZipStorage[zipId].myZipFile = zipOpen(zipFilename, APPEND_STATUS_CREATE); + zipHandle->handle = zipOpen(zipFilename, APPEND_STATUS_CREATE); + + if (zipHandle->handle) + return zipHandle; - return (myZipStorage[zipId].myZipFile) ? zipId : -1; + free(zipHandle); + return NULL; } -int DFextZipClose(int zipId) +int DFextZipClose(DFextZipHandleP zipHandle) { int rc; - if (myZipStorage[zipId].myZipFile) { - if (myZipStorage[zipId].myZipFlag) - rc = (unzClose(myZipStorage[zipId].myZipFile) == UNZ_OK); + if (zipHandle->handle) { + if (zipHandle->zipFlag) + rc = (unzClose(zipHandle->handle) == UNZ_OK); else - rc = (zipClose(myZipStorage[zipId].myZipFile, NULL) == ZIP_OK); - myZipStorage[zipId].myZipFile = NULL; + rc = (zipClose(zipHandle->handle, NULL) == ZIP_OK); + zipHandle->handle = NULL; } - return rc ? 0 : -1; + free(zipHandle); + return rc ? 1 : -1; } -int DFextZipOpenNextFile(int zipId, char *entryName, const int maxName) +int DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName, const int maxName) { int rc; - if (myZipStorage[zipId].myZipFlag) { + if (zipHandle->zipFlag) { unz_file_info info; // handling of first file and all others are different - if (myZipStorage[zipId].myZipFirst) { - rc = unzGoToFirstFile(myZipStorage[zipId].myZipFile); - myZipStorage[zipId].myZipFirst = 0; + if (zipHandle->zipFirst) { + rc = unzGoToFirstFile(zipHandle->handle); + zipHandle->zipFirst = 0; } else - rc = unzGoToNextFile(myZipStorage[zipId].myZipFile); + rc = unzGoToNextFile(zipHandle->handle); // Error or past last file if (rc != UNZ_OK) return (rc == UNZ_END_OF_LIST_OF_FILE) ? 0 : -1; // get file name - if (unzGetCurrentFileInfo(myZipStorage[zipId].myZipFile, &info, entryName, maxName, NULL, 0, NULL, 0) != UNZ_OK) + if (unzGetCurrentFileInfo(zipHandle->handle, &info, entryName, maxName, NULL, 0, NULL, 0) != UNZ_OK) return -1; // check for prefix "/" and if present skip file if (entryName[strlen(entryName) - 1] == '/') - return DFextZipOpenNextFile(zipId, entryName, maxName); + return DFextZipOpenNextFile(zipHandle, entryName, maxName); // open Regular file - if (unzOpenCurrentFile(myZipStorage[zipId].myZipFile) != UNZ_OK) + if (unzOpenCurrentFile(zipHandle->handle) != UNZ_OK) return -1; } else { zip_fileinfo fileinfo; memset(&fileinfo, 0, sizeof(fileinfo)); - if (zipOpenNewFileInZip(myZipStorage[zipId].myZipFile, + if (zipOpenNewFileInZip(zipHandle->handle, entryName, &fileinfo, NULL, 0, @@ -116,25 +113,25 @@ int DFextZipOpenNextFile(int zipId, char *entryName, const int maxName) -int DFextZipCloseFile(int zipId) +int DFextZipCloseFile(DFextZipHandleP zipHandle) { - if (myZipStorage[zipId].myZipFlag) - return (unzCloseCurrentFile(myZipStorage[zipId].myZipFile) != UNZ_OK) ? -1 : 1; + if (zipHandle->zipFlag) + return (unzCloseCurrentFile(zipHandle->handle) != UNZ_OK) ? -1 : 1; else - return (zipCloseFileInZip(myZipStorage[zipId].myZipFile) != UNZ_OK) ? -1 : 1; + return (zipCloseFileInZip(zipHandle->handle) != UNZ_OK) ? -1 : 1; } -int DFextZipReadCurrentFile(int zipId, char *buf, const int maxLen) +int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, char *buf, const int maxLen) { - return unzReadCurrentFile(myZipStorage[zipId].myZipFile, buf, maxLen); + return unzReadCurrentFile(zipHandle->handle, buf, maxLen); } -int DFextZipWriteCurrentFile(int zipId, char *buf, const int len) +int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, char *buf, const int len) { - return (zipWriteInFileInZip(myZipStorage[zipId].myZipFile, buf, len) == ZIP_OK) ? 1 : -1; + return (zipWriteInFileInZip(zipHandle->handle, buf, len) == ZIP_OK) ? 1 : -1; }