Example #1
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);
		
	}
}
Example #3
0
/*
 * Fetches and parses the UPNP response
 */
bool MediaServer::fetchContents()
{
    IXML_Document* p_response = _browseAction( m_psz_objectId,
                                "BrowseDirectChildren",
                                "*",
                                // Some servers don't understand "0" as "no-limit"
                                "1000", /* RequestedCount */
                                "" /* SortCriteria */
                                             );
    if ( !p_response )
    {
        msg_Err( m_access, "No response from browse() action" );
        return false;
    }

    IXML_Document* p_result = parseBrowseResult( p_response );

    ixmlDocument_free( p_response );

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

#ifndef NDEBUG
    msg_Dbg( m_access, "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++ )
            addContainer( (IXML_Element*)ixmlNodeList_item( containerNodeList, i ) );
        ixmlNodeList_free( containerNodeList );
    }

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

    ixmlDocument_free( p_result );
    return true;
}
Example #4
0
/********************************************************************************
 * upnp_igd_state_update
 *
 * Description:
 *       Handle a uPnP event that was received.  Process the event and update
 *       the appropriate service state table.
 *
 * Parameters:
 *   igd_ctxt          -- The upnp igd context
 *   device_node       -- The device updated
 *   service           -- The service updated
 *   changed_variables -- The updated variables
 *   values            -- The values of variables to update
 *
 ********************************************************************************/
void upnp_igd_state_update(upnp_igd_context* igd_ctxt, upnp_igd_device_node *device_node, int service, IXML_Document *changed_variables, char **values) {
	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;

	upnp_igd_print(igd_ctxt, UPNP_IGD_DEBUG, "IGD State Update (service %d):", service);
	/* Find all of the e:property tags in the document */
	properties = ixmlDocument_getElementsByTagNameNS(changed_variables, UPNPDeviceType, "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 < IGDVarCount[service]; j++) {
				variables = ixmlElement_getElementsByTagNameNS(property, IGDServiceType[service], IGDVarName[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 = upnp_igd_get_element_value(igd_ctxt, variable);
						if (tmpstate) {
							if(strcmp(values[j], tmpstate)) {
								upnp_igd_strncpy(values[j], tmpstate, IGD_MAX_VAR_LEN);
								upnp_igd_var_updated(igd_ctxt, device_node, service, j, values[j]);
							}
						}
						if (tmpstate) {
							free(tmpstate);
						}
						tmpstate = NULL;
					}
					ixmlNodeList_free(variables);
					variables = NULL;
				}
			}
		}
		ixmlNodeList_free(properties);
	}
	return;
}
Example #5
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);
}
Example #6
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;
}
Example #7
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;
}
Example #8
0
IXML_Node *ixmlNodeList_item(
	IXML_NodeList *nList,
	unsigned long index)
{
	IXML_NodeList *next;
	unsigned int i;

	// if the list ptr is NULL
	if (nList == NULL) {
		return NULL;
	}
	// if index is more than list length
	if (index > ixmlNodeList_length(nList) - 1) {
		return NULL;
	}

	next = nList;
	for (i = 0; i < index && next != NULL; ++i) {
		next = next->next;
	}

	if (next == NULL) {
		return NULL;
	}

	return next->nodeItem;
}
Example #9
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;
}
Example #10
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;
}
Example #11
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;
}
Example #12
0
			v = (char*) ixmlNode_getNodeValue(l1_1_node);
			LoadConfigItem(Conf, sq_conf, n, v);
		}
		if (node_list) ixmlNodeList_free(node_list);
	}

	return node;
}

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

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

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

	elm = ixmlDocument_getElementById((IXML_Document	*)elm, "common");
	if (elm) {
		char *n, *v;
		IXML_NodeList *l1_node_list;
		unsigned i;
		l1_node_list = ixmlNode_getChildNodes((IXML_Node*) elm);
		for (i = 0; i < ixmlNodeList_length(l1_node_list); i++) {
			IXML_Node *l1_node, *l1_1_node;
			l1_node = ixmlNodeList_item(l1_node_list, i);
Example #13
0
/* 
 * supported properties are:
 * deviceType
 * friendlyName
 * manufacturer
 * modelName
 * UDN
 * serviceType
 * serviceId
 **/
const char *get_device_property(IXML_Document *desc, const char *prop) {
    IXML_NodeList *list = ixmlDocument_getElementsByTagName(desc, prop);
    int length = ixmlNodeList_length(list);
    if (length < 1) {
        fprintf(stderr, "Error obtaining device name\n");
    }
    IXML_Node *n = ixmlNodeList_item(list, 0);
    n = ixmlNode_getFirstChild(n);
    return ixmlNode_getNodeValue(n);
}
Example #14
0
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;
}
Example #15
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;
}
Example #16
0
/********************************************************************************
 * upnp_igd_handle_send_action
 *
 * Description:
 *       Function called when a variable is grabbed
 *
 * Parameters:
 *   igd_ctxt   -- The upnp igd context
 *   controlURL -- The control url used for the update
 *   varName    -- The variable name
 *   varValue   -- The value of the variable
 *
 ********************************************************************************/
void upnp_igd_handle_send_action(upnp_igd_context* igd_ctxt, const char *controlURL, IXML_Document *action, IXML_Document *result) {
	upnp_igd_device_node *tmpdevnode;
	int service;
	IXML_Element *variable;
	IXML_NodeList *variables;
	long unsigned int length1;
	int j;
	char *tmpstate = NULL;
	char variable_name[sizeof("New") + IGD_MAX_VAR_LEN];

	ithread_mutex_lock(&igd_ctxt->devices_mutex);

	tmpdevnode = igd_ctxt->devices;
	while (tmpdevnode) {
		for (service = 0; service < IGD_SERVICE_SERVCOUNT; service++) {
			if (strcmp(tmpdevnode->device.services[service].control_url, controlURL) == 0) {
				for (j = 0; j < IGDVarCount[service]; j++) {
						// Build the element name from the variable
						strcpy(variable_name, "New");
						strcat(variable_name, IGDVarName[service][j]);
						variables = ixmlDocument_getElementsByTagName(result, variable_name);

						/* 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 = upnp_igd_get_element_value(igd_ctxt, variable);
								if (tmpstate) {
									if(strcmp(tmpdevnode->device.services[service].variables[j], tmpstate)) {
										upnp_igd_strncpy(tmpdevnode->device.services[service].variables[j], tmpstate, IGD_MAX_VAR_LEN);
										upnp_igd_var_updated(igd_ctxt, tmpdevnode, service, j, tmpdevnode->device.services[service].variables[j]);
									}
								}
								if (tmpstate) {
									free(tmpstate);
								}
								tmpstate = NULL;
							}
							ixmlNodeList_free(variables);
							variables = NULL;
						}
				}
				break;
			}
		}
		tmpdevnode = tmpdevnode->next;
	}

	ithread_mutex_unlock(&igd_ctxt->devices_mutex);
}
Example #17
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);
}
Example #18
0
static IXML_Node* s_CD_GetWantedRes(char *dms_ip, IXML_NodeList *reslist, char *method, char *option)
{
	char *dup_protocol, *transport, *mimetype, *dlna; 
	int i, len;
	IXML_Node *ret = NULL;

	if(!dms_ip || !reslist || !method || !option)
		return ret;
	
	len = ixmlNodeList_length(reslist);
	HT_DBG_FUNC_START(HT_MOD_DMC, HT_BIT_MANY,len,0);
	
	for (i = 0; i < len; i++)
	{
		IXML_Node *res = ixmlNodeList_item (reslist, i);
		IXML_Element*element = (IXML_Element*)res;
		const char* protocol = ixmlElement_getAttribute (element, "protocolInfo");
		const char* uri = XMLUtil_GetElementValue (element);
	
		HT_DBG_FUNC(i, protocol);
        if (uri == NULL || protocol == NULL || !s_YX_CD_CheckInfo(protocol, &dup_protocol, &transport, &mimetype, &dlna)) 
			continue;
		
		if(strstr(transport, method) && s_CD_IpMatched_Ex(dms_ip, uri) )
		{
			if( !strstr(dlna, "DLNA.ORG_CI=1") )//raw media file
			{
				ret = res;
                free(dup_protocol);
				break;
			}
		}
        free(dup_protocol);
	}
	
	HT_DBG_FUNC_END((int)ret, 0);
	return ret;
}
Example #19
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;
}
Example #20
0
		if (v && !strcmp(v, UDN)) {
			device = ixmlNode_getParentNode(l1_node);
			break;
		}
	}
	if (l1_node_list) ixmlNodeList_free(l1_node_list);
	return device;
}

/*----------------------------------------------------------------------------*/
void *LoadMRConfig(void *ref, char *UDN, tMRConfig *Conf, sq_dev_param_t *sq_conf)
{
	IXML_NodeList *node_list;
	IXML_Document *doc = (IXML_Document*) ref;
	IXML_Node *node;
	char *n, *v;
	unsigned i;

	node = (IXML_Node*) FindMRConfig(doc, UDN);
	if (node) {
		node_list = ixmlNode_getChildNodes(node);
		for (i = 0; i < ixmlNodeList_length(node_list); i++) {
			IXML_Node *l1_node, *l1_1_node;
			l1_node = ixmlNodeList_item(node_list, i);
Example #21
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);
Example #22
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;
}
Example #23
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 );
}
Example #24
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 );
    }
}
Example #25
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;
}
Example #26
0
/********************************************************************************
 * SampleUtil_FindAndParseService
 *
 * Description: 
 *       This routine finds the first occurance of a service in a DOM representation
 *       of a description document and parses it.  
 *
 * Parameters:
 *   DescDoc -- The DOM description document
 *   location -- The location of the description document
 *   serviceSearchType -- The type of service to search for
 *   serviceId -- OUT -- The service ID
 *   eventURL -- OUT -- The event URL for the service
 *   controlURL -- OUT -- The control URL for the service
 *
 ********************************************************************************/
int
SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
                                IN char *location,
                                IN char *serviceType,
                                OUT char **serviceId,
                                OUT char **eventURL,
                                OUT char **controlURL )
{
    int i,
      length,
      found = 0;
    int ret;
    char *tempServiceType = NULL;
    char *baseURL = NULL;
    char *base;
    char *relcontrolURL = NULL,
     *releventURL = NULL;
    IXML_NodeList *serviceList = NULL;
    IXML_Element *service = NULL;

    baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" );

    if( baseURL )
        base = baseURL;
    else
        base = location;

    serviceList = SampleUtil_GetFirstServiceList( DescDoc );
    length = ixmlNodeList_length( serviceList );
    for( i = 0; i < length; i++ ) {
        service = ( IXML_Element * ) ixmlNodeList_item( serviceList, i );
        tempServiceType =
            SampleUtil_GetFirstElementItem( ( IXML_Element * ) service,
                                            "serviceType" );

        if( strcmp( tempServiceType, serviceType ) == 0 ) {
            SampleUtil_Print( "Found service: %s\n", serviceType );
            *serviceId =
                SampleUtil_GetFirstElementItem( service, "serviceId" );
            SampleUtil_Print( "serviceId: %s\n", ( *serviceId ) );
            relcontrolURL =
                SampleUtil_GetFirstElementItem( service, "controlURL" );
            releventURL =
                SampleUtil_GetFirstElementItem( service, "eventSubURL" );

            *controlURL =
                malloc( strlen( base ) + strlen( relcontrolURL ) + 1 );
            if( *controlURL ) {
                ret = UpnpResolveURL( base, relcontrolURL, *controlURL );
                if( ret != UPNP_E_SUCCESS )
                    SampleUtil_Print
                        ( "Error generating controlURL from %s + %s\n",
                          base, relcontrolURL );
            }

            *eventURL =
                malloc( strlen( base ) + strlen( releventURL ) + 1 );
            if( *eventURL ) {
                ret = UpnpResolveURL( base, releventURL, *eventURL );
                if( ret != UPNP_E_SUCCESS )
                    SampleUtil_Print
                        ( "Error generating eventURL from %s + %s\n", base,
                          releventURL );
            }

            if( relcontrolURL )
                free( relcontrolURL );
            if( releventURL )
                free( releventURL );
            relcontrolURL = releventURL = NULL;

            found = 1;
            break;
        }

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

    if( tempServiceType )
        free( tempServiceType );
    if( serviceList )
        ixmlNodeList_free( serviceList );
    if( baseURL )
        free( baseURL );

    return ( found );
}
Example #27
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;

}
Example #28
0
unsigned long rtpxmlNodeList_length(RTPXML_NodeList *nList)
{
	return ixmlNodeList_length(nList);
}
Example #29
0
/**************************************************************************
* 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;
}
Example #30
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;
}