Beispiel #1
0
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);
}
Beispiel #2
0
mUpnpSoapResponse *mupnp_soap_request_post(mUpnpSoapRequest *soapReq, const char *ipaddr, int port)
{
	mUpnpHttpResponse *httpRes;
	char *content;
	size_t contentLen;
	mUpnpXmlParser *xmlParser;
	mUpnpHttpHeader *header = NULL;
	
	mupnp_log_debug_l4("Entering...\n");

	httpRes = mupnp_http_request_post(soapReq->httpReq, ipaddr, port);
	
	/* Check for HTTP response 405 Method Not Allowed */
	if (mupnp_http_response_getstatuscode(httpRes) == MUPNP_HTTP_STATUS_METHOD_NOT_ALLOWED)
	{
		/* Status code implies that we need to use M-POST */
		mupnp_http_request_setmethod(soapReq->httpReq, MUPNP_HTTP_MPOST);
		
		/* Add MAN header */
		header = mupnp_http_header_new();
		mupnp_http_header_setname(header, MUPNP_HTTP_MAN);
		mupnp_http_header_setvalue(header, MUPNP_HTTP_SOAP_MAN_VALUE);
		mupnp_http_packet_addheader((mUpnpHttpPacket*)soapReq->httpReq, header);
		
		/* Change soapaction header name to include namespace */
		header = mupnp_http_packet_getheader((mUpnpHttpPacket*)soapReq->httpReq, 
						  MUPNP_HTTP_SOAP_ACTION);
		if (header != NULL)
		{
			mupnp_http_header_setname(header, MUPNP_HTTP_SOAP_ACTION_WITH_NS);
		}
		
		/* New attempt */
		httpRes = mupnp_http_request_post(soapReq->httpReq, ipaddr, port);
	}
	
	mupnp_soap_response_sethttpresponse(soapReq->soapRes,httpRes);

	content = mupnp_http_response_getcontent(httpRes);
	contentLen = mupnp_http_response_getcontentlength(httpRes);
	if (content == NULL || contentLen <= 0)
		return soapReq->soapRes;

	xmlParser = mupnp_xml_parser_new();
	mupnp_xml_parse(xmlParser, soapReq->soapRes->rootNodeList, content, contentLen);
	mupnp_xml_parser_delete(xmlParser);

	mupnp_log_debug_l4("Leaving...\n");
	
	return soapReq->soapRes;
}
Beispiel #3
0
bool mupnp_soap_request_parsemessage(mUpnpSoapRequest *soapReq, char *msg, size_t msgLen)
{
	mUpnpXmlParser *xmlParser;
	bool parseRet;

	mupnp_log_debug_l4("Entering...\n");

	if (msgLen<= 0)
		return false;

	xmlParser = mupnp_xml_parser_new();
	parseRet = mupnp_xml_parse(xmlParser, soapReq->rootNodeList, msg, msgLen);
	mupnp_xml_parser_delete(xmlParser);

	mupnp_log_debug_l4("Leaving...\n");
	
	return parseRet;
}
Beispiel #4
0
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;
}