MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / epan / dissectors / packet-aim-buddylist.c
bloba42321f019c2c6b14ca5d759de7a524eede6839c
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$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/strutil.h>
33 #include "packet-aim.h"
35 void proto_register_aim_buddylist(void);
36 void proto_reg_handoff_aim_buddylist(void);
38 #define FAMILY_BUDDYLIST 0x0003
41 #define AIM_BUDDYLIST_TLV_MAX_CONTACT_ENTRIES 0x0001
42 #define AIM_BUDDYLIST_TLV_MAX_WATCHER_ENTRIES 0x0002
43 #define AIM_BUDDYLIST_TLV_MAX_ONLINE_NOTIFICATIONS 0x0003
45 static const aim_tlv aim_buddylist_tlvs[] = {
46 { AIM_BUDDYLIST_TLV_MAX_CONTACT_ENTRIES, "Max number of contact list entries", dissect_aim_tlv_value_uint16 },
47 { AIM_BUDDYLIST_TLV_MAX_WATCHER_ENTRIES, "Max number of watcher list entries", dissect_aim_tlv_value_uint16 },
48 { AIM_BUDDYLIST_TLV_MAX_ONLINE_NOTIFICATIONS, "Max online notifications", dissect_aim_tlv_value_uint16 },
49 {0, NULL, NULL }
53 /* Initialize the protocol and registered fields */
54 static int proto_aim_buddylist = -1;
55 static int hf_aim_userinfo_warninglevel = -1;
57 /* Initialize the subtree pointers */
58 static gint ett_aim_buddylist = -1;
60 static int dissect_aim_buddylist_buddylist(tvbuff_t *tvb, packet_info *pinfo, proto_tree *buddy_tree)
62 int offset = 0;
63 while (tvb_length_remaining(tvb, offset) > 0) {
64 offset = dissect_aim_buddyname( tvb, pinfo, offset, buddy_tree);
66 return offset;
69 static int dissect_aim_buddylist_rights_repl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *buddy_tree)
71 return dissect_aim_tlv_sequence(tvb, pinfo, 0, buddy_tree, aim_buddylist_tlvs);
74 static int dissect_aim_buddylist_reject(tvbuff_t *tvb, packet_info *pinfo, proto_tree *buddy_tree)
76 return dissect_aim_buddyname(tvb, pinfo, 0, buddy_tree);
79 static int dissect_aim_buddylist_oncoming(tvbuff_t *tvb, packet_info *pinfo, proto_tree *buddy_tree)
81 guchar buddyname[MAX_BUDDYNAME_LENGTH+1];
82 int offset = 0;
83 int buddyname_length = aim_get_buddyname( buddyname, tvb, offset, offset + 1 );
85 col_set_str(pinfo->cinfo, COL_INFO, "Oncoming Buddy");
86 col_append_fstr(pinfo->cinfo, COL_INFO, ": %s",
87 format_text(buddyname, buddyname_length));
89 offset += dissect_aim_buddyname(tvb, pinfo, offset, buddy_tree);
91 /* Warning level */
92 proto_tree_add_item(buddy_tree, hf_aim_userinfo_warninglevel, tvb, offset,
93 2, ENC_BIG_ENDIAN);
94 offset += 2;
96 offset = dissect_aim_tlv_list(tvb, pinfo, offset, buddy_tree, aim_onlinebuddy_tlvs);
98 return offset;
101 static int dissect_aim_buddylist_offgoing(tvbuff_t *tvb, packet_info *pinfo, proto_tree *buddy_tree)
104 guchar buddyname[MAX_BUDDYNAME_LENGTH+1];
105 int offset = 0;
106 int buddyname_length = aim_get_buddyname( buddyname, tvb, offset, offset + 1 );
108 col_set_str(pinfo->cinfo, COL_INFO, "Offgoing Buddy");
109 col_append_fstr(pinfo->cinfo, COL_INFO, ": %s",
110 format_text(buddyname, buddyname_length));
112 offset += dissect_aim_buddyname(tvb, pinfo, offset, buddy_tree);
114 /* Warning level */
115 proto_tree_add_item(buddy_tree, hf_aim_userinfo_warninglevel, tvb, offset,
116 2, ENC_BIG_ENDIAN);
117 offset += 2;
119 return dissect_aim_tlv_list(tvb, pinfo, offset, buddy_tree, aim_onlinebuddy_tlvs);
122 static const aim_subtype aim_fnac_family_buddylist[] = {
123 { 0x0001, "Error", dissect_aim_snac_error },
124 { 0x0002, "Rights Request", NULL },
125 { 0x0003, "Rights Reply", dissect_aim_buddylist_rights_repl },
126 { 0x0004, "Add Buddy", dissect_aim_buddylist_buddylist },
127 { 0x0005, "Remove Buddy", dissect_aim_buddylist_buddylist },
128 { 0x0006, "Watchers List Request", NULL },
129 { 0x0007, "Watchers List Reply", dissect_aim_buddylist_buddylist },
130 { 0x000a, "Reject Buddy", dissect_aim_buddylist_reject },
131 { 0x000b, "Oncoming Buddy", dissect_aim_buddylist_oncoming },
132 { 0x000c, "Offgoing Buddy", dissect_aim_buddylist_offgoing },
133 { 0, NULL, NULL }
136 /* Register the protocol with Wireshark */
137 void
138 proto_register_aim_buddylist(void)
141 /* Setup list of header fields */
142 static hf_register_info hf[] = {
143 { &hf_aim_userinfo_warninglevel,
144 { "Warning Level", "aim_buddylist.userinfo.warninglevel", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
148 /* Setup protocol subtree array */
149 static gint *ett[] = {
150 &ett_aim_buddylist,
153 /* Register the protocol name and description */
154 proto_aim_buddylist = proto_register_protocol("AIM Buddylist Service", "AIM Buddylist", "aim_buddylist");
156 /* Required function calls to register the header fields and subtrees used */
157 proto_register_field_array(proto_aim_buddylist, hf, array_length(hf));
158 proto_register_subtree_array(ett, array_length(ett));
161 void
162 proto_reg_handoff_aim_buddylist(void)
164 aim_init_family(proto_aim_buddylist, ett_aim_buddylist, FAMILY_BUDDYLIST, aim_fnac_family_buddylist);