Esempio n. 1
0
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");
}
Esempio n. 2
0
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");
}
Esempio n. 3
0
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");
}
Esempio n. 4
0
/****************************************
* mupnp_control_action_response_geterror
****************************************/
bool mupnp_control_action_response_geterror(mUpnpActionResponse *actionRes, mUpnpAction *action)
{
	mUpnpXmlNode *resNode;
	mUpnpXmlNode *upnpErrorNode;
	mUpnpXmlNode *node;
	char *errDesc = NULL;
	char *errCode = NULL;
	
	mupnp_log_debug_l4("Entering...\n");

	resNode = mupnp_control_action_response_getactionresponsenode(actionRes);
	if (resNode == NULL)
	{
		return false;
	}
		
	/* Response node is FAULT node, there will be no output args,
	   but set action status and description */
	upnpErrorNode = mupnp_xml_node_getchildnodewithnamespace(resNode, MUPNP_SOAP_DETAIL, NULL, true);

	if (upnpErrorNode == NULL) return false;
		
	upnpErrorNode = mupnp_xml_node_getchildnodewithnamespace(upnpErrorNode, MUPNP_CONTROL_FAULT_STRING, 
							      NULL, true);

	if (upnpErrorNode == NULL) return false;
		
	node = mupnp_xml_node_getchildnodewithnamespace(upnpErrorNode, MUPNP_CONTROL_ERROR_DESCRIPTION, 
						     NULL, true);
	if (node)
		errDesc = mupnp_xml_node_getvalue(node);

	node = mupnp_xml_node_getchildnodewithnamespace(upnpErrorNode, MUPNP_CONTROL_ERROR_CODE, 
						     NULL, true);
	if (node)
		errCode = mupnp_xml_node_getvalue(node);

	if (errCode == NULL) return false;

	mupnp_action_setstatusdescription(action, errDesc);
	mupnp_action_setstatuscode(action, mupnp_str2int(errCode));
		
	return true;

	mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 5
0
const char *mupnp_xml_node_getchildnodevalue(mUpnpXmlNode *node, const char *name)
{
	mUpnpXmlNode *childNode;

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

	childNode = mupnp_xml_node_getchildnode(node, name);
	if (childNode != NULL)
		return mupnp_xml_node_getvalue(childNode);

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

	return NULL;
}
Esempio n. 6
0
File: crss.c Progetto: 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;
}
Esempio n. 7
0
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);
}