4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1996-1998,2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Protocol interpreter for the Hypertext Transfer Protocol (HTTP)
33 * Berners-Lee, T., et al: Hypertext Transfer Protocol -- HTTP/1.0.
35 * Fielding, R., et al: Hypertext Transfer Protocol -- HTTP/1.1.
39 #include <netinet/in.h>
45 #define CR 13 /* "carriage return" character */
46 #define LF 10 /* "line feed" character */
49 * Summary lines: packet contents starting with less than MINCHARS
50 * printable characters will not be printed. MAXCHARS is the maximum
51 * number of characters printed.
52 * Detail lines: NLINES is the maximum number of content lines to print
58 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
60 static int printable(const char *line
, const char *endp
);
63 interpret_http(int flags
, char *line
, int fraglen
)
69 endp
= line
+ fraglen
;
72 c
= printable(line
, endp
- 1);
74 (void) snprintf(get_sum_line(), MAXLINE
,
77 (void) snprintf(get_sum_line(), MAXLINE
,
78 "HTTP %.*s", MIN(c
, MAXCHARS
), line
);
82 if (flags
& F_DTAIL
) {
83 show_header("HTTP: ", "HyperText Transfer Protocol", fraglen
);
87 for (p
= line
; p
< endp
&& lineno
< NLINES
; p
= q
+ 1) {
88 c
= printable(p
, endp
- 1);
90 /* stop if no printables, except if at line end */
91 if (c
== 0 && *p
!= CR
&& *p
!= LF
)
95 * A line may be terminated either by an CR LF sequence
96 * (DOS, Mac), or by LF alone
99 q
= memchr(p
, CR
, (endp
- p
));
101 if (q
< endp
- 1 && q
[1] == LF
)
102 ++q
; /* ignore subsequent LF character */
104 q
= memchr(p
, LF
, (endp
- p
));
105 /* no CR/LF: use end of buffer */
110 /* truncate lines containing non-printable characters */
111 (void) snprintf(get_line(0, c
), get_line_remain(),
116 if (p
< endp
) /* there was more data to be printed */
117 (void) snprintf(get_line(0, 5), get_line_remain(),
127 * Return the length of the initial string starting with "startp" and
128 * ending with "endp" (inclusively) consisting only of printable
133 printable(const char *startp
, const char *endp
)
135 const char *p
= startp
;
137 while (p
<= endp
&& (isprint(*p
) || *p
== '\t'))