From 4de2aa3ed29a512a22b6ab9b759947cdc16285b2 Mon Sep 17 00:00:00 2001 From: Jason Pincin Date: Wed, 19 Sep 2012 16:39:31 -0400 Subject: [PATCH] client-side support for paged search Re-applied paged search work by thomasv, without introducing logging changes. --- bin/ldapjs-search | 6 +++++ lib/client/client.js | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/bin/ldapjs-search b/bin/ldapjs-search index 06fd75a..66853bd 100755 --- a/bin/ldapjs-search +++ b/bin/ldapjs-search @@ -37,6 +37,7 @@ var opts = { 'control': Array, 'password': String, 'persistent': Boolean, + 'paged': Number, 'scope': String, 'timeout': Number, 'url': url @@ -49,6 +50,7 @@ var shortOpts = { 'D': ['--binddn'], 'w': ['--password'], 'p': ['--persistent'], + 'g': ['--paged'], 's': ['--scope'], 't': ['--timeout'], 'u': ['--url'] @@ -166,6 +168,10 @@ client.bind(parsed.binddn, parsed.password, function(err, res) { }); controls.push(pCtrl); } + if (parsed.paged) { + var ctrl = new ldap.PagedResultsControl({ value: { size: parsed.paged } }); + controls.push(ctrl); + } var req = { scope: parsed.scope || 'sub', filter: parsed.argv.remain[0], diff --git a/lib/client/client.js b/lib/client/client.js index 3504447..3b39550 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -10,6 +10,7 @@ var assert = require('assert-plus'); var Attribute = require('../attribute'); var Change = require('../change'); var Control = require('../controls/index').Control; +var PagedResultsControl = require('../controls/index').PagedResultsControl; var Protocol = require('../protocol'); var dn = require('../dn'); var errors = require('../errors'); @@ -770,6 +771,57 @@ Client.prototype._send = function _send(message, expect, emitter, callback) { return callback(null, obj); } // end function _done(event, obj) + function _continuePagedSearch(msg) { + // this function looks for a paged control in the response msg + // and continue searching or not according to RFC 2696 - http://www.ietf.org/rfc/rfc2696.txt + if (util.isArray(msg.controls) && msg.controls.length > 0) { + log.trace('message has %d controls', msg.controls.length); + + for (var i=0; i 0) { + log.trace('paged search: received cookie in response'); + + if (util.isArray(message.controls) && message.controls.length > 0) { + for (var j=0; j