64 static int traverse_string(
const unsigned char *
p,
int len,
int inform,
65 int (*rfunc)(
unsigned long value,
void *in),
void *
arg);
66 static int in_utf8(
unsigned long value,
void *
arg);
67 static int out_utf8(
unsigned long value,
void *
arg);
68 static int type_str(
unsigned long value,
void *
arg);
69 static int cpy_asc(
unsigned long value,
void *
arg);
70 static int cpy_bmp(
unsigned long value,
void *
arg);
71 static int cpy_univ(
unsigned long value,
void *
arg);
72 static int cpy_utf8(
unsigned long value,
void *
arg);
73 static int is_printable(
unsigned long value);
84 int inform,
unsigned long mask)
90 int inform,
unsigned long mask,
91 long minsize,
long maxsize)
96 int outform, outlen = 0;
101 int (*cpyfunc)(
unsigned long,
void *) = NULL;
102 if(len == -1) len = strlen((
const char *)in);
129 ret = traverse_string(in, len,
MBSTRING_UTF8, in_utf8, &nchar);
146 if((minsize > 0) && (nchar < minsize)) {
153 if((maxsize > 0) && (nchar > maxsize)) {
161 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
182 if(!out)
return str_type;
191 dest->
type = str_type;
203 if(inform == outform) {
230 traverse_string(in, len, inform, out_utf8, &outlen);
242 traverse_string(in, len, inform, cpyfunc, &p);
250 static int traverse_string(
const unsigned char *p,
int len,
int inform,
251 int (*rfunc)(
unsigned long value,
void *in),
void *
arg)
264 value = ((
unsigned long)*p++) << 24;
265 value |= ((
unsigned long)*p++) << 16;
271 if(ret < 0)
return -1;
276 ret = rfunc(value, arg);
277 if(ret <= 0)
return ret;
287 static int in_utf8(
unsigned long value,
void *arg)
297 static int out_utf8(
unsigned long value,
void *arg)
309 static int type_str(
unsigned long value,
void *arg)
312 types = *((
unsigned long *)arg);
314 types &= ~B_ASN1_PRINTABLESTRING;
316 types &= ~B_ASN1_IA5STRING;
318 types &= ~B_ASN1_T61STRING;
320 types &= ~B_ASN1_BMPSTRING;
321 if(!types)
return -1;
322 *((
unsigned long *)arg) = types;
328 static int cpy_asc(
unsigned long value,
void *arg)
330 unsigned char **
p, *
q;
333 *q = (
unsigned char) value;
340 static int cpy_bmp(
unsigned long value,
void *arg)
342 unsigned char **
p, *
q;
345 *q++ = (
unsigned char) ((value >> 8) & 0xff);
346 *q = (
unsigned char) (value & 0xff);
353 static int cpy_univ(
unsigned long value,
void *arg)
355 unsigned char **
p, *
q;
358 *q++ = (
unsigned char) ((value >> 24) & 0xff);
359 *q++ = (
unsigned char) ((value >> 16) & 0xff);
360 *q++ = (
unsigned char) ((value >> 8) & 0xff);
361 *q = (
unsigned char) (value & 0xff);
368 static int cpy_utf8(
unsigned long value,
void *arg)
380 static int is_printable(
unsigned long value)
383 if(value > 0x7f)
return 0;
388 #ifndef CHARSET_EBCDIC
389 if((ch >=
'a') && (ch <=
'z'))
return 1;
390 if((ch >=
'A') && (ch <=
'Z'))
return 1;
391 if((ch >=
'0') && (ch <=
'9'))
return 1;
392 if ((ch ==
' ') || strchr(
"'()+,-./:=?", ch))
return 1;