Skip to content

Commit

Permalink
idn_win32: Use boolean based success codes
Browse files Browse the repository at this point in the history
Rather than use 0 and 1 integer base result codes use a FALSE / TRUE
based success code.
  • Loading branch information
captain-caveman2k committed Mar 11, 2016
1 parent b084173 commit 58e4a06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
24 changes: 14 additions & 10 deletions lib/idn_win32.c
Expand Up @@ -65,12 +65,13 @@ WINBASEAPI int WINAPI IdnToUnicode(DWORD dwFlags,

#define IDN_MAX_LENGTH 255

int curl_win32_idn_to_ascii(const char *in, char **out);
int curl_win32_ascii_to_idn(const char *in, char **out);
bool curl_win32_idn_to_ascii(const char *in, char **out);
bool curl_win32_ascii_to_idn(const char *in, char **out);

int curl_win32_idn_to_ascii(const char *in, char **out)
bool curl_win32_idn_to_ascii(const char *in, char **out)
{
int ret = 0;
bool success = FALSE;

wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
if(in_w) {
wchar_t punycode[IDN_MAX_LENGTH];
Expand All @@ -79,15 +80,17 @@ int curl_win32_idn_to_ascii(const char *in, char **out)
if(chars) {
*out = Curl_convert_wchar_to_UTF8(punycode);
if(*out)
ret = 1; /* success */
success = TRUE;
}
}
return ret;

return success;
}

int curl_win32_ascii_to_idn(const char *in, char **out)
bool curl_win32_ascii_to_idn(const char *in, char **out)
{
int ret = 0;
bool success = FALSE;

wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
if(in_w) {
size_t in_len = wcslen(in_w) + 1;
Expand All @@ -98,10 +101,11 @@ int curl_win32_ascii_to_idn(const char *in, char **out)
if(chars) {
*out = Curl_convert_wchar_to_UTF8(unicode);
if(*out)
ret = 1; /* success */
success = TRUE;
}
}
return ret;

return success;
}

#endif /* USE_WIN32_IDN */
11 changes: 5 additions & 6 deletions lib/url.c
Expand Up @@ -75,7 +75,7 @@ void idn_free (void *ptr);
#endif
#elif defined(USE_WIN32_IDN)
/* prototype for curl_win32_idn_to_ascii() */
int curl_win32_idn_to_ascii(const char *in, char **out);
bool curl_win32_idn_to_ascii(const char *in, char **out);
#endif /* USE_LIBIDN */

#include "urldata.h"
Expand Down Expand Up @@ -3803,15 +3803,14 @@ static void fix_hostname(struct SessionHandle *data,
* Check name for non-ASCII and convert hostname to ACE form.
*************************************************************/
char *ace_hostname = NULL;
int rc = curl_win32_idn_to_ascii(host->name, &ace_hostname);
if(rc == 0)
infof(data, "Failed to convert %s to ACE;\n",
host->name);
else {

if(curl_win32_idn_to_ascii(host->name, &ace_hostname)) {
host->encalloc = ace_hostname;
/* change the name pointer to point to the encoded hostname */
host->name = host->encalloc;
}
else
infof(data, "Failed to convert %s to ACE;\n", host->name);
#else
infof(data, "IDN support not present, can't parse Unicode domains\n");
#endif
Expand Down

0 comments on commit 58e4a06

Please sign in to comment.