Skip to content

Commit

Permalink
Bugfixes and tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Childs committed May 10, 2011
1 parent f376b73 commit 87d1756
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
42 changes: 29 additions & 13 deletions LDAP.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ var Connection = function() {
var self = this;
var requestcount = 0;
var reconnects = 0;
var retries = 0;
var connectretries = 0;
var uri;
var openSuccessCB;
var openErrCB;
var openCB;

self.maxconnectretries = 3;
self.retrywait = 10000;

binding.addListener("search", function(msgid, result) {
if (typeof(requests[msgid].successCB) != "undefined") {
Expand Down Expand Up @@ -60,23 +62,29 @@ var Connection = function() {
requests[msgid] = r;
}

self.Open = function(u, sCB, eCB) {
self.Open = function(u, CB) {
startup = new Date();
openSuccessCB = sCB;
openErrCB = eCB;
openCB = CB;
uri = u;

self.openWithRetry();
}

self.openWithRetry = function() {
if (binding.open(uri)) {
retries++;
setTimeout(self.openWithRetry, 1000);
console.log("Open failed. Retry in 1 s");
var err;
if (err = binding.open(uri)) {
if (++connectretries > self.maxconnectretries) {
connectretries = 0;
if (typeof openCB == 'function') { openCB(err); }
return;
}
setTimeout(self.openWithRetry, self.retrywait);
console.log("Open "+connectretries+" of "+
self.maxconnectretries+
" failed. Retry in "+self.retrywait+" ms");
} else {
retries=0;
if (typeof openSuccessCB == 'function') { openSuccessCB(); }
connectretries=0;
if (typeof openCB == 'function') { openCB(); }
}
}

Expand Down Expand Up @@ -104,6 +112,15 @@ var Connection = function() {
binding.close(a);
}

self.modify = function (dn, mods, successCB, errCB) {
requestcount++;
var r = new Request(successCB, errCB);
var msgid = r.doAction(function () {
return binding.modify(dn, mods);
});
requests[msgid] = r;
};

self.SearchAuthenticate = function(base, filter, password, CB) {
self.Search(base, filter, "", function(res) {
// TODO: see if there's only one result, and exit if not
Expand All @@ -123,7 +140,6 @@ var Connection = function() {
'startup' : startup,
'reconnects' : reconnects };
}

}

var Request = function(successCB, errCB) {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"type": "git",
"url": "git://github.com/jeremycx/node-LDAP.git"
},
"main": "ldap",
"main": "./LDAP.js",
"engines": {
"node": ">= 0.4.0"
},
"dependencies": {},
"dependencies": {
"nodeunit": ">=0.5.1"
},
"devDependencies": {}
}
7 changes: 5 additions & 2 deletions src/ldap_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ class Connection : EventEmitter {
HandleScope scope;
LDAPURLDesc *ludpp;
int fd; //TODO: LDAP protocol version should be a parameter to open
int err;

ldap_url_parse(uri, &ludpp); // TODO: errcheck
if (err = ldap_url_parse(uri, &ludpp)) {
return err;
}

char * host = ludpp->lud_host;
int port = ludpp->lud_port;
int ver = 3;

ldap = ldap_open(host, port); // TODO: errcheck
ldap = ldap_open(host, port);

// TODO: set default base if present in uri.

Expand Down

0 comments on commit 87d1756

Please sign in to comment.