Fix some aclocal warnings during autogen.sh
[obnox/wireshark/wip.git] / packet-aim-location.c
1 /* packet-aim-location.c
2  * Routines for AIM Instant Messenger (OSCAR) dissection, SNAC Location
3  * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
4  * Copyright 2000, Ralf Hoelzer <ralf@well.com>
5  *
6  * $Id: packet-aim-location.c,v 1.1 2004/03/23 06:21:16 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 /* SNAC families */
44 #define FAMILY_LOCATION   0x0002
45
46 /* Family Location Services */
47 #define FAMILY_LOCATION_ERROR         0x0001
48 #define FAMILY_LOCATION_REQRIGHTS     0x0002
49 #define FAMILY_LOCATION_RIGHTSINFO    0x0003
50 #define FAMILY_LOCATION_SETUSERINFO   0x0004
51 #define FAMILY_LOCATION_REQUSERINFO   0x0005
52 #define FAMILY_LOCATION_USERINFO      0x0006
53 #define FAMILY_LOCATION_WATCHERSUBREQ 0x0007
54 #define FAMILY_LOCATION_WATCHERNOT    0x0008
55 #define FAMILY_LOCATION_DEFAULT       0xffff
56
57 static const value_string aim_fnac_family_location[] = {
58   { FAMILY_LOCATION_ERROR, "Error" },
59   { FAMILY_LOCATION_REQRIGHTS, "Request Rights" },
60   { FAMILY_LOCATION_RIGHTSINFO, "Rights Info" },
61   { FAMILY_LOCATION_SETUSERINFO, "Set User Info" },
62   { FAMILY_LOCATION_REQUSERINFO, "Request User Info" },
63   { FAMILY_LOCATION_USERINFO, "User Info" },
64   { FAMILY_LOCATION_WATCHERSUBREQ, "Watcher Subrequest" },
65   { FAMILY_LOCATION_WATCHERNOT, "Watcher Notification" },
66   { FAMILY_LOCATION_DEFAULT, "Location Default" },
67   { 0, NULL }
68 };
69
70 #define FAMILY_LOCATION_USERINFO_INFOENCODING  0x0001
71 #define FAMILY_LOCATION_USERINFO_INFOMSG       0x0002
72 #define FAMILY_LOCATION_USERINFO_AWAYENCODING  0x0003
73 #define FAMILY_LOCATION_USERINFO_AWAYMSG       0x0004
74 #define FAMILY_LOCATION_USERINFO_CAPS          0x0005
75                                                                                                                               
76 static const aim_tlv aim_fnac_family_location_userinfo_tlv[] = {
77   { FAMILY_LOCATION_USERINFO_INFOENCODING, "Info Msg Encoding", FT_STRING },
78   { FAMILY_LOCATION_USERINFO_INFOMSG, "Info Message", FT_STRING },
79   { FAMILY_LOCATION_USERINFO_AWAYENCODING, "Away Msg Encoding", FT_STRING },
80   { FAMILY_LOCATION_USERINFO_AWAYMSG, "Away Message", FT_STRING },
81   { FAMILY_LOCATION_USERINFO_CAPS, "Capabilities", FT_BYTES },
82   { 0, "Unknown", 0 }
83 };
84
85
86 static int dissect_aim_snac_location_request_user_information(tvbuff_t *tvb, int offset, proto_tree *tree);
87 static int dissect_aim_snac_location_user_information(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree);
88
89 /* Initialize the protocol and registered fields */
90 static int proto_aim_location = -1;
91 static int hf_aim_snac_location_request_user_info_infotype = -1;
92 static int hf_aim_userinfo_warninglevel = -1;
93 static int hf_aim_userinfo_tlvcount = -1;
94 static int hf_aim_buddyname_len = -1;
95 static int hf_aim_buddyname = -1;
96
97 /* Initialize the subtree pointers */
98 static gint ett_aim_location    = -1;
99
100 static int dissect_aim_location(tvbuff_t *tvb, packet_info *pinfo, 
101                                       proto_tree *tree )
102 {
103         struct aiminfo *aiminfo = pinfo->private_data;
104         int offset = 0;
105          proto_item *ti = NULL;
106     proto_tree *loc_tree = NULL;
107
108     if(tree) {
109         ti = proto_tree_add_text(tree, tvb, 0, -1,"AIM Location Service");
110         loc_tree = proto_item_add_subtree(ti, ett_aim_location);
111     }
112
113   switch(aiminfo->subtype)
114     {
115         case FAMILY_LOCATION_ERROR:
116       return dissect_aim_snac_error(tvb, pinfo, offset, loc_tree);
117     case FAMILY_LOCATION_REQUSERINFO:
118       return dissect_aim_snac_location_request_user_information(tvb, offset, loc_tree);
119     case FAMILY_LOCATION_USERINFO:
120       return dissect_aim_snac_location_user_information(tvb, pinfo, offset, loc_tree);
121         case FAMILY_LOCATION_REQRIGHTS:
122         case FAMILY_LOCATION_RIGHTSINFO:
123         case FAMILY_LOCATION_SETUSERINFO:
124         case FAMILY_LOCATION_WATCHERSUBREQ:
125         case FAMILY_LOCATION_WATCHERNOT:
126           /* FIXME */
127         default:
128           return 0;
129     }
130 }
131
132 static int dissect_aim_snac_location_request_user_information(tvbuff_t *tvb, 
133                                                           int offset,
134                                                           proto_tree *tree)
135 {
136   guint8 buddyname_length = 0;
137
138   /* Info Type */
139   proto_tree_add_item(tree, hf_aim_snac_location_request_user_info_infotype, 
140                       tvb, offset, 2, FALSE);
141   offset += 2;
142
143   /* Buddy Name length */
144   buddyname_length = tvb_get_guint8(tvb, offset);
145   proto_tree_add_item(tree, hf_aim_buddyname_len, tvb, offset, 1, FALSE);
146   offset += 1;
147   
148   /* Buddy name */
149   proto_tree_add_item(tree, hf_aim_buddyname, tvb, offset, buddyname_length, FALSE);
150   offset += buddyname_length;
151   return offset;
152 }
153
154 static int dissect_aim_snac_location_user_information(tvbuff_t *tvb, 
155                                                        packet_info *pinfo _U_, 
156                                                   int offset, proto_tree *tree)
157 {
158   guint8 buddyname_length = 0;
159   guint16 tlv_count = 0;
160   guint16 i = 0;
161
162   /* Buddy Name length */
163   buddyname_length = tvb_get_guint8(tvb, offset);
164   proto_tree_add_item(tree, hf_aim_buddyname_len, tvb, offset, 1, FALSE);
165   offset += 1;
166   
167   /* Buddy name */
168   proto_tree_add_item(tree, hf_aim_buddyname, tvb, offset, buddyname_length, FALSE);
169   offset += buddyname_length;
170
171   /* Warning level */
172   proto_tree_add_item(tree, hf_aim_userinfo_warninglevel, tvb, offset, 2, FALSE);
173   offset += 2;
174
175   /* TLV Count */
176   tlv_count = tvb_get_ntohs(tvb, offset);
177   proto_tree_add_item(tree, hf_aim_userinfo_tlvcount, tvb, offset, 2, FALSE);
178   offset += 2;
179
180   /* Dissect the TLV array containing general user status  */
181   while (i++ < tlv_count) {
182     offset = dissect_aim_tlv_buddylist(tvb, pinfo, offset, tree);
183   }
184
185   /* Dissect the TLV array containing the away message (or whatever info was
186      specifically requested) */
187   while (tvb_length_remaining(tvb, offset) > 0) {
188     offset = dissect_aim_tlv_specific(tvb, pinfo, offset, tree, 
189                              aim_fnac_family_location_userinfo_tlv);
190   }
191   return offset;
192 }
193
194 void
195 proto_register_aim_location(void)
196 {
197
198 /* Setup list of header fields */
199   static hf_register_info hf[] = {
200     { &hf_aim_buddyname_len,
201       { "Buddyname len", "aim.buddynamelen", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }
202     },
203     { &hf_aim_buddyname,
204       { "Buddy Name", "aim.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
205     },
206     { &hf_aim_userinfo_warninglevel,
207       { "Warning Level", "aim.userinfo.warninglevel", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
208     },
209     { &hf_aim_userinfo_tlvcount,
210       { "TLV Count", "aim.userinfo.tlvcount", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
211     },
212   };
213
214 /* Setup protocol subtree array */
215   static gint *ett[] = {
216     &ett_aim_location,
217   };
218
219 /* Register the protocol name and description */
220   proto_aim_location = proto_register_protocol("AIM Location", "AIM Location", "aim_location");
221
222 /* Required function calls to register the header fields and subtrees used */
223   proto_register_field_array(proto_aim_location, hf, array_length(hf));
224   proto_register_subtree_array(ett, array_length(ett));
225 }
226
227 void
228 proto_reg_handoff_aim_location(void)
229 {
230   dissector_handle_t aim_handle;
231   aim_handle = new_create_dissector_handle(dissect_aim_location, proto_aim_location);
232   dissector_add("aim.family", FAMILY_LOCATION, aim_handle);
233   aim_init_family(FAMILY_LOCATION, "Location", aim_fnac_family_location);
234 }