OSF DCE Application Development Guide--Core Components
The DCE Backing Store
return;
}
if (e_array->count == 0) { /* No items, nothing to do */
dce_db_unlock(db_h, st);
return;
}
/* Allocate the space for the output. */
e_array->entry = rpc_sm_allocate(
e_array->count*sizeof(e_array->entry[0]),st);
if (*st != rpc_s_ok) {
dce_fprintf(stderr, *st); /* or some other treatment */
return
}
dce_db_iter_start(db_h, st);
i=0;
while (TRUE) {
/* Get the next key. */
dce_db_iter_next(db_h, &dbkey, st);
/* break when we’ve scanned the entire backing store */
if (*st == db_s_no_more) break;
/* Get the data associated with the next key. */
dce_db_fetch_by_uuid(db_h, dbkey, (void *)&pd, st);
if (*st != error_status_ok) {
dce_fprintf(stderr, *st);
/* Don’t forget to stop iterating and unlock after
* an error. */
dce_db_iter_done(db_h, &st2);
dce_db_unlock(db_h, &st2);
return;
}
/* Stick the item into the array to be returned
* when done. */
e_array->entry[i].name = strdup(pd.ph.name);
e_array->entry[i].email = strdup(pd.ph.email);
e_array->entry[i].phone = strdup(pd.ph.phone);
e_array->entry[i].office = strdup(pd.ph.office);
i++;
/* The use of strdup() above is illustrative, but it
* is not correct within a server, because the
* allocated memory is never freed. Correct code
* would involve the use of rpc_sm_allocate().
*/
}
/* The iteration is finished. */
dce_db_iter_done(db_h, st);
dce_db_unlock(db_h, st);
}
124245 Tandem Computers Incorporated 5− 11