update to netlogon to show DsrGetDcNameEx2() Client account name, domain name and...
[obnox/wireshark/wip.git] / 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: packet-aim-chat.c,v 1.3 2004/04/20 04:48:31 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
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
41 #include "packet-tcp.h"
42 #include "packet-aim.h"
43 #include "prefs.h"
44
45 /* SNAC families */
46 #define FAMILY_CHAT       0x000E
47
48 /* Family Chat */
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
58
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" },
69   { 0, NULL }
70 };
71
72 /* Initialize the protocol and registered fields */
73 static int proto_aim_chat = -1;
74
75 /* Initialize the subtree pointers */
76 static gint ett_aim_chat          = -1;
77
78 static int dissect_aim_snac_chat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
79 {
80   guint8 buddyname_length = 0;
81   int offset = 0;
82   struct aiminfo *aiminfo = pinfo->private_data;
83   char buddyname[MAX_BUDDYNAME_LENGTH + 1];
84   guchar msg[1000];
85   proto_item *ti;
86   proto_tree *chat_tree = NULL;
87                                                                                                                               
88   if(tree) {
89       ti = proto_tree_add_text(tree, tvb, 0, -1, "Chat Service");
90       chat_tree = proto_item_add_subtree(ti, ett_aim_chat);
91   }
92
93   switch(aiminfo->subtype)
94     {
95         case FAMILY_CHAT_ERROR:
96       return dissect_aim_snac_error(tvb, pinfo, offset, chat_tree);
97         case FAMILY_CHAT_ROOMINFOUPDATE:
98           /* FIXME */
99           return 0;
100         case FAMILY_CHAT_USERJOIN:
101           while(tvb_length_remaining(tvb, offset) > 0) {
102                   offset = dissect_aim_buddyname(tvb, pinfo, offset, chat_tree);
103                   /* FIXME */
104           }
105           return offset;
106         case FAMILY_CHAT_USERLEAVE:
107         case FAMILY_CHAT_EVIL_REQ:
108         case FAMILY_CHAT_EVIL_REPLY:
109           /* FIXME */
110           return 0;
111     case FAMILY_CHAT_OUTGOINGMSG:
112       /* channel message from client */
113       aim_get_message( msg, tvb, 40 + buddyname_length, tvb_length(tvb) 
114                    - 40 - buddyname_length );
115       
116       if (check_col(pinfo->cinfo, COL_INFO)) 
117         col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s", msg);
118           return tvb_length(tvb);
119       
120     case FAMILY_CHAT_INCOMINGMSG:
121       /* channel message to client */
122       buddyname_length = aim_get_buddyname( buddyname, tvb, 30, 31 );
123       aim_get_message( msg, tvb, 36 + buddyname_length, tvb_length(tvb) 
124                    - 36 - buddyname_length );
125       
126       if (check_col(pinfo->cinfo, COL_INFO)) {
127         col_append_fstr(pinfo->cinfo, COL_INFO, "from: %s", buddyname);
128         col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s", msg);
129       }
130       
131       if(chat_tree) {
132         proto_tree_add_text(chat_tree, tvb, 31, buddyname_length, 
133                             "Screen Name: %s", buddyname);
134       }
135           return tvb_length(tvb);
136         default: return 0;
137     }
138 }
139
140 /* Register the protocol with Ethereal */
141 void
142 proto_register_aim_chat(void)
143 {
144
145 /* Setup list of header fields */
146 /*FIXME
147   static hf_register_info hf[] = {
148   };*/
149
150 /* Setup protocol subtree array */
151   static gint *ett[] = {
152     &ett_aim_chat,
153   };
154
155 /* Register the protocol name and description */
156   proto_aim_chat = proto_register_protocol("AIM Chat Service", "AIM Chat", "aim_chat");
157
158 /* Required function calls to register the header fields and subtrees used */
159 /*FIXME
160   proto_register_field_array(proto_aim_chat, hf, array_length(hf));*/
161   proto_register_subtree_array(ett, array_length(ett));
162 }
163
164 void
165 proto_reg_handoff_aim_chat(void)
166 {
167   dissector_handle_t aim_handle;
168   aim_handle = new_create_dissector_handle(dissect_aim_snac_chat, proto_aim_chat);
169   dissector_add("aim.family", FAMILY_CHAT, aim_handle);
170   aim_init_family(FAMILY_CHAT, "Chat", aim_fnac_family_chat);
171 }