Пример #1
0
int GetTotalFiles(char * filepath, int *totalFile, int *totalSize)
{
	int iRet = 0;
	int isDir = 0;
	char *size = NULL;
	char *files = NULL;
	
	IXML_Document   * Dom = NULL;
	
	if(!filepath || strlen(filepath) <= 0){

		iRet = -8;
		goto FuncOut;
	}
	if(!CheckFilePresent(filepath,&isDir))
	{
		iRet = -8;
		goto FuncOut;
	}
	if(!(Dom = ixmlLoadDocument(filepath)))
	{
		fprintf(stderr, "Load Document error\n");
		iRet = -9;
		goto FuncOut;
	}
	size = ixmlGetFirstDocumentItem(Dom,"TotalSize");
	files = ixmlGetFirstDocumentItem(Dom,"TotalFiles");
	
	if(size == NULL || files == NULL)
	{
		fprintf(stderr, "error get size and files\n");
		iRet = -10;
		goto FuncOut;
	}
	
	*totalFile = atoi(files);
	*totalSize = atoi(size);

FuncOut:
	if(size)
		free(size);
	if(files)
		free(files);
	if(Dom)
		free(Dom);
	
	return iRet;
}
Пример #2
0
/*----------------------------------------------------
******FUNCTION NAME:getSWVersion
***FUNCTION INPUTS:
**PSystemConfig pConfig:system config
***FUNCTION OUTPUTS:

**FUNCTION DESCRIPTION
**This function will get the dms name by parse the xml file
**RETURN: 0 ok else error
**HISTORY:
**2009-03-02 James Update
**********************************************************/
int getSWVersion(PSystemConfig pConfig)
{
    IXML_Document *rootDom = NULL;

	/* VERSTIONFILE is the file where in /zapp/version.xml  */
    if((rootDom = ixmlLoadDocument(VERSIONFILE)) == NULL)
        return 1;

	/* Get the <SWVersion> value which in file /zapp/version.xml with tag <software>  */
    pConfig->value = ixmlGetFirstElementItem((IXML_Element *)rootDom, "software");
   
    if (rootDom)
        ixmlDocument_free(rootDom);

    return 0;
}
Пример #3
0
/*
 * Upgrade Function
 * Carl<2008-Nev-10>
 */
void zripUpgare()
{
	U32 InserCDID = 0;
    IXML_Document  *persXmlDoc = NULL; /**Configure file handler that opened*/
    /*1 check the file have ?*/
    persXmlDoc = ixmlLoadDocument(ZRIP_OLD_TASKFILE);
    if(persXmlDoc == NULL){
        return ;
    }
    /*2.check encodeing */
    processInsertEncode(persXmlDoc,&InserCDID);
    /*3.check cddbpeeding */
    processCDDBUp(persXmlDoc,InserCDID);
    ixmlDocument_free( persXmlDoc );
	remove(ZRIP_OLD_TASKFILE);
    return ;
}
Пример #4
0
			v = (char*) ixmlNode_getNodeValue(l1_1_node);
			LoadConfigItem(Conf, sq_conf, n, v);
		}
		if (node_list) ixmlNodeList_free(node_list);
	}

	return node;
}

/*----------------------------------------------------------------------------*/
void *LoadConfig(char *name, tMRConfig *Conf, sq_dev_param_t *sq_conf)
{
	IXML_Element *elm;
	IXML_Document	*doc;

	doc = ixmlLoadDocument(name);
	if (!doc) return NULL;

	elm = ixmlDocument_getElementById(doc, "squeeze2upnp");
	if (elm) {
		unsigned i;
		char *n, *v;
		IXML_NodeList *l1_node_list;
		l1_node_list = ixmlNode_getChildNodes((IXML_Node*) elm);
		for (i = 0; i < ixmlNodeList_length(l1_node_list); i++) {
			IXML_Node *l1_node, *l1_1_node;
			l1_node = ixmlNodeList_item(l1_node_list, i);
			n = (char*) ixmlNode_getNodeName(l1_node);
			l1_1_node = ixmlNode_getFirstChild(l1_node);
			v = (char*) ixmlNode_getNodeValue(l1_1_node);
			LoadGlobalItem(n, v);
		}
		if (l1_node_list) ixmlNodeList_free(l1_node_list);
	}

	elm = ixmlDocument_getElementById((IXML_Document	*)elm, "common");
	if (elm) {
		char *n, *v;
		IXML_NodeList *l1_node_list;
		unsigned i;
		l1_node_list = ixmlNode_getChildNodes((IXML_Node*) elm);
		for (i = 0; i < ixmlNodeList_length(l1_node_list); i++) {
			IXML_Node *l1_node, *l1_1_node;
			l1_node = ixmlNodeList_item(l1_node_list, i);
Пример #5
0
/*----------------------------------------------------
******FUNCTION NAME:getDMRName
***FUNCTION INPUTS:
**PSystemConfig pConfig:system config
***FUNCTION OUTPUTS:

**FUNCTION DESCRIPTION
**This function will get the dmr name by parse the xml file
**RETURN: 0 ok else error
**HISTORY:
**2009-03-02 James Update
**********************************************************/
int getDMRName(PSystemConfig pConfig)
{
    IXML_Document *rootDom = NULL;
    IXML_NodeList   *nodeList = NULL;
    IXML_Node       *node = NULL;

	/* DMSCFGFILE from /data/MediaServer1.xml */
    rootDom = ixmlLoadDocument(MEDIARENDERCFGFILE);
	
    if (rootDom == NULL )
    {
/*        fprintf(stderr, "Document not parsed successfully.");*/
/*        errIndex = 12;//configure file in wrong format*/
		ZCommandResponseError(GETSYSTEMCONFIGURATION,1);
        return -1;
    }
    nodeList = ixmlDocument_getElementsByTagName(rootDom,"friendlyName");
	
    if (nodeList == NULL)
    {
/*        fprintf(stderr, "empty document");*/
/*        errIndex = 12;//configure file in wrong format*/
		ZCommandResponseError(GETSYSTEMCONFIGURATION,1);
        ixmlDocument_free(rootDom);
        return -1;
    }
    node = ixmlNodeList_item(nodeList, 0);
    if(node)
       pConfig->value = ixmlElementToString(node);

    if (nodeList)
        ixmlNodeList_free(nodeList);

    if (rootDom)
        ixmlDocument_free(rootDom);

    return ZSUCCESS;
	
}
Пример #6
0
void getFileSupport(const char *filePath, PZFS pzfs)
{

	IXML_Document *doc = NULL;
	char *tmp = NULL;
	
	if ((doc = ixmlLoadDocument((char *)filePath)) == NULL)
	{
		ZError(DBG_MISC, "Can not load the file -> %s", filePath);
		exit (-1);
	}

	tmp = ixmlGetFirstDocumentItem(doc,"AudioSupported");
	if (strcmp(tmp, "yes") == 0)
		pzfs->audioConfig = 1;
	else
		pzfs->audioConfig = 0;
	if (tmp != NULL)
		free(tmp);

	tmp = ixmlGetFirstDocumentItem(doc,"VideoSupported");
	if (strcmp(tmp, "yes") == 0)
		pzfs->videoConfig= 1;
	else
		pzfs->videoConfig = 0;
	if (tmp != NULL)
		free(tmp);

	tmp = ixmlGetFirstDocumentItem(doc,"PhotoSupported");
	if (strcmp(tmp, "yes") == 0)
		pzfs->photoConfig= 1;
	else
		pzfs->photoConfig = 0;
	
	ixmlDocument_free(doc);
	if (tmp != NULL)
		free(tmp);
}
Пример #7
0
RTPXML_Document *rtpxmlLoadDocument(char* xmlFile)
{
	return ixmlLoadDocument(xmlFile);
}
Пример #8
0
static int SetFriendlyName(char *file, char *newname, int status) 
{
	int iRet = 0;
	IXML_Document * doc = NULL;
	IXML_NodeList * nodelist = NULL;
	IXML_Node * node = NULL;
	char * escapeStr = NULL;	
	void * zdbhandle = NULL;
	if(ZDBOpen(Z_UTIL_ZQDEV,DBfile,&zdbhandle) != Z_SUCCESS){
		fprintf(stderr,"open db error\n");
		return 0;
	}

	if(!newname || !file){
		iRet = -3;
		goto FuncOut;
	}
	
	doc = ixmlLoadDocument(file);
	if(!doc){
		fprintf(stderr, "Document not parsed successfully.");
		iRet = -1;
		goto FuncOut;
	}
	
	if((nodelist = ixmlDocument_getElementsByTagName(doc, "friendlyName"))!= NULL){
		node = ixmlNodeList_item(nodelist, 0);
		node = ixmlNode_getFirstChild(node);

		if(node != NULL)
		{	
			if(strlen(newname) > 0)
				iRet = ixmlNode_setNodeValue(node, newname);

			if(iRet == IXML_SUCCESS){
				iRet = 0;
				if(ixmlUpdateDocument(doc, file)==0)
				{
					//update the zconfig database by jyan 09-06-08
					if(!strcmp(file,DMSCFGFILE))
						updateDB(zdbhandle,"LocalDMSName",newname);
					else
						updateDB(zdbhandle,"LocalDMRName",newname);
				}
				else
					fprintf(stderr,"Update Document fail!!");
				goto FuncOut;
			}
			else {
				iRet = -32;
				goto FuncOut;
			}
		}
	}

FuncOut:
	if(escapeStr)
	{
		free(escapeStr);
		escapeStr = NULL;
	}
	if(nodelist)
		  ixmlNodeList_free(nodelist);
	if(doc)
		ixmlDocument_free(doc);
	ZDBClose(zdbhandle);
	return iRet;	
}
Пример #9
0
int main(int argc, char **argv) {

    int i;

    int files = 0;

    xmlSchemaPtr schema = NULL;

    for (i = 1; i < argc ; i++) {

#ifdef LIBXML_DEBUG_ENABLED

	if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))

	    debug++;

	else

#endif

#ifdef HAVE_SYS_MMAN_H

	if ((!strcmp(argv[i], "-memory")) || (!strcmp(argv[i], "--memory"))) {

	    memory++;

        } else

#endif

	if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) {

	    noout++;

        }

    }

    /*xmlLineNumbersDefault(1);*/

    for (i = 1; i < argc ; i++) {

	if (argv[i][0] != '-') {

	    if (schema == NULL) {

		xmlSchemaParserCtxtPtr ctxt;



#ifdef HAVE_SYS_MMAN_H

		if (memory) {

		    int fd;

		    struct stat info;

		    const char *base;

		    if (stat(argv[i], &info) < 0) 

			break;

		    if ((fd = open(argv[i], O_RDONLY)) < 0)

			break;

		    base = mmap(NULL, info.st_size, PROT_READ,

			        MAP_SHARED, fd, 0) ;

		    if (base == (void *) MAP_FAILED)

			break;



		    ctxt = xmlSchemaNewMemParserCtxt((char *)base,info.st_size);



		    xmlSchemaSetParserErrors(ctxt,

			    (xmlSchemaValidityErrorFunc) fprintf,

			    (xmlSchemaValidityWarningFunc) fprintf,

			    stderr);

		    schema = xmlSchemaParse(ctxt);

		    xmlSchemaFreeParserCtxt(ctxt);

		    munmap((char *) base, info.st_size);

		} else

#endif

		{	

		    /*printf("\n**** CALLING :: xmlSchemaNewParserCtxt argv[i] = %s \n ", argv[i]);*/



		    printf("\n**** CALLING :: xmlSchemaNewParserCtxt \n ");



		    ctxt = xmlSchemaNewParserCtxt(argv[i]);

		    //ctxt = xmlSchemaNewParserCtxt("/root/Code/libxml2-2.6.15/ixml/basic/memory_test.xsd");



		    printf("\n**** CALLING :: xmlSchemaParse \n ");



		    xmlSchemaSetParserErrors(ctxt,

			    (xmlSchemaValidityErrorFunc) fprintf,

			    (xmlSchemaValidityWarningFunc) fprintf,

			    stderr);

		    printf("\n**** CALLING :: xmlSchemaParse \n ");

		    schema = xmlSchemaParse(ctxt);

		    xmlSchemaFreeParserCtxt(ctxt);

		}

#if 0		

#ifdef LIBXML_OUTPUT_ENABLED

#ifdef LIBXML_DEBUG_ENABLED

		if (debug)

		    xmlSchemaDump(stdout, schema);

#endif

#endif /* LIBXML_OUTPUT_ENABLED */

#endif /*#if 0*/		

		if (schema == NULL) 

		    goto failed_schemas;

	    } else {



		IXML_Document *doc;



       	printf("\n ***** CALLING :: xmlReadFile:> %s ", argv[i]);



		//doc = xmlReadFile(argv[i],NULL,0);

		//doc = ixmlLoadDocument("/root/Code/libxml2-2.6.15/ixml/basic/memory_test.xml");

		doc = ixmlLoadDocument(argv[i]);

#if 0		

	printf("nodeName = %s\n",doc->n.firstChild->nodeName);

	printf("firstAttr->nodeName = %s\n",doc->n.firstChild->firstChild->firstAttr->nodeName);

	printf("firstAttr->nodeValue = %s\n",doc->n.firstChild->firstChild->firstAttr->nodeValue);

	printf("firstAttr->nextSibling->nodeName = %s\n",doc->n.firstChild->firstChild->firstAttr->nextSibling->nodeName);

	printf("firstAttr->nextSibling->nodeValue = %s\n",doc->n.firstChild->firstChild->firstAttr->nextSibling->nodeValue);

#endif

		if (doc == NULL) {

		    fprintf(stderr, "Could not parse %s\n", argv[i]);

		} else {

		    xmlSchemaValidCtxtPtr ctxt;

		    int ret;

	        	printf("\n ***** CALLING :: xmlSchemaNewValidCtxt *****\n ");



		    ctxt = xmlSchemaNewValidCtxt(schema);



	        	printf("\n ***** CALLING :: xmlSchemaSetValidErrors *****\n ");



		    xmlSchemaSetValidErrors(ctxt,

			    (xmlSchemaValidityErrorFunc) fprintf,

			    (xmlSchemaValidityWarningFunc) fprintf,

			    stderr);

		    ret = xmlSchemaValidateDoc(ctxt, doc);

			

#if 0			

			printf("nodeName = %s\n",doc->n.firstChild->nodeName);

			printf("firstAttr->nodeName = %s\n",doc->n.firstChild->firstChild->firstAttr->nodeName);

			printf("firstAttr->nodeValue = %s\n",doc->n.firstChild->firstChild->firstAttr->nodeValue);

			printf("firstAttr->nextSibling->nodeName = %s\n",doc->n.firstChild->firstChild->firstAttr->nextSibling->nodeName);

			printf("firstAttr->nextSibling->nodeValue = %s\n",doc->n.firstChild->firstChild->firstAttr->nextSibling->nodeValue);

#endif			

		    if (ret == 0) {

			printf("%s validates\n", argv[i]);

		    } else if (ret > 0) {

			printf("%s fails to validate\n", argv[i]);

		    } else {

			printf("%s validation generated an internal error\n",

			       argv[i]);

		    }

		    xmlSchemaFreeValidCtxt(ctxt);



		    ixmlDocument_free(doc);

		}

	    }

	    files ++;

	}

    }

    if (schema != NULL)

	xmlSchemaFree(schema);

    if (files == 0) {

	printf("Usage : %s [--debug] [--noout] schemas XMLfiles ...\n",

	       argv[0]);

	printf("\tParse the HTML files and output the result of the parsing\n");

#ifdef LIBXML_DEBUG_ENABLED

	printf("\t--debug : dump a debug tree of the in-memory document\n");

#endif

	printf("\t--noout : do not print the result\n");

#ifdef HAVE_SYS_MMAN_H

	printf("\t--memory : test the schemas in memory parsing\n");

#endif

    }

failed_schemas:

	/*printf("\n**** failed_schemas\n");*/

    xmlSchemaCleanupTypes();

    /*xmlCleanupParser();

	xmlResetLastError();

    xmlMemoryDump();*/



    return(0);

}