Interstage Application Server Smart Repository運用ガイド
|
目次
索引

|
6.3.3.7 日本語を含むエントリ情報の出力
受信したエントリの情報を出力する場合のサンプルプログラムを以下に示します。このサンプルプログラムでは、属性値に日本語が含まれる場合の処理をしています。
[jp_prt_entry.c]
/*
* All Rights Reserved, Copyright (C) FUJITSU LIMITED 2006
*
* エントリ情報の出力(日本語データ含む)
*
* [For Japanese]
*
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "examples.h"
#include "def.h"
#include "jp_def.h"
/*-------------------------------------------------------------*/
/*
* エントリ出力処理
*/
int print_entry_jp(
LDAP *ld,
LDAPMessage *result,
int freeit )
{
LDAPMessage *entry;
int cnt, num_entry;
char *dn, *utf_dn;
BerElement *ber;
char *attr;
struct berval **vals;
char *value, *utf_value;
/*----------------------------------------------------------*/
/* エントリ数の初期化 */
num_entry = 0;
/* エントリ情報の取得 */
for ( entry = ldap_first_entry( ld, result );
entry != NULL;
entry = ldap_next_entry( ld, entry ) ) {
utf_dn = (char *)ldap_get_dn( ld, entry );
/* 日本語を含む文字列をUTF-8に変換 */
ldap_conv_utf( utf_dn, &dn,
LDAP_CHARS_OPT_UTF8, BASE_CONV_OPT );
printf( "dn: %s\n", dn );
ldap_memfree( utf_dn );
ldap_memfree( (char *)dn );
for ( attr = ldap_first_attribute( ld, entry, &ber );
attr != NULL;
attr = ldap_next_attribute( ld, entry, ber ) ) {
vals = ldap_get_values_len( ld, entry, attr );
for ( cnt = 0; vals[cnt] != NULL; cnt++ ) {
utf_value = calloc( (size_t)1, (vals[cnt]->bv_len + 1) );
memcpy( utf_value, vals[cnt]->bv_val, vals[cnt]->bv_len );
ldap_conv_utf( utf_value, &value,
LDAP_CHARS_OPT_UTF8, BASE_CONV_OPT );
printf( "%s: %s\n", attr, value );
free( utf_value );
ldap_memfree( value );
}
ldap_memfree( attr );
ldap_value_free_len( vals );
}
ber_free( ber, 0 );
printf( "\n" );
num_entry++; /* エントリ数加算 */
}
if ( freeit != 0 ) {
ldap_msgfree( result );
}
return( num_entry );
}
All Rights Reserved, Copyright(C) 富士通株式会社 2007