1 | |
---|
2 | /* |
---|
3 | * aim_misc.c |
---|
4 | * |
---|
5 | * TODO: Seperate a lot of this into an aim_bos.c. |
---|
6 | * |
---|
7 | * Other things... |
---|
8 | * |
---|
9 | * - Idle setting |
---|
10 | * |
---|
11 | * |
---|
12 | */ |
---|
13 | |
---|
14 | #include <aim.h> |
---|
15 | |
---|
16 | /* |
---|
17 | * aim_bos_setprofile(profile) |
---|
18 | * |
---|
19 | * Gives BOS your profile. |
---|
20 | * |
---|
21 | */ |
---|
22 | int aim_bos_setprofile(aim_session_t *sess, aim_conn_t *conn, const char *profile, const char *awaymsg, guint32 caps) |
---|
23 | { |
---|
24 | static const char defencoding[] = { "text/aolrtf; charset=\"utf-8\"" }; |
---|
25 | aim_frame_t *fr; |
---|
26 | aim_tlvlist_t *tl = NULL; |
---|
27 | aim_snacid_t snacid; |
---|
28 | |
---|
29 | /* Build to packet first to get real length */ |
---|
30 | if (profile) { |
---|
31 | aim_addtlvtochain_raw(&tl, 0x0001, strlen(defencoding), (guint8 *) defencoding); |
---|
32 | aim_addtlvtochain_raw(&tl, 0x0002, strlen(profile), (guint8 *) profile); |
---|
33 | } |
---|
34 | |
---|
35 | /* |
---|
36 | * So here's how this works: |
---|
37 | * - You are away when you have a non-zero-length type 4 TLV stored. |
---|
38 | * - You become unaway when you clear the TLV with a zero-length |
---|
39 | * type 4 TLV. |
---|
40 | * - If you do not send the type 4 TLV, your status does not change |
---|
41 | * (that is, if you were away, you'll remain away). |
---|
42 | */ |
---|
43 | if (awaymsg) { |
---|
44 | if (strlen(awaymsg)) { |
---|
45 | aim_addtlvtochain_raw(&tl, 0x0003, strlen(defencoding), (guint8 *) defencoding); |
---|
46 | aim_addtlvtochain_raw(&tl, 0x0004, strlen(awaymsg), (guint8 *) awaymsg); |
---|
47 | } else { |
---|
48 | aim_addtlvtochain_noval(&tl, 0x0004); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | aim_addtlvtochain_caps(&tl, 0x0005, caps); |
---|
53 | |
---|
54 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_sizetlvchain(&tl)))) { |
---|
55 | return -ENOMEM; |
---|
56 | } |
---|
57 | |
---|
58 | snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0); |
---|
59 | |
---|
60 | aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid); |
---|
61 | aim_writetlvchain(&fr->data, &tl); |
---|
62 | aim_freetlvchain(&tl); |
---|
63 | |
---|
64 | aim_tx_enqueue(sess, fr); |
---|
65 | |
---|
66 | return 0; |
---|
67 | } |
---|
68 | |
---|
69 | /* |
---|
70 | * aim_bos_reqbuddyrights() |
---|
71 | * |
---|
72 | * Request Buddy List rights. |
---|
73 | * |
---|
74 | */ |
---|
75 | int aim_bos_reqbuddyrights(aim_session_t *sess, aim_conn_t *conn) |
---|
76 | { |
---|
77 | return aim_genericreq_n(sess, conn, 0x0003, 0x0002); |
---|
78 | } |
---|
79 | |
---|
80 | /* |
---|
81 | * Generic routine for sending commands. |
---|
82 | * |
---|
83 | * |
---|
84 | * I know I can do this in a smarter way...but I'm not thinking straight |
---|
85 | * right now... |
---|
86 | * |
---|
87 | * I had one big function that handled all three cases, but then it broke |
---|
88 | * and I split it up into three. But then I fixed it. I just never went |
---|
89 | * back to the single. I don't see any advantage to doing it either way. |
---|
90 | * |
---|
91 | */ |
---|
92 | int aim_genericreq_n(aim_session_t *sess, aim_conn_t *conn, guint16 family, guint16 subtype) |
---|
93 | { |
---|
94 | aim_frame_t *fr; |
---|
95 | aim_snacid_t snacid = 0x00000000; |
---|
96 | |
---|
97 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10))) { |
---|
98 | return -ENOMEM; |
---|
99 | } |
---|
100 | |
---|
101 | aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
---|
102 | |
---|
103 | aim_tx_enqueue(sess, fr); |
---|
104 | |
---|
105 | return 0; |
---|
106 | } |
---|
107 | |
---|
108 | int aim_genericreq_n_snacid(aim_session_t *sess, aim_conn_t *conn, guint16 family, guint16 subtype) |
---|
109 | { |
---|
110 | aim_frame_t *fr; |
---|
111 | aim_snacid_t snacid; |
---|
112 | |
---|
113 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10))) { |
---|
114 | return -ENOMEM; |
---|
115 | } |
---|
116 | |
---|
117 | snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
---|
118 | aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
---|
119 | |
---|
120 | aim_tx_enqueue(sess, fr); |
---|
121 | |
---|
122 | return 0; |
---|
123 | } |
---|
124 | |
---|
125 | int aim_genericreq_l(aim_session_t *sess, aim_conn_t *conn, guint16 family, guint16 subtype, guint32 *longdata) |
---|
126 | { |
---|
127 | aim_frame_t *fr; |
---|
128 | aim_snacid_t snacid; |
---|
129 | |
---|
130 | if (!longdata) { |
---|
131 | return aim_genericreq_n(sess, conn, family, subtype); |
---|
132 | } |
---|
133 | |
---|
134 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4))) { |
---|
135 | return -ENOMEM; |
---|
136 | } |
---|
137 | |
---|
138 | snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
---|
139 | |
---|
140 | aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
---|
141 | aimbs_put32(&fr->data, *longdata); |
---|
142 | |
---|
143 | aim_tx_enqueue(sess, fr); |
---|
144 | |
---|
145 | return 0; |
---|
146 | } |
---|
147 | |
---|
148 | int aim_genericreq_s(aim_session_t *sess, aim_conn_t *conn, guint16 family, guint16 subtype, guint16 *shortdata) |
---|
149 | { |
---|
150 | aim_frame_t *fr; |
---|
151 | aim_snacid_t snacid; |
---|
152 | |
---|
153 | if (!shortdata) { |
---|
154 | return aim_genericreq_n(sess, conn, family, subtype); |
---|
155 | } |
---|
156 | |
---|
157 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2))) { |
---|
158 | return -ENOMEM; |
---|
159 | } |
---|
160 | |
---|
161 | snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0); |
---|
162 | |
---|
163 | aim_putsnac(&fr->data, family, subtype, 0x0000, snacid); |
---|
164 | aimbs_put16(&fr->data, *shortdata); |
---|
165 | |
---|
166 | aim_tx_enqueue(sess, fr); |
---|
167 | |
---|
168 | return 0; |
---|
169 | } |
---|
170 | |
---|
171 | /* |
---|
172 | * aim_bos_reqlocaterights() |
---|
173 | * |
---|
174 | * Request Location services rights. |
---|
175 | * |
---|
176 | */ |
---|
177 | int aim_bos_reqlocaterights(aim_session_t *sess, aim_conn_t *conn) |
---|
178 | { |
---|
179 | return aim_genericreq_n(sess, conn, 0x0002, 0x0002); |
---|
180 | } |
---|
181 | |
---|
182 | /* |
---|
183 | * Should be generic enough to handle the errors for all groups. |
---|
184 | * |
---|
185 | */ |
---|
186 | static int generror(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
187 | { |
---|
188 | int ret = 0; |
---|
189 | int error = 0; |
---|
190 | aim_rxcallback_t userfunc; |
---|
191 | aim_snac_t *snac2; |
---|
192 | |
---|
193 | snac2 = aim_remsnac(sess, snac->id); |
---|
194 | |
---|
195 | if (aim_bstream_empty(bs)) { |
---|
196 | error = aimbs_get16(bs); |
---|
197 | } |
---|
198 | |
---|
199 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
200 | ret = userfunc(sess, rx, error, snac2 ? snac2->data : NULL); |
---|
201 | } |
---|
202 | |
---|
203 | if (snac2) { |
---|
204 | g_free(snac2->data); |
---|
205 | } |
---|
206 | g_free(snac2); |
---|
207 | |
---|
208 | return ret; |
---|
209 | } |
---|
210 | |
---|
211 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
212 | { |
---|
213 | |
---|
214 | if (snac->subtype == 0x0001) { |
---|
215 | return generror(sess, mod, rx, snac, bs); |
---|
216 | } else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) { |
---|
217 | aim_rxcallback_t userfunc; |
---|
218 | |
---|
219 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
220 | return userfunc(sess, rx); |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | return 0; |
---|
225 | } |
---|
226 | |
---|
227 | int misc_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
228 | { |
---|
229 | |
---|
230 | mod->family = 0xffff; |
---|
231 | mod->version = 0x0000; |
---|
232 | mod->flags = AIM_MODFLAG_MULTIFAMILY; |
---|
233 | strncpy(mod->name, "misc", sizeof(mod->name)); |
---|
234 | mod->snachandler = snachandler; |
---|
235 | |
---|
236 | return 0; |
---|
237 | } |
---|
238 | |
---|
239 | |
---|