### Using XOM to Access CDS

The following code fragments demonstrate an alternative way to set up the entry modification object for a ds_modify_entry( ) call, mainly for the sake of showing how the om_put( ) and om_write( ) functions are used.

The following technique is used to initialize the modification object:

1. The om_create( ) function is called to generate a private object of a specified class.

2. The om_put( ) function is called to copy statically declared attributes into a declared private object.

3. The om_write( ) function is called to write the value string, which is to be assigned to the attribute, into the private object.

4. The om_get( ) function is called to make the private object public.

5. The object is now public, and its address is inserted into the DS_C_ENTRY_MOD_LIST object's DS_CHANGES attribute.

The following new declarations are necessary:

OM_private_object newAttributeMod_priv;

/* ...handle to a private object to "om_put()" to */

OM_public_object newAttributeMod_pub;

/* ...to hold public object from "om_get()" */

OM_type types_to_include[] = {DS_ATTRIBUTE_TYPE, DS_ATTRIBUTE_VALUES,

DS_MOD_TYPE, OM_NO_MORE_TYPES};

/* ...that is, all attribute values of the Entry Modification */

/* object. For "om_put()" and "om_get()" */

char *my_string = "O brave new attribute";

/* ...value I want to write into attribute */

OM_value_position number_of_descriptors;

/* ...to hold value returned by "om_get()" */

First, use XOM to generate a private object of the desired class:

omStatus = om_create(DS_C_ENTRY_MOD, /* Class of object */

OM_TRUE, /* Initialize attributes per defaults */

xdsWorkspace, /* Our workspace handle */

&newAttributeMod_priv); /* Created object handle */

Next, copy the public object's attributes into the private object:

omStatus = om_put(newAttributeMod_priv, /* Private object to copy */

/* attributes into */

OM_REPLACE_ALL, /* Which attributes to replace in */

/* destination object */

Entry_Modification_Object, /* Source object to copy */

/* attributes from */

types_to_include, /* List of attribute types we */

/* want copied */

0, 0); /* Start-stop index for multivalued */

/* attributes; ignored with OM_REPLACE_ALL */

Since om_put( ) ignores the class of the source object (the object from which attributes are being copied), it is not necessary to declare class descriptors for the source objects. In other words, the static declarations could have omitted the OM_CLASS initializations if this technique were being used, for example:

static OM_descriptor Entry_Modification_Object_2[] = {

/* OM_OID_DESC(OM_CLASS, DS_C_ENTRY_MOD), */

/* Not needed for "om_put()" ... */

OM_OID_DESC(DS_ATTRIBUTE_TYPE, DSX_A_CDS_Class),

{DS_ATTRIBUTE_VALUES, OM_S_PRINTABLE_STRING, \

OM_STRING("Miscellaneous")},

{DS_MOD_TYPE, OM_S_ENUMERATION, DS_ADD_ATTRIBUTE},

OM_NULL_DESCRIPTOR

};

The OM_CLASS was already properly initialized by om_create( ).

Next, write the attribute value string into the private object:

omStatus = om_write(newAttributeMod_priv,/* Private object to write to */

DS_ATTRIBUTE_VALUES, /* Attribute type whose value */

/* we're writing */

0, /* Descriptor index if attribute is multivalued */

OM_S_PRINTABLE_STRING, /* Syntax of value */

0, /* Offset in source string to write from */

my_string); /* Source string to write from */

Now make the whole thing public again:

omStatus = om_get(newAttributeMod_priv, /* Private object to get */

0, /* Get everything */

types_to_include, /* All attribute types */

0, /* Unsupported argument */

0, 0, /* Start-stop descriptor index for multivalued */

/* attributes; ignored in this case */

&newAttributeMod_pub, /* Pointer to returned copy */

&number_of_descriptors); /* Number of attribute */

/* descriptors returned */

Finally, insert the address of the subobject into its superobject:

Entry_Modification_List_Object[1].value.object.object = \

newAttributeMod_pub;

###