fix-memory-leaks #1
3 changed files with 14 additions and 3 deletions
6
http.c
6
http.c
|
@ -20,6 +20,10 @@ char* request(char *url)
|
||||||
CURL *httpHandler = curl_easy_init();
|
CURL *httpHandler = curl_easy_init();
|
||||||
CURLcode return_code;
|
CURLcode return_code;
|
||||||
if(httpHandler) {
|
if(httpHandler) {
|
||||||
|
for(int i=0;i<128;i++)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"%x",url[i]);
|
||||||
|
}
|
||||||
curl_easy_setopt(httpHandler,CURLOPT_URL, url);
|
curl_easy_setopt(httpHandler,CURLOPT_URL, url);
|
||||||
curl_easy_setopt(httpHandler,CURLOPT_WRITEFUNCTION, httpResponseCallback);
|
curl_easy_setopt(httpHandler,CURLOPT_WRITEFUNCTION, httpResponseCallback);
|
||||||
curl_easy_setopt(httpHandler,CURLOPT_USERAGENT, "cWikiBot/0.1 (https://git.zom.bi/cpp/cWikiBot; cpp@zom.bi) libcurl4/7.64.0");
|
curl_easy_setopt(httpHandler,CURLOPT_USERAGENT, "cWikiBot/0.1 (https://git.zom.bi/cpp/cWikiBot; cpp@zom.bi) libcurl4/7.64.0");
|
||||||
|
@ -33,7 +37,7 @@ char* request(char *url)
|
||||||
}
|
}
|
||||||
if(return_code != CURLE_OK)
|
if(return_code != CURLE_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "HTTP Error: %s",curl_easy_strerror(return_code));
|
fprintf(stderr, "HTTP Error: %s\n",curl_easy_strerror(return_code));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return httpResponse.response;
|
return httpResponse.response;
|
||||||
|
|
|
@ -13,8 +13,10 @@ json_object* query_lichess(char* username)
|
||||||
char* api_base = "https://lichess.org/api/user/";
|
char* api_base = "https://lichess.org/api/user/";
|
||||||
char user_url[128];
|
char user_url[128];
|
||||||
int retries = 5;
|
int retries = 5;
|
||||||
strcpy(user_url,api_base);
|
//strcpy(user_url,api_base);
|
||||||
strcat(user_url,username);
|
//strcat(user_url,username);
|
||||||
|
int user_url_length = sprintf(user_url,"%s%s\0",api_base,username);
|
||||||
|
user_url[user_url_length]=0;
|
||||||
printf("querying %s\n",user_url);
|
printf("querying %s\n",user_url);
|
||||||
char* http_response = request(user_url);
|
char* http_response = request(user_url);
|
||||||
while(http_response == NULL)
|
while(http_response == NULL)
|
||||||
|
|
5
main.c
5
main.c
|
@ -41,8 +41,11 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
fputs("lichess_id,name\n",output);
|
fputs("lichess_id,name\n",output);
|
||||||
char line [128];
|
char line [128];
|
||||||
|
int j=0;
|
||||||
while(fgets(line, sizeof line, playersfile) != NULL)
|
while(fgets(line, sizeof line, playersfile) != NULL)
|
||||||
{
|
{
|
||||||
|
printf("%i",j);
|
||||||
|
j++;
|
||||||
char outline[256];
|
char outline[256];
|
||||||
char name[128];
|
char name[128];
|
||||||
line[strlen(line)-1] = '\0';
|
line[strlen(line)-1] = '\0';
|
||||||
|
@ -65,6 +68,8 @@ int main(int argc, char **argv)
|
||||||
sprintf(outline, "%s,%s\n",line,name);
|
sprintf(outline, "%s,%s\n",line,name);
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
fputs(outline,output);
|
fputs(outline,output);
|
||||||
|
fclose(output);
|
||||||
|
fopen("output.csv","a");
|
||||||
}
|
}
|
||||||
fclose(output);
|
fclose(output);
|
||||||
fclose(playersfile);
|
fclose(playersfile);
|
||||||
|
|
Loading…
Reference in a new issue