Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/aim/toc/buddy.c
1072 views
1
/*
2
* gaim
3
*
4
* Copyright (C) 1998-1999, Mark Spencer <[email protected]>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program 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
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19
*
20
*/
21
22
23
/*
24
* Heavily modified by Nadeem Riaz ([email protected])
25
* for use in libtoc
26
*/
27
28
29
#include <string.h>
30
#include "ll.h"
31
#include "toc.h"
32
33
LL groups;
34
LL permit;
35
LL deny;
36
LL buddy_chats;
37
LL invited_chats;
38
39
struct buddy *add_buddy(char *group, char *buddy)
40
{
41
struct buddy *b;
42
struct group *g;
43
44
toc_debug_printf("adding '%s' to '%s'\n",buddy,group);
45
46
if ((b = find_buddy(buddy)) != NULL)
47
return b;
48
49
g = find_group(group);
50
51
if (g == NULL)
52
g = add_group(group);
53
54
b = (struct buddy *) malloc(sizeof(struct buddy));
55
56
if (!b)
57
return NULL;
58
59
b->present = 0;
60
61
snprintf(b->name, sizeof(b->name), "%s", buddy);
62
AddToLL(g->members,b->name,b);
63
64
b->idle = 0;
65
66
return b;
67
}
68
69
struct group *add_group(char *group)
70
{
71
struct group *g;
72
g = (struct group *) malloc(sizeof(struct group));
73
if (!g)
74
return NULL;
75
76
strncpy(g->name, group, sizeof(g->name));
77
AddToLL(groups, g->name, g);
78
79
g->members = CreateLL();
80
81
return g;
82
}
83
84
struct group *find_group(char *group)
85
{
86
struct group *g;
87
LLE e;
88
char *grpname = malloc(strlen(group) + 1);
89
strcpy(grpname, normalize(group));
90
91
for ( TLL(groups,e) ) {
92
g = (struct group *)e->data;
93
if (!strcasecmp(normalize(g->name), grpname)) {
94
free(grpname);
95
return g;
96
}
97
}
98
99
free(grpname);
100
return NULL;
101
102
}
103
104
struct buddy *find_buddy(char *who)
105
{
106
struct group *g;
107
struct buddy *b;
108
LLE tg,tb;
109
LL mems;
110
char *whoname = malloc(strlen(who) + 1);
111
112
strcpy(whoname, normalize(who));
113
114
for ( TLL(groups,tg) ) {
115
g = (struct group *) tg->data;
116
mems = g->members;
117
118
for ( TLL(mems,tb) ) {
119
b = (struct buddy *)tb->data;
120
if (!strcasecmp(normalize(b->name), whoname)) {
121
free(whoname);
122
return b;
123
}
124
}
125
126
}
127
128
free(whoname);
129
return NULL;
130
}
131
132
int user_remove_buddy(char *buddy) {
133
struct group *g;
134
struct buddy *b;
135
LLE e,m;
136
char *budname = malloc(strlen(buddy) + 1);
137
strcpy(budname, normalize(buddy));
138
139
for ( TLL(groups,e) ) {
140
g = (struct group *)e->data;
141
142
for ( TLL(g->members,m) ) {
143
b = (struct buddy *)m->data;
144
if ( ! strcasecmp(normalize(b->name),budname) ) {
145
RemoveFromLLByKey(g->members,buddy);
146
serv_remove_buddy(buddy);
147
serv_save_config();
148
free(budname);
149
return 1;
150
}
151
}
152
}
153
154
free(budname);
155
return -1;
156
}
157
158
int user_add_buddy(char *group, char *buddy) {
159
struct buddy *b;
160
b = find_buddy(buddy);
161
if ( b != NULL )
162
return -1;
163
add_buddy(group,buddy);
164
serv_add_buddy(buddy);
165
serv_save_config();
166
return 1;
167
}
168
169
/*
170
* mode 1 = move current group members to a enw group
171
* mode 2 = delete current group members from buddy list
172
*/
173
int remove_group(char *group, char *newgroup, int mode)
174
{
175
LL mem;
176
LLE t;
177
178
struct group *delg = find_group(group);
179
struct group *newg = NULL;
180
struct buddy *delb;
181
182
if ( ! delg ) {
183
return -1;
184
}
185
186
if ( mode == 1 ) {
187
newg = find_group(newgroup);
188
if ( ! newg ) {
189
newg = add_group(newgroup);
190
}
191
}
192
193
mem = delg->members;
194
for ( TLL(mem,t) ) {
195
delb = (struct buddy *)t->data;
196
if ( mode == 1 ) {
197
AddToLL(newg->members,delb->name,delb);
198
} else {
199
serv_remove_buddy(delb->name);
200
/* free(delb); */
201
}
202
}
203
204
RemoveFromLLByKey(groups,delg->name);
205
serv_save_config();
206
return 1;
207
}
208
209
int add_permit(char *sn) {
210
LLE t;
211
t = FindInLL(permit,sn);
212
if ( t )
213
return -1;
214
AddToLL(permit,sn,NULL);
215
if ( permdeny == PERMIT_PERMITSOME )
216
serv_add_permit(sn);
217
serv_save_config();
218
return 1;
219
}
220
221
int remove_permit(char *sn) {
222
LLE t;
223
t = FindInLL(permit,sn);
224
if ( ! t )
225
return -1;
226
RemoveFromLLByKey(permit,sn);
227
serv_save_config();
228
if (permdeny == PERMIT_PERMITSOME )
229
serv_set_permit_deny();
230
return 1;
231
}
232
233
int add_deny(char *sn) {
234
LLE t;
235
t = FindInLL(deny,sn);
236
if ( t )
237
return -1;
238
AddToLL(deny,sn,NULL);
239
if ( permdeny == PERMIT_DENYSOME )
240
serv_add_deny(sn);
241
serv_save_config();
242
return 1;
243
}
244
245
int remove_deny(char *sn) {
246
LLE t;
247
t = FindInLL(deny,sn);
248
if ( ! t )
249
return -1;
250
RemoveFromLLByKey(deny,sn);
251
if ( permdeny == PERMIT_DENYSOME ) {
252
/*
253
* DAMN AOL HOEBAGS to lazzy toinclude a delete from deny list
254
* Thus we need to first go into permit mode */
255
serv_set_permit_deny();
256
}
257
serv_save_config();
258
return 1;
259
}
260
261
int buddy_invite(char *chat, char *buddy, char *msg) {
262
LLE t;
263
struct buddy_chat *b;
264
t = FindInLL(buddy_chats,chat);
265
if ( ! t )
266
return -1;
267
b = (struct buddy_chat *)t->data;
268
serv_chat_invite(b->id, msg, buddy);
269
return 1;
270
}
271
272
/*
273
* Checks invite list first
274
* then tries to create chat
275
*/
276
277
void buddy_chat_join(char *chan) {
278
LLE t = FindInLL(invited_chats,chan);
279
if ( ! t ) {
280
/* Standard exchange is 4 */
281
toc_debug_printf("Creating chan %s",chan);
282
serv_join_chat(4,chan);
283
} else {
284
/* The chat is in our invite list */
285
int *d;
286
d = (int *) t->data;
287
serv_accept_chat(*d);
288
toc_debug_printf("Trying to join invited to %s %d",t->key, *d);
289
RemoveFromLLByKey(invited_chats,chan);
290
}
291
}
292
293
struct buddy_chat *find_buddy_chat(char *chat) {
294
LLE t;
295
t = FindInLL(buddy_chats,chat);
296
if ( ! t )
297
return NULL;
298
else
299
return (struct buddy_chat *) t->data;
300
}
301
302
int buddy_chat_leave(char *chan) {
303
LLE t;
304
struct buddy_chat *b;
305
t = FindInLL(buddy_chats,chan);
306
if ( ! t )
307
return -1;
308
b = (struct buddy_chat *) t->data;
309
serv_chat_leave(b->id);
310
/* Removed from buddy_chats in toc_callback */
311
return 1;
312
}
313
314
struct buddy_chat *buddy_chat_getbyid(int id) {
315
LLE t;
316
struct buddy_chat *b;
317
for ( TLL(buddy_chats,t) ) {
318
b = (struct buddy_chat *) t->data;
319
if ( id == b->id )
320
return b;
321
}
322
return NULL;
323
}
324
325
int buddy_chat_invite(char *chat, char *buddy, char *msg) {
326
LLE t;
327
struct buddy_chat *b;
328
t = FindInLL(buddy_chats,chat);
329
if ( ! t )
330
return -1;
331
b = (struct buddy_chat *) t->data;
332
serv_chat_invite(b->id, msg, buddy);
333
return 1;
334
}
335
336
int buddy_chat_warn(char *chat, char *user, int anon) {
337
LLE t;
338
struct buddy_chat *b;
339
t = FindInLL(buddy_chats,chat);
340
if ( ! t )
341
return -1;
342
b = (struct buddy_chat *) t->data;
343
serv_chat_warn(b->id, user, anon);
344
return 1;
345
}
346
347