Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save the original user and password part when parsing URI #4043

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pjsip/include/pjsip/sip_uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ typedef struct pjsip_sip_uri
pjsip_uri_vptr *vptr; /**< Pointer to virtual function table.*/
pj_str_t user; /**< Optional user part. */
pj_str_t passwd; /**< Optional password part. */
pj_str_t orig_userpass; /**< Optional original user&pass. */
pj_str_t host; /**< Host part, always exists. */
int port; /**< Optional port number, or zero. */
pj_str_t user_param; /**< Optional user parameter */
Expand Down
7 changes: 7 additions & 0 deletions pjsip/src/pjsip/sip_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,14 @@ static void* int_parse_sip_url( pj_scanner *scanner,
}

if (int_is_next_user(scanner)) {
char *start = scanner->curptr;
pj_str_t orig;

start = scanner->curptr;
int_parse_user_pass(scanner, pool, &url->user, &url->passwd);

pj_strset3(&orig, start, scanner->curptr - 1);
pj_strdup(pool, &url->orig_userpass, &orig);
}

/* Get host:port */
Expand Down
20 changes: 13 additions & 7 deletions pjsip/src/pjsip/sip_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,18 @@ static pj_ssize_t pjsip_url_print( pjsip_uri_context_e context,

/* Print "user:password@", if any. */
if (url->user.slen) {
const pj_cis_t *spec = pjsip_cfg()->endpt.allow_tx_hash_in_uri ?
&pc->pjsip_USER_SPEC_LENIENT :
&pc->pjsip_USER_SPEC;
copy_advance_escape(buf, url->user, *spec);
if (url->passwd.slen) {
copy_advance_char_check(buf, ':');
copy_advance_escape(buf, url->passwd, pc->pjsip_PASSWD_SPEC);
/* Use the URI's original username and password, if any. */
if (url->orig_userpass.slen) {
copy_advance_check(buf, url->orig_userpass);
} else {
const pj_cis_t *spec = pjsip_cfg()->endpt.allow_tx_hash_in_uri ?
&pc->pjsip_USER_SPEC_LENIENT :
&pc->pjsip_USER_SPEC;
copy_advance_escape(buf, url->user, *spec);
if (url->passwd.slen) {
copy_advance_char_check(buf, ':');
copy_advance_escape(buf, url->passwd, pc->pjsip_PASSWD_SPEC);
}
}

copy_advance_char_check(buf, '@');
Expand Down Expand Up @@ -508,6 +513,7 @@ PJ_DEF(void) pjsip_sip_uri_assign(pj_pool_t *pool, pjsip_sip_uri *url,
{
pj_strdup( pool, &url->user, &rhs->user);
pj_strdup( pool, &url->passwd, &rhs->passwd);
pj_strdup( pool, &url->orig_userpass, &rhs->orig_userpass);
pj_strdup( pool, &url->host, &rhs->host);
url->port = rhs->port;
pj_strdup( pool, &url->user_param, &rhs->user_param);
Expand Down
1 change: 1 addition & 0 deletions pjsip/src/test/uri_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ static pjsip_uri *create_uri14(pj_pool_t *pool)
pj_strdup2(pool, &name_addr->display, "This is -. !% *_+`'~ me");
pj_strdup2(pool, &url->user, "a19A&=+$,;?/,");
pj_strdup2(pool, &url->passwd, "@a&Zz=+$,");
pj_strdup2(pool, &url->orig_userpass, "a19A&=+$,;?/%2c:%40a&Zz=+$,");
pj_strdup2(pool, &url->host, "my_proxy09.MY-domain.com");
url->port = 9801;
return (pjsip_uri*)name_addr;
Expand Down
Loading