1 /* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * The contents of this file constitute Original Code as defined in and 7 * are subject to the Apple Public Source License Version 1.1 (the 8 * "License"). You may not use this file except in compliance with the 9 * License. Please obtain a copy of the License at 10 * http://www.apple.com/publicsource and read it before using this file. 11 * 12 * This Original Code and all software distributed under the License are 13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 * License for the specific language governing rights and limitations 18 * under the License. 19 * 20 * @APPLE_LICENSE_HEADER_END@ 21 */ 22 #include <libkern/OSBase.h> 23 24 __BEGIN_DECLS 25 #include <mach/mach_types.h> 26 #include <mach/vm_types.h> 27 #include <mach/kmod.h> 28 29 kmod_start_func_t test2_start; 30 kmod_stop_func_t test2_stop; 31 __END_DECLS 32 33 #include <libkern/c++/OSContainers.h> 34 #include <iokit/IOLib.h> 35 36 char *testBuffer = 37 " <?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" 38 " <!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\"> \n" 39 " <plist version=\"1.0\"> \n" 40 " <!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> \n" 41 " <plist version=\"0.9\"> \n" 42 " <dict> \n" 43 44 " <key>key true</key> <true/> \n" 45 " <key>key false</key> <false/> \n" 46 47 " <key>key d0</key> <data> </data> \n" 48 " <key>key d1</key> <data>AQ==</data> \n" 49 " <key>key d2</key> <data>ASM=</data> \n" 50 " <key>key d3</key> <data>ASNF</data> \n" 51 " <key>key d4</key> <data ID=\"1\">ASNFZw==</data> \n" 52 53 " <key>key i0</key> <integer></integer> \n" 54 " <key>key i1</key> <integer>123456789</integer> \n" 55 " <key>key i2</key> <integer>-123456789</integer> \n" 56 " <key>key i3</key> <integer size=\"32\" ID=\"2\">0x12345678</integer> \n" 57 58 " <key>key s0</key> <string></string> \n" 59 " <key>key s1</key> <string>string 1</string> \n" 60 " <key>key s2</key> <string ID=\"3\">string 2</string> \n" 61 " <key>key mr �</key> <string>mac roman copyright �</string> \n" 62 " <key>key uft8 \xc2\xa9</key> <string>utf-8 copyright \xc2\xa9</string> \n" 63 " <key>key <&></key> <string><&></string> \n" 64 65 " <key>key D0</key> <dict ID=\"4\"> \n" 66 " </dict> \n" 67 68 " <key>key a0</key> <array> \n" 69 " </array> \n" 70 71 " <key>key a1</key> <array ID=\"5\"> \n" 72 " <string>array string 1</string> \n" 73 " <string>array string 2</string> \n" 74 " </array> \n" 75 76 " <key>key r1</key> <ref IDREF=\"1\"/> \n" 77 " <key>key r2</key> <ref IDREF=\"2\"/> \n" 78 " <key>key r3</key> <ref IDREF=\"3\"/> \n" 79 " <key>key r4</key> <ref IDREF=\"4\"/> \n" 80 " <key>key r5</key> <ref IDREF=\"5\"/> \n" 81 82 " <key>key e1</key> <array/> \n" 83 " <key>key e2</key> <dict/> \n" 84 " <key>key e4</key> <integer/> \n" 85 " <key>key e5</key> <string/> \n" 86 " <key>key e6</key> <data/> \n" 87 88 " <key>key S0</key> <set> \n" 89 " </set> \n" 90 " <key>key S1</key> <set ID=\"6\"> \n" 91 " <string>set string 1</string> \n" 92 " <string>set string 2</string> \n" 93 " </set> \n" 94 " <key>key r6</key> <ref IDREF=\"6\"/> \n" 95 " <key>key e3</key> <set/> \n" 96 97 " </dict> \n" 98 " </plist> \n" 99 ; 100 101 /* 102 this causes the parser to return an empty string? it doesn't look like yyerror gets called 103 char *testBuffer = "<array ID=1><array IDREF=\"1\"/></array>" 104 105 */ 106 107 kern_return_t 108 test2_start(struct kmod_info *ki, void *data) 109 { 110 IOLog("test buffer start:\n%s\n:test buffer end.\n", testBuffer); 111 112 // test unserialize 113 OSString *errmsg = 0; 114 OSObject *d = OSUnserializeXML(testBuffer, &errmsg); 115 if (!d) { 116 if (errmsg) 117 IOLog("%s\n", errmsg->getCStringNoCopy()); 118 else 119 IOLog("bogus error message\n"); 120 121 return KMOD_RETURN_SUCCESS; 122 } 123 124 // test serialize 125 OSSerialize *s = OSSerialize::withCapacity(5); 126 if (!d->serialize(s)) { 127 IOLog("serialization failed\n"); 128 return KMOD_RETURN_SUCCESS; 129 } 130 131 IOLog("serialized object's length = %d, capacity = %d\n", s->getLength(), s->getCapacity()); 132 IOLog("object unformatted = %s\n", s->text()); 133 134 // try second time 135 OSObject *d2 = OSUnserializeXML(s->text(), &errmsg); 136 if (!d2) { 137 IOLog("%s\n", errmsg->getCStringNoCopy()); 138 return KMOD_RETURN_SUCCESS; 139 } 140 OSSerialize *s2 = OSSerialize::withCapacity(5); 141 if (!d2->serialize(s2)) { 142 IOLog("serialization #2 failed\n"); 143 return KMOD_RETURN_SUCCESS; 144 } 145 146 IOLog("serialized object's length = %d, capacity = %d\n", 147 s2->getLength(), s2->getCapacity()); 148 IOLog("object unformatted = %s\n", s2->text()); 149 150 IOLog("\nserialized objects compared %ssuccessfully textually\n\n", 151 strcmp(s->text(), s2->text()) ? "un":""); 152 153 IOLog("\nserialized objects compared %ssuccessfully objectwise\n\n", 154 d->isEqualTo(d2) ? "":"un"); 155 156 s2->release(); 157 if (d2) d2->release(); 158 s->release(); 159 if (d) d->release(); 160 161 return KMOD_RETURN_SUCCESS; 162 } 163 164 kern_return_t 165 test2_stop(struct kmod_info *ki, void *data) 166 { 167 return KMOD_RETURN_SUCCESS; 168 } 169