/** * Checks the node to comply with storage standards. * @todo Check that all objects in the input document have required attributes * and correct URI's. * * @param node Node to check * @param checkPrefix If @a TRUE than all nodes with absolute URIs will be also * checked to have /obix prefix. * @return @a href attribute of the parent node, or @a NULL if check fails. */ static const char* checkNode(IXML_Node* node, BOOL checkPrefix) { // so far it only checks the href attribute from of the parent object :) IXML_Element* element = ixmlNode_convertToElement(node); if (element == NULL) { log_warning("Input document has wrong format."); return NULL; } const char* href = ixmlElement_getAttribute(element, OBIX_ATTR_HREF); if (href == NULL) { log_warning("Unable to write to the storage: " "No \'href\' attribute found."); return NULL; } if (*href != '/') { log_warning("Unable to write to the storage: " "\'href\' attribute should have absolute URI (without " "server address)."); return NULL; } if (checkPrefix) { insertDefaultUriPrefix(node); } // the href could be changed so we need to get it once more return ixmlElement_getAttribute(element, OBIX_ATTR_HREF); }
int YX_CD_GetBestMediaInfo(char *dms_ip, char *metadata, t_MEDIA_INFO *minfo) { char *dup_protocol, *transport, *mimetype, *dlna; IXML_Node *node=NULL; int ret = -1; if(!dms_ip || !metadata || !minfo) return -2; ret = s_CD_GetBestRes(dms_ip, metadata, &node); if(node) { IXML_Element*element = (IXML_Element*)node; const char* protocol = ixmlElement_getAttribute (element, "protocolInfo"); const char* uri = XMLUtil_GetElementValue (element); if (uri && protocol && s_YX_CD_CheckInfo(protocol, &dup_protocol, &transport, &mimetype, &dlna)) { s_CD_CreateMediaInfo(mimetype, element, dlna, minfo); free(dup_protocol); ret = 0; } ixmlNode_free(node); } return ret; }
// Extract attribute from URI_METADATA const char *transport_get_attr_metadata(const char *key) { IXML_Document *doc; IXML_Element *elm; const char *attr = NULL; const char *metadata = transport_get_var(TRANSPORT_VAR_AV_URI_META); if (!metadata || (strcmp(metadata, "") == 0)) return NULL; doc = ixmlParseBuffer(metadata); if (doc) { // Locate 'res' element elm = ixmlDocument_getElementById(doc, "res"); if (elm != NULL) { // Look for 'key' attribute in 'res' element attr = ixmlElement_getAttribute(elm, key); // Copy of result (caller must free) if (attr) attr = strdup(attr); } // Free the whole DOM ixmlDocument_free(doc); } DBG_PRINT(DBG_LVL1, "Track metadata: %s = %s\n", key, (attr) ? attr : "<not found>"); // NULL if not found return attr; }
int s_YX_CD_GetMinfoByUri (char *uri, IXML_NodeList *reslist, int len, char **protocolInfo, t_MEDIA_INFO *mInfo) { char *transport, *mimetype, *dlna; int i; 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* url = XMLUtil_GetElementValue (element); if (uri == NULL || protocol == NULL || !s_YX_CD_CheckInfo(protocol, &dup_protocol, &transport, &mimetype, &dlna)) continue; if( strcmp(uri, url) == 0 ) { s_CD_CreateMediaInfo(mimetype, element, dlna, mInfo); if(protocolInfo) *protocolInfo = Dlna_strdup(protocol); HT_DBG_FUNC_END(i, 0); return i; } } HT_DBG_FUNC_END(-1, 0); return -1; }
int YX_CD_GetPreferred (pClassContentDirectory me, IXML_NodeList *reslist, int len, char **protocolInfo, char **url, t_MEDIA_INFO *mInfo) { char *dup_protocol, *transport, *mimetype, *dlna; int i; HT_DBG_FUNC_START(HT_MOD_DMC, HT_BIT_MYRIAD,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); // if (uri == NULL || protocol == NULL ||sscanf (protocol, "http-get:*:%63[^:]", mimetype) != 1) HT_DBG_FUNC(i, protocol); if (uri == NULL || protocol == NULL || !s_YX_CD_CheckInfo(protocol, &dup_protocol, &transport, &mimetype, &dlna)) continue; if( strstr(transport, "http-get") ) { if( s_YX_CD_IpMatched(me,uri )) { t_MEDIA_INFO info; s_CD_CreateMediaInfo(mimetype, element, dlna, &info); if( info.dlnaCI == 0 ) //raw media file { if(protocolInfo) { *protocolInfo = Dlna_strdup(protocol); } if(url) { *url = Dlna_strdup(uri); } if(mInfo) memcpy(mInfo, &info, sizeof(t_MEDIA_INFO)); HT_DBG_FUNC_END(i, 0); free(dup_protocol); return i; } } } else { } free(dup_protocol); } return -1; }
/* * Returns the value of a child element's attribute, or NULL on error */ const char* xml_getChildElementAttributeValue( IXML_Element* p_parent, const char* psz_tag_name_, const char* psz_attribute_ ) { if ( !p_parent ) return NULL; if ( !psz_tag_name_ ) return NULL; if ( !psz_attribute_ ) return NULL; IXML_NodeList* p_node_list = ixmlElement_getElementsByTagName( p_parent, psz_tag_name_ ); if ( !p_node_list ) return NULL; IXML_Node* p_element = ixmlNodeList_item( p_node_list, 0 ); ixmlNodeList_free( p_node_list ); if ( !p_element ) return NULL; return ixmlElement_getAttribute( (IXML_Element*) p_element, psz_attribute_ ); }
char *YX_CD_GetThumbnailForImage (pClassContentDirectory me, IXML_NodeList *reslist, int len, int max_w, int max_h) { char *dup_protocol, *transport, *mimetype, *dlna; int i, index=-1; 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); // if (uri == NULL || protocol == NULL ||sscanf (protocol, "http-get:*:%63[^:]", mimetype) != 1) if (uri == NULL || protocol == NULL || !s_YX_CD_CheckInfo(protocol, &dup_protocol, &transport, &mimetype, &dlna)) continue; if( strstr(transport, "http-get") ) { if( s_YX_CD_IpMatched(me,uri )) { t_MEDIA_INFO info; s_CD_CreateMediaInfo(mimetype, element, dlna, &info); int w = info.resWidth; int h = info.resHeight; if( w>0 && w<max_w && h>0 && h<max_h ) { max_w = w; max_h = h; index = i; } } } free(dup_protocol); } if( index != -1 ) { HT_DBG_FUNC(index, NULL); return Dlna_strdup( XMLUtil_GetElementValue( (IXML_Element*)(ixmlNodeList_item (reslist, index)) ) ); } return NULL; }
char *YX_CD_GetThumbnailForVideo (pClassContentDirectory me, IXML_NodeList *reslist, int len) { char *dup_protocol, *transport, *mimetype, *dlna; int i; 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); // if (uri == NULL || protocol == NULL ||sscanf (protocol, "http-get:*:%63[^:]", mimetype) != 1) if (uri == NULL || protocol == NULL || !s_YX_CD_CheckInfo(protocol, &dup_protocol, &transport, &mimetype, &dlna)) continue; if( strstr(transport, "http-get") ) { if( s_YX_CD_IpMatched(me,uri )) { t_MEDIA_INFO info; s_CD_CreateMediaInfo(mimetype, element, dlna, &info); //if( strcmp(info.majorType, "image") ==0 ) if( info.majorType == 3 ) { HT_DBG_FUNC(0, uri); free(dup_protocol); return Dlna_strdup(uri); } } } free(dup_protocol); } return NULL; }
/** * Checks for all href attributes in the provided piece of XML and inserts * @a /obix prefix if necessary to all URI's which are absolute. */ static void insertDefaultUriPrefix(IXML_Node* node) { if (node == NULL) return; // exit point for the recursion // if this node is element and has 'href' attribute than check it: IXML_Element* element = ixmlNode_convertToElement(node); if (element != NULL) { const char* href = ixmlElement_getAttribute(element, OBIX_ATTR_HREF); if ((href != NULL) && (*href == '/')) { // href attribute points to the server root // check whether it starts with /obix/ if (strncmp(href, DEFAULT_URI_PREFIX, DEFAULT_URI_PREFIX_LENGTH) != 0) { // let's add /obix prefix char newHref[strlen(href) + DEFAULT_URI_PREFIX_LENGTH + 1]; strcpy(newHref, DEFAULT_URI_PREFIX); strcpy(newHref + DEFAULT_URI_PREFIX_LENGTH, href); int error = ixmlElement_setAttribute(element, OBIX_ATTR_HREF, newHref); if (error != IXML_SUCCESS) { log_warning("Unable to update \"%s\" attribute of the object " "before storing it: ixmlElement_setAttribute " "returned %d.", OBIX_ATTR_HREF, error); } } } } // search also in child and neighbor tags insertDefaultUriPrefix(ixmlNode_getFirstChild(node)); insertDefaultUriPrefix(ixmlNode_getNextSibling(node)); }
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; }
bool MediaServer::addContainer( IXML_Element* containerElement ) { char* psz_url; const char* objectID = ixmlElement_getAttribute( containerElement, "id" ); if ( !objectID ) return false; const char* title = xml_getChildElementValue( containerElement, "dc:title" ); if ( !title ) return false; if( asprintf( &psz_url, "upnp://%s?ObjectID=%s", m_psz_root, objectID ) < 0 ) return false; input_item_t* p_item = input_item_NewDirectory( psz_url, title, ITEM_NET ); free( psz_url); if ( !p_item ) return false; input_item_CopyOptions( p_item, m_node->p_item ); input_item_node_AppendItem( m_node, p_item ); input_item_Release( p_item ); return true; }
void processInsertEncode(IXML_Document * persXmlDoc,U32 * InserID) { int i, numPending; IXML_NodeList *nodeList; char *xmlBuff; char * xmlBuff2; IXML_Node *node; U32 tempId; char persFile[128]; INSERT_PENDING sInsertP;/* for InsertPending table */ ENC_PENDING sEncodeP; U32 affectedDiscId = 0; U32 prevDiscId; int b_updated = 0; sprintf(persFile, ZRIP_OLD_TASKFILE); /* first test if have rip interupt */ if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "WavPending")) != NULL){ if ((numPending = ixmlNodeList_length(nodeList)) != 0){ if (numPending != 1){ goto funcOut; } if ((node = ixmlNodeList_item(nodeList, 0)) != NULL){ if ((xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId")) != NULL){ sscanf(xmlBuff,"%x",&affectedDiscId); xmlBuff2=ixmlElement_getAttribute((IXML_Element *)node, TOTAL_FRMTAG); if(xmlBuff2) { sInsertP.uCDID = affectedDiscId; sInsertP.ptrFrames = strdup(xmlBuff2); InsertPendingTask(INSERTPENDING, &sInsertP); ZFREE(sInsertP.ptrFrames); /* Insert in to database */ } if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){ ZError(DBG_ZRIP, "Failed to remove <WavPending>"); } else{ b_updated = 1; } } } } ixmlNodeList_free(nodeList); } /* second test if have EncPending */ if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "EncPending")) == NULL){ goto funcOut; } if ((numPending = ixmlNodeList_length(nodeList)) == 0){ ixmlNodeList_free(nodeList); goto funcOut; } prevDiscId = 0; node = NULL; for (i = 0; i < numPending; i++){ if ((node = ixmlNodeList_item(nodeList, i)) == NULL){ continue; } xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId"); if (!xmlBuff){ continue; } sscanf(xmlBuff,"%x",&tempId); if (affectedDiscId == tempId){ continue; } /* getAudioFormat */ xmlBuff = NULL; xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "AudioFormat"); if (!xmlBuff){ continue; } else{ sEncodeP.ptrAudioFormat = strdup(xmlBuff); } if(strncasecmp(xmlBuff, AUDIO_MP3_TYPE, 3) == 0) { sEncodeP.ptrFormatCfg = strdup("128"); } else sEncodeP.ptrFormatCfg = strdup("0"); /* getpbject */ xmlBuff = NULL; xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "objid"); if (!xmlBuff){ ZFREE(sEncodeP.ptrAudioFormat); ZFREE(sEncodeP.ptrFormatCfg); continue; } else{ sEncodeP.objID = strdup(xmlBuff); } InsertPendingTask(ENCPENDING,&sEncodeP); ZFREE(sEncodeP.ptrAudioFormat); ZFREE(sEncodeP.ptrFormatCfg); ZFREE(sEncodeP.objID); /* insert database */ } for (i = 0; i < numPending; i++){ if ((node = ixmlNodeList_item(nodeList, i)) == NULL){ continue; } if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){ ZError(DBG_ZRIP, "Failed to remove <WavPending>"); } } /* remove all child */ b_updated = 1; ixmlNodeList_free(nodeList); funcOut: if ( affectedDiscId){ /* delete no use */ *InserID = affectedDiscId; } if ( b_updated && ixmlUpdateDocument(persXmlDoc, persFile) == -1){ dprintf("Unable to write file path->%s", persFile); } return; }
void processCDDBUp(IXML_Document * persXmlDoc,U32 InserID) { IXML_NodeList *nodeList = NULL; IXML_Node *node; int i; int numPending; char *xmlBuff; char * xmlBuff2=NULL; char tempStr[1024]; int bUpdated = 0; CDDB_PENDING sCddbP; sprintf(tempStr,ZRIP_OLD_TASKFILE); if ((nodeList = ixmlDocument_getElementsByTagName(persXmlDoc, "CDDBPending")) == NULL) { dprintf( "Can't find <CDDBPending> node in the %s file", tempStr); goto funcOut; } if ((numPending = ixmlNodeList_length(nodeList)) == 0) { dprintf( "Can't find any <CDDBPending> nodes in the %s file", tempStr); goto funcOut; } for (i = 0; i < numPending; i++) { if ((node = ixmlNodeList_item(nodeList, i)) == NULL) { continue; } xmlBuff = ixmlElement_getAttribute((IXML_Element *)node, "discId"); if (!xmlBuff) continue; sscanf(xmlBuff,"%x",&sCddbP.uCDID); if(sCddbP.uCDID == InserID) continue; xmlBuff = ixmlGetFirstElementItem( (IXML_Element *)node, "playsecs" ); if ( xmlBuff == NULL ) { continue; } else { sCddbP.nPlaySecs = atoi(xmlBuff); } xmlBuff = ixmlGetFirstElementItem( (IXML_Element *)node, "tracks" ); if ( xmlBuff == NULL ) { continue; } else { sCddbP.uTotalTracks = atoi(xmlBuff); } xmlBuff2=ixmlGetFirstElementItem( (IXML_Element *)node, "frames" ); if ( !xmlBuff2) continue; else{ sCddbP.ptrFrames = strdup(xmlBuff2); ZFREE(xmlBuff2); } /* insert into database and free the memory */ InsertPendingTask(CDDBPENDING,&sCddbP); ZFREE(sCddbP.ptrFrames); } /* free the xml */ for (i = 0; i < numPending; i++) { if ((node = ixmlNodeList_item(nodeList, i)) == NULL) { continue; } if (ixmlNode_removeChild(ixmlNode_getParentNode(node), node, NULL) != IXML_SUCCESS){ dprintf("Failed to remove <cddbPending>"); } } bUpdated = 1; funcOut: if ( nodeList ) ixmlNodeList_free(nodeList); if (bUpdated && ixmlUpdateDocument(persXmlDoc, tempStr) == -1) { /* free it odirect */ dprintf( "Unable to write file path->%s", tempStr); } return; }
/* * Fetches and parses the UPNP response */ bool MediaServer::_fetchContents( Container* p_parent ) { if (!p_parent) { msg_Err( _p_sd, "No parent" ); return false; } IXML_Document* p_response = _browseAction( p_parent->getObjectID(), "BrowseDirectChildren", "*", "0", "0", "" ); if ( !p_response ) { msg_Err( _p_sd, "No response from browse() action" ); return false; } IXML_Document* p_result = parseBrowseResult( p_response ); ixmlDocument_free( p_response ); if ( !p_result ) { msg_Err( _p_sd, "browse() response parsing failed" ); return false; } #ifndef NDEBUG else { msg_Dbg( _p_sd, "Got DIDL document: %s", ixmlPrintDocument( p_result ) ); } #endif IXML_NodeList* containerNodeList = ixmlDocument_getElementsByTagName( p_result, "container" ); if ( containerNodeList ) { for ( unsigned int i = 0; i < ixmlNodeList_length( containerNodeList ); i++ ) { IXML_Element* containerElement = ( IXML_Element* )ixmlNodeList_item( containerNodeList, i ); const char* objectID = ixmlElement_getAttribute( containerElement, "id" ); if ( !objectID ) continue; const char* title = xml_getChildElementValue( containerElement, "dc:title" ); if ( !title ) continue; Container* container = new Container( p_parent, objectID, title ); p_parent->addContainer( container ); _fetchContents( container ); } ixmlNodeList_free( containerNodeList ); } IXML_NodeList* itemNodeList = ixmlDocument_getElementsByTagName( p_result, "item" ); if ( itemNodeList ) { for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ ) { IXML_Element* itemElement = ( IXML_Element* )ixmlNodeList_item( itemNodeList, i ); const char* objectID = ixmlElement_getAttribute( itemElement, "id" ); if ( !objectID ) continue; const char* title = xml_getChildElementValue( itemElement, "dc:title" ); if ( !title ) continue; const char* resource = xml_getChildElementValue( itemElement, "res" ); if ( !resource ) continue; const char* psz_duration = xml_getChildElementAttributeValue( itemElement, "res", "duration" ); mtime_t i_duration = -1; int i_hours, i_minutes, i_seconds, i_decis; if ( psz_duration ) { if( sscanf( psz_duration, "%02d:%02d:%02d.%d", &i_hours, &i_minutes, &i_seconds, &i_decis )) i_duration = INT64_C(1000000) * ( i_hours*3600 + i_minutes*60 + i_seconds ) + INT64_C(100000) * i_decis; } Item* item = new Item( p_parent, objectID, title, resource, i_duration ); p_parent->addItem( item ); } ixmlNodeList_free( itemNodeList ); } ixmlDocument_free( p_result ); return true; }
int xmldb_updateDOM(IXML_Element* input, const char* href, IXML_Element** updatedNode, int* slashFlag) { const char* newValue = ixmlElement_getAttribute(input, OBIX_ATTR_VAL); if (newValue == NULL) { log_warning("Unable to update the storage: " "Input data doesn't contain \'%s\' attribute.", OBIX_ATTR_VAL); return -1; } // get the object from the storage IXML_Element* nodeInStorage = xmldb_getDOM(href, slashFlag); if (nodeInStorage == NULL) { log_warning("Unable to update the storage: " "No object with the URI \"%s\" is found.", href); return -2; } // check that the object is writable const char* writable = ixmlElement_getAttribute(nodeInStorage, OBIX_ATTR_WRITABLE); if ((writable == NULL) || (strcmp(writable, XML_TRUE) != 0)) { log_warning("Unable to update the storage: " "The object with the URI \"%s\" is not writable.", href); return -3; } // check the current value of the object in storage const char* oldValue = ixmlElement_getAttribute(nodeInStorage, OBIX_ATTR_VAL); if ((oldValue != NULL) && (strcmp(oldValue, newValue) == 0)) { // new value is the same as was in storage. // return address of the node in the storage if (updatedNode != NULL) { *updatedNode = nodeInStorage; } return 1; } // overwrite 'val' attribute int error = ixmlElement_setAttributeWithLog( nodeInStorage, OBIX_ATTR_VAL, newValue); if (error != 0) { return -4; } // return address of updated node if (updatedNode != NULL) { *updatedNode = nodeInStorage; } return 0; }
input_item_t* MediaServer::getNextItem() { input_item_t *p_item = NULL; if( !xmlDocument_ ) { fetchContents(); if( !xmlDocument_ ) return NULL; } if ( containerNodeList_ ) { for ( ; !p_item && containerNodeIndex_ < ixmlNodeList_length( containerNodeList_ ) ; containerNodeIndex_++ ) { IXML_Element* containerElement = (IXML_Element*)ixmlNodeList_item( containerNodeList_, containerNodeIndex_ ); const char* objectID = ixmlElement_getAttribute( containerElement, "id" ); if ( !objectID ) continue; const char* title = xml_getChildElementValue( containerElement, "dc:title" ); if ( !title ) continue; p_item = newItem(objectID, title); } } if( itemNodeList_ ) { for ( ; !p_item && itemNodeIndex_ < ixmlNodeList_length( itemNodeList_ ) ; itemNodeIndex_++ ) { IXML_Element* itemElement = ( IXML_Element* )ixmlNodeList_item( itemNodeList_, itemNodeIndex_ ); const char* objectID = ixmlElement_getAttribute( itemElement, "id" ); if ( !objectID ) continue; const char* title = xml_getChildElementValue( itemElement, "dc:title" ); if ( !title ) continue; const char* psz_subtitles = xml_getChildElementValue( itemElement, "sec:CaptionInfo" ); if ( !psz_subtitles ) psz_subtitles = xml_getChildElementValue( itemElement, "sec:CaptionInfoEx" ); if ( !psz_subtitles ) psz_subtitles = xml_getChildElementValue( itemElement, "pv:subtitlefile" ); /* Try to extract all resources in DIDL */ IXML_NodeList* p_resource_list = ixmlDocument_getElementsByTagName( (IXML_Document*) itemElement, "res" ); if ( p_resource_list && ixmlNodeList_length( p_resource_list ) > 0 ) { mtime_t i_duration = -1; int i_hours, i_minutes, i_seconds; IXML_Element* p_resource = ( IXML_Element* ) ixmlNodeList_item( p_resource_list, 0 ); const char* psz_resource_url = xml_getChildElementValue( p_resource, "res" ); if( !psz_resource_url ) continue; const char* psz_duration = ixmlElement_getAttribute( p_resource, "duration" ); if ( psz_duration ) { if( sscanf( psz_duration, "%d:%02d:%02d", &i_hours, &i_minutes, &i_seconds ) ) i_duration = INT64_C(1000000) * ( i_hours*3600 + i_minutes*60 + i_seconds ); } p_item = newItem( title, objectID, psz_subtitles, i_duration, psz_resource_url ); } ixmlNodeList_free( p_resource_list ); } } return p_item; }
/****************************************************************************** * DIDLObject_Create *****************************************************************************/ DIDLObject* DIDLObject_Create (void* talloc_context, IN IXML_Element* elem, IN bool is_container) { if (elem == NULL) { Log_Printf (LOG_ERROR, "DIDLObject can't create from NULL XML Element"); return NULL; // ----------> } DIDLObject* o = talloc (talloc_context, DIDLObject); if (o) { *o = (DIDLObject) { .is_container = is_container }; IXML_Node* node = NULL; /* Steal the node from its parent (instead of copying it, given * that the parent document is going to be deallocated anyway) */ ixmlNode_removeChild (ixmlNode_getParentNode (XML_E2N (elem)), XML_E2N (elem), &node); o->element = (IXML_Element*) node; // TBD need to copy ?? o->id = talloc_strdup (o, ixmlElement_getAttribute (o->element, "id")); if (o->id == NULL || o->id[0] == NUL) { char* s = DIDLObject_GetElementString (o, NULL); Log_Printf (LOG_ERROR, "DIDLObject can't create with NULL " "or empty id, XML = %s", s); talloc_free (s); talloc_free (o); return NULL; // ----------> } o->title = XMLUtil_FindFirstElementValue (node, "dc:title", false, true); if (o->title == NULL) o->title = ""; o->basename = String_CleanFileName (o, o->title); if (o->basename[0] == NUL) { char* s = DIDLObject_GetElementString (o, NULL); Log_Printf (LOG_WARNING, "DIDLObject NULL or empty <dc:title>, " "XML = %s", s); talloc_free (s); talloc_free (o->basename); o->basename = talloc_asprintf (o, "-id-%s", o->id); } else if (o->basename[0] == '.' || o->basename[0] == '_') { o->basename[0] = '-'; } o->cds_class = String_StripSpaces (o, XMLUtil_FindFirstElementValue (node, "upnp:class", false, true)); if (o->cds_class == NULL) o->cds_class = ""; char* s = ixmlElement_getAttribute (o->element, "searchable"); o->searchable = String_ToBoolean (s, false); Log_Printf (LOG_DEBUG, "new DIDLObject : %s : id='%s' " "title='%s' class='%s'", (is_container ? "container" : "item"), o->id, o->title, o->cds_class); // Register destructor talloc_set_destructor (o, DestroyObject); } return o; }
/** * Helper function for #getNodeByHref(IXML_Document*,const char*). * * @param checked specifies number of symbols from href which are already * checked (and match) in parent node. */ static IXML_Node* getNodeByHrefRecursive(IXML_Node* node, const char* href, int checked, int* slashFlag) { if (node == NULL) { //recursion exit point return NULL; } IXML_Node* match = NULL; IXML_Element* element = ixmlNode_convertToElement(node); int compareResult = 0; // ignore all nodes which are not tags, are reference tags // or do not have 'href' attribute if (element != NULL) { const char* currentUri = ixmlElement_getAttribute(element, OBIX_ATTR_HREF); if ((strcmp(ixmlElement_getTagName(element), OBIX_OBJ_REF) != 0) && (currentUri != NULL)) { compareResult = compare_uri(currentUri, href, checked, slashFlag); if (compareResult == 0) { // we found the required node return node; } } } // check children // note that compareResult == 0 means that URI's // were not compared at all if (compareResult == 0) { match = getNodeByHrefRecursive(ixmlNode_getFirstChild(node), href, checked, slashFlag); } else if (compareResult > 0) { // we found part of the uri on this step // continue search in children the remaining address match = getNodeByHrefRecursive(ixmlNode_getFirstChild(node), href, compareResult, slashFlag); } // do not check children if compareResult < 0 if (match == NULL) { match = getNodeByHrefRecursive(ixmlNode_getNextSibling(node), href, checked, slashFlag); } return match; }
int L_getAttribute(lua_State *L) { lua_pushstring(L, ixmlElement_getAttribute(checkelement(L, 1), luaL_checkstring(L,2))); return 1; }
/* * Fetches and parses the UPNP response */ bool MediaServer::_fetchContents( Container* p_parent, int i_offset ) { if (!p_parent) { msg_Err( _p_sd, "No parent" ); return false; } char* psz_starting_index; if( asprintf( &psz_starting_index, "%d", i_offset ) < 0 ) { msg_Err( _p_sd, "asprintf error:%d", i_offset ); return false; } IXML_Document* p_response = _browseAction( p_parent->getObjectID(), "BrowseDirectChildren", "*", /* Filter */ psz_starting_index, /* StartingIndex */ "0", /* RequestedCount */ "" /* SortCriteria */ ); free( psz_starting_index ); if ( !p_response ) { msg_Err( _p_sd, "No response from browse() action" ); return false; } IXML_Document* p_result = parseBrowseResult( p_response ); int i_number_returned = xml_getNumber( p_response, "NumberReturned" ); int i_total_matches = xml_getNumber( p_response , "TotalMatches" ); #ifndef NDEBUG msg_Dbg( _p_sd, "i_offset[%d]i_number_returned[%d]_total_matches[%d]\n", i_offset, i_number_returned, i_total_matches ); #endif ixmlDocument_free( p_response ); if ( !p_result ) { msg_Err( _p_sd, "browse() response parsing failed" ); return false; } #ifndef NDEBUG msg_Dbg( _p_sd, "Got DIDL document: %s", ixmlPrintDocument( p_result ) ); #endif IXML_NodeList* containerNodeList = ixmlDocument_getElementsByTagName( p_result, "container" ); if ( containerNodeList ) { for ( unsigned int i = 0; i < ixmlNodeList_length( containerNodeList ); i++ ) { IXML_Element* containerElement = ( IXML_Element* )ixmlNodeList_item( containerNodeList, i ); const char* objectID = ixmlElement_getAttribute( containerElement, "id" ); if ( !objectID ) continue; const char* title = xml_getChildElementValue( containerElement, "dc:title" ); if ( !title ) continue; Container* container = new Container( p_parent, objectID, title ); p_parent->addContainer( container ); _fetchContents( container, 0 ); } ixmlNodeList_free( containerNodeList ); } IXML_NodeList* itemNodeList = ixmlDocument_getElementsByTagName( p_result, "item" ); if ( itemNodeList ) { for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ ) { IXML_Element* itemElement = ( IXML_Element* )ixmlNodeList_item( itemNodeList, i ); const char* objectID = ixmlElement_getAttribute( itemElement, "id" ); if ( !objectID ) continue; const char* title = xml_getChildElementValue( itemElement, "dc:title" ); if ( !title ) continue; const char* resource = xml_getChildElementValue( itemElement, "res" ); if ( !resource ) continue; const char* psz_duration = xml_getChildElementAttributeValue( itemElement, "res", "duration" ); mtime_t i_duration = -1; int i_hours, i_minutes, i_seconds, i_decis; if ( psz_duration ) { if( sscanf( psz_duration, "%02d:%02d:%02d.%d", &i_hours, &i_minutes, &i_seconds, &i_decis )) i_duration = INT64_C(1000000) * ( i_hours*3600 + i_minutes*60 + i_seconds ) + INT64_C(100000) * i_decis; } Item* item = new Item( p_parent, objectID, title, resource, i_duration ); p_parent->addItem( item ); } ixmlNodeList_free( itemNodeList ); } ixmlDocument_free( p_result ); if( i_offset + i_number_returned < i_total_matches ) return _fetchContents( p_parent, i_offset + i_number_returned ); return true; }
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; }
void SetDMRState(IXML_Document *stateDoc) { char *dmrState = NULL; int idmrState = DMR_STATE_STOPPED; char *dmrPlayType = NULL; int idmrPlayType = DMR_PLAYTYPE_IDLE; char *objID = NULL; char *udn = NULL; dmrState = ixmlGetFirstDocumentItem(stateDoc, "state"); if(dmrState == NULL) { ZError(DBG_MISC, "Missing DMR state!"); goto errOut; } else if(strcmp(dmrState, "STOPPED") == 0) { idmrState = DMR_STATE_STOPPED; } else if(strcmp(dmrState, "NO_MEDIA") == 0) { idmrState = DMR_STATE_NO_MEDIA; } else if(strcmp(dmrState, "PLAYING") == 0) { idmrState = DMR_STATE_PLAYING; } else if(strcmp(dmrState, "PAUSED_PLAYBACK") == 0) { idmrState = DMR_STATE_PAUSED; } else { ZError(DBG_MISC, "Unknown DMR state! state->%s", dmrState); goto errOut; } if(idmrState == DMR_STATE_PLAYING || idmrState == DMR_STATE_PAUSED) { dmrPlayType = ixmlGetFirstDocumentItem(stateDoc, "PlayType"); if (dmrPlayType == NULL) { ZError(DBG_MISC, "Missing PlayType"); goto errOut; } else if(strcmp(dmrPlayType, "IDLE") == 0) { idmrPlayType = DMR_PLAYTYPE_IDLE; } else if(strcmp(dmrPlayType, "CD") == 0) { idmrPlayType = DMR_PLAYTYPE_CD; } else if(strcmp(dmrPlayType, "INTERNET_RADIO") == 0) { idmrPlayType = DMR_PLAYTYPE_INTERNET_RADIO; } else if(strcmp(dmrPlayType, "STREAM") == 0) { idmrPlayType = DMR_PLAYTYPE_STREAM; } else if(strcmp(dmrPlayType, "MUSIC_ITEM") == 0) { idmrPlayType = DMR_PLAYTYPE_MUSIC_ITEM; } else if(strcmp(dmrPlayType, "PLAY_QUEUE") == 0) { idmrPlayType = DMR_PLAYTYPE_PLAY_QUEUE; } else if(strcmp(dmrPlayType, "UNDEFINE") == 0) { idmrPlayType = DMR_PLAYTYPE_UNDEFINE; } else { ZError(DBG_MISC, "Unknown DMR PlayType! PlayType->%s", dmrPlayType); goto errOut; } if(idmrPlayType == DMR_PLAYTYPE_MUSIC_ITEM || idmrPlayType == DMR_PLAYTYPE_PLAY_QUEUE) { IXML_Node *objectNode = NULL; objectNode = ixmlGetFirstNodeByTagName(stateDoc, "object"); if(objectNode == NULL) { ZInfo4(DBG_MISC, "No playing object!"); goto errOut; } objID = ixmlElement_getAttribute((IXML_Element *)objectNode, "id"); udn = ixmlElement_getAttribute((IXML_Element *)objectNode, "udn"); if(objID == NULL || udn == NULL) { ZInfo4(DBG_MISC, "Wrong playing object udn![%s][%s]", objID, udn); goto errOut; } } } ZInfo4(DBG_MISC, "state: %s, playtype: %s, objid: %s, udn: %s", dmrState, dmrPlayType, objID, udn); switch (idmrState) { case DMR_STATE_STOPPED: case DMR_STATE_NO_MEDIA: SetWorkStatus(WPlayLocalDMS, WORK_STOPPED ); SetWorkStatus(WPlayExtDMS, WORK_STOPPED ); SetWorkStatus(WPlayIR, WORK_STOPPED ); SetWorkStatus(WPlayCD, WORK_STOPPED ); break; case DMR_STATE_PLAYING: case DMR_STATE_PAUSED: SetWorkStatus(WPlayLocalDMS, WORK_STOPPED ); SetWorkStatus(WPlayExtDMS, WORK_STOPPED ); SetWorkStatus(WPlayIR, WORK_STOPPED ); SetWorkStatus(WPlayCD, WORK_STOPPED ); SetSysState(DMRState, idmrState); SetSysState(DMRPlayType, idmrPlayType); switch (idmrPlayType) { case DMR_PLAYTYPE_MUSIC_ITEM: case DMR_PLAYTYPE_PLAY_QUEUE: SetCache(CACHE_PLAYINGOBJECT, objID); SetCache(CACHE_PLAYINGUDN, udn); char *localudn = UpdateLocalDMSUdn(); if (strstr(udn, localudn) != NULL) { SetWorkStatus(WPlayLocalDMS, WORK_RUNNING); } else { SetWorkStatus(WPlayExtDMS, WORK_RUNNING); } break; case DMR_PLAYTYPE_CD: SetWorkStatus(WPlayCD, WORK_RUNNING); SetCache(CACHE_PLAYINGOBJECT, NULL); SetCache(CACHE_PLAYINGUDN, NULL); break; case DMR_PLAYTYPE_INTERNET_RADIO: SetWorkStatus(WPlayIR, WORK_RUNNING); SetCache(CACHE_PLAYINGOBJECT, objID); SetCache(CACHE_PLAYINGUDN, udn); break; default: SetCache(CACHE_PLAYINGOBJECT, NULL); SetCache(CACHE_PLAYINGUDN, NULL); } } errOut: free(dmrState); free(dmrPlayType); return; }
/*-------------------------------------------------- * Function: GetDMRState * Description: * GetState from DMR and parse the result into * DMRSTATE structure. * Parameters: * NONE * Returns: *--------------------------------------------------*/ MODSTATE * GetDMRState() { //<ret op="GetState" mod=" zappdmr "> // <err>0 Means OK, else return error</err> // <msg></msg> // <state> STOPPED | PLAYING | PAUSED| NO_MEDIA </state>//If is playing/paused should include following tags // <PlayType> IDLE|CD|INTERNET_RADIO|MUSIC_ITEM|PLAY_QUEUE| UNDEFINE </PlayType> // <object id="" udn="">// id is a CDS object; udn is udn of this object //</ret> MODSTATE *modState = ModStateCreate(ZAPP_DMR); if(modState == NULL) { return NULL; } DMRSTATE *dmrState = DMRStateCreate(); modState->DetailState.dmrState = dmrState; IXML_Document *stateDoc = NULL; char *state; stateDoc = CMDGetStateDMR(); if(stateDoc == NULL) { goto errOut; } modState->err = GetErrNum(stateDoc); if(modState->err != 0) { modState->msg = ixmlGetFirstDocumentItem(stateDoc, "msg"); goto funcOut; } state = ixmlGetFirstDocumentItem(stateDoc, "state"); if(state == NULL) { goto errOut; } if(strcmp(state, "STOPPED") == 0) { modState->state = DMR_STATE_STOPPED; } else if(strcmp(state, "NO_MEDIA") == 0) { modState->state = DMR_STATE_NO_MEDIA; } else if(strcmp(state, "PLAYING") == 0) { modState->state = DMR_STATE_PLAYING; } else if(strcmp(state, "PAUSED_PLAYBACK") == 0) { modState->state = DMR_STATE_PAUSED; } else { ZError(DBG_MISC, "Unknown DMR state! state->%s", state); free(state); goto errOut; } free(state); state = NULL; if(modState->state == DMR_STATE_PLAYING || modState->state == DMR_STATE_PAUSED) { state = ixmlGetFirstDocumentItem(stateDoc, "PlayType"); if(strcmp(state, "IDLE") == 0) { dmrState->PlayType = DMR_PLAYTYPE_IDLE; } else if(strcmp(state, "CD") == 0) { dmrState->PlayType = DMR_PLAYTYPE_CD; } else if(strcmp(state, "INTERNET_RADIO") == 0) { dmrState->PlayType = DMR_PLAYTYPE_INTERNET_RADIO; } else if(strcmp(state, "STREAM") == 0) { dmrState->PlayType = DMR_PLAYTYPE_STREAM; } else if(strcmp(state, "MUSIC_ITEM") == 0) { dmrState->PlayType = DMR_PLAYTYPE_MUSIC_ITEM; } else if(strcmp(state, "PLAY_QUEUE") == 0) { dmrState->PlayType = DMR_PLAYTYPE_PLAY_QUEUE; } else if(strcmp(state, "UNDEFINE") == 0) { dmrState->PlayType = DMR_PLAYTYPE_UNDEFINE; } else { ZError(DBG_MISC, "Unknown DMR PlayType! PlayType->%s", state); free(state); goto errOut; } free(state); state = NULL; if(dmrState->PlayType == DMR_PLAYTYPE_MUSIC_ITEM || dmrState->PlayType == DMR_PLAYTYPE_PLAY_QUEUE) { IXML_Node *objectNode = NULL; objectNode = ixmlGetFirstNodeByTagName(stateDoc, "object"); if(objectNode == NULL) { ZInfo4(DBG_MISC, "No playing object!"); goto errOut; } char *temp = NULL; if((temp = ixmlElement_getAttribute((IXML_Element *)objectNode, "id")) != NULL) { dmrState->ObjectID = strdup(temp); temp = NULL; } else { ZInfo4(DBG_MISC, "No playing object id!"); goto errOut; } if((temp = ixmlElement_getAttribute((IXML_Element *)objectNode, "udn")) != NULL) { dmrState->Udn = strdup(temp); temp = NULL; } else { ZInfo4(DBG_MISC, "No playing object udn!"); goto errOut; } } } funcOut: ixmlDocument_free(stateDoc); ZInfo4(DBG_MISC, "Parse DMR state structure success"); return modState; errOut: ixmlDocument_free(stateDoc); ZError(DBG_MISC, "GetState from DMR Failed!"); ModStateFree(modState); return NULL; }
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; }
void s_CD_CreateMediaInfo(char *mimetype, IXML_Element*res, char *dlna, t_MEDIA_INFO *minfo) { const char *str = NULL; HT_DBG_FUNC_START(HT_MOD_DMC, HT_BIT_MYRIAD,0,mimetype); if(!mimetype || !minfo) return; memset(minfo, 0, sizeof(t_MEDIA_INFO)); s_CD_ParseMime(mimetype, minfo); /* attributes */ str = ixmlElement_getAttribute (res, "size"); if(str) minfo->fileSize = atoll(str); str = ixmlElement_getAttribute (res, "resolution"); if(str) sscanf ( str, "%dx%d", &(minfo->resWidth), &(minfo->resHeight) ); str = ixmlElement_getAttribute (res, "colorDepth"); if(str) minfo->colorDepth = atoi(str); str = ixmlElement_getAttribute (res, "bitrate"); if(str) minfo->bitrate = atoi(str); /* H+:MM:SS[.F+] or H+:MM:SS[.F0/F1] where: H+: one or more digits to indicate elapsed hours, MM: exactly 2 digits to indicate minutes (00 to 59), SS: exactly 2 digits to indicate seconds (00 to 59), F+: any number of digits (including no digits) to indicate fractions of seconds, F0/F1: a fraction, with F0 and F1 at least one digit long, and F0 < F1. The string MAY be preceded by a “+” or “-” sign, and the decimal point itself MUST be omitted if there are no fractional second digits. */ str = ixmlElement_getAttribute (res, "duration"); if(str) { // int hh = 0; unsigned int hh=0, mm = 0, ss = 0; if (sscanf (str, "%u:%u:%u", &hh, &mm, &ss) == 3 ) { minfo->xduration = (ss + 60*(mm + 60*hh)) * 1000; } } /* PVR sharing */ str = ixmlElement_getAttribute (res, "contentSource"); if(str) { minfo->pvr_flag = 1; minfo->pvr_contentSource = atoi(str); str = ixmlElement_getAttribute (res, "localEncrypted"); if(str) { minfo->pvr_encrypted = atoi(str); if( minfo->pvr_encrypted ) { str = ixmlElement_getAttribute (res, "localEncryptionKey"); strncpy(minfo->pvr_keys, str, sizeof(minfo->pvr_keys)-1); } } } /* DLNA specially */ if( dlna ) { if( strstr(dlna, "DLNA.ORG_CI=1") ) minfo->dlnaCI = 1; if( strstr(dlna, "DLNA.ORG_PS=") ) minfo->dlnaPS = 1; } HT_DBG_FUNC_END(minfo->pvr_encrypted, minfo->pvr_keys); }
/* Function:Prints a callback event type as a string; INPUT: S -- The callback event; SUCCESS:0; ERROR:-1; */ int PrintEvent( IN Upnp_EventType EventType, IN void *Event ) { ithread_mutex_lock( &display_mutex ); SA_Print ( "\n\n\n======================================================================\n" ); SA_Print ( "----------------------------------------------------------------------\n" ); PrintEventType( EventType ); switch ( EventType ) { /* SSDP */ case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: case UPNP_DISCOVERY_SEARCH_RESULT: { struct Upnp_Discovery *d_event = ( struct Upnp_Discovery * )Event; SA_Print( "ErrCode = %d\n", d_event->ErrCode ); SA_Print( "Expires = %d\n", d_event->Expires ); SA_Print( "DeviceId = %s\n", d_event->DeviceId ); SA_Print( "DeviceType = %s\n", d_event->DeviceType ); SA_Print( "ServiceType = %s\n", d_event->ServiceType ); SA_Print( "ServiceVer = %s\n", d_event->ServiceVer ); SA_Print( "Location = %s\n", d_event->Location ); SA_Print( "OS = %s\n", d_event->Os ); SA_Print( "Ext = %s\n", d_event->Ext ); sem_post(&ServerSem); } break; case UPNP_DISCOVERY_SEARCH_TIMEOUT: // Nothing to print out here break; /* SOAP */ case UPNP_CONTROL_ACTION_REQUEST: { struct Upnp_Action_Request *a_event = ( struct Upnp_Action_Request * )Event; char *xmlbuff = NULL; SA_Print( "ErrCode = %d\n", a_event->ErrCode ); SA_Print( "ErrStr = %s\n", a_event->ErrStr ); SA_Print( "ActionName = %s\n", a_event->ActionName ); SA_Print( "UDN = %s\n", a_event->DevUDN ); SA_Print( "ServiceID = %s\n", a_event->ServiceID ); if( a_event->ActionRequest ) { xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest ); if( xmlbuff ) SA_Print( "ActRequest = %s\n", xmlbuff ); if( xmlbuff ) ixmlFreeDOMString( xmlbuff ); xmlbuff = NULL; } else { SA_Print( "ActRequest = (null)\n" ); } if( a_event->ActionResult ) { xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult ); if( xmlbuff ) SA_Print( "ActResult = %s\n", xmlbuff ); if( xmlbuff ) ixmlFreeDOMString( xmlbuff ); xmlbuff = NULL; } else { SA_Print( "ActResult = (null)\n" ); } } break; case UPNP_CONTROL_ACTION_COMPLETE: { struct Upnp_Action_Complete *a_event = ( struct Upnp_Action_Complete * )Event; char *xmlbuff = NULL; SA_Print( "ErrCode = %d\n", a_event->ErrCode ); SA_Print( "CtrlUrl = %s\n", a_event->CtrlUrl ); if( a_event->ActionRequest ) { xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest ); if( xmlbuff ) SA_Print( "ActRequest = %s\n", xmlbuff ); if( xmlbuff ) ixmlFreeDOMString( xmlbuff ); xmlbuff = NULL; } else { SA_Print( "ActRequest = (null)\n" ); } if( a_event->ActionResult ) { xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult ); if( xmlbuff ) SA_Print( "ActResult = %s\n", xmlbuff ); if(strncmp(NowCommand,"Browse",6) == 0) { FNode *Now = (FNode *)malloc(sizeof(FNode)); FNode *Last = NowNode; NowNode -> LeftChild = Now; IXML_Document *document = ixmlParseBuffer(XMLP_GetFirstDocumentItem(a_event->ActionResult,"Result")); IXML_NodeList *ContainerList = ixmlElement_getElementsByTagName( ( IXML_Element * ) document, "container" ); IXML_Node *ContainerNode = ixmlNodeList_item(ContainerList,0); IXML_NodeList *FileList = ixmlElement_getElementsByTagName( ( IXML_Element * ) document, "item" ); IXML_Node *FileNode = ixmlNodeList_item(FileList,0); int ContainerLength = ixmlNodeList_length(ContainerList); int FileLength = ixmlNodeList_length(FileList); if(ContainerLength) { int i=0; for(i=0;i<ContainerLength;i++) { char *Container_id = ixmlElement_getAttribute(( IXML_Element * ) ContainerNode,"id"); IXML_NodeList *Title = ixmlElement_getElementsByTagName( ( IXML_Element * ) ContainerNode, "dc:title" ); IXML_Node *TitleNode = ixmlNodeList_item(Title,0); TitleNode= ixmlNode_getFirstChild(TitleNode); char *TitleName = strdup(ixmlNode_getNodeValue(TitleNode)); SA_Print("%s %s\n", Container_id,TitleName); Now -> Type = 0; strcpy(Now -> Name,TitleName); strcpy(Now -> Url,Container_id); Now -> LeftChild = NULL; Now -> Brother = NULL; Now -> Brother = (FNode *)malloc(sizeof(FNode)); Last = Now; Now = Now -> Brother; ContainerNode = ixmlNode_getNextSibling(ContainerNode); } } if(FileLength) { int j=0; for(j=0;j<FileLength;j++) { IXML_NodeList *Path = ixmlElement_getElementsByTagName( ( IXML_Element * ) FileNode, "res" ); IXML_Node *PathNode = ixmlNodeList_item(Path,0); PathNode= ixmlNode_getFirstChild(PathNode); char *PathName = strdup(ixmlNode_getNodeValue(PathNode)); IXML_NodeList *Title = ixmlElement_getElementsByTagName( ( IXML_Element * ) FileNode, "dc:title" ); IXML_Node *TitleNode = ixmlNodeList_item(Title,0); TitleNode= ixmlNode_getFirstChild(TitleNode); char *TitleName = strdup(ixmlNode_getNodeValue(TitleNode)); SA_Print( "%s %s\n", PathName,TitleName); Now -> Type = 1; strcpy(Now -> Name,TitleName); strcpy(Now -> Url,PathName); Now -> LeftChild = NULL; Now -> Brother = NULL; Now -> Brother = (FNode *)malloc(sizeof(FNode)); Last = Now; Now = Now -> Brother; FileNode = ixmlNode_getNextSibling(FileNode); } } Last -> Brother = NULL; Last -> LeftChild = NULL; free(Now); Now = NULL; } if( xmlbuff ) { ixmlFreeDOMString( xmlbuff ); xmlbuff = NULL; } } else { SA_Print( "ActResult = (null)\n" ); } sem_post(&BrowseSem); } break; /* GENA */ case UPNP_EVENT_SUBSCRIPTION_REQUEST: { struct Upnp_Subscription_Request *sr_event = ( struct Upnp_Subscription_Request * )Event; SA_Print( "ServiceID = %s\n", sr_event->ServiceId ); SA_Print( "UDN = %s\n", sr_event->UDN ); SA_Print( "SID = %s\n", sr_event->Sid ); } break; case UPNP_EVENT_RECEIVED: break; case UPNP_EVENT_RENEWAL_COMPLETE: { struct Upnp_Event_Subscribe *es_event = ( struct Upnp_Event_Subscribe * )Event; SA_Print( "SID = %s\n", es_event->Sid ); SA_Print( "ErrCode = %d\n", es_event->ErrCode ); SA_Print( "TimeOut = %d\n", es_event->TimeOut ); } break; case UPNP_EVENT_SUBSCRIBE_COMPLETE: case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: { struct Upnp_Event_Subscribe *es_event = ( struct Upnp_Event_Subscribe * )Event; SA_Print( "SID = %s\n", es_event->Sid ); SA_Print( "ErrCode = %d\n", es_event->ErrCode ); SA_Print( "PublisherURL= %s\n", es_event->PublisherUrl ); SA_Print( "TimeOut = %d\n", es_event->TimeOut ); } break; case UPNP_EVENT_AUTORENEWAL_FAILED: case UPNP_EVENT_SUBSCRIPTION_EXPIRED: { struct Upnp_Event_Subscribe *es_event = ( struct Upnp_Event_Subscribe * )Event; SA_Print( "SID = %s\n", es_event->Sid ); SA_Print( "ErrCode = %d\n", es_event->ErrCode ); SA_Print( "PublisherURL= %s\n", es_event->PublisherUrl ); SA_Print( "TimeOut = %d\n", es_event->TimeOut ); } break; default: break; } SA_Print ( "----------------------------------------------------------------------\n" ); SA_Print ( "======================================================================\n\n\n\n" ); ithread_mutex_unlock( &display_mutex ); return ( 0 ); }
DOMString rtpxmlElement_getAttribute(RTPXML_Element* element, DOMString name) { return ixmlElement_getAttribute((IXML_Element *)element, name); }
void HandleRequestMsg (PZFS pzfs, char *buf, int fromSock) { char rsp[2048] = { 0 }; char *rsp_tail = rsp; /* Parse xml string */ IXML_Document *doc = NULL; if ((doc = ixmlParseBuffer (buf)) == NULL) { ZError (DBG_MISC, "Invalid xml string->Cannot parse buffer"); rsp_tail += sprintf (rsp_tail, "%s<ret><err>10000001</err><msg>Invalid xml string</msg></ret>", XML_HEADER); goto RESPONSE; } /* find the cmd tag??? */ IXML_Node *node = NULL; if ((node = ixmlGetFirstNodeByTagName (doc, "cmd")) == NULL) { ZError (DBG_MISC, "Invalid xml string->Not find cmd tag."); rsp_tail += sprintf (rsp_tail, "%s<ret><err>10000001</err><msg>Invalid xml string</msg></ret>", XML_HEADER); goto RESPONSE; } /* find the op attribute??? */ char *op = NULL; if ((op = ixmlElement_getAttribute ((IXML_Element *) node, "op")) == NULL) { ZError (DBG_MISC, "Not find op attribute."); rsp_tail += sprintf (rsp_tail, "%s<ret><err>10000001</err><msg>Invalid xml string</msg></ret>", XML_HEADER); goto RESPONSE; } /* do the command */ /* GetState */ if (!strcmp (op, "GetState")) { /* NOTE: Don't implement yet */ rsp_tail += sprintf (rsp_tail, "%s<ret op=\"GetState\" mod=\"zfs\"><err>0</err></ret>", XML_HEADER); goto RESPONSE; } else if (!strcmp (op, "ImportSummary")) { /* get state */ ZLock (&pzfs->iLock); char *state = pzfs->iState == IDLE ? "idle" : "importing"; ZUnlock (&pzfs->iLock); /* get import summary */ ZLock (&pzfs->nLock); int uploaded = pzfs->imported + pzfs->deleted; int imported = pzfs->imported; int deleted = pzfs->deleted; ZUnlock (&pzfs->nLock); /* package evt */ rsp_tail += sprintf (rsp_tail, "%s<ret op=\"ImportSummary\" mod=\"zfs\"><err>0</err><state>%s</state><upload>%d</upload><imported>%d</imported><deleted>%d</deleted></ret>", XML_HEADER, state, uploaded, imported, deleted); goto RESPONSE; } else if (!strcmp (op, "ClearSummary")) { rsp_tail += sprintf (rsp_tail, "%s<ret op=\"ClearSummary\" mod=\"zfs\"><err>0</err></ret>", XML_HEADER); /* Clear all persist data */ ZLock (&pzfs->nLock); pzfs->imported = 0; pzfs->deleted = 0; ZUnlock (&pzfs->nLock); if (saveSummary (pzfs) != 0) ZError (DBG_MISC, "Clear ImportsummaryDB failed."); goto RESPONSE; } rsp_tail += sprintf (rsp_tail, "%s<ret op=\"%s\" mod=\"zfs\"><err>10000002</err><msg>Unsupported command</msg></ret>", XML_HEADER, op); RESPONSE: ZInfo4 (DBG_MISC, "Response XML->%s", rsp); write (fromSock, rsp, strlen (rsp)); close (fromSock); /* Destory doc */ if (doc) ixmlDocument_free (doc); }