Interstage Application Server Smart Repository運用ガイド
目次 索引 前ページ次ページ

第6章 アプリケーションの作成(C API)> 6.3 サンプルプログラム> 6.3.3 サンプルプログラムの紹介

6.3.3.6 属性値のUTF-8への変換

 属性値の集合をUTF-8に変換する場合のサンプルプログラムを以下に示します。

[conv_values.c]

/*
 * All Rights Reserved, Copyright (C) FUJITSU LIMITED 2006
 *
 * 属性値を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( (size_t)(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( (size_t)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) 富士通株式会社 2007