Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Completion callbacks [Table of Contents] Encryption callbacks

Open Client Client-Library/C Reference Manual

[-] Chapter 2 Topics
[-] Callbacks
[-] Directory callbacks

Directory callbacks

The ct_ds_lookup routine and the application's directory callback provide the mechanism which an application uses to examine the contents of directory entries.

When an application calls ct_ds_lookup to begin a directory search, Client-Library retrieves the appropriate entries from the directory and then calls the directory callback once for each entry. Each time the callback is invoked, it receives a pointer to one directory object structure. Each directory object structure contains a copy of information read from a directory entry.

Client-Library calls the directory callback once for each entry retrieved, as long as the callback returns CS_CONTINUE. When the callback returns CS_SUCCEED, Client-Library discards any remaining objects that the callback has not received.

The directory callback calls only the Client-Library routines ct_con_props, ct_config, ct_ds_objinfo, and ct_ds_dropobj. On an asynchronous connection, the application uses the completion callback to call other Client-Library routines (see Table 2-2).

Defining a directory callback

A directory callback is defined as follows:

CS_RETCODE CS_PUBLIC 
 directory_cb (connection, reqid, status,
              numentries, ds_object, userdata)
CS_CONNECTION   *connection;
 CS_INT                     reqid;
 CS_RETCODE          status;
 CS_INT                     numentries;
 CS_DS_OBJECT     *ds_object;
 CS_VOID                  *userdata;

where:

Directory search results processing

A directory callback typically performs the following to collect and optionally process the results of a directory search:

  1. Checks the values of status and numentries to determine whether the search was successful and whether entries were returned.

  2. Either saves the pointer to the directory object; or copies any information that it wants to keep (using ct_ds_objinfo to extract the information), then frees the directory object's memory with ct_ds_dropobj.

  3. Returns control to Client-Library in one of the following ways:

Callback invocation sequence

If a search is successful, Client-Library invokes the directory callback with numentries as the total number of entries to be examined. If the search finds no entries, numentries is 0. If the search finds one or more entries, numentries gives the number of unexamined entries including the current entry.

The application examines all the entries simply by returning CS_CONTINUE from the callback each time Client-Library invokes the callback. ct_ds_lookup invokes the callback repeatedly until one of the following conditions is satisfied:

If asynchronous network I/O is in effect for the connection, all invocations of the directory callback occur before Client-Library invokes the application's completion callback.

If synchronous network I/O is in effect for the connection, all invocations of the directory callback occur before ct_ds_lookup returns.

Directory callback example

Directory callbacks are used with ct_ds_lookup. See the ct_ds_lookup reference page for an example directory callback.


Completion callbacks [Table of Contents] Encryption callbacks