| 1200 | } |
| 1201 | |
| 1202 | int 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) { |
no test coverage detected