Call subdissectors even if we're not building a protocol tree.
[obnox/wireshark/wip.git] / packet-msn-messenger.c
1 /* packet-msn-messenger.c
2  * Routines for MSN Messenger Service packet dissection
3  * Copyright 2003, Chris Waters <chris@waters.co.nz>
4  *
5  * $Id: packet-msn-messenger.c,v 1.3 2003/02/13 23:49:19 jmayer Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-pop.c
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33
34 #include <string.h>
35 #include <glib.h>
36 #include <epan/packet.h>
37 #include <epan/strutil.h>
38
39 /*
40  * The now-expired Internet-Draft for the MSN Messenger 1.0 protocol
41  * can, as of the time of the writing of this comment, be found at:
42  *
43  *      http://praya.sourceforge.net/draft-movva-msn-messenger-protocol-00.txt
44  *
45  *      http://mono.es.gnome.org/imsharp/tutoriales/msn/appendixa.html
46  *
47  *      http://www.hypothetic.org/docs/msn/ietf_draft.php
48  *
49  *      http://babble.wundsam.net/docs/protocol-msn-im.txt
50  *
51  * Note that it's Yet Another FTP-Like Command/Response Protocol,
52  * so it arguably should be dissected as such, although you do have
53  * to worry about the MSG command, as only the first line of it
54  * should be parsed as a command, the rest should be parsed as the
55  * message body.  We therefore leave "hf_msnms_command", "tokenlen",
56  * and "next_token", even though they're unused, as reminders that
57  * this should be done.
58  */
59
60 static int proto_msnms = -1;
61 /* static int hf_msnms_command = -1; */
62
63 static gint ett_msnms = -1;
64
65 static dissector_handle_t data_handle;
66
67 #define TCP_PORT_MSNMS                  1863
68
69 static void
70 dissect_msnms(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
71 {
72         proto_tree      *msnms_tree;
73         proto_item      *ti;
74         gint            offset = 0;
75         const guchar    *line;
76         gint            next_offset;
77         int             linelen;
78         /* int          tokenlen; */
79         /* const guchar *next_token; */
80
81         if (check_col(pinfo->cinfo, COL_PROTOCOL))
82                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSNMS");
83
84         /*
85          * Find the end of the first line.
86          *
87          * Note that "tvb_find_line_end()" will return a value that is
88          * not longer than what's in the buffer, so the "tvb_get_ptr()"
89          * call won't throw an exception.
90          */
91         linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
92         line = tvb_get_ptr(tvb, offset, linelen);
93
94
95         if (check_col(pinfo->cinfo, COL_INFO)) {
96                 /*
97                  * Put the first line from the buffer into the summary.
98                  */
99                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
100                             format_text(line, linelen));
101         }
102
103         if (tree) {
104                 ti = proto_tree_add_item(tree, proto_msnms, tvb, offset, -1,
105                     FALSE);
106                 msnms_tree = proto_item_add_subtree(ti, ett_msnms);
107
108                 /*
109                  * Show the rest of the packet as text,
110                  * a line at a time.
111                  */
112                 while (tvb_offset_exists(tvb, offset)) {
113                         /*
114                          * Find the end of the line.
115                          */
116                         linelen = tvb_find_line_end(tvb, offset, -1,
117                             &next_offset, FALSE);
118
119                         /*
120                          * Put this line.
121                          */
122                         proto_tree_add_text(msnms_tree, tvb, offset,
123                             next_offset - offset, "%s",
124                             tvb_format_text(tvb, offset, next_offset - offset));
125                         offset = next_offset;
126                 }
127         }
128 }
129
130 void
131 proto_register_msnms(void)
132 {
133   static gint *ett[] = {
134     &ett_msnms,
135   };
136
137   proto_msnms = proto_register_protocol("MSN Messenger Service", "MSNMS", "msnms");
138   proto_register_subtree_array(ett, array_length(ett));
139 }
140
141 void
142 proto_reg_handoff_msnms(void)
143 {
144   dissector_handle_t msnms_handle;
145
146   msnms_handle = create_dissector_handle(dissect_msnms, proto_msnms);
147   dissector_add("tcp.port", TCP_PORT_MSNMS, msnms_handle);
148   data_handle = find_dissector("data");
149 }