GSoC2k9 - Torbutton Feature Fulfillment - Kory Kirk
nsIProtocolHandler and nsIIOService correct implementation for Torbutton 
Tuesday, June 2, 2009, 03:19 PM
Posted by Administrator
Thanks to some direction from my mentor, Mike, I feel much more comfortable with this step of the project. I have rewritten the newURI and newChannel functions:

newURI: function(spec, charset, baseURI)
const nsIStandardURL = Components.interfaces.nsIStandardURL;
var uri = Components.classes[";1"].createInstance(nsIStandardURL);
uri.init(nsIStandardURL.URLTYPE_STANDARD, 80, spec, charset, baseURI);

return uri.QueryInterface(Components.interfaces.nsIURI);


newChannel: function(aURI)
/*The protocol has been called, therefore we want to enable tor, wait for it to activate return the new channel with the scheme of http.*/
var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);
if (!ios.allowPort(aURI.port, aURI.scheme))
throw Components.results.NS_ERROR_FAILURE;

//this is where I need to turn tor on, I am going to wait to talk to Mike a little to add these parts

//if tor is turned on then, else we should throw exception of some sort.
aURI.scheme = "http";
return ios.newChannelFromURI(aURI);

Instead of parsing the uri by hand, nsIStandarURL does that for us. The nsIURI MDC page says that the proper way to parse a uri is through the IOService function, newURI(), but that method just calls the newURI() function from the scheme's protocol handler, so it would have caused an infinite loop. The newChannel code is not finished, I want to learn a little bit more about the 3 step Tor activation process that Torbutton uses before I go ahead and fill that part in. But the channel just makes sure that the scheme allows the port, and then changes the scheme to http and creates the channel based upon that. I believe this will work, because the newChannelFromURI uses the newChannel method for the scheme's protocol handler - which in this case will be http.

The updates are reflected in

p.s. the format of that code is ugly, sorry
1 comment ( 19 views )

<<First <Back | 1 | 2 | Next> Last>>