* gets the part of the uri we will use as a key for hashing * params: key1 - will be filled with first part of the key * (uri user or "" if no user) * key2 - will be filled with the second part of the key * (uri host:port) * uri - str with the whole uri * parsed_uri - struct sip_uri pointer with the pa
| 1339 | * returns: -1 on error, 0 on success |
| 1340 | */ |
| 1341 | static inline int get_uri_hash_keys(str* key1, str* key2, |
| 1342 | str* uri, struct sip_uri* parsed_uri, int flags) |
| 1343 | { |
| 1344 | struct sip_uri tmp_p_uri; /* used only if parsed_uri==0 */ |
| 1345 | unsigned short proto; |
| 1346 | |
| 1347 | if (parsed_uri==0) |
| 1348 | { |
| 1349 | if (parse_uri(uri->s, uri->len, &tmp_p_uri)<0) |
| 1350 | { |
| 1351 | LM_ERR("invalid uri %.*s\n", uri->len, uri->len?uri->s:""); |
| 1352 | goto error; |
| 1353 | } |
| 1354 | parsed_uri=&tmp_p_uri; |
| 1355 | } |
| 1356 | /* uri sanity checks */ |
| 1357 | if (parsed_uri->host.s==0) |
| 1358 | { |
| 1359 | LM_ERR("invalid uri, no host present: %.*s\n", |
| 1360 | uri->len, uri->len?uri->s:""); |
| 1361 | goto error; |
| 1362 | } |
| 1363 | |
| 1364 | /* we want: user@host:port if port is not the defaut one |
| 1365 | * user@host if port is the default one |
| 1366 | * user if the user flag is set*/ |
| 1367 | *key1=parsed_uri->user; |
| 1368 | key2->s=0; |
| 1369 | key2->len=0; |
| 1370 | if (!(flags & DS_HASH_USER_ONLY)) |
| 1371 | { /* key2=host */ |
| 1372 | *key2=parsed_uri->host; |
| 1373 | /* add port if needed */ |
| 1374 | if (parsed_uri->port.s!=0) |
| 1375 | { /* uri has a port */ |
| 1376 | /* skip port if the default one ( first extract proto from URI) */ |
| 1377 | if ( get_uri_port(parsed_uri, &proto) && |
| 1378 | parsed_uri->port_no != protos[proto].default_port ) |
| 1379 | key2->len+=parsed_uri->port.len+1 /* ':' */; |
| 1380 | } |
| 1381 | } |
| 1382 | if (key1->s==0) |
| 1383 | { |
| 1384 | LM_WARN("empty username in: %.*s\n", uri->len, uri->len?uri->s:""); |
| 1385 | } |
| 1386 | return 0; |
| 1387 | error: |
| 1388 | return -1; |
| 1389 | } |
| 1390 | |
| 1391 | |
| 1392 |
no test coverage detected