No value returned using PJSIP_CONTACTS()

Good morning!

Using Asterisk 20.4.0.

We have a temporary need to only Dial contacts that match a specific PJSIP contact user_agent.

PJSIP_CONTACT() to the rescue! Or so I thought. Using the following test I’m successfully parsing the contacts and getting them into VAR1 and VAR2, but when I try to pull the user_agent it’s just blank. I can’t seem to retrieve any field this way, perhaps I’m missing something obvious.

Thanks for any advice! :slight_smile:

exten => s,1,Set(CONTACTS=${REPLACE(PJSIP_DIAL_CONTACTS(${ENDPOINT}),&,\,)})
exten => s,n,NoOp( *** CONTACTS:${CONTACTS} *** )
exten => s,n,Set(ARRAY(VAR1,VAR2,VAR3)=${CONTACTS})
exten => s,n,NoOp( *** VAR1:${VAR1} *** )
exten => s,n,NoOp( *** VAR2:${VAR2} *** )
exten => s,n,NoOp( *** UA1:${PJSIP_CONTACT(${VAR1},user_agent)} *** )
exten => s,n,NoOp( *** UA2:${PJSIP_CONTACT(${VAR2},user_agent)} *** ) 

Hmm… the plot thickens! This warning was generated (edited for privacy):

func_pjsip_contact.c: Failed to retrieve information for contact 'PJSIP/endpoint/sip:foo@1.2.3.4:51670;transport=ws;x-ast-orig-host=bar.invalid:0

However, the contact exists via the cli using pjsip show contact :confused:

Hmm… I also see the user agents are stored in the database:

/registrar/contact/endpoint;@7685c0ce5b4d2628db0788b437726213

Looks like the contact string is hashed with MD5(), this may get me there in a pinch!

Still looking for advice for the PJSIP_CONTACT() function, seems the better way to go.

Big Thanks :slight_smile:

I definitely get the “Best Way to Hack Asterisk on a Monday” award! :laughing: :sweat_smile: :joy:

[test]
exten => s,1,Set(CONTACTS=${REPLACE(PJSIP_DIAL_CONTACTS(ENDPOINT),&,\,)})
exten => s,n,Set(ARRAY(VAR1,VAR2)=${CONTACTS})
exten => s,n,Gosub(ua,s,1(${VAR1},${EXTEN}))
exten => s,n,NoOp( *** UA1:${GOSUB_RETVAL} *** )                                                                                                                                                                                                                                               
exten => s,n,Gosub(ua,s,1(${VAR2},${EXTEN}))
exten => s,n,NoOp( *** UA2:${GOSUB_RETVAL} *** )

[ua]
exten => s,1,Set(HASH=${MD5(${CUT(ARG1,/,3)})})
exten => s,n,Set(JSON=${DB(registrar/contact/ENDPOINT\;@${HASH})})
exten => s,n,Set(UA=${JSON_DECODE(JSON,user_agent)})
exten => s,n,Return(${UA})
4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.