Ejemplo n.º 1
0
	RESULT GoogleHTTPConnector::downloadFile(QString& url, QString& path)
	{
		QMutexLocker locker(&_connectorMutex);

		RESULT res = eNO_ERROR;
		struct curl_slist *headers = NULL;
		CURL* p_curl = curl_easy_init();
		long http_code;
		if(p_curl)
		{
			initCurl(p_curl, headers, url, fwrite_b, 3, "GET");
			curl_easy_setopt(p_curl, CURLOPT_HTTPGET, 1L);
			curl_easy_setopt(p_curl, CURLOPT_WRITEDATA, &path);

			CURLcode _error = curl_easy_perform(p_curl);

			curl_easy_getinfo(p_curl, CURLINFO_RESPONSE_CODE, &http_code);
			res = (_error == CURLE_OK && http_code == 200) ? eNO_ERROR : eERROR;

			// clean up
			curl_easy_cleanup(p_curl);
			curl_slist_free_all(headers);
		}
		else
		{
			res = eERROR;
		}

		return res;
	}
Ejemplo n.º 2
0
	RESULT GoogleHTTPConnector::getRemoteFile(const QString& id, QString& xmlResp)
	{
		{   LOCK(_connectorMutex)

			xmlResp = "";
			RESULT res = eNO_ERROR;
			struct curl_slist *headers = NULL;
			CURL* p_curl = curl_easy_init();
			long http_code;
			QString url = kDocListScope + kDocListFeed_V3 + "/" + id;
			
			if(p_curl)
			{
				initCurl(p_curl, headers, url, write_str, 3, "GET");
				curl_easy_setopt(p_curl, CURLOPT_WRITEDATA, &xmlResp);

				CURLcode _error = curl_easy_perform(p_curl);

				curl_easy_getinfo(p_curl, CURLINFO_RESPONSE_CODE, &http_code);
				res = (_error == CURLE_OK && http_code == 200 ) ? eNO_ERROR : eERROR;

				// clean up
				curl_easy_cleanup(p_curl);
				curl_slist_free_all(headers);
			}
			else
			{
				res = eERROR;
			}
			return res;
		}
	}
Ejemplo n.º 3
0
	RESULT GoogleHTTPConnector::checkRemoteFile(VFSCache::iterator iter)
	{
		{   LOCK(_connectorMutex)

			RESULT res = eNO_ERROR;
			struct curl_slist *headers = NULL;
			CURL* p_curl = curl_easy_init();
			long http_code;
			QString url = kDocListScope + kDocListFeed_V3 + "/" + iter->getId();
			QString response;

			if(p_curl)
			{
				headers = curl_slist_append(headers, qPrintable(QString("If-None-Match: " + iter->getModified())));
				initCurl(p_curl, headers, url, write_str, 3, "GET");
				curl_easy_setopt(p_curl, CURLOPT_WRITEDATA, &response);

				CURLcode _error = curl_easy_perform(p_curl);

				curl_easy_getinfo(p_curl, CURLINFO_RESPONSE_CODE, &http_code);
				res = (_error == CURLE_OK 
					&& (http_code == 304 || http_code == 412)) ? eNO_ERROR : eERROR;

				// clean up
				curl_easy_cleanup(p_curl);
				curl_slist_free_all(headers);
			}
			else
			{
				res = eERROR;
			}
			return res;
		}
	}
Ejemplo n.º 4
0
bool TwitchTMI::OnBoot()
{
	initCurl();

	timer = new TwitchTMIUpdateTimer(this);
	AddTimer(timer);

	return true;
}
Ejemplo n.º 5
0
int main()
{
	int graph;
	int graphSize;
	long graphId;

	initCurl(&graph, &graphSize, &graphId);
    
    printf("%d\n", graph);
    printf("%d\n", graphSize);
    printf("%ld\n", graphId);

	return 0;
}
Ejemplo n.º 6
0
std::string getUrl(const char *url, const char* extraHeader)
{
	std::string resStr;

	CURL *curl;
	CURLcode res;

	initCurl();

	curl = curl_easy_init();
	if(!curl)
		return resStr;

	curl_easy_setopt(curl, CURLOPT_URL, url);
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
	curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resStr);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCB);

	struct curl_slist *hlist = nullptr;

	hlist = curl_slist_append(hlist, "Client-ID: deh0rnosabytmgde2jtn13k8mo899ye");

	if(extraHeader)
		hlist = curl_slist_append(hlist, extraHeader);

	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hlist);

	res = curl_easy_perform(curl);

	curl_slist_free_all(hlist);
	curl_easy_cleanup(curl);

	if(res != CURLE_OK)
		resStr.clear();

	return resStr;
}
Ejemplo n.º 7
0
	QString GoogleHTTPConnector::getElements(const QString* nextLink) const 
	{
		QString doc_list_feed;

		if(nextLink == 0) // request for first 100 elements
		{
			doc_list_feed = kDocListScope + kDocListFeed_V3 + "?showfolders=true";
		}
		else // request for next elements
		{
			doc_list_feed = *nextLink + "&showfolders=true";
		}

		QString response;		
		struct curl_slist *headers = NULL;
		CURL* p_curl = curl_easy_init();
		int http_code = 0;

		if(p_curl)
		{
			curl_easy_setopt(p_curl, CURLOPT_HTTPGET, 1L);
			headers = curl_slist_append(headers, "Content-Type: application/atom+xml");
			initCurl(p_curl, headers, doc_list_feed, write_str, 3, "GET");
			curl_easy_setopt(p_curl, CURLOPT_WRITEDATA, &response);

			CURLcode _error = curl_easy_perform(p_curl);
			curl_easy_getinfo(p_curl, CURLINFO_RESPONSE_CODE, &http_code);

			if (_error != CURLE_OK || 400 <= http_code) 
			{
				response = "";
			}

			// clean up
			curl_easy_cleanup(p_curl);
			curl_slist_free_all(headers);			
		}

		return response;
	}
HttpFormRequest::HttpFormRequest()
: _formPost(0), _lastPost(0)
{
    initCurl();
}
Ejemplo n.º 9
0
	RESULT GoogleHTTPConnector::auth()
	{
		QString responseDoc;
		QString responseSpr;
		char* dataDoc;
		char* dataSpr;
		
		try
		{
			CURL *p_curlDoc = curl_easy_init();
			CURL *p_curlSpr = curl_easy_init();
			struct curl_slist *headersDoc = NULL;
			struct curl_slist *headersSpr = NULL;
			
			if(p_curlDoc && p_curlSpr)
			{
				QString bodyDoc = "Email=" + _login + "&Passwd=" + _password +
					"&accountType=" + "HOSTED_OR_GOOGLE" +
					"&source=WebMounter&service=" + kDocServiceName;
				
				QString bodySpr = "Email=" + _login + "&Passwd=" + _password +
					"&accountType=" + "HOSTED_OR_GOOGLE" +
					"&source=WebMounter&service=" + kSpreadsheetServiceName;

				dataDoc = new char[strlen(bodyDoc.toLocal8Bit().constData()) + 1];
				strcpy(dataDoc, qPrintable(bodyDoc));

				dataSpr = new char[strlen(bodySpr.toLocal8Bit().constData()) + 1];
				strcpy(dataSpr, qPrintable(bodySpr));

				initCurl(p_curlDoc, headersDoc, kClientLoginUrl, write_str, 2, "POST");
				initCurl(p_curlSpr, headersSpr, kClientLoginUrl, write_str, 2, "POST");

				curl_easy_setopt(p_curlDoc, CURLOPT_WRITEDATA, &responseDoc);
				curl_easy_setopt(p_curlDoc, CURLOPT_POSTFIELDS, dataDoc);
				curl_easy_setopt(p_curlDoc, CURLOPT_POSTFIELDSIZE, strlen(dataDoc));

				curl_easy_setopt(p_curlSpr, CURLOPT_WRITEDATA, &responseSpr);
				curl_easy_setopt(p_curlSpr, CURLOPT_POSTFIELDS, dataSpr);
				curl_easy_setopt(p_curlSpr, CURLOPT_POSTFIELDSIZE, strlen(dataSpr));

				CURLcode errorDoc = curl_easy_perform(p_curlDoc);
				long codeDoc;
				curl_easy_getinfo(p_curlDoc, CURLINFO_RESPONSE_CODE, &codeDoc);

				CURLcode errorSpr = curl_easy_perform(p_curlSpr);
				long codeSpr;
				curl_easy_getinfo(p_curlSpr, CURLINFO_RESPONSE_CODE, &codeSpr);

				/* free slist */ 
				curl_slist_free_all(headersDoc);
				curl_slist_free_all(headersSpr);
				curl_easy_cleanup(p_curlDoc);
				curl_easy_cleanup(p_curlSpr);

				if(errorDoc == CURLE_OK && codeDoc == 200 
					&& errorSpr == CURLE_OK && codeSpr == 200)
				{
					QString prefix = "Auth=";  // prefix of the ClientLogin token
					QString tokenDoc = responseDoc.mid(responseDoc.indexOf(QRegExp(prefix)) + prefix.size());
					QString tokenSpr = responseSpr.mid(responseSpr.indexOf(QRegExp(prefix)) + prefix.size());
					auth_token_doc = tokenDoc.mid(0, tokenDoc.size() - 1);  // remove trailing "\n"
					auth_token_spr = tokenSpr.mid(0, tokenSpr.size() - 1);  // remove trailing "\n"

					// Attach Authorization header to every subsequent request
					request_headers_doc.push_back(kClientLoginAuthHeaderPrefix + auth_token_doc);
					request_headers_spr.push_back(kClientLoginAuthHeaderPrefix + auth_token_spr);
					return eNO_ERROR;
				}
				else
				{
					return eERROR;
				}
			}
		}
		catch(...)
		{
		}

		if(dataDoc)
		{
			delete[] dataDoc;
		}

		if(dataSpr)
		{
			delete[] dataSpr;
		}
		return eERROR;
	}
Ejemplo n.º 10
0
	RESULT GoogleHTTPConnector::downloadFiles(QList <QString>& urlList, QList <QString>& pathList)
	{
		QMutexLocker locker(&_connectorMutex);

		RESULT res = eNO_ERROR;
		QList <CURL*> curls_list;
		CURLM* p_mcurl = curl_multi_init();
		QList <curl_slist*> headers_list;
		long http_code;
		
		for(int i = 0; i < urlList.size(); i++)
		{
			CURL* p_curl = curl_easy_init();
			if(p_curl)
			{
				struct curl_slist *headers = NULL;
				
				int offset = pathList.at(i).lastIndexOf(".");
				if(offset != -1)
				{
					if(getDocType(pathList.at(i).mid(offset + 1).toLower()) == "spreadsheet")
					{
						initCurl(p_curl, headers, urlList.at(i), fwrite_b, 3, "GET", "spr");
					}
					else
					{
						initCurl(p_curl, headers, urlList.at(i), fwrite_b, 3, "GET", "doc");
					}
				}
				else
				{
					return eERROR;
				}
				
				//initCurl(p_curl, headers, urlList.at(i), fwrite_b, 3, "GET");
				//if((_proxy != "") && (_proxy != ":"))
				//{
				//	curl_easy_setopt(p_curl, CURLOPT_PROXY, qPrintable(_proxy));
				//	curl_easy_setopt(p_curl, CURLOPT_PROXYUSERPWD, qPrintable(_proxy_login_pwd));
				//}

				//curl_easy_setopt(p_curl, CURLOPT_HTTPGET, 1L);
				//curl_easy_setopt(p_curl, CURLOPT_URL, qPrintable(urlList.at(i)));
				//curl_easy_setopt(p_curl, CURLOPT_VERBOSE, 1L);
				//curl_easy_setopt(p_curl, CURLOPT_WRITEFUNCTION, fwrite_b);
				////curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
				//curl_easy_setopt(p_curl, CURLOPT_HEADER, 0L);
				//curl_easy_setopt(p_curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
				//curl_easy_setopt(p_curl, CURLOPT_FOLLOWLOCATION, 1L);
				//curl_easy_setopt(p_curl, CURLOPT_SSL_VERIFYPEER, 0L);
				//curl_easy_setopt(p_curl, CURLOPT_SSL_VERIFYHOST, 0L);

				//// Add standard headers
				//for (unsigned int j = 0; j < request_headers_.size(); ++j) 
				//{
				//	headers = curl_slist_append(headers, qPrintable(request_headers_[j]));
				//}

				//headers = curl_slist_append(headers, "GData-Version: 3.0");
				//headers = curl_slist_append(headers, "Cache-Control: no-store, no-cache, must-revalidate");

				//// attach headers to this request
				//curl_easy_setopt(p_curl, CURLOPT_HTTPHEADER, headers);

				curl_easy_setopt(p_curl, CURLOPT_WRITEDATA, &pathList.at(i));
				curls_list.append(p_curl);
				headers_list.append(headers);
				curl_multi_add_handle(p_mcurl, p_curl);
			}
			else
			{
				res = eERROR;
				break;
			}
		}

		if(res != eERROR)
		{
			int still_running = 0;
			int result = CURLM_CALL_MULTI_PERFORM;
			do
			{
				result = (int)curl_multi_perform(p_mcurl, &still_running);

				if(still_running <= 0)
				{
					break;
				}
			}
			while(result == CURLM_CALL_MULTI_PERFORM || still_running > 0);

			int msgs_in_queue = 0;
			do
			{
				CURLMsg* msg = curl_multi_info_read(p_mcurl, &msgs_in_queue);
				if(msg)
				{
					curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &http_code);
					if((RESULT)msg->data.result == eERROR
						|| http_code != 200)
					{
						CURLcode _error = curl_easy_perform(msg->easy_handle);
						curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &http_code);
						if(_error != CURLE_OK || http_code != 200)
						{
							res = eERROR;
							break;
						}
					}
				}
			}
			while(msgs_in_queue);
		}

		// clean up
		for(int i = 0; i < curls_list.size(); i++)
		{
			curl_multi_remove_handle(p_mcurl, curls_list.at(i)); 
			curl_easy_cleanup(curls_list.at(i));
			curl_slist_free_all(headers_list.at(i));
		}

		curl_multi_cleanup(p_mcurl);
		return res;
	}
Ejemplo n.º 11
0
CurlNetAccessor::CurlNetAccessor()
{
    initCurl();
}