You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by ja...@apache.org on 2015/07/29 22:20:28 UTC
[3/3] incubator-corinthia git commit: work
work
Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/1257d3f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/1257d3f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/1257d3f9
Branch: refs/heads/newZipExperiment
Commit: 1257d3f945db748552a49f1166960d56b5713a7a
Parents: be6c3ce
Author: jani <ja...@apache.org>
Authored: Tue Jul 28 20:45:34 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Tue Jul 28 20:45:34 2015 +0200
----------------------------------------------------------------------
DocFormats/headers/DFPlatform.h | 7 +-
DocFormats/platform/CMakeLists.txt | 3 +-
DocFormats/platform/src/Wrapper.c | 184 ---------------------
DocFormats/platform/src/Wrapper_zip.c | 250 +++++++++++++++++++++++++++++
4 files changed, 255 insertions(+), 189 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/1257d3f9/DocFormats/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/headers/DFPlatform.h b/DocFormats/headers/DFPlatform.h
index d594779..f55ccc2 100644
--- a/DocFormats/headers/DFPlatform.h
+++ b/DocFormats/headers/DFPlatform.h
@@ -70,13 +70,12 @@ void DFInitOnce(DFOnce *once, DFOnceFunction fun);
// Zip functions
typedef struct {
- int x;
- } DFextZipHandle;
-
+ FILE *zip;
+} DFextZipHandle;
typedef DFextZipHandle * DFextZipHandleP;
-DFextZipHandleP DFextZipOpen(const char *zipFilename);
+DFextZipHandleP DFextZipOpen(const char *zipFilename);
DFextZipHandleP DFextZipCreate(const char *zipFilename);
int DFextZipClose(DFextZipHandleP zipHandle);
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/1257d3f9/DocFormats/platform/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/DocFormats/platform/CMakeLists.txt b/DocFormats/platform/CMakeLists.txt
index f3ba68b..c31c031 100644
--- a/DocFormats/platform/CMakeLists.txt
+++ b/DocFormats/platform/CMakeLists.txt
@@ -93,7 +93,8 @@ set(GroupSrc
src/Linux.c
src/Unix.c
src/Win32.c
- src/Wrapper.c)
+ src/Wrapper.c
+ src/Wrapper_zip.c)
set(GroupTests
tests/OStests.c
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/1257d3f9/DocFormats/platform/src/Wrapper.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper.c b/DocFormats/platform/src/Wrapper.c
index 1ca4ef2..c397bf4 100644
--- a/DocFormats/platform/src/Wrapper.c
+++ b/DocFormats/platform/src/Wrapper.c
@@ -14,194 +14,10 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "DFPlatform.h"
-#include "unzip.h"
-#include "zip.h"
-
-
-DFextZipHandleP DFextZipOpen(const char *zipFilename) {
- DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
-#if 0
- // no more memory
- if (!zipHandle)
- return NULL;
-
- // Open file
- zipHandle->zipFirst = 1;
- zipHandle->handle = unzOpen(zipFilename);
-
- if (zipHandle->handle)
- return zipHandle;
-
- free(zipHandle);
-#endif
- return NULL;
-}
-
-
-
-DFextZipHandleP OLD_DFextZipOpen(const char *zipFilename) {
- DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
-
-#if 0
- // no more memory
- if (!zipHandle)
- return NULL;
-
- // Open file
- zipHandle->zipFirst = 1;
- zipHandle->handle = unzOpen(zipFilename);
-
- if (zipHandle->handle)
- return zipHandle;
-
- free(zipHandle);
-#endif
- return NULL;
-}
-
-
-
-DFextZipHandleP DFextZipCreate(const char *zipFilename) {
- DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
-
-#if 0
- // no more memory
- if (!zipHandle)
- return NULL;
-
- // Open file
- zipHandle->zipFirst = 1;
- zipHandle->handle = zipOpen(zipFilename, APPEND_STATUS_CREATE);
-
- if (zipHandle->handle)
- return zipHandle;
-
- free(zipHandle);
-#endif
- return NULL;
-}
-
-
-int DFextZipClose(DFextZipHandleP zipHandle)
-{
- int rc = 0;
-
-#if 0
- if (zipHandle->handle) {
- if (zipHandle->zipFlag)
- rc = (unzClose(zipHandle->handle) == UNZ_OK);
- else
- rc = (zipClose(zipHandle->handle, NULL) == ZIP_OK);
- zipHandle->handle = NULL;
- }
-
- free(zipHandle);
-#endif
- return rc ? 1 : -1;
-}
-
-
-
-int DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName, const int maxName)
-{
-#if 0
- int rc;
-
- if (zipHandle->zipFlag) {
- unz_file_info info;
-
- // handling of first file and all others are different
- if (zipHandle->zipFirst) {
- rc = unzGoToFirstFile(zipHandle->handle);
- zipHandle->zipFirst = 0;
- }
- else
- 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(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(zipHandle, entryName, maxName);
-
- // open Regular file
- if (unzOpenCurrentFile(zipHandle->handle) != UNZ_OK)
- return -1;
- }
- else {
- return -1; // Zip file is open in write-only mode
- }
-
- // ready to read
-#endif
- return 1;
-}
-
-int DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName)
-{
-#if 0
- zip_fileinfo fileinfo;
- memset(&fileinfo, 0, sizeof(fileinfo));
-
- if (zipHandle->zipFlag)
- return -1; // Zip file is open in read-only mode
-
- if (zipOpenNewFileInZip(zipHandle->handle,
- entryName,
- &fileinfo,
- NULL, 0,
- NULL, 0,
- NULL,
- Z_DEFLATED,
- Z_DEFAULT_COMPRESSION) != ZIP_OK) {
- return -1;
- }
-#endif
- return 1;
-}
-
-int DFextZipCloseFile(DFextZipHandleP zipHandle)
-{
-#if 0
- if (zipHandle->zipFlag)
- return (unzCloseCurrentFile(zipHandle->handle) != UNZ_OK) ? -1 : 1;
- else
- return (zipCloseFileInZip(zipHandle->handle) != UNZ_OK) ? -1 : 1;
-#endif
- return 0;
-}
-
-
-
-
-int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, void *buf, const int maxLen)
-{
-#if 0
- return unzReadCurrentFile(zipHandle->handle, buf, maxLen);
-#endif
- return 0;
-}
-
-
-
-int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, const void *buf, const int len)
-{
-#if 0
- return (zipWriteInFileInZip(zipHandle->handle, buf, len) == ZIP_OK) ? 1 : -1;
-#endif
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/1257d3f9/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
new file mode 100644
index 0000000..e73234c
--- /dev/null
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -0,0 +1,250 @@
+// 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.
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "DFPlatform.h"
+#include "zlib.h"
+
+
+
+DFextZipHandleP DFextZipOpen(const char *zipFilename) {
+ DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
+
+ // open zip file for reading
+ zipHandle->zip = fopen(zipFilename, "rb");
+ if (!zipHandle->zip) {
+ free(zipHandle);
+ return NULL;
+ }
+
+
+ int jzReadEndRecord(FILE *zip, JZEndRecord *endRecord) {
+ long fileSize, readBytes, i;
+ JZEndRecord *er;
+
+ if (fseek(zip, 0, SEEK_END)) {
+ fprintf(stderr, "Couldn't go to end of zip file!");
+ return Z_ERRNO;
+ }
+
+ if ((fileSize = ftell(zip)) <= sizeof(JZEndRecord)) {
+ fprintf(stderr, "Too small file to be a zip!");
+ return Z_ERRNO;
+ }
+
+ readBytes = (fileSize < sizeof(jzBuffer)) ? fileSize : sizeof(jzBuffer);
+
+ if (fseek(zip, fileSize - readBytes, SEEK_SET)) {
+ fprintf(stderr, "Cannot seek in zip file!");
+ return Z_ERRNO;
+ }
+
+ if (fread(jzBuffer, 1, readBytes, zip) < readBytes) {
+ fprintf(stderr, "Couldn't read end of zip file!");
+ return Z_ERRNO;
+ }
+
+ // Naively assume signature can only be found in one place...
+ for (i = readBytes - sizeof(JZEndRecord); i >= 0; i--) {
+ er = (JZEndRecord *)(jzBuffer + i);
+ if (er->signature == 0x06054B50)
+ break;
+ }
+
+ if (i < 0) {
+ fprintf(stderr, "End record signature not found in zip!");
+ return Z_ERRNO;
+ }
+
+ memcpy(endRecord, er, sizeof(JZEndRecord));
+
+ if (endRecord->diskNumber || endRecord->centralDirectoryDiskNumber ||
+ endRecord->numEntries != endRecord->numEntriesThisDisk) {
+ fprintf(stderr, "Multifile zips not supported!");
+ return Z_ERRNO;
+ }
+
+ return Z_OK;
+
+
+
+ // release memory
+ free(zipHandle);
+ return NULL;
+}
+
+
+
+DFextZipHandleP OLD_DFextZipOpen(const char *zipFilename) {
+ DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
+
+#if 0
+ // no more memory
+ if (!zipHandle)
+ return NULL;
+
+ // Open file
+ zipHandle->zipFirst = 1;
+ zipHandle->handle = unzOpen(zipFilename);
+
+ if (zipHandle->handle)
+ return zipHandle;
+
+ free(zipHandle);
+#endif
+ return NULL;
+}
+
+
+
+DFextZipHandleP DFextZipCreate(const char *zipFilename) {
+ DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
+
+#if 0
+ // no more memory
+ if (!zipHandle)
+ return NULL;
+
+ // Open file
+ zipHandle->zipFirst = 1;
+ zipHandle->handle = zipOpen(zipFilename, APPEND_STATUS_CREATE);
+
+ if (zipHandle->handle)
+ return zipHandle;
+
+ free(zipHandle);
+#endif
+ return NULL;
+}
+
+
+int DFextZipClose(DFextZipHandleP zipHandle)
+{
+ int rc = 0;
+
+#if 0
+ if (zipHandle->handle) {
+ if (zipHandle->zipFlag)
+ rc = (unzClose(zipHandle->handle) == UNZ_OK);
+ else
+ rc = (zipClose(zipHandle->handle, NULL) == ZIP_OK);
+ zipHandle->handle = NULL;
+ }
+
+ free(zipHandle);
+#endif
+ return rc ? 1 : -1;
+}
+
+
+
+int DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName, const int maxName)
+{
+#if 0
+ int rc;
+
+ if (zipHandle->zipFlag) {
+ unz_file_info info;
+
+ // handling of first file and all others are different
+ if (zipHandle->zipFirst) {
+ rc = unzGoToFirstFile(zipHandle->handle);
+ zipHandle->zipFirst = 0;
+ }
+ else
+ 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(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(zipHandle, entryName, maxName);
+
+ // open Regular file
+ if (unzOpenCurrentFile(zipHandle->handle) != UNZ_OK)
+ return -1;
+ }
+ else {
+ return -1; // Zip file is open in write-only mode
+ }
+
+ // ready to read
+#endif
+ return 1;
+}
+
+int DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName)
+{
+#if 0
+ zip_fileinfo fileinfo;
+ memset(&fileinfo, 0, sizeof(fileinfo));
+
+ if (zipHandle->zipFlag)
+ return -1; // Zip file is open in read-only mode
+
+ if (zipOpenNewFileInZip(zipHandle->handle,
+ entryName,
+ &fileinfo,
+ NULL, 0,
+ NULL, 0,
+ NULL,
+ Z_DEFLATED,
+ Z_DEFAULT_COMPRESSION) != ZIP_OK) {
+ return -1;
+ }
+#endif
+ return 1;
+}
+
+int DFextZipCloseFile(DFextZipHandleP zipHandle)
+{
+#if 0
+ if (zipHandle->zipFlag)
+ return (unzCloseCurrentFile(zipHandle->handle) != UNZ_OK) ? -1 : 1;
+ else
+ return (zipCloseFileInZip(zipHandle->handle) != UNZ_OK) ? -1 : 1;
+#endif
+ return 0;
+}
+
+
+
+
+int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, void *buf, const int maxLen)
+{
+#if 0
+ return unzReadCurrentFile(zipHandle->handle, buf, maxLen);
+#endif
+ return 0;
+}
+
+
+
+int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, const void *buf, const int len)
+{
+#if 0
+ return (zipWriteInFileInZip(zipHandle->handle, buf, len) == ZIP_OK) ? 1 : -1;
+#endif
+ return 0;
+}