comparison libpurple/protocols/oscar/family_bos.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /*
2 * Gaim's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /*
22 * Family 0x0009 - Basic Oscar Service.
23 *
24 * The functionality of this family has been replaced by SSI.
25 */
26
27 #include "oscar.h"
28
29 #include <string.h>
30
31 /* Subtype 0x0002 - Request BOS rights. */
32 void
33 aim_bos_reqrights(OscarData *od, FlapConnection *conn)
34 {
35 aim_genericreq_n_snacid(od, conn, 0x0009, 0x0002);
36 }
37
38 /* Subtype 0x0003 - BOS Rights. */
39 static int rights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
40 {
41 aim_rxcallback_t userfunc;
42 aim_tlvlist_t *tlvlist;
43 guint16 maxpermits = 0, maxdenies = 0;
44 int ret = 0;
45
46 /*
47 * TLVs follow
48 */
49 tlvlist = aim_tlvlist_read(bs);
50
51 /*
52 * TLV type 0x0001: Maximum number of buddies on permit list.
53 */
54 if (aim_tlv_gettlv(tlvlist, 0x0001, 1))
55 maxpermits = aim_tlv_get16(tlvlist, 0x0001, 1);
56
57 /*
58 * TLV type 0x0002: Maximum number of buddies on deny list.
59 */
60 if (aim_tlv_gettlv(tlvlist, 0x0002, 1))
61 maxdenies = aim_tlv_get16(tlvlist, 0x0002, 1);
62
63 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
64 ret = userfunc(od, conn, frame, maxpermits, maxdenies);
65
66 aim_tlvlist_free(&tlvlist);
67
68 return ret;
69 }
70
71 /*
72 * Subtype 0x0004 - Set group permission mask.
73 *
74 * Normally 0x1f (all classes).
75 *
76 * The group permission mask allows you to keep users of a certain
77 * class or classes from talking to you. The mask should be
78 * a bitwise OR of all the user classes you want to see you.
79 *
80 */
81 void
82 aim_bos_setgroupperm(OscarData *od, FlapConnection *conn, guint32 mask)
83 {
84 aim_genericreq_l(od, conn, 0x0009, 0x0004, &mask);
85 }
86
87 /*
88 * Stubtypes 0x0005, 0x0006, 0x0007, and 0x0008 - Modify permit/deny lists.
89 *
90 * Changes your visibility depending on changetype:
91 *
92 * AIM_VISIBILITYCHANGE_PERMITADD: Lets provided list of names see you
93 * AIM_VISIBILITYCHANGE_PERMIDREMOVE: Removes listed names from permit list
94 * AIM_VISIBILITYCHANGE_DENYADD: Hides you from provided list of names
95 * AIM_VISIBILITYCHANGE_DENYREMOVE: Lets list see you again
96 *
97 * list should be a list of
98 * screen names in the form "Screen Name One&ScreenNameTwo&" etc.
99 *
100 * Equivelents to options in WinAIM:
101 * - Allow all users to contact me: Send an AIM_VISIBILITYCHANGE_DENYADD
102 * with only your name on it.
103 * - Allow only users on my Buddy List: Send an
104 * AIM_VISIBILITYCHANGE_PERMITADD with the list the same as your
105 * buddy list
106 * - Allow only the uesrs below: Send an AIM_VISIBILITYCHANGE_PERMITADD
107 * with everyone listed that you want to see you.
108 * - Block all users: Send an AIM_VISIBILITYCHANGE_PERMITADD with only
109 * yourself in the list
110 * - Block the users below: Send an AIM_VISIBILITYCHANGE_DENYADD with
111 * the list of users to be blocked
112 *
113 * XXX ye gods.
114 */
115 int aim_bos_changevisibility(OscarData *od, FlapConnection *conn, int changetype, const char *denylist)
116 {
117 FlapFrame *frame;
118 int packlen = 0;
119 guint16 subtype;
120 char *localcpy = NULL, *tmpptr = NULL;
121 int i;
122 int listcount;
123 aim_snacid_t snacid;
124
125 if (!denylist)
126 return -EINVAL;
127
128 if (changetype == AIM_VISIBILITYCHANGE_PERMITADD)
129 subtype = 0x05;
130 else if (changetype == AIM_VISIBILITYCHANGE_PERMITREMOVE)
131 subtype = 0x06;
132 else if (changetype == AIM_VISIBILITYCHANGE_DENYADD)
133 subtype = 0x07;
134 else if (changetype == AIM_VISIBILITYCHANGE_DENYREMOVE)
135 subtype = 0x08;
136 else
137 return -EINVAL;
138
139 localcpy = strdup(denylist);
140
141 listcount = aimutil_itemcnt(localcpy, '&');
142 packlen = aimutil_tokslen(localcpy, 99, '&') + listcount + 9;
143
144 frame = flap_frame_new(od, 0x02, packlen);
145
146 snacid = aim_cachesnac(od, 0x0009, subtype, 0x0000, NULL, 0);
147 aim_putsnac(&frame->data, 0x0009, subtype, 0x00, snacid);
148
149 for (i = 0; (i < (listcount - 1)) && (i < 99); i++) {
150 tmpptr = aimutil_itemindex(localcpy, i, '&');
151
152 byte_stream_put8(&frame->data, strlen(tmpptr));
153 byte_stream_putstr(&frame->data, tmpptr);
154
155 free(tmpptr);
156 }
157 free(localcpy);
158
159 flap_connection_send(conn, frame);
160
161 return 0;
162 }
163
164 static int
165 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
166 {
167 if (snac->subtype == 0x0003)
168 return rights(od, conn, mod, frame, snac, bs);
169
170 return 0;
171 }
172
173 int
174 bos_modfirst(OscarData *od, aim_module_t *mod)
175 {
176 mod->family = 0x0009;
177 mod->version = 0x0001;
178 mod->toolid = 0x0110;
179 mod->toolversion = 0x0629;
180 mod->flags = 0;
181 strncpy(mod->name, "bos", sizeof(mod->name));
182 mod->snachandler = snachandler;
183
184 return 0;
185 }