Skip to content

Commit 8133656

Browse files
committed
Fix proper callig in local cancels with TH.
Extend the coverage of the preocessing context and TM context over the cancel_branch() function (in the timeout handler) so the TH callbacks can reach back the dialog and do the TH related changes. Reported by Julian Santer on mailing list.
1 parent ad44a05 commit 8133656

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

modules/tm/timer.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -243,24 +243,10 @@ static void delete_cell( struct cell *p_cell, int unlock )
243243

244244
static void fake_reply(struct cell *t, int branch, int code )
245245
{
246-
static context_p my_ctx = NULL;
247-
context_p old_ctx;
248246
branch_bm_t cancel_bitmap;
249247
short do_cancel_branch;
250248
enum rps reply_status;
251249

252-
/* as this processing is outside the scope of other messages (it is
253-
trigger from timer), a processing context must be attached to it */
254-
old_ctx = current_processing_ctx;
255-
if (my_ctx==NULL) {
256-
my_ctx = context_alloc(CONTEXT_GLOBAL);
257-
if (my_ctx==NULL) {
258-
LM_ERR("failed to alloc new ctx in pkg\n");
259-
}
260-
}
261-
memset( my_ctx, 0, context_size(CONTEXT_GLOBAL) );
262-
current_processing_ctx = my_ctx;
263-
264250
do_cancel_branch = is_invite(t) && should_cancel_branch(t, branch);
265251

266252
cancel_bitmap=do_cancel_branch ? 1<<branch : 0;
@@ -274,14 +260,6 @@ static void fake_reply(struct cell *t, int branch, int code )
274260
reply_status=relay_reply( t, FAKED_REPLY, branch, code,
275261
&cancel_bitmap );
276262
}
277-
278-
if (current_processing_ctx==NULL)
279-
my_ctx=NULL;
280-
else
281-
context_destroy(CONTEXT_GLOBAL, my_ctx);
282-
283-
/* switch back to the old context */
284-
current_processing_ctx = old_ctx;
285263
}
286264

287265

@@ -341,6 +319,8 @@ inline static void final_response_handler( struct timer_link *fr_tl )
341319
#define CANCEL_REASON_SIP_480 \
342320
"Reason: SIP;cause=480;text=\"NO_ANSWER\"" CRLF
343321

322+
static context_p my_ctx = NULL;
323+
context_p old_ctx;
344324
struct retr_buf* r_buf;
345325
struct cell *t;
346326

@@ -385,6 +365,20 @@ inline static void final_response_handler( struct timer_link *fr_tl )
385365
return;
386366
};
387367

368+
/* as this processing is outside the scope of other messages (it is
369+
trigger from timer), a processing context must be attached to it */
370+
old_ctx = current_processing_ctx;
371+
if (my_ctx==NULL) {
372+
my_ctx = context_alloc(CONTEXT_GLOBAL);
373+
if (my_ctx==NULL) {
374+
LM_ERR("failed to alloc new ctx in pkg\n");
375+
}
376+
}
377+
memset( my_ctx, 0, context_size(CONTEXT_GLOBAL) );
378+
current_processing_ctx = my_ctx;
379+
/* set the T context too */
380+
set_t( t );
381+
388382
/* out-of-lock do the cancel I/O */
389383
if (is_invite(t) && should_cancel_branch(t, r_buf->branch) ) {
390384
set_cancel_extra_hdrs( CANCEL_REASON_SIP_480, sizeof(CANCEL_REASON_SIP_480)-1);
@@ -396,6 +390,16 @@ inline static void final_response_handler( struct timer_link *fr_tl )
396390
LM_DBG("Cancel sent out, sending 408 (%p)\n", t);
397391
fake_reply(t, r_buf->branch, 408 );
398392

393+
/* flush the context */
394+
if (current_processing_ctx==NULL)
395+
my_ctx=NULL;
396+
else
397+
context_destroy(CONTEXT_GLOBAL, my_ctx);
398+
/* switch back to the old context */
399+
current_processing_ctx = old_ctx;
400+
/* reset the T context */
401+
init_t();
402+
399403
LM_DBG("done\n");
400404
}
401405

0 commit comments

Comments
 (0)