The example below shows how to list the attributes of an object.
#include <stdio.h>
#include <xfn/xfn.h>
/*
This routine prints all the attributes associated
with the named object to the standard output.
Examples of using the function:
fns_attr_list("user/jsmith");
fns_attr_list("thisorgunit/service/printer/color");
*/
void fns_attr_list(const char *name)
{
FN_composite_name_t *name_comp;
const FN_identifier_t *identifier;
FN_attribute_t *attribute;
const FN_attrvalue_t *values;
char *id, *val;
FN_multigetlist_t *attrset;
void *ip;
FN_status_t *status;
FN_ctx_t *initial_context;
name_comp = fn_composite_name_from_str((unsigned char *) name);
status = fn_status_create();
/* Obtain the initial context */
initial_context = fn_ctx_handle_from_initial(0, status);
if (!fn_status_is_success(status)) {
fprintf(stderr, "Unable to obtain intial context\n");
return;
}
/* Obtain all the attributes */
attrset = fn_attr_multi_get(initial_context, name_comp, 0, 0,
status);
if (!fn_status_is_success(status)) {
fprintf(stderr, "Unable to obtain attributes\n");
return;
}
/* List all attributes */
while (attribute = fn_multigetlist_next(attrset, status)) {
identifier = fn_attribute_identifier(attribute);
switch(identifier->format) {
case FN_ID_STRING:
id = (char *) malloc(identifier->length + 1);
memcpy(id, identifier->contents, identifier->length);
id[identifier->length] = '\0';
printf("Attribute Identifier: %s", id);
free(id);
break;
default:
printf("Attribute of non-string format\n\n");
continue;
}
for (values = fn_attribute_first(attribute, &ip);
values != NULL;
values = fn_attribute_next(attribute, &ip)) {
val = (char *) malloc(values->length + 1);
memcpy(val, values->contents, values->length);
val[values->length] = '\0';
printf("Value: %s", val);
free(val);
}
fn_attribute_destroy(attribute);
printf("\n");
}
fn_multigetlist_destroy(attrset);
fn_ctx_destroy(initial_context);
fn_status_destroy(status);
fn_composite_name_destroy(name_comp);
}
|