2.2 Buffer Tasks

Many eDirectory functions require input buffers or output buffers. Many require both. This section provides procedures for managing these buffers.

2.2.1 Preparing eDirectory Input Buffers

This task prepares a memory buffer for writing data to eDirectory.

  1. Allocate memory for the input buffer by calling NWDSAllocBuf. The following code allocates a buffer of size DEFAULT_MESSAGE_LEN constant.

      pBuf_T    inputBuffer; 
       
      ccode = NWDSAllocBuf (DEFAULT_MESSASE_LEN, &inputBuffer); 
      if (ccode) 
          printf("Error while allocating buffer: %d\n", ccode);
      
  2. Initialize the input buffer by calling NWDSInitBuf. Choose one of the Initialization Operations for eDirectory Input Buffers according to the intended operation. The following code initializes an input buffer for a read operation.

      ccode = NWDSInitBuf(context, DSV_READ, &inputBuffer); 
      if (ccode) 
          printf("Error while initializing buffer: %d\n", ccode);
      
  3. Place the input data into the buffer using the eDirectory Input Buffer Functions that correspond to the data type you are handling.

      ccode = NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &inputBuffer); 
      if (!ccode) 
      {  ccode = NWDSInitBuf (context, DSV_READ, &inputBuffer); 
         ccode = NWDSPutAttrName (context, inputBuffer, "surname"); 
         ccode = NWDSPutAttrName (context, inputBuffer, "CN"); 
         ccode = NWDSPutAttrName (context, inputBuffer, "Login Script"); 
         ccode = NWDSPutAttrName (context, inputBuffer, "Language"); 
         ccode = NWDSPutAttrName (context, inputBuffer, "Email Address"); 
      }
      

NOTE:Don’t add data to a buffer directly. eDirectory contains a complete set of input buffer functions that operate on buffers allowing you to enter data. To add data to the Buffer, you must use the function that corresponds to the data type you are handling.

See Also:

2.2.2 Preparing eDirectory Output Buffers

This task prepares a buffer for retrieving data from an eDirectory directory.

  1. Allocate memory for the input buffer by calling NWDSAllocBuf. The following code allocates a buffer of size DEFAULT_MESSAGE_LEN constant.

      pBuf_T    outputBuffer; 
       
      ccode = NWDSAllocBuf (DEFAULT_MESSASE_LEN, &outputBuffer); 
      if (ccode) 
          printf("Error while allocating buffer: %d\n", ccode);
      

NOTE:Unlike an input buffer, you don’t need to initialize an output buffer.

Don’t retrieve or delete data from a buffer directly. eDirectory contains a complete set of eDirectory Output Buffer Functions that operate on buffers allowing you to retrieve data. To read data from the Buffer, you must use the function that corresponds to the data type you are handling.

See Also:

2.2.3 Retrieving Results from eDirectory Output Buffers

This task reads data from an output buffer.

  1. Determine the number of objects in the buffer by calling NWDSGetObjectCount.

  2. Determine the amount of memory required for each object attribute by calling NWDSComputeAttrValSize.

  3. Allocate memory to receive the attribute data.

  4. Retrieve the attribute data from the buffer by calling the eDirectory Output Buffer Functions that correspond to the data type you are handling.

  5. Loop through steps 2, 3, and 4 until all attributes of every object in the buffer has been retrieved.

NOTE:Data must be read from an output buffer sequentially. Do not skip an item, even if you already know its value.

See Also:

2.2.4 Freeing eDirectory Buffers

This task releases a buffer allocated by NWDSAllocBuf. After you have executed an operation using a buffer and retrieved the information from the output buffer (if applicable), always free the buffer memory.

  1. To free buffer memory, call NWDSFreeBuf, as shown in the following example.

      NWDSFreeBuf(outBuf); // Always returns successful
      

See Also: