#### Coding Examples

In the following code fragments a set of declarations similar to those in the previous examples is assumed.

The ds_modify_entry( ) function, which is called to add new attributes to an entry or to write new values into existing attributes, requires a DS_C_ENTRY_MOD_LIST input object whose contents specify the attributes and values to be written to the entry. The name, as always, is specified in a DS_C_DS_DN object. The following is a static declaration of such a list, which consists of two attributes:

static OM_descriptor Entry_Modification_Object_1[] = {

OM_OID_DESC(OM_CLASS, DS_C_ENTRY_MOD),

OM_OID_DESC(DS_ATTRIBUTE_TYPE, DSX_A_CDS_Brave_New_Attrib),

{DS_ATTRIBUTE_VALUES, OM_S_PRINTABLE_STRING,

OM_STRING("O brave new attribute")},

{DS_MOD_TYPE, OM_S_ENUMERATION, DS_ADD_ATTRIBUTE},

OM_NULL_DESCRIPTOR

};

static OM_descriptor Entry_Modification_Object_2[] = {

OM_OID_DESC(OM_CLASS, DS_C_ENTRY_MOD),

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

};

static OM_descriptor Entry_Modification_List_Object[] = {

OM_OID_DESC(OM_CLASS, DS_C_ENTRY_MOD_LIST),

{DS_CHANGES, OM_S_OBJECT, {0, Entry_Modification_Object_1}},

{DS_CHANGES, OM_S_OBJECT, {0, Entry_Modification_Object_2}},

OM_NULL_DESCRIPTOR

};

A full description of this object can be found in XDS/CDS Object Recipes . There could be any number of additional attribute changes in the list; this would mean additional DS_C_ENTRY_MOD objects declared, and an additional DS_CHANGES descriptor declared and initialized in the DS_C_ENTRY_MOD_LIST object.

With the DS_C_ENTRY_MOD_LIST class object having been declared as shown previously, the following code fragment illustrates how to call XDS to write a new attribute value (actually two new values since two attributes are contained in the list object). Note that any of the attributes may be new, although the entry itself must already exist.

dsStatus = ds_modify_entry(session, /* Directory session */

/* from "ds_bind()" */

DS_DEFAULT_CONTEXT, /* Usual directory context */

Full_Entry_Name_Object, /* Entry name object */

Entry_Modification_List_Object, /* Entry */

/* Modification object */

&dummy); /* Unsupported argument */

If the entire entry is new, you must call ds_add_entry( ). This function requires an input object of class DS_C_ATTRIBUTE_LIST, whose contents specify the attributes (and values) to be attached to the new entry. Following is the static declaration for an attribute list that contains three attributes:

static OM_descriptor Class_Attribute_Object[] = {

OM_OID_DESC(OM_CLASS, DS_C_ATTRIBUTE),

OM_OID_DESC(DS_ATTRIBUTE_TYPE, DSX_A_CDS_Class),

{DS_ATTRIBUTE_VALUES, OM_S_PRINTABLE_STRING, OM_STRING("Printer")},

OM_NULL_DESCRIPTOR

};

static OM_descriptor ClassVersion_Attribute_Object[] = {

OM_OID_DESC(OM_CLASS, DS_C_ATTRIBUTE),

OM_OID_DESC(DS_ATTRIBUTE_TYPE, DSX_A_CDS_ClassVersion),

{DS_ATTRIBUTE_VALUES, OM_S_PRINTABLE_STRING, OM_STRING("1.0")},

OM_NULL_DESCRIPTOR

};

static OM_descriptor My_Own_Attribute_Object[] = {

OM_OID_DESC(OM_CLASS, DS_C_ATTRIBUTE),

OM_OID_DESC(DS_ATTRIBUTE_TYPE, DSX_A_CDS_My_OwnAttribute),

{DS_ATTRIBUTE_VALUES, OM_S_PRINTABLE_STRING, OM_STRING("zorro")},

OM_NULL_DESCRIPTOR

};

static OM_descriptor Attribute_List_Object[] = {

OM_OID_DESC(OM_CLASS, DS_C_ATTRIBUTE_LIST),

{DS_ATTRIBUTES, OM_S_OBJECT, {0, Class_Attribute_Object}},

{DS_ATTRIBUTES, OM_S_OBJECT, {0, ClassVersion_Attribute_Object}},

{DS_ATTRIBUTES, OM_S_OBJECT, {0, My_Own_Attribute_Object}},

OM_NULL_DESCRIPTOR

};

The ds_add_entry( ) function also requires a DS_C_DS_DN class object containing the new entry's full name, for example:

/.../osf.org.dce/subsys/doc/my_book

where every member of the name exists except for the last one, my_book. Assuming that Full_Entry_Name_Object is a DS_C_DS_DN object, the following code shows what the call would look like:

dsStatus = ds_add_entry(session, /* Directory session */

/* from "ds_bind()" */

DS_DEFAULT_CONTEXT, /* Usual directory context */

Full_Entry_Name_Object, /* Name of new entry */

Attribute_List_Object, /* Attributes to be */

/* attached to new entry, with values */

&dummy); /* Unsupported argument */

##