Update Free Software Foundation address.
[metze/wireshark/wip.git] / epan / dissectors / 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$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <glib.h>
33 #include <epan/packet.h>
34 #include <epan/strutil.h>
35
36 /*
37  * The now-expired Internet-Draft for the MSN Messenger 1.0 protocol
38  * can, as of the time of the writing of this comment, be found at:
39  *
40  *      http://praya.sourceforge.net/draft-movva-msn-messenger-protocol-00.txt
41  *
42  *      http://mono.es.gnome.org/imsharp/tutoriales/msn/appendixa.html
43  *
44  *      http://www.hypothetic.org/docs/msn/ietf_draft.php
45  *
46  *      http://babble.wundsam.net/docs/protocol-msn-im.txt
47  *
48  * Note that it's Yet Another FTP-Like Command/Response Protocol,
49  * so it arguably should be dissected as such, although you do have
50  * to worry about the MSG command, as only the first line of it
51  * should be parsed as a command, the rest should be parsed as the
52  * message body.  We therefore leave "hf_msnms_command", "tokenlen",
53  * and "next_token", even though they're unused, as reminders that
54  * this should be done.
55  */
56
57 static int proto_msnms = -1;
58 /* static int hf_msnms_command = -1; */
59
60 static gint ett_msnms = -1;
61
62 #define TCP_PORT_MSNMS                  1863
63
64 static void
65 dissect_msnms(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
66 {
67         proto_tree      *msnms_tree;
68         proto_item      *ti;
69         gint            offset = 0;
70         const guchar    *line;
71         gint            next_offset;
72         int             linelen;
73         /* int          tokenlen; */
74         /* const guchar *next_token; */
75
76         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSNMS");
77
78         /*
79          * Find the end of the first line.
80          *
81          * Note that "tvb_find_line_end()" will return a value that is
82          * not longer than what's in the buffer, so the "tvb_get_ptr()"
83          * call won't throw an exception.
84          */
85         linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
86         line = tvb_get_ptr(tvb, offset, linelen);
87
88
89         if (check_col(pinfo->cinfo, COL_INFO)) {
90                 /*
91                  * Put the first line from the buffer into the summary.
92                  */
93                 col_add_str(pinfo->cinfo, COL_INFO,
94                             format_text(line, linelen));
95         }
96
97         if (tree) {
98                 ti = proto_tree_add_item(tree, proto_msnms, tvb, offset, -1,
99                     ENC_NA);
100                 msnms_tree = proto_item_add_subtree(ti, ett_msnms);
101
102                 /*
103                  * Show the rest of the packet as text,
104                  * a line at a time.
105                  */
106                 while (tvb_offset_exists(tvb, offset)) {
107                         /*
108                          * Find the end of the line.
109                          */
110                         linelen = tvb_find_line_end(tvb, offset, -1,
111                             &next_offset, FALSE);
112
113                         /*
114                          * Put this line.
115                          */
116                         proto_tree_add_text(msnms_tree, tvb, offset,
117                             next_offset - offset, "%s",
118                             tvb_format_text(tvb, offset, next_offset - offset));
119                         offset = next_offset;
120                 }
121         }
122 }
123
124 void
125 proto_register_msnms(void)
126 {
127   static gint *ett[] = {
128     &ett_msnms,
129   };
130
131   proto_msnms = proto_register_protocol("MSN Messenger Service", "MSNMS", "msnms");
132   proto_register_subtree_array(ett, array_length(ett));
133 }
134
135 void
136 proto_reg_handoff_msnms(void)
137 {
138   dissector_handle_t msnms_handle;
139
140   msnms_handle = create_dissector_handle(dissect_msnms, proto_msnms);
141   dissector_add_uint("tcp.port", TCP_PORT_MSNMS, msnms_handle);
142   /*
143    * For MSN Messenger Protocol over HTTP
144    */
145   dissector_add_string("media_type", "application/x-msn-messenger", msnms_handle);
146 }