Directory callback example

The following example fragment defines a directory callback. This callback:

 /*
 ** directory_cb() -- Directory callback to install in Client-Library.
 **   When we call ct_ds_lookup(), Client-Library calls this function
 **   once for each object that is found in the search.
 **
 **   This particular callback collects the objects in
 **   the SERVER_INFO_LIST that is received as userdata.
 **
 ** Parameters
 **   conn -- The connection handle passed to ct_ds_lookup() to
 **      begin the search.
 **   reqid -- The request id for the operation (assigned by Client-Library).
 **   status -- CS_SUCCEED when search succeeded (ds_object is valid).
 **      CS_FAIL if the search failed (ds_object is not valid).
 **   numentries -- The count of objects to be returned for the
 **      search. Includes the current object. Can be 0 if search
 **      failed.
 **   ds_object -- Pointer to a CS_DS_OBJECT structure. Will
 **      be NULL if the search failed.
 **   userdata -- The address of user-allocated data that was
 **      passed to ct_ds_lookup().
 **
 **      This particular callback requires userdata to be the
 **      address of a valid, initialized SERVER_INFO_LIST pointer.
 **      (SERVER_INFO_LIST is an application data structure defined
 **      by this sample).
 **
 ** Returns
 **   CS_CONTINUE unless the SERVER_INFO_LIST pointed at by userdata fills
 **     up, then CS_SUCCEED to truncate the search results.
 */
 S_RETCODE          CS_PUBLIC
 directory_cb(conn, reqid, status, numentries, ds_object, userdata)
 CS_CONNECTION      *conn;
 CS_INT              reqid;
 CS_RETCODE          status;
 CS_INT              numentries;
 CS_DS_OBJECT       *ds_object;
 CS_VOID            *userdata;
 {
     CS_RETCODE          ret;
     SERVER_INFO_LIST   *server_list;
 
     if (status != CS_SUCCEED || numentries <= 0)
     {
         return CS_SUCCEED;
     }
     /*
     ** Append the object to the list of servers.
     */
     server_list = *((SERVER_INFO_LIST **)userdata);
     ret = sil_add_object(server_list, ds_object);
     if (ret != CS_SUCCEED)
     {
 
         /*
         ** Return CS_SUCCEED to discard the rest of the objects that were
         ** found in the search.
         */
         ex_error(
            "directory_cb: Too many servers! Truncating search results.");
         return CS_SUCCEED;
     }
     /*
     ** Return CS_CONTINUE so Client-Library will call us again if more
     ** entries are found.
     */
     return CS_CONTINUE;
 
 } /* directory_cb() */