Fix some aclocal warnings during autogen.sh
[obnox/wireshark/wip.git] / 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: packet-aim-ssi.c,v 1.1 2004/03/23 06:21:17 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
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 /* Family Server-Stored Buddy Lists */
46 #define FAMILY_SSI_ERROR              0x0001
47 #define FAMILY_SSI_REQRIGHTS          0x0002
48 #define FAMILY_SSI_RIGHTSINFO         0x0003
49 #define FAMILY_SSI_REQLIST_FIRSTTIME  0x0004
50 #define FAMILY_SSI_REQLIST            0x0005
51 #define FAMILY_SSI_LIST               0x0006
52 #define FAMILY_SSI_ACTIVATE           0x0007
53 #define FAMILY_SSI_ADD                0x0008
54 #define FAMILY_SSI_MOD                0x0009
55 #define FAMILY_SSI_DEL                0x000a
56 #define FAMILY_SSI_SRVACK             0x000e
57 #define FAMILY_SSI_NOLIST             0x000f
58 #define FAMILY_SSI_EDITSTART          0x0011
59 #define FAMILY_SSI_EDITSTOP           0x0012
60 #define FAMILY_SSI_GRANT_FUTURE_AUTH  0x0014
61 #define FAMILY_SSI_FUTUR_AUTH_GRANTED 0x0015
62 #define FAMILY_SSI_SEND_AUTH_REQ      0x0018
63 #define FAMILY_SSI_AUTH_REQ           0x0019
64 #define FAMILY_SSI_SEND_AUTH_REPLY    0x001a
65 #define FAMILY_SSI_AUTH_REPLY         0x001b
66 #define FAMILY_SSI_WAS_ADDED          0x001c
67
68 static const value_string aim_fnac_family_ssi[] = {
69   { FAMILY_SSI_ERROR, "Error" },
70   { FAMILY_SSI_REQRIGHTS, "Request Rights" },
71   { FAMILY_SSI_RIGHTSINFO, "Rights Info" },
72   { FAMILY_SSI_REQLIST_FIRSTTIME, "Request List (first time)" },
73   { FAMILY_SSI_REQLIST, "Request List" },
74   { FAMILY_SSI_LIST, "List" },
75   { FAMILY_SSI_ACTIVATE, "Activate" },
76   { FAMILY_SSI_ADD, "Add Buddy" },
77   { FAMILY_SSI_MOD, "Modify Buddy" },
78   { FAMILY_SSI_DEL, "Delete Buddy" },
79   { FAMILY_SSI_SRVACK, "Server Ack" },
80   { FAMILY_SSI_NOLIST, "No List" },
81   { FAMILY_SSI_EDITSTART, "Edit Start" },
82   { FAMILY_SSI_EDITSTOP, "Edit Stop" },
83   { FAMILY_SSI_GRANT_FUTURE_AUTH, "Grant Future Authorization to Client" },
84   { FAMILY_SSI_FUTUR_AUTH_GRANTED, "Future Authorization Granted" },
85   { FAMILY_SSI_SEND_AUTH_REQ, "Send Authentication Request" },
86   { FAMILY_SSI_AUTH_REQ, "Authentication Request" },
87   { FAMILY_SSI_SEND_AUTH_REPLY, "Send Authentication Reply" },
88   { FAMILY_SSI_AUTH_REPLY, "Authentication Reply" },
89   { FAMILY_SSI_WAS_ADDED, "Remote User Added Client To List" },
90   { 0, NULL }
91 };
92
93 #define FAMILY_SSI_TYPE_BUDDY         0x0000
94 #define FAMILY_SSI_TYPE_GROUP         0x0001
95 #define FAMILY_SSI_TYPE_PERMIT        0x0002
96 #define FAMILY_SSI_TYPE_DENY          0x0003
97 #define FAMILY_SSI_TYPE_PDINFO        0x0004
98 #define FAMILY_SSI_TYPE_PRESENCEPREFS 0x0005
99 #define FAMILY_SSI_TYPE_ICONINFO      0x0014
100
101 static const value_string aim_fnac_family_ssi_types[] = {
102   { FAMILY_SSI_TYPE_BUDDY, "Buddy" },
103   { FAMILY_SSI_TYPE_GROUP, "Group" },
104   { FAMILY_SSI_TYPE_PERMIT, "Permit" },
105   { FAMILY_SSI_TYPE_DENY, "Deny" },
106   { FAMILY_SSI_TYPE_PDINFO, "PDINFO" },
107   { FAMILY_SSI_TYPE_PRESENCEPREFS, "Presence Preferences" },
108   { FAMILY_SSI_TYPE_ICONINFO, "Icon Info" },
109   { 0, NULL }
110 };
111
112 static int dissect_aim_snac_ssi_list(tvbuff_t *tvb, packet_info *pinfo _U_, 
113                                       int offset, proto_tree *tree, guint16 subtype _U_);
114
115 /* Initialize the protocol and registered fields */
116 static int proto_aim_ssi = -1;
117 static int hf_aim_fnac_subtype_ssi_version = -1;
118 static int hf_aim_fnac_subtype_ssi_numitems = -1;
119 static int hf_aim_fnac_subtype_ssi_buddyname_len = -1;
120 static int hf_aim_fnac_subtype_ssi_buddyname = -1;
121 static int hf_aim_fnac_subtype_ssi_gid = -1;
122 static int hf_aim_fnac_subtype_ssi_bid = -1;
123 static int hf_aim_fnac_subtype_ssi_type = -1;
124 static int hf_aim_fnac_subtype_ssi_tlvlen = -1;
125 static int hf_aim_fnac_subtype_ssi_data = -1;
126
127 /* Initialize the subtree pointers */
128 static gint ett_aim_ssi      = -1;
129 static gint ett_ssi      = -1;
130
131 static int dissect_aim_snac_ssi(tvbuff_t *tvb, packet_info *pinfo _U_, 
132                                  proto_tree *tree)
133 {
134         struct aiminfo *aiminfo = pinfo->private_data;
135         int offset = 0;
136     proto_item *ti = NULL;
137     proto_tree *ssi_tree = NULL;
138                                                                                 
139     if(tree) {
140                 ti = proto_tree_add_text(tree, tvb, 0, -1,"AIM Service Side Information Service");
141         ssi_tree = proto_item_add_subtree(ti, ett_ssi);
142     }
143
144   switch(aiminfo->subtype)
145     {    
146         case FAMILY_SSI_ERROR:
147       return dissect_aim_snac_error(tvb, pinfo, offset, ssi_tree);
148     case FAMILY_SSI_LIST:
149           return dissect_aim_snac_ssi_list(tvb, pinfo, offset, ssi_tree, aiminfo->subtype);
150           /* FIXME */
151     default:
152           return 0;
153     }
154 }
155
156 static int dissect_aim_snac_ssi_list(tvbuff_t *tvb, packet_info *pinfo _U_, 
157                                       int offset, proto_tree *tree, 
158                                       guint16 subtype _U_)
159 {
160   guint16 buddyname_length = 0;
161   guint16 tlv_len = 0;
162   int endoffset;
163   proto_item *ti;
164   proto_tree *ssi_entry = NULL;
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   offset += 2;
175   
176   while (tvb_length_remaining(tvb, offset) > 4) {
177         
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     
181     /* Buddy Name Length */
182     buddyname_length = tvb_get_ntohs(tvb, offset);
183     proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_buddyname_len, 
184                         tvb, offset, 2, FALSE);
185     offset += 2;
186     
187     /* Buddy Name */
188     if (buddyname_length > 0) {
189       proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_buddyname, tvb, 
190                           offset, buddyname_length, FALSE);
191       offset += buddyname_length;
192     }
193     
194     /* Buddy group ID */
195     proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_gid, tvb, offset, 
196                         2, FALSE);
197     offset += 2;
198     
199     /* Buddy ID */
200     proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_bid, tvb, offset, 
201                         2, FALSE);
202     offset += 2;
203     
204     /* Buddy Type */
205     proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_type, tvb, offset,
206                         2, FALSE);
207     offset += 2;
208     
209     /* Size of the following TLV in bytes (as opposed to the number of 
210        TLV objects in the chain) */
211     tlv_len = tvb_get_ntohs(tvb, offset);
212     proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_tlvlen, tvb, 
213                         offset, 2, FALSE);
214     offset += 2;
215     
216         endoffset = offset;
217     /* For now, we just dump the TLV contents as-is, since there is not a
218        TLV dissection utility that works based on total chain length */
219         while(endoffset < offset+tlv_len) {
220         endoffset = dissect_aim_tlv(tvb, pinfo, endoffset, ssi_entry);
221     }
222         offset = endoffset;
223   }
224   return offset;
225 }
226
227 /* Register the protocol with Ethereal */
228 void
229 proto_register_aim_ssi(void)
230 {
231
232 /* Setup list of header fields */
233   static hf_register_info hf[] = {
234     { &hf_aim_fnac_subtype_ssi_version,
235       { "SSI Version", "aim.fnac.ssi.version", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }
236     },
237     { &hf_aim_fnac_subtype_ssi_numitems,
238       { "SSI Object count", "aim.fnac.ssi.numitems", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
239     },
240     { &hf_aim_fnac_subtype_ssi_buddyname_len,
241       { "SSI Buddy Name length", "aim.fnac.ssi.buddyname_len", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
242     },
243     { &hf_aim_fnac_subtype_ssi_buddyname,
244       { "Buddy Name", "aim.fnac.ssi.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
245     },
246     { &hf_aim_fnac_subtype_ssi_gid,
247       { "SSI Buddy Group ID", "aim.fnac.ssi.gid", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
248     },
249     { &hf_aim_fnac_subtype_ssi_bid,
250       { "SSI Buddy ID", "aim.fnac.ssi.bid", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
251     },
252     { &hf_aim_fnac_subtype_ssi_type,
253       { "SSI Buddy type", "aim.fnac.ssi.type", FT_UINT16, BASE_HEX, VALS(aim_fnac_family_ssi_types), 0x0, "", HFILL }
254     },
255     { &hf_aim_fnac_subtype_ssi_tlvlen,
256       { "SSI TLV Len", "aim.fnac.ssi.tlvlen", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
257     },
258     { &hf_aim_fnac_subtype_ssi_data,
259       { "SSI Buddy Data", "aim.fnac.ssi.data", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
260     },
261   };
262
263 /* Setup protocol subtree array */
264   static gint *ett[] = {
265     &ett_aim_ssi,
266         &ett_ssi,
267   };
268
269 /* Register the protocol name and description */
270   proto_aim_ssi = proto_register_protocol("AIM Server Side Info", "AIM SSI", "aim_ssi");
271
272 /* Required function calls to register the header fields and subtrees used */
273   proto_register_field_array(proto_aim_ssi, hf, array_length(hf));
274   proto_register_subtree_array(ett, array_length(ett));
275 }
276
277 void
278 proto_reg_handoff_aim_ssi(void)
279 {
280   dissector_handle_t aim_handle;
281
282   aim_handle = new_create_dissector_handle(dissect_aim_snac_ssi, proto_aim_ssi);
283   dissector_add("aim.family", FAMILY_SSI, aim_handle);
284   aim_init_family(FAMILY_SSI, "SSI", aim_fnac_family_ssi);
285 }