2 * Routines for AIM Instant Messenger (OSCAR) dissection, SNAC Chat
3 * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
4 * Copyright 2000, Ralf Hoelzer <ralf@well.com>
6 * $Id: packet-aim-chat.c,v 1.4 2004/04/26 18:21:09 obiot Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
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.
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.
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.
38 #include <epan/packet.h>
39 #include <epan/strutil.h>
41 #include "packet-tcp.h"
42 #include "packet-aim.h"
46 #define FAMILY_CHAT 0x000E
49 #define FAMILY_CHAT_ERROR 0x0001
50 #define FAMILY_CHAT_ROOMINFOUPDATE 0x0002
51 #define FAMILY_CHAT_USERJOIN 0x0003
52 #define FAMILY_CHAT_USERLEAVE 0x0004
53 #define FAMILY_CHAT_OUTGOINGMSG 0x0005
54 #define FAMILY_CHAT_INCOMINGMSG 0x0006
55 #define FAMILY_CHAT_EVIL_REQ 0x0007
56 #define FAMILY_CHAT_EVIL_REPLY 0x0008
57 #define FAMILY_CHAT_DEFAULT 0xffff
59 static const value_string aim_fnac_family_chat[] = {
60 { FAMILY_CHAT_ERROR, "Error" },
61 { FAMILY_CHAT_ROOMINFOUPDATE, "Room Info Update" },
62 { FAMILY_CHAT_USERJOIN, "User Join" },
63 { FAMILY_CHAT_USERLEAVE, "User Leave" },
64 { FAMILY_CHAT_OUTGOINGMSG, "Outgoing Message" },
65 { FAMILY_CHAT_INCOMINGMSG, "Incoming Message" },
66 { FAMILY_CHAT_EVIL_REQ, "Evil Request" },
67 { FAMILY_CHAT_EVIL_REPLY, "Evil Reply" },
68 { FAMILY_CHAT_DEFAULT, "Chat Default" },
72 #define AIM_CHAT_TLV_BROWSABLE_TREE 0x001
73 #define AIM_CHAT_TLV_CLASS_EXCLUSIVE 0x002
74 #define AIM_CHAT_TLV_MAX_CONCURRENT_ROOMS 0x003
75 #define AIM_CHAT_TLV_MAX_ROOM_NAME_LEN 0x004
76 #define AIM_CHAT_TLV_ROOT_ROOMS 0x005
77 #define AIM_CHAT_TLV_SEARCH_TAGS 0x006
78 #define AIM_CHAT_TLV_CHILD_ROOMS 0x065
79 #define AIM_CHAT_TLV_CONTAINS_USER_CLASS 0x066
80 #define AIM_CHAT_TLV_CONTAINS_USER_ARRAY 0x067
82 static const aim_tlv chat_tlvs[] = {
83 { AIM_CHAT_TLV_BROWSABLE_TREE, "Browsable tree", dissect_aim_tlv_value_bytes },
84 { AIM_CHAT_TLV_CLASS_EXCLUSIVE, "Exclusively for class", dissect_aim_tlv_value_userclass },
85 { AIM_CHAT_TLV_MAX_CONCURRENT_ROOMS, "Max. number of concurrent rooms", dissect_aim_tlv_value_uint8 },
86 { AIM_CHAT_TLV_MAX_ROOM_NAME_LEN, "Max. length of room name", dissect_aim_tlv_value_uint8 },
87 { AIM_CHAT_TLV_ROOT_ROOMS, "Root Rooms", dissect_aim_tlv_value_bytes },
88 { AIM_CHAT_TLV_SEARCH_TAGS, "Search Tags", dissect_aim_tlv_value_bytes },
89 { AIM_CHAT_TLV_CHILD_ROOMS, "Child Rooms", dissect_aim_tlv_value_bytes },
90 { AIM_CHAT_TLV_CONTAINS_USER_CLASS, "Contains User Class", dissect_aim_tlv_value_bytes },
91 { AIM_CHAT_TLV_CONTAINS_USER_ARRAY, "Contains User Array", dissect_aim_tlv_value_bytes },
95 /* Initialize the protocol and registered fields */
96 static int proto_aim_chat = -1;
98 /* Initialize the subtree pointers */
99 static gint ett_aim_chat = -1;
101 static int dissect_aim_snac_chat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
103 guint8 buddyname_length = 0;
105 struct aiminfo *aiminfo = pinfo->private_data;
106 char buddyname[MAX_BUDDYNAME_LENGTH + 1];
109 proto_tree *chat_tree = NULL;
112 ti = proto_tree_add_text(tree, tvb, 0, -1, "Chat Service");
113 chat_tree = proto_item_add_subtree(ti, ett_aim_chat);
116 switch(aiminfo->subtype)
118 case FAMILY_CHAT_ERROR:
119 return dissect_aim_snac_error(tvb, pinfo, offset, chat_tree);
120 case FAMILY_CHAT_USERLEAVE:
121 case FAMILY_CHAT_USERJOIN:
122 while(tvb_length_remaining(tvb, offset) > 0) {
123 offset = dissect_aim_userinfo(tvb, pinfo, offset, chat_tree);
126 case FAMILY_CHAT_EVIL_REQ:
127 case FAMILY_CHAT_EVIL_REPLY:
128 case FAMILY_CHAT_ROOMINFOUPDATE:
131 case FAMILY_CHAT_OUTGOINGMSG:
132 /* channel message from client */
133 aim_get_message( msg, tvb, 40 + buddyname_length, tvb_length(tvb)
134 - 40 - buddyname_length );
136 if (check_col(pinfo->cinfo, COL_INFO))
137 col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s", msg);
138 return tvb_length(tvb);
140 case FAMILY_CHAT_INCOMINGMSG:
141 /* channel message to client */
142 buddyname_length = aim_get_buddyname( buddyname, tvb, 30, 31 );
143 aim_get_message( msg, tvb, 36 + buddyname_length, tvb_length(tvb)
144 - 36 - buddyname_length );
146 if (check_col(pinfo->cinfo, COL_INFO)) {
147 col_append_fstr(pinfo->cinfo, COL_INFO, "from: %s", buddyname);
148 col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s", msg);
152 proto_tree_add_text(chat_tree, tvb, 31, buddyname_length,
153 "Screen Name: %s", buddyname);
155 return tvb_length(tvb);
160 /* Register the protocol with Ethereal */
162 proto_register_aim_chat(void)
165 /* Setup list of header fields */
167 static hf_register_info hf[] = {
170 /* Setup protocol subtree array */
171 static gint *ett[] = {
175 /* Register the protocol name and description */
176 proto_aim_chat = proto_register_protocol("AIM Chat Service", "AIM Chat", "aim_chat");
178 /* Required function calls to register the header fields and subtrees used */
180 proto_register_field_array(proto_aim_chat, hf, array_length(hf));*/
181 proto_register_subtree_array(ett, array_length(ett));
185 proto_reg_handoff_aim_chat(void)
187 dissector_handle_t aim_handle;
188 aim_handle = new_create_dissector_handle(dissect_aim_snac_chat, proto_aim_chat);
189 dissector_add("aim.family", FAMILY_CHAT, aim_handle);
190 aim_init_family(FAMILY_CHAT, "Chat", aim_fnac_family_chat);