static int s_CD_GetBestRes (char *dms_ip, char *metadata, IXML_Node **best_res) { int ret = -1; if(!dms_ip || !metadata || !best_res) return -2; IXML_Document *subdoc = ixmlParseBuffer (discard_const_p (char, metadata)); if(subdoc) { IXML_NodeList* items = ixmlDocument_getElementsByTagName (subdoc, "item"); if(items) { IXML_Node* node = ixmlNodeList_item(items, 0); if(node) { IXML_NodeList* reslist = ixmlElement_getElementsByTagName ((IXML_Element*)node, "res"); if(reslist) { IXML_Node* res = s_CD_GetWantedRes(dms_ip, reslist, "http-get","null"); if(res) { *best_res = ixmlNode_cloneNode(res, true); ret = 0; } ixmlNodeList_free (reslist); } } ixmlNodeList_free (items); } ixmlDocument_free(subdoc); } return ret; }
char *upnp_igd_get_first_element_item(upnp_igd_context *igd_ctxt,IXML_Element *element, const char *item) { IXML_NodeList *nodeList = NULL; IXML_Node *textNode = NULL; IXML_Node *tmpNode = NULL; char *ret = NULL; nodeList = ixmlElement_getElementsByTagName(element, (char *)item); if (nodeList == NULL) { upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error finding %s in XML Node", __FILE__, __LINE__, item); return NULL; } tmpNode = ixmlNodeList_item(nodeList, 0); if (!tmpNode) { upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error finding %s value in XML Node", __FILE__, __LINE__, item); ixmlNodeList_free(nodeList); return NULL; } textNode = ixmlNode_getFirstChild(tmpNode); ret = strdup(ixmlNode_getNodeValue(textNode)); if (!ret) { upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "%s(%d): Error allocating memory for %s in XML Node", __FILE__, __LINE__, item); ixmlNodeList_free(nodeList); return NULL; } ixmlNodeList_free(nodeList); return ret; }
char *SampleUtil_GetFirstElementItem(IXML_Element *element, const char *item) { IXML_NodeList *nodeList = NULL; IXML_Node *textNode = NULL; IXML_Node *tmpNode = NULL; char *ret = NULL; nodeList = ixmlElement_getElementsByTagName(element, (char *)item); if (nodeList == NULL) { SampleUtil_Print("%s(%d): Error finding %s in XML Node\n", __FILE__, __LINE__, item); return NULL; } tmpNode = ixmlNodeList_item(nodeList, 0); if (!tmpNode) { SampleUtil_Print("%s(%d): Error finding %s value in XML Node\n", __FILE__, __LINE__, item); ixmlNodeList_free(nodeList); return NULL; } textNode = ixmlNode_getFirstChild(tmpNode); ret = strdup(ixmlNode_getNodeValue(textNode)); if (!ret) { SampleUtil_Print("%s(%d): Error allocating memory for %s in XML Node\n", __FILE__, __LINE__, item); ixmlNodeList_free(nodeList); return NULL; } ixmlNodeList_free(nodeList); return ret; }
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; }
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); }
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); } }
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; }
/* * 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; }
/******************************************************************************** * 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; }
BOOL CVCAMetaParserIXML::ParseCE( ) { IXML_NodeList *pNodeList = NULL, *pCENodeList = NULL; IXML_Node *pCENode = NULL, *pNode = NULL; ULONG ulVal = 0; USHORT usVal = 0; pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, _XML_COUNTEVENTS); if( pNodeList ) { pCENode = pNodeList->nodeItem; // There are some event specified in this packet... take a look... memset(&m_vcaCountLineEvents, 0, sizeof(m_vcaCountLineEvents)); pCENodeList = ixmlElement_getElementsByTagName((IXML_Element*)pCENode, _XML_CE); if( pCENodeList ) { pNode = pCENodeList->nodeItem; while(pNode) { VCA5_COUNTLINE_EVENT clEvent; memset( &clEvent, 0, sizeof( VCA5_COUNTLINE_EVENT ) ); ulVal = (ULONG)GetNodeValueInt(pNode, _XML_ID); if(ulVal != -1) clEvent.uiId = ulVal; usVal = (USHORT)GetNodeValueInt(pNode, _XML_P); if(usVal != -1) clEvent.usPos = usVal; usVal = (USHORT)GetNodeValueInt(pNode, _XML_W); if(usVal != -1) clEvent.usWidth = usVal; usVal = (USHORT)GetNodeValueInt(pNode, _XML_N); if(usVal != -1) clEvent.usNum = usVal; m_vcaCountLineEvents.CountLineEvents[m_vcaCountLineEvents.ulTotalCountLineEvents] = clEvent; m_vcaCountLineEvents.ulTotalCountLineEvents++; pNode = pNode->nextSibling; } ixmlNodeList_free(pCENodeList); } ixmlNodeList_free(pNodeList); } return TRUE; }
BOOL GetMultipleNodeValueString(IXML_Node *pNode, char *pszName, char (*arrOutStr)[VCA5_APP_MAX_STR_LEN]) { BOOL ret = FALSE; IXML_NodeList *pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pNode, pszName); if( pTmpNodeList ) { IXML_Node *pTmpNode = pTmpNodeList->nodeItem; IXML_Node *child = ixmlNode_getFirstChild( pTmpNode ); char *pszNodeValue = ixmlNode_getNodeValue( child ); switch ( ixmlNode_getNodeType( child ) ) { case eTEXT_NODE: strcpy(arrOutStr[0], pszNodeValue); ret = TRUE; break; case eELEMENT_NODE: // while() { // } // break; default: break; } ixmlNodeList_free(pTmpNodeList); } return ret; }
char *ReadElement(const char *Path,const char *NodeElement) { char *Val = NULL; IXML_Document *doc = NULL; IXML_NodeList *node = NULL; IXML_Node *NodePtr = NULL; if(ixmlLoadDocumentEx(Path, &doc) == IXML_INVALID_PARAMETER) goto EXIT_THIS; node = ixmlDocument_getElementsByTagName(doc, NodeElement); if (node) { if (NodePtr = ixmlNodeList_item(node, 0)) { NodePtr = ixmlNode_getFirstChild(NodePtr); if(!NodePtr) { Val = (NULL); } Val = NodePtr->nodeValue;//strdup(NodePtr->nodeValue); if(!Val) { Val = (NULL); } } } if (node) ixmlNodeList_free(node); ixmlDocument_free(doc); EXIT_THIS: return Val; }
/**************************************************************************** * Function : check_soap_body * * Parameters : * IN IXML_Document *doc : soap body xml document * IN const char *urn : * IN const char *actionName : Name of the requested action * * Description : This function checks the soap body xml came in the * SOAP request. * * Return : int * UPNP_E_SUCCESS if successful else returns appropriate error * * Note : ****************************************************************************/ static int check_soap_body( IN IXML_Document * doc, IN const char *urn, IN const char *actionName ) { IXML_NodeList *nl = NULL; IXML_Node *bodyNode = NULL; IXML_Node *actionNode = NULL; const DOMString ns = NULL; const DOMString name = NULL; int ret_code = UPNP_E_INVALID_ACTION; nl = ixmlDocument_getElementsByTagNameNS( doc, SOAP_URN, SOAP_BODY ); if( nl ) { bodyNode = ixmlNodeList_item( nl, 0 ); if( bodyNode ) { actionNode = ixmlNode_getFirstChild( bodyNode ); if( actionNode ) { ns = ixmlNode_getNamespaceURI( actionNode ); name = ixmlNode_getLocalName( actionNode ); if (name && ns && !strcmp( actionName, name ) && !strcmp( urn, ns ) ) { ret_code = UPNP_E_SUCCESS; } } } ixmlNodeList_free( nl ); } return ret_code; }
BOOL CVCAMetaParserIXML::ParseTrail( IXML_NodeList *pTrailNodeList, VCA5_TRAIL *pTrail ) { USHORT usVal = 0; IXML_Node *pTrailNode = pTrailNodeList->nodeItem; IXML_NodeList *pPtNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pTrailNode, _XML_PT); if( pPtNodeList ) { IXML_Node *pPtNode = pPtNodeList->nodeItem; pTrail->usNumTrailPoints = 0; while(pPtNode) { VCA5_POINT vcaPoint; memset( &vcaPoint, 0, sizeof( vcaPoint ) ); usVal = (USHORT)GetNodeValueInt(pPtNode, _XML_X); if(usVal != -1) vcaPoint.x = usVal; usVal = (USHORT)GetNodeValueInt(pPtNode, _XML_Y); if(usVal != -1) vcaPoint.y = usVal; pTrail->trailPoints[pTrail->usNumTrailPoints] = vcaPoint; pTrail->usNumTrailPoints++; pPtNode = pPtNode->nextSibling; } ixmlNodeList_free(pPtNodeList); } return TRUE; }
/******************************************************************************** * 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; }
/*! * \brief Separates the action node from the root DOM node. * * \return 0 if successful, or -1 if fails. */ static UPNP_INLINE int get_action_node( /*! [in] The root DOM node. */ IXML_Document *TempDoc, /*! [in] IXML_Node name to be searched. */ char *NodeName, /*! [out] Response/Output node. */ IXML_Document **RespNode) { IXML_Node *EnvpNode = NULL; IXML_Node *BodyNode = NULL; IXML_Node *ActNode = NULL; DOMString ActNodeName = NULL; const DOMString nodeName; int ret_code = -1; /* error, by default */ IXML_NodeList *nl = NULL; UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__, "get_action_node(): node name =%s\n ", NodeName); *RespNode = NULL; /* Got the Envelope node here */ EnvpNode = ixmlNode_getFirstChild((IXML_Node *) TempDoc); if (!EnvpNode) goto error_handler; nl = ixmlElement_getElementsByTagNameNS((IXML_Element *)EnvpNode, "*", "Body"); if (!nl) goto error_handler; BodyNode = ixmlNodeList_item(nl, 0); if (!BodyNode) goto error_handler; /* Got action node here */ ActNode = ixmlNode_getFirstChild(BodyNode); if (!ActNode) goto error_handler; /* Test whether this is the action node */ nodeName = ixmlNode_getNodeName(ActNode); if (!nodeName) goto error_handler; if (!strstr(nodeName, NodeName)) goto error_handler; else { ActNodeName = ixmlPrintNode(ActNode); if (!ActNodeName) goto error_handler; ret_code = ixmlParseBufferEx(ActNodeName, RespNode); if (ret_code != IXML_SUCCESS) { ixmlFreeDOMString(ActNodeName); ret_code = -1; goto error_handler; } } /* success */ ret_code = 0; error_handler: ixmlFreeDOMString(ActNodeName); if (nl) ixmlNodeList_free(nl); return ret_code; }
/******************************************************************************** * 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; }
BOOL GetMultipleNodeValueInt(IXML_Node *pNode, char *pszName, int *arrOutint) { BOOL ret = FALSE; IXML_NodeList *pTmpNodeList = ixmlElement_getElementsByTagName((IXML_Element*)pNode, pszName); if( pTmpNodeList ) { IXML_Node *pTmpNode = pTmpNodeList->nodeItem; IXML_Node *child = ixmlNode_getFirstChild( pTmpNode ); char *pszNodeValue = ixmlNode_getNodeValue( child ); switch ( ixmlNode_getNodeType( child ) ) { case eTEXT_NODE: arrOutint[0] = atoi(pszNodeValue); ret = TRUE; break; case eELEMENT_NODE: // while() { // } // break; default: break; } ixmlNodeList_free(pTmpNodeList); } return ret; }
// Extracts the result document from a SOAP response IXML_Document* parseBrowseResult( IXML_Document* doc ) { ixmlRelaxParser(1); if ( !doc ) return 0; IXML_NodeList* resultList = ixmlDocument_getElementsByTagName( doc, "Result" ); if ( !resultList ) return 0; IXML_Node* resultNode = ixmlNodeList_item( resultList, 0 ); ixmlNodeList_free( resultList ); if ( !resultNode ) return 0; IXML_Node* textNode = ixmlNode_getFirstChild( resultNode ); if ( !textNode ) return 0; const char* resultString = ixmlNode_getNodeValue( textNode ); char* resultXML = strdup( resultString ); IXML_Document* browseDoc = ixmlParseBuffer( resultXML ); free( resultXML ); return browseDoc; }
/*================================================================ * ixmlNode_getChildNodes * Returns a IXML_NodeList of all the child nodes of nodeptr. * External function. * *=================================================================*/ IXML_NodeList * ixmlNode_getChildNodes( IN IXML_Node * nodeptr ) { IXML_Node *tempNode; IXML_NodeList *newNodeList; int rc; if( nodeptr == NULL ) { return NULL; } newNodeList = ( IXML_NodeList * ) ixml_malloc( sizeof( IXML_NodeList ) ); if( newNodeList == NULL ) { return NULL; } ixmlNodeList_init( newNodeList ); tempNode = nodeptr->firstChild; while( tempNode != NULL ) { rc = ixmlNodeList_addToNodeList( &newNodeList, tempNode ); if( rc != IXML_SUCCESS ) { ixmlNodeList_free( newNodeList ); return NULL; } tempNode = tempNode->nextSibling; } return newNodeList; }
/* * Extracts the result document from a SOAP response */ IXML_Document* parseBrowseResult( IXML_Document* p_doc ) { ixmlRelaxParser( 1 ); if ( !p_doc ) return 0; IXML_NodeList* p_result_list = ixmlDocument_getElementsByTagName( p_doc, "Result" ); if ( !p_result_list ) return 0; IXML_Node* p_result_node = ixmlNodeList_item( p_result_list, 0 ); ixmlNodeList_free( p_result_list ); if ( !p_result_node ) return 0; IXML_Node* p_text_node = ixmlNode_getFirstChild( p_result_node ); if ( !p_text_node ) return 0; const char* psz_result_string = ixmlNode_getNodeValue( p_text_node ); IXML_Document* p_browse_doc = ixmlParseBuffer( psz_result_string ); return p_browse_doc; }
/************************************************************************ * 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, ¤tUDN ) ) && ( 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; }
BOOL CVCAMetaParserIXML::ParseStab() { IXML_NodeList *pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, _XML_STAB); if( pNodeList ) { IXML_Node *pNode = pNodeList->nodeItem; IXML_NodeList *pShiftNodeList = ixmlElement_getElementsByTagName ((IXML_Element*)pNode, _XML_SHIFT); if( pShiftNodeList ) { m_vcaStab.iShiftX = (ULONG)GetNodeValueIntFromNodelist(pNodeList, _XML_X); m_vcaStab.iShiftY = (ULONG)GetNodeValueIntFromNodelist(pNodeList, _XML_Y); ixmlNodeList_free(pShiftNodeList); } ixmlNodeList_free(pNodeList); } return TRUE; }
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);
BOOL CVCAMetaParserIXML::ParseHeader( ) { IXML_NodeList *pNodeList = ixmlDocument_getElementsByTagName(m_pDOMDoc, _XML_VCA_HDR); if( pNodeList ) { m_vcaHdr.ulVCAStatus = (ULONG)GetNodeValueIntFromNodelist(pNodeList, _XML_VCA_STATUS); m_vcaHdr.ulFrameId = (ULONG)GetNodeValueIntFromNodelist(pNodeList, _XML_FRAME_ID); ixmlNodeList_free(pNodeList); } return TRUE; }
/******************************************************************************** * 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); }
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); }
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; }
/* * Extracts the result document from a SOAP response */ IXML_Document* parseBrowseResult( IXML_Document* p_doc ) { assert( p_doc ); // ixml*_getElementsByTagName will ultimately only case the pointer to a Node // pointer, and pass it to a private function. Don't bother have a IXML_Document // version of getChildElementValue const char* psz_raw_didl = xml_getChildElementValue( (IXML_Element*)p_doc, "Result" ); if( !psz_raw_didl ) return NULL; /* First, try parsing the buffer as is */ IXML_Document* p_result_doc = ixmlParseBuffer( psz_raw_didl ); if( !p_result_doc ) { /* Missing namespaces confuse the ixml parser. This is a very ugly * hack but it is needeed until devices start sending valid XML. * * It works that way: * * The DIDL document is extracted from the Result tag, then wrapped into * a valid XML header and a new root tag which contains missing namespace * definitions so the ixml parser understands it. * * If you know of a better workaround, please oh please fix it */ const char* psz_xml_result_fmt = "<?xml version=\"1.0\" ?>" "<Result xmlns:sec=\"urn:samsung:metadata:2009\">%s</Result>"; char* psz_xml_result_string = NULL; if( -1 == asprintf( &psz_xml_result_string, psz_xml_result_fmt, psz_raw_didl) ) return NULL; p_result_doc = ixmlParseBuffer( psz_xml_result_string ); free( psz_xml_result_string ); } if( !p_result_doc ) return NULL; IXML_NodeList *p_elems = ixmlDocument_getElementsByTagName( p_result_doc, "DIDL-Lite" ); IXML_Node *p_node = ixmlNodeList_item( p_elems, 0 ); ixmlNodeList_free( p_elems ); return (IXML_Document*)p_node; }