简体   繁体   中英

How to remove sip-id after contacturi in contactheader in pjsip when using TLS

I am able successfully register to my sip server using pjsip.
But when sending register from pjsip using tls transport, there happens to be extra string attached to the contact header.

Contact: <sip:8888@192.168.1.14:57336;transport=TLS;ob>;reg-id=1;+sip.instance="<urn:uuid:00000000-0000-0000-0000-0000e922f243>"

Can somebody tell how to remove it from contact header??

This is my code.

    String sipURI = "sip:";
    String addTransport = "";
    if(enableTLS)
         addTransport = ";hide;transport=tls";
    String sipid = sipURI + username + "@" + switch_ip + ":" + switch_port;
    String registrar = sipURI + switch_ip + ":" + switch_port;
    String proxy = sipURI + switch_ip + ":" + switch_port+addTransport;

    AccountConfig accCfg = new AccountConfig();
    accCfg.setIdUri(sipid);

     AuthCredInfoVector creds = accCfg.getSipConfig().getAuthCreds();
    creds.clear();
    if (username.length() != 0) {
        creds.add(new AuthCredInfo("Digest", "*", username, 0, password));
    }
    StringVector proxies = accCfg.getSipConfig().getProxies();
    proxies.clear();

    if (proxy.length() != 0) {
        proxies.add(proxy);
    }
    accCfg.getRegConfig().setRegistrarUri(registrar);
    accCfg.getRegConfig().setRetryIntervalSec(60);
    accCfg.getRegConfig().setTimeoutSec(60);
    accCfg.getNatConfig().setIceEnabled(false);
 accCfg.getCallConfig().setTimerUse(pjsua_sip_timer_use.PJSUA_SIP_TIMER_INACTIVE);         accCfg.getCallConfig().setPrackUse(pjsua_100rel_use.PJSUA_100REL_NOT_USED);    
   app.addAcc(accCfg);

First of all you have to set the port in TransportConfig with setPort(switch_port) . There is no need to set id of uri with port or to create registrar string with port or to write proxy with port. This is enough, see code below.

TransportConfig sipTpConfig = new TransportConfig();
sipTpConfig.setPort(switch_port); 
...

String sipid = sipURI + username + "@" + switch_ip;
String registrar = sipURI + switch_ip;
String proxy = sipURI + switch_ip + addTransport;
...

accCfg.getRegConfig().setRegistrarUri("sip:" + SIP_DOMAIN);
accCfg.getSipConfig().getProxies().add("sip:" + SIP_SERVER_HOST + ";hide");

Once again, set your port when you are setting up transport configuration. Another thing is if you have SRV-record configured on server side, let pjsip automatically detect available port. I mean, don't hard code port in register signal and don't set the port manually at all. Use this code instead to present correct contact header.

accCfg.getNatConfig().setContactRewriteUse(0);
accCfg.getNatConfig().setContactRewriteMethod(0);
accCfg.getNatConfig().setContactUseSrcPort(0);
accCfg.getNatConfig().setViaRewriteUse(0);

The SIP_DOMAIN is your domain, switch_ip , everything before "@" and SIP_SERVER_HOST is your outbound proxy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM