Re: PJSUA: Set From userpart when making a call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andreas,
IMHO, you should be able to "rewrite" any header by using the pjsip_module mod_default_handler.

E.g.:
/* The module instance. */
static pjsip_module mod_default_handler =
{
    NULL, NULL,        /* prev, next.    */
    { "mod-default-handler", 19 },  /* Name.    */
    -1,          /* Id      */
    PJSIP_MOD_PRIORITY_APPLICATION+99,  /* Priority          */
    NULL,        /* load()    */
    NULL,        /* start()    */
    NULL,        /* stop()    */
    NULL,        /* unload()    */
    NULL,                /* on_rx_request()  */
    NULL,        /* on_rx_response()  */
    &default_mod_on_tx_request, /* on_tx_request()  */
    NULL,           /* on_tx_response()  */
    NULL,        /* on_tsx_state()  */

};

So, for the purpose of rewriting the from header, you could save the header (temp)
rewrite it by changing the FROM header, then replace it in the linked list and at the end, insert it after the VIA Header.

E.g. my program adds the UA to any outgoing request (add User Agent)
static pj_status_t default_mod_on_tx_request(pjsip_tx_data *tdata){

    /* Add User-Agent header */
  pj_str_t user_agent;
  char tmp[80];
  const pj_str_t USER_AGENT = { "User-Agent", 10};
  pjsip_hdr *h;

  pj_ansi_snprintf(tmp, sizeof(tmp), "Dummy SUA v%s/%s",
  pj_get_version(), PJ_OS_NAME);
  pj_strdup2_with_null(tdata->pool, &user_agent, tmp);

  h = (pjsip_hdr*) pjsip_generic_string_hdr_create(tdata->pool,
               &USER_AGENT,
               &user_agent);
  pjsip_msg_add_hdr(tdata->msg, h);

    return PJ_SUCCESS;
}

Take a look at these functions:

https://www.pjsip.org/pjsip/docs/html/group__PJSIP__MSG__MSG.htm

Best regards
Franz

Citycom Telekommunikation GmbH
Gadollaplatz 1
8010 Graz | Austria

________________________________________
Von: pjsip <pjsip-bounces@xxxxxxxxxxxxxxx> im Auftrag von Andreas Wehrmann <a.wehrmann@xxxxxxxxxx>
Gesendet: Mittwoch, 27. November 2019 10:15
An: pjsip@xxxxxxxxxxxxxxx
Betreff:  PJSUA: Set From userpart when making a call

Hey there,

I was wondering whether there is a way to set the userpart of
the From header when making a call with PJSUA's pjsua_call_make_call().

Looking at the code, and assuming I'm not overlooking something, it
doesn't seem to be possible.
 From what I understand, the From header is constructed with what is
configured in the account that is used for the call.

My scenario is the following:
I'm writing a gateway to translate between VoIP and a digital radio network.
The gateway is to be registered with a PBX and is to forward calls from
the radio network
to the registrar by translating radio calls to SIP calls (and vice
versa: SIP->radio network).

Each participant of the radio network has their own ID (think: telephone
number)
and VoIP users must be able to call back radio users.
For this reason I'd like to set the radio user's number in the From
header header when calling the PBX,
so that they see not only who is calling but also to give them the
ability to call back.

My current approach is to patch PJSUA by introducing another member to
pjsua_call_setting
(probably not the right place, but would serve my purposes) that takes a
pj_str_t which contains the userpart to be put in the From header.
In the function itself, it would check whether the string is not empty
and take that string instead of what's configured with the account.


Best Regards,

Andreas Wehrmann


_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org



[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux