pjsip / pjproject

PJSIP project
http://www.pjsip.org
GNU General Public License v2.0
2.02k stars 770 forks source link

Allow Call-Id to be set manually #3994

Closed austinkottke closed 3 months ago

austinkottke commented 3 months ago

Describe the feature

Allow Call-ID to be set via developers instead of letting pjsip dynamically generate the id. This is very important if call-ids are generated on the server side during a call setup.

Describe alternatives you've considered

No response

Additional context

No response

sauwming commented 3 months ago

Not sure what you are trying to implement here, but it seems that you should be using PJSIP API directly, instead of the higher-level PJSUA API. That way, you can have access to the Call-ID header and content.

austinkottke commented 3 months ago

Well, I need to be able to set the Call-ID with the outgoing invite. I do not want pjsip to set the call-id with a random generated string -- I would like to provide the Call-ID for pjsip to use on the invite -- the Call-ID is generated and synchronized across a back-end cluster BEFORE executing the sip call. Once the back-end verifies that Call-ID is ok to use the invite goes out using that Call-ID in the invite.

austinkottke commented 3 months ago

SIP.js supports this - Im trying to prevent hacking the pjsip c api on every release to allow a custom call-id.

austinkottke commented 3 months ago
/*
 * Create an UAC dialog.
 */
PJ_DEF(pj_status_t) custom_pjsip_dlg_create_uac( pjsip_user_agent *ua,
                      const pj_str_t *local_uri,
                      const pj_str_t *local_contact,
                      const pj_str_t *remote_uri,
                      const pj_str_t *target,
                      pjsip_dialog **p_dlg, const cm_sip_call_options *options )
{
    pjsip_dlg_create_uac_param create_param;

    PJ_ASSERT_RETURN(ua && local_uri && remote_uri && p_dlg, PJ_EINVAL);

    pj_bzero(&create_param, sizeof(create_param));
    create_param.ua = ua;
    create_param.local_uri = *local_uri;
    create_param.remote_uri = *remote_uri;
    if (local_contact)
    create_param.local_contact = *local_contact;

    if (target)
    create_param.target = *target;

    pj_status_t status = pjsip_dlg_create_uac2(&create_param, p_dlg);

    pjsip_dialog *dlg = *p_dlg;

    if( options->sipCallId != NULL ){
        PJ_LOG(4,(THIS_FILE, "Attempting to manually set Call-ID"));
        **pj_strcpy(&dlg->call_id->id, options->sipCallId->ptr);**
        PJ_LOG(4,(THIS_FILE, "Creating call with Call-Id [%s] ", dlg->call_id->id));
    }

    return status;

}

This allows me to now use the highlevel cpp api pjsua2 to set the call-id - however, I patch it on every release.