Interstage Application Server Smart Repository運用ガイド
|
目次
索引
|
5.3.3.6 属性値のUTF-8への変換
属性値の集合をUTF-8に変換する場合のサンプルプログラムを以下に示します。
[conv_values.c]
/*
* Copyright (c) 2004. Fujitsu Limited. All rights reserved.
*
* 属性値のUTF-8への変換を行う。
*
*/
#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 );
}
/* 日本語を含む文字列をUTF-8に変換 */
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 == 0 ) {
vals[i] = NULL;
ldap_value_free_len( vals );
*out_vals = NULL;
free(berval);
return(-1);
}
berval->bv_len = (unsigned long)rtn;
vals[i] = berval;
}
*out_vals = vals;
return(0);
}
All Rights Reserved, Copyright(C) 富士通株式会社 2005