Skip to content

Commit

Permalink
Store URI's original user and password
Browse files Browse the repository at this point in the history
  • Loading branch information
sauwming committed Aug 20, 2024
1 parent 7589f06 commit 7d36884
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pjsip/include/pjsip/sip_uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ PJ_INLINE(void*) pjsip_uri_clone( pj_pool_t *pool, const void *uri )
typedef struct pjsip_sip_uri
{
pjsip_uri_vptr *vptr; /**< Pointer to virtual function table.*/
pj_str_t original; /**< Optional pointer to original user and password. */
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
15 changes: 7 additions & 8 deletions pjsip/src/pjsip/sip_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,8 +1508,6 @@ static void* int_parse_sip_url( pj_scanner *scanner,
int colon;
int skip_ws = scanner->skip_ws;
scanner->skip_ws = 0;
char *start, *end;
pj_str_t orig;

pj_scan_get(scanner, &pconst.pjsip_TOKEN_SPEC, &scheme);
colon = pj_scan_get_char(scanner);
Expand All @@ -1532,15 +1530,16 @@ static void* int_parse_sip_url( pj_scanner *scanner,
})
}

start = scanner->curptr;

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);
}

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

/* Get host:port */
int_parse_uri_host_port(scanner, &url->host, &url->port);
Expand Down
26 changes: 13 additions & 13 deletions pjsip/src/pjsip/sip_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,24 @@ static pj_ssize_t pjsip_url_print( pjsip_uri_context_e context,
copy_advance_check(buf, *scheme);
copy_advance_char_check(buf, ':');

if (url->original.slen) {
copy_advance_check(buf, url->original);
} else {

/* 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, '@');
}
}

/* Print host. */
pj_assert(url->host.slen != 0);
Expand Down Expand Up @@ -511,9 +511,9 @@ static pj_status_t pjsip_url_compare( pjsip_uri_context_e context,
PJ_DEF(void) pjsip_sip_uri_assign(pj_pool_t *pool, pjsip_sip_uri *url,
const pjsip_sip_uri *rhs)
{
pj_strdup( pool, &url->original, &rhs->original);
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
4 changes: 1 addition & 3 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 Expand Up @@ -908,8 +909,6 @@ static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry)
pj_add_timestamp(&var.cmp_time, &t2);

/* Compare text. */
/* Printing results may differ, but the comparison above must match. */
#if 0
if (entry->printed) {
if (pj_strcmp2(&s1, entry->printed) != 0) {
/* Not equal. */
Expand All @@ -929,7 +928,6 @@ static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry)
status = -70;
}
}
#endif

on_return:
return status;
Expand Down

0 comments on commit 7d36884

Please sign in to comment.