rename accountopt.[ch] to purpleaccountoption.[ch]
[pidgin-git.git] / libpurple / protocols / oscar / family_admin.c
blobd199a789c10c0c64cfc056d810fed337af268303
1 /*
2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * Family 0x0007 - Account Administration.
24 * Used for stuff like changing the formating of your username, changing your
25 * email address, requesting an account confirmation email, getting account info,
28 #include "oscar.h"
30 /**
31 * Subtype 0x0002 - Request a bit of account info.
33 * Info should be one of the following:
34 * 0x0001 - Username formatting
35 * 0x0011 - Email address
36 * 0x0013 - Unknown
38 void
39 aim_admin_getinfo(OscarData *od, FlapConnection *conn, guint16 info)
41 ByteStream bs;
42 aim_snacid_t snacid;
44 byte_stream_new(&bs, 4);
46 byte_stream_put16(&bs, info);
47 byte_stream_put16(&bs, 0x0000);
49 snacid = aim_cachesnac(od, SNAC_FAMILY_ADMIN, 0x0002, 0x0000, NULL, 0);
50 flap_connection_send_snac(od, conn, SNAC_FAMILY_ADMIN, 0x0002, snacid, &bs);
52 byte_stream_destroy(&bs);
55 /**
56 * Subtypes 0x0003 and 0x0005 - Parse account info.
58 * Called in reply to both an information request (subtype 0x0002) and
59 * an information change (subtype 0x0004).
61 static void
62 infochange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
64 aim_rxcallback_t userfunc;
65 char *url=NULL, *sn=NULL, *email=NULL;
66 guint16 perms, tlvcount, err=0;
68 perms = byte_stream_get16(bs);
69 tlvcount = byte_stream_get16(bs);
71 while (tlvcount && byte_stream_bytes_left(bs)) {
72 guint16 type, length;
74 type = byte_stream_get16(bs);
75 length = byte_stream_get16(bs);
77 switch (type) {
78 case 0x0001: {
79 g_free(sn);
80 sn = byte_stream_getstr(bs, length);
81 } break;
83 case 0x0004: {
84 g_free(url);
85 url = byte_stream_getstr(bs, length);
86 } break;
88 case 0x0008: {
89 err = byte_stream_get16(bs);
90 } break;
92 case 0x0011: {
93 g_free(email);
94 if (length == 0)
95 email = g_strdup("*suppressed");
96 else
97 email = byte_stream_getstr(bs, length);
98 } break;
101 tlvcount--;
104 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
105 userfunc(od, conn, frame, (snac->subtype == 0x0005) ? 1 : 0, perms, err, url, sn, email);
107 g_free(sn);
108 g_free(url);
109 g_free(email);
113 * Subtype 0x0004 - Set the formatting of username (change spaces and capitalization).
115 void
116 aim_admin_setnick(OscarData *od, FlapConnection *conn, const char *newnick)
118 ByteStream bs;
119 aim_snacid_t snacid;
120 GSList *tlvlist = NULL;
122 byte_stream_new(&bs, 2+2+strlen(newnick));
124 aim_tlvlist_add_str(&tlvlist, 0x0001, newnick);
126 aim_tlvlist_write(&bs, &tlvlist);
127 aim_tlvlist_free(tlvlist);
129 snacid = aim_cachesnac(od, SNAC_FAMILY_ADMIN, 0x0004, 0x0000, NULL, 0);
130 flap_connection_send_snac(od, conn, SNAC_FAMILY_ADMIN, 0x0004, snacid, &bs);
132 byte_stream_destroy(&bs);
136 * Subtype 0x0004 - Change password.
138 void
139 aim_admin_changepasswd(OscarData *od, FlapConnection *conn, const char *newpw, const char *curpw)
141 ByteStream bs;
142 GSList *tlvlist = NULL;
143 aim_snacid_t snacid;
145 byte_stream_new(&bs, 4+strlen(curpw)+4+strlen(newpw));
147 /* new password TLV t(0002) */
148 aim_tlvlist_add_str(&tlvlist, 0x0002, newpw);
150 /* current password TLV t(0012) */
151 aim_tlvlist_add_str(&tlvlist, 0x0012, curpw);
153 aim_tlvlist_write(&bs, &tlvlist);
154 aim_tlvlist_free(tlvlist);
156 snacid = aim_cachesnac(od, SNAC_FAMILY_ADMIN, 0x0004, 0x0000, NULL, 0);
157 flap_connection_send_snac(od, conn, SNAC_FAMILY_ADMIN, 0x0004, snacid, &bs);
159 byte_stream_destroy(&bs);
163 * Subtype 0x0004 - Change email address.
165 void
166 aim_admin_setemail(OscarData *od, FlapConnection *conn, const char *newemail)
168 ByteStream bs;
169 aim_snacid_t snacid;
170 GSList *tlvlist = NULL;
172 byte_stream_new(&bs, 2+2+strlen(newemail));
174 aim_tlvlist_add_str(&tlvlist, 0x0011, newemail);
176 aim_tlvlist_write(&bs, &tlvlist);
177 aim_tlvlist_free(tlvlist);
179 snacid = aim_cachesnac(od, SNAC_FAMILY_ADMIN, 0x0004, 0x0000, NULL, 0);
180 flap_connection_send_snac(od, conn, SNAC_FAMILY_ADMIN, 0x0004, snacid, &bs);
182 byte_stream_destroy(&bs);
186 * Subtype 0x0006 - Request account confirmation.
188 * This will cause an email to be sent to the address associated with
189 * the account. By following the instructions in the mail, you can
190 * get the TRIAL flag removed from your account.
193 void
194 aim_admin_reqconfirm(OscarData *od, FlapConnection *conn)
196 aim_genericreq_n(od, conn, SNAC_FAMILY_ADMIN, 0x0006);
200 * Subtype SNAC_FAMILY_ADMIN - Account confirmation request acknowledgement.
202 static int
203 accountconfirm(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
205 int ret = 0;
206 aim_rxcallback_t userfunc;
207 guint16 status;
208 /* GSList *tlvlist; */
210 status = byte_stream_get16(bs);
211 /* Status is 0x0013 if unable to confirm at this time */
213 /* tlvlist = aim_tlvlist_read(bs); */
215 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
216 ret = userfunc(od, conn, frame, status);
218 /* aim_tlvlist_free(tlvlist); */
220 return ret;
223 static int
224 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
226 if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005)) {
227 infochange(od, conn, mod, frame, snac, bs);
228 return 1;
229 } else if (snac->subtype == SNAC_FAMILY_ADMIN)
230 return accountconfirm(od, conn, mod, frame, snac, bs);
232 return 0;
235 int admin_modfirst(OscarData *od, aim_module_t *mod)
237 mod->family = SNAC_FAMILY_ADMIN;
238 mod->version = 0x0001;
239 mod->toolid = 0x0010;
240 mod->toolversion = 0x0629;
241 mod->flags = 0;
242 strncpy(mod->name, "admin", sizeof(mod->name));
243 mod->snachandler = snachandler;
245 return 0;