From 5cf381b667d77a52381155a5b64dfa0a2c75da2b Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Tue, 24 Jun 2014 09:43:32 +0200 Subject: [PATCH] add linphone_core_get_user_agent to retrieve local user agent --- coreapi/bellesip_sal/sal_impl.c | 14 ++++-- coreapi/linphonecore.c | 9 ++++ coreapi/linphonecore.h | 7 +++ coreapi/quality_reporting.c | 76 ++++++++++++++++++++------------- coreapi/quality_reporting.h | 45 ++++++++++--------- include/sal/sal.h | 1 + 6 files changed, 97 insertions(+), 55 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index c4809ecc6..daf746c79 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -424,21 +424,21 @@ static void process_auth_requested(void *sal, belle_sip_auth_event_t *event) { Sal * sal_init(){ belle_sip_listener_callbacks_t listener_callbacks; Sal * sal=ms_new0(Sal,1); - + /*belle_sip_object_enable_marshal_check(TRUE);*/ sal->auto_contacts=TRUE; - + /*first create the stack, which initializes the belle-sip object's pool for this thread*/ belle_sip_set_log_handler(_belle_sip_log); sal->stack = belle_sip_stack_new(NULL); - + sal->user_agent=belle_sip_header_user_agent_new(); #if defined(PACKAGE_NAME) && defined(LINPHONE_VERSION) belle_sip_header_user_agent_add_product(sal->user_agent, PACKAGE_NAME "/" LINPHONE_VERSION); #endif sal_append_stack_string_to_user_agent(sal); belle_sip_object_ref(sal->user_agent); - + sal->prov = belle_sip_stack_create_provider(sal->stack,NULL); sal_nat_helper_enable(sal,TRUE); memset(&listener_callbacks,0,sizeof(listener_callbacks)); @@ -617,6 +617,12 @@ void sal_set_user_agent(Sal *ctx, const char *user_agent){ return ; } +const char* sal_get_user_agent(Sal *ctx){ + static char user_agent[255]; + belle_sip_header_user_agent_get_products_as_string(ctx->user_agent, user_agent, 254); + return user_agent; +} + void sal_append_stack_string_to_user_agent(Sal *ctx) { char stack_string[64]; snprintf(stack_string, sizeof(stack_string) - 1, "(belle-sip/%s)", belle_sip_version_to_string()); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 9f4cfbd9c..65db5a709 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1914,6 +1914,15 @@ void linphone_core_set_user_agent(LinphoneCore *lc, const char *name, const char apply_user_agent(lc); #endif } +const char *linphone_core_get_user_agent(LinphoneCore *lc){ +#if USE_BELLESIP + return sal_get_user_agent(lc->sal); +#else + static char ua_buffer[255] = {0}; + snprintf(ua_buffer, "%s/%s", _ua_name, _ua_version, 254); + return ua_buffer; +#endif +} const char *linphone_core_get_user_agent_name(void){ return _ua_name; diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index dd0ff311a..0cabc434f 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1542,7 +1542,14 @@ LINPHONE_PUBLIC void linphone_core_enable_logs(FILE *file); LINPHONE_PUBLIC void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc); LINPHONE_PUBLIC void linphone_core_disable_logs(void); LINPHONE_PUBLIC const char *linphone_core_get_version(void); +LINPHONE_PUBLIC const char *linphone_core_get_user_agent(LinphoneCore *lc); +/** + * @deprecated Use #linphone_core_get_user_agent instead. +**/ LINPHONE_PUBLIC const char *linphone_core_get_user_agent_name(void); +/** + * @deprecated Use #linphone_core_get_user_agent instead. +**/ LINPHONE_PUBLIC const char *linphone_core_get_user_agent_version(void); LINPHONE_PUBLIC LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable, diff --git a/coreapi/quality_reporting.c b/coreapi/quality_reporting.c index e16dd8f81..528ec5208 100644 --- a/coreapi/quality_reporting.c +++ b/coreapi/quality_reporting.c @@ -236,6 +236,11 @@ static void append_metrics_to_buffer(char ** buffer, size_t * size, size_t * off APPEND_IF_NOT_NULL_STR(buffer, size, offset, " MOSCQ=%s", moscq_str); } + if (rm.user_agent!=NULL){ + append_to_buffer(buffer, size, offset, "\r\nLinphoneExt:"); + APPEND_IF_NOT_NULL_STR(buffer, size, offset, " UA=\"%s\"", rm.user_agent); + } + append_to_buffer(buffer, size, offset, "\r\n"); ms_free(timestamps_start_str); @@ -430,17 +435,27 @@ void linphone_reporting_update_media_info(LinphoneCall * call, int stats_type) { STR_REASSIGN(report->info.call_id, ms_strdup(call->log->call_id)); - STR_REASSIGN(report->info.local_addr.group, ms_strdup_printf("linphone-%s-%s-%s", - (stats_type == LINPHONE_CALL_STATS_AUDIO ? "audio" : "video"), - linphone_core_get_user_agent_name(), - report->info.call_id) + STR_REASSIGN(report->dialog_id, sal_op_get_dialog_id(call->op)); + + STR_REASSIGN(report->local_metrics.user_agent, ms_strdup(linphone_core_get_user_agent(call->core))); + STR_REASSIGN(report->remote_metrics.user_agent, ms_strdup(linphone_call_get_remote_user_agent(call))); + + // RFC states: "LocalGroupID provides the identification for the purposes + // of aggregation for the local endpoint.". + STR_REASSIGN(report->info.local_addr.group, ms_strdup_printf("%s-%s-%s" + , report->dialog_id + , "local" + , report->local_metrics.user_agent + ) ); - STR_REASSIGN(report->info.remote_addr.group, ms_strdup_printf("linphone-%s-%s-%s", - (stats_type == LINPHONE_CALL_STATS_AUDIO ? "audio" : "video"), - linphone_call_get_remote_user_agent(call), - report->info.call_id) + STR_REASSIGN(report->info.remote_addr.group, ms_strdup_printf("%s-%s-%s" + , report->dialog_id + , "remote" + , report->remote_metrics.user_agent + ) ); + if (call->dir == LinphoneCallIncoming) { STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(call->log->from)); STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(call->log->to)); @@ -451,7 +466,6 @@ void linphone_reporting_update_media_info(LinphoneCall * call, int stats_type) { STR_REASSIGN(report->info.orig_id, ms_strdup(report->info.local_addr.id)); } - STR_REASSIGN(report->dialog_id, sal_op_get_dialog_id(call->op)); report->local_metrics.timestamps.start = call->log->start_date_time; report->local_metrics.timestamps.stop = call->log->start_date_time + linphone_call_get_duration(call); @@ -663,27 +677,29 @@ reporting_session_report_t * linphone_reporting_new() { } void linphone_reporting_destroy(reporting_session_report_t * report) { - if (report->info.call_id != NULL) ms_free(report->info.call_id); - if (report->info.local_addr.id != NULL) ms_free(report->info.local_addr.id); - if (report->info.remote_addr.id != NULL) ms_free(report->info.remote_addr.id); - if (report->info.orig_id != NULL) ms_free(report->info.orig_id); - if (report->info.local_addr.ip != NULL) ms_free(report->info.local_addr.ip); - if (report->info.remote_addr.ip != NULL) ms_free(report->info.remote_addr.ip); - if (report->info.local_addr.group != NULL) ms_free(report->info.local_addr.group); - if (report->info.remote_addr.group != NULL) ms_free(report->info.remote_addr.group); - if (report->info.local_addr.mac != NULL) ms_free(report->info.local_addr.mac); - if (report->info.remote_addr.mac != NULL) ms_free(report->info.remote_addr.mac); - if (report->dialog_id != NULL) ms_free(report->dialog_id); - if (report->local_metrics.session_description.fmtp != NULL) ms_free(report->local_metrics.session_description.fmtp); - if (report->local_metrics.session_description.payload_desc != NULL) ms_free(report->local_metrics.session_description.payload_desc); - if (report->remote_metrics.session_description.fmtp != NULL) ms_free(report->remote_metrics.session_description.fmtp); - if (report->remote_metrics.session_description.payload_desc != NULL) ms_free(report->remote_metrics.session_description.payload_desc); - if (report->qos_analyzer.name != NULL) ms_free(report->qos_analyzer.name); - if (report->qos_analyzer.timestamp != NULL) ms_free(report->qos_analyzer.timestamp); - if (report->qos_analyzer.input_leg != NULL) ms_free(report->qos_analyzer.input_leg); - if (report->qos_analyzer.input != NULL) ms_free(report->qos_analyzer.input); - if (report->qos_analyzer.output_leg != NULL) ms_free(report->qos_analyzer.output_leg); - if (report->qos_analyzer.output != NULL) ms_free(report->qos_analyzer.output); + STR_REASSIGN(report->info.call_id, NULL); + STR_REASSIGN(report->info.local_addr.id, NULL); + STR_REASSIGN(report->info.remote_addr.id, NULL); + STR_REASSIGN(report->info.orig_id, NULL); + STR_REASSIGN(report->info.local_addr.ip, NULL); + STR_REASSIGN(report->info.remote_addr.ip, NULL); + STR_REASSIGN(report->info.local_addr.group, NULL); + STR_REASSIGN(report->info.remote_addr.group, NULL); + STR_REASSIGN(report->info.local_addr.mac, NULL); + STR_REASSIGN(report->info.remote_addr.mac, NULL); + STR_REASSIGN(report->dialog_id, NULL); + STR_REASSIGN(report->local_metrics.session_description.fmtp, NULL); + STR_REASSIGN(report->local_metrics.session_description.payload_desc, NULL); + STR_REASSIGN(report->local_metrics.user_agent, NULL); + STR_REASSIGN(report->remote_metrics.session_description.fmtp, NULL); + STR_REASSIGN(report->remote_metrics.session_description.payload_desc, NULL); + STR_REASSIGN(report->remote_metrics.user_agent, NULL); + STR_REASSIGN(report->qos_analyzer.name, NULL); + STR_REASSIGN(report->qos_analyzer.timestamp, NULL); + STR_REASSIGN(report->qos_analyzer.input_leg, NULL); + STR_REASSIGN(report->qos_analyzer.input, NULL); + STR_REASSIGN(report->qos_analyzer.output_leg, NULL); + STR_REASSIGN(report->qos_analyzer.output, NULL); ms_free(report); } diff --git a/coreapi/quality_reporting.h b/coreapi/quality_reporting.h index 3c387a903..acc898924 100644 --- a/coreapi/quality_reporting.h +++ b/coreapi/quality_reporting.h @@ -54,48 +54,51 @@ typedef struct reporting_content_metrics { // session description - optional struct { int payload_type; - char * payload_desc; // mime type - int sample_rate; // clock rate - int frame_duration; // to check (ptime?) - audio only + char * payload_desc; + int sample_rate; + int frame_duration; char * fmtp; - int packet_loss_concealment; // in voip metrics - audio only + int packet_loss_concealment; } session_description; // jitter buffet - optional struct { - int adaptive; // constant - int nominal; // average - int max; // average - int abs_max; // constant + int adaptive; + int nominal; + int max; + int abs_max; } jitter_buffer; // packet loss - optional struct { - float network_packet_loss_rate; // average - float jitter_buffer_discard_rate; // average + float network_packet_loss_rate; + float jitter_buffer_discard_rate; } packet_loss; // delay - optional struct { - int round_trip_delay; // no - vary - int end_system_delay; // no - not implemented yet - int symm_one_way_delay; // no - not implemented (depends on end_system_delay) - int interarrival_jitter; // no - not implemented yet - int mean_abs_jitter; // to check + int round_trip_delay; + int end_system_delay; + int symm_one_way_delay; + int interarrival_jitter; + int mean_abs_jitter; } delay; // signal - optional struct { - int level; // no - vary - int noise_level; // no - vary + int level; + int noise_level; } signal; // quality estimates - optional struct { - float moslq; // no - vary or avg - voip metrics - in [0..4.9] - float moscq; // no - vary or avg - voip metrics - in [0..4.9] + float moslq; + float moscq; } quality_estimates; + // custom extension + char * user_agent; + // for internal processing uint8_t rtcp_xr_count; // number of RTCP XR packets received since last report, used to compute average of instantaneous parameters as stated in the RFC 6035 (4.5) uint8_t rtcp_sr_count; // number of RTCP SR packets received since last report, used to compute RTT average values in case RTCP XR voip metrics is not enabled @@ -127,9 +130,9 @@ typedef struct reporting_session_report { char * name; /*type of the QoS analyzer used*/ char* timestamp; /*time of each decision in seconds*/ char* input_leg; /*input parameters' name*/ - char* input; /*set of inputs for each decision, semicolon separated*/ + char* input; /*set of inputs for each semicolon separated decision*/ char* output_leg; /*output parameters' name*/ - char* output; /*set of outputs for each decision, semicolon separated*/ + char* output; /*set of outputs for each semicolon separated decision*/ } qos_analyzer; // for internal processing diff --git a/include/sal/sal.h b/include/sal/sal.h index e9719fc7b..642cfdd2a 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -519,6 +519,7 @@ void sal_set_dscp(Sal *ctx, int dscp); int sal_reset_transports(Sal *ctx); ortp_socket_t sal_get_socket(Sal *ctx); void sal_set_user_agent(Sal *ctx, const char *user_agent); +const char* sal_get_user_agent(Sal *ctx); void sal_append_stack_string_to_user_agent(Sal *ctx); /*keepalive period in ms*/ void sal_set_keepalive_period(Sal *ctx,unsigned int value);