2 * Copyright (c) 1999-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * OSUnserializeXML.y created by rsulack on Tue Oct 12 1999
35 // parser for unserializing OSContainer objects serialized to XML
38 // bison -p OSUnserializeXML OSUnserializeXML.y
39 // head -50 OSUnserializeXML.y > OSUnserializeXML.cpp
40 // sed -e "s/#include <stdio.h>//" < OSUnserializeXML.tab.c >> OSUnserializeXML.cpp
42 // when changing code check in both OSUnserializeXML.y and OSUnserializeXML.cpp
48 // DO NOT EDIT OSUnserializeXML.cpp!
63 #include <libkern/c++/OSMetaClass.h>
64 #include <libkern/c++/OSContainers.h>
65 #include <libkern/c++/OSLib.h>
67 #define MAX_OBJECTS 131071
68 #define MAX_REFED_OBJECTS 65535
70 #define YYSTYPE object_t *
71 #define YYPARSE_PARAM state
72 #define YYLEX_PARAM (parser_state_t *)state
74 // this is the internal struct used to hold objects on parser stack
75 // it represents objects both before and after they have been created
76 typedef struct object {
79 struct object *elements;
81 OSSymbol *key; // for dictionary
83 void *data; // for data
84 char *string; // for string & symbol
85 long long number; // for number
89 // this code is reentrant, this structure contains all
90 // state information for the parsing of a single buffer
91 typedef struct parser_state {
92 const char *parseBuffer; // start of text to be parsed
93 int parseBufferIndex; // current index into text
94 int lineNumber; // current line number
95 object_t *objects; // internal objects in use
96 object_t *freeObjects; // internal objects that are free
97 OSDictionary *tags; // used to remember "ID" tags
98 OSString **errorString; // parse error with line
99 OSObject *parsedObject; // resultant object of parsed text
100 int parsedObjectCount;
101 int retrievedObjectCount;
104 #define STATE ((parser_state_t *)state)
107 #define yyerror(s) OSUnserializeerror(STATE, (s))
108 static int OSUnserializeerror(parser_state_t *state, const char *s);
110 static int yylex(YYSTYPE *lvalp, parser_state_t *state);
112 static object_t *newObject(parser_state_t *state);
113 static void freeObject(parser_state_t *state, object_t *o);
114 static void rememberObject(parser_state_t *state, int tag, OSObject *o);
115 static object_t *retrieveObject(parser_state_t *state, int tag);
116 static void cleanupObjects(parser_state_t *state);
118 static object_t *buildDictionary(parser_state_t *state, object_t *o);
119 static object_t *buildArray(parser_state_t *state, object_t *o);
120 static object_t *buildSet(parser_state_t *state, object_t *o);
121 static object_t *buildString(parser_state_t *state, object_t *o);
122 static object_t *buildSymbol(parser_state_t *state, object_t *o);
123 static object_t *buildData(parser_state_t *state, object_t *o);
124 static object_t *buildNumber(parser_state_t *state, object_t *o);
125 static object_t *buildBoolean(parser_state_t *state, object_t *o);
127 #include <libkern/OSRuntime.h>
129 #define malloc(s) kern_os_malloc(s)
130 #define realloc(a, s) kern_os_realloc(a, s)
131 #define free(a) kern_os_free((void *)a)
144 %% /* Grammar rules and actions follow */
146 input: /* empty */ { yyerror("unexpected end of buffer");
149 | object { STATE->parsedObject = $1->object;
151 freeObject(STATE, $1);
154 | SYNTAX_ERROR { yyerror("syntax error");
159 object: dict { $$ = buildDictionary(STATE, $1);
161 if (!yyval->object) {
162 yyerror("buildDictionary");
165 STATE->parsedObjectCount++;
166 if (STATE->parsedObjectCount > MAX_OBJECTS) {
167 yyerror("maximum object count");
171 | array { $$ = buildArray(STATE, $1);
173 if (!yyval->object) {
174 yyerror("buildArray");
177 STATE->parsedObjectCount++;
178 if (STATE->parsedObjectCount > MAX_OBJECTS) {
179 yyerror("maximum object count");
183 | set { $$ = buildSet(STATE, $1);
185 if (!yyval->object) {
189 STATE->parsedObjectCount++;
190 if (STATE->parsedObjectCount > MAX_OBJECTS) {
191 yyerror("maximum object count");
195 | string { $$ = buildString(STATE, $1);
197 if (!yyval->object) {
198 yyerror("buildString");
201 STATE->parsedObjectCount++;
202 if (STATE->parsedObjectCount > MAX_OBJECTS) {
203 yyerror("maximum object count");
207 | data { $$ = buildData(STATE, $1);
209 if (!yyval->object) {
210 yyerror("buildData");
213 STATE->parsedObjectCount++;
214 if (STATE->parsedObjectCount > MAX_OBJECTS) {
215 yyerror("maximum object count");
219 | number { $$ = buildNumber(STATE, $1);
221 if (!yyval->object) {
222 yyerror("buildNumber");
225 STATE->parsedObjectCount++;
226 if (STATE->parsedObjectCount > MAX_OBJECTS) {
227 yyerror("maximum object count");
231 | boolean { $$ = buildBoolean(STATE, $1);
233 if (!yyval->object) {
234 yyerror("buildBoolean");
237 STATE->parsedObjectCount++;
238 if (STATE->parsedObjectCount > MAX_OBJECTS) {
239 yyerror("maximum object count");
243 | idref { $$ = retrieveObject(STATE, $1->idref);
245 STATE->retrievedObjectCount++;
246 $$->object->retain();
247 if (STATE->retrievedObjectCount > MAX_REFED_OBJECTS) {
248 yyerror("maximum object reference count");
252 yyerror("forward reference detected");
255 freeObject(STATE, $1);
257 STATE->parsedObjectCount++;
258 if (STATE->parsedObjectCount > MAX_OBJECTS) {
259 yyerror("maximum object count");
265 //------------------------------------------------------------------------------
267 dict: '{' '}' { $$ = $1;
270 | '{' pairs '}' { $$ = $1;
277 | pairs pair { $$ = $2;
283 if (o->key == $$->key) {
284 yyerror("duplicate dictionary key");
292 pair: key object { $$ = $1;
293 $$->key = (OSSymbol *)$$->object;
294 $$->object = $2->object;
297 freeObject(STATE, $2);
301 key: KEY { $$ = buildSymbol(STATE, $1);
303 // STATE->parsedObjectCount++;
304 // if (STATE->parsedObjectCount > MAX_OBJECTS) {
305 // yyerror("maximum object count");
311 //------------------------------------------------------------------------------
313 array: '(' ')' { $$ = $1;
316 | '(' elements ')' { $$ = $1;
322 set: '[' ']' { $$ = $1;
325 | '[' elements ']' { $$ = $1;
331 elements: object { $$ = $1;
334 | elements object { $$ = $2;
339 //------------------------------------------------------------------------------
359 OSUnserializeerror(parser_state_t * state, const char *s) /* Called by yyparse on errors */
361 if (state->errorString) {
362 char tempString[128];
363 snprintf(tempString, 128, "OSUnserializeXML: %s near line %d\n", s, state->lineNumber);
364 *(state->errorString) = OSString::withCString(tempString);
370 #define TAG_MAX_LENGTH 32
371 #define TAG_MAX_ATTRIBUTES 32
378 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
379 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
380 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
382 #define isSpace(c) ((c) == ' ' || (c) == '\t')
383 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
384 #define isDigit(c) ((c) >= '0' && (c) <= '9')
385 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f')
386 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
387 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-'))
390 getTag(parser_state_t *state,
391 char tag[TAG_MAX_LENGTH],
393 char attributes[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH],
394 char values[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH] )
397 int c = currentChar();
398 int tagType = TAG_START;
405 c = nextChar(); // skip '<'
408 // <!TAG declarations >
412 bool isComment = (c == '-') && ((c = nextChar()) != 0) && (c == '-');
413 if (!isComment && !isAlpha(c)) {
414 return TAG_BAD; // <!1, <!-A, <!eos
416 while (c && (c = nextChar()) != 0) {
440 // <? Processing Instructions ?>
442 while ((c = nextChar()) != 0) {
462 c = nextChar(); // skip '/'
469 /* find end of tag while copying it */
470 while (isAlphaNumeric(c)) {
473 if (length >= (TAG_MAX_LENGTH - 1)) {
480 // printf("tag %s, type %d\n", tag, tagType);
482 // look for attributes of the form attribute = "value" ...
483 while ((c != '>') && (c != '/')) {
489 while (isAlphaNumeric(c)) {
490 attributes[*attributeCount][length++] = c;
491 if (length >= (TAG_MAX_LENGTH - 1)) {
496 attributes[*attributeCount][length] = 0;
517 values[*attributeCount][length++] = c;
518 if (length >= (TAG_MAX_LENGTH - 1)) {
526 values[*attributeCount][length] = 0;
528 c = nextChar(); // skip closing quote
530 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
531 // attributes[*attributeCount], values[*attributeCount], c);
534 if (*attributeCount >= TAG_MAX_ATTRIBUTES) {
540 c = nextChar(); // skip '/'
546 c = nextChar(); // skip '>'
552 getString(parser_state_t *state)
554 int c = currentChar();
555 int start, length, i, j;
558 start = state->parseBufferIndex;
559 /* find end of string */
575 length = state->parseBufferIndex - start;
577 /* copy to null terminated buffer */
578 tempString = (char *)malloc(length + 1);
579 if (tempString == NULL) {
580 printf("OSUnserializeXML: can't alloc temp memory\n");
584 // copy out string in tempString
585 // "&" -> '&', "<" -> '<', ">" -> '>'
589 c = state->parseBuffer[start + i++];
593 if ((i + 3) > length) {
596 c = state->parseBuffer[start + i++];
598 if (state->parseBuffer[start + i++] != 't') {
601 if (state->parseBuffer[start + i++] != ';') {
604 tempString[j++] = '<';
608 if (state->parseBuffer[start + i++] != 't') {
611 if (state->parseBuffer[start + i++] != ';') {
614 tempString[j++] = '>';
617 if ((i + 3) > length) {
621 if (state->parseBuffer[start + i++] != 'm') {
624 if (state->parseBuffer[start + i++] != 'p') {
627 if (state->parseBuffer[start + i++] != ';') {
630 tempString[j++] = '&';
638 // printf("string %s\n", tempString);
650 getNumber(parser_state_t *state)
652 unsigned long long n = 0;
655 int c = currentChar();
670 n = (n * base + c - '0');
674 n = (unsigned long long)((long long)n * (long long)-1);
677 while (isHexDigit(c)) {
679 n = (n * base + c - '0');
681 n = (n * base + 0xa + c - 'a');
686 // printf("number 0x%x\n", (unsigned long)n);
690 // taken from CFXMLParsing/CFPropertyList.c
692 static const signed char __CFPLDataDecodeTable[128] = {
693 /* 000 */ -1, -1, -1, -1, -1, -1, -1, -1,
694 /* 010 */ -1, -1, -1, -1, -1, -1, -1, -1,
695 /* 020 */ -1, -1, -1, -1, -1, -1, -1, -1,
696 /* 030 */ -1, -1, -1, -1, -1, -1, -1, -1,
697 /* ' ' */ -1, -1, -1, -1, -1, -1, -1, -1,
698 /* '(' */ -1, -1, -1, 62, -1, -1, -1, 63,
699 /* '0' */ 52, 53, 54, 55, 56, 57, 58, 59,
700 /* '8' */ 60, 61, -1, -1, -1, 0, -1, -1,
701 /* '@' */ -1, 0, 1, 2, 3, 4, 5, 6,
702 /* 'H' */ 7, 8, 9, 10, 11, 12, 13, 14,
703 /* 'P' */ 15, 16, 17, 18, 19, 20, 21, 22,
704 /* 'X' */ 23, 24, 25, -1, -1, -1, -1, -1,
705 /* '`' */ -1, 26, 27, 28, 29, 30, 31, 32,
706 /* 'h' */ 33, 34, 35, 36, 37, 38, 39, 40,
707 /* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48,
708 /* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1
711 #define DATA_ALLOC_SIZE 4096
714 getCFEncodedData(parser_state_t *state, unsigned int *size)
716 int numeq = 0, cntr = 0;
717 unsigned int acc = 0;
718 int tmpbufpos = 0, tmpbuflen = 0;
719 unsigned char *tmpbuf = (unsigned char *)malloc(DATA_ALLOC_SIZE);
721 int c = currentChar();
738 if (__CFPLDataDecodeTable[c] < 0) {
744 acc += __CFPLDataDecodeTable[c];
745 if (0 == (cntr & 0x3)) {
746 if (tmpbuflen <= tmpbufpos + 2) {
747 tmpbuflen += DATA_ALLOC_SIZE;
748 tmpbuf = (unsigned char *)realloc(tmpbuf, tmpbuflen);
750 tmpbuf[tmpbufpos++] = (acc >> 16) & 0xff;
752 tmpbuf[tmpbufpos++] = (acc >> 8) & 0xff;
755 tmpbuf[tmpbufpos++] = acc & 0xff;
769 getHexData(parser_state_t *state, unsigned int *size)
772 unsigned char *d, *start, *lastStart;
774 start = lastStart = d = (unsigned char *)malloc(DATA_ALLOC_SIZE);
779 while ((c = nextChar()) != 0 && isSpace(c)) {
792 } else if (isAlphaDigit(c)) {
793 *d = (0xa + (c - 'a')) << 4;
802 } else if (isAlphaDigit(c)) {
803 *d |= 0xa + (c - 'a');
809 if ((d - lastStart) >= DATA_ALLOC_SIZE) {
810 int oldsize = d - start;
811 start = (unsigned char *)realloc(start, oldsize + DATA_ALLOC_SIZE);
812 d = lastStart = start + oldsize;
828 yylex(YYSTYPE *lvalp, parser_state_t *state)
832 char tag[TAG_MAX_LENGTH];
834 char attributes[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH];
835 char values[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH];
841 /* skip white space */
843 while ((c = nextChar()) != 0 && isSpace(c)) {
848 /* keep track of line number, don't return \n's */
855 // end of the buffer?
860 tagType = getTag(STATE, tag, &attributeCount, attributes, values);
861 if (tagType == TAG_BAD) {
864 if (tagType == TAG_IGNORE) {
868 // handle allocation and check for "ID" and "IDREF" tags up front
869 *lvalp = object = newObject(STATE);
871 for (i = 0; i < attributeCount; i++) {
872 if (attributes[i][0] == 'I' && attributes[i][1] == 'D') {
873 // check for idref's, note: we ignore the tag, for
874 // this to work correctly, all idrefs must be unique
875 // across the whole serialization
876 if (attributes[i][2] == 'R' && attributes[i][3] == 'E' &&
877 attributes[i][4] == 'F' && !attributes[i][5]) {
878 if (tagType != TAG_EMPTY) {
881 object->idref = strtol(values[i], NULL, 0);
885 if (!attributes[i][2]) {
886 object->idref = strtol(values[i], NULL, 0);
895 if (!strcmp(tag, "array")) {
896 if (tagType == TAG_EMPTY) {
897 object->elements = NULL;
900 return (tagType == TAG_START) ? '(' : ')';
904 if (!strcmp(tag, "dict")) {
905 if (tagType == TAG_EMPTY) {
906 object->elements = NULL;
909 return (tagType == TAG_START) ? '{' : '}';
911 if (!strcmp(tag, "data")) {
913 if (tagType == TAG_EMPTY) {
919 bool isHexFormat = false;
920 for (i = 0; i < attributeCount; i++) {
921 if (!strcmp(attributes[i], "format") && !strcmp(values[i], "hex")) {
926 // CF encoded is the default form
928 object->data = getHexData(STATE, &size);
930 object->data = getCFEncodedData(STATE, &size);
933 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END) || strcmp(tag, "data")) {
940 if (!strcmp(tag, "false")) {
941 if (tagType == TAG_EMPTY) {
948 if (!strcmp(tag, "integer")) {
949 object->size = 64; // default
950 for (i = 0; i < attributeCount; i++) {
951 if (!strcmp(attributes[i], "size")) {
952 object->size = strtoul(values[i], NULL, 0);
955 if (tagType == TAG_EMPTY) {
959 object->number = getNumber(STATE);
960 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END) || strcmp(tag, "integer")) {
967 if (!strcmp(tag, "key")) {
968 if (tagType == TAG_EMPTY) {
971 object->string = getString(STATE);
972 if (!object->string) {
975 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END)
976 || strcmp(tag, "key")) {
983 if (!strcmp(tag, "plist")) {
984 freeObject(STATE, object);
989 if (!strcmp(tag, "string")) {
990 if (tagType == TAG_EMPTY) {
991 object->string = (char *)malloc(1);
992 object->string[0] = 0;
995 object->string = getString(STATE);
996 if (!object->string) {
999 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END)
1000 || strcmp(tag, "string")) {
1001 return SYNTAX_ERROR;
1005 if (!strcmp(tag, "set")) {
1006 if (tagType == TAG_EMPTY) {
1007 object->elements = NULL;
1010 if (tagType == TAG_START) {
1018 if (!strcmp(tag, "true")) {
1019 if (tagType == TAG_EMPTY) {
1027 return SYNTAX_ERROR;
1030 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1031 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1032 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1034 // "java" like allocation, if this code hits a syntax error in the
1035 // the middle of the parsed string we just bail with pointers hanging
1036 // all over place, this code helps keeps it all together
1038 //static int object_count = 0;
1041 newObject(parser_state_t *state)
1045 if (state->freeObjects) {
1046 o = state->freeObjects;
1047 state->freeObjects = state->freeObjects->next;
1049 o = (object_t *)malloc(sizeof(object_t));
1051 bzero(o, sizeof(object_t));
1052 o->free = state->objects;
1060 freeObject(parser_state_t * state, object_t *o)
1062 o->next = state->freeObjects;
1063 state->freeObjects = o;
1067 cleanupObjects(parser_state_t *state)
1069 object_t *t, *o = state->objects;
1073 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
1074 o->object->release();
1077 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
1081 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
1085 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
1094 // printf("object_count = %d\n", object_count);
1097 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1098 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1099 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1102 rememberObject(parser_state_t *state, int tag, OSObject *o)
1105 snprintf(key, 16, "%u", tag);
1107 // printf("remember key %s\n", key);
1109 state->tags->setObject(key, o);
1113 retrieveObject(parser_state_t *state, int tag)
1118 snprintf(key, 16, "%u", tag);
1120 // printf("retrieve key '%s'\n", key);
1122 ref = state->tags->getObject(key);
1127 o = newObject(state);
1132 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1133 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1134 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1137 buildDictionary(parser_state_t *state, object_t * header)
1143 // get count and reverse order
1144 o = header->elements;
1145 header->elements = 0;
1151 t->next = header->elements;
1152 header->elements = t;
1155 dict = OSDictionary::withCapacity(count);
1156 if (header->idref >= 0) {
1157 rememberObject(state, header->idref, dict);
1160 o = header->elements;
1162 dict->setObject(o->key, o->object);
1165 o->object->release();
1171 freeObject(state, t);
1179 buildArray(parser_state_t *state, object_t * header)
1185 // get count and reverse order
1186 o = header->elements;
1187 header->elements = 0;
1193 t->next = header->elements;
1194 header->elements = t;
1197 array = OSArray::withCapacity(count);
1198 if (header->idref >= 0) {
1199 rememberObject(state, header->idref, array);
1202 o = header->elements;
1204 array->setObject(o->object);
1206 o->object->release();
1211 freeObject(state, t);
1219 buildSet(parser_state_t *state, object_t *header)
1221 object_t *o = buildArray(state, header);
1223 OSArray *array = (OSArray *)o->object;
1224 OSSet *set = OSSet::withArray(array, array->getCapacity());
1226 // write over the reference created in buildArray
1227 if (header->idref >= 0) {
1228 rememberObject(state, header->idref, set);
1237 buildString(parser_state_t *state, object_t *o)
1241 string = OSString::withCString(o->string);
1242 if (o->idref >= 0) {
1243 rememberObject(state, o->idref, string);
1254 buildSymbol(parser_state_t *state, object_t *o)
1258 symbol = const_cast < OSSymbol * > (OSSymbol::withCString(o->string));
1259 if (o->idref >= 0) {
1260 rememberObject(state, o->idref, symbol);
1271 buildData(parser_state_t *state, object_t *o)
1276 data = OSData::withBytes(o->data, o->size);
1278 data = OSData::withCapacity(0);
1280 if (o->idref >= 0) {
1281 rememberObject(state, o->idref, data);
1293 buildNumber(parser_state_t *state, object_t *o)
1295 OSNumber *number = OSNumber::withNumber(o->number, o->size);
1297 if (o->idref >= 0) {
1298 rememberObject(state, o->idref, number);
1306 buildBoolean(parser_state_t *state __unused, object_t *o)
1308 o->object = ((o->number == 0) ? kOSBooleanFalse : kOSBooleanTrue);
1309 o->object->retain();
1314 OSUnserializeXML(const char *buffer, OSString **errorString)
1321 parser_state_t *state = (parser_state_t *)malloc(sizeof(parser_state_t));
1328 *errorString = NULL;
1331 state->parseBuffer = buffer;
1332 state->parseBufferIndex = 0;
1333 state->lineNumber = 1;
1335 state->freeObjects = 0;
1336 state->tags = OSDictionary::withCapacity(128);
1337 state->errorString = errorString;
1338 state->parsedObject = 0;
1339 state->parsedObjectCount = 0;
1340 state->retrievedObjectCount = 0;
1342 (void)yyparse((void *)state);
1344 object = state->parsedObject;
1346 cleanupObjects(state);
1347 state->tags->release();
1353 #include <libkern/OSSerializeBinary.h>
1356 OSUnserializeXML(const char *buffer, size_t bufferSize, OSString **errorString)
1361 if (bufferSize < sizeof(kOSSerializeBinarySignature)) {
1365 if (!strcmp(kOSSerializeBinarySignature, buffer)
1366 || (kOSSerializeIndexedBinarySignature == (uint8_t)buffer[0])) {
1367 return OSUnserializeBinary(buffer, bufferSize, errorString);
1370 // XML must be null terminated
1371 if (buffer[bufferSize - 1]) {
1375 return OSUnserializeXML(buffer, errorString);
1384 // DO NOT EDIT OSUnserializeXML.cpp!