Пример #1
0
        private void OnLinkTag(HTMLParser instance, string tag)
        {
            HashMap attrMap = instance.ParseAttributes(tag);

            if ((string)attrMap ["rel"] == "alternate" &&
                ((string)attrMap ["type"] == "application/rss+xml" || (string)attrMap ["type"] == "application/atom+xml"))
            {
                string href = (string)attrMap ["href"];
                if (href != null)
                {
                    string url;
                    try
                    {
                        url = new Uri(_baseUri, href).ToString();
                    }
                    catch (UriFormatException)
                    {
                        return;
                    }
                    if (!HttpReader.IsSupportedProtocol(url))
                    {
                        return;
                    }
                    _candidateURLs.Push(10, url);
                    _candidateURLSet.Add(url);
                    _candidateHintTexts [url] = attrMap ["title"];
                }
            }
        }
Пример #2
0
        private void OnDownloadClick()
        {
            _feedAddressPane.SetExistingFeedLink(null);
            if (File.Exists(_feedAddressPane.FeedUrl))
            {
                _feedAddressPane.FeedUrl = "file://" + _feedAddressPane.FeedUrl;
            }
            else
            if (_feedAddressPane.FeedUrl.IndexOf("://") < 0)
            {
                _feedAddressPane.FeedUrl = "http://" + _feedAddressPane.FeedUrl;
            }
            else
            {
                string url = _feedAddressPane.FeedUrl.ToLower();
                if (!HttpReader.IsSupportedProtocol(url))
                {
                    _feedAddressPane.ErrorMessage = "Unknown URL schema. Only http:, https: and file: are supported.";
                    return;
                }
            }

            try
            {
                new Uri(_feedAddressPane.FeedUrl);
            }
            catch (Exception ex)
            {
                _feedAddressPane.ErrorMessage = ex.Message;
                return;
            }

            IResource existingFeed = RSSPlugin.GetExistingFeed(_feedAddressPane.FeedUrl);

            if (existingFeed != null)
            {
                _feedAddressPane.ErrorMessage = "You are already subscribed to that feed.";
                _feedAddressPane.SetExistingFeedLink(existingFeed);
                return;
            }

            _progressLabel.Text = "Downloading...";
            _nextButton.Enabled = false;
            _feedAddressPane.ControlsEnabled = false;

            if (_newFeedProxy != null)
            {
                _newFeedProxy.DeleteAsync();
                _newFeedProxy = null;
            }

            _newFeedProxy = CreateFeedProxy(_feedAddressPane.FeedUrl, null);

            _rssUnitOfWork = new RSSUnitOfWork(_newFeedProxy.Resource, false, true);
            _rssUnitOfWork.DownloadProgress += OnDownloadProgress;
            _rssUnitOfWork.ParseDone        += OnParseDone;
            Core.NetworkAP.QueueJob(JobPriority.Immediate, _rssUnitOfWork);
        }
Пример #3
0
        public RSSUnitOfWork(IResource feed, bool parseItems, bool acceptHtmlIfXmlError)
        {
            Trace.WriteLineIf(Settings.Trace, "Starting update of feed " + feed.DisplayName);
            _feed                 = feed;
            _parseItems           = parseItems;
            _acceptHtmlIfXmlError = acceptHtmlIfXmlError;
            _statusWriter         = Core.UIManager.GetStatusWriter(this, StatusPane.Network);

            string feedUrl = feed.GetStringProp(Props.URL);

            if (!HttpReader.IsSupportedProtocol(feedUrl))
            {
                throw new ArgumentException("Unsupported feed protocol: " + feedUrl);
            }
            if (parseItems)
            {
                FavIconManager favIconManager = (FavIconManager)Core.GetComponentImplementation(typeof(FavIconManager));
                favIconManager.DownloadFavIcon(feedUrl);
            }
            _httpReader = new HttpReader(feedUrl);

            string etag = feed.GetPropText(Props.ETag);

            if (etag.Length > 0)
            {
                _httpReader.IfNoneMatch = etag;
            }

            string httpUserName = feed.GetStringProp(Props.HttpUserName);
            string httpPassword = feed.GetStringProp(Props.HttpPassword);

            if (httpUserName != null && httpPassword != null)
            {
                _httpReader.Credentials = new NetworkCredential(httpUserName, httpPassword);
            }

            _httpReader.AcceptInstanceManipulation = "feed";

            if (_feed.HasProp(Props.DisableCompression) || Settings.DisableCompression)
            {
                _httpReader.AcceptEncoding = null;
            }

            _httpReader.CookieProvider = CookiesManager.GetUserCookieProvider(typeof(RSSUnitOfWork));

            _status = RSSWorkStatus.NotStarted;

            Timeout    = Settings.TimeoutInSec * 1000;
            OnTimeout += RSSUnitOfWork_OnTimeout;
        }
Пример #4
0
        private void QueueFeedUpdate(IResource feed, int attempt, JobPriority jobPriority)
        {
            if (feed.Type != "RSSFeed")
            {
                throw new ArgumentException("Invalid resource type for QueueFeedUpdate: " + feed.Type);
            }

            if (!HttpReader.IsSupportedProtocol(feed.GetPropText(Props.URL)))
            {
                return;
            }

            //  Do not update feeds which were manually set into
            //  hybernating state.
            if (feed.HasProp(Props.IsPaused))
            {
                return;
            }

            lock (this)
            {
                if (_updatingCount >= _maxCount)
                {
                    _pendingFeeds.Push((int)jobPriority, new PendingFeed(feed, attempt));
                }
                else
                {
                    RSSUnitOfWork uow = new RSSUnitOfWork(feed, true, false);
                    uow.Attempts   = attempt;
                    uow.ParseDone += new EventHandler(OnRSSParseDone);
                    Core.NetworkAP.QueueJob(jobPriority, uow);
                    _updatingCount++;
                }
            }
            if (feed.HasProp(Props.AutoUpdateComments))
            {
                foreach (IResource commentFeed in feed.GetLinksTo(null, Props.FeedComment2Feed))
                {
                    if (NeedUpdate(commentFeed))
                    {
                        QueueFeedUpdate(commentFeed);
                    }
                }
            }
        }
Пример #5
0
        private void OnATag(HTMLParser instance, string tag)
        {
            if (instance.InScript)
            {
                return;
            }

            HashMap attrMap = instance.ParseAttributes(tag);
            string  href    = (string)attrMap ["href"];

            if (href == null)
            {
                return;
            }

            if (href.StartsWith("feed:"))
            {
                href = "http:" + href.Substring(5);
            }

            Uri hrefUri;

            try
            {
                hrefUri = new Uri(_baseUri, href);
            }
            catch (Exception)
            {
                // sometimes generic exceptions are thrown from Uri constructor (see OM-9323)
                return;
            }

            string hrefUriString;

            try
            {
/*
 *              OM-12523.
 *              System.UriFormatException: Invalid URI: The hostname could not be parsed.
 *              at System.Uri.CreateHostStringHelper(String str, UInt16 idx, UInt16 end, Flags& flags, String& scopeId)
 *              at System.Uri.CreateHostString()
 *              at System.Uri.EnsureHostString(Boolean allowDnsOptimization)
 *              at System.Uri.GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat)
 *              at System.Uri.ToString()
 */
                hrefUriString = hrefUri.ToString();
            }
            catch (System.UriFormatException)
            {
                return;
            }

            if (!HttpReader.IsSupportedProtocol(hrefUriString))
            {
                return;
            }

            bool sameServer = (String.Compare(_baseUri.Host, hrefUri.Host, true) == 0);

            int    pos      = href.LastIndexOf(".");
            string ext      = (pos < 0) ? "" : href.Substring(pos).ToLower();
            int    priority = 0;

            if (ext == ".rss" || ext == ".rdf" || ext == ".xml")
            {
                priority = sameServer ? 9 : 7;
            }
            else
            {
                href = href.ToLower();
                if (href.IndexOf("rss") >= 0 || href.IndexOf("rdf") >= 0 || href.IndexOf("xml") >= 0)
                {
                    priority = sameServer ? 8 : 6;
                }
            }
            if (priority != 0)
            {
                if (!_candidateURLSet.Contains(hrefUriString))
                {
                    _lastCandidateURL = hrefUriString;
                    _candidateURLSet.Add(_lastCandidateURL);
                    _candidateURLs.Push(priority, _lastCandidateURL);
                }
            }
        }