mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Slightly reduce the code repetition between two loops in
copy_and_escape.
This commit is contained in:
parent
2892367cde
commit
b416b48a33
@ -1,3 +1,8 @@
|
|||||||
|
2005-05-05 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
|
* log.c (copy_and_escape): Slightly reduce code repetition between
|
||||||
|
the two loops.
|
||||||
|
|
||||||
2005-05-05 Charles C.Fu <ccwf@bacchus.com>
|
2005-05-05 Charles C.Fu <ccwf@bacchus.com>
|
||||||
|
|
||||||
* utils.c (proclist): Strip leading slash when calling fnmatch
|
* utils.c (proclist): Strip leading slash when calling fnmatch
|
||||||
|
53
src/log.c
53
src/log.c
@ -618,11 +618,7 @@ log_dump_context (void)
|
|||||||
/* String escape functions. */
|
/* String escape functions. */
|
||||||
|
|
||||||
/* Return the number of non-printable characters in SOURCE.
|
/* Return the number of non-printable characters in SOURCE.
|
||||||
|
Non-printable characters are determined as per safe-ctype.c. */
|
||||||
Non-printable characters are determined as per safe-ctype.h,
|
|
||||||
i.e. the non-printable characters of the "C" locale. This code is
|
|
||||||
meant to be used to protect the user from binary characters in
|
|
||||||
(normally ASCII) server messages. */
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
count_nonprint (const char *source)
|
count_nonprint (const char *source)
|
||||||
@ -639,21 +635,21 @@ count_nonprint (const char *source)
|
|||||||
|
|
||||||
Non-printable refers to anything outside the non-control ASCII
|
Non-printable refers to anything outside the non-control ASCII
|
||||||
range (32-126) which means that, for example, CR, LF, and TAB are
|
range (32-126) which means that, for example, CR, LF, and TAB are
|
||||||
considered non-printable along with ESC and other control chars.
|
considered non-printable along with ESC, BS, and other control
|
||||||
This is by design: it makes sure that messages from remote servers
|
chars. This is by design: it makes sure that messages from remote
|
||||||
cannot be used to deceive the users by mimicking Wget's output.
|
servers cannot be easily used to deceive the users by mimicking
|
||||||
Disallowing non-ASCII characters is another necessary security
|
Wget's output. Disallowing non-ASCII characters is another
|
||||||
measure, which makes sure that remote servers cannot garble the
|
necessary security measure, which makes sure that remote servers
|
||||||
screen or guess the local charset and perform homographic attacks.
|
cannot garble the screen or guess the local charset and perform
|
||||||
|
homographic attacks.
|
||||||
|
|
||||||
Of course, the above means that escnonprint must only be used in
|
Of course, the above mandates that escnonprint only be used in
|
||||||
decidedly ASCII-only context, such as when printing host names,
|
contexts expected to be ASCII, such as when printing host names,
|
||||||
responses from HTTP headers, messages coming from FTP servers, and
|
URL components, HTTP headers, FTP server messages, and the like.
|
||||||
the like.
|
|
||||||
|
|
||||||
ESCAPE is the character used to introduce the escape sequence.
|
ESCAPE is the leading character of the escape sequence. BASE
|
||||||
BASE should be the base of the escape sequence, and must be either
|
should be the base of the escape sequence, and must be either 8 for
|
||||||
8 for octal or 16 for hex.
|
octal or 16 for hex.
|
||||||
|
|
||||||
DEST must point to a location with sufficient room to store an
|
DEST must point to a location with sufficient room to store an
|
||||||
encoded version of SOURCE. */
|
encoded version of SOURCE. */
|
||||||
@ -661,19 +657,19 @@ count_nonprint (const char *source)
|
|||||||
static void
|
static void
|
||||||
copy_and_escape (const char *source, char *dest, char escape, int base)
|
copy_and_escape (const char *source, char *dest, char escape, int base)
|
||||||
{
|
{
|
||||||
const char *from;
|
const char *from = source;
|
||||||
char *to;
|
char *to = dest;
|
||||||
|
unsigned char c;
|
||||||
|
|
||||||
/* Copy the string from SOURCE to DEST, escaping non-printable chars. */
|
/* Copy chars from SOURCE to DEST, escaping non-printable ones. */
|
||||||
switch (base)
|
switch (base)
|
||||||
{
|
{
|
||||||
case 8:
|
case 8:
|
||||||
for (from = source, to = dest; *from; from++)
|
while ((c = *from++) != '\0')
|
||||||
if (ISPRINT (*from))
|
if (ISPRINT (c))
|
||||||
*to++ = *from;
|
*to++ = c;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const unsigned char c = *from;
|
|
||||||
*to++ = escape;
|
*to++ = escape;
|
||||||
*to++ = '0' + (c >> 6);
|
*to++ = '0' + (c >> 6);
|
||||||
*to++ = '0' + ((c >> 3) & 7);
|
*to++ = '0' + ((c >> 3) & 7);
|
||||||
@ -681,12 +677,11 @@ copy_and_escape (const char *source, char *dest, char escape, int base)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
for (from = source, to = dest; *from; from++)
|
while ((c = *from++) != '\0')
|
||||||
if (ISPRINT (*from))
|
if (ISPRINT (c))
|
||||||
*to++ = *from;
|
*to++ = c;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const unsigned char c = *from;
|
|
||||||
*to++ = escape;
|
*to++ = escape;
|
||||||
*to++ = XNUM_TO_DIGIT (c >> 4);
|
*to++ = XNUM_TO_DIGIT (c >> 4);
|
||||||
*to++ = XNUM_TO_DIGIT (c & 0xf);
|
*to++ = XNUM_TO_DIGIT (c & 0xf);
|
||||||
|
Loading…
Reference in New Issue
Block a user