---
name: "ldap_entry2text_search"
section: "3"
platform: "linux"
package: "libldap2-dev"
version: "2.0.23-6.3"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/ldap_entry2text"
---

# ldap\_entry2text\_search(3)

LDAP entry display routines

Part of [ldap\_entry2text(3)](/ldap_entry2text/3.md).

## NAME

ldap\_entry2text, ldap\_entry2text\_search, ldap\_vals2text - LDAP entry display routines

## SYNOPSIS

```
#include <ldap.h>
#include <disptmpl.h>
```

**int ldap\_entry2text( ld, buf, entry, tmpl, defattrs, defvals, writeproc,**\
     **writeparm, eol, rdncount, opts )**\
 	LDAP			\*ld;\
 	char			\*buf;\
 	LDAPMessage		\*entry;\
 	struct ldap\_disptmpl	\*tmpl;\
 	char			\*\*defattrs;\
 	char			\*\*\*defvals;\
 	int			(\*writeproc)();\
 	void			\*writeparm;\
 	char			\*eol;\
 	int			rdncount;\
 	unsigned long		opts;

**int ldap\_entry2text\_search( ld, entry, tmpllist, defattrs, defvals,**\
     **writeproc, writeparm, eol, rdncount, opts )**\
 	LDAP			\*ld;\
 	char			\*dn;\
 	char			\*base;\
 	LDAPMessage		\*entry;\
 	struct ldap\_disptmpl	\*tmpllist;\
 	char			\*\*defattrs;\
 	char			\*\*\*defvals;\
 	int			(\*writeproc)();\
 	void			\*writeparm;\
 	char			\*eol;\
 	int			rdncount;\
 	unsigned long		opts;

**int ldap\_vals2text( ld, buf, vals, label, labelwidth, syntaxid, writeproc,**\
     **writeparm, eol, rdncount )**\
 	LDAP			\*ld;\
 	char			\*buf;\
 	char			\*\*vals;\
 	char			\*label;\
 	int			labelwidth;\
 	unsigned long		syntaxid;\
 	int			(\*writeproc)();\
 	void			\*writeparm;\
 	char			\*eol;\
 	int			rdncount;

**int ldap\_entry2html( ld, buf, entry, tmpl, defattrs, defvals, writeproc,**\
     **writeparm, eol, rdncount, opts )**\
 	LDAP			\*ld;\
 	char			\*buf;\
 	LDAPMessage		\*entry;\
 	struct ldap\_disptmpl	\*tmpl;\
 	char			\*\*defattrs;\
 	char			\*\*\*defvals;\
 	int			(\*writeproc)();\
 	void			\*writeparm;\
 	char			\*eol;\
 	int			rdncount;\
 	unsigned long		opts;\
 	char			\*urlprefix;\
 	char			\*base;

**int ldap\_entry2html\_search( ld, entry, tmpllist, defattrs, defvals,**\
     **writeproc, writeparm, eol, rdncount, opts )**\
 	LDAP			\*ld;\
 	char			\*dn;\
 	LDAPMessage		\*entry;\
 	struct ldap\_disptmpl	\*tmpllist;\
 	char			\*\*defattrs;\
 	char			\*\*\*defvals;\
 	int			(\*writeproc)();\
 	void			\*writeparm;\
 	char			\*eol;\
 	int			rdncount;\
 	unsigned long		opts;\
 	char			\*urlprefix;

**int ldap\_vals2html( ld, buf, vals, label, labelwidth, syntaxid, writeproc,**\
     **writeparm, eol, rdncount )**\
 	LDAP			\*ld;\
 	char			\*buf;\
 	char			\*\*vals;\
 	char			\*label;\
 	int			labelwidth;\
 	unsigned long		syntaxid;\
 	int			(\*writeproc)();\
 	void			\*writeparm;\
 	char			\*eol;\
 	int			rdncount;\
 	char			\*urlprefix;

**#define LDAP\_DISP\_OPT\_AUTOLABELWIDTH	0x00000001** **#define LDAP\_DISP\_OPT\_HTMLBODYONLY      0x00000002**

**#define LDAP\_DTMPL\_BUFSIZ		2048**

## DESCRIPTION

These functions use the LDAP display template routines (see [ldap\_disptmpl(3)](/ldap_disptmpl/3.md) and ldap\_templates.conf(5)) to produce a plain text or an HyperText Markup Language (HTML) display of an entry or a set of values.  Typical plain text output produced for an entry might look like:

```
    "Barbara J Jensen, Information Technology Division"
     Also Known As:
		   Babs Jensen
		   Barbara Jensen
		   Barbara J Jensen
     E-Mail Address:
		   bjensen@terminator.rs.itd.umich.edu
     Work Address:
		   535 W. William
		   Ann Arbor, MI 48103
     Title:
		   Mythical Manager, Research Systems
     ...
```

The exact output produced will depend on the display template configuration. HTML output is similar to the plain text output, but more richly formatted.

**ldap\_entry2text()** produces a text representation of *entry* and writes the text by calling the *writeproc* function.  All of the attributes values to be displayed must be present in *entry;* no interaction with the LDAP server will be performed within **ldap\_entry2text.** *ld* is the LDAP pointer obtained by a previous call to **ldap\_open.** *writeproc* should be declared as:

```
int writeproc( writeparm, p, len )
	void		*writeparm;
	char		*p;
	int		len;
```

where *p* is a pointer to text to be written and *len* is the length of the text. *p* is guaranteed to be zero-terminated.  Lines of text are terminated with the string *eol.* *buf* is a pointer to a buffer of size **LDAP\_DTMPL\_BUFSIZ** or larger.  If *buf is* **NULL** then a buffer is allocated and freed internally. *tmpl* is a pointer to the display template to be used (usually obtained by calling **ldap\_oc2template).** If *tmpl* is NULL, no template is used and a generic display is produced. *defattrs* is a NULL-terminated array of LDAP attribute names which you wish to provide default values for (only used if *entry* contains no values for the attribute).  An array of NULL-terminated arrays of default values corresponding to the attributes should be passed in *defvals. The* *rdncount* parameter is used to limit the number of Distinguished Name (DN) components that are actually displayed for DN attributes.  If *rdncount* is zero, all components are shown. *opts* is used to specify output options.  The only values currently allowed are zero (default output), **LDAP\_DISP\_OPT\_AUTOLABELWIDTH** which causes the width for labels to be determined based on the longest label in *tmpl, and* **LDAP\_DISP\_OPT\_HTMLBODYONLY.** The  **LDAP\_DISP\_OPT\_HTMLBODYONLY** option instructs the library not to include \<HTML\>, \<HEAD\>, \<TITLE\>, and \<BODY\> tags.  In other words, an HTML fragment is generated, and the caller is responsible for prepending and appending the appropriate HTML tags to construct a correct HTML document.

**ldap\_entry2text\_search()** is similar to **ldap\_entry2text,** and all of the like-named parameters have the same meaning except as noted below.   If *base* is not NULL, it is the search base to use when executing search actions.  If it is NULL, search action template items are ignored.  If *entry* is not NULL, it should contain the *objectClass* attribute values for the entry to be displayed.  If *entry* is NULL, *dn* must not be NULL, and  **ldap\_entry2text\_search** will retrieve the objectClass values itself by calling **ldap\_search\_s.** **ldap\_entry2text\_search** will determine the appropriate display template to use by calling **ldap\_oc2template,** and will call **ldap\_search\_s** to retrieve any attribute values to be displayed.  The *tmpllist* parameter is a pointer to the entire list of templates available (usually obtained by calling **ldap\_init\_templates** or **ldap\_init\_templates\_buf).** If *tmpllist* is NULL, **ldap\_entry2text\_search** will attempt to read a load templates from the default template configuration file /etc/ldap/ldaptemplates.conf.

**ldap\_vals2text** produces a text representation of a single set of LDAP attribute values.  The *ld,* *buf,* *writeproc,* *writeparm,* *eol,* and *rdncount* parameters are the same as the like-named parameters for **ldap\_entry2text.** *vals* is a NULL-terminated list of values, usually obtained by a call to **ldap\_get\_values.** *label* is a string shown next to the values (usually a friendly form of an LDAP attribute name). *labelwidth* specifies the label margin, which is the number of blank spaces displayed to the left of the values.  If zero is passed, a default label width is used. *syntaxid* is a display template attribute syntax identifier (see [ldap\_disptmpl(3)](/ldap_disptmpl/3.md) for a list of the pre-defined  **LDAP\_SYN\_...** values).

**ldap\_entry2html** produces an HTML representation of  *entry.* It behaves exactly like [ldap\_entry2text(3)](/ldap_entry2text/3.md), except for the formatted output and the addition of two parameters. *urlprefix* is the starting text to use when constructing an LDAP URL.  The default is the string *ldap:///* The second additional parameter, *base,* the search base to use when executing search actions.  If it is NULL, search action template items are ignored.

**ldap\_entry2html\_search** behaves exactly like [ldap\_entry2text\_search(3)](/ldap_entry2text_search/3.md), except HTML output is produced and one additional parameter is required. *urlprefix* is the starting text to use when constructing an LDAP URL.  The default is the string *ldap:///*

**ldap\_vals2html** behaves exactly like ldap\_vals2text, except HTML output is produced and one additional parameter is required. *urlprefix* is the starting text to use when constructing an LDAP URL.  The default is the string *ldap:///*

## ERRORS

These routines all return an LDAP error code (LDAP\_SUCCESS is returned if no error occurs).  See [ldap\_error(3)](/ldap_error/3.md) for details. The *ld\_errno* field of the *ld* parameter is also set to indicate the error.

## FILES

/etc/ldap/ldaptemplates.conf

## SEE ALSO

[**ldap**(3)](/ldap/3.md), [**ldap\_disptmpl**(3)](/ldap_disptmpl/3.md), [**ldaptemplates.conf**(5)](/ldaptemplates.conf/5.md)

## ACKNOWLEDGEMENTS

**OpenLDAP** is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). **OpenLDAP** is derived from University of Michigan LDAP 3.3 Release.
