2 * Copyright (c) 1999-2013 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 65535
69 #define YYSTYPE object_t *
70 #define YYPARSE_PARAM state
71 #define YYLEX_PARAM (parser_state_t *)state
73 // this is the internal struct used to hold objects on parser stack
74 // it represents objects both before and after they have been created
75 typedef struct object {
78 struct object *elements;
80 OSSymbol *key; // for dictionary
82 void *data; // for data
83 char *string; // for string & symbol
84 long long number; // for number
88 // this code is reentrant, this structure contains all
89 // state information for the parsing of a single buffer
90 typedef struct parser_state {
91 const char *parseBuffer; // start of text to be parsed
92 int parseBufferIndex; // current index into text
93 int lineNumber; // current line number
94 object_t *objects; // internal objects in use
95 object_t *freeObjects; // internal objects that are free
96 OSDictionary *tags; // used to remember "ID" tags
97 OSString **errorString; // parse error with line
98 OSObject *parsedObject; // resultant object of parsed text
99 int parsedObjectCount;
102 #define STATE ((parser_state_t *)state)
105 #define yyerror(s) OSUnserializeerror(STATE, (s))
106 static int OSUnserializeerror(parser_state_t *state, const char *s);
108 static int yylex(YYSTYPE *lvalp, parser_state_t *state);
110 static object_t *newObject(parser_state_t *state);
111 static void freeObject(parser_state_t *state, object_t *o);
112 static void rememberObject(parser_state_t *state, int tag, OSObject *o);
113 static object_t *retrieveObject(parser_state_t *state, int tag);
114 static void cleanupObjects(parser_state_t *state);
116 static object_t *buildDictionary(parser_state_t *state, object_t *o);
117 static object_t *buildArray(parser_state_t *state, object_t *o);
118 static object_t *buildSet(parser_state_t *state, object_t *o);
119 static object_t *buildString(parser_state_t *state, object_t *o);
120 static object_t *buildSymbol(parser_state_t *state, object_t *o);
121 static object_t *buildData(parser_state_t *state, object_t *o);
122 static object_t *buildNumber(parser_state_t *state, object_t *o);
123 static object_t *buildBoolean(parser_state_t *state, object_t *o);
125 #include <libkern/OSRuntime.h>
127 #define malloc(s) kern_os_malloc(s)
128 #define realloc(a, s) kern_os_realloc(a, s)
129 #define free(a) kern_os_free((void *)a)
142 %% /* Grammar rules and actions follow */
144 input: /* empty */ { yyerror("unexpected end of buffer");
147 | object { STATE->parsedObject = $1->object;
149 freeObject(STATE, $1);
152 | SYNTAX_ERROR { yyerror("syntax error");
157 object: dict { $$ = buildDictionary(STATE, $1);
159 if (!yyval->object) {
160 yyerror("buildDictionary");
163 STATE->parsedObjectCount++;
164 if (STATE->parsedObjectCount > MAX_OBJECTS) {
165 yyerror("maximum object count");
169 | array { $$ = buildArray(STATE, $1);
171 if (!yyval->object) {
172 yyerror("buildArray");
175 STATE->parsedObjectCount++;
176 if (STATE->parsedObjectCount > MAX_OBJECTS) {
177 yyerror("maximum object count");
181 | set { $$ = buildSet(STATE, $1);
183 if (!yyval->object) {
187 STATE->parsedObjectCount++;
188 if (STATE->parsedObjectCount > MAX_OBJECTS) {
189 yyerror("maximum object count");
193 | string { $$ = buildString(STATE, $1);
195 if (!yyval->object) {
196 yyerror("buildString");
199 STATE->parsedObjectCount++;
200 if (STATE->parsedObjectCount > MAX_OBJECTS) {
201 yyerror("maximum object count");
205 | data { $$ = buildData(STATE, $1);
207 if (!yyval->object) {
208 yyerror("buildData");
211 STATE->parsedObjectCount++;
212 if (STATE->parsedObjectCount > MAX_OBJECTS) {
213 yyerror("maximum object count");
217 | number { $$ = buildNumber(STATE, $1);
219 if (!yyval->object) {
220 yyerror("buildNumber");
223 STATE->parsedObjectCount++;
224 if (STATE->parsedObjectCount > MAX_OBJECTS) {
225 yyerror("maximum object count");
229 | boolean { $$ = buildBoolean(STATE, $1);
231 if (!yyval->object) {
232 yyerror("buildBoolean");
235 STATE->parsedObjectCount++;
236 if (STATE->parsedObjectCount > MAX_OBJECTS) {
237 yyerror("maximum object count");
241 | idref { $$ = retrieveObject(STATE, $1->idref);
243 $$->object->retain();
245 yyerror("forward reference detected");
248 freeObject(STATE, $1);
250 STATE->parsedObjectCount++;
251 if (STATE->parsedObjectCount > MAX_OBJECTS) {
252 yyerror("maximum object count");
258 //------------------------------------------------------------------------------
260 dict: '{' '}' { $$ = $1;
263 | '{' pairs '}' { $$ = $1;
270 | pairs pair { $$ = $2;
276 if (o->key == $$->key) {
277 yyerror("duplicate dictionary key");
285 pair: key object { $$ = $1;
286 $$->key = (OSSymbol *)$$->object;
287 $$->object = $2->object;
290 freeObject(STATE, $2);
294 key: KEY { $$ = buildSymbol(STATE, $1);
296 // STATE->parsedObjectCount++;
297 // if (STATE->parsedObjectCount > MAX_OBJECTS) {
298 // yyerror("maximum object count");
304 //------------------------------------------------------------------------------
306 array: '(' ')' { $$ = $1;
309 | '(' elements ')' { $$ = $1;
315 set: '[' ']' { $$ = $1;
318 | '[' elements ']' { $$ = $1;
324 elements: object { $$ = $1;
327 | elements object { $$ = $2;
332 //------------------------------------------------------------------------------
352 OSUnserializeerror(parser_state_t * state, const char *s) /* Called by yyparse on errors */
354 if (state->errorString) {
355 char tempString[128];
356 snprintf(tempString, 128, "OSUnserializeXML: %s near line %d\n", s, state->lineNumber);
357 *(state->errorString) = OSString::withCString(tempString);
363 #define TAG_MAX_LENGTH 32
364 #define TAG_MAX_ATTRIBUTES 32
371 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
372 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
373 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
375 #define isSpace(c) ((c) == ' ' || (c) == '\t')
376 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
377 #define isDigit(c) ((c) >= '0' && (c) <= '9')
378 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f')
379 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
380 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-'))
383 getTag(parser_state_t *state,
384 char tag[TAG_MAX_LENGTH],
386 char attributes[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH],
387 char values[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH] )
390 int c = currentChar();
391 int tagType = TAG_START;
395 if (c != '<') return TAG_BAD;
396 c = nextChar(); // skip '<'
399 // <!TAG declarations >
403 bool isComment = (c == '-') && ((c = nextChar()) != 0) && (c == '-');
404 if (!isComment && !isAlpha(c)) return TAG_BAD; // <!1, <!-A, <!eos
406 while (c && (c = nextChar()) != 0) {
407 if (c == '\n') state->lineNumber++;
409 if (c != '-') continue;
411 if (c != '-') continue;
418 if (isComment) break;
425 // <? Processing Instructions ?>
427 while ((c = nextChar()) != 0) {
428 if (c == '\n') state->lineNumber++;
429 if (c != '?') continue;
431 if (!c) return TAG_IGNORE;
444 c = nextChar(); // skip '/'
447 if (!isAlpha(c)) return TAG_BAD;
449 /* find end of tag while copying it */
450 while (isAlphaNumeric(c)) {
453 if (length >= (TAG_MAX_LENGTH - 1)) return TAG_BAD;
458 // printf("tag %s, type %d\n", tag, tagType);
460 // look for attributes of the form attribute = "value" ...
461 while ((c != '>') && (c != '/')) {
462 while (isSpace(c)) c = nextChar();
465 while (isAlphaNumeric(c)) {
466 attributes[*attributeCount][length++] = c;
467 if (length >= (TAG_MAX_LENGTH - 1)) return TAG_BAD;
470 attributes[*attributeCount][length] = 0;
472 while (isSpace(c)) c = nextChar();
474 if (c != '=') return TAG_BAD;
477 while (isSpace(c)) c = nextChar();
479 if (c != '"') return TAG_BAD;
483 values[*attributeCount][length++] = c;
484 if (length >= (TAG_MAX_LENGTH - 1)) return TAG_BAD;
486 if (!c) return TAG_BAD;
488 values[*attributeCount][length] = 0;
490 c = nextChar(); // skip closing quote
492 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
493 // attributes[*attributeCount], values[*attributeCount], c);
496 if (*attributeCount >= TAG_MAX_ATTRIBUTES) return TAG_BAD;
500 c = nextChar(); // skip '/'
503 if (c != '>') return TAG_BAD;
504 c = nextChar(); // skip '>'
510 getString(parser_state_t *state)
512 int c = currentChar();
513 int start, length, i, j;
516 start = state->parseBufferIndex;
517 /* find end of string */
520 if (c == '\n') state->lineNumber++;
527 if (c != '<') return 0;
529 length = state->parseBufferIndex - start;
531 /* copy to null terminated buffer */
532 tempString = (char *)malloc(length + 1);
533 if (tempString == 0) {
534 printf("OSUnserializeXML: can't alloc temp memory\n");
538 // copy out string in tempString
539 // "&" -> '&', "<" -> '<', ">" -> '>'
543 c = state->parseBuffer[start + i++];
547 if ((i+3) > length) goto error;
548 c = state->parseBuffer[start + i++];
550 if (state->parseBuffer[start + i++] != 't') goto error;
551 if (state->parseBuffer[start + i++] != ';') goto error;
552 tempString[j++] = '<';
556 if (state->parseBuffer[start + i++] != 't') goto error;
557 if (state->parseBuffer[start + i++] != ';') goto error;
558 tempString[j++] = '>';
561 if ((i+3) > length) goto error;
563 if (state->parseBuffer[start + i++] != 'm') goto error;
564 if (state->parseBuffer[start + i++] != 'p') goto error;
565 if (state->parseBuffer[start + i++] != ';') goto error;
566 tempString[j++] = '&';
574 // printf("string %s\n", tempString);
579 if (tempString) free(tempString);
584 getNumber(parser_state_t *state)
586 unsigned long long n = 0;
589 int c = currentChar();
604 n = (n * base + c - '0');
608 n = (unsigned long long)((long long)n * (long long)-1);
611 while(isHexDigit(c)) {
613 n = (n * base + c - '0');
615 n = (n * base + 0xa + c - 'a');
620 // printf("number 0x%x\n", (unsigned long)n);
624 // taken from CFXMLParsing/CFPropertyList.c
626 static const signed char __CFPLDataDecodeTable[128] = {
627 /* 000 */ -1, -1, -1, -1, -1, -1, -1, -1,
628 /* 010 */ -1, -1, -1, -1, -1, -1, -1, -1,
629 /* 020 */ -1, -1, -1, -1, -1, -1, -1, -1,
630 /* 030 */ -1, -1, -1, -1, -1, -1, -1, -1,
631 /* ' ' */ -1, -1, -1, -1, -1, -1, -1, -1,
632 /* '(' */ -1, -1, -1, 62, -1, -1, -1, 63,
633 /* '0' */ 52, 53, 54, 55, 56, 57, 58, 59,
634 /* '8' */ 60, 61, -1, -1, -1, 0, -1, -1,
635 /* '@' */ -1, 0, 1, 2, 3, 4, 5, 6,
636 /* 'H' */ 7, 8, 9, 10, 11, 12, 13, 14,
637 /* 'P' */ 15, 16, 17, 18, 19, 20, 21, 22,
638 /* 'X' */ 23, 24, 25, -1, -1, -1, -1, -1,
639 /* '`' */ -1, 26, 27, 28, 29, 30, 31, 32,
640 /* 'h' */ 33, 34, 35, 36, 37, 38, 39, 40,
641 /* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48,
642 /* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1
645 #define DATA_ALLOC_SIZE 4096
648 getCFEncodedData(parser_state_t *state, unsigned int *size)
650 int numeq = 0, acc = 0, cntr = 0;
651 int tmpbufpos = 0, tmpbuflen = 0;
652 unsigned char *tmpbuf = (unsigned char *)malloc(DATA_ALLOC_SIZE);
654 int c = currentChar();
663 if (c == '=') numeq++; else numeq = 0;
664 if (c == '\n') state->lineNumber++;
665 if (__CFPLDataDecodeTable[c] < 0) {
671 acc += __CFPLDataDecodeTable[c];
672 if (0 == (cntr & 0x3)) {
673 if (tmpbuflen <= tmpbufpos + 2) {
674 tmpbuflen += DATA_ALLOC_SIZE;
675 tmpbuf = (unsigned char *)realloc(tmpbuf, tmpbuflen);
677 tmpbuf[tmpbufpos++] = (acc >> 16) & 0xff;
679 tmpbuf[tmpbufpos++] = (acc >> 8) & 0xff;
681 tmpbuf[tmpbufpos++] = acc & 0xff;
694 getHexData(parser_state_t *state, unsigned int *size)
697 unsigned char *d, *start, *lastStart;
699 start = lastStart = d = (unsigned char *)malloc(DATA_ALLOC_SIZE);
704 if (isSpace(c)) while ((c = nextChar()) != 0 && isSpace(c)) {};
714 } else if (isAlphaDigit(c)) {
715 *d = (0xa + (c - 'a')) << 4;
724 } else if (isAlphaDigit(c)) {
725 *d |= 0xa + (c - 'a');
731 if ((d - lastStart) >= DATA_ALLOC_SIZE) {
732 int oldsize = d - start;
733 start = (unsigned char *)realloc(start, oldsize + DATA_ALLOC_SIZE);
734 d = lastStart = start + oldsize;
750 yylex(YYSTYPE *lvalp, parser_state_t *state)
754 char tag[TAG_MAX_LENGTH];
756 char attributes[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH];
757 char values[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH];
763 /* skip white space */
764 if (isSpace(c)) while ((c = nextChar()) != 0 && isSpace(c)) {};
766 /* keep track of line number, don't return \n's */
773 // end of the buffer?
776 tagType = getTag(STATE, tag, &attributeCount, attributes, values);
777 if (tagType == TAG_BAD) return SYNTAX_ERROR;
778 if (tagType == TAG_IGNORE) goto top;
780 // handle allocation and check for "ID" and "IDREF" tags up front
781 *lvalp = object = newObject(STATE);
783 for (i=0; i < attributeCount; i++) {
784 if (attributes[i][0] == 'I' && attributes[i][1] == 'D') {
785 // check for idref's, note: we ignore the tag, for
786 // this to work correctly, all idrefs must be unique
787 // across the whole serialization
788 if (attributes[i][2] == 'R' && attributes[i][3] == 'E' &&
789 attributes[i][4] == 'F' && !attributes[i][5]) {
790 if (tagType != TAG_EMPTY) return SYNTAX_ERROR;
791 object->idref = strtol(values[i], NULL, 0);
795 if (!attributes[i][2]) {
796 object->idref = strtol(values[i], NULL, 0);
805 if (!strcmp(tag, "array")) {
806 if (tagType == TAG_EMPTY) {
807 object->elements = NULL;
810 return (tagType == TAG_START) ? '(' : ')';
814 if (!strcmp(tag, "dict")) {
815 if (tagType == TAG_EMPTY) {
816 object->elements = NULL;
819 return (tagType == TAG_START) ? '{' : '}';
821 if (!strcmp(tag, "data")) {
823 if (tagType == TAG_EMPTY) {
829 bool isHexFormat = false;
830 for (i=0; i < attributeCount; i++) {
831 if (!strcmp(attributes[i], "format") && !strcmp(values[i], "hex")) {
836 // CF encoded is the default form
838 object->data = getHexData(STATE, &size);
840 object->data = getCFEncodedData(STATE, &size);
843 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END) || strcmp(tag, "data")) {
850 if (!strcmp(tag, "false")) {
851 if (tagType == TAG_EMPTY) {
858 if (!strcmp(tag, "integer")) {
859 object->size = 64; // default
860 for (i=0; i < attributeCount; i++) {
861 if (!strcmp(attributes[i], "size")) {
862 object->size = strtoul(values[i], NULL, 0);
865 if (tagType == TAG_EMPTY) {
869 object->number = getNumber(STATE);
870 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END) || strcmp(tag, "integer")) {
877 if (!strcmp(tag, "key")) {
878 if (tagType == TAG_EMPTY) return SYNTAX_ERROR;
879 object->string = getString(STATE);
880 if (!object->string) {
883 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END)
884 || strcmp(tag, "key")) {
891 if (!strcmp(tag, "plist")) {
892 freeObject(STATE, object);
897 if (!strcmp(tag, "string")) {
898 if (tagType == TAG_EMPTY) {
899 object->string = (char *)malloc(1);
900 object->string[0] = 0;
903 object->string = getString(STATE);
904 if (!object->string) {
907 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END)
908 || strcmp(tag, "string")) {
913 if (!strcmp(tag, "set")) {
914 if (tagType == TAG_EMPTY) {
915 object->elements = NULL;
918 if (tagType == TAG_START) {
926 if (!strcmp(tag, "true")) {
927 if (tagType == TAG_EMPTY) {
938 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
939 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
940 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
942 // "java" like allocation, if this code hits a syntax error in the
943 // the middle of the parsed string we just bail with pointers hanging
944 // all over place, this code helps keeps it all together
946 //static int object_count = 0;
949 newObject(parser_state_t *state)
953 if (state->freeObjects) {
954 o = state->freeObjects;
955 state->freeObjects = state->freeObjects->next;
957 o = (object_t *)malloc(sizeof(object_t));
959 bzero(o, sizeof(object_t));
960 o->free = state->objects;
968 freeObject(parser_state_t * state, object_t *o)
970 o->next = state->freeObjects;
971 state->freeObjects = o;
975 cleanupObjects(parser_state_t *state)
977 object_t *t, *o = state->objects;
981 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
982 o->object->release();
985 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
989 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
993 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
1002 // printf("object_count = %d\n", object_count);
1005 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1006 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1007 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1010 rememberObject(parser_state_t *state, int tag, OSObject *o)
1013 snprintf(key, 16, "%u", tag);
1015 // printf("remember key %s\n", key);
1017 state->tags->setObject(key, o);
1021 retrieveObject(parser_state_t *state, int tag)
1026 snprintf(key, 16, "%u", tag);
1028 // printf("retrieve key '%s'\n", key);
1030 ref = state->tags->getObject(key);
1033 o = newObject(state);
1038 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1039 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1040 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1043 buildDictionary(parser_state_t *state, object_t * header)
1049 // get count and reverse order
1050 o = header->elements;
1051 header->elements = 0;
1057 t->next = header->elements;
1058 header->elements = t;
1061 dict = OSDictionary::withCapacity(count);
1062 if (header->idref >= 0) rememberObject(state, header->idref, dict);
1064 o = header->elements;
1066 dict->setObject(o->key, o->object);
1069 o->object->release();
1075 freeObject(state, t);
1083 buildArray(parser_state_t *state, object_t * header)
1089 // get count and reverse order
1090 o = header->elements;
1091 header->elements = 0;
1097 t->next = header->elements;
1098 header->elements = t;
1101 array = OSArray::withCapacity(count);
1102 if (header->idref >= 0) rememberObject(state, header->idref, array);
1104 o = header->elements;
1106 array->setObject(o->object);
1108 o->object->release();
1113 freeObject(state, t);
1121 buildSet(parser_state_t *state, object_t *header)
1123 object_t *o = buildArray(state, header);
1125 OSArray *array = (OSArray *)o->object;
1126 OSSet *set = OSSet::withArray(array, array->getCapacity());
1128 // write over the reference created in buildArray
1129 if (header->idref >= 0) rememberObject(state, header->idref, set);
1137 buildString(parser_state_t *state, object_t *o)
1141 string = OSString::withCString(o->string);
1142 if (o->idref >= 0) rememberObject(state, o->idref, string);
1152 buildSymbol(parser_state_t *state, object_t *o)
1156 symbol = const_cast<OSSymbol *>(OSSymbol::withCString(o->string));
1157 if (o->idref >= 0) rememberObject(state, o->idref, symbol);
1167 buildData(parser_state_t *state, object_t *o)
1172 data = OSData::withBytes(o->data, o->size);
1174 data = OSData::withCapacity(0);
1176 if (o->idref >= 0) rememberObject(state, o->idref, data);
1178 if (o->size) free(o->data);
1185 buildNumber(parser_state_t *state, object_t *o)
1187 OSNumber *number = OSNumber::withNumber(o->number, o->size);
1189 if (o->idref >= 0) rememberObject(state, o->idref, number);
1196 buildBoolean(parser_state_t *state __unused, object_t *o)
1198 o->object = ((o->number == 0) ? kOSBooleanFalse : kOSBooleanTrue);
1199 o->object->retain();
1204 OSUnserializeXML(const char *buffer, OSString **errorString)
1208 if (!buffer) return 0;
1209 parser_state_t *state = (parser_state_t *)malloc(sizeof(parser_state_t));
1210 if (!state) return 0;
1213 if (errorString) *errorString = NULL;
1215 state->parseBuffer = buffer;
1216 state->parseBufferIndex = 0;
1217 state->lineNumber = 1;
1219 state->freeObjects = 0;
1220 state->tags = OSDictionary::withCapacity(128);
1221 state->errorString = errorString;
1222 state->parsedObject = 0;
1223 state->parsedObjectCount = 0;
1225 (void)yyparse((void *)state);
1227 object = state->parsedObject;
1229 cleanupObjects(state);
1230 state->tags->release();
1236 #include <libkern/OSSerializeBinary.h>
1239 OSUnserializeXML(const char *buffer, size_t bufferSize, OSString **errorString)
1241 if (!buffer) return (0);
1242 if (bufferSize < sizeof(kOSSerializeBinarySignature)) return (0);
1244 if (!strcmp(kOSSerializeBinarySignature, buffer)) return OSUnserializeBinary(buffer, bufferSize, errorString);
1246 // XML must be null terminated
1247 if (buffer[bufferSize - 1]) return 0;
1249 return OSUnserializeXML(buffer, errorString);
1258 // DO NOT EDIT OSUnserializeXML.cpp!