idn_win32.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023  /*
00024   * IDN conversions using Windows kernel32 and normaliz libraries.
00025   */
00026 
00027 #include "curl_setup.h"
00028 
00029 #ifdef USE_WIN32_IDN
00030 
00031 #include "curl_multibyte.h"
00032 #include "curl_memory.h"
00033 #include "warnless.h"
00034 
00035   /* The last #include file should be: */
00036 #include "memdebug.h"
00037 
00038 #ifdef WANT_IDN_PROTOTYPES
00039 #  if defined(_SAL_VERSION)
00040 WINNORMALIZEAPI int WINAPI
00041 IdnToAscii(_In_                           DWORD    dwFlags,
00042            _In_reads_(cchUnicodeChar)     LPCWSTR  lpUnicodeCharStr,
00043            _In_                           int      cchUnicodeChar,
00044            _Out_writes_opt_(cchASCIIChar) LPWSTR   lpASCIICharStr,
00045            _In_                           int      cchASCIIChar);
00046 WINNORMALIZEAPI int WINAPI
00047 IdnToUnicode(_In_                             DWORD   dwFlags,
00048              _In_reads_(cchASCIIChar)         LPCWSTR lpASCIICharStr,
00049              _In_                             int     cchASCIIChar,
00050              _Out_writes_opt_(cchUnicodeChar) LPWSTR  lpUnicodeCharStr,
00051              _In_                             int     cchUnicodeChar);
00052 #  else
00053 WINBASEAPI int WINAPI IdnToAscii(DWORD dwFlags,
00054                                  const WCHAR *lpUnicodeCharStr,
00055                                  int cchUnicodeChar,
00056                                  WCHAR *lpASCIICharStr,
00057                                  int cchASCIIChar);
00058 WINBASEAPI int WINAPI IdnToUnicode(DWORD dwFlags,
00059                                    const WCHAR *lpASCIICharStr,
00060                                    int cchASCIIChar,
00061                                    WCHAR *lpUnicodeCharStr,
00062                                    int cchUnicodeChar);
00063 #  endif
00064 #endif
00065 
00066 #define IDN_MAX_LENGTH 255
00067 
00068 bool curl_win32_idn_to_ascii(const char *in, char **out);
00069 bool curl_win32_ascii_to_idn(const char *in, char **out);
00070 
00071 bool curl_win32_idn_to_ascii(const char *in, char **out)
00072 {
00073   bool success = FALSE;
00074 
00075   wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
00076   if(in_w) {
00077     wchar_t punycode[IDN_MAX_LENGTH];
00078     int chars = IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH);
00079     free(in_w);
00080     if(chars) {
00081       *out = Curl_convert_wchar_to_UTF8(punycode);
00082       if(*out)
00083         success = TRUE;
00084     }
00085   }
00086 
00087   return success;
00088 }
00089 
00090 bool curl_win32_ascii_to_idn(const char *in, char **out)
00091 {
00092   bool success = FALSE;
00093 
00094   wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
00095   if(in_w) {
00096     size_t in_len = wcslen(in_w) + 1;
00097     wchar_t unicode[IDN_MAX_LENGTH];
00098     int chars = IdnToUnicode(0, in_w, curlx_uztosi(in_len),
00099                              unicode, IDN_MAX_LENGTH);
00100     free(in_w);
00101     if(chars) {
00102       *out = Curl_convert_wchar_to_UTF8(unicode);
00103       if(*out)
00104         success = TRUE;
00105     }
00106   }
00107 
00108   return success;
00109 }
00110 
00111 #endif /* USE_WIN32_IDN */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:04