From f9eaa1a0f15e0a7fcc0d0b1029620203fb37f367 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 19 Feb 2016 15:14:28 +0100 Subject: [PATCH] Handle body compression for presence list. --- coreapi/bellesip_sal/sal_impl.c | 4 ++++ coreapi/friendlist.c | 4 ++++ coreapi/linphonecore.c | 6 ++++++ coreapi/linphonecore.h | 2 ++ include/sal/sal.h | 1 + tester/presence_tester.c | 24 +++++++++++++++++++++++- 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index 6be8142e6..b3ebfb3e7 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -595,6 +595,10 @@ int sal_transport_available(Sal *sal, SalTransport t){ return FALSE; } +bool_t sal_content_encoding_available(Sal *sal, const char *content_encoding) { + return (bool_t)belle_sip_stack_content_encoding_available(sal->stack, content_encoding); +} + static int sal_add_listen_port(Sal *ctx, SalAddress* addr, bool_t is_tunneled){ int result; belle_sip_listening_point_t* lp; diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index ef3919b4a..6780bec4c 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -419,6 +419,10 @@ void linphone_friend_list_update_subscriptions(LinphoneFriendList *list, Linphon linphone_content_set_type(content, "application"); linphone_content_set_subtype(content, "resource-lists+xml"); linphone_content_set_string_buffer(content, xml_content); + if (linphone_core_content_encoding_supported(list->lc, "deflate")) { + linphone_content_set_encoding(content, "deflate"); + linphone_event_add_custom_header(list->event, "Accept-Encoding", "deflate"); + } linphone_event_send_subscribe(list->event, content); linphone_content_unref(content); linphone_event_set_user_data(list->event, list); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 332617399..375ad5a56 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2454,6 +2454,12 @@ void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){ } +bool_t linphone_core_content_encoding_supported(const LinphoneCore *lc, const char *content_encoding) { + const char *handle_content_encoding = lp_config_get_string(lc->config, "sip", "handle_content_encoding", "deflate"); + return (strcmp(handle_content_encoding, content_encoding) == 0) && sal_content_encoding_available(lc->sal, content_encoding); +} + + static void monitor_network_state(LinphoneCore *lc, time_t curtime){ bool_t new_status=lc->network_last_status; char newip[LINPHONE_IPADDR_SIZE]; diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 772f82276..42d326353 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -3073,6 +3073,8 @@ LINPHONE_PUBLIC void linphone_core_get_sip_transports_used(LinphoneCore *lc, LCS LINPHONE_PUBLIC bool_t linphone_core_sip_transport_supported(const LinphoneCore *lc, LinphoneTransportType tp); +LINPHONE_PUBLIC bool_t linphone_core_content_encoding_supported(const LinphoneCore *lc, const char *content_encoding); + /** * * Give access to the UDP sip socket. Can be useful to configure this socket as persistent I.E kCFStreamNetworkServiceType set to kCFStreamNetworkServiceTypeVoIP) diff --git a/include/sal/sal.h b/include/sal/sal.h index e24007175..e24cd2b52 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -587,6 +587,7 @@ int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int i int sal_get_listening_port(Sal *ctx, SalTransport tr); int sal_unlisten_ports(Sal *ctx); LINPHONE_PUBLIC int sal_transport_available(Sal *ctx, SalTransport t); +LINPHONE_PUBLIC bool_t sal_content_encoding_available(Sal *ctx, const char *content_encoding); void sal_set_dscp(Sal *ctx, int dscp); void sal_set_supported_tags(Sal *ctx, const char* tags); void sal_add_supported_tag(Sal *ctx, const char* tag); diff --git a/tester/presence_tester.c b/tester/presence_tester.c index d529e6888..ff9f713b5 100644 --- a/tester/presence_tester.c +++ b/tester/presence_tester.c @@ -677,7 +677,15 @@ static void enable_publish(LinphoneCoreManager *mgr, bool_t enable) { linphone_proxy_config_done(cfg); } -static void test_presence_list(void) { +static void enable_deflate_content_encoding(LinphoneCoreManager *mgr, bool_t enable) { + LinphoneCore *lc = mgr->lc; + if (enable == TRUE) + lp_config_set_string(lc->config, "sip", "handle_content_encoding", "deflate"); + else + lp_config_set_string(lc->config, "sip", "handle_content_encoding", "none"); +} + +static void test_presence_list_base(bool_t enable_compression) { LinphoneCoreManager *laure = linphone_core_manager_new("laure_tcp_rc"); LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_rc"); @@ -696,6 +704,9 @@ static void test_presence_list(void) { enable_publish(marie, TRUE); enable_publish(pauline, TRUE); enable_publish(laure, TRUE); + enable_deflate_content_encoding(marie, enable_compression); + enable_deflate_content_encoding(pauline, enable_compression); + enable_deflate_content_encoding(laure, enable_compression); linphone_core_set_presence_model(marie->lc, linphone_core_create_presence_model_with_activity(marie->lc, LinphonePresenceActivityBusy, NULL)); linphone_core_set_presence_model(pauline->lc, linphone_core_create_presence_model_with_activity(pauline->lc, LinphonePresenceActivityVacation, NULL)); @@ -801,6 +812,15 @@ static void test_presence_list(void) { linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } + +static void test_presence_list(void) { + test_presence_list_base(TRUE); +} + +static void test_presence_list_without_compression(void) { + test_presence_list_base(FALSE); +} + #if 0 static void test_presence_list_subscribe_before_publish(void) { LinphoneCoreManager *laure = linphone_core_manager_new("laure_tcp_rc"); @@ -852,6 +872,7 @@ static void test_presence_list_subscribe_before_publish(void) { linphone_core_manager_destroy(pauline); } #endif + static void test_presence_list_subscription_expire_for_unknown(void) { LinphoneCoreManager *laure = linphone_core_manager_new("laure_tcp_rc"); const char *rls_uri = "sip:rls@sip.example.org"; @@ -968,6 +989,7 @@ test_t presence_tests[] = { TEST_NO_TAG("Subscribe with late publish", test_subscribe_notify_publish), TEST_NO_TAG("Forked subscribe with late publish", test_forked_subscribe_notify_publish), TEST_NO_TAG("Presence list", test_presence_list), + TEST_NO_TAG("Presence list without compression", test_presence_list_without_compression), TEST_NO_TAG("Presence list, subscription expiration for unknown contact",test_presence_list_subscription_expire_for_unknown), TEST_NO_TAG("Presence list, silent subscription expiration", test_presence_list_subscribe_dialog_expire), TEST_NO_TAG("Presence list, io error",test_presence_list_subscribe_io_error)