
|
Home |
Download |
Getting Started |
Contact |
White Paper |
Examples |
Documentation |
Troubleshooting |
Newsgroup |
Mailing List |
Source Code |
Bugs |
Screenshots |
Protozilla: pipes, protocols, and P2P in Mozilla
(If you were directed to this page from a recent Slashdot discussion on Protozilla, you may want to check out a posting on the Protozilla newsgroup that addresses some of issues raised in that discussion.)Protozilla is a browser add-on that makes it very easy to implement protocols in Mozilla (or Netscape 6.x). It is not a traditional browser plugin, but may be described as a "socket adapter", like the kind that you may carry around with your laptop when you travel internationally. With Protozilla, implementing a new protocol becomes as easy as typing a one line URL prefix, or dragging-and-dropping a file. Protozilla enables any CGI program or Unix/MSDOS command line program to instantly become a Mozilla "plugin" with little or no modification. These external programs, which may be written in any language, communicate with Mozilla through their standard input/output and the environment variables.
Before you begin to wonder why anyone would want to do this, here are some applications: interprocess communication, client-side CGI, protocol handlers, and peer-to-peer applications. (See the Examples and Documentation pages for more information on using Protozilla.)
- Interprocess communication (IPC): Protozilla makes stateless IPC
very easy in Mozilla. Privileged Javascript can execute any command line
program with arguments and retrieve the output as a string. This is like
the `backtick` operator in shell/Perl scripts, or like the IPC::Open2 Perl
module. For example, Mozilla could use an external XSL filter program to
process XML data and display HTML output. Another example would be to
invoke the GnuPG program to access the user's public key ring. Along with
the I/O functions available through the "io.js" package, this feature could
turn Javascript into a viable shell scripting language!
- Client-side CGI: Protozilla enables Mozilla to execute any CGI
program on the local disk directly, without passing it through an HTTP
server. One can think of this feature as "client-side CGI" as opposed to
the usual server-side CGI. This feature may be useful for testing CGI
programs, or for implementing applications that use Mozilla as a UI
platform, rather than as a HTTP client. For example, if you have a Perl
script that parses your e-mail, you could choose to have it display its
output in the browser. In addition to the usual scripting languages,
Protozilla can also execute Javascript CGI programs.
- Protocol handlers: Protozilla takes care of the details of
registering any external program as a Mozilla protocol handler, if
necessary. For example, the "finger" protocol may be implemented using a
one line script (provided the corresponding corresponding command line
client is available). Protocols may also be implemented through simple URL
re-direction. This allows the user to easily implement special-purpose
protocols for personal use.
- Peer-to-peer (P2P) URLs: Seamless access to P2P protocols through the familiar browser interface should make them much more accessible to the end-user. Not only will the the user be able to access the protocols by typing a P2P URL in the URL bar, but the clickable P2P URLs may also be embedded in e-mail messages and other documents and exchanged just like HTTP or FTP URLs. Protozilla enables clients for P2P protocols to be implemented trivially in Mozilla.
Here is a brief technical overview of Protozilla: Mozilla communicates with the outside world using TCP sockets and multi-threaded asynchronous I/O. What Protozilla does is to execute an external program as a separate process, but makes it appear to Mozilla like a TCP socket. Protozilla communicates with the process using pipes and synchronous I/O, but uses asynchronous I/O to communicate with the rest of Mozilla. The core portion of Protozilla, which deals with pipes and IPC, is an XPCOM component written in C++. It provides an interface called nsIPipeTransport similar to the nsISocketTransport interface for sockets. The rest of Protozilla, dealing with protocols, is implemented as a Javascript component. (At present, the C++ portion of Protozilla has been tested on Unix/Linux and Windows platforms only.)
Of course, an out-of-process implementation of a protocol is not going to be as efficient as a multi-threaded, in-process implementation. But there is a trade-off between efficiency and ease of implementation. Protozilla is better suited for experimental protocol implementations, rather than for mature protocols. Out-of-process CGI execution is considered a *bad* thing on an HTTP server with a large number of users, but it is not as serious a performance issue on a client that is serving just one user. An out-of-process implementation does have one advantage though--if an experimental protocol implementation hangs or crashes, it will not drag the rest of the browser down with it!