+ *host_ptr = '\0';
+ state->offset += host_ptr - state->url.host;
+
+ return SUCCESS;
+
+ error:
+ if (!error) {
+ slprintf(ebuf, sizeof(ebuf)-1, "errorcode: %d", rc);
+ error = ebuf;
+ }
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN (ICU IDNA2003); %s", error);
+
+ return FAILURE;
+}
+#endif
+
+#ifdef HAVE_UIDNA_IDNTOASCII
+# if PHP_HTTP_HAVE_LIBICU
+# include <unicode/uidna.h>
+# endif
+static ZEND_RESULT_CODE parse_uidn_2008(struct parse_state *state)
+{
+ char *host_ptr, *error = NULL, ebuf[64] = {0};
+ UErrorCode rc = U_ZERO_ERROR;
+ UIDNAInfo info = UIDNA_INFO_INITIALIZER;
+ UIDNA *uidna = uidna_openUTS46(UIDNA_ALLOW_UNASSIGNED|UIDNA_USE_STD3_RULES, &rc);
+
+ if (!uidna || U_FAILURE(rc)) {
+ return FAILURE;
+ }
+
+ host_ptr = state->url.host;
+
+ if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
+ char ahost_str[MAXHOSTNAMELEN], *ahost_ptr = &ahost_str[0];
+ size_t ahost_len = uidna_nameToASCII_UTF8(uidna, host_ptr, -1, ahost_str, sizeof(ahost_str)-1, &info, &rc);
+
+ if (U_FAILURE(rc) || info.errors) {
+ goto error;
+ }
+ PHP_HTTP_DUFF(ahost_len, *host_ptr++ = *ahost_ptr++);
+#ifdef PHP_HTTP_HAVE_WCHAR
+ } else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
+ uint16_t *uhost_str, whost_str[MAXHOSTNAMELEN], *whost_ptr = &whost_str[0];
+ size_t uhost_len, whost_len;
+
+ if (SUCCESS != to_utf16(parse_mb_loc, host_ptr, &uhost_str, &uhost_len)) {
+ error = "could not convert to UTF-16";
+ goto error;
+ }
+
+ whost_len = uidna_nameToASCII(uidna, uhost_str, uhost_len, whost_str, sizeof(whost_str)-1, &info, &rc);
+ whost_ptr = whost_str;
+ if (U_FAILURE(rc) || info.errors) {
+ goto error;
+ }
+ PHP_HTTP_DUFF(whost_len, *host_ptr++ = *whost_ptr++);
+#endif
+ } else {
+ error = "codepage not specified";
+ goto error;
+ }