annotate mcabber/src/roster.c @ 1292:382ec54b584e

Muc nick coloring functionality
author Michal 'vorner' Vaner <vorner@ucw.cz>
date Tue, 28 Aug 2007 10:11:39 +0200
parents 2de8f8ba1f34
children 0dda8238af21
rev   line source
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1 /*
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
2 * roster.c -- Local roster implementation
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
3 *
1205
2de8f8ba1f34 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1092
diff changeset
4 * Copyright (C) 2005-2007 Mikael Berthe <mikael@lilotux.net>
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
5 *
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
9 * your option) any later version.
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
10 *
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
14 * General Public License for more details.
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
15 *
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
19 * USA
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
20 */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
21
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
22 #include <string.h>
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
23
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
24 #include "roster.h"
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
25 #include "utils.h"
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
26
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
27
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
28 char *strrole[] = { /* Should match enum in roster.h */
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
29 "none",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
30 "moderator",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
31 "participant",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
32 "visitor"
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
33 };
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
34
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
35 char *straffil[] = { /* Should match enum roster.h */
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
36 "none",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
37 "owner",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
38 "admin",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
39 "memeber",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
40 "outcast"
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
41 };
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
42
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
43 /* Resource structure */
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
44
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
45 typedef struct {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
46 gchar *name;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
47 gchar prio;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
48 enum imstatus status;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
49 gchar *status_msg;
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
50 time_t status_timestamp;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
51 enum imrole role;
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
52 enum imaffiliation affil;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
53 gchar *realjid; /* for chatrooms, if buddy's real jid is known */
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
54 guint events;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
55 #ifdef JEP0022
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
56 struct jep0022 jep22;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
57 #endif
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
58 #ifdef JEP0085
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
59 struct jep0085 jep85;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
60 #endif
1043
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
61 #ifdef HAVE_GPGME
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
62 struct pgp_data pgpdata;
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
63 #endif
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
64 } res;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
65
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
66 /* This is a private structure type for the roster */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
67
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
68 typedef struct {
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
69 gchar *name;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
70 gchar *jid;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
71 guint type;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
72 enum subscr subscription;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
73 GSList *resource;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
74
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
75 /* For groupchats */
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
76 gchar *nickname;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
77 gchar *topic;
952
527d6f234924 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
78 guint inside_room;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
79
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
80 /* To keep track of last status message */
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
81 gchar *offline_status_message;
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
82
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
83 /* Flag used for the UI */
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
84 guint flags;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
85
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
86 // list: user -> points to his group; group -> points to its users list
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
87 GSList *list;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
88 } roster;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
89
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
90
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
91 /* ### Variables ### */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
92
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
93 static int hide_offline_buddies;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
94 static GSList *groups;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
95 static GSList *unread_list;
662
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
96 static GHashTable *unread_jids;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
97 GList *buddylist;
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
98 GList *current_buddy;
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
99 GList *alternate_buddy;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
100
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
101 static roster roster_special;
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
102
662
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
103 void unread_jid_add(const char *jid);
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
104 int unread_jid_del(const char *jid);
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
105
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
106
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
107 /* ### Initialization ### */
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
108
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
109 void roster_init(void)
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
110 {
889
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
111 roster_special.name = SPECIAL_BUFFER_STATUS_ID;
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
112 roster_special.type = ROSTER_TYPE_SPECIAL;
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
113 }
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
114
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
115 /* ### Resources functions ### */
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
116
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
117 static inline void free_resource_data(res *p_res)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
118 {
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
119 if (!p_res)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
120 return;
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
121 g_free((gchar*)p_res->status_msg);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
122 g_free((gchar*)p_res->name);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
123 g_free((gchar*)p_res->realjid);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
124 #ifdef JEP0022
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
125 g_free(p_res->jep22.last_msgid_sent);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
126 g_free(p_res->jep22.last_msgid_rcvd);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
127 #endif
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
128 #ifdef HAVE_GPGME
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
129 g_free(p_res->pgpdata.sign_keyid);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
130 #endif
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
131 g_free(p_res);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
132 }
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
133
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
134 static void free_all_resources(GSList **reslist)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
135 {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
136 GSList *lip;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
137
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
138 for (lip = *reslist; lip ; lip = g_slist_next(lip))
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
139 free_resource_data((res*)lip->data);
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
140 // Free all nodes but the first (which is static)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
141 g_slist_free(*reslist);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
142 *reslist = NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
143 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
144
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
145 // Resources are sorted in ascending order
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
146 static gint resource_compare_prio(res *a, res *b) {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
147 //return (a->prio - b->prio);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
148 if (a->prio < b->prio) return -1;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
149 else return 1;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
150 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
151
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
152 // get_resource(rost, resname)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
153 // Return a pointer to the resource with name resname, in rost's resources list
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
154 // - if rost has no resources, return NULL
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
155 // - if resname is defined, return the match or NULL
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
156 // - if resname is NULL, the last resource is returned, currently
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
157 // This could change in the future, because we should return the best one
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
158 // (priority? last used? and fall back to the first resource)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
159 //
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
160 static res *get_resource(roster *rost, const char *resname)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
161 {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
162 GSList *p;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
163 res *r = NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
164
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
165 for (p = rost->resource; p; p = g_slist_next(p)) {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
166 r = p->data;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
167 if (resname && !strcmp(r->name, resname))
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
168 return r;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
169 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
170
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
171 // The last resource is one of the resources with the highest priority,
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
172 // however, we don't know if it is the more-recently-used.
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
173 if (!resname) return r;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
174 return NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
175 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
176
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
177 // get_or_add_resource(rost, resname, priority)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
178 // - if there is a "resname" resource in rost's resources, return a pointer
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
179 // on this resource
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
180 // - if not, add the resource, set the name, and return a pointer on this
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
181 // new resource
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
182 static res *get_or_add_resource(roster *rost, const char *resname, gchar prio)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
183 {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
184 GSList *p;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
185 res *nres;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
186
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
187 if (!resname) return NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
188
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
189 for (p = rost->resource; p; p = g_slist_next(p)) {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
190 res *r = p->data;
1092
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
191 if (!strcmp(r->name, resname)) {
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
192 if (prio != r->prio) {
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
193 r->prio = prio;
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
194 rost->resource = g_slist_sort(rost->resource,
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
195 (GCompareFunc)&resource_compare_prio);
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
196 }
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
197 return r;
1092
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
198 }
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
199 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
200
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
201 // Resource not found
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
202 nres = g_new0(res, 1);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
203 nres->name = g_strdup(resname);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
204 nres->prio = prio;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
205 rost->resource = g_slist_insert_sorted(rost->resource, nres,
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
206 (GCompareFunc)&resource_compare_prio);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
207 return nres;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
208 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
209
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
210 static void del_resource(roster *rost, const char *resname)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
211 {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
212 GSList *p;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
213 GSList *p_res_elt = NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
214 res *p_res;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
215
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
216 if (!resname) return;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
217
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
218 for (p = rost->resource; p; p = g_slist_next(p)) {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
219 res *r = p->data;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
220 if (!strcmp(r->name, resname))
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
221 p_res_elt = p;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
222 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
223
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
224 if (!p_res_elt) return; // Resource not found
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
225
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
226 p_res = p_res_elt->data;
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
227
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
228 // Keep a copy of the status message when a buddy goes offline
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
229 if (g_slist_length(rost->resource) == 1) {
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
230 g_free(rost->offline_status_message);
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
231 rost->offline_status_message = p_res->status_msg;
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
232 p_res->status_msg = NULL;
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
233 }
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
234
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
235 // Free allocations and delete resource node
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
236 free_resource_data(p_res);
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
237 rost->resource = g_slist_delete_link(rost->resource, p_res_elt);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
238 return;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
239 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
240
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
241
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
242 /* ### Roster functions ### */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
243
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
244 static inline void free_roster_user_data(roster *roster_usr)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
245 {
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
246 if (!roster_usr)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
247 return;
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
248 g_free((gchar*)roster_usr->jid);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
249 g_free((gchar*)roster_usr->name);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
250 g_free((gchar*)roster_usr->nickname);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
251 g_free((gchar*)roster_usr->topic);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
252 g_free((gchar*)roster_usr->offline_status_message);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
253 free_all_resources(&roster_usr->resource);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
254 g_free(roster_usr);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
255 }
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
256
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
257 // Comparison function used to search in the roster (compares jids and types)
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 331
diff changeset
258 static gint roster_compare_jid_type(roster *a, roster *b) {
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
259 if (! (a->type & b->type))
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
260 return -1; // arbitrary (but should be != 0, of course)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
261 return strcasecmp(a->jid, b->jid);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
262 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
263
670
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
264 // Comparison function used to search in the roster (compares names and types)
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
265 static gint roster_compare_name_type(roster *a, roster *b) {
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
266 if (! (a->type & b->type))
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
267 return -1; // arbitrary (but should be != 0, of course)
783
25022410f80f Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
268 return strcmp(a->name, b->name);
670
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
269 }
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
270
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
271 // Comparison function used to sort the roster (by name)
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 331
diff changeset
272 static gint roster_compare_name(roster *a, roster *b) {
783
25022410f80f Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
273 return strcmp(a->name, b->name);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
274 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
275
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
276 // Finds a roster element (user, group, agent...), by jid or name
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
277 // If roster_type is 0, returns match of any type.
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
278 // Returns the roster GSList element, or NULL if jid/name not found
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
279 GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
280 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
281 GSList *sl_roster_elt = groups;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
282 GSList *resource;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
283 roster sample;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
284 GCompareFunc comp;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
285
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 166
diff changeset
286 if (!jidname) return NULL;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
287
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
288 if (!roster_type)
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
289 roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM |
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
290 ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP;
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
291
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
292 sample.type = roster_type;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
293 if (type == jidsearch) {
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
294 sample.jid = (gchar*)jidname;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
295 comp = (GCompareFunc)&roster_compare_jid_type;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
296 } else if (type == namesearch) {
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
297 sample.name = (gchar*)jidname;
670
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
298 comp = (GCompareFunc)&roster_compare_name_type;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
299 } else
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 863
diff changeset
300 return NULL; // Should not happen...
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
301
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
302 while (sl_roster_elt) {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
303 roster *roster_elt = (roster*)sl_roster_elt->data;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
304 if (roster_type & ROSTER_TYPE_GROUP) {
783
25022410f80f Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
305 if ((type == namesearch) && !strcmp(jidname, roster_elt->name))
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
306 return sl_roster_elt;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
307 }
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
308 resource = g_slist_find_custom(roster_elt->list, &sample, comp);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
309 if (resource) return resource;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
310 sl_roster_elt = g_slist_next(sl_roster_elt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
311 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
312 return NULL;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
313 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
314
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
315 // Returns pointer to new group, or existing group with that name
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
316 GSList *roster_add_group(const char *name)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
317 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
318 roster *roster_grp;
669
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
319 GSList *p_group;
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
320
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
321 // #1 Check name doesn't already exist
669
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
322 p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP);
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
323 if (!p_group) {
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
324 // #2 Create the group node
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
325 roster_grp = g_new0(roster, 1);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
326 roster_grp->name = g_strdup(name);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
327 roster_grp->type = ROSTER_TYPE_GROUP;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
328 // #3 Insert (sorted)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
329 groups = g_slist_insert_sorted(groups, roster_grp,
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
330 (GCompareFunc)&roster_compare_name);
669
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
331 p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
332 }
669
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
333 return p_group;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
334 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
335
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
336 // Returns a pointer to the new user, or existing user with that name
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
337 GSList *roster_add_user(const char *jid, const char *name, const char *group,
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
338 guint type, enum subscr esub)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
339 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
340 roster *roster_usr;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
341 roster *my_group;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
342 GSList *slist;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
343
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
344 if ((type != ROSTER_TYPE_USER) &&
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
345 (type != ROSTER_TYPE_ROOM) &&
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
346 (type != ROSTER_TYPE_AGENT)) {
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
347 // XXX Error message?
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
348 return NULL;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
349 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
350
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
351 // Let's be arbitrary: default group has an empty name ("").
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
352 if (!group) group = "";
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
353
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
354 // #1 Check this user doesn't already exist
563
b0f1b127bfb6 Prevent from adding a duplicate jid (when types are different)
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
355 slist = roster_find(jid, jidsearch, 0);
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
356 if (slist) {
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
357 char *oldgroupname;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
358 // That's an update
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
359 roster_usr = slist->data;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
360 roster_usr->subscription = esub;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
361 if (name)
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
362 buddy_setname(slist->data, (char*)name);
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
363 // Let's check if the group name has changed
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
364 oldgroupname = ((roster*)((GSList*)roster_usr->list)->data)->name;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
365 if (group && strcmp(oldgroupname, group))
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
366 buddy_setgroup(slist->data, (char*)group);
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
367 return slist;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
368 }
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
369 // #2 add group if necessary
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
370 slist = roster_add_group(group);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
371 if (!slist) return NULL;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
372 my_group = (roster*)slist->data;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
373 // #3 Create user node
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
374 roster_usr = g_new0(roster, 1);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
375 roster_usr->jid = g_strdup(jid);
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
376 if (name) {
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
377 roster_usr->name = g_strdup(name);
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
378 } else {
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
379 gchar *p, *str = g_strdup(jid);
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 974
diff changeset
380 p = strchr(str, JID_RESOURCE_SEPARATOR);
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
381 if (p) *p = '\0';
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
382 roster_usr->name = g_strdup(str);
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
383 g_free(str);
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
384 }
662
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
385 if (unread_jid_del(jid)) {
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
386 roster_usr->flags |= ROSTER_FLAG_MSG;
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
387 // Append the roster_usr to unread_list
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
388 unread_list = g_slist_append(unread_list, roster_usr);
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
389 }
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
390 roster_usr->type = type;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
391 roster_usr->subscription = esub;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
392 roster_usr->list = slist; // (my_group SList element)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
393 // #4 Insert node (sorted)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
394 my_group->list = g_slist_insert_sorted(my_group->list, roster_usr,
564
95d6297a9654 Cosmetic changes
Mikael Berthe <mikael@lilotux.net>
parents: 563
diff changeset
395 (GCompareFunc)&roster_compare_name);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
396 return roster_find(jid, jidsearch, type);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
397 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
398
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
399 // Removes user (jid) from roster, frees allocated memory
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
400 void roster_del_user(const char *jid)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
401 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
402 GSList *sl_user, *sl_group;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
403 GSList **sl_group_listptr;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
404 roster *roster_usr;
246
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
405 GSList *node;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
406
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
407 sl_user = roster_find(jid, jidsearch,
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
408 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM);
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
409 if (sl_user == NULL)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
410 return;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
411 roster_usr = (roster*)sl_user->data;
246
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
412
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
413 // Remove (if present) from unread messages list
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
414 node = g_slist_find(unread_list, roster_usr);
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
415 if (node) unread_list = g_slist_delete_link(unread_list, node);
662
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
416 // If there is a pending unread message, keep track of it
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
417 if (roster_usr->flags & ROSTER_FLAG_MSG)
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
418 unread_jid_add(roster_usr->jid);
246
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
419
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
420 // Let's free roster_usr memory (jid, name, status message...)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
421 free_roster_user_data(roster_usr);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
422
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
423 // That's a little complex, we need to dereference twice
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
424 sl_group = ((roster*)sl_user->data)->list;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
425 sl_group_listptr = &((roster*)(sl_group->data))->list;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
426 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user);
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
427
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
428 // We need to rebuild the list
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
429 if (current_buddy)
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
430 buddylist_build();
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
431 // TODO What we could do, too, is to check if the deleted node is
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
432 // current_buddy, in which case we could move current_buddy to the
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
433 // previous (or next) node.
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
434 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
435
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
436 // Free all roster data and call buddylist_build() to free the buddylist.
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
437 void roster_free(void)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
438 {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
439 GSList *sl_grp = groups;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
440
301
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
441 // Free unread_list
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
442 if (unread_list) {
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
443 g_slist_free(unread_list);
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
444 unread_list = NULL;
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
445 }
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
446
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
447 // Walk through groups
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
448 while (sl_grp) {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
449 roster *roster_grp = (roster*)sl_grp->data;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
450 GSList *sl_usr = roster_grp->list;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
451 // Walk through this group users
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
452 while (sl_usr) {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
453 roster *roster_usr = (roster*)sl_usr->data;
662
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
454 // If there is a pending unread message, keep track of it
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
455 if (roster_usr->flags & ROSTER_FLAG_MSG)
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
456 unread_jid_add(roster_usr->jid);
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
457 // Free roster_usr data (jid, name, status message...)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
458 free_roster_user_data(roster_usr);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
459 sl_usr = g_slist_next(sl_usr);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
460 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
461 // Free group's users list
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
462 if (roster_grp->list)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
463 g_slist_free(roster_grp->list);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
464 // Free group's name and jid
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
465 g_free((gchar*)roster_grp->jid);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
466 g_free((gchar*)roster_grp->name);
214
9484ba81ec53 [/trunk] Changeset 226 by mikael
mikael
parents: 212
diff changeset
467 g_free(roster_grp);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
468 sl_grp = g_slist_next(sl_grp);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
469 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
470 // Free groups list
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
471 if (groups) {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
472 g_slist_free(groups);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
473 groups = NULL;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
474 // Update (i.e. free) buddylist
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
475 if (buddylist)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
476 buddylist_build();
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
477 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
478 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
479
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
480 // roster_setstatus()
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
481 // Note: resname, role, affil and realjid are for room members only
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
482 void roster_setstatus(const char *jid, const char *resname, gchar prio,
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
483 enum imstatus bstat, const char *status_msg,
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
484 time_t status_time,
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
485 enum imrole role, enum imaffiliation affil,
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
486 const char *realjid)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
487 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
488 GSList *sl_user;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
489 roster *roster_usr;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
490 res *p_res;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
491
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
492 sl_user = roster_find(jid, jidsearch,
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
493 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
92
c6270994fb6e [/trunk] Changeset 106 by mikael
mikael
parents: 90
diff changeset
494 // If we can't find it, we add it
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
495 if (sl_user == NULL)
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
496 sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, sub_none);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
497
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
498 // If there is no resource name, we can leave now
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
499 if (!resname) return;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
500
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
501 roster_usr = (roster*)sl_user->data;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
502
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
503 // New or updated resource
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
504 p_res = get_or_add_resource(roster_usr, resname, prio);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
505 p_res->status = bstat;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
506 if (p_res->status_msg) {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
507 g_free((gchar*)p_res->status_msg);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
508 p_res->status_msg = NULL;
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 214
diff changeset
509 }
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 214
diff changeset
510 if (status_msg)
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
511 p_res->status_msg = g_strdup(status_msg);
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
512 if (!status_time)
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
513 time(&status_time);
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
514 p_res->status_timestamp = status_time;
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
515
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
516 p_res->role = role;
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
517 p_res->affil = affil;
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
518
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
519 if (p_res->realjid) {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
520 g_free((gchar*)p_res->realjid);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
521 p_res->realjid = NULL;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
522 }
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
523 if (realjid)
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
524 p_res->realjid = g_strdup(realjid);
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
525
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
526 // If bstat is offline, we MUST delete the resource, actually
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
527 if (bstat == offline) {
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
528 del_resource(roster_usr, resname);
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
529 return;
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
530 }
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
531 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
532
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
533 // roster_setflags()
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
534 // Set one or several flags to value (TRUE/FALSE)
80
7fb661f19a77 [/trunk] Changeset 94 by mikael
mikael
parents: 78
diff changeset
535 void roster_setflags(const char *jid, guint flags, guint value)
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
536 {
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
537 GSList *sl_user;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
538 roster *roster_usr;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
539
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
540 sl_user = roster_find(jid, jidsearch,
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
541 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
542 if (sl_user == NULL)
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
543 return;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
544
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
545 roster_usr = (roster*)sl_user->data;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
546 if (value)
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
547 roster_usr->flags |= flags;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
548 else
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
549 roster_usr->flags &= ~flags;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
550 }
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
551
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
552 // roster_msg_setflag()
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
553 // Set the ROSTER_FLAG_MSG to the given value for the given jid.
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
554 // It will update the buddy's group message flag.
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
555 // Update the unread messages list too.
889
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
556 void roster_msg_setflag(const char *jid, guint special, guint value)
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
557 {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
558 GSList *sl_user;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
559 roster *roster_usr, *roster_grp;
860
a8fadbd97858 Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
560 int new_roster_item = FALSE;
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
561
889
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
562 if (special) {
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
563 //sl_user = roster_find(jid, namesearch, ROSTER_TYPE_SPECIAL);
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
564 //if (!sl_user) return;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
565 //roster_usr = (roster*)sl_user->data;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
566 roster_usr = &roster_special;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
567 if (value) {
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
568 roster_usr->flags |= ROSTER_FLAG_MSG;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
569 // Append the roster_usr to unread_list, but avoid duplicates
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
570 if (!g_slist_find(unread_list, roster_usr))
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
571 unread_list = g_slist_append(unread_list, roster_usr);
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
572 } else {
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
573 roster_usr->flags &= ~ROSTER_FLAG_MSG;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
574 if (unread_list) {
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
575 GSList *node = g_slist_find(unread_list, roster_usr);
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
576 if (node) unread_list = g_slist_delete_link(unread_list, node);
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
577 }
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
578 }
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
579 return;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
580 }
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
581
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
582 sl_user = roster_find(jid, jidsearch,
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
583 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
678
e175f5d96f04 Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents: 670
diff changeset
584 // If we can't find it, we add it
e175f5d96f04 Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents: 670
diff changeset
585 if (sl_user == NULL) {
e175f5d96f04 Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents: 670
diff changeset
586 sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, sub_none);
860
a8fadbd97858 Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
587 new_roster_item = TRUE;
678
e175f5d96f04 Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents: 670
diff changeset
588 }
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
589
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
590 roster_usr = (roster*)sl_user->data;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
591 roster_grp = (roster*)roster_usr->list->data;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
592 if (value) {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
593 // Message flag is TRUE. This is easy, we just have to set both flags
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
594 // to TRUE...
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
595 roster_usr->flags |= ROSTER_FLAG_MSG;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
596 roster_grp->flags |= ROSTER_FLAG_MSG; // group
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
597 // Append the roster_usr to unread_list, but avoid duplicates
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
598 if (!g_slist_find(unread_list, roster_usr))
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
599 unread_list = g_slist_append(unread_list, roster_usr);
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
600 } else {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
601 // Message flag is FALSE.
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
602 guint msg = FALSE;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
603 roster_usr->flags &= ~ROSTER_FLAG_MSG;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
604 if (unread_list) {
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
605 GSList *node = g_slist_find(unread_list, roster_usr);
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
606 if (node) unread_list = g_slist_delete_link(unread_list, node);
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
607 }
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
608 // For the group value we need to watch all buddies in this group;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
609 // if one is flagged, then the group will be flagged.
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
610 // I will re-use sl_user and roster_usr here, as they aren't used
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
611 // anymore.
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
612 sl_user = roster_grp->list;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
613 while (sl_user) {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
614 roster_usr = (roster*)sl_user->data;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
615 if (roster_usr->flags & ROSTER_FLAG_MSG) {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
616 msg = TRUE;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
617 break;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
618 }
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
619 sl_user = g_slist_next(sl_user);
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
620 }
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
621 if (!msg)
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
622 roster_grp->flags &= ~ROSTER_FLAG_MSG;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
623 else
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
624 roster_grp->flags |= ROSTER_FLAG_MSG;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
625 // Actually the "else" part is useless, because the group
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
626 // ROSTER_FLAG_MSG should already be set...
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
627 }
860
a8fadbd97858 Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
628
1010
54405d09b15a Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
629 if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr)))
860
a8fadbd97858 Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
630 buddylist_build();
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
631 }
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
632
510
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
633 const char *roster_getname(const char *jid)
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
634 {
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
635 GSList *sl_user;
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
636 roster *roster_usr;
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
637
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
638 sl_user = roster_find(jid, jidsearch,
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
639 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
640 if (sl_user == NULL)
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
641 return NULL; // Not in the roster...
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
642
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
643 roster_usr = (roster*)sl_user->data;
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
644 return roster_usr->name;
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
645 }
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
646
863
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
647 const char *roster_getnickname(const char *jid)
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
648 {
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
649 GSList *sl_user;
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
650 roster *roster_usr;
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
651
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
652 sl_user = roster_find(jid, jidsearch,
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
653 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
654 if (sl_user == NULL)
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
655 return NULL; // Not in the roster...
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
656
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
657 roster_usr = (roster*)sl_user->data;
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
658 return roster_usr->nickname;
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
659 }
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
660
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
661 void roster_settype(const char *jid, guint type)
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
662 {
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
663 GSList *sl_user;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
664 roster *roster_usr;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
665
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
666 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
667 return;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
668
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
669 roster_usr = (roster*)sl_user->data;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
670 roster_usr->type = type;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
671 }
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
672
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
673 enum imstatus roster_getstatus(const char *jid, const char *resname)
90
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
674 {
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
675 GSList *sl_user;
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
676 roster *roster_usr;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
677 res *p_res;
90
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
678
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
679 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
680 if (sl_user == NULL)
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
681 return offline; // Not in the roster, anyway...
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
682
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
683 roster_usr = (roster*)sl_user->data;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
684 p_res = get_resource(roster_usr, resname);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
685 if (p_res)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
686 return p_res->status;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
687 return offline;
90
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
688 }
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
689
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
690 const char *roster_getstatusmsg(const char *jid, const char *resname)
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
691 {
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
692 GSList *sl_user;
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
693 roster *roster_usr;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
694 res *p_res;
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
695
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
696 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
697 if (sl_user == NULL)
425
03f1e37759a6 roster_getstatusmsg() should return a pointer
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
698 return NULL; // Not in the roster, anyway...
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
699
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
700 roster_usr = (roster*)sl_user->data;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
701 p_res = get_resource(roster_usr, resname);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
702 if (p_res)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
703 return p_res->status_msg;
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
704 return roster_usr->offline_status_message;
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
705 }
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
706
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
707 guint roster_gettype(const char *jid)
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
708 {
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
709 GSList *sl_user;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
710 roster *roster_usr;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
711
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
712 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
713 return 0;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
714
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
715 roster_usr = (roster*)sl_user->data;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
716 return roster_usr->type;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
717 }
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
718
819
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
719 guint roster_getsubscription(const char *jid)
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
720 {
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
721 GSList *sl_user;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
722 roster *roster_usr;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
723
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
724 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
725 return 0;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
726
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
727 roster_usr = (roster*)sl_user->data;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
728 return roster_usr->subscription;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
729 }
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
730
610
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
731 // roster_unsubscribed()
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
732 // We have lost buddy's presence updates; this function clears the status
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
733 // message, sets the buddy offline and frees the resources
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
734 void roster_unsubscribed(const char *jid)
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
735 {
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
736 GSList *sl_user;
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
737 roster *roster_usr;
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
738
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
739 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
740 if (sl_user == NULL)
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
741 return;
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
742
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
743 roster_usr = (roster*)sl_user->data;
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
744 free_all_resources(&roster_usr->resource);
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
745 }
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
746
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
747
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
748 /* ### BuddyList functions ### */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
749
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
750 // buddylist_set_hide_offline_buddies(hide)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
751 // "hide" values: 1=hide 0=show_all -1=invert
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
752 void buddylist_set_hide_offline_buddies(int hide)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
753 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
754 if (hide < 0) // NEG (invert)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
755 hide_offline_buddies = !hide_offline_buddies;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
756 else if (hide == 0) // FALSE (don't hide)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
757 hide_offline_buddies = 0;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
758 else // TRUE (hide)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
759 hide_offline_buddies = 1;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
760 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
761
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
762 inline int buddylist_get_hide_offline_buddies(void)
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
763 {
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
764 return hide_offline_buddies;
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
765 }
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
766
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
767 // buddylist_build()
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
768 // Creates the buddylist from the roster entries.
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
769 void buddylist_build(void)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
770 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
771 GSList *sl_roster_elt = groups;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
772 roster *roster_elt;
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
773 roster *roster_current_buddy = NULL;
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
774 roster *roster_alternate_buddy = NULL;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
775 int shrunk_group;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
776
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
777 // We need to remember which buddy is selected.
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
778 if (current_buddy)
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
779 roster_current_buddy = BUDDATA(current_buddy);
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
780 current_buddy = NULL;
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
781 if (alternate_buddy)
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
782 roster_alternate_buddy = BUDDATA(alternate_buddy);
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
783 alternate_buddy = NULL;
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
784
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
785 // Destroy old buddylist
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
786 if (buddylist) {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
787 g_list_free(buddylist);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
788 buddylist = NULL;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
789 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
790
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
791 buddylist = g_list_append(buddylist, &roster_special);
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
792
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
793 // Create the new list
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
794 while (sl_roster_elt) {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
795 GSList *sl_roster_usrelt;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
796 roster *roster_usrelt;
147
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
797 guint pending_group = FALSE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
798 roster_elt = (roster*) sl_roster_elt->data;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
799
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
800 // Add the group now unless hide_offline_buddies is set,
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
801 // in which case we'll add it only if an online buddy belongs to it.
147
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
802 // We take care to keep the current_buddy in the list, too.
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
803 if (!hide_offline_buddies || roster_elt == roster_current_buddy)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
804 buddylist = g_list_append(buddylist, roster_elt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
805 else
147
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
806 pending_group = TRUE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
807
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
808 shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
809
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
810 sl_roster_usrelt = roster_elt->list;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
811 while (sl_roster_usrelt) {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
812 roster_usrelt = (roster*) sl_roster_usrelt->data;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
813
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
814 // Buddy will be added if either:
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
815 // - hide_offline_buddies is FALSE
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
816 // - buddy is not offline
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
817 // - buddy has a lock (for example the buddy window is currently open)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
818 // - buddy has a pending (non-read) message
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
819 // - group isn't hidden (shrunk)
147
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
820 // - this is the current_buddy
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
821 if (!hide_offline_buddies || roster_usrelt == roster_current_buddy ||
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
822 (buddy_getstatus((gpointer)roster_usrelt, NULL) != offline) ||
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
823 (buddy_getflags((gpointer)roster_usrelt) &
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 952
diff changeset
824 (ROSTER_FLAG_LOCK | ROSTER_FLAG_USRLOCK | ROSTER_FLAG_MSG))) {
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
825 // This user should be added. Maybe the group hasn't been added yet?
147
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
826 if (pending_group &&
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
827 (hide_offline_buddies || roster_usrelt == roster_current_buddy)) {
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
828 // It hasn't been done yet
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
829 buddylist = g_list_append(buddylist, roster_elt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
830 pending_group = FALSE;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
831 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
832 // Add user
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
833 // XXX Should we add the user if there is a message and
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
834 // the group is shrunk? If so, we'd need to check LOCK flag too,
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
835 // perhaps...
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
836 if (!shrunk_group)
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
837 buddylist = g_list_append(buddylist, roster_usrelt);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
838 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
839
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
840 sl_roster_usrelt = g_slist_next(sl_roster_usrelt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
841 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
842 sl_roster_elt = g_slist_next(sl_roster_elt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
843 }
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
844
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
845 // Check if we can find our saved current_buddy...
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
846 if (roster_current_buddy)
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
847 current_buddy = g_list_find(buddylist, roster_current_buddy);
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
848 if (roster_alternate_buddy)
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
849 alternate_buddy = g_list_find(buddylist, roster_alternate_buddy);
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
850 // current_buddy initialization
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
851 if (!current_buddy || (g_list_position(buddylist, current_buddy) == -1))
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
852 current_buddy = g_list_first(buddylist);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
853 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
854
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
855 // buddy_hide_group(roster, hide)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
856 // "hide" values: 1=hide 0=show_all -1=invert
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
857 void buddy_hide_group(gpointer rosterdata, int hide)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
858 {
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
859 roster *roster_usr = rosterdata;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
860 if (hide > 0) // TRUE (hide)
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
861 roster_usr->flags |= ROSTER_FLAG_HIDE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
862 else if (hide < 0) // NEG (invert)
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
863 roster_usr->flags ^= ROSTER_FLAG_HIDE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
864 else // FALSE (don't hide)
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
865 roster_usr->flags &= ~ROSTER_FLAG_HIDE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
866 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
867
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
868 const char *buddy_getjid(gpointer rosterdata)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
869 {
1292
382ec54b584e Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1205
diff changeset
870 if (!rosterdata)
382ec54b584e Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1205
diff changeset
871 return NULL;
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
872 roster *roster_usr = rosterdata;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
873 return roster_usr->jid;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
874 }
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
875
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
876 // buddy_setgroup()
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
877 // Change the group of current buddy
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
878 //
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
879 void buddy_setgroup(gpointer rosterdata, char *newgroupname)
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
880 {
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
881 roster *roster_usr = rosterdata;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
882 GSList **sl_group;
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
883 GSList *sl_newgroup;
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
884 roster *my_newgroup;
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
885
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
886 // A group has no group :)
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
887 if (roster_usr->type & ROSTER_TYPE_GROUP) return;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
888
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
889 // Add newgroup if necessary
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
890 if (!newgroupname) newgroupname = "";
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
891 sl_newgroup = roster_add_group(newgroupname);
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
892 if (!sl_newgroup) return;
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
893 my_newgroup = (roster*)sl_newgroup->data;
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
894
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
895 // Remove the buddy from current group
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
896 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
897 *sl_group = g_slist_remove(*sl_group, rosterdata);
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
898
621
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
899 // Remove old group if it is empty
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
900 if (!*sl_group) {
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
901 roster *roster_grp = (roster*)((GSList*)roster_usr->list)->data;
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
902 g_free((gchar*)roster_grp->jid);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
903 g_free((gchar*)roster_grp->name);
621
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
904 g_free(roster_grp);
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
905 groups = g_slist_remove(groups, roster_grp);
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
906 }
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
907
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
908 // Add the buddy to its new group
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
909 roster_usr->list = sl_newgroup; // (my_newgroup SList element)
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
910 my_newgroup->list = g_slist_insert_sorted(my_newgroup->list, roster_usr,
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
911 (GCompareFunc)&roster_compare_name);
212
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
912
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
913 buddylist_build();
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
914 }
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
915
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
916 void buddy_setname(gpointer rosterdata, char *newname)
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
917 {
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
918 roster *roster_usr = rosterdata;
209
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
919 GSList **sl_group;
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
920
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
921 // TODO For groups, we need to check for unicity
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
922 // However, renaming a group boils down to moving all its buddies to
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
923 // another group, so calling this function is not really necessary...
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
924 if (roster_usr->type & ROSTER_TYPE_GROUP) return;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
925
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
926 if (roster_usr->name) {
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
927 g_free((gchar*)roster_usr->name);
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
928 roster_usr->name = NULL;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
929 }
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
930 if (newname)
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
931 roster_usr->name = g_strdup(newname);
209
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
932
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
933 // We need to resort the group list
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
934 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list;
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
935 *sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name);
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
936
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
937 buddylist_build();
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
938 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
939
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
940 const char *buddy_getname(gpointer rosterdata)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
941 {
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
942 roster *roster_usr = rosterdata;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
943 return roster_usr->name;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
944 }
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
945
548
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
946 // buddy_setnickname(buddy, newnickname)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
947 // Only for chatrooms
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
948 void buddy_setnickname(gpointer rosterdata, const char *newname)
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
949 {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
950 roster *roster_usr = rosterdata;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
951
649
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
952 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; // XXX Error message?
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
953
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
954 if (roster_usr->nickname) {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
955 g_free((gchar*)roster_usr->nickname);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
956 roster_usr->nickname = NULL;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
957 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
958 if (newname)
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
959 roster_usr->nickname = g_strdup(newname);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
960 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
961
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
962 const char *buddy_getnickname(gpointer rosterdata)
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
963 {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
964 roster *roster_usr = rosterdata;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
965 return roster_usr->nickname;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
966 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
967
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
968 // buddy_setinsideroom(buddy, inside)
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
969 // Only for chatrooms
952
527d6f234924 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
970 void buddy_setinsideroom(gpointer rosterdata, guint inside)
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
971 {
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
972 roster *roster_usr = rosterdata;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
973
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
974 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
975
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
976 roster_usr->inside_room = inside;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
977 }
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
978
952
527d6f234924 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
979 guint buddy_getinsideroom(gpointer rosterdata)
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
980 {
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
981 roster *roster_usr = rosterdata;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
982 return roster_usr->inside_room;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
983 }
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
984
548
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
985 // buddy_settopic(buddy, newtopic)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
986 // Only for chatrooms
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
987 void buddy_settopic(gpointer rosterdata, const char *newtopic)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
988 {
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
989 roster *roster_usr = rosterdata;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
990
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
991 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
992
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
993 if (roster_usr->topic) {
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
994 g_free((gchar*)roster_usr->topic);
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
995 roster_usr->topic = NULL;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
996 }
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
997 if (newtopic)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
998 roster_usr->topic = g_strdup(newtopic);
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
999 }
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1000
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1001 const char *buddy_gettopic(gpointer rosterdata)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1002 {
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1003 roster *roster_usr = rosterdata;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1004 return roster_usr->topic;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1005 }
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1006
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1007 // buddy_getgroupname()
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1008 // Returns a pointer on buddy's group name.
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1009 const char *buddy_getgroupname(gpointer rosterdata)
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1010 {
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1011 roster *roster_usr = rosterdata;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1012
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1013 if (roster_usr->type & ROSTER_TYPE_GROUP)
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1014 return roster_usr->name;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1015
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
1016 if (roster_usr->type & ROSTER_TYPE_SPECIAL)
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
1017 return NULL;
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
1018
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1019 // This is a user
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1020 return ((roster*)((GSList*)roster_usr->list)->data)->name;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1021 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1022
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1023 // buddy_getgroup()
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1024 // Returns a pointer on buddy's group.
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1025 gpointer buddy_getgroup(gpointer rosterdata)
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1026 {
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1027 roster *roster_usr = rosterdata;
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1028
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1029 if (roster_usr->type & ROSTER_TYPE_GROUP)
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1030 return rosterdata;
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1031
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
1032 if (roster_usr->type & ROSTER_TYPE_SPECIAL)
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
1033 return NULL;
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
1034
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1035 // This is a user
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1036 return (gpointer)((GSList*)roster_usr->list)->data;
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1037 }
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
1038
489
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 483
diff changeset
1039 void buddy_settype(gpointer rosterdata, guint type)
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 483
diff changeset
1040 {
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 483
diff changeset
1041 roster *roster_usr = rosterdata;
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 483
diff changeset
1042 roster_usr->type = type;
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 483
diff changeset
1043 }
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 483
diff changeset
1044
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1045 guint buddy_gettype(gpointer rosterdata)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1046 {
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1047 roster *roster_usr = rosterdata;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1048 return roster_usr->type;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1049 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1050
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1051 guint buddy_getsubscription(gpointer rosterdata)
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1052 {
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1053 roster *roster_usr = rosterdata;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1054 return roster_usr->subscription;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1055 }
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1056
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1057 enum imstatus buddy_getstatus(gpointer rosterdata, const char *resname)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1058 {
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1059 roster *roster_usr = rosterdata;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1060 res *p_res = get_resource(roster_usr, resname);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1061 if (p_res)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1062 return p_res->status;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1063 return offline;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1064 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1065
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1066 const char *buddy_getstatusmsg(gpointer rosterdata, const char *resname)
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 214
diff changeset
1067 {
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 214
diff changeset
1068 roster *roster_usr = rosterdata;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1069 res *p_res = get_resource(roster_usr, resname);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1070 if (p_res)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
1071 return p_res->status_msg;
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
1072 return roster_usr->offline_status_message;
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 214
diff changeset
1073 }
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 214
diff changeset
1074
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1075 time_t buddy_getstatustime(gpointer rosterdata, const char *resname)
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1076 {
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1077 roster *roster_usr = rosterdata;
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1078 res *p_res = get_resource(roster_usr, resname);
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1079 if (p_res)
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1080 return p_res->status_timestamp;
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1081 return 0;
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1082 }
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
1083
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1084 gchar buddy_getresourceprio(gpointer rosterdata, const char *resname)
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1085 {
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1086 roster *roster_usr = rosterdata;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1087 res *p_res = get_resource(roster_usr, resname);
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1088 if (p_res)
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1089 return p_res->prio;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1090 return 0;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1091 }
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1092
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1093 guint buddy_resource_getevents(gpointer rosterdata, const char *resname)
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1094 {
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1095 roster *roster_usr = rosterdata;
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1096 res *p_res = get_resource(roster_usr, resname);
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1097 if (p_res)
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1098 return p_res->events;
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1099 return ROSTER_EVENT_NONE;
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1100 }
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1101
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1102 void buddy_resource_setevents(gpointer rosterdata, const char *resname,
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1103 guint events)
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1104 {
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1105 roster *roster_usr = rosterdata;
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1106 res *p_res = get_resource(roster_usr, resname);
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1107 if (p_res)
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1108 p_res->events = events;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1109 }
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1110
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1111 struct jep0022 *buddy_resource_jep22(gpointer rosterdata, const char *resname)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1112 {
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1113 #ifdef JEP0022
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1114 roster *roster_usr = rosterdata;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1115 res *p_res = get_resource(roster_usr, resname);
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1116 if (p_res)
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1117 return &p_res->jep22;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1118 #endif
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1119 return NULL;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1120 }
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1121
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1122 struct jep0085 *buddy_resource_jep85(gpointer rosterdata, const char *resname)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1123 {
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1124 #ifdef JEP0085
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1125 roster *roster_usr = rosterdata;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1126 res *p_res = get_resource(roster_usr, resname);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1127 if (p_res)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1128 return &p_res->jep85;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1129 #endif
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
1130 return NULL;
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1131 }
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1132
1043
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1133 struct pgp_data *buddy_resource_pgp(gpointer rosterdata, const char *resname)
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1134 {
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1135 #ifdef HAVE_GPGME
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1136 roster *roster_usr = rosterdata;
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1137 res *p_res = get_resource(roster_usr, resname);
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1138 if (p_res)
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1139 return &p_res->pgpdata;
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1140 #endif
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1141 return NULL;
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1142 }
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
1143
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1144 enum imrole buddy_getrole(gpointer rosterdata, const char *resname)
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1145 {
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1146 roster *roster_usr = rosterdata;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1147 res *p_res = get_resource(roster_usr, resname);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1148 if (p_res)
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1149 return p_res->role;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1150 return role_none;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1151 }
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1152
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1153 enum imaffiliation buddy_getaffil(gpointer rosterdata, const char *resname)
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1154 {
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1155 roster *roster_usr = rosterdata;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1156 res *p_res = get_resource(roster_usr, resname);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1157 if (p_res)
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1158 return p_res->affil;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1159 return affil_none;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1160 }
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1161
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1162 const char *buddy_getrjid(gpointer rosterdata, const char *resname)
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1163 {
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1164 roster *roster_usr = rosterdata;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1165 res *p_res = get_resource(roster_usr, resname);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1166 if (p_res)
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1167 return p_res->realjid;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1168 return NULL;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1169 }
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
1170
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1171 // buddy_getresources(roster_data)
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1172 // Return a singly-linked-list of resource names
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1173 // Note: the caller should free the list (and data) after use
501
7c1ca00070e8 Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents: 494
diff changeset
1174 // If roster_data is null, the current buddy is selected
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1175 GSList *buddy_getresources(gpointer rosterdata)
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1176 {
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1177 roster *roster_usr = rosterdata;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1178 GSList *reslist = NULL, *lp;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1179
501
7c1ca00070e8 Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents: 494
diff changeset
1180 if (!roster_usr) {
7c1ca00070e8 Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents: 494
diff changeset
1181 if (!current_buddy) return NULL;
7c1ca00070e8 Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents: 494
diff changeset
1182 roster_usr = BUDDATA(current_buddy);
7c1ca00070e8 Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents: 494
diff changeset
1183 }
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1184 for (lp = roster_usr->resource; lp; lp = g_slist_next(lp))
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1185 reslist = g_slist_append(reslist, g_strdup(((res*)lp->data)->name));
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1186
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1187 return reslist;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1188 }
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1189
792
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1190 // buddy_getresources_locale(roster_data)
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1191 // Same as buddy_getresources() but names are converted to user's locale
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1192 // Note: the caller should free the list (and data) after use
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1193 GSList *buddy_getresources_locale(gpointer rosterdata)
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1194 {
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1195 GSList *reslist, *lp;
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1196
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1197 reslist = buddy_getresources(rosterdata);
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1198 // Convert each item to UI's locale
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1199 for (lp = reslist; lp; lp = g_slist_next(lp)) {
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1200 gchar *oldname = lp->data;
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1201 lp->data = from_utf8(oldname);
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1202 if (lp->data)
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1203 g_free(oldname);
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1204 else
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1205 lp->data = oldname;
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1206 }
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1207 return reslist;
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1208 }
89ad7b530b3c MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 783
diff changeset
1209
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 649
diff changeset
1210 /*
539
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1211 // buddy_isresource(roster_data)
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1212 // Return true if there is at least one resource
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1213 // (which means, for a room, that it isn't empty)
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1214 int buddy_isresource(gpointer rosterdata)
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1215 {
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1216 roster *roster_usr = rosterdata;
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1217 if (!roster_usr)
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1218 return FALSE;
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1219 if (roster_usr->resource)
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1220 return TRUE;
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1221 return FALSE;
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1222 }
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 649
diff changeset
1223 */
539
ffdfddd351b8 Fix some memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
1224
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1225 // buddy_resource_setname(roster_data, oldname, newname)
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1226 // Useful for nickname change in a MUC room
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1227 void buddy_resource_setname(gpointer rosterdata, const char *resname,
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1228 const char *newname)
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1229 {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1230 roster *roster_usr = rosterdata;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1231 res *p_res = get_resource(roster_usr, resname);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1232 if (p_res) {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1233 if (p_res->name) {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1234 g_free((gchar*)p_res->name);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1235 p_res->name = NULL;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1236 }
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: