source: protocols/oscar/misc.c @ be1efa3

Last change on this file since be1efa3 was 6042a54, checked in by Wilmer van der Gaast <wilmer@…>, at 2012-10-19T23:38:33Z

Massive cleanup in OSCAR.

  • Property mode set to 100644
File size: 5.3 KB
Line 
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 */
22int 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        aim_addtlvtochain_caps(&tl, 0x0005, caps);
52
53        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_sizetlvchain(&tl))))
54                return -ENOMEM;
55
56        snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0);
57       
58        aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid);
59        aim_writetlvchain(&fr->data, &tl);
60        aim_freetlvchain(&tl);
61
62        aim_tx_enqueue(sess, fr);
63
64        return 0;
65}
66
67/*
68 * aim_bos_reqbuddyrights()
69 *
70 * Request Buddy List rights.
71 *
72 */
73int aim_bos_reqbuddyrights(aim_session_t *sess, aim_conn_t *conn)
74{
75        return aim_genericreq_n(sess, conn, 0x0003, 0x0002);
76}
77
78/*
79 * Generic routine for sending commands.
80 *
81 *
82 * I know I can do this in a smarter way...but I'm not thinking straight
83 * right now...
84 *
85 * I had one big function that handled all three cases, but then it broke
86 * and I split it up into three.  But then I fixed it.  I just never went
87 * back to the single.  I don't see any advantage to doing it either way.
88 *
89 */
90int aim_genericreq_n(aim_session_t *sess, aim_conn_t *conn, guint16 family, guint16 subtype)
91{
92        aim_frame_t *fr;
93        aim_snacid_t snacid = 0x00000000;
94
95        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10)))
96                return -ENOMEM;
97
98        aim_putsnac(&fr->data, family, subtype, 0x0000, snacid);
99
100        aim_tx_enqueue(sess, fr);
101
102        return 0;
103}
104
105int aim_genericreq_n_snacid(aim_session_t *sess, aim_conn_t *conn, guint16 family, guint16 subtype)
106{
107        aim_frame_t *fr;
108        aim_snacid_t snacid;
109
110        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10)))
111                return -ENOMEM;
112
113        snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0);
114        aim_putsnac(&fr->data, family, subtype, 0x0000, snacid);
115
116        aim_tx_enqueue(sess, fr);
117
118        return 0;
119}
120
121int aim_genericreq_l(aim_session_t *sess, aim_conn_t *conn, guint16 family, guint16 subtype, guint32 *longdata)
122{
123        aim_frame_t *fr;
124        aim_snacid_t snacid;
125
126        if (!longdata)
127                return aim_genericreq_n(sess, conn, family, subtype);
128
129        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4)))
130                return -ENOMEM; 
131
132        snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0);
133
134        aim_putsnac(&fr->data, family, subtype, 0x0000, snacid);
135        aimbs_put32(&fr->data, *longdata);
136
137        aim_tx_enqueue(sess, fr);
138
139        return 0;
140}
141
142int aim_genericreq_s(aim_session_t *sess, aim_conn_t *conn, guint16 family, guint16 subtype, guint16 *shortdata)
143{
144        aim_frame_t *fr;
145        aim_snacid_t snacid;
146
147        if (!shortdata)
148                return aim_genericreq_n(sess, conn, family, subtype);
149
150        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2)))
151                return -ENOMEM; 
152
153        snacid = aim_cachesnac(sess, family, subtype, 0x0000, NULL, 0);
154
155        aim_putsnac(&fr->data, family, subtype, 0x0000, snacid);
156        aimbs_put16(&fr->data, *shortdata);
157
158        aim_tx_enqueue(sess, fr);
159
160        return 0;
161}
162
163/*
164 * aim_bos_reqlocaterights()
165 *
166 * Request Location services rights.
167 *
168 */
169int aim_bos_reqlocaterights(aim_session_t *sess, aim_conn_t *conn)
170{
171        return aim_genericreq_n(sess, conn, 0x0002, 0x0002);
172}
173
174/*
175 * Should be generic enough to handle the errors for all groups.
176 *
177 */
178static int generror(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
179{
180        int ret = 0;
181        int error = 0;
182        aim_rxcallback_t userfunc;
183        aim_snac_t *snac2;
184
185        snac2 = aim_remsnac(sess, snac->id);
186
187        if (aim_bstream_empty(bs))
188                error = aimbs_get16(bs);
189
190        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
191                ret = userfunc(sess, rx, error, snac2 ? snac2->data : NULL);
192
193        if (snac2)
194                g_free(snac2->data);
195        g_free(snac2);
196
197        return ret;
198}
199
200static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
201{
202
203        if (snac->subtype == 0x0001)
204                return generror(sess, mod, rx, snac, bs);
205        else if ((snac->family == 0xffff) && (snac->subtype == 0xffff)) {
206                aim_rxcallback_t userfunc;
207
208                if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
209                        return userfunc(sess, rx);
210        }
211
212        return 0;
213}
214
215int misc_modfirst(aim_session_t *sess, aim_module_t *mod)
216{
217
218        mod->family = 0xffff;
219        mod->version = 0x0000;
220        mod->flags = AIM_MODFLAG_MULTIFAMILY;
221        strncpy(mod->name, "misc", sizeof(mod->name));
222        mod->snachandler = snachandler;
223
224        return 0;
225}
226
227
Note: See TracBrowser for help on using the repository browser.