Revision cfb53624
| b/programs/ios/WebODF.xcodeproj/project.pbxproj | ||
|---|---|---|
| 416 | 416 |
isa = XCBuildConfiguration; |
| 417 | 417 |
buildSettings = {
|
| 418 | 418 |
ALWAYS_SEARCH_USER_PATHS = YES; |
| 419 |
CODE_SIGN_IDENTITY = "iPhone Developer: Jos van den Oever (GJ9RDPR233)"; |
|
| 420 |
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Jos van den Oever (GJ9RDPR233)"; |
|
| 419 |
CODE_SIGN_IDENTITY = "iPhone Developer"; |
|
| 421 | 420 |
COPY_PHASE_STRIP = NO; |
| 422 | 421 |
FRAMEWORK_SEARCH_PATHS = /Users/Shared/PhoneGap/Frameworks; |
| 423 | 422 |
GCC_DYNAMIC_NO_PIC = NO; |
| ... | ... | |
| 438 | 437 |
/usr/lib/libSystem.B.dylib, |
| 439 | 438 |
); |
| 440 | 439 |
PRODUCT_NAME = "$(TARGET_NAME)"; |
| 441 |
PROVISIONING_PROFILE = "856ACE2B-07C3-43F7-877C-BC4CD60F4C79"; |
|
| 442 |
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "856ACE2B-07C3-43F7-877C-BC4CD60F4C79"; |
|
| 440 |
PROVISIONING_PROFILE = ""; |
|
| 443 | 441 |
TARGETED_DEVICE_FAMILY = "1,2"; |
| 444 | 442 |
WRAPPER_EXTENSION = app; |
| 445 | 443 |
}; |
| ... | ... | |
| 453 | 451 |
armv6, |
| 454 | 452 |
"$(ARCHS_STANDARD_32_BIT)", |
| 455 | 453 |
); |
| 456 |
CODE_SIGN_IDENTITY = "iPhone Developer: Jos van den Oever (GJ9RDPR233)"; |
|
| 457 |
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Jos van den Oever (GJ9RDPR233)"; |
|
| 454 |
CODE_SIGN_IDENTITY = "iPhone Developer"; |
|
| 458 | 455 |
COPY_PHASE_STRIP = YES; |
| 459 | 456 |
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; |
| 460 | 457 |
FRAMEWORK_SEARCH_PATHS = /Users/Shared/PhoneGap/Frameworks; |
| ... | ... | |
| 475 | 472 |
/usr/lib/libSystem.B.dylib, |
| 476 | 473 |
); |
| 477 | 474 |
PRODUCT_NAME = "$(TARGET_NAME)"; |
| 478 |
PROVISIONING_PROFILE = "856ACE2B-07C3-43F7-877C-BC4CD60F4C79"; |
|
| 479 |
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "856ACE2B-07C3-43F7-877C-BC4CD60F4C79"; |
|
| 475 |
PROVISIONING_PROFILE = ""; |
|
| 480 | 476 |
TARGETED_DEVICE_FAMILY = "1,2"; |
| 481 | 477 |
VALIDATE_PRODUCT = YES; |
| 482 | 478 |
WRAPPER_EXTENSION = app; |
| b/programs/ios/WebODF/Classes/NSData+Base64.h | ||
|---|---|---|
| 1 |
// |
|
| 2 |
// NSData+Base64.h |
|
| 3 |
// base64 |
|
| 4 |
// |
|
| 5 |
// Created by Matt Gallagher on 2009/06/03. |
|
| 6 |
// Copyright 2009 Matt Gallagher. All rights reserved. |
|
| 7 |
// |
|
| 8 |
// Permission is given to use this source code file, free of charge, in any |
|
| 9 |
// project, commercial or otherwise, entirely at your risk, with the condition |
|
| 10 |
// that any redistribution (in part or whole) of source code must retain |
|
| 11 |
// this copyright and permission notice. Attribution in compiled projects is |
|
| 12 |
// appreciated but not required. |
|
| 13 |
// |
|
| 14 |
|
|
| 15 |
#import <Foundation/Foundation.h> |
|
| 16 |
|
|
| 17 |
void *NewBase64Decode( |
|
| 18 |
const char *inputBuffer, |
|
| 19 |
size_t length, |
|
| 20 |
size_t *outputLength); |
|
| 21 |
|
|
| 22 |
char *NewBase64Encode( |
|
| 23 |
const void *inputBuffer, |
|
| 24 |
size_t length, |
|
| 25 |
bool separateLines, |
|
| 26 |
size_t *outputLength); |
|
| 27 |
|
|
| 28 |
@interface NSData (Base64) |
|
| 29 |
|
|
| 30 |
+ (NSData *)dataFromBase64String:(NSString *)aString; |
|
| 31 |
- (NSString *)base64EncodedString; |
|
| 32 |
|
|
| 33 |
@end |
|
| b/programs/ios/WebODF/Classes/NSData+Base64.m | ||
|---|---|---|
| 1 |
// |
|
| 2 |
// NSData+Base64.m |
|
| 3 |
// base64 |
|
| 4 |
// |
|
| 5 |
// Created by Matt Gallagher on 2009/06/03. |
|
| 6 |
// Copyright 2009 Matt Gallagher. All rights reserved. |
|
| 7 |
// |
|
| 8 |
// Permission is given to use this source code file, free of charge, in any |
|
| 9 |
// project, commercial or otherwise, entirely at your risk, with the condition |
|
| 10 |
// that any redistribution (in part or whole) of source code must retain |
|
| 11 |
// this copyright and permission notice. Attribution in compiled projects is |
|
| 12 |
// appreciated but not required. |
|
| 13 |
// |
|
| 14 |
|
|
| 15 |
#import "NSData+Base64.h" |
|
| 16 |
|
|
| 17 |
// |
|
| 18 |
// Mapping from 6 bit pattern to ASCII character. |
|
| 19 |
// |
|
| 20 |
static unsigned char base64EncodeLookup[65] = |
|
| 21 |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
|
| 22 |
|
|
| 23 |
// |
|
| 24 |
// Definition for "masked-out" areas of the base64DecodeLookup mapping |
|
| 25 |
// |
|
| 26 |
#define xx 65 |
|
| 27 |
|
|
| 28 |
// |
|
| 29 |
// Mapping from ASCII character to 6 bit pattern. |
|
| 30 |
// |
|
| 31 |
static unsigned char base64DecodeLookup[256] = |
|
| 32 |
{
|
|
| 33 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 34 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 35 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 62, xx, xx, xx, 63, |
|
| 36 |
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, xx, xx, xx, xx, xx, xx, |
|
| 37 |
xx, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
|
| 38 |
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, xx, xx, xx, xx, xx, |
|
| 39 |
xx, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
|
| 40 |
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, xx, xx, xx, xx, xx, |
|
| 41 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 42 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 43 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 44 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 45 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 46 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 47 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 48 |
xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, |
|
| 49 |
}; |
|
| 50 |
|
|
| 51 |
// |
|
| 52 |
// Fundamental sizes of the binary and base64 encode/decode units in bytes |
|
| 53 |
// |
|
| 54 |
#define BINARY_UNIT_SIZE 3 |
|
| 55 |
#define BASE64_UNIT_SIZE 4 |
|
| 56 |
|
|
| 57 |
// |
|
| 58 |
// NewBase64Decode |
|
| 59 |
// |
|
| 60 |
// Decodes the base64 ASCII string in the inputBuffer to a newly malloced |
|
| 61 |
// output buffer. |
|
| 62 |
// |
|
| 63 |
// inputBuffer - the source ASCII string for the decode |
|
| 64 |
// length - the length of the string or -1 (to specify strlen should be used) |
|
| 65 |
// outputLength - if not-NULL, on output will contain the decoded length |
|
| 66 |
// |
|
| 67 |
// returns the decoded buffer. Must be free'd by caller. Length is given by |
|
| 68 |
// outputLength. |
|
| 69 |
// |
|
| 70 |
void *NewBase64Decode( |
|
| 71 |
const char *inputBuffer, |
|
| 72 |
size_t length, |
|
| 73 |
size_t *outputLength) |
|
| 74 |
{
|
|
| 75 |
if (length == -1) |
|
| 76 |
{
|
|
| 77 |
length = strlen(inputBuffer); |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
size_t outputBufferSize = (length / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE; |
|
| 81 |
unsigned char *outputBuffer = (unsigned char *)malloc(outputBufferSize); |
|
| 82 |
|
|
| 83 |
size_t i = 0; |
|
| 84 |
size_t j = 0; |
|
| 85 |
while (i < length) |
|
| 86 |
{
|
|
| 87 |
// |
|
| 88 |
// Accumulate 4 valid characters (ignore everything else) |
|
| 89 |
// |
|
| 90 |
unsigned char accumulated[BASE64_UNIT_SIZE]; |
|
| 91 |
bzero(accumulated, sizeof(unsigned char) * BASE64_UNIT_SIZE); |
|
| 92 |
size_t accumulateIndex = 0; |
|
| 93 |
while (i < length) |
|
| 94 |
{
|
|
| 95 |
unsigned char decode = base64DecodeLookup[inputBuffer[i++]]; |
|
| 96 |
if (decode != xx) |
|
| 97 |
{
|
|
| 98 |
accumulated[accumulateIndex] = decode; |
|
| 99 |
accumulateIndex++; |
|
| 100 |
|
|
| 101 |
if (accumulateIndex == BASE64_UNIT_SIZE) |
|
| 102 |
{
|
|
| 103 |
break; |
|
| 104 |
} |
|
| 105 |
} |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
// |
|
| 109 |
// Store the 6 bits from each of the 4 characters as 3 bytes |
|
| 110 |
// |
|
| 111 |
outputBuffer[j] = (accumulated[0] << 2) | (accumulated[1] >> 4); |
|
| 112 |
outputBuffer[j + 1] = (accumulated[1] << 4) | (accumulated[2] >> 2); |
|
| 113 |
outputBuffer[j + 2] = (accumulated[2] << 6) | accumulated[3]; |
|
| 114 |
j += accumulateIndex - 1; |
|
| 115 |
} |
|
| 116 |
|
|
| 117 |
if (outputLength) |
|
| 118 |
{
|
|
| 119 |
*outputLength = j; |
|
| 120 |
} |
|
| 121 |
return outputBuffer; |
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
// |
|
| 125 |
// NewBase64Decode |
|
| 126 |
// |
|
| 127 |
// Encodes the arbitrary data in the inputBuffer as base64 into a newly malloced |
|
| 128 |
// output buffer. |
|
| 129 |
// |
|
| 130 |
// inputBuffer - the source data for the encode |
|
| 131 |
// length - the length of the input in bytes |
|
| 132 |
// separateLines - if zero, no CR/LF characters will be added. Otherwise |
|
| 133 |
// a CR/LF pair will be added every 64 encoded chars. |
|
| 134 |
// outputLength - if not-NULL, on output will contain the encoded length |
|
| 135 |
// (not including terminating 0 char) |
|
| 136 |
// |
|
| 137 |
// returns the encoded buffer. Must be free'd by caller. Length is given by |
|
| 138 |
// outputLength. |
|
| 139 |
// |
|
| 140 |
char *NewBase64Encode( |
|
| 141 |
const void *buffer, |
|
| 142 |
size_t length, |
|
| 143 |
bool separateLines, |
|
| 144 |
size_t *outputLength) |
|
| 145 |
{
|
|
| 146 |
const unsigned char *inputBuffer = (const unsigned char *)buffer; |
|
| 147 |
|
|
| 148 |
#define MAX_NUM_PADDING_CHARS 2 |
|
| 149 |
#define OUTPUT_LINE_LENGTH 64 |
|
| 150 |
#define INPUT_LINE_LENGTH ((OUTPUT_LINE_LENGTH / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE) |
|
| 151 |
#define CR_LF_SIZE 0 |
|
| 152 |
|
|
| 153 |
// |
|
| 154 |
// Byte accurate calculation of final buffer size |
|
| 155 |
// |
|
| 156 |
size_t outputBufferSize = |
|
| 157 |
((length / BINARY_UNIT_SIZE) |
|
| 158 |
+ ((length % BINARY_UNIT_SIZE) ? 1 : 0)) |
|
| 159 |
* BASE64_UNIT_SIZE; |
|
| 160 |
if (separateLines) |
|
| 161 |
{
|
|
| 162 |
outputBufferSize += |
|
| 163 |
(outputBufferSize / OUTPUT_LINE_LENGTH) * CR_LF_SIZE; |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
// |
|
| 167 |
// Include space for a terminating zero |
|
| 168 |
// |
|
| 169 |
outputBufferSize += 1; |
|
| 170 |
|
|
| 171 |
// |
|
| 172 |
// Allocate the output buffer |
|
| 173 |
// |
|
| 174 |
char *outputBuffer = (char *)malloc(outputBufferSize); |
|
| 175 |
if (!outputBuffer) |
|
| 176 |
{
|
|
| 177 |
return NULL; |
|
| 178 |
} |
|
| 179 |
|
|
| 180 |
size_t i = 0; |
|
| 181 |
size_t j = 0; |
|
| 182 |
const size_t lineLength = separateLines ? INPUT_LINE_LENGTH : length; |
|
| 183 |
size_t lineEnd = lineLength; |
|
| 184 |
|
|
| 185 |
while (true) |
|
| 186 |
{
|
|
| 187 |
if (lineEnd > length) |
|
| 188 |
{
|
|
| 189 |
lineEnd = length; |
|
| 190 |
} |
|
| 191 |
|
|
| 192 |
for (; i + BINARY_UNIT_SIZE - 1 < lineEnd; i += BINARY_UNIT_SIZE) |
|
| 193 |
{
|
|
| 194 |
// |
|
| 195 |
// Inner loop: turn 48 bytes into 64 base64 characters |
|
| 196 |
// |
|
| 197 |
outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; |
|
| 198 |
outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4) |
|
| 199 |
| ((inputBuffer[i + 1] & 0xF0) >> 4)]; |
|
| 200 |
outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i + 1] & 0x0F) << 2) |
|
| 201 |
| ((inputBuffer[i + 2] & 0xC0) >> 6)]; |
|
| 202 |
outputBuffer[j++] = base64EncodeLookup[inputBuffer[i + 2] & 0x3F]; |
|
| 203 |
} |
|
| 204 |
|
|
| 205 |
if (lineEnd == length) |
|
| 206 |
{
|
|
| 207 |
break; |
|
| 208 |
} |
|
| 209 |
|
|
| 210 |
// |
|
| 211 |
// Add the newline |
|
| 212 |
// |
|
| 213 |
//outputBuffer[j++] = '\r'; |
|
| 214 |
//outputBuffer[j++] = '\n'; |
|
| 215 |
lineEnd += lineLength; |
|
| 216 |
} |
|
| 217 |
|
|
| 218 |
if (i + 1 < length) |
|
| 219 |
{
|
|
| 220 |
// |
|
| 221 |
// Handle the single '=' case |
|
| 222 |
// |
|
| 223 |
outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; |
|
| 224 |
outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4) |
|
| 225 |
| ((inputBuffer[i + 1] & 0xF0) >> 4)]; |
|
| 226 |
outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i + 1] & 0x0F) << 2]; |
|
| 227 |
outputBuffer[j++] = '='; |
|
| 228 |
} |
|
| 229 |
else if (i < length) |
|
| 230 |
{
|
|
| 231 |
// |
|
| 232 |
// Handle the double '=' case |
|
| 233 |
// |
|
| 234 |
outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; |
|
| 235 |
outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0x03) << 4]; |
|
| 236 |
outputBuffer[j++] = '='; |
|
| 237 |
outputBuffer[j++] = '='; |
|
| 238 |
} |
|
| 239 |
outputBuffer[j] = 0; |
|
| 240 |
|
|
| 241 |
// |
|
| 242 |
// Set the output length and return the buffer |
|
| 243 |
// |
|
| 244 |
if (outputLength) |
|
| 245 |
{
|
|
| 246 |
*outputLength = j; |
|
| 247 |
} |
|
| 248 |
return outputBuffer; |
|
| 249 |
} |
|
| 250 |
|
|
| 251 |
@implementation NSData (Base64) |
|
| 252 |
|
|
| 253 |
// |
|
| 254 |
// dataFromBase64String: |
|
| 255 |
// |
|
| 256 |
// Creates an NSData object containing the base64 decoded representation of |
|
| 257 |
// the base64 string 'aString' |
|
| 258 |
// |
|
| 259 |
// Parameters: |
|
| 260 |
// aString - the base64 string to decode |
|
| 261 |
// |
|
| 262 |
// returns the autoreleased NSData representation of the base64 string |
|
| 263 |
// |
|
| 264 |
+ (NSData *)dataFromBase64String:(NSString *)aString |
|
| 265 |
{
|
|
| 266 |
NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding]; |
|
| 267 |
size_t outputLength; |
|
| 268 |
void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength); |
|
| 269 |
NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength]; |
|
| 270 |
free(outputBuffer); |
|
| 271 |
return result; |
|
| 272 |
} |
|
| 273 |
|
|
| 274 |
// |
|
| 275 |
// base64EncodedString |
|
| 276 |
// |
|
| 277 |
// Creates an NSString object that contains the base 64 encoding of the |
|
| 278 |
// receiver's data. Lines are broken at 64 characters long. |
|
| 279 |
// |
|
| 280 |
// returns an autoreleased NSString being the base 64 representation of the |
|
| 281 |
// receiver. |
|
| 282 |
// |
|
| 283 |
- (NSString *)base64EncodedString |
|
| 284 |
{
|
|
| 285 |
size_t outputLength; |
|
| 286 |
char *outputBuffer = |
|
| 287 |
NewBase64Encode([self bytes], [self length], true, &outputLength); |
|
| 288 |
|
|
| 289 |
NSString *result = |
|
| 290 |
[[[NSString alloc] |
|
| 291 |
initWithBytes:outputBuffer |
|
| 292 |
length:outputLength |
|
| 293 |
encoding:NSASCIIStringEncoding] |
|
| 294 |
autorelease]; |
|
| 295 |
free(outputBuffer); |
|
| 296 |
return result; |
|
| 297 |
} |
|
| 298 |
|
|
| 299 |
@end |
|
| b/programs/ios/WebODF/Classes/NativeZip.h | ||
|---|---|---|
| 6 | 6 |
|
| 7 | 7 |
@property (nonatomic, copy) NSString* callbackID; |
| 8 | 8 |
|
| 9 |
- (void) load:(BOOL)base64 arguments:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; |
|
| 9 | 10 |
- (void) loadAsString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; |
| 11 |
- (void) loadAsDataURL:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; |
|
| 10 | 12 |
|
| 11 | 13 |
@end |
| b/programs/ios/WebODF/Classes/NativeZip.m | ||
|---|---|---|
| 1 | 1 |
#import "NativeZip.h" |
| 2 |
//#import "Objective-Zip/ZipReadStream.h" |
|
| 3 |
//#import "Objective-Zip/ZipFile.h" |
|
| 4 | 2 |
#import "minizip/unzip.h" |
| 3 |
#import "NSData+Base64.h" |
|
| 5 | 4 |
|
| 6 | 5 |
@implementation NativeZip |
| 7 | 6 |
@synthesize callbackID; |
| 8 | 7 |
|
| 9 |
-(void)loadAsString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options |
|
| 8 |
|
|
| 9 |
-(void) load:(BOOL)base64 arguments:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options |
|
| 10 | 10 |
{
|
| 11 | 11 |
self.callbackID = [arguments objectAtIndex:0]; |
| 12 | 12 |
NSString *zipPath = [arguments objectAtIndex:1]; |
| ... | ... | |
| 38 | 38 |
if (r != info.uncompressed_size) {
|
| 39 | 39 |
jsString = [[NSString alloc] initWithString: @"cannot uncompress file"]; |
| 40 | 40 |
} else {
|
| 41 |
jsString = [[NSString alloc] initWithUTF8String: contents]; |
|
| 41 |
if (base64) {
|
|
| 42 |
NSData* readData = [NSData dataWithBytes:(const void *)contents length:sizeof(unsigned char)*info.uncompressed_size]; |
|
| 43 |
jsString = [NSString stringWithFormat:@"data:%@;base64,%@", @"mimetype", [readData base64EncodedString]]; |
|
| 44 |
} else {
|
|
| 45 |
jsString = [[NSString alloc] initWithUTF8String: contents]; |
|
| 46 |
} |
|
| 42 | 47 |
} |
| 43 | 48 |
unzCloseCurrentFile(unzipFile); |
| 44 | 49 |
free(contents); |
| ... | ... | |
| 59 | 64 |
} |
| 60 | 65 |
} |
| 61 | 66 |
|
| 67 |
-(void)loadAsString:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options |
|
| 68 |
{
|
|
| 69 |
[self load:FALSE arguments:arguments withDict:options]; |
|
| 70 |
} |
|
| 71 |
-(void)loadAsDataURL:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options |
|
| 72 |
{
|
|
| 73 |
[self load:TRUE arguments:arguments withDict:options]; |
|
| 74 |
} |
|
| 75 |
|
|
| 62 | 76 |
@end |
| b/programs/ios/WebODF/Classes/minizip/crypt.h | ||
|---|---|---|
| 1 |
/* crypt.h -- base code for crypt/uncrypt ZIPfile |
|
| 2 |
|
|
| 3 |
|
|
| 4 |
Version 1.01e, February 12th, 2005 |
|
| 5 |
|
|
| 6 |
Copyright (C) 1998-2005 Gilles Vollant |
|
| 7 |
|
|
| 8 |
This code is a modified version of crypting code in Infozip distribution |
|
| 9 |
|
|
| 10 |
The encryption/decryption parts of this source code (as opposed to the |
|
| 11 |
non-echoing password parts) were originally written in Europe. The |
|
| 12 |
whole source package can be freely distributed, including from the USA. |
|
| 13 |
(Prior to January 2000, re-export from the US was a violation of US law.) |
|
| 14 |
|
|
| 15 |
This encryption code is a direct transcription of the algorithm from |
|
| 16 |
Roger Schlafly, described by Phil Katz in the file appnote.txt. This |
|
| 17 |
file (appnote.txt) is distributed with the PKZIP program (even in the |
|
| 18 |
version without encryption capabilities). |
|
| 19 |
|
|
| 20 |
If you don't need crypting in your application, just define symbols |
|
| 21 |
NOCRYPT and NOUNCRYPT. |
|
| 22 |
|
|
| 23 |
This code support the "Traditional PKWARE Encryption". |
|
| 24 |
|
|
| 25 |
The new AES encryption added on Zip format by Winzip (see the page |
|
| 26 |
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong |
|
| 27 |
Encryption is not supported. |
|
| 28 |
*/ |
|
| 29 |
|
|
| 30 |
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) |
|
| 31 |
|
|
| 32 |
/*********************************************************************** |
|
| 33 |
* Return the next byte in the pseudo-random sequence |
|
| 34 |
*/ |
|
| 35 |
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) |
|
| 36 |
{
|
|
| 37 |
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an |
|
| 38 |
* unpredictable manner on 16-bit systems; not a problem |
|
| 39 |
* with any known compiler so far, though */ |
|
| 40 |
|
|
| 41 |
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; |
|
| 42 |
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); |
|
| 43 |
} |
|
| 44 |
|
|
| 45 |
/*********************************************************************** |
|
| 46 |
* Update the encryption keys with the next byte of plain text |
|
| 47 |
*/ |
|
| 48 |
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) |
|
| 49 |
{
|
|
| 50 |
(*(pkeys+0)) = CRC32((*(pkeys+0)), c); |
|
| 51 |
(*(pkeys+1)) += (*(pkeys+0)) & 0xff; |
|
| 52 |
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; |
|
| 53 |
{
|
|
| 54 |
register int keyshift = (int)((*(pkeys+1)) >> 24); |
|
| 55 |
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); |
|
| 56 |
} |
|
| 57 |
return c; |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
|
|
| 61 |
/*********************************************************************** |
|
| 62 |
* Initialize the encryption keys and the random header according to |
|
| 63 |
* the given password. |
|
| 64 |
*/ |
|
| 65 |
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) |
|
| 66 |
{
|
|
| 67 |
*(pkeys+0) = 305419896L; |
|
| 68 |
*(pkeys+1) = 591751049L; |
|
| 69 |
*(pkeys+2) = 878082192L; |
|
| 70 |
while (*passwd != '\0') {
|
|
| 71 |
update_keys(pkeys,pcrc_32_tab,(int)*passwd); |
|
| 72 |
passwd++; |
|
| 73 |
} |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
#define zdecode(pkeys,pcrc_32_tab,c) \ |
|
| 77 |
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) |
|
| 78 |
|
|
| 79 |
#define zencode(pkeys,pcrc_32_tab,c,t) \ |
|
| 80 |
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) |
|
| 81 |
|
|
| 82 |
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED |
|
| 83 |
|
|
| 84 |
#define RAND_HEAD_LEN 12 |
|
| 85 |
/* "last resort" source for second part of crypt seed pattern */ |
|
| 86 |
# ifndef ZCR_SEED2 |
|
| 87 |
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ |
|
| 88 |
# endif |
|
| 89 |
|
|
| 90 |
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) |
|
| 91 |
const char *passwd; /* password string */ |
|
| 92 |
unsigned char *buf; /* where to write header */ |
|
| 93 |
int bufSize; |
|
| 94 |
unsigned long* pkeys; |
|
| 95 |
const unsigned long* pcrc_32_tab; |
|
| 96 |
unsigned long crcForCrypting; |
|
| 97 |
{
|
|
| 98 |
int n; /* index in random header */ |
|
| 99 |
int t; /* temporary */ |
|
| 100 |
int c; /* random byte */ |
|
| 101 |
unsigned char header[RAND_HEAD_LEN-2]; /* random header */ |
|
| 102 |
static unsigned calls = 0; /* ensure different random header each time */ |
|
| 103 |
|
|
| 104 |
if (bufSize<RAND_HEAD_LEN) |
|
| 105 |
return 0; |
|
| 106 |
|
|
| 107 |
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the |
|
| 108 |
* output of rand() to get less predictability, since rand() is |
|
| 109 |
* often poorly implemented. |
|
| 110 |
*/ |
|
| 111 |
if (++calls == 1) |
|
| 112 |
{
|
|
| 113 |
srand((unsigned)(time(NULL) ^ ZCR_SEED2)); |
|
| 114 |
} |
|
| 115 |
init_keys(passwd, pkeys, pcrc_32_tab); |
|
| 116 |
for (n = 0; n < RAND_HEAD_LEN-2; n++) |
|
| 117 |
{
|
|
| 118 |
c = (rand() >> 7) & 0xff; |
|
| 119 |
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); |
|
| 120 |
} |
|
| 121 |
/* Encrypt random header (last two bytes is high word of crc) */ |
|
| 122 |
init_keys(passwd, pkeys, pcrc_32_tab); |
|
| 123 |
for (n = 0; n < RAND_HEAD_LEN-2; n++) |
|
| 124 |
{
|
|
| 125 |
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); |
|
| 126 |
} |
|
| 127 |
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); |
|
| 128 |
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); |
|
| 129 |
return n; |
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
#endif |
|
| b/programs/ios/WebODF/Classes/minizip/mztools.c | ||
|---|---|---|
| 26 | 26 |
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ |
| 27 | 27 |
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ |
| 28 | 28 |
} while(0) |
| 29 |
|
|
| 30 |
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) |
|
| 31 |
const char* file; |
|
| 32 |
const char* fileOut; |
|
| 33 |
const char* fileOutTmp; |
|
| 34 |
uLong* nRecovered; |
|
| 35 |
uLong* bytesRecovered; |
|
| 36 |
{
|
|
| 37 |
int err = Z_OK; |
|
| 38 |
FILE* fpZip = fopen(file, "rb"); |
|
| 39 |
FILE* fpOut = fopen(fileOut, "wb"); |
|
| 40 |
FILE* fpOutCD = fopen(fileOutTmp, "wb"); |
|
| 41 |
if (fpZip != NULL && fpOut != NULL) {
|
|
| 42 |
int entries = 0; |
|
| 43 |
uLong totalBytes = 0; |
|
| 44 |
char header[30]; |
|
| 45 |
char filename[256]; |
|
| 46 |
char extra[1024]; |
|
| 47 |
int offset = 0; |
|
| 48 |
int offsetCD = 0; |
|
| 49 |
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
|
| 50 |
int currentOffset = offset; |
|
| 51 |
|
|
| 52 |
/* File entry */ |
|
| 53 |
if (READ_32(header) == 0x04034b50) {
|
|
| 54 |
unsigned int version = READ_16(header + 4); |
|
| 55 |
unsigned int gpflag = READ_16(header + 6); |
|
| 56 |
unsigned int method = READ_16(header + 8); |
|
| 57 |
unsigned int filetime = READ_16(header + 10); |
|
| 58 |
unsigned int filedate = READ_16(header + 12); |
|
| 59 |
unsigned int crc = READ_32(header + 14); /* crc */ |
|
| 60 |
unsigned int cpsize = READ_32(header + 18); /* compressed size */ |
|
| 61 |
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ |
|
| 62 |
unsigned int fnsize = READ_16(header + 26); /* file name length */ |
|
| 63 |
unsigned int extsize = READ_16(header + 28); /* extra field length */ |
|
| 64 |
filename[0] = extra[0] = '\0'; |
|
| 65 |
|
|
| 66 |
/* Header */ |
|
| 67 |
if (fwrite(header, 1, 30, fpOut) == 30) {
|
|
| 68 |
offset += 30; |
|
| 69 |
} else {
|
|
| 70 |
err = Z_ERRNO; |
|
| 71 |
break; |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/* Filename */ |
|
| 75 |
if (fnsize > 0) {
|
|
| 76 |
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
|
| 77 |
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
|
| 78 |
offset += fnsize; |
|
| 79 |
} else {
|
|
| 80 |
err = Z_ERRNO; |
|
| 81 |
break; |
|
| 82 |
} |
|
| 83 |
} else {
|
|
| 84 |
err = Z_ERRNO; |
|
| 85 |
break; |
|
| 86 |
} |
|
| 87 |
} else {
|
|
| 88 |
err = Z_STREAM_ERROR; |
|
| 89 |
break; |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/* Extra field */ |
|
| 93 |
if (extsize > 0) {
|
|
| 94 |
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
|
| 95 |
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
|
| 96 |
offset += extsize; |
|
| 97 |
} else {
|
|
| 98 |
err = Z_ERRNO; |
|
| 99 |
break; |
|
| 100 |
} |
|
| 101 |
} else {
|
|
| 102 |
err = Z_ERRNO; |
|
| 103 |
break; |
|
| 104 |
} |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/* Data */ |
|
| 108 |
{
|
|
| 109 |
int dataSize = cpsize; |
|
| 110 |
if (dataSize == 0) {
|
|
| 111 |
dataSize = uncpsize; |
|
| 112 |
} |
|
| 113 |
if (dataSize > 0) {
|
|
| 114 |
char* data = malloc(dataSize); |
|
| 115 |
if (data != NULL) {
|
|
| 116 |
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
|
| 117 |
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
|
| 118 |
offset += dataSize; |
|
| 119 |
totalBytes += dataSize; |
|
| 120 |
} else {
|
|
| 121 |
err = Z_ERRNO; |
|
| 122 |
} |
|
| 123 |
} else {
|
|
| 124 |
err = Z_ERRNO; |
|
| 125 |
} |
|
| 126 |
free(data); |
|
| 127 |
if (err != Z_OK) {
|
|
| 128 |
break; |
|
| 129 |
} |
|
| 130 |
} else {
|
|
| 131 |
err = Z_MEM_ERROR; |
|
| 132 |
break; |
|
| 133 |
} |
|
| 134 |
} |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
/* Central directory entry */ |
|
| 138 |
{
|
|
| 139 |
char header[46]; |
|
| 140 |
char* comment = ""; |
|
| 141 |
int comsize = (int) strlen(comment); |
|
| 142 |
WRITE_32(header, 0x02014b50); |
|
| 143 |
WRITE_16(header + 4, version); |
|
| 144 |
WRITE_16(header + 6, version); |
|
| 145 |
WRITE_16(header + 8, gpflag); |
|
| 146 |
WRITE_16(header + 10, method); |
|
| 147 |
WRITE_16(header + 12, filetime); |
|
| 148 |
WRITE_16(header + 14, filedate); |
|
| 149 |
WRITE_32(header + 16, crc); |
|
| 150 |
WRITE_32(header + 20, cpsize); |
|
| 151 |
WRITE_32(header + 24, uncpsize); |
|
| 152 |
WRITE_16(header + 28, fnsize); |
|
| 153 |
WRITE_16(header + 30, extsize); |
|
| 154 |
WRITE_16(header + 32, comsize); |
|
| 155 |
WRITE_16(header + 34, 0); /* disk # */ |
|
| 156 |
WRITE_16(header + 36, 0); /* int attrb */ |
|
| 157 |
WRITE_32(header + 38, 0); /* ext attrb */ |
|
| 158 |
WRITE_32(header + 42, currentOffset); |
|
| 159 |
/* Header */ |
|
| 160 |
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
|
| 161 |
offsetCD += 46; |
|
| 162 |
|
|
| 163 |
/* Filename */ |
|
| 164 |
if (fnsize > 0) {
|
|
| 165 |
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
|
| 166 |
offsetCD += fnsize; |
|
| 167 |
} else {
|
|
| 168 |
err = Z_ERRNO; |
|
| 169 |
break; |
|
| 170 |
} |
|
| 171 |
} else {
|
|
| 172 |
err = Z_STREAM_ERROR; |
|
| 173 |
break; |
|
| 174 |
} |
|
| 175 |
|
|
| 176 |
/* Extra field */ |
|
| 177 |
if (extsize > 0) {
|
|
| 178 |
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
|
| 179 |
offsetCD += extsize; |
|
| 180 |
} else {
|
|
| 181 |
err = Z_ERRNO; |
|
| 182 |
break; |
|
| 183 |
} |
|
| 184 |
} |
|
| 185 |
|
|
| 186 |
/* Comment field */ |
|
| 187 |
if (comsize > 0) {
|
|
| 188 |
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
|
| 189 |
offsetCD += comsize; |
|
| 190 |
} else {
|
|
| 191 |
err = Z_ERRNO; |
|
| 192 |
break; |
|
| 193 |
} |
|
| 194 |
} |
|
| 195 |
|
|
| 196 |
|
|
| 197 |
} else {
|
|
| 198 |
err = Z_ERRNO; |
|
| 199 |
break; |
|
| 200 |
} |
|
| 201 |
} |
|
| 202 |
|
|
| 203 |
/* Success */ |
|
| 204 |
entries++; |
|
| 205 |
|
|
| 206 |
} else {
|
|
| 207 |
break; |
|
| 208 |
} |
|
| 209 |
} |
|
| 210 |
|
|
| 211 |
/* Final central directory */ |
|
| 212 |
{
|
|
| 213 |
int entriesZip = entries; |
|
| 214 |
char header[22]; |
|
| 215 |
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; |
|
| 216 |
int comsize = (int) strlen(comment); |
|
| 217 |
if (entriesZip > 0xffff) {
|
|
| 218 |
entriesZip = 0xffff; |
|
| 219 |
} |
|
| 220 |
WRITE_32(header, 0x06054b50); |
|
| 221 |
WRITE_16(header + 4, 0); /* disk # */ |
|
| 222 |
WRITE_16(header + 6, 0); /* disk # */ |
|
| 223 |
WRITE_16(header + 8, entriesZip); /* hack */ |
|
| 224 |
WRITE_16(header + 10, entriesZip); /* hack */ |
|
| 225 |
WRITE_32(header + 12, offsetCD); /* size of CD */ |
|
| 226 |
WRITE_32(header + 16, offset); /* offset to CD */ |
|
| 227 |
WRITE_16(header + 20, comsize); /* comment */ |
|
| 228 |
|
|
| 229 |
/* Header */ |
|
| 230 |
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
|
| 231 |
|
|
| 232 |
/* Comment field */ |
|
| 233 |
if (comsize > 0) {
|
|
| 234 |
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
|
| 235 |
err = Z_ERRNO; |
|
| 236 |
} |
|
| 237 |
} |
|
| 238 |
|
|
| 239 |
} else {
|
|
| 240 |
err = Z_ERRNO; |
|
| 241 |
} |
|
| 242 |
} |
|
| 243 |
|
|
| 244 |
/* Final merge (file + central directory) */ |
|
| 245 |
fclose(fpOutCD); |
|
| 246 |
if (err == Z_OK) {
|
|
| 247 |
fpOutCD = fopen(fileOutTmp, "rb"); |
|
| 248 |
if (fpOutCD != NULL) {
|
|
| 249 |
int nRead; |
|
| 250 |
char buffer[8192]; |
|
| 251 |
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
|
| 252 |
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
|
| 253 |
err = Z_ERRNO; |
|
| 254 |
break; |
|
| 255 |
} |
|
| 256 |
} |
|
| 257 |
fclose(fpOutCD); |
|
| 258 |
} |
|
| 259 |
} |
|
| 260 |
|
|
| 261 |
/* Close */ |
|
| 262 |
fclose(fpZip); |
|
| 263 |
fclose(fpOut); |
|
| 264 |
|
|
| 265 |
/* Wipe temporary file */ |
|
| 266 |
(void)remove(fileOutTmp); |
|
| 267 |
|
|
| 268 |
/* Number of recovered entries */ |
|
| 269 |
if (err == Z_OK) {
|
|
| 270 |
if (nRecovered != NULL) {
|
|
| 271 |
*nRecovered = entries; |
|
| 272 |
} |
|
| 273 |
if (bytesRecovered != NULL) {
|
|
| 274 |
*bytesRecovered = totalBytes; |
|
| 275 |
} |
|
| 276 |
} |
|
| 277 |
} else {
|
|
| 278 |
err = Z_STREAM_ERROR; |
|
| 279 |
} |
|
| 280 |
return err; |
|
| 281 |
} |
|
| b/programs/ios/WebODF/Classes/minizip/unzip.c | ||
|---|---|---|
| 1239 | 1239 |
return UNZ_PARAMERROR; |
| 1240 | 1240 |
|
| 1241 | 1241 |
|
| 1242 |
if ((pfile_in_zip_read_info->read_buffer == NULL))
|
|
| 1242 |
if (pfile_in_zip_read_info->read_buffer == NULL)
|
|
| 1243 | 1243 |
return UNZ_END_OF_LIST_OF_FILE; |
| 1244 | 1244 |
if (len==0) |
| 1245 | 1245 |
return 0; |
| ... | ... | |
| 1534 | 1534 |
char *szComment; |
| 1535 | 1535 |
uLong uSizeBuf; |
| 1536 | 1536 |
{
|
| 1537 |
int err=UNZ_OK; |
|
| 1538 | 1537 |
unz_s* s; |
| 1539 | 1538 |
uLong uReadThis ; |
| 1540 | 1539 |
if (file==NULL) |
| b/programs/ios/www/nativezip.js | ||
|---|---|---|
| 1 | 1 |
var ZipPlugin = {
|
| 2 |
loadAsString: function(zippath, entrypath, success, fail) {
|
|
| 3 |
return PhoneGap.exec(success, fail, "ZipClass", "loadAsString", [zippath, entrypath]); |
|
| 4 |
} |
|
| 2 |
loadAsString: function(zippath, entrypath, success, fail) {
|
|
| 3 |
return PhoneGap.exec(success, fail, "ZipClass", "loadAsString", [zippath, entrypath]); |
|
| 4 |
}, |
|
| 5 |
loadAsDataURL: function(zippath, entrypath, success, fail) {
|
|
| 6 |
return PhoneGap.exec(success, fail, "ZipClass", "loadAsDataURL", [zippath, entrypath]); |
|
| 7 |
}, |
|
| 5 | 8 |
}; |
| 6 | 9 |
core.Zip = function (url, entriesReadCallback) {
|
| 7 | 10 |
// remove 'odf:' prefix |
| 8 | 11 |
url = url.substr(4); |
| 9 | 12 |
var zip = this; |
| 10 | 13 |
this.load = function (filename, callback) {
|
| 11 |
alert(filename); |
|
| 12 |
callback(null, "");
|
|
| 14 |
//alert(filename);
|
|
| 15 |
callback(null, ""); |
|
| 13 | 16 |
}; |
| 14 | 17 |
/** |
| 15 | 18 |
* @param {!string} filename
|
| ... | ... | |
| 17 | 20 |
* @return {undefined}
|
| 18 | 21 |
*/ |
| 19 | 22 |
this.loadAsString = function (filename, callback) {
|
| 20 |
alert(filename); |
|
| 21 | 23 |
ZipPlugin.loadAsString(url, filename, |
| 22 | 24 |
function (content) {
|
| 23 | 25 |
callback(null, content); |
| ... | ... | |
| 25 | 27 |
function (err) { callback(err, null); }
|
| 26 | 28 |
); |
| 27 | 29 |
}; |
| 30 |
this.loadAsDataURL = function (filename, callback) {
|
|
| 31 |
ZipPlugin.loadAsDataURL(url, filename, |
|
| 32 |
function (content) {
|
|
| 33 |
callback(null, content); |
|
| 34 |
}, |
|
| 35 |
function (err) { callback(err, null); }
|
|
| 36 |
); |
|
| 37 |
}; |
|
| 28 | 38 |
this.getEntries = function () {
|
| 29 | 39 |
alert("getEntries");
|
| 30 | 40 |
}; |
| ... | ... | |
| 36 | 46 |
} |
| 37 | 47 |
handler.rootElementReady(null, data, true); |
| 38 | 48 |
}); |
| 39 |
|
|
| 40 | 49 |
}; |
| 41 | 50 |
this.save = function () {
|
| 42 | 51 |
alert("save");
|
Also available in: Unified diff