Postfix3.3.1
midna_adomain.c
[詳解]
1 /*++
2 /* NAME
3 /* midna_adomain 3
4 /* SUMMARY
5 /* address domain part conversion
6 /* SYNOPSIS
7 /* #include <midna_adomain.h>
8 /*
9 /* char *midna_adomain_to_ascii(
10 /* VSTRING *dest,
11 /* const char *name)
12 /*
13 /* char *midna_adomain_to_utf8(
14 /* VSTRING *dest,
15 /* const char *name)
16 /* DESCRIPTION
17 /* The functions in this module transform the domain portion
18 /* of an email address between ASCII and UTF-8 form. Both
19 /* functions tolerate a missing domain, and both functions
20 /* return a copy of the input when the domain portion requires
21 /* no conversion.
22 /*
23 /* midna_adomain_to_ascii() converts an UTF-8 or ASCII domain
24 /* portion to ASCII. The result is a null pointer when
25 /* conversion fails. This function verifies that the resulting
26 /* domain passes valid_hostname().
27 /*
28 /* midna_adomain_to_utf8() converts an UTF-8 or ASCII domain
29 /* name to UTF-8. The result is a null pointer when conversion
30 /* fails. This function verifies that the resulting domain,
31 /* after conversion to ASCII, passes valid_hostname().
32 /* SEE ALSO
33 /* midna_domain(3), Postfix ASCII/UTF-8 domain name conversion
34 /* DIAGNOSTICS
35 /* Fatal errors: memory allocation problem.
36 /* Warnings: conversion error or result validation error.
37 /* LICENSE
38 /* .ad
39 /* .fi
40 /* The Secure Mailer license must be distributed with this software.
41 /* AUTHOR(S)
42 /* Wietse Venema
43 /* IBM T.J. Watson Research
44 /* P.O. Box 704
45 /* Yorktown Heights, NY 10598, USA
46 /*--*/
47 
48  /*
49  * System library.
50  */
51 #include <sys_defs.h>
52 #include <string.h>
53 
54 #ifndef NO_EAI
55 #include <unicode/uidna.h>
56 
57  /*
58  * Utility library.
59  */
60 #include <vstring.h>
61 #include <stringops.h>
62 #include <midna_domain.h>
63 
64  /*
65  * Global library.
66  */
67 #include <midna_adomain.h>
68 
69 #define STR(x) vstring_str(x)
70 
71 /* midna_adomain_to_utf8 - convert address domain portion to UTF8 */
72 
73 char *midna_adomain_to_utf8(VSTRING *dest, const char *src)
74 {
75  const char *cp;
76  const char *domain_utf8;
77 
78  if ((cp = strrchr(src, '@')) == 0) {
79  vstring_strcpy(dest, src);
80  } else {
81  vstring_sprintf(dest, "%*s@", (int) (cp - src), src);
82  if (*(cp += 1)) {
83  if (allascii(cp) && strstr(cp, "--") == 0) {
84  vstring_strcat(dest, cp);
85  } else if ((domain_utf8 = midna_domain_to_utf8(cp)) == 0) {
86  return (0);
87  } else {
88  vstring_strcat(dest, domain_utf8);
89  }
90  }
91  }
92  return (STR(dest));
93 }
94 
95 /* midna_adomain_to_ascii - convert address domain portion to ASCII */
96 
97 char *midna_adomain_to_ascii(VSTRING *dest, const char *src)
98 {
99  const char *cp;
100  const char *domain_ascii;
101 
102  if ((cp = strrchr(src, '@')) == 0) {
103  vstring_strcpy(dest, src);
104  } else {
105  vstring_sprintf(dest, "%*s@", (int) (cp - src), src);
106  if (*(cp += 1)) {
107  if (allascii(cp)) {
108  vstring_strcat(dest, cp);
109  } else if ((domain_ascii = midna_domain_to_ascii(cp + 1)) == 0) {
110  return (0);
111  } else {
112  vstring_strcat(dest, domain_ascii);
113  }
114  }
115  }
116  return (STR(dest));
117 }
118 
119 #endif /* NO_IDNA */
VSTRING * vstring_strcpy(VSTRING *vp, const char *src)
Definition: vstring.c:431
const char * midna_domain_to_utf8(const char *name)
Definition: midna_domain.c:275
char * midna_adomain_to_ascii(VSTRING *dest, const char *src)
Definition: midna_adomain.c:97
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
Definition: vstring.c:602
#define allascii(s)
Definition: stringops.h:66
const char * midna_domain_to_ascii(const char *name)
Definition: midna_domain.c:261
char * midna_adomain_to_utf8(VSTRING *dest, const char *src)
Definition: midna_adomain.c:73
#define STR(x)
Definition: midna_adomain.c:69
VSTRING * vstring_strcat(VSTRING *vp, const char *src)
Definition: vstring.c:459