aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Fourchan.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-06-16 05:53:18 +0200
committerdec05eba <dec05eba@protonmail.com>2022-06-16 05:53:18 +0200
commite471a1f93ee23f0f729d64068504cb892481b56f (patch)
treea75b0a9d5ff891b603096c75e07a2346801b70e2 /src/plugins/Fourchan.cpp
parent3586e3b510ef6828ab44dad1467f18ef4f2d7e2b (diff)
4chan: show error from server when posting fails (when error is not one of the predefined ones)
Diffstat (limited to 'src/plugins/Fourchan.cpp')
-rw-r--r--src/plugins/Fourchan.cpp37
1 files changed, 27 insertions, 10 deletions
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() {