Пример #1
0
CgUpnpAvContent* cg_upnpav_content_next(CgUpnpAvContent* con)
{
  CgXmlNode* nextNode;
  nextNode = cg_xml_node_next(con);
  while (nextNode) {
    if (cg_upnpav_content_iscontentnode(nextNode))
      return nextNode;
    nextNode = cg_xml_node_next(con);
  }
  return NULL;
}
Пример #2
0
void cg_upnpav_content_copy(CgUpnpAvContent* destContent, CgUpnpAvContent* srcContent)
{
  CgXmlAttribute* attr;
  CgUpnpAvContent* destNode;
  CgUpnpAvContent* srcNode;

  cg_xml_node_setname(destContent, cg_xml_node_getname(srcContent));
  cg_xml_node_setvalue(destContent, cg_xml_node_getvalue(srcContent));
  for (attr = cg_xml_node_getattributes(srcContent); attr; attr = cg_xml_attribute_next(attr))
    cg_xml_node_setattribute(destContent, cg_xml_attribute_getname(attr), cg_xml_attribute_getvalue(attr));

  for (srcNode = cg_xml_node_getchildnodes(srcContent); srcNode; srcNode = cg_xml_node_next(srcNode)) {
    if (cg_upnpav_content_gettype(srcNode) != CG_UPNPAV_CONTENT_NONE)
      continue;
    if (cg_streq(cg_xml_node_getname(srcNode), CG_UPNPAV_RESOURCE_NAME)) {
      destNode = cg_upnpav_resource_new();
      cg_upnpav_resource_copy(destNode, srcNode);
    }
    else {
      destNode = cg_upnpav_content_new();
      cg_xml_node_setname(destNode, cg_xml_node_getname(srcNode));
      cg_xml_node_setvalue(destNode, cg_xml_node_getvalue(srcNode));
      for (attr = cg_xml_node_getattributes(srcNode); attr; attr = cg_xml_attribute_next(attr))
        cg_xml_node_setattribute(destNode, cg_xml_attribute_getname(attr), cg_xml_attribute_getvalue(attr));
    }
    cg_xml_node_addchildnode(destContent, destNode);
  }
}
Пример #3
0
BOOL cg_upnpav_content_haschildcontents(CgUpnpAvContent* con)
{
  CgXmlNode* childNode;
  for (childNode = cg_xml_node_getchildnodes(con); childNode; childNode = cg_xml_node_next(childNode)) {
    if (cg_upnpav_content_iscontentnode(childNode))
      return TRUE;
  }
  return FALSE;
}
Пример #4
0
CgUpnpAvContent* cg_upnpav_content_getchildcontents(CgUpnpAvContent* con)
{
  CgXmlNode* childNode;
  for (childNode = cg_xml_node_getchildnodes(con); childNode; childNode = cg_xml_node_next(childNode)) {
    if (cg_upnpav_content_iscontentnode(childNode))
      return childNode;
  }
  return NULL;
}
Пример #5
0
int cg_upnpav_content_getnchildcontents(CgUpnpAvContent* con)
{
  CgXmlNode* childNode;
  int contentNodeCnt;
  contentNodeCnt = 0;
  for (childNode = cg_xml_node_getchildnodes(con); childNode; childNode = cg_xml_node_next(childNode)) {
    if (cg_upnpav_content_iscontentnode(childNode))
      contentNodeCnt++;
  }
  return contentNodeCnt;
}
CgUpnpPropertyList *cg_upnp_event_notify_request_getpropertylist(CgUpnpNotifyRequest *notifyReq)
{
    CgUpnpPropertyList *propList;
    CgXmlNode *propSetNode;
    CgXmlNode *propNode;
    CgXmlNode *varNode;
    CgUpnpProperty *prop;
    const char *sid;
    size_t seq;

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

  sid = cg_upnp_event_notify_request_getsid(notifyReq);
    seq = cg_upnp_event_notify_request_getseq(notifyReq);

    propList = cg_upnp_event_notify_request_getpropertylistonly(notifyReq);
    cg_upnp_propertylist_clear(propList);

    propSetNode = cg_soap_request_getrootnoode(notifyReq);
    if (propSetNode == NULL)
        return propList;

    for (propNode = cg_xml_node_getchildnodes(propSetNode); propNode != NULL; propNode = cg_xml_node_next(propNode)) {
        varNode = cg_xml_node_getchildnodes(propNode);
        prop = cg_upnp_property_createfromnode(varNode);
        cg_upnp_property_setsid(prop, sid);
        cg_upnp_property_setseq(prop, seq);
        cg_upnp_propertylist_add(propList, prop);
    }

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

    return propList;
}
Пример #7
0
static char *cg_xml_node_tostring_indent(CgXmlNode *node, int indentLevel, BOOL withChildNode, CgString *str)
{
	char *name;
	char *value;
	CgString *valueStr;
	CgXmlNode *childNode;
	
	cg_log_debug_l4("Entering...\n");

	name = cg_xml_node_getname(node);
	value = cg_xml_node_getvalue(node);

	if (cg_xml_node_haschildnodes(node) == FALSE || withChildNode == FALSE) {
		cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
		if (!cg_string_naddvalue(str, "<", 1) ||
		    !cg_string_addvalue(str, name) ||
		    !cg_xml_node_attribute_tostring(node, str))
			/* Memory allocation failed */
			return NULL;
		
		valueStr = cg_string_new();
		if (!valueStr)
			/* Memory allocation failed */
			return NULL;
		
		cg_string_setvalue(valueStr, value);
		cg_xml_escapechars(valueStr);

		if (!cg_string_naddvalue(str, ">", 1) ||
		    !cg_string_addvalue(str, cg_string_getvalue(valueStr)) ||
		    !cg_string_naddvalue(str, "</", 2) ||
		    !cg_string_addvalue(str, name) ||
		    !cg_string_naddvalue(str, ">", 1) ||
		    !cg_string_addvalue(str, "\n"))
		{
			/* Memory allocation failed */
			cg_string_delete(valueStr);
			return NULL;
		}

		cg_string_delete(valueStr);
		
		return cg_string_getvalue(str);
	}

	cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
	if (!cg_string_naddvalue(str, "<", 1) ||
	    !cg_string_addvalue(str, name) ||
	    !cg_xml_node_attribute_tostring(node, str) ||
	    !cg_string_naddvalue(str, ">", 1) ||
	    !cg_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	for (childNode = cg_xml_node_getchildnodes(node); childNode != NULL; childNode = cg_xml_node_next(childNode))
		if (!cg_xml_node_tostring_indent(childNode, indentLevel+1, TRUE, str))
			/* Memory allocation failed */
			return NULL;

	cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
	if (!cg_string_naddvalue(str, "</", 2) ||
	    !cg_string_addvalue(str, name) ||
	    !cg_string_naddvalue(str, ">", 1) ||
	    !cg_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	cg_log_debug_l4("Leaving...\n");
	
	return cg_string_getvalue(str);
}
Пример #8
0
void cg_xml_node_copy(CgXmlNode *dstNode, CgXmlNode *srcNode)
{
	CgXmlAttribute *attr;
	CgXmlNode *dstChildNode;
	CgXmlNode *srcChildNode;
	
	cg_log_debug_l4("Entering...\n");
	
	if (!dstNode || !srcNode)
		return;

	cg_xml_node_setname(dstNode, cg_xml_node_getname(srcNode));
	cg_xml_node_setvalue(dstNode, cg_xml_node_getvalue(srcNode));
	
	for (attr = cg_xml_node_getattributes(srcNode); attr != NULL; attr = cg_xml_attribute_next(attr))
		cg_xml_node_setattribute(dstNode, cg_xml_attribute_getname(attr), cg_xml_attribute_getvalue(attr));
	
	for (srcChildNode = cg_xml_node_getchildnodes(srcNode); srcChildNode != NULL; srcChildNode = cg_xml_node_next(srcChildNode)) {
		dstChildNode = cg_xml_node_new();
		cg_xml_node_copy(dstChildNode, srcChildNode);
		cg_xml_node_addchildnode(dstNode, dstChildNode);
	}
	
	 cg_log_debug_l4("Leaving...\n");
}
Пример #9
0
CgXmlNode *cg_xml_node_getchildnodewithnamespace(CgXmlNode *node, char *name, char *ns, BOOL ignoreNs)
{
	char *nameWithPrefix = NULL;
	int nameLen = 0;
	int nameIdx;
	CgXmlNode *result = NULL;
	CgXmlNode *child = NULL;
	char *nodeName = NULL;

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

	if (node == NULL)
		return NULL;

	if (name == NULL)
		return NULL;

	if (ignoreNs == TRUE)
	{
		for (child = cg_xml_node_getchildnodelist(node); child != NULL; child = cg_xml_node_next(child))
		{
			nodeName = cg_xml_node_getname(child);
			if (nodeName == NULL)
				continue;

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

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

		nameLen = cg_strlen(name) + cg_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 = cg_xml_node_getchildnode(node, nameWithPrefix);

		free(nameWithPrefix);
		return result;
	}

	cg_log_debug_l4("Leaving...\n");	
}