<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">That code gets you about 95% of the way
      there.<br>
      <br>
      The biggest difference would be that the pjsip_msg_add_hdr() call
      may need to be broken up based on whether the SIPREFERREDBYHDR
      channel variable is set or not. To determine that, you can use the
      pbx_builtin_getvar_helper() function call declared in
      include/asterisk/pbx.h to retrieve the variable value, and the
      ast_strlen_zero() function to determine if the channel variable
      value is zero-length or not.<br>
      <br>
      Other than that, you should be able to omit the call to
      pjsua_process_msg_data() since Asterisk doesn't use pjsua.<br>
      <br>
      On 08/25/2015 12:35 PM, Dan Cropp wrote:<br>
    </div>
    <blockquote
cite="mid:09CB4F1B52EDEE40A8CD0772960C106E01450D27E1@Mail2010.amtelco.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <meta name="Generator" content="Microsoft Word 14 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        color:black;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoPlainText">In doing a little research, it seems the
          Referred-By header could be added after the
          pjsip_xfer_initiate.<o:p></o:p></p>
        <p class="MsoPlainText">This is the approach PJSIP did for some
          code as far back as PJSIP 1.6.<o:p></o:p></p>
        <p class="MsoPlainText"><o:p> </o:p></p>
        <p class="MsoPlainText">    /*<o:p></o:p></p>
        <p class="MsoPlainText">     * Create REFER request.<o:p></o:p></p>
        <p class="MsoPlainText">     */<o:p></o:p></p>
        <p class="MsoPlainText">    status = pjsip_xfer_initiate(sub,
          dest, &tdata);<o:p></o:p></p>
        <p class="MsoPlainText">    if (status != PJ_SUCCESS) {<o:p></o:p></p>
        <p class="MsoPlainText">                pjsua_perror(THIS_FILE,
          "Unable to create REFER request", status);<o:p></o:p></p>
        <p class="MsoPlainText">                pjsip_dlg_dec_lock(dlg);<o:p></o:p></p>
        <p class="MsoPlainText">                return status;<o:p></o:p></p>
        <p class="MsoPlainText">    }<o:p></o:p></p>
        <p class="MsoPlainText"><o:p> </o:p></p>
        <p class="MsoPlainText">    /* Add Referred-By header */<o:p></o:p></p>
        <p class="MsoPlainText">    gs_hdr =
          pjsip_generic_string_hdr_create(tdata->pool,
          &str_ref_by,<o:p></o:p></p>
        <p class="MsoPlainText">                                                                               
               &dlg->local.info_str);<o:p></o:p></p>
        <p class="MsoPlainText">    pjsip_msg_add_hdr(tdata->msg,
          (pjsip_hdr*)gs_hdr);<o:p></o:p></p>
        <p class="MsoPlainText"><o:p> </o:p></p>
        <p class="MsoPlainText"><o:p> </o:p></p>
        <p class="MsoPlainText">    /* Add additional headers etc */<o:p></o:p></p>
        <p class="MsoPlainText">    pjsua_process_msg_data( tdata,
          msg_data);<o:p></o:p></p>
        <p class="MsoPlainText"><o:p> </o:p></p>
        <p class="MsoPlainText">    /* Send. */<o:p></o:p></p>
        <p class="MsoPlainText">    status =
          pjsip_xfer_send_request(sub, tdata);<o:p></o:p></p>
        <p class="MsoPlainText">    if (status != PJ_SUCCESS) {<o:p></o:p></p>
        <p class="MsoPlainText">                pjsua_perror(THIS_FILE,
          "Unable to send REFER request", status);<o:p></o:p></p>
        <p class="MsoPlainText">                pjsip_dlg_dec_lock(dlg);<o:p></o:p></p>
        <p class="MsoPlainText">                return status;<o:p></o:p></p>
        <p class="MsoPlainText">    }<o:p></o:p></p>
        <p class="MsoPlainText"><o:p> </o:p></p>
        <p class="MsoPlainText">Could anyone provider some insight into
          how difficult this might be for me to add and submit for
          approval?  Depending on the answer, my manager may be willing
          to let me work on this.<o:p></o:p></p>
        <p class="MsoPlainText">I've developed in C/C++ for over 25
          years so I'm plenty familiar with the language.<o:p></o:p></p>
        <p class="MsoPlainText">I'm less familiar with the syntax and
          coding standards of Asterisk.  I know the group is very good
          at letting people know about their mistakes and how to fix
          them.<o:p></o:p></p>
        <p class="MsoPlainText"><o:p> </o:p></p>
        <p class="MsoPlainText">Have a great day!<o:p></o:p></p>
        <p class="MsoNormal">Dan<span
            style="font-size:9.0pt;color:#1F497D"> <o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:9.0pt;color:#1F497D"><o:p> </o:p></span></p>
        <div>
          <div style="border:none;border-top:solid #B5C4DF
            1.0pt;padding:3.0pt 0in 0in 0in">
            <p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">
                <a class="moz-txt-link-abbreviated" href="mailto:asterisk-dev-bounces@lists.digium.com">asterisk-dev-bounces@lists.digium.com</a>
                [<a class="moz-txt-link-freetext" href="mailto:asterisk-dev-bounces@lists.digium.com">mailto:asterisk-dev-bounces@lists.digium.com</a>] <b>On
                  Behalf Of </b>Dan Cropp<br>
                <b>Sent:</b> Tuesday, August 25, 2015 10:50 AM<br>
                <b>To:</b> Asterisk Developers Mailing List<br>
                <b>Subject:</b> Re: [asterisk-dev] Transfer cmd (PJSIP
                not sending Referred-By but chan_sip does)<o:p></o:p></span></p>
          </div>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><span style="color:#1F497D">Thank you Mark<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
        <div>
          <div style="border:none;border-top:solid #B5C4DF
            1.0pt;padding:3.0pt 0in 0in 0in">
            <p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">
                <a moz-do-not-send="true"
                  href="mailto:asterisk-dev-bounces@lists.digium.com">asterisk-dev-bounces@lists.digium.com</a>
                [<a moz-do-not-send="true"
                  href="mailto:asterisk-dev-bounces@lists.digium.com">mailto:asterisk-dev-bounces@lists.digium.com</a>]
                <b>On Behalf Of </b>Mark Michelson<br>
                <b>Sent:</b> Tuesday, August 25, 2015 10:30 AM<br>
                <b>To:</b> Asterisk Developers Mailing List<br>
                <b>Subject:</b> Re: [asterisk-dev] Transfer cmd (PJSIP
                not sending Referred-By but chan_sip does)<o:p></o:p></span></p>
          </div>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <div>
          <p class="MsoNormal">The answer to this is actually pretty
            simple: adding Referred-By in outgoing SIP REFERs is simply
            not implemented in chan_pjsip's chan_pjsip_transfer()
            function.<br>
            <br>
            As far as the syntax required for the Transfer()
            application, that's probably a case where that needs to be
            clarified in documentation. There are lots of places in
            PJSIP configuration where we require full SIP URIs rather
            than just IP addresses or bare URIs (user@domain).<br>
            <br>
            On 08/25/2015 10:00 AM, Dan Cropp wrote:<o:p></o:p></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <p class="MsoNormal">I asked the question on asterisk–users
            but did not receive a response, so I am sending the question
            here.<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">I am running Asterisk 13.5.0.<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">A call comes in, Asterisk answers it. 
            After some actions, the call needs to be Transferred (SIP
            REFER) to another number.  The other switch is responsible
            for accepting the Transfer and tromboning the lines
            internally.  It will also send a BYE so Asterisk no longer
            has the call.<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">The behavior works when I have the
            endpoint configured at chan_sip.  It does not work when the
            endpoint is configured as PJSIP.  I worked with the other
            switch vendor and he determined chan_sip includes the
            Referred-By header.  PJSIP does not include the Referred-By
            header.  The other switch requires the Referred-By header to
            be present.<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">I tried setting the channel’s
            SIPREFERREDBYHDR variable before the Transfer command and
            that still did not force the Referred-By header to be part
            of the REFER packet.<o:p></o:p></p>
          <p class="MsoNormal">I tried the PJSIP_HEADER add and it still
            did not add the Referred-By header to the REFER packet.<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">Is there a PJSIP setting to force the
            Referred-By to be part of the REFER packet?<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">chan_sip (succeeds)<o:p></o:p></p>
          <p class="MsoNormal">19:27:32.512123 IP (tos 0x0, ttl 64, id
            11492, offset 0, flags [none], proto UDP (17), length 630)<o:p></o:p></p>
          <p class="MsoNormal">    192.168.xxx.xxx.sip >
            192.168.yyy.yyy.sip: SIP, length: 602<o:p></o:p></p>
          <p class="MsoNormal">        REFER <a moz-do-not-send="true"
              href="sip:3400@192.168.yyy.yyy:5060">sip:3400@192.168.yyy.yyy:5060</a>
            SIP/2.0<o:p></o:p></p>
          <p class="MsoNormal">        Via: SIP/2.0/UDP
            192.168.xxx.xxx:5060;branch=z9hG4bK58f4bd1d<o:p></o:p></p>
          <p class="MsoNormal">        Max-Forwards: 70<o:p></o:p></p>
          <p class="MsoNormal">        From: <<a
              moz-do-not-send="true" href="sip:3344@192.168.xxx.xxx">sip:3344@192.168.xxx.xxx</a>>;tag=as44000cf4<o:p></o:p></p>
          <p class="MsoNormal">        To: <<a moz-do-not-send="true"
              href="sip:3400@192.168.yyy.yyy">sip:3400@192.168.yyy.yyy</a>>;tag=7Iy0JkwDC<o:p></o:p></p>
          <p class="MsoNormal">        Contact: <<a
              moz-do-not-send="true"
              href="sip:3344@192.168.xxx.xxx:5060">sip:3344@192.168.xxx.xxx:5060</a>><o:p></o:p></p>
          <p class="MsoNormal">        Call-ID: <a
              moz-do-not-send="true"
              href="mailto:jdEuqpAK-0002-@192.168.yyy.yyy">jdEuqpAK-0002-@192.168.yyy.yyy</a><o:p></o:p></p>
          <p class="MsoNormal">        CSeq: 102 REFER<o:p></o:p></p>
          <p class="MsoNormal">        User-Agent: Asterisk PBX 13.5.0<o:p></o:p></p>
          <p class="MsoNormal">        Date: Thu, 20 Aug 2015 19:27:32
            GMT<o:p></o:p></p>
          <p class="MsoNormal">        Refer-To: <<a
              moz-do-not-send="true" href="sip:370@192.168.yyy.yyy">sip:370@192.168.yyy.yyy</a>><o:p></o:p></p>
          <p class="MsoNormal">        Referred-By: <<a
              moz-do-not-send="true"
              href="sip:3344@192.168.xxx.xxx:5060">sip:3344@192.168.xxx.xxx:5060</a>><o:p></o:p></p>
          <p class="MsoNormal">        Allow: INVITE, ACK, CANCEL,
            OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH,
            MESSAGE<o:p></o:p></p>
          <p class="MsoNormal">        Supported: replaces, timer<o:p></o:p></p>
          <p class="MsoNormal">        Content-Length: 0<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">Pjsip<o:p></o:p></p>
          <p class="MsoNormal">18:46:58.386372 IP (tos 0x0, ttl 64, id
            38690, offset 0, flags [DF], proto UDP (17), length 654)<o:p></o:p></p>
          <p class="MsoNormal">    192.168.xxx.xxx.sip >
            192.168.yyy.yyy.sip: SIP, length: 626<o:p></o:p></p>
          <p class="MsoNormal">        REFER <a moz-do-not-send="true"
              href="sip:3400@192.168.yyy.yyy:5060">sip:3400@192.168.yyy.yyy:5060</a>
            SIP/2.0<o:p></o:p></p>
          <p class="MsoNormal">        Via: SIP/2.0/UDP
192.168.xxx.xxx:5060;rport;branch=z9hG4bKPjec41c3b9-d734-482d-82c1-2a6f8d9452a3<o:p></o:p></p>
          <p class="MsoNormal">        From: <<a
              moz-do-not-send="true" href="sip:3344@192.168.xxx.xxx">sip:3344@192.168.xxx.xxx</a>>;tag=3c10f423-e468-42ea-87a1-658ae106581c<o:p></o:p></p>
          <p class="MsoNormal">        To: <<a moz-do-not-send="true"
              href="sip:3400@192.168.yyy.yyy">sip:3400@192.168.yyy.yyy</a>>;tag=WITKDakt<o:p></o:p></p>
          <p class="MsoNormal">        Contact: <<a
              moz-do-not-send="true" href="sip:192.168.xxx.xxx:5060">sip:192.168.xxx.xxx:5060</a>><o:p></o:p></p>
          <p class="MsoNormal">        Call-ID: <a
              moz-do-not-send="true"
              href="mailto:s6Wk6l6Q-0001-@192.168.yyy.yyy">s6Wk6l6Q-0001-@192.168.yyy.yyy</a><o:p></o:p></p>
          <p class="MsoNormal">        CSeq: 981 REFER<o:p></o:p></p>
          <p class="MsoNormal">        Event: refer<o:p></o:p></p>
          <p class="MsoNormal">        Expires: 600<o:p></o:p></p>
          <p class="MsoNormal">        Supported: 100rel, timer,
            replaces, norefersub<o:p></o:p></p>
          <p class="MsoNormal">        Accept:
            message/sipfrag;version=2.0<o:p></o:p></p>
          <p class="MsoNormal">        Allow-Events: message-summary,
            presence, dialog, refer<o:p></o:p></p>
          <p class="MsoNormal">        Refer-To: <<a
              moz-do-not-send="true" href="sip:370@192.168.yyy.yyy">sip:370@192.168.yyy.yyy</a>><o:p></o:p></p>
          <p class="MsoNormal">        Max-Forwards: 70<o:p></o:p></p>
          <p class="MsoNormal">        User-Agent: Asterisk PBX 13.5.0<o:p></o:p></p>
          <p class="MsoNormal">        Content-Length:  0<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">One other slight oddity.<o:p></o:p></p>
          <p class="MsoNormal">To get chan_sip to Transfer<o:p></o:p></p>
          <p class="MsoNormal"><span style="color:#1F497D"><a
                moz-do-not-send="true" href="mailto:370@192.168.yyy.yyy">370@192.168.yyy.yyy</a></span><o:p></o:p></p>
          <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span style="color:#1F497D">To get PJSIP
              to Transfer with the correct Refer-To header, I had to
              include the <> and sip:</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="color:#4F81BD"><<u><a
                  moz-do-not-send="true" href="sip:370@192.168.yyy.">sip:370@192.168.yyy.</a></u></span><u><span
                style="color:#1F497D">yyy</span></u><span
              style="color:#4F81BD">></span><o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">Have a great day!<o:p></o:p></p>
          <p class="MsoNormal">Dan<o:p></o:p></p>
          <p class="MsoNormal" style="margin-bottom:12.0pt"><span
              style="font-size:12.0pt;font-family:"Times New
              Roman","serif""><o:p> </o:p></span></p>
        </blockquote>
        <p class="MsoNormal"><span
            style="font-size:12.0pt;font-family:"Times New
            Roman","serif""><o:p> </o:p></span></p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
    </blockquote>
    <br>
  </body>
</html>