aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Fourchan.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Fourchan.cpp')
-rw-r--r--src/plugins/Fourchan.cpp53
1 files changed, 34 insertions, 19 deletions
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp
index 84a0675..24886c6 100644
--- a/src/plugins/Fourchan.cpp
+++ b/src/plugins/Fourchan.cpp
@@ -503,6 +503,12 @@ namespace QuickMedia {
}
PostResult FourchanThreadPage::post_comment(const std::string &captcha_id, const std::string &captcha_solution, const std::string &comment, const std::string &filepath) {
+ Path cookies_filepath;
+ if(get_cookies_filepath(cookies_filepath, SERVICE_NAME) != 0) {
+ fprintf(stderr, "Failed to get 4chan cookies filepath\n");
+ return PostResult::ERR;
+ }
+
std::string url = "https://sys.4chan.org/" + board_id + "/post";
std::vector<CommandArg> additional_args = {
@@ -510,7 +516,9 @@ namespace QuickMedia {
CommandArg{"-H", "Origin: https://boards.4chan.org"},
CommandArg{"--form-string", "resto=" + thread_id},
CommandArg{"--form-string", "com=" + comment},
- CommandArg{"--form-string", "mode=regist"}
+ CommandArg{"--form-string", "mode=regist"},
+ CommandArg{"-c", cookies_filepath.data},
+ CommandArg{"-b", cookies_filepath.data}
};
if(!filepath.empty()) {
@@ -520,17 +528,7 @@ namespace QuickMedia {
if(pass_id.empty()) {
additional_args.push_back(CommandArg{"--form-string", "t-challenge=" + captcha_id});
- if(!captcha_solution.empty())
- additional_args.push_back(CommandArg{"--form-string", "t-response=" + captcha_solution});
- } else {
- Path cookies_filepath;
- if(get_cookies_filepath(cookies_filepath, SERVICE_NAME) != 0) {
- fprintf(stderr, "Failed to get 4chan cookies filepath\n");
- return PostResult::ERR;
- } else {
- additional_args.push_back(CommandArg{"-c", cookies_filepath.data});
- additional_args.push_back(CommandArg{"-b", cookies_filepath.data});
- }
+ additional_args.push_back(CommandArg{"--form-string", "t-response=" + captcha_solution});
}
std::string response;
@@ -541,8 +539,10 @@ namespace QuickMedia {
return PostResult::OK;
if(response.find("banned") != std::string::npos)
return PostResult::BANNED;
- if(response.find("try again") != std::string::npos || response.find("No valid captcha") != std::string::npos)
+ if(response.find("try again") != std::string::npos)
return PostResult::TRY_AGAIN;
+ if(response.find("No valid captcha") != std::string::npos)
+ return PostResult::INVALID_CAPTCHA;
if(response.find("Audio streams are not allowed") != std::string::npos)
return PostResult::FILE_TYPE_NOT_ALLOWED;
if(response.find("Error: Upload failed") != std::string::npos)
@@ -581,8 +581,19 @@ namespace QuickMedia {
}
PluginResult FourchanThreadPage::request_captcha_challenge(ImageBoardCaptchaChallenge &challenge_response) {
+ Path cookies_filepath;
+ if(get_cookies_filepath(cookies_filepath, SERVICE_NAME) != 0) {
+ fprintf(stderr, "Failed to get 4chan cookies filepath\n");
+ return PluginResult::ERR;
+ }
+
+ std::vector<CommandArg> additional_args = {
+ CommandArg{"-c", cookies_filepath.data},
+ CommandArg{"-b", cookies_filepath.data}
+ };
+
Json::Value json_root;
- DownloadResult result = download_json(json_root, "https://sys.4chan.org/captcha?board=" + url_param_encode(board_id) + "&thread_id=" + thread_id, {}, true);
+ DownloadResult result = download_json(json_root, "https://sys.4chan.org/captcha?board=" + url_param_encode(board_id) + "&thread_id=" + thread_id, std::move(additional_args), true);
if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
if(!json_root.isObject())
@@ -598,16 +609,20 @@ namespace QuickMedia {
const Json::Value &img_json = json_root["img"];
const Json::Value &bg_json = json_root["bg"];
const Json::Value &ttl_json = json_root["ttl"];
- if(!challenge_json.isString() || !img_json.isString())
+ if(!challenge_json.isString())
return PluginResult::ERR;
challenge_response.challenge_id = challenge_json.asString();
+ if(strcmp(challenge_json.asCString(), "noop") != 0) {
+ if(!img_json.isString())
+ return PluginResult::ERR;
- if(!base64_decode(img_json, challenge_response.img_data))
- return PluginResult::ERR;
+ if(!base64_decode(img_json, challenge_response.img_data))
+ return PluginResult::ERR;
- if(bg_json.isString() && !base64_decode(bg_json, challenge_response.bg_data))
- return PluginResult::ERR;
+ if(bg_json.isString() && !base64_decode(bg_json, challenge_response.bg_data))
+ return PluginResult::ERR;
+ }
if(ttl_json.isInt())
challenge_response.ttl = ttl_json.asInt();