There are no comments yet...Kick things off by filling out the form below.
Google Safe Browsing Library for .NET Beta 2
Last Friday I released the first Beta of my Google Safe Browsing API library for .NET with some limitations that I listed there.
During the last week I worked on this library to solve those limitation and improve the code and design and the result was what I'm now announcing as the Beta 2 with some major updates and bug fixes that can make the library much better and stable.
Phil's idea on having a single library to fight against spam and badware stuff in .NET applications was a great idea and I'm interested to help it as much as I can.
In my opinion .NET open source should move from writing many blogging engines or data and code generation applications to more specific projects that can be helpful for .NET developers. Subkismet is one of them and a unique project in .NET community.
What's New in Beta 2?
Last week I outlined some limitations with Beta 1 and stated that this version isn't appropriate for production and all its API is subject to change. For new Beta 2 version I added some new features:
- Data provider model is added. The new data provider model lets you implement your own data provider for storage system. Default provider which is included in the library is XML data provider and I may implement a SQL data provider for next versions as well.
- Ability to check single links and a list of links has been added to the API. Previously you could only check a comment as an IComment object in Subkismet library.
- You no longer need to pass your Google Safe Browsing API key or the path of XML files. This information can be set in configuration files.
- New API returns the number of phishing and malware links separately. Previously you just could get the number of all bad URLs.
- A fresh new unit testing project has been added. Some new tests have been written to improve the code. New project is built based on unit testing features in Visual Studio 2008 to solve some inconsistencies that I experienced when upgraded the solution from VS 2005 to 2008.
- XML code comments have been added to all code.
- Some bugs have been fixed.
Limitations
While these changes have made the library completely different from the Beta 1 but there are still four things that I need to pay attention to them for the final release:
- Normalizing IP addresses as a part of canonicalization process which isn't done yet. Actually I didn't care about this because in Subkismet we usually deal with online scenarios where we see IP addresses occasionally. However, now that this API has reached to a stable point I'd like to solve this one for the final version as well.
- Working more on exception handling. Currently this library doesn't catch some possible exceptions and I have to add some code to make this better.
- Testing the library with more sample data. So far I haven't put much effort into testing the library with real world data to see if it has any problem.
- Managing the update process. I haven't inserted any code to automatically update local data because I thought we need to do this based on user's choice. Since Subkismet is proposed for online scenarios it's better to avoid making this the default behavior and putting more pressure on the server but for final version I'll make it optional and will write a code that users can use to update their local black lists on a regular basis.
How to Use
However, the current version (Beta 2) is stable and most likely public API won't change after this. So you can feel free to use it. I updated the sample Windows Application included in the Subkismet solution to let you test the library and see how to use it in your own code. Now it's integrated with Phil's form and you can enjoy testing your data in a single Windows Form with Akismet implementation.
If you're looking for a sample code on how to use this library, here I give new samples to teach you the answer. If you compare this code with what I had provided for Beta 1, can believe the changes in the API.
First of all you need to add appropriate elements to your application configuration file (App.Config or Web.Config) to define your data provider and Google Safe Browsing API key.
Following is all the code that you need to add to your configuration files:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="GoogleSafeBrowsingProvider"
type="Subkismet.Services.GoogleSafeBrowsing.Provider.DataProviderConfiguration, Subkismet" />
</configSections>
<appSettings>
<add key="apiKey" value="ABQIAAAAHmeOB6h5POEjgHbmfLJGzxS6yEDbsEeEJ6eL17v7yJ9rbkUbMA"/>
</appSettings>
<GoogleSafeBrowsingProvider default="XmlProvider">
<providers>
<add name="XmlProvider"
type="Subkismet.Services.GoogleSafeBrowsing.Provider.XmlDataProvider, Subkismet"
phishingFilePath="C:\Data\phishing.xml"
malwareFilePath="C:\Data\malware.xml" />
</providers>
</GoogleSafeBrowsingProvider>
</configuration>
Here I defined the configuration section for my data provider and then inserted the Google Safe Browsing API key in <appSettings /> and added appropriate elements to declare my data provider and file paths. The default data provider is XmlProvider but you can implement your own provider as well.
After this, you just need to write a simple code to check your comments or links with local data.
To update a local black list, you need to create an instance of the GoogleSafeBrowsing class and call its UpdateList method by passing the appropriate list name.
private void btnGoogleSafeUpdate_Click(object sender, EventArgs e)
{
// Create an instance of the GoogleSafeBrowsing
GoogleSafeBrowsing gsb = new GoogleSafeBrowsing();
// Update phishing black list
gsb.UpdateList(BlackListType.Phishing);
// Update malware black list
gsb.UpdateList(BlackListType.Malware);
// Display the response
txtResponse.Text += "Update done!\n";
}
To check all links in a comment, you need to create an instance of the GoogleSafeBrowsing and call its CheckPost method by passing an IComment object and two out parameters that will be updated with the number of phishing and malware links respectively.
private void btnGoogleSafeCheck_Click(object sender, EventArgs e)
{
// Create an instance of the GoogleSafeBrowsing
GoogleSafeBrowsing gsb = new GoogleSafeBrowsing();
int phishingCount = 0;
int malwareCount = 0;
// Peform a check and get the number of bad URLs
gsb.CheckPost(GetComment(), out phishingCount, out malwareCount);
// Display the number of bad URLs
txtResponse.Text += string.Format("Phishing URLs: {0}\nMalware URLs: {1}\n",
phishingCount, malwareCount);
}
In new Beta 2 version you have two alternative approaches to check a single link or a list of links by passing their string values to CheckLink and CheckLinks methods. In this new version you can also enjoy the result of XML code comments as descriptions for classes, methods and their parameters that guide you.
Download
You can download the Beta 2 from the CodePlex workspace. I can consider change set 14737 as Beta 2.
Hopefully the next version will be the final version and as a part of a new version for Subkismet project. I'm going to ask Phil how should we release it, as a Beta or as a final version. I think we'll be able to release this version in next couple of weeks, though.
[advertisement] Axosoft OnTime 2008 is four developer tools in one: bug tracking, project wiki, feature management, and help desk. It manages your development process so developers can focus on coding. Installed or Hosted – Free Single-user license -- Free 30-day team trial.
No Comments : 12.28.07