示例#1
0
文件: ccontent.c 项目: Coramo/mupnp
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);
  }
}
示例#2
0
文件: cdidl.c 项目: Coramo/mupnp
CgXmlNode* cg_upnpav_didl_node_new()
{
  CgXmlNode* node;

  node = cg_xml_node_new();

  cg_xml_node_setname(node, CG_UPNPAV_DMS_DIDL_NAME);
  cg_xml_node_setattribute(node, CG_UPNPAV_DMS_DIDL_XMLNS, CG_UPNPAV_DMS_DIDL_XMLNS_URL);
  cg_xml_node_setattribute(node, CG_UPNPAV_DMS_DIDL_XMLNS_DC, CG_UPNPAV_DMS_DIDL_XMLNS_DC_URL);
  cg_xml_node_setattribute(node, CG_UPNPAV_DMS_DIDL_XMLNS_UPNP, CG_UPNPAV_DMS_DIDL_XMLNS_UPNP_URL);
  cg_xml_node_setattribute(node, CG_UPNPAV_DMS_DIDL_XMLNS_DLNA, CG_UPNPAV_DMS_DIDL_XMLNS_DLNA_URL);

  return node;
}
示例#3
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");
}
CgXmlNode *cg_upnp_control_soap_response_createfaultresponsenode(int errCode, char *errDescr)
{
	CgXmlNode *faultNode;
	CgXmlNode *faultCodeNode;
	CgXmlNode *faultStringNode;
	CgXmlNode *detailNode;
	CgXmlNode *upnpErrorNode;
	CgXmlNode *errorCodeNode;
	CgXmlNode *errorDesctiprionNode;
	
	cg_log_debug_l4("Entering...\n");

	/**** <s:Fault> ****/
	faultNode = cg_xml_node_new();
	cg_xml_node_setname(faultNode, CG_SOAP_XMLNS CG_SOAP_DELIM CG_SOAP_FAULT);
	
	/**** <faultcode>s:Client</faultcode> ****/
	faultCodeNode = cg_xml_node_new();
	cg_xml_node_setname(faultCodeNode, CG_SOAP_FAULT_CODE);
	cg_xml_node_setvalue(faultCodeNode, CG_SOAP_XMLNS CG_SOAP_DELIM CG_UPNP_CONTROL_FAULT_CODE);
	cg_xml_node_addchildnode(faultNode, faultCodeNode);
		
	/**** <faultstring>UPnPError</faultstring> ****/
	faultStringNode = cg_xml_node_new();
	cg_xml_node_setname(faultStringNode, CG_SOAP_FAULT_STRING);
	cg_xml_node_setvalue(faultStringNode, CG_UPNP_CONTROL_FAULT_STRING);
	cg_xml_node_addchildnode(faultNode, faultStringNode);

	/**** <detail> ****/
	detailNode = cg_xml_node_new();
	cg_xml_node_setname(detailNode, CG_SOAP_DETAIL);
	cg_xml_node_addchildnode(faultNode, detailNode);

	/**** <UPnPError xmlns="urn:schemas-upnp-org:control-1-0"> ****/
	upnpErrorNode = cg_xml_node_new();
	cg_xml_node_setname(upnpErrorNode, CG_UPNP_CONTROL_FAULT_STRING);
	/**** Thanks for Visa Smolander (09/11/2005) ****/
	cg_xml_node_setattribute(upnpErrorNode, CG_SOAP_ATTRIBUTE_XMLNS, CG_UPNP_CONTROL_XMLNS);
	cg_xml_node_addchildnode(detailNode, upnpErrorNode);

	/**** <errorCode>error code</errorCode> ****/
	errorCodeNode = cg_xml_node_new();
	cg_xml_node_setname(errorCodeNode, CG_UPNP_CONTROL_ERROR_CODE);
	cg_xml_node_setintvalue(errorCodeNode, errCode);
	cg_xml_node_addchildnode(upnpErrorNode, errorCodeNode);

	/**** <errorDescription>error string</errorDescription> ****/
	errorDesctiprionNode = cg_xml_node_new();
	cg_xml_node_setname(errorDesctiprionNode, CG_UPNP_CONTROL_ERROR_DESCRIPTION);
	cg_xml_node_setvalue(errorDesctiprionNode, errDescr);
	cg_xml_node_addchildnode(upnpErrorNode, errorDesctiprionNode);
	
	return faultNode;

	cg_log_debug_l4("Leaving...\n");
}
示例#5
0
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));
}
示例#6
0
void cg_upnpav_resource_setsize(CgUpnpAvResource *res, long value)
{
    char strBuf[CG_STRING_LONG_BUFLEN];

    if (value <= 0) {
        cg_xml_node_removeattribute(res, CG_UPNPAV_RESOURCE_PROTOCOLINFO_SIZE);
        return;
    }
    cg_xml_node_setattribute(res, CG_UPNPAV_RESOURCE_PROTOCOLINFO_SIZE, cg_long2str(value, strBuf, (CG_STRING_LONG_BUFLEN-1)));
}
示例#7
0
CgXmlNode *cg_soap_createenvelopebodynode()
{
	CgXmlNode *envNode;
	CgXmlNode *bodyNode;
	
	cg_log_debug_l4("Entering...\n");

	envNode = cg_xml_node_new();
	cg_xml_node_setname(envNode, CG_SOAP_XMLNS CG_SOAP_DELIM CG_SOAP_ENVELOPE);
	cg_xml_node_setattribute(envNode, CG_SOAP_ATTRIBUTE_XMLNS CG_SOAP_DELIM CG_SOAP_XMLNS, CG_SOAP_XMLNS_URL);
	cg_xml_node_setattribute(envNode, CG_SOAP_XMLNS CG_SOAP_DELIM CG_SOAP_ENCORDING, CG_SOAP_ENCSTYLE_URL);

	bodyNode = cg_xml_node_new();
	cg_xml_node_setname(bodyNode, CG_SOAP_XMLNS CG_SOAP_DELIM CG_SOAP_BODY);
	cg_xml_node_addchildnode(envNode, bodyNode);

	return envNode;

	cg_log_debug_l4("Leaving...\n");
}
static void XMLCALL cg_expat_element_start(void *userData, const char *el, const char **attr)
{
    CgExpatData *expatData;
    CgXmlNode *node;
    int n;
#if defined DEBUG_XML
    int out,j;
    char* outbuf;
    char* lpout;
#endif

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

#if defined DEBUG_XML
    outbuf = (char*) malloc(4096);
    lpout = outbuf;
    outbuf[4095] = (char)0;
    for (out = 0; out < indent; out++) outbuf[out] = (char)' ';
    lpout += out;
    for (j = 0; attr[j]; j += 2) {
         lpout += sprintf(lpout,"%s='%s'", attr[j], attr[j + 1]);
    }
    lpout[0] = 0;
    printf("%8x XML Node start %s - %d Attribute %s\n",userData,el,j/2,outbuf);
    free(outbuf);
    ++indent;
#endif
    //memdiags_memlist_report_unmarkedsize();

    expatData = (CgExpatData *)userData;

    node = cg_xml_node_new();
    cg_xml_node_setname(node, (char *)el);

    for (n = 0; attr[n]; n += 2)
        cg_xml_node_setattribute(node, (char *)attr[n], (char *)attr[n+1]);

    if (expatData->rootNode != NULL) {
        if (expatData->currNode != NULL)
            cg_xml_node_addchildnode(expatData->currNode, node);
        else
            cg_xml_node_addchildnode(expatData->rootNode, node);
    }
    else
        expatData->rootNode = node;

    expatData->currNode = node;

    cg_log_debug_l4("Leaving...\n");
}
示例#9
0
void cg_upnpav_resource_updateattributes(CgUpnpAvResource *res)
{
    CgUpnpAvResourceData *nodeData;
    CgString *resAttr;
    char *mimeType;
    char *dlnaAttr;

    nodeData = (CgUpnpAvResourceData *)cg_xml_node_getuserdata(res);
    mimeType = (0 < cg_string_length(nodeData->mimeType)) ? cg_string_getvalue(nodeData->mimeType) : "*/*";
    dlnaAttr = (0 < cg_string_length(nodeData->dlnaAttr)) ? cg_string_getvalue(nodeData->dlnaAttr) : "*";

    resAttr = cg_string_new();
    cg_string_addvalue(resAttr, "http-get:*:");
    cg_string_addvalue(resAttr, mimeType);
    cg_string_addvalue(resAttr, ":");
    cg_string_addvalue(resAttr, dlnaAttr);
    cg_xml_node_setattribute(res, CG_UPNPAV_RESOURCE_PROTOCOLINFO, cg_string_getvalue(resAttr));
    cg_string_delete(resAttr);
}