]> andersk Git - libfaim.git/blob - src/admin.c
- Sun Oct 14 19:45:54 PDT 2001
[libfaim.git] / src / admin.c
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 = 0x0000;
81         mod->flags = 0;
82         strncpy(mod->name, "admin", sizeof(mod->name));
83         mod->snachandler = snachandler;
84
85         return 0;
86 }
87
88 faim_export int aim_auth_clientready(aim_session_t *sess, aim_conn_t *conn)
89 {
90         static const struct aim_tool_version tools[] = {
91                 {0x0001, 0x0003,    AIM_TOOL_NEWWIN, 0x0361},
92                 {0x0007, 0x0001,    AIM_TOOL_NEWWIN, 0x0361},
93         };
94         int j;
95         aim_frame_t *tx;
96         int toolcount = sizeof(tools) / sizeof(struct aim_tool_version);
97         aim_snacid_t snacid;
98
99         if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0002, 1152)))
100                 return -ENOMEM;
101
102         snacid = aim_cachesnac(sess, 0x0001, 0x0002, 0x0000, NULL, 0);
103         aim_putsnac(&tx->data, 0x0001, 0x0002, 0x0000, snacid);
104
105         for (j = 0; j < toolcount; j++) {
106                 aimbs_put16(&tx->data, tools[j].group);
107                 aimbs_put16(&tx->data, tools[j].version);
108                 aimbs_put16(&tx->data, tools[j].tool);
109                 aimbs_put16(&tx->data, tools[j].toolversion);
110         }
111
112         aim_tx_enqueue(sess, tx);
113
114         return 0;
115 }
116
117 faim_export int aim_auth_changepasswd(aim_session_t *sess, aim_conn_t *conn, const char *newpw, const char *curpw)
118 {
119         aim_frame_t *tx;
120         aim_tlvlist_t *tl = NULL;
121         aim_snacid_t snacid;
122
123         if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw))))
124                 return -ENOMEM;
125
126         snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
127         aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid);
128
129         /* new password TLV t(0002) */
130         aim_addtlvtochain_raw(&tl, 0x0002, strlen(newpw), newpw);
131
132         /* current password TLV t(0012) */
133         aim_addtlvtochain_raw(&tl, 0x0012, strlen(curpw), curpw);
134
135         aim_writetlvchain(&tx->data, &tl);
136         aim_freetlvchain(&tl);
137
138         aim_tx_enqueue(sess, tx);
139
140         return 0;
141 }
142
143 faim_export int aim_auth_setversions(aim_session_t *sess, aim_conn_t *conn)
144 {
145         aim_frame_t *tx;
146         aim_snacid_t snacid;
147
148         if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 18)))
149                 return -ENOMEM;
150
151         snacid = aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0);
152         aim_putsnac(&tx->data, 0x0001, 0x0017, 0x0000, snacid);
153
154         aimbs_put16(&tx->data, 0x0001);
155         aimbs_put16(&tx->data, 0x0003);
156
157         aimbs_put16(&tx->data, 0x0007);
158         aimbs_put16(&tx->data, 0x0001);
159
160         aim_tx_enqueue(sess, tx);
161
162         return 0;
163 }
164
165 /*
166  * Request account confirmation. 
167  *
168  * This will cause an email to be sent to the address associated with
169  * the account.  By following the instructions in the mail, you can
170  * get the TRIAL flag removed from your account.
171  *
172  */
173 faim_export int aim_auth_reqconfirm(aim_session_t *sess, aim_conn_t *conn)
174 {
175         return aim_genericreq_n(sess, conn, 0x0007, 0x0006);
176 }
177
178 /*
179  * Request a bit of account info.
180  *
181  * The only known valid tag is 0x0011 (email address).
182  *
183  */ 
184 faim_export int aim_auth_getinfo(aim_session_t *sess, aim_conn_t *conn, fu16_t info)
185 {
186         aim_frame_t *tx;
187         aim_snacid_t snacid;
188
189         if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14)))
190                 return -ENOMEM;
191
192         snacid = aim_cachesnac(sess, 0x0002, 0x0002, 0x0000, NULL, 0);
193         aim_putsnac(&tx->data, 0x0007, 0x0002, 0x0000, snacid);
194
195         aimbs_put16(&tx->data, info);
196         aimbs_put16(&tx->data, 0x0000);
197
198         aim_tx_enqueue(sess, tx);
199
200         return 0;
201 }
202
203 faim_export int aim_auth_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail)
204 {
205         aim_frame_t *tx;
206         aim_snacid_t snacid;
207         aim_tlvlist_t *tl = NULL;
208
209         if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail))))
210                 return -ENOMEM;
211
212         snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
213         aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid);
214
215         aim_addtlvtochain_raw(&tl, 0x0011, strlen(newemail), newemail);
216         
217         aim_writetlvchain(&tx->data, &tl);
218         aim_freetlvchain(&tl);
219         
220         aim_tx_enqueue(sess, tx);
221
222         return 0;
223 }
This page took 0.04905 seconds and 5 git commands to generate.