From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- comm/chat/protocols/irc/ircDCC.sys.mjs | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 comm/chat/protocols/irc/ircDCC.sys.mjs (limited to 'comm/chat/protocols/irc/ircDCC.sys.mjs') diff --git a/comm/chat/protocols/irc/ircDCC.sys.mjs b/comm/chat/protocols/irc/ircDCC.sys.mjs new file mode 100644 index 0000000000..afd88f52be --- /dev/null +++ b/comm/chat/protocols/irc/ircDCC.sys.mjs @@ -0,0 +1,66 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * This contains an implementation of the Direct Client-to-Client (DCC) + * protocol. + * A description of the DCC protocol + * http://www.irchelp.org/irchelp/rfc/dccspec.html + */ + +import { ircHandlerPriorities } from "resource:///modules/ircHandlerPriorities.sys.mjs"; + +// Parse a CTCP message into a DCC message. A DCC message is a CTCP message of +// the form: +// DCC
[] +function DCCMessage(aMessage, aAccount) { + let message = aMessage; + let params = message.ctcp.param.split(" "); + if (params.length < 4) { + aAccount.ERROR("Not enough DCC parameters:\n" + JSON.stringify(aMessage)); + return null; + } + + try { + // Address, port and size should be treated as unsigned long, unsigned short + // and unsigned long, respectively. The protocol is designed to handle + // further arguments, if necessary. + message.ctcp.dcc = { + type: params[0], + argument: params[1], + address: Number(params[2]), + port: Number(params[3]), + size: params.length == 5 ? Number(params[4]) : null, + furtherArguments: params.length > 5 ? params.slice(5) : [], + }; + } catch (e) { + aAccount.ERROR( + "Error parsing DCC parameters:\n" + JSON.stringify(aMessage) + ); + return null; + } + + return message; +} + +// This is the DCC handler for CTCP, it will call each DCC handler. +export var ctcpDCC = { + name: "DCC", + // Slightly above default CTCP priority. + priority: ircHandlerPriorities.HIGH_PRIORITY + 10, + isEnabled: () => true, + + commands: { + // Handle a DCC message by parsing the message and executing any handlers. + DCC(message, ircHandlers) { + // If there are no DCC handlers, then don't parse the DCC message. + if (!ircHandlers.hasDCCHandlers) { + return false; + } + + // Parse the message and attempt to handle it. + return ircHandlers.handleDCCMessage(this, DCCMessage(message, this)); + }, + }, +}; -- cgit v1.2.3