示例#1
0
文件: wswcurl.c 项目: ewirch/qfusion
void wswcurl_start(wswcurl_req *req)
{
	CURLcode res;

	if (!req)
		return;
	if (req->status)
		return; // was already started

	if (!req->curl)
	{
		wswcurl_delete(req);
		return;
	}

	if (req->txhead)
	{
		CURLSETOPT(req->curl, res, CURLOPT_HTTPHEADER, req->txhead);
	}
	if (req->post)
	{
		CURLSETOPT(req->curl, res, CURLOPT_HTTPPOST, req->post);
		req->post_last = NULL;
	}
	// Initialize multi handle if needed
	if (curlmulti == NULL)
	{
		curlmulti = curl_multi_init();
		if (curlmulti == NULL) {
			CURLDBG(("OOPS: CURL MULTI NULL!!!"));
		}
	}

	req->status = WSTATUS_QUEUED; // queued
}
示例#2
0
文件: wswcurl.c 项目: tenght/qfusion
void wswcurl_start(wswcurl_req *req)
{
	CURLcode res;

	if (!req)
		return;
	if (req->status)
		return; // was already started

	if (!req->curl)
	{
		wswcurl_delete(req);
		return;
	}

	if (req->txhead)
	{
		CURLSETOPT(req->curl, res, CURLOPT_HTTPHEADER, req->txhead);
	}
	if (req->post)
	{
		CURLSETOPT(req->curl, res, CURLOPT_HTTPPOST, req->post);
		req->post_last = NULL;
	}

	req->status = WSTATUS_QUEUED; // queued
}
示例#3
0
文件: wswcurl.c 项目: Racenet/racesow
wswcurl_req *wswcurl_create(wswcurl_cb_done callback, char *furl, ...)
{
    wswcurl_req req, *retreq = NULL;
    CURLcode res;
    char url[4 * 1024]; // 4kb url buffer?
    va_list arg;

    // Prepare url formatting with variable arguments
    va_start(arg, furl);
    vsnprintf(url, sizeof(url), furl, arg);
    va_end(arg);

    // Initialize structure
    memset(&req, 0, sizeof(req));

    if (! (req.curl = curl_easy_init())) {
        return NULL;
    }
    CURLSETOPT(req.curl, res, CURLOPT_URL, url);
    CURLSETOPT(req.curl, res, CURLOPT_WRITEFUNCTION, wswcurl_write);
    CURLSETOPT(req.curl, res, CURLOPT_NOPROGRESS, 1);
    CURLSETOPT(req.curl, res, CURLOPT_FOLLOWLOCATION, 1);
    CURLSETOPT(req.curl, res, CURLOPT_HEADERFUNCTION, wswcurl_readheader);

    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // TODO: Warsow specific stuff? Modify!!
    //CURLSETOPT(req.curl, res, CURLOPT_USERAGENT, "Warsow 0.5");
    //wswcurl_header(&req, "X-Warsow-Version", "0.5");
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    if (!req.curl) {
        return NULL;
    }
    req.url = WSTRDUP(url);
    req.callback_done = callback;
    req.filenum = -1;
    // Everything OK, allocate, copy, prepend to list and return
    retreq = WMALLOC(sizeof(req));
    memcpy(retreq, &req, sizeof(req));
    retreq->prev = NULL;
    retreq->next = http_requests;
    if (retreq->next) retreq->next->prev = retreq;
    http_requests = retreq;
    // Set the wswcurl_req as data
    CURLSETOPT(retreq->curl, res, CURLOPT_WRITEDATA, (void*)retreq);
    CURLSETOPT(retreq->curl, res, CURLOPT_WRITEHEADER, (void*)retreq);

    return retreq;
}
示例#4
0
文件: wswcurl.c 项目: ewirch/qfusion
wswcurl_req *wswcurl_create( const char *furl, ... )
{
	wswcurl_req *retreq;
	CURL *curl;
	CURLcode res;
	char url[4 * 1024]; // 4kb url buffer?
	va_list arg;
	const char *proxy = http_proxy->string;
	const char *proxy_userpwd = http_proxyuserpwd->string;

	// Prepare url formatting with variable arguments
	va_start( arg, furl );
	Q_vsnprintfz( url, sizeof( url ), furl, arg );
	va_end( arg );

	// Initialize structure
	if( !(curl = curl_easy_init()) ) {
		return NULL;
	}

	// allocate, copy
	retreq = ( wswcurl_req * )WMALLOC( sizeof( wswcurl_req ) );
	memset( retreq, 0, sizeof( *retreq ) );

	retreq->curl = curl;
	retreq->url = ( char* )WMALLOC( strlen( url ) + 1 );
	memcpy( retreq->url, url, strlen( url ) + 1 );

	CURLSETOPT( curl, res, CURLOPT_URL, retreq->url );
	CURLSETOPT( curl, res, CURLOPT_WRITEFUNCTION, wswcurl_write );
	CURLSETOPT( curl, res, CURLOPT_NOPROGRESS, 1 );
	CURLSETOPT( curl, res, CURLOPT_FOLLOWLOCATION, 1 );
	CURLSETOPT( curl, res, CURLOPT_HEADERFUNCTION, wswcurl_readheader );
	CURLSETOPT( curl, res, CURLOPT_CONNECTTIMEOUT, WCONNECTTIMEOUT );
#if defined( APPLICATION ) && defined( APP_VERSION_STR ) && defined( OSNAME ) && defined( CPUSTRING )
	CURLSETOPT( curl, res, CURLOPT_USERAGENT, APPLICATION"/"APP_VERSION_STR" (compatible; N; "OSNAME"; "CPUSTRING")" );
#endif
	CURLSETOPT( curl, res, CURLOPT_WRITEDATA, ( void * )retreq );
	CURLSETOPT( curl, res, CURLOPT_WRITEHEADER, ( void * )retreq );
	CURLSETOPT( curl, res, CURLOPT_PRIVATE, ( void * )retreq );

	if( developer->integer ) {
		CURLSETOPT( curl, res, CURLOPT_DEBUGFUNCTION, &wswcurl_debug_callback );
		CURLSETOPT( curl, res, CURLOPT_DEBUGDATA, ( void * )retreq );
		CURLSETOPT( curl, res, CURLOPT_VERBOSE, 1 );
	}

	// HTTP proxy settings
	if( proxy && *proxy ) {
		CURLSETOPT( curl, res, CURLOPT_PROXYTYPE, CURLPROXY_HTTP );

		CURLSETOPT( curl, res, CURLOPT_PROXY, proxy );
		if( proxy_userpwd && *proxy_userpwd ) {
			CURLSETOPT( curl, res, CURLOPT_PROXYUSERPWD, proxy_userpwd );
		}
	}

	wswcurl_set_timeout( retreq, WTIMEOUT );

	// link
	retreq->prev = NULL;
	retreq->next = http_requests;
	if( retreq->next ) {
		retreq->next->prev = retreq;
	}
	else {
		http_requests_hnode = retreq;
	}
	http_requests = retreq;

	CURLDBG((va("   CURL CREATE %s\n", url)));

	return retreq;
}