- len=strlen("sip:"); if(crt+len>end) goto error_uri;
- memcpy(crt,"sip:",len);crt+=len;
+ /* Preserve the URI scheme unless the host part needs
+ * to be rewritten, and the shceme is tel: or tels: */
+ switch (uri.type) {
+ case SIP_URI_T:
+ len=s_sip.len;
+ tmp=s_sip.s;
+ break;
+
+ case SIPS_URI_T:
+ len=s_sips.len;
+ tmp=s_sips.s;
+ break;
+
+ case TEL_URI_T:
+ if ((uri.flags & URI_SIP_USER_PHONE)
+ || (a->type==SET_HOST_T)
+ || (a->type==SET_HOSTPORT_T)
+ || (a->type==SET_HOSTPORTTRANS_T)
+ ) {
+ len=s_sip.len;
+ tmp=s_sip.s;
+ break;
+ }
+ len=s_tel.len;
+ tmp=s_tel.s;
+ break;
+
+ case TELS_URI_T:
+ if ((uri.flags & URI_SIP_USER_PHONE)
+ || (a->type==SET_HOST_T)
+ || (a->type==SET_HOSTPORT_T)
+ || (a->type==SET_HOSTPORTTRANS_T)
+ ) {
+ len=s_sips.len;
+ tmp=s_sips.s;
+ break;
+ }
+ len=s_tels.len;
+ tmp=s_tels.s;
+ break;
+
+ default:
+ LOG(L_ERR, "ERROR: Unsupported URI scheme (%d), "
+ "reverted to sip:\n",
+ uri.type);
+ len=s_sip.len;
+ tmp=s_sip.s;
+ }
+ if(crt+len+1 /* colon */ >end) goto error_uri;
+ memcpy(crt,tmp,len);crt+=len;
+ *crt=':'; crt++;