-- CHATZILLA CHANGES ONLY --

* connection-rhino.js
formatting changes.

* connection-xpcom.js
Necko-only implementation courtesy peter.vanderbeken@pandora.be.

* irc.js
Fixed bug in error message.

* munger.js
Added ability to temporarily disable all rules.

* test3-handlers.js
not-implemented placeholder function.
hide, delete, and clear current view functions.
munger-toggle function.

* test3-static.js
disable munger by default.
fix rheet regex.
deleteToolbutton function.

* test3.xul
xul hookup for new functions.
This commit is contained in:
rginda%netscape.com 2000-01-07 05:15:32 +00:00
parent fdf869afbc
commit 19e2cc1648
9 changed files with 326 additions and 147 deletions

View File

@ -35,65 +35,66 @@
function CBSConnection ()
{
this._socket = null;
this._socket = null;
}
CBSConnection.prototype.connect = function(host, port, bind, tcp_flag)
{
if (typeof tcp_flag == "undefined")
tcp_flag = false;
this.host = host;
this.port = port;
this.bind = bind;
this.tcp_flag = tcp_flag;
this._socket = new java.net.Socket(host, port);
this._inputStream = new java.io.DataInputStream(this._socket.getInputStream());
this._outputStream = this._socket.getOutputStream();
print("connected to " + host);
if (typeof tcp_flag == "undefined")
tcp_flag = false;
this.host = host;
this.port = port;
this.bind = bind;
this.tcp_flag = tcp_flag;
this._socket = new java.net.Socket(host, port);
this._inputStream =
new java.io.DataInputStream(this._socket.getInputStream());
this._outputStream = this._socket.getOutputStream();
dd("connected to " + host);
this.isConnected = true;
this.isConnected = true;
return this.isConnected;
return this.isConnected;
}
CBSConnection.prototype.disconnect = function()
{
if (this.isConnected) {
this.isConnected = false;
if (this.isConnected) {
this.isConnected = false;
this._socket.close();
delete this._socket;
delete this._inputStream;
delete this._outputStream;
}
delete this._socket;
delete this._inputStream;
delete this._outputStream;
}
}
CBSConnection.prototype.sendData = function(str)
{
if (!this.isConnected)
throw "Not Connected.";
if (!this.isConnected)
throw "Not Connected.";
var rv = false;
var rv = false;
try
{
this._outputStream.write(str.getBytes());
rv = true;
}
catch (ex)
{
if (typeof ex != "undefined")
{
this.isConnected = false;
throw (ex);
}
else
rv = false;
}
return rv;
try
{
this._outputStream.write(str.getBytes());
rv = true;
}
catch (ex)
{
if (typeof ex != "undefined")
{
this.isConnected = false;
throw (ex);
}
else
rv = false;
}
return rv;
}
CBSConnection.prototype.readData = function(timeout)
@ -101,13 +102,20 @@ CBSConnection.prototype.readData = function(timeout)
if (!this.isConnected)
throw "Not Connected.";
var rv;
var rv;
dd ("readData: timeout " + timeout);
try {
// FIXME: how to do a timeout.
rv = this._inputStream.readLine();
this._socket.setSoTimeout(Number(timeout));
rv = this._inputStream.read();
} catch (ex) {
if (typeof ex != "undefined") {
if ((typeof ex != "undefined") &&
(ex.indexOf("java.io.InterruptedIOException") != -1))
{
dd ("throwing " + ex);
this.isConnected = false;
throw (ex);
} else {
@ -115,5 +123,7 @@ CBSConnection.prototype.readData = function(timeout)
}
}
dd ("readData: rv = '" + rv + "'");
return rv;
}

View File

@ -22,7 +22,7 @@
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*
* Peter Van der Beken, peter.vanderbeken@pandora.be, necko-only version
*
* depends on utils.js, XPCOM, and the XPCOM component
* component://misc/bs/connection
@ -33,51 +33,87 @@
*
*/
function toScriptableInputStream (i)
{
var si = Components.classes["component://netscape/scriptableinputstream"];
si = si.createInstance();
si = si.QueryInterface(Components.interfaces.nsIScriptableInputStream);
si.init(i);
return si;
}
function CBSConnection ()
{
this._bsc = newObject ("component://misc/bs/connection", "bsIConnection");
if (!this._bsc)
throw ("Error Creating component://misc/bs/connection");
var sockServiceClass =
Components.classesByID["{c07e81e0-ef12-11d2-92b6-00105a1b0d64}"];
if (!sockServiceClass)
throw ("Couldn't get socket service class.");
var sockService = sockServiceClass.getService();
if (!sockService)
throw ("Couldn't get socket service.");
this._sockService = sockService.QueryInterface
(Components.interfaces.nsISocketTransportService);
}
CBSConnection.prototype.connect =
function bs_connect (host, port, bind, tcp_flag)
CBSConnection.prototype.connect = function(host, port, bind, tcp_flag)
{
if (typeof tcp_flag == "undefined")
tcp_flag = false;
tcp_flag = false;
this._bsc.init (host);
this.host = host;
this.port = port;
this.bind = bind;
this.tcp_flag = tcp_flag;
this.isConnected = this._bsc.connect (port, bind, tcp_flag);
this._channel = this._sockService.createTransport (host, port, host, 0, 0);
if (!this._channel)
throw ("Error opening channel.");
this._inputStream =
toScriptableInputStream(this._channel.openInputStream (0, 0));
if (!this._inputStream)
throw ("Error getting input stream.");
this._outputStream = this._channel.openOutputStream(0);
if (!this._outputStream)
throw ("Error getting output stream.");
this.isConnected = true;
return this.isConnected;
}
CBSConnection.prototype.disconnect =
function bs_disconnect ()
CBSConnection.prototype.disconnect = function()
{
this.isConnected = false;
return this._bsc.disconnect();
if (this.isConnected) {
this.isConnected = false;
this._inputStream.Close();
this._outputStream.Close();
}
}
CBSConnection.prototype.sendData =
function bs_send (str)
CBSConnection.prototype.sendData = function(str)
{
if (!this.isConnected)
throw "Not Connected.";
var rv = false;
try
{
var rv = this._bsc.sendData (str);
this._outputStream.Write(str, str.length);
rv = true;
}
catch (ex)
{
@ -87,35 +123,34 @@ function bs_send (str)
throw (ex);
}
else
var rv = false;
rv = false;
}
return rv;
}
CBSConnection.prototype.readData = function(timeout)
{
if (!this.isConnected)
throw "Not Connected.";
var rv, av;
try {
av = this._inputStream.available();
if (av)
rv = this._inputStream.read (av);
else
rv = "";
} catch (ex) {
dd ("*** Caught " + ex + " while reading.")
if (typeof ex != "undefined") {
this.isConnected = false;
throw (ex);
} else {
rv = "";
}
}
return rv;
}
CBSConnection.prototype.readData =
function bs_read (timeout)
{
if (!this.isConnected)
throw "Not Connected.";
try
{
var rv = this._bsc.readData(timeout);
}
catch (ex)
{
if (typeof ex != "undefined")
{
this.isConnected = false;
throw (ex);
}
else
var rv = "";
}
return rv;
}

View File

@ -178,8 +178,8 @@ function ep_routeevent (e)
catch (ex)
{
dd ("Error routing event: " + ex + " in " + e.destMethod);
}
if (count++ > this.MAX_EVENT_DEPTH)
throw "Too many events in chain";
break;

View File

@ -429,8 +429,8 @@ function serv_poll(e)
}
catch (ex)
{
dd ("** Caught exception " + ex + " reading from server " +
this.connection.name);
dd ("*** Caught exception " + ex + " reading from server " +
this.connection.host);
if (typeof ex != "undefined")
{
var ev = new CEvent ("server", "disconnect", this,

View File

@ -6,9 +6,9 @@ function CMungerEntry (name, regex, className, tagName)
if (regex instanceof RegExp)
this.regex = regex;
else
else
this.lambdaMatch = regex;
if (typeof className == "function")
this.lambdaReplace = className;
else
@ -23,6 +23,8 @@ function CMunger ()
}
CMunger.prototype.enabled = true;
CMunger.prototype.addRule =
function mng_addrule (name, regex, className)
{
@ -47,56 +49,62 @@ function mng_munge (text, containerTag, eventDetails)
if (!containerTag)
containerTag = document.createElement (tagName);
for (entry in this.entries)
if (this.enabled)
{
if (typeof this.entries[entry].lambdaMatch == "function")
for (entry in this.entries)
{
var rval;
rval = this.entries[entry].lambdaMatch(text, containerTag,
eventDetails,
this.entries[entry]);
if (rval)
ary = [(void 0), rval];
else
ary = null;
}
else
ary = text.match(this.entries[entry].regex);
if (ary != null)
{
var startPos = text.indexOf(ary[1]);
if (typeof this.entries[entry].lambdaReplace == "function")
if (typeof this.entries[entry].lambdaMatch == "function")
{
this.munge (text.substr(0,startPos), containerTag,
eventDetails);
this.entries[entry].lambdaReplace (ary[1], containerTag,
eventDetails,
this.entries[entry]);
this.munge (text.substr (startPos + ary[1].length, text.length),
containerTag, eventDetails);
var rval;
return containerTag;
rval = this.entries[entry].lambdaMatch(text, containerTag,
eventDetails,
this.entries[entry]);
if (rval)
ary = [(void 0), rval];
else
ary = null;
}
else
ary = text.match(this.entries[entry].regex);
if ((ary != null) && (ary[1]))
{
this.munge (text.substr(0,startPos), containerTag, eventDetails);
var startPos = text.indexOf(ary[1]);
if (typeof this.entries[entry].lambdaReplace == "function")
{
this.munge (text.substr(0,startPos), containerTag,
eventDetails);
this.entries[entry].lambdaReplace (ary[1], containerTag,
eventDetails,
this.entries[entry]);
this.munge (text.substr (startPos + ary[1].length,
text.length), containerTag,
eventDetails);
return containerTag;
}
else
{
this.munge (text.substr(0,startPos), containerTag,
eventDetails);
var subTag = document.createElement
(this.entries[entry].tagName);
var subTag = document.createElement
(this.entries[entry].tagName);
subTag.setAttribute ("class", this.entries[entry].className);
subTag.appendChild (document.createTextNode (ary[1]));
containerTag.appendChild (subTag);
this.munge (text.substr (startPos + ary[1].length,
text.length), containerTag,
eventDetails);
subTag.setAttribute ("class", this.entries[entry].className);
subTag.appendChild
(document.createTextNode (ary[1]));
containerTag.appendChild (subTag);
this.munge (text.substr (startPos + ary[1].length, text.length),
containerTag, eventDetails);
return containerTag;
return containerTag;
}
}
}
}
}
containerTag.appendChild (document.createTextNode (text));

View File

@ -85,7 +85,7 @@
<address><a href="mailto:rginda@ndcico.com"></a></address>
<!-- Created: Wed Aug 25 01:43:14 DST 1999 -->
<!-- hhmts start -->
Last modified: Mon Sep 13 23:21:35 XXX 1999
Last modified: Sat Dec 18 05:27:43 XXX 1999
<!-- hhmts end -->
</body>
</html>

View File

@ -38,7 +38,14 @@ function onLoad()
function onUnload()
{
client.quit ("ChatZilla!");
client.quit ("ChatZilla! [" + navigator.userAgent + "]");
}
function onNotImplemented()
{
alert ("'We're accepting patches'");
}
@ -76,6 +83,57 @@ function onDoStyleChange (newStyle)
}
function onHideCurrentView()
{
var tb = getTBForObject(client.currentObject);
if (tb)
if (deleteToolbutton (tb))
setCurrentObject (client);
}
function onClearCurrentView()
{
if (client.output.firstChild)
client.output.removeChild (client.output.firstChild);
delete client.currentObject.messages;
client.currentObject.display ("Messages Cleared.", "INFO");
client.output.appendChild (client.currentObject.messages);
}
function onDeleteCurrentView()
{
var tb = getTBForObject(client.currentObject);
if (tb)
{
if (deleteToolbutton (tb))
{
delete client.currentObject.messages;
setCurrentObject (client);
}
}
}
function onToggleMunger()
{
client.munger.enabled = !client.munger.enabled;
if (client.munger.enabled)
alert ("The munger may be broken, see " +
"http://bugzilla.mozilla.org/show_bug.cgi?id=22048");
document.getElementById("menu-munger").setAttribute ("checked",
client.munger.enabled);
}
function onInputKeyUp (e)
{
@ -774,6 +832,22 @@ function my_whoisreply (e)
}
CIRCNetwork.prototype.on433 = /* nickname in use */
function my_433 (e)
{
e.server.parent.display ("The nickname '" + e.params[2] +
"' is already in use.", e.code);
}
CIRCNetwork.prototype.onError =
function my_netping (e)
{
e.server.parent.display (e.meat, "ERROR");
}
CIRCNetwork.prototype.onPing =
function my_netping (e)

View File

@ -50,6 +50,7 @@ client.lastListType = "chan-users";
client.inputHistory = new Array();
client.lastHistoryReferenced = -1;
client.incompleteLine = "";
client.isPermanent = true;
CIRCNetwork.prototype.INITIAL_NICK = "IRCMonkey";
CIRCNetwork.prototype.INITIAL_NAME = "chatzilla";
@ -110,8 +111,8 @@ function initHost(obj)
obj.eventPump = new CEventPump (10);
obj.networks["efnet"] =
new CIRCNetwork ("efnet", [{name: "irc.freei.net", port: 6667},
{name: "irc.primenet.com", port: 6667},
new CIRCNetwork ("efnet", [{name: "irc.magic.ca", port: 6667},
{name: "irc.freei.net", port: 6667},
{name: "irc.cs.cmu.edu", port: 6667}],
obj.eventPump);
obj.networks["moznet"] =
@ -132,6 +133,7 @@ function initHost(obj)
false /* disable */);
obj.munger = new CMunger();
obj.munger.enabled = false;
obj.munger.addRule ("you-talking-to-me?", matchMyNick, "");
obj.munger.addRule
("link", /((http|mailto|ftp)\:\/\/[^\)\s]*|www\.\S+\.\S[^\)\s]*)/,
@ -140,7 +142,7 @@ function initHost(obj)
("face",
/((^|\s)[\<\>]?[\;\=\:\8]\~?[\-\^\v]?[\)\|\(pP\<\>oO0\[\]\/\\](\s|$))/,
insertSmiley);
obj.munger.addRule ("rheet", /(rhe+t\!*)/i, "rheet");
obj.munger.addRule ("rheet", /(rhee+t\!*)/i, "rheet");
obj.munger.addRule ("bold", /(\*.*\*)/, "bold");
obj.munger.addRule ("italic", /[^sS](\/.*\/)/, "italic");
obj.munger.addRule ("teletype", /(\|.*\|)/, "teletype");
@ -186,8 +188,9 @@ function insertLink (matchText, containerTag)
function insertSmiley (emoticon, containerTag)
{
var src = "";
dd ("arguments: " + emoticon + ", " + containerTag);
var src = "";
if (emoticon.search (/\;[\-\^\v]?[\)\>\]]/) != -1)
src = "face-wink.gif";
@ -582,6 +585,39 @@ function getTBForObject (source, create)
}
function deleteToolbutton (tb)
{
var i, key = Number(tb.getAttribute("viewKey"));
if (!isNaN(key))
{
if (!client.viewsArray[key].source.isPermanent)
{
/* re-index higher toolbuttons */
for (i = key + 1; i < client.viewsArray.length; i--)
{
dd ("re-indexing tb " + i);
tb.setAttribute ("viewKey", Number(key) - 1);
}
arrayRemoveAt(client.viewsArray, key);
document.getElementById("views-tbar").removeChild(tb.parentNode);
}
else
{
window.alert ("Current view cannot be deleted.");
return false;
}
}
else
dd ("*** INVALID OBJECT passed to deleteToolButton (" + tb + ") " +
"no viewKey attribute. (" + key + ")");
return true;
}
function filterOutput (msg, msgtype)
{

View File

@ -56,23 +56,39 @@ resource:///irc/tests/test3.xul
<menu value="Options">
<menupopup>
<menuitem id="menu-dmessages" value="Debug Messages"
oncommand="onToggleTraceHook()"/>
oncommand="onToggleTraceHook()"/>
<menuitem id="menu-munger" value="Munger" oncommand="onToggleMunger()"/>
<menuitem id="menu-viewicons" value="Icons in View Buttons"
checked="true" oncommand="onNotImplemented();"/>
<menuseparator/>
<menu value="Style">
<menupopup>
<menuitem value="Default"
oncommand="onDoStyleChange('default')"/>
oncommand="onDoStyleChange('default')"/>
<menuitem value="Marble"
oncommand="onDoStyleChange('marble')"/>
oncommand="onDoStyleChange('marble')"/>
<menuitem value="Loud"
oncommand="onDoStyleChange('loud')"/>
oncommand="onDoStyleChange('loud')"/>
<menuseparator/>
<menuitem value="Other..."
oncommand="onDoStyleChange('other')"/>
oncommand="onDoStyleChange('other')"/>
</menupopup>
</menu>
</menupopup>
</menu>
<menu value="Views">
<menupopup>
<menu value="Current View">
<menupopup>
<menuitem value="Hide" oncommand="onHideCurrentView();"/>
<menuitem value="Clear" oncommand="onClearCurrentView();"/>
<menuitem value="Delete" oncommand="onDeleteCurrentView();"/>
</menupopup>
</menu>
<menuitem value="Logging..." enabled="false"
oncommand="onNotImplemented();"/>
</menupopup>
</menu>
</menubar>
</toolbox>