source: libfaim/admin.c @ 35b6eb9

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 35b6eb9 was cf02dd6, checked in by James M. Kretchmar <kretch@mit.edu>, 20 years ago
*** empty log message ***
  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Family 0x0007 - Account Administration.
3 *
4 * Used for stuff like changing the formating of your screen name, changing your
5 * email address, requesting an account confirmation email, getting account info,
6 *
7 */
8
9#define FAIM_INTERNAL
10#include <aim.h>
11
12/*
13 * Subtype 0x0002 - Request a bit of account info.
14 *
15 * Info should be one of the following:
16 * 0x0001 - Screen name formatting
17 * 0x0011 - Email address
18 * 0x0013 - Unknown
19 *
20 */ 
21faim_export int aim_admin_getinfo(aim_session_t *sess, aim_conn_t *conn, fu16_t info)
22{
23        aim_frame_t *fr;
24        aim_snacid_t snacid;
25
26        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14)))
27                return -ENOMEM;
28
29        snacid = aim_cachesnac(sess, 0x0007, 0x0002, 0x0000, NULL, 0);
30        aim_putsnac(&fr->data, 0x0007, 0x0002, 0x0000, snacid);
31
32        aimbs_put16(&fr->data, info);
33        aimbs_put16(&fr->data, 0x0000);
34
35        aim_tx_enqueue(sess, fr);
36
37        return 0;
38}
39
40/*
41 * Subtypes 0x0003 and 0x0005 - Parse account info.
42 *
43 * Called in reply to both an information request (subtype 0x0002) and
44 * an information change (subtype 0x0004).
45 *
46 */
47static int infochange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
48{
49        aim_rxcallback_t userfunc;
50        char *url=NULL, *sn=NULL, *email=NULL;
51        fu16_t perms, tlvcount, err=0;
52
53        perms = aimbs_get16(bs);
54        tlvcount = aimbs_get16(bs);
55
56        while (tlvcount && aim_bstream_empty(bs)) {
57                fu16_t type, length;
58
59                type = aimbs_get16(bs);
60                length = aimbs_get16(bs);
61
62                switch (type) {
63                        case 0x0001: {
64                                sn = aimbs_getstr(bs, length);
65                        } break;
66
67                        case 0x0004: {
68                                url = aimbs_getstr(bs, length);
69                        } break;
70
71                        case 0x0008: {
72                                err = aimbs_get16(bs);
73                        } break;
74
75                        case 0x0011: {
76                                if (length == 0) {
77                                        email = (char*)malloc(13*sizeof(char));
78                                        strcpy(email, "*suppressed*");
79                                } else
80                                        email = aimbs_getstr(bs, length);
81                        } break;
82                }
83
84                tlvcount--;
85        }
86
87        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
88                userfunc(sess, rx, (snac->subtype == 0x0005) ? 1 : 0, perms, err, url, sn, email);
89
90        if (sn) free(sn);
91        if (url) free(url);
92        if (email) free(email);
93
94        return 1;
95}
96
97/*
98 * Subtype 0x0004 - Set screenname formatting.
99 *
100 */
101faim_export int aim_admin_setnick(aim_session_t *sess, aim_conn_t *conn, const char *newnick)
102{
103        aim_frame_t *fr;
104        aim_snacid_t snacid;
105        aim_tlvlist_t *tl = NULL;
106
107        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newnick))))
108                return -ENOMEM;
109
110        snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
111        aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid);
112
113        aim_tlvlist_add_raw(&tl, 0x0001, strlen(newnick), newnick);
114       
115        aim_tlvlist_write(&fr->data, &tl);
116        aim_tlvlist_free(&tl);
117       
118        aim_tx_enqueue(sess, fr);
119
120
121        return 0;
122}
123
124/*
125 * Subtype 0x0004 - Change password.
126 *
127 */
128faim_export int aim_admin_changepasswd(aim_session_t *sess, aim_conn_t *conn, const char *newpw, const char *curpw)
129{
130        aim_frame_t *fr;
131        aim_tlvlist_t *tl = NULL;
132        aim_snacid_t snacid;
133
134        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw))))
135                return -ENOMEM;
136
137        snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
138        aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid);
139
140        /* new password TLV t(0002) */
141        aim_tlvlist_add_raw(&tl, 0x0002, strlen(newpw), newpw);
142
143        /* current password TLV t(0012) */
144        aim_tlvlist_add_raw(&tl, 0x0012, strlen(curpw), curpw);
145
146        aim_tlvlist_write(&fr->data, &tl);
147        aim_tlvlist_free(&tl);
148
149        aim_tx_enqueue(sess, fr);
150
151        return 0;
152}
153
154/*
155 * Subtype 0x0004 - Change email address.
156 *
157 */
158faim_export int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail)
159{
160        aim_frame_t *fr;
161        aim_snacid_t snacid;
162        aim_tlvlist_t *tl = NULL;
163
164        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail))))
165                return -ENOMEM;
166
167        snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
168        aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid);
169
170        aim_tlvlist_add_raw(&tl, 0x0011, strlen(newemail), newemail);
171       
172        aim_tlvlist_write(&fr->data, &tl);
173        aim_tlvlist_free(&tl);
174       
175        aim_tx_enqueue(sess, fr);
176
177        return 0;
178}
179
180/*
181 * Subtype 0x0006 - Request account confirmation.
182 *
183 * This will cause an email to be sent to the address associated with
184 * the account.  By following the instructions in the mail, you can
185 * get the TRIAL flag removed from your account.
186 *
187 */
188faim_export int aim_admin_reqconfirm(aim_session_t *sess, aim_conn_t *conn)
189{
190        return aim_genericreq_n(sess, conn, 0x0007, 0x0006);
191}
192
193/*
194 * Subtype 0x0007 - Account confirmation request acknowledgement.
195 *
196 */
197static int accountconfirm(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
198{
199        int ret = 0;
200        aim_rxcallback_t userfunc;
201        fu16_t status;
202        aim_tlvlist_t *tl;
203
204        status = aimbs_get16(bs);
205        /* This is 0x0013 if unable to confirm at this time */
206
207        tl = aim_tlvlist_read(bs);
208
209        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
210                ret = userfunc(sess, rx, status);
211
212        return ret;
213}
214
215static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
216{
217
218        if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005))
219                return infochange(sess, mod, rx, snac, bs);
220        else if (snac->subtype == 0x0007)
221                return accountconfirm(sess, mod, rx, snac, bs);
222
223        return 0;
224}
225
226faim_internal int admin_modfirst(aim_session_t *sess, aim_module_t *mod)
227{
228
229        mod->family = 0x0007;
230        mod->version = 0x0001;
231        mod->toolid = 0x0010;
232        mod->toolversion = 0x0629;
233        mod->flags = 0;
234        strncpy(mod->name, "admin", sizeof(mod->name));
235        mod->snachandler = snachandler;
236
237        return 0;
238}
Note: See TracBrowser for help on using the repository browser.