char *Util_GetFirstDocumentItem(IXML_Document *doc, const char *item)
{
	IXML_NodeList *nodeList = NULL;
	IXML_Node *textNode = NULL;
	IXML_Node *tmpNode = NULL;
	char *ret = NULL;

	nodeList = ixmlDocument_getElementsByTagName(doc, (char *)item);
	if (nodeList) {
		tmpNode = ixmlNodeList_item(nodeList, 0);
		if (tmpNode) {
			textNode = ixmlNode_getFirstChild(tmpNode);
			if (!textNode) {
				g_print("%s(%d): (BUG) ixmlNode_getFirstChild(tmpNode) returned NULL\n",
					__FILE__, __LINE__); 
				ret = strdup("");
				goto epilogue;
			}
			ret = strdup(ixmlNode_getNodeValue(textNode));
			if (!ret) {
				g_print("%s(%d): ixmlNode_getNodeValue returned NULL\n",
					__FILE__, __LINE__); 
				ret = strdup("");
			}
		} else
			g_print("%s(%d): ixmlNodeList_item(nodeList, 0) returned NULL\n",
				__FILE__, __LINE__);
	} else
		g_print("%s(%d): Error finding %s in XML Node\n",
			__FILE__, __LINE__, item);

epilogue:
	if (nodeList)
		ixmlNodeList_free(nodeList);

	return ret;
}
Exemple #2
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;
}
Exemple #3
0
/********************************************************************************
 * SampleUtil_GetFirstDocumentItem
 *
 * Description: 
 *       Given a document node, this routine searches for the first element
 *       named by the input string item, and returns its value as a string.
 *       String must be freed by caller using free.
 * Parameters:
 *   doc -- The DOM document from which to extract the value
 *   item -- The item to search for
 *
 ********************************************************************************/
char *
SampleUtil_GetFirstDocumentItem( IN IXML_Document * doc,
                                 IN const char *item )
{
    IXML_NodeList *nodeList = NULL;
    IXML_Node *textNode = NULL;
    IXML_Node *tmpNode = NULL;

    char *ret = NULL;

    nodeList = ixmlDocument_getElementsByTagName( doc, ( char * )item );

    if( nodeList ) {
        if( ( tmpNode = ixmlNodeList_item( nodeList, 0 ) ) ) {
            textNode = ixmlNode_getFirstChild( tmpNode );

            ret = strdup( ixmlNode_getNodeValue( textNode ) );
        }
    }

    if( nodeList )
        ixmlNodeList_free( nodeList );
    return ret;
}
char *upnp_igd_get_first_document_item(upnp_igd_context *igd_ctxt, IXML_Document *doc, const char *item) {
	IXML_NodeList *nodeList = NULL;
	IXML_Node *textNode = NULL;
	IXML_Node *tmpNode = NULL;
	char *ret = NULL;

	nodeList = ixmlDocument_getElementsByTagName(doc, (char *)item);
	if (nodeList) {
		tmpNode = ixmlNodeList_item(nodeList, 0);
		if (tmpNode) {
			textNode = ixmlNode_getFirstChild(tmpNode);
			if (!textNode) {
				upnp_igd_print(igd_ctxt, UPNP_IGD_WARNING, "%s(%d): (BUG) ixmlNode_getFirstChild(tmpNode) returned NULL",
					__FILE__, __LINE__);
				ret = strdup("");
				goto epilogue;
			}
			ret = strdup(ixmlNode_getNodeValue(textNode));
			if (!ret) {
				upnp_igd_print(igd_ctxt, UPNP_IGD_WARNING, "%s(%d): ixmlNode_getNodeValue returned NULL",
					__FILE__, __LINE__);
				ret = strdup("");
			}
		} else
			upnp_igd_print(igd_ctxt, UPNP_IGD_WARNING, "%s(%d): ixmlNodeList_item(nodeList, 0) returned NULL",
				__FILE__, __LINE__);
	} else
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error finding %s in XML Node",
			__FILE__, __LINE__, item);

epilogue:
	if (nodeList)
		ixmlNodeList_free(nodeList);

	return ret;
}
Exemple #5
0
	if (!strcmp(name, "main_log")) glLog.main = debug2level(val);
	if (!strcmp(name, "sq2mr_log")) glLog.sq2mr = debug2level(val);
	if (!strcmp(name, "base_mac"))  sscanf(val,"%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
								   &glMac[0],&glMac[1],&glMac[2],&glMac[3],&glMac[4],&glMac[5]);
	if (!strcmp(name, "upnp_scan_interval")) gluPNPScanInterval = atol(val);
	if (!strcmp(name, "upnp_scan_timeout")) gluPNPScanTimeout = atol(val);
 }


/*----------------------------------------------------------------------------*/
void *FindMRConfig(void *ref, char *UDN)
{
	IXML_Element *elm;
	IXML_Node	*device = NULL;
	IXML_NodeList *l1_node_list;
	IXML_Document *doc = (IXML_Document*) ref;
	char *v;
	unsigned i;

	elm = ixmlDocument_getElementById(doc, "squeeze2upnp");
	l1_node_list = ixmlDocument_getElementsByTagName((IXML_Document*) elm, "udn");
	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);
Exemple #6
0
/*
 * Fetches and parses the UPNP response
 */
bool MediaServer::_fetchContents( Container* p_parent )
{
    if (!p_parent)
    {
        msg_Err( _p_sd, "No parent" );
        return false;
    }

    IXML_Document* p_response = _browseAction( p_parent->getObjectID(),
                                      "BrowseDirectChildren",
                                      "*", "0", "0", "" );
    if ( !p_response )
    {
        msg_Err( _p_sd, "No response from browse() action" );
        return false;
    }

    IXML_Document* p_result = parseBrowseResult( p_response );
    ixmlDocument_free( p_response );

    if ( !p_result )
    {
        msg_Err( _p_sd, "browse() response parsing failed" );
        return false;
    }
#ifndef NDEBUG
    else
    {
        msg_Dbg( _p_sd, "Got DIDL document: %s",
                ixmlPrintDocument( p_result ) );
    }
#endif

    IXML_NodeList* containerNodeList =
                ixmlDocument_getElementsByTagName( p_result, "container" );

    if ( containerNodeList )
    {
        for ( unsigned int i = 0;
                i < ixmlNodeList_length( containerNodeList ); i++ )
        {
            IXML_Element* containerElement =
                  ( IXML_Element* )ixmlNodeList_item( containerNodeList, i );

            const char* objectID = ixmlElement_getAttribute( containerElement,
                                                             "id" );
            if ( !objectID )
                continue;

            const char* title = xml_getChildElementValue( containerElement,
                                                          "dc:title" );

            if ( !title )
                continue;

            Container* container = new Container( p_parent, objectID, title );
            p_parent->addContainer( container );
            _fetchContents( container );
        }
        ixmlNodeList_free( containerNodeList );
    }

    IXML_NodeList* itemNodeList = ixmlDocument_getElementsByTagName( p_result,
                                                                     "item" );
    if ( itemNodeList )
    {
        for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ )
        {
            IXML_Element* itemElement =
                        ( IXML_Element* )ixmlNodeList_item( itemNodeList, i );

            const char* objectID =
                        ixmlElement_getAttribute( itemElement, "id" );

            if ( !objectID )
                continue;

            const char* title =
                        xml_getChildElementValue( itemElement, "dc:title" );

            if ( !title )
                continue;

            const char* resource =
                        xml_getChildElementValue( itemElement, "res" );

            if ( !resource )
                continue;

            const char* psz_duration = xml_getChildElementAttributeValue( itemElement,
                                                                    "res",
                                                                    "duration" );

            mtime_t i_duration = -1;
            int i_hours, i_minutes, i_seconds, i_decis;

            if ( psz_duration )
            {
                if( sscanf( psz_duration, "%02d:%02d:%02d.%d",
                        &i_hours, &i_minutes, &i_seconds, &i_decis ))
                    i_duration = INT64_C(1000000) * ( i_hours*3600 +
                                                      i_minutes*60 +
                                                      i_seconds ) +
                                 INT64_C(100000) * i_decis;
            }

            Item* item = new Item( p_parent, objectID, title, resource, i_duration );
            p_parent->addItem( item );
        }
        ixmlNodeList_free( itemNodeList );
    }

    ixmlDocument_free( p_result );
    return true;
}
Exemple #7
0
BOOL CVCAMetaParserIXML::ParseEvents()
{
	IXML_NodeList *pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, _XML_EVENTS);
	if( pNodeList ) {
		IXML_Node *pEventsNode, *pEventNode;
		IXML_NodeList *pEventNodeList, *pTmpNodeList;

		m_vcaEvents.ulTotalEvents = 0;

		pEventsNode = pNodeList->nodeItem;
		pEventNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pEventsNode, _XML_EVENT);
		if(pEventNodeList) {
			
			VCA5_PACKET_EVENT vcaEvent;
			char szStr[VCA5_APP_MAX_STR_LEN] = {0,};
			ULONG ulVal = 0;
			BOOL ret = FALSE;

			pEventNode = pEventNodeList->nodeItem;
			while(pEventNode) {
			//	TRACE("=====================================\n");
			//	TRACE(ixmlPrintNode(pEventNode));
			//	TRACE("\n\n");

				memset( &vcaEvent, 0, sizeof( VCA5_PACKET_EVENT ) );
				
				ret = GetNodeValueString(pEventNode, _XML_TYPE, szStr);
				if(ret) {
					if( 0 == strcmp( szStr, "zone")) vcaEvent.ulEventType = VCA5_EVENT_TYPE_ZONE;
					else if( 0 == strcmp( szStr, "tamper")) vcaEvent.ulEventType = VCA5_EVENT_TYPE_TAMPER;
					else assert(0);
				}

				switch (vcaEvent.ulEventType)
				{
				case VCA5_EVENT_TYPE_TAMPER:
					m_uTamperAlarm = 300;

					strcpy( vcaEvent.szRuleName, "---" );
					strcpy( vcaEvent.szZoneName, "---" );
					break;

				case VCA5_EVENT_TYPE_ZONE:
					int arIntValues[10];
					char arStrValues[10][VCA5_APP_MAX_STR_LEN];

					// <id>
					ulVal = (ULONG)GetNodeValueInt(pEventNode, _XML_ID);
					if(ulVal != -1) vcaEvent.ulId = ulVal;

					// <rule_name>
					// TBD

					// <rule_id>
					ulVal = (ULONG)GetNodeValueInt(pEventNode, _XML_RULE_ID);
					if(ulVal != -1) vcaEvent.ulRuleId = ulVal;

					// <rule_name>
					ret = GetNodeValueString(pEventNode, _XML_RULE_NAME, szStr);
					if(ret) {
						strcpy( vcaEvent.szRuleName, szStr );
					} else {
						strcpy( vcaEvent.szRuleName, "---" );
					}

					// <obj_id> (multiple)
					ret = GetMultipleNodeValueInt(pEventNode, _XML_OBJ_ID, arIntValues);
					if(ret) vcaEvent.ulObjId = (ULONG)arIntValues[0];

					// <zone_id> (multiple)
					ret = GetMultipleNodeValueInt(pEventNode, _XML_ZONE_ID, arIntValues);
					if(ret) vcaEvent.ulZoneId = (ULONG)arIntValues[0];

					// <zone_name> (multiple)
					ret = GetMultipleNodeValueString(pEventNode, _XML_ZONE_NAME, arStrValues);
					if(ret) strcpy( vcaEvent.szZoneName, arStrValues[0]);

					// <status>
					ulVal = (ULONG)GetNodeValueInt(pEventNode, _XML_STATUS);
					if(ulVal != -1) vcaEvent.ulStatus = ulVal;

					// <start_time>
					pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pEventsNode, _XML_START_TIME);
					if(pTmpNodeList) {
						vcaEvent.tStartTime.ulSec = (ULONG)GetNodeValueIntFromNodelist(pTmpNodeList, _XML_S);
						vcaEvent.tStartTime.ulMSec = (ULONG)GetNodeValueIntFromNodelist(pTmpNodeList, _XML_MS);
						ixmlNodeList_free(pTmpNodeList);
					}

					// <end_time>
					pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pEventsNode, _XML_END_TIME);
					if(pTmpNodeList) {
						vcaEvent.tStopTime.ulSec = (ULONG)GetNodeValueIntFromNodelist(pTmpNodeList, _XML_S);
						vcaEvent.tStopTime.ulMSec = (ULONG)GetNodeValueIntFromNodelist(pTmpNodeList, _XML_MS);
						ixmlNodeList_free(pTmpNodeList);
					}

					// Bounding box
					ParseBBox( pEventNode, &vcaEvent.bBox );

					m_vcaEvents.Events[m_vcaEvents.ulTotalEvents] =  vcaEvent;
					m_vcaEvents.ulTotalEvents++;
				break;

				default: break;
				}

				pEventNode = pEventNode->nextSibling;
			}
			ixmlNodeList_free(pEventNodeList);
		//	TRACE("# Objects [%2d]\n", m_vcaObjects.ulTotalObject);
		}

		ixmlNodeList_free(pNodeList);
	}


	
	return TRUE;
}
/**************************************************************************
* Function: prepareParameter
* Functionality: it will get the parameter from pipe and check it
* @IN : fd: the file description id for the pipe
*      enable: enable or disable flag
* @OUT: 0 success, else failed.
* Used description:
    The parameter is a xml, it will get from the pipe
* Date: 20080108
* Changed history:
* Date 		Who		Reason
* 20080108	kelly  		First  creation
***************************************************************************/
int prepareParameter(PSystemConfig **pList,int *count)
{
    IXML_Document *rootDom = NULL;
    IXML_NodeList   *nodeList = NULL;
    IXML_NodeList   *nodeList2 = NULL;
    IXML_Node       *node = NULL;
    IXML_Node       *cmdNode = NULL;
    char buffer[1024] = {0};
    char Str[1024] = {0};
    int i = 0;
	int nodeLen = 0;
	PSystemConfig *pConfigList  = NULL;

    while(1)
    {
        fgets(Str, 1024, stdin);
        strcat(buffer, Str);
        if(strstr(buffer,EndFlag))
            break;
    }

	if(strlen(buffer) == 0)
		goto failed;

	if((rootDom = ixmlParseBuffer(buffer)) == NULL)
		goto failed;
	if((nodeList = ixmlDocument_getElementsByTagName(rootDom,"cmd")) != NULL) 
	{
		cmdNode   = ixmlGetFirstNodeByTagName(rootDom,"cmd");
		nodeList2 = ixmlNode_getChildNodes(cmdNode);
		nodeLen   = ixmlNodeList_length(nodeList2);
/*        fprintf(stderr, "=======nodeLen -> [%d]\n", nodeLen);*/
		pConfigList = (PSystemConfig*)malloc(sizeof(PSystemConfig) * nodeLen);
		memset(pConfigList, 0, sizeof(PSystemConfig)*nodeLen);

		node = ixmlNodeList_item(nodeList, 0);
		node = ixmlNode_getFirstChild(node);
		for(i=0; i<nodeLen; i++) {
			if(node){
				pConfigList[i] = (PSystemConfig)malloc(sizeof(SystemConfig));
				memset(pConfigList[i],0,sizeof(SystemConfig));
				pConfigList[i]->name = strdup(ixmlNode_getNodeName(node));
				if(i != nodeLen-1)
				node = ixmlNode_getNextSibling(node);
			}
			else{
				fprintf(stderr, "===== node is empty. i->[%d]\n", i);
			}
		}
	}

	*count = nodeLen;

	if(pConfigList){
		*pList = pConfigList;
	}
	else{
		fprintf(stderr, " !!!!!!pLIST is NULL");
	}

	if (rootDom)
		ixmlDocument_free(rootDom);
	if (nodeList)
		ixmlNodeList_free(nodeList);
	if (nodeList2)
		ixmlNodeList_free(nodeList2);
	return i;

failed:
        fprintf(stderr,"Got a command parameter->%s", buffer);
        //fprintf(stderr,"Got a command parameter->%s", buffer);
    return i;
}
Exemple #9
0
bool MediaServer::_fetchContents( Container* parent )
{
    if (!parent)
    {
        msg_Dbg( _p_sd,
                "%s:%d: parent==NULL", __FILE__, __LINE__ );
        return false;
    }

    IXML_Document* response = _browseAction( parent->getObjectID(),
                                      "BrowseDirectChildren",
                                      "*", "0", "0", "" );
    if ( !response )
    {
        msg_Dbg( _p_sd,
                "%s:%d: ERROR! No response from browse() action",
                __FILE__, __LINE__ );
        return false;
    }

    IXML_Document* result = parseBrowseResult( response );
    ixmlDocument_free( response );
    
    if ( !result )
    {
        msg_Dbg( _p_sd,
                "%s:%d: ERROR! browse() response parsing failed",
                __FILE__, __LINE__ );
        return false;
    }

    IXML_NodeList* containerNodeList =
                ixmlDocument_getElementsByTagName( result, "container" );
    
    if ( containerNodeList )
    {
        for ( unsigned int i = 0;
                i < ixmlNodeList_length( containerNodeList ); i++ )
        {
            IXML_Element* containerElement =
                  ( IXML_Element* )ixmlNodeList_item( containerNodeList, i );

            const char* objectID = ixmlElement_getAttribute( containerElement,
                                                             "id" );
            if ( !objectID )
                continue;

            const char* childCountStr =
                    ixmlElement_getAttribute( containerElement, "childCount" );
            
            if ( !childCountStr )
                continue;
            
            int childCount = atoi( childCountStr );
            const char* title = xml_getChildElementValue( containerElement,
                                                          "dc:title" );
            
            if ( !title )
                continue;
            
            const char* resource = xml_getChildElementValue( containerElement,
                                                             "res" );

            if ( resource && childCount < 1 )
            {
                Item* item = new Item( parent, objectID, title, resource );
                parent->addItem( item );
            }

            else
            {
                Container* container = new Container( parent, objectID, title );
                parent->addContainer( container );

                if ( childCount > 0 )
                    _fetchContents( container );
            }
        }
        ixmlNodeList_free( containerNodeList );
    }

    IXML_NodeList* itemNodeList = ixmlDocument_getElementsByTagName( result,
                                                                     "item" );
    if ( itemNodeList )
    {
        for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ )
        {
            IXML_Element* itemElement =
                        ( IXML_Element* )ixmlNodeList_item( itemNodeList, i );

            const char* objectID =
                        ixmlElement_getAttribute( itemElement, "id" );
            
            if ( !objectID )
                continue;

            const char* title =
                        xml_getChildElementValue( itemElement, "dc:title" );
            
            if ( !title )
                continue;

            const char* resource =
                        xml_getChildElementValue( itemElement, "res" );
            
            if ( !resource )
                continue;

            Item* item = new Item( parent, objectID, title, resource );
            parent->addItem( item );
        }
        ixmlNodeList_free( itemNodeList );
    }

    ixmlDocument_free( result );
    return true;
}
Exemple #10
0
void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &location )
{
    if ( !doc )
    {
        msg_Err( m_sd, "Null IXML_Document" );
        return;
    }

    if ( location.empty() )
    {
        msg_Err( m_sd, "Empty location" );
        return;
    }

    const char* psz_base_url = location.c_str();

    /* Try to extract baseURL */
    IXML_NodeList* p_url_list = ixmlDocument_getElementsByTagName( doc, "URLBase" );
    if ( p_url_list )
    {
        if ( IXML_Node* p_url_node = ixmlNodeList_item( p_url_list, 0 ) )
        {
            IXML_Node* p_text_node = ixmlNode_getFirstChild( p_url_node );
            if ( p_text_node )
                psz_base_url = ixmlNode_getNodeValue( p_text_node );
        }
        ixmlNodeList_free( p_url_list );
    }

    /* Get devices */
    IXML_NodeList* p_device_list = ixmlDocument_getElementsByTagName( doc, "device" );

    if ( !p_device_list )
        return;

    for ( unsigned int i = 0; i < ixmlNodeList_length( p_device_list ); i++ )
    {
        IXML_Element* p_device_element = ( IXML_Element* ) ixmlNodeList_item( p_device_list, i );

        if( !p_device_element )
            continue;

        const char* psz_device_type = xml_getChildElementValue( p_device_element, "deviceType" );

        if ( !psz_device_type )
        {
            msg_Warn( m_sd, "No deviceType found!" );
            continue;
        }

        if ( strncmp( MEDIA_SERVER_DEVICE_TYPE, psz_device_type,
                      strlen( MEDIA_SERVER_DEVICE_TYPE ) - 1 )
                && strncmp( SATIP_SERVER_DEVICE_TYPE, psz_device_type,
                            strlen( SATIP_SERVER_DEVICE_TYPE ) - 1 ) )
            continue;

        const char* psz_udn = xml_getChildElementValue( p_device_element,
                              "UDN" );
        if ( !psz_udn )
        {
            msg_Warn( m_sd, "No UDN!" );
            continue;
        }

        /* Check if server is already added */
        if ( getServer( psz_udn ) )
        {
            msg_Warn( m_sd, "Server with uuid '%s' already exists.", psz_udn );
            continue;
        }

        const char* psz_friendly_name =
            xml_getChildElementValue( p_device_element,
                                      "friendlyName" );

        if ( !psz_friendly_name )
        {
            msg_Dbg( m_sd, "No friendlyName!" );
            continue;
        }

        std::string iconUrl = getIconURL( p_device_element, psz_base_url );

        // We now have basic info, we need to get the content browsing url
        // so the access module can browse without fetching the manifest again

        if ( !strncmp( SATIP_SERVER_DEVICE_TYPE, psz_device_type,
                       strlen( SATIP_SERVER_DEVICE_TYPE ) - 1 ) )
        {
            SD::MediaServerDesc* p_server = NULL;

            vlc_url_t url;
            vlc_UrlParse( &url, psz_base_url );

            char *psz_satip_channellist = config_GetPsz(m_sd, "satip-channelist");
            if( !psz_satip_channellist ) {
                break;
            }

            /* a user may have provided a custom playlist url */
            if (strncmp(psz_satip_channellist, "CustomList", 10) == 0) {
                char *psz_satip_playlist_url = config_GetPsz( m_sd, "satip-channellist-url" );
                if ( psz_satip_playlist_url ) {
                    p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_satip_playlist_url, iconUrl );

                    if( likely( p_server ) ) {
                        p_server->satIpHost = url.psz_host;
                        p_server->isSatIp = true;
                        if( !addServer( p_server ) ) {
                            delete p_server;
                        }
                    }

                    /* to comply with the SAT>IP specification, we don't fall back on another channel list if this path failed */
                    free( psz_satip_playlist_url );
                    vlc_UrlClean( &url );
                    continue;
                }
            }

            /* If requested by the user, check for a SAT>IP m3u list, which may be provided by some rare devices */
            if (strncmp(psz_satip_channellist, "ServerList", 10) == 0) {
                const char* psz_m3u_url = xml_getChildElementValue( p_device_element, "satip:X_SATIPM3U" );
                if ( psz_m3u_url ) {
                    if ( strncmp( "http", psz_m3u_url, 4) )
                    {
                        char* psz_url = NULL;
                        if ( UpnpResolveURL2( psz_base_url, psz_m3u_url, &psz_url ) == UPNP_E_SUCCESS )
                        {
                            p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_url, iconUrl );
                            free(psz_url);
                        }
                    } else {
                        p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_m3u_url, iconUrl );
                    }

                    if ( unlikely( !p_server ) )
                        break;

                    p_server->satIpHost = url.psz_host;
                    p_server->isSatIp = true;
                    if ( !addServer( p_server ) )
                        delete p_server;

                    free(psz_satip_channellist);
                } else {
                    msg_Warn( m_sd, "SAT>IP server '%s' did not provide a playlist", url.psz_host);
                }

                /* to comply with the SAT>IP specifications, we don't fallback on another channel list if this path failed */
                vlc_UrlClean( &url );
                continue;
            }

            /* Normally, fetch a playlist from the web,
             * which will be processed by a lua script a bit later */
            char *psz_url;
            if (asprintf( &psz_url, "http://www.satip.info/Playlists/%s.m3u",
                          psz_satip_channellist ) < 0 ) {
                vlc_UrlClean( &url );
                free( psz_satip_channellist );
                continue;
            }

            p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn,
                    psz_friendly_name, psz_url, iconUrl );

            if( likely( p_server ) ) {
                p_server->satIpHost = url.psz_host;
                p_server->isSatIp = true;
                if( !addServer( p_server ) ) {
                    delete p_server;
                }
            }
            free( psz_url );
            free( psz_satip_channellist );
            vlc_UrlClean( &url );

            continue;
        }

        /* Check for ContentDirectory service. */
        IXML_NodeList* p_service_list = ixmlElement_getElementsByTagName( p_device_element, "service" );
        if ( !p_service_list )
            continue;
        for ( unsigned int j = 0; j < ixmlNodeList_length( p_service_list ); j++ )
        {
            IXML_Element* p_service_element = (IXML_Element*)ixmlNodeList_item( p_service_list, j );

            const char* psz_service_type = xml_getChildElementValue( p_service_element, "serviceType" );
            if ( !psz_service_type )
            {
                msg_Warn( m_sd, "No service type found." );
                continue;
            }

            int k = strlen( CONTENT_DIRECTORY_SERVICE_TYPE ) - 1;
            if ( strncmp( CONTENT_DIRECTORY_SERVICE_TYPE,
                          psz_service_type, k ) )
                continue;

            const char* psz_control_url = xml_getChildElementValue( p_service_element,
                                          "controlURL" );
            if ( !psz_control_url )
            {
                msg_Warn( m_sd, "No control url found." );
                continue;
            }

            /* Try to browse content directory. */
            char* psz_url = ( char* ) malloc( strlen( psz_base_url ) + strlen( psz_control_url ) + 1 );
            if ( psz_url )
            {
                if ( UpnpResolveURL( psz_base_url, psz_control_url, psz_url ) == UPNP_E_SUCCESS )
                {
                    SD::MediaServerDesc* p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn,
                            psz_friendly_name, psz_url, iconUrl );
                    free( psz_url );
                    if ( unlikely( !p_server ) )
                        break;

                    if ( !addServer( p_server ) )
                    {
                        delete p_server;
                        continue;
                    }
                }
                else
                    free( psz_url );
            }
        }
        ixmlNodeList_free( p_service_list );
    }
    ixmlNodeList_free( p_device_list );
}
Exemple #11
0
void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &location )
{
    if ( !doc )
    {
        msg_Err( p_sd_, "Null IXML_Document" );
        return;
    }

    if ( location.empty() )
    {
        msg_Err( p_sd_, "Empty location" );
        return;
    }

    const char* psz_base_url = location.c_str();

    /* Try to extract baseURL */
    IXML_NodeList* p_url_list = ixmlDocument_getElementsByTagName( doc, "URLBase" );
    if ( p_url_list )
    {
        if ( IXML_Node* p_url_node = ixmlNodeList_item( p_url_list, 0 ) )
        {
            IXML_Node* p_text_node = ixmlNode_getFirstChild( p_url_node );
            if ( p_text_node )
                psz_base_url = ixmlNode_getNodeValue( p_text_node );
        }
        ixmlNodeList_free( p_url_list );
    }

    /* Get devices */
    IXML_NodeList* p_device_list = ixmlDocument_getElementsByTagName( doc, "device" );

    if ( !p_device_list )
        return;
    for ( unsigned int i = 0; i < ixmlNodeList_length( p_device_list ); i++ )
    {
        IXML_Element* p_device_element = ( IXML_Element* ) ixmlNodeList_item( p_device_list, i );

        if( !p_device_element )
            continue;

        const char* psz_device_type = xml_getChildElementValue( p_device_element, "deviceType" );

        if ( !psz_device_type )
        {
            msg_Warn( p_sd_, "No deviceType found!" );
            continue;
        }

        if ( strncmp( MEDIA_SERVER_DEVICE_TYPE, psz_device_type,
                strlen( MEDIA_SERVER_DEVICE_TYPE ) - 1 ) )
            continue;

        const char* psz_udn = xml_getChildElementValue( p_device_element,
                                                        "UDN" );
        if ( !psz_udn )
        {
            msg_Warn( p_sd_, "No UDN!" );
            continue;
        }

        /* Check if server is already added */
        if ( p_sd_->p_sys->p_server_list->getServer( psz_udn ) )
        {
            msg_Warn( p_sd_, "Server with uuid '%s' already exists.", psz_udn );
            continue;
        }

        const char* psz_friendly_name =
                   xml_getChildElementValue( p_device_element,
                                             "friendlyName" );

        if ( !psz_friendly_name )
        {
            msg_Dbg( p_sd_, "No friendlyName!" );
            continue;
        }

        // We now have basic info, we need to get the content browsing url
        // so the access module can browse without fetching the manifest again

        /* Check for ContentDirectory service. */
        IXML_NodeList* p_service_list = ixmlElement_getElementsByTagName( p_device_element, "service" );
        if ( !p_service_list )
            continue;
        for ( unsigned int j = 0; j < ixmlNodeList_length( p_service_list ); j++ )
        {
            IXML_Element* p_service_element = (IXML_Element*)ixmlNodeList_item( p_service_list, j );

            const char* psz_service_type = xml_getChildElementValue( p_service_element, "serviceType" );
            if ( !psz_service_type )
            {
                msg_Warn( p_sd_, "No service type found." );
                continue;
            }

            int k = strlen( CONTENT_DIRECTORY_SERVICE_TYPE ) - 1;
            if ( strncmp( CONTENT_DIRECTORY_SERVICE_TYPE,
                        psz_service_type, k ) )
                continue;

            const char* psz_control_url = xml_getChildElementValue( p_service_element,
                                          "controlURL" );
            if ( !psz_control_url )
            {
                msg_Warn( p_sd_, "No control url found." );
                continue;
            }

            /* Try to browse content directory. */
            char* psz_url = ( char* ) malloc( strlen( psz_base_url ) + strlen( psz_control_url ) + 1 );
            if ( psz_url )
            {
                if ( UpnpResolveURL( psz_base_url, psz_control_url, psz_url ) == UPNP_E_SUCCESS )
                {
                    SD::MediaServerDesc* p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn,
                            psz_friendly_name, psz_url );
                    free( psz_url );
                    if ( unlikely( !p_server ) )
                        break;

                    if ( !addServer( p_server ) )
                    {
                        delete p_server;
                        continue;
                    }
                }
                else
                    free( psz_url );
            }
        }
        ixmlNodeList_free( p_service_list );
    }
    ixmlNodeList_free( p_device_list );
}
/**************************************************************************
 * Function: ParaseXMLString
 * Functionality: parase the xml string
 * @IN :  XMLString: the xml string

 * @OUT:   NetConfig: fill this struct from xml string 
WifiParam:wifi config parameters
0 OK else error
 * Used description:
 get the xml string and fill the struct NetworkConfig
 * Date: 20080117
 * Changed history:
 * Date          Who             Reason
 * 20080117     sandy           First  creation
 ***************************************************************************/ 
int ParaseXMLString(char * XMLString, NetworkConfig *NetConfig, PWifiConfig WifiParam)
{
	IXML_Document   * Dom = NULL;

	IXML_NodeList   *nodeList = NULL;
	IXML_Node       *node;

	/*parse the xml string, and get the needed value*/
	if(!(Dom = ixmlParseBuffer(XMLString))){
		fprintf(stderr, "Load Document error\n");
		return -1;
	}
	NetConfig->PreferNetwork = ixmlGetFirstDocumentItem(Dom,"PreferNetwork");
	NetConfig->IPDNS1 = ixmlGetFirstDocumentItem(Dom,"IPDNS1");
	NetConfig->IPDNS2 = ixmlGetFirstDocumentItem(Dom,"IPDNS2");

	if ((nodeList = ixmlDocument_getElementsByTagName(Dom,"Wired")) != NULL) {
		if ((node = ixmlNodeList_item(nodeList, 0)) != NULL) {
			NetConfig->WireConfig.Enabled = ixmlGetFirstElementItem((IXML_Element *)node, "Enabled");
			NetConfig->WireConfig.DHCPEnable = ixmlGetFirstElementItem((IXML_Element *)node, "DHCPEnable");
			NetConfig->WireConfig.IPAddr = ixmlGetFirstElementItem((IXML_Element *)node, "IPAddr");
			NetConfig->WireConfig.IPGateway = ixmlGetFirstElementItem((IXML_Element *)node, "IPGateway");
			NetConfig->WireConfig.IPSubnetMask = ixmlGetFirstElementItem((IXML_Element *)node, "IPSubnetMask");
		}
		if (nodeList)
			ixmlNodeList_free(nodeList);
	}

	if ((nodeList = ixmlDocument_getElementsByTagName(Dom,"Wireless")) != NULL) {
		if ((node = ixmlNodeList_item(nodeList, 0)) != NULL) {
			WifiParam->encryption = ixmlGetFirstElementItem((IXML_Element *)node, "Encryption");
			WifiParam->ssid = ixmlGetFirstElementItem((IXML_Element *)node, "ESSID");
			WifiParam->key = ixmlGetFirstElementItem((IXML_Element *)node, "Key");
			NetConfig->WifiConfig.Enabled = ixmlGetFirstElementItem((IXML_Element *)node, "Enabled");
			NetConfig->WifiConfig.DHCPEnable = ixmlGetFirstElementItem((IXML_Element *)node, "DHCPEnable");
			NetConfig->WifiConfig.IPAddr = ixmlGetFirstElementItem((IXML_Element *)node, "IPAddr");
			NetConfig->WifiConfig.IPGateway = ixmlGetFirstElementItem((IXML_Element *)node, "IPGateway");
			NetConfig->WifiConfig.IPSubnetMask = ixmlGetFirstElementItem((IXML_Element *)node, "IPSubnetMask");
		}
		if (nodeList)
			ixmlNodeList_free(nodeList);
	}


	if(Dom){
		ixmlDocument_free(Dom);
		Dom = NULL;
	}

#if 0
	printf("the DNS is %s %s \n", NetConfig->IPDNS1, NetConfig->IPDNS2);
	printf("the return NetConfig.DHCPStatus is %s\n", NetConfig->DHCPStatus);
	printf("the return NetConfig.PreferNetwork is %s\n", NetConfig->PreferNetwork);

	printf("the return NetConfig.WireConfig.Enabled is %s\n", NetConfig->WireConfig.Enabled);
	printf("the return NetConfig.WireConfig.DHCPEnable is %s\n", NetConfig->WireConfig.DHCPEnable);
	printf("the return NetConfig.WireConfig.IPAddr is %s\n", NetConfig->WireConfig.IPAddr);
	printf("the return NetConfig.WireConfig.IPSubnetMask is %s\n", NetConfig->WireConfig.IPSubnetMask);
	printf("the return NetConfig.WireConfig.IPSubnetMask is %s\n", NetConfig->WireConfig.IPGateway);

	printf("the return NetConfig.WifiConfig.Enabled is %s\n", NetConfig->WifiConfig.Enabled);
	printf("the return NetConfig.WifiConfig.DHCPEnable is %s\n", NetConfig->WifiConfig.DHCPEnable);
	printf("the return NetConfig.WifiConfig.IPAddr is %s\n", NetConfig->WifiConfig.IPAddr);
	printf("the return NetConfig.WifiConfig.IPSubnetMask is %s\n", NetConfig->WifiConfig.IPSubnetMask);
	printf("the return NetConfig.WifiConfig.IPGateway is %s\n", NetConfig->WifiConfig.IPGateway);
#endif

	return 0;
}
Exemple #13
0
/*
 * Fetches and parses the UPNP response
 */
bool MediaServer::_fetchContents( Container* p_parent, int i_offset )
{
    if (!p_parent)
    {
        msg_Err( _p_sd, "No parent" );
        return false;
    }

    char* psz_starting_index;
    if( asprintf( &psz_starting_index, "%d", i_offset ) < 0 )
    {
        msg_Err( _p_sd, "asprintf error:%d", i_offset );
        return false;
    }

    IXML_Document* p_response = _browseAction( p_parent->getObjectID(),
                                      "BrowseDirectChildren",
                                      "*", /* Filter */
                                      psz_starting_index, /* StartingIndex */
                                      "0", /* RequestedCount */
                                      "" /* SortCriteria */
                                      );
    free( psz_starting_index );
    if ( !p_response )
    {
        msg_Err( _p_sd, "No response from browse() action" );
        return false;
    }

    IXML_Document* p_result = parseBrowseResult( p_response );
    int i_number_returned = xml_getNumber( p_response, "NumberReturned" );
    int i_total_matches   = xml_getNumber( p_response , "TotalMatches" );

#ifndef NDEBUG
    msg_Dbg( _p_sd, "i_offset[%d]i_number_returned[%d]_total_matches[%d]\n",
             i_offset, i_number_returned, i_total_matches );
#endif

    ixmlDocument_free( p_response );

    if ( !p_result )
    {
        msg_Err( _p_sd, "browse() response parsing failed" );
        return false;
    }

#ifndef NDEBUG
    msg_Dbg( _p_sd, "Got DIDL document: %s", ixmlPrintDocument( p_result ) );
#endif

    IXML_NodeList* containerNodeList =
                ixmlDocument_getElementsByTagName( p_result, "container" );

    if ( containerNodeList )
    {
        for ( unsigned int i = 0;
                i < ixmlNodeList_length( containerNodeList ); i++ )
        {
            IXML_Element* containerElement =
                  ( IXML_Element* )ixmlNodeList_item( containerNodeList, i );

            const char* objectID = ixmlElement_getAttribute( containerElement,
                                                             "id" );
            if ( !objectID )
                continue;

            const char* title = xml_getChildElementValue( containerElement,
                                                          "dc:title" );

            if ( !title )
                continue;

            Container* container = new Container( p_parent, objectID, title );
            p_parent->addContainer( container );
            _fetchContents( container, 0 );
        }
        ixmlNodeList_free( containerNodeList );
    }

    IXML_NodeList* itemNodeList = ixmlDocument_getElementsByTagName( p_result,
                                                                     "item" );
    if ( itemNodeList )
    {
        for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ )
        {
            IXML_Element* itemElement =
                        ( IXML_Element* )ixmlNodeList_item( itemNodeList, i );

            const char* objectID =
                        ixmlElement_getAttribute( itemElement, "id" );

            if ( !objectID )
                continue;

            const char* title =
                        xml_getChildElementValue( itemElement, "dc:title" );

            if ( !title )
                continue;

            const char* resource =
                        xml_getChildElementValue( itemElement, "res" );

            if ( !resource )
                continue;

            const char* psz_duration = xml_getChildElementAttributeValue( itemElement,
                                                                    "res",
                                                                    "duration" );

            mtime_t i_duration = -1;
            int i_hours, i_minutes, i_seconds, i_decis;

            if ( psz_duration )
            {
                if( sscanf( psz_duration, "%02d:%02d:%02d.%d",
                        &i_hours, &i_minutes, &i_seconds, &i_decis ))
                    i_duration = INT64_C(1000000) * ( i_hours*3600 +
                                                      i_minutes*60 +
                                                      i_seconds ) +
                                 INT64_C(100000) * i_decis;
            }

            Item* item = new Item( p_parent, objectID, title, resource, i_duration );
            p_parent->addItem( item );
        }
        ixmlNodeList_free( itemNodeList );
    }

    ixmlDocument_free( p_result );

    if( i_offset + i_number_returned < i_total_matches )
        return _fetchContents( p_parent, i_offset + i_number_returned );

    return true;
}
int WscUPnPCPHandleActionResponse(
	IN struct Upnp_Action_Complete *a_event)
{
	IXML_NodeList *nodeList = NULL, *msgNodeList = NULL;
	IXML_Node *element, *child = NULL;
	char *varName = NULL;
	struct upnpDeviceNode *nodePtr;
	
	char *inStr = NULL, *pWscU2KMsg = NULL;
	unsigned char *decodeStr = NULL;
	int i, decodeLen = 0, wscU2KMsgLen;
	
	unsigned int UPnPDevIP = 0;
			
	DBGPRINTF(RT_DBG_INFO, "ErrCode = %d, CtrlUrl=%s!\n", a_event->ErrCode, a_event->CtrlUrl);
	
	if(a_event->ActionResult == NULL || a_event->ErrCode != 0)
		return 0;

	// Check if this device is already in the list
	nodePtr = WscDeviceList;
	while (nodePtr)
	{
		if(strcmp(nodePtr->device.services.ControlURL, a_event->CtrlUrl) == 0)
		{
			UPnPDevIP = nodePtr->device.ipAddr;
			nodePtr->device.timeCount = nodePtr->device.AdvrTimeOut;
			break;
		}
		nodePtr = nodePtr->next;
    }
	if (UPnPDevIP == 0)
		goto done;
	DBGPRINTF(RT_DBG_INFO, "Find the ActionResponse Device IP=%x\n", UPnPDevIP);

	
	/*
		We just support following ActionResponse from remote device.
	*/
	for (i=0; i < CP_RESP_SUPPORT_LIST_NUM; i++)
	{
		DBGPRINTF(RT_DBG_INFO, "check actionResNames[%d]=%s!\n", i, actionResNames[i]);
		nodeList = ixmlDocument_getElementsByTagName(a_event->ActionResult, actionResNames[i]);
		if(nodeList){
			varName = stateVarNames[i];
			break;
		}
	}

	if(nodeList == NULL)
	{
		DBGPRINTF(RT_DBG_INFO, "UnSupportted ActResponse!\n");
		goto done;
	}
	
	if ((element = ixmlNodeList_item(nodeList, 0)))
	{
		//First check if we have supportted State Variable name!
		ixmlNode_getElementsByTagName(element, varName, &msgNodeList);
		if(msgNodeList != NULL)
		{
			DBGPRINTF(RT_DBG_INFO, "find stateVarName=%s!\n", varName);
			while((child = ixmlNode_getFirstChild(element))!= NULL)
			{	// Find the Response text content!
				if (ixmlNode_getNodeType(child) == eTEXT_NODE)
				{
					inStr = strdup(ixmlNode_getNodeValue(child));
					break;
				}
				element = child;
			}
			ixmlNodeList_free(msgNodeList);
		}
	}
	
	// Here depends on the ActionRequest and ActionResponse, dispatch to correct handler!
	if(inStr!= NULL)
	{
		DBGPRINTF(RT_DBG_INFO, "Receive a %s Message!\n", actionResNames[i]);
		DBGPRINTF(RT_DBG_INFO, "\tinStr=%s!\n", inStr);
		decodeLen = ILibBase64Decode((unsigned char *)inStr, strlen(inStr), &decodeStr);
		if((decodeLen > 0) && (ioctl_sock >= 0))
		{
			RTMP_WSC_U2KMSG_HDR *msgHdr;
			WscEnvelope *msgEnvelope;
			int msgQIdx = -1;
			 
			/* Prepare the msg buffers */
			wscU2KMsgLen = wscU2KMsgCreate(&pWscU2KMsg, (char *)decodeStr, decodeLen, EAP_FRAME_TYPE_WSC);
			if (wscU2KMsgLen == 0)
				goto done;

			/* Prepare the msg envelope */
			if ((msgEnvelope = wscEnvelopeCreate()) == NULL)
				goto done;
			msgEnvelope->callBack = wscCPPutMessage;
			
			/* Lock the msgQ and check if we can get a valid mailbox to insert our request! */
			if (wscMsgQInsert(msgEnvelope, &msgQIdx) != WSC_SYS_SUCCESS)
				goto done;

			// Fill the session ID to the U2KMsg buffer header.
			msgHdr = (RTMP_WSC_U2KMSG_HDR *)pWscU2KMsg;
			msgHdr->envID = msgEnvelope->envID;

			// copy the Addr1 & Addr2
			memcpy(msgHdr->Addr1, HostMacAddr, MAC_ADDR_LEN);
			memcpy(msgHdr->Addr2, &UPnPDevIP, sizeof(unsigned int));

			// Now send the msg to kernel space.
			DBGPRINTF(RT_DBG_INFO, "(%s):Ready to send pWscU2KMsg(len=%d) to kernel by ioctl(%d)!\n", __FUNCTION__, wscU2KMsgLen, ioctl_sock);
			//wsc_hexdump("U2KMsg", pWscU2KMsg, wscU2KMsgLen);
	
			if(wsc_set_oid(RT_OID_WSC_EAPMSG, pWscU2KMsg, wscU2KMsgLen) != 0)
				wscEnvelopeRemove(msgEnvelope, msgQIdx);
		}
	}


done:
	if (nodeList)
		ixmlNodeList_free(nodeList);
	if (inStr)
		free(inStr);
	if (pWscU2KMsg)
		free(pWscU2KMsg);
	if (decodeStr)
		free(decodeStr);
			
	//wsc_printEvent(UPNP_CONTROL_ACTION_COMPLETE, (void *)a_event);
	return 0;
}
Exemple #15
0
BOOL CVCAMetaParserIXML::ParseBlobsImp(char* szTag, VCA5_PACKET_BLOBMAP *pBLOBMAP )
{
	ULONG ulWidth = 0, ulHeight = 0;
	ULONG ulVal = 0;
	BOOL ret = FALSE;
	char pszStr = NULL;

	IXML_NodeList *pNodeList = NULL;
	IXML_Node *pBlobmapNode = NULL;

	// See if we have any objects this time round
	pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, szTag);
	if( pNodeList ) {
		// Blobmap is there
		pBlobmapNode = pNodeList->nodeItem;

		ulVal = (ULONG)GetNodeValueInt(pBlobmapNode, _XML_W);
		if(ulVal != -1) ulWidth = ulVal;

		ulVal = (ULONG)GetNodeValueInt(pBlobmapNode, _XML_H);
		if(ulVal != -1) ulHeight = ulVal;

		if( ulWidth != pBLOBMAP->ulWidth ||
			ulHeight != pBLOBMAP->ulHeight )
		{
			delete [] pBLOBMAP->pBlobMap;
			delete [] m_pTmpBuf4BlobMap;

			pBLOBMAP->pBlobMap	= new unsigned char[ ulWidth * (ulHeight +1) ];
			pBLOBMAP->ulWidth	= ulWidth;
			pBLOBMAP->ulHeight	= ulHeight;
			m_pTmpBuf4BlobMap	= new unsigned char[ ulWidth * ulHeight ];
		}

		// Now look for the data
		ret = GetNodeValueString(pBlobmapNode, _XML_DATA, (char*)m_pTmpBuf4BlobMap);
		if(ret) {
			unsigned char *pBlobMap = pBLOBMAP->pBlobMap;

			int len = (int)strlen((char*)m_pTmpBuf4BlobMap);
			for( int i = 0; i < len; i++ )
			{
				char cc = (char)m_pTmpBuf4BlobMap[i];
				unsigned char ucBits = m_base64[m_pTmpBuf4BlobMap[i]];

				*pBlobMap++	= ucBits & 0x01 ? 1 : 0;
				*pBlobMap++	= ucBits & 0x02 ? 1 : 0;
				*pBlobMap++	= ucBits & 0x04 ? 1 : 0;
				*pBlobMap++	= ucBits & 0x08 ? 1 : 0;
				*pBlobMap++	= ucBits & 0x10 ? 1 : 0;
				*pBlobMap++	= ucBits & 0x20 ? 1 : 0;
			}
		}
		ixmlNodeList_free(pNodeList);

		pBLOBMAP->ulMapAge = 0;

	}else{
		pBLOBMAP->ulMapAge++;
	
		// we shoud get map update every 2nd frame
		// if map is 2 frames old so clean it up or else we get old map hanging around
		if ( pBLOBMAP->ulMapAge == 2 && pBLOBMAP->pBlobMap )
		{
			memset( pBLOBMAP->pBlobMap, 0, pBLOBMAP->ulWidth * pBLOBMAP->ulHeight );
		}
	}

	return TRUE;
}
Exemple #16
0
void processCDDBUp(IXML_Document * persXmlDoc,U32 InserID)
{
    IXML_NodeList   *nodeList = NULL;
    IXML_Node       *node;
    int             i;
    int             numPending;
    char            *xmlBuff;
    char            * xmlBuff2=NULL;
    char            tempStr[1024];
    int             bUpdated = 0;
    CDDB_PENDING    sCddbP;

    sprintf(tempStr,ZRIP_OLD_TASKFILE);

    if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "CDDBPending")) == NULL)
    {
        dprintf( "Can't find <CDDBPending> node in the %s file",
                tempStr);
        goto funcOut;
    }

    if ((numPending = ixmlNodeList_length(nodeList)) == 0)
    {
        dprintf( "Can't find any <CDDBPending> nodes in the %s file",
                tempStr);
        goto funcOut;
    }

    for (i = 0; i < numPending; i++)
    {
        if ((node = ixmlNodeList_item(nodeList, i)) == NULL)
        {
            continue;
        }
        xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId");
        if (!xmlBuff)
            continue;

        sscanf(xmlBuff,"%x",&sCddbP.uCDID);
		if(sCddbP.uCDID == InserID)
			continue;

        xmlBuff = ixmlGetFirstElementItem( (IXML_Element *)node, "playsecs" );
        if ( xmlBuff == NULL )
        {
            continue;
        }
        else
        {
            sCddbP.nPlaySecs = atoi(xmlBuff);
        }

        xmlBuff = ixmlGetFirstElementItem( (IXML_Element *)node, "tracks" );
        if ( xmlBuff == NULL )
        {
            continue;
        }
        else
        {
            sCddbP.uTotalTracks = atoi(xmlBuff);
        }

        xmlBuff2=ixmlGetFirstElementItem( (IXML_Element *)node, "frames" );

        if ( !xmlBuff2)
            continue;
        else{
            sCddbP.ptrFrames = strdup(xmlBuff2);
            ZFREE(xmlBuff2);
        }
        /* insert into database and free the memory */
        InsertPendingTask(CDDBPENDING,&sCddbP);
        ZFREE(sCddbP.ptrFrames);
    }

    /* free the xml */
    for (i = 0; i < numPending; i++)
    {
        if ((node = ixmlNodeList_item(nodeList, i)) == NULL)
        {
            continue;
        }
        if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){
            dprintf("Failed to remove <cddbPending>");
        }
    }
    bUpdated = 1;

funcOut:
    if ( nodeList )
        ixmlNodeList_free(nodeList);

    if (bUpdated && ixmlUpdateDocument(persXmlDoc, tempStr) == -1)
    {
        /* free it odirect */
        dprintf( "Unable to write file path->%s", tempStr);
    }

    return;
}
Exemple #17
0
void processInsertEncode(IXML_Document * persXmlDoc,U32 * InserID)
{
    int  i, numPending;
    IXML_NodeList  *nodeList;
    char  *xmlBuff;
    char * xmlBuff2;
    IXML_Node  *node;
    U32  tempId;
    char  persFile[128];
    INSERT_PENDING sInsertP;/* for InsertPending table */
    ENC_PENDING    sEncodeP;

    U32  affectedDiscId = 0;
    U32  prevDiscId;
    int  b_updated = 0;

    sprintf(persFile, ZRIP_OLD_TASKFILE);

    /* first test if have rip interupt */
    if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "WavPending")) != NULL){
        if ((numPending = ixmlNodeList_length(nodeList)) != 0){
            if (numPending != 1){
                goto    funcOut;
            }

            if ((node = ixmlNodeList_item(nodeList, 0)) != NULL){
                if ((xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId")) != NULL){
                    sscanf(xmlBuff,"%x",&affectedDiscId);
                    xmlBuff2=ixmlElement_getAttribute((IXML_Element *)node, TOTAL_FRMTAG);
                    if(xmlBuff2)
                    {
                        sInsertP.uCDID = affectedDiscId;
                        sInsertP.ptrFrames = strdup(xmlBuff2);
                        InsertPendingTask(INSERTPENDING, &sInsertP);
                        ZFREE(sInsertP.ptrFrames);
                        /* Insert in to database */
                    }

                    if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){
                        ZError(DBG_ZRIP, "Failed to remove <WavPending>");
                    }
                    else{
                        b_updated = 1;
                    }
                }
            }
        }
        ixmlNodeList_free(nodeList);
    }

    /* second test if have EncPending */
    if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "EncPending")) == NULL){
        goto funcOut;
    }

    if ((numPending = ixmlNodeList_length(nodeList)) == 0){
        ixmlNodeList_free(nodeList);
        goto funcOut;
    }

    prevDiscId = 0;
    node = NULL;

    for (i = 0; i < numPending; i++){
        if ((node = ixmlNodeList_item(nodeList, i)) == NULL){
            continue;
        }
        xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId");

        if (!xmlBuff){
            continue;
        }

        sscanf(xmlBuff,"%x",&tempId);
        if (affectedDiscId == tempId){
            continue;
        }

        /* getAudioFormat */
        xmlBuff = NULL;
        xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "AudioFormat");
        if (!xmlBuff){
            continue;
        }
        else{
            sEncodeP.ptrAudioFormat = strdup(xmlBuff);
		}
		if(strncasecmp(xmlBuff, AUDIO_MP3_TYPE, 3) == 0)
		{
			sEncodeP.ptrFormatCfg = strdup("128");
		}
		else
			sEncodeP.ptrFormatCfg = strdup("0");

        /* getpbject */
        xmlBuff = NULL;
        xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "objid");
        if (!xmlBuff){
            ZFREE(sEncodeP.ptrAudioFormat);
			ZFREE(sEncodeP.ptrFormatCfg);
            continue;
        }
        else{
            sEncodeP.objID = strdup(xmlBuff);
        }
	
		InsertPendingTask(ENCPENDING,&sEncodeP);	
        ZFREE(sEncodeP.ptrAudioFormat);
		ZFREE(sEncodeP.ptrFormatCfg);
        ZFREE(sEncodeP.objID);
        /* insert database */
    }

    for (i = 0; i < numPending; i++){
        if ((node = ixmlNodeList_item(nodeList, i)) == NULL){
            continue;
        }
        if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){
            ZError(DBG_ZRIP, "Failed to remove <WavPending>");
        }
    }
    /* remove all child */
    b_updated = 1;
    ixmlNodeList_free(nodeList);
funcOut:
    if ( affectedDiscId){
        /* delete no use  */
		*InserID = affectedDiscId;
    }
    if ( b_updated && ixmlUpdateDocument(persXmlDoc, persFile) == -1){
        dprintf("Unable to write file path->%s", persFile);
    }
    return;
}
Exemple #18
0
input_item_t* MediaServer::getNextItem()
{
    input_item_t *p_item = NULL;

    if( !xmlDocument_ )
    {
        fetchContents();
        if( !xmlDocument_ )
            return NULL;
    }

    if ( containerNodeList_ )
    {
        for ( ; !p_item && containerNodeIndex_ < ixmlNodeList_length( containerNodeList_ )
              ; containerNodeIndex_++ )
        {
            IXML_Element* containerElement = (IXML_Element*)ixmlNodeList_item( containerNodeList_,
                                                                                containerNodeIndex_ );

            const char* objectID = ixmlElement_getAttribute( containerElement,
                                                             "id" );
            if ( !objectID )
                continue;

            const char* title = xml_getChildElementValue( containerElement,
                                                          "dc:title" );
            if ( !title )
                continue;
            p_item = newItem(objectID, title);
        }
    }

    if( itemNodeList_ )
    {
        for ( ; !p_item && itemNodeIndex_ < ixmlNodeList_length( itemNodeList_ )
              ; itemNodeIndex_++ )
        {
            IXML_Element* itemElement =
                        ( IXML_Element* )ixmlNodeList_item( itemNodeList_,
                                                            itemNodeIndex_ );

            const char* objectID =
                        ixmlElement_getAttribute( itemElement, "id" );

            if ( !objectID )
                continue;

            const char* title =
                        xml_getChildElementValue( itemElement, "dc:title" );

            if ( !title )
                continue;

            const char* psz_subtitles = xml_getChildElementValue( itemElement,
                    "sec:CaptionInfo" );

            if ( !psz_subtitles )
                psz_subtitles = xml_getChildElementValue( itemElement,
                        "sec:CaptionInfoEx" );

            if ( !psz_subtitles )
                psz_subtitles = xml_getChildElementValue( itemElement,
                        "pv:subtitlefile" );

            /* Try to extract all resources in DIDL */
            IXML_NodeList* p_resource_list = ixmlDocument_getElementsByTagName( (IXML_Document*) itemElement, "res" );
            if ( p_resource_list && ixmlNodeList_length( p_resource_list ) > 0 )
            {
                mtime_t i_duration = -1;
                int i_hours, i_minutes, i_seconds;
                IXML_Element* p_resource = ( IXML_Element* ) ixmlNodeList_item( p_resource_list, 0 );
                const char* psz_resource_url = xml_getChildElementValue( p_resource, "res" );
                if( !psz_resource_url )
                    continue;
                const char* psz_duration = ixmlElement_getAttribute( p_resource, "duration" );

                if ( psz_duration )
                {
                    if( sscanf( psz_duration, "%d:%02d:%02d",
                        &i_hours, &i_minutes, &i_seconds ) )
                        i_duration = INT64_C(1000000) * ( i_hours*3600 +
                                                          i_minutes*60 +
                                                          i_seconds );
                }

                p_item = newItem( title, objectID, psz_subtitles, i_duration,
                                  psz_resource_url );
            }
            ixmlNodeList_free( p_resource_list );
        }
    }

    return p_item;
}
Exemple #19
0
bool MediaServer::addItem( IXML_Element* itemElement )
{
    ItemDescriptionHolder holder;

    if (!holder.init(itemElement))
        return false;
    /* Try to extract all resources in DIDL */
    IXML_NodeList* p_resource_list = ixmlDocument_getElementsByTagName( (IXML_Document*) itemElement, "res" );
    if ( !p_resource_list)
        return false;
    int list_lenght = ixmlNodeList_length( p_resource_list );
    if (list_lenght <= 0 ) {
        ixmlNodeList_free( p_resource_list );
        return false;
    }
    input_item_t *p_item = NULL;

    for (int index = 0; index < list_lenght; index++)
    {
        IXML_Element* p_resource = ( IXML_Element* ) ixmlNodeList_item( p_resource_list, index );
        const char* rez_type = ixmlElement_getAttribute( p_resource, "protocolInfo" );

        if (strncmp(rez_type, "http-get:*:video/", 17) == 0 && holder.media_type == ItemDescriptionHolder::VIDEO)
        {
            if (!p_item)
                p_item = holder.createNewItem(p_resource);
            holder.addSubtitleSlave(p_resource);
        }
        else if (strncmp(rez_type, "http-get:*:image/", 17) == 0)
            switch (holder.media_type)
            {
            case ItemDescriptionHolder::IMAGE:
                if (!p_item) {
                    p_item = holder.createNewItem(p_resource);
                    break;
                }
            case ItemDescriptionHolder::VIDEO:
            case ItemDescriptionHolder::AUDIO:
                holder.setArtworkURL(p_resource);
                break;
            }
        else if (strncmp(rez_type, "http-get:*:text/", 16) == 0)
            holder.addSlave(xml_getChildElementValue( p_resource, "res" ), SLAVE_TYPE_SPU);
        else if (strncmp(rez_type, "http-get:*:audio/", 17) == 0)
        {
            if (holder.media_type == ItemDescriptionHolder::AUDIO)
            {
                if (!p_item)
                    p_item = holder.createNewItem(p_resource);
            }
            else
                holder.addSlave(xml_getChildElementValue( p_resource, "res" ),
                                SLAVE_TYPE_AUDIO);
        }
    }
    ixmlNodeList_free( p_resource_list );
    if (!p_item)
        return false;
    holder.apply(p_item);
    input_item_CopyOptions( p_item, m_node->p_item );
    input_item_node_AppendItem( m_node, p_item );
    input_item_Release( p_item );
    return true;
}
/**************************************************************************
* Function: prepareParameter
* Functionality: it will get the parameter from pipe and check it
* @IN : fd: the file description id for the pipe
*      enable: enable or disable flag
* @OUT: 0 success, else failed.
* Used description:
    The parameter is a xml, it will get from the pipe
* Date: 20080108
* Changed history:
* Date 		Who		Reason
* 20080108	kelly  		First  creation
***************************************************************************/
int prepareParameter(PSystemConfig **pList,int *count)
{
    IXML_Document *rootDom = NULL;
    IXML_NodeList   *nodeList = NULL;
    IXML_NodeList   *nodeList2 = NULL;
    IXML_Node       *node = NULL;
    IXML_Node       *cmdNode = NULL;
	IXML_Node       *node2 = NULL;
    char buffer[1024] = {0};
    char Str[1024] = {0};
    int i = 0;
	int i_ret=0;
	int nodeLen = 0;
	PSystemConfig *pConfigList = NULL;

    while(1)
    {
        fgets(Str, 1024, stdin);
        strcat(buffer, Str);
        if(strstr(buffer,EndFlag))
            break;
    }

    if(strlen(buffer) == 0)
        goto failed;

    if((rootDom = ixmlParseBuffer(buffer)) == NULL){
		i_ret = -1;
		goto Err_handler;
	}

	if((nodeList = ixmlDocument_getElementsByTagName(rootDom,"cmd")) != NULL) 
	{
		cmdNode   = ixmlGetFirstNodeByTagName(rootDom,"cmd");
		nodeList2 = ixmlNode_getChildNodes(cmdNode);
		nodeLen   = ixmlNodeList_length(nodeList2);

		pConfigList = (PSystemConfig*)malloc(sizeof(PSystemConfig) * nodeLen);
		memset(pConfigList, 0, sizeof(PSystemConfig)*nodeLen);

		node = ixmlNodeList_item(nodeList, 0);
		node = ixmlNode_getFirstChild(node);
		while (node != NULL)
		{
			pConfigList[i] = (PSystemConfig)malloc(sizeof(SystemConfig));
			memset(pConfigList[i],0,sizeof(SystemConfig));						
			pConfigList[i]->name = strdup(ixmlNode_getNodeName(node));


			node2 = ixmlNode_getFirstChild(node);
			pConfigList[i]->value = (ixmlNode_getNodeValue(node2))?strdup(ixmlNode_getNodeValue(node2)):strdup("");

/*            fprintf(stderr, "name->%s , value ->%s\n" , pConfigList[i]->name , pConfigList[i]->value);		*/

			i_ret=CheckVariable(pConfigList[i]->name,pConfigList[i]->value);
			if(i_ret<0)
			{
				i_ret = -3;
				goto Err_handler;
			}

			node = ixmlNode_getNextSibling(node);
			i++;
		}
	}

	*count = nodeLen;

	if(pConfigList){
		*pList = pConfigList;
	}
	else{
		fprintf(stderr, " !!!!!!pLIST is NULL");
	}

	if (rootDom)
        ixmlDocument_free(rootDom);
    if (nodeList)
        ixmlNodeList_free(nodeList);
    if (nodeList2)
        ixmlNodeList_free(nodeList2);
    return i;

failed:
        fprintf(stderr,"Got a command parameter->%s", buffer);
        //fprintf(stderr,"Got a command parameter->%s", buffer);
		return i;
Err_handler:
		if (rootDom)
			ixmlDocument_free(rootDom);
		if (nodeList)
			ixmlNodeList_free(nodeList);
		if (nodeList2)
			ixmlNodeList_free(nodeList2);
		return i_ret;
}
Exemple #21
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 );
    }
}
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;	
}
Exemple #23
0
/******************************************************************************
 * BrowseAction
 *****************************************************************************/
static int
BrowseOrSearchAction (ContentDir* cds,
		      void* result_context,
		      const char* objectId, 
		      const char* criteria,
		      Index starting_index,
		      Count requested_count,
		      Count* nb_matched,
		      Count* nb_returned,
		      PtrArray* objects)
{
	if (cds == NULL || objectId == NULL || criteria == NULL) {
		Log_Printf (LOG_ERROR, 
			    "BrowseOrSearchAction NULL parameter");
		return UPNP_E_INVALID_PARAM; // ---------->
	}
	
	// Create a working context for temporary allocations
	void* tmp_ctx = talloc_new (NULL);
	
	const bool browse = is_browse (criteria);
	IXML_Document* doc = NULL;
	int rc = Service_SendActionVa
		(OBJECT_SUPER_CAST(cds), &doc, 
		 (browse ? "Browse" : "Search"),
		 (browse ? "ObjectID" : "ContainerID"),		objectId,
		 (browse ? "BrowseFlag" : "SearchCriteria"),	criteria,
		 "Filter", 	      "*",
		 "StartingIndex",     int_to_string (tmp_ctx, starting_index),
		 "RequestedCount",    int_to_string (tmp_ctx, requested_count),
		 "SortCriteria",      "",
		 NULL, 		      NULL);
	if (doc == NULL && rc == UPNP_E_SUCCESS)
		rc = UPNP_E_BAD_RESPONSE;
	if (rc != UPNP_E_SUCCESS) {
		Log_Printf (LOG_ERROR, "BrowseOrSearchAction ObjectId='%s'",
			    NN(objectId));
		goto cleanup; // ---------->
	}
	
	const char* s = XMLUtil_FindFirstElementValue 
		(XML_D2N (doc), "TotalMatches", true, true);
	STRING_TO_INT (s, *nb_matched, 0);
	
	s = XMLUtil_FindFirstElementValue 
		(XML_D2N (doc), "NumberReturned", true, true);
	STRING_TO_INT (s, *nb_returned, 0);
	
	Log_Printf (LOG_DEBUG, "+++BROWSE RESULT+++\n%s\n", 
		    XMLUtil_GetDocumentString (tmp_ctx, doc));
	
	const char* const resstr = XMLUtil_FindFirstElementValue
		(XML_D2N (doc), "Result", true, true);
	if (resstr == NULL) {
		Log_Printf (LOG_ERROR, "BrowseOrSearchAction ObjectId=%s : "
			    "can't get 'Result' in doc=%s",
			    objectId, 
			    XMLUtil_GetDocumentString (tmp_ctx, doc));
		rc = UPNP_E_BAD_RESPONSE;
		goto cleanup; // ---------->
	}

	IXML_Document* const subdoc = 
		ixmlParseBuffer (discard_const_p (char, resstr));
	if (subdoc == NULL) {
		Log_Printf (LOG_ERROR, "BrowseOrSearchAction ObjectId=%s : "
			    "can't parse 'Result'=%s", objectId, resstr);
		rc = UPNP_E_BAD_RESPONSE;
	} else {
		IXML_NodeList* containers = ixmlDocument_getElementsByTagName
			(subdoc, "container"); 
		ContentDir_Count const nb_containers = 
			ixmlNodeList_length (containers);
		IXML_NodeList* items =
			ixmlDocument_getElementsByTagName (subdoc, "item"); 
		ContentDir_Count const nb_items = ixmlNodeList_length (items);
		if (nb_containers + nb_items != *nb_returned) {
			Log_Printf (LOG_ERROR, 
				    "BrowseOrSearchAction ObjectId=%s "
				    "got %d containers + %d items, "
				    "expected %d", objectId, 
				    (int) nb_containers, (int) nb_items,
				    (int) *nb_returned);
			*nb_returned = nb_containers + nb_items;
		}
		if (criteria == CRITERIA_BROWSE_METADATA && *nb_returned != 1){
			Log_Printf (LOG_ERROR, "ContentDir_Browse Metadata : "
				    "not 1 result exactly ! Id=%s", 
				    NN(objectId));
		}

		ContentDir_Count i; 
		for (i = 0; i < *nb_returned; i++) {
			bool const is_container = (i < nb_containers);
			IXML_Element* const elem = (IXML_Element*) 
				ixmlNodeList_item
				(is_container ? containers : items, 
				 is_container ? i : i - nb_containers);
			DIDLObject* o = DIDLObject_Create (result_context, 
							   elem, is_container);
			if (o) {
				PtrArray_Append (objects, o);
			}
		}
		
		if (containers)
			ixmlNodeList_free (containers);
		if (items)
			ixmlNodeList_free (items);
		ixmlDocument_free (subdoc);
	}
	
 cleanup:
	
	ixmlDocument_free (doc);
	doc = NULL;
	
	// Delete all temporary storage
	talloc_free (tmp_ctx);
	tmp_ctx = NULL;
	
	if (rc != UPNP_E_SUCCESS)
		*nb_returned = *nb_matched = 0;
	
	return rc;
}
Exemple #24
0
/************************************************************************
*	Function :	config_description_doc
*
*	Parameters :
*		INOUT IXML_Document *doc ;IMXL description document to be 
*					configured	
*		IN const char* ip_str ;	string containing the IP port number
*		OUT char** root_path_str ;	buffer to hold the root path
*					of the configured description document
*		INOUT IXML_Document *doc :	Description document
*		IN const char* ip_str :	ipaddress string
*		OUT char** root_path_str :	root path string
*
*	Description : Configure the description document. Add the standard 
*		format and then add information from the root device and any
*		child nodes.
*
*	Return : int ;
*		UPNP_E_SUCCESS - On Success
*		UPNP_E_OUTOF_MEMORY - Default Error
*		UPNP_E_INVALID_DESC - Invalid child node		
*		UPNP_E_INVALID_URL - Invalid node information
*
*	Note :
************************************************************************/
static int
config_description_doc( INOUT IXML_Document * doc,
                        IN const char *ip_str,
                        OUT char **root_path_str )
{
    xboolean addNew = FALSE;
    IXML_NodeList *baseList;
    IXML_Element *element = NULL;
    IXML_Element *newElement = NULL;
    IXML_Node *textNode = NULL;
    IXML_Node *rootNode = NULL;
    IXML_Node *urlbase_node = NULL;
    char *urlBaseStr = "URLBase";
    const DOMString domStr = NULL;
    uri_type uri;
    int err_code;
    int len;
    membuffer url_str;
    membuffer root_path;

    membuffer_init( &url_str );
    membuffer_init( &root_path );

    err_code = UPNP_E_OUTOF_MEMORY; // default error

    baseList = ixmlDocument_getElementsByTagName( doc, urlBaseStr );
    if( baseList == NULL ) {
        // urlbase not found -- create new one
        addNew = TRUE;
        element = ixmlDocument_createElement( doc, urlBaseStr );
        if( element == NULL ) {
            goto error_handler;
        }

        if( membuffer_append_str( &url_str, "http://" ) != 0 ||
            membuffer_append_str( &url_str, ip_str ) != 0 ||
            membuffer_append_str( &url_str, "/" ) != 0 ||
            membuffer_append_str( &root_path, "/" ) != 0 ) {
            goto error_handler;
        }

        rootNode = ixmlNode_getFirstChild( ( IXML_Node * ) doc );
        if( rootNode == NULL ) {
            err_code = UPNP_E_INVALID_DESC;
            goto error_handler;
        }

        err_code =
            ixmlNode_appendChild( rootNode, ( IXML_Node * ) element );
        if( err_code != IXML_SUCCESS ) {
            goto error_handler;
        }

        textNode =
            ixmlDocument_createTextNode( doc, ( char * )url_str.buf );
        if( textNode == NULL ) {
            goto error_handler;
        }

        err_code =
            ixmlNode_appendChild( ( IXML_Node * ) element, textNode );
        if( err_code != IXML_SUCCESS ) {
            goto error_handler;
        }

    } else {
        // urlbase found
        urlbase_node = ixmlNodeList_item( baseList, 0 );
        assert( urlbase_node != NULL );

        textNode = ixmlNode_getFirstChild( urlbase_node );
        if( textNode == NULL ) {
            err_code = UPNP_E_INVALID_DESC;
            goto error_handler;
        }

        domStr = ixmlNode_getNodeValue( textNode );
        if( domStr == NULL ) {
            err_code = UPNP_E_INVALID_URL;
            goto error_handler;
        }

        len = parse_uri( domStr, strlen( domStr ), &uri );
        if( len < 0 || uri.type != ABSOLUTE ) {
            err_code = UPNP_E_INVALID_URL;
            goto error_handler;
        }

        if( membuffer_assign( &url_str, uri.scheme.buff,
                              uri.scheme.size ) != 0 ||
            membuffer_append_str( &url_str, "://" ) != 0 ||
            membuffer_append_str( &url_str, ip_str ) != 0 ) {
            goto error_handler;
        }
        // add leading '/' if missing from relative path
        if( ( uri.pathquery.size > 0 && uri.pathquery.buff[0] != '/' ) ||
            ( uri.pathquery.size == 0 )
             ) {
            if( membuffer_append_str( &url_str, "/" ) != 0 ||
                membuffer_append_str( &root_path, "/" ) != 0 ) {
                goto error_handler;
            }
        }

        if( membuffer_append( &url_str, uri.pathquery.buff,
                              uri.pathquery.size ) != 0 ||
            membuffer_append( &root_path, uri.pathquery.buff,
                              uri.pathquery.size ) != 0 ) {
            goto error_handler;
        }
        // add trailing '/' if missing
        if( url_str.buf[url_str.length - 1] != '/' ) {
            if( membuffer_append( &url_str, "/", 1 ) != 0 ) {
                goto error_handler;
            }
        }

        err_code = ixmlNode_setNodeValue( textNode, url_str.buf );
        if( err_code != IXML_SUCCESS ) {
            goto error_handler;
        }
    }

    *root_path_str = membuffer_detach( &root_path );    // return path
    err_code = UPNP_E_SUCCESS;

  error_handler:
    if( err_code != UPNP_E_SUCCESS ) {
        ixmlElement_free( newElement );
    }

    ixmlNodeList_free( baseList );

    membuffer_destroy( &root_path );
    membuffer_destroy( &url_str );

    return err_code;
}
Exemple #25
0
RTPXML_NodeList *rtpxmlDocument_getElementsByTagName(RTPXML_Document *doc, DOMString tagName)
{
	return (RTPXML_NodeList *)ixmlDocument_getElementsByTagName((IXML_Document *)doc, tagName);
}
Exemple #26
0
/********************************************************************************
 * TvStateUpdate
 *
 * Description: 
 *       Update a Tv state table.  Called when an event is
 *       received.  Note: this function is NOT thread save.  It must be
 *       called from another function that has locked the global device list.
 *
 * Parameters:
 *   UDN     -- The UDN of the parent device.
 *   Service -- The service state table to update
 *   ChangedVariables -- DOM document representing the XML received
 *                       with the event
 *   State -- pointer to the state table for the Tv  service
 *            to update
 *
 ********************************************************************************/
void
TvStateUpdate( char *UDN,
               int Service,
               IXML_Document * ChangedVariables,
               char **State )
{
    IXML_NodeList *properties,
     *variables;
    IXML_Element *property,
     *variable;
    int length,
      length1;
    int i,
      j;
    char *tmpstate = NULL;

    SampleUtil_Print( "Tv State Update (service %d): ", Service );

    /*
       Find all of the e:property tags in the document 
     */
    properties =
        ixmlDocument_getElementsByTagName( ChangedVariables,
                                           "e:property" );
    if( NULL != 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'",
                                  TvVarName[Service][j], State[j] );
                        }

                        if( tmpstate )
                            free( tmpstate );
                        tmpstate = NULL;
                    }

                    ixmlNodeList_free( variables );
                    variables = NULL;
                }
            }

        }
        ixmlNodeList_free( properties );
    }
}
Exemple #27
0
void MediaServer::parseDeviceDescription( IXML_Document* p_doc,
                                          const char*    p_location,
                                          services_discovery_t* p_sd )
{
    if ( !p_doc )
    {
        msg_Err( p_sd, "Null IXML_Document" );
        return;
    }

    if ( !p_location )
    {
        msg_Err( p_sd, "Null location" );
        return;
    }

    const char* psz_base_url = p_location;

    /* Try to extract baseURL */
    IXML_NodeList* p_url_list = ixmlDocument_getElementsByTagName( p_doc, "URLBase" );
    if ( p_url_list )
    {

        if ( IXML_Node* p_url_node = ixmlNodeList_item( p_url_list, 0 ) )
        {
            IXML_Node* p_text_node = ixmlNode_getFirstChild( p_url_node );
            if ( p_text_node ) psz_base_url = ixmlNode_getNodeValue( p_text_node );
        }

        ixmlNodeList_free( p_url_list );
    }

    /* Get devices */
    IXML_NodeList* p_device_list =
                ixmlDocument_getElementsByTagName( p_doc, "device" );

    if ( p_device_list )
    {
        for ( unsigned int i = 0; i < ixmlNodeList_length( p_device_list ); i++ )
        {
            IXML_Element* p_device_element =
                   ( IXML_Element* ) ixmlNodeList_item( p_device_list, i );

            const char* psz_device_type = xml_getChildElementValue( p_device_element,
                                                               "deviceType" );
            if ( !psz_device_type )
            {
                msg_Warn( p_sd, "No deviceType found!" );
                continue;
            }

            if ( strncmp( MEDIA_SERVER_DEVICE_TYPE, psz_device_type,
                    strlen( MEDIA_SERVER_DEVICE_TYPE ) - 1 ) != 0 )
                continue;

            const char* psz_udn = xml_getChildElementValue( p_device_element, "UDN" );
            if ( !psz_udn )
            {
                msg_Warn( p_sd, "No UDN!" );
                continue;
            }

            /* Check if server is already added */
            if ( p_sd->p_sys->p_server_list->getServer( psz_udn ) != 0 )
            {
                msg_Warn( p_sd, "Server with uuid '%s' already exists.", psz_udn );
                continue;
            }

            const char* psz_friendly_name =
                       xml_getChildElementValue( p_device_element,
                                                 "friendlyName" );

            if ( !psz_friendly_name )
            {
                msg_Dbg( p_sd, "No friendlyName!" );
                continue;
            }

            MediaServer* p_server = new MediaServer( psz_udn, psz_friendly_name, p_sd );

            if ( !p_sd->p_sys->p_server_list->addServer( p_server ) )
            {
                delete p_server;
                p_server = 0;
                continue;
            }

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

                    const char* psz_service_type =
                        xml_getChildElementValue( p_service_element,
                                                  "serviceType" );
                    if ( !psz_service_type )
                    {
                        msg_Warn( p_sd, "No service type found." );
                        continue;
                    }

                    int k = strlen( CONTENT_DIRECTORY_SERVICE_TYPE ) - 1;
                    if ( strncmp( CONTENT_DIRECTORY_SERVICE_TYPE,
                                psz_service_type, k ) != 0 )
                        continue;

		    p_server->_i_content_directory_service_version =
			psz_service_type[k];

                    const char* psz_event_sub_url =
                        xml_getChildElementValue( p_service_element,
                                                  "eventSubURL" );
                    if ( !psz_event_sub_url )
                    {
                        msg_Warn( p_sd, "No event subscription url found." );
                        continue;
                    }

                    const char* psz_control_url =
                        xml_getChildElementValue( p_service_element,
                                                  "controlURL" );
                    if ( !psz_control_url )
                    {
                        msg_Warn( p_sd, "No control url found." );
                        continue;
                    }

                    /* Try to subscribe to ContentDirectory service */

                    char* psz_url = ( char* ) malloc( strlen( psz_base_url ) +
                            strlen( psz_event_sub_url ) + 1 );
                    if ( psz_url )
                    {
                        if ( UpnpResolveURL( psz_base_url, psz_event_sub_url, psz_url ) ==
                                UPNP_E_SUCCESS )
                        {
                            p_server->setContentDirectoryEventURL( psz_url );
                            p_server->subscribeToContentDirectory();
                        }

                        free( psz_url );
                    }

                    /* Try to browse content directory. */

                    psz_url = ( char* ) malloc( strlen( psz_base_url ) +
                            strlen( psz_control_url ) + 1 );
                    if ( psz_url )
                    {
                        if ( UpnpResolveURL( psz_base_url, psz_control_url, psz_url ) ==
                                UPNP_E_SUCCESS )
                        {
                            p_server->setContentDirectoryControlURL( psz_url );
                            p_server->fetchContents();
                        }

                        free( psz_url );
                    }
               }
               ixmlNodeList_free( p_service_list );
           }
       }
       ixmlNodeList_free( p_device_list );
    }
}
Exemple #28
0
BOOL CVCAMetaParserIXML::ParseObjects( )
{
	IXML_NodeList *pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, _XML_OBJECTS);
	if( pNodeList ) {
		IXML_Node *pObjectsNode, *pObjectNode;
		IXML_NodeList *pObjectNodeList;

		m_vcaObjects.ulTotalObject = 0;

		pObjectsNode = pNodeList->nodeItem;

	//	TRACE(ixmlPrintNode(pObjectsNode));
		//pObjectNode = ixmlNode_getFirstChild(pObjectsNode);
		pObjectNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pObjectsNode, _XML_OBJECT);
#if 0
		if(pObjectNodeList) {
			pObjectNode = pObjectNodeList->nodeItem;
			while(pObjectNode) {
				TRACE("=====================================\n");
				TRACE(ixmlPrintNode(pObjectNode));
				pObjectNode = pObjectNode->nextSibling;
				//pObjectNode = pObjectNodeList->next;
			}
		}
#endif
		VCA5_PACKET_OBJECT	vcaObj;
		ULONG ulVal = 0;
		int iVal = 0;
		if(pObjectNodeList) {
			pObjectNode = pObjectNodeList->nodeItem;

			while(pObjectNode) {
				memset( &vcaObj, 0, sizeof( vcaObj ) );

				ulVal = (ULONG)GetNodeValueInt(pObjectNode, _XML_ID);
				if(ulVal != -1) vcaObj.ulId = ulVal;

				ulVal = (ULONG)GetNodeValueInt(pObjectNode, _XML_CH);
				if(ulVal != -1) vcaObj.ulCalibHeight = ulVal;

				ulVal = (ULONG)GetNodeValueInt(pObjectNode, _XML_CS);
				if(ulVal != -1) vcaObj.ulCalibSpeed = ulVal;

				ulVal = (ULONG)GetNodeValueInt(pObjectNode, _XML_CA);
				if(ulVal != -1) vcaObj.ulCalibArea = ulVal;

				iVal = (ULONG)GetNodeValueInt(pObjectNode, _XML_CLS);
				if(ulVal != -1) vcaObj.iClassificationId = iVal;
				else vcaObj.iClassificationId = -2;  // unknown
				
				CHAR colSigs[VCA5_APP_PALETTE_SIZE * 2] = { 0, };
				ulVal = (ULONG)GetNodeValueString(pObjectNode, _XML_COLSIG, colSigs);
				if(ulVal != FALSE) memcpy(vcaObj.colSigs, colSigs, sizeof( vcaObj.colSigs ) );

				// Bounding box
				IXML_NodeList *pBBOXNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pObjectNode, _XML_BB);
				if(pBBOXNodeList) {
					ParseBBox( pBBOXNodeList->nodeItem, &vcaObj.bBox );
					ixmlNodeList_free(pBBOXNodeList);
				}

				// Trail
				IXML_NodeList *pTrailNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pObjectNode, _XML_TRAIL);
				if( pTrailNodeList ) {
					ParseTrail( pTrailNodeList, &vcaObj.trail );
					ixmlNodeList_free(pTrailNodeList);
				}

				// Flags
				ulVal = (ULONG)GetNodeValueInt(pObjectNode, _XML_FLAGS);
				if(ulVal != -1) vcaObj.ulFlags = ulVal;

				m_vcaObjects.Objects[m_vcaObjects.ulTotalObject]  = vcaObj;
				m_vcaObjects.ulTotalObject++;

				pObjectNode = pObjectNode->nextSibling;
			}
			ixmlNodeList_free(pObjectNodeList);
		//	TRACE("# Objects [%2d]\n", m_vcaObjects.ulTotalObject);
		}

		ixmlNodeList_free(pNodeList);
	}

	return TRUE;
}