1. Your indentation is all messed up, because you've used a mix of tabs and spaces. Be consistent.
2. Curl.h:
Code:
#include "curl/curl.h"
#include "curl/types.h"
#include "curl/easy.h"
Nothing from these files is used in this header. Move the includes to Curl.cpp. You're polluting clients' namespaces.
Code:
bool downloadFile(char *fileURL, string filePath);
If this is supposed to be C++, why isn't fileUrl a string?
Code:
void progress_func(...);
size_t write_data(...);
These should not be in the header, since they're just internal helpers for downloadFile and not meant for use by clients. Remove these declarations (and copy them after the #include "Curl.h" line in Curl.cpp if you want to not worry about using the functions before they're defined.
3. Curl.cpp
Code:
bool downloadFile(char *fileURL, ...)
{
char *url;
url = new char[255];
url = fileURL;
...
curl_easy_setopt(curl, CURLOPT_URL, url);
...
delete [] url;
}
This is completely wrong. For starters, you could simply eliminate the "url" variable and do "curl_easy_setopt(curl, CURLOPT_URL, fileURL);". Next, it's leaking memory - the "url = fileURL" line overwrites the result of the "new char[]" call, so your "delete[] url" call doesn't delete the allocation. What it actually tries to delete is the caller's memory - which may or may not be legal to delete with delete[] and is certainly none of this function's business (it may be a string literal, after all). You're lucky it's not crashing. Another option would be to change the type of fileURL to string and do "curl_easy_setopt(curl, CURLOPT_URL, fileURL.c_str());" - just like you do with "filePath". This would give a nice C++ API with no leaks or crashes.
Code:
res = curl_easy_perform(curl);
You never inspect the value of "res". Either inspect it, or eliminate the variable. Probably the right thing to do is inspect it and return true to the caller only if the download actually succeeded.
Regarding your variable declarations, this is C++, not C. They don't all have to be at the top of the function. Everything except "CURL *curl;" can move inside the "if (curl)" block.
Code:
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
This appears to be pointless. You should be able to delete it and just call "curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);"
Code:
void progress_func(...)
{
}
You didn't write this. Unless you've worked out explicit permission from the author, Stack Overflow contributions are all Creative Commons
Attribution Required.
Edit: and it looks like you probably derived downloadFunc from this: http://stackoverflow.com/questions/1636333
or this: http://siddhantahuja.wordpress.com/2009 ... g-libcurl/