Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/roster.c @ 89:d39f15683c34
[/trunk] Changeset 103 by mikael
* Can now use a TYPE mask combination.
* Add roster_settype() and roster_gettype().
author | mikael |
---|---|
date | Mon, 18 Apr 2005 17:14:12 +0000 |
parents | 0bd578421ce9 |
children | ac48ace7ee19 |
comparison
equal
deleted
inserted
replaced
88:3c51989b0982 | 89:d39f15683c34 |
---|---|
52 | 52 |
53 /* ### Roster functions ### */ | 53 /* ### Roster functions ### */ |
54 | 54 |
55 // Comparison function used to search in the roster (compares jids and types) | 55 // Comparison function used to search in the roster (compares jids and types) |
56 gint roster_compare_jid_type(roster *a, roster *b) { | 56 gint roster_compare_jid_type(roster *a, roster *b) { |
57 if (a->type != b->type) | 57 if (! (a->type & b->type)) |
58 return -1; // arbitrary (but should be != , of course) | 58 return -1; // arbitrary (but should be != , of course) |
59 return strcasecmp(a->jid, b->jid); | 59 return strcasecmp(a->jid, b->jid); |
60 } | 60 } |
61 | 61 |
62 // Comparison function used to sort the roster (by name) | 62 // Comparison function used to sort the roster (by name) |
63 gint roster_compare_name(roster *a, roster *b) { | 63 gint roster_compare_name(roster *a, roster *b) { |
64 return strcasecmp(a->name, b->name); | 64 return strcasecmp(a->name, b->name); |
65 } | 65 } |
66 | 66 |
67 // Finds a roster element (user, group, agent...), by jid or name | 67 // Finds a roster element (user, group, agent...), by jid or name |
68 // If roster_type is 0, returns match of any type. | |
68 // Returns the roster GSList element, or NULL if jid/name not found | 69 // Returns the roster GSList element, or NULL if jid/name not found |
69 GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type) | 70 GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type) |
70 { | 71 { |
71 GSList *sl_roster_elt = groups; | 72 GSList *sl_roster_elt = groups; |
72 GSList *res; | 73 GSList *res; |
73 roster sample; | 74 roster sample; |
74 GCompareFunc comp; | 75 GCompareFunc comp; |
75 | 76 |
76 if (!jidname) | 77 if (!jidname) |
77 return NULL; // should not happen | 78 return NULL; // should not happen |
79 | |
80 if (!roster_type) | |
81 roster_type = ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_GROUP; | |
78 | 82 |
79 sample.type = roster_type; | 83 sample.type = roster_type; |
80 if (type == jidsearch) { | 84 if (type == jidsearch) { |
81 sample.jid = jidname; | 85 sample.jid = jidname; |
82 comp = (GCompareFunc)&roster_compare_jid_type; | 86 comp = (GCompareFunc)&roster_compare_jid_type; |
166 { | 170 { |
167 GSList *sl_user, *sl_group; | 171 GSList *sl_user, *sl_group; |
168 GSList **sl_group_listptr; | 172 GSList **sl_group_listptr; |
169 roster *roster_usr; | 173 roster *roster_usr; |
170 | 174 |
171 if ((sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER)) == NULL) | 175 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
176 if (sl_user == NULL) | |
172 return; | 177 return; |
173 // Let's free memory (jid, name) | 178 // Let's free memory (jid, name) |
174 roster_usr = (roster*)sl_user->data; | 179 roster_usr = (roster*)sl_user->data; |
175 if (roster_usr->jid) | 180 if (roster_usr->jid) |
176 g_free((gchar*)roster_usr->jid); | 181 g_free((gchar*)roster_usr->jid); |
193 void roster_setstatus(const char *jid, enum imstatus bstat) | 198 void roster_setstatus(const char *jid, enum imstatus bstat) |
194 { | 199 { |
195 GSList *sl_user; | 200 GSList *sl_user; |
196 roster *roster_usr; | 201 roster *roster_usr; |
197 | 202 |
198 if ((sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER)) == NULL) | 203 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
204 if (sl_user == NULL) | |
199 return; | 205 return; |
200 | 206 |
201 roster_usr = (roster*)sl_user->data; | 207 roster_usr = (roster*)sl_user->data; |
202 roster_usr->status = bstat; | 208 roster_usr->status = bstat; |
203 } | 209 } |
207 void roster_setflags(const char *jid, guint flags, guint value) | 213 void roster_setflags(const char *jid, guint flags, guint value) |
208 { | 214 { |
209 GSList *sl_user; | 215 GSList *sl_user; |
210 roster *roster_usr; | 216 roster *roster_usr; |
211 | 217 |
212 if ((sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER)) == NULL) | 218 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
219 if (sl_user == NULL) | |
213 return; | 220 return; |
214 | 221 |
215 roster_usr = (roster*)sl_user->data; | 222 roster_usr = (roster*)sl_user->data; |
216 if (value) | 223 if (value) |
217 roster_usr->flags |= flags; | 224 roster_usr->flags |= flags; |
218 else | 225 else |
219 roster_usr->flags &= ~flags; | 226 roster_usr->flags &= ~flags; |
220 } | 227 } |
221 | 228 |
229 void roster_settype(const char *jid, guint type) | |
230 { | |
231 GSList *sl_user; | |
232 roster *roster_usr; | |
233 | |
234 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) | |
235 return; | |
236 | |
237 roster_usr = (roster*)sl_user->data; | |
238 roster_usr->type = type; | |
239 } | |
240 | |
241 guint roster_gettype(const char *jid) | |
242 { | |
243 GSList *sl_user; | |
244 roster *roster_usr; | |
245 | |
246 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) | |
247 return 0; | |
248 | |
249 roster_usr = (roster*)sl_user->data; | |
250 return roster_usr->type; | |
251 } | |
252 | |
222 // char *roster_getgroup(...) / Or *GSList? Which use?? | 253 // char *roster_getgroup(...) / Or *GSList? Which use?? |
223 // ... setgroup(char*) ?? | 254 // ... setgroup(char*) ?? |
224 // guint roster_gettype(...) / settype | |
225 // guchar roster_getflags(...) | 255 // guchar roster_getflags(...) |
226 // guchar roster_getname(...) / setname ?? | 256 // guchar roster_getname(...) / setname ?? |
227 // roster_del_group? | 257 // roster_del_group? |
228 | 258 |
229 | 259 |