MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / rewrite_ruri

Function rewrite_ruri

parser/msg_parser.c:1202–1359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1200}
1201
1202int rewrite_ruri(struct sip_msg *msg, str *sval, int ival,
1203 enum rw_ruri_part part)
1204{
1205 int user = 0;
1206 char *tmp, *new_uri, *end, *crt;
1207 int len;
1208 struct sip_uri uri;
1209
1210 if (msg->new_uri.s) {
1211 tmp=msg->new_uri.s;
1212 len=msg->new_uri.len;
1213 }else{
1214 tmp=msg->first_line.u.request.uri.s;
1215 len=msg->first_line.u.request.uri.len;
1216 }
1217 if (parse_uri(tmp, len, &uri)<0){
1218 LM_ERR("bad uri <%.*s>, dropping packet\n", len, tmp);
1219 return -1;
1220 }
1221
1222 new_uri=pkg_malloc(MAX_URI_SIZE);
1223 if (new_uri==0){
1224 LM_ERR("memory allocation failure\n");
1225 return -1;
1226 }
1227 end=new_uri+MAX_URI_SIZE;
1228 crt=new_uri;
1229 /* begin copying */
1230 len = (uri.user.len?uri.user.s:uri.host.s) - tmp;
1231 if (crt+len>end) goto error;
1232 memcpy(crt,tmp,len);crt+=len;
1233
1234 if (part==RW_RURI_PREFIX && sval->len) {
1235 if (crt+sval->len>end) goto error;
1236 memcpy( crt, sval->s, sval->len);
1237 crt+=sval->len;
1238 /* whatever we had before, with prefix we have username
1239 now */
1240 user=1;
1241 }
1242
1243 if ((part==RW_RURI_USER)||(part==RW_RURI_USERPASS)) {
1244 tmp=sval->s;
1245 len=sval->len;
1246 } else if (part==RW_RURI_STRIP) {
1247 if (ival>uri.user.len) {
1248 LM_WARN("too long strip asked; "
1249 " deleting username: %d of <%.*s>\n",
1250 ival, uri.user.len, uri.user.s);
1251 len=0;
1252 } else if (ival==uri.user.len) {
1253 len=0;
1254 } else {
1255 tmp=uri.user.s + ival;
1256 len=uri.user.len - ival;
1257 }
1258 } else if (part==RW_RURI_STRIP_TAIL) {
1259 if (ival>uri.user.len) {

Callers 15

w_sethostFunction · 0.85
w_sethostportFunction · 0.85
w_setuserFunction · 0.85
w_setuserpassFunction · 0.85
w_setportFunction · 0.85
w_prefixFunction · 0.85
w_stripFunction · 0.85
w_strip_tailFunction · 0.85
pv_set_ruri_userFunction · 0.85
pv_set_ruri_hostFunction · 0.85
pv_set_ruri_portFunction · 0.85
ds_update_dstFunction · 0.85

Calls 1

parse_uriFunction · 0.85

Tested by

no test coverage detected