Bug 1525190 - Run eslint --fix over XMPP code. r=florian
This commit is contained in:
Родитель
38e9d7b09a
Коммит
f9d1ba960d
|
@ -32,7 +32,8 @@ var {
|
|||
XMPPAccountPrototype,
|
||||
} = ChromeUtils.import("resource:///modules/xmpp.jsm");
|
||||
var {
|
||||
XMPPSession, XMPPDefaultResource
|
||||
XMPPSession,
|
||||
XMPPDefaultResource,
|
||||
} = ChromeUtils.import("resource:///modules/xmpp-session.jsm");
|
||||
var {
|
||||
Stanza,
|
||||
|
@ -50,15 +51,15 @@ XPCOMUtils.defineLazyGetter(this, "_", () =>
|
|||
// support their JID Domain Discovery extension.
|
||||
// See https://developers.google.com/talk/jep_extensions/jid_domain_change
|
||||
function* PlainFullBindAuth(aUsername, aPassword, aDomain) {
|
||||
let key = btoa("\0"+ aUsername + "\0" + aPassword);
|
||||
let key = btoa("\0" + aUsername + "\0" + aPassword);
|
||||
let attrs = {
|
||||
mechanism: "PLAIN",
|
||||
"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 {
|
||||
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")
|
||||
|
@ -70,7 +71,7 @@ function GTalkAccount(aProtoInstance, aImAccount) {
|
|||
}
|
||||
GTalkAccount.prototype = {
|
||||
__proto__: XMPPAccountPrototype,
|
||||
connect: function() {
|
||||
connect() {
|
||||
this._jid = this._parseJID(this.name);
|
||||
// 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
|
||||
|
@ -95,7 +96,7 @@ GTalkAccount.prototype = {
|
|||
new XMPPSession("talk.google.com", 443,
|
||||
"require_tls", this._jid,
|
||||
this.imAccount.password, this);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function GTalkProtocol() {
|
||||
|
@ -108,12 +109,12 @@ GTalkProtocol.prototype = {
|
|||
get name() { return _("gtalk.protocolName"); },
|
||||
get iconBaseURI() { return "chrome://prpl-gtalk/skin/"; },
|
||||
get usernameEmptyText() { return _("gtalk.usernameHint"); },
|
||||
getAccount: function(aImAccount) { return new GTalkAccount(this, aImAccount); },
|
||||
getAccount(aImAccount) { return new GTalkAccount(this, aImAccount); },
|
||||
options: {
|
||||
resource: {get label() { return _("options.resource"); }, default: ""}
|
||||
resource: {get label() { return _("options.resource"); }, default: ""},
|
||||
},
|
||||
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]);
|
||||
|
|
|
@ -32,7 +32,8 @@ var {
|
|||
XMPPAccountPrototype,
|
||||
} = ChromeUtils.import("resource:///modules/xmpp.jsm");
|
||||
var {
|
||||
XMPPSession, XMPPDefaultResource
|
||||
XMPPSession,
|
||||
XMPPDefaultResource,
|
||||
} = ChromeUtils.import("resource:///modules/xmpp-session.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "_", () =>
|
||||
|
@ -45,7 +46,7 @@ function OdnoklassnikiAccount(aProtoInstance, aImAccount) {
|
|||
OdnoklassnikiAccount.prototype = {
|
||||
__proto__: XMPPAccountPrototype,
|
||||
get canJoinChat() { return false; },
|
||||
connect: function() {
|
||||
connect() {
|
||||
if (!this.name.includes("@")) {
|
||||
// TODO: Do not use the default resource value if the user has not
|
||||
// specified it and let the service generate it.
|
||||
|
@ -66,7 +67,7 @@ OdnoklassnikiAccount.prototype = {
|
|||
this._connection = new XMPPSession("xmpp.odnoklassniki.ru", 5222,
|
||||
"require_tls", this._jid,
|
||||
this.imAccount.password, this);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function OdnoklassnikiProtocol() {
|
||||
|
@ -77,8 +78,8 @@ OdnoklassnikiProtocol.prototype = {
|
|||
get name() { return _("odnoklassniki.protocolName"); },
|
||||
get iconBaseURI() { return "chrome://prpl-odnoklassniki/skin/"; },
|
||||
get usernameEmptyText() { return _("odnoklassniki.usernameHint"); },
|
||||
getAccount: function(aImAccount) { return new OdnoklassnikiAccount(this, aImAccount); },
|
||||
classID: Components.ID("{29b09a83-81c1-2032-11e2-6d9bc4f8e969}")
|
||||
getAccount(aImAccount) { return new OdnoklassnikiAccount(this, aImAccount); },
|
||||
classID: Components.ID("{29b09a83-81c1-2032-11e2-6d9bc4f8e969}"),
|
||||
};
|
||||
|
||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([OdnoklassnikiProtocol]);
|
||||
|
|
|
@ -11,7 +11,7 @@ add_task(async function testPlain() {
|
|||
const username = "juliet";
|
||||
const password = "r0m30myr0m30";
|
||||
|
||||
let mech = XMPPAuthMechanisms["PLAIN"](username, password, undefined);
|
||||
let mech = XMPPAuthMechanisms.PLAIN(username, password, undefined);
|
||||
|
||||
// Send the initiation message.
|
||||
let result = mech.next();
|
||||
|
|
|
@ -19,15 +19,15 @@ FakeXMPPSession.prototype = {
|
|||
_account: { __proto__: xmpp.XMPPAccount.prototype },
|
||||
_host: null,
|
||||
_port: 0,
|
||||
connect: function(aHostOrigin, aPortOrigin, aSecurity, aProxy,
|
||||
aHost = aHostOrigin, aPort = aPortOrigin) {},
|
||||
_connectNextRecord: function() { this.isConnectNextRecord = true; },
|
||||
connect(aHostOrigin, aPortOrigin, aSecurity, aProxy,
|
||||
aHost = aHostOrigin, aPort = aPortOrigin) {},
|
||||
_connectNextRecord() { this.isConnectNextRecord = true; },
|
||||
|
||||
// Used to indicate that method _connectNextRecord is called or not.
|
||||
isConnectNextRecord: false,
|
||||
|
||||
LOG: function(aMsg) {},
|
||||
WARN: function(aMsg) {},
|
||||
LOG(aMsg) {},
|
||||
WARN(aMsg) {},
|
||||
};
|
||||
|
||||
var TEST_DATA = [
|
||||
|
@ -38,16 +38,16 @@ var TEST_DATA = [
|
|||
new dns.SRVRecord(5, 0, "xmpp1.instantbird.com", 5222),
|
||||
new dns.SRVRecord(10, 0, "xmpp2.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: [
|
||||
new dns.SRVRecord(0, 0, "xmpp3.instantbird.com", 5222),
|
||||
new dns.SRVRecord(5, 0, "xmpp1.instantbird.com", 5222),
|
||||
new dns.SRVRecord(10, 0, "xmpp2.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: [
|
||||
|
@ -56,7 +56,7 @@ var TEST_DATA = [
|
|||
new dns.SRVRecord(10, 60, "xmpp2.instantbird.com", 5222),
|
||||
new dns.SRVRecord(5, 10, "xmpp3.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: [
|
||||
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(10, 60, "xmpp2.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.
|
||||
{
|
||||
input: [],
|
||||
output: [],
|
||||
isConnectNextRecord: false
|
||||
isConnectNextRecord: false,
|
||||
},
|
||||
|
||||
// Tests XMPP is not supported if the result is one record with target ".".
|
||||
{
|
||||
input: [
|
||||
new dns.SRVRecord(5, 30, ".", 5222)
|
||||
new dns.SRVRecord(5, 30, ".", 5222),
|
||||
],
|
||||
output: xmppSession.XMPPSession.prototype.SRV_ERROR_XMPP_NOT_SUPPORTED,
|
||||
isConnectNextRecord: false
|
||||
isConnectNextRecord: false,
|
||||
},
|
||||
{
|
||||
input: [
|
||||
new dns.SRVRecord(5, 30, "xmpp.instantbird.com", 5222)
|
||||
new dns.SRVRecord(5, 30, "xmpp.instantbird.com", 5222),
|
||||
],
|
||||
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.
|
||||
{
|
||||
input: -1,
|
||||
output: xmppSession.XMPPSession.prototype.SRV_ERROR_LOOKUP_FAILED,
|
||||
isConnectNextRecord: false
|
||||
}
|
||||
isConnectNextRecord: false,
|
||||
},
|
||||
];
|
||||
|
||||
function run_test() {
|
||||
|
|
|
@ -11,55 +11,55 @@ var TEST_DATA = {
|
|||
node: "abdelrhman",
|
||||
domain: "instantbird",
|
||||
jid: "abdelrhman@instantbird",
|
||||
normalized: "abdelrhman@instantbird"
|
||||
normalized: "abdelrhman@instantbird",
|
||||
},
|
||||
" room@instantbird/abdelrhman ": {
|
||||
node: "room",
|
||||
domain: "instantbird",
|
||||
resource: "abdelrhman",
|
||||
jid: "room@instantbird/abdelrhman",
|
||||
normalized: "room@instantbird"
|
||||
normalized: "room@instantbird",
|
||||
},
|
||||
"room@instantbird/@bdelrhman": {
|
||||
node: "room",
|
||||
domain: "instantbird",
|
||||
resource: "@bdelrhman",
|
||||
jid: "room@instantbird/@bdelrhman",
|
||||
normalized: "room@instantbird"
|
||||
normalized: "room@instantbird",
|
||||
},
|
||||
"room@instantbird/abdelrhm\u0061\u0308n": {
|
||||
node: "room",
|
||||
domain: "instantbird",
|
||||
resource: "abdelrhm\u0061\u0308n",
|
||||
jid: "room@instantbird/abdelrhm\u0061\u0308n",
|
||||
normalized: "room@instantbird"
|
||||
normalized: "room@instantbird",
|
||||
},
|
||||
"Room@Instantbird/Abdelrhman": {
|
||||
node: "room",
|
||||
domain: "instantbird",
|
||||
resource: "Abdelrhman",
|
||||
jid: "room@instantbird/Abdelrhman",
|
||||
normalized: "room@instantbird"
|
||||
normalized: "room@instantbird",
|
||||
},
|
||||
"Abdelrhman@instantbird/Instant bird": {
|
||||
node: "abdelrhman",
|
||||
domain: "instantbird",
|
||||
resource: "Instant bird",
|
||||
jid: "abdelrhman@instantbird/Instant bird",
|
||||
normalized: "abdelrhman@instantbird"
|
||||
normalized: "abdelrhman@instantbird",
|
||||
},
|
||||
"abdelrhman@host/instant/Bird": {
|
||||
node: "abdelrhman",
|
||||
domain: "host",
|
||||
resource: "instant/Bird",
|
||||
jid: "abdelrhman@host/instant/Bird",
|
||||
normalized: "abdelrhman@host"
|
||||
normalized: "abdelrhman@host",
|
||||
},
|
||||
"instantbird": {
|
||||
domain: "instantbird",
|
||||
jid: "instantbird",
|
||||
normalized: "instantbird"
|
||||
}
|
||||
normalized: "instantbird",
|
||||
},
|
||||
};
|
||||
|
||||
function testParseJID() {
|
||||
|
|
|
@ -13,49 +13,49 @@ var TEST_DATA = [
|
|||
// SOFT HYPHEN mapped to nothing.
|
||||
input: "I\u00adX",
|
||||
output: "IX",
|
||||
isError: false
|
||||
isError: false,
|
||||
},
|
||||
{
|
||||
// No transformation.
|
||||
input: "user",
|
||||
output: "user",
|
||||
isError: false
|
||||
isError: false,
|
||||
},
|
||||
{
|
||||
// Case preserved, will not match #2.
|
||||
input: "USER",
|
||||
output: "USER",
|
||||
isError: false
|
||||
isError: false,
|
||||
},
|
||||
{
|
||||
// Output is NFKC, input in ISO 8859-1.
|
||||
input: "\u00aa",
|
||||
output: "a",
|
||||
isError: false
|
||||
isError: false,
|
||||
},
|
||||
{
|
||||
// Output is NFKC, will match #1.
|
||||
input: "\u2168",
|
||||
output: "IX",
|
||||
isError: false
|
||||
isError: false,
|
||||
},
|
||||
{
|
||||
// Error - prohibited character.
|
||||
input: "\u0007",
|
||||
output: "",
|
||||
isError: true
|
||||
isError: true,
|
||||
},
|
||||
{
|
||||
// Error - bidirectional check.
|
||||
input: "\u0627\u0031",
|
||||
output: "",
|
||||
isError: true
|
||||
}
|
||||
isError: true,
|
||||
},
|
||||
];
|
||||
|
||||
function run_test() {
|
||||
for (let current of TEST_DATA) {
|
||||
try{
|
||||
try {
|
||||
let result = xmppAuth.saslPrep(current.input);
|
||||
equal(current.isError, false);
|
||||
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>\
|
||||
</message>',
|
||||
isError: false,
|
||||
description: "Message stanza with body element"
|
||||
description: "Message stanza with body element",
|
||||
},
|
||||
{
|
||||
input: '<message xmlns="jabber:client" from="romeo@montague.example" \
|
||||
|
@ -48,7 +48,7 @@ so stumblest on my counsel?</body>\
|
|||
</received>\
|
||||
</message>',
|
||||
isError: false,
|
||||
description: "Forwarded copy of message carbons"
|
||||
description: "Forwarded copy of message carbons",
|
||||
},
|
||||
{
|
||||
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 \
|
||||
counsel?\
|
||||
</message>',
|
||||
output: '',
|
||||
output: "",
|
||||
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" \
|
||||
|
@ -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 \
|
||||
counsel?</body>\
|
||||
</message>',
|
||||
output: '',
|
||||
output: "",
|
||||
isError: true,
|
||||
description: "Invalid namespace of top-level element"
|
||||
description: "Invalid namespace of top-level element",
|
||||
},
|
||||
{
|
||||
input: '<field xmlns="jabber:x:data" type="fixed">\
|
||||
<value>What man art thou that, thus bescreen"d in night, so stumblest on my \
|
||||
counsel?</value>\
|
||||
</field>',
|
||||
output: '',
|
||||
output: "",
|
||||
isError: true,
|
||||
description: "Invalid top-level element"
|
||||
}
|
||||
description: "Invalid top-level element",
|
||||
},
|
||||
];
|
||||
|
||||
function testXMPPParser() {
|
||||
|
@ -87,15 +87,15 @@ function testXMPPParser() {
|
|||
output: current.output,
|
||||
description: current.description,
|
||||
isError: current.isError,
|
||||
onXMLError: function(aString) {
|
||||
onXMLError(aString) {
|
||||
ok(this.isError, aString + " - " + this.description);
|
||||
},
|
||||
LOG: function(aString) {},
|
||||
startLegacyAuth: function() {},
|
||||
onXmppStanza: function(aStanza) {
|
||||
LOG(aString) {},
|
||||
startLegacyAuth() {},
|
||||
onXmppStanza(aStanza) {
|
||||
equal(this.output, aStanza.getXML(), this.description);
|
||||
ok(!this.isError, this.description);
|
||||
}
|
||||
},
|
||||
};
|
||||
let parser = new xmppXml.XMPPParser(listener);
|
||||
let istream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
|
|
|
@ -13,14 +13,14 @@ var TEST_DATA = [
|
|||
namespace: xmppXml.NS.client,
|
||||
attributes: {
|
||||
jid: "user@domain",
|
||||
type: null
|
||||
type: null,
|
||||
},
|
||||
data: []
|
||||
data: [],
|
||||
},
|
||||
XmlOutput: '<message xmlns="jabber:client" jid="user@domain"/>',
|
||||
stringOutput: '<message xmlns="jabber:client" jid="user@domain"/>\n',
|
||||
isError: false,
|
||||
description: "Ignore attribute with null value"
|
||||
description: "Ignore attribute with null value",
|
||||
},
|
||||
{
|
||||
input: {
|
||||
|
@ -28,49 +28,49 @@ var TEST_DATA = [
|
|||
namespace: xmppXml.NS.client,
|
||||
attributes: {
|
||||
jid: "user@domain",
|
||||
type: undefined
|
||||
type: undefined,
|
||||
},
|
||||
data: []
|
||||
data: [],
|
||||
},
|
||||
XmlOutput: '<message xmlns="jabber:client" jid="user@domain"/>',
|
||||
stringOutput: '<message xmlns="jabber:client" jid="user@domain"/>\n',
|
||||
isError: false,
|
||||
description: "Ignore attribute with undefined value"
|
||||
description: "Ignore attribute with undefined value",
|
||||
},
|
||||
{
|
||||
input: {
|
||||
name: "message",
|
||||
namespace: undefined,
|
||||
attributes: {},
|
||||
data: []
|
||||
data: [],
|
||||
},
|
||||
XmlOutput: '<message/>',
|
||||
stringOutput: '<message/>\n',
|
||||
XmlOutput: "<message/>",
|
||||
stringOutput: "<message/>\n",
|
||||
isError: false,
|
||||
description: "Ignore namespace with undefined value"
|
||||
description: "Ignore namespace with undefined value",
|
||||
},
|
||||
{
|
||||
input: {
|
||||
name: undefined,
|
||||
attributes: {},
|
||||
data: []
|
||||
data: [],
|
||||
},
|
||||
XmlOutput: '',
|
||||
stringOutput: '',
|
||||
XmlOutput: "",
|
||||
stringOutput: "",
|
||||
isError: true,
|
||||
description: "Node must have a name"
|
||||
description: "Node must have a name",
|
||||
},
|
||||
{
|
||||
input: {
|
||||
name: "message",
|
||||
attributes: {},
|
||||
data: "test message"
|
||||
data: "test message",
|
||||
},
|
||||
XmlOutput: '<message>test message</message>',
|
||||
stringOutput: '<message>\n test message\n</message>\n',
|
||||
XmlOutput: "<message>test message</message>",
|
||||
stringOutput: "<message>\n test message\n</message>\n",
|
||||
isError: false,
|
||||
description: "Node with text content"
|
||||
}
|
||||
description: "Node with text content",
|
||||
},
|
||||
];
|
||||
|
||||
function testXMLNode() {
|
||||
|
|
|
@ -24,7 +24,7 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["crypto"]);
|
|||
|
||||
// Handle PLAIN authorization mechanism.
|
||||
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
|
||||
let base64Data = btoa(unescape(encodeURIComponent(data)));
|
||||
|
@ -32,7 +32,7 @@ function* PlainAuth(aUsername, aPassword, aDomain) {
|
|||
let stanza = yield {
|
||||
send: Stanza.node("auth", Stanza.NS.sasl, {mechanism: "PLAIN"},
|
||||
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")
|
||||
|
@ -235,7 +235,7 @@ const RFC3454 = {
|
|||
[\u{1d516}-\u{1d51c}]|[\u{1d51e}-\u{1d539}]|[\u{1d53b}-\u{1d53e}]|\
|
||||
[\u{1d540}-\u{1d544}]|\u{1d546}|[\u{1d54a}-\u{1d550}]|\
|
||||
[\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.
|
||||
|
@ -298,7 +298,7 @@ function saslName(aName) {
|
|||
// RFC 5802 (5.1): the client SHOULD prepare the username using the "SASLprep".
|
||||
// The characters ’,’ or ’=’ in usernames are sent as ’=2C’ and
|
||||
// ’=3D’ respectively.
|
||||
let saslName = saslPrep(aName).replace(/=/g,"=3D").replace(/,/g, "=2C");
|
||||
let saslName = saslPrep(aName).replace(/=/g, "=3D").replace(/,/g, "=2C");
|
||||
if (!saslName)
|
||||
throw "Name is not valid";
|
||||
|
||||
|
@ -350,7 +350,7 @@ function* scramSHA1Auth(aUsername, aPassword, aDomain, aNonce) {
|
|||
|
||||
let receivedStanza = yield {
|
||||
send: Stanza.node("auth", Stanza.NS.sasl, {mechanism: "SCRAM-SHA-1"},
|
||||
btoa(clientFirstMessage))
|
||||
btoa(clientFirstMessage)),
|
||||
};
|
||||
|
||||
if (receivedStanza.localName != "challenge")
|
||||
|
@ -427,7 +427,7 @@ function* scramSHA1Auth(aUsername, aPassword, aDomain, aNonce) {
|
|||
|
||||
return {
|
||||
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",
|
||||
get helpString() { return _("command.join3", "join"); },
|
||||
run: function(aMsg, aConv, aReturnedConv) {
|
||||
run(aMsg, aConv, aReturnedConv) {
|
||||
let account = getAccount(aConv);
|
||||
let params = aMsg.trim();
|
||||
let conv;
|
||||
|
@ -146,36 +146,36 @@ var commands = [
|
|||
if (aReturnedConv)
|
||||
aReturnedConv.value = conv;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "part",
|
||||
get helpString() { return _("command.part2", "part"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||
run: function(aMsg, aConv) {
|
||||
run(aMsg, aConv) {
|
||||
let conv = getConv(aConv);
|
||||
if (!conv.left)
|
||||
conv.part(aMsg);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "topic",
|
||||
get helpString() { return _("command.topic", "topic"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||
run: function(aMsg, aConv) {
|
||||
run(aMsg, aConv) {
|
||||
let conv = getMUC(aConv);
|
||||
if (!conv)
|
||||
return true;
|
||||
conv.topic = aMsg;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ban",
|
||||
get helpString() { return _("command.ban", "ban"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||
run: function(aMsg, aConv) {
|
||||
run(aMsg, aConv) {
|
||||
let params = splitInput(aMsg);
|
||||
if (!params.length)
|
||||
return false;
|
||||
|
@ -184,13 +184,13 @@ var commands = [
|
|||
if (conv)
|
||||
conv.ban(...params);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "kick",
|
||||
get helpString() { return _("command.kick", "kick"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||
run: function(aMsg, aConv) {
|
||||
run(aMsg, aConv) {
|
||||
let conv = getMUC(aConv);
|
||||
if (!conv)
|
||||
return true;
|
||||
|
@ -200,31 +200,31 @@ var commands = [
|
|||
return false;
|
||||
conv.kick(...params);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invite",
|
||||
get helpString() { return _("command.invite", "invite"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||
run: function(aMsg, aConv) {
|
||||
run(aMsg, aConv) {
|
||||
let conv = getMUC(aConv);
|
||||
if (!conv)
|
||||
return true;
|
||||
|
||||
return invite(aMsg, conv);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "inviteto",
|
||||
get helpString() { return _("command.inviteto", "inviteto"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_IM,
|
||||
run: (aMsg, aConv) => invite(aMsg, getConv(aConv))
|
||||
run: (aMsg, aConv) => invite(aMsg, getConv(aConv)),
|
||||
},
|
||||
{
|
||||
name: "me",
|
||||
get helpString() { return _("command.me", "me"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||
run: function(aMsg, aConv) {
|
||||
run(aMsg, aConv) {
|
||||
let params = aMsg.trim();
|
||||
if (!params)
|
||||
return false;
|
||||
|
@ -236,13 +236,13 @@ var commands = [
|
|||
conv.sendMsg("/me " + params);
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nick",
|
||||
get helpString() { return _("command.nick", "nick"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||
run: function(aMsg, aConv) {
|
||||
run(aMsg, aConv) {
|
||||
let params = aMsg.trim().split(/\s+/);
|
||||
if (!params[0])
|
||||
return false;
|
||||
|
@ -251,13 +251,13 @@ var commands = [
|
|||
if (conv)
|
||||
conv.setNick(params[0]);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "msg",
|
||||
get helpString() { return _("command.msg", "msg"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||
run: function(aMsg, aConv, aReturnedConv) {
|
||||
run(aMsg, aConv, aReturnedConv) {
|
||||
let conv = getMUC(aConv);
|
||||
if (!conv)
|
||||
return true;
|
||||
|
@ -276,13 +276,13 @@ var commands = [
|
|||
if (aReturnedConv)
|
||||
aReturnedConv.value = privateConv;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "version",
|
||||
get helpString() { return _("command.version", "version"); },
|
||||
usageContext: Ci.imICommand.CMD_CONTEXT_IM,
|
||||
run: function(aMsg, aConv, aReturnedConv) {
|
||||
run(aMsg, aConv, aReturnedConv) {
|
||||
let conv = getConv(aConv);
|
||||
if (conv.left)
|
||||
return true;
|
||||
|
@ -297,6 +297,6 @@ var commands = [
|
|||
|
||||
conv.getVersion();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
@ -38,7 +38,7 @@ Object.defineProperty(this, "XMPPDefaultResource", {
|
|||
enumerable: true,
|
||||
get() {
|
||||
return _defaultResource;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
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.
|
||||
_srvRecords: [],
|
||||
|
||||
sendPing: function() {
|
||||
sendPing() {
|
||||
this.sendStanza(Stanza.iq("get", null, null,
|
||||
Stanza.node("ping", Stanza.NS.ping)),
|
||||
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,
|
||||
// otherwise throws error.
|
||||
_handleSrvQuery: function(aResult) {
|
||||
_handleSrvQuery(aResult) {
|
||||
if (typeof aResult == "number" && aResult == -1)
|
||||
throw this.SRV_ERROR_LOOKUP_FAILED;
|
||||
|
||||
|
@ -177,7 +177,7 @@ XMPPSession.prototype = {
|
|||
this._connectNextRecord();
|
||||
},
|
||||
|
||||
_connectNextRecord: function() {
|
||||
_connectNextRecord() {
|
||||
if (!this._srvRecords.length) {
|
||||
this.ERROR("_connectNextRecord is called and there are no more records " +
|
||||
"to connect.");
|
||||
|
@ -193,7 +193,7 @@ XMPPSession.prototype = {
|
|||
},
|
||||
|
||||
/* Disconnect from the server */
|
||||
disconnect: function() {
|
||||
disconnect() {
|
||||
if (this.onXmppStanza == this.stanzaListeners.accountListening)
|
||||
this.send("</stream:stream>");
|
||||
delete this.onXmppStanza;
|
||||
|
@ -206,10 +206,10 @@ XMPPSession.prototype = {
|
|||
},
|
||||
|
||||
/* 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
|
||||
// successful connection occurs or we run out of SRV entries to try.
|
||||
if (!!this._srvRecords.length) {
|
||||
if (this._srvRecords.length) {
|
||||
this._connectNextRecord();
|
||||
return;
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ XMPPSession.prototype = {
|
|||
},
|
||||
|
||||
/* Send a text message to the server */
|
||||
send: function(aMsg, aLogString) {
|
||||
send(aMsg, 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
|
||||
* undefined return value is treated as true.
|
||||
*/
|
||||
sendStanza: function(aStanza, aCallback, aThis, aLogString) {
|
||||
sendStanza(aStanza, aCallback, aThis, aLogString) {
|
||||
if (!aStanza.attributes.hasOwnProperty("id"))
|
||||
aStanza.attributes["id"] = this._account.generateId();
|
||||
aStanza.attributes.id = this._account.generateId();
|
||||
if (aCallback)
|
||||
this._handlers.set(aStanza.attributes.id, aCallback.bind(aThis));
|
||||
this.send(aStanza.getXML(), aLogString);
|
||||
|
@ -239,7 +239,7 @@ XMPPSession.prototype = {
|
|||
},
|
||||
|
||||
/* This method handles callbacks for specific ids. */
|
||||
execHandler: function(aId, aStanza) {
|
||||
execHandler(aId, aStanza) {
|
||||
let handler = this._handlers.get(aId);
|
||||
if (!handler)
|
||||
return false;
|
||||
|
@ -252,7 +252,7 @@ XMPPSession.prototype = {
|
|||
},
|
||||
|
||||
/* Start the XMPP stream */
|
||||
startStream: function() {
|
||||
startStream() {
|
||||
if (this._parser)
|
||||
this._parser.destroy();
|
||||
this._parser = new XMPPParser(this);
|
||||
|
@ -260,15 +260,15 @@ XMPPSession.prototype = {
|
|||
'" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">');
|
||||
},
|
||||
|
||||
startSession: function() {
|
||||
startSession() {
|
||||
this.sendStanza(Stanza.iq("set", null, null,
|
||||
Stanza.node("session", Stanza.NS.session)),
|
||||
(aStanza) => aStanza.attributes["type"] == "result");
|
||||
(aStanza) => aStanza.attributes.type == "result");
|
||||
this.onXmppStanza = this.stanzaListeners.sessionStarted;
|
||||
},
|
||||
|
||||
/* XEP-0078: Non-SASL Authentication */
|
||||
startLegacyAuth: function() {
|
||||
startLegacyAuth() {
|
||||
if (!this._encrypted && this._connectionSecurity == "require_tls") {
|
||||
this.onError(Ci.prplIAccount.ERROR_ENCRYPTION_ERROR,
|
||||
_("connection.error.startTLSNotSupported"));
|
||||
|
@ -285,7 +285,7 @@ XMPPSession.prototype = {
|
|||
|
||||
// If aResource is null, it will request to bind a server-generated
|
||||
// resourcepart, otherwise request to bind a client-submitted resourcepart.
|
||||
_requestBind: function(aResource) {
|
||||
_requestBind(aResource) {
|
||||
let resourceNode =
|
||||
aResource ? Stanza.node("resource", null, null, aResource) : null;
|
||||
this.sendStanza(Stanza.iq("set", null, null,
|
||||
|
@ -295,7 +295,7 @@ XMPPSession.prototype = {
|
|||
|
||||
/* Socket events */
|
||||
/* The connection is established */
|
||||
onConnection: function() {
|
||||
onConnection() {
|
||||
if (this._security.includes("ssl")) {
|
||||
this.onXmppStanza = this.stanzaListeners.startAuth;
|
||||
this._encrypted = true;
|
||||
|
@ -311,7 +311,7 @@ XMPPSession.prototype = {
|
|||
},
|
||||
|
||||
/* When incoming data is available to be parsed */
|
||||
onDataReceived: function(aData) {
|
||||
onDataReceived(aData) {
|
||||
this.checkPingTimer();
|
||||
let istream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
|
@ -319,7 +319,7 @@ XMPPSession.prototype = {
|
|||
this._lastReceivedData = aData;
|
||||
try {
|
||||
this._parser.onDataAvailable(istream, 0, aData.length);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
Cu.reportError(e);
|
||||
this.onXMLError("parser-exception", e);
|
||||
}
|
||||
|
@ -327,26 +327,26 @@ XMPPSession.prototype = {
|
|||
},
|
||||
|
||||
/* The connection got disconnected without us closing it. */
|
||||
onConnectionClosed: function() {
|
||||
onConnectionClosed() {
|
||||
this._networkError(_("connection.error.serverClosedConnection"));
|
||||
},
|
||||
onBadCertificate: function(aIsSslError, aNSSErrorMessage) {
|
||||
onBadCertificate(aIsSslError, aNSSErrorMessage) {
|
||||
let error = this._account.handleBadCertificate(this, aIsSslError);
|
||||
this.onError(error, aNSSErrorMessage);
|
||||
},
|
||||
onConnectionReset: function() {
|
||||
onConnectionReset() {
|
||||
this._networkError(_("connection.error.resetByPeer"));
|
||||
},
|
||||
onConnectionTimedOut: function() {
|
||||
onConnectionTimedOut() {
|
||||
this._networkError(_("connection.error.timedOut"));
|
||||
},
|
||||
_networkError: function(aMessage) {
|
||||
_networkError(aMessage) {
|
||||
this.onError(Ci.prplIAccount.ERROR_NETWORK_ERROR, aMessage);
|
||||
},
|
||||
|
||||
|
||||
/* Methods called by the XMPPParser instance */
|
||||
onXMLError: function(aError, aException) {
|
||||
onXMLError(aError, aException) {
|
||||
if (aError == "parsing-characters")
|
||||
this.WARN(aError + ": " + aException + "\n" + this._lastReceivedData);
|
||||
else
|
||||
|
@ -358,7 +358,7 @@ XMPPSession.prototype = {
|
|||
// All the functions in stanzaListeners are used as onXmppStanza
|
||||
// implementations at various steps of establishing the session.
|
||||
stanzaListeners: {
|
||||
initStream: function(aStanza) {
|
||||
initStream(aStanza) {
|
||||
if (aStanza.localName != "features") {
|
||||
this.ERROR("Unexpected stanza " + aStanza.localName + ", expected 'features'");
|
||||
this._networkError(_("connection.error.incorrectResponse"));
|
||||
|
@ -388,7 +388,7 @@ XMPPSession.prototype = {
|
|||
this.onXmppStanza = this.stanzaListeners.startAuth;
|
||||
this.onXmppStanza(aStanza);
|
||||
},
|
||||
startTLS: function(aStanza) {
|
||||
startTLS(aStanza) {
|
||||
if (aStanza.localName != "proceed") {
|
||||
this._networkError(_("connection.error.failedToStartTLS"));
|
||||
return;
|
||||
|
@ -399,7 +399,7 @@ XMPPSession.prototype = {
|
|||
this.startStream();
|
||||
this.onXmppStanza = this.stanzaListeners.startAuth;
|
||||
},
|
||||
startAuth: function(aStanza) {
|
||||
startAuth(aStanza) {
|
||||
if (aStanza.localName != "features") {
|
||||
this.ERROR("Unexpected stanza " + aStanza.localName + ", expected 'features'");
|
||||
this._networkError(_("connection.error.incorrectResponse"));
|
||||
|
@ -461,7 +461,7 @@ XMPPSession.prototype = {
|
|||
this.onXmppStanza = this.stanzaListeners.authDialog.bind(this, authMec);
|
||||
this.onXmppStanza(null); // the first auth step doesn't read anything
|
||||
},
|
||||
authDialog: function(aAuthMec, aStanza) {
|
||||
authDialog(aAuthMec, aStanza) {
|
||||
if (aStanza && aStanza.localName == "failure") {
|
||||
let errorMsg = "authenticationFailure";
|
||||
if (aStanza.getElement(["not-authorized"]) ||
|
||||
|
@ -476,7 +476,7 @@ XMPPSession.prototype = {
|
|||
let result;
|
||||
try {
|
||||
result = aAuthMec.next(aStanza);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
this.ERROR(e);
|
||||
this.onError(Ci.prplIAccount.ERROR_AUTHENTICATION_FAILED,
|
||||
_("connection.error.authenticationFailure"));
|
||||
|
@ -496,7 +496,7 @@ XMPPSession.prototype = {
|
|||
this.onXmppStanza = this.stanzaListeners.startBind;
|
||||
}
|
||||
},
|
||||
startBind: function(aStanza) {
|
||||
startBind(aStanza) {
|
||||
if (!aStanza.getElement(["bind"])) {
|
||||
this.ERROR("Unexpected lack of the bind feature");
|
||||
this._networkError(_("connection.error.incorrectResponse"));
|
||||
|
@ -507,8 +507,8 @@ XMPPSession.prototype = {
|
|||
this._requestBind(this._resource);
|
||||
this.onXmppStanza = this.stanzaListeners.bindResult;
|
||||
},
|
||||
bindResult: function(aStanza) {
|
||||
if (aStanza.attributes["type"] == "error") {
|
||||
bindResult(aStanza) {
|
||||
if (aStanza.attributes.type == "error") {
|
||||
let error = this._account.parseError(aStanza);
|
||||
let message;
|
||||
switch (error.condition) {
|
||||
|
@ -548,15 +548,15 @@ XMPPSession.prototype = {
|
|||
this._resource = this._jid.resource;
|
||||
this.startSession();
|
||||
},
|
||||
legacyAuth: function(aStanza) {
|
||||
if (aStanza.attributes["type"] == "error") {
|
||||
legacyAuth(aStanza) {
|
||||
if (aStanza.attributes.type == "error") {
|
||||
let error = aStanza.getElement(["error"]);
|
||||
if (!error) {
|
||||
this._networkError(_("connection.error.incorrectResponse"));
|
||||
return;
|
||||
}
|
||||
|
||||
let code = parseInt(error.attributes["code"], 10);
|
||||
let code = parseInt(error.attributes.code, 10);
|
||||
if (code == 401) {
|
||||
// Failed Authentication (Incorrect Credentials)
|
||||
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"));
|
||||
return;
|
||||
}
|
||||
|
@ -612,7 +612,7 @@ XMPPSession.prototype = {
|
|||
|
||||
let children = [
|
||||
Stanza.node("username", null, null, this._jid.node),
|
||||
Stanza.node("resource", null, null, this._resource)
|
||||
Stanza.node("resource", null, null, this._resource),
|
||||
];
|
||||
|
||||
let logString;
|
||||
|
@ -656,16 +656,15 @@ XMPPSession.prototype = {
|
|||
|
||||
let s = Stanza.iq("set", null, this._domain,
|
||||
Stanza.node("query", Stanza.NS.auth, null, children));
|
||||
this.sendStanza(s, undefined, undefined,
|
||||
'<iq type="set".../> (' + logString + ')');
|
||||
this.sendStanza(s, undefined, undefined, `<iq type="set".../> (${logString})`);
|
||||
},
|
||||
sessionStarted: function(aStanza) {
|
||||
sessionStarted(aStanza) {
|
||||
this.resetPingTimer();
|
||||
this._account.onConnection();
|
||||
this.LOG("Account successfully connected.");
|
||||
this.onXmppStanza = this.stanzaListeners.accountListening;
|
||||
},
|
||||
accountListening: function(aStanza) {
|
||||
accountListening(aStanza) {
|
||||
let id = aStanza.attributes.id;
|
||||
if (id && this.execHandler(id, aStanza))
|
||||
return;
|
||||
|
@ -678,9 +677,9 @@ XMPPSession.prototype = {
|
|||
this._account.onMessageStanza(aStanza);
|
||||
else if (name == "iq")
|
||||
this._account.onIQStanza(aStanza);
|
||||
}
|
||||
},
|
||||
},
|
||||
onXmppStanza: function(aStanza) {
|
||||
onXmppStanza(aStanza) {
|
||||
this.ERROR("should not be reached\n");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
|
||||
this.EXPORTED_SYMBOLS = ["Stanza", "XMPPParser", "SupportedFeatures"];
|
||||
|
||||
/* eslint-disable key-spacing */
|
||||
var NS = {
|
||||
xml : "http://www.w3.org/XML/1998/namespace",
|
||||
xhtml : "http://www.w3.org/1999/xhtml",
|
||||
xhtml_im : "http://jabber.org/protocol/xhtml-im",
|
||||
|
||||
//auth
|
||||
// auth
|
||||
client : "jabber:client",
|
||||
streams : "http://etherx.jabber.org/streams",
|
||||
stream : "urn:ietf:params:xml:ns:xmpp-streams",
|
||||
|
@ -26,20 +27,20 @@ var NS = {
|
|||
"private" : "jabber:iq:private",
|
||||
xdata : "jabber:x:data",
|
||||
|
||||
//roster
|
||||
// roster
|
||||
roster : "jabber:iq:roster",
|
||||
roster_versioning : "urn:xmpp:features:rosterver",
|
||||
roster_delimiter : "roster:delimiter",
|
||||
|
||||
//privacy lists
|
||||
// privacy lists
|
||||
privacy : "jabber:iq:privacy",
|
||||
|
||||
//discovering
|
||||
// discovering
|
||||
disco_info : "http://jabber.org/protocol/disco#info",
|
||||
disco_items : "http://jabber.org/protocol/disco#items",
|
||||
caps : "http://jabber.org/protocol/caps",
|
||||
|
||||
//addressing
|
||||
// addressing
|
||||
address : "http://jabber.org/protocol/address",
|
||||
|
||||
muc_user : "http://jabber.org/protocol/muc#user",
|
||||
|
@ -75,7 +76,7 @@ var NS = {
|
|||
avatar_metadata : "urn:xmpp:avatar:metadata",
|
||||
avatar_metadata_notify : "urn:xmpp:avatar:metadata+notify",
|
||||
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 = {
|
||||
|
@ -88,8 +89,9 @@ var TOP_LEVEL_ELEMENTS = {
|
|||
"urn:ietf:params:xml:ns:xmpp-sasl"],
|
||||
"success" : "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.
|
||||
// Don't forget to add your new features here.
|
||||
|
@ -101,18 +103,18 @@ var SupportedFeatures = [
|
|||
NS.muc,
|
||||
NS.ping,
|
||||
NS.vcard,
|
||||
NS.version
|
||||
NS.version,
|
||||
];
|
||||
|
||||
/* Stanza Builder */
|
||||
var Stanza = {
|
||||
NS: NS,
|
||||
NS,
|
||||
|
||||
/* Create a presence stanza */
|
||||
presence: (aAttr, aData) => Stanza.node("presence", null, aAttr, aData),
|
||||
|
||||
/* Create a message stanza */
|
||||
message: function(aTo, aMsg, aState, aAttr = {}, aData = []) {
|
||||
message(aTo, aMsg, aState, aAttr = {}, aData = []) {
|
||||
aAttr.to = aTo;
|
||||
if (!("type" in aAttr))
|
||||
aAttr.type = "chat";
|
||||
|
@ -127,7 +129,7 @@ var Stanza = {
|
|||
},
|
||||
|
||||
/* Create a iq stanza */
|
||||
iq: function(aType, aId, aTo, aData) {
|
||||
iq(aType, aId, aTo, aData) {
|
||||
let attrs = {type: aType};
|
||||
if (aId)
|
||||
attrs.id = aId;
|
||||
|
@ -137,7 +139,7 @@ var Stanza = {
|
|||
},
|
||||
|
||||
/* Create a XML node */
|
||||
node: function(aName, aNs, aAttr, aData) {
|
||||
node(aName, aNs, aAttr, aData) {
|
||||
let node = new XMLNode(null, aNs, aName, aName, aAttr);
|
||||
if (aData) {
|
||||
if (!Array.isArray(aData))
|
||||
|
@ -147,7 +149,7 @@ var Stanza = {
|
|||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/* Text node
|
||||
|
@ -158,22 +160,22 @@ function TextNode(aText) {
|
|||
TextNode.prototype = {
|
||||
get type() { return "text"; },
|
||||
|
||||
append: function(aText) {
|
||||
append(aText) {
|
||||
this.text += aText;
|
||||
},
|
||||
|
||||
/* 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 */
|
||||
getXML: function() {
|
||||
getXML() {
|
||||
return Cc["@mozilla.org/txttohtmlconv;1"]
|
||||
.getService(Ci.mozITXTToHTMLConv)
|
||||
.scanTXT(this.text, Ci.mozITXTToHTMLConv.kEntities);
|
||||
},
|
||||
|
||||
/* To read the unencoded data. */
|
||||
get innerText() { return this.text; }
|
||||
get innerText() { return this.text; },
|
||||
};
|
||||
|
||||
/* XML node */
|
||||
|
@ -211,12 +213,12 @@ XMLNode.prototype = {
|
|||
get type() { return "node"; },
|
||||
|
||||
/* Add a new child node */
|
||||
addChild: function(aNode) {
|
||||
addChild(aNode) {
|
||||
this.children.push(aNode);
|
||||
},
|
||||
|
||||
/* Add text node */
|
||||
addText: function(aText) {
|
||||
addText(aText) {
|
||||
let lastIndex = this.children.length - 1;
|
||||
if (lastIndex >= 0 && this.children[lastIndex] instanceof TextNode)
|
||||
this.children[lastIndex].append(aText);
|
||||
|
@ -225,14 +227,14 @@ XMLNode.prototype = {
|
|||
},
|
||||
|
||||
/* Get child elements by namespace */
|
||||
getChildrenByNS: function(aNS) {
|
||||
getChildrenByNS(aNS) {
|
||||
return this.children.filter(c => c.uri == aNS);
|
||||
},
|
||||
|
||||
/* Get the first element anywhere inside the node (including child nodes)
|
||||
that matches the query.
|
||||
A query consists of an array of localNames. */
|
||||
getElement: function(aQuery) {
|
||||
getElement(aQuery) {
|
||||
if (aQuery.length == 0)
|
||||
return this;
|
||||
|
||||
|
@ -250,7 +252,7 @@ XMLNode.prototype = {
|
|||
|
||||
/* Get all elements of the node (including child nodes) that match the query.
|
||||
A query consists of an array of localNames. */
|
||||
getElements: function(aQuery) {
|
||||
getElements(aQuery) {
|
||||
if (aQuery.length == 0)
|
||||
return [this];
|
||||
|
||||
|
@ -266,12 +268,12 @@ XMLNode.prototype = {
|
|||
},
|
||||
|
||||
/* Get immediate children by the node name */
|
||||
getChildren: function(aName) {
|
||||
getChildren(aName) {
|
||||
return this.children.filter((c) => (c.type != "text" && c.localName == aName));
|
||||
},
|
||||
|
||||
// Test if the node is a stanza and its namespace is valid.
|
||||
isXmppStanza: function() {
|
||||
isXmppStanza() {
|
||||
if (!TOP_LEVEL_ELEMENTS.hasOwnProperty(this.qName))
|
||||
return false;
|
||||
let ns = TOP_LEVEL_ELEMENTS[this.qName];
|
||||
|
@ -279,7 +281,7 @@ XMLNode.prototype = {
|
|||
},
|
||||
|
||||
/* Returns indented XML */
|
||||
convertToString: function(aIndent = "") {
|
||||
convertToString(aIndent = "") {
|
||||
let s =
|
||||
aIndent + "<" + this.qName + this._getXmlns() + this._getAttributeText();
|
||||
let content = "";
|
||||
|
@ -289,7 +291,7 @@ XMLNode.prototype = {
|
|||
},
|
||||
|
||||
/* Returns the XML */
|
||||
getXML: function() {
|
||||
getXML() {
|
||||
let s = "<" + this.qName + this._getXmlns() + this._getAttributeText();
|
||||
let innerXML = this.innerXML;
|
||||
return s + (innerXML ? ">" + innerXML + "</" + this.qName : "/") + ">";
|
||||
|
@ -299,13 +301,13 @@ XMLNode.prototype = {
|
|||
get innerText() { return this.children.map(c => c.innerText).join(""); },
|
||||
|
||||
/* Private methods */
|
||||
_getXmlns: function() { return this.uri ? " xmlns=\"" + this.uri + "\"" : ""; },
|
||||
_getAttributeText: function() {
|
||||
_getXmlns() { return this.uri ? " xmlns=\"" + this.uri + "\"" : ""; },
|
||||
_getAttributeText() {
|
||||
let s = "";
|
||||
for (let name in this.attributes)
|
||||
s += " " +name + "=\"" + this.attributes[name] + "\"";
|
||||
s += " " + name + "=\"" + this.attributes[name] + "\"";
|
||||
return s;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function XMPPParser(aListener) {
|
||||
|
@ -319,7 +321,7 @@ function XMPPParser(aListener) {
|
|||
}
|
||||
XMPPParser.prototype = {
|
||||
_destroyPending: false,
|
||||
destroy: function() {
|
||||
destroy() {
|
||||
// Avoid reference cycles
|
||||
this._parser.contentHandler = null;
|
||||
delete this._listener;
|
||||
|
@ -337,17 +339,17 @@ XMPPParser.prototype = {
|
|||
delete this._parser;
|
||||
},
|
||||
_dummyRequest: {
|
||||
cancel: function() { },
|
||||
isPending: function() { },
|
||||
resume: function() { },
|
||||
suspend: function() { }
|
||||
cancel() { },
|
||||
isPending() { },
|
||||
resume() { },
|
||||
suspend() { },
|
||||
},
|
||||
|
||||
_logReceivedData: function(aData) {
|
||||
_logReceivedData(aData) {
|
||||
this._listener.LOG("received:\n" + aData);
|
||||
},
|
||||
_inOnDataAvailable: false,
|
||||
onDataAvailable: function(aInputStream, aOffset, aCount) {
|
||||
onDataAvailable(aInputStream, aOffset, aCount) {
|
||||
this._inOnDataAvailable = true;
|
||||
this._parser.onDataAvailable(this._dummyRequest, null,
|
||||
aInputStream, aOffset, aCount);
|
||||
|
@ -357,10 +359,10 @@ XMPPParser.prototype = {
|
|||
},
|
||||
|
||||
/* nsISAXContentHandler implementation */
|
||||
startDocument: function() { },
|
||||
endDocument: function() { },
|
||||
startDocument() { },
|
||||
endDocument() { },
|
||||
|
||||
startElement: function(aUri, aLocalName, aQName, aAttributes) {
|
||||
startElement(aUri, aLocalName, aQName, aAttributes) {
|
||||
if (aQName == "stream:stream") {
|
||||
let node = new XMLNode(null, aUri, aLocalName, aQName, aAttributes);
|
||||
// The node we created doesn't have children, but
|
||||
|
@ -373,7 +375,7 @@ XMPPParser.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
this._listener._streamId = node.attributes["id"];
|
||||
this._listener._streamId = node.attributes.id;
|
||||
if (!("version" in node.attributes))
|
||||
this._listener.startLegacyAuth();
|
||||
|
||||
|
@ -388,7 +390,7 @@ XMPPParser.prototype = {
|
|||
this._node = node;
|
||||
},
|
||||
|
||||
characters: function(aCharacters) {
|
||||
characters(aCharacters) {
|
||||
if (!this._node) {
|
||||
// Ignore whitespace received on the stream to keep the connection alive.
|
||||
if (aCharacters.trim()) {
|
||||
|
@ -401,7 +403,7 @@ XMPPParser.prototype = {
|
|||
this._node.addText(aCharacters);
|
||||
},
|
||||
|
||||
endElement: function(aUri, aLocalName, aQName) {
|
||||
endElement(aUri, aLocalName, aQName) {
|
||||
if (aQName == "stream:stream") {
|
||||
this._logReceivedData("</stream:stream>");
|
||||
delete this._node;
|
||||
|
@ -435,18 +437,18 @@ XMPPParser.prototype = {
|
|||
this._node = this._node._parentNode;
|
||||
},
|
||||
|
||||
processingInstruction: function(aTarget, aData) { },
|
||||
processingInstruction(aTarget, aData) { },
|
||||
|
||||
/* nsISAXErrorHandler implementation */
|
||||
error: function(aError) {
|
||||
error(aError) {
|
||||
if (this._listener)
|
||||
this._listener.onXMLError("parse-error", aError);
|
||||
},
|
||||
fatalError: function(aError) {
|
||||
fatalError(aError) {
|
||||
if (this._listener)
|
||||
this._listener.onXMLError("parse-fatal-error", aError);
|
||||
},
|
||||
ignorableWarning: function(aError) {
|
||||
ignorableWarning(aError) {
|
||||
if (this._listener)
|
||||
this._listener.onXMLError("parse-warning", aError);
|
||||
},
|
||||
|
|
|
@ -32,7 +32,8 @@ var {
|
|||
XMPPAccountPrototype,
|
||||
} = ChromeUtils.import("resource:///modules/xmpp.jsm");
|
||||
var {
|
||||
XMPPSession, XMPPDefaultResource
|
||||
XMPPSession,
|
||||
XMPPDefaultResource,
|
||||
} = ChromeUtils.import("resource:///modules/xmpp-session.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "_", () =>
|
||||
|
@ -53,11 +54,11 @@ XMPPProtocol.prototype = {
|
|||
get normalizedName() { return "jabber"; },
|
||||
get name() { return "XMPP"; },
|
||||
get iconBaseURI() { return "chrome://prpl-jabber/skin/"; },
|
||||
getAccount: function(aImAccount) { return new XMPPAccount(this, aImAccount); },
|
||||
getAccount(aImAccount) { return new XMPPAccount(this, aImAccount); },
|
||||
|
||||
usernameSplits: [
|
||||
{get label() { return _("options.domain"); }, separator: "@",
|
||||
defaultValue: "jabber.org", reverse: true}
|
||||
defaultValue: "jabber.org", reverse: true},
|
||||
],
|
||||
|
||||
options: {
|
||||
|
@ -72,14 +73,14 @@ XMPPProtocol.prototype = {
|
|||
// "old_ssl" and "none" are also supported, but not exposed in the UI.
|
||||
// Any unknown value will fallback to the opportunistic_tls behavior.
|
||||
},
|
||||
default: "require_tls"
|
||||
default: "require_tls",
|
||||
},
|
||||
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; },
|
||||
|
||||
classID: Components.ID("{dde786d1-6f59-43d0-9bc8-b505a757fb30}")
|
||||
classID: Components.ID("{dde786d1-6f59-43d0-9bc8-b505a757fb30}"),
|
||||
};
|
||||
|
||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([XMPPProtocol]);
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче