Way to get ToHeader name or Number

Hello;
I am trying to get ToHeader number but couldnt find a way. I tried to get it with CUT method on Sipheader function.
I tried to Callerid(dnid) , ConnectedLine() etc…

even if there is a called party parameters on structer , i couldnt find any function or variable about it?
Could you help me about it please.
Cheers

Keyword How to get destination number id
How to get To header number

Please provide the code that used CUT and we will tell you what is wrong with it.

exten => _X.,1,NoOp( *- -* )
exten => _X.,n,Noop(${SIP_HEADER(P-Asserted-Identity)})
exten => _X.,n,SET(VALTO=${SIP_HEADER(To)})
exten => _X.,n,SET(VALTO=${CUT(VALTO,:,2)})
exten => _X.,n,SET(VALTO=${CUT(VALTO,@,1)})
exten => _X.,n,SipAddHeader(P-Unique:${UNIQUEID})
exten => _X.,n,Set(ARANAN=${EXTEN:-10})
exten => _X.,n,Dial(SIP/${EXTEN}@trunk!${VALTO}@192.168.0.5,40,S(3602))
exten => _X.,n,Hangup()

i cutted it with “:” but there is possible that can be added (:port) on To header. so it is possible that breaks CUT function. if there is function that parse to header like CallerID , i think it is really useful.

In addition , there isnt any option PJSIP to manipulate toheader like Chan_sip. a function that parse toheader and can manipulate number or name , is really useful both chan_sip and chan_pjsip. once , i sent a email to asterisk developer about it , i couldnt get any response. i can spend my time to add this function but if it isnt accepted from asterisk developer to add asterisk project , it is waste of time.

so here is my problem : To header.

Please use </> (unformatted text) to avoid things like <...> being deleted and _ being interpreted as start and end of italics (this forum software may be good for mobile devices but it is useless for documenting SIP problems).

You should be able to see how the parse of the header is working by enable verbose logging at at least level 3, but I can’t see any problem for a simple addr-spec without a port number. It won’t cope with name-addr format headers.

For a relatively complicated parse, like this, regular expressions may be better.

User defined headers should start with “X-”, not “P-”.

It looks like you are trying to make Asterisk behave like a proxy when it is a back to back user agent.

Thanks for reply,advices

i had a look a Code button on text window ,couldnt find so i am sorry missed texts.

You are right that without port there isnt any problem. i need to add a little controls to avoid Errors.I dont use Name parts as name -addr.

thanks advice for User defined headers.

you are right it is back to back User Agent and Asterisk makes more flexible system so I like it. I tried to move chan_pjsip but Toheader manipulations stopped me.

Can you explain why you need to manipulate the To header?

Hello,

After watching Matt Jordan’s presentation at Kamailio World Conf in 2016 , I decided to switch architecture chan_sip to pjsip.
So i started to testing Pjsip that is suitable for our system because There is always a feature that can be forgetten , missing or has a bug.
First of all , i realized that to header manipulation is removed with exclamation mark in Pjsip.
I tried to some configuration with outbound parameters.But i failed. Maybe , i couldnt find way to change it.

In Addition , i realized that it changes to header with the same as Request Uri Number on lr mode!

In conclusion , I already sent a topic to Forum and then couldn’t find solution with jcolp ,So is it possible to Add a Function about Setting To header Number like CallerId In Pjsip?
How can we solve this problem? I dont want to add a purge about To header in Kamailio because it can be breakable on ACK ,200-OK or other transacations. Asterisk is so good about dialog transacations.

Why i am trying to do that? Because some kind of FXS devices need to waits Request Uri Number and To header Number must be same ,if not it declines the calls.Kamailio Modules can only remove/add prefix/suffix on Request Uri Number(Carrier Module).

Thanks for Helps.

Yasin CANER

Here is Flow;

KamailioIP:5060    -->    AsteriskIP:5060

x x

xINVITE sip:102105066109057atAsteriskIP:5060 SIP/2.0
xRecord-Route: sip:KamailioIP;lr;ftag=c963d657
Via: SIP/2.0/UDP KamailioIP;branch=z9hG4bKcdef.f
xVia: SIP/2.0/UDP 192.168.0.223:64556
xContact: sip:8503023423atUac1IP:3321;transport=UDP
xTo: sip:05066109057atKamailioIP;transport=UDP
xFrom: "8503023423"sip:8503023423atKamailioIP;transport=UDP;tag=c963d6
xCall-ID: 2tiU_X3S8_qbX3K0nOFYeQ…
xCSeq: 2 INVITE
xAllow: INVITE, ACK, CANCEL, BYE

        AsteriskIP:5060  --->        KamailioIP:5060
                x        INVITE (SDP)         x

xINVITE sip:102105066109057atKamailioIP:5060 SIP/2.0
xVia: SIP/2.0/UDP AsteriskIP:5060;rport;branch=z9hG4b
xFrom: “8503023423” sip:8503023423atAsteriskIP;tag=a21fc
xTo: sip:102105066109057atKamailioIP
xContact: sip:asteriskatAsteriskIP:5060
xCall-ID: d170e273-6bcc-474b-9816-a6b884419ff2
xCSeq: 23680 INVITE
xRoute: sip:KamailioIP;lr
xAllow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE
xUser-Agent: Asterisk PBX 14.0.1
xContent-Type: application/sdp
xContent-Length: 259

Here is architecture;
Kamailio -> registrar server , location server , edge server …
Asterisk -> Application server , RTP server …

|||||||
| UAC1|
|||||||
^
|
|
|||||||||||| ||||||||||||||
| |<---------- | |
| Kamailio | | Asterisk* |
| |----------> | |
|||||||||||| ||||||||||||||
^
|
|
|
|||||||
| UAC2|
|||||||

Here is my pjsip.conf

[global]
max_forwards=30
user_agent=TEST
keep_alive_interval=60

[simpletrans]
type=transport
protocol=udp
bind=AsteriskIP

[kamailio]
type=endpoint
transport=simpletrans
context=netgsm
disallow=all
allow=ulaw
allow=alaw
;outbound_proxy=sip:kamailioIP
outbound_proxy=sip:kamailioIP;lr

[kamailio]
type=identify
endpoint=kamailio
match=kamailioIP

That’s what I was looking for, thanks :smile:

Did you try using the PJSIP_HEADER function in a pre-dial handler on the outbound channel?

i cant remember clearly that it just adds more To header because i tried it about 3 months ago.

i can try it again.

Make sure you specify update. It should be something like:

same => n,Set(PJSIP_HEADER(update,To)=${TO_VALUE})
1 Like

Hello;
There isnt any effect on it. I think it creates new dialog with pjsip functions so it dont work. Here is my conf.

res_pjsip_session.c:1733 ast_sip_session_create_outgoing: psjip_inv_create uac

[system]
type=system
threadpool_auto_increment=15

[global]
type=global
max_forwards=30
user_agent=operatorX
keep_alive_interval=20
default_realm=operatorXXD
default_from_user=Net

[simpletrans]
type=transport
protocol=udp
bind=bindip

[notsimple]
type=transport
protocol=udp
bind=172.20.12.186


[kamailio]
type = endpoint
transport=simpletrans
t38_udptl=no
fax_detect=no
allow_transfer=no
force_rport=yes
direct_media=no
disallow=all
allow=g729
allow=ulaw
allow=alaw
allow=g723
allow=g722
aors=kamailio
context=operatorX-out
;rtp_timeout=60
allow_subscribe=no

[kamailio]
type=identify
endpoint=kamailio
match=kamailioip

[kamailio]
type = aor
max_contacts = 10
qualify_frequency=60
qualify_timeout=3.0      ; Qualify timeout in fractional seconds (default: "3.0")
authenticate_qualify=no


[operatorX]
type = endpoint
transport=notsimple
t38_udptl=no
fax_detect=no
allow_transfer=no
direct_media=no
disallow=all
allow=g729
allow=ulaw
allow=alaw
allow=g723
allow=g722
aors=operatorX
rtp_timeout=120
context=operatorX-in
rewrite_contact=yes
allow_subscribe=no
user_eq_phone=yes

[operatorX]
type=identify
endpoint=operatorX
match=172.20.12.186

[operatorX]
type = aor
max_contacts = 10
qualify_frequency=60
qualify_timeout=5.0      ; Qualify timeout in fractional seconds (default: "3.0")
authenticate_qualify=no



[operatorX-out]
exten => _X.,1,NoOp(***************** Avea-out ******************)
exten => _X.,n,Set(GROUP()=OUT)
exten => _X.,n,NoOp(${GROUP_COUNT()})
exten => _X.,n,NoOp(CALLERID:${CALLERID(all)})
exten => _X.,n,Set(CALLERID(name)=${CALLERID(num)})
exten => _X.,n,NoOp(DEGISEN CALLERID:${CALLERID(all)})
exten => _X.,n,NoOp(Redirecting-from-all ${REDIRECTING(from-all)})
exten => _X.,n,NoOp(Redirecting-from-num ${REDIRECTING(from-num)})
exten => _X.,n,NoOp(Redirecting-reason ${REDIRECTING(reason)})
exten => _X.,n,NoOp(Redirecting-count ${REDIRECTING(count)})
exten => _X.,n,NoOp(CLI rdnis ${CALLERID(rdnis)})
exten => _X.,n,Set(VALTO=${PJSIP_HEADER(read,To)})
exten => _X.,n,NoOp(${VALTO})
exten => _X.,n,Set(PJSIP_HEADER(update,To)=sip:23423@kamailioip)
exten => _X.,n,Dial(PJSIP/operatorX/sip:${EXTEN}@172.20.12.186:5060)
exten => _X.,n,Hangup()


exten => h,1,Noop(billsec  ${CDR(billsec)} ${UNIQUEID} )
exten => h,n,Noop(DIALSTATUS -> ${DIALSTATUS}  )

Pjsip creates new dialog so we need to find another way to easy to it. if there is a need a To Header function like CallerID , i can spend my time or could you give me another advice please.

Pjsip is nice coded and like it but it is hard to add new thing without understanding pjsip. and it is really acceptable that it is really hard.

Thanks, cheers.

I wouldn’t expect the dialplan you posted to work, as PJSIP_HEADER is operating on the inbound channel:

exten => _X.,n,Set(PJSIP_HEADER(update,To)=sip:23423@kamailioip)
exten => _X.,n,Dial(PJSIP/operatorX/sip:${EXTEN}@172.20.12.186:5060)

Your premise that PJSIP is going to create a new dialog for the outbound channel is correct - Asterisk is a B2BUA and each channel has its own dialog. Hence, to modify the SIP headers on the outbound channel, we need to call PJSIP_HEADER on the right channel.

In order to do that, you need to use a pre-dial handler. Examples of doing that can be seen on the documentation for Dial as well.

Try the following:

exten => _X.,n,Dial(PJSIP/operatorX/sip:${EXTEN}@172.20.12.186:5060,,b(operatorX-out^outbound_cb^1))
...

exten => outbound_cb,1,NoOp()
 same => n,Set(PJSIP_HEADER(update,To)=sip:23423@kamailioip)
 same => n,Return()

Hello;
Thanks for reply.

it doesnt work. it gives error as below.

-- Executing [s@outchannelsub:1] NoOp("PJSIP/operatorX-00001016", "Out Channel ") in new stack
    -- Executing [s@outchannelsub:2] Set("PJSIP/operatorX-00001016", "PJSIP_HEADER(update,To)=sip:23423@kamailioip") in new stack
[Nov 16 08:54:02] ERROR[8431]: res_pjsip_header_funcs.c:380 **update_header: No headers had been previously added to this session.**
    -- Executing [s@outchannelsub:3] Return("PJSIP/operatorX-00001016", "") in new stack
  == Spawn extension (operatorX-in, 8503023423, 1) exited non-zero on 'PJSIP/operatorX-00001016'
    -- PJSIP/operatorX-00001016 Internal Gosub(outchannelsub,s,1) complete GOSUB_RETVAL=

So i tried to add a To header and update it. But it adds more To header.I have a look other Dial commands i couldnt find any options.

Today i got another problem for To header. An International Trunks needs to “To header must be E.164 format” and add request Line must be with out “+” or “00” and add a prefix like 4325

Cheers.