1 /*
2  * muc.h
3  * vim: expandtab:ts=4:sts=4:sw=4
4  *
5  * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
6  *
7  * This file is part of Profanity.
8  *
9  * Profanity is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Profanity is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
21  *
22  * In addition, as a special exception, the copyright holders give permission to
23  * link the code of portions of this program with the OpenSSL library under
24  * certain conditions as described in each individual source file, and
25  * distribute linked combinations including the two.
26  *
27  * You must obey the GNU General Public License in all respects for all of the
28  * code used other than OpenSSL. If you modify file(s) with this exception, you
29  * may extend this exception to your version of the file(s), but you are not
30  * obligated to do so. If you do not wish to do so, delete this exception
31  * statement from your version. If you delete this exception statement from all
32  * source files in the program, then also delete it here.
33  *
34  */
35 
36 #ifndef XMPP_MUC_H
37 #define XMPP_MUC_H
38 
39 #include <glib.h>
40 
41 #include "tools/autocomplete.h"
42 #include "ui/win_types.h"
43 #include "xmpp/contact.h"
44 #include "xmpp/jid.h"
45 
46 typedef enum {
47     MUC_ROLE_NONE,
48     MUC_ROLE_VISITOR,
49     MUC_ROLE_PARTICIPANT,
50     MUC_ROLE_MODERATOR
51 } muc_role_t;
52 
53 typedef enum {
54     MUC_AFFILIATION_NONE,
55     MUC_AFFILIATION_OUTCAST,
56     MUC_AFFILIATION_MEMBER,
57     MUC_AFFILIATION_ADMIN,
58     MUC_AFFILIATION_OWNER
59 } muc_affiliation_t;
60 
61 typedef enum {
62     MUC_MEMBER_TYPE_UNKNOWN,
63     MUC_MEMBER_TYPE_PUBLIC,
64     MUC_MEMBER_TYPE_MEMBERS_ONLY
65 } muc_member_type_t;
66 
67 typedef enum {
68     MUC_ANONYMITY_TYPE_UNKNOWN,
69     MUC_ANONYMITY_TYPE_NONANONYMOUS,
70     MUC_ANONYMITY_TYPE_SEMIANONYMOUS
71 } muc_anonymity_type_t;
72 
73 typedef struct _muc_occupant_t
74 {
75     char* nick;
76     gchar* nick_collate_key;
77     char* jid;
78     muc_role_t role;
79     muc_affiliation_t affiliation;
80     resource_presence_t presence;
81     char* status;
82 } Occupant;
83 
84 void muc_init(void);
85 void muc_close(void);
86 
87 void muc_join(const char* const room, const char* const nick, const char* const password, gboolean autojoin);
88 void muc_leave(const char* const room);
89 
90 gboolean muc_active(const char* const room);
91 gboolean muc_autojoin(const char* const room);
92 
93 GList* muc_rooms(void);
94 
95 void muc_set_features(const char* const room, GSList* features);
96 
97 char* muc_nick(const char* const room);
98 char* muc_password(const char* const room);
99 
100 void muc_nick_change_start(const char* const room, const char* const new_nick);
101 void muc_nick_change_complete(const char* const room, const char* const nick);
102 gboolean muc_nick_change_pending(const char* const room);
103 char* muc_old_nick(const char* const room, const char* const new_nick);
104 
105 gboolean muc_roster_contains_nick(const char* const room, const char* const nick);
106 gboolean muc_roster_complete(const char* const room);
107 gboolean muc_roster_add(const char* const room, const char* const nick, const char* const jid, const char* const role,
108                         const char* const affiliation, const char* const show, const char* const status);
109 void muc_roster_remove(const char* const room, const char* const nick);
110 void muc_roster_set_complete(const char* const room);
111 GList* muc_roster(const char* const room);
112 Autocomplete muc_roster_ac(const char* const room);
113 Autocomplete muc_roster_jid_ac(const char* const room);
114 void muc_jid_autocomplete_reset(const char* const room);
115 void muc_jid_autocomplete_add_all(const char* const room, GSList* jids);
116 
117 Occupant* muc_roster_item(const char* const room, const char* const nick);
118 
119 gboolean muc_occupant_available(Occupant* occupant);
120 const char* muc_occupant_affiliation_str(Occupant* occupant);
121 const char* muc_occupant_role_str(Occupant* occupant);
122 GSList* muc_occupants_by_role(const char* const room, muc_role_t role);
123 GSList* muc_occupants_by_affiliation(const char* const room, muc_affiliation_t affiliation);
124 
125 void muc_occupant_nick_change_start(const char* const room, const char* const new_nick, const char* const old_nick);
126 char* muc_roster_nick_change_complete(const char* const room, const char* const nick);
127 
128 void muc_confserver_add(const char* const server);
129 void muc_confserver_reset_ac(void);
130 char* muc_confserver_find(const char* const search_str, gboolean previous, void* context);
131 void muc_confserver_clear(void);
132 
133 void muc_invites_add(const char* const room, const char* const password);
134 void muc_invites_remove(const char* const room);
135 gint muc_invites_count(void);
136 GList* muc_invites(void);
137 gboolean muc_invites_contain(const char* const room);
138 void muc_invites_reset_ac(void);
139 char* muc_invites_find(const char* const search_str, gboolean previous, void* context);
140 void muc_invites_clear(void);
141 char* muc_invite_password(const char* const room);
142 
143 void muc_set_subject(const char* const room, const char* const subject);
144 char* muc_subject(const char* const room);
145 
146 void muc_pending_broadcasts_add(const char* const room, const char* const message);
147 GList* muc_pending_broadcasts(const char* const room);
148 
149 char* muc_autocomplete(ProfWin* window, const char* const input, gboolean previous);
150 void muc_autocomplete_reset(const char* const room);
151 
152 gboolean muc_requires_config(const char* const room);
153 void muc_set_requires_config(const char* const room, gboolean val);
154 
155 void muc_set_role(const char* const room, const char* const role);
156 void muc_set_affiliation(const char* const room, const char* const affiliation);
157 char* muc_role_str(const char* const room);
158 char* muc_affiliation_str(const char* const room);
159 
160 muc_member_type_t muc_member_type(const char* const room);
161 muc_anonymity_type_t muc_anonymity_type(const char* const room);
162 
163 GList* muc_members(const char* const room);
164 void muc_members_add(const char* const room, const char* const jid);
165 void muc_members_remove(const char* const room, const char* const jid);
166 void muc_members_update(const char* const room, const char* const jid, const char* const affiliation);
167 
168 #endif
169