From 6a89a97fcfebf660852eeb82660329e2b59af483 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Thu, 20 Dec 2012 18:58:53 +0100 Subject: [PATCH] add unsubscribe test --- coreapi/bellesip_sal/sal_impl.c | 1 + coreapi/bellesip_sal/sal_impl.h | 2 +- coreapi/bellesip_sal/sal_op_call.c | 7 +++++-- coreapi/bellesip_sal/sal_op_presence.c | 4 ++++ tester/liblinphone_tester.c | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index 1a67506df..ccb8f7f52 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -183,6 +183,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even belle_sip_request_t* old_request=NULL;; belle_sip_response_t* old_response=NULL;; int response_code = belle_sip_response_get_status_code(response); + if (op->state == SalOpStateTerminated) { belle_sip_message("Op is terminated, nothing to do with this [%i]",response_code); return; diff --git a/coreapi/bellesip_sal/sal_impl.h b/coreapi/bellesip_sal/sal_impl.h index 1b036cc92..aca82a252 100644 --- a/coreapi/bellesip_sal/sal_impl.h +++ b/coreapi/bellesip_sal/sal_impl.h @@ -38,7 +38,7 @@ struct Sal{ typedef enum SalOpSate { SalOpStateEarly=0 ,SalOpStateActive - ,SalOpStateTerminating /*this state is used to wait until a procedding state, so we can send the cancel*/ + ,SalOpStateTerminating /*this state is used to wait until a proceeding state, so we can send the cancel*/ ,SalOpStateTerminated }SalOpSate_t; diff --git a/coreapi/bellesip_sal/sal_op_call.c b/coreapi/bellesip_sal/sal_op_call.c index 88455a2f6..5c672860c 100644 --- a/coreapi/bellesip_sal/sal_op_call.c +++ b/coreapi/bellesip_sal/sal_op_call.c @@ -84,8 +84,11 @@ static int set_sdp_from_desc(belle_sip_message_t *msg, const SalMediaDescription static void call_process_io_error(void *user_ctx, const belle_sip_io_error_event_t *event){ ms_error("process_io_error not implemented yet"); } -static void process_dialog_terminated(void *op, const belle_sip_dialog_terminated_event_t *event) { - if (((SalOp*)op)->dialog) ((SalOp*)op)->dialog=NULL; +static void process_dialog_terminated(void *ctx, const belle_sip_dialog_terminated_event_t *event) { + SalOp* op=(SalOp*)ctx; + if (op->dialog) { + op->dialog=NULL; + } } static void handle_sdp_from_response(SalOp* op,belle_sip_response_t* response) { belle_sdp_session_description_t* sdp; diff --git a/coreapi/bellesip_sal/sal_op_presence.c b/coreapi/bellesip_sal/sal_op_presence.c index 742f48e02..84db5b0a2 100644 --- a/coreapi/bellesip_sal/sal_op_presence.c +++ b/coreapi/bellesip_sal/sal_op_presence.c @@ -591,6 +591,10 @@ int sal_subscribe_presence(SalOp *op, const char *from, const char *to){ } int sal_unsubscribe(SalOp *op){ belle_sip_request_t* req=belle_sip_dialog_create_request(op->dialog,"SUBSCRIBE"); + if (!req) { + ms_error("Cannot unsubscribe to [%s]",sal_op_get_to(op)); + return -1; + } belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),belle_sip_header_create("Event","Presence")); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(0))); return sal_op_send_request(op,req); diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index a012d8035..bdd78c750 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -611,6 +611,17 @@ static void simple_subscribe() { linphone_core_manager_destroy(pauline); } +static void unsubscribe_while_subscribing() { + LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc"); + LinphoneFriend* friend = linphone_friend_new_with_addr("sip:toto@git.linphone.org"); /*any unexisting address*/ + linphone_friend_edit(friend); + linphone_friend_enable_subscribes(friend,TRUE); + linphone_friend_done(friend); + linphone_core_add_friend(marie->lc,friend); + linphone_core_iterate(marie->lc); + linphone_core_manager_destroy(marie); + +} static void call_early_media() { LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_early_rc"); @@ -692,6 +703,9 @@ CU_pSuite pSuite = CU_add_suite("liblinphone", init, uninit); if (NULL == CU_add_test(pSuite, "simple_publish", simple_publish)) { return CU_get_error(); } + if (NULL == CU_add_test(pSuite, "unsubscribe_while_subscribing", unsubscribe_while_subscribing)) { + return CU_get_error(); + } return 0; } int main (int argc, char *argv[]) {