[asterisk-dev] Add SIP Header with PJSIP in C module

Neimar neimar.avila at virtualsistemas.com.br
Wed Oct 21 12:50:41 CDT 2020


Hi, your header need to be inside dial, not before 
pbx_exec(chan, "Dial(PJSIP/101 at trunk-test,10, b(predial-vars,s,1) )"); 

And context: 

[predial-vars] 
exten=> s,1,Set(PJSIP_HEADER(add,X-VSPhone-Case)=${X-VSPhone-Case})) 



Atenciosamente, 
Neimar Lima de Ávila | Desenvolvimento/Telecomunicações | Virtual Sistemas Ltda. 
Rua Gonçalves Dias, 142 SL 704 - Funcionários - CEP:30.140-090 - Bhte/MG 
Tel: (31)3245-6213 - Ramal 2016 | Cel: (31)98495-2402 
[ http://www.virtualsistemas.com.br/ | www.virtualsistemas.com.br ] | [ mailto:neimar.avila at virtualsistemas.com.br | neimar.avila at virtualsistemas.com.br ] 





Preserve o Meio Ambiente! Pense Antes de Imprimir 
Os dados transmitidos nesta mensagem destinam-se exclusivamente a(s) pessoa(s) mencionada(s) e contém informações confidenciais, 
legalmente protegidas, para conhecimento exclusivo do(s) destinatário(s).O exame, retransmissão, divulgação, leitura, cópia ou outro uso 
desta correspondência, por pessoas, físicas ou jurídicas, que não o(s) destinatário(s), constituirá obtenção de dados por meio ilícito, 
configurando ofensa ao Art. 5°, inciso XII, da CF/88. 


De: "Benoit Duverger" <bduverger at atwtech.com> 
Para: "Asterisk Developers Mailing List" <asterisk-dev at lists.digium.com> 
Enviadas: Quarta-feira, 21 de outubro de 2020 14:28:08 
Assunto: Re: [asterisk-dev] Add SIP Header with PJSIP in C module 

Thanks for your quick answer. 
I'm not sure to understand how Pre-Dial Handlers can help my module written in C. But if I decide to rewrite this module in asterisk language, that could help me. For the moment I hope to fix my C module. 

A big resume of what this part of my module do is: 
pbx_exec(chan, "SipAddHeader(X-MyHeader:valuetest)"); 
pbx_exec(chan, "Dial(SIP/101 at trunk-test,10)"); 
That works in asterisk 1.8, 11 and probably in asterisk 16 if I use chan_sip but SipAddHeader is no longer a valid application in my asterisk because I don't load chan_sip.so, just all modules related to PJSIP. 

So with PJSIP, I try: 
pbx_builtin_setvar_helper(chan, "PJSIP_HEADER(add,X-MyHeader)", "valuetest"); 
pbx_exec(chan, "Dial(PJSIP/101 at trunk-test,10)"); 

I didn't have any errors but my header is not added. 

Thanks 


Le mer. 21 oct. 2020 à 12:23, Richard Mudgett < [ mailto:rmudgett at digium.com | rmudgett at digium.com ] > a écrit : 



You add headers in a similar way as before. It is just a matter of adding them to the right channel. 
You must add them to the outgoing channel for PJSIP. This can be accomplished by using pre-dial handlers [1][2]. 

Richard 

[1] [ https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers | https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers ] 
[2] [ https://www.asterisk.org/dialplan-handler-routines-allow-customization/ | https://www.asterisk.org/dialplan-handler-routines-allow-customization/ ] 

On Wed, Oct 21, 2020 at 10:49 AM Benoit Duverger < [ mailto:bduverger at atwtech.com | bduverger at atwtech.com ] > wrote: 

BQ_BEGIN

Hello, 

We have a module written in C which was developed initially for asterisk 1.4, modified a few years ago to run in asterisk 1.8 then 11. This module is used to verify user's limits, route calls etc... 
Actually, I try to adapt it to run in asterisk 16, I moved from chan_sip to PJSIP and I don't know how can I add SIP Headers into the channel. With chan_sip we used that: 
sprintf( cmd, "SipAddHeader(command:%s)", command ); 
res = astcmd( chan, cmd ); 
astcmd is a custom function wrapped onto pbx_exec(). 

I tried to use pbx_builtin_setvar_helper(), with the function PJSIP_HEADER() but I didn't see any custom headers in SIP... and no errors, res = 0. 
res = pbx_builtin_setvar_helper(chan, "PJSIP_HEADER(add, X-test)", "test"); 


How can I use PJSIP_HEADER in a C module ?, which libraries should I need to import ? 

Thanks 

-- 
Benoit 
-- 
_____________________________________________________________________ 
-- Bandwidth and Colocation Provided by [ http://www.api-digital.com/ | http://www.api-digital.com ] -- 

asterisk-dev mailing list 
To UNSUBSCRIBE or update options visit: 
[ http://lists.digium.com/mailman/listinfo/asterisk-dev | http://lists.digium.com/mailman/listinfo/asterisk-dev ] 


-- 
_____________________________________________________________________ 
-- Bandwidth and Colocation Provided by [ http://www.api-digital.com/ | http://www.api-digital.com ] -- 

asterisk-dev mailing list 
To UNSUBSCRIBE or update options visit: 
[ http://lists.digium.com/mailman/listinfo/asterisk-dev | http://lists.digium.com/mailman/listinfo/asterisk-dev ] 
BQ_END



-- 
Benoit Duverger 
Administrateur Systèmes et Réseaux 
Sysadmin 
T : [ tel:(514)%20985-2570 | 514- ] 985-2570 #148 


[ http://www.atwtech.com/ | www.atwtech.com ] 
1050 de la Montagne, Suite 400 
Montréal (Québec) H3G 1Y8 Avis de confidentialité 
Le contenu de ce message ainsi que du ou des fichiers qui y sont joints est strictement confidentiel et destiné exclusivement à son ou sa destinataire. Si vous n’êtes pas cette personne, nous attirons votre attention sur le fait qu’il est strictement interdit de copier, de faire suivre ou d’utiliser les informations contenues dans ce courriel. Si vous l’avez reçu par erreur, nous vous remercions de nous le faire savoir et de détruire toute copie de ce message. 

Confidentiality Warning 
The information contained in this email and any attachments may be privileged, confidential, and/or proprietary and is intended solely for the use of the person(s) to whom it is addressed. If you are not the intended recipient, any review, retransmission, dissemination or any other use of the information contained in this email and any attachments is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to this email and delete all copies of the message. 

-- 
_____________________________________________________________________ 
-- Bandwidth and Colocation Provided by http://www.api-digital.com -- 

asterisk-dev mailing list 
To UNSUBSCRIBE or update options visit: 
http://lists.digium.com/mailman/listinfo/asterisk-dev 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20201021/2779ad73/attachment-0001.html>


More information about the asterisk-dev mailing list