Date: Mon, 20 May 2002 06:10:03 -0700 (PDT) From: Cyrille Lefevre <cyrille.lefevre@laposte.net> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/26005: MIME quoted-printable encoding added to vis/unvis + bug fix Message-ID: <200205201310.g4KDA3s87981@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/26005; it has been noted by GNATS.
From: Cyrille Lefevre <cyrille.lefevre@laposte.net>
To: freebsd gnats <freebsd-gnats-submit@freebsd.org>,
freebsd bugs <freebsd-bugs@freebsd.org>
Cc:
Subject: Re: bin/26005: MIME quoted-printable encoding added to vis/unvis + bug
fix
Date: Mon, 20 May 2002 15:06:41 +0200 (CEST)
--ELM1021900001-24230-0_
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII
On Mar 22, 2001 11:30:01 am -0800, gnats-admin@FreeBSD.org wrote:
humm! bug fix related to changes in vis(3).
patch supplied.
Cyrille.
--
Cyrille Lefevre mailto:cyrille.lefevre@laposte.net
--ELM1021900001-24230-0_
Content-Transfer-Encoding: 7bit
Content-Type: text/x-patch
Content-Disposition: attachment; filename=vis-2.patch
Content-Description: vis-2.patch
Index: lib/libc/gen/vis.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/gen/vis.c,v
retrieving revision 1.5.8.2
diff -u -r1.5.8.2 vis.c
--- lib/libc/gen/vis.c 5 Mar 2001 09:44:34 -0000 1.5.8.2
+++ lib/libc/gen/vis.c 22 Apr 2002 12:06:47 -0000
@@ -54,33 +54,84 @@
int c, nextc;
register int flag;
{
- c = (unsigned char)c;
+ static int lastc = EOF;
+
+ if (flag & VIS_QPSTYLE) {
+ /* Described in RFC 2045 */
+ if (c == '\n') {
+ if (isascii(lastc) && isblank(lastc)) {
+ *dst++ = '=';
+ *dst++ = c;
+ }
+ *dst++ = c;
+ goto done;
+ }
+ if (c == '=' || !(isascii(c) && (isgraph(c) || isblank(c)))) {
+ *dst++ = '=';
+ snprintf(dst, 4, "%02X", c);
+ dst += 2;
+ goto done;
+ }
+ }
if (flag & VIS_HTTPSTYLE) {
- /* Described in RFC 1808 */
- if (!(isalnum(c) /* alpha-numeric */
+ if (!(
+#define RFC 0
+#if RFC == 2396
+ isalnum(c) /* alpha-numeric */
+ /* reserved */
+ || c == ';' || c == '/' || c == '?' || c == ':'
+ || c == '@' || c == '&' || c == '=' || c == '+'
+ || c == '$' || c == ','
+ /* mark */
+ || c == '-' || c == '_' || c == '.' || c == '!'
+ || c == '~' || c == '*' || c == '\'' || c == '('
+ || c == ')'
+ /* delims */
+ || c == '<' || c == '>' || c == '#' || c == '%'
+ || c == '"'
+ /* unwise */
+ || c == '{' || c == '}' || c == '|' || c == '\\'
+ || c == '^' || c == '[' || c == ']' || c == '`'
+#elif RFC == 1808 /* obsoleted by RFC2396 */
+ isalnum(c) /* alpha-numeric */
/* safe */
- || c == '$' || c == '-' || c == '_' || c == '.' || c == '+'
+ || c == '$' || c == '-' || c == '_' || c == '.'
+ || c == '+'
/* extra */
|| c == '!' || c == '*' || c == '\'' || c == '('
- || c == ')' || c == ',')) {
+ || c == ')' || c == ','
+ /* national */
+ || c == '{' || c == '}' || c == '|' || c == '\\'
+ || c == '^' || c == '~' || c == '[' || c == ']'
+ || c == '`'
+ /* reserved */
+ || c == ';' || c == '/' || c == '?' || c == ':'
+ || c == '@' || c == '&' || c == '='
+ /* punctuation */
+ || c == '<' || c == '>' || c == '#' || c == '%'
+ || c == '"'
+#else /* same as above, but faster. */
+ isgraph(c) && isascii(c)
+#endif
+ )) {
*dst++ = '%';
- snprintf(dst, 4, (c < 16 ? "0%X" : "%X"), c);
+ snprintf(dst, 4, "%02X", c);
dst += 2;
goto done;
}
}
if (isgraph(c) ||
- ((flag & VIS_SP) == 0 && c == ' ') ||
- ((flag & VIS_TAB) == 0 && c == '\t') ||
- ((flag & VIS_NL) == 0 && c == '\n') ||
- ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) {
+ (c == ' ' && !(flag & VIS_SP)) ||
+ (c == '\t' && !(flag & VIS_TAB)) ||
+ (c == '\n' && !(flag & VIS_NL)) ||
+ ((c == '\b' || c == '\007' || c == '\r') && (flag & VIS_SAFE))) {
*dst++ = c;
- if (c == '\\' && (flag & VIS_NOSLASH) == 0)
+ if (c == '\\' &&
+ !(flag & (VIS_NOSLASH|VIS_QPSTYLE|VIS_HTTPSTYLE)))
*dst++ = '\\';
- *dst = '\0';
- return (dst);
+ goto done;
}
if (flag & VIS_CSTYLE) {
@@ -133,9 +184,9 @@
}
if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
*dst++ = '\\';
- *dst++ = ((u_char)c >> 6 & 07) + '0';
- *dst++ = ((u_char)c >> 3 & 07) + '0';
- *dst++ = ((u_char)c & 07) + '0';
+ *dst++ = (c >> 6 & 07) + '0';
+ *dst++ = (c >> 3 & 07) + '0';
+ *dst++ = (c & 07) + '0';
goto done;
}
if ((flag & VIS_NOSLASH) == 0)
@@ -155,6 +206,7 @@
*dst++ = c;
}
done:
+ lastc = c;
*dst = '\0';
return (dst);
}
@@ -175,10 +227,10 @@
register const char *src;
int flag;
{
- register char c;
- char *start;
+ register int c;
+ char *start = dst;
- for (start = dst; (c = *src); )
+ while ( (c = *src) )
dst = vis(dst, c, flag, *++src);
*dst = '\0';
return (dst - start);
@@ -191,16 +243,15 @@
register size_t len;
int flag;
{
- int c;
- char *start;
+ register int c;
+ char *start = dst;
- for (start = dst; len > 1; len--) {
+ while (len-- > 1) {
c = *src;
dst = vis(dst, c, flag, *++src);
}
- if (len)
- dst = vis(dst, *src, flag, '\0');
+ if (!len)
+ dst = vis(dst, *src, flag, 0);
*dst = '\0';
-
return (dst - start);
}
--ELM1021900001-24230-0_--
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200205201310.g4KDA3s87981>
