1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 # include <stringprep.h>
10 #include "alloc-util.h"
11 #include "dlfcn-util.h"
14 #if HAVE_LIBIDN || HAVE_LIBIDN2
15 static void* idn_dl
= NULL
;
19 int (*sym_idn2_lookup_u8
)(const uint8_t* src
, uint8_t** lookupname
, int flags
) = NULL
;
20 const char *(*sym_idn2_strerror
)(int rc
) = NULL
;
21 int (*sym_idn2_to_unicode_8z8z
)(const char * input
, char ** output
, int flags
) = NULL
;
23 int dlopen_idn(void) {
24 _cleanup_(dlclosep
) void *dl
= NULL
;
28 return 0; /* Already loaded */
30 dl
= dlopen("libidn2.so.0", RTLD_LAZY
);
32 return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
33 "libidn2 support is not installed: %s", dlerror());
35 r
= dlsym_many_and_warn(
38 &sym_idn2_lookup_u8
, "idn2_lookup_u8",
39 &sym_idn2_strerror
, "idn2_strerror",
40 &sym_idn2_to_unicode_8z8z
, "idn2_to_unicode_8z8z",
45 /* Note that we never release the reference here, because there's no real reason to, after all this
46 * was traditionally a regular shared library dependency which lives forever too. */
47 idn_dl
= TAKE_PTR(dl
);
54 int (*sym_idna_to_ascii_4i
)(const uint32_t * in
, size_t inlen
, char *out
, int flags
);
55 int (*sym_idna_to_unicode_44i
)(const uint32_t * in
, size_t inlen
,uint32_t * out
, size_t * outlen
, int flags
);
56 char* (*sym_stringprep_ucs4_to_utf8
)(const uint32_t * str
, ssize_t len
, size_t * items_read
, size_t * items_written
);
57 uint32_t* (*sym_stringprep_utf8_to_ucs4
)(const char *str
, ssize_t len
, size_t *items_written
);
59 int dlopen_idn(void) {
60 _cleanup_(dlclosep
) void *dl
= NULL
;
64 return 0; /* Already loaded */
66 dl
= dlopen("libidn.so.12", RTLD_LAZY
);
68 /* libidn broke ABI in 1.34, but not in a way we care about (a new field got added to an
69 * open-coded struct we do not use), hence support both versions. */
70 dl
= dlopen("libidn.so.11", RTLD_LAZY
);
72 return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
73 "libidn support is not installed: %s", dlerror());
76 r
= dlsym_many_and_warn(
79 &sym_idna_to_ascii_4i
, "idna_to_ascii_4i",
80 &sym_idna_to_unicode_44i
, "idna_to_unicode_44i",
81 &sym_stringprep_ucs4_to_utf8
, "stringprep_ucs4_to_utf8",
82 &sym_stringprep_utf8_to_ucs4
, "stringprep_utf8_to_ucs4",
87 idn_dl
= TAKE_PTR(dl
);