1 | /* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar |
---|
2 | * |
---|
3 | * This file is part of Owl. |
---|
4 | * |
---|
5 | * Owl is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation, either version 3 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * Owl is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with Owl. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | * |
---|
18 | * --------------------------------------------------------------- |
---|
19 | * |
---|
20 | * As of Owl version 2.1.12 there are patches contributed by |
---|
21 | * developers of the the branched BarnOwl project, Copyright (c) |
---|
22 | * 2006-2008 The BarnOwl Developers. All rights reserved. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "owl.h" |
---|
26 | |
---|
27 | static const char fileIdent[] = "$Id"; |
---|
28 | |
---|
29 | void owl_zbuddylist_create(owl_zbuddylist *zb) |
---|
30 | { |
---|
31 | owl_list_create(&(zb->zusers)); |
---|
32 | } |
---|
33 | |
---|
34 | int owl_zbuddylist_adduser(owl_zbuddylist *zb, char *name) |
---|
35 | { |
---|
36 | int i, j; |
---|
37 | char *user; |
---|
38 | |
---|
39 | user=long_zuser(name); |
---|
40 | |
---|
41 | j=owl_list_get_size(&(zb->zusers)); |
---|
42 | for (i=0; i<j; i++) { |
---|
43 | if (!strcasecmp(user, owl_list_get_element(&(zb->zusers), i))) { |
---|
44 | owl_free(user); |
---|
45 | return(-1); |
---|
46 | } |
---|
47 | } |
---|
48 | owl_list_append_element(&(zb->zusers), user); |
---|
49 | return(0); |
---|
50 | } |
---|
51 | |
---|
52 | int owl_zbuddylist_deluser(owl_zbuddylist *zb, char *name) |
---|
53 | { |
---|
54 | int i, j; |
---|
55 | char *user, *ptr; |
---|
56 | |
---|
57 | user=long_zuser(name); |
---|
58 | |
---|
59 | j=owl_list_get_size(&(zb->zusers)); |
---|
60 | for (i=0; i<j; i++) { |
---|
61 | ptr=owl_list_get_element(&(zb->zusers), i); |
---|
62 | if (!strcasecmp(user, ptr)) { |
---|
63 | owl_list_remove_element(&(zb->zusers), i); |
---|
64 | owl_free(ptr); |
---|
65 | owl_free(user); |
---|
66 | return(0); |
---|
67 | } |
---|
68 | } |
---|
69 | owl_free(user); |
---|
70 | return(-1); |
---|
71 | } |
---|
72 | |
---|
73 | int owl_zbuddylist_contains_user(owl_zbuddylist *zb, char *name) |
---|
74 | { |
---|
75 | int i, j; |
---|
76 | char *user; |
---|
77 | |
---|
78 | user=long_zuser(name); |
---|
79 | |
---|
80 | j=owl_list_get_size(&(zb->zusers)); |
---|
81 | for (i=0; i<j; i++) { |
---|
82 | if (!strcasecmp(user, owl_list_get_element(&(zb->zusers), i))) { |
---|
83 | owl_free(user); |
---|
84 | return(1); |
---|
85 | } |
---|
86 | } |
---|
87 | owl_free(user); |
---|
88 | return(0); |
---|
89 | } |
---|