[Sems] 403 response to INVITE

Stefan Sayer stefan.sayer at iptego.de
Tue Oct 30 18:56:47 CET 2007

Cyril Raymond wrote:
> Thanks Stefan and it works fine. BTW, is there any reason why there is a
> sleep for 5 seconds in AmSessionContainer::run(). Is this deliberate?
this sleep is there to let the thread itself stop (not the 
call/session), i.e. the time from the point that in AmThread::_start the 
thread sets _stopped, to the time that the thread is really stopped.

a more correct way would be to call pthread_join() (AmThread::join()) in 
  AmSessionContainer::run to wait for the thread to stop. In this case 
the sleep would not be necessary.

> The comment says,
> "Let some time for the Sessions to stop by themselves". But in cases
> where the session is terminated by  the server itself, isn't it ok to
if you are thinking about the call though, the situation is different: 
if the call is terminated by the server, the status is set to 
disconnecting, and the session waits for the response to the BYE to get 
in disconnected state - see the second loop in AmSession::run. otoh if 
the call is terminated from the other end, it goes into disconnected 
state immediately and is ended.

> cleanup asap? Is it advisable to remove this sleep?
not really, if you don't replace it with join (which could block the 
session cleaner if the session thread does not terminate).


> Thx,
>   Cyril
> -----Original Message-----
> From: Stefan Sayer [mailto:stefan.sayer at iptego.de] 
> Sent: Wednesday, October 24, 2007 11:15 PM
> To: Cyril Raymond
> Cc: sems at lists.iptel.org
> Subject: Re: [Sems] 403 response to INVITE
> Cyril Raymond wrote:
>> Hi all,
>>     How can I send a 403 Forbidden response to an incoming INVITE in a
>> conferencing application?
> either throw AmSession::Exception in the conferencefactory onInvite 
> function, or reply and stop in the session's onInvite function - depends
> on whether you need possibly blocking processing like db access; if this
> is the case then better do it in the session's thread (in onInvite), 
> otherwise you can already stop it in the factory, no need to create the 
> session thread then.
> in factory:
>   if (not allowed)
>    throw AmSession::Exception(403, "forbidden);
> in the session, sth like this:
> MySession::onInvite(const AmSipRequest& r) {
> if (not allowed) {
>    dlg.reply(403, "forbidden");
>    setStopped();
>   } else {
>     AmSession(onInvite(r));
> }
> }
> hth
> Stefan
>> A sample use-case would be the server hosting a conference and some 
>> unsolicited user wants to join the conference. In such a case, the 
>> server is required to respond with a 403 and not create any session.
>> Had browsed the AmSession and AmB2BSession classes and couldn't find
> any 
>> methods in AmSession, however the closest was terminateLeg of 
>> AmB2BSession. But the terminateLeg also sends a BYE after terminating 
>> the dialog, which is something I don't need.
>> Any pointers would be greatly appreciated.
>> Thanks,
>>     Cyril
> ------------------------------------------------------------------------
>> _______________________________________________
>> Sems mailing list
>> Sems at lists.iptel.org
>> http://lists.iptel.org/mailman/listinfo/sems

Stefan Sayer
VoIP Services

stefan.sayer at iptego.de

iptego GmbH
Am Borsigturm 40
13507 Berlin

Amtsgericht Charlottenburg, HRB 101010
Geschaeftsfuehrer: Alexander Hoffmann

More information about the Sems mailing list