InfoDirectory使用手引書
|
目次
索引
|
5.5.3.6 属性値のUTF-8への変換
属性値の集合をUTF-8に変換する場合のサンプルプログラムを以下に示します。
[conv_values.c]
/*
* Copyright (c) 2001. Fujitsu Limited. All rights reserved.
*
* Convert attribute values to UTF8.
*
*/
#include <sys/types.h>
#include <stdlib.h>
#include "examples.h"
/*-------------------------------------------------------------*/
int do_conv_values(
char *in_vals[],
struct berval **out_vals[],
int in,
int out
)
{
int i;
int rtn;
int count;
struct berval **vals;
struct berval *berval;
/*----------------------------------------------------------*/
count = ldap_count_values( in_vals );
vals = (struct berval **)calloc( count + 1, sizeof( struct berval* ) );
if ( vals == NULL ) {
*out_vals = NULL;
return( -1 );
}
for ( i = 0; i < count; i++ ) {
berval = (struct berval *)calloc( 1, sizeof( struct berval ) );
rtn = ldap_conv_utf( in_vals[i], &berval->bv_val, in, out );
if ( rtn == -1 ) {
vals[i] = NULL;
ldap_value_free_len( vals );
*out_vals = NULL;
return(-1);
}
berval->bv_len = (unsigned long)rtn;
vals[i] = berval;
}
*out_vals = vals;
return(0);
}
All Rights Reserved, Copyright(C) 富士通株式会社 2005