Enable Lua tcp tap userdata.
[obnox/wireshark/wip.git] / epan / dissectors / packet-aim-icq.c
1 /* packet-aim-icq.c
2  * Routines for AIM Instant Messenger (OSCAR) dissection, SNAC ICQ
3  * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <ctype.h>
34
35 #include <glib.h>
36
37 #include <epan/packet.h>
38 #include <epan/strutil.h>
39
40 #include "packet-aim.h"
41
42 #define FAMILY_ICQ        0x0015
43
44
45 #define ICQ_CLI_OFFLINE_MESSAGE_REQ     0x003c
46 #define ICQ_CLI_DELETE_OFFLINE_MSGS             0x003e
47 #define ICQ_SRV_OFFLINE_MSGS                    0x0041
48 #define ICQ_SRV_END_OF_OFFLINE_MSGS             0x0042
49 #define ICQ_CLI_META_INFO_REQ                   0x07d0
50 #define ICQ_SRV_META_INFO_REPL                  0x07da
51
52 static const value_string aim_icq_data_types[] = {
53   { ICQ_CLI_OFFLINE_MESSAGE_REQ, "Offline Message Request" },
54   { ICQ_SRV_OFFLINE_MSGS, "Offline Messages Reply" },
55   { ICQ_SRV_END_OF_OFFLINE_MSGS, "End Of Offline Messages Reply" },
56   { ICQ_CLI_DELETE_OFFLINE_MSGS, "Delete Offline Messages Request" },
57   { ICQ_CLI_META_INFO_REQ, "Metainfo Request" },
58   { ICQ_SRV_META_INFO_REPL, "Metainfo Reply" },
59   { 0, NULL }
60 };
61
62
63 static int dissect_aim_tlv_value_icq(proto_item *ti, guint16 subtype, tvbuff_t *tvb, packet_info *pinfo _U_);
64
65 #define TLV_ICQ_META_DATA                         0x0001
66
67 static const aim_tlv icq_tlv[] = {
68    { TLV_ICQ_META_DATA, "Encapsulated ICQ Meta Data", dissect_aim_tlv_value_icq },
69    { 0, NULL, NULL },
70 };
71
72 /* Initialize the protocol and registered fields */
73 static int proto_aim_icq = -1;
74
75 /* Initialize the subtree pointers */
76 static gint ett_aim_icq      = -1;
77 static gint ett_aim_icq_tlv  = -1;
78
79 static gint hf_icq_tlv_data_chunk_size = -1;
80 static gint hf_icq_tlv_request_owner_uid = -1;
81 static gint hf_icq_tlv_request_type = -1;
82 static gint hf_icq_meta_subtype = -1;
83 static gint hf_icq_tlv_request_seq_num = -1;
84 static gint hf_icq_dropped_msg_flag = -1;
85
86
87 static struct
88 {
89         guint16 subtype;
90         const char *name;
91         int (*dissector) (tvbuff_t *, packet_info *, proto_tree *);
92 } icq_calls [] = {
93         { 0x0001, "Server Error Reply", NULL },
94         { 0x0064, "Set User Home Info Reply", NULL },
95         { 0x006e, "Set User Work Info Reply", NULL },
96         { 0x0078, "Set User More Info Reply", NULL },
97         { 0x0082, "Set User Notes Info Reply", NULL },
98         { 0x0087, "Set User Email Info Reply", NULL },
99         { 0x008c, "Set User Interests Info Reply", NULL },
100         { 0x0096, "Set User Affiliations Info Reply", NULL },
101         { 0x00a0, "Set User Permissions Reply", NULL },
102         { 0x00aa, "Set User Password Reply", NULL },
103         { 0x00b4, "Unregister Account Reply", NULL },
104         { 0x00be, "Set User Homepage Category Reply", NULL },
105         { 0x00c8, "User Basic Info Reply", NULL },
106         { 0x00d2, "User Work Info Reply", NULL },
107         { 0x00dc, "User More Info Reply", NULL },
108         { 0x00e6, "User Notes Info Reply", NULL },
109         { 0x00eb, "User Extended Email Reply", NULL },
110         { 0x00f0, "User Interests Info Reply", NULL },
111         { 0x00fa, "User Affiliations Info Reply", NULL },
112         { 0x0104, "Short User Info Reply", NULL },
113         { 0x010e, "User Homepage Category Reply", NULL },
114         { 0x01a4, "Search: User found", NULL },
115         { 0x0302, "Registration Stats Reply", NULL },
116         { 0x0366, "Random Search Server Reply", NULL },
117         { 0x03ea, "Set User Home Info Request", NULL },
118         { 0x03f3, "Set User Work Info Request", NULL },
119         { 0x03fd, "Set User More Info Request", NULL },
120         { 0x0406, "Set User Notes Request", NULL },
121         { 0x040b, "Set User Extended Email Info Request", NULL },
122         { 0x0410, "Set User Interests Info Request", NULL },
123         { 0x041a, "Set User Affiliations Info Request", NULL },
124         { 0x0424, "Set User Permissions Info Request", NULL },
125         { 0x042e, "Change User Password Request", NULL },
126         { 0x0442, "Set User Homepage Category Request", NULL },
127         { 0x04b2, "Fullinfo Request", NULL },
128         { 0x04ba, "Short User Info Request", NULL },
129         { 0x04c4, "Unregister User Request", NULL },
130         { 0x0515, "Search By Details Request", NULL },
131         { 0x0569, "Search By UIN Request", NULL },
132         { 0x055f, "Whitepages Search Request", NULL },
133         { 0x0573, "Search By Email Request", NULL },
134         { 0x074e, "Random Chat User Search Request", NULL },
135         { 0x0898, "Server Variable Request (XML)", NULL },
136         { 0x0aa5, "Registration Report Request", NULL },
137         { 0x0aaf, "Shortcut Bar Stats Report Request", NULL },
138         { 0x0c3a, "Save Info Request", NULL },
139         { 0x1482, "Send SMS Request", NULL },
140         { 0x2008, "Spam Report Request", NULL },
141         { 0x08a2, "Server Variable Reply (XML)", NULL },
142         { 0x0c3f, "Set Fullinfo Reply", NULL },
143         { 0x2012, "User Spam Report Reply", NULL },
144         { 0, NULL, NULL },
145 };
146
147
148 static int dissect_aim_tlv_value_icq(proto_item *ti _U_, guint16 subtype _U_, tvbuff_t *tvb _U_, packet_info *pinfo)
149 {
150         int offset = 0;
151         int i;
152         proto_item *subtype_item;
153         guint16 req_type, req_subtype;
154         proto_tree *t = proto_item_add_subtree(ti, ett_aim_icq_tlv);
155
156         proto_tree_add_item(t, hf_icq_tlv_data_chunk_size, tvb, offset, 2, TRUE);
157         offset += 2;
158         
159         proto_tree_add_item(t, hf_icq_tlv_request_owner_uid, tvb, offset, 4, TRUE);
160         offset += 4;
161
162         proto_tree_add_item(t, hf_icq_tlv_request_type, tvb, offset, 2, TRUE);
163         req_type = tvb_get_letohs(tvb, offset);
164         offset += 2;
165
166         proto_tree_add_item(t, hf_icq_tlv_request_seq_num, tvb, offset, 2, TRUE);
167         offset += 2;
168
169         switch(req_type) {
170         case ICQ_CLI_OFFLINE_MESSAGE_REQ: return offset;
171         case ICQ_CLI_DELETE_OFFLINE_MSGS: return offset;
172         case ICQ_SRV_OFFLINE_MSGS:
173                 /* FIXME */
174                 break;
175         case ICQ_SRV_END_OF_OFFLINE_MSGS: 
176                 proto_tree_add_item(t, hf_icq_dropped_msg_flag, tvb, offset, 1, TRUE);
177                 return offset+1;
178         case ICQ_CLI_META_INFO_REQ:
179         case ICQ_SRV_META_INFO_REPL:
180                 req_subtype = tvb_get_letohs(tvb, offset);
181                 subtype_item = proto_tree_add_item(t, hf_icq_meta_subtype, tvb, offset, 2, TRUE); offset+=2;
182                 
183                 for(i = 0; icq_calls[i].name; i++) {
184                         if(icq_calls[i].subtype == req_subtype) break;
185                 }
186
187                 if(check_col(pinfo->cinfo, COL_INFO)) 
188                         col_set_str(pinfo->cinfo, COL_INFO, icq_calls[i].name?icq_calls[i].name:"Unknown ICQ Meta Call");
189
190                 proto_item_append_text(subtype_item, " (%s)", icq_calls[i].name?icq_calls[i].name:"Unknown");
191
192                 if(icq_calls[i].dissector) 
193                         return icq_calls[i].dissector(tvb_new_subset(tvb, offset, -1, -1), pinfo, t);
194
195         default:
196                 break;
197         }
198
199         return offset;
200 }
201
202 static int dissect_aim_icq_tlv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
203 {
204         return dissect_aim_tlv(tvb, pinfo, 0, tree, icq_tlv);
205 }
206
207 static const aim_subtype aim_fnac_family_icq[] = {
208   { 0x0001, "Error", dissect_aim_snac_error },
209   { 0x0002, "ICQ Request", dissect_aim_icq_tlv },
210   { 0x0003, "ICQ Response", dissect_aim_icq_tlv },
211   { 0x0006, "Auth Request", NULL },
212   { 0x0007, "Auth Response", NULL },
213   { 0, NULL, NULL }
214 };
215
216
217 /* Register the protocol with Wireshark */
218 void
219 proto_register_aim_icq(void)
220 {
221
222 /* Setup list of header fields */
223   static hf_register_info hf[] = {
224           { &hf_icq_tlv_data_chunk_size,
225             { "Data chunk size", "aim_icq.chunk_size", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
226           },
227           { &hf_icq_tlv_request_owner_uid,
228             { "Owner UID", "aim_icq.owner_uid", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL},
229           },
230           { &hf_icq_tlv_request_type,
231             {"Request Type", "aim_icq.request_type", FT_UINT16, BASE_DEC, VALS(aim_icq_data_types), 0x0, "", HFILL},
232           },
233           { &hf_icq_tlv_request_seq_num,
234             {"Request Sequence Number", "aim_icq.request_seq_number", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL},
235           },
236           { &hf_icq_dropped_msg_flag,
237                 {"Dropped messages flag", "aim_icq.offline_msgs.dropped_flag", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL },
238           },
239           { &hf_icq_meta_subtype,
240                 {"Meta Request Subtype", "aim_icq.subtype", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL },
241           },
242   };
243
244 /* Setup protocol subtree array */
245   static gint *ett[] = {
246     &ett_aim_icq,
247         &ett_aim_icq_tlv
248   };
249
250 /* Register the protocol name and description */
251   proto_aim_icq = proto_register_protocol("AIM ICQ", "AIM ICQ", "aim_icq");
252
253 /* Required function calls to register the header fields and subtrees used */
254   proto_register_field_array(proto_aim_icq, hf, array_length(hf));
255   proto_register_subtree_array(ett, array_length(ett));
256 }
257
258 void
259 proto_reg_handoff_aim_icq(void)
260 {
261   aim_init_family(proto_aim_icq, ett_aim_icq, FAMILY_ICQ, aim_fnac_family_icq);
262 }