[asterisk-dev] reset/remove SipAddHeader() headers

Leif Madsen leif.madsen at asteriskdocs.org
Fri Jan 16 08:00:31 CST 2009



Klaus Darilion wrote:
> John Todd schrieb:
>> Even in the instance where a 500 is received and somehow the dialplan  
>> is re-entered, it seems burdensome to remove ALL headers and start  
>> from scratch.  Wouldn't you just want to remove the specific header  
>> that is causing problems?  This would imply some sort of indexing, or  
>> at the minimum, regexp-style string matching so I could say:
>>
>>   exten => _X11.,SipRemoveHeader(X-PSAP-ID)
>>
>> which would remove both of these headers:
>>
>> X-PSAP-ID: 33-MONTCOPA-PRIMARY-9929312311AA
>> X-PSAP-ID: 33-MONTCOPA-BACK-99283122833CD
> 
> I submitted a patch which also takes at least some of your ideas - to 
> remove selectively too: http://bugs.digium.com/view.php?id=14246
> 
> 
> For example you have added these 2 headers:
>    SIPAddHeader(P-Asserted-Identity: sip:foo at bar);
>    SIPAddHeader(P-Preferred-Identity: sip:bar at foo);
> 
>    // remove all headers
>    SIPRemoveHeader();
> 
>    // remove all P- headers
>    SIPRemoveHeader(P-);
> 
>    // remove one the PAI header (note the : at the end)
>    SIPRemoveHeader(P-Asserted-Identity:);


What about programming it in such a way that you can get the number of 
results that match your criteria, then that would allow you to parse 
through the headers that match, and then you can filter out the ones you 
want.

I'm thinking about how the DUNDIQUERY() and DUNDIRESULT() functions work 
(see them for more information about the syntax I'm using below). Here 
is a little dialplan code that would go through, get the number SIP 
headers that started with P-, check if the value of the header was 
'sip:foo at bar', and if so, remove that header. If not, then move onto the 
next header, until no more exist.

    Set(HEADER_RES=${SIP_HEADER_QUERY(P-)})
    Set(HEADER_COUNT=${SIP_HEADER_RESULT(${HEADER_RES},getnum)})   ; 
(Result returns say 2)



    Verbose(2,Removing all headers starting with P- and a value of 
sip:foo at bar)
    Set(X=1)
    While($[${HEADER_COUNT} <= ${X}])
    Set(CURRENT_HEADER=${SIP_HEADER_RESULT(${HEADER_RES},${X})})
    ExecIf($["${CURRENT_HEADER}" = "sip:foo at bar"]?SIPRemoveHeader(P-,${X}))
    Verbose(2,${IF($[${CURRENT_HEADER}" = 
"sip:foo at bar"]?Verbose(2,Header removed:No header modification))
    Set(X=$[${X} + 1])
    EndWhile()
    Verbose(2,Headers removal complete)



Thanks!
Leif Madsen
http://www.leifmadsen.com
http://www.asteriskdocs.org



More information about the asterisk-dev mailing list