Exemple #1
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);
  }
}
Exemple #2
0
int cg_upnpav_content_gettype(CgUpnpAvContent* con)
{
  if (cg_streq(cg_xml_node_getname(con), CG_UPNPAV_CONTENT_ITEM_STRING))
    return CG_UPNPAV_CONTENT_ITEM;
  if (cg_streq(cg_xml_node_getname(con), CG_UPNPAV_CONTENT_CONTAINER_STRING))
    return CG_UPNPAV_CONTENT_CONTAINER;
  return CG_UPNPAV_CONTENT_NONE;
}
static CgUpnpProperty *cg_upnp_property_createfromnode(CgXmlNode *varNode)
{
    CgUpnpProperty *prop;
    char *varName;
    char *varValue;
    ssize_t colonIdx;

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

    prop = cg_upnp_property_new();
    if (varNode == NULL)
        return prop;

    // remove the event namespace
    varName = cg_xml_node_getname(varNode);
    colonIdx = cg_strstr(varName, ":");
    if (0 <= colonIdx)
        varName = varName + colonIdx + 1;
    varValue = cg_xml_node_getvalue(varNode);
    cg_upnp_property_setname(prop, varName);
    cg_upnp_property_setvalue(prop, varValue);

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

    return prop;
}
Exemple #4
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");
}
void cg_upnpav_resource_copy(CgUpnpAvResource *destRes, CgUpnpAvResource *srcRes)
{
    CgXmlAttribute *attr;

    cg_xml_node_setname(destRes, cg_xml_node_getname(srcRes));
    cg_xml_node_setvalue(destRes, cg_xml_node_getvalue(srcRes));
    for (attr=cg_xml_node_getattributes(srcRes); attr; attr=cg_xml_attribute_next(attr))
        cg_xml_node_setattribute(destRes, cg_xml_attribute_getname(attr), cg_xml_attribute_getvalue(attr));
    cg_upnpav_resource_data_copy((CgUpnpAvResourceData *)cg_xml_node_getuserdata(destRes), (CgUpnpAvResourceData *)cg_xml_node_getuserdata(srcRes));
}
Exemple #6
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);
}
Exemple #7
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");	
}