Skip to content

Commit 37010ad

Browse files
committed
Updated comments and some wording
1 parent 9385175 commit 37010ad

File tree

9 files changed

+131
-120
lines changed

9 files changed

+131
-120
lines changed

MTADiag/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
#include <vector>
2323
#include "Log.h"
2424

25-
#define VERSION "2.3.4"
25+
#define VERSION "2.3.5"
2626

2727
#endif

MTADiag/Curl.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,42 @@
1717
#include "curl/easy.h"
1818
#include "curl/types.h"
1919

20-
void progress_callback ( void* percent, double TotalToDL, double CurrentDL, double TotalToUL, double CurrentUL );
21-
size_t write_data ( void *ptr, size_t size, size_t nmemb, void *stream );
20+
void progress_callback ( void* percent, double TotalToDL, double CurrentDL, double TotalToUL, double CurrentUL ); // percentage progress callback
21+
size_t write_data ( void *ptr, size_t size, size_t nmemb, void *stream ); // writes HTTP response to a string
2222

2323
bool Curl::DownloadFile ( std::string fileURL, std::string filePath )
2424
{
25-
CURL *curl;
26-
CURLcode res;
27-
curl = curl_easy_init();
28-
if ( curl )
25+
CURL *curl; // initialize curl
26+
CURLcode res; // variable to store curl result
27+
curl = curl_easy_init(); // initialize curl_easy
28+
if ( curl ) // if curl was initialized
2929
{
30-
FILE *fp;
31-
fopen_s ( &fp, filePath.c_str(), "wb" );
32-
curl_easy_setopt ( curl, CURLOPT_URL, fileURL.c_str() );
33-
curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, fwrite );
34-
curl_easy_setopt ( curl, CURLOPT_WRITEDATA, fp );
35-
curl_easy_setopt ( curl, CURLOPT_NOPROGRESS, FALSE );
36-
curl_easy_setopt ( curl, CURLOPT_PROGRESSFUNCTION, progress_callback );
37-
res = curl_easy_perform ( curl );
38-
curl_easy_cleanup ( curl );
39-
fclose ( fp );
30+
FILE *fp; // file pointer
31+
fopen_s ( &fp, filePath.c_str(), "wb" ); // open the temporary file download location
32+
curl_easy_setopt ( curl, CURLOPT_URL, fileURL.c_str() ); // set the URL
33+
curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, fwrite ); // set the write function
34+
curl_easy_setopt ( curl, CURLOPT_WRITEDATA, fp ); // set the file path
35+
curl_easy_setopt ( curl, CURLOPT_NOPROGRESS, FALSE ); // we want progress
36+
curl_easy_setopt ( curl, CURLOPT_PROGRESSFUNCTION, progress_callback ); // set the progress callback function
37+
res = curl_easy_perform ( curl ); // perform; store result into res
38+
curl_easy_cleanup ( curl ); // clean up
39+
fclose ( fp ); // close the file
4040
}
41-
if ( !res )
41+
if ( !res ) // if we were successful
4242
return true;
43-
else
43+
else // failure
4444
return false;
4545
}
4646

4747
std::string Curl::CreatePasteBin ( std::string filePath, std::string pasteName )
4848
{
49-
CURL *curl;
50-
CURLcode res;
51-
curl = curl_easy_init();
49+
CURL *curl; // initialize curl
50+
CURLcode res; // variable to store curl result
51+
curl = curl_easy_init(); // initialize curl_easy
5252

53-
std::string logText;
54-
std::string post;
55-
std::stringstream ss;
53+
std::string logText; // stores entire log file
54+
std::string post; // stores POST string
55+
std::stringstream ss; // create a stringstream
5656
std::ifstream file;
5757

5858
// read entire MTADiag log into string
@@ -75,7 +75,7 @@ std::string Curl::CreatePasteBin ( std::string filePath, std::string pasteName )
7575
<< curl_easy_escape ( curl, pasteName.c_str(), pasteName.length() ) // urlencode MTADiag log filename
7676
<< "&"
7777
<< "api_paste_expire_date=1M&" // paste will expire in one month
78-
<< "api_dev_key=supply_your_own&" // Pastebin API dev key
78+
<< "api_dev_key=384625ea6f332a4eaf07ed02f00d2e2b&" // Pastebin API dev key
7979
<< "api_paste_code="
8080
<< curl_easy_escape ( curl, logText.c_str(), logText.length() ); // urlencode log file contents
8181
post = ss.str();
@@ -84,21 +84,22 @@ std::string Curl::CreatePasteBin ( std::string filePath, std::string pasteName )
8484
ss.str ("");
8585
ss.clear();
8686

87-
if ( curl )
87+
if ( curl ) // if curl was initialized
8888
{
89-
curl_easy_setopt ( curl, CURLOPT_URL, "http://pastebin.com/api/api_post.php" );
90-
curl_easy_setopt ( curl, CURLOPT_POSTFIELDS, post.c_str() );
91-
curl_easy_setopt ( curl, CURLOPT_NOPROGRESS, FALSE );
92-
curl_easy_setopt ( curl, CURLOPT_PROGRESSFUNCTION, progress_callback );
93-
curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, write_data );
94-
res = curl_easy_perform ( curl );
95-
curl_easy_cleanup ( curl );
89+
curl_easy_setopt ( curl, CURLOPT_URL, "http://pastebin.com/api/api_post.php" ); // set the URL
90+
curl_easy_setopt ( curl, CURLOPT_POSTFIELDS, post.c_str() ); // set our log file as the POST field
91+
curl_easy_setopt ( curl, CURLOPT_NOPROGRESS, FALSE ); // we want progress
92+
curl_easy_setopt ( curl, CURLOPT_PROGRESSFUNCTION, progress_callback ); // set the progress callback function
93+
curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, write_data ); // set the write function
94+
res = curl_easy_perform ( curl ); // perform; store result into res
95+
curl_easy_cleanup ( curl ); // clean up
9696
}
97-
if ( !res )
97+
if ( !res ) // if we were successful
9898
{
99+
99100
return response;
100101
}
101-
else
102+
else // failure
102103
{
103104
return "Failed to upload to Pastebin.";
104105
}

MTADiag/Curl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Curl {
2121
bool DownloadFile ( std::string fileURL, std::string filePath );
2222
std::string CreatePasteBin ( std::string filePath, std::string pasteName );
2323

24-
static std::string response;
24+
static std::string response; // HTTP POST response
2525
}
2626

2727
#endif

0 commit comments

Comments
 (0)