1 /* packet-aim-buddylist.c
2 * Routines for AIM Instant Messenger (OSCAR) dissection, SNAC Buddylist
3 * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
5 * $Id: packet-aim-buddylist.c,v 1.4 2004/06/16 07:51:21 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include <epan/packet.h>
38 #include <epan/strutil.h>
40 #include "packet-aim.h"
43 #define FAMILY_BUDDYLIST 0x0003
45 /* Family Buddy List */
46 #define FAMILY_BUDDYLIST_ERROR 0x0001
47 #define FAMILY_BUDDYLIST_REQRIGHTS 0x0002
48 #define FAMILY_BUDDYLIST_RIGHTSINFO 0x0003
49 #define FAMILY_BUDDYLIST_ADDBUDDY 0x0004
50 #define FAMILY_BUDDYLIST_REMBUDDY 0x0005
51 #define FAMILY_BUDDYLIST_WATCHERS_REQ 0x0006
52 #define FAMILY_BUDDYLIST_WATCHERS_REP 0x0007
53 #define FAMILY_BUDDYLIST_REJECT 0x000a
54 #define FAMILY_BUDDYLIST_ONCOMING 0x000b
55 #define FAMILY_BUDDYLIST_OFFGOING 0x000c
56 #define FAMILY_BUDDYLIST_DEFAULT 0xffff
58 static const value_string aim_fnac_family_buddylist[] = {
59 { FAMILY_BUDDYLIST_ERROR, "Error" },
60 { FAMILY_BUDDYLIST_REQRIGHTS, "Request Rights" },
61 { FAMILY_BUDDYLIST_RIGHTSINFO, "Rights Info" },
62 { FAMILY_BUDDYLIST_ADDBUDDY, "Add Buddy" },
63 { FAMILY_BUDDYLIST_REMBUDDY, "Remove Buddy" },
64 { FAMILY_BUDDYLIST_REJECT, "Reject Buddy" },
65 { FAMILY_BUDDYLIST_ONCOMING, "Oncoming Buddy" },
66 { FAMILY_BUDDYLIST_OFFGOING, "Offgoing Buddy" },
67 { FAMILY_BUDDYLIST_DEFAULT, "Buddy Default" },
71 #define AIM_BUDDYLIST_TLV_MAX_CONTACT_ENTRIES 0x0001
72 #define AIM_BUDDYLIST_TLV_MAX_WATCHER_ENTRIES 0x0002
73 #define AIM_BUDDYLIST_TLV_MAX_ONLINE_NOTIFICATIONS 0x0003
75 const aim_tlv buddylist_tlvs[] = {
76 { AIM_BUDDYLIST_TLV_MAX_CONTACT_ENTRIES, "Max number of contact list entries", dissect_aim_tlv_value_uint16 },
77 { AIM_BUDDYLIST_TLV_MAX_WATCHER_ENTRIES, "Max number of watcher list entries", dissect_aim_tlv_value_uint16 },
78 { AIM_BUDDYLIST_TLV_MAX_ONLINE_NOTIFICATIONS, "Max online notifications", dissect_aim_tlv_value_uint16 },
83 /* Initialize the protocol and registered fields */
84 static int proto_aim_buddylist = -1;
85 static int hf_aim_buddyname_len = -1;
86 static int hf_aim_buddyname = -1;
87 static int hf_aim_userinfo_warninglevel = -1;
88 static int hf_aim_userinfo_tlvcount = -1;
90 /* Initialize the subtree pointers */
91 static gint ett_aim_buddylist = -1;
93 static int dissect_aim_snac_buddylist(tvbuff_t *tvb, packet_info *pinfo,
96 guint8 buddyname_length = 0;
97 char buddyname[MAX_BUDDYNAME_LENGTH + 1];
98 guint16 tlv_count = 0;
99 struct aiminfo *aiminfo = pinfo->private_data;
102 proto_tree *buddy_tree = NULL;
105 ti = proto_tree_add_text(tree, tvb, 0, -1, "Buddy List Service");
106 buddy_tree = proto_item_add_subtree(ti, ett_aim_buddylist);
110 switch(aiminfo->subtype)
112 case FAMILY_BUDDYLIST_REQRIGHTS:
113 case FAMILY_BUDDYLIST_WATCHERS_REQ:
116 case FAMILY_BUDDYLIST_REMBUDDY:
117 case FAMILY_BUDDYLIST_ADDBUDDY:
118 case FAMILY_BUDDYLIST_WATCHERS_REP:
119 while(tvb_length_remaining(tvb, offset) > 0) {
120 offset = dissect_aim_buddyname( tvb, pinfo, offset, buddy_tree);
123 case FAMILY_BUDDYLIST_ERROR:
124 return dissect_aim_snac_error(tvb, pinfo, offset, buddy_tree);
125 case FAMILY_BUDDYLIST_RIGHTSINFO:
126 while(tvb_length_remaining(tvb, offset) > 0) {
127 offset = dissect_aim_tlv( tvb, pinfo, offset, buddy_tree, buddylist_tlvs);
130 case FAMILY_BUDDYLIST_REJECT:
131 return dissect_aim_buddyname(tvb, pinfo, offset, buddy_tree);
132 case FAMILY_BUDDYLIST_ONCOMING:
133 buddyname_length = aim_get_buddyname( buddyname, tvb, offset, offset + 1 );
135 if (check_col(pinfo->cinfo, COL_INFO)) {
136 col_add_fstr(pinfo->cinfo, COL_INFO, "Oncoming Buddy");
137 col_append_fstr(pinfo->cinfo, COL_INFO, ": %s",
138 format_text(buddyname, buddyname_length));
142 proto_tree_add_text(buddy_tree, tvb, offset + 1, buddyname_length,
144 format_text(buddyname, buddyname_length));
146 offset += buddyname_length + 1;
149 proto_tree_add_item(buddy_tree, hf_aim_userinfo_warninglevel, tvb, offset,
154 tlv_count = tvb_get_ntohs(tvb, offset);
155 proto_tree_add_item(buddy_tree, hf_aim_userinfo_tlvcount, tvb, offset,
159 while (tvb_length_remaining(tvb, offset) > 0) {
160 offset = dissect_aim_tlv(tvb, pinfo, offset, buddy_tree, onlinebuddy_tlvs);
165 case FAMILY_BUDDYLIST_OFFGOING:
166 buddyname_length = aim_get_buddyname( buddyname, tvb, offset, offset + 1 );
168 if (check_col(pinfo->cinfo, COL_INFO)) {
169 col_add_fstr(pinfo->cinfo, COL_INFO, "Offgoing Buddy");
170 col_append_fstr(pinfo->cinfo, COL_INFO, ": %s",
171 format_text(buddyname, buddyname_length));
175 proto_tree_add_text(buddy_tree, tvb, offset + 1, buddyname_length,
177 format_text(buddyname, buddyname_length));
179 offset += buddyname_length + 1;
182 proto_tree_add_item(buddy_tree, hf_aim_userinfo_warninglevel, tvb, offset,
186 return dissect_aim_tlv_list(tvb, pinfo, offset, buddy_tree, onlinebuddy_tlvs);
193 /* Register the protocol with Ethereal */
195 proto_register_aim_buddylist(void)
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 }
204 { "Buddy Name", "aim.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
206 { &hf_aim_userinfo_warninglevel,
207 { "Warning Level", "aim.userinfo.warninglevel", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
209 { &hf_aim_userinfo_tlvcount,
210 { "TLV Count", "aim.userinfo.tlvcount", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
214 /* Setup protocol subtree array */
215 static gint *ett[] = {
219 /* Register the protocol name and description */
220 proto_aim_buddylist = proto_register_protocol("AIM Buddylist Service", "AIM Buddylist", "aim_buddylist");
222 /* Required function calls to register the header fields and subtrees used */
223 proto_register_field_array(proto_aim_buddylist, hf, array_length(hf));
224 proto_register_subtree_array(ett, array_length(ett));
228 proto_reg_handoff_aim_buddylist(void)
230 dissector_handle_t aim_handle;
232 aim_handle = new_create_dissector_handle(dissect_aim_snac_buddylist, proto_aim_buddylist);
233 dissector_add("aim.family", FAMILY_BUDDYLIST, aim_handle);
234 aim_init_family(FAMILY_BUDDYLIST, "Buddylist", aim_fnac_family_buddylist);