13234
|
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 */
|
13239
|
40 faim_export int aim_admin_getinfo(OscarSession *sess, OscarConnection *conn, guint16 info)
|
13234
|
41 {
|
13239
|
42 FlapFrame *fr;
|
13234
|
43 aim_snacid_t snacid;
|
|
44
|
13253
|
45 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14)))
|
13234
|
46 return -ENOMEM;
|
|
47
|
|
48 snacid = aim_cachesnac(sess, 0x0007, 0x0002, 0x0000, NULL, 0);
|
|
49 aim_putsnac(&fr->data, 0x0007, 0x0002, 0x0000, snacid);
|
|
50
|
|
51 aimbs_put16(&fr->data, info);
|
|
52 aimbs_put16(&fr->data, 0x0000);
|
|
53
|
|
54 aim_tx_enqueue(sess, 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 */
|
13239
|
66 static int infochange(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
67 {
|
|
68 aim_rxcallback_t userfunc;
|
|
69 char *url=NULL, *sn=NULL, *email=NULL;
|
|
70 guint16 perms, tlvcount, err=0;
|
|
71
|
|
72 perms = aimbs_get16(bs);
|
|
73 tlvcount = aimbs_get16(bs);
|
|
74
|
|
75 while (tlvcount && aim_bstream_empty(bs)) {
|
|
76 guint16 type, length;
|
|
77
|
|
78 type = aimbs_get16(bs);
|
|
79 length = aimbs_get16(bs);
|
|
80
|
|
81 switch (type) {
|
|
82 case 0x0001: {
|
|
83 sn = aimbs_getstr(bs, length);
|
|
84 } break;
|
|
85
|
|
86 case 0x0004: {
|
|
87 url = aimbs_getstr(bs, length);
|
|
88 } break;
|
|
89
|
|
90 case 0x0008: {
|
|
91 err = aimbs_get16(bs);
|
|
92 } break;
|
|
93
|
|
94 case 0x0011: {
|
|
95 if (length == 0) {
|
|
96 email = (char*)malloc(13*sizeof(char));
|
|
97 strcpy(email, "*suppressed*");
|
|
98 } else
|
|
99 email = aimbs_getstr(bs, length);
|
|
100 } break;
|
|
101 }
|
|
102
|
|
103 tlvcount--;
|
|
104 }
|
|
105
|
|
106 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
107 userfunc(sess, rx, (snac->subtype == 0x0005) ? 1 : 0, perms, err, url, sn, email);
|
|
108
|
|
109 free(sn);
|
|
110 free(url);
|
|
111 free(email);
|
|
112
|
|
113 return 1;
|
|
114 }
|
|
115
|
|
116 /*
|
|
117 * Subtype 0x0004 - Set screenname formatting.
|
|
118 *
|
|
119 */
|
13239
|
120 faim_export int aim_admin_setnick(OscarSession *sess, OscarConnection *conn, const char *newnick)
|
13234
|
121 {
|
13239
|
122 FlapFrame *fr;
|
13234
|
123 aim_snacid_t snacid;
|
|
124 aim_tlvlist_t *tl = NULL;
|
|
125
|
13253
|
126 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newnick))))
|
13234
|
127 return -ENOMEM;
|
|
128
|
|
129 snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
|
|
130 aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid);
|
|
131
|
|
132 aim_tlvlist_add_str(&tl, 0x0001, newnick);
|
|
133
|
|
134 aim_tlvlist_write(&fr->data, &tl);
|
|
135 aim_tlvlist_free(&tl);
|
|
136
|
|
137 aim_tx_enqueue(sess, fr);
|
|
138
|
|
139
|
|
140 return 0;
|
|
141 }
|
|
142
|
|
143 /*
|
|
144 * Subtype 0x0004 - Change password.
|
|
145 *
|
|
146 */
|
13239
|
147 faim_export int aim_admin_changepasswd(OscarSession *sess, OscarConnection *conn, const char *newpw, const char *curpw)
|
13234
|
148 {
|
13239
|
149 FlapFrame *fr;
|
13234
|
150 aim_tlvlist_t *tl = NULL;
|
|
151 aim_snacid_t snacid;
|
|
152
|
13253
|
153 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw))))
|
13234
|
154 return -ENOMEM;
|
|
155
|
|
156 snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
|
|
157 aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid);
|
|
158
|
|
159 /* new password TLV t(0002) */
|
|
160 aim_tlvlist_add_str(&tl, 0x0002, newpw);
|
|
161
|
|
162 /* current password TLV t(0012) */
|
|
163 aim_tlvlist_add_str(&tl, 0x0012, curpw);
|
|
164
|
|
165 aim_tlvlist_write(&fr->data, &tl);
|
|
166 aim_tlvlist_free(&tl);
|
|
167
|
|
168 aim_tx_enqueue(sess, fr);
|
|
169
|
|
170 return 0;
|
|
171 }
|
|
172
|
|
173 /*
|
|
174 * Subtype 0x0004 - Change email address.
|
|
175 *
|
|
176 */
|
13239
|
177 faim_export int aim_admin_setemail(OscarSession *sess, OscarConnection *conn, const char *newemail)
|
13234
|
178 {
|
13239
|
179 FlapFrame *fr;
|
13234
|
180 aim_snacid_t snacid;
|
|
181 aim_tlvlist_t *tl = NULL;
|
|
182
|
13253
|
183 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail))))
|
13234
|
184 return -ENOMEM;
|
|
185
|
|
186 snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
|
|
187 aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid);
|
|
188
|
|
189 aim_tlvlist_add_str(&tl, 0x0011, newemail);
|
|
190
|
|
191 aim_tlvlist_write(&fr->data, &tl);
|
|
192 aim_tlvlist_free(&tl);
|
|
193
|
|
194 aim_tx_enqueue(sess, fr);
|
|
195
|
|
196 return 0;
|
|
197 }
|
|
198
|
|
199 /*
|
|
200 * Subtype 0x0006 - Request account confirmation.
|
|
201 *
|
|
202 * This will cause an email to be sent to the address associated with
|
|
203 * the account. By following the instructions in the mail, you can
|
|
204 * get the TRIAL flag removed from your account.
|
|
205 *
|
|
206 */
|
13239
|
207 faim_export int aim_admin_reqconfirm(OscarSession *sess, OscarConnection *conn)
|
13234
|
208 {
|
|
209 return aim_genericreq_n(sess, conn, 0x0007, 0x0006);
|
|
210 }
|
|
211
|
|
212 /*
|
|
213 * Subtype 0x0007 - Account confirmation request acknowledgement.
|
|
214 *
|
|
215 */
|
13239
|
216 static int accountconfirm(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
217 {
|
|
218 int ret = 0;
|
|
219 aim_rxcallback_t userfunc;
|
|
220 guint16 status;
|
|
221 aim_tlvlist_t *tl;
|
|
222
|
|
223 status = aimbs_get16(bs);
|
|
224 /* This is 0x0013 if unable to confirm at this time */
|
|
225
|
|
226 tl = aim_tlvlist_read(bs);
|
|
227
|
|
228 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
229 ret = userfunc(sess, rx, status);
|
|
230
|
|
231 return ret;
|
|
232 }
|
|
233
|
13239
|
234 static int snachandler(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
235 {
|
|
236
|
|
237 if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005))
|
|
238 return infochange(sess, mod, rx, snac, bs);
|
|
239 else if (snac->subtype == 0x0007)
|
|
240 return accountconfirm(sess, mod, rx, snac, bs);
|
|
241
|
|
242 return 0;
|
|
243 }
|
|
244
|
13239
|
245 faim_internal int admin_modfirst(OscarSession *sess, aim_module_t *mod)
|
13234
|
246 {
|
|
247
|
|
248 mod->family = 0x0007;
|
|
249 mod->version = 0x0001;
|
|
250 mod->toolid = 0x0010;
|
|
251 mod->toolversion = 0x0629;
|
|
252 mod->flags = 0;
|
|
253 strncpy(mod->name, "admin", sizeof(mod->name));
|
|
254 mod->snachandler = snachandler;
|
|
255
|
|
256 return 0;
|
|
257 }
|