void CurlWrapper::setOptions()

in host/curlwrapperlib/curlwrapper.cpp [139:195]


void CurlWrapper::setOptions(const CurlOptions & options)
{

    if (0 == m_handle) {
        throw ERROR_EXCEPTION << "internal error curl not initialized";
    }
    CURL* handle = m_handle.get();

    if (CURLE_OK != curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1)) {
        throw ERROR_EXCEPTION << "failed to set set curl options";
    }

    if (options.debug() && CURLE_OK !=  curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L)) {
        throw ERROR_EXCEPTION << "failed to set set curl options";
    }

    if(options.lowSpeedLimit() && options.lowSpeedTime() 
        && (CURLE_OK != curl_easy_setopt(handle,CURLOPT_LOW_SPEED_LIMIT,options.lowSpeedLimit())
        || CURLE_OK != curl_easy_setopt(handle, CURLOPT_LOW_SPEED_TIME, options.lowSpeedTime())) ) {
            throw ERROR_EXCEPTION << "failed to set set curl options";
    }
    else{
        if(options.responseTimeout() && CURLE_OK != curl_easy_setopt(handle, CURLOPT_FTP_RESPONSE_TIMEOUT, options.responseTimeout())) {
            throw ERROR_EXCEPTION << "failed to set set curl options";
        }

        if(options.transferTimeout() && CURLE_OK != curl_easy_setopt(handle, CURLOPT_TIMEOUT, options.transferTimeout())) {
            throw ERROR_EXCEPTION << "failed to set set curl options";
        }
    }


    m_server = options.server();
    m_port = options.port();
    m_secure = options.isSecure();
    std::string url = options.partialUrl();
	std::string fullUrl = options.fullUrl();

    m_caFile = options.caFile();


    if (m_secure) {
        if (CURLE_OK != curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 1L)
            || CURLE_OK != curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L)
            || CURLE_OK != curl_easy_setopt(handle, CURLOPT_SSL_CTX_DATA, (void*)this)
            || CURLE_OK != curl_easy_setopt(handle, CURLOPT_SSL_CTX_FUNCTION, curlSslCallback)) {
                throw ERROR_EXCEPTION << "failed to set curl secure options";
        }
        if (!m_caFile.empty() && CURLE_OK != curl_easy_setopt(handle, CURLOPT_CAINFO, m_caFile.c_str())) {
            throw ERROR_EXCEPTION << "failed to set curl cainfo";
        }
    }

    if(CURLE_OK != curl_easy_setopt(handle, CURLOPT_URL, fullUrl.c_str())) {
        throw ERROR_EXCEPTION << "failed to set set curl options";
    }
}