summaryrefslogtreecommitdiffstats
path: root/fetcher
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2016-03-25 15:31:17 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2016-03-25 19:48:06 +0100
commit0d5c4e438e001ef21dfae69df4ae186b697d2efc (patch)
tree82e00390f6bac6fbcb1bb09479982167b5e792f4 /fetcher
parentf7520a8fe7191475668904f5f8c1816df25e2e5a (diff)
add basic basic auth support
Diffstat (limited to 'fetcher')
-rw-r--r--fetcher/feedfetcher.php21
-rw-r--r--fetcher/fetcher.php9
-rw-r--r--fetcher/ifeedfetcher.php6
-rw-r--r--fetcher/youtubefetcher.php9
4 files changed, 38 insertions, 7 deletions
diff --git a/fetcher/feedfetcher.php b/fetcher/feedfetcher.php
index 6b7460679..458f1220d 100644
--- a/fetcher/feedfetcher.php
+++ b/fetcher/feedfetcher.php
@@ -23,6 +23,8 @@ use PicoFeed\Client\InvalidUrlException;
use PicoFeed\Client\MaxRedirectException;
use PicoFeed\Client\MaxSizeException;
use PicoFeed\Client\TimeoutException;
+use PicoFeed\Client\ForbiddenException;
+use PicoFeed\Client\UnauthorizedException;
use OCP\IL10N;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -71,14 +73,24 @@ class FeedFetcher implements IFeedFetcher {
* no results are fetched
* @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
+ * @param string $basicAuthUser if given, basic auth is set for this feed
+ * @param string $basicAuthPassword if given, basic auth is set for this
+ * feed. Ignored if user is null or an empty string
* @throws FetcherException if it fails
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
public function fetch($url, $getFavicon=true, $lastModified=null,
- $etag=null, $fullTextEnabled=false) {
+ $etag=null, $fullTextEnabled=false,
+ $basicAuthUser=null, $basicAuthPassword=null) {
try {
- $resource = $this->reader->discover($url, $lastModified, $etag);
+ if ($basicAuthUser !== null && trim($basicAuthUser) !== '') {
+ $resource = $this->reader->discover($url, $lastModified, $etag,
+ $basicAuthUser,
+ $basicAuthPassword);
+ } else {
+ $resource = $this->reader->discover($url, $lastModified, $etag);
+ }
if (!$resource->isModified()) {
return [null, null];
@@ -131,6 +143,11 @@ class FeedFetcher implements IFeedFetcher {
$msg = $this->l10n->t('Bigger than maximum allowed size');
} else if ($ex instanceof TimeoutException) {
$msg = $this->l10n->t('Request timed out');
+ } else if ($ex instanceof UnauthorizedException) {
+ $msg = $this->l10n->t('Required credentials for feed were ' .
+ 'either missing or incorrect');
+ } else if ($ex instanceof ForbiddenException) {
+ $msg = $this->l10n->t('Forbidden to access feed');
}
throw new FetcherException($msg);
diff --git a/fetcher/fetcher.php b/fetcher/fetcher.php
index 4787ccfdd..43c9e7a3f 100644
--- a/fetcher/fetcher.php
+++ b/fetcher/fetcher.php
@@ -44,16 +44,21 @@ class Fetcher {
* no results are fetched
* @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
+ * @param string $basicAuthUser if given, basic auth is set for this feed
+ * @param string $basicAuthPassword if given, basic auth is set for this
+ * feed. Ignored if user is null or an empty string
* @throws FetcherException if simple pie fails
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
public function fetch($url, $getFavicon=true, $lastModified=null,
- $etag=null, $fullTextEnabled=false) {
+ $etag=null, $fullTextEnabled=false,
+ $basicAuthUser=null, $basicAuthPassword=null) {
foreach($this->fetchers as $fetcher){
if($fetcher->canHandle($url)){
return $fetcher->fetch($url, $getFavicon, $lastModified, $etag,
- $fullTextEnabled);
+ $fullTextEnabled, $basicAuthUser,
+ $basicAuthPassword);
}
}
diff --git a/fetcher/ifeedfetcher.php b/fetcher/ifeedfetcher.php
index 297885930..e854d83fe 100644
--- a/fetcher/ifeedfetcher.php
+++ b/fetcher/ifeedfetcher.php
@@ -27,12 +27,16 @@ interface IFeedFetcher {
* no results are fetched
* @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
+ * @param string $basicAuthUser if given, basic auth is set for this feed
+ * @param string $basicAuthPassword if given, basic auth is set for this
+ * feed. Ignored if user is null or an empty string
* @throws FetcherException if the fetcher encounters a problem
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
function fetch($url, $getFavicon=true, $lastModified=null, $etag=null,
- $fullTextEnabled=false);
+ $fullTextEnabled=false, $basicAuthUser=null,
+ $basicAuthPassword=null);
/**
* @param string $url the url that should be fetched
diff --git a/fetcher/youtubefetcher.php b/fetcher/youtubefetcher.php
index 35ecd80f0..3752ba197 100644
--- a/fetcher/youtubefetcher.php
+++ b/fetcher/youtubefetcher.php
@@ -55,16 +55,21 @@ class YoutubeFetcher implements IFeedFetcher {
* no results are fetched
* @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
+ * @param string $basicAuthUser if given, basic auth is set for this feed
+ * @param string $basicAuthPassword if given, basic auth is set for this
+ * feed. Ignored if user is null or an empty string
* @throws FetcherException if it fails
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
public function fetch($url, $getFavicon=true, $lastModified=null,
- $etag=null, $fullTextEnabled=false) {
+ $etag=null, $fullTextEnabled=false,
+ $basicAuthUser=null, $basicAuthPassword=null) {
$transformedUrl = $this->buildUrl($url);
$result = $this->feedFetcher->fetch(
- $transformedUrl, $getFavicon, $lastModified, $etag, $fullTextEnabled
+ $transformedUrl, $getFavicon, $lastModified, $etag,
+ $fullTextEnabled, $basicAuthUser, $basicAuthPassword
);
// reset feed url so we know the correct added url for the feed