source: libfaim/bos.c @ 453bd70

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