示例#1
0
//#if UNUSED
//==========================================================================
// XMLParseFile
// Expects to see one dictionary in the XML file, the final pos will be returned
// If the pos is not equal to the strlen, then there are multiple dicts
// Puts the first dictionary it finds in the
// tag pointer and returns the end of the dic, or returns -1 if not found.
//
long
XMLParseFile( char * buffer, TagPtr * dict )
{
    long       length, pos;
    TagPtr     tag;
    pos = 0;
	char       *configBuffer;
	
    int strlength = strlen(buffer);
    configBuffer = malloc(strlength+1);
    bcopy(buffer, configBuffer, strlength);
    configBuffer[strlength] = 0;

	buffer_start = configBuffer;

    while (1)
    {
        length = XMLParseNextTag(configBuffer + pos, &tag);
        if (length == -1) break;
    
        pos += length;
    
        if (tag == 0) continue;
        if (tag->type == kTagTypeDict) break;
    
        XMLFreeTag(tag);
    }
	free(configBuffer);
	if (length < 0) {
        return -1;
    }
    *dict = tag;
    return pos;
}
示例#2
0
//==========================================================================
// ParseXMLFile
// Modifies the input buffer.
// Expects to see one dictionary in the XML file.
// Puts the first dictionary it finds in the
// tag pointer and returns 0, or returns -1 if not found
// (and does not modify dict pointer).
// Prints an error message if there is a parsing error.
//
int ParseXMLFile( char * buffer, TagPtr * dict )
{
    long       length, pos;
    TagPtr     tag;
    pos = 0;
    char       *configBuffer;
  
    configBuffer = malloc(strlen(buffer)+1);
    strcpy(configBuffer, buffer);

    while (1)
    {
        length = XMLParseNextTag(configBuffer + pos, &tag);
        if (length == -1) break;
    
        pos += length;
    
        if (tag == 0) continue;
        if (tag->type == kTagTypeDict) break;
    
        XMLFreeTag(tag);
    }
    free(configBuffer);
    if (length < 0) {
        error ("Error parsing plist file\n");
        return -1;
    }
    *dict = tag;
    return 0;
}
示例#3
0
//==========================================================================
// XMLParseFile
// Expects to see one dictionary in the XML file.
// Puts the first dictionary it finds in the
// tag pointer and returns 0, or returns -1 if not found.
//
long
XMLParseFile( char * buffer, TagPtr * dict )
{
    long       length, pos;
    TagPtr     tag;
    pos = 0;
  
    while (1)
    {
        length = XMLParseNextTag(buffer + pos, &tag);
        if (length == -1) break;
    
        pos += length;
    
        if (tag == 0) continue;
        if (tag->type == kTagTypeDict) break;
    
        XMLFreeTag(tag);
    }
    if (length < 0) {
        return -1;
    }
    *dict = tag;
    return 0;
}
示例#4
0
static long
ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities )
{
	long       length, pos;
	TagPtr     moduleDict, required;
	ModulePtr  tmpModule;
  
    pos = 0;
  
    while (1)
    {
        length = XMLParseNextTag(buffer + pos, &moduleDict);
        if (length == -1) break;
    
        pos += length;
    
        if (moduleDict == 0) continue;
        if (moduleDict->type == kTagTypeDict) break;
    
        XMLFreeTag(moduleDict);
    }
  
    if (length == -1) return -1;

    required = XMLGetProperty(moduleDict, kPropOSBundleRequired);
    if ( (required == 0) ||
         (required->type != kTagTypeString) ||
         !strcmp(required->string, "Safe Boot"))
    {
        XMLFreeTag(moduleDict);
        return -2;
    }

    tmpModule = (ModulePtr)malloc(sizeof(Module));
    if (tmpModule == 0)
    {
        XMLFreeTag(moduleDict);
        return -1;
    }
    tmpModule->dict = moduleDict;
  
    // For now, load any module that has OSBundleRequired != "Safe Boot".

    tmpModule->willLoad = 1;

    *module = tmpModule;
  
    // Get the personalities.

    *personalities = XMLGetProperty(moduleDict, kPropIOKitPersonalities);
  
    return 0;
}
示例#5
0
文件: plist.c 项目: weixu8/Duet
EFI_STATUS ParseTagList( CHAR8* buffer, TagPtr * tag, UINT32 type, UINT32 empty, UINT32* lenPtr)
{
	EFI_STATUS	Status=EFI_SUCCESS;
	UINT32		pos;
	TagPtr		tagList;
	TagPtr		tmpTag;
	UINT32		length=0;

	tagList = NULL;
	pos = 0;

	if (!empty)
	{
		while (TRUE)
		{
			Status = XMLParseNextTag(buffer + pos, &tmpTag,&length);
			if (EFI_ERROR(Status)) 
				break;

			pos += length;

			if (tmpTag == NULL) 
				break;

			tmpTag->tagNext = tagList;
			tagList = tmpTag;
		}

		if (EFI_ERROR(Status))
		{
			FreeTag(tagList);
			return Status;
		}
	}

	tmpTag = NewTag();
	if (tmpTag == NULL)
	{
		FreeTag(tagList);
		return EFI_UNSUPPORTED;
	}

	tmpTag->type = type;
	tmpTag->string = 0;
	tmpTag->offset = buffer_start ? buffer - buffer_start : 0;
	tmpTag->tag = tagList;
	tmpTag->tagNext = 0;

	*tag = tmpTag;
	*lenPtr=pos;
	return Status;
}
示例#6
0
static long ParseTagList(char *buffer, TagPtr * tag, long type, long empty)
{
    long length, pos = 0;

    TagPtr tmpTag, tagList = 0;

    if (!empty) {
        while (1) {
            length = XMLParseNextTag(buffer + pos, &tmpTag);

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

            pos += length;

            if (tmpTag == 0) {
                break;
            }

            tmpTag->tagNext = tagList;
            tagList = tmpTag;
        }

        if (length == -1) {
            XMLFreeTag(tagList);

            return -1;
        }
    }

    tmpTag = NewTag();

    if (tmpTag == 0) {
        XMLFreeTag(tagList);

        return -1;
    }

    tmpTag->type = type;
    tmpTag->string = 0;
    tmpTag->tag = tagList;
    tmpTag->tagNext = 0;

    *tag = tmpTag;

    return pos;
}
示例#7
0
文件: plist.c 项目: weixu8/Duet
EFI_STATUS ParseXML(const CHAR8* buffer, TagPtr * dict)
{
	EFI_STATUS	Status;
	UINT32		length=0;
	UINT32		pos=0;
	TagPtr		tag=NULL;
	CHAR8*		configBuffer=NULL;
	UINT32		bufferSize=(UINT32)AsciiStrLen(buffer)+1;

	if(dict==NULL)
		return EFI_UNSUPPORTED;

	*dict=NULL;

	configBuffer=AllocateZeroPool(bufferSize);
	if(configBuffer==NULL)
		return EFI_UNSUPPORTED;

	CopyMem(configBuffer,buffer,bufferSize);
	buffer_start = configBuffer;
	while (TRUE)
	{
		Status = XMLParseNextTag(configBuffer + pos, &tag, &length);
		if (EFI_ERROR(Status))
			break;

		pos += length;

		if (tag == NULL) 
			continue;
		if (tag->type == kTagTypeDict) 
			break;

		FreeTag(tag);
	}
		
	FreePool(configBuffer);

	if (EFI_ERROR(Status)) 
		return Status;

	*dict = tag;

	return EFI_SUCCESS;
}
示例#8
0
文件: plist.c 项目: weixu8/Duet
EFI_STATUS ParseTagKey( char * buffer, TagPtr * tag,UINT32* lenPtr)
{
	EFI_STATUS	Status;
	UINT32		length;
	UINT32		length2;
	CHAR8*		string;
	TagPtr		tmpTag;
	TagPtr		subTag;

	Status = FixDataMatchingTag(buffer, kXMLTagKey,&length);
	if (EFI_ERROR(Status)) 
		return Status;

	Status = XMLParseNextTag(buffer + length, &subTag,&length2);
	if (EFI_ERROR(Status)) 
		return Status;

	tmpTag = NewTag();
	if (tmpTag == NULL)
	{
		FreeTag(subTag);
		return EFI_UNSUPPORTED;
	}

	string = NewSymbol(buffer);
	if (string == NULL)
	{
		FreeTag(subTag);
		FreeTag(tmpTag);
		return EFI_UNSUPPORTED;
	}

	tmpTag->type = kTagTypeKey;
	tmpTag->string = string;
	tmpTag->tag = subTag;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
	tmpTag->tagNext = 0;

	*tag = tmpTag;
	*lenPtr=length + length2;

	return EFI_SUCCESS;
}
示例#9
0
static long ParseTagKey(char *buffer, TagPtr * tag)
{
    long length = FixDataMatchingTag(buffer, kXMLTagKey);

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

    TagPtr subTag;

    long length2 = XMLParseNextTag(buffer + length, &subTag);

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

    TagPtr tmpTag = NewTag();

    if (tmpTag == 0) {
        XMLFreeTag(subTag);

        return -1;
    }

    char *string = NewSymbol(buffer);

    if (string == 0) {
        XMLFreeTag(subTag);
        XMLFreeTag(tmpTag);

        return -1;
    }

    tmpTag->type = kTagTypeKey;
    tmpTag->string = string;
    tmpTag->tag = subTag;
    tmpTag->tagNext = 0;

    *tag = tmpTag;

    return length + length2;
}
示例#10
0
/**
 * prepare_devicetree
 *
 * Prepare and flatten the devicetree.
 */
int prepare_devicetree(void)
{
    void *deviceTreeImage, *deviceTreeData;
    uint32_t deviceTreeSize, length, pos = 0;
    Node *root;
    TagPtr tag;
    char *xmlRepresentation;

    deviceTreeImage = get_image3(kImage3TypeXmlDeviceTree);
    assert(deviceTreeImage != NULL);
    image3_get_tag_data(deviceTreeImage, kImage3TagData, &deviceTreeData,
                        &deviceTreeSize);

    /* Create root of DT */
    DT__Initialize();
    root = DT__RootNode();

    xmlRepresentation = (char *)deviceTreeData;

    /* Enter everything into the DeviceTree. (not mine) */
    assert(root);

    while (1) {
        length = XMLParseNextTag(xmlRepresentation + pos, &tag);
        if (length == -1)
            break;
        pos += length;
        if (!tag)
            continue;
        if (tag->type == kTagTypeDict) {
            PopulateDeviceTreeNode(tag, root);
            XMLFreeTag(tag);
            return true;
        }
        XMLFreeTag(tag);
    }

    return false;
}