Joerg Mayer's updates to the VINES dissector and to protocol layers
[obnox/wireshark/wip.git] / packet-yhoo.c
1 /* packet-yhoo.c
2  * Routines for yahoo messenger packet dissection
3  * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
4  *
5  * $Id: packet-yhoo.c,v 1.5 2000/01/07 22:05:42 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-tftp.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 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
40 #endif
41
42 #include <string.h>
43 #include <glib.h>
44 #include "packet.h"
45 #include "packet-yhoo.h"
46
47 static int proto_yhoo = -1;
48 static int hf_yhoo_version = -1;
49 static int hf_yhoo_len = -1;
50 static int hf_yhoo_service = -1;
51 static int hf_yhoo_connection_id = -1;
52 static int hf_yhoo_magic_id = -1;
53 static int hf_yhoo_unknown1 = -1;
54 static int hf_yhoo_msgtype = -1;
55 static int hf_yhoo_nick1 = -1;
56 static int hf_yhoo_nick2 = -1;
57 static int hf_yhoo_content = -1;
58
59 static gint ett_yhoo = -1;
60
61 static const value_string yhoo_service_vals[] = {
62         {YAHOO_SERVICE_LOGON, "Pager Logon"},
63         {YAHOO_SERVICE_LOGOFF, "Pager Logoff"},
64         {YAHOO_SERVICE_ISAWAY, "Is Away"},
65         {YAHOO_SERVICE_ISBACK, "Is Back"},
66         {YAHOO_SERVICE_IDLE, "Idle"},
67         {YAHOO_SERVICE_MESSAGE, "Message"},
68         {YAHOO_SERVICE_IDACT, "Activate Identity"},
69         {YAHOO_SERVICE_IDDEACT, "Deactivate Identity"},
70         {YAHOO_SERVICE_MAILSTAT, "Mail Status"},
71         {YAHOO_SERVICE_USERSTAT, "User Status"},
72         {YAHOO_SERVICE_NEWMAIL, "New Mail"},
73         {YAHOO_SERVICE_CHATINVITE, "Chat Invitation"},
74         {YAHOO_SERVICE_CALENDAR, "Calendar Reminder"},
75         {YAHOO_SERVICE_NEWPERSONALMAIL, "New Personals Mail"},
76         {YAHOO_SERVICE_NEWCONTACT, "New Friend"},
77         {YAHOO_SERVICE_GROUPRENAME, "Group Renamed"},
78         {YAHOO_SERVICE_ADDIDENT, "Add Identity"},
79         {YAHOO_SERVICE_ADDIGNORE, "Add Ignore"},
80         {YAHOO_SERVICE_PING, "Ping"},
81         {YAHOO_SERVICE_SYSMESSAGE, "System Message"},
82         {YAHOO_SERVICE_CONFINVITE, "Conference Invitation"},
83         {YAHOO_SERVICE_CONFLOGON, "Conference Logon"},
84         {YAHOO_SERVICE_CONFDECLINE, "Conference Decline"},
85         {YAHOO_SERVICE_CONFLOGOFF, "Conference Logoff"},
86         {YAHOO_SERVICE_CONFMSG, "Conference Message"},
87         {YAHOO_SERVICE_CONFADDINVITE, "Conference Additional Invitation"},
88         {YAHOO_SERVICE_CHATLOGON, "Chat Logon"},
89         {YAHOO_SERVICE_CHATLOGOFF, "Chat Logoff"},
90         {YAHOO_SERVICE_CHATMSG, "Chat Message"},
91         {YAHOO_SERVICE_FILETRANSFER, "File Transfer"},
92         {YAHOO_SERVICE_PASSTHROUGH2, "Passthrough 2"},
93         {0, NULL}
94 };
95
96 static const value_string yhoo_msgtype_vals[] = {
97         {YAHOO_MSGTYPE_NONE, "None"},
98         {YAHOO_MSGTYPE_NORMAL, "Normal"},
99         {YAHOO_MSGTYPE_BOUNCE, "Bounce"},
100         {YAHOO_MSGTYPE_STATUS, "Status Update"},
101         {YAHOO_MSGTYPE_OFFLINE, "Request Offline"},
102         {0, NULL}
103 };
104
105 void
106 dissect_yhoo(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
107 {
108         proto_tree      *yhoo_tree, *ti;
109         struct yahoo_rawpacket *pkt;
110
111         /* get at least a full packet structure */
112         if ( !BYTES_ARE_IN_FRAME(offset, sizeof(struct yahoo_rawpacket)) )
113                 return;
114
115         pkt = (struct yahoo_rawpacket *) &pd[offset];
116         
117         if (check_col(fd, COL_PROTOCOL))
118                 col_add_str(fd, COL_PROTOCOL, "YHOO");
119
120         if (check_col(fd, COL_INFO))
121                 col_add_fstr(fd, COL_INFO, 
122                         "%s: %s", 
123                         ( strncmp(pkt->version, "YPNS", 4) == 0 ) ? "Request" : "Response",
124                         val_to_str(pletohl(pkt->service),
125                                  yhoo_service_vals, "Unknown Service: %u")
126                 );
127
128         if (tree) {
129                 ti = proto_tree_add_item(tree, proto_yhoo, offset, END_OF_FRAME, NULL);
130                 yhoo_tree = proto_item_add_subtree(ti, ett_yhoo);
131
132                 proto_tree_add_item(yhoo_tree, hf_yhoo_version, 
133                         offset, 8, pkt->version);
134                 proto_tree_add_item(yhoo_tree, hf_yhoo_len, 
135                         offset+8, 4, pletohl(pkt->len));
136                 proto_tree_add_item(yhoo_tree, hf_yhoo_service, 
137                         offset+12, 4, pletohl(pkt->service));
138                 proto_tree_add_item(yhoo_tree, hf_yhoo_connection_id, 
139                         offset+16, 4, pletohl(pkt->connection_id));
140                 proto_tree_add_item(yhoo_tree, hf_yhoo_magic_id, 
141                         offset+20, 4, pletohl(pkt->magic_id));
142                 proto_tree_add_item(yhoo_tree, hf_yhoo_unknown1, 
143                         offset+24, 4, pletohl(pkt->unknown1));
144                 proto_tree_add_item(yhoo_tree, hf_yhoo_msgtype, 
145                         offset+28, 4, pletohl(pkt->msgtype));
146                 proto_tree_add_item(yhoo_tree, hf_yhoo_nick1, 
147                         offset+32, 36, pkt->nick1);
148                 proto_tree_add_item(yhoo_tree, hf_yhoo_nick2, 
149                         offset+68, 36, pkt->nick2);
150                 proto_tree_add_item(yhoo_tree, hf_yhoo_content, 
151                         offset+104, END_OF_FRAME, pkt->content);
152         }
153 }
154
155 void
156 proto_register_yhoo(void)
157 {
158         static hf_register_info hf[] = {
159                         { &hf_yhoo_service, {   
160                                 "Service Type", "yhoo.service", FT_UINT32, BASE_DEC,
161                                 VALS(yhoo_service_vals), 0, "Service Type" }},
162                         { &hf_yhoo_msgtype, {   
163                                 "Message Type", "yhoo.msgtype", FT_UINT32, BASE_DEC,
164                                 VALS(yhoo_msgtype_vals), 0, "Message Type Flags" }},
165                         { &hf_yhoo_connection_id, {     
166                                 "Connection ID", "yhoo.connection_id", FT_UINT32, BASE_HEX,
167                                 NULL, 0, "Connection ID" }},
168                         { &hf_yhoo_magic_id, {  
169                                 "Magic ID", "yhoo.magic_id", FT_UINT32, BASE_HEX,
170                                 NULL, 0, "Magic ID" }},
171                         { &hf_yhoo_unknown1, {  
172                                 "Unknown 1", "yhoo.unknown1", FT_UINT32, BASE_HEX,
173                                 NULL, 0, "Unknown 1" }},
174                         { &hf_yhoo_len, {       
175                                 "Packet Length", "yhoo.len", FT_UINT32, BASE_DEC,
176                                 NULL, 0, "Packet Length" }},
177                         { &hf_yhoo_nick1, {     
178                                 "Real Nick (nick1)", "yhoo.nick1", FT_STRING, 0,
179                                 NULL, 0, "Real Nick (nick1)" }},
180                         { &hf_yhoo_nick2, {     
181                                 "Active Nick (nick2)", "yhoo.nick2", FT_STRING, 0,
182                                 NULL, 0, "Active Nick (nick2)" }},
183                         { &hf_yhoo_content, {   
184                                 "Content", "yhoo.content", FT_STRING, 0,
185                                 NULL, 0, "Data portion of the packet" }},
186                         { &hf_yhoo_version, {   
187                                 "Version", "yhoo.version", FT_STRING, 0,
188                                 NULL, 0, "Packet version identifier" }},
189         };
190         static gint *ett[] = {
191                 &ett_yhoo,
192         };
193
194         proto_yhoo = proto_register_protocol("Yahoo Messenger Protocol", "yhoo");
195
196         proto_register_field_array(proto_yhoo, hf, array_length(hf));
197
198         proto_register_subtree_array(ett, array_length(ett));
199 }