Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
632dcfa4
Commit
632dcfa4
authored
5 years ago
by
Friendly Automation
Committed by
Gerrit Code Review
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge "res_ari.c: Prefer exact handler match over wildcard"
parents
64906c4c
8da4e28a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
res/res_ari.c
+18
-5
18 additions, 5 deletions
res/res_ari.c
with
18 additions
and
5 deletions
res/res_ari.c
+
18
−
5
View file @
632dcfa4
...
@@ -495,6 +495,7 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser,
...
@@ -495,6 +495,7 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser,
{
{
RAII_VAR
(
struct
stasis_rest_handlers
*
,
root
,
NULL
,
ao2_cleanup
);
RAII_VAR
(
struct
stasis_rest_handlers
*
,
root
,
NULL
,
ao2_cleanup
);
struct
stasis_rest_handlers
*
handler
;
struct
stasis_rest_handlers
*
handler
;
struct
stasis_rest_handlers
*
wildcard_handler
=
NULL
;
RAII_VAR
(
struct
ast_variable
*
,
path_vars
,
NULL
,
ast_variables_destroy
);
RAII_VAR
(
struct
ast_variable
*
,
path_vars
,
NULL
,
ast_variables_destroy
);
char
*
path
=
ast_strdupa
(
uri
);
char
*
path
=
ast_strdupa
(
uri
);
char
*
path_segment
;
char
*
path_segment
;
...
@@ -503,37 +504,49 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser,
...
@@ -503,37 +504,49 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser,
root
=
handler
=
get_root_handler
();
root
=
handler
=
get_root_handler
();
ast_assert
(
root
!=
NULL
);
ast_assert
(
root
!=
NULL
);
ast_debug
(
3
,
"Finding handler for %s
\n
"
,
path
);
while
((
path_segment
=
strsep
(
&
path
,
"/"
))
&&
(
strlen
(
path_segment
)
>
0
))
{
while
((
path_segment
=
strsep
(
&
path
,
"/"
))
&&
(
strlen
(
path_segment
)
>
0
))
{
struct
stasis_rest_handlers
*
found_handler
=
NULL
;
struct
stasis_rest_handlers
*
found_handler
=
NULL
;
int
i
;
int
i
;
ast_uri_decode
(
path_segment
,
ast_uri_http_legacy
);
ast_uri_decode
(
path_segment
,
ast_uri_http_legacy
);
ast_debug
(
3
,
"Finding handler for %s
\n
"
,
path_segment
);
ast_debug
(
3
,
"
Finding handler for %s
\n
"
,
path_segment
);
for
(
i
=
0
;
found_handler
==
NULL
&&
i
<
handler
->
num_children
;
++
i
)
{
for
(
i
=
0
;
found_handler
==
NULL
&&
i
<
handler
->
num_children
;
++
i
)
{
struct
stasis_rest_handlers
*
child
=
handler
->
children
[
i
];
struct
stasis_rest_handlers
*
child
=
handler
->
children
[
i
];
ast_debug
(
3
,
" Checking %s
\n
"
,
child
->
path_segment
);
if
(
child
->
is_wildcard
)
{
if
(
child
->
is_wildcard
)
{
/* Record the path variable */
/* Record the path variable */
struct
ast_variable
*
path_var
=
ast_variable_new
(
child
->
path_segment
,
path_segment
,
__FILE__
);
struct
ast_variable
*
path_var
=
ast_variable_new
(
child
->
path_segment
,
path_segment
,
__FILE__
);
path_var
->
next
=
path_vars
;
path_var
->
next
=
path_vars
;
path_vars
=
path_var
;
path_vars
=
path_var
;
found_handler
=
child
;
wildcard_handler
=
child
;
ast_debug
(
3
,
" Checking %s %s: Matched wildcard.
\n
"
,
handler
->
path_segment
,
child
->
path_segment
);
}
else
if
(
strcmp
(
child
->
path_segment
,
path_segment
)
==
0
)
{
}
else
if
(
strcmp
(
child
->
path_segment
,
path_segment
)
==
0
)
{
found_handler
=
child
;
found_handler
=
child
;
ast_debug
(
3
,
" Checking %s %s: Explicit match with %s
\n
"
,
handler
->
path_segment
,
child
->
path_segment
,
path_segment
);
}
else
{
ast_debug
(
3
,
" Checking %s %s: Didn't match %s
\n
"
,
handler
->
path_segment
,
child
->
path_segment
,
path_segment
);
}
}
}
}
if
(
!
found_handler
&&
wildcard_handler
)
{
ast_debug
(
3
,
" No explicit handler found for %s. Using wildcard %s.
\n
"
,
path_segment
,
wildcard_handler
->
path_segment
);
found_handler
=
wildcard_handler
;
wildcard_handler
=
NULL
;
}
if
(
found_handler
==
NULL
)
{
if
(
found_handler
==
NULL
)
{
/* resource not found */
/* resource not found */
ast_debug
(
3
,
" Handler not found
\n
"
);
ast_debug
(
3
,
" Handler not found
for %s
\n
"
,
path_segment
);
ast_ari_response_error
(
ast_ari_response_error
(
response
,
404
,
"Not Found"
,
response
,
404
,
"Not Found"
,
"Resource not found"
);
"Resource not found"
);
return
;
return
;
}
else
{
}
else
{
ast_debug
(
3
,
" Got it!
\n
"
);
handler
=
found_handler
;
handler
=
found_handler
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment