PreviousNext

Adding New Hostdata

In addition to modifying existing hostdata, you can add your own data by using the hostdata API. For example, suppose you want to add a printer to a host and make the configuration file part of that host's dced data. The following example shows how to do this:

dced_binding_handle_t dced_bh;

error_status_t status;

dced_entry_t entry;

dced_attr_list_t data;

int num_attr, str_size;

sec_attr_enc_str_array_t *attr_array;

.

.

.

dced_binding_create(dced_c_service_hostdata,

dced_c_binding_syntax_default,

&dced_bh,

&status);

/*Create Entry Data */

uuid_create(&(entry.id), &status);

entry.name = (dced_string_t)("NEWERprinter");

entry.description = (dced_string_t)("Configuration for a new printer.");

entry.storage_tag = (dced_string_t)("/etc/NEWprinter");


/* Create the Attributes, one for this example */

data.count = 1;

num_attr = 1;

data.list = (sec_attr_t *)malloc( data.count * sizeof(sec_attr_t) );

(data.list)->attr_id = dced_g_uuid_fileattr;

(data.list)->attr_value.attr_encoding = sec_attr_enc_printstring_array;

str_size = sizeof(sec_attr_enc_str_array_t) +

num_attr * sizeof(sec_attr_enc_printstring_p_t);

attr_array = (sec_attr_enc_str_array_t *)malloc(str_size);

(data.list)->attr_value.tagged_union.string_array = attr_array;

attr_array->num_strings = num_attr;

attr_array->strings[0] = (dced_string_t)("New printer configuration data");


dced_hostdata_create(dced_bh, &entry, &data, &status);

dced_binding_free( dced_bh, &status);

The description of this example is as follows:

dced_binding_create( )
This routine creates a dced binding to a dced service. The binding handle created is used in all subsequent calls to appropriate dced API routines. By using the dced_c_server_hostdata value for the first parameter, we are using the hostdata service on the local host.

Create Entry Data
Prior to creating a hostdata entry, we have to set its values. These include the name and UUID that dced will use to identify the new data, a description of the entry, and a file name with the full path name of where the actual data will reside.

Create the Attributes
The data stored is of type sec_attr_t. This data type is a very flexible one that can store many different kinds of data. In this example, we set the file to have one attribute, printable string information. This example has only one string of data. You can also establish binary data for the file.

dced_hostdata_create( )
This routine takes the binding handle, entry, and new data as input; it creates the file with the new data and returns a status code.

If the printer configuration file already exists on the host, but you want to now make it accessible to dced, use the dce_entry_add( ) routine instead of dced_hostdata_create( ).

dced_binding_free( )
Each call to the dced_binding_create( ) routine requires a corresponding call to dced_binding_free( ) to release the binding resources allocated.

Use the dced_hostdata_delete( ) routine to delete application-specific hostdata items and their entries. For example, the printer installed in the example is easily removed with this routine. If you are only taking the printer out of service for a short time, use the dced_entry_remove( ) routine to remove the dced entry but not the data file itself. When the printer is later ready again, use the dced_entry_add( ) routine to reinstall it.

Do not delete the well-known hostdata items or remove their entries.