pastebin

Paste #wbw -- näytä pelkkänä tekstinä -- uusi tämän pohjalta

Värjäys: Tyyli: ensimmäinen rivinumero: Tabin korvaus:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <curl.h>

size_t my_writefunction(char *ptr, size_t size, size_t nmemb, void *userdata)
{
	fwrite(ptr, size, nmemb, stdout);
	return size * nmemb;
}

int main(void)
{
	CURL *curl = NULL;
	CURLcode res = CURLE_OK;
	long response_code = 0;
	long protocols =
		CURLPROTO_HTTP |
		CURLPROTO_HTTPS |
		CURLPROTO_FTP |
		CURLPROTO_FTPS;

	res = curl_global_init(CURL_GLOBAL_DEFAULT);
	if (res != CURLE_OK) {
		fprintf(stderr, "curl_global_init returned an error\n");
		return 1;
	}

	curl = curl_easy_init();
	if (curl == NULL) {
		fprintf(stderr, "curl_easy_init returned NULL\n");
		return 1;
	}

	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
	curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 1);

	curl_easy_setopt(curl, CURLOPT_PROTOCOLS, protocols);
	curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, protocols);

	curl_easy_setopt(curl, CURLOPT_URL, "https://forum.minetest.net/mmdb/");
	curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 5000);
	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 5000);
	curl_easy_setopt(curl, CURLOPT_USERAGENT, "Minetest");

	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_writefunction);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);

	curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);

	res = curl_easy_perform(curl);
	if (res != CURLE_OK) {
		fprintf(stderr, "curl_easy_perform returned error: %s\n",
				curl_easy_strerror(res));
	}

	curl_easy_cleanup(curl);

	if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE,
			&response_code) == CURLE_OK) {
		fprintf(stderr, "got response code %ld\n", response_code);
	}
	else {
		fprintf(stderr, "failed to get response code\n");
	}

	curl_global_cleanup();

	return 0;
}