From 0845662322bf1df00bcc96b32c714a32314cc84e Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Sun, 26 Sep 2010 14:40:17 +0200 Subject: [PATCH] implement reporting of far end's user agent string --- console/commands.c | 27 +++++++++++++++++++++++++++ coreapi/linphonecall.c | 36 ++++++++++++++++++++++++++++++++++-- coreapi/linphonecore.h | 1 + coreapi/sal.c | 8 ++++++++ coreapi/sal.h | 3 +++ coreapi/sal_eXosip2.c | 17 +++++++++++++++-- 6 files changed, 88 insertions(+), 4 deletions(-) diff --git a/console/commands.c b/console/commands.c index f0148e553..2b41e342f 100644 --- a/console/commands.c +++ b/console/commands.c @@ -92,6 +92,7 @@ static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args); static int lpc_cmd_camera(LinphoneCore *lc, char *args); static int lpc_cmd_video_window(LinphoneCore *lc, char *args); static int lpc_cmd_states(LinphoneCore *lc, char *args); +static int lpc_cmd_identify(LinphoneCore *lc, char *args); /* Command handler helpers */ static void linphonec_proxy_add(LinphoneCore *lc); @@ -293,6 +294,10 @@ static LPC_COMMAND advanced_commands[] = { "'staticpic set' : Set path to picture that should be used.\n" "'staticpic fps' : Get/set frames per seconds for picture emission.\n" }, + { "identify", lpc_cmd_identify, "Returns the user-agent string of far end", + "'identify' \t: returns remote user-agent string for current call.\n" + "'identify ' \t: returns remote user-agent string for call with supplied id.\n" + }, { NULL,NULL,NULL,NULL} }; @@ -2325,6 +2330,28 @@ static int lpc_cmd_camera(LinphoneCore *lc, char *args){ return 1; } +static int lpc_cmd_identify(LinphoneCore *lc, char *args){ + LinphoneCall *call; + const char *remote_ua; + if (args==NULL){ + call=linphone_core_get_current_call(lc); + if (call==NULL) { + linphonec_out("There is currently running call. Specify call id.\n"); + return 0; + } + }else{ + call=linphonec_get_call(atoi(args)); + if (call==NULL){ + return 0; + } + } + remote_ua=linphone_call_get_remote_user_agent(call); + if (remote_ua){ + linphonec_out("Remote user agent string is: %s\n",remote_ua); + } + return 1; +} + /*************************************************************************** * * Command table management funx diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index daf512264..f28521e4f 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -417,10 +417,23 @@ const char *linphone_call_get_refer_to(const LinphoneCall *call){ return call->refer_to; } +/** + * Returns direction of the call (incoming or outgoing). +**/ LinphoneCallDir linphone_call_get_dir(const LinphoneCall *call){ return call->log->dir; } +/** + * Returns the far end's user agent description string, if available. +**/ +const char *linphone_call_get_remote_user_agent(LinphoneCall *call){ + if (call->op){ + return sal_op_get_remote_ua (call->op); + } + return NULL; +} + /** * Returns true if this calls has received a transfer that has not been * executed yet. @@ -456,24 +469,39 @@ void linphone_call_enable_camera (LinphoneCall *call, bool_t enable){ call->camera_active=enable; } +/** + * +**/ bool_t linphone_call_camera_enabled (const LinphoneCall *call){ return call->camera_active; } +/** + * +**/ void linphone_call_params_enable_video(LinphoneCallParams *cp, bool_t enabled){ cp->has_video=enabled; } +/** + * +**/ bool_t linphone_call_params_video_enabled(const LinphoneCallParams *cp){ return cp->has_video; } +/** + * +**/ LinphoneCallParams * linphone_call_params_copy(const LinphoneCallParams *cp){ LinphoneCallParams *ncp=ms_new0(LinphoneCallParams,1); memcpy(ncp,cp,sizeof(LinphoneCallParams)); return ncp; } +/** + * +**/ void linphone_call_params_destroy(LinphoneCallParams *p){ ms_free(p); } @@ -680,8 +708,12 @@ static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, static void setup_ring_player(LinphoneCore *lc, LinphoneCall *call){ const char *ringfile=lc->sound_conf.remote_ring; int pause_time=3000; - audio_stream_play(call->audiostream,ringfile); - ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time); + if (lc->play_file!=NULL){ + audio_stream_play(call->audiostream,lc->play_file); + }else{ + audio_stream_play(call->audiostream,ringfile); + ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time); + } } static void _linphone_call_start_media_streams(LinphoneCall *call, bool_t send_early_media){ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 12ca8675d..d94ed2d09 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -225,6 +225,7 @@ const LinphoneCallParams * linphone_call_get_current_params(const LinphoneCall * void linphone_call_enable_camera(LinphoneCall *lc, bool_t enabled); bool_t linphone_call_camera_enabled(const LinphoneCall *lc); LinphoneError linphone_call_get_error(const LinphoneCall *call); +const char *linphone_call_get_remote_user_agent(LinphoneCall *call); void *linphone_call_get_user_pointer(LinphoneCall *call); void linphone_call_set_user_pointer(LinphoneCall *call, void *user_pointer); diff --git a/coreapi/sal.c b/coreapi/sal.c index 3c8801ad8..ac44470a6 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -143,6 +143,10 @@ const char *sal_op_get_route(const SalOp *op){ return ((SalOpBase*)op)->route; } +const char *sal_op_get_remote_ua(const SalOp *op){ + return ((SalOpBase*)op)->remote_ua; +} + void *sal_op_get_user_pointer(const SalOp *op){ return ((SalOpBase*)op)->user_pointer; } @@ -187,6 +191,10 @@ void __sal_op_free(SalOp *op){ ms_free(b->origin); b->origin=NULL; } + if (b->remote_ua){ + ms_free(b->remote_ua); + b->remote_ua=NULL; + } if (b->local_media) sal_media_description_unref(b->local_media); if (b->remote_media) diff --git a/coreapi/sal.h b/coreapi/sal.h index ea1799ef7..9f97c5239 100644 --- a/coreapi/sal.h +++ b/coreapi/sal.h @@ -140,6 +140,7 @@ typedef struct SalOpBase{ char *from; char *to; char *origin; + char *remote_ua; SalMediaDescription *local_media; SalMediaDescription *remote_media; void *user_pointer; @@ -267,6 +268,8 @@ const char *sal_op_get_route(const SalOp *op); const char *sal_op_get_proxy(const SalOp *op); /*for incoming requests, returns the origin of the packet as a sip uri*/ const char *sal_op_get_network_origin(const SalOp *op); +/*returns far-end "User-Agent" string */ +const char *sal_op_get_remote_ua(const SalOp *op); void *sal_op_get_user_pointer(const SalOp *op); /*Call API*/ diff --git a/coreapi/sal_eXosip2.c b/coreapi/sal_eXosip2.c index 2ac94f089..428e6aed3 100644 --- a/coreapi/sal_eXosip2.c +++ b/coreapi/sal_eXosip2.c @@ -722,6 +722,16 @@ static void set_network_origin(SalOp *op, osip_message_t *req){ __sal_op_set_network_origin(op,origin); } +static void set_remote_ua(SalOp* op, osip_message_t *req){ + if (op->base.remote_ua==NULL){ + osip_header_t *h=NULL; + osip_message_get_user_agent(req,0,&h); + if (h){ + op->base.remote_ua=ms_strdup(h->hvalue); + } + } +} + static SalOp *find_op(Sal *sal, eXosip_event_t *ev){ if (ev->cid>0){ return sal_find_call(sal,ev->cid); @@ -741,6 +751,7 @@ static void inc_new_call(Sal *sal, eXosip_event_t *ev){ sdp_message_t *sdp=eXosip_get_sdp_info(ev->request); set_network_origin(op,ev->request); + set_remote_ua(op,ev->request); if (sdp){ op->sdp_offering=FALSE; @@ -886,7 +897,8 @@ static void call_ringing(Sal *sal, eXosip_event_t *ev){ sdp_message_t *sdp; SalOp *op=find_op(sal,ev); if (call_proceeding(sal, ev)==-1) return; - + + set_remote_ua(op,ev->response); sdp=eXosip_get_sdp_info(ev->response); if (sdp){ op->base.remote_media=sal_media_description_new(); @@ -909,7 +921,8 @@ static void call_accepted(Sal *sal, eXosip_event_t *ev){ } op->did=ev->did; - + set_remote_ua(op,ev->response); + sdp=eXosip_get_sdp_info(ev->response); if (sdp){ op->base.remote_media=sal_media_description_new();