Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 102141) +++ channels/chan_sip.c (arbetskopia) @@ -899,6 +899,10 @@ int attendedtransfer; /*!< Attended or blind transfer? */ int localtransfer; /*!< Transfer to local domain? */ enum referstatus status; /*!< REFER status */ + int notify_cseq; /*!< Cseq of unanswered NOTIFY */ + char *next_notify; /*!< Next notify to send */ + int next_cseq; /*!< Cseq to use */ + int next_terminate; /*!< Terminate flag of next message */ }; /*! \brief sip_pvt: PVT structures are used for each SIP dialog, ie. a call, a registration, a subscribe */ @@ -3086,6 +3090,10 @@ ast_rtp_destroy(p->vrtp); if (p->udptl) ast_udptl_destroy(p->udptl); + + if (p->refer && p->refer->next_notify) + free(p->refer->next_notify); + if (p->refer) free(p->refer); if (p->route) { @@ -7337,6 +7345,18 @@ struct sip_request req; char tmp[SIPBUFSIZE/2]; + /* Check if we already have an open NOTIFY transaction. If so, then cache this. + Overwrite previous message if we have multiple messages on queue. */ + if (p->refer && p->refer->notify_cseq) { + if (p->refer->next_notify) + free(p->refer->next_notify); + p->refer->next_notify = ast_strdup(message); + p->refer->next_cseq = cseq; + p->refer->next_terminate = terminate; + if (option_debug > 2) + ast_log(LOG_DEBUG, "Queueing Refer NOTIFY message due to open transaction.\n"); + } + reqprep(&req, p, SIP_NOTIFY, 0, 1); snprintf(tmp, sizeof(tmp), "refer;id=%d", cseq); add_header(&req, "Event", tmp); @@ -7353,6 +7373,8 @@ initialize_initreq(p, &req); p->lastnoninvite = p->ocseq; + if (p->refer) + p->refer->notify_cseq = p->ocseq; return send_request(p, &req, XMIT_RELIABLE, p->ocseq); } @@ -12633,8 +12655,16 @@ if (!p->refer) { ast_log(LOG_WARNING, "Notify answer on an owned channel? - %s\n", p->owner->name); ast_queue_hangup(p->owner); - } else if (option_debug > 3) - ast_log(LOG_DEBUG, "Got OK on REFER Notify message\n"); + } else { + if (option_debug > 3) + ast_log(LOG_DEBUG, "Got OK on REFER Notify message\n"); + p->refer->notify_cseq = 0; /* No pending NOTIFY's */ + if (p->refer->next_notify) { /* If we have a queued notify, send it now */ + transmit_notify_with_sipfrag(p, p->refer->next_cseq, p->refer->next_notify, p->refer->next_terminate); + free(p->refer->next_notify); + p->refer->next_notify = NULL; + } + } } else { if (p->subscribed == NONE) ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);