From e471a1f93ee23f0f729d64068504cb892481b56f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 16 Jun 2022 05:53:18 +0200 Subject: 4chan: show error from server when posting fails (when error is not one of the predefined ones) --- src/plugins/Fourchan.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 4522a56..c11e13e 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -581,7 +581,7 @@ namespace QuickMedia { Path cookies_filepath; if(get_cookies_filepath(cookies_filepath, SERVICE_NAME) != 0) { fprintf(stderr, "Failed to get 4chan cookies filepath\n"); - return PostResult::ERR; + return PostResult::Type::ERR; } std::string url = "https://sys.4chan.org/" + board_id + "/post"; @@ -608,22 +608,39 @@ namespace QuickMedia { std::string response; if(download_to_string(url, response, additional_args, true) != DownloadResult::OK) - return PostResult::ERR; + return PostResult::Type::ERR; if(response.find("successful") != std::string::npos) - return PostResult::OK; + return PostResult::Type::OK; if(response.find("banned") != std::string::npos) - return PostResult::BANNED; + return PostResult::Type::BANNED; if(response.find("mistyped the CAPTCHA") != std::string::npos || response.find("No valid captcha") != std::string::npos) - return PostResult::INVALID_CAPTCHA; + return PostResult::Type::INVALID_CAPTCHA; if(response.find("Audio streams are not allowed") != std::string::npos) - return PostResult::FILE_TYPE_NOT_ALLOWED; + return PostResult::Type::FILE_TYPE_NOT_ALLOWED; if(response.find("Error: Upload failed") != std::string::npos) - return PostResult::UPLOAD_FAILED; + return PostResult::Type::UPLOAD_FAILED; if(response.find("try again") != std::string::npos) - return PostResult::TRY_AGAIN; - - return PostResult::ERR; + return PostResult::Type::TRY_AGAIN; + + size_t errmsg_start = response.find("id=\"errmsg\""); + if(errmsg_start == std::string::npos) + return PostResult::Type::ERR; + + errmsg_start += 11; + errmsg_start = response.find('>', errmsg_start); + if(errmsg_start == std::string::npos) + return PostResult::Type::ERR; + + errmsg_start += 1; + const size_t errmsg_end = response.find('<', errmsg_start); + if(errmsg_end == std::string::npos) + return PostResult::Type::ERR; + + PostResult result(PostResult::Type::ERR); + result.err_msg = response.substr(errmsg_start, errmsg_end - errmsg_start); + html_unescape_sequences(result.err_msg); + return result; } const std::string& FourchanThreadPage::get_pass_id() { -- cgit v1.2.3