| |
1 /* |
| |
2 * Gaim's oscar protocol plugin |
| |
3 * This file is the legal property of its developers. |
| |
4 * Please see the AUTHORS file distributed alongside this file. |
| |
5 * |
| |
6 * This library is free software; you can redistribute it and/or |
| |
7 * modify it under the terms of the GNU Lesser General Public |
| |
8 * License as published by the Free Software Foundation; either |
| |
9 * version 2 of the License, or (at your option) any later version. |
| |
10 * |
| |
11 * This library is distributed in the hope that it will be useful, |
| |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| |
14 * Lesser General Public License for more details. |
| |
15 * |
| |
16 * You should have received a copy of the GNU Lesser General Public |
| |
17 * License along with this library; if not, write to the Free Software |
| |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| |
19 */ |
| |
20 |
| |
21 /* |
| |
22 * Family 0x0007 - Account Administration. |
| |
23 * |
| |
24 * Used for stuff like changing the formating of your screen name, changing your |
| |
25 * email address, requesting an account confirmation email, getting account info, |
| |
26 * |
| |
27 */ |
| |
28 |
| |
29 #include "oscar.h" |
| |
30 |
| |
31 /* |
| |
32 * Subtype 0x0002 - Request a bit of account info. |
| |
33 * |
| |
34 * Info should be one of the following: |
| |
35 * 0x0001 - Screen name formatting |
| |
36 * 0x0011 - Email address |
| |
37 * 0x0013 - Unknown |
| |
38 * |
| |
39 */ |
| |
40 int |
| |
41 aim_admin_getinfo(OscarData *od, FlapConnection *conn, guint16 info) |
| |
42 { |
| |
43 FlapFrame *fr; |
| |
44 aim_snacid_t snacid; |
| |
45 |
| |
46 fr = flap_frame_new(od, 0x02, 14); |
| |
47 |
| |
48 snacid = aim_cachesnac(od, 0x0007, 0x0002, 0x0000, NULL, 0); |
| |
49 aim_putsnac(&fr->data, 0x0007, 0x0002, 0x0000, snacid); |
| |
50 |
| |
51 byte_stream_put16(&fr->data, info); |
| |
52 byte_stream_put16(&fr->data, 0x0000); |
| |
53 |
| |
54 flap_connection_send(conn, fr); |
| |
55 |
| |
56 return 0; |
| |
57 } |
| |
58 |
| |
59 /* |
| |
60 * Subtypes 0x0003 and 0x0005 - Parse account info. |
| |
61 * |
| |
62 * Called in reply to both an information request (subtype 0x0002) and |
| |
63 * an information change (subtype 0x0004). |
| |
64 * |
| |
65 */ |
| |
66 static int |
| |
67 infochange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| |
68 { |
| |
69 aim_rxcallback_t userfunc; |
| |
70 char *url=NULL, *sn=NULL, *email=NULL; |
| |
71 guint16 perms, tlvcount, err=0; |
| |
72 |
| |
73 perms = byte_stream_get16(bs); |
| |
74 tlvcount = byte_stream_get16(bs); |
| |
75 |
| |
76 while (tlvcount && byte_stream_empty(bs)) { |
| |
77 guint16 type, length; |
| |
78 |
| |
79 type = byte_stream_get16(bs); |
| |
80 length = byte_stream_get16(bs); |
| |
81 |
| |
82 switch (type) { |
| |
83 case 0x0001: { |
| |
84 free(sn); |
| |
85 sn = byte_stream_getstr(bs, length); |
| |
86 } break; |
| |
87 |
| |
88 case 0x0004: { |
| |
89 free(url); |
| |
90 url = byte_stream_getstr(bs, length); |
| |
91 } break; |
| |
92 |
| |
93 case 0x0008: { |
| |
94 err = byte_stream_get16(bs); |
| |
95 } break; |
| |
96 |
| |
97 case 0x0011: { |
| |
98 free(email); |
| |
99 if (length == 0) |
| |
100 email = g_strdup("*suppressed"); |
| |
101 else |
| |
102 email = byte_stream_getstr(bs, length); |
| |
103 } break; |
| |
104 } |
| |
105 |
| |
106 tlvcount--; |
| |
107 } |
| |
108 |
| |
109 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
| |
110 userfunc(od, conn, frame, (snac->subtype == 0x0005) ? 1 : 0, perms, err, url, sn, email); |
| |
111 |
| |
112 free(sn); |
| |
113 free(url); |
| |
114 free(email); |
| |
115 |
| |
116 return 1; |
| |
117 } |
| |
118 |
| |
119 /* |
| |
120 * Subtype 0x0004 - Set screenname formatting. |
| |
121 * |
| |
122 */ |
| |
123 int |
| |
124 aim_admin_setnick(OscarData *od, FlapConnection *conn, const char *newnick) |
| |
125 { |
| |
126 FlapFrame *fr; |
| |
127 aim_snacid_t snacid; |
| |
128 aim_tlvlist_t *tl = NULL; |
| |
129 |
| |
130 fr = flap_frame_new(od, 0x02, 10+2+2+strlen(newnick)); |
| |
131 |
| |
132 snacid = aim_cachesnac(od, 0x0007, 0x0004, 0x0000, NULL, 0); |
| |
133 aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid); |
| |
134 |
| |
135 aim_tlvlist_add_str(&tl, 0x0001, newnick); |
| |
136 |
| |
137 aim_tlvlist_write(&fr->data, &tl); |
| |
138 aim_tlvlist_free(&tl); |
| |
139 |
| |
140 flap_connection_send(conn, fr); |
| |
141 |
| |
142 |
| |
143 return 0; |
| |
144 } |
| |
145 |
| |
146 /* |
| |
147 * Subtype 0x0004 - Change password. |
| |
148 * |
| |
149 */ |
| |
150 int |
| |
151 aim_admin_changepasswd(OscarData *od, FlapConnection *conn, const char *newpw, const char *curpw) |
| |
152 { |
| |
153 FlapFrame *fr; |
| |
154 aim_tlvlist_t *tl = NULL; |
| |
155 aim_snacid_t snacid; |
| |
156 |
| |
157 fr = flap_frame_new(od, 0x02, 10+4+strlen(curpw)+4+strlen(newpw)); |
| |
158 |
| |
159 snacid = aim_cachesnac(od, 0x0007, 0x0004, 0x0000, NULL, 0); |
| |
160 aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid); |
| |
161 |
| |
162 /* new password TLV t(0002) */ |
| |
163 aim_tlvlist_add_str(&tl, 0x0002, newpw); |
| |
164 |
| |
165 /* current password TLV t(0012) */ |
| |
166 aim_tlvlist_add_str(&tl, 0x0012, curpw); |
| |
167 |
| |
168 aim_tlvlist_write(&fr->data, &tl); |
| |
169 aim_tlvlist_free(&tl); |
| |
170 |
| |
171 flap_connection_send(conn, fr); |
| |
172 |
| |
173 return 0; |
| |
174 } |
| |
175 |
| |
176 /* |
| |
177 * Subtype 0x0004 - Change email address. |
| |
178 * |
| |
179 */ |
| |
180 int |
| |
181 aim_admin_setemail(OscarData *od, FlapConnection *conn, const char *newemail) |
| |
182 { |
| |
183 FlapFrame *fr; |
| |
184 aim_snacid_t snacid; |
| |
185 aim_tlvlist_t *tl = NULL; |
| |
186 |
| |
187 fr = flap_frame_new(od, 0x02, 10+2+2+strlen(newemail)); |
| |
188 |
| |
189 snacid = aim_cachesnac(od, 0x0007, 0x0004, 0x0000, NULL, 0); |
| |
190 aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid); |
| |
191 |
| |
192 aim_tlvlist_add_str(&tl, 0x0011, newemail); |
| |
193 |
| |
194 aim_tlvlist_write(&fr->data, &tl); |
| |
195 aim_tlvlist_free(&tl); |
| |
196 |
| |
197 flap_connection_send(conn, fr); |
| |
198 |
| |
199 return 0; |
| |
200 } |
| |
201 |
| |
202 /* |
| |
203 * Subtype 0x0006 - Request account confirmation. |
| |
204 * |
| |
205 * This will cause an email to be sent to the address associated with |
| |
206 * the account. By following the instructions in the mail, you can |
| |
207 * get the TRIAL flag removed from your account. |
| |
208 * |
| |
209 */ |
| |
210 int |
| |
211 aim_admin_reqconfirm(OscarData *od, FlapConnection *conn) |
| |
212 { |
| |
213 return aim_genericreq_n(od, conn, 0x0007, 0x0006); |
| |
214 } |
| |
215 |
| |
216 /* |
| |
217 * Subtype 0x0007 - Account confirmation request acknowledgement. |
| |
218 * |
| |
219 */ |
| |
220 static int |
| |
221 accountconfirm(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| |
222 { |
| |
223 int ret = 0; |
| |
224 aim_rxcallback_t userfunc; |
| |
225 guint16 status; |
| |
226 /* aim_tlvlist_t *tl; */ |
| |
227 |
| |
228 status = byte_stream_get16(bs); |
| |
229 /* Status is 0x0013 if unable to confirm at this time */ |
| |
230 |
| |
231 /* tl = aim_tlvlist_read(bs); */ |
| |
232 |
| |
233 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
| |
234 ret = userfunc(od, conn, frame, status); |
| |
235 |
| |
236 /* aim_tlvlist_free(&tl); */ |
| |
237 |
| |
238 return ret; |
| |
239 } |
| |
240 |
| |
241 static int |
| |
242 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| |
243 { |
| |
244 if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005)) |
| |
245 return infochange(od, conn, mod, frame, snac, bs); |
| |
246 else if (snac->subtype == 0x0007) |
| |
247 return accountconfirm(od, conn, mod, frame, snac, bs); |
| |
248 |
| |
249 return 0; |
| |
250 } |
| |
251 |
| |
252 int admin_modfirst(OscarData *od, aim_module_t *mod) |
| |
253 { |
| |
254 mod->family = 0x0007; |
| |
255 mod->version = 0x0001; |
| |
256 mod->toolid = 0x0010; |
| |
257 mod->toolversion = 0x0629; |
| |
258 mod->flags = 0; |
| |
259 strncpy(mod->name, "admin", sizeof(mod->name)); |
| |
260 mod->snachandler = snachandler; |
| |
261 |
| |
262 return 0; |
| |
263 } |