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);
126 extern void *kern_os_malloc(size_t size);
127 extern void *kern_os_realloc(void * addr, size_t size);
128 extern void kern_os_free(void * addr);
132 #define malloc(s) kern_os_malloc(s)
133 #define realloc(a, s) kern_os_realloc(a, s)
134 #define free(a) kern_os_free((void *)a)
147 %% /* Grammar rules and actions follow */
149 input: /* empty */ { yyerror("unexpected end of buffer");
152 | object { STATE->parsedObject = $1->object;
154 freeObject(STATE, $1);
157 | SYNTAX_ERROR { yyerror("syntax error");
162 object: dict { $$ = buildDictionary(STATE, $1);
164 STATE->parsedObjectCount++;
165 if (STATE->parsedObjectCount > MAX_OBJECTS) {
166 yyerror("maximum object count");
170 | array { $$ = buildArray(STATE, $1);
172 STATE->parsedObjectCount++;
173 if (STATE->parsedObjectCount > MAX_OBJECTS) {
174 yyerror("maximum object count");
178 | set { $$ = buildSet(STATE, $1);
180 STATE->parsedObjectCount++;
181 if (STATE->parsedObjectCount > MAX_OBJECTS) {
182 yyerror("maximum object count");
186 | string { $$ = buildString(STATE, $1);
188 STATE->parsedObjectCount++;
189 if (STATE->parsedObjectCount > MAX_OBJECTS) {
190 yyerror("maximum object count");
194 | data { $$ = buildData(STATE, $1);
196 STATE->parsedObjectCount++;
197 if (STATE->parsedObjectCount > MAX_OBJECTS) {
198 yyerror("maximum object count");
202 | number { $$ = buildNumber(STATE, $1);
204 STATE->parsedObjectCount++;
205 if (STATE->parsedObjectCount > MAX_OBJECTS) {
206 yyerror("maximum object count");
210 | boolean { $$ = buildBoolean(STATE, $1);
212 STATE->parsedObjectCount++;
213 if (STATE->parsedObjectCount > MAX_OBJECTS) {
214 yyerror("maximum object count");
218 | idref { $$ = retrieveObject(STATE, $1->idref);
220 $$->object->retain();
222 yyerror("forward reference detected");
225 freeObject(STATE, $1);
227 STATE->parsedObjectCount++;
228 if (STATE->parsedObjectCount > MAX_OBJECTS) {
229 yyerror("maximum object count");
235 //------------------------------------------------------------------------------
237 dict: '{' '}' { $$ = $1;
240 | '{' pairs '}' { $$ = $1;
247 | pairs pair { $$ = $2;
253 if (o->key == $$->key) {
254 yyerror("duplicate dictionary key");
262 pair: key object { $$ = $1;
263 $$->key = (OSSymbol *)$$->object;
264 $$->object = $2->object;
267 freeObject(STATE, $2);
271 key: KEY { $$ = buildSymbol(STATE, $1);
273 // STATE->parsedObjectCount++;
274 // if (STATE->parsedObjectCount > MAX_OBJECTS) {
275 // yyerror("maximum object count");
281 //------------------------------------------------------------------------------
283 array: '(' ')' { $$ = $1;
286 | '(' elements ')' { $$ = $1;
292 set: '[' ']' { $$ = $1;
295 | '[' elements ']' { $$ = $1;
301 elements: object { $$ = $1;
304 | elements object { $$ = $2;
309 //------------------------------------------------------------------------------
329 OSUnserializeerror(parser_state_t * state, const char *s) /* Called by yyparse on errors */
331 if (state->errorString) {
332 char tempString[128];
333 snprintf(tempString, 128, "OSUnserializeXML: %s near line %d\n", s, state->lineNumber);
334 *(state->errorString) = OSString::withCString(tempString);
340 #define TAG_MAX_LENGTH 32
341 #define TAG_MAX_ATTRIBUTES 32
348 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
349 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
350 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
352 #define isSpace(c) ((c) == ' ' || (c) == '\t')
353 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
354 #define isDigit(c) ((c) >= '0' && (c) <= '9')
355 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f')
356 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
357 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-'))
360 getTag(parser_state_t *state,
361 char tag[TAG_MAX_LENGTH],
363 char attributes[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH],
364 char values[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH] )
367 int c = currentChar();
368 int tagType = TAG_START;
372 if (c != '<') return TAG_BAD;
373 c = nextChar(); // skip '<'
376 // <!TAG declarations >
380 bool isComment = (c == '-') && ((c = nextChar()) != 0) && (c == '-');
381 if (!isComment && !isAlpha(c)) return TAG_BAD; // <!1, <!-A, <!eos
383 while (c && (c = nextChar()) != 0) {
384 if (c == '\n') state->lineNumber++;
386 if (c != '-') continue;
388 if (c != '-') continue;
395 if (isComment) break;
402 // <? Processing Instructions ?>
404 while ((c = nextChar()) != 0) {
405 if (c == '\n') state->lineNumber++;
406 if (c != '?') continue;
420 c = nextChar(); // skip '/'
423 if (!isAlpha(c)) return TAG_BAD;
425 /* find end of tag while copying it */
426 while (isAlphaNumeric(c)) {
429 if (length >= (TAG_MAX_LENGTH - 1)) return TAG_BAD;
434 // printf("tag %s, type %d\n", tag, tagType);
436 // look for attributes of the form attribute = "value" ...
437 while ((c != '>') && (c != '/')) {
438 while (isSpace(c)) c = nextChar();
441 while (isAlphaNumeric(c)) {
442 attributes[*attributeCount][length++] = c;
443 if (length >= (TAG_MAX_LENGTH - 1)) return TAG_BAD;
446 attributes[*attributeCount][length] = 0;
448 while (isSpace(c)) c = nextChar();
450 if (c != '=') return TAG_BAD;
453 while (isSpace(c)) c = nextChar();
455 if (c != '"') return TAG_BAD;
459 values[*attributeCount][length++] = c;
460 if (length >= (TAG_MAX_LENGTH - 1)) return TAG_BAD;
463 values[*attributeCount][length] = 0;
465 c = nextChar(); // skip closing quote
467 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
468 // attributes[*attributeCount], values[*attributeCount], c);
471 if (*attributeCount >= TAG_MAX_ATTRIBUTES) return TAG_BAD;
475 c = nextChar(); // skip '/'
478 if (c != '>') return TAG_BAD;
479 c = nextChar(); // skip '>'
485 getString(parser_state_t *state)
487 int c = currentChar();
488 int start, length, i, j;
491 start = state->parseBufferIndex;
492 /* find end of string */
495 if (c == '\n') state->lineNumber++;
502 if (c != '<') return 0;
504 length = state->parseBufferIndex - start;
506 /* copy to null terminated buffer */
507 tempString = (char *)malloc(length + 1);
508 if (tempString == 0) {
509 printf("OSUnserializeXML: can't alloc temp memory\n");
513 // copy out string in tempString
514 // "&" -> '&', "<" -> '<', ">" -> '>'
518 c = state->parseBuffer[start + i++];
522 if ((i+3) > length) goto error;
523 c = state->parseBuffer[start + i++];
525 if (state->parseBuffer[start + i++] != 't') goto error;
526 if (state->parseBuffer[start + i++] != ';') goto error;
527 tempString[j++] = '<';
531 if (state->parseBuffer[start + i++] != 't') goto error;
532 if (state->parseBuffer[start + i++] != ';') goto error;
533 tempString[j++] = '>';
536 if ((i+3) > length) goto error;
538 if (state->parseBuffer[start + i++] != 'm') goto error;
539 if (state->parseBuffer[start + i++] != 'p') goto error;
540 if (state->parseBuffer[start + i++] != ';') goto error;
541 tempString[j++] = '&';
549 // printf("string %s\n", tempString);
554 if (tempString) free(tempString);
559 getNumber(parser_state_t *state)
561 unsigned long long n = 0;
564 int c = currentChar();
579 n = (n * base + c - '0');
583 n = (unsigned long long)((long long)n * (long long)-1);
586 while(isHexDigit(c)) {
588 n = (n * base + c - '0');
590 n = (n * base + 0xa + c - 'a');
595 // printf("number 0x%x\n", (unsigned long)n);
599 // taken from CFXMLParsing/CFPropertyList.c
601 static const signed char __CFPLDataDecodeTable[128] = {
602 /* 000 */ -1, -1, -1, -1, -1, -1, -1, -1,
603 /* 010 */ -1, -1, -1, -1, -1, -1, -1, -1,
604 /* 020 */ -1, -1, -1, -1, -1, -1, -1, -1,
605 /* 030 */ -1, -1, -1, -1, -1, -1, -1, -1,
606 /* ' ' */ -1, -1, -1, -1, -1, -1, -1, -1,
607 /* '(' */ -1, -1, -1, 62, -1, -1, -1, 63,
608 /* '0' */ 52, 53, 54, 55, 56, 57, 58, 59,
609 /* '8' */ 60, 61, -1, -1, -1, 0, -1, -1,
610 /* '@' */ -1, 0, 1, 2, 3, 4, 5, 6,
611 /* 'H' */ 7, 8, 9, 10, 11, 12, 13, 14,
612 /* 'P' */ 15, 16, 17, 18, 19, 20, 21, 22,
613 /* 'X' */ 23, 24, 25, -1, -1, -1, -1, -1,
614 /* '`' */ -1, 26, 27, 28, 29, 30, 31, 32,
615 /* 'h' */ 33, 34, 35, 36, 37, 38, 39, 40,
616 /* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48,
617 /* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1
620 #define DATA_ALLOC_SIZE 4096
623 getCFEncodedData(parser_state_t *state, unsigned int *size)
625 int numeq = 0, acc = 0, cntr = 0;
626 int tmpbufpos = 0, tmpbuflen = 0;
627 unsigned char *tmpbuf = (unsigned char *)malloc(DATA_ALLOC_SIZE);
629 int c = currentChar();
638 if (c == '=') numeq++; else numeq = 0;
639 if (c == '\n') state->lineNumber++;
640 if (__CFPLDataDecodeTable[c] < 0) {
646 acc += __CFPLDataDecodeTable[c];
647 if (0 == (cntr & 0x3)) {
648 if (tmpbuflen <= tmpbufpos + 2) {
649 tmpbuflen += DATA_ALLOC_SIZE;
650 tmpbuf = (unsigned char *)realloc(tmpbuf, tmpbuflen);
652 tmpbuf[tmpbufpos++] = (acc >> 16) & 0xff;
654 tmpbuf[tmpbufpos++] = (acc >> 8) & 0xff;
656 tmpbuf[tmpbufpos++] = acc & 0xff;
669 getHexData(parser_state_t *state, unsigned int *size)
672 unsigned char *d, *start, *lastStart;
674 start = lastStart = d = (unsigned char *)malloc(DATA_ALLOC_SIZE);
679 if (isSpace(c)) while ((c = nextChar()) != 0 && isSpace(c)) {};
689 } else if (isAlphaDigit(c)) {
690 *d = (0xa + (c - 'a')) << 4;
699 } else if (isAlphaDigit(c)) {
700 *d |= 0xa + (c - 'a');
706 if ((d - lastStart) >= DATA_ALLOC_SIZE) {
707 int oldsize = d - start;
708 start = (unsigned char *)realloc(start, oldsize + DATA_ALLOC_SIZE);
709 d = lastStart = start + oldsize;
725 yylex(YYSTYPE *lvalp, parser_state_t *state)
729 char tag[TAG_MAX_LENGTH];
731 char attributes[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH];
732 char values[TAG_MAX_ATTRIBUTES][TAG_MAX_LENGTH];
738 /* skip white space */
739 if (isSpace(c)) while ((c = nextChar()) != 0 && isSpace(c)) {};
741 /* keep track of line number, don't return \n's */
748 // end of the buffer?
751 tagType = getTag(STATE, tag, &attributeCount, attributes, values);
752 if (tagType == TAG_BAD) return SYNTAX_ERROR;
753 if (tagType == TAG_IGNORE) goto top;
755 // handle allocation and check for "ID" and "IDREF" tags up front
756 *lvalp = object = newObject(STATE);
758 for (i=0; i < attributeCount; i++) {
759 if (attributes[i][0] == 'I' && attributes[i][1] == 'D') {
760 // check for idref's, note: we ignore the tag, for
761 // this to work correctly, all idrefs must be unique
762 // across the whole serialization
763 if (attributes[i][2] == 'R' && attributes[i][3] == 'E' &&
764 attributes[i][4] == 'F' && !attributes[i][5]) {
765 if (tagType != TAG_EMPTY) return SYNTAX_ERROR;
766 object->idref = strtol(values[i], NULL, 0);
770 if (!attributes[i][2]) {
771 object->idref = strtol(values[i], NULL, 0);
780 if (!strcmp(tag, "array")) {
781 if (tagType == TAG_EMPTY) {
782 object->elements = NULL;
785 return (tagType == TAG_START) ? '(' : ')';
789 if (!strcmp(tag, "dict")) {
790 if (tagType == TAG_EMPTY) {
791 object->elements = NULL;
794 return (tagType == TAG_START) ? '{' : '}';
796 if (!strcmp(tag, "data")) {
798 if (tagType == TAG_EMPTY) {
804 bool isHexFormat = false;
805 for (i=0; i < attributeCount; i++) {
806 if (!strcmp(attributes[i], "format") && !strcmp(values[i], "hex")) {
811 // CF encoded is the default form
813 object->data = getHexData(STATE, &size);
815 object->data = getCFEncodedData(STATE, &size);
818 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END) || strcmp(tag, "data")) {
825 if (!strcmp(tag, "false")) {
826 if (tagType == TAG_EMPTY) {
833 if (!strcmp(tag, "integer")) {
834 object->size = 64; // default
835 for (i=0; i < attributeCount; i++) {
836 if (!strcmp(attributes[i], "size")) {
837 object->size = strtoul(values[i], NULL, 0);
840 if (tagType == TAG_EMPTY) {
844 object->number = getNumber(STATE);
845 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END) || strcmp(tag, "integer")) {
852 if (!strcmp(tag, "key")) {
853 if (tagType == TAG_EMPTY) return SYNTAX_ERROR;
854 object->string = getString(STATE);
855 if (!object->string) {
858 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END)
859 || strcmp(tag, "key")) {
866 if (!strcmp(tag, "plist")) {
867 freeObject(STATE, object);
872 if (!strcmp(tag, "string")) {
873 if (tagType == TAG_EMPTY) {
874 object->string = (char *)malloc(1);
875 object->string[0] = 0;
878 object->string = getString(STATE);
879 if (!object->string) {
882 if ((getTag(STATE, tag, &attributeCount, attributes, values) != TAG_END)
883 || strcmp(tag, "string")) {
888 if (!strcmp(tag, "set")) {
889 if (tagType == TAG_EMPTY) {
890 object->elements = NULL;
893 if (tagType == TAG_START) {
901 if (!strcmp(tag, "true")) {
902 if (tagType == TAG_EMPTY) {
913 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
914 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
915 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
917 // "java" like allocation, if this code hits a syntax error in the
918 // the middle of the parsed string we just bail with pointers hanging
919 // all over place, this code helps keeps it all together
921 //static int object_count = 0;
924 newObject(parser_state_t *state)
928 if (state->freeObjects) {
929 o = state->freeObjects;
930 state->freeObjects = state->freeObjects->next;
932 o = (object_t *)malloc(sizeof(object_t));
934 bzero(o, sizeof(object_t));
935 o->free = state->objects;
943 freeObject(parser_state_t * state, object_t *o)
945 o->next = state->freeObjects;
946 state->freeObjects = o;
950 cleanupObjects(parser_state_t *state)
952 object_t *t, *o = state->objects;
956 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
957 o->object->release();
960 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
964 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
968 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
977 // printf("object_count = %d\n", object_count);
980 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
981 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
982 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
985 rememberObject(parser_state_t *state, int tag, OSObject *o)
988 snprintf(key, 16, "%u", tag);
990 // printf("remember key %s\n", key);
992 state->tags->setObject(key, o);
996 retrieveObject(parser_state_t *state, int tag)
1001 snprintf(key, 16, "%u", tag);
1003 // printf("retrieve key '%s'\n", key);
1005 ref = state->tags->getObject(key);
1008 o = newObject(state);
1013 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1014 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1015 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1018 buildDictionary(parser_state_t *state, object_t * header)
1024 // get count and reverse order
1025 o = header->elements;
1026 header->elements = 0;
1032 t->next = header->elements;
1033 header->elements = t;
1036 dict = OSDictionary::withCapacity(count);
1037 if (header->idref >= 0) rememberObject(state, header->idref, dict);
1039 o = header->elements;
1041 dict->setObject(o->key, o->object);
1044 o->object->release();
1050 freeObject(state, t);
1058 buildArray(parser_state_t *state, object_t * header)
1064 // get count and reverse order
1065 o = header->elements;
1066 header->elements = 0;
1072 t->next = header->elements;
1073 header->elements = t;
1076 array = OSArray::withCapacity(count);
1077 if (header->idref >= 0) rememberObject(state, header->idref, array);
1079 o = header->elements;
1081 array->setObject(o->object);
1083 o->object->release();
1088 freeObject(state, t);
1096 buildSet(parser_state_t *state, object_t *header)
1098 object_t *o = buildArray(state, header);
1100 OSArray *array = (OSArray *)o->object;
1101 OSSet *set = OSSet::withArray(array, array->getCapacity());
1103 // write over the reference created in buildArray
1104 if (header->idref >= 0) rememberObject(state, header->idref, set);
1112 buildString(parser_state_t *state, object_t *o)
1116 string = OSString::withCString(o->string);
1117 if (o->idref >= 0) rememberObject(state, o->idref, string);
1127 buildSymbol(parser_state_t *state, object_t *o)
1131 symbol = (OSSymbol *)OSSymbol::withCString(o->string);
1132 if (o->idref >= 0) rememberObject(state, o->idref, symbol);
1142 buildData(parser_state_t *state, object_t *o)
1147 data = OSData::withBytes(o->data, o->size);
1149 data = OSData::withCapacity(0);
1151 if (o->idref >= 0) rememberObject(state, o->idref, data);
1153 if (o->size) free(o->data);
1160 buildNumber(parser_state_t *state, object_t *o)
1162 OSNumber *number = OSNumber::withNumber(o->number, o->size);
1164 if (o->idref >= 0) rememberObject(state, o->idref, number);
1171 buildBoolean(parser_state_t *state __unused, object_t *o)
1173 o->object = ((o->number == 0) ? kOSBooleanFalse : kOSBooleanTrue);
1174 o->object->retain();
1179 OSUnserializeXML(const char *buffer, OSString **errorString)
1182 parser_state_t *state = (parser_state_t *)malloc(sizeof(parser_state_t));
1184 if ((!state) || (!buffer)) return 0;
1187 if (errorString) *errorString = NULL;
1189 state->parseBuffer = buffer;
1190 state->parseBufferIndex = 0;
1191 state->lineNumber = 1;
1193 state->freeObjects = 0;
1194 state->tags = OSDictionary::withCapacity(128);
1195 state->errorString = errorString;
1196 state->parsedObject = 0;
1197 state->parsedObjectCount = 0;
1199 (void)yyparse((void *)state);
1201 object = state->parsedObject;
1203 cleanupObjects(state);
1204 state->tags->release();
1211 OSUnserializeXML(const char *buffer, size_t bufferSize, OSString **errorString)
1213 if ((!buffer) || (!bufferSize)) return 0;
1215 // XML must be null terminated
1216 if (buffer[bufferSize - 1] || strnlen(buffer, bufferSize) == bufferSize) return 0;
1218 return OSUnserializeXML(buffer, errorString);
1227 // DO NOT EDIT OSUnserializeXML.cpp!