From 05b045cb6714a09ce55eb2fce0f609d992e91edd Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 18 Apr 2017 17:28:46 +0200 Subject: [PATCH] Added missing set_user_data and get_user_data to LinphoneRange + created LinphoneTransports to replace LinphoneSipTransports --- coreapi/linphonecore.c | 130 ++++++++++++++++++++++++++------- coreapi/misc.c | 14 +++- coreapi/private.h | 16 ++++- include/linphone/core.h | 150 +++++++++++++++++++++++++++++++++------ include/linphone/misc.h | 26 +++++-- include/linphone/types.h | 21 +++--- 6 files changed, 292 insertions(+), 65 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 187a37bf5..184d94244 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2523,14 +2523,6 @@ void linphone_core_get_audio_port_range(const LinphoneCore *lc, int *min_port, i *max_port = lc->rtp_conf.audio_rtp_max_port; } -LinphoneIntRange linphone_core_get_audio_port_range_2(const LinphoneCore *lc) { - LinphoneIntRange range = { - .min = lc->rtp_conf.audio_rtp_min_port, - .max = lc->rtp_conf.audio_rtp_max_port - }; - return range; -} - LinphoneRange *linphone_core_get_audio_ports_range(const LinphoneCore *lc) { LinphoneRange *range = linphone_range_new(); range->min = lc->rtp_conf.audio_rtp_min_port; @@ -2547,14 +2539,6 @@ void linphone_core_get_video_port_range(const LinphoneCore *lc, int *min_port, i *max_port = lc->rtp_conf.video_rtp_max_port; } -LinphoneIntRange linphone_core_get_video_port_range_2(const LinphoneCore *lc) { - LinphoneIntRange range = { - .min = lc->rtp_conf.video_rtp_min_port, - .max = lc->rtp_conf.video_rtp_max_port - }; - return range; -} - LinphoneRange *linphone_core_get_video_ports_range(const LinphoneCore *lc) { LinphoneRange *range = linphone_range_new(); range->min = lc->rtp_conf.video_rtp_min_port; @@ -2571,14 +2555,6 @@ void linphone_core_get_text_port_range(const LinphoneCore *lc, int *min_port, in *max_port = lc->rtp_conf.text_rtp_max_port; } -LinphoneIntRange linphone_core_get_text_port_range_2(const LinphoneCore *lc) { - LinphoneIntRange range = { - .min = lc->rtp_conf.text_rtp_min_port, - .max = lc->rtp_conf.text_rtp_max_port - }; - return range; -} - LinphoneRange *linphone_core_get_text_ports_range(const LinphoneCore *lc) { LinphoneRange *range = linphone_range_new(); range->min = lc->rtp_conf.text_rtp_min_port; @@ -2787,6 +2763,72 @@ bool_t linphone_core_sip_transport_supported(const LinphoneCore *lc, LinphoneTra return sal_transport_available(lc->sal,(SalTransport)tp); } +BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneTransports); + +BELLE_SIP_INSTANCIATE_VPTR(LinphoneTransports, belle_sip_object_t, + NULL, // destroy + NULL, // clone + NULL, // marshal + FALSE +); + +LinphoneTransports *linphone_transports_new(LinphoneCore *lc) { + LinphoneTransports *transports = belle_sip_object_new(LinphoneTransports); + transports->udp_port = 0; + transports->tcp_port = 0; + transports->tls_port = 0; + transports->dtls_port = 0; + return transports; +} + +LinphoneTransports* linphone_transports_ref(LinphoneTransports* transports) { + return (LinphoneTransports*) belle_sip_object_ref(transports); +} + +void linphone_transports_unref (LinphoneTransports* transports) { + belle_sip_object_unref(transports); +} + +void *linphone_transports_get_user_data(const LinphoneTransports *transports) { + return transports->user_data; +} + +void linphone_transports_set_user_data(LinphoneTransports *transports, void *data) { + transports->user_data = data; +} + +int linphone_transports_get_udp_port(const LinphoneTransports* transports) { + return transports->udp_port; +} + +int linphone_transports_get_tcp_port(const LinphoneTransports* transports) { + return transports->tcp_port; +} + +int linphone_transports_get_tls_port(const LinphoneTransports* transports) { + return transports->tls_port; +} + +int linphone_transports_get_dtls_port(const LinphoneTransports* transports) { + return transports->dtls_port; +} + +void linphone_transports_set_udp_port(LinphoneTransports *transports, int port) { + transports->udp_port = port; +} + +void linphone_transports_set_tcp_port(LinphoneTransports *transports, int port) { + transports->tcp_port = port; +} + +void linphone_transports_set_tls_port(LinphoneTransports *transports, int port) { + transports->tls_port = port; +} + +void linphone_transports_set_dtls_port(LinphoneTransports *transports, int port) { + transports->dtls_port = port; +} + LinphoneStatus linphone_core_set_sip_transports(LinphoneCore *lc, const LinphoneSipTransports * tr_config /*config to be saved*/){ LinphoneSipTransports tr=*tr_config; @@ -2821,17 +2863,57 @@ LinphoneStatus linphone_core_set_sip_transports(LinphoneCore *lc, const Linphone return _linphone_core_apply_transports(lc); } +LinphoneStatus linphone_core_set_transports(LinphoneCore *lc, const LinphoneTransports * transports){ + if (transports->udp_port == lc->sip_conf.transports.udp_port && + transports->tcp_port == lc->sip_conf.transports.tcp_port && + transports->tls_port == lc->sip_conf.transports.tls_port && + transports->dtls_port == lc->sip_conf.transports.dtls_port) { + return 0; + } + lc->sip_conf.transports.udp_port = transports->udp_port; + lc->sip_conf.transports.tcp_port = transports->tcp_port; + lc->sip_conf.transports.tls_port = transports->tls_port; + lc->sip_conf.transports.dtls_port = transports->dtls_port; + + if (linphone_core_ready(lc)) { + lp_config_set_int(lc->config,"sip", "sip_port", transports->udp_port); + lp_config_set_int(lc->config,"sip", "sip_tcp_port", transports->tcp_port); + lp_config_set_int(lc->config,"sip", "sip_tls_port", transports->tls_port); + } + + if (lc->sal == NULL) return 0; + return _linphone_core_apply_transports(lc); +} + LinphoneStatus linphone_core_get_sip_transports(LinphoneCore *lc, LinphoneSipTransports *tr){ memcpy(tr,&lc->sip_conf.transports,sizeof(*tr)); return 0; } +LinphoneTransports *linphone_core_get_transports(LinphoneCore *lc){ + LinphoneTransports *transports = linphone_transports_new(lc); + transports->udp_port = lc->sip_conf.transports.udp_port; + transports->tcp_port = lc->sip_conf.transports.tcp_port; + transports->tls_port = lc->sip_conf.transports.tls_port; + transports->dtls_port = lc->sip_conf.transports.dtls_port; + return transports; +} + void linphone_core_get_sip_transports_used(LinphoneCore *lc, LinphoneSipTransports *tr){ tr->udp_port=sal_get_listening_port(lc->sal,SalTransportUDP); tr->tcp_port=sal_get_listening_port(lc->sal,SalTransportTCP); tr->tls_port=sal_get_listening_port(lc->sal,SalTransportTLS); } +LinphoneTransports *linphone_core_get_transports_used(LinphoneCore *lc){ + LinphoneTransports *transports = linphone_transports_new(lc); + transports->udp_port = sal_get_listening_port(lc->sal, SalTransportUDP); + transports->tcp_port = sal_get_listening_port(lc->sal, SalTransportTCP); + transports->tls_port = sal_get_listening_port(lc->sal, SalTransportTLS); + transports->dtls_port = sal_get_listening_port(lc->sal, SalTransportDTLS); + return transports; +} + void linphone_core_set_sip_port(LinphoneCore *lc,int port) { LinphoneSipTransports tr; memset(&tr,0,sizeof(tr)); diff --git a/coreapi/misc.c b/coreapi/misc.c index 5db955617..fa295f6c7 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -1828,17 +1828,27 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneRange, belle_sip_object_t, LinphoneRange *linphone_range_new() { LinphoneRange *range = belle_sip_object_new(LinphoneRange); + range->min = 0; + range->max = 0; return range; } -LinphoneRange* linphone_range_ref (LinphoneRange* range) { +LinphoneRange* linphone_range_ref(LinphoneRange* range) { return (LinphoneRange*) belle_sip_object_ref(range); } -void linphone_range_unref (LinphoneRange* range) { +void linphone_range_unref(LinphoneRange* range) { belle_sip_object_unref(range); } +void *linphone_range_get_user_data(const LinphoneRange *range) { + return range->user_data; +} + +void linphone_range_set_user_data(LinphoneRange *range, void *data) { + range->user_data = data; +} + int linphone_range_get_min(const LinphoneRange *range) { return range->min; } diff --git a/coreapi/private.h b/coreapi/private.h index 1d8672cfe..537337cf5 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1737,6 +1737,19 @@ BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneRange); LinphoneRange *linphone_range_new(void); +struct _LinphoneTransports { + belle_sip_object_t base; + void *user_data; + int udp_port; /**< SIP/UDP port */ + int tcp_port; /**< SIP/TCP port */ + int dtls_port; /**< SIP/DTLS port */ + int tls_port; /**< SIP/TLS port */ +}; + +BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneTransports); + +LINPHONE_PUBLIC LinphoneTransports *linphone_transports_new(LinphoneCore *lc); + /** Belle Sip-based objects need unique ids */ @@ -1788,7 +1801,8 @@ BELLE_SIP_TYPE_ID(LinphoneConference), BELLE_SIP_TYPE_ID(LinphoneInfoMessage), BELLE_SIP_TYPE_ID(LinphonePayloadType), BELLE_SIP_TYPE_ID(LinphoneRange), -BELLE_SIP_TYPE_ID(LinphoneVideoDefinition) +BELLE_SIP_TYPE_ID(LinphoneVideoDefinition), +BELLE_SIP_TYPE_ID(LinphoneTransports) BELLE_SIP_DECLARE_TYPES_END diff --git a/include/linphone/core.h b/include/linphone/core.h index 93fd4f422..559973ab2 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -2104,13 +2104,6 @@ LINPHONE_PUBLIC int linphone_core_get_audio_port(const LinphoneCore *lc); */ LINPHONE_PUBLIC void linphone_core_get_audio_port_range(const LinphoneCore *lc, int *min_port, int *max_port); -/** - * Overload of linphone_core_get_audio_port_range(). - * @deprecated Use linphone_core_get_audio_ports_range instead - * @ingroup network_parameters - */ -LINPHONE_PUBLIC LinphoneIntRange linphone_core_get_audio_port_range_2(const LinphoneCore *lc); - /** * Get the audio port range from which is randomly chosen the UDP port used for audio streaming. * @param[in] lc LinphoneCore object @@ -2137,13 +2130,6 @@ LINPHONE_PUBLIC int linphone_core_get_video_port(const LinphoneCore *lc); */ LINPHONE_PUBLIC void linphone_core_get_video_port_range(const LinphoneCore *lc, int *min_port, int *max_port); -/** - * Overload of linphone_core_get_video_port_range(). - * @deprecated Use linphone_core_get_video_ports_range instead - * @ingroup network_parameters - */ -LINPHONE_PUBLIC LinphoneIntRange linphone_core_get_video_port_range_2(const LinphoneCore *lc); - /** * Get the video port range from which is randomly chosen the UDP port used for video streaming. * @param[in] lc LinphoneCore object @@ -2170,13 +2156,6 @@ LINPHONE_PUBLIC int linphone_core_get_text_port(const LinphoneCore *lc); */ LINPHONE_PUBLIC void linphone_core_get_text_port_range(const LinphoneCore *lc, int *min_port, int *max_port); -/** - * Overload of linphone_core_get_text_port_range(). - * @deprecated Use linphone_core_get_text_ports_range instead - * @ingroup network_parameters - */ -LINPHONE_PUBLIC LinphoneIntRange linphone_core_get_text_port_range_2(const LinphoneCore *lc); - /** * Get the text port range from which is randomly chosen the UDP port used for text streaming. * @param[in] lc LinphoneCore object @@ -2324,6 +2303,8 @@ LINPHONE_PUBLIC LINPHONE_DEPRECATED int linphone_core_get_sip_port(LinphoneCore * @param[in] transports A LinphoneSipTransports structure giving the ports to use * @return 0 * @ingroup network_parameters + * @deprecated Use linphone_core_set_transports instead + * @donotwrap **/ LINPHONE_PUBLIC LinphoneStatus linphone_core_set_sip_transports(LinphoneCore *lc, const LinphoneSipTransports *transports); @@ -2335,6 +2316,7 @@ LINPHONE_PUBLIC LinphoneStatus linphone_core_set_sip_transports(LinphoneCore *lc * @param[out] transports A #LinphoneSipTransports structure that will receive the configured ports * @return 0 * @ingroup network_parameters + * @deprecated * @donotwrap **/ LINPHONE_PUBLIC LinphoneStatus linphone_core_get_sip_transports(LinphoneCore *lc, LinphoneSipTransports *transports); @@ -2346,10 +2328,136 @@ LINPHONE_PUBLIC LinphoneStatus linphone_core_get_sip_transports(LinphoneCore *lc * @param[in] lc LinphoneCore object * @param[out] tr A #LinphoneSipTransports structure that will receive the ports being used * @ingroup network_parameters + * @deprecated Use linphone_core_get_transports_used instead * @donotwrap **/ LINPHONE_PUBLIC void linphone_core_get_sip_transports_used(LinphoneCore *lc, LinphoneSipTransports *tr); +/** + * Sets the ports to be used for each of transport (UDP or TCP) + * A zero value port for a given transport means the transport + * is not used. A value of LC_SIP_TRANSPORT_RANDOM (-1) means the port is to be choosen randomly by the system. + * @param[in] lc LinphoneCore object + * @param[in] transports A LinphoneSipTransports structure giving the ports to use + * @return 0 + * @ingroup network_parameters +**/ +LINPHONE_PUBLIC LinphoneStatus linphone_core_set_transports(LinphoneCore *lc, const LinphoneTransports *transports); + +/** + * Retrieves the port configuration used for each transport (udp, tcp, tls). + * A zero value port for a given transport means the transport + * is not used. A value of LC_SIP_TRANSPORT_RANDOM (-1) means the port is to be chosen randomly by the system. + * @param[in] lc LinphoneCore object + * @return A #LinphoneTransports structure with the configured ports + * @ingroup network_parameters +**/ +LINPHONE_PUBLIC LinphoneTransports *linphone_core_get_transports(LinphoneCore *lc); + +/** + * Retrieves the real port number assigned for each sip transport (udp, tcp, tls). + * A zero value means that the transport is not activated. + * If LC_SIP_TRANSPORT_RANDOM was passed to linphone_core_set_sip_transports(), the random port choosed by the system is returned. + * @param[in] lc LinphoneCore object + * @return A #LinphoneTransports structure with the ports being used + * @ingroup network_parameters +**/ +LINPHONE_PUBLIC LinphoneTransports *linphone_core_get_transports_used(LinphoneCore *lc); + +/** + * Increment refcount. + * @param[in] transports LinphoneTransports object + * @ingroup network_parameters +**/ +LINPHONE_PUBLIC LinphoneTransports *linphone_transports_ref(LinphoneTransports *transports); + +/** + * Decrement refcount and possibly free the object. + * @param[in] transports LinphoneTransports object + * @ingroup network_parameters +**/ +LINPHONE_PUBLIC void linphone_transports_unref(LinphoneTransports *transports); + +/** + * Gets the user data in the LinphoneTransports object + * @param[in] transports the LinphoneTransports + * @return the user data + * @ingroup network_parameters +*/ +LINPHONE_PUBLIC void *linphone_transports_get_user_data(const LinphoneTransports *transports); + +/** + * Sets the user data in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @param[in] data the user data + * @ingroup network_parameters +*/ +LINPHONE_PUBLIC void linphone_transports_set_user_data(LinphoneTransports *transports, void *data); + +/** + * Gets the UDP port in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @return the UDP port + * @ingroup network_parameters + */ +LINPHONE_PUBLIC int linphone_transports_get_udp_port(const LinphoneTransports* transports); + +/** + * Gets the TCP port in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @return the TCP port + * @ingroup network_parameters + */ +LINPHONE_PUBLIC int linphone_transports_get_tcp_port(const LinphoneTransports* transports); + +/** + * Gets the TLS port in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @return the TLS port + * @ingroup network_parameters + */ +LINPHONE_PUBLIC int linphone_transports_get_tls_port(const LinphoneTransports* transports); + +/** + * Gets the DTLS port in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @return the DTLS port + * @ingroup network_parameters + */ +LINPHONE_PUBLIC int linphone_transports_get_dtls_port(const LinphoneTransports* transports); + +/** + * Sets the UDP port in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @param[in] port the UDP port + * @ingroup network_parameters + */ +LINPHONE_PUBLIC void linphone_transports_set_udp_port(LinphoneTransports *transports, int port); + +/** + * Sets the TCP port in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @param[in] port the TCP port + * @ingroup network_parameters + */ +LINPHONE_PUBLIC void linphone_transports_set_tcp_port(LinphoneTransports *transports, int port); + +/** + * Sets the TLS port in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @param[in] port the TLS port + * @ingroup network_parameters + */ +LINPHONE_PUBLIC void linphone_transports_set_tls_port(LinphoneTransports *transports, int port); + +/** + * Sets the DTLS port in the LinphoneTransports object + * @param[in] transports the LinphoneTransports object + * @param[in] port the DTLS port + * @ingroup network_parameters + */ +LINPHONE_PUBLIC void linphone_transports_set_dtls_port(LinphoneTransports *transports, int port); + /** * Tells whether the given transport type is supported by the library. * @param[in] lc LinphoneCore object diff --git a/include/linphone/misc.h b/include/linphone/misc.h index c80d7abf2..6f04e1c2a 100644 --- a/include/linphone/misc.h +++ b/include/linphone/misc.h @@ -159,6 +159,14 @@ LINPHONE_PUBLIC LinphoneTransportType linphone_transport_parse(const char* trans **/ LINPHONE_PUBLIC LinphoneReason linphone_error_code_to_reason(int err); +/** + * Converts a LinphoneReason to an error code. + * @param[in] reason A LinphoneReason + * @return The error code corresponding to the specified LinphoneReason + * @ingroup misc + */ +LINPHONE_PUBLIC int linphone_reason_to_error_code(LinphoneReason reason); + /** * Increment refcount. * @param[in] range LinphoneRange object @@ -172,12 +180,18 @@ LINPHONE_PUBLIC LinphoneRange *linphone_range_ref(LinphoneRange *range); LINPHONE_PUBLIC void linphone_range_unref(LinphoneRange *range); /** - * Converts a LinphoneReason to an error code. - * @param[in] reason A LinphoneReason - * @return The error code corresponding to the specified LinphoneReason - * @ingroup misc - */ -LINPHONE_PUBLIC int linphone_reason_to_error_code(LinphoneReason reason); + * Gets the user data in the LinphoneRange object + * @param[in] range the LinphoneRange + * @return the user data +*/ +LINPHONE_PUBLIC void *linphone_range_get_user_data(const LinphoneRange *range); + +/** + * Sets the user data in the LinphoneRange object + * @param[in] range the LinphoneRange object + * @param[in] data the user data +*/ +LINPHONE_PUBLIC void linphone_range_set_user_data(LinphoneRange *range, void *data); /** * Gets the lower value of the range diff --git a/include/linphone/types.h b/include/linphone/types.h index 4fb6244b1..301e08da8 100644 --- a/include/linphone/types.h +++ b/include/linphone/types.h @@ -972,7 +972,8 @@ typedef struct _LinphoneRingtonePlayer LinphoneRingtonePlayer; * Linphone core SIP transport ports. * Special values #LC_SIP_TRANSPORT_RANDOM, #LC_SIP_TRANSPORT_RANDOM, #LC_SIP_TRANSPORT_DONTBIND can be used. * Use with #linphone_core_set_sip_transports - * @ingroup initializing + * @deprecated + * @donotwrap */ typedef struct _LinphoneSipTransports { int udp_port; /**< SIP/UDP port */ @@ -981,6 +982,14 @@ typedef struct _LinphoneSipTransports { int tls_port; /**< SIP/TLS port */ } LinphoneSipTransports; +/** + * Linphone core SIP transport ports. + * Special values #LC_SIP_TRANSPORT_RANDOM, #LC_SIP_TRANSPORT_RANDOM, #LC_SIP_TRANSPORT_DONTBIND can be used. + * Use with #linphone_core_set_sip_transports + * @ingroup initializing + */ +typedef struct _LinphoneTransports LinphoneTransports; + /** * Old name of LinphoneSipTransports * @deprecated @@ -1184,16 +1193,6 @@ typedef struct _LsdPlayer LsdPlayer; */ typedef struct _LinphonePayloadType LinphonePayloadType; - -/** - * Structure describing a range of integers - * @deprecated - */ -typedef struct _LinphoneIntRange { - int min; /**< Minimum value */ - int max; /**< Maximum value */ -} LinphoneIntRange; - /** * Structure describing a range of integers * @ingroup misc