<commit_before>var ldapbinding = require("./build/default/LDAP");

var Connection = function() {
    var callbacks = {};
    var binding = new ldapbinding.LDAPConnection();
    var self = this;
    var querytimeout = 5000;

    self.SetCallback(msgid, CB) {
        if (msgid > 0) {
            callbacks[msgid] = CB;
            callbacks[msgid].tm = setTimeout(function() {
                CB(msgid, -2);
                delete callbacks[msgid];
            }, querytimeout);
        }
        return msgid;
    }

    self.Open = function(uri) {
        return binding.Open(uri);
    }

    self.Search = function(base, scope, filter, attrs, CB) {
        var msgid = binding.Search(base, scope, filter, attrs);
        return self.SetCallback(msgid, CB);
    }

    self.Add = function(dn, data, CB) {
        var msgid = binding.Add(dn, data);
        return self.SetCallback(msgid, CB);
    }

    self.Modify = function(dn, data, CB) {
        var msgid = binding.Modify(dn, data);
        return self.SetCallback(msgid, CB);
    }

    binding.addListener("searchresult", function(msgid, result, data) {
        clearTimeout(callbacks[msgid].tm);
        callbacks[msgid](msgid, result, data);
        delete(callbacks[msgid]);
    });

    binding.addListener("result", function(msgid, result) {
        clearTimeout(callbacks[msgid].tm);
        callbacks[msgid](msgid, result);
        delete(callbacks[msgid]);
    });
}

exports.Connection = Connection;<commit_msg>SimpleBind() implemented. Now handles NULL callbacks.<commit_after>var ldapbinding = require("./build/default/LDAP");

var Connection = function() {
    var callbacks = {};
    var binding = new ldapbinding.LDAPConnection();
    var self = this;
    var querytimeout = 5000;
    var totalqueries = 0;

    self.SetCallback = function(msgid, CB) {
        if (msgid > 0) {
            totalqueries++;
            if (typeof(CB) == 'function') {
                callbacks[msgid] = CB;
                callbacks[msgid].tm = setTimeout(function() {
                    CB(msgid, -2);
                    delete callbacks[msgid];
                }, querytimeout);
            }
        }
        return msgid;
    }

    self.Open = function(uri) {
        return binding.Open(uri);
    }

    self.Search = function(base, scope, filter, attrs, CB) {
        var msgid = binding.Search(base, scope, filter, attrs);
        return self.SetCallback(msgid, CB);
    }

    self.SimpleBind = function(binddn, password, CB) {
        var msgid;
        if (arguments.length == 0) {
            msgid = binding.SimpleBind();
        } else {
            msgid = binding.SimpleBind(binddn, password);
        }
        return self.SetCallback(msgid, CB);
    }

    self.Add = function(dn, data, CB) {
        var msgid = binding.Add(dn, data);
        return self.SetCallback(msgid, CB);
    }

    self.Modify = function(dn, data, CB) {
        var msgid = binding.Modify(dn, data);
        return self.SetCallback(msgid, CB);
    }

    binding.addListener("searchresult", function(msgid, result, data) {
        if (callbacks[msgid]) {
            clearTimeout(callbacks[msgid].tm);
            callbacks[msgid](msgid, result, data);
            delete(callbacks[msgid]);
        }
    });

    binding.addListener("result", function(msgid, result) {
        if (callbacks[msgid]) {
            clearTimeout(callbacks[msgid].tm);
            callbacks[msgid](msgid, result);
            delete(callbacks[msgid]);
        }
    });

}

exports.Connection = Connection;
{'fraction_non_alphanumeric': 0.13231552162849872, 'fraction_numerical': 0.003958156629912355, 'mean_word_length': 2.1759425493716336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '266959', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1011, 'n_words': 220}