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

Decode url in custom header #2816

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

nltd101
Copy link
Contributor

@nltd101 nltd101 commented Nov 24, 2023

Problem:
utilize /uaaddheader to add a custom header
usage: /uaaddheader =
So that it is impossible to custom header containing space (' ').
My solution:
implement decode URL format before pushing to custom headers

modules/menu/static_menu.c Outdated Show resolved Hide resolved
modules/menu/static_menu.c Outdated Show resolved Hide resolved
@alfredh
Copy link
Collaborator

alfredh commented Nov 26, 2023

thanks

please take a look at the failing CI jobs.

@nltd101 nltd101 force-pushed the datnlt/decode_url_custom_header branch 5 times, most recently from d70765e to e5edd25 Compare November 27, 2023 08:40
modules/menu/menu.c Outdated Show resolved Hide resolved
@nltd101 nltd101 force-pushed the datnlt/decode_url_custom_header branch from e5edd25 to 9c32b91 Compare November 27, 2023 08:46
char a, b;
while (*src && src < w->p+len) {
if ((*src == '%') &&
((a = src[1]) && (b = src[2])) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src[1]) and src[2] can be out of bound here if url is malformed, right? a struct pl is not necessary null terminated. so pl length has to be checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it. Thanks for correcting me.

@nltd101 nltd101 force-pushed the datnlt/decode_url_custom_header branch from 9c32b91 to 3c01658 Compare November 27, 2023 08:59
@alfredh
Copy link
Collaborator

alfredh commented Nov 29, 2023

Is it an option to use this function for decode and/or escaping/un-escaping:

https://github.com/baresip/re/blob/main/include/re_uri.h#L37

*
* @param w Pl correspond the string is in URL format will be decoded
*/
void url_decode(struct pl* w)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the function is global for the menu module, it should have a menu_ prefix.
you can also move it to the file where it is used, and make it static.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have tried. I will use escaping/un-escaping in re_uri.h as your suggestion above.

@alfredh
Copy link
Collaborator

alfredh commented Dec 2, 2023

can you please clarify what is that function doing ? is it URL encode or decode ?

can you add some sample URLs to the documentation ?

@nltd101 nltd101 force-pushed the datnlt/decode_url_custom_header branch from 3c01658 to 60653be Compare December 5, 2023 09:07
struct mbuf mbe;
err = mbuf_printf(&mbe, "%H", uri_header_unescape, &v);
if (err == 0) {
v.p = (const char *)mbe.buf;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • mbe has to be initialized
  • mbuf_printf allocates memory in mbe.buf and has to be derefed after ua_add_custom_hdr
  • instead of err please use ret here

@alfredh alfredh merged commit 46b87a0 into baresip:main Dec 6, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants