void PrintContentDirectory(mUpnpAction* browseAction, int indent, const char* objectId) { int n; char indentStr[128]; char* resultXml; mUpnpXmlParser* xmlParser; mUpnpXmlNodeList* rootNode; mUpnpXmlNode* didlNode; mUpnpXmlNode* cnode; const char* id; const char* title; const char* url; for (n = 0; n < indent && n < (sizeof(indentStr) - 1); n++) indentStr[n] = ' '; indentStr[n] = '\0'; mupnp_action_setargumentvaluebyname(browseAction, "ObjectID", objectId); mupnp_action_setargumentvaluebyname(browseAction, "BrowseFlag", "BrowseDirectChildren"); mupnp_action_setargumentvaluebyname(browseAction, "Filter", "*"); mupnp_action_setargumentvaluebyname(browseAction, "StartingIndex", "0"); mupnp_action_setargumentvaluebyname(browseAction, "RequestedCount", "0"); mupnp_action_setargumentvaluebyname(browseAction, "SortCriteria", ""); if (!mupnp_action_post(browseAction)) return; resultXml = mupnp_action_getargumentvaluebyname(browseAction, "Result"); if (mupnp_strlen(resultXml) <= 0) return; rootNode = mupnp_xml_nodelist_new(); xmlParser = mupnp_xml_parser_new(); if (mupnp_xml_parse(xmlParser, rootNode, resultXml, mupnp_strlen(resultXml))) { didlNode = mupnp_xml_nodelist_getbyname(rootNode, "DIDL-Lite"); if (didlNode) { for (cnode = mupnp_xml_node_getchildnodes(didlNode); cnode; cnode = mupnp_xml_node_next(cnode)) { id = mupnp_xml_node_getattributevalue(cnode, "id"); title = mupnp_xml_node_getchildnodevalue(cnode, "dc:title"); if (mupnp_xml_node_isname(cnode, "container")) { printf(" %s[%s]%s\n", indentStr, id, ((0 < mupnp_strlen(title)) ? title : "")); PrintContentDirectory(browseAction, (indent + 1), id); } else { url = mupnp_xml_node_getchildnodevalue(cnode, "res"); printf(" %s[%s]%s (%s)\n", indentStr, id, ((0 < mupnp_strlen(title)) ? title : ""), ((0 < mupnp_strlen(url)) ? url : "")); } } } } mupnp_xml_nodelist_delete(rootNode); mupnp_xml_parser_delete(xmlParser); }
/** * Destroy the given control point * * @param ctrlPoint The control point struct to destroy */ void mupnp_controlpoint_delete(mUpnpControlPoint *ctrlPoint) { mupnp_log_debug_l4("Entering...\n"); mupnp_controlpoint_stop(ctrlPoint); /* Delete cached interfaces */ mupnp_net_interfacelist_delete(ctrlPoint->ifCache); /* Delete expiration handlers */ mupnp_thread_delete(ctrlPoint->expThread); mupnp_mutex_delete(ctrlPoint->expMutex); mupnp_cond_delete(ctrlPoint->expCond); /* Delete others */ mupnp_mutex_delete(ctrlPoint->mutex); mupnp_xml_nodelist_delete(ctrlPoint->deviceRootNodeList); mupnp_devicelist_delete(ctrlPoint->deviceList); mupnp_ssdp_serverlist_delete(ctrlPoint->ssdpServerList); mupnp_ssdpresponse_serverlist_delete(ctrlPoint->ssdpResServerList); mupnp_http_serverlist_delete(ctrlPoint->httpServerList); mupnp_string_delete(ctrlPoint->httpEventURI); mupnp_eventlistenerlist_delete(ctrlPoint->eventListeners); #ifdef MUPNP_HTTP_USE_PERSISTENT_CONNECTIONS mupnp_http_persistentconnection_clear(); #endif free(ctrlPoint); mupnp_log_debug_l4("Leaving...\n"); }
void mupnp_xml_node_delete(mUpnpXmlNode *node) { mupnp_log_debug_l4("Entering...\n"); mupnp_list_remove((mUpnpList *)node); mupnp_string_delete(node->name); mupnp_string_delete(node->value); mupnp_xml_attributelist_delete(node->attrList); mupnp_xml_nodelist_delete(node->nodeList); if (node->userDataDestructorFunc != NULL) node->userDataDestructorFunc(node->userData); free(node); mupnp_log_debug_l4("Leaving...\n"); }
void mupnp_soap_request_delete(mUpnpSoapRequest *soapReq) { mupnp_log_debug_l4("Entering...\n"); mupnp_soap_request_clear(soapReq); mupnp_xml_nodelist_delete(soapReq->rootNodeList); if (soapReq->isHttpReqCreated == true) mupnp_http_request_delete(soapReq->httpReq); mupnp_soap_response_delete(soapReq->soapRes); free(soapReq); mupnp_log_debug_l4("Leaving...\n"); }
mUpnpMediaContent* mupnp_http_getrsscontents(char* rssURL) { mUpnpString* content_str; char* content_string; mUpnpXmlParser* xmlParser; mUpnpXmlNodeList* nodeList; mUpnpXmlNode* rootNode; mUpnpXmlNode* channelNode; mUpnpXmlNode* node; mUpnpXmlNode* childNode; char* container_title; char* content_title; char* contentURL; char containerID[CG_MD5_STRING_BUF_SIZE]; char contentID[CG_MD5_STRING_BUF_SIZE]; long contentSize; int nContentent; char* contentMimeType; mUpnpMediaContent* content; mUpnpMediaContent* container; mUpnpMediaResource* res; content_str = mupnp_string_new(); if (!mupnp_http_getrestresponse(rssURL, content_str)) { mupnp_string_delete(content_str); return NULL; } content_string = mupnp_string_getvalue(content_str); if (mupnp_strlen(content_string) <= 0) { mupnp_string_delete(content_str); return NULL; } nodeList = mupnp_xml_nodelist_new(); xmlParser = mupnp_xml_parser_new(); if (mupnp_xml_parse(xmlParser, nodeList, content_string, mupnp_strlen(content_string)) == FALSE) { mupnp_string_delete(content_str); mupnp_xml_parser_delete(xmlParser); mupnp_xml_nodelist_delete(nodeList); return NULL; } mupnp_string_delete(content_str); mupnp_xml_parser_delete(xmlParser); nContentent = 0; rootNode = mupnp_xml_nodelist_gets(nodeList); if (rootNode == NULL) { mupnp_xml_nodelist_delete(rootNode); return NULL; } channelNode = mupnp_xml_node_getchildnode(rootNode, "channel"); if (channelNode == NULL) { mupnp_xml_nodelist_delete(rootNode); return NULL; } /**** container ****/ // Title container_title = ""; childNode = mupnp_xml_node_getchildnode(channelNode, "title"); if (childNode) { if (mupnp_xml_node_getvalue(childNode)) container_title = mupnp_xml_node_getvalue(childNode); } if (mupnp_strlen(container_title) <= 0) { mupnp_xml_nodelist_delete(rootNode); return NULL; } container = mupnp_media_content_new(); mupnp_media_content_settype(container, MUPNP_MEDIA_CONTENT_CONTAINER); mupnp_media_content_settitle(container, container_title); mupnp_str2md5(container_title, containerID); mupnp_media_content_setid(container, containerID); /**** item ****/ for (node = mupnp_xml_node_getchildnodes(channelNode); node; node = mupnp_xml_node_next(node)) { if (!mupnp_xml_node_isname(node, "item")) continue; content_title = ""; contentURL = ""; contentSize = 0; // Title childNode = mupnp_xml_node_getchildnode(node, "title"); if (childNode) { if (mupnp_xml_node_getvalue(childNode)) content_title = mupnp_xml_node_getvalue(childNode); } // Enclosure childNode = mupnp_xml_node_getchildnode(node, "enclosure"); if (childNode) { // url if (mupnp_xml_node_getattributevalue(childNode, "url")) contentURL = mupnp_xml_node_getattributevalue(childNode, "url"); // type if (mupnp_xml_node_getattributevalue(childNode, "type")) contentMimeType = mupnp_xml_node_getattributevalue(childNode, "type"); // type if (mupnp_xml_node_getattributevalue(childNode, "length")) contentSize = atol(mupnp_xml_node_getattributevalue(childNode, "length")); } if (mupnp_strlen(content_title) <= 0 || mupnp_strlen(contentURL) <= 0) continue; content = mupnp_media_content_new(); mupnp_media_content_settype(content, MUPNP_MEDIA_CONTENT_ITEM); /**** content name ****/ content_title = mupnp_strtrim(content_title, " ", 1); if (mupnp_strlen(content_title) <= 0) { continue; } mupnp_media_content_settitle(content, content_title); /**** content id ****/ mupnp_str2md5(contentURL, contentID); mupnp_media_content_setid(content, contentID); mupnp_media_content_addchildcontent(container, content); res = mupnp_media_resource_new(); mupnp_media_resource_setmimetype(res, contentMimeType); mupnp_media_resource_seturl(res, contentURL); mupnp_media_resource_setsize(res, contentSize); mupnp_media_content_addresource(content, res); nContentent++; } mupnp_xml_nodelist_delete(nodeList); return container; }