You are looking at historical revision 691 of this page. It may differ significantly from its current revision.
Parser and generator for LDIF (LDAP Data Interchange Format) files.
The parser returns a stream of hashes, one for each entry in the file. Each hash has as keys names of attributes and as values lists of the values for the given keys.
The generator expects information in exactly the same format (which makes it easy to perform transformations in LDIF files, for example).
Getting an attribute of all objects
The following example prints all the values for the cn attributes for all objects in the LDIF file:
(use stream-ldif format-modular) (stream-for-each (lambda (hash) (for-each (lambda (value) (format #t "~A~%" (stream->string value))) (hash-table-ref/default hash 'cn '()))) (stream->ldif (port->stream (current-input-port))))
The stream-ldif egg was created by Alejandro Forero Cuervo.
Parsing an LDIF file
Given a stream of characters corresponding to a file in the LDIF format, returns a stream of hash tables. Each hash table corresponds to one of the entries in the LDIF file. The hash tables are indexed by the names of the attributes in lowercase (as symbols); each value is a list with all the values (as streams of characters).
The parsing of the LDIF stream is done in a lazy file, reading entries only as required (as the stream of hash table is built).
Generating an LDIF file
Performs the opposite function of stream->ldif: given a stream with hashes corresponding to changes, produces an LDIF file and returns it as a stream of characters. Each hash should be indexed by the names of the attribute as symbols; the value for each entry must be a list with the values for the attributes as streams of characters encoded in UTF-8.
Note that each hash table must always contain a dn entry having its distinguished name as its first element.
The stream LDIF egg for Chicken Scheme is in the public domain and may be reproduced or copied without permission from its author. Citation of the source is appreciated.
- Adapted to SRFI-69-compatible hash-tables
- First public release