Ejemplo n.º 1
0
am_status_t BaseService::doHttpPost(const ServiceInfo& service,
				    const std::string& uriParameters,
				    const Http::CookieList& cookieList,
				    const BodyChunkList& bodyChunkList,
				    Http::Response& response,
				    std::size_t initialBufferLen,
				    const std::string &cert_nick_name,
				    bool doFormPost,
				    bool checkHTTPRetCode,
				    const ServerInfo **serverInfo) const
{
    am_status_t status;

    if(doFormPost) {
	status = doRequest(service, postPrefixChunk, uriParameters,
			   cookieList, postFormSuffixChunk, bodyChunkList,
			   response, initialBufferLen, cert_nick_name,
			   serverInfo);
    } else {
	status = doRequest(service, postPrefixChunk, uriParameters,
			   cookieList, postSuffixChunk, bodyChunkList,
			   response, initialBufferLen, cert_nick_name,
			   serverInfo);
    }


    if (checkHTTPRetCode &&
	(AM_SUCCESS == status && Http::OK != response.getStatus())) {
	Http::Status httpStatus = response.getStatus();

	if (Http::NOT_FOUND == httpStatus) {
	    status = AM_NOT_FOUND;
	} else if (Http::FORBIDDEN == httpStatus) {
	    status = AM_ACCESS_DENIED;
	} else {
	    Log::log(logModule, Log::LOG_WARNING,
		     "BaseService::doHttpPost() failed, HTTP error = %d",
		     httpStatus);
	    status = AM_HTTP_ERROR;
	}
    }
    return status;
}
Ejemplo n.º 2
0
bool WebSocketFramer::checkHandshakeResponse(http::Response& response)
{	
	assert(_mode == ws::ClientSide);
	assert(_headerState == 1);
	if (response.getStatus() == http::StatusCode::SwitchingProtocols) 
	{
		// Complete handshake or throw
		completeHandshake(response);
		
		// Success
		_headerState++;
		assert(handshakeComplete());
		return true;
	}
	else if (response.getStatus() == http::StatusCode::Unauthorized)
		assert(0 && "authentication not implemented");
	else
		throw std::runtime_error("WebSocket error: Cannot upgrade to WebSocket connection: " + response.getReason()); //, ws::ErrorNoHandshake

	// Need to resend request
	return false;
}
Ejemplo n.º 3
0
am_status_t BaseService::doHttpPost(const ServiceInfo& service,
        const std::string& uriParameters,
        const Http::CookieList& cookieList,
        const BodyChunkList& bodyChunkList,
        Http::Response& response,
        bool doFormPost,
        bool checkHTTPRetCode,
        const ServerInfo **serverInfo) const {
    am_status_t status;

    if (doFormPost) {
        status = doRequest(service, BodyChunk(std::string(HTTP_POST_PREFIX)), uriParameters,
                cookieList, BodyChunk(std::string(HTTP_POST_FORM_SUFFIX)), bodyChunkList,
                response, serverInfo);
    } else {
        status = doRequest(service, BodyChunk(std::string(HTTP_POST_PREFIX)), uriParameters,
                cookieList, BodyChunk(std::string(HTTP_POST_SUFFIX)), bodyChunkList,
                response, serverInfo);
    }


    if (checkHTTPRetCode &&
            (AM_SUCCESS == status && Http::OK != response.getStatus())) {
        Http::Status httpStatus = response.getStatus();

        if (Http::NOT_FOUND == httpStatus) {
            status = AM_NOT_FOUND;
        } else if (Http::FORBIDDEN == httpStatus) {
            status = AM_ACCESS_DENIED;
        } else {
            Log::log(logModule, Log::LOG_ERROR,
                    "BaseService::doHttpPost() failed, HTTP error = %d",
                    httpStatus);
            status = AM_HTTP_ERROR;
        }
    }
    return status;
}
Ejemplo n.º 4
0
IpAddress IpAddress::getPublicAddress(Time timeout)
{
    // The trick here is more complicated, because the only way
    // to get our public IP address is to get it from a distant computer.
    // Here we get the web page from http://www.sfml-dev.org/ip-provider.php
    // and parse the result to extract our IP address
    // (not very hard: the web page contains only our IP address).

    Http server("www.sfml-dev.org");
    Http::Request request("/ip-provider.php", Http::Request::Get);
    Http::Response page = server.sendRequest(request, timeout);
    if (page.getStatus() == Http::Response::Ok)
        return IpAddress(page.getBody());

    // Something failed: return an invalid address
    return IpAddress();
}