This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
curlExtra.c
66 lines (52 loc) · 1.83 KB
/
curlExtra.c
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
//Cbot BTC-e is a wrapper to hide the low work and allow more easily programing to access the BTC-e API.
/*Copyright (C) 2014 Rafael Sampaio
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A pairTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.*/
//author contact:[email protected]
#ifndef _CURLEXTRA_H
#include"curlExtra.h"
#endif
//extracted from curl examples
//http://curl.haxx.se/libcurl/c/getinmemory.html
size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp){
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
mem->memory = realloc(mem->memory, mem->size + realsize + 1);
if(mem->memory == NULL) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
return realsize;
}
int execRequest(CURL *pt){
int i=0,control;
do{
if((control=curl_easy_perform(pt))){
i++;
sleep(CURL_SLEEP);
}
else return control;
}while(i<CURL_ATTEMPTS);
return control;
}
void curlExtra_GlobalInitAll(){
curl_global_init(CURL_GLOBAL_ALL);
}
void curlExtra_GlobalInitSSL(){
curl_global_init(CURL_GLOBAL_SSL);
}
void curlExtra_GlobalCleanUp(){
curl_global_cleanup();
}