<commit_before>var Connection = require('./connection');
var JID = require('./jid').JID;
var ltx = require('ltx');
var sys = require('sys');
var crypto = require('crypto');
var SRV = require('./srv');
var net = require('net');
var sasl = require('./sasl');
var router = require('./router');

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';

/**
* params:
*   options : port on which to listen to C2S connections */
function C2S(options) {
    var self = this;
    this.sessions = {}; // We may actually want to store sessions somewhere else than in memory (like Redis to support clustering.)
    this.options = options;

    // And now start listening to connections on the port provided as an option.
    net.createServer(function (inStream) {
        self.acceptConnection(inStream, options);
    }).listen(options.port, options.host);

    // Sets up a router for S2S.
    self.router = new router.Router();
    
    if(options.tls) {
        self.router.loadCredentials(options.domain, options.tls.keyPath, options.tls.certPath);
    }

    // Called when a stanza was received to be routed.
    self.router.register(options.domain, function(stanza) {
        self.route(stanza);
    });
}

sys.inherits(C2S, Connection.Connection);
exports.C2S = C2S;

/**
* Called upon TCP connection from client. */
C2S.prototype.acceptConnection = function(socket, options) {
    var client = new C2SClient(socket, this);
    socket.addListener('error', function() { });
    client.addListener('error', function() { });
}

/**
* C2S Router */
C2S.prototype.route = function(stanza) {
    var self = this;
    if(stanza.attrs && stanza.attrs.to) {
        var toJid = new JID(stanza.attrs.to);
        if(self.sessions.hasOwnProperty(toJid.bare().toString())) {
            // Now loop over all the sesssions and only send to the right jid(s)
            for(var resource in self.sessions[toJid.bare().toString()]) {
                if(toJid.bare().toString() === stanza.attrs.to || toJid.resource === resource) {<commit_msg>c2s: C2S listener only inherits from EventEmitter<commit_after>var EventEmitter = require('events').EventEmitter;
var Connection = require('./connection');
var JID = require('./jid').JID;
var ltx = require('ltx');
var sys = require('sys');
var crypto = require('crypto');
var SRV = require('./srv');
var net = require('net');
var sasl = require('./sasl');
var router = require('./router');

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';

/**
* params:
*   options : port on which to listen to C2S connections */
function C2S(options) {
    var self = this;
    this.sessions = {}; // We may actually want to store sessions somewhere else than in memory (like Redis to support clustering.)
    this.options = options;

    // And now start listening to connections on the port provided as an option.
    net.createServer(function (inStream) {
        self.acceptConnection(inStream, options);
    }).listen(options.port, options.host);

    // Sets up a router for S2S.
    self.router = new router.Router();
    
    if(options.tls) {
        self.router.loadCredentials(options.domain, options.tls.keyPath, options.tls.certPath);
    }

    // Called when a stanza was received to be routed.
    self.router.register(options.domain, function(stanza) {
        self.route(stanza);
    });
}

sys.inherits(C2S, EventEmitter);
exports.C2S = C2S;

/**
* Called upon TCP connection from client. */
C2S.prototype.acceptConnection = function(socket, options) {
    var client = new C2SClient(socket, this);
    socket.addListener('error', function() { });
    client.addListener('error', function() { });
}

/**
* C2S Router */
C2S.prototype.route = function(stanza) {
    var self = this;
    if(stanza.attrs && stanza.attrs.to) {
        var toJid = new JID(stanza.attrs.to);
        if(self.sessions.hasOwnProperty(toJid.bare().toString())) {
            // Now loop over all the sesssions and only send to the right jid(s)
            for(var resource in self.sessions[toJid.bare().toString()]) {
                if(toJid.bare().toString() === stanza.attrs.to || toJid.resource === resource) {
{'fraction_non_alphanumeric': 0.14827746741154563, 'fraction_numerical': 0.005121042830540037, 'mean_word_length': 3.4162384378211716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4576590', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1370, 'n_words': 353}