diff --git a/coreapi/bellesip_sal/sal_op_presence.c b/coreapi/bellesip_sal/sal_op_presence.c index 434c73a81..390462ebf 100644 --- a/coreapi/bellesip_sal/sal_op_presence.c +++ b/coreapi/bellesip_sal/sal_op_presence.c @@ -392,9 +392,10 @@ void sal_add_presence_info(belle_sip_message_t *notify, SalPresenceStatus online mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style); - + belle_sip_message_remove_header(BELLE_SIP_MESSAGE(notify),BELLE_SIP_CONTENT_TYPE); belle_sip_message_add_header(BELLE_SIP_MESSAGE(notify) ,BELLE_SIP_HEADER(belle_sip_header_content_type_create("application",presence_style?"xpidf+xml":"pidf+xml"))); + belle_sip_message_remove_header(BELLE_SIP_MESSAGE(notify),BELLE_SIP_CONTENT_LENGTH); belle_sip_message_add_header(BELLE_SIP_MESSAGE(notify) ,BELLE_SIP_HEADER(belle_sip_header_content_length_create(content_length=strlen(buf)))); belle_sip_message_set_body(BELLE_SIP_MESSAGE(notify),buf,content_length); diff --git a/coreapi/bellesip_sal/sal_op_publish.c b/coreapi/bellesip_sal/sal_op_publish.c index 82e48f5c1..29d78cd72 100644 --- a/coreapi/bellesip_sal/sal_op_publish.c +++ b/coreapi/bellesip_sal/sal_op_publish.c @@ -32,15 +32,24 @@ static void publish_refresher_listener ( const belle_sip_refresher_t* refresher /*presence publish */ int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus status){ belle_sip_request_t *req=NULL; - if (from) - sal_op_set_from(op,from); - if (to) - sal_op_set_to(op,to); - - op->type=SalOpPublish; - req=sal_op_build_request(op,"PUBLISH"); - sal_add_presence_info(BELLE_SIP_MESSAGE(req),status); - return sal_op_send_and_create_refresher(op,req,600,publish_refresher_listener); + if(!op->refresher || !belle_sip_refresher_get_transaction(op->refresher)) { + if (from) + sal_op_set_from(op,from); + if (to) + sal_op_set_to(op,to); + op->type=SalOpPublish; + req=sal_op_build_request(op,"PUBLISH"); + belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),belle_sip_header_create("Event","presence")); + sal_add_presence_info(BELLE_SIP_MESSAGE(req),status); + return sal_op_send_and_create_refresher(op,req,600,publish_refresher_listener); + } else { + /*update status*/ + const belle_sip_client_transaction_t* last_publish_trans=belle_sip_refresher_get_transaction(op->refresher); + belle_sip_request_t* last_publish=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(last_publish_trans)); + /*update status*/ + sal_add_presence_info(BELLE_SIP_MESSAGE(last_publish),status); + return belle_sip_refresher_refresh(op->refresher,BELLE_SIP_REFRESHER_REUSE_EXPIRES); + } } diff --git a/tester/presence_tester.c b/tester/presence_tester.c index cf7ce5f6d..308388710 100644 --- a/tester/presence_tester.c +++ b/tester/presence_tester.c @@ -78,6 +78,11 @@ static void simple_publish(void) { linphone_core_iterate(marie->lc); ms_usleep(100000); } + linphone_core_set_presence_info(marie->lc,0,NULL,LinphoneStatusOffline); + for (i=0;i<10;i++) { + linphone_core_iterate(marie->lc); + ms_usleep(100000); + } linphone_core_manager_destroy(marie); }