updating log entry server scripts

This commit is contained in:
jakani24
2024-03-09 14:29:45 +01:00
parent 732dbb8432
commit e22fffb15f
10 changed files with 125 additions and 30 deletions

View File

@@ -164,4 +164,35 @@ char* url_encode(const char* input) {
return encoded;
}
int upload_to_srv(const char* url, const char* filepath,bool ignore_insecure) {
//upload a file to the server
CURL* curl;
CURLcode res;
struct curl_httppost* formpost = NULL;
struct curl_httppost* lastptr = NULL;
struct curl_slist* headerlist = NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "file", CURLFORM_FILE, filepath, CURLFORM_END);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
if(ignore_insecure==true)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
headerlist = curl_slist_append(headerlist, buf);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_formfree(formpost);
curl_slist_free_all(headerlist);
if (res == CURLE_OK) {
return 0;
}
else {
return 1;
}
}
}
#endif