1 | |
---|
2 | #define FAIM_INTERNAL |
---|
3 | #include <aim.h> |
---|
4 | |
---|
5 | /* called for both reply and change-reply */ |
---|
6 | static int infochange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
7 | { |
---|
8 | |
---|
9 | /* |
---|
10 | * struct { |
---|
11 | * unsigned short perms; |
---|
12 | * unsigned short tlvcount; |
---|
13 | * aim_tlv_t tlvs[tlvcount]; |
---|
14 | * } admin_info[n]; |
---|
15 | */ |
---|
16 | while (aim_bstream_empty(bs)) { |
---|
17 | fu16_t perms, tlvcount; |
---|
18 | |
---|
19 | perms = aimbs_get16(bs); |
---|
20 | tlvcount = aimbs_get16(bs); |
---|
21 | |
---|
22 | while (tlvcount && aim_bstream_empty(bs)) { |
---|
23 | aim_rxcallback_t userfunc; |
---|
24 | fu16_t type, len; |
---|
25 | fu8_t *val; |
---|
26 | int str = 0; |
---|
27 | |
---|
28 | type = aimbs_get16(bs); |
---|
29 | len = aimbs_get16(bs); |
---|
30 | |
---|
31 | if ((type == 0x0011) || (type == 0x0004)) |
---|
32 | str = 1; |
---|
33 | |
---|
34 | if (str) |
---|
35 | val = aimbs_getstr(bs, len); |
---|
36 | else |
---|
37 | val = aimbs_getraw(bs, len); |
---|
38 | |
---|
39 | /* XXX fix so its only called once for the entire packet */ |
---|
40 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
41 | userfunc(sess, rx, (snac->subtype == 0x0005) ? 1 : 0, perms, type, len, val, str); |
---|
42 | |
---|
43 | free(val); |
---|
44 | |
---|
45 | tlvcount--; |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | return 1; |
---|
50 | } |
---|
51 | |
---|
52 | static int accountconfirm(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
53 | { |
---|
54 | aim_rxcallback_t userfunc; |
---|
55 | fu16_t status; |
---|
56 | |
---|
57 | status = aimbs_get16(bs); |
---|
58 | |
---|
59 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
60 | return userfunc(sess, rx, status); |
---|
61 | |
---|
62 | return 0; |
---|
63 | } |
---|
64 | |
---|
65 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
66 | { |
---|
67 | |
---|
68 | if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005)) |
---|
69 | return infochange(sess, mod, rx, snac, bs); |
---|
70 | else if (snac->subtype == 0x0007) |
---|
71 | return accountconfirm(sess, mod, rx, snac, bs); |
---|
72 | |
---|
73 | return 0; |
---|
74 | } |
---|
75 | |
---|
76 | faim_internal int admin_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
77 | { |
---|
78 | |
---|
79 | mod->family = 0x0007; |
---|
80 | mod->version = 0x0001; |
---|
81 | mod->toolid = AIM_TOOL_NEWWIN; |
---|
82 | mod->toolversion = 0x0361; /* XXX this and above aren't right */ |
---|
83 | mod->flags = 0; |
---|
84 | strncpy(mod->name, "admin", sizeof(mod->name)); |
---|
85 | mod->snachandler = snachandler; |
---|
86 | |
---|
87 | return 0; |
---|
88 | } |
---|
89 | |
---|
90 | faim_export int aim_admin_changepasswd(aim_session_t *sess, aim_conn_t *conn, const char *newpw, const char *curpw) |
---|
91 | { |
---|
92 | aim_frame_t *tx; |
---|
93 | aim_tlvlist_t *tl = NULL; |
---|
94 | aim_snacid_t snacid; |
---|
95 | |
---|
96 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw)))) |
---|
97 | return -ENOMEM; |
---|
98 | |
---|
99 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
100 | aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
101 | |
---|
102 | /* new password TLV t(0002) */ |
---|
103 | aim_addtlvtochain_raw(&tl, 0x0002, strlen(newpw), newpw); |
---|
104 | |
---|
105 | /* current password TLV t(0012) */ |
---|
106 | aim_addtlvtochain_raw(&tl, 0x0012, strlen(curpw), curpw); |
---|
107 | |
---|
108 | aim_writetlvchain(&tx->data, &tl); |
---|
109 | aim_freetlvchain(&tl); |
---|
110 | |
---|
111 | aim_tx_enqueue(sess, tx); |
---|
112 | |
---|
113 | return 0; |
---|
114 | } |
---|
115 | |
---|
116 | /* |
---|
117 | * Request account confirmation. |
---|
118 | * |
---|
119 | * This will cause an email to be sent to the address associated with |
---|
120 | * the account. By following the instructions in the mail, you can |
---|
121 | * get the TRIAL flag removed from your account. |
---|
122 | * |
---|
123 | */ |
---|
124 | faim_export int aim_admin_reqconfirm(aim_session_t *sess, aim_conn_t *conn) |
---|
125 | { |
---|
126 | return aim_genericreq_n(sess, conn, 0x0007, 0x0006); |
---|
127 | } |
---|
128 | |
---|
129 | /* |
---|
130 | * Request a bit of account info. |
---|
131 | * |
---|
132 | * The only known valid tag is 0x0011 (email address). |
---|
133 | * |
---|
134 | */ |
---|
135 | faim_export int aim_admin_getinfo(aim_session_t *sess, aim_conn_t *conn, fu16_t info) |
---|
136 | { |
---|
137 | aim_frame_t *tx; |
---|
138 | aim_snacid_t snacid; |
---|
139 | |
---|
140 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14))) |
---|
141 | return -ENOMEM; |
---|
142 | |
---|
143 | snacid = aim_cachesnac(sess, 0x0002, 0x0002, 0x0000, NULL, 0); |
---|
144 | aim_putsnac(&tx->data, 0x0007, 0x0002, 0x0000, snacid); |
---|
145 | |
---|
146 | aimbs_put16(&tx->data, info); |
---|
147 | aimbs_put16(&tx->data, 0x0000); |
---|
148 | |
---|
149 | aim_tx_enqueue(sess, tx); |
---|
150 | |
---|
151 | return 0; |
---|
152 | } |
---|
153 | |
---|
154 | faim_export int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail) |
---|
155 | { |
---|
156 | aim_frame_t *tx; |
---|
157 | aim_snacid_t snacid; |
---|
158 | aim_tlvlist_t *tl = NULL; |
---|
159 | |
---|
160 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail)))) |
---|
161 | return -ENOMEM; |
---|
162 | |
---|
163 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
164 | aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
165 | |
---|
166 | aim_addtlvtochain_raw(&tl, 0x0011, strlen(newemail), newemail); |
---|
167 | |
---|
168 | aim_writetlvchain(&tx->data, &tl); |
---|
169 | aim_freetlvchain(&tl); |
---|
170 | |
---|
171 | aim_tx_enqueue(sess, tx); |
---|
172 | |
---|
173 | return 0; |
---|
174 | } |
---|
175 | |
---|
176 | faim_export int aim_admin_setnick(aim_session_t *sess, aim_conn_t *conn, const char *newnick) |
---|
177 | { |
---|
178 | aim_frame_t *tx; |
---|
179 | aim_snacid_t snacid; |
---|
180 | aim_tlvlist_t *tl = NULL; |
---|
181 | |
---|
182 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newnick)))) |
---|
183 | return -ENOMEM; |
---|
184 | |
---|
185 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
186 | aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
187 | |
---|
188 | aim_addtlvtochain_raw(&tl, 0x0001, strlen(newnick), newnick); |
---|
189 | |
---|
190 | aim_writetlvchain(&tx->data, &tl); |
---|
191 | aim_freetlvchain(&tl); |
---|
192 | |
---|
193 | aim_tx_enqueue(sess, tx); |
---|
194 | |
---|
195 | return 0; |
---|
196 | } |
---|
197 | |
---|