Ejemplo n.º 1
0
am_status_t BaseService::sendRequest(Connection& conn,
        const BodyChunk& headerPrefix,
        const std::string& uri,
        const std::string& uriParameters,
        const Http::HeaderList& headerList,
        const Http::CookieList& cookieList,
        const BodyChunk& contentLine,
        const BodyChunk& headerSuffix,
        const BodyChunkList& bodyChunkList) const {

    Connection::ConnHeaderMap hdrs;
    size_t hListSize = headerList.size();
    Http::Cookie theCookie;
    for (size_t idx = 0; idx < hListSize; idx++) {
        std::string headerLine;
        theCookie = headerList[idx];
        headerLine.append(theCookie.name);
        headerLine.append(": ");
        headerLine.append(theCookie.value);
        hdrs.insert(Connection::ConnHeaderMapValue(headerLine, ""));
    }

    size_t listSize = cookieList.size();
    if (listSize > 0) {
        std::string cookieLine("Cookie: ");
        for (size_t iii = 0; iii < listSize; iii++) {
            theCookie = cookieList[iii];
            cookieLine.append(theCookie.name);
            cookieLine.append("=");
            cookieLine.append(theCookie.value);
            if (iii != listSize - 1) {
                cookieLine.append(";");
            }
        }
        hdrs.insert(Connection::ConnHeaderMapValue(cookieLine, ""));
    }

    std::string hsorig(headerSuffix.data);
    hsorig.erase(hsorig.size() - 2);
    std::stringstream hs(hsorig);
    std::string line;
    while (std::getline(hs, line)) {
        if (line != "")
            hdrs.insert(Connection::ConnHeaderMapValue(line, ""));
    }

    std::string body;
    for (std::size_t i = 0; i < bodyChunkList.size(); ++i) {
        body.append(bodyChunkList[i].data);
    }

    std::string u(uri + uriParameters);
    return conn.sendRequest(headerPrefix.data.c_str(),
            u, hdrs, body);
}
Ejemplo n.º 2
0
      void do_parse(const std::string& line)
      {
	std::vector<std::string> tuple = Split::by_char<std::vector<std::string>, StandardLex, Split::NullLimit>(line, ' ', 0, 1);
	if (tuple.size() >= 1)
	  method = tuple[0];
	if (tuple.size() == 2)
	  {
	    std::vector<std::string> list = Split::by_char<std::vector<std::string>, StandardLex, Split::NullLimit>(tuple[1], ',', Split::TRIM_LEADING_SPACES|Split::TRIM_SPECIAL);
	    for (std::vector<std::string>::const_iterator i = list.begin(); i != list.end(); ++i)
	      {
		std::vector<std::string> pair = Split::by_char<std::vector<std::string>, StandardLex, Split::NullLimit>(*i, '=', 0, 1);
		if (pair.size() == 2)
		  parms.push_back(HTTP::Header(pair[0], pair[1]));
	      }
	  }
      }
Ejemplo n.º 3
0
am_status_t
BaseService::sendRequest(Connection& conn,
			 const BodyChunk& headerPrefix,
			 const std::string& uri,
			 const std::string& uriParameters,
			 const Http::HeaderList& headerList,
			 const Http::CookieList& cookieList,
			 const BodyChunk& contentLine,
			 const BodyChunk& headerSuffix,
			 const BodyChunkList& bodyChunkList) const
{
    am_status_t status;
    std::string requestLine(headerPrefix.data);

    requestLine.append(uri);
    requestLine.append(uriParameters);
    requestLine.append(HTTP_VERSION_SUFFIX);

    Log::log(logModule, Log::LOG_MAX_DEBUG,
            "BaseService::sendRequest "
            "Request line: %s", requestLine.c_str());

    status = sendChunk(conn, BodyChunk(requestLine));
    if (AM_SUCCESS == status) {
	std::string cookieLine;
	// XXX - Need to send cookies here.
        
	size_t hListSize = headerList.size();
        Http::Cookie theCookie;
	for(size_t idx = 0; idx < hListSize; idx++) {
	    theCookie = headerList[idx];
	    cookieLine.append(theCookie.name);
	    cookieLine.append(": ");
	    cookieLine.append(theCookie.value);
	    cookieLine.append("\r\n");
	}
        size_t listSize = cookieList.size();
	if(listSize > 0) {
	    cookieLine.append("Cookie: ");
	    for (size_t iii=0; iii < listSize; iii++) {
		theCookie = cookieList[iii];
		cookieLine.append(theCookie.name);
		cookieLine.append("=");
		cookieLine.append(theCookie.value);
		if (iii == listSize-1) {
		    cookieLine.append("\r\n");
		} else {
		    cookieLine.append(";");
		}
	    }
	}
        Log::log(logModule, Log::LOG_DEBUG,
            "BaseService::sendRequest "
            "Cookie and Headers =%s ", cookieLine.c_str());

        if (cookieLine.size() > 0) {
            status = sendChunk(conn, BodyChunk(cookieLine));
        }

        Log::log(logModule, Log::LOG_DEBUG,
            "BaseService::sendRequest "
            "Content-Length =%s.", contentLine.data.c_str());

	if (AM_SUCCESS == status) {
	    status = sendChunk(conn, contentLine);
	}

        Log::log(logModule, Log::LOG_DEBUG,
            "BaseService::sendRequest "
            "Header Suffix =%s ", headerSuffix.data.c_str());

	if (AM_SUCCESS == status) {
	    status = sendChunk(conn, headerSuffix);
	    if (AM_SUCCESS == status) {
		Log::log(logModule, Log::LOG_MAX_DEBUG,
			 "BaseService::sendRequest(): "
			 "Total chunks:  %ld.", bodyChunkList.size());
		std::size_t i = 0;
		for (i = 0; i < bodyChunkList.size(); ++i) {
		    status = sendChunk(conn, bodyChunkList[i]);
		    if (AM_SUCCESS != status) {
			Log::log(logModule, Log::LOG_ERROR,
				 "BaseService::sendRequest "
				 "Sending chunk %ld failed with error: %s",
				 i, am_status_to_string(status));
			break;
		    }
		}
		Log::log(logModule, Log::LOG_MAX_DEBUG,
			 "BaseService::sendRequest(): "
			 "Sent %ld chunks.", i);
	    }
	}
    }

    return status;
}