From 180b7d3703d8f3a275629ecb5b0ec26db2ea1d9a Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sat, 6 May 2023 01:23:23 +0200 Subject: [PATCH] FeedReader: Added process of response code 403 and added user agent --- .../FeedReader/gui/FeedReaderStringDefs.cpp | 3 ++ plugins/FeedReader/interface/rsFeedReader.h | 1 + plugins/FeedReader/lang/FeedReader_en.ts | 29 +++++++++++-------- .../FeedReader/services/p3FeedReaderThread.cc | 3 ++ plugins/FeedReader/util/CURLWrapper.cpp | 4 +++ 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/plugins/FeedReader/gui/FeedReaderStringDefs.cpp b/plugins/FeedReader/gui/FeedReaderStringDefs.cpp index 647c4cf7b..07f0d44ab 100644 --- a/plugins/FeedReader/gui/FeedReaderStringDefs.cpp +++ b/plugins/FeedReader/gui/FeedReaderStringDefs.cpp @@ -101,6 +101,9 @@ QString FeedReaderStringDefs::errorString(RsFeedReaderErrorState errorState, con case RS_FEED_ERRORSTATE_DOWNLOAD_UNKOWN_RESPONSE_CODE: errorText = QApplication::translate("FeedReaderStringDefs", "Unknown response code"); break; + case RS_FEED_ERRORSTATE_DOWNLOAD_BLOCKED: + errorText = QApplication::translate("FeedReaderStringDefs", "Download blocked"); + break; /* process */ case RS_FEED_ERRORSTATE_PROCESS_INTERNAL_ERROR: diff --git a/plugins/FeedReader/interface/rsFeedReader.h b/plugins/FeedReader/interface/rsFeedReader.h index ad1ecec9a..044dcdd80 100644 --- a/plugins/FeedReader/interface/rsFeedReader.h +++ b/plugins/FeedReader/interface/rsFeedReader.h @@ -43,6 +43,7 @@ enum RsFeedReaderErrorState { RS_FEED_ERRORSTATE_DOWNLOAD_UNKNOWN_CONTENT_TYPE = 3, RS_FEED_ERRORSTATE_DOWNLOAD_NOT_FOUND = 4, RS_FEED_ERRORSTATE_DOWNLOAD_UNKOWN_RESPONSE_CODE = 5, + RS_FEED_ERRORSTATE_DOWNLOAD_BLOCKED = 6, /* process */ RS_FEED_ERRORSTATE_PROCESS_INTERNAL_ERROR = 50, diff --git a/plugins/FeedReader/lang/FeedReader_en.ts b/plugins/FeedReader/lang/FeedReader_en.ts index 93db4a686..db5748893 100644 --- a/plugins/FeedReader/lang/FeedReader_en.ts +++ b/plugins/FeedReader/lang/FeedReader_en.ts @@ -9,7 +9,7 @@ - + Board @@ -34,7 +34,7 @@ - + Authentication (not yet supported) @@ -84,12 +84,12 @@ - + Embed images - + Storage time @@ -124,7 +124,7 @@ - + Type @@ -139,7 +139,7 @@ - + Transformation @@ -154,7 +154,7 @@ - + Misc @@ -169,17 +169,17 @@ - + Update forum information - + Save complete web page (experimental for local feeds) - + Description: @@ -714,12 +714,12 @@ - + Unknown - + Internal download error @@ -743,6 +743,11 @@ Unknown response code + + + Download blocked + + Internal process error diff --git a/plugins/FeedReader/services/p3FeedReaderThread.cc b/plugins/FeedReader/services/p3FeedReaderThread.cc index 00da7a007..1c8714a05 100644 --- a/plugins/FeedReader/services/p3FeedReaderThread.cc +++ b/plugins/FeedReader/services/p3FeedReaderThread.cc @@ -302,6 +302,9 @@ RsFeedReaderErrorState p3FeedReaderThread::download(const RsFeedReaderFeed &feed } } break; + case 403: + result = RS_FEED_ERRORSTATE_DOWNLOAD_BLOCKED; + break; case 404: result = RS_FEED_ERRORSTATE_DOWNLOAD_NOT_FOUND; break; diff --git a/plugins/FeedReader/util/CURLWrapper.cpp b/plugins/FeedReader/util/CURLWrapper.cpp index 87fd986ff..94ae7beaa 100644 --- a/plugins/FeedReader/util/CURLWrapper.cpp +++ b/plugins/FeedReader/util/CURLWrapper.cpp @@ -21,6 +21,8 @@ #include "CURLWrapper.h" #include +#define USERAGENT "Mozilla/5.0 (rv:109.0) Gecko/20100101 Firefox/112.0" + CURLWrapper::CURLWrapper(const std::string &proxy) { mCurl = curl_easy_init(); @@ -65,6 +67,7 @@ CURLcode CURLWrapper::downloadText(const std::string &link, std::string &data) curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, writeFunctionString); curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, &data); curl_easy_setopt(mCurl, CURLOPT_SSL_VERIFYPEER, false); + curl_easy_setopt(mCurl, CURLOPT_USERAGENT, USERAGENT); return curl_easy_perform(mCurl); } @@ -95,6 +98,7 @@ CURLcode CURLWrapper::downloadBinary(const std::string &link, std::vector