change the signature that asn2wrs generates for functions to marm all parameters...
[obnox/wireshark/wip.git] / epan / dissectors / packet-aim-chat.c
1 /* packet-aim-chat.c
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>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
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 #include <epan/emem.h>
41
42 #include "packet-tcp.h"
43 #include "packet-aim.h"
44
45 /* SNAC families */
46 #define FAMILY_CHAT       0x000E
47
48 #define AIM_CHAT_TLV_BROWSABLE_TREE             0x001
49 #define AIM_CHAT_TLV_CLASS_EXCLUSIVE            0x002
50 #define AIM_CHAT_TLV_MAX_CONCURRENT_ROOMS       0x003
51 #define AIM_CHAT_TLV_MAX_ROOM_NAME_LEN          0x004
52 #define AIM_CHAT_TLV_ROOT_ROOMS                         0x005
53 #define AIM_CHAT_TLV_SEARCH_TAGS                        0x006
54 #define AIM_CHAT_TLV_CHILD_ROOMS                        0x065
55 #define AIM_CHAT_TLV_CONTAINS_USER_CLASS        0x066
56 #define AIM_CHAT_TLV_CONTAINS_USER_ARRAY        0x067
57
58 static const aim_tlv chat_tlvs[] = {
59         { AIM_CHAT_TLV_BROWSABLE_TREE, "Browsable tree", dissect_aim_tlv_value_bytes },
60         { AIM_CHAT_TLV_CLASS_EXCLUSIVE, "Exclusively for class", dissect_aim_tlv_value_userclass },
61         { AIM_CHAT_TLV_MAX_CONCURRENT_ROOMS, "Max. number of concurrent rooms", dissect_aim_tlv_value_uint8 },
62         { AIM_CHAT_TLV_MAX_ROOM_NAME_LEN, "Max. length of room name", dissect_aim_tlv_value_uint8 },
63         { AIM_CHAT_TLV_ROOT_ROOMS, "Root Rooms", dissect_aim_tlv_value_bytes },
64         { AIM_CHAT_TLV_SEARCH_TAGS, "Search Tags", dissect_aim_tlv_value_bytes },
65         { AIM_CHAT_TLV_CHILD_ROOMS, "Child Rooms", dissect_aim_tlv_value_bytes },
66         { AIM_CHAT_TLV_CONTAINS_USER_CLASS, "Contains User Class", dissect_aim_tlv_value_bytes },
67         { AIM_CHAT_TLV_CONTAINS_USER_ARRAY, "Contains User Array", dissect_aim_tlv_value_bytes },
68         { 0, NULL, NULL }
69 };
70
71 /* Initialize the protocol and registered fields */
72 static int proto_aim_chat = -1;
73
74 /* Initialize the subtree pointers */
75 static gint ett_aim_chat          = -1;
76
77 static int dissect_aim_chat_userinfo_list(tvbuff_t *tvb, packet_info *pinfo, proto_tree *chat_tree)
78 {
79         int offset = 0;
80         while(tvb_length_remaining(tvb, offset) > 0) {
81                 offset = dissect_aim_userinfo(tvb, pinfo, offset, chat_tree);
82         }
83         return offset;
84 }
85
86 static int dissect_aim_chat_outgoing_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *chat_tree _U_)
87 {
88         char *buddyname;
89         guchar *msg;
90         int buddyname_length;
91
92         buddyname=ep_alloc(MAX_BUDDYNAME_LENGTH+1);
93         msg=ep_alloc(1000);
94         buddyname_length = aim_get_buddyname( buddyname, tvb, 30, 31 );
95
96         /* channel message from client */
97         aim_get_message( msg, tvb, 40 + buddyname_length, tvb_length(tvb) 
98                                          - 40 - buddyname_length );
99
100         if (check_col(pinfo->cinfo, COL_INFO)) 
101                 col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s", msg);
102         
103         return tvb_length(tvb);
104 }
105
106
107 static int dissect_aim_chat_incoming_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *chat_tree)
108 {
109         char *buddyname;
110         guchar *msg;
111         /* channel message to client */
112         int buddyname_length;
113         
114         buddyname=ep_alloc(MAX_BUDDYNAME_LENGTH+1);
115         msg=ep_alloc(1000);
116         buddyname_length = aim_get_buddyname( buddyname, tvb, 30, 31 );
117
118         aim_get_message( msg, tvb, 36 + buddyname_length, tvb_length(tvb) 
119                                          - 36 - buddyname_length );
120
121         if (check_col(pinfo->cinfo, COL_INFO)) {
122                 col_append_fstr(pinfo->cinfo, COL_INFO, "from: %s", buddyname);
123                 col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s", msg);
124         }
125
126         if(chat_tree) {
127                 proto_tree_add_text(chat_tree, tvb, 31, buddyname_length, 
128                                                         "Screen Name: %s",
129                                                         format_text(buddyname, buddyname_length));
130         }
131         return tvb_length(tvb);
132 }
133
134 static const aim_subtype aim_fnac_family_chat[] = {
135   { 0x0001, "Error", dissect_aim_snac_error },
136   { 0x0002, "Room Info Update", NULL },
137   { 0x0003, "User Join", dissect_aim_chat_userinfo_list },
138   { 0x0004, "User Leave", dissect_aim_chat_userinfo_list },
139   { 0x0005, "Outgoing Message", dissect_aim_chat_outgoing_msg },
140   { 0x0006, "Incoming Message", dissect_aim_chat_incoming_msg },
141   { 0x0007, "Evil Request", NULL },
142   { 0x0008, "Evil Reply", NULL },
143   { 0, NULL, NULL }
144 };
145
146 /* Register the protocol with Wireshark */
147 void
148 proto_register_aim_chat(void)
149 {
150
151 /* Setup list of header fields */
152 /*FIXME
153   static hf_register_info hf[] = {
154   };*/
155
156 /* Setup protocol subtree array */
157   static gint *ett[] = {
158     &ett_aim_chat,
159   };
160
161 /* Register the protocol name and description */
162   proto_aim_chat = proto_register_protocol("AIM Chat Service", "AIM Chat", "aim_chat");
163
164 /* Required function calls to register the header fields and subtrees used */
165 /*FIXME
166   proto_register_field_array(proto_aim_chat, hf, array_length(hf));*/
167   proto_register_subtree_array(ett, array_length(ett));
168 }
169
170 void
171 proto_reg_handoff_aim_chat(void)
172 {
173   aim_init_family(proto_aim_chat, ett_aim_chat, FAMILY_CHAT, aim_fnac_family_chat);
174 }