// // BugzillaDriver.cs // // Copyright (C) 2004 Novell, Inc. // // // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // using System; using System.Collections; using System.IO; using System.Xml; using System.Runtime.InteropServices; using System.Net; using System.Text.RegularExpressions; using Beagle.Util; namespace Beagle.Daemon { [QueryableFlavor (Name="Bugzilla", Domain=QueryDomain.Global, RequireInotify=false)] public class BugzillaDriver : IQueryable { private string bugzilla_host = "http://bugzilla.ximian.com"; int maxResults = 5; public BugzillaDriver () { } public string Name { get { return "Bugzilla"; } } public void Start () { } public bool AcceptQuery (Query query) { if (query.IsEmpty) return false; return true; } public void DoQuery (Query query, IQueryResult result, IQueryableChangeData changeData) { Logger.Log.Debug ("Kicking off a bugzilla query"); // FIXME - hard coding the url here XmlDocument xml = GetBugzillaXml (query.QuotedText); if (xml != null) { Hit hit = XmlBugToHit (xml, query.QuotedText); if (hit != null) result.Add (hit); } } public string GetSnippet (string[] query_terms, Hit hit) { return null; } private XmlDocument GetBugzillaXml (string bug) { // Confirm that the text we have been passed looks // like a bug ID (i.e. is numeric) Regex bugregex = new Regex ("[0-9]+", RegexOptions.Compiled); if (!bugregex.Match (bug).Success) { return null; } XmlDocument xml = new XmlDocument (); HttpWebRequest req = (HttpWebRequest) WebRequest.Create (String.Format ("{0}/xml.cgi?id={1}", bugzilla_host, bug)); req.UserAgent = "Beagle"; StreamReader input; try { WebResponse resp = req.GetResponse (); input = new StreamReader (resp.GetResponseStream ()); } catch { return null; } string bugxml; try { bugxml = input.ReadToEnd (); } catch { return null; } Logger.Log.Debug (bugxml); int startidx = bugxml.IndexOf ("