void mupnp_http_header_delete(mUpnpHttpHeader* header) { mupnp_log_debug_l4("Entering...\n"); mupnp_list_remove((mUpnpList*)header); mupnp_string_delete(header->name); mupnp_string_delete(header->value); free(header); mupnp_log_debug_l4("Leaving...\n"); }
void mupnp_http_response_delete(mUpnpHttpResponse* httpRes) { mupnp_log_debug_l4("Entering...\n"); mupnp_http_packet_clean((mUpnpHttpPacket*)httpRes); mupnp_string_delete(httpRes->version); mupnp_string_delete(httpRes->reasonPhrase); free(httpRes); mupnp_log_debug_l4("Leaving...\n"); }
void mupnp_net_interface_delete(mUpnpNetworkInterface *netIf) { mupnp_log_debug_l4("Entering...\n"); mupnp_list_remove((mUpnpList *)netIf); mupnp_string_delete(netIf->name); mupnp_string_delete(netIf->ipaddr); mupnp_string_delete(netIf->netmask); mupnp_log_debug_l4("Leaving...\n"); free(netIf); }
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"); }
/** * Destroy an event subscriber * * @param sub The event subscriber */ void mupnp_subscriber_delete(mUpnpSubscriber* sub) { mupnp_log_debug_l4("Entering...\n"); mupnp_subscriber_clear(sub); mupnp_list_remove((mUpnpList*)sub); mupnp_string_delete(sub->sid); mupnp_string_delete(sub->ifAddr); mupnp_net_url_delete(sub->deliveryURL); free(sub); mupnp_log_debug_l4("Leaving...\n"); }
mUpnpXmlNode *mupnp_control_action_request_createactionnode(mUpnpAction *action) { mUpnpService *service; mUpnpXmlNode *actionNode; mUpnpArgument *arg; mUpnpXmlNode *argNode; mUpnpString *nameWithNamespace; mupnp_log_debug_l4("Entering...\n"); service = mupnp_action_getservice(action); actionNode = mupnp_xml_node_new(); /**** Thanks for Visa Smolander (10/31/2005) ****/ nameWithNamespace = mupnp_string_new(); mupnp_string_addvalue( nameWithNamespace, MUPNP_CONTROL_NS ":" ); mupnp_string_addvalue( nameWithNamespace, mupnp_action_getname(action) ); mupnp_xml_node_setname(actionNode, mupnp_string_getvalue( nameWithNamespace ) ); mupnp_string_delete( nameWithNamespace ); mupnp_xml_node_setnamespace(actionNode, MUPNP_CONTROL_NS, mupnp_service_getservicetype(service)); for (arg = mupnp_action_getarguments(action); arg; arg = mupnp_argument_next(arg)) { if (mupnp_argument_isindirection(arg) == false) continue; argNode = mupnp_xml_node_new(); mupnp_xml_node_setname(argNode, mupnp_argument_getname(arg)); mupnp_xml_node_setvalue(argNode, mupnp_argument_getvalue(arg)); mupnp_xml_node_addchildnode(actionNode, argNode); } mupnp_log_debug_l4("Leaving...\n"); return actionNode; }
bool mupnp_ssdpresponse_server_post(mUpnpSSDPResponseServer* server, mUpnpSSDPRequest* ssdpReq) { mUpnpHttpUSocket* httpuSock; char* ifAddr; const char* ssdpAddr; mUpnpString* ssdpMsg; size_t sentLen = 0; mupnp_log_debug_l4("Entering...\n"); httpuSock = mupnp_ssdpresponse_server_getsocket(server); ifAddr = mupnp_socket_getaddress(httpuSock); ssdpAddr = mupnp_ssdp_gethostaddress(ifAddr); mupnp_ssdprequest_sethost(ssdpReq, ssdpAddr, MUPNP_SSDP_PORT); ssdpMsg = mupnp_string_new(); mupnp_ssdprequest_tostring(ssdpReq, ssdpMsg); sentLen = mupnp_socket_sendto(httpuSock, ssdpAddr, MUPNP_SSDP_PORT, mupnp_string_getvalue(ssdpMsg), mupnp_string_length(ssdpMsg)); mupnp_string_delete(ssdpMsg); mupnp_log_debug_l4("Leaving...\n"); return (sentLen > 0); }
void mupnp_control_action_request_setaction(mUpnpActionRequest *actionReq, mUpnpAction *action) { mUpnpService *service; mUpnpSoapRequest *soapReq; mUpnpString *soapAction; mUpnpXmlNode *bodyNode; mUpnpXmlNode *contentNode; mupnp_log_debug_l4("Entering...\n"); service = mupnp_action_getservice(action); soapReq = mupnp_control_action_request_getsoaprequest(actionReq); soapAction = mupnp_string_new(); mupnp_string_addvalue(soapAction, "\""); mupnp_string_addvalue(soapAction, mupnp_service_getservicetype(service)); mupnp_string_addvalue(soapAction, "#"); mupnp_string_addvalue(soapAction, mupnp_action_getname(action)); mupnp_string_addvalue(soapAction, "\""); mupnp_soap_request_setsoapaction(soapReq, mupnp_string_getvalue(soapAction)); mupnp_string_delete(soapAction); mupnp_control_request_sethostfromservice(soapReq, service); mupnp_control_soap_request_initializeenvelopenode(soapReq); bodyNode = mupnp_soap_request_getbodynode(soapReq); contentNode = mupnp_control_action_request_createactionnode(action); mupnp_xml_node_addchildnode(bodyNode, contentNode); mupnp_soap_request_createcontent(soapReq); mupnp_log_debug_l4("Leaving...\n"); }
void mupnp_xml_node_print(mUpnpXmlNode *node) { mUpnpString *str = mupnp_string_new(); mupnp_xml_node_tostring(node, true, str); printf("%s", mupnp_string_getvalue(str)); mupnp_string_delete(str); }
/** * 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_event_subscription_request_settimeout(mUpnpSubscriptionRequest* subReq, long timeout) { mUpnpString* timeoutBuf; mupnp_log_debug_l4("Entering...\n"); timeoutBuf = mupnp_string_new(); mupnp_http_packet_setheadervalue(((mUpnpHttpPacket*)subReq), MUPNP_HTTP_TIMEOUT, mupnp_event_subscription_totimeoutheaderstring(timeout, timeoutBuf)); mupnp_string_delete(timeoutBuf); mupnp_log_debug_l4("Leaving...\n"); }
void mupnp_event_subscription_response_settimeout(mUpnpSubscriptionResponse* subRes, long value) { mUpnpString* buf; mupnp_log_debug_l4("Entering...\n"); buf = mupnp_string_new(); mupnp_http_packet_setheadervalue((mUpnpHttpPacket*)subRes, MUPNP_HTTP_TIMEOUT, mupnp_event_subscription_totimeoutheaderstring(value, buf)); mupnp_string_delete(buf); mupnp_log_debug_l4("Leaving...\n"); }
void mupnp_argument_delete(mUpnpArgument* arg) { mupnp_log_debug_l4("Entering...\n"); mupnp_list_remove((mUpnpList*)arg); mupnp_string_delete(arg->value); mupnp_log_debug_l4("Leaving...\n"); free(arg); }
void mupnp_upnpav_protocolinfo_delete(mUpnpAvProtocolInfo *info) { mupnp_log_debug_l4("Entering...\n"); mupnp_list_remove((mUpnpList *)info); if (info->protocol) mupnp_string_delete(info->protocol); if (info->network) mupnp_string_delete(info->network); if (info->mimeType) mupnp_string_delete(info->mimeType); if (info->additionalInfo) mupnp_string_delete(info->additionalInfo); if (info->string) mupnp_string_delete(info->string); free(info); mupnp_log_debug_l4("Leaving...\n"); }
static char *mupnp_xml_node_attribute_tostring(mUpnpXmlNode *node, mUpnpString *str) { mUpnpXmlAttribute *attr; const char *name; const char *value; mUpnpString *valueStr; mupnp_log_debug_l4("Entering...\n"); valueStr = mupnp_string_new(); if (valueStr == NULL) return NULL; for (attr = mupnp_xml_node_getattributes(node); attr != NULL; attr = mupnp_xml_attribute_next(attr)) { name = mupnp_xml_attribute_getname(attr); value = mupnp_xml_attribute_getvalue(attr); mupnp_string_setvalue(valueStr, value); mupnp_xml_escapechars(valueStr); /* All the following functions return NULL only when memory allocation fails, so we can check them all */ if (!mupnp_string_naddvalue(str, " ", 1) || !mupnp_string_addvalue(str, name) || !mupnp_string_naddvalue(str, "=\"", 2) || !mupnp_string_addvalue(str, mupnp_string_getvalue(valueStr)) || !mupnp_string_naddvalue(str, "\"", 1)) { /* Memory allocation failed */ mupnp_string_delete(valueStr); return NULL; } } mupnp_string_delete(valueStr); mupnp_log_debug_l4("Leaving...\n"); return mupnp_string_getvalue(str); }
void mupnp_http_persistentconnection_delete(mUpnpHttpPersistentConnection *node) { mupnp_log_debug_l4("Entering...\n"); mupnp_string_delete(node->host); /* Terminate and delete connection according libcurl usage */ #if !defined(CG_HTTP_CURL) mupnp_socket_close((mUpnpSocket *)node->cacheData); mupnp_socket_delete((mUpnpSocket *)node->cacheData); #else curl_easy_cleanup((CURL *)node->cacheData); #endif free(node); mupnp_log_debug_l4("Leaving...\n"); }
void mupnp_event_subscription_response_setsid(mUpnpSubscriptionResponse* subRes, const char* sid) { mUpnpString* headerSID; ssize_t uuidIdx; mupnp_log_debug_l4("Entering...\n"); headerSID = mupnp_string_new(); uuidIdx = mupnp_strstr(sid, MUPNP_ST_UUID_DEVICE); if (uuidIdx < 0) mupnp_string_addvalue(headerSID, MUPNP_ST_UUID_DEVICE ":"); mupnp_string_addvalue(headerSID, sid); mupnp_http_packet_setheadervalue(((mUpnpHttpPacket*)subRes), MUPNP_HTTP_SID, mupnp_string_getvalue(headerSID)); mupnp_string_delete(headerSID); mupnp_log_debug_l4("Leaving...\n"); }
/**************************************** * mupnp_upnpav_dms_condir_browsemetadata ****************************************/ static bool mupnp_upnpav_dms_condir_browsemetadata(mUpnpAvServer *dms, mUpnpAction *action) { char *objectID; mUpnpAvContent *objectContent; mUpnpXmlNode *didlNode; mUpnpString *resultStr; char intBuf[MUPNP_STRING_INTEGER_BUFLEN]; mUpnpAvContent *copyContent; objectID = mupnp_action_getargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_OBJECT_ID); if (mupnp_strlen(objectID) <= 0) return false; objectContent = mupnp_upnpav_dms_findcontentbyid(dms, objectID); if (!objectContent) return false; didlNode = mupnp_upnpav_didl_node_new(); copyContent = mupnp_upnpav_content_new(); mupnp_upnpav_content_copy(copyContent, objectContent); mupnp_xml_node_addchildnode(didlNode, copyContent); resultStr = mupnp_string_new(); mupnp_upnpav_didl_node_tostring(didlNode, resultStr); mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_RESULT, mupnp_string_getvalue(resultStr)); mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_NUMBER_RETURNED, "1"); mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_TOTAL_MACHES, "1"); mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_UPDATE_ID, (char*)mupnp_int2str(mupnp_upnpav_dms_condir_getsystemupdateid(dms), intBuf, sizeof(intBuf))); /* printf("browsemetadata reply: '%s'\n", mupnp_string_getvalue(resultStr)); */ mupnp_string_delete(resultStr); mupnp_upnpav_didl_node_delete(didlNode); return true; }
void mupnp_upnpav_dmr_addprotocolinfo(mUpnpAvRenderer *dmr, mUpnpAvProtocolInfo *info) { mUpnpString *protocolInfos; mUpnpAvProtocolInfo *protocolInfo; mUpnpService *service; mUpnpStateVariable *stateVar; mupnp_upnpav_protocolinfolist_add(dmr->protocolInfoList, info); protocolInfos = mupnp_string_new(); for (protocolInfo = mupnp_upnpav_dmr_getprotocolinfos(dmr); protocolInfo; protocolInfo = mupnp_upnpav_protocolinfo_next(protocolInfo)) { if (0 < mupnp_string_length(protocolInfos)) mupnp_string_addvalue(protocolInfos, ","); mupnp_string_addvalue(protocolInfos, mupnp_upnpav_protocolinfo_getstring(protocolInfo)); } service = mupnp_device_getservicebyexacttype(dmr->dev, CG_UPNPAV_DMR_CONNECTIONMANAGER_SERVICE_TYPE); stateVar = mupnp_service_getstatevariablebyname(service, CG_UPNPAV_DMR_CONNECTIONMANAGER_SINKPROTOCOLINFO); mupnp_statevariable_setvalue(stateVar, mupnp_string_getvalue(protocolInfos)); mupnp_string_delete(protocolInfos); }
static char *mupnp_xml_node_tostring_indent(mUpnpXmlNode *node, int indentLevel, bool withChildNode, mUpnpString *str) { char *name; char *value; mUpnpString *valueStr; mUpnpXmlNode *childNode; mupnp_log_debug_l4("Entering...\n"); name = mupnp_xml_node_getname(node); value = mupnp_xml_node_getvalue(node); if (mupnp_xml_node_haschildnodes(node) == false || withChildNode == false) { mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel); if (!mupnp_string_naddvalue(str, "<", 1) || !mupnp_string_addvalue(str, name) || !mupnp_xml_node_attribute_tostring(node, str)) /* Memory allocation failed */ return NULL; valueStr = mupnp_string_new(); if (!valueStr) /* Memory allocation failed */ return NULL; mupnp_string_setvalue(valueStr, value); mupnp_xml_escapechars(valueStr); if (!mupnp_string_naddvalue(str, ">", 1) || !mupnp_string_addvalue(str, mupnp_string_getvalue(valueStr)) || !mupnp_string_naddvalue(str, "</", 2) || !mupnp_string_addvalue(str, name) || !mupnp_string_naddvalue(str, ">", 1) || !mupnp_string_addvalue(str, "\n")) { /* Memory allocation failed */ mupnp_string_delete(valueStr); return NULL; } mupnp_string_delete(valueStr); return mupnp_string_getvalue(str); } mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel); if (!mupnp_string_naddvalue(str, "<", 1) || !mupnp_string_addvalue(str, name) || !mupnp_xml_node_attribute_tostring(node, str) || !mupnp_string_naddvalue(str, ">", 1) || !mupnp_string_addvalue(str, "\n")) /* Memory allocation failed */ return NULL; for (childNode = mupnp_xml_node_getchildnodes(node); childNode != NULL; childNode = mupnp_xml_node_next(childNode)) if (!mupnp_xml_node_tostring_indent(childNode, indentLevel+1, true, str)) /* Memory allocation failed */ return NULL; mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel); if (!mupnp_string_naddvalue(str, "</", 2) || !mupnp_string_addvalue(str, name) || !mupnp_string_naddvalue(str, ">", 1) || !mupnp_string_addvalue(str, "\n")) /* Memory allocation failed */ return NULL; mupnp_log_debug_l4("Leaving...\n"); return mupnp_string_getvalue(str); }
static bool mupnp_upnpav_dms_condir_browsedirectchildren(mUpnpAvServer *dms, mUpnpAction *action) { char *objectID; mUpnpAvContent *objectContent; mUpnpAvContent *content; mUpnpAvContent *copyContent; mUpnpAvContentList *sortedContentList; mUpnpAvContent **sortedContentArray; int startingIndex; int requestedCount; int numberReturned; int totalMachesCnt; char intBuf[MUPNP_STRING_INTEGER_BUFLEN]; int n; mUpnpXmlNode *didlNode; mUpnpString *resultStr; objectID = mupnp_action_getargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_OBJECT_ID); if (mupnp_strlen(objectID) <= 0) return false; objectContent = mupnp_upnpav_dms_findcontentbyid(dms, objectID); if (!objectContent) return false; totalMachesCnt = 0; sortedContentList = mupnp_upnpav_contentlist_new(); for (content=mupnp_upnpav_content_getchildcontents(objectContent); content; content=mupnp_upnpav_content_next(content)) { copyContent = mupnp_upnpav_content_new(); mupnp_upnpav_content_copy(copyContent, content); mupnp_upnpav_contentlist_add(sortedContentList, copyContent); totalMachesCnt++; } /* Not Implemented // Sort Content Node Lists string sortCriteria = action->getSortCriteria(); ContentNodeList sortedContentNodeBufList(false); ContentNodeList *sortedContentNodeList = sortContentNodeList(&contentNodeList, sortCriteria.c_str(), sortedContentNodeBufList); */ startingIndex = mupnp_str2int(mupnp_action_getargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_STARTING_INDEX)); if (startingIndex <= 0) startingIndex = 0; requestedCount = mupnp_str2int(mupnp_action_getargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_REQUESTED_COUNT)); if (requestedCount <= 0) requestedCount = mupnp_upnpav_contentlist_size(sortedContentList); numberReturned = 0; didlNode = mupnp_upnpav_didl_node_new(); sortedContentArray = (mUpnpAvContent **)malloc(sizeof(mUpnpAvContent*) * totalMachesCnt); n = 0; for (content=mupnp_upnpav_contentlist_gets(sortedContentList); content; content=mupnp_upnpav_content_next(content)) { sortedContentArray[n] = content; n++; } for (n=startingIndex; (n<totalMachesCnt && numberReturned<requestedCount); n++) { content = sortedContentArray[n]; mupnp_upnpav_content_remove(content); mupnp_upnpav_content_addchildcontent(didlNode, content); mupnp_upnpav_content_setparentid(content, objectID); numberReturned++; } resultStr = mupnp_string_new(); mupnp_upnpav_didl_node_tostring(didlNode, resultStr); mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_RESULT, mupnp_string_getvalue(resultStr)); mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_NUMBER_RETURNED, (char*)mupnp_int2str(numberReturned, intBuf, sizeof(intBuf))); mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_TOTAL_MACHES, (char*)mupnp_int2str(totalMachesCnt, intBuf, sizeof(intBuf))); mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_UPDATE_ID, (char*)mupnp_int2str(mupnp_upnpav_dms_condir_getsystemupdateid(dms), intBuf, sizeof(intBuf))); mupnp_string_delete(resultStr); free(sortedContentArray); mupnp_upnpav_didl_node_delete(didlNode); mupnp_upnpav_contentlist_delete(sortedContentList); return true; }
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; }
bool mupnp_xml_parse(mUpnpXmlParser* parser, mUpnpXmlNodeList* nodeList, const char* data, size_t len) { #if defined DEBUG_XML_RESULT mUpnpString* resdata = NULL; #endif XML_Parser p; mUpnpExpatData expatData; #ifdef MUPNP_SHOW_TIMINGS struct timeval start_time, end_time, elapsed_time; #endif mupnp_log_debug_l4("Entering...\n"); #ifdef MUPNP_SHOW_TIMINGS gettimeofday(&start_time, NULL); #endif if (!data || len <= 0) return false; p = XML_ParserCreate(NULL); if (!p) return false; /* Fix to get expat parser to work with DLink-routers */ if (data[len - 1] == 0) len--; expatData.rootNode = NULL; expatData.currNode = NULL; XML_SetUserData(p, &expatData); XML_SetElementHandler(p, mupnp_expat_element_start, mupnp_expat_element_end); XML_SetCharacterDataHandler(p, mupnp_expat_character_data); parser->parseResult = XML_Parse(p, data, len, 1); XML_ParserFree(p); if (parser->parseResult == 0 /*XML_STATUS_ERROR*/) { if (expatData.rootNode != NULL) mupnp_xml_node_delete(expatData.rootNode); #if defined DEBUG_XML_RESULT resdata = mupnp_string_new(); mupnp_string_naddvalue(resdata, data, len); printf("XML parse Error on data %s\n time used = %ds\n", mupnp_string_getvalue(resdata), time(NULL) - startTime); mupnp_string_delete(resdata); #endif return false; } mupnp_xml_nodelist_add(nodeList, expatData.rootNode); #ifdef MUPNP_SHOW_TIMINGS gettimeofday(&end_time, NULL); timersub(&end_time, &start_time, &elapsed_time); mupnp_log_debug_s("Parsing XML completed. Elapsed time: " "%ld msec\n", ((elapsed_time.tv_sec * 1000) + (elapsed_time.tv_usec / 1000))); mupnp_total_elapsed_time += (elapsed_time.tv_sec * 1000000) + (elapsed_time.tv_usec); mupnp_log_debug_s("Total elapsed time: %ld msec\n", mupnp_total_elapsed_time / 1000); #endif #if defined DEBUG_XML_RESULT resdata = mupnp_string_new(); mupnp_string_naddvalue(resdata, data, len); printf("XML parse success - time used %ds\n", time(NULL) - startTime); mupnp_string_delete(resdata); #endif return true; mupnp_log_debug_l4("Leaving...\n"); }