im_notif_policy.c 7.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*
linphone
Copyright (C) 2010-2016 Belledonne Communications SARL

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "linphone/core.h"
#include "private.h"


BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneImNotifPolicy);

BELLE_SIP_INSTANCIATE_VPTR(LinphoneImNotifPolicy, belle_sip_object_t,
	NULL, // destroy
	NULL, // clone
	NULL, // marshal
	FALSE
);


static void load_im_notif_policy_from_config(LinphoneImNotifPolicy *policy) {
	bctbx_list_t *default_list = bctbx_list_append(NULL, "all");
	bctbx_list_t *values = lp_config_get_string_list(policy->lc->config, "sip", "im_notif_policy", default_list);
	bctbx_list_t *elem;

	for (elem = values; elem != NULL; elem = bctbx_list_next(elem)) {
		const char *value = (const char *)bctbx_list_get_data(elem);
		if (strcasecmp(value, "all") == 0) {
			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 49
		} else if (strcasecmp(value, "none") == 0) {
			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 56
		} else if (strcasecmp(value, "send_is_comp") == 0) {
			policy->send_is_composing = TRUE;
57 58
		} else if (strcasecmp(value, "recv_is_comp") == 0) {
			policy->recv_is_composing = TRUE;
59 60
		} else if (strcasecmp(value, "send_imdn_delivered") == 0) {
			policy->send_imdn_delivered = TRUE;
61 62
		} else if (strcasecmp(value, "recv_imdn_delivered") == 0) {
			policy->recv_imdn_delivered = TRUE;
63 64
		} else if (strcasecmp(value, "send_imdn_displayed") == 0) {
			policy->send_imdn_displayed = TRUE;
65 66
		} else if (strcasecmp(value, "recv_imdn_displayed") == 0) {
			policy->recv_imdn_displayed = TRUE;
67 68 69 70 71 72 73 74 75 76 77
		}
	}
	if (values != default_list) {
		bctbx_list_free_with_data(values, ms_free);
	}
	bctbx_list_free(default_list);
}

static void save_im_notif_policy_to_config(LinphoneImNotifPolicy *policy) {
	bctbx_list_t *values = NULL;
	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 84
		/* Do not save anything, the default is everything enabled */
	} 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 91 92 93
		values = bctbx_list_append(values, "none");
	} else {
		if (policy->send_is_composing == TRUE)
			values = bctbx_list_append(values, "send_is_comp");
94 95
		if (policy->recv_is_composing == TRUE)
			values = bctbx_list_append(values, "recv_is_comp");
96 97
		if (policy->send_imdn_delivered == TRUE)
			values = bctbx_list_append(values, "send_imdn_delivered");
98 99
		if (policy->recv_imdn_delivered == TRUE)
			values = bctbx_list_append(values, "recv_imdn_delivered");
100 101
		if (policy->send_imdn_displayed == TRUE)
			values = bctbx_list_append(values, "send_imdn_displayed");
102 103
		if (policy->recv_imdn_displayed == TRUE)
			values = bctbx_list_append(values, "recv_imdn_displayed");
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
	}
	lp_config_set_string_list(policy->lc->config, "sip", "im_notif_policy", values);
	if (values != NULL) bctbx_list_free(values);
}

LinphoneImNotifPolicy * linphone_im_notif_policy_ref(LinphoneImNotifPolicy *policy) {
	belle_sip_object_ref(policy);
	return policy;
}

void linphone_im_notif_policy_unref(LinphoneImNotifPolicy *policy) {
	belle_sip_object_unref(policy);
}

void *linphone_im_notif_policy_get_user_data(const LinphoneImNotifPolicy *policy) {
	return policy->user_data;
}

void linphone_im_notif_policy_set_user_data(LinphoneImNotifPolicy *policy, void *ud) {
	policy->user_data = ud;
}


void linphone_im_notif_policy_clear(LinphoneImNotifPolicy *policy) {
	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 134 135 136 137 138 139 140 141 142 143
	policy->recv_imdn_displayed = FALSE;
	save_im_notif_policy_to_config(policy);
}

void linphone_im_notif_policy_enable_all(LinphoneImNotifPolicy *policy) {
	policy->send_is_composing = TRUE;
	policy->recv_is_composing = TRUE;
	policy->send_imdn_delivered = TRUE;
	policy->recv_imdn_delivered = TRUE;
	policy->send_imdn_displayed = TRUE;
	policy->recv_imdn_displayed = TRUE;
144 145 146 147 148 149 150 151 152 153 154 155
	save_im_notif_policy_to_config(policy);
}

bool_t linphone_im_notif_policy_get_send_is_composing(const LinphoneImNotifPolicy *policy) {
	return policy->send_is_composing;
}

void linphone_im_notif_policy_set_send_is_composing(LinphoneImNotifPolicy *policy, bool_t enable) {
	policy->send_is_composing = enable;
	save_im_notif_policy_to_config(policy);
}

156 157
bool_t linphone_im_notif_policy_get_recv_is_composing(const LinphoneImNotifPolicy *policy) {
	return policy->recv_is_composing;
158 159
}

160 161
void linphone_im_notif_policy_set_recv_is_composing(LinphoneImNotifPolicy *policy, bool_t enable) {
	policy->recv_is_composing = enable;
162 163 164 165 166 167 168 169 170 171 172 173
	save_im_notif_policy_to_config(policy);
}

bool_t linphone_im_notif_policy_get_send_imdn_delivered(const LinphoneImNotifPolicy *policy) {
	return policy->send_imdn_delivered;
}

void linphone_im_notif_policy_set_send_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable) {
	policy->send_imdn_delivered = enable;
	save_im_notif_policy_to_config(policy);
}

174 175
bool_t linphone_im_notif_policy_get_recv_imdn_delivered(const LinphoneImNotifPolicy *policy) {
	return policy->recv_imdn_delivered;
176 177
}

178 179
void linphone_im_notif_policy_set_recv_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable) {
	policy->recv_imdn_delivered = enable;
180 181 182 183 184 185 186 187 188 189 190 191
	save_im_notif_policy_to_config(policy);
}

bool_t linphone_im_notif_policy_get_send_imdn_displayed(const LinphoneImNotifPolicy *policy) {
	return policy->send_imdn_displayed;
}

void linphone_im_notif_policy_set_send_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable) {
	policy->send_imdn_displayed = enable;
	save_im_notif_policy_to_config(policy);
}

192 193
bool_t linphone_im_notif_policy_get_recv_imdn_displayed(const LinphoneImNotifPolicy *policy) {
	return policy->recv_imdn_displayed;
194 195
}

196 197
void linphone_im_notif_policy_set_recv_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable) {
	policy->recv_imdn_displayed = enable;
198 199 200 201 202 203 204 205 206 207 208 209 210
	save_im_notif_policy_to_config(policy);
}

LinphoneImNotifPolicy * linphone_core_get_im_notif_policy(const LinphoneCore *lc) {
	return lc->im_notif_policy;
}

void linphone_core_create_im_notif_policy(LinphoneCore *lc) {
	lc->im_notif_policy = belle_sip_object_new(LinphoneImNotifPolicy);
	lc->im_notif_policy->lc = lc;
	load_im_notif_policy_from_config(lc->im_notif_policy);
	save_im_notif_policy_to_config(lc->im_notif_policy);
}