Upgrade Contact URIs on outgoing SIP requests to SIPS if required. 
The rules being used here are according to RFC 3261 section 8.1.1.8. In brief, if the request URI is SIPS or the topmost Route header is SIPS, then the Contact header we send must also be SIPS. 
   40{
   41    pjsip_contact_hdr *contact;
   42    pjsip_route_hdr *route;
   43    pjsip_sip_uri *contact_uri;
   44 
   45    contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, 
NULL);
 
   46    if (!contact) {
   47        return PJ_SUCCESS;
   48    }
   49 
   50    contact_uri = pjsip_uri_get_uri(contact->uri);
   51    if (PJSIP_URI_SCHEME_IS_SIPS(contact_uri)) {
   52        
   53        return PJ_SUCCESS;
   54    }
   55 
   56    if (PJSIP_URI_SCHEME_IS_SIPS(tdata->msg->line.req.uri)) {
   57        ast_debug(1, 
"Upgrading contact URI on outgoing SIP request to SIPS due to SIPS Request URI\n");
 
   58        pjsip_sip_uri_set_secure(contact_uri, PJ_TRUE);
   59        return PJ_SUCCESS;
   60    }
   61 
   62    route = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, 
NULL);
 
   63    if (!route) {
   64        return PJ_SUCCESS;
   65    }
   66 
   67    if (!PJSIP_URI_SCHEME_IS_SIPS(&route->name_addr)) {
   68        return PJ_SUCCESS;
   69    }
   70 
   71    
   72    ast_debug(1, 
"Upgrading contact URI on outgoing SIP request to SIPS due to SIPS Route header\n");
 
   73    pjsip_sip_uri_set_secure(contact_uri, PJ_TRUE);
   74 
   75    return PJ_SUCCESS;
   76}
#define ast_debug(level,...)
Log a DEBUG message.