Bug 1525190 - Run eslint --fix over XMPP code. r=florian

This commit is contained in:
Patrick Cloke 2019-02-21 12:10:43 -05:00
Родитель 38e9d7b09a
Коммит f9d1ba960d
14 изменённых файлов: 404 добавлений и 404 удалений

Просмотреть файл

@ -32,7 +32,8 @@ var {
XMPPAccountPrototype, XMPPAccountPrototype,
} = ChromeUtils.import("resource:///modules/xmpp.jsm"); } = ChromeUtils.import("resource:///modules/xmpp.jsm");
var { var {
XMPPSession, XMPPDefaultResource XMPPSession,
XMPPDefaultResource,
} = ChromeUtils.import("resource:///modules/xmpp-session.jsm"); } = ChromeUtils.import("resource:///modules/xmpp-session.jsm");
var { var {
Stanza, Stanza,
@ -50,15 +51,15 @@ XPCOMUtils.defineLazyGetter(this, "_", () =>
// support their JID Domain Discovery extension. // support their JID Domain Discovery extension.
// See https://developers.google.com/talk/jep_extensions/jid_domain_change // See https://developers.google.com/talk/jep_extensions/jid_domain_change
function* PlainFullBindAuth(aUsername, aPassword, aDomain) { function* PlainFullBindAuth(aUsername, aPassword, aDomain) {
let key = btoa("\0"+ aUsername + "\0" + aPassword); let key = btoa("\0" + aUsername + "\0" + aPassword);
let attrs = { let attrs = {
mechanism: "PLAIN", mechanism: "PLAIN",
"xmlns:ga": "http://www.google.com/talk/protocol/auth", "xmlns:ga": "http://www.google.com/talk/protocol/auth",
"ga:client-uses-full-bind-result": "true" "ga:client-uses-full-bind-result": "true",
}; };
let stanza = yield { let stanza = yield {
send: Stanza.node("auth", Stanza.NS.sasl, attrs, key), send: Stanza.node("auth", Stanza.NS.sasl, attrs, key),
log: '<auth.../> (PlainFullBindAuth base64 encoded username and password not logged)' log: "<auth.../> (PlainFullBindAuth base64 encoded username and password not logged)",
}; };
if (stanza.localName != "success") if (stanza.localName != "success")
@ -70,7 +71,7 @@ function GTalkAccount(aProtoInstance, aImAccount) {
} }
GTalkAccount.prototype = { GTalkAccount.prototype = {
__proto__: XMPPAccountPrototype, __proto__: XMPPAccountPrototype,
connect: function() { connect() {
this._jid = this._parseJID(this.name); this._jid = this._parseJID(this.name);
// The XMPP spec says that the node part of a JID is optional, but // The XMPP spec says that the node part of a JID is optional, but
// in the case of Google Talk if the username typed by the user // in the case of Google Talk if the username typed by the user
@ -95,7 +96,7 @@ GTalkAccount.prototype = {
new XMPPSession("talk.google.com", 443, new XMPPSession("talk.google.com", 443,
"require_tls", this._jid, "require_tls", this._jid,
this.imAccount.password, this); this.imAccount.password, this);
} },
}; };
function GTalkProtocol() { function GTalkProtocol() {
@ -108,12 +109,12 @@ GTalkProtocol.prototype = {
get name() { return _("gtalk.protocolName"); }, get name() { return _("gtalk.protocolName"); },
get iconBaseURI() { return "chrome://prpl-gtalk/skin/"; }, get iconBaseURI() { return "chrome://prpl-gtalk/skin/"; },
get usernameEmptyText() { return _("gtalk.usernameHint"); }, get usernameEmptyText() { return _("gtalk.usernameHint"); },
getAccount: function(aImAccount) { return new GTalkAccount(this, aImAccount); }, getAccount(aImAccount) { return new GTalkAccount(this, aImAccount); },
options: { options: {
resource: {get label() { return _("options.resource"); }, default: ""} resource: {get label() { return _("options.resource"); }, default: ""},
}, },
get chatHasTopic() { return true; }, get chatHasTopic() { return true; },
classID: Components.ID("{38a224c1-6748-49a9-8ab2-efc362b1000d}") classID: Components.ID("{38a224c1-6748-49a9-8ab2-efc362b1000d}"),
}; };
var NSGetFactory = XPCOMUtils.generateNSGetFactory([GTalkProtocol]); var NSGetFactory = XPCOMUtils.generateNSGetFactory([GTalkProtocol]);

Просмотреть файл

@ -32,7 +32,8 @@ var {
XMPPAccountPrototype, XMPPAccountPrototype,
} = ChromeUtils.import("resource:///modules/xmpp.jsm"); } = ChromeUtils.import("resource:///modules/xmpp.jsm");
var { var {
XMPPSession, XMPPDefaultResource XMPPSession,
XMPPDefaultResource,
} = ChromeUtils.import("resource:///modules/xmpp-session.jsm"); } = ChromeUtils.import("resource:///modules/xmpp-session.jsm");
XPCOMUtils.defineLazyGetter(this, "_", () => XPCOMUtils.defineLazyGetter(this, "_", () =>
@ -45,7 +46,7 @@ function OdnoklassnikiAccount(aProtoInstance, aImAccount) {
OdnoklassnikiAccount.prototype = { OdnoklassnikiAccount.prototype = {
__proto__: XMPPAccountPrototype, __proto__: XMPPAccountPrototype,
get canJoinChat() { return false; }, get canJoinChat() { return false; },
connect: function() { connect() {
if (!this.name.includes("@")) { if (!this.name.includes("@")) {
// TODO: Do not use the default resource value if the user has not // TODO: Do not use the default resource value if the user has not
// specified it and let the service generate it. // specified it and let the service generate it.
@ -66,7 +67,7 @@ OdnoklassnikiAccount.prototype = {
this._connection = new XMPPSession("xmpp.odnoklassniki.ru", 5222, this._connection = new XMPPSession("xmpp.odnoklassniki.ru", 5222,
"require_tls", this._jid, "require_tls", this._jid,
this.imAccount.password, this); this.imAccount.password, this);
} },
}; };
function OdnoklassnikiProtocol() { function OdnoklassnikiProtocol() {
@ -77,8 +78,8 @@ OdnoklassnikiProtocol.prototype = {
get name() { return _("odnoklassniki.protocolName"); }, get name() { return _("odnoklassniki.protocolName"); },
get iconBaseURI() { return "chrome://prpl-odnoklassniki/skin/"; }, get iconBaseURI() { return "chrome://prpl-odnoklassniki/skin/"; },
get usernameEmptyText() { return _("odnoklassniki.usernameHint"); }, get usernameEmptyText() { return _("odnoklassniki.usernameHint"); },
getAccount: function(aImAccount) { return new OdnoklassnikiAccount(this, aImAccount); }, getAccount(aImAccount) { return new OdnoklassnikiAccount(this, aImAccount); },
classID: Components.ID("{29b09a83-81c1-2032-11e2-6d9bc4f8e969}") classID: Components.ID("{29b09a83-81c1-2032-11e2-6d9bc4f8e969}"),
}; };
var NSGetFactory = XPCOMUtils.generateNSGetFactory([OdnoklassnikiProtocol]); var NSGetFactory = XPCOMUtils.generateNSGetFactory([OdnoklassnikiProtocol]);

Просмотреть файл

@ -11,7 +11,7 @@ add_task(async function testPlain() {
const username = "juliet"; const username = "juliet";
const password = "r0m30myr0m30"; const password = "r0m30myr0m30";
let mech = XMPPAuthMechanisms["PLAIN"](username, password, undefined); let mech = XMPPAuthMechanisms.PLAIN(username, password, undefined);
// Send the initiation message. // Send the initiation message.
let result = mech.next(); let result = mech.next();

Просмотреть файл

@ -19,15 +19,15 @@ FakeXMPPSession.prototype = {
_account: { __proto__: xmpp.XMPPAccount.prototype }, _account: { __proto__: xmpp.XMPPAccount.prototype },
_host: null, _host: null,
_port: 0, _port: 0,
connect: function(aHostOrigin, aPortOrigin, aSecurity, aProxy, connect(aHostOrigin, aPortOrigin, aSecurity, aProxy,
aHost = aHostOrigin, aPort = aPortOrigin) {}, aHost = aHostOrigin, aPort = aPortOrigin) {},
_connectNextRecord: function() { this.isConnectNextRecord = true; }, _connectNextRecord() { this.isConnectNextRecord = true; },
// Used to indicate that method _connectNextRecord is called or not. // Used to indicate that method _connectNextRecord is called or not.
isConnectNextRecord: false, isConnectNextRecord: false,
LOG: function(aMsg) {}, LOG(aMsg) {},
WARN: function(aMsg) {}, WARN(aMsg) {},
}; };
var TEST_DATA = [ var TEST_DATA = [
@ -38,16 +38,16 @@ var TEST_DATA = [
new dns.SRVRecord(5, 0, "xmpp1.instantbird.com", 5222), new dns.SRVRecord(5, 0, "xmpp1.instantbird.com", 5222),
new dns.SRVRecord(10, 0, "xmpp2.instantbird.com", 5222), new dns.SRVRecord(10, 0, "xmpp2.instantbird.com", 5222),
new dns.SRVRecord(0, 0, "xmpp3.instantbird.com", 5222), new dns.SRVRecord(0, 0, "xmpp3.instantbird.com", 5222),
new dns.SRVRecord(15, 0, "xmpp4.instantbird.com", 5222) new dns.SRVRecord(15, 0, "xmpp4.instantbird.com", 5222),
], ],
output: [ output: [
new dns.SRVRecord(0, 0, "xmpp3.instantbird.com", 5222), new dns.SRVRecord(0, 0, "xmpp3.instantbird.com", 5222),
new dns.SRVRecord(5, 0, "xmpp1.instantbird.com", 5222), new dns.SRVRecord(5, 0, "xmpp1.instantbird.com", 5222),
new dns.SRVRecord(10, 0, "xmpp2.instantbird.com", 5222), new dns.SRVRecord(10, 0, "xmpp2.instantbird.com", 5222),
new dns.SRVRecord(15, 0, "xmpp4.instantbird.com", 5222), new dns.SRVRecord(15, 0, "xmpp4.instantbird.com", 5222),
new dns.SRVRecord(20, 0, "xmpp.instantbird.com", 5222) new dns.SRVRecord(20, 0, "xmpp.instantbird.com", 5222),
], ],
isConnectNextRecord: true isConnectNextRecord: true,
}, },
{ {
input: [ input: [
@ -56,7 +56,7 @@ var TEST_DATA = [
new dns.SRVRecord(10, 60, "xmpp2.instantbird.com", 5222), new dns.SRVRecord(10, 60, "xmpp2.instantbird.com", 5222),
new dns.SRVRecord(5, 10, "xmpp3.instantbird.com", 5222), new dns.SRVRecord(5, 10, "xmpp3.instantbird.com", 5222),
new dns.SRVRecord(20, 10, "xmpp.instantbird.com", 5222), new dns.SRVRecord(20, 10, "xmpp.instantbird.com", 5222),
new dns.SRVRecord(15, 0, "xmpp4.instantbird.com", 5222) new dns.SRVRecord(15, 0, "xmpp4.instantbird.com", 5222),
], ],
output: [ output: [
new dns.SRVRecord(5, 30, "xmpp5.instantbird.com", 5222), new dns.SRVRecord(5, 30, "xmpp5.instantbird.com", 5222),
@ -64,42 +64,42 @@ var TEST_DATA = [
new dns.SRVRecord(5, 0, "xmpp1.instantbird.com", 5222), new dns.SRVRecord(5, 0, "xmpp1.instantbird.com", 5222),
new dns.SRVRecord(10, 60, "xmpp2.instantbird.com", 5222), new dns.SRVRecord(10, 60, "xmpp2.instantbird.com", 5222),
new dns.SRVRecord(15, 0, "xmpp4.instantbird.com", 5222), new dns.SRVRecord(15, 0, "xmpp4.instantbird.com", 5222),
new dns.SRVRecord(20,10, "xmpp.instantbird.com", 5222) new dns.SRVRecord(20, 10, "xmpp.instantbird.com", 5222),
], ],
isConnectNextRecord: true isConnectNextRecord: true,
}, },
// Tests no SRV records are found. // Tests no SRV records are found.
{ {
input: [], input: [],
output: [], output: [],
isConnectNextRecord: false isConnectNextRecord: false,
}, },
// Tests XMPP is not supported if the result is one record with target ".". // Tests XMPP is not supported if the result is one record with target ".".
{ {
input: [ input: [
new dns.SRVRecord(5, 30, ".", 5222) new dns.SRVRecord(5, 30, ".", 5222),
], ],
output: xmppSession.XMPPSession.prototype.SRV_ERROR_XMPP_NOT_SUPPORTED, output: xmppSession.XMPPSession.prototype.SRV_ERROR_XMPP_NOT_SUPPORTED,
isConnectNextRecord: false isConnectNextRecord: false,
}, },
{ {
input: [ input: [
new dns.SRVRecord(5, 30, "xmpp.instantbird.com", 5222) new dns.SRVRecord(5, 30, "xmpp.instantbird.com", 5222),
], ],
output: [ output: [
new dns.SRVRecord(5, 30, "xmpp.instantbird.com", 5222) new dns.SRVRecord(5, 30, "xmpp.instantbird.com", 5222),
], ],
isConnectNextRecord: true isConnectNextRecord: true,
}, },
// Tests error happened during SRV lookup. // Tests error happened during SRV lookup.
{ {
input: -1, input: -1,
output: xmppSession.XMPPSession.prototype.SRV_ERROR_LOOKUP_FAILED, output: xmppSession.XMPPSession.prototype.SRV_ERROR_LOOKUP_FAILED,
isConnectNextRecord: false isConnectNextRecord: false,
} },
]; ];
function run_test() { function run_test() {

Просмотреть файл

@ -11,55 +11,55 @@ var TEST_DATA = {
node: "abdelrhman", node: "abdelrhman",
domain: "instantbird", domain: "instantbird",
jid: "abdelrhman@instantbird", jid: "abdelrhman@instantbird",
normalized: "abdelrhman@instantbird" normalized: "abdelrhman@instantbird",
}, },
" room@instantbird/abdelrhman ": { " room@instantbird/abdelrhman ": {
node: "room", node: "room",
domain: "instantbird", domain: "instantbird",
resource: "abdelrhman", resource: "abdelrhman",
jid: "room@instantbird/abdelrhman", jid: "room@instantbird/abdelrhman",
normalized: "room@instantbird" normalized: "room@instantbird",
}, },
"room@instantbird/@bdelrhman": { "room@instantbird/@bdelrhman": {
node: "room", node: "room",
domain: "instantbird", domain: "instantbird",
resource: "@bdelrhman", resource: "@bdelrhman",
jid: "room@instantbird/@bdelrhman", jid: "room@instantbird/@bdelrhman",
normalized: "room@instantbird" normalized: "room@instantbird",
}, },
"room@instantbird/abdelrhm\u0061\u0308n": { "room@instantbird/abdelrhm\u0061\u0308n": {
node: "room", node: "room",
domain: "instantbird", domain: "instantbird",
resource: "abdelrhm\u0061\u0308n", resource: "abdelrhm\u0061\u0308n",
jid: "room@instantbird/abdelrhm\u0061\u0308n", jid: "room@instantbird/abdelrhm\u0061\u0308n",
normalized: "room@instantbird" normalized: "room@instantbird",
}, },
"Room@Instantbird/Abdelrhman": { "Room@Instantbird/Abdelrhman": {
node: "room", node: "room",
domain: "instantbird", domain: "instantbird",
resource: "Abdelrhman", resource: "Abdelrhman",
jid: "room@instantbird/Abdelrhman", jid: "room@instantbird/Abdelrhman",
normalized: "room@instantbird" normalized: "room@instantbird",
}, },
"Abdelrhman@instantbird/Instant bird": { "Abdelrhman@instantbird/Instant bird": {
node: "abdelrhman", node: "abdelrhman",
domain: "instantbird", domain: "instantbird",
resource: "Instant bird", resource: "Instant bird",
jid: "abdelrhman@instantbird/Instant bird", jid: "abdelrhman@instantbird/Instant bird",
normalized: "abdelrhman@instantbird" normalized: "abdelrhman@instantbird",
}, },
"abdelrhman@host/instant/Bird": { "abdelrhman@host/instant/Bird": {
node: "abdelrhman", node: "abdelrhman",
domain: "host", domain: "host",
resource: "instant/Bird", resource: "instant/Bird",
jid: "abdelrhman@host/instant/Bird", jid: "abdelrhman@host/instant/Bird",
normalized: "abdelrhman@host" normalized: "abdelrhman@host",
}, },
"instantbird": { "instantbird": {
domain: "instantbird", domain: "instantbird",
jid: "instantbird", jid: "instantbird",
normalized: "instantbird" normalized: "instantbird",
} },
}; };
function testParseJID() { function testParseJID() {

Просмотреть файл

@ -13,49 +13,49 @@ var TEST_DATA = [
// SOFT HYPHEN mapped to nothing. // SOFT HYPHEN mapped to nothing.
input: "I\u00adX", input: "I\u00adX",
output: "IX", output: "IX",
isError: false isError: false,
}, },
{ {
// No transformation. // No transformation.
input: "user", input: "user",
output: "user", output: "user",
isError: false isError: false,
}, },
{ {
// Case preserved, will not match #2. // Case preserved, will not match #2.
input: "USER", input: "USER",
output: "USER", output: "USER",
isError: false isError: false,
}, },
{ {
// Output is NFKC, input in ISO 8859-1. // Output is NFKC, input in ISO 8859-1.
input: "\u00aa", input: "\u00aa",
output: "a", output: "a",
isError: false isError: false,
}, },
{ {
// Output is NFKC, will match #1. // Output is NFKC, will match #1.
input: "\u2168", input: "\u2168",
output: "IX", output: "IX",
isError: false isError: false,
}, },
{ {
// Error - prohibited character. // Error - prohibited character.
input: "\u0007", input: "\u0007",
output: "", output: "",
isError: true isError: true,
}, },
{ {
// Error - bidirectional check. // Error - bidirectional check.
input: "\u0627\u0031", input: "\u0627\u0031",
output: "", output: "",
isError: true isError: true,
} },
]; ];
function run_test() { function run_test() {
for (let current of TEST_DATA) { for (let current of TEST_DATA) {
try{ try {
let result = xmppAuth.saslPrep(current.input); let result = xmppAuth.saslPrep(current.input);
equal(current.isError, false); equal(current.isError, false);
equal(result, current.output); equal(result, current.output);

Просмотреть файл

@ -19,7 +19,7 @@ type="chat"><body xmlns="jabber:client">What man art thou that, thus \
bescreen"d in night, so stumblest on my counsel?</body>\ bescreen"d in night, so stumblest on my counsel?</body>\
</message>', </message>',
isError: false, isError: false,
description: "Message stanza with body element" description: "Message stanza with body element",
}, },
{ {
input: '<message xmlns="jabber:client" from="romeo@montague.example" \ input: '<message xmlns="jabber:client" from="romeo@montague.example" \
@ -48,7 +48,7 @@ so stumblest on my counsel?</body>\
</received>\ </received>\
</message>', </message>',
isError: false, isError: false,
description: "Forwarded copy of message carbons" description: "Forwarded copy of message carbons",
}, },
{ {
input: '<message xmlns="jabber:client" from="juliet@capulet.example/balcony" \ input: '<message xmlns="jabber:client" from="juliet@capulet.example/balcony" \
@ -56,9 +56,9 @@ to="romeo@montague.example/garden" type="chat">\
<body>What man art thou that, thus bescreen"d in night, so stumblest on my \ <body>What man art thou that, thus bescreen"d in night, so stumblest on my \
counsel?\ counsel?\
</message>', </message>',
output: '', output: "",
isError: true, isError: true,
description: "No closing of body tag" description: "No closing of body tag",
}, },
{ {
input: '<message xmlns="http://etherx.jabber.org/streams" from="juliet@capulet.example/balcony" \ input: '<message xmlns="http://etherx.jabber.org/streams" from="juliet@capulet.example/balcony" \
@ -66,19 +66,19 @@ to="romeo@montague.example/garden" type="chat">\
<body>What man art thou that, thus bescreen"d in night, so stumblest on my \ <body>What man art thou that, thus bescreen"d in night, so stumblest on my \
counsel?</body>\ counsel?</body>\
</message>', </message>',
output: '', output: "",
isError: true, isError: true,
description: "Invalid namespace of top-level element" description: "Invalid namespace of top-level element",
}, },
{ {
input: '<field xmlns="jabber:x:data" type="fixed">\ input: '<field xmlns="jabber:x:data" type="fixed">\
<value>What man art thou that, thus bescreen"d in night, so stumblest on my \ <value>What man art thou that, thus bescreen"d in night, so stumblest on my \
counsel?</value>\ counsel?</value>\
</field>', </field>',
output: '', output: "",
isError: true, isError: true,
description: "Invalid top-level element" description: "Invalid top-level element",
} },
]; ];
function testXMPPParser() { function testXMPPParser() {
@ -87,15 +87,15 @@ function testXMPPParser() {
output: current.output, output: current.output,
description: current.description, description: current.description,
isError: current.isError, isError: current.isError,
onXMLError: function(aString) { onXMLError(aString) {
ok(this.isError, aString + " - " + this.description); ok(this.isError, aString + " - " + this.description);
}, },
LOG: function(aString) {}, LOG(aString) {},
startLegacyAuth: function() {}, startLegacyAuth() {},
onXmppStanza: function(aStanza) { onXmppStanza(aStanza) {
equal(this.output, aStanza.getXML(), this.description); equal(this.output, aStanza.getXML(), this.description);
ok(!this.isError, this.description); ok(!this.isError, this.description);
} },
}; };
let parser = new xmppXml.XMPPParser(listener); let parser = new xmppXml.XMPPParser(listener);
let istream = Cc["@mozilla.org/io/string-input-stream;1"] let istream = Cc["@mozilla.org/io/string-input-stream;1"]

Просмотреть файл

@ -13,14 +13,14 @@ var TEST_DATA = [
namespace: xmppXml.NS.client, namespace: xmppXml.NS.client,
attributes: { attributes: {
jid: "user@domain", jid: "user@domain",
type: null type: null,
}, },
data: [] data: [],
}, },
XmlOutput: '<message xmlns="jabber:client" jid="user@domain"/>', XmlOutput: '<message xmlns="jabber:client" jid="user@domain"/>',
stringOutput: '<message xmlns="jabber:client" jid="user@domain"/>\n', stringOutput: '<message xmlns="jabber:client" jid="user@domain"/>\n',
isError: false, isError: false,
description: "Ignore attribute with null value" description: "Ignore attribute with null value",
}, },
{ {
input: { input: {
@ -28,49 +28,49 @@ var TEST_DATA = [
namespace: xmppXml.NS.client, namespace: xmppXml.NS.client,
attributes: { attributes: {
jid: "user@domain", jid: "user@domain",
type: undefined type: undefined,
}, },
data: [] data: [],
}, },
XmlOutput: '<message xmlns="jabber:client" jid="user@domain"/>', XmlOutput: '<message xmlns="jabber:client" jid="user@domain"/>',
stringOutput: '<message xmlns="jabber:client" jid="user@domain"/>\n', stringOutput: '<message xmlns="jabber:client" jid="user@domain"/>\n',
isError: false, isError: false,
description: "Ignore attribute with undefined value" description: "Ignore attribute with undefined value",
}, },
{ {
input: { input: {
name: "message", name: "message",
namespace: undefined, namespace: undefined,
attributes: {}, attributes: {},
data: [] data: [],
}, },
XmlOutput: '<message/>', XmlOutput: "<message/>",
stringOutput: '<message/>\n', stringOutput: "<message/>\n",
isError: false, isError: false,
description: "Ignore namespace with undefined value" description: "Ignore namespace with undefined value",
}, },
{ {
input: { input: {
name: undefined, name: undefined,
attributes: {}, attributes: {},
data: [] data: [],
}, },
XmlOutput: '', XmlOutput: "",
stringOutput: '', stringOutput: "",
isError: true, isError: true,
description: "Node must have a name" description: "Node must have a name",
}, },
{ {
input: { input: {
name: "message", name: "message",
attributes: {}, attributes: {},
data: "test message" data: "test message",
}, },
XmlOutput: '<message>test message</message>', XmlOutput: "<message>test message</message>",
stringOutput: '<message>\n test message\n</message>\n', stringOutput: "<message>\n test message\n</message>\n",
isError: false, isError: false,
description: "Node with text content" description: "Node with text content",
} },
]; ];
function testXMLNode() { function testXMLNode() {

Просмотреть файл

@ -24,7 +24,7 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["crypto"]);
// Handle PLAIN authorization mechanism. // Handle PLAIN authorization mechanism.
function* PlainAuth(aUsername, aPassword, aDomain) { function* PlainAuth(aUsername, aPassword, aDomain) {
let data = "\0"+ aUsername + "\0" + aPassword; let data = "\0" + aUsername + "\0" + aPassword;
// btoa for Unicode, see https://developer.mozilla.org/en-US/docs/DOM/window.btoa // btoa for Unicode, see https://developer.mozilla.org/en-US/docs/DOM/window.btoa
let base64Data = btoa(unescape(encodeURIComponent(data))); let base64Data = btoa(unescape(encodeURIComponent(data)));
@ -32,7 +32,7 @@ function* PlainAuth(aUsername, aPassword, aDomain) {
let stanza = yield { let stanza = yield {
send: Stanza.node("auth", Stanza.NS.sasl, {mechanism: "PLAIN"}, send: Stanza.node("auth", Stanza.NS.sasl, {mechanism: "PLAIN"},
base64Data), base64Data),
log: '<auth mechanism:="PLAIN"/> (base64 encoded username and password not logged)' log: '<auth mechanism:="PLAIN"/> (base64 encoded username and password not logged)',
}; };
if (stanza.localName != "success") if (stanza.localName != "success")
@ -235,7 +235,7 @@ const RFC3454 = {
[\u{1d516}-\u{1d51c}]|[\u{1d51e}-\u{1d539}]|[\u{1d53b}-\u{1d53e}]|\ [\u{1d516}-\u{1d51c}]|[\u{1d51e}-\u{1d539}]|[\u{1d53b}-\u{1d53e}]|\
[\u{1d540}-\u{1d544}]|\u{1d546}|[\u{1d54a}-\u{1d550}]|\ [\u{1d540}-\u{1d544}]|\u{1d546}|[\u{1d54a}-\u{1d550}]|\
[\u{1d552}-\u{1d6a3}]|[\u{1d6a8}-\u{1d7c9}]|[\u{20000}-\u{2a6d6}]|\ [\u{1d552}-\u{1d6a3}]|[\u{1d6a8}-\u{1d7c9}]|[\u{20000}-\u{2a6d6}]|\
[\u{2f800}-\u{2fa1d}]|[\u{f0000}-\u{ffffd}]|[\u{100000}-\u{10fffd}]" [\u{2f800}-\u{2fa1d}]|[\u{f0000}-\u{ffffd}]|[\u{100000}-\u{10fffd}]",
}; };
// Generates a random nonce and returns a base64 encoded string. // Generates a random nonce and returns a base64 encoded string.
@ -298,7 +298,7 @@ function saslName(aName) {
// RFC 5802 (5.1): the client SHOULD prepare the username using the "SASLprep". // RFC 5802 (5.1): the client SHOULD prepare the username using the "SASLprep".
// The characters , or = in usernames are sent as =2C and // The characters , or = in usernames are sent as =2C and
// =3D respectively. // =3D respectively.
let saslName = saslPrep(aName).replace(/=/g,"=3D").replace(/,/g, "=2C"); let saslName = saslPrep(aName).replace(/=/g, "=3D").replace(/,/g, "=2C");
if (!saslName) if (!saslName)
throw "Name is not valid"; throw "Name is not valid";
@ -350,7 +350,7 @@ function* scramSHA1Auth(aUsername, aPassword, aDomain, aNonce) {
let receivedStanza = yield { let receivedStanza = yield {
send: Stanza.node("auth", Stanza.NS.sasl, {mechanism: "SCRAM-SHA-1"}, send: Stanza.node("auth", Stanza.NS.sasl, {mechanism: "SCRAM-SHA-1"},
btoa(clientFirstMessage)) btoa(clientFirstMessage)),
}; };
if (receivedStanza.localName != "challenge") if (receivedStanza.localName != "challenge")
@ -427,7 +427,7 @@ function* scramSHA1Auth(aUsername, aPassword, aDomain, aNonce) {
return { return {
send: Stanza.node("response", Stanza.NS.sasl, null, btoa(clientFinalMessage)), send: Stanza.node("response", Stanza.NS.sasl, null, btoa(clientFinalMessage)),
log: '<response/> (base64 encoded SCRAM response containing password not logged)' log: "<response/> (base64 encoded SCRAM response containing password not logged)",
}; };
}); });

Просмотреть файл

@ -118,7 +118,7 @@ var commands = [
{ {
name: "join", name: "join",
get helpString() { return _("command.join3", "join"); }, get helpString() { return _("command.join3", "join"); },
run: function(aMsg, aConv, aReturnedConv) { run(aMsg, aConv, aReturnedConv) {
let account = getAccount(aConv); let account = getAccount(aConv);
let params = aMsg.trim(); let params = aMsg.trim();
let conv; let conv;
@ -146,36 +146,36 @@ var commands = [
if (aReturnedConv) if (aReturnedConv)
aReturnedConv.value = conv; aReturnedConv.value = conv;
return true; return true;
} },
}, },
{ {
name: "part", name: "part",
get helpString() { return _("command.part2", "part"); }, get helpString() { return _("command.part2", "part"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT, usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) { run(aMsg, aConv) {
let conv = getConv(aConv); let conv = getConv(aConv);
if (!conv.left) if (!conv.left)
conv.part(aMsg); conv.part(aMsg);
return true; return true;
} },
}, },
{ {
name: "topic", name: "topic",
get helpString() { return _("command.topic", "topic"); }, get helpString() { return _("command.topic", "topic"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT, usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) { run(aMsg, aConv) {
let conv = getMUC(aConv); let conv = getMUC(aConv);
if (!conv) if (!conv)
return true; return true;
conv.topic = aMsg; conv.topic = aMsg;
return true; return true;
} },
}, },
{ {
name: "ban", name: "ban",
get helpString() { return _("command.ban", "ban"); }, get helpString() { return _("command.ban", "ban"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT, usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) { run(aMsg, aConv) {
let params = splitInput(aMsg); let params = splitInput(aMsg);
if (!params.length) if (!params.length)
return false; return false;
@ -184,13 +184,13 @@ var commands = [
if (conv) if (conv)
conv.ban(...params); conv.ban(...params);
return true; return true;
} },
}, },
{ {
name: "kick", name: "kick",
get helpString() { return _("command.kick", "kick"); }, get helpString() { return _("command.kick", "kick"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT, usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) { run(aMsg, aConv) {
let conv = getMUC(aConv); let conv = getMUC(aConv);
if (!conv) if (!conv)
return true; return true;
@ -200,31 +200,31 @@ var commands = [
return false; return false;
conv.kick(...params); conv.kick(...params);
return true; return true;
} },
}, },
{ {
name: "invite", name: "invite",
get helpString() { return _("command.invite", "invite"); }, get helpString() { return _("command.invite", "invite"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT, usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) { run(aMsg, aConv) {
let conv = getMUC(aConv); let conv = getMUC(aConv);
if (!conv) if (!conv)
return true; return true;
return invite(aMsg, conv); return invite(aMsg, conv);
} },
}, },
{ {
name: "inviteto", name: "inviteto",
get helpString() { return _("command.inviteto", "inviteto"); }, get helpString() { return _("command.inviteto", "inviteto"); },
usageContext: Ci.imICommand.CMD_CONTEXT_IM, usageContext: Ci.imICommand.CMD_CONTEXT_IM,
run: (aMsg, aConv) => invite(aMsg, getConv(aConv)) run: (aMsg, aConv) => invite(aMsg, getConv(aConv)),
}, },
{ {
name: "me", name: "me",
get helpString() { return _("command.me", "me"); }, get helpString() { return _("command.me", "me"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT, usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) { run(aMsg, aConv) {
let params = aMsg.trim(); let params = aMsg.trim();
if (!params) if (!params)
return false; return false;
@ -236,13 +236,13 @@ var commands = [
conv.sendMsg("/me " + params); conv.sendMsg("/me " + params);
return true; return true;
} },
}, },
{ {
name: "nick", name: "nick",
get helpString() { return _("command.nick", "nick"); }, get helpString() { return _("command.nick", "nick"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT, usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) { run(aMsg, aConv) {
let params = aMsg.trim().split(/\s+/); let params = aMsg.trim().split(/\s+/);
if (!params[0]) if (!params[0])
return false; return false;
@ -251,13 +251,13 @@ var commands = [
if (conv) if (conv)
conv.setNick(params[0]); conv.setNick(params[0]);
return true; return true;
} },
}, },
{ {
name: "msg", name: "msg",
get helpString() { return _("command.msg", "msg"); }, get helpString() { return _("command.msg", "msg"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT, usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv, aReturnedConv) { run(aMsg, aConv, aReturnedConv) {
let conv = getMUC(aConv); let conv = getMUC(aConv);
if (!conv) if (!conv)
return true; return true;
@ -276,13 +276,13 @@ var commands = [
if (aReturnedConv) if (aReturnedConv)
aReturnedConv.value = privateConv; aReturnedConv.value = privateConv;
return true; return true;
} },
}, },
{ {
name: "version", name: "version",
get helpString() { return _("command.version", "version"); }, get helpString() { return _("command.version", "version"); },
usageContext: Ci.imICommand.CMD_CONTEXT_IM, usageContext: Ci.imICommand.CMD_CONTEXT_IM,
run: function(aMsg, aConv, aReturnedConv) { run(aMsg, aConv, aReturnedConv) {
let conv = getConv(aConv); let conv = getConv(aConv);
if (conv.left) if (conv.left)
return true; return true;
@ -297,6 +297,6 @@ var commands = [
conv.getVersion(); conv.getVersion();
return true; return true;
} },
} },
]; ];

Просмотреть файл

@ -38,7 +38,7 @@ Object.defineProperty(this, "XMPPDefaultResource", {
enumerable: true, enumerable: true,
get() { get() {
return _defaultResource; return _defaultResource;
} },
}); });
function XMPPSession(aHost, aPort, aSecurity, aJID, aPassword, aAccount) { function XMPPSession(aHost, aPort, aSecurity, aJID, aPassword, aAccount) {
@ -114,7 +114,7 @@ XMPPSession.prototype = {
// Contains the remaining SRV records if we failed to connect the current one. // Contains the remaining SRV records if we failed to connect the current one.
_srvRecords: [], _srvRecords: [],
sendPing: function() { sendPing() {
this.sendStanza(Stanza.iq("get", null, null, this.sendStanza(Stanza.iq("get", null, null,
Stanza.node("ping", Stanza.NS.ping)), Stanza.node("ping", Stanza.NS.ping)),
this.cancelDisconnectTimer, this); this.cancelDisconnectTimer, this);
@ -153,7 +153,7 @@ XMPPSession.prototype = {
// Handles result of DNS SRV query and saves sorted results if it's OK in _srvRecords, // Handles result of DNS SRV query and saves sorted results if it's OK in _srvRecords,
// otherwise throws error. // otherwise throws error.
_handleSrvQuery: function(aResult) { _handleSrvQuery(aResult) {
if (typeof aResult == "number" && aResult == -1) if (typeof aResult == "number" && aResult == -1)
throw this.SRV_ERROR_LOOKUP_FAILED; throw this.SRV_ERROR_LOOKUP_FAILED;
@ -177,7 +177,7 @@ XMPPSession.prototype = {
this._connectNextRecord(); this._connectNextRecord();
}, },
_connectNextRecord: function() { _connectNextRecord() {
if (!this._srvRecords.length) { if (!this._srvRecords.length) {
this.ERROR("_connectNextRecord is called and there are no more records " + this.ERROR("_connectNextRecord is called and there are no more records " +
"to connect."); "to connect.");
@ -193,7 +193,7 @@ XMPPSession.prototype = {
}, },
/* Disconnect from the server */ /* Disconnect from the server */
disconnect: function() { disconnect() {
if (this.onXmppStanza == this.stanzaListeners.accountListening) if (this.onXmppStanza == this.stanzaListeners.accountListening)
this.send("</stream:stream>"); this.send("</stream:stream>");
delete this.onXmppStanza; delete this.onXmppStanza;
@ -206,10 +206,10 @@ XMPPSession.prototype = {
}, },
/* Report errors to the account */ /* Report errors to the account */
onError: function(aError, aException) { onError(aError, aException) {
// If we're trying to connect to SRV entries, then keep trying until a // If we're trying to connect to SRV entries, then keep trying until a
// successful connection occurs or we run out of SRV entries to try. // successful connection occurs or we run out of SRV entries to try.
if (!!this._srvRecords.length) { if (this._srvRecords.length) {
this._connectNextRecord(); this._connectNextRecord();
return; return;
} }
@ -218,7 +218,7 @@ XMPPSession.prototype = {
}, },
/* Send a text message to the server */ /* Send a text message to the server */
send: function(aMsg, aLogString) { send(aMsg, aLogString) {
this.sendString(aMsg, "UTF-8", aLogString); this.sendString(aMsg, "UTF-8", aLogString);
}, },
@ -228,9 +228,9 @@ XMPPSession.prototype = {
* return true if the stanza was handled, false if not. Note that an * return true if the stanza was handled, false if not. Note that an
* undefined return value is treated as true. * undefined return value is treated as true.
*/ */
sendStanza: function(aStanza, aCallback, aThis, aLogString) { sendStanza(aStanza, aCallback, aThis, aLogString) {
if (!aStanza.attributes.hasOwnProperty("id")) if (!aStanza.attributes.hasOwnProperty("id"))
aStanza.attributes["id"] = this._account.generateId(); aStanza.attributes.id = this._account.generateId();
if (aCallback) if (aCallback)
this._handlers.set(aStanza.attributes.id, aCallback.bind(aThis)); this._handlers.set(aStanza.attributes.id, aCallback.bind(aThis));
this.send(aStanza.getXML(), aLogString); this.send(aStanza.getXML(), aLogString);
@ -239,7 +239,7 @@ XMPPSession.prototype = {
}, },
/* This method handles callbacks for specific ids. */ /* This method handles callbacks for specific ids. */
execHandler: function(aId, aStanza) { execHandler(aId, aStanza) {
let handler = this._handlers.get(aId); let handler = this._handlers.get(aId);
if (!handler) if (!handler)
return false; return false;
@ -252,7 +252,7 @@ XMPPSession.prototype = {
}, },
/* Start the XMPP stream */ /* Start the XMPP stream */
startStream: function() { startStream() {
if (this._parser) if (this._parser)
this._parser.destroy(); this._parser.destroy();
this._parser = new XMPPParser(this); this._parser = new XMPPParser(this);
@ -260,15 +260,15 @@ XMPPSession.prototype = {
'" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">'); '" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">');
}, },
startSession: function() { startSession() {
this.sendStanza(Stanza.iq("set", null, null, this.sendStanza(Stanza.iq("set", null, null,
Stanza.node("session", Stanza.NS.session)), Stanza.node("session", Stanza.NS.session)),
(aStanza) => aStanza.attributes["type"] == "result"); (aStanza) => aStanza.attributes.type == "result");
this.onXmppStanza = this.stanzaListeners.sessionStarted; this.onXmppStanza = this.stanzaListeners.sessionStarted;
}, },
/* XEP-0078: Non-SASL Authentication */ /* XEP-0078: Non-SASL Authentication */
startLegacyAuth: function() { startLegacyAuth() {
if (!this._encrypted && this._connectionSecurity == "require_tls") { if (!this._encrypted && this._connectionSecurity == "require_tls") {
this.onError(Ci.prplIAccount.ERROR_ENCRYPTION_ERROR, this.onError(Ci.prplIAccount.ERROR_ENCRYPTION_ERROR,
_("connection.error.startTLSNotSupported")); _("connection.error.startTLSNotSupported"));
@ -285,7 +285,7 @@ XMPPSession.prototype = {
// If aResource is null, it will request to bind a server-generated // If aResource is null, it will request to bind a server-generated
// resourcepart, otherwise request to bind a client-submitted resourcepart. // resourcepart, otherwise request to bind a client-submitted resourcepart.
_requestBind: function(aResource) { _requestBind(aResource) {
let resourceNode = let resourceNode =
aResource ? Stanza.node("resource", null, null, aResource) : null; aResource ? Stanza.node("resource", null, null, aResource) : null;
this.sendStanza(Stanza.iq("set", null, null, this.sendStanza(Stanza.iq("set", null, null,
@ -295,7 +295,7 @@ XMPPSession.prototype = {
/* Socket events */ /* Socket events */
/* The connection is established */ /* The connection is established */
onConnection: function() { onConnection() {
if (this._security.includes("ssl")) { if (this._security.includes("ssl")) {
this.onXmppStanza = this.stanzaListeners.startAuth; this.onXmppStanza = this.stanzaListeners.startAuth;
this._encrypted = true; this._encrypted = true;
@ -311,7 +311,7 @@ XMPPSession.prototype = {
}, },
/* When incoming data is available to be parsed */ /* When incoming data is available to be parsed */
onDataReceived: function(aData) { onDataReceived(aData) {
this.checkPingTimer(); this.checkPingTimer();
let istream = Cc["@mozilla.org/io/string-input-stream;1"] let istream = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream); .createInstance(Ci.nsIStringInputStream);
@ -319,7 +319,7 @@ XMPPSession.prototype = {
this._lastReceivedData = aData; this._lastReceivedData = aData;
try { try {
this._parser.onDataAvailable(istream, 0, aData.length); this._parser.onDataAvailable(istream, 0, aData.length);
} catch(e) { } catch (e) {
Cu.reportError(e); Cu.reportError(e);
this.onXMLError("parser-exception", e); this.onXMLError("parser-exception", e);
} }
@ -327,26 +327,26 @@ XMPPSession.prototype = {
}, },
/* The connection got disconnected without us closing it. */ /* The connection got disconnected without us closing it. */
onConnectionClosed: function() { onConnectionClosed() {
this._networkError(_("connection.error.serverClosedConnection")); this._networkError(_("connection.error.serverClosedConnection"));
}, },
onBadCertificate: function(aIsSslError, aNSSErrorMessage) { onBadCertificate(aIsSslError, aNSSErrorMessage) {
let error = this._account.handleBadCertificate(this, aIsSslError); let error = this._account.handleBadCertificate(this, aIsSslError);
this.onError(error, aNSSErrorMessage); this.onError(error, aNSSErrorMessage);
}, },
onConnectionReset: function() { onConnectionReset() {
this._networkError(_("connection.error.resetByPeer")); this._networkError(_("connection.error.resetByPeer"));
}, },
onConnectionTimedOut: function() { onConnectionTimedOut() {
this._networkError(_("connection.error.timedOut")); this._networkError(_("connection.error.timedOut"));
}, },
_networkError: function(aMessage) { _networkError(aMessage) {
this.onError(Ci.prplIAccount.ERROR_NETWORK_ERROR, aMessage); this.onError(Ci.prplIAccount.ERROR_NETWORK_ERROR, aMessage);
}, },
/* Methods called by the XMPPParser instance */ /* Methods called by the XMPPParser instance */
onXMLError: function(aError, aException) { onXMLError(aError, aException) {
if (aError == "parsing-characters") if (aError == "parsing-characters")
this.WARN(aError + ": " + aException + "\n" + this._lastReceivedData); this.WARN(aError + ": " + aException + "\n" + this._lastReceivedData);
else else
@ -358,7 +358,7 @@ XMPPSession.prototype = {
// All the functions in stanzaListeners are used as onXmppStanza // All the functions in stanzaListeners are used as onXmppStanza
// implementations at various steps of establishing the session. // implementations at various steps of establishing the session.
stanzaListeners: { stanzaListeners: {
initStream: function(aStanza) { initStream(aStanza) {
if (aStanza.localName != "features") { if (aStanza.localName != "features") {
this.ERROR("Unexpected stanza " + aStanza.localName + ", expected 'features'"); this.ERROR("Unexpected stanza " + aStanza.localName + ", expected 'features'");
this._networkError(_("connection.error.incorrectResponse")); this._networkError(_("connection.error.incorrectResponse"));
@ -388,7 +388,7 @@ XMPPSession.prototype = {
this.onXmppStanza = this.stanzaListeners.startAuth; this.onXmppStanza = this.stanzaListeners.startAuth;
this.onXmppStanza(aStanza); this.onXmppStanza(aStanza);
}, },
startTLS: function(aStanza) { startTLS(aStanza) {
if (aStanza.localName != "proceed") { if (aStanza.localName != "proceed") {
this._networkError(_("connection.error.failedToStartTLS")); this._networkError(_("connection.error.failedToStartTLS"));
return; return;
@ -399,7 +399,7 @@ XMPPSession.prototype = {
this.startStream(); this.startStream();
this.onXmppStanza = this.stanzaListeners.startAuth; this.onXmppStanza = this.stanzaListeners.startAuth;
}, },
startAuth: function(aStanza) { startAuth(aStanza) {
if (aStanza.localName != "features") { if (aStanza.localName != "features") {
this.ERROR("Unexpected stanza " + aStanza.localName + ", expected 'features'"); this.ERROR("Unexpected stanza " + aStanza.localName + ", expected 'features'");
this._networkError(_("connection.error.incorrectResponse")); this._networkError(_("connection.error.incorrectResponse"));
@ -461,7 +461,7 @@ XMPPSession.prototype = {
this.onXmppStanza = this.stanzaListeners.authDialog.bind(this, authMec); this.onXmppStanza = this.stanzaListeners.authDialog.bind(this, authMec);
this.onXmppStanza(null); // the first auth step doesn't read anything this.onXmppStanza(null); // the first auth step doesn't read anything
}, },
authDialog: function(aAuthMec, aStanza) { authDialog(aAuthMec, aStanza) {
if (aStanza && aStanza.localName == "failure") { if (aStanza && aStanza.localName == "failure") {
let errorMsg = "authenticationFailure"; let errorMsg = "authenticationFailure";
if (aStanza.getElement(["not-authorized"]) || if (aStanza.getElement(["not-authorized"]) ||
@ -476,7 +476,7 @@ XMPPSession.prototype = {
let result; let result;
try { try {
result = aAuthMec.next(aStanza); result = aAuthMec.next(aStanza);
} catch(e) { } catch (e) {
this.ERROR(e); this.ERROR(e);
this.onError(Ci.prplIAccount.ERROR_AUTHENTICATION_FAILED, this.onError(Ci.prplIAccount.ERROR_AUTHENTICATION_FAILED,
_("connection.error.authenticationFailure")); _("connection.error.authenticationFailure"));
@ -496,7 +496,7 @@ XMPPSession.prototype = {
this.onXmppStanza = this.stanzaListeners.startBind; this.onXmppStanza = this.stanzaListeners.startBind;
} }
}, },
startBind: function(aStanza) { startBind(aStanza) {
if (!aStanza.getElement(["bind"])) { if (!aStanza.getElement(["bind"])) {
this.ERROR("Unexpected lack of the bind feature"); this.ERROR("Unexpected lack of the bind feature");
this._networkError(_("connection.error.incorrectResponse")); this._networkError(_("connection.error.incorrectResponse"));
@ -507,8 +507,8 @@ XMPPSession.prototype = {
this._requestBind(this._resource); this._requestBind(this._resource);
this.onXmppStanza = this.stanzaListeners.bindResult; this.onXmppStanza = this.stanzaListeners.bindResult;
}, },
bindResult: function(aStanza) { bindResult(aStanza) {
if (aStanza.attributes["type"] == "error") { if (aStanza.attributes.type == "error") {
let error = this._account.parseError(aStanza); let error = this._account.parseError(aStanza);
let message; let message;
switch (error.condition) { switch (error.condition) {
@ -548,15 +548,15 @@ XMPPSession.prototype = {
this._resource = this._jid.resource; this._resource = this._jid.resource;
this.startSession(); this.startSession();
}, },
legacyAuth: function(aStanza) { legacyAuth(aStanza) {
if (aStanza.attributes["type"] == "error") { if (aStanza.attributes.type == "error") {
let error = aStanza.getElement(["error"]); let error = aStanza.getElement(["error"]);
if (!error) { if (!error) {
this._networkError(_("connection.error.incorrectResponse")); this._networkError(_("connection.error.incorrectResponse"));
return; return;
} }
let code = parseInt(error.attributes["code"], 10); let code = parseInt(error.attributes.code, 10);
if (code == 401) { if (code == 401) {
// Failed Authentication (Incorrect Credentials) // Failed Authentication (Incorrect Credentials)
this.onError(Ci.prplIAccount.ERROR_AUTHENTICATION_FAILED, this.onError(Ci.prplIAccount.ERROR_AUTHENTICATION_FAILED,
@ -579,7 +579,7 @@ XMPPSession.prototype = {
// } // }
} }
if (aStanza.attributes["type"] != "result") { if (aStanza.attributes.type != "result") {
this._networkError(_("connection.error.incorrectResponse")); this._networkError(_("connection.error.incorrectResponse"));
return; return;
} }
@ -612,7 +612,7 @@ XMPPSession.prototype = {
let children = [ let children = [
Stanza.node("username", null, null, this._jid.node), Stanza.node("username", null, null, this._jid.node),
Stanza.node("resource", null, null, this._resource) Stanza.node("resource", null, null, this._resource),
]; ];
let logString; let logString;
@ -656,16 +656,15 @@ XMPPSession.prototype = {
let s = Stanza.iq("set", null, this._domain, let s = Stanza.iq("set", null, this._domain,
Stanza.node("query", Stanza.NS.auth, null, children)); Stanza.node("query", Stanza.NS.auth, null, children));
this.sendStanza(s, undefined, undefined, this.sendStanza(s, undefined, undefined, `<iq type="set".../> (${logString})`);
'<iq type="set".../> (' + logString + ')');
}, },
sessionStarted: function(aStanza) { sessionStarted(aStanza) {
this.resetPingTimer(); this.resetPingTimer();
this._account.onConnection(); this._account.onConnection();
this.LOG("Account successfully connected."); this.LOG("Account successfully connected.");
this.onXmppStanza = this.stanzaListeners.accountListening; this.onXmppStanza = this.stanzaListeners.accountListening;
}, },
accountListening: function(aStanza) { accountListening(aStanza) {
let id = aStanza.attributes.id; let id = aStanza.attributes.id;
if (id && this.execHandler(id, aStanza)) if (id && this.execHandler(id, aStanza))
return; return;
@ -678,9 +677,9 @@ XMPPSession.prototype = {
this._account.onMessageStanza(aStanza); this._account.onMessageStanza(aStanza);
else if (name == "iq") else if (name == "iq")
this._account.onIQStanza(aStanza); this._account.onIQStanza(aStanza);
} },
}, },
onXmppStanza: function(aStanza) { onXmppStanza(aStanza) {
this.ERROR("should not be reached\n"); this.ERROR("should not be reached\n");
} },
}; };

Просмотреть файл

@ -4,12 +4,13 @@
this.EXPORTED_SYMBOLS = ["Stanza", "XMPPParser", "SupportedFeatures"]; this.EXPORTED_SYMBOLS = ["Stanza", "XMPPParser", "SupportedFeatures"];
/* eslint-disable key-spacing */
var NS = { var NS = {
xml : "http://www.w3.org/XML/1998/namespace", xml : "http://www.w3.org/XML/1998/namespace",
xhtml : "http://www.w3.org/1999/xhtml", xhtml : "http://www.w3.org/1999/xhtml",
xhtml_im : "http://jabber.org/protocol/xhtml-im", xhtml_im : "http://jabber.org/protocol/xhtml-im",
//auth // auth
client : "jabber:client", client : "jabber:client",
streams : "http://etherx.jabber.org/streams", streams : "http://etherx.jabber.org/streams",
stream : "urn:ietf:params:xml:ns:xmpp-streams", stream : "urn:ietf:params:xml:ns:xmpp-streams",
@ -26,20 +27,20 @@ var NS = {
"private" : "jabber:iq:private", "private" : "jabber:iq:private",
xdata : "jabber:x:data", xdata : "jabber:x:data",
//roster // roster
roster : "jabber:iq:roster", roster : "jabber:iq:roster",
roster_versioning : "urn:xmpp:features:rosterver", roster_versioning : "urn:xmpp:features:rosterver",
roster_delimiter : "roster:delimiter", roster_delimiter : "roster:delimiter",
//privacy lists // privacy lists
privacy : "jabber:iq:privacy", privacy : "jabber:iq:privacy",
//discovering // discovering
disco_info : "http://jabber.org/protocol/disco#info", disco_info : "http://jabber.org/protocol/disco#info",
disco_items : "http://jabber.org/protocol/disco#items", disco_items : "http://jabber.org/protocol/disco#items",
caps : "http://jabber.org/protocol/caps", caps : "http://jabber.org/protocol/caps",
//addressing // addressing
address : "http://jabber.org/protocol/address", address : "http://jabber.org/protocol/address",
muc_user : "http://jabber.org/protocol/muc#user", muc_user : "http://jabber.org/protocol/muc#user",
@ -75,7 +76,7 @@ var NS = {
avatar_metadata : "urn:xmpp:avatar:metadata", avatar_metadata : "urn:xmpp:avatar:metadata",
avatar_metadata_notify : "urn:xmpp:avatar:metadata+notify", avatar_metadata_notify : "urn:xmpp:avatar:metadata+notify",
pubsub : "http://jabber.org/protocol/pubsub", pubsub : "http://jabber.org/protocol/pubsub",
pubsub_event : "http://jabber.org/protocol/pubsub#event" pubsub_event : "http://jabber.org/protocol/pubsub#event",
}; };
var TOP_LEVEL_ELEMENTS = { var TOP_LEVEL_ELEMENTS = {
@ -88,8 +89,9 @@ var TOP_LEVEL_ELEMENTS = {
"urn:ietf:params:xml:ns:xmpp-sasl"], "urn:ietf:params:xml:ns:xmpp-sasl"],
"success" : "urn:ietf:params:xml:ns:xmpp-sasl", "success" : "urn:ietf:params:xml:ns:xmpp-sasl",
"challenge" : "urn:ietf:params:xml:ns:xmpp-sasl", "challenge" : "urn:ietf:params:xml:ns:xmpp-sasl",
"error" : "urn:ietf:params:xml:ns:xmpp-streams" "error" : "urn:ietf:params:xml:ns:xmpp-streams",
}; };
/* eslint-enable key-spacing */
// Features that we support in XMPP. // Features that we support in XMPP.
// Don't forget to add your new features here. // Don't forget to add your new features here.
@ -101,18 +103,18 @@ var SupportedFeatures = [
NS.muc, NS.muc,
NS.ping, NS.ping,
NS.vcard, NS.vcard,
NS.version NS.version,
]; ];
/* Stanza Builder */ /* Stanza Builder */
var Stanza = { var Stanza = {
NS: NS, NS,
/* Create a presence stanza */ /* Create a presence stanza */
presence: (aAttr, aData) => Stanza.node("presence", null, aAttr, aData), presence: (aAttr, aData) => Stanza.node("presence", null, aAttr, aData),
/* Create a message stanza */ /* Create a message stanza */
message: function(aTo, aMsg, aState, aAttr = {}, aData = []) { message(aTo, aMsg, aState, aAttr = {}, aData = []) {
aAttr.to = aTo; aAttr.to = aTo;
if (!("type" in aAttr)) if (!("type" in aAttr))
aAttr.type = "chat"; aAttr.type = "chat";
@ -127,7 +129,7 @@ var Stanza = {
}, },
/* Create a iq stanza */ /* Create a iq stanza */
iq: function(aType, aId, aTo, aData) { iq(aType, aId, aTo, aData) {
let attrs = {type: aType}; let attrs = {type: aType};
if (aId) if (aId)
attrs.id = aId; attrs.id = aId;
@ -137,7 +139,7 @@ var Stanza = {
}, },
/* Create a XML node */ /* Create a XML node */
node: function(aName, aNs, aAttr, aData) { node(aName, aNs, aAttr, aData) {
let node = new XMLNode(null, aNs, aName, aName, aAttr); let node = new XMLNode(null, aNs, aName, aName, aAttr);
if (aData) { if (aData) {
if (!Array.isArray(aData)) if (!Array.isArray(aData))
@ -147,7 +149,7 @@ var Stanza = {
} }
return node; return node;
} },
}; };
/* Text node /* Text node
@ -158,22 +160,22 @@ function TextNode(aText) {
TextNode.prototype = { TextNode.prototype = {
get type() { return "text"; }, get type() { return "text"; },
append: function(aText) { append(aText) {
this.text += aText; this.text += aText;
}, },
/* For debug purposes, returns an indented (unencoded) string */ /* For debug purposes, returns an indented (unencoded) string */
convertToString: function(aIndent) { return aIndent + this.text + "\n"; }, convertToString(aIndent) { return aIndent + this.text + "\n"; },
/* Returns the encoded XML */ /* Returns the encoded XML */
getXML: function() { getXML() {
return Cc["@mozilla.org/txttohtmlconv;1"] return Cc["@mozilla.org/txttohtmlconv;1"]
.getService(Ci.mozITXTToHTMLConv) .getService(Ci.mozITXTToHTMLConv)
.scanTXT(this.text, Ci.mozITXTToHTMLConv.kEntities); .scanTXT(this.text, Ci.mozITXTToHTMLConv.kEntities);
}, },
/* To read the unencoded data. */ /* To read the unencoded data. */
get innerText() { return this.text; } get innerText() { return this.text; },
}; };
/* XML node */ /* XML node */
@ -211,12 +213,12 @@ XMLNode.prototype = {
get type() { return "node"; }, get type() { return "node"; },
/* Add a new child node */ /* Add a new child node */
addChild: function(aNode) { addChild(aNode) {
this.children.push(aNode); this.children.push(aNode);
}, },
/* Add text node */ /* Add text node */
addText: function(aText) { addText(aText) {
let lastIndex = this.children.length - 1; let lastIndex = this.children.length - 1;
if (lastIndex >= 0 && this.children[lastIndex] instanceof TextNode) if (lastIndex >= 0 && this.children[lastIndex] instanceof TextNode)
this.children[lastIndex].append(aText); this.children[lastIndex].append(aText);
@ -225,14 +227,14 @@ XMLNode.prototype = {
}, },
/* Get child elements by namespace */ /* Get child elements by namespace */
getChildrenByNS: function(aNS) { getChildrenByNS(aNS) {
return this.children.filter(c => c.uri == aNS); return this.children.filter(c => c.uri == aNS);
}, },
/* Get the first element anywhere inside the node (including child nodes) /* Get the first element anywhere inside the node (including child nodes)
that matches the query. that matches the query.
A query consists of an array of localNames. */ A query consists of an array of localNames. */
getElement: function(aQuery) { getElement(aQuery) {
if (aQuery.length == 0) if (aQuery.length == 0)
return this; return this;
@ -250,7 +252,7 @@ XMLNode.prototype = {
/* Get all elements of the node (including child nodes) that match the query. /* Get all elements of the node (including child nodes) that match the query.
A query consists of an array of localNames. */ A query consists of an array of localNames. */
getElements: function(aQuery) { getElements(aQuery) {
if (aQuery.length == 0) if (aQuery.length == 0)
return [this]; return [this];
@ -266,12 +268,12 @@ XMLNode.prototype = {
}, },
/* Get immediate children by the node name */ /* Get immediate children by the node name */
getChildren: function(aName) { getChildren(aName) {
return this.children.filter((c) => (c.type != "text" && c.localName == aName)); return this.children.filter((c) => (c.type != "text" && c.localName == aName));
}, },
// Test if the node is a stanza and its namespace is valid. // Test if the node is a stanza and its namespace is valid.
isXmppStanza: function() { isXmppStanza() {
if (!TOP_LEVEL_ELEMENTS.hasOwnProperty(this.qName)) if (!TOP_LEVEL_ELEMENTS.hasOwnProperty(this.qName))
return false; return false;
let ns = TOP_LEVEL_ELEMENTS[this.qName]; let ns = TOP_LEVEL_ELEMENTS[this.qName];
@ -279,7 +281,7 @@ XMLNode.prototype = {
}, },
/* Returns indented XML */ /* Returns indented XML */
convertToString: function(aIndent = "") { convertToString(aIndent = "") {
let s = let s =
aIndent + "<" + this.qName + this._getXmlns() + this._getAttributeText(); aIndent + "<" + this.qName + this._getXmlns() + this._getAttributeText();
let content = ""; let content = "";
@ -289,7 +291,7 @@ XMLNode.prototype = {
}, },
/* Returns the XML */ /* Returns the XML */
getXML: function() { getXML() {
let s = "<" + this.qName + this._getXmlns() + this._getAttributeText(); let s = "<" + this.qName + this._getXmlns() + this._getAttributeText();
let innerXML = this.innerXML; let innerXML = this.innerXML;
return s + (innerXML ? ">" + innerXML + "</" + this.qName : "/") + ">"; return s + (innerXML ? ">" + innerXML + "</" + this.qName : "/") + ">";
@ -299,13 +301,13 @@ XMLNode.prototype = {
get innerText() { return this.children.map(c => c.innerText).join(""); }, get innerText() { return this.children.map(c => c.innerText).join(""); },
/* Private methods */ /* Private methods */
_getXmlns: function() { return this.uri ? " xmlns=\"" + this.uri + "\"" : ""; }, _getXmlns() { return this.uri ? " xmlns=\"" + this.uri + "\"" : ""; },
_getAttributeText: function() { _getAttributeText() {
let s = ""; let s = "";
for (let name in this.attributes) for (let name in this.attributes)
s += " " +name + "=\"" + this.attributes[name] + "\""; s += " " + name + "=\"" + this.attributes[name] + "\"";
return s; return s;
} },
}; };
function XMPPParser(aListener) { function XMPPParser(aListener) {
@ -319,7 +321,7 @@ function XMPPParser(aListener) {
} }
XMPPParser.prototype = { XMPPParser.prototype = {
_destroyPending: false, _destroyPending: false,
destroy: function() { destroy() {
// Avoid reference cycles // Avoid reference cycles
this._parser.contentHandler = null; this._parser.contentHandler = null;
delete this._listener; delete this._listener;
@ -337,17 +339,17 @@ XMPPParser.prototype = {
delete this._parser; delete this._parser;
}, },
_dummyRequest: { _dummyRequest: {
cancel: function() { }, cancel() { },
isPending: function() { }, isPending() { },
resume: function() { }, resume() { },
suspend: function() { } suspend() { },
}, },
_logReceivedData: function(aData) { _logReceivedData(aData) {
this._listener.LOG("received:\n" + aData); this._listener.LOG("received:\n" + aData);
}, },
_inOnDataAvailable: false, _inOnDataAvailable: false,
onDataAvailable: function(aInputStream, aOffset, aCount) { onDataAvailable(aInputStream, aOffset, aCount) {
this._inOnDataAvailable = true; this._inOnDataAvailable = true;
this._parser.onDataAvailable(this._dummyRequest, null, this._parser.onDataAvailable(this._dummyRequest, null,
aInputStream, aOffset, aCount); aInputStream, aOffset, aCount);
@ -357,10 +359,10 @@ XMPPParser.prototype = {
}, },
/* nsISAXContentHandler implementation */ /* nsISAXContentHandler implementation */
startDocument: function() { }, startDocument() { },
endDocument: function() { }, endDocument() { },
startElement: function(aUri, aLocalName, aQName, aAttributes) { startElement(aUri, aLocalName, aQName, aAttributes) {
if (aQName == "stream:stream") { if (aQName == "stream:stream") {
let node = new XMLNode(null, aUri, aLocalName, aQName, aAttributes); let node = new XMLNode(null, aUri, aLocalName, aQName, aAttributes);
// The node we created doesn't have children, but // The node we created doesn't have children, but
@ -373,7 +375,7 @@ XMPPParser.prototype = {
return; return;
} }
this._listener._streamId = node.attributes["id"]; this._listener._streamId = node.attributes.id;
if (!("version" in node.attributes)) if (!("version" in node.attributes))
this._listener.startLegacyAuth(); this._listener.startLegacyAuth();
@ -388,7 +390,7 @@ XMPPParser.prototype = {
this._node = node; this._node = node;
}, },
characters: function(aCharacters) { characters(aCharacters) {
if (!this._node) { if (!this._node) {
// Ignore whitespace received on the stream to keep the connection alive. // Ignore whitespace received on the stream to keep the connection alive.
if (aCharacters.trim()) { if (aCharacters.trim()) {
@ -401,7 +403,7 @@ XMPPParser.prototype = {
this._node.addText(aCharacters); this._node.addText(aCharacters);
}, },
endElement: function(aUri, aLocalName, aQName) { endElement(aUri, aLocalName, aQName) {
if (aQName == "stream:stream") { if (aQName == "stream:stream") {
this._logReceivedData("</stream:stream>"); this._logReceivedData("</stream:stream>");
delete this._node; delete this._node;
@ -435,18 +437,18 @@ XMPPParser.prototype = {
this._node = this._node._parentNode; this._node = this._node._parentNode;
}, },
processingInstruction: function(aTarget, aData) { }, processingInstruction(aTarget, aData) { },
/* nsISAXErrorHandler implementation */ /* nsISAXErrorHandler implementation */
error: function(aError) { error(aError) {
if (this._listener) if (this._listener)
this._listener.onXMLError("parse-error", aError); this._listener.onXMLError("parse-error", aError);
}, },
fatalError: function(aError) { fatalError(aError) {
if (this._listener) if (this._listener)
this._listener.onXMLError("parse-fatal-error", aError); this._listener.onXMLError("parse-fatal-error", aError);
}, },
ignorableWarning: function(aError) { ignorableWarning(aError) {
if (this._listener) if (this._listener)
this._listener.onXMLError("parse-warning", aError); this._listener.onXMLError("parse-warning", aError);
}, },

Просмотреть файл

@ -32,7 +32,8 @@ var {
XMPPAccountPrototype, XMPPAccountPrototype,
} = ChromeUtils.import("resource:///modules/xmpp.jsm"); } = ChromeUtils.import("resource:///modules/xmpp.jsm");
var { var {
XMPPSession, XMPPDefaultResource XMPPSession,
XMPPDefaultResource,
} = ChromeUtils.import("resource:///modules/xmpp-session.jsm"); } = ChromeUtils.import("resource:///modules/xmpp-session.jsm");
XPCOMUtils.defineLazyGetter(this, "_", () => XPCOMUtils.defineLazyGetter(this, "_", () =>
@ -53,11 +54,11 @@ XMPPProtocol.prototype = {
get normalizedName() { return "jabber"; }, get normalizedName() { return "jabber"; },
get name() { return "XMPP"; }, get name() { return "XMPP"; },
get iconBaseURI() { return "chrome://prpl-jabber/skin/"; }, get iconBaseURI() { return "chrome://prpl-jabber/skin/"; },
getAccount: function(aImAccount) { return new XMPPAccount(this, aImAccount); }, getAccount(aImAccount) { return new XMPPAccount(this, aImAccount); },
usernameSplits: [ usernameSplits: [
{get label() { return _("options.domain"); }, separator: "@", {get label() { return _("options.domain"); }, separator: "@",
defaultValue: "jabber.org", reverse: true} defaultValue: "jabber.org", reverse: true},
], ],
options: { options: {
@ -72,14 +73,14 @@ XMPPProtocol.prototype = {
// "old_ssl" and "none" are also supported, but not exposed in the UI. // "old_ssl" and "none" are also supported, but not exposed in the UI.
// Any unknown value will fallback to the opportunistic_tls behavior. // Any unknown value will fallback to the opportunistic_tls behavior.
}, },
default: "require_tls" default: "require_tls",
}, },
server: {get label() { return _("options.connectServer"); }, default: ""}, server: {get label() { return _("options.connectServer"); }, default: ""},
port: {get label() { return _("options.connectPort"); }, default: 5222} port: {get label() { return _("options.connectPort"); }, default: 5222},
}, },
get chatHasTopic() { return true; }, get chatHasTopic() { return true; },
classID: Components.ID("{dde786d1-6f59-43d0-9bc8-b505a757fb30}") classID: Components.ID("{dde786d1-6f59-43d0-9bc8-b505a757fb30}"),
}; };
var NSGetFactory = XPCOMUtils.generateNSGetFactory([XMPPProtocol]); var NSGetFactory = XPCOMUtils.generateNSGetFactory([XMPPProtocol]);

Разница между файлами не показана из-за своего большого размера Загрузить разницу