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()
}
headerElement() {
return new xml.Element('', {
version: '1.0',
xmlns: this.NS,
})
}
footerElement() {
return new xml.Element('close', {
xmlns: NS_FRAMING,
})
}
onStartElement(name, attrs) {
const element = new Element(name, attrs)
const {cursor} = this
if (cursor) {
cursor.append(element)
}
this.cursor = element
}