Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.parser.on('startElement', (name, attrs) => {
if (!self.element) {
self.emit('startElement', name, attrs)
self.emit('start', new Element(name, attrs))
}
// TODO: refuse anything but
if (!self.element && (name === 'stream:stream')) {
self.emit('streamStart', attrs)
} else {
let child
if (!self.element) { // eslint-disable-line no-negated-condition
/* A new stanza */
child = new Stanza(name, attrs)
self.element = child
/* For maxStanzaSize enforcement */
self.bytesParsedOnStanzaBegin = self.bytesParsed
} else {
/* A child element of a stanza */
child = new ElementInterface(name, attrs)
Connection.prototype.onStanza = function (stanza) {
if (stanza.is('error', NS_STREAM)) {
var error = new Error('' + getAllText(stanza))
error.stanza = stanza
this.socket.emit('error', error)
} else if (stanza.is('features', this.NS_STREAM) &&
this.allowTLS &&
!this.isSecure &&
stanza.getChild('starttls', this.NS_XMPP_TLS)) {
/* Signal willingness to perform TLS handshake */
this.send(new Element('starttls', { xmlns: this.NS_XMPP_TLS }))
} else if (this.allowTLS &&
stanza.is('proceed', this.NS_XMPP_TLS)) {
/* Server is waiting for TLS handshake */
this.setSecure()
} else {
this.emit('stanza', stanza)
}
}
Connection.prototype.error = function (condition, message) {
this.emit('error', new Error(message))
if (!this.socket || !this.socket.writable) return
/* RFC 3920, 4.7.1 stream-level errors rules */
if (!this.streamOpened) this.openStream()
var error = new Element('stream:error')
error.c(condition, { xmlns: NS_XMPP_STREAMS })
if (message) {
error.c('text', {
xmlns: NS_XMPP_STREAMS,
'xml:lang': 'en'
}).t(message)
}
this.send(error)
this.end()
}
this.parser.on('startElement', (name, attrs) => {
if (!self.element) {
self.emit('startElement', name, attrs)
self.emit('start', new Element(name, attrs))
}
// TODO: refuse anything but
if (!self.element && (name === 'stream:stream')) {
self.emit('streamStart', attrs)
} else {
let child
if (!self.element) { // eslint-disable-line no-negated-condition
/* A new stanza */
child = new Stanza(name, attrs)
self.element = child
/* For maxStanzaSize enforcement */
self.bytesParsedOnStanzaBegin = self.bytesParsed
} else {
/* A child element of a stanza */
child = new ElementInterface(name, attrs)
self.element = self.element.cnode(child)
}
}
})
onEndElement(name) {
const {cursor} = this
if (name !== cursor.name) {
//
this.emit('error', new XMLError(`${cursor.name} must be closed.`))
return
}
if (cursor.parent) {
this.cursor = cursor.parent
return
}
if (cursor.is('open', 'urn:ietf:params:xml:ns:xmpp-framing')) {
this.emit('start', cursor)
} else if (cursor.is('close', 'urn:ietf:params:xml:ns:xmpp-framing')) {
this.emit('end', cursor)
} else {
this.emit('element', cursor)
}
stanza.attrs.to,
stanza.attrs.from,
undefined,
"member",
"participant",
true,
),
);
this.reflectXMPPMessage(chatName, x("presence", {
from: stanza.attrs.from,
to: null,
id: stanza.attrs.id,
}, x("x", {
xmlns: "http://jabber.org/protocol/muc#user",
}, [
x("item", {affiliation: "member", role: "participant"}),
]),
));
// 3. Room history
log.debug("Emitting history");
const history = this.roomHistory.get(room.roomId) || [];
history.forEach((e) => {
e.attrs.to = stanza.attrs.from;
// TODO: Add delay info to this.
this.xmpp.xmppWriteToStream(e);
});
log.debug("Emitting subject");
// 4. The room subject
this.xmpp.xmppSend(new StzaMessageSubject(chatName, stanza.attrs.from, undefined,
`${room.name || ""} ${room.topic ? "| " + room.topic : ""}`,
));
// All done, now for some house cleaning.
exports.exportCoreUtils = function (obj) {
// core
obj.Connection = Connection
obj.StreamParser = StreamParser
// jid
obj.JID = JID
// inherits
obj.inherits = inherits
// xml
obj.stanza = xml
obj.Stanza = xml.Stanza
obj.createStanza = xml.createStanza
obj.IQ = xml.IQ
obj.Presence = xml.Presence
obj.Message = xml.Message
obj.Parser = xml.Parser
obj.parse = xml.parse
// ltx
obj.ltx = xml.ltx
obj.createElement = xml.createElement
obj.Element = xml.Element
obj.escapeXML = xml.escapeXML
obj.escapeXMLText = xml.escapeXMLText
}
obj.Connection = Connection
obj.StreamParser = StreamParser
// jid
obj.JID = JID
// inherits
obj.inherits = inherits
// xml
obj.stanza = xml
obj.Stanza = xml.Stanza
obj.createStanza = xml.createStanza
obj.IQ = xml.IQ
obj.Presence = xml.Presence
obj.Message = xml.Message
obj.Parser = xml.Parser
obj.parse = xml.parse
// ltx
obj.ltx = xml.ltx
obj.createElement = xml.createElement
obj.Element = xml.Element
obj.escapeXML = xml.escapeXML
obj.escapeXMLText = xml.escapeXMLText
}
obj.StreamParser = StreamParser
// jid
obj.JID = JID
// inherits
obj.inherits = inherits
// xml
obj.stanza = xml
obj.Stanza = xml.Stanza
obj.createStanza = xml.createStanza
obj.IQ = xml.IQ
obj.Presence = xml.Presence
obj.Message = xml.Message
obj.Parser = xml.Parser
obj.parse = xml.parse
// ltx
obj.ltx = xml.ltx
obj.createElement = xml.createElement
obj.Element = xml.Element
obj.escapeXML = xml.escapeXML
obj.escapeXMLText = xml.escapeXMLText
}
// core
obj.Connection = Connection
obj.StreamParser = StreamParser
// jid
obj.JID = JID
// inherits
obj.inherits = inherits
// xml
obj.stanza = xml
obj.Stanza = xml.Stanza
obj.createStanza = xml.createStanza
obj.IQ = xml.IQ
obj.Presence = xml.Presence
obj.Message = xml.Message
obj.Parser = xml.Parser
obj.parse = xml.parse
// ltx
obj.ltx = xml.ltx
obj.createElement = xml.createElement
obj.Element = xml.Element
obj.escapeXML = xml.escapeXML
obj.escapeXMLText = xml.escapeXMLText
}