CgSoapRequest *cg_soap_request_new()
{
    CgSoapRequest *soapReq;

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

    soapReq = (CgSoapRequest *)malloc(sizeof(CgSoapRequest));

    if ( NULL != soapReq )
    {
        soapReq->rootNodeList = cg_xml_nodelist_new();
        soapReq->soapRes = cg_soap_response_new();

        soapReq->httpReq = cg_http_request_new();
        soapReq->isHttpReqCreated = TRUE;
        cg_http_request_setcontenttype(soapReq->httpReq, CG_SOAP_CONTENT_TYPE);
        cg_http_request_setmethod(soapReq->httpReq, CG_HTTP_POST);

        cg_soap_request_setuserdata(soapReq, NULL);
    }

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

    return soapReq;
}
void cg_upnp_control_soap_request_initializeenvelopenode(CgSoapRequest *soapReq)
{
	CgXmlNodeList *rootNodeList;
	CgHttpRequest *httpReq;

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

	rootNodeList = cg_soap_request_getrootnoodelist(soapReq);
	cg_xml_nodelist_add(rootNodeList, cg_soap_createenvelopebodynode());

	httpReq = cg_soap_request_gethttprequest(soapReq);
	cg_http_request_setcontenttype(httpReq, CG_SOAP_CONTENT_TYPE);

	cg_log_debug_l4("Leaving...\n");
}
void cg_soap_request_clear(CgSoapRequest *soapReq)
{
    cg_log_debug_l4("Entering...\n");

    cg_xml_nodelist_clear(soapReq->rootNodeList);

    if (soapReq->isHttpReqCreated == TRUE)
        cg_http_request_delete(soapReq->httpReq);

    soapReq->httpReq = cg_http_request_new();
    soapReq->isHttpReqCreated = TRUE;
    cg_http_request_setcontenttype(soapReq->httpReq, CG_SOAP_CONTENT_TYPE);
    cg_http_request_setmethod(soapReq->httpReq, CG_HTTP_POST);

    cg_log_debug_l4("Leaving...\n");
}
void cg_soap_request_setcontent(CgSoapRequest *soapReq, CgXmlNode *node)
{
    CgHttpRequest *httpReq;

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

    httpReq = cg_soap_request_gethttprequest(soapReq);

    /**** content type ****/
    cg_http_request_setcontenttype(httpReq, CG_XML_CONTENT_TYPE);

    /**** content ****/
    cg_http_request_appendncontent(httpReq, CG_SOAP_VERSION_HEADER,
                    cg_strlen(CG_SOAP_VERSION_HEADER));
    cg_http_request_appendncontent(httpReq, CG_XML_CONTENT_LF,
                    cg_strlen(CG_XML_CONTENT_LF));
    cg_xml_node_tostring(node, TRUE, httpReq->content);

    /**** content length ****/
    cg_http_request_setcontentlength(httpReq,
                     cg_string_length(httpReq->content));

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