Changed some symbols inside parser, fixed default error message in
[obnox/wireshark/wip.git] / packet-nntp.c
1 /* packet-nntp.c
2  * Routines for nntp packet dissection
3  * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
4  *
5  * $Id: packet-nntp.c,v 1.4 1999/08/18 00:57:52 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@unicom.net>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #ifdef HAVE_NETINET_IN_H
37 # include <netinet/in.h>
38 #endif
39
40 #include <string.h>
41 #include <glib.h>
42 #include "packet.h"
43
44 static int proto_nntp = -1;
45
46 void
47 dissect_nntp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
48 {
49         gchar           *type;
50         proto_tree      *nntp_tree, *ti;
51         const u_char    *data, *dataend;
52         const u_char    *lineend, *eol;
53         int             linelen;
54         int             max_data = pi.captured_len - offset;
55
56         data = &pd[offset];
57         dataend = data + END_OF_FRAME;
58         if (dataend > data + max_data)
59                 dataend = data + max_data;
60
61         if (pi.match_port == pi.destport)
62                 type = "Request";
63         else
64                 type = "Response";
65
66         if (check_col(fd, COL_PROTOCOL))
67                 col_add_str(fd, COL_PROTOCOL, "NNTP");
68
69         if (check_col(fd, COL_INFO)) {
70                 /*
71                  * Put the first line from the buffer into the summary.
72                  */
73                 lineend = find_line_end(data, dataend, &eol);
74                 linelen = eol - data;
75                 col_add_fstr(fd, COL_INFO, "%s: %s", type,
76                     format_text(data, linelen));
77         }
78
79         if (tree) {
80
81           ti = proto_tree_add_item(tree, proto_nntp, offset, END_OF_FRAME, NULL);
82           nntp_tree = proto_item_add_subtree(ti, ETT_NNTP);
83
84           /*
85            * Show the request or response as text, a line at a time.
86            * XXX - for requests, we could display the stuff after the
87            * first line, if any, based on what the request was, and
88            * for responses, we could display it based on what the
89            * matching request was, although the latter requires us to
90            * know what the matching request was....
91            */
92           while (data < dataend) {
93                 /*
94                  * Find the end of the line.
95                  */
96                 lineend = find_line_end(data, dataend, &eol);
97                 linelen = lineend - data;
98
99                 /*
100                  * Put this line.
101                  */
102                 proto_tree_add_text(nntp_tree, offset, linelen, "%s",
103                     format_text(data, linelen));
104                 offset += linelen;
105                 data = lineend;
106           }
107         }
108 }
109
110 void
111 proto_register_nntp(void)
112 {
113 /*        static hf_register_info hf[] = {
114                 { &variable,
115                 { "Name",           "nntp.abbreviation", TYPE, VALS_POINTER }},
116         };*/
117
118         proto_nntp = proto_register_protocol("Network News Transfer Protocol", "nntp");
119  /*       proto_register_field_array(proto_nntp, hf, array_length(hf));*/
120 }