34#define NO_DYNAMIC_PLIST_DTD_CHANGE
41#ifndef NO_DYNAMIC_PLIST_DTD_CHANGE
42static NSData* ChangeDTDIfApplicable(NSData* data);
51 NSString* error =
nil;
54 whereFrom =
@"<data in memory>";
60#ifndef NO_DYNAMIC_PLIST_DTD_CHANGE
61 data = ChangeDTDIfApplicable(data);
64 result = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:&error];
67#if OOLITE_RELEASE_PLIST_ERROR_STRINGS
72 error =
@"<no error message>";
74 whereFrom =
@"<data in memory>";
102#ifndef NO_DYNAMIC_PLIST_DTD_CHANGE
103static NSData* ChangeDTDIfApplicable(NSData* data)
105 const uint8_t* bytes = NULL;
106 uint8_t* newBytes = NULL;
111 const char xmlDeclLine[] =
"<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>";
112 const char* appleDTDLines[] = {
113 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">",
114 "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">",
117 const char gstepDTDLine[] =
"<!DOCTYPE plist PUBLIC \"-//GNUstep//DTD plist 0.9//EN\" \"http://www.gnustep.org/plist-0_9.xml\">";
118 const char* srcDTDLine = NULL;
119 size_t srcDTDLineSize = 0;
122 length = [data length];
123 if (length <
sizeof xmlDeclLine)
126 bytes = [data bytes];
129 if (memcmp(bytes, xmlDeclLine,
sizeof xmlDeclLine - 1) != 0)
132 offset += sizeof xmlDeclLine - 1;
138 srcDTDLine = appleDTDLines[i];
139 if (srcDTDLine == NULL)
142 srcDTDLineSize = strlen(appleDTDLines[i]);
144 if (srcDTDLineSize <= length -
offset && memcmp(bytes +
offset, srcDTDLine, srcDTDLineSize) == 0) {
152 newLength = length -
offset + sizeof xmlDeclLine + sizeof gstepDTDLine - 1;
153 newBytes = malloc(newLength);
154 if (newBytes == NULL)
158 memcpy(newBytes, xmlDeclLine,
sizeof xmlDeclLine - 1);
159 newOffset =
sizeof xmlDeclLine - 1;
160 newBytes[newOffset++] =
'\n';
161 memcpy(newBytes + newOffset, gstepDTDLine,
sizeof gstepDTDLine - 1);
162 newOffset += sizeof gstepDTDLine - 1;
163 memcpy(newBytes + newOffset, bytes +
offset, length -
offset);
165 return [NSData dataWithBytes:newBytes length:newLength];
175 return [[NSData oo_dataWithOXZFile:path] retain];
179 return [[NSData alloc] initWithContentsOfMappedFile:path];
181 NSFileManager *fmgr = [NSFileManager defaultManager];
184 if ([fmgr fileExistsAtPath:path isDirectory:&dir])
188 return [[NSData alloc] initWithContentsOfMappedFile:path];
228 if (value !=
nil && ![value isKindOfClass:
class]) {
#define OOLog(class, format,...)
NSString *const kOOLogFileNotFound
NSArray * OOArrayFromData(NSData *data, NSString *whereFrom)
static NSString *const kOOLogPListFoundationParseError
static id ValueIfClass(id value, Class class)
id OOPropertyListFromData(NSData *data, NSString *whereFrom)
id OOPropertyListFromFile(NSString *path)
NSDictionary * OODictionaryFromFile(NSString *path)
static NSString *const kOOLogPListInformation
NSArray * OOArrayFromFile(NSString *path)
static NSString *const kOOLogPListWrongType
static NSData * CopyDataFromFile(NSString *path)
NSDictionary * OODictionaryFromData(NSData *data, NSString *whereFrom)