示例#1
0
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");
}
示例#2
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;
}
示例#3
0
bool mupnp_xml_node_removechildnode(mUpnpXmlNode *node, const char *name)
{
	mUpnpXmlNode *childNode;
  
	mupnp_log_debug_l4("Entering...\n");
  
	childNode = mupnp_xml_node_getchildnode(node, name);
	if (!childNode)
    return false;

  mupnp_xml_node_remove(childNode);
  
  return true;
}
示例#4
0
void mupnp_xml_node_setchildnode(mUpnpXmlNode *node, const char *name, const char *value)
{
	mUpnpXmlNode *childNode;

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

	childNode = mupnp_xml_node_getchildnode(node, name);
	if (childNode != NULL) {
		mupnp_xml_node_setvalue(childNode, value);
		return;
	}
	childNode = mupnp_xml_node_new();
	mupnp_xml_node_setname(childNode, name);
	mupnp_xml_node_setvalue(childNode, value);
	
	mupnp_xml_node_addchildnode(node, childNode);

	mupnp_log_debug_l4("Leaving...\n");
}
示例#5
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;
}
示例#6
0
mUpnpXmlNode *mupnp_xml_node_getchildnodewithnamespace(mUpnpXmlNode *node, const char *name, const char *ns, bool ignoreNs)
{
	char *nameWithPrefix = NULL;
	size_t nameLen = 0;
	ssize_t nameIdx;
	mUpnpXmlNode *result = NULL;
	mUpnpXmlNode *child = NULL;
	char *nodeName = NULL;

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

	if (node == NULL)
		return NULL;

	if (name == NULL)
		return NULL;

	if (ignoreNs == true)
	{
		for (child = mupnp_xml_node_getchildnodelist(node); child != NULL; child = mupnp_xml_node_next(child))
		{
			nodeName = mupnp_xml_node_getname(child);
			if (nodeName == NULL)
				continue;

			nameIdx = mupnp_strstr(nodeName, ":");
			if (nameIdx < 0)
			{
				/* No prefix (no ':') */
				if (mupnp_strcasecmp(nodeName, name) == 0)
					return child;
			}
			else
			{
				if (mupnp_strcasecmp(&(nodeName[nameIdx+1]), name) == 0)
					return child;
			}
		}

		return NULL;
	}
	else
	{
		if (ns == NULL)
		{
			/* When ns is NULL, this works like normal ..._getchildnode */
			return mupnp_xml_node_getchildnode(node, name);
		}

		nameLen = mupnp_strlen(name) + mupnp_strlen(ns) + 1; /* Not including the terminating \0 */
		nameWithPrefix = (char*) malloc(nameLen + 1);
		if (nameWithPrefix == NULL)
			return NULL;

#if defined(HAVE_SNPRINTF)
		snprintf(nameWithPrefix, nameLen + 1, "%s:%s", ns, name);
#else
		sprintf(nameWithPrefix, "%s:%s", ns, name);
#endif
		
		result = mupnp_xml_node_getchildnode(node, nameWithPrefix);

		free(nameWithPrefix);
		return result;
	}

	mupnp_log_debug_l4("Leaving...\n");	
}
示例#7
0
mUpnpXmlNode *mupnp_soap_request_getbodynode(mUpnpSoapRequest *soapReq)
{
	mUpnpXmlNode *envNode;
	mUpnpXmlNode *bodyNode = NULL;
  mUpnpXmlAttribute *attr;
  char *name;
  mUpnpStringTokenizer *tok;
  char *nsPrefix;
  size_t bodyLen;
  char *body;

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

	envNode = mupnp_soap_request_getenvelopenode(soapReq);
	if (envNode == NULL)
		return NULL;
	if (mupnp_xml_node_haschildnodes(envNode) == false)
		return NULL;

        /* We cannot assume the namespace prefix for Body is 's'. 
           According to spec, it could be anything... */
        for (attr = mupnp_xml_node_getattributes(envNode); attr != NULL; 
             attr = mupnp_xml_attribute_next(attr)) {
                /* First, find the namespace declaration attribute. */
                /* Note: We must take a copy of the attr name. 
                   Tokenizer doesn't do it (by default) */
                name = mupnp_strdup( mupnp_xml_attribute_getname(attr) );
                tok = mupnp_string_tokenizer_new(name, ":");

                nsPrefix = mupnp_string_tokenizer_nexttoken(tok);
                if ( -1 != mupnp_strstr(nsPrefix, "xmlns")) {
                        /* This attribute is a namespace declaration. Check is 
                           it the one defined for SOAP. */
                        if (mupnp_strcmp(mupnp_xml_attribute_getvalue(attr), MUPNP_SOAP_XMLNS_URL) == 0) {
                                /* This namespace declaration is correct. 
                                   Use it to find the body node... */
                                if (mupnp_string_tokenizer_hasmoretoken(tok)) {
                                        /* There is a prefix */
                                        nsPrefix = mupnp_string_tokenizer_nexttoken(tok);
                                        bodyLen = mupnp_strlen(nsPrefix) + 
                                                mupnp_strlen(MUPNP_SOAP_DELIM) + 
                                                mupnp_strlen(MUPNP_SOAP_BODY) + 1; /* +1 for trailing '\0'*/
                                        body = (char*)malloc(bodyLen);

					if ( NULL == body )
					{
						mupnp_log_debug_s("Memory allocation failure!\n");
						return NULL;
					}
#if defined(HAVE_SNPRINTF)
                                        snprintf(body, bodyLen, "%s%s%s", nsPrefix, 
                                                 MUPNP_SOAP_DELIM, MUPNP_SOAP_BODY);
#else
                                        sprintf(body, "%s%s%s", nsPrefix, MUPNP_SOAP_DELIM, MUPNP_SOAP_BODY);
#endif
                                        bodyNode = mupnp_xml_node_getchildnode(envNode, body);
                                        free(body);
                                }
                                else {
                                        /* No prefix */
                                        bodyNode = mupnp_xml_node_getchildnode(envNode, MUPNP_SOAP_BODY);
                                }
                                /* Free memory before leaving the loop */
                                mupnp_string_tokenizer_delete(tok);
                                free(name);
                                break;
                        }
                }
                mupnp_string_tokenizer_delete(tok);
                free(name);
        }

	mupnp_log_debug_l4("Leaving...\n");
	
	return bodyNode;
}