Пример #1
0
static long ParseNextTag(char *buffer, TagPtr *tag)
{
  long length, pos, empty = 0;
  char *tagName;
  TagPtr refTag;
  
  length = GetNextTag(buffer, &tagName, 0, &empty);
  if (length == -1) return -1;
#if PLIST_DEBUG
  gLastTag = tagName;
  gTagsParsed++;
#endif
  
  pos = length;
  if (MATCHTAG(tagName, kXMLTagPList)) {
    length = 0;  // just a header; nothing to parse
	// return-via-reference tag should be left alone
  } else if (MATCHTAG(tagName, kXMLTagDict)) {
    length = ParseTagList(buffer + pos, tag, kTagTypeDict, empty);
  } else if (!strcmp(tagName, kXMLTagKey)) {
    length = ParseTagKey(buffer + pos, tag);
  } else if (MATCHTAG(tagName, kXMLTagReference) && 
	(refTag = TagFromRef(tagName, sizeof(kXMLTagReference)-1))) {
      *tag = refTag;
      length = 0;
  } else if (MATCHTAG(tagName, kXMLTagString)) {
    PARSESTASHINGTAG(tagName, kXMLTagString, ParseTagString);
  } else if (MATCHTAG(tagName, kXMLTagInteger)) {
    PARSESTASHINGTAG(tagName, kXMLTagInteger, ParseTagInteger);
  } else if (!strcmp(tagName, kXMLTagData)) {
    length = ParseTagData(buffer + pos, tag);
  } else if (!strcmp(tagName, kXMLTagDate)) {
    length = ParseTagDate(buffer + pos, tag);
  } else if (!strcmp(tagName, kXMLTagFalse)) {
    length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
  } else if (!strcmp(tagName, kXMLTagTrue)) {
    length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
  } else if (MATCHTAG(tagName, kXMLTagArray)) {
    length = ParseTagList(buffer + pos, tag, kTagTypeArray, empty);
  } else {
    // it wasn't parsed so we consumed no additional characters
    length = 0;
    if (tagName[0] == '/')  // was it an end tag (indicated w/*tag = 0)
      *tag = 0;
    else {
//printf("ignored plist tag: %s (*tag: %x)\n", tagName, *tag);
      *tag = (TagPtr)-1;  // we're *not* returning a tag
    }
  }
  
  if (length == -1) return -1;
  
  return pos + length;
}
Пример #2
0
long XMLParseNextTag(char *buffer, TagPtr * tag)
{
    char *tagName;

    long length = GetNextTag(buffer, &tagName, 0);

    if (length == -1) {
        return -1;
    }

    long pos = length;

    if (!strncmp(tagName, kXMLTagPList, 6)) {
        length = 0;
    } else if (!strcmp(tagName, kXMLTagDict)) {
        length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
    } else if (!strcmp(tagName, kXMLTagDict "/")) {
        length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
    } else if (!strcmp(tagName, kXMLTagKey)) {
        length = ParseTagKey(buffer + pos, tag);
    } else if (!strcmp(tagName, kXMLTagString)) {
        length = ParseTagString(buffer + pos, tag);
    } else if (!strcmp(tagName, kXMLTagInteger)) {
        length = ParseTagInteger(buffer + pos, tag);
    } else if (!strcmp(tagName, kXMLTagData)) {
        length = ParseTagData(buffer + pos, tag);
    } else if (!strcmp(tagName, kXMLTagDate)) {
        length = ParseTagDate(buffer + pos, tag);
    } else if (!strcmp(tagName, kXMLTagFalse)) {
        length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
    } else if (!strcmp(tagName, kXMLTagTrue)) {
        length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
    } else if (!strcmp(tagName, kXMLTagArray)) {
        length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
    } else if (!strcmp(tagName, kXMLTagArray "/")) {
        length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
    } else {
        *tag = 0;
        length = 0;
    }

    if (length == -1) {
        return -1;
    }

    return pos + length;
}
Пример #3
0
//==========================================================================
// ParseNextTag
// TODO: cleanup
long
XMLParseNextTag( char * buffer, TagPtr * tag )
{
	long   length, pos;
	char * tagName;
	
	length = GetNextTag(buffer, &tagName, 0);
	if (length == -1) return -1;
	
	pos = length;

    /* Check most common cases first, make them fast */

	/***** key ****/
	if (!strcmp(tagName, kXMLTagKey))
	{
		length = ParseTagKey(buffer + pos, tag);
	}

	/***** string ****/
    else if (!strncmp(tagName, kXMLTagString, kXMLTagStringLen)) {
      if (!tagName[kXMLTagStringLen]) /* <string> */
        {
          length = ParseTagString(buffer + pos, tag);
        }
      else if (' ' == tagName[kXMLTagStringLen]) /* <string ...> */
        {
          // TODO: save tag if if found
          if(!strncmp(tagName + kXMLTagStringLen + 1, (kXMLStringID "\""), kXMLStringIDLen + 1)) /* <string ID="...> */
            {
              // ID=
              int id = 0;
              /* find end of ID string */
              int cnt = kXMLTagStringLen + 1 + kXMLStringIDLen + 2;
              while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
              tagName[cnt] = 0;
              char* val = tagName + kXMLTagStringLen + 1 + kXMLStringIDLen + 1;
              while(*val)
                {
                  if ((*val >= '0' && *val <= '9'))	// 0 - 9
                    {
                      id = (id * 10) + (*val++ - '0');
                    }
                  else
                    {
                      printf("ParseStringID error (0x%x)\n", *val);
                      getchar();
                      return -1;
                    }
                }
              length = ParseTagString(buffer + pos, tag);
			
              SaveRefString(buffer + pos, id);
            }
          else if(!strncmp(tagName + kXMLTagStringLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) /* <string IDREF= ...> */
            {
              // IDREF=
              int id = 0;
              int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
              while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
              tagName[cnt] = 0;
              char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
              while(*val)
                {
                  if ((*val >= '0' && *val <= '9'))	// 0 - 9
                    {
                      id = (id * 10) + (*val++ - '0');
                    }
                  else
                    {
                      printf("ParseStringIDREF error (0x%x)\n", *val);
                      getchar();
                      return -1;
                    }
                }
              char* str = GetRefString(id);

              TagPtr tmpTag = NewTag();
              tmpTag->type = kTagTypeString;
              tmpTag->string = str;
              tmpTag->tag = 0;
              tmpTag->tagNext = 0;
              tmpTag->offset = buffer_start ? buffer - buffer_start  + pos : 0;
              *tag = tmpTag;
			
              length = 0;
              //printf("Located IDREF, id = %d, string = %s\n", id, str);
            }
        }
      else /* unrecognized <string...> */
        {
          *tag = 0;
          length = 0;
        }
    }
	
	/***** integer ****/
    else if (!strncmp(tagName, kXMLTagInteger, kXMLTagIntegerLen)) {
      if (!tagName[kXMLTagIntegerLen]) /* <integer> */
        {
          length = ParseTagInteger(buffer + pos, tag);
        }
      else if (' ' == tagName[kXMLTagIntegerLen]) /* <integer ...> */
        {
          if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringID, kXMLStringIDLen)) /* <integer ID=...> */
            {
              // ID=
              int id = 0;
              int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
              while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
              tagName[cnt] = 0;
              char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
              while(*val)
                {
                  if ((*val >= '0' && *val <= '9'))	// 0 - 9
                    {
                      id = (id * 10) + (*val++ - '0');
                    }
                  else
                    {
                      printf("ParseIntegerID error (0x%x)\n", *val);
                      getchar();
                      return -1;
                    }
                }
              length = ParseTagInteger(buffer + pos, tag);
			
              SaveRefString((*tag)->string, id);
            }
          else if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) /* <integer IDREF=...> */
            {
              // IDREF=
              int id = 0;
              int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
              while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
              tagName[cnt] = 0;
              char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
              while(*val)
                {
                  if ((*val >= '0' && *val <= '9'))	// 0 - 9
                    {
                      id = (id * 10) + (*val++ - '0');
                    }
                  else
                    {
                      printf("ParseStringIDREF error (0x%x)\n", *val);
                      getchar();
                      return -1;
                    }
                }
              int integer = (int)GetRefString(id);
			
              TagPtr tmpTag = NewTag();
              tmpTag->type = kTagTypeInteger;
              tmpTag->string = (char*) integer;
              tmpTag->tag = 0;
              tmpTag->tagNext = 0;
              tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
			
              *tag = tmpTag;
			
              length = 0;
              //printf("Located IDREF, id = %d, string = %s\n", id, str);
            }
          else /* presume <integer ...>...</integer> */
            {
              length = ParseTagInteger(buffer + pos, tag);
            }
        }
      else /* unrecognized <integer...> */
        {
          *tag = 0;
          length = 0;
        }
    }
	
	/***** false ****/
	else if (!strcmp(tagName, kXMLTagFalse))
	{
		length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
	}

	/***** true ****/
	else if (!strcmp(tagName, kXMLTagTrue))
	{
		length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
	}

	/***** plist ****/
	else if (!strncmp(tagName, kXMLTagPList, kXMLTagPListLen))
	{
		length = 0;
	}

	/***** dict ****/
    else if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen)) {
      if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen) && tagName[strlen(tagName)-1] == '/') /* <dict.../> */
        {
          length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
        }
      else if (!tagName[kXMLTagDictLen] || ' ' == tagName[kXMLTagDictLen]) /* <dict> or<dict ...> */
        {
          length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
        }
      else /* unrecognized <dict...> */
        {
          *tag = 0;
          length = 0;
        }
    }
	
	/***** data ****/
	else if ((!strncmp(tagName, kXMLTagData, kXMLTagDataLen))
             && (!tagName[kXMLTagDataLen]             /* <data> */
                 || ' ' == tagName[kXMLTagDataLen]))  /* <data ...> */
	{
		length = ParseTagData(buffer + pos, tag);
	}
	
	/***** date ****/
	else if ((!strncmp(tagName, kXMLTagDate, kXMLTagDateLen))
             && (!tagName[kXMLTagDateLen]             /* <date> */
                 || ' ' == tagName[kXMLTagDateLen]))  /* <date ...> */
	{
		length = ParseTagDate(buffer + pos, tag);
	}
	
	/***** array ****/
	else if (!strncmp(tagName, kXMLTagArray, kXMLTagArrayLen)) { /* <array...> */
      char c = tagName[kXMLTagArrayLen];
      if ('/' == c) /* <array/> */
        {
          length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
        }
      else if ('\0' == c || ' ' == c) /* <array> or <array ...> */
        {
          length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
        }
      else /* unrecognized <array...> */
        {
          *tag = 0;
          length = 0;
        }
	}
	/***** unknown ****/
	else
	{
		*tag = 0;
		length = 0;
	}
	
	if (length == -1) return -1;
	
	return pos + length;
}
Пример #4
0
//==========================================================================
// ParseNextTag
// TODO: cleanup
long
XMLParseNextTag( char * buffer, TagPtr * tag )
{
	long   length, pos;
	char * tagName;
	
	length = GetNextTag(buffer, &tagName, 0);
	if (length == -1) return -1;
	
	pos = length;
	if (!strncmp(tagName, kXMLTagPList, 6))
	{
		length = 0;
	}
	/***** dict ****/
	else if (!strcmp(tagName, kXMLTagDict))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
	}
	else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/')
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
	}
	else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " ")))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
	}
	/***** key ****/
	else if (!strcmp(tagName, kXMLTagKey))
	{
		length = ParseTagKey(buffer + pos, tag);
	}
	
	/***** string ****/
	else if (!strcmp(tagName, kXMLTagString))
	{
		length = ParseTagString(buffer + pos, tag);
	}
	else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " ")))
	{
		// TODO: save tag if if found
		if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID)))
		{
			// ID=
			int id = 0;
			int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1;
			while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
			tagName[cnt] = 0;
			char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\"");
			while(*val)
			{
				if ((*val >= '0' && *val <= '9'))	// 0 - 9
				{
					id = (id * 10) + (*val++ - '0');
				}
				else
				{
					printf("ParseStringID error (0x%x)\n", *val);
					getchar();
					return -1;
				}
			}
			length = ParseTagString(buffer + pos, tag);
			
			SaveRefString(buffer + pos, id);
		}
		else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
		{
			// IDREF=
			int id = 0;
			int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
			while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
			tagName[cnt] = 0;
			char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
			while(*val)
			{
				if ((*val >= '0' && *val <= '9'))	// 0 - 9
				{
					id = (id * 10) + (*val++ - '0');
				}
				else
				{
					printf("ParseStringIDREF error (0x%x)\n", *val);
					getchar();
					return -1;
				}
			}
			char* str = GetRefString(id);

			TagPtr tmpTag = NewTag();
			tmpTag->type = kTagTypeString;
			tmpTag->string = str;
			tmpTag->tag = 0;
			tmpTag->tagNext = 0;
			tmpTag->offset = buffer_start ? buffer - buffer_start  + pos : 0;
			*tag = tmpTag;
			
			length = 0;
			//printf("Located IDREF, id = %d, string = %s\n", id, str);
		}
	}
	
	/***** integer ****/
	else if (!strcmp(tagName, kXMLTagInteger))
	{
		length = ParseTagInteger(buffer + pos, tag);
	}
	else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " ")))
	{
		if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID)))
		{
			// ID=
			int id = 0;
			int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
			while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
			tagName[cnt] = 0;
			char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
			while(*val)
			{
				if ((*val >= '0' && *val <= '9'))	// 0 - 9
				{
					id = (id * 10) + (*val++ - '0');
				}
				else
				{
					printf("ParseIntegerID error (0x%x)\n", *val);
					getchar();
					return -1;
				}
			}
			length = ParseTagInteger(buffer + pos, tag);
			
			SaveRefString((*tag)->string, id);
		}
		else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
		{
			// IDREF=
			int id = 0;
			int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
			while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
			tagName[cnt] = 0;
			char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
			while(*val)
			{
				if ((*val >= '0' && *val <= '9'))	// 0 - 9
				{
					id = (id * 10) + (*val++ - '0');
				}
				else
				{
					printf("ParseStringIDREF error (0x%x)\n", *val);
					getchar();
					return -1;
				}
			}
			int integer = (int)GetRefString(id);
			
			TagPtr tmpTag = NewTag();
			tmpTag->type = kTagTypeInteger;
			tmpTag->string = (char*) integer;
			tmpTag->tag = 0;
			tmpTag->tagNext = 0;
			tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
			
			*tag = tmpTag;
			
			length = 0;
			//printf("Located IDREF, id = %d, string = %s\n", id, str);
		}
		else
		{
			length = ParseTagInteger(buffer + pos, tag);
		}
	}
	
	/***** data ****/
	else if (!strcmp(tagName, kXMLTagData))
	{
		length = ParseTagData(buffer + pos, tag);
	}
	else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " ")))
	{
		length = ParseTagData(buffer + pos, tag);
	}
	else if (!strcmp(tagName, kXMLTagDate))
	{
		length = ParseTagDate(buffer + pos, tag);
	}
	
	/***** date ****/
	else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " ")))
	{
		length = ParseTagDate(buffer + pos, tag);
	}
	
	/***** false ****/
	else if (!strcmp(tagName, kXMLTagFalse))
	{
		length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
	}
	/***** true ****/
	else if (!strcmp(tagName, kXMLTagTrue))
	{
		length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
	}
	
	/***** array ****/
	else if (!strcmp(tagName, kXMLTagArray))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
	}
	else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " ")))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
	}
	else if (!strcmp(tagName, kXMLTagArray "/"))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
	}
	
	/***** unknown ****/
	else
	{
		*tag = 0;
		length = 0;
	}
	
	if (length == -1) return -1;
	
	return pos + length;
}
Пример #5
0
EFI_STATUS XMLParseNextTag(CHAR8* buffer, TagPtr * tag, UINT32* lenPtr)
{
	EFI_STATUS	Status;
	UINT32		length=0;
	UINT32		pos=0;
	CHAR8*		tagName=NULL;
	
	*lenPtr=0;
  
	Status = GetNextTag((UINT8*)buffer, &tagName, 0, &length);
	if (EFI_ERROR(Status)) 
		return Status;
  
	pos = length;
	if (!AsciiStrnCmp(tagName, kXMLTagPList, 6))
	{
		length=0;
		Status=EFI_SUCCESS;
	}
  /***** dict ****/
	else if (!AsciiStrCmp(tagName, kXMLTagDict))
	{
		Status = ParseTagList(buffer + pos, tag, kTagTypeDict, 0, &length);
	}
	else if (!AsciiStrCmp(tagName, kXMLTagDict "/"))
	{
		Status = ParseTagList(buffer + pos, tag, kTagTypeDict, 1, &length);
	}
	else if (!AsciiStrCmp(tagName, kXMLTagDict " "))
	{
		Status = ParseTagList(buffer + pos, tag, kTagTypeDict, 0, &length);
	}
	/***** key ****/
	else if (!AsciiStrCmp(tagName, kXMLTagKey))
	{
		Status = ParseTagKey(buffer + pos, tag,&length);
	}
	/***** string ****/
	else if (!AsciiStrCmp(tagName, kXMLTagString))
	{
		Status = ParseTagString(buffer + pos, tag, &length);
	}
	/***** integer ****/
	else if (!AsciiStrCmp(tagName, kXMLTagInteger))
	{
		Status = ParseTagInteger(buffer + pos, tag, &length);
	}
	else if (!AsciiStrCmp(tagName, kXMLTagInteger " "))
	{
		Status = ParseTagInteger(buffer + pos, tag, &length);
	}
	
	/***** data ****/
	else if (!AsciiStrCmp(tagName, kXMLTagData))
	{
		Status = ParseTagData(buffer + pos, tag,&length);
	}
	else if (!AsciiStrCmp(tagName, kXMLTagData " "))
	{
		Status = ParseTagData(buffer + pos, tag, &length);
	}
  /***** date ****/
	else if (!AsciiStrCmp(tagName, kXMLTagDate))
	{
		Status = ParseTagDate(buffer + pos, tag, &length);
	}
	/***** FALSE ****/
	else if (!AsciiStrCmp(tagName, kXMLTagFalse))
	{
		Status = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse, &length);
	}
	/***** TRUE ****/	
	else if (!AsciiStrCmp(tagName, kXMLTagTrue))
	{
		Status = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue, &length);
	}
	/***** array ****/
	else if (!AsciiStrCmp(tagName, kXMLTagArray))
	{
		Status = ParseTagList(buffer + pos, tag, kTagTypeArray, 0, &length);
	}
	else if (!AsciiStrCmp(tagName, kXMLTagArray " "))
	{
		Status = ParseTagList(buffer + pos, tag, kTagTypeArray, 0, &length);
	}
	else if (!AsciiStrCmp(tagName, kXMLTagArray "/"))
	{
		Status = ParseTagList(buffer + pos, tag, kTagTypeArray, 1, &length);
	}
  /***** unknown ****/
	else
	{
		*tag = NULL;
		length = 0;
	}
  
	if (EFI_ERROR(Status))
		return EFI_UNSUPPORTED;
  
	*lenPtr=pos + length;
  
	return EFI_SUCCESS;
}