Пример #1
0
void cg_http_packet_read_headers(CgHttpPacket *httpPkt, CgSocket *sock, char *lineBuf, size_t lineBufSize)
{
	CgStringTokenizer *strTok;
	CgHttpHeader *header;
	ssize_t readLen;
	char *name, *value;
	
	cg_log_debug_l4("Entering...\n");

	while (1) {
		readLen = cg_socket_readline(sock, lineBuf, lineBufSize);
		if (readLen <= 2)
			break;
		name = NULL;
		value = NULL;
		strTok = cg_string_tokenizer_new(lineBuf, CG_HTTP_HEADERLINE_DELIM);
		if (cg_string_tokenizer_hasmoretoken(strTok) == TRUE)
			name = cg_string_tokenizer_nexttoken(strTok);
		if (cg_string_tokenizer_hasmoretoken(strTok) == TRUE) {
			value = cg_string_tokenizer_nextalltoken(strTok);
			cg_strrtrim(value, CG_HTTP_HEADERLINE_DELIM, cg_strlen(CG_HTTP_HEADERLINE_DELIM));
		}
		if (0 < cg_strlen(name)) {
			if (cg_strlen(value) == 0)
				value = "";
			header = cg_http_header_new();
			cg_http_header_setname(header, name);
			cg_http_header_setvalue(header, value);
			cg_http_packet_addheader(httpPkt, header);
		}
		cg_string_tokenizer_delete(strTok);
	}

	cg_log_debug_l4("Leaving...\n");
}
Пример #2
0
CgSoapResponse *cg_soap_request_post(CgSoapRequest *soapReq, const char *ipaddr, int port)
{
    CgHttpResponse *httpRes;
    char *content;
    size_t contentLen;
    CgXmlParser *xmlParser;
    CgHttpHeader *header = NULL;

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

    httpRes = cg_http_request_post(soapReq->httpReq, ipaddr, port);

    /* Check for HTTP response 405 Method Not Allowed */
    if (cg_http_response_getstatuscode(httpRes) == CG_HTTP_STATUS_METHOD_NOT_ALLOWED)
    {
        /* Status code implies that we need to use M-POST */
        cg_http_request_setmethod(soapReq->httpReq, CG_HTTP_MPOST);

        /* Add MAN header */
        header = cg_http_header_new();
        cg_http_header_setname(header, CG_HTTP_MAN);
        cg_http_header_setvalue(header, CG_HTTP_SOAP_MAN_VALUE);
        cg_http_packet_addheader((CgHttpPacket*)soapReq->httpReq, header);

        /* Change soapaction header name to include namespace */
        header = cg_http_packet_getheader((CgHttpPacket*)soapReq->httpReq,
                          CG_HTTP_SOAP_ACTION);
        if (header != NULL)
        {
            cg_http_header_setname(header, CG_HTTP_SOAP_ACTION_WITH_NS);
        }

        /* New attempt */
        httpRes = cg_http_request_post(soapReq->httpReq, ipaddr, port);
    }

    cg_soap_response_sethttpresponse(soapReq->soapRes,httpRes);

    content = cg_http_response_getcontent(httpRes);
    contentLen = cg_http_response_getcontentlength(httpRes);
    if (content == NULL || contentLen <= 0)
        return soapReq->soapRes;

    xmlParser = cg_xml_parser_new();
    cg_xml_parse(xmlParser, soapReq->soapRes->rootNodeList, content, contentLen);
    cg_xml_parser_delete(xmlParser);

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

    return soapReq->soapRes;
}
Пример #3
0
void cg_http_headerlist_set(CgHttpHeaderList *headerList, const char *name, const char *value)
{
	CgHttpHeader *header;
	
	cg_log_debug_l4("Entering...\n");

	header = cg_http_headerlist_get(headerList, name);
	if (header == NULL) {
		header = cg_http_header_new();
		cg_http_headerlist_add(headerList, header);
		cg_http_header_setname(header, name);
	}
	
	cg_http_header_setvalue(header, value);

	cg_log_debug_l4("Leaving...\n");
}
Пример #4
0
void cg_http_packet_copy(CgHttpPacket *destHttpPkt, CgHttpPacket *srcHttpPkt)
{
	CgHttpHeader *srcHeader;
	CgHttpHeader *destHeader;
	
	cg_log_debug_l4("Entering...\n");

	cg_http_packet_clear(destHttpPkt);
	
	/**** copy headers ****/
	for (srcHeader = cg_http_packet_getheaders(srcHttpPkt); srcHeader != NULL; srcHeader = cg_http_header_next(srcHeader)) {
		destHeader = cg_http_header_new();
		cg_http_header_setname(destHeader, cg_http_header_getname(srcHeader));
		cg_http_header_setvalue(destHeader, cg_http_header_getvalue(srcHeader));
		cg_http_packet_addheader(destHttpPkt, destHeader);
	}
	
	/**** copy content ****/
	cg_http_packet_setcontent(destHttpPkt, cg_http_packet_getcontent(srcHttpPkt));

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