Remove all $Id$ from top of file
[metze/wireshark/wip.git] / epan / dissectors / 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  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <glib.h>
28
29 #include <epan/packet.h>
30
31 #include "packet-aim.h"
32
33 void proto_register_aim_location(void);
34 void proto_reg_handoff_aim_location(void);
35
36 /* SNAC families */
37 #define FAMILY_LOCATION   0x0002
38
39 #define AIM_LOCATION_RIGHTS_TLV_MAX_PROFILE_LENGTH      0x0001
40 #define AIM_LOCATION_RIGHTS_TLV_MAX_CAPABILITIES        0x0002
41
42 static const aim_tlv aim_location_rights_tlvs[] = {
43         { AIM_LOCATION_RIGHTS_TLV_MAX_PROFILE_LENGTH, "Max Profile Length", dissect_aim_tlv_value_uint16 },
44         { AIM_LOCATION_RIGHTS_TLV_MAX_CAPABILITIES, "Max capabilities", dissect_aim_tlv_value_uint16 },
45         { 0, NULL, NULL }
46 };
47
48 #define AIM_LOCATE_TAG_TLV_SIG_TYPE                     0x0001
49 #define AIM_LOCATE_TAG_TLV_SIG_DATA                     0x0002
50 #define AIM_LOCATE_TAG_TLV_UNAVAILABLE_TYPE             0x0003
51 #define AIM_LOCATE_TAG_TLV_UNAVAILABLE_DATA             0x0004
52 #define AIM_LOCATE_TAG_TLV_CAPABILITIES                 0x0005
53 #define AIM_LOCATE_TAG_TLV_SIG_TIME                     0x000A
54 #define AIM_LOCATE_TAG_TLV_UNAVAILABLE_TIME             0x000B
55 #define AIM_LOCATE_TAG_TLV_SUPPORT_HOST_SIG             0x000C
56 #define AIM_LOCATE_TAG_TLV_HTML_INFO_TYPE               0x000D
57 #define AIM_LOCATE_TAG_TLV_HTML_INFO_DATA               0x000E
58
59 static const aim_tlv aim_locate_tags_tlvs[] = {
60         { AIM_LOCATE_TAG_TLV_SIG_TYPE,         "Signature MIME Type"          , dissect_aim_tlv_value_string },
61         { AIM_LOCATE_TAG_TLV_SIG_DATA,         "Signature Data"               , dissect_aim_tlv_value_string },
62         { AIM_LOCATE_TAG_TLV_UNAVAILABLE_TYPE, "Away Message MIME Type"       , dissect_aim_tlv_value_string },
63         { AIM_LOCATE_TAG_TLV_UNAVAILABLE_DATA, "Away Message Data"            , dissect_aim_tlv_value_string },
64         { AIM_LOCATE_TAG_TLV_CAPABILITIES,     "Client Capabilities"          , dissect_aim_tlv_value_client_capabilities },
65         { AIM_LOCATE_TAG_TLV_SIG_TIME,         "Signature Time"               , dissect_aim_tlv_value_time },
66         { AIM_LOCATE_TAG_TLV_UNAVAILABLE_TIME, "Away Message Time"            , dissect_aim_tlv_value_time },
67         { AIM_LOCATE_TAG_TLV_SUPPORT_HOST_SIG, "Enable Server Based Profiles" , dissect_aim_tlv_value_uint8 },
68         { AIM_LOCATE_TAG_TLV_HTML_INFO_TYPE,   "Host Based Buddy MIME Type"   , dissect_aim_tlv_value_string },
69         { AIM_LOCATE_TAG_TLV_HTML_INFO_DATA,   "Host Bases Buddy Data"        , dissect_aim_tlv_value_string },
70         { 0, NULL, NULL }
71 };
72
73 #define FAMILY_LOCATION_USERINFO_INFOTYPE_GENERALINFO  0x0001
74 #define FAMILY_LOCATION_USERINFO_INFOTYPE_AWAYMSG      0x0003
75 #define FAMILY_LOCATION_USERINFO_INFOTYPE_CAPS         0x0005
76
77 static const value_string aim_snac_location_request_user_info_infotypes[] = {
78         { FAMILY_LOCATION_USERINFO_INFOTYPE_GENERALINFO, "Request General Info" },
79         { FAMILY_LOCATION_USERINFO_INFOTYPE_AWAYMSG,     "Request Away Message" },
80         { FAMILY_LOCATION_USERINFO_INFOTYPE_CAPS,        "Request Capabilities" },
81         { 0, NULL }
82 };
83
84 /* Initialize the protocol and registered fields */
85 static int proto_aim_location = -1;
86 static int hf_aim_snac_location_request_user_info_infotype = -1;
87 static int hf_aim_userinfo_warninglevel = -1;
88 static int hf_aim_buddyname_len = -1;
89 static int hf_aim_buddyname = -1;
90
91 /* Initialize the subtree pointers */
92 static gint ett_aim_location    = -1;
93
94 static int dissect_aim_location_rightsinfo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *loc_tree)
95 {
96         return dissect_aim_tlv_sequence(tvb, pinfo, 0, loc_tree, aim_location_rights_tlvs);
97 }
98
99 static int dissect_aim_location_setuserinfo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *loc_tree)
100 {
101         return dissect_aim_tlv_sequence(tvb, pinfo, 0, loc_tree, aim_locate_tags_tlvs);
102 }
103
104 static int dissect_aim_location_watcher_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *loc_tree)
105 {
106         int offset = 0;
107         while (tvb_length_remaining(tvb, offset) > 0) {
108                 offset = dissect_aim_buddyname(tvb, pinfo, offset, loc_tree);
109         }
110         return offset;
111 }
112
113 static int dissect_aim_location_user_info_query(tvbuff_t *tvb, packet_info *pinfo, proto_tree *loc_tree)
114 {
115         return dissect_aim_buddyname(tvb, pinfo, 4, loc_tree);
116 }
117
118 static int dissect_aim_snac_location_request_user_information(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
119 {
120         int    offset           = 0;
121         guint8 buddyname_length = 0;
122
123         /* Info Type */
124         proto_tree_add_item(tree, hf_aim_snac_location_request_user_info_infotype,
125                                                 tvb, offset, 2, ENC_BIG_ENDIAN);
126         offset += 2;
127
128         /* Buddy Name length */
129         buddyname_length = tvb_get_guint8(tvb, offset);
130         proto_tree_add_item(tree, hf_aim_buddyname_len, tvb, offset, 1, ENC_BIG_ENDIAN);
131         offset += 1;
132
133         /* Buddy name */
134         proto_tree_add_item(tree, hf_aim_buddyname, tvb, offset, buddyname_length, ENC_UTF_8|ENC_NA);
135         offset += buddyname_length;
136
137         return offset;
138 }
139
140 static int dissect_aim_snac_location_user_information(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
141 {
142         int    offset           = 0;
143         guint8 buddyname_length = 0;
144
145         /* Buddy Name length */
146         buddyname_length = tvb_get_guint8(tvb, offset);
147         proto_tree_add_item(tree, hf_aim_buddyname_len, tvb, offset, 1, ENC_BIG_ENDIAN);
148         offset += 1;
149
150         /* Buddy name */
151         proto_tree_add_item(tree, hf_aim_buddyname, tvb, offset, buddyname_length, ENC_UTF_8|ENC_NA);
152         offset += buddyname_length;
153
154         /* Warning level */
155         proto_tree_add_item(tree, hf_aim_userinfo_warninglevel, tvb, offset, 2, ENC_BIG_ENDIAN);
156         offset += 2;
157
158         offset = dissect_aim_tlv_list(tvb, pinfo, offset, tree, aim_onlinebuddy_tlvs);
159
160         return dissect_aim_tlv_sequence(tvb, pinfo, offset, tree, aim_locate_tags_tlvs);
161 }
162
163 static const aim_subtype aim_fnac_family_location[] = {
164         { 0x0001, "Error"                , dissect_aim_snac_error },
165         { 0x0002, "Request Rights"       , NULL },
166         { 0x0003, "Rights Info"          , dissect_aim_location_rightsinfo },
167         { 0x0004, "Set User Info"        , dissect_aim_location_setuserinfo },
168         { 0x0005, "Request User Info"    , dissect_aim_snac_location_request_user_information },
169         { 0x0006, "User Info"            , dissect_aim_snac_location_user_information },
170         { 0x0007, "Watcher Subrequest"   , NULL },
171         { 0x0008, "Watcher Notification" , dissect_aim_location_watcher_notification },
172         { 0x0015, "User Info Query"      , dissect_aim_location_user_info_query },
173         { 0, NULL, NULL }
174 };
175
176
177
178 void
179 proto_register_aim_location(void)
180 {
181
182         /* Setup list of header fields */
183         static hf_register_info hf[] = {
184                 { &hf_aim_buddyname_len,
185                   { "Buddyname len", "aim_location.buddynamelen", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
186                 },
187                 { &hf_aim_buddyname,
188                   { "Buddy Name", "aim_location.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
189                 },
190                 { &hf_aim_userinfo_warninglevel,
191                   { "Warning Level", "aim_location.userinfo.warninglevel", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
192                 },
193                 { &hf_aim_snac_location_request_user_info_infotype,
194                   { "Infotype", "aim_location.snac.request_user_info.infotype", FT_UINT16, BASE_HEX, VALS(aim_snac_location_request_user_info_infotypes), 0x0,
195                                 NULL, HFILL }
196                 },
197         };
198
199         /* Setup protocol subtree array */
200         static gint *ett[] = {
201                 &ett_aim_location,
202         };
203
204         /* Register the protocol name and description */
205         proto_aim_location = proto_register_protocol("AIM Location", "AIM Location", "aim_location");
206
207         /* Required function calls to register the header fields and subtrees used */
208         proto_register_field_array(proto_aim_location, hf, array_length(hf));
209         proto_register_subtree_array(ett, array_length(ett));
210 }
211
212 void
213 proto_reg_handoff_aim_location(void)
214 {
215         aim_init_family(proto_aim_location, ett_aim_location, FAMILY_LOCATION, aim_fnac_family_location);
216 }