handle iconv-failure more gracefully

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@863 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Michael Gernoth 2005-03-14 18:02:24 +00:00
parent 76526ecffe
commit fe3011d666

55
rdp.c
View File

@ -59,6 +59,10 @@ extern RDPCOMP g_mppc_dict;
static uint32 g_packetno;
#endif
#ifdef HAVE_ICONV
static BOOL g_iconv_works = True;
#endif
/* Receive an RDP packet */
static STREAM
rdp_recv(uint8 * type)
@ -161,21 +165,28 @@ rdp_out_unistr(STREAM s, char *string, int len)
memset(pout, 0, len + 4);
if (g_iconv_works)
{
if (iconv_h == (iconv_t) - 1)
{
size_t i = 1, o = 4;
if ((iconv_h = iconv_open(WINDOWS_CODEPAGE, g_codepage)) == (iconv_t) - 1)
{
printf("rdp_out_unistr: iconv_open[%s -> %s] fail %d\n",
warning("rdp_out_unistr: iconv_open[%s -> %s] fail %d\n",
g_codepage, WINDOWS_CODEPAGE, (int) iconv_h);
return;
g_iconv_works = False;
return (rdp_out_unistr(s, string, len));
}
if (iconv(iconv_h, (ICONV_CONST char **) &pin, &i, &pout, &o) == (size_t) - 1)
if (iconv(iconv_h, (ICONV_CONST char **) &pin, &i, &pout, &o) ==
(size_t) - 1)
{
iconv_close(iconv_h);
iconv_h = (iconv_t) - 1;
printf("rdp_out_unistr: iconv(1) fail, errno %d\n", errno);
return;
warning("rdp_out_unistr: iconv(1) fail, errno %d\n", errno);
g_iconv_works = False;
return (rdp_out_unistr(s, string, len));
}
pin = string;
pout = (char *) s->p;
@ -185,13 +196,18 @@ rdp_out_unistr(STREAM s, char *string, int len)
{
iconv_close(iconv_h);
iconv_h = (iconv_t) - 1;
printf("rdp_out_unistr: iconv(2) fail, errno %d\n", errno);
return;
warning("rdp_out_unistr: iconv(2) fail, errno %d\n", errno);
g_iconv_works = False;
return (rdp_out_unistr(s, string, len));
}
s->p += len + 2;
#else /* HAVE_ICONV undef */
}
else
#endif
{
int i = 0, j = 0;
len += 2;
@ -203,7 +219,7 @@ rdp_out_unistr(STREAM s, char *string, int len)
}
s->p += len;
#endif
}
}
/* Input a string in Unicode
@ -218,13 +234,17 @@ rdp_in_unistr(STREAM s, char *string, int uni_len)
char *pin = s->p, *pout = string;
static iconv_t iconv_h = (iconv_t) - 1;
if (g_iconv_works)
{
if (iconv_h == (iconv_t) - 1)
{
if ((iconv_h = iconv_open(g_codepage, WINDOWS_CODEPAGE)) == (iconv_t) - 1)
{
printf("rdp_in_unistr: iconv_open[%s -> %s] fail %d\n",
warning("rdp_in_unistr: iconv_open[%s -> %s] fail %d\n",
WINDOWS_CODEPAGE, g_codepage, (int) iconv_h);
return 0;
g_iconv_works = False;
return rdp_in_unistr(s, string, uni_len);
}
}
@ -232,11 +252,16 @@ rdp_in_unistr(STREAM s, char *string, int uni_len)
{
iconv_close(iconv_h);
iconv_h = (iconv_t) - 1;
printf("rdp_in_unistr: iconv fail, errno %d\n", errno);
return 0;
warning("rdp_in_unistr: iconv fail, errno %d\n", errno);
g_iconv_works = False;
return rdp_in_unistr(s, string, uni_len);
}
return pout - string;
#else /* HAVE_ICONV undef */
}
else
#endif
{
int i = 0;
while (i < uni_len / 2)
@ -246,7 +271,7 @@ rdp_in_unistr(STREAM s, char *string, int uni_len)
}
return i - 1;
#endif
}
}