| 451 | |
| 452 | |
| 453 | static inline int build_user_AOR(str *username, str *domain, str *uh, int sip) |
| 454 | { |
| 455 | unsigned char do_strip; |
| 456 | char *p; |
| 457 | int i; |
| 458 | |
| 459 | /* calculate the len (without terminating \0) */ |
| 460 | uh->len = 4*(sip!=0) + username->len; |
| 461 | do_strip = 0; |
| 462 | |
| 463 | if (sip || cpl_env.use_domain) { |
| 464 | /* do we need to strip realm prefix? */ |
| 465 | if (cpl_env.realm_prefix.len && cpl_env.realm_prefix.len<domain->len){ |
| 466 | for( i=cpl_env.realm_prefix.len-1 ; i>=0 ; i-- ) |
| 467 | if ( cpl_env.realm_prefix.s[i]!=tolower(domain->s[i]) ) |
| 468 | break; |
| 469 | if (i==-1) |
| 470 | do_strip = 1; |
| 471 | } |
| 472 | uh->len += 1 + domain->len - do_strip*cpl_env.realm_prefix.len; |
| 473 | } |
| 474 | |
| 475 | uh->s = (char*)shm_malloc( uh->len + 1 ); |
| 476 | if (!uh->s) { |
| 477 | LM_ERR("no more shm memory.\n"); |
| 478 | return -1; |
| 479 | } |
| 480 | |
| 481 | /* build user@host */ |
| 482 | p = uh->s; |
| 483 | if (sip) { |
| 484 | memcpy( uh->s, "sip:", 4); |
| 485 | p += 4; |
| 486 | } |
| 487 | /* user part */ |
| 488 | if (cpl_env.case_sensitive) { |
| 489 | memcpy( p, username->s, username->len); |
| 490 | p += username->len; |
| 491 | } else { |
| 492 | for(i=0;i<username->len;i++) |
| 493 | *(p++) = tolower(username->s[i]); |
| 494 | } |
| 495 | if (sip || cpl_env.use_domain) { |
| 496 | *(p++) = '@'; |
| 497 | /* host part in lower cases */ |
| 498 | for( i=do_strip*cpl_env.realm_prefix.len ; i< domain->len ; i++ ) |
| 499 | *(p++) = tolower(domain->s[i]); |
| 500 | } |
| 501 | *(p++) = 0; |
| 502 | |
| 503 | /* sanity check */ |
| 504 | if (p-uh->s!=uh->len+1) { |
| 505 | LM_CRIT("buffer overflow l=%d,w=%ld\n", uh->len,(long)(p-uh->s)); |
| 506 | return -1; |
| 507 | } |
| 508 | return 0; |
| 509 | } |
| 510 |
no test coverage detected