source: protocols/oscar/bos.c @ 4c225f0

Last change on this file since 4c225f0 was b7d3cc34, checked in by Wilmer van der Gaast <wilmer@…>, at 2005-11-06T18:23:18Z

Initial repository (0.99 release tree)

  • Property mode set to 100644
File size: 4.3 KB
Line 
1#include <aim.h>
2#include "bos.h"
3
4/* Request BOS rights (group 9, type 2) */
5int aim_bos_reqrights(aim_session_t *sess, aim_conn_t *conn)
6{
7        return aim_genericreq_n(sess, conn, 0x0009, 0x0002);
8}
9
10/* BOS Rights (group 9, type 3) */
11static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
12{
13        aim_rxcallback_t userfunc;
14        aim_tlvlist_t *tlvlist;
15        guint16 maxpermits = 0, maxdenies = 0;
16        int ret = 0;
17
18        /*
19         * TLVs follow
20         */
21        tlvlist = aim_readtlvchain(bs);
22
23        /*
24         * TLV type 0x0001: Maximum number of buddies on permit list.
25         */
26        if (aim_gettlv(tlvlist, 0x0001, 1))
27                maxpermits = aim_gettlv16(tlvlist, 0x0001, 1);
28
29        /*
30         * TLV type 0x0002: Maximum number of buddies on deny list.
31         */
32        if (aim_gettlv(tlvlist, 0x0002, 1)) 
33                maxdenies = aim_gettlv16(tlvlist, 0x0002, 1);
34
35        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
36                ret = userfunc(sess, rx, maxpermits, maxdenies);
37
38        aim_freetlvchain(&tlvlist);
39
40        return ret; 
41}
42
43/*
44 * Set group permisson mask (group 9, type 4)
45 *
46 * Normally 0x1f (all classes).
47 *
48 * The group permission mask allows you to keep users of a certain
49 * class or classes from talking to you.  The mask should be
50 * a bitwise OR of all the user classes you want to see you.
51 *
52 */
53int aim_bos_setgroupperm(aim_session_t *sess, aim_conn_t *conn, guint32 mask)
54{
55        return aim_genericreq_l(sess, conn, 0x0009, 0x0004, &mask);
56}
57
58/*
59 * Modify permit/deny lists (group 9, types 5, 6, 7, and 8)
60 *
61 * Changes your visibility depending on changetype:
62 *
63 *  AIM_VISIBILITYCHANGE_PERMITADD: Lets provided list of names see you
64 *  AIM_VISIBILITYCHANGE_PERMIDREMOVE: Removes listed names from permit list
65 *  AIM_VISIBILITYCHANGE_DENYADD: Hides you from provided list of names
66 *  AIM_VISIBILITYCHANGE_DENYREMOVE: Lets list see you again
67 *
68 * list should be a list of
69 * screen names in the form "Screen Name One&ScreenNameTwo&" etc.
70 *
71 * Equivelents to options in WinAIM:
72 *   - Allow all users to contact me: Send an AIM_VISIBILITYCHANGE_DENYADD
73 *      with only your name on it.
74 *   - Allow only users on my Buddy List: Send an
75 *      AIM_VISIBILITYCHANGE_PERMITADD with the list the same as your
76 *      buddy list
77 *   - Allow only the uesrs below: Send an AIM_VISIBILITYCHANGE_PERMITADD
78 *      with everyone listed that you want to see you.
79 *   - Block all users: Send an AIM_VISIBILITYCHANGE_PERMITADD with only
80 *      yourself in the list
81 *   - Block the users below: Send an AIM_VISIBILITYCHANGE_DENYADD with
82 *      the list of users to be blocked
83 *
84 * XXX ye gods.
85 */
86int aim_bos_changevisibility(aim_session_t *sess, aim_conn_t *conn, int changetype, const char *denylist)
87{
88        aim_frame_t *fr;
89        int packlen = 0;
90        guint16 subtype;
91        char *localcpy = NULL, *tmpptr = NULL;
92        int i;
93        int listcount;
94        aim_snacid_t snacid;
95
96        if (!denylist)
97                return -EINVAL;
98
99        if (changetype == AIM_VISIBILITYCHANGE_PERMITADD)
100                subtype = 0x05;
101        else if (changetype == AIM_VISIBILITYCHANGE_PERMITREMOVE)
102                subtype = 0x06;
103        else if (changetype == AIM_VISIBILITYCHANGE_DENYADD)
104                subtype = 0x07;
105        else if (changetype == AIM_VISIBILITYCHANGE_DENYREMOVE)
106                subtype = 0x08;
107        else
108                return -EINVAL;
109
110        localcpy = g_strdup(denylist);
111
112        listcount = aimutil_itemcnt(localcpy, '&');
113        packlen = aimutil_tokslen(localcpy, 99, '&') + listcount + 9;
114
115        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, packlen))) {
116                g_free(localcpy);
117                return -ENOMEM;
118        }
119
120        snacid = aim_cachesnac(sess, 0x0009, subtype, 0x0000, NULL, 0);
121        aim_putsnac(&fr->data, 0x0009, subtype, 0x00, snacid);
122
123        for (i = 0; (i < (listcount - 1)) && (i < 99); i++) {
124                tmpptr = aimutil_itemidx(localcpy, i, '&');
125
126                aimbs_put8(&fr->data, strlen(tmpptr));
127                aimbs_putraw(&fr->data, (guint8 *)tmpptr, strlen(tmpptr));
128
129                g_free(tmpptr);
130        }
131        g_free(localcpy);
132
133        aim_tx_enqueue(sess, fr);
134
135        return 0;
136}
137
138static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
139{
140
141        if (snac->subtype == 0x0003)
142                return rights(sess, mod, rx, snac, bs);
143
144        return 0;
145}
146
147int bos_modfirst(aim_session_t *sess, aim_module_t *mod)
148{
149
150        mod->family = 0x0009;
151        mod->version = 0x0001;
152        mod->toolid = 0x0110;
153        mod->toolversion = 0x0629;
154        mod->flags = 0;
155        strncpy(mod->name, "bos", sizeof(mod->name));
156        mod->snachandler = snachandler;
157
158        return 0;
159}
160
161
Note: See TracBrowser for help on using the repository browser.