Beispiel #1
0
std::string utils::retrieve_url(const std::string& url, configcontainer * cfgcont, const char * authinfo, const std::string* postdata) {
	std::string buf;

	CURL * easyhandle = curl_easy_init();
	set_common_curl_options(easyhandle, cfgcont);
	curl_easy_setopt(easyhandle, CURLOPT_URL, url.c_str());
	curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, my_write_data);
	curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, &buf);

	if(postdata != NULL) {
		curl_easy_setopt(easyhandle, CURLOPT_POST, 1);
		curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, postdata->c_str());
	}

	if (authinfo) {
		curl_easy_setopt(easyhandle, CURLOPT_HTTPAUTH, get_auth_method(cfgcont->get_configvalue("http-auth-method")));
		curl_easy_setopt(easyhandle, CURLOPT_USERPWD, authinfo);
	}

	curl_easy_perform(easyhandle);
	curl_easy_cleanup(easyhandle);

	if(postdata != NULL) {
		LOG(LOG_DEBUG, "utils::retrieve_url(%s)[%s]: %s", url.c_str(), postdata->c_str(), buf.c_str());
	}
	else {
		LOG(LOG_DEBUG, "utils::retrieve_url(%s)[-]: %s", url.c_str(), buf.c_str());
	}

	return buf;
}
Beispiel #2
0
void utils::set_common_curl_options(CURL * handle, configcontainer * cfg) {
	std::string proxy;
	std::string proxyauth;
	std::string proxyauthmethod;
	std::string proxytype;
	std::string useragent; 
	std::string cookie_cache;
	unsigned int dl_timeout = 0;

	if (cfg) {
		if (cfg->get_configvalue_as_bool("use-proxy")) {
			proxy = cfg->get_configvalue("proxy");
			proxyauth = cfg->get_configvalue("proxy-auth");
			proxyauthmethod = cfg->get_configvalue("proxy-auth-method");
			proxytype = cfg->get_configvalue("proxy-type");
		}
		useragent = utils::get_useragent(cfg);
		dl_timeout = cfg->get_configvalue_as_int("download-timeout");
		cookie_cache = cfg->get_configvalue("cookie-cache");
	}

	curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
	curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1);
	curl_easy_setopt(handle, CURLOPT_ENCODING, "gzip, deflate");
	curl_easy_setopt(handle, CURLOPT_TIMEOUT, dl_timeout);

	if (proxy != "")
		curl_easy_setopt(handle, CURLOPT_PROXY, proxy.c_str());
	if (proxyauth != "") {
		curl_easy_setopt(handle, CURLOPT_PROXYAUTH, get_auth_method(proxyauthmethod));
		curl_easy_setopt(handle, CURLOPT_PROXYUSERPWD, proxyauth.c_str());
	}
	if (proxytype != "") {
		LOG(LOG_DEBUG, "utils::set_common_curl_options: proxytype = %s", proxytype.c_str());
		curl_easy_setopt(handle, CURLOPT_PROXYTYPE, get_proxy_type(proxytype));
	}

	curl_easy_setopt(handle, CURLOPT_USERAGENT, useragent.c_str());

	curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 10);
	curl_easy_setopt(handle, CURLOPT_FAILONERROR, 1);

	if (cookie_cache != "") {
		curl_easy_setopt(handle, CURLOPT_COOKIEFILE, cookie_cache.c_str());
		curl_easy_setopt(handle, CURLOPT_COOKIEJAR, cookie_cache.c_str());
	}
}
std::string Sip_Header_Value_Proxy_Authenticate::get_string() const
{
    return get_auth_method();
}