<commit_before>'use strict';

var EventEmitter = require('events').EventEmitter,
    Connection = require('./connection'),
    JID = require('./jid').JID,
    ltx = require('ltx'),
    util = require('util'),
    crypto = require('crypto'),
    net = require('net'),
    sasl = require('./sasl'),
    fs = require('fs');

var NS_CLIENT = 'jabber:client';
var NS_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl';
var NS_XMPP_TLS = 'urn:ietf:params:xml:ns:xmpp-tls';
var NS_REGISTER = 'jabber:iq:register';
var NS_SESSION = 'urn:ietf:params:xml:ns:xmpp-session';
var NS_BIND = 'urn:ietf:params:xml:ns:xmpp-bind';
var NS_STANZAS = 'urn:ietf:params:xml:ns:xmpp-stanzas';

/**
 * params:
 *   options : port on which to listen to C2S connections
 *   options.port : xmpp tcp socket port
 *   options.domain : domain of xmpp server
 *   options.autostact : if we start listening at given port
 *   options.tls : wrapper object for tlc config
 *   options.tls.keyPath : path to key
 *   options.tls.certPath : path to certificate
 */
function C2SServer(options) {
    var self = this;
    this.options = {};
    if (options) this.options = options;
    this.availableSaslMechanisms = [];
    this.c2sPort = null;

    // And now start listening to connections on the port provided as an option.
    if (this.options.autostart !== false) {
        this.c2sPort = net.createServer(function(inStream) {
            self.acceptConnection(inStream)
        }).listen(this.options.port || this.C2S_PORT, this.options.bindAddress || '::')
    }

    // Load TLS key material
    if (this.options.tls) {
        var key = fs.readFileSync(options.tls.keyPath, 'ascii')
        var cert = fs.readFileSync(options.tls.certPath, 'ascii')
        this.credentials = crypto.createCredentials({
            key: key,
            cert: cert
        })
    }
}

util.inherits(C2SServer, EventEmitter);

C2SServer.prototype.C2S_PORT = 5222;

/**
 * Called upon TCP connection from client. */
C2SServer.prototype.acceptConnection = function(socket) {
    var stream = new C2SStream({
        socket: socket,
        server: this
    });<commit_msg>allow tls key & cert options as string<commit_after>'use strict';

var EventEmitter = require('events').EventEmitter,
    Connection = require('./connection'),
    JID = require('./jid').JID,
    ltx = require('ltx'),
    util = require('util'),
    crypto = require('crypto'),
    net = require('net'),
    sasl = require('./sasl'),
    fs = require('fs');

var NS_CLIENT = 'jabber:client';
var NS_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl';
var NS_XMPP_TLS = 'urn:ietf:params:xml:ns:xmpp-tls';
var NS_REGISTER = 'jabber:iq:register';
var NS_SESSION = 'urn:ietf:params:xml:ns:xmpp-session';
var NS_BIND = 'urn:ietf:params:xml:ns:xmpp-bind';
var NS_STANZAS = 'urn:ietf:params:xml:ns:xmpp-stanzas';

/**
 * params:
 *   options : port on which to listen to C2S connections
 *   options.port : xmpp tcp socket port
 *   options.domain : domain of xmpp server
 *   options.autostact : if we start listening at given port
 *   options.tls : wrapper object for tlc config
 *   options.tls.key : private key string
 *   options.tls.cert : certificate string
 *   options.tls.keyPath : path to key
 *   options.tls.certPath : path to certificate
 */
function C2SServer(options) {
    var self = this;
    this.options = {};
    if (options) this.options = options;
    this.availableSaslMechanisms = [];
    this.c2sPort = null;

    // And now start listening to connections on the port provided as an option.
    if (this.options.autostart !== false) {
        this.c2sPort = net.createServer(function(inStream) {
            self.acceptConnection(inStream)
        }).listen(this.options.port || this.C2S_PORT, this.options.bindAddress || '::')
    }

    // Load TLS key material
    if (this.options.tls) {
        var details = this.options.tls;
        details.key = details.key || fs.readFileSync(details.keyPath, 'ascii');
        details.cert = details.cert || fs.readFileSync(details.certPath, 'ascii');
        this.credentials = crypto.createCredentials(details);
    }
}

util.inherits(C2SServer, EventEmitter);

C2SServer.prototype.C2S_PORT = 5222;

/**
 * Called upon TCP connection from client. */
C2SServer.prototype.acceptConnection = function(socket) {
    var stream = new C2SStream({
        socket: socket,
        server: this
    });
{'fraction_non_alphanumeric': 0.13645714285714286, 'fraction_numerical': 0.0064, 'mean_word_length': 3.324110671936759, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7100581', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1450, 'n_words': 330}