I'm Keyvan Nayyeri, a 25 years old Ph.D. student at
the Computer Science department of
the University of Texas at San Antonio.
I'm also
a Software Architect and Developer and previously held a B.Sc.
degree in Applied Mathematics.
This is my blog where I publish content about various topics specifically Programming Languages and Compilers, Software
Engineering and Programming.
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.
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:
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:
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.
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.
Leave a Comment