コード例 #1
0
ファイル: upnpavdump.c プロジェクト: Coramo/mupnp
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);
}
コード例 #2
0
ファイル: action_response.c プロジェクト: WilliamRen/mupnpc
bool mupnp_control_action_response_getresult(mUpnpActionResponse *actionRes, mUpnpAction *action)
{
	mUpnpXmlNode *resNode;
	mUpnpXmlNode *argNode;
	char *argName;
	mUpnpArgument *arg;
	
	mupnp_log_debug_l4("Entering...\n");

	resNode = mupnp_control_action_response_getactionresponsenode(actionRes);
	if (resNode == NULL)
		return false;
		
	for (argNode = mupnp_xml_node_getchildnodes(resNode); argNode != NULL; argNode = mupnp_xml_node_next(argNode)) {
		argName = mupnp_xml_node_getname(argNode);
		arg = mupnp_action_getargumentbyname(action, argName);
		if (arg == NULL)
			continue;
		mupnp_argument_setvalue(arg, mupnp_xml_node_getvalue(argNode));
	}

	return true;

	mupnp_log_debug_l4("Leaving...\n");
}
コード例 #3
0
ファイル: xml_node.c プロジェクト: WilliamRen/mupnpc
void mupnp_xml_node_copy(mUpnpXmlNode *dstNode, mUpnpXmlNode *srcNode)
{
	mUpnpXmlAttribute *attr;
	mUpnpXmlNode *dstChildNode;
	mUpnpXmlNode *srcChildNode;
	
	mupnp_log_debug_l4("Entering...\n");
	
	if (!dstNode || !srcNode)
		return;

	mupnp_xml_node_setname(dstNode, mupnp_xml_node_getname(srcNode));
	mupnp_xml_node_setvalue(dstNode, mupnp_xml_node_getvalue(srcNode));
	
	for (attr = mupnp_xml_node_getattributes(srcNode); attr != NULL; attr = mupnp_xml_attribute_next(attr))
		mupnp_xml_node_setattribute(dstNode, mupnp_xml_attribute_getname(attr), mupnp_xml_attribute_getvalue(attr));
	
	for (srcChildNode = mupnp_xml_node_getchildnodes(srcNode); srcChildNode != NULL; srcChildNode = mupnp_xml_node_next(srcChildNode)) {
		dstChildNode = mupnp_xml_node_new();
		mupnp_xml_node_copy(dstChildNode, srcChildNode);
		mupnp_xml_node_addchildnode(dstNode, dstChildNode);
	}
	
	 mupnp_log_debug_l4("Leaving...\n");
}
コード例 #4
0
ファイル: action_request.c プロジェクト: WilliamRen/mupnpc
void mupnp_control_action_request_setsoaprequest(mUpnpActionRequest *actionReq, mUpnpSoapRequest *soapReq)
{
	mUpnpXmlNode *actionNode;
	mUpnpXmlNode *argNode;
	mUpnpArgument *arg;
	
	mupnp_log_debug_l4("Entering...\n");

	if (actionReq->isSoapReqCreated == true)
		mupnp_soap_request_delete(actionReq->soapReq);
	actionReq->soapReq = soapReq;
	actionReq->isSoapReqCreated = false;
	
	mupnp_argumentlist_clear(actionReq->argList);
	
	actionNode = mupnp_control_action_request_getactionnode(actionReq);
	if (actionNode == NULL)
		return;
	
	for (argNode = mupnp_xml_node_getchildnodes(actionNode); argNode != NULL; argNode = mupnp_xml_node_next(argNode)) {
		arg = mupnp_argument_new();
		mupnp_argument_setargumentnode(arg, argNode);
		mupnp_argument_setname(arg, mupnp_xml_node_getname( argNode ) );
		mupnp_argument_setvalue(arg, mupnp_xml_node_getvalue( argNode ) );
		mupnp_argumentlist_add(actionReq->argList, arg);
	}

	mupnp_soap_request_createcontent(soapReq);

	mupnp_log_debug_l4("Leaving...\n");
}
コード例 #5
0
ファイル: action.c プロジェクト: WilliamRen/mupnpc
static void mupnp_action_initargumentlist(mUpnpAction *action)
{
	mUpnpXmlNode *actionNode;
	mUpnpXmlNode *argumentListNode;
	mUpnpXmlNode *childNode;
	mUpnpArgument *arg;
	
	mupnp_log_debug_l4("Entering...\n");

	mupnp_argumentlist_clear(action->argumentList);

	actionNode = mupnp_action_getactionnode(action);
	argumentListNode = mupnp_xml_node_getchildnode(actionNode, MUPNP_ARGUMENTLIST_ELEM_NAME);
	
	if (argumentListNode == NULL)
		return;

	for (childNode = mupnp_xml_node_getchildnodes(argumentListNode); childNode != NULL; childNode = mupnp_xml_node_next(childNode)) {
	
		if (mupnp_argument_isargumentnode(childNode) == false)
			continue;
			
		arg = mupnp_argument_new();
		mupnp_argument_setargumentnode(arg, childNode);
		mupnp_argumentlist_add(action->argumentList, arg);
	} 

	mupnp_log_debug_l4("Leaving...\n");
}
コード例 #6
0
ファイル: action_response.c プロジェクト: WilliamRen/mupnpc
mUpnpXmlNode *mupnp_control_action_response_getactionresponsenode(mUpnpActionResponse *actionRes)
{
	mUpnpSoapResponse *soapRes;
	mUpnpXmlNode *bodyNode;
	
	mupnp_log_debug_l4("Entering...\n");

	soapRes = mupnp_control_action_response_getsoapresponse(actionRes);
	
	bodyNode = mupnp_soap_response_getbodynode(soapRes);

	if (bodyNode == NULL)
		return NULL;
	if (mupnp_xml_node_haschildnodes(bodyNode) == false)
		return NULL;

	return mupnp_xml_node_getchildnodes(bodyNode);		

	mupnp_log_debug_l4("Leaving...\n");
}
コード例 #7
0
ファイル: crss.c プロジェクト: Coramo/mupnp
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;
}
コード例 #8
0
ファイル: xml_node.c プロジェクト: WilliamRen/mupnpc
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);
}