-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtnqc_download_thread.cc
98 lines (77 loc) · 1.65 KB
/
qtnqc_download_thread.cc
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
** -- C++ Includes --
*/
#include <iostream.h>
/*
** -- Local Includes --
*/
#include <qtnqc_main.h>
#include <qtnqc_download_thread.h>
/*
** -- Local Structures --
*/
struct curl_struct
{
char *data;
size_t data_len;
};
static size_t saveVersionToMemory(void *, size_t, size_t, void *);
/*
** -- saveVersionToMemory() --
*/
static size_t saveVersionToMemory(void *ptr, size_t size,
size_t nmemb, void *data)
{
size_t realsize = size * nmemb;
struct curl_struct *mem = (struct curl_struct *) data;
mem->data = (char *) malloc(mem->data_len + realsize + 1);
if(mem->data != NULL)
{
snprintf(mem->data, mem->data_len + realsize + 1, "%s", (char *) ptr);
mem->data_len += realsize + 1;
}
return realsize;
}
/*
** -- run() --
*/
void qtnqc_download_thread::run(void)
{
CURL *curl = NULL;
CURLcode res = (CURLcode) 0;
struct curl_struct data;
version = "";
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl != NULL)
{
data.data = NULL;
data.data_len = 0;
curl_easy_setopt(curl, CURLOPT_URL,
"http://qtnqc.sourceforge.net/VERSION");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, saveVersionToMemory);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &data);
res = curl_easy_perform(curl);
if(res == 0)
{
version = QString(data.data);
version.remove(' ');
version.remove('\n');
}
free(data.data);
curl_easy_cleanup(curl);
}
}
/*
** -- getVersion() --
*/
QString qtnqc_download_thread::getVersion(void)
{
return version;
}
/*
** -- ~qtnqc_download_thread()
*/
qtnqc_download_thread::~qtnqc_download_thread()
{
}