change the signature that asn2wrs generates for functions to marm all parameters...
[obnox/wireshark/wip.git] / epan / dissectors / packet-aim-ssi.c
1 /* packet-aim-ssi.c
2  * Routines for AIM Instant Messenger (OSCAR) dissection, SNAC SSI
3  * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
4  * Copyright 2000, Ralf Hoelzer <ralf@well.com>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <ctype.h>
35
36 #include <glib.h>
37
38 #include <epan/packet.h>
39 #include <epan/strutil.h>
40
41 #include "packet-aim.h"
42
43 #define FAMILY_SSI        0x0013
44
45
46 #define FAMILY_SSI_TYPE_BUDDY         0x0000
47 #define FAMILY_SSI_TYPE_GROUP         0x0001
48 #define FAMILY_SSI_TYPE_PERMIT        0x0002
49 #define FAMILY_SSI_TYPE_DENY          0x0003
50 #define FAMILY_SSI_TYPE_PDINFO        0x0004
51 #define FAMILY_SSI_TYPE_PRESENCEPREFS 0x0005
52 #define FAMILY_SSI_TYPE_ICONINFO      0x0014
53
54 static const value_string aim_fnac_family_ssi_types[] = {
55   { FAMILY_SSI_TYPE_BUDDY, "Buddy" },
56   { FAMILY_SSI_TYPE_GROUP, "Group" },
57   { FAMILY_SSI_TYPE_PERMIT, "Permit" },
58   { FAMILY_SSI_TYPE_DENY, "Deny" },
59   { FAMILY_SSI_TYPE_PDINFO, "PDINFO" },
60   { FAMILY_SSI_TYPE_PRESENCEPREFS, "Presence Preferences" },
61   { FAMILY_SSI_TYPE_ICONINFO, "Icon Info" },
62   { 0, NULL }
63 };
64
65 #define SSI_RIGHTSINFO_TLV_MAX_ITEMS    0x0004
66
67 static const aim_tlv ssi_rightsinfo_tlvs[] = {
68         { SSI_RIGHTSINFO_TLV_MAX_ITEMS, "Maximums For Items", dissect_aim_tlv_value_bytes }, 
69         { 0, NULL, NULL },
70 };
71
72 /* Initialize the protocol and registered fields */
73 static int proto_aim_ssi = -1;
74 static int hf_aim_fnac_subtype_ssi_version = -1;
75 static int hf_aim_fnac_subtype_ssi_numitems = -1;
76 static int hf_aim_fnac_subtype_ssi_last_change_time = -1;
77 static int hf_aim_fnac_subtype_ssi_buddyname_len = -1;
78 static int hf_aim_fnac_subtype_ssi_buddyname = -1;
79 static int hf_aim_fnac_subtype_ssi_gid = -1;
80 static int hf_aim_fnac_subtype_ssi_bid = -1;
81 static int hf_aim_fnac_subtype_ssi_type = -1;
82 static int hf_aim_fnac_subtype_ssi_tlvlen = -1;
83 static int hf_aim_fnac_subtype_ssi_data = -1;
84
85 /* Initialize the subtree pointers */
86 static gint ett_aim_ssi      = -1;
87 static gint ett_ssi      = -1;
88
89 static int dissect_ssi_item(tvbuff_t *tvb, packet_info *pinfo _U_, 
90                                       int offset, proto_tree *ssi_entry)
91 {
92         guint16 buddyname_length = 0;
93         int endoffset;
94         guint16 tlv_len = 0;
95
96         /* Buddy Name Length */
97         buddyname_length = tvb_get_ntohs(tvb, offset);
98         proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_buddyname_len, 
99                                                 tvb, offset, 2, FALSE);
100         offset += 2;
101
102         /* Buddy Name */
103         if (buddyname_length > 0) {
104                 proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_buddyname, tvb, 
105                                                         offset, buddyname_length, FALSE);
106                 offset += buddyname_length;
107         }
108
109         /* Buddy group ID */
110         proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_gid, tvb, offset, 
111                                                 2, FALSE);
112         offset += 2;
113
114         /* Buddy ID */
115         proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_bid, tvb, offset, 
116                                                 2, FALSE);
117         offset += 2;
118
119         /* Buddy Type */
120         proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_type, tvb, offset,
121                                                 2, FALSE);
122         offset += 2;
123
124         /* Size of the following TLV in bytes (as opposed to the number of 
125            TLV objects in the chain) */
126         tlv_len = tvb_get_ntohs(tvb, offset);
127         proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_tlvlen, tvb, 
128                                                 offset, 2, FALSE);
129         offset += 2;
130
131         endoffset = offset;
132         /* For now, we just dump the TLV contents as-is, since there is not a
133            TLV dissection utility that works based on total chain length */
134         while(endoffset < offset+tlv_len) {
135                 endoffset = dissect_aim_tlv(tvb, pinfo, endoffset, ssi_entry, client_tlvs);
136         }
137         return endoffset;
138 }
139
140 static int dissect_ssi_ssi_item(tvbuff_t *tvb, packet_info *pinfo, 
141                                       proto_tree *ssi_entry)
142 {
143         return dissect_ssi_item(tvb, pinfo, 0, ssi_entry);
144 }
145
146
147 static int dissect_aim_ssi_rightsinfo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ssi_tree)
148 {
149         return dissect_aim_tlv_sequence(tvb, pinfo, 0, ssi_tree, ssi_rightsinfo_tlvs);
150 }
151
152 static int dissect_aim_ssi_was_added(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ssi_tree)
153 {
154         return dissect_aim_buddyname(tvb, pinfo, 0, ssi_tree);
155 }
156
157 static int dissect_aim_snac_ssi_list(tvbuff_t *tvb, packet_info *pinfo _U_, 
158                                                                          proto_tree *tree)
159
160 {
161         int offset = 0;
162         proto_item *ti;
163         proto_tree *ssi_entry = NULL;
164         guint16 num_items, i;
165
166         /* SSI Version */
167         proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_version, tvb, offset, 1,
168                                                 FALSE);
169         offset += 1;
170
171         /* Number of items */
172         proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_numitems, tvb, offset, 2,
173                                                 FALSE);
174         num_items = tvb_get_ntohs(tvb, offset);
175         offset += 2;
176
177         for(i = 0; i < num_items; i++) {
178                 ti = proto_tree_add_text(tree, tvb, offset, tvb_get_ntohs(tvb, offset+10)+10, "SSI Entry");
179                 ssi_entry = proto_item_add_subtree(ti, ett_aim_ssi);
180                 offset = dissect_ssi_item(tvb, pinfo, offset, ssi_entry);
181         }
182         proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_last_change_time, tvb, offset, 4, FALSE);
183         return offset;
184 }
185
186 static const aim_subtype aim_fnac_family_ssi[] = {
187         { 0x0001, "Error", dissect_aim_snac_error },
188         { 0x0002, "Request Rights", NULL },
189         { 0x0003, "Rights Info", dissect_aim_ssi_rightsinfo },
190         { 0x0004, "Request List (first time)", NULL },
191         { 0x0005, "Request List", NULL },
192         { 0x0006, "List", dissect_aim_snac_ssi_list },
193         { 0x0007, "Activate", NULL },
194         { 0x0008, "Add Buddy", dissect_ssi_ssi_item },
195         { 0x0009, "Modify Buddy", dissect_ssi_ssi_item },
196         { 0x000a, "Delete Buddy", dissect_ssi_ssi_item },
197         { 0x000e, "Server Ack", NULL },
198         { 0x000f, "No List", NULL },
199         { 0x0011, "Edit Start", NULL },
200         { 0x0012, "Edit Stop", NULL },
201         { 0x0014, "Grant Future Authorization to Buddy", NULL },
202         { 0x0015, "Future Authorization Granted", NULL },
203         { 0x0018, "Send Authentication Request", NULL },
204         { 0x0019, "Authentication Request", NULL },
205         { 0x001a, "Send Authentication Reply", NULL },
206         { 0x001b, "Authentication Reply", NULL },
207         { 0x001c, "Remote User Added Client To List", dissect_aim_ssi_was_added },
208         { 0, NULL, NULL }
209 };
210
211
212 /* Register the protocol with Wireshark */
213 void
214 proto_register_aim_ssi(void)
215 {
216
217         /* Setup list of header fields */
218         static hf_register_info hf[] = {
219                 { &hf_aim_fnac_subtype_ssi_version,
220                         { "SSI Version", "aim.fnac.ssi.version", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }
221                 },
222                 { &hf_aim_fnac_subtype_ssi_numitems,
223                         { "SSI Object count", "aim.fnac.ssi.numitems", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
224                 },
225                 { &hf_aim_fnac_subtype_ssi_last_change_time,
226                         { "SSI Last Change Time", "aim.fnac.ssi.last_change_time", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }
227                 },
228                 { &hf_aim_fnac_subtype_ssi_buddyname_len,
229                         { "SSI Buddy Name length", "aim.fnac.ssi.buddyname_len", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
230                 },
231                 { &hf_aim_fnac_subtype_ssi_buddyname,
232                         { "Buddy Name", "aim.fnac.ssi.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
233                 },
234                 { &hf_aim_fnac_subtype_ssi_gid,
235                         { "SSI Buddy Group ID", "aim.fnac.ssi.gid", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
236                 },
237                 { &hf_aim_fnac_subtype_ssi_bid,
238                         { "SSI Buddy ID", "aim.fnac.ssi.bid", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
239                 },
240                 { &hf_aim_fnac_subtype_ssi_type,
241                         { "SSI Buddy type", "aim.fnac.ssi.type", FT_UINT16, BASE_HEX, VALS(aim_fnac_family_ssi_types), 0x0, "", HFILL }
242                 },
243                 { &hf_aim_fnac_subtype_ssi_tlvlen,
244                         { "SSI TLV Len", "aim.fnac.ssi.tlvlen", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
245                 },
246                 { &hf_aim_fnac_subtype_ssi_data,
247                         { "SSI Buddy Data", "aim.fnac.ssi.data", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
248                 },
249         };
250
251         /* Setup protocol subtree array */
252         static gint *ett[] = {
253                 &ett_aim_ssi,
254                 &ett_ssi,
255         };
256
257         /* Register the protocol name and description */
258         proto_aim_ssi = proto_register_protocol("AIM Server Side Info", "AIM SSI", "aim_ssi");
259
260         /* Required function calls to register the header fields and subtrees used */
261         proto_register_field_array(proto_aim_ssi, hf, array_length(hf));
262         proto_register_subtree_array(ett, array_length(ett));
263 }
264
265 void
266 proto_reg_handoff_aim_ssi(void)
267 {
268         aim_init_family(proto_aim_ssi, ett_aim_ssi, FAMILY_SSI, aim_fnac_family_ssi);
269 }