Beispiel #1
0
std::string MediaServerList::getIconURL( IXML_Element* p_device_elem, const char* psz_base_url )
{
    std::string res;
    IXML_NodeList* p_icon_lists = ixmlElement_getElementsByTagName( p_device_elem, "iconList" );
    if ( p_icon_lists == NULL )
        return res;
    IXML_Element* p_icon_list = (IXML_Element*)ixmlNodeList_item( p_icon_lists, 0 );
    if ( p_icon_list != NULL )
    {
        IXML_NodeList* p_icons = ixmlElement_getElementsByTagName( p_icon_list, "icon" );
        if ( p_icons != NULL )
        {
            unsigned int maxWidth = 0;
            unsigned int maxHeight = 0;
            for ( unsigned int i = 0; i < ixmlNodeList_length( p_icons ); ++i )
            {
                IXML_Element* p_icon = (IXML_Element*)ixmlNodeList_item( p_icons, i );
                const char* widthStr = xml_getChildElementValue( p_icon, "width" );
                const char* heightStr = xml_getChildElementValue( p_icon, "height" );
                if ( widthStr == NULL || heightStr == NULL )
                    continue;
                unsigned int width = atoi( widthStr );
                unsigned int height = atoi( heightStr );
                if ( width <= maxWidth || height <= maxHeight )
                    continue;
                const char* iconUrl = xml_getChildElementValue( p_icon, "url" );
                if ( iconUrl == NULL )
                    continue;
                maxWidth = width;
                maxHeight = height;
                res = iconUrl;
            }
            ixmlNodeList_free( p_icons );
        }
    }
    ixmlNodeList_free( p_icon_lists );

    if ( res.empty() == false )
    {
        vlc_url_t url;
        vlc_UrlParse( &url, psz_base_url );
        char* psz_url;
        if ( asprintf( &psz_url, "%s://%s:%u%s", url.psz_protocol, url.psz_host, url.i_port, res.c_str() ) < 0 )
            res.clear();
        else
        {
            res = psz_url;
            free( psz_url );
        }
        vlc_UrlClean( &url );
    }
    return res;
}
Beispiel #2
0
static int s_CD_GetBestRes (char *dms_ip, char *metadata, IXML_Node **best_res)
{
	int ret = -1;
	
	if(!dms_ip || !metadata || !best_res)
		return -2;
	
	IXML_Document *subdoc = ixmlParseBuffer (discard_const_p (char, metadata));
	if(subdoc)
	{
		IXML_NodeList* items =	ixmlDocument_getElementsByTagName (subdoc, "item"); 
		if(items)
		{
			IXML_Node* node = ixmlNodeList_item(items,  0);
			if(node)
			{
				IXML_NodeList* reslist = ixmlElement_getElementsByTagName ((IXML_Element*)node, "res");
				if(reslist)
				{
					IXML_Node* res = s_CD_GetWantedRes(dms_ip, reslist, "http-get","null");
					if(res)
					{
						*best_res = ixmlNode_cloneNode(res, true);
						ret = 0;
					}
					ixmlNodeList_free (reslist);
				}
			}
			ixmlNodeList_free (items);
		}
		ixmlDocument_free(subdoc);
	}
	return ret;
}
Beispiel #3
0
/********************************************************************************
 * SampleUtil_GetFirstServiceList
 *
 * Description: 
 *       Given a DOM node representing a UPnP Device Description Document,
 *       this routine parses the document and finds the first service list
 *       (i.e., the service list for the root device).  The service list
 *       is returned as a DOM node list.
 *
 * Parameters:
 *   node -- The DOM node from which to extract the service list
 *
 ********************************************************************************/
IXML_NodeList *
SampleUtil_GetFirstServiceList( IN IXML_Document * doc )
{
    IXML_NodeList *ServiceList = NULL;
    IXML_NodeList *servlistnodelist = NULL;
    IXML_Node *servlistnode = NULL;

    servlistnodelist =
        ixmlDocument_getElementsByTagName( doc, "serviceList" );
    if( servlistnodelist && ixmlNodeList_length( servlistnodelist ) ) {

        /*
           we only care about the first service list, from the root device 
         */
        servlistnode = ixmlNodeList_item( servlistnodelist, 0 );

        /*
           create as list of DOM nodes 
         */
        ServiceList =
            ixmlElement_getElementsByTagName( ( IXML_Element * )
                                              servlistnode, "service" );
    }

    if( servlistnodelist )
        ixmlNodeList_free( servlistnodelist );

    return ServiceList;
}
Beispiel #4
0
/********************************************************************************
 * SampleUtil_GetFirstServiceList
 *
 * Description: 
 *       Given a DOM node representing a UPnP Device Description Document,
 *       this routine parses the document and finds the first service list
 *       (i.e., the service list for the root device).  The service list
 *       is returned as a DOM node list.
 *
 * Parameters:
 *   node -- The DOM node from which to extract the service list
 *
 ********************************************************************************/
IXML_NodeList *
SampleUtil_GetServiceList( IN IXML_Document * doc )
{
    IXML_NodeList *ServiceList = NULL;
    IXML_NodeList *servlistnodelist = NULL;
    IXML_Node *servlistnode = NULL;
    
    printf("SampleUtil_GetServiceList go\n");
    servlistnodelist =
        ixmlDocument_getElementsByTagName( doc, "serviceList" );
     printf("ixmlDocument_getElementsByTagName\n");   
     //printf("servlistnodelist=%s",servlistnodelist); 
   if( servlistnodelist && ixmlNodeList_length( servlistnodelist ) ) {

        /*
           we only care about the first service list, from the root device 
         */
         printf("if\n"); 
        servlistnode = ixmlNodeList_item( servlistnodelist, 2 );

        /*
           create as list of DOM nodes 
         */ printf("servlistnode\n"); 
        ServiceList =
            ixmlElement_getElementsByTagName( ( IXML_Element * )
                                              servlistnode, "service" );
                     printf("ServiceList=%s\n",ServiceList);                          
    }

    if( servlistnodelist )
        ixmlNodeList_free( servlistnodelist );
printf("free\n");  
    return ServiceList;
}
Beispiel #5
0
BOOL GetMultipleNodeValueInt(IXML_Node *pNode, char *pszName, int *arrOutint)
{
	BOOL ret = FALSE;
	IXML_NodeList *pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pNode, pszName);
	if( pTmpNodeList ) {
		
		IXML_Node *pTmpNode = pTmpNodeList->nodeItem;
		IXML_Node *child  = ixmlNode_getFirstChild( pTmpNode );
		char *pszNodeValue = ixmlNode_getNodeValue( child );

		switch ( ixmlNode_getNodeType( child ) ) {

		case eTEXT_NODE:
			arrOutint[0] = atoi(pszNodeValue);
			ret = TRUE;
			break;

		case eELEMENT_NODE:
		//	while() {
		//	}
		//	break;

		default:
			break;
		}

		ixmlNodeList_free(pTmpNodeList);
	}

	return ret;
}
Beispiel #6
0
BOOL CVCAMetaParserIXML::ParseTrail( IXML_NodeList *pTrailNodeList, VCA5_TRAIL *pTrail )
{
	USHORT usVal = 0;
	IXML_Node *pTrailNode = pTrailNodeList->nodeItem;
	IXML_NodeList *pPtNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pTrailNode, _XML_PT);
	if( pPtNodeList ) {
		IXML_Node *pPtNode = pPtNodeList->nodeItem;
		pTrail->usNumTrailPoints = 0;
		while(pPtNode) {
			VCA5_POINT	vcaPoint;
			memset( &vcaPoint, 0, sizeof( vcaPoint ) );

			usVal = (USHORT)GetNodeValueInt(pPtNode, _XML_X);
			if(usVal != -1) vcaPoint.x = usVal;

			usVal = (USHORT)GetNodeValueInt(pPtNode, _XML_Y);
			if(usVal != -1) vcaPoint.y = usVal;

			pTrail->trailPoints[pTrail->usNumTrailPoints] = vcaPoint;
			pTrail->usNumTrailPoints++;	

			pPtNode = pPtNode->nextSibling;
		}
		ixmlNodeList_free(pPtNodeList);
	}

	return TRUE;
}
Beispiel #7
0
void xmldb_deleteMetaInfo(IXML_Element* doc)
{
    IXML_NodeList* list = ixmlElement_getElementsByTagName(doc, OBIX_META);
    if (list == NULL)
    {
        log_debug("oBIX object doesn't contain any meta information.");
        return;
    }

    int length = ixmlNodeList_length(list);

    IXML_Node* node;
    int error;
    int i;

    for (i = 0; i < length; i++)
    {
        node = ixmlNodeList_item(list, i);
        error = ixmlNode_removeChild(ixmlNode_getParentNode(node), node, &node);
        if (error != IXML_SUCCESS)
        {
            log_warning("Unable to clean the oBIX object from meta information "
                        "(error %d).", error);
            ixmlNodeList_free(list);
            return;
        }
        ixmlNode_free(node);
    }

    ixmlNodeList_free(list);
}
Beispiel #8
0
char *SampleUtil_GetFirstElementItem(IXML_Element *element, const char *item)
{
	IXML_NodeList *nodeList = NULL;
	IXML_Node *textNode = NULL;
	IXML_Node *tmpNode = NULL;
	char *ret = NULL;

	nodeList = ixmlElement_getElementsByTagName(element, (char *)item);
	if (nodeList == NULL) {
		SampleUtil_Print("%s(%d): Error finding %s in XML Node\n",
			__FILE__, __LINE__, item);
		return NULL;
	}
	tmpNode = ixmlNodeList_item(nodeList, 0);
	if (!tmpNode) {
		SampleUtil_Print("%s(%d): Error finding %s value in XML Node\n",
			__FILE__, __LINE__, item);
		ixmlNodeList_free(nodeList);
		return NULL;
	}
	textNode = ixmlNode_getFirstChild(tmpNode);
	ret = strdup(ixmlNode_getNodeValue(textNode));
	if (!ret) {
		SampleUtil_Print("%s(%d): Error allocating memory for %s in XML Node\n",
			__FILE__, __LINE__, item);
		ixmlNodeList_free(nodeList);
		return NULL;
	}
	ixmlNodeList_free(nodeList);

	return ret;
}
char *upnp_igd_get_first_element_item(upnp_igd_context *igd_ctxt,IXML_Element *element, const char *item)
{
	IXML_NodeList *nodeList = NULL;
	IXML_Node *textNode = NULL;
	IXML_Node *tmpNode = NULL;
	char *ret = NULL;

	nodeList = ixmlElement_getElementsByTagName(element, (char *)item);
	if (nodeList == NULL) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error finding %s in XML Node",
			__FILE__, __LINE__, item);
		return NULL;
	}
	tmpNode = ixmlNodeList_item(nodeList, 0);
	if (!tmpNode) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error finding %s value in XML Node",
			__FILE__, __LINE__, item);
		ixmlNodeList_free(nodeList);
		return NULL;
	}
	textNode = ixmlNode_getFirstChild(tmpNode);
	ret = strdup(ixmlNode_getNodeValue(textNode));
	if (!ret) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error allocating memory for %s in XML Node",
			__FILE__, __LINE__, item);
		ixmlNodeList_free(nodeList);
		return NULL;
	}
	ixmlNodeList_free(nodeList);

	return ret;
}
Beispiel #10
0
IXML_Element* xmldb_getMetaInfo(IXML_Element* doc)
{
    IXML_NodeList* list = ixmlElement_getElementsByTagName(doc, OBIX_META);
    if (list == NULL)
    {
        return NULL;
    }

    int length = ixmlNodeList_length(list);
    int i;
    IXML_Node* result = NULL;

    for (i = 0; i < length; i++)
    {
        result = ixmlNodeList_item(list, i);
        // check that we have found meta of exactly this tag but not of
        // meta of it's child
        if (ixmlNode_getParentNode(result) == ixmlElement_getNode(doc))
        {
            ixmlNodeList_free(list);
            return ixmlNode_convertToElement(result);
        }
    }

    // We did not find anything
    ixmlNodeList_free(list);
    return NULL;
}
Beispiel #11
0
BOOL GetMultipleNodeValueString(IXML_Node *pNode, char *pszName, char (*arrOutStr)[VCA5_APP_MAX_STR_LEN])
{
	BOOL ret = FALSE;
	IXML_NodeList *pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pNode, pszName);
	if( pTmpNodeList ) {

		IXML_Node *pTmpNode = pTmpNodeList->nodeItem;
		IXML_Node *child  = ixmlNode_getFirstChild( pTmpNode );
		char *pszNodeValue = ixmlNode_getNodeValue( child );

		switch ( ixmlNode_getNodeType( child ) ) {

		case eTEXT_NODE:
			strcpy(arrOutStr[0], pszNodeValue);
			ret = TRUE;
			break;

		case eELEMENT_NODE:
		//	while() {
		//	}
		//	break;

		default:
			break;
		}

		ixmlNodeList_free(pTmpNodeList);
	}

	return ret;
}
Beispiel #12
0
/************************************************************************
*	Function :	removeServiceTable
*
*	Parameters :
*		IXML_Node *node ;	XML node information
*		service_table *in ;	service table from which services will be 
*							removed
*
*	Description :	This function assumes that services for a particular 
*		root device are placed linearly in the service table, and in the 
*		order in which they are found in the description document
*		all services for this root device are removed from the list
*
*	Return : int ;
*
*	Note :
************************************************************************/
int
removeServiceTable( IXML_Node * node,
                    service_table * in )
{
    IXML_Node *root = NULL;
    IXML_Node *currentUDN = NULL;
    DOMString UDN = NULL;
    IXML_NodeList *deviceList = NULL;
    service_info *current_service = NULL;
    service_info *start_search = NULL;
    service_info *prev_service = NULL;
    long unsigned int NumOfDevices = 0lu;
    long unsigned int i = 0lu;

    if( getSubElement( "root", node, &root ) ) {
        current_service = in->serviceList;
        start_search = in->serviceList;
        deviceList =
            ixmlElement_getElementsByTagName( ( IXML_Element * ) root,
                                              "device" );
        if( deviceList != NULL ) {
            NumOfDevices = ixmlNodeList_length( deviceList );
            for( i = 0lu; i < NumOfDevices; i++ ) {
                if( ( start_search )
                    && ( ( getSubElement( "UDN", node, &currentUDN ) )
                         && ( UDN = getElementValue( currentUDN ) ) ) ) {
                    current_service = start_search;
                    /*Services are put in the service table in the order in which they appear in the  */
                    /*description document, therefore we go through the list only once to remove a particular */
                    /*root device */
                    while( ( current_service )
                           && ( strcmp( current_service->UDN, UDN ) ) ) {
                        current_service = current_service->next;
			if( current_service != NULL) 
                        	prev_service = current_service->next;
                    }
                    while( ( current_service )
                           && ( !strcmp( current_service->UDN, UDN ) ) ) {
                        if( prev_service ) {
                            prev_service->next = current_service->next;
                        } else {
                            in->serviceList = current_service->next;
                        }
                        if( current_service == in->endServiceList )
                            in->endServiceList = prev_service;
                        start_search = current_service->next;
                        freeService( current_service );
                        current_service = start_search;
                    }
                    ixmlFreeDOMString( UDN );
                    UDN = NULL;
                }
            }

            ixmlNodeList_free( deviceList );
        }
    }
    return 1;
}
Beispiel #13
0
void TvStateUpdate(char *UDN, int Service, IXML_Document *ChangedVariables,
		   char **State)
{
	IXML_NodeList *properties;
	IXML_NodeList *variables;
	IXML_Element *property;
	IXML_Element *variable;
	long unsigned int length;
	long unsigned int length1;
	long unsigned int i;
	int j;
	char *tmpstate = NULL;

	SampleUtil_Print("Tv State Update (service %d):\n", Service);
	/* Find all of the e:property tags in the document */
	properties = ixmlDocument_getElementsByTagName(ChangedVariables,
		"e:property");
	if (properties) {
		length = ixmlNodeList_length(properties);
		for (i = 0; i < length; i++) {
			/* Loop through each property change found */
			property = (IXML_Element *)ixmlNodeList_item(
				properties, i);
			/* For each variable name in the state table,
			 * check if this is a corresponding property change */
			for (j = 0; j < TvVarCount[Service]; j++) {
				variables = ixmlElement_getElementsByTagName(
					property, TvVarName[Service][j]);
				/* If a match is found, extract 
				 * the value, and update the state table */
				if (variables) {
					length1 = ixmlNodeList_length(variables);
					if (length1) {
						variable = (IXML_Element *)
							ixmlNodeList_item(variables, 0);
						tmpstate =
						    SampleUtil_GetElementValue(variable);
						if (tmpstate) {
							strcpy(State[j], tmpstate);
							SampleUtil_Print(
								" Variable Name: %s New Value:'%s'\n",
								TvVarName[Service][j], State[j]);
						}
						if (tmpstate)
							free(tmpstate);
						tmpstate = NULL;
					}
					ixmlNodeList_free(variables);
					variables = NULL;
				}
			}
		}
		ixmlNodeList_free(properties);
	}
	return;
	UDN = UDN;
}
/********************************************************************************
 * WscStateVarUpdate
 *
 * Description: 
 *       Update a Wsc state table.  Called when an event is received.  
 *
 * Parameters:
 *   devNode -- The Wsc Device which need to update the State Variables.
 *   ChangedStateVars -- DOM document representing the XML received with the event
 *
 * Note: 
 *       This function is NOT thread save.  It must be called from another function 
 *       that has locked the global device list.
 ********************************************************************************/
void WscStateVarUpdate(
	IN struct upnpDeviceNode *devNode,
	IN IXML_Document *stateDoc)
{
	IXML_NodeList *properties, *stateVars;
	IXML_Element *propItem, *varItem;
	int propLen;
	int i, j;
	char *stateVal = NULL;


	/* Find all of the e:property tags in the document */
	properties = ixmlDocument_getElementsByTagName(stateDoc, "e:property");
	if (properties != NULL)
	{
		propLen = ixmlNodeList_length(properties);
		for (i = 0; i < propLen; i++)
		{ 	/* Loop through each property change found */
			propItem = (IXML_Element *)ixmlNodeList_item(properties, i);
			
			/*
				For each stateVar name in the state table, check if this
				is a corresponding property change
			*/
			for (j = 0; j < WSC_STATE_VAR_MAXVARS; j++)
			{
				stateVars = ixmlElement_getElementsByTagName(propItem, WscVarName[j]);
				/* If found matched item, extract the value, and update the stateVar table */
				if (stateVars)
				{
					if (ixmlNodeList_length(stateVars))
					{
						varItem = (IXML_Element *)ixmlNodeList_item(stateVars, 0);
						stateVal = SampleUtil_GetElementValue(varItem);
						if (stateVal)
						{
							if (devNode->device.services.StateVarVal[j] != NULL)
							{
								//DBGPRINTF(RT_DBG_INFO, "Free the OLD statVarVal!\n"); 
								// We didn't need do this, because the libupnp will free it.
								//free(&devNode->device.services.StateVarVal[j]);
							}
							devNode->device.services.StateVarVal[j] = stateVal;
						}
					}

					ixmlNodeList_free(stateVars);
					stateVars = NULL;
				}
			}
		}
		
		ixmlNodeList_free(properties);
		
	}
}
Beispiel #15
0
BOOL CVCAMetaParserIXML::ParseCE( )
{

	IXML_NodeList *pNodeList = NULL, *pCENodeList = NULL;
	IXML_Node *pCENode = NULL, *pNode = NULL;
	ULONG ulVal = 0;
	USHORT usVal = 0;
	
	pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, _XML_COUNTEVENTS);
	if( pNodeList ) {
		pCENode = pNodeList->nodeItem;

		// There are some event specified in this packet... take a look...
		memset(&m_vcaCountLineEvents, 0, sizeof(m_vcaCountLineEvents));

		pCENodeList = ixmlElement_getElementsByTagName((IXML_Element*)pCENode, _XML_CE);
		if( pCENodeList ) {

			pNode = pCENodeList->nodeItem;
			while(pNode) {
				VCA5_COUNTLINE_EVENT clEvent;
				memset( &clEvent, 0, sizeof( VCA5_COUNTLINE_EVENT ) );

				ulVal = (ULONG)GetNodeValueInt(pNode, _XML_ID);
				if(ulVal != -1) clEvent.uiId = ulVal;

				usVal = (USHORT)GetNodeValueInt(pNode, _XML_P);
				if(usVal != -1) clEvent.usPos = usVal;

				usVal = (USHORT)GetNodeValueInt(pNode, _XML_W);
				if(usVal != -1) clEvent.usWidth = usVal;

				usVal = (USHORT)GetNodeValueInt(pNode, _XML_N);
				if(usVal != -1) clEvent.usNum = usVal;

				m_vcaCountLineEvents.CountLineEvents[m_vcaCountLineEvents.ulTotalCountLineEvents] = clEvent;
				m_vcaCountLineEvents.ulTotalCountLineEvents++;

				pNode = pNode->nextSibling;
			}
			ixmlNodeList_free(pCENodeList);
		}

		ixmlNodeList_free(pNodeList);
	}


	return TRUE;
}
Beispiel #16
0
/*
 * Obtain the service list 
 *    n == 0 the first
 *    n == 1 the next in the device list, etc..
 */
static IXML_NodeList *SampleUtil_GetNthServiceList(
	/*! [in] . */
	IXML_Document *doc,
	/*! [in] . */
	unsigned int n)
{
	IXML_NodeList *ServiceList = NULL;
	IXML_NodeList *servlistnodelist = NULL;
	IXML_Node *servlistnode = NULL;

	/*  ixmlDocument_getElementsByTagName()
	 *  Returns a NodeList of all Elements that match the given
	 *  tag name in the order in which they were encountered in a preorder
	 *  traversal of the Document tree.  
	 *
	 *  return (NodeList*) A pointer to a NodeList containing the 
	 *                      matching items or NULL on an error. 	 */
	SampleUtil_Print("SampleUtil_GetNthServiceList called : n = %d\n", n);
	servlistnodelist =
		ixmlDocument_getElementsByTagName(doc, "serviceList");
	if (servlistnodelist &&
	    ixmlNodeList_length(servlistnodelist) &&
	    n < ixmlNodeList_length(servlistnodelist)) {
		/* For the first service list (from the root device),
		 * we pass 0 */
		/*servlistnode = ixmlNodeList_item( servlistnodelist, 0 );*/

		/* Retrieves a Node from a NodeList} specified by a 
		 *  numerical index.
		 *
		 *  return (Node*) A pointer to a Node or NULL if there was an 
		 *                  error. */
		servlistnode = ixmlNodeList_item(servlistnodelist, n);
		if (!servlistnode) {
			/* create as list of DOM nodes */
			ServiceList = ixmlElement_getElementsByTagName(
				(IXML_Element *)servlistnode, "service");
		} else
			SampleUtil_Print("%s(%d): ixmlNodeList_item(nodeList, n) returned NULL\n",
				__FILE__, __LINE__);
	}
	if (servlistnodelist)
		ixmlNodeList_free(servlistnodelist);

	return ServiceList;
}
Beispiel #17
0
BOOL CVCAMetaParserIXML::ParseStab()
{
	IXML_NodeList *pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, _XML_STAB);
	if( pNodeList ) {
		IXML_Node *pNode = pNodeList->nodeItem;
		IXML_NodeList *pShiftNodeList = ixmlElement_getElementsByTagName ((IXML_Element*)pNode, _XML_SHIFT);
		
		if( pShiftNodeList ) {
			m_vcaStab.iShiftX	= (ULONG)GetNodeValueIntFromNodelist(pNodeList, _XML_X);
			m_vcaStab.iShiftY	= (ULONG)GetNodeValueIntFromNodelist(pNodeList, _XML_Y);
			ixmlNodeList_free(pShiftNodeList);
		}
		ixmlNodeList_free(pNodeList);
	}

	return TRUE;
}
Beispiel #18
0
/*
 * Returns the value of a child element's attribute, or NULL on error
 */
const char* xml_getChildElementAttributeValue( IXML_Element* p_parent,
                                        const char* psz_tag_name_,
                                        const char* psz_attribute_ )
{
    if ( !p_parent ) return NULL;
    if ( !psz_tag_name_ ) return NULL;
    if ( !psz_attribute_ ) return NULL;

    IXML_NodeList* p_node_list = ixmlElement_getElementsByTagName( p_parent, psz_tag_name_ );
    if ( !p_node_list ) return NULL;

    IXML_Node* p_element = ixmlNodeList_item( p_node_list, 0 );
    ixmlNodeList_free( p_node_list );
    if ( !p_element ) return NULL;

    return ixmlElement_getAttribute( (IXML_Element*) p_element, psz_attribute_ );
}
Beispiel #19
0
int GetNodeValueInt(IXML_Node *pNode, char *pszName)
{
	assert( pNode != NULL && pszName != NULL );

	int nVal = -1;
	IXML_NodeList	*pTmpNodeList = NULL;
	pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pNode, pszName);
	if(pTmpNodeList) {
		IXML_Node *n = pTmpNodeList->nodeItem;
		IXML_Node *child = ixmlNode_getFirstChild( n );
	//	printf("%s = %d\n", n->nodeName, atoi(ixmlNode_getNodeValue(child)));
		if( !child ) nVal = -1;
		else nVal = atoi(ixmlNode_getNodeValue(child));
		ixmlNodeList_free(pTmpNodeList);
	}
	return nVal;
}
Beispiel #20
0
/*
 * Returns the value of a child element, or NULL on error
 */
const char* xml_getChildElementValue( IXML_Element* p_parent,
                                      const char*   psz_tag_name_ )
{
    if ( !p_parent ) return NULL;
    if ( !psz_tag_name_ ) return NULL;

    IXML_NodeList* p_node_list = ixmlElement_getElementsByTagName( p_parent, psz_tag_name_ );
    if ( !p_node_list ) return NULL;

    IXML_Node* p_element = ixmlNodeList_item( p_node_list, 0 );
    ixmlNodeList_free( p_node_list );
    if ( !p_element ) return NULL;

    IXML_Node* p_text_node = ixmlNode_getFirstChild( p_element );
    if ( !p_text_node ) return NULL;

    return ixmlNode_getNodeValue( p_text_node );
}
Beispiel #21
0
static char *GetChildValueByName(IXML_Node *node, char *name)
{
	IXML_NodeList *nodeList = NULL;
	IXML_Node *textNode = NULL;
	IXML_Node *tmpNode = NULL;
	char *value = NULL;
	
	nodeList = ixmlElement_getElementsByTagName((IXML_Element*)node, name);
	if( nodeList != NULL ) {
		if((tmpNode = ixmlNodeList_item( nodeList, 0 )) != NULL) {
			if((textNode = ixmlNode_getFirstChild( tmpNode)) != NULL) {
				value = ixmlNode_getNodeValue(textNode);
			}
		}
		ixmlNodeList_free( nodeList );
	}
	return value;
}
Beispiel #22
0
BOOL GetNodeValueString(IXML_Node *pNode, char *pszName, char *pszOutStr)
{
	assert( pNode != NULL && pszName != NULL );

	BOOL ret = FALSE;
	IXML_NodeList	*pTmpNodeList = NULL;
	pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pNode, pszName);
	if(pTmpNodeList) {
		IXML_Node *n = pTmpNodeList->nodeItem;
		IXML_Node *child = ixmlNode_getFirstChild( n );
		if( !child ) {
			ret = FALSE;
		} else {
			strcpy(pszOutStr, ixmlNode_getNodeValue(child));
			ret = TRUE;
		}
		ixmlNodeList_free(pTmpNodeList);
	}
	return ret;
}
Beispiel #23
0
// Returns the value of a child element, or 0 on error
const char* xml_getChildElementValue( IXML_Element* parent,
                                      const char*   tagName )
{
    if ( !parent ) return 0;
    if ( !tagName ) return 0;

    char* s = strdup( tagName );
    IXML_NodeList* nodeList = ixmlElement_getElementsByTagName( parent, s );
    free( s );
    if ( !nodeList ) return 0;

    IXML_Node* element = ixmlNodeList_item( nodeList, 0 );
    ixmlNodeList_free( nodeList );
    if ( !element ) return 0;

    IXML_Node* textNode = ixmlNode_getFirstChild( element );
    if ( !textNode ) return 0;

    return ixmlNode_getNodeValue( textNode );
}
IXML_NodeList *upnp_igd_get_nth_service_list(upnp_igd_context *igd_ctxt,
	/*! [in] . */
	IXML_Document *doc,
	/*! [in] . */
	unsigned int n) {
	IXML_NodeList *ServiceList = NULL;
	IXML_NodeList *servlistnodelist = NULL;
	IXML_Node *servlistnode = NULL;

	/*  ixmlDocument_getElementsByTagName()
	 *  Returns a NodeList of all Elements that match the given
	 *  tag name in the order in which they were encountered in a preorder
	 *  traversal of the Document tree.
	 *
	 *  return (NodeList*) A pointer to a NodeList containing the
	 *                      matching items or NULL on an error. 	 */
	servlistnodelist = ixmlDocument_getElementsByTagName(doc, "serviceList");
	if (servlistnodelist && ixmlNodeList_length(servlistnodelist) && n < ixmlNodeList_length(servlistnodelist)) {
		/* For the first service list (from the root device),
		 * we pass 0 */
		/*servlistnode = ixmlNodeList_item( servlistnodelist, 0 );*/

		/* Retrieves a Node from a NodeList} specified by a
		 *  numerical index.
		 *
		 *  return (Node*) A pointer to a Node or NULL if there was an
		 *                  error. */
		servlistnode = ixmlNodeList_item(servlistnodelist, n);
		if (servlistnode) {
			/* create as list of DOM nodes */
			ServiceList = ixmlElement_getElementsByTagName((IXML_Element *)servlistnode, "service");
		} else {
			upnp_igd_print(igd_ctxt, UPNP_IGD_WARNING, "%s(%d): ixmlNodeList_item(nodeList, n) returned NULL", __FILE__, __LINE__);
		}
	}
	if (servlistnodelist) {
		ixmlNodeList_free(servlistnodelist);
	}

	return ServiceList;
}
Beispiel #25
0
void YX_CD_ParseMetadataByUri(char *metadata, char *uri, char **protocolInfo, t_MEDIA_INFO* minfo )
{
	if( !(metadata && uri && minfo) )
		return;
	
	memset(minfo, 0, sizeof(t_MEDIA_INFO));
	
	IXML_Document *subdoc = ixmlParseBuffer( metadata );
	IXML_NodeList* items =	ixmlDocument_getElementsByTagName (subdoc, "item"); 
	IXML_Node* const node = ixmlNodeList_item(items,  0);
	IXML_Element* const elem = (IXML_Element*)node;
	IXML_NodeList* const reslist = ixmlElement_getElementsByTagName ((IXML_Element*)elem, "res");
	int nb_reslist = ixmlNodeList_length (reslist);
	
	if( nb_reslist > 0 )
		nb_reslist = s_YX_CD_GetMinfoByUri(uri, reslist, nb_reslist, protocolInfo, minfo);
	
	if (reslist)
		ixmlNodeList_free (reslist);
	if (items)
		ixmlNodeList_free (items);
}
Beispiel #26
0
/************************************************************************
* Function : getAllServiceList
*
* Parameters :
*	IXML_Node *node ;	XML node information
*	char * URLBase ;	provides Base URL to resolve relative URL 
*	service_info **out_end ; service added is returned to the output
*				parameter
*
* Description :	Returns pointer to service info after getting the 
*		sub-elements of the service info. 
*
* Return : service_info * ;
*
* Note :
************************************************************************/
service_info *
getAllServiceList( IXML_Node * node,
                   char *URLBase,
                   service_info ** out_end )
{
    service_info *head = NULL;
    service_info *end = NULL;
    service_info *next_end = NULL;
    IXML_NodeList *deviceList = NULL;
    IXML_Node *currentDevice = NULL;

    int NumOfDevices = 0;
    int i = 0;

    ( *out_end ) = NULL;

    deviceList =
        ixmlElement_getElementsByTagName( ( IXML_Element * ) node,
                                          "device" );
    if( deviceList != NULL ) {
        NumOfDevices = ixmlNodeList_length( deviceList );
        for( i = 0; i < NumOfDevices; i++ ) {
            currentDevice = ixmlNodeList_item( deviceList, i );
            if( head ) {
                end->next =
                    getServiceList( currentDevice, &next_end, URLBase );
                end = next_end;
            } else
                head = getServiceList( currentDevice, &end, URLBase );

        }

        ixmlNodeList_free( deviceList );
    }

    ( *out_end ) = end;
    return head;
}
Beispiel #27
0
BOOL CVCAMetaParserIXML::ParseCounts()
{
	IXML_NodeList *pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, _XML_COUNTS);
	if( pNodeList ) {
		// There are some event specified in this packet... take a look...
		m_vcaCounts.ulTotalCounter = 0;

		IXML_Node *pCountsNode, *pCountNode;
		IXML_NodeList *pCountNodeList;
		pCountsNode = pNodeList->nodeItem;
		pCountNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pCountsNode, _XML_COUNT);
		if(pCountNodeList) {
			pCountNode = pCountNodeList->nodeItem;
			while(pCountNode) {
				VCA5_PACKET_COUNT vcaCount;
				memset( &vcaCount, 0, sizeof( vcaCount ) );
				
				ULONG ulVal = 0;
				int iVal = 0;
				ulVal = (ULONG)GetNodeValueInt(pCountNode, _XML_ID);
				if(ulVal != -1) vcaCount.ulId = ulVal;

				iVal = GetNodeValueInt(pCountNode, _XML_VAL);
				if(iVal != -1) vcaCount.iVal = iVal;

				m_vcaCounts.Counters[m_vcaCounts.ulTotalCounter] = vcaCount;
				m_vcaCounts.ulTotalCounter++;

				pCountNode = pCountNode->nextSibling;
			}
			ixmlNodeList_free(pCountNodeList);
		}
		ixmlNodeList_free(pNodeList);
	}

	return TRUE;
}
Beispiel #28
0
RTPXML_NodeList *rtpxmlElement_getElementsByTagName(RTPXML_Element* element,DOMString tagName)
{
	return (RTPXML_NodeList *)ixmlElement_getElementsByTagName((IXML_Element *)element,tagName);
}
Beispiel #29
0
/************************************************************************
*	Function :	getServiceList
*
*	Parameters :
*		IXML_Node *node ;	XML node information
*		service_info **end ; service added is returned to the output
*							parameter
*		char * URLBase ;	provides Base URL to resolve relative URL 
*
*	Description :	Returns pointer to service info after getting the 
*		sub-elements of the service info. 
*
*	Return : service_info * - pointer to the service info node ;
*
*	Note :
************************************************************************/
service_info *
getServiceList( IXML_Node * node,
                service_info ** end,
                char *URLBase )
{
    IXML_Node *serviceList = NULL;
    IXML_Node *current_service = NULL;
    IXML_Node *UDN = NULL;

    IXML_Node *serviceType = NULL;
    IXML_Node *serviceId = NULL;
    IXML_Node *SCPDURL = NULL;
    IXML_Node *controlURL = NULL;
    IXML_Node *eventURL = NULL;
    DOMString tempDOMString = NULL;
    service_info *head = NULL;
    service_info *current = NULL;
    service_info *previous = NULL;
    IXML_NodeList *serviceNodeList = NULL;
    int NumOfServices = 0;
    int i = 0;
    int fail = 0;

    if( getSubElement( "UDN", node, &UDN ) &&
        getSubElement( "serviceList", node, &serviceList ) ) {

        serviceNodeList = ixmlElement_getElementsByTagName( ( IXML_Element
                                                              * )
                                                            serviceList,
                                                            "service" );

        if( serviceNodeList != NULL ) {
            NumOfServices = ixmlNodeList_length( serviceNodeList );
            for( i = 0; i < NumOfServices; i++ ) {
                current_service = ixmlNodeList_item( serviceNodeList, i );
                fail = 0;

                if( current ) {
                    current->next =
                        ( service_info * )
                        malloc( sizeof( service_info ) );

                    previous = current;
                    current = current->next;
                } else {
                    head =
                        ( service_info * )
                        malloc( sizeof( service_info ) );
                    current = head;
                }

                if( !current ) {
                    freeServiceList( head );
                    return NULL;
                }

                current->next = NULL;
                current->controlURL = NULL;
                current->eventURL = NULL;
                current->serviceType = NULL;
                current->serviceId = NULL;
                current->SCPDURL = NULL;
                current->active = 1;
                current->subscriptionList = NULL;
                current->TotalSubscriptions = 0;

                if( !( current->UDN = getElementValue( UDN ) ) )
                    fail = 1;

                if( ( !getSubElement( "serviceType", current_service,
                                      &serviceType ) ) ||
                    ( !( current->serviceType =
                         getElementValue( serviceType ) ) ) )
                    fail = 1;

                if( ( !getSubElement( "serviceId", current_service,
                                      &serviceId ) ) ||
                    ( !
                      ( current->serviceId =
                        getElementValue( serviceId ) ) ) )
                    fail = 1;

                if( ( !
                      ( getSubElement
                        ( "SCPDURL", current_service, &SCPDURL ) ) )
                    || ( !( tempDOMString = getElementValue( SCPDURL ) ) )
                    ||
                    ( !
                      ( current->SCPDURL =
                        resolve_rel_url( URLBase, tempDOMString ) ) ) )
                    fail = 1;

                ixmlFreeDOMString( tempDOMString );
                tempDOMString = NULL;

                if( ( !
                      ( getSubElement
                        ( "controlURL", current_service, &controlURL ) ) )
                    ||
                    ( !( tempDOMString = getElementValue( controlURL ) ) )
                    ||
                    ( !
                      ( current->controlURL =
                        resolve_rel_url( URLBase, tempDOMString ) ) ) ) {
                    UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__,
                        "BAD OR MISSING CONTROL URL" );
                    UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__,
                        "CONTROL URL SET TO NULL IN SERVICE INFO" );
                    current->controlURL = NULL;
                    fail = 0;
                }

                ixmlFreeDOMString( tempDOMString );
                tempDOMString = NULL;

                if( ( !
                      ( getSubElement
                        ( "eventSubURL", current_service, &eventURL ) ) )
                    || ( !( tempDOMString = getElementValue( eventURL ) ) )
                    ||
                    ( !
                      ( current->eventURL =
                        resolve_rel_url( URLBase, tempDOMString ) ) ) ) {
                    UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__,
                        "BAD OR MISSING EVENT URL" );
                    UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__,
                        "EVENT URL SET TO NULL IN SERVICE INFO" );
                    current->eventURL = NULL;
                    fail = 0;
                }

                ixmlFreeDOMString( tempDOMString );
                tempDOMString = NULL;

                if( fail ) {
                    freeServiceList( current );

                    if( previous )
                        previous->next = NULL;
                    else
                        head = NULL;

                    current = previous;
                }

            }

            ixmlNodeList_free( serviceNodeList );
        }

        ( *end ) = current;

        return head;
    } else
        return NULL;

}
Beispiel #30
0
void MediaServer::parseDeviceDescription( IXML_Document* doc,
                                          const char*    location,
                                          services_discovery_t* p_sd )
{
    if ( !doc )
    { 
        msg_Dbg( p_sd, "%s:%d: NULL", __FILE__, __LINE__ ); 
        return;
    }
    
    if ( !location )
    {
        msg_Dbg( p_sd, "%s:%d: NULL", __FILE__, __LINE__ ); 
        return;
    }

    const char* baseURL = location;

    // Try to extract baseURL

    IXML_NodeList* urlList = ixmlDocument_getElementsByTagName( doc, "baseURL" );
    if ( !urlList )
    {

        if ( IXML_Node* urlNode = ixmlNodeList_item( urlList, 0 ) )
        {
            IXML_Node* textNode = ixmlNode_getFirstChild( urlNode );
            if ( textNode ) baseURL = ixmlNode_getNodeValue( textNode );
        }

        ixmlNodeList_free( urlList );
    }

    // Get devices

    IXML_NodeList* deviceList =
                ixmlDocument_getElementsByTagName( doc, "device" );
    
    if ( deviceList )
    {
        for ( unsigned int i = 0; i < ixmlNodeList_length( deviceList ); i++ )
        {
            IXML_Element* deviceElement =
                   ( IXML_Element* ) ixmlNodeList_item( deviceList, i );

            const char* deviceType = xml_getChildElementValue( deviceElement,
                                                               "deviceType" );
            if ( !deviceType )
            {
                msg_Dbg( p_sd,
                        "%s:%d: no deviceType!",
                        __FILE__, __LINE__ );
                continue;
            }

            if ( strcmp( MEDIA_SERVER_DEVICE_TYPE, deviceType ) != 0 )
                continue;

            const char* UDN = xml_getChildElementValue( deviceElement, "UDN" );
            if ( !UDN )
            {
                msg_Dbg( p_sd, "%s:%d: no UDN!",
                        __FILE__, __LINE__ );
                continue;
            }
            
            if ( p_sd->p_sys->serverList->getServer( UDN ) != 0 )
                continue;

            const char* friendlyName =
                       xml_getChildElementValue( deviceElement, 
                                                 "friendlyName" );
            
            if ( !friendlyName )
            {
                msg_Dbg( p_sd, "%s:%d: no friendlyName!", __FILE__, __LINE__ );
                continue;
            }

            MediaServer* server = new MediaServer( UDN, friendlyName, p_sd );
            
            if ( !p_sd->p_sys->serverList->addServer( server ) )
            {

                delete server;
                server = 0;
                continue;
            }

            // Check for ContentDirectory service...
            IXML_NodeList* serviceList =
                       ixmlElement_getElementsByTagName( deviceElement,
                                                         "service" );
            if ( serviceList )
            {
                for ( unsigned int j = 0;
                      j < ixmlNodeList_length( serviceList ); j++ )
                {
                    IXML_Element* serviceElement =
                        ( IXML_Element* ) ixmlNodeList_item( serviceList, j );

                    const char* serviceType =
                        xml_getChildElementValue( serviceElement,
                                                  "serviceType" );
                    if ( !serviceType )
                        continue;

                    if ( strcmp( CONTENT_DIRECTORY_SERVICE_TYPE,
                                serviceType ) != 0 )
                        continue;

                    const char* eventSubURL =
                        xml_getChildElementValue( serviceElement,
                                                  "eventSubURL" );
                    if ( !eventSubURL )
                        continue;

                    const char* controlURL =
                        xml_getChildElementValue( serviceElement,
                                                  "controlURL" );
                    if ( !controlURL )
                        continue;

                    // Try to subscribe to ContentDirectory service

                    char* url = ( char* ) malloc( strlen( baseURL ) +
                            strlen( eventSubURL ) + 1 );
                    if ( url )
                    {
                        char* s1 = strdup( baseURL );
                        char* s2 = strdup( eventSubURL );

                        if ( UpnpResolveURL( s1, s2, url ) ==
                                UPNP_E_SUCCESS )
                        {
                            server->setContentDirectoryEventURL( url );
                            server->subscribeToContentDirectory();
                        }

                        free( s1 );
                        free( s2 );
                        free( url );
                    }

                    // Try to browse content directory...

                    url = ( char* ) malloc( strlen( baseURL ) +
                            strlen( controlURL ) + 1 );
                    if ( url )
                    {
                        char* s1 = strdup( baseURL );
                        char* s2 = strdup( controlURL );

                        if ( UpnpResolveURL( s1, s2, url ) ==
                                UPNP_E_SUCCESS )
                        {
                            server->setContentDirectoryControlURL( url );
                            server->fetchContents();
                        }

                        free( s1 );
                        free( s2 );
                        free( url );
                    }
               }
               ixmlNodeList_free( serviceList );
           }
       }
       ixmlNodeList_free( deviceList );
    }
}