1 /*
2 linphone
3 Copyright (C) 2010-2016 Belledonne Communications SARL
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "linphone/core.h"
21 #include "private.h"
22
23
24 BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneImNotifPolicy);
25
26 BELLE_SIP_INSTANCIATE_VPTR(LinphoneImNotifPolicy, belle_sip_object_t,
27 NULL, // destroy
28 NULL, // clone
29 NULL, // marshal
30 FALSE
31 );
32
33
load_im_notif_policy_from_config(LinphoneImNotifPolicy * policy)34 static void load_im_notif_policy_from_config(LinphoneImNotifPolicy *policy) {
35 bctbx_list_t *default_list = bctbx_list_append(NULL, "all");
36 bctbx_list_t *values = lp_config_get_string_list(policy->lc->config, "sip", "im_notif_policy", default_list);
37 bctbx_list_t *elem;
38
39 for (elem = values; elem != NULL; elem = bctbx_list_next(elem)) {
40 const char *value = (const char *)bctbx_list_get_data(elem);
41 if (strcasecmp(value, "all") == 0) {
42 policy->send_is_composing = TRUE;
43 policy->recv_is_composing = TRUE;
44 policy->send_imdn_delivered = TRUE;
45 policy->recv_imdn_delivered = TRUE;
46 policy->send_imdn_displayed = TRUE;
47 policy->recv_imdn_displayed = TRUE;
48 } else if (strcasecmp(value, "none") == 0) {
49 policy->send_is_composing = FALSE;
50 policy->recv_is_composing = FALSE;
51 policy->send_imdn_delivered = FALSE;
52 policy->recv_imdn_delivered = FALSE;
53 policy->send_imdn_displayed = FALSE;
54 policy->recv_imdn_displayed = FALSE;
55 } else if (strcasecmp(value, "send_is_comp") == 0) {
56 policy->send_is_composing = TRUE;
57 } else if (strcasecmp(value, "recv_is_comp") == 0) {
58 policy->recv_is_composing = TRUE;
59 } else if (strcasecmp(value, "send_imdn_delivered") == 0) {
60 policy->send_imdn_delivered = TRUE;
61 } else if (strcasecmp(value, "recv_imdn_delivered") == 0) {
62 policy->recv_imdn_delivered = TRUE;
63 } else if (strcasecmp(value, "send_imdn_displayed") == 0) {
64 policy->send_imdn_displayed = TRUE;
65 } else if (strcasecmp(value, "recv_imdn_displayed") == 0) {
66 policy->recv_imdn_displayed = TRUE;
67 }
68 }
69 if (values != default_list) {
70 bctbx_list_free_with_data(values, ms_free);
71 }
72 bctbx_list_free(default_list);
73 }
74
save_im_notif_policy_to_config(LinphoneImNotifPolicy * policy)75 static void save_im_notif_policy_to_config(LinphoneImNotifPolicy *policy) {
76 bctbx_list_t *values = NULL;
77 if ((policy->send_is_composing == TRUE)
78 && (policy->recv_is_composing == TRUE)
79 && (policy->send_imdn_delivered == TRUE)
80 && (policy->recv_imdn_delivered == TRUE)
81 && (policy->send_imdn_displayed == TRUE)
82 && (policy->recv_imdn_displayed == TRUE)) {
83 /* Do not save anything, the default is everything enabled */
84 } else if ((policy->send_is_composing == FALSE)
85 && (policy->recv_is_composing == FALSE)
86 && (policy->send_imdn_delivered == FALSE)
87 && (policy->recv_imdn_delivered == FALSE)
88 && (policy->send_imdn_displayed == FALSE)
89 && (policy->recv_imdn_displayed == FALSE)) {
90 values = bctbx_list_append(values, "none");
91 } else {
92 if (policy->send_is_composing == TRUE)
93 values = bctbx_list_append(values, "send_is_comp");
94 if (policy->recv_is_composing == TRUE)
95 values = bctbx_list_append(values, "recv_is_comp");
96 if (policy->send_imdn_delivered == TRUE)
97 values = bctbx_list_append(values, "send_imdn_delivered");
98 if (policy->recv_imdn_delivered == TRUE)
99 values = bctbx_list_append(values, "recv_imdn_delivered");
100 if (policy->send_imdn_displayed == TRUE)
101 values = bctbx_list_append(values, "send_imdn_displayed");
102 if (policy->recv_imdn_displayed == TRUE)
103 values = bctbx_list_append(values, "recv_imdn_displayed");
104 }
105 lp_config_set_string_list(policy->lc->config, "sip", "im_notif_policy", values);
106 if (values != NULL) bctbx_list_free(values);
107 }
108
linphone_im_notif_policy_ref(LinphoneImNotifPolicy * policy)109 LinphoneImNotifPolicy * linphone_im_notif_policy_ref(LinphoneImNotifPolicy *policy) {
110 belle_sip_object_ref(policy);
111 return policy;
112 }
113
linphone_im_notif_policy_unref(LinphoneImNotifPolicy * policy)114 void linphone_im_notif_policy_unref(LinphoneImNotifPolicy *policy) {
115 belle_sip_object_unref(policy);
116 }
117
linphone_im_notif_policy_get_user_data(const LinphoneImNotifPolicy * policy)118 void *linphone_im_notif_policy_get_user_data(const LinphoneImNotifPolicy *policy) {
119 return policy->user_data;
120 }
121
linphone_im_notif_policy_set_user_data(LinphoneImNotifPolicy * policy,void * ud)122 void linphone_im_notif_policy_set_user_data(LinphoneImNotifPolicy *policy, void *ud) {
123 policy->user_data = ud;
124 }
125
126
linphone_im_notif_policy_clear(LinphoneImNotifPolicy * policy)127 void linphone_im_notif_policy_clear(LinphoneImNotifPolicy *policy) {
128 policy->send_is_composing = FALSE;
129 policy->recv_is_composing = FALSE;
130 policy->send_imdn_delivered = FALSE;
131 policy->recv_imdn_delivered = FALSE;
132 policy->send_imdn_displayed = FALSE;
133 policy->recv_imdn_displayed = FALSE;
134 save_im_notif_policy_to_config(policy);
135 }
136
linphone_im_notif_policy_enable_all(LinphoneImNotifPolicy * policy)137 void linphone_im_notif_policy_enable_all(LinphoneImNotifPolicy *policy) {
138 policy->send_is_composing = TRUE;
139 policy->recv_is_composing = TRUE;
140 policy->send_imdn_delivered = TRUE;
141 policy->recv_imdn_delivered = TRUE;
142 policy->send_imdn_displayed = TRUE;
143 policy->recv_imdn_displayed = TRUE;
144 save_im_notif_policy_to_config(policy);
145 }
146
linphone_im_notif_policy_get_send_is_composing(const LinphoneImNotifPolicy * policy)147 bool_t linphone_im_notif_policy_get_send_is_composing(const LinphoneImNotifPolicy *policy) {
148 return policy->send_is_composing;
149 }
150
linphone_im_notif_policy_set_send_is_composing(LinphoneImNotifPolicy * policy,bool_t enable)151 void linphone_im_notif_policy_set_send_is_composing(LinphoneImNotifPolicy *policy, bool_t enable) {
152 policy->send_is_composing = enable;
153 save_im_notif_policy_to_config(policy);
154 }
155
linphone_im_notif_policy_get_recv_is_composing(const LinphoneImNotifPolicy * policy)156 bool_t linphone_im_notif_policy_get_recv_is_composing(const LinphoneImNotifPolicy *policy) {
157 return policy->recv_is_composing;
158 }
159
linphone_im_notif_policy_set_recv_is_composing(LinphoneImNotifPolicy * policy,bool_t enable)160 void linphone_im_notif_policy_set_recv_is_composing(LinphoneImNotifPolicy *policy, bool_t enable) {
161 policy->recv_is_composing = enable;
162 save_im_notif_policy_to_config(policy);
163 }
164
linphone_im_notif_policy_get_send_imdn_delivered(const LinphoneImNotifPolicy * policy)165 bool_t linphone_im_notif_policy_get_send_imdn_delivered(const LinphoneImNotifPolicy *policy) {
166 return policy->send_imdn_delivered;
167 }
168
linphone_im_notif_policy_set_send_imdn_delivered(LinphoneImNotifPolicy * policy,bool_t enable)169 void linphone_im_notif_policy_set_send_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable) {
170 policy->send_imdn_delivered = enable;
171 save_im_notif_policy_to_config(policy);
172 }
173
linphone_im_notif_policy_get_recv_imdn_delivered(const LinphoneImNotifPolicy * policy)174 bool_t linphone_im_notif_policy_get_recv_imdn_delivered(const LinphoneImNotifPolicy *policy) {
175 return policy->recv_imdn_delivered;
176 }
177
linphone_im_notif_policy_set_recv_imdn_delivered(LinphoneImNotifPolicy * policy,bool_t enable)178 void linphone_im_notif_policy_set_recv_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable) {
179 policy->recv_imdn_delivered = enable;
180 save_im_notif_policy_to_config(policy);
181 }
182
linphone_im_notif_policy_get_send_imdn_displayed(const LinphoneImNotifPolicy * policy)183 bool_t linphone_im_notif_policy_get_send_imdn_displayed(const LinphoneImNotifPolicy *policy) {
184 return policy->send_imdn_displayed;
185 }
186
linphone_im_notif_policy_set_send_imdn_displayed(LinphoneImNotifPolicy * policy,bool_t enable)187 void linphone_im_notif_policy_set_send_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable) {
188 policy->send_imdn_displayed = enable;
189 save_im_notif_policy_to_config(policy);
190 }
191
linphone_im_notif_policy_get_recv_imdn_displayed(const LinphoneImNotifPolicy * policy)192 bool_t linphone_im_notif_policy_get_recv_imdn_displayed(const LinphoneImNotifPolicy *policy) {
193 return policy->recv_imdn_displayed;
194 }
195
linphone_im_notif_policy_set_recv_imdn_displayed(LinphoneImNotifPolicy * policy,bool_t enable)196 void linphone_im_notif_policy_set_recv_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable) {
197 policy->recv_imdn_displayed = enable;
198 save_im_notif_policy_to_config(policy);
199 }
200
linphone_core_get_im_notif_policy(const LinphoneCore * lc)201 LinphoneImNotifPolicy * linphone_core_get_im_notif_policy(const LinphoneCore *lc) {
202 return lc->im_notif_policy;
203 }
204
linphone_core_create_im_notif_policy(LinphoneCore * lc)205 void linphone_core_create_im_notif_policy(LinphoneCore *lc) {
206 lc->im_notif_policy = belle_sip_object_new(LinphoneImNotifPolicy);
207 lc->im_notif_policy->lc = lc;
208 load_im_notif_policy_from_config(lc->im_notif_policy);
209 save_im_notif_policy_to_config(lc->im_notif_policy);
210 }
211