Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PJSIP Custom Registration Header

I am attempting to setup SIP communication with an internal server (using the PJSIP library), however, this server requires a custom header field with a specified header value for the REGISTRATION call. For example's sake we'll call this required header MyHeader.

From what I have found, the pjsua_acc_add() function will add an account and register it to the server using a config struct.

The parameter reg_hdr_list of the config struct has the description:

The optional custom SIP headers to be put in the registration request.

Which sounds like exactly what I need, however doesn't seem to have any effect on the call itself.

Here's what I have so far:

    pjsua_acc_config cfg;
    pjsua_acc_config_default(&cfg);

    //...Some other config stuff related to the server...

    pjsip_hdr test;
    test.name = pj_str("MyHeader");
    test.sname = pj_str("MyHdr");
    test.type = PJSIP_H_OTHER;
    test.prev = cfg.reg_hdr_list.prev;
    test.next = cfg.reg_hdr_list.next;
    cfg.reg_hdr_list = test;

    pj_status_t status;
    status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);

From the server side, there are no extra header fields or anything. And the struct that is used to define the header (pjsua_hdr) has no value or equivalent field, so even if it did create the header, how does it set the value?

Here is the refrence for the header list definition and the reference for the header struct.

Edit: I found the solution thanks to a co-worker:

    struct pjsip_generic_string_hdr CustomHeader;
    pj_str_t name = pj_str("MyHeader");
    pj_str_t value = pj_str("HeaderValue");
    pjsip_generic_string_hdr_init2(&CustomHeader, &name, &value);

    pj_list_push_back(&cfg.reg_hdr_list, &CustomHeader);

This seems to work as expected.

like image 908
Daniel Redington Avatar asked Nov 11 '11 17:11

Daniel Redington


1 Answers

Just quoting the OP as he found the solution, but forgot to add it as an answer:

Edit: I found the solution thanks to a co-worker:

struct pjsip_generic_string_hdr CustomHeader;
pj_str_t name = pj_str("MyHeader");
pj_str_t value = pj_str("HeaderValue");
pjsip_generic_string_hdr_init2(&CustomHeader, &name, &value);

pj_list_push_back(&cfg.reg_hdr_list, &CustomHeader);

This seems to work as expected.

like image 167
Islam Avatar answered Nov 10 '22 19:11

Islam