FTAM/9000 Programmer's Guide

374 Chapter 10
Example Programs
Setting Ae_dir_dn and P_address Utility Example
*dirname = (struct Dir_dn *)malloc(sizeof(struct Dir_dn));
(*dirname)->rdn = (struct Dir_rdn *)malloc(index*sizeof(struct Dir_rdn));
/*
** Set the Ae_dir_name.
*/
(*dirname)->n = index;
/*
** Parse the string and set up the Dir_dn structure.
**
** NOTE: index is set to “-1” since the string MUST start with
** a delimiter “/”.
*/
j = 0;
index = -1;
while ( !null_flag ) {
/*
** Have we reached the end of the string?
*/
if (name[j] == NULL)
null_flag = TRUE;
/*
** “/” is the signal for another Dir_rdn structure.
*/
if ((name[j] != ‘/’) & & ( !null_flag )) {
/*
** Is the attribute or the value of the attribute being parsed?
*/
if (name[j] == ‘=’) {
val_flag = TRUE;
} else if (val_flag) {
value[i] = name[j];
++i;
} else {
attr[k] = name[j];
++k;
}
++j;
}
value[i] = attr[k] = ‘\0’;
/*
** Has the end of the string or the delimiter for
** another rdn structure been reached?
*/
if ((null_flag) || (name[j] == ‘/’)) {
if ((i != 0) & & (k != 0)) {
(*dirname)->rdn[index].n = 1;
(*dirname)->rdn[index].avas =
(struct Dir_ava *)malloc(sizeof(struct Dir_ava));
(*dirname)->rdn[index].avas->attr_id.length = 1;
(*dirname)->rdn[index].avas->attr_id.element =
(Sint32 *)malloc(sizeof(Sint32));
/*
** Set up the attr_value.
*/
(*dirname)->rdn[index].avas->attr_value.pointer =
(Octet *)malloc(i*sizeof(Octet));
memcpy((char *)(*dirname)->rdn[index].avas->attr_value.pointer,
value,i);
(*dirname)->rdn[index].avas->attr_value.length = i;