@@ -1664,40 +1664,41 @@ void KeyAuth::api::setDebug(bool value) {
16641664 KeyAuth::api::debug = value;
16651665}
16661666
1667- std::string KeyAuth::api::req (std::string data, std::string url) {
1667+ std::string KeyAuth::api::req (const std::string& data, const std::string& url) {
1668+
16681669 CURL* curl = curl_easy_init ();
1669- if (!curl)
1670- return XorStr (" null" );
1670+ if (!curl) {
1671+ error (XorStr (" CURL Initialization Failed!" ));
1672+ }
16711673
16721674 std::string to_return;
16731675 std::string headers;
16741676
1677+ // Set CURL options
16751678 curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
1676-
1677- curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 1 );
1678-
1679- curl_easy_setopt (curl, CURLOPT_NOPROXY, XorStr ( " keyauth.win" ) );
1680-
1679+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2L );
16811680 curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1L );
16821681 curl_easy_setopt (curl, CURLOPT_CERTINFO, 1L );
1683-
1682+ curl_easy_setopt (curl, CURLOPT_NOPROXY, XorStr ( " keyauth.win " ). c_str ());
16841683 curl_easy_setopt (curl, CURLOPT_POSTFIELDS, data.c_str ());
1685-
16861684 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_callback);
16871685 curl_easy_setopt (curl, CURLOPT_WRITEDATA, &to_return);
1688-
16891686 curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, header_callback);
16901687 curl_easy_setopt (curl, CURLOPT_HEADERDATA, &headers);
16911688
1692- auto code = curl_easy_perform (curl);
1693-
1694- if (code != CURLE_OK)
1695- error (curl_easy_strerror (code));
1689+ // Perform the request
1690+ CURLcode code = curl_easy_perform (curl);
1691+ if (code != CURLE_OK) {
1692+ std::string errorMsg = " CURL Error: " + std::string (curl_easy_strerror (code));
1693+ curl_easy_cleanup (curl);
1694+ error (errorMsg);
1695+ }
16961696
16971697 debugInfo (data, url, to_return, " Sig: " + signature + " \n Timestamp:" + signatureTimestamp);
1698-
1698+ curl_easy_cleanup (curl);
16991699 return to_return;
17001700}
1701+
17011702void error (std::string message) {
17021703 system ((XorStr (" start cmd /C \" color b && title Error && echo " ).c_str () + message + XorStr (" && timeout /t 5\" " )).c_str ());
17031704 LI_FN (__fastfail)(0 );
0 commit comments