From 3fda5955fd5bdef7717af044706942373a27ad0c Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Tue, 9 Jul 2013 17:05:23 +0200 Subject: [PATCH] fix various crash due to // transaction --- coreapi/bellesip_sal/sal_op_events.c | 5 +++-- coreapi/bellesip_sal/sal_op_presence.c | 25 +++++++++++++++++++++---- tester/eventapi_tester.c | 5 +++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/coreapi/bellesip_sal/sal_op_events.c b/coreapi/bellesip_sal/sal_op_events.c index e454ab293..2c490ce6b 100644 --- a/coreapi/bellesip_sal/sal_op_events.c +++ b/coreapi/bellesip_sal/sal_op_events.c @@ -293,7 +293,8 @@ int sal_notify(SalOp *op, const SalBody *body){ if (!op->dialog) return -1; - notify=belle_sip_dialog_create_request(op->dialog,"NOTIFY"); + if (!(notify=belle_sip_dialog_create_request(op->dialog,"NOTIFY"))) return -1; + if (set_event_name(op,(belle_sip_message_t*)notify)==-1){ belle_sip_object_unref(notify); return -1; @@ -309,7 +310,7 @@ int sal_notify(SalOp *op, const SalBody *body){ int sal_notify_close(SalOp *op){ belle_sip_request_t* notify; if (!op->dialog) return -1; - notify=belle_sip_dialog_create_request(op->dialog,"NOTIFY"); + if (!(notify=belle_sip_dialog_create_request(op->dialog,"NOTIFY"))) return -1; set_event_name(op,(belle_sip_message_t*)notify); belle_sip_message_add_header(BELLE_SIP_MESSAGE(notify) ,BELLE_SIP_HEADER(belle_sip_header_subscription_state_create(BELLE_SIP_SUBSCRIPTION_STATE_TERMINATED,-1))); diff --git a/coreapi/bellesip_sal/sal_op_presence.c b/coreapi/bellesip_sal/sal_op_presence.c index 89a6dbbb5..769e1740d 100644 --- a/coreapi/bellesip_sal/sal_op_presence.c +++ b/coreapi/bellesip_sal/sal_op_presence.c @@ -287,18 +287,29 @@ int sal_subscribe_presence(SalOp *op, const char *from, const char *to, int expi static belle_sip_request_t *create_presence_notify(SalOp *op){ belle_sip_request_t* notify=belle_sip_dialog_create_request(op->dialog,"NOTIFY"); + if (!notify) return NULL; + belle_sip_message_add_header((belle_sip_message_t*)notify,belle_sip_header_create("Event","presence")); return notify; } -int sal_notify_presence(SalOp *op, SalPresenceModel *presence){ +static int sal_op_check_dialog_state(SalOp *op) { belle_sip_dialog_state_t state=op->dialog?belle_sip_dialog_get_state(op->dialog): BELLE_SIP_DIALOG_NULL; - belle_sip_request_t* notify=NULL; if (state != BELLE_SIP_DIALOG_CONFIRMED) { - ms_warning("Cannot notify presence because dialog in state [%s]",belle_sip_dialog_state_to_string(state)); + ms_warning("Cannot notify presence for op [%p] because dialog in state [%s]",op, belle_sip_dialog_state_to_string(state)); + return -1; + } else + return 0; + +} +int sal_notify_presence(SalOp *op, SalPresenceModel *presence){ + belle_sip_request_t* notify=NULL; + if (sal_op_check_dialog_state(op)) { return -1; } notify=create_presence_notify(op); + if (!notify) return-1; + sal_add_presence_info(op,BELLE_SIP_MESSAGE(notify),presence); /*FIXME, what about expires ??*/ belle_sip_message_add_header(BELLE_SIP_MESSAGE(notify) ,BELLE_SIP_HEADER(belle_sip_header_subscription_state_create(BELLE_SIP_SUBSCRIPTION_STATE_ACTIVE,600))); @@ -306,7 +317,13 @@ int sal_notify_presence(SalOp *op, SalPresenceModel *presence){ } int sal_notify_presence_close(SalOp *op){ - belle_sip_request_t* notify=create_presence_notify(op); + belle_sip_request_t* notify=NULL; + if (sal_op_check_dialog_state(op)) { + return -1; + } + notify=create_presence_notify(op); + if (!notify) return-1; + sal_add_presence_info(op,BELLE_SIP_MESSAGE(notify),NULL); /*FIXME, what about expires ??*/ belle_sip_message_add_header(BELLE_SIP_MESSAGE(notify) ,BELLE_SIP_HEADER(belle_sip_header_subscription_state_create(BELLE_SIP_SUBSCRIPTION_STATE_TERMINATED,-1))); diff --git a/tester/eventapi_tester.c b/tester/eventapi_tester.c index 9e3e15a36..cc7a6905b 100644 --- a/tester/eventapi_tester.c +++ b/tester/eventapi_tester.c @@ -30,6 +30,8 @@ static const char *notify_content="blabla"; void linphone_notify_received(LinphoneCore *lc, LinphoneEvent *lev, const char *eventname, const LinphoneContent *content){ CU_ASSERT_PTR_NOT_NULL_FATAL(content); CU_ASSERT_TRUE(strcmp(notify_content,(const char*)content->data)==0); + LinphoneCoreManager *mgr=get_manager(lc); + mgr->stat.number_of_NotifyReceived++; } void linphone_subscription_state_change(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state) { @@ -124,6 +126,9 @@ static void subscribe_test_with_args(bool_t terminated_by_subscriber) { CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionActive,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneSubscriptionActive,1,1000)); + /*make sure marie receives first notification before terminating + CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_NotifyReceived,1,1000));*/ + if (terminated_by_subscriber){ linphone_event_terminate(lev); }else{