⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 charset.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 *  Copyright (c) 1995 Regents of the University of Michigan.
 *  All rights reserved.
 *
 *  charset.c
 */

#if defined( DOS )
/*
 * This MUST precede "#ifdef STR_TRANSLATION"
 * because STR_TRANSLATION and friends are defined in msdos.h.
 */
#include "msdos.h"
#endif /* DOS */

#ifdef STR_TRANSLATION

#ifndef lint 
static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University "
			  "of Michigan.\nAll rights reserved.\n";
#endif

#include <stdio.h>
#include <string.h>

#ifdef MACOS
#include <stdlib.h>
#include "macos.h"
#endif /* MACOS */

#if !defined(MACOS) && !defined(DOS) && !defined( _WIN32 ) && !defined(VMS)
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#endif
#include "lber.h"
#include "ldap.h"
#include "ldap-int.h"


void
ldap_set_string_translators( LDAP *ld, BERTranslateProc encode_proc,
	BERTranslateProc decode_proc )
{
	ld->ld_lber_encode_translate_proc = encode_proc;
	ld->ld_lber_decode_translate_proc = decode_proc;
}


void
ldap_enable_translation( LDAP *ld, LDAPMessage *entry, int enable )
{
	char	*optionsp;

	optionsp = ( entry == NULLMSG ) ? &ld->ld_lberoptions :
	    &entry->lm_ber->ber_options;
		
	if ( enable ) {
		*optionsp |= LBER_TRANSLATE_STRINGS;
	} else {
		*optionsp &= ~LBER_TRANSLATE_STRINGS;
	}
}


int
ldap_translate_from_t61( LDAP *ld, char **bufp, unsigned long *lenp,
    int free_input )
{
	if ( ld->ld_lber_decode_translate_proc == NULL ) {
		return( LDAP_SUCCESS );
	}
	    
	return( (*ld->ld_lber_decode_translate_proc)( bufp, lenp, free_input ));
}


int
ldap_translate_to_t61( LDAP *ld, char **bufp, unsigned long *lenp,
    int free_input )
{
	if ( ld->ld_lber_encode_translate_proc == NULL ) {
		return( LDAP_SUCCESS );
	}
	    
	return( (*ld->ld_lber_encode_translate_proc)( bufp, lenp, free_input ));
}


/*
 ** Character translation routine notes:
 *
 * On entry:  bufp points to a "string" to be converted (not necessarily
 *  zero-terminated) and buflenp points to the length of the buffer.
 *
 * On exit:  bufp should point to a malloc'd result.  If free_input is
 *  non-zero then the original bufp will be freed.  *buflenp should be
 *  set to the new length.  Zero bytes in the input buffer must be left
 *  as zero bytes.
 *
 * Return values: any ldap error code (LDAP_SUCCESS if all goes well).
 */


#ifdef LDAP_CHARSET_8859

#if LDAP_CHARSET_8859 == 88591
#define ISO_8859 1
#elif LDAP_CHARSET_8859 == 88592
#define ISO_8859 2
#elif LDAP_CHARSET_8859 == 88593
#define ISO_8859 3
#elif LDAP_CHARSET_8859 == 88594
#define ISO_8859 4
#elif LDAP_CHARSET_8859 == 88595
#define ISO_8859 5
#elif LDAP_CHARSET_8859 == 88596
#define ISO_8859 6
#elif LDAP_CHARSET_8859 == 88597
#define ISO_8859 7
#elif LDAP_CHARSET_8859 == 88598
#define ISO_8859 8
#elif LDAP_CHARSET_8859 == 88599
#define ISO_8859 9
#elif LDAP_CHARSET_8859 == 885910
#define ISO_8859 10
#else
#define ISO_8859 0
#endif

/*
 * the following ISO_8859 to/afrom T.61 character set translation code is
 * based on the code found in Enrique Silvestre Mora's iso-t61.c, found
 * as part of this package:
 *   ftp://pereiii.uji.es/pub/uji-ftp/unix/ldap/iso-t61.translation.tar.Z
 * Enrique is now (10/95) at this address: enrique.silvestre@uv.es
 *
 * changes made by mcs@umich.edu 12 October 1995:
 *   Change calling conventions of iso8859_t61() and t61_iso8859() to
 *	match libldap conventions; rename to ldap_8859_to_t61() and
 *	ldap_t61_to_8859().
 *   Change conversion routines to deal with non-zero terminated strings.
 *   ANSI-ize functions and include prototypes.
 */

/* iso-t61.c - ISO-T61 translation routines (version: 0.2.1, July-1994) */
/*
 * Copyright (c) 1994 Enrique Silvestre Mora, Universitat Jaume I, Spain.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the Universitat Jaume I. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Character set used: ISO 8859-1, ISO 8859-2, ISO 8859-3, ... */
/* #define  ISO_8859      1 */

#ifndef ISO_8859
#  define ISO_8859     0
#endif

typedef unsigned char  Byte;
typedef struct { Byte  a, b; } Couple;

#ifdef NEEDPROTOS
static Byte *c_to_hh( Byte *o, Byte c );
static Byte *c_to_cc( Byte *o, Couple *cc, Byte c );
static int hh_to_c( Byte *h );
static Byte *cc_to_t61( Byte *o, Byte *s );
#else /* NEEDPROTOS */
static Byte *c_to_hh();
static Byte *c_to_cc();
static int hh_to_c();
static Byte *cc_to_t61();
#endif /* NEEDPROTOS */

/*
   Character choosed as base in diacritics alone: NO-BREAK SPACE.
   (The standard say it must be a blank space, 0x20.)
*/
#define  ALONE  0xA0

static Couple diacritic[16] = {
#if (ISO_8859 == 1) || (ISO_8859 == 9)
	{0,0},       {'`',0},     {0xb4,0},    {'^',0},
	{'~',0},     {0xaf,0},    {'(',ALONE}, {'.',ALONE},
	{0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
	{0,0},       {'"',ALONE}, {';',ALONE}, {'<',ALONE},
#elif (ISO_8859 == 2)
	{0,0},       {'`',0},     {0xb4,0},    {'^',0},
	{'~',0},     {'-',ALONE}, {0xa2,0},    {0xff,0},
	{0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
	{0,0},       {0xbd,0},    {0xb2,0},    {0xb7,0}
#elif (ISO_8859 == 3)
	{0,0},       {'`',0},     {0xb4,0},    {'^',0},
	{'~',0},     {'-',ALONE}, {0xa2,0},    {0xff,0},
	{0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
	{0,0},       {'"',ALONE}, {';',ALONE}, {'<',ALONE}
#elif (ISO_8859 == 4)
	{0,0},       {'`',0},     {0xb4,0},    {'^',0},
	{'~',0},     {0xaf,0},    {'(',ALONE}, {0xff,0},
	{0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
	{0,0},       {'"',ALONE}, {0xb2,0},    {0xb7,0}
#else
	{0,0},       {'`',0},     {'\'',ALONE}, {'^',0},
	{'~',0},     {'-',ALONE}, {'(',ALONE},  {'.',ALONE},
	{':',ALONE}, {0,0},       {'0',ALONE},  {',',ALONE},
	{0,0},       {'"',ALONE}, {';',ALONE},  {'<',ALONE}
#endif
};

/*
   --- T.61 (T.51) letters with diacritics: conversion to ISO 8859-n -----
       A,   C,   D,   E,   G,   H,   I,   J,   K,
       L,   N,   O,   R,   S,   T,   U,   W,   Y,   Z.
   -----------------------------------------------------------------------
*/
static int letter_w_diacritic[16][38] = {
#if (ISO_8859 == 1)
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0xc0,0,   0,   0xc8,0,   0,   0xcc,0,   0,
	0,   0,   0xd2,0,   0,   0,   0xd9,0,   0,   0,
	0xe0,0,   0,   0xe8,0,   0,   0xec,0,   0,
	0,   0,   0xf2,0,   0,   0,   0xf9,0,   0,   0,
	0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
	-1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   0xdd,-1,
	0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
	-1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   0xfd,-1,
	0xc2,-1,  0,   0xca,-1,  -1,  0xce,-1,  0,
	0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
	0xe2,-1,  0,   0xea,-1,  -1,  0xee,-1,  0,
	0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
	0xc3,0,   0,   0,   0,   0,   -1,  0,   0,
	0,   0xd1,0xd5,0,   0,   0,   -1,  0,   0,   0,
	0xe3,0,   0,   0,   0,   0,   -1,  0,   0,
	0,   0xf1,0xf5,0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   -1,  0,   0,   -1,  0,   0,
	0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   -1,  0,   0,   -1,  0,   0,
	0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   0,   -1,  0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   0,   -1,  0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	0,   -1,  0,   -1,  -1,  0,   -1,  0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
	0,   -1,  0,   -1,  -1,  0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
	0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
	0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
	0xe4,0,   0,   0xeb,0,   0,   0xef,0,   0,
	0,   0,   0xf6,0,   0,   0,   0xfc,0,   0xff,0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0xc5,0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	0xe5,0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
	-1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
	0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
	-1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   -1,  0,   0,   -1,  0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   -1,  0,   0,   -1,  0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
	-1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
	0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
	-1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
#elif (ISO_8859 == 2)
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-1,  0,   0,   -1,  0,   0,   -1,  0,   0,
	0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   -1,  0,   0,   -1,  0,   0,
	0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
	0xc1,0xc6,0,   0xc9,0,   0,   0xcd,0,   0,
	0xc5,0xd1,0xd3,0xc0,0xa6,0,   0xda,0,   0xdd,0xac,
	0xe1,0xe6,0,   0xe9,0,   0,   0xed,0,   0,
	0xe5,0xf1,0xf3,0xe0,0xb6,0,   0xfa,0,   0xfd,0xbc,
	0xc2,-1,  0,   -1,  -1,  -1,  0xce,-1,  0,
	0,   0,   0xd4,0,   -1,  0,   -1,  -1,  -1,  0,
	0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
	0,   0,   0xf4,0,   -1,  0,   -1,  -1,  -1,  0,
	-1,  0,   0,   0,   0,   0,   -1,  0,   0,
	0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   0,   0,   0,   -1,  0,   0,
	0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   -1,  0,   0,   -1,  0,   0,
	0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
	-1,  0,   0,   -1,  0,   0,   -1,  0,   0,
	0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
	0xc3,0,   0,   0,   -1,  0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	0xe3,0,   0,   0,   -1,  0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	0,   -1,  0,   -1,  -1,  0,   -1,  0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0xaf,
	0,   -1,  0,   -1,  -1,  0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0xbf,
	0xc4,0,   0,   0xcb,0,   0,   -1,  0,   0,
	0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
	0xe4,0,   0,   0xeb,0,   0,   -1,  0,   0,
	0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-1,  0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0xd9,0,   0,   0,
	-1,  0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0xf9,0,   0,   0,
	0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
	-1,  -1,  0,   -1,  0xaa,0xde,0,   0,   0,   0,
	0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
	-1,  -1,  0,   -1,  0xba,0xfe,0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0xd5,0,   0,   0,   0xdb,0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0xf5,0,   0,   0,   0xfb,0,   0,   0,
	0xa1,0,   0,   0xca,0,   0,   -1,  0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	0xb1,0,   0,   0xea,0,   0,   -1,  0,   0,
	0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
	0,   0xc8,0xcf,0xcc,0,   0,   0,   0,   0,
	0xa5,0xd2,0,   0xd8,0xa9,0xab,0,   0,   0,   0xae,
	0,   0xe8,0xef,0xec,0,   0,   0,   0,   0,
	0xb5,0xf2,0,   0xf8,0xb9,0xbb,0,   0,   0,   0xbe
#elif (ISO_8859 == 3)
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,
	0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	0xc0,0,   0,   0xc8,0,   0,   0xcc,0,   0,
	0,   0,   0xd2,0,   0,   0,   0xd9,0,   0,   0,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -