version 1.38, 2008/09/04 09:41:44 |
version 1.39, 2009/02/10 23:06:31 |
Line 91 static char *do_svis(char *, int, int, i |
|
Line 91 static char *do_svis(char *, int, int, i |
|
#define iswhite(c) (c == ' ' || c == '\t' || c == '\n') |
#define iswhite(c) (c == ' ' || c == '\t' || c == '\n') |
#define issafe(c) (c == '\b' || c == BELL || c == '\r') |
#define issafe(c) (c == '\b' || c == BELL || c == '\r') |
#define xtoa(c) "0123456789abcdef"[c] |
#define xtoa(c) "0123456789abcdef"[c] |
|
#define XTOA(c) "0123456789ABCDEF"[c] |
|
|
#define MAXEXTRAS 5 |
#define MAXEXTRAS 5 |
|
|
Line 130 do_hvis(char *dst, int c, int flag, int |
|
Line 131 do_hvis(char *dst, int c, int flag, int |
|
} |
} |
|
|
/* |
/* |
|
* This is do_mvis, for Quoted-Printable MIME (RFC 2045) |
|
* NB: No handling of long lines or CRLF. |
|
*/ |
|
static char * |
|
do_mvis(char *dst, int c, int flag, int nextc, const char *extra) |
|
{ |
|
if ((c != '\n') && |
|
/* Space at the end of the line */ |
|
((isspace(c) && (nextc == '\r' || nextc == '\n')) || |
|
/* Out of range */ |
|
(!isspace(c) && (c < 33 || (c > 60 && c < 62) || c > 126)) || |
|
/* Specific char to be escaped */ |
|
strchr("#$@[\\]^`{|}~", c) != NULL)) { |
|
*dst++ = '='; |
|
*dst++ = XTOA(((unsigned int)c >> 4) & 0xf); |
|
*dst++ = XTOA((unsigned int)c & 0xf); |
|
} else { |
|
dst = do_svis(dst, c, flag, nextc, extra); |
|
} |
|
return dst; |
|
} |
|
|
|
/* |
* This is do_vis, the central code of vis. |
* This is do_vis, the central code of vis. |
* dst: Pointer to the destination buffer |
* dst: Pointer to the destination buffer |
* c: Character to encode |
* c: Character to encode |
Line 211 do_svis(char *dst, int c, int flag, int |
|
Line 235 do_svis(char *dst, int c, int flag, int |
|
return dst; |
return dst; |
} |
} |
|
|
|
typedef char *(*visfun_t)(char *, int, int, int, const char *); |
|
|
|
/* |
|
* Return the appropriate encoding function depending on the flags given. |
|
*/ |
|
static visfun_t |
|
getvisfun(int flag) |
|
{ |
|
if (flag & VIS_HTTPSTYLE) |
|
return do_hvis; |
|
if (flag * VIS_MIMESTYLE) |
|
return do_mvis; |
|
return do_svis; |
|
} |
|
|
/* |
/* |
* svis - visually encode characters, also encoding the characters |
* svis - visually encode characters, also encoding the characters |
|
|
svis(char *dst, int c, int flag, int nextc, const char *extra) |
svis(char *dst, int c, int flag, int nextc, const char *extra) |
{ |
{ |
char *nextra = NULL; |
char *nextra = NULL; |
|
visfun_t f; |
|
|
_DIAGASSERT(dst != NULL); |
_DIAGASSERT(dst != NULL); |
_DIAGASSERT(extra != NULL); |
_DIAGASSERT(extra != NULL); |
Line 228 svis(char *dst, int c, int flag, int nex |
|
Line 267 svis(char *dst, int c, int flag, int nex |
|
*dst = '\0'; /* can't create nextra, return "" */ |
*dst = '\0'; /* can't create nextra, return "" */ |
return dst; |
return dst; |
} |
} |
if (flag & VIS_HTTPSTYLE) |
f = getvisfun(flag); |
dst = do_hvis(dst, c, flag, nextc, nextra); |
dst = (*f)(dst, c, flag, nextc, nextra); |
else |
|
dst = do_svis(dst, c, flag, nextc, nextra); |
|
free(nextra); |
free(nextra); |
*dst = '\0'; |
*dst = '\0'; |
return dst; |
return dst; |
Line 260 strsvis(char *dst, const char *csrc, int |
|
Line 297 strsvis(char *dst, const char *csrc, int |
|
char *start; |
char *start; |
char *nextra = NULL; |
char *nextra = NULL; |
const unsigned char *src = (const unsigned char *)csrc; |
const unsigned char *src = (const unsigned char *)csrc; |
|
visfun_t f; |
|
|
_DIAGASSERT(dst != NULL); |
_DIAGASSERT(dst != NULL); |
_DIAGASSERT(src != NULL); |
_DIAGASSERT(src != NULL); |
Line 269 strsvis(char *dst, const char *csrc, int |
|
Line 307 strsvis(char *dst, const char *csrc, int |
|
*dst = '\0'; /* can't create nextra, return "" */ |
*dst = '\0'; /* can't create nextra, return "" */ |
return 0; |
return 0; |
} |
} |
if (flag & VIS_HTTPSTYLE) { |
f = getvisfun(flag); |
for (start = dst; (c = *src++) != '\0'; /* empty */) |
for (start = dst; (c = *src++) != '\0'; /* empty */) |
dst = do_hvis(dst, c, flag, *src, nextra); |
dst = (*f)(dst, c, flag, *src, nextra); |
} else { |
|
for (start = dst; (c = *src++) != '\0'; /* empty */) |
|
dst = do_svis(dst, c, flag, *src, nextra); |
|
} |
|
free(nextra); |
free(nextra); |
*dst = '\0'; |
*dst = '\0'; |
return (dst - start); |
return (int)(dst - start); |
} |
} |
|
|
|
|
Line 289 strsvisx(char *dst, const char *csrc, si |
|
Line 323 strsvisx(char *dst, const char *csrc, si |
|
char *start; |
char *start; |
char *nextra = NULL; |
char *nextra = NULL; |
const unsigned char *src = (const unsigned char *)csrc; |
const unsigned char *src = (const unsigned char *)csrc; |
|
visfun_t f; |
|
|
_DIAGASSERT(dst != NULL); |
_DIAGASSERT(dst != NULL); |
_DIAGASSERT(src != NULL); |
_DIAGASSERT(src != NULL); |
Line 299 strsvisx(char *dst, const char *csrc, si |
|
Line 334 strsvisx(char *dst, const char *csrc, si |
|
return 0; |
return 0; |
} |
} |
|
|
if (flag & VIS_HTTPSTYLE) { |
f = getvisfun(flag); |
for (start = dst; len > 0; len--) { |
for (start = dst; len > 0; len--) { |
c = *src++; |
c = *src++; |
dst = do_hvis(dst, c, flag, |
dst = (*f)(dst, c, flag, len > 1 ? *src : '\0', nextra); |
len > 1 ? *src : '\0', nextra); |
|
} |
|
} else { |
|
for (start = dst; len > 0; len--) { |
|
c = *src++; |
|
dst = do_svis(dst, c, flag, |
|
len > 1 ? *src : '\0', nextra); |
|
} |
|
} |
} |
free(nextra); |
free(nextra); |
*dst = '\0'; |
*dst = '\0'; |
return (dst - start); |
return (int)(dst - start); |
} |
} |
#endif |
#endif |
|
|
Line 327 vis(char *dst, int c, int flag, int next |
|
Line 354 vis(char *dst, int c, int flag, int next |
|
{ |
{ |
char *extra = NULL; |
char *extra = NULL; |
unsigned char uc = (unsigned char)c; |
unsigned char uc = (unsigned char)c; |
|
visfun_t f; |
|
|
_DIAGASSERT(dst != NULL); |
_DIAGASSERT(dst != NULL); |
|
|
Line 335 vis(char *dst, int c, int flag, int next |
|
Line 363 vis(char *dst, int c, int flag, int next |
|
*dst = '\0'; /* can't create extra, return "" */ |
*dst = '\0'; /* can't create extra, return "" */ |
return dst; |
return dst; |
} |
} |
if (flag & VIS_HTTPSTYLE) |
f = getvisfun(flag); |
dst = do_hvis(dst, uc, flag, nextc, extra); |
dst = (*f)(dst, uc, flag, nextc, extra); |
else |
|
dst = do_svis(dst, uc, flag, nextc, extra); |
|
free(extra); |
free(extra); |
*dst = '\0'; |
*dst = '\0'; |
return dst; |
return dst; |