<commit_before>"use strict";

var WildEmitter = require('wildemitter');
var _ = require('underscore');
var util = require('util');
var Promise = require('bluebird');
var async = require('async');
var uuid = require('node-uuid');
var b64decode = require('atob');
var b64encode = require('btoa');
var SASL = require('./stanza/sasl');
var Message = require('./stanza/message');
var Presence = require('./stanza/presence');
var StreamError = require('./stanza/streamError');
var Iq = require('./stanza/iq');
var JID = require('./jid');
var StreamManagement = require('./sm');
var WSConnection = require('./websocket');
var BOSHConnection = require('./bosh');
var getHostMeta = require('hostmeta');
var SASLFactory = require('saslmechanisms');

SASLFactory = new SASLFactory();
SASLFactory.use(require('sasl-external'));
SASLFactory.use(require('sasl-scram-sha-1'));
SASLFactory.use(require('sasl-digest-md5'));
SASLFactory.use(require('sasl-plain'));
SASLFactory.use(require('sasl-anonymous'));


// Ensure that all basic stanza relationships are established
require('./stanza/stream');
require('./stanza/sm');
require('./stanza/error');
require('./stanza/streamFeatures');
require('./stanza/bind');
require('./stanza/session');


function Client(opts) {
    var self = this;

    WildEmitter.call(this);

    opts = opts || {};
    this.config = _.extend({
        useStreamManagement: true,
        transports: ['websocket', 'bosh']
    }, opts);
<commit_msg>Make SASL mechanisms configurable.<commit_after>"use strict";

var WildEmitter = require('wildemitter');
var _ = require('underscore');
var util = require('util');
var Promise = require('bluebird');
var async = require('async');
var uuid = require('node-uuid');
var b64decode = require('atob');
var b64encode = require('btoa');
var SASL = require('./stanza/sasl');
var Message = require('./stanza/message');
var Presence = require('./stanza/presence');
var StreamError = require('./stanza/streamError');
var Iq = require('./stanza/iq');
var JID = require('./jid');
var StreamManagement = require('./sm');
var WSConnection = require('./websocket');
var BOSHConnection = require('./bosh');
var getHostMeta = require('hostmeta');
var SASLFactory = require('saslmechanisms');

SASLFactory = new SASLFactory();

var SASL_MECHS = {
    external: require('sasl-external'),
    'scram-sha-1': require('sasl-scram-sha-1'),
    'digest-md5': require('sasl-digest-md5'),
    plain: require('sasl-plain'),
    anonymous: require('sasl-anonymous')
};


// Ensure that all basic stanza relationships are established
require('./stanza/stream');
require('./stanza/sm');
require('./stanza/error');
require('./stanza/streamFeatures');
require('./stanza/bind');
require('./stanza/session');


function Client(opts) {
    var self = this;

    WildEmitter.call(this);

    opts = opts || {};
    this.config = _.extend({
        useStreamManagement: true,
        transports: ['websocket', 'bosh'],
        sasl: ['external', 'scram-sha-1', 'digest-md5', 'plain', 'anonymous']
    }, opts);


    // Enable SASL authentication mechanisms (and their preferred order)
    // based on user configuration.
    if (!_.isArray(this.config.sasl)) {
        this.config.sasl = [this.config.sasl];
    }
    this.config.sasl.forEach(function (mech) {
        if (typeof mech === 'string') {
            var existingMech = SASL_MECHS[mech.toLowerCase()];
            if (existingMech) {
                SASLFactory.use(existingMech);
            }
        } else {
            SASLFactory.use(mech);
        }
    });


{'fraction_non_alphanumeric': 0.18245910885504793, 'fraction_numerical': 0.0045121263395375075, 'mean_word_length': 4.103597122302158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '292201', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1105, 'n_words': 238}