Support for RFC-2696 "LDAP Control Extension for
Simple Paged Results Manipulation" (Ulrich Doewich) git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@190 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
49
ldapsend.pas
49
ldapsend.pas
@@ -44,7 +44,7 @@
|
||||
|
||||
{:@abstract(LDAP client)
|
||||
|
||||
Used RFC: RFC-2251, RFC-2254, RFC-2829, RFC-2830
|
||||
Used RFC: RFC-2251, RFC-2254, RFC-2696, RFC-2829, RFC-2830
|
||||
}
|
||||
|
||||
{$IFDEF FPC}
|
||||
@@ -88,6 +88,7 @@ const
|
||||
LDAP_ASN1_ABANDON_REQUEST = $70;
|
||||
LDAP_ASN1_EXT_REQUEST = $77;
|
||||
LDAP_ASN1_EXT_RESPONSE = $78;
|
||||
LDAP_ASN1_CONTROLS = $A0;
|
||||
|
||||
|
||||
type
|
||||
@@ -218,6 +219,8 @@ type
|
||||
FSearchAliases: TLDAPSearchAliases;
|
||||
FSearchSizeLimit: integer;
|
||||
FSearchTimeLimit: integer;
|
||||
FSearchPageSize: integer;
|
||||
FSearchCookie: AnsiString;
|
||||
FSearchResult: TLDAPResultList;
|
||||
FExtName: AnsiString;
|
||||
FExtValue: AnsiString;
|
||||
@@ -315,6 +318,14 @@ type
|
||||
without limit.}
|
||||
property SearchTimeLimit: integer read FSearchTimeLimit Write FSearchTimeLimit;
|
||||
|
||||
{:Specify number of results to return per search request. Value 0 means
|
||||
no paging.}
|
||||
property SearchPageSize: integer read FSearchPageSize Write FSearchPageSize;
|
||||
|
||||
{:Cookie returned by paged search results. Use an empty string for the first
|
||||
search request.}
|
||||
property SearchCookie: AnsiString read FSearchCookie Write FSearchCookie;
|
||||
|
||||
{:Here is result of search command.}
|
||||
property SearchResult: TLDAPResultList read FSearchResult;
|
||||
|
||||
@@ -528,6 +539,8 @@ begin
|
||||
FSearchAliases := SA_Always;
|
||||
FSearchSizeLimit := 0;
|
||||
FSearchTimeLimit := 0;
|
||||
FSearchPageSize := 0;
|
||||
FSearchCookie := '';
|
||||
FSearchResult := TLDAPResultList.Create;
|
||||
end;
|
||||
|
||||
@@ -1079,7 +1092,7 @@ end;
|
||||
function TLDAPSend.Search(obj: AnsiString; TypesOnly: Boolean; Filter: AnsiString;
|
||||
const Attributes: TStrings): Boolean;
|
||||
var
|
||||
s, t, u: AnsiString;
|
||||
s, t, u, c: AnsiString;
|
||||
n, i, x: integer;
|
||||
r: TLDAPResult;
|
||||
a: TLDAPAttribute;
|
||||
@@ -1107,6 +1120,17 @@ begin
|
||||
t := t + ASNObject(Attributes[n], ASN1_OCTSTR);
|
||||
s := s + ASNObject(t, ASN1_SEQ);
|
||||
s := ASNObject(s, LDAP_ASN1_SEARCH_REQUEST);
|
||||
if FSearchPageSize > 0 then
|
||||
begin
|
||||
c := ASNObject('1.2.840.113556.1.4.319', ASN1_OCTSTR); // controlType: pagedResultsControl
|
||||
c := c + ASNObject(ASNEncInt(0), ASN1_BOOL); // criticality: FALSE
|
||||
t := ASNObject(ASNEncInt(FSearchPageSize), ASN1_INT); // page size
|
||||
t := t + ASNObject(FSearchCookie, ASN1_OCTSTR); // search cookie
|
||||
t := ASNObject(t, ASN1_SEQ); // wrap with SEQUENCE
|
||||
c := c + ASNObject(t, ASN1_OCTSTR); // add searchControlValue as OCTET STRING
|
||||
c := ASNObject(c, ASN1_SEQ); // wrap with SEQUENCE
|
||||
s := s + ASNObject(c, LDAP_ASN1_CONTROLS); // append Controls to SearchRequest
|
||||
end;
|
||||
Fsock.SendString(BuildPacket(s));
|
||||
repeat
|
||||
s := ReceiveResponse;
|
||||
@@ -1147,6 +1171,27 @@ begin
|
||||
FReferals.Add(ASNItem(n, t, x));
|
||||
end;
|
||||
until FResponseCode = LDAP_ASN1_SEARCH_DONE;
|
||||
n := 1;
|
||||
ASNItem(n, t, x);
|
||||
if x = LDAP_ASN1_CONTROLS then
|
||||
begin
|
||||
ASNItem(n, t, x);
|
||||
if x = ASN1_SEQ then
|
||||
begin
|
||||
s := ASNItem(n, t, x);
|
||||
if s = '1.2.840.113556.1.4.319' then
|
||||
begin
|
||||
s := ASNItem(n, t, x); // searchControlValue
|
||||
n := 1;
|
||||
ASNItem(n, s, x);
|
||||
if x = ASN1_SEQ then
|
||||
begin
|
||||
ASNItem(n, s, x); // total number of result records, if known, otherwise 0
|
||||
FSearchCookie := ASNItem(n, s, x); // active search cookie, empty when done
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
Result := FResultCode = 0;
|
||||
end;
|
||||
|
||||
|
Reference in New Issue
Block a user