PJSIP Add

Home » Asterisk Users » PJSIP Add
Asterisk Users 4 Comments

I am trying to set add a SIP Header to a call before adding it to the Queue.

The dial plan sends the call to my macro to perform the work. When I use chan_sip, everything works as expected. When I use PSJIP support, it’s not adding the SIP header. Looking at the output, I see the macro is called in both cases. In the PJSIP case, the added sip header never is showing up in the asterisk logs (verbose 999). In the SIP case, I see it.

Does the function Set(PJSIP_HEADER(add, ….. not transfer over to the call when the Queue function is called?
Am I calling the Set(PJSIP_Header(add portion incorrectly? Or is this a problem with the Asterisk PJSIP support?

chan_sip…
[macro-MY-SetDNID]
exten => s,1,Verbose(X-MY-DNID:${MY_DNID})
exten => s,1,SIPAddHeader(X-MY-DNID:${MY_DNID})
same => n,Queue(${ARG2})

pjsip….
[macro-MY-SetDNID]
exten => s,1,Verbose(X-MY-DNID:${MY_DNID})
same => n,Set(PJSIP_HEADER(add,X-MY-DNID)=${MY_DNID})
same => n,Queue(${ARG2})

Have a great day!
Dan

4 thoughts on - PJSIP Add

  • Dan Cropp wrote:

    PJSIP_HEADER works on the channel it is invoked on. SIPAddHeader does things differently and uses channel variables underneath which can be inherited. What is the exact call flow and where do you expect the headers to appear?

  • In doing a little research, it seems the Referred-By header could be added after the pjsip_xfer_initiate. This is the approach PJSIP did for some code as far back as PJSIP 1.6.

    /*
    * Create REFER request.
    */
    status = pjsip_xfer_initiate(sub, dest, &tdata);
    if (status != PJ_SUCCESS) {
    pjsua_perror(THIS_FILE, “Unable to create REFER request”, status);
    pjsip_dlg_dec_lock(dlg);
    return status;
    }

    /* Add Referred-By header */
    gs_hdr = pjsip_generic_string_hdr_create(tdata->pool, &str_ref_by,
    &dlg->local.info_str);
    pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)gs_hdr);

    /* Add additional headers etc */
    pjsua_process_msg_data( tdata, msg_data);

    /* Send. */
    status = pjsip_xfer_send_request(sub, tdata);
    if (status != PJ_SUCCESS) {
    pjsua_perror(THIS_FILE, “Unable to send REFER request”, status);
    pjsip_dlg_dec_lock(dlg);
    return status;
    }

    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. I’ve developed in C/C++ for over 25 years so I’m plenty familiar with the language. 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.

    Have a great day!
    Dan

    —–Original Message—

  • Thank you for responding Joshua.

    My goal is to send a custom header in the INVITE packet. A developer wrote a macro using Asterisk and the SIPAddHeader many years ago. He has custom software that looks for this custom header field to know what number the original call came into Asterisk on. After the SIPAddHeader, a Queue is called.

    The basic call flow is the call comes in, It copies the EXTEN to a DNID variable exten => _X.,n,Set(__MY_DNID=${EXTEN})

    It is sent to AsyncAGI. exten => _X.,n,AGI(agi:async)

    Using AMI, we control the call from there. From AMI, we Answer the call. For testing the very next thing I do is

    Action: AGI
    ActionID: C15
    Channel: PJSIP/3400-00000000
    CommandID: C15
    Command: EXEC Macro My-SetDNID,${MY_DNID},TestApp

    [macro-My-SetDNID]
    exten => s,1,Verbose(X-My-DNID:${MY_DNID})
    ; SIP version (which works)
    same => n,SIPAddHeader(X-My-DNID:${MY_DNID})
    ; PJSIP version code
    ; same => n,Set(PJSIP_HEADER(add,X-My-DNID)=${MY_DNID})
    same => n,Queue(${ARG2})

    When using chan_sip, I’m seeing the following INVITE sent to the Agent in the queue…
    18:48:01.650180 IP (tos 0x0, ttl 64, id 44633, offset 0, flags [none], proto UDP (17), length 950)
    192.168.xxx.xxx.sip > 192.168.yyy.yyy.5063: SIP, length: 922
    INVITE sip:TestApp_EmergencyAgent1@192.168.yyy.yyy:5063 SIP/2.0
    Via: SIP/2.0/UDP 192.168.xxx.xxx:5060;branch=z9hG4bK77caff71
    Max-Forwards: 70
    From: ;tag=as13bb4901
    To:
    Contact:
    Call-ID: 32d64cd37cc3673661a5819818e6201f@192.168.xxx.xxx:5060
    CSeq: 102 INVITE
    User-Agent: Asterisk PBX 13.5.0
    Date: Tue, 25 Aug 2015 18:48:01 GMT
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
    Supported: replaces, timer
    X-My-DNID: 3344
    Content-Type: application/sdp
    Content-Length: 290

    v=0
    o=root 1563523699 1563523699 IN IP4 192.168.xxx.xxx
    s=Asterisk PBX 13.5.0
    c=IN IP4 192.168.xxx.xxx
    t=0 0
    m=audio 17706 RTP/AVP 0 8 3 101
    a=rtpmap:0 PCMU/8000
    a=rtpmap:8 PCMA/8000
    a=rtpmap:3 GSM/8000
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-16
    a=maxptime:150
    a=sendrecv

    When using PJSIP, the header X-My-DNID: 3344 is missing

    When using PJSIP, is it possible to have an additional header added into the INVITE when the Asterisk Queue method is called?

    Have a great day!
    Dan

    —–Original Message—