As the gtk2 directory is no longer needed (GTK1 and 2 are using the same sources...
[obnox/wireshark/wip.git] / packet-aim-admin.c
1 /* packet-aim-admin.c
2  * Routines for AIM (OSCAR) dissection, Administration Service
3  * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
4  *
5  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
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_ADMIN      0x0007
43
44 /* Family Admin */
45 #define FAMILY_ADMIN_ERROR            0x0001
46 #define FAMILY_ADMIN_ACCNT_INFO_REQ   0x0002
47 #define FAMILY_ADMIN_ACCNT_INFO_REPL  0x0003
48 #define FAMILY_ADMIN_INFOCHANGEREQ    0x0004
49 #define FAMILY_ADMIN_INFOCHANGEREPLY  0x0005
50 #define FAMILY_ADMIN_ACCT_CFRM_REQ    0x0006
51 #define FAMILY_ADMIN_ACCT_CFRM_REPL   0x0007
52 #define FAMILY_ADMIN_DEFAULT          0xffff
53
54 static const value_string aim_fnac_family_admin[] = {
55   { FAMILY_ADMIN_ERROR, "Error" },
56   { FAMILY_ADMIN_ACCNT_INFO_REQ, "Request Account Information" },
57   { FAMILY_ADMIN_ACCNT_INFO_REPL, "Requested Account Information" },
58   { FAMILY_ADMIN_INFOCHANGEREQ, "Infochange Request" },
59   { FAMILY_ADMIN_INFOCHANGEREPLY, "Infochange Reply" },
60   { FAMILY_ADMIN_ACCT_CFRM_REQ, "Account Confirm Request" },
61   { FAMILY_ADMIN_ACCT_CFRM_REPL, "Account Confirm Reply" },
62   { FAMILY_ADMIN_DEFAULT, "Adminstrative Default" },
63   { 0, NULL }
64 };
65
66 #define CONFIRM_STATUS_EMAIL_SENT                0x00
67 #define CONFIRM_STATUS_ALREADY_CONFIRMED 0x1E
68 #define CONFIRM_STATUS_SERVER_ERROR          0x23
69
70 static const value_string confirm_statusses[] = {
71         { CONFIRM_STATUS_EMAIL_SENT, "A confirmation email has been sent" },
72         { CONFIRM_STATUS_ALREADY_CONFIRMED, "Account was already confirmed" },
73         { CONFIRM_STATUS_SERVER_ERROR, "Server couldn't start confirmation process" },
74         { 0, NULL }
75 };
76
77 /* Initialize the protocol and registered fields */
78 static int proto_aim_admin = -1;
79 static int hf_admin_acctinfo_code = -1;
80 static int hf_admin_acctinfo_permissions = -1;
81 static int hf_admin_confirm_status = -1;
82
83 /* Initialize the subtree pointers */
84 static gint ett_aim_admin          = -1;
85
86 static int dissect_aim_admin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
87         struct aiminfo *aiminfo = pinfo->private_data;
88     proto_item *ti = NULL;
89     proto_tree *admin_tree = NULL;
90         int offset = 0;
91                                                                                 
92     if(tree) {
93         ti = proto_tree_add_text(tree, tvb, 0, -1,"AIM Administration Service");
94         admin_tree = proto_item_add_subtree(ti, ett_aim_admin);
95     }
96         
97         switch(aiminfo->subtype) {
98         case FAMILY_ADMIN_ERROR:
99                 return dissect_aim_snac_error(tvb, pinfo, 0, admin_tree);
100         case FAMILY_ADMIN_ACCNT_INFO_REQ:
101                 proto_tree_add_item(admin_tree, hf_admin_acctinfo_code, tvb, 0, 2, tvb_get_ntohs(tvb, 0)); 
102                 proto_tree_add_text(admin_tree, tvb, 2, 2, "Unknown");
103                 return 4;
104                 
105         case FAMILY_ADMIN_INFOCHANGEREPLY:
106     case FAMILY_ADMIN_ACCNT_INFO_REPL:
107                 {
108                         proto_tree_add_uint(admin_tree, hf_admin_acctinfo_permissions, tvb, offset, 2, tvb_get_ntohs(tvb, offset)); offset+=2;
109                         return dissect_aim_tlv_list(tvb, pinfo, offset, admin_tree, client_tlvs);
110                 }
111         case FAMILY_ADMIN_INFOCHANGEREQ:
112                 while(tvb_length_remaining(tvb, offset) > 0) {
113                         offset = dissect_aim_tlv(tvb, pinfo, offset, admin_tree, client_tlvs);
114                 }
115                 return offset;
116         case FAMILY_ADMIN_ACCT_CFRM_REQ:
117                 /* No data */
118                 return 0;
119         case FAMILY_ADMIN_ACCT_CFRM_REPL:
120                 proto_tree_add_uint(admin_tree, hf_admin_confirm_status, tvb, offset, 2, tvb_get_ntohs(tvb, offset)); offset+=2;
121                 while(tvb_length_remaining(tvb, offset) > 0) {
122                         offset = dissect_aim_tlv(tvb, pinfo, offset, admin_tree, client_tlvs);
123                 }
124                 return offset;
125
126         default: return 0;
127         }
128         return 0;
129 }
130
131 /* Register the protocol with Ethereal */
132 void
133 proto_register_aim_admin(void)
134 {
135
136 /* Setup list of header fields */
137   static hf_register_info hf[] = {
138           { &hf_admin_acctinfo_code,
139                   { "Account Information Request Code", "aim.acctinfo.code", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL },
140           },
141           { &hf_admin_acctinfo_permissions,
142                   { "Account Permissions", "aim.acctinfo.permissions", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL },
143           }, 
144           { &hf_admin_confirm_status,
145                   { "Confirmation status", "admin.confirm_status", FT_UINT16, BASE_HEX, VALS(confirm_statusses), 0x0, "", HFILL },
146                                                                                                                                                                          },
147   };
148
149 /* Setup protocol subtree array */
150   static gint *ett[] = {
151     &ett_aim_admin,
152   };
153
154 /* Register the protocol name and description */
155   proto_aim_admin = proto_register_protocol("AIM Administrative", "AIM Administration", "aim_admin");
156
157 /* Required function calls to register the header fields and subtrees used */
158   proto_register_field_array(proto_aim_admin, hf, array_length(hf));
159   proto_register_subtree_array(ett, array_length(ett));
160 }
161
162 void
163 proto_reg_handoff_aim_admin(void)
164 {
165   dissector_handle_t aim_handle;
166
167   aim_handle = new_create_dissector_handle(dissect_aim_admin, proto_aim_admin);
168   dissector_add("aim.family", FAMILY_ADMIN, aim_handle);
169   aim_init_family(FAMILY_ADMIN, "Administration", aim_fnac_family_admin);
170 }