Mercurial > pidgin
comparison src/protocols/oscar/family_bos.c @ 13254:e9802db22b06
[gaim-migrate @ 15620]
This is the way we clean the code, clean the code, clean the code
This is the way we clean the code, clean the code, clean the code
So early in the morning
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 12 Feb 2006 22:14:38 +0000 |
parents | 87a7c3077c19 |
children | fccf09946174 |
comparison
equal
deleted
inserted
replaced
13253:87a7c3077c19 | 13254:e9802db22b06 |
---|---|
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 faim_export int aim_bos_reqrights(OscarSession *sess, OscarConnection *conn) | |
33 { | |
34 return aim_genericreq_n_snacid(sess, conn, 0x0009, 0x0002); | |
35 } | |
36 | |
37 /* Subtype 0x0003 - BOS Rights. */ | |
38 static int rights(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs) | |
39 { | |
40 aim_rxcallback_t userfunc; | |
41 aim_tlvlist_t *tlvlist; | |
42 guint16 maxpermits = 0, maxdenies = 0; | |
43 int ret = 0; | |
44 | |
45 /* | |
46 * TLVs follow | |
47 */ | |
48 tlvlist = aim_tlvlist_read(bs); | |
49 | |
50 /* | |
51 * TLV type 0x0001: Maximum number of buddies on permit list. | |
52 */ | |
53 if (aim_tlv_gettlv(tlvlist, 0x0001, 1)) | |
54 maxpermits = aim_tlv_get16(tlvlist, 0x0001, 1); | |
55 | |
56 /* | |
57 * TLV type 0x0002: Maximum number of buddies on deny list. | |
58 */ | |
59 if (aim_tlv_gettlv(tlvlist, 0x0002, 1)) | |
60 maxdenies = aim_tlv_get16(tlvlist, 0x0002, 1); | |
61 | |
62 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
63 ret = userfunc(sess, rx, maxpermits, maxdenies); | |
64 | |
65 aim_tlvlist_free(&tlvlist); | |
66 | |
67 return ret; | |
68 } | |
69 | |
70 /* | |
71 * Subtype 0x0004 - Set group permission mask. | |
72 * | |
73 * Normally 0x1f (all classes). | |
74 * | |
75 * The group permission mask allows you to keep users of a certain | |
76 * class or classes from talking to you. The mask should be | |
77 * a bitwise OR of all the user classes you want to see you. | |
78 * | |
79 */ | |
80 faim_export int aim_bos_setgroupperm(OscarSession *sess, OscarConnection *conn, guint32 mask) | |
81 { | |
82 return aim_genericreq_l(sess, conn, 0x0009, 0x0004, &mask); | |
83 } | |
84 | |
85 /* | |
86 * Stubtypes 0x0005, 0x0006, 0x0007, and 0x0008 - Modify permit/deny lists. | |
87 * | |
88 * Changes your visibility depending on changetype: | |
89 * | |
90 * AIM_VISIBILITYCHANGE_PERMITADD: Lets provided list of names see you | |
91 * AIM_VISIBILITYCHANGE_PERMIDREMOVE: Removes listed names from permit list | |
92 * AIM_VISIBILITYCHANGE_DENYADD: Hides you from provided list of names | |
93 * AIM_VISIBILITYCHANGE_DENYREMOVE: Lets list see you again | |
94 * | |
95 * list should be a list of | |
96 * screen names in the form "Screen Name One&ScreenNameTwo&" etc. | |
97 * | |
98 * Equivelents to options in WinAIM: | |
99 * - Allow all users to contact me: Send an AIM_VISIBILITYCHANGE_DENYADD | |
100 * with only your name on it. | |
101 * - Allow only users on my Buddy List: Send an | |
102 * AIM_VISIBILITYCHANGE_PERMITADD with the list the same as your | |
103 * buddy list | |
104 * - Allow only the uesrs below: Send an AIM_VISIBILITYCHANGE_PERMITADD | |
105 * with everyone listed that you want to see you. | |
106 * - Block all users: Send an AIM_VISIBILITYCHANGE_PERMITADD with only | |
107 * yourself in the list | |
108 * - Block the users below: Send an AIM_VISIBILITYCHANGE_DENYADD with | |
109 * the list of users to be blocked | |
110 * | |
111 * XXX ye gods. | |
112 */ | |
113 faim_export int aim_bos_changevisibility(OscarSession *sess, OscarConnection *conn, int changetype, const char *denylist) | |
114 { | |
115 FlapFrame *fr; | |
116 int packlen = 0; | |
117 guint16 subtype; | |
118 char *localcpy = NULL, *tmpptr = NULL; | |
119 int i; | |
120 int listcount; | |
121 aim_snacid_t snacid; | |
122 | |
123 if (!denylist) | |
124 return -EINVAL; | |
125 | |
126 if (changetype == AIM_VISIBILITYCHANGE_PERMITADD) | |
127 subtype = 0x05; | |
128 else if (changetype == AIM_VISIBILITYCHANGE_PERMITREMOVE) | |
129 subtype = 0x06; | |
130 else if (changetype == AIM_VISIBILITYCHANGE_DENYADD) | |
131 subtype = 0x07; | |
132 else if (changetype == AIM_VISIBILITYCHANGE_DENYREMOVE) | |
133 subtype = 0x08; | |
134 else | |
135 return -EINVAL; | |
136 | |
137 localcpy = strdup(denylist); | |
138 | |
139 listcount = aimutil_itemcnt(localcpy, '&'); | |
140 packlen = aimutil_tokslen(localcpy, 99, '&') + listcount + 9; | |
141 | |
142 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, packlen))) { | |
143 free(localcpy); | |
144 return -ENOMEM; | |
145 } | |
146 | |
147 snacid = aim_cachesnac(sess, 0x0009, subtype, 0x0000, NULL, 0); | |
148 aim_putsnac(&fr->data, 0x0009, subtype, 0x00, snacid); | |
149 | |
150 for (i = 0; (i < (listcount - 1)) && (i < 99); i++) { | |
151 tmpptr = aimutil_itemindex(localcpy, i, '&'); | |
152 | |
153 aimbs_put8(&fr->data, strlen(tmpptr)); | |
154 aimbs_putstr(&fr->data, tmpptr); | |
155 | |
156 free(tmpptr); | |
157 } | |
158 free(localcpy); | |
159 | |
160 aim_tx_enqueue(sess, fr); | |
161 | |
162 return 0; | |
163 } | |
164 | |
165 static int snachandler(OscarSession *sess, aim_module_t *mod, FlapFrame *rx, aim_modsnac_t *snac, ByteStream *bs) | |
166 { | |
167 | |
168 if (snac->subtype == 0x0003) | |
169 return rights(sess, mod, rx, snac, bs); | |
170 | |
171 return 0; | |
172 } | |
173 | |
174 faim_internal int bos_modfirst(OscarSession *sess, aim_module_t *mod) | |
175 { | |
176 | |
177 mod->family = 0x0009; | |
178 mod->version = 0x0001; | |
179 mod->toolid = 0x0110; | |
180 mod->toolversion = 0x0629; | |
181 mod->flags = 0; | |
182 strncpy(mod->name, "bos", sizeof(mod->name)); | |
183 mod->snachandler = snachandler; | |
184 | |
185 return 0; | |
186 } |