Skip to content
GitLab
Explore
Sign in
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
f81a8840
Commit
f81a8840
authored
7 years ago
by
Jenkins2
Committed by
Gerrit Code Review
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge "loader: Refactor resource_name_match."
parents
5d43a4d4
d2e87b8e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main/loader.c
+27
-16
27 additions, 16 deletions
main/loader.c
with
27 additions
and
16 deletions
main/loader.c
+
27
−
16
View file @
f81a8840
...
@@ -376,35 +376,39 @@ static int verify_key(const unsigned char *key)
...
@@ -376,35 +376,39 @@ static int verify_key(const unsigned char *key)
return
-
1
;
return
-
1
;
}
}
static
in
t
resource_name_
match
(
const
char
*
name1_in
,
const
char
*
name
2_in
)
static
size_
t
resource_name_
baselen
(
const
char
*
name
)
{
{
char
*
name1
=
(
char
*
)
name1_in
;
size_t
len
=
strlen
(
name
);
char
*
name2
=
(
char
*
)
name2_in
;
/* trim off any .so extensions */
if
(
len
>
3
&&
!
strcasecmp
(
name
+
len
-
3
,
".so"
))
{
if
(
!
strcasecmp
(
name1
+
strlen
(
name1
)
-
3
,
".so"
))
{
return
len
-
3
;
name1
=
ast_strdupa
(
name1
);
name1
[
strlen
(
name1
)
-
3
]
=
'\0'
;
}
}
if
(
!
strcasecmp
(
name2
+
strlen
(
name2
)
-
3
,
".so"
))
{
name2
=
ast_strdupa
(
name2
);
return
len
;
name2
[
strlen
(
name2
)
-
3
]
=
'\0'
;
}
static
int
resource_name_match
(
const
char
*
name1
,
size_t
baselen1
,
const
char
*
name2
)
{
if
(
baselen1
!=
resource_name_baselen
(
name2
))
{
return
-
1
;
}
}
return
strcasecmp
(
name1
,
name2
);
return
str
n
casecmp
(
name1
,
name2
,
baselen1
);
}
}
static
struct
ast_module
*
find_resource
(
const
char
*
resource
,
int
do_lock
)
static
struct
ast_module
*
find_resource
(
const
char
*
resource
,
int
do_lock
)
{
{
struct
ast_module
*
cur
;
struct
ast_module
*
cur
;
size_t
resource_baselen
=
resource_name_baselen
(
resource
);
if
(
do_lock
)
{
if
(
do_lock
)
{
AST_DLLIST_LOCK
(
&
module_list
);
AST_DLLIST_LOCK
(
&
module_list
);
}
}
AST_DLLIST_TRAVERSE
(
&
module_list
,
cur
,
entry
)
{
AST_DLLIST_TRAVERSE
(
&
module_list
,
cur
,
entry
)
{
if
(
!
resource_name_match
(
resource
,
cur
->
resource
))
if
(
!
resource_name_match
(
resource
,
resource_baselen
,
cur
->
resource
))
{
break
;
break
;
}
}
}
if
(
do_lock
)
{
if
(
do_lock
)
{
...
@@ -938,6 +942,7 @@ enum ast_module_reload_result ast_module_reload(const char *name)
...
@@ -938,6 +942,7 @@ enum ast_module_reload_result ast_module_reload(const char *name)
struct
ast_module
*
cur
;
struct
ast_module
*
cur
;
enum
ast_module_reload_result
res
=
AST_MODULE_RELOAD_NOT_FOUND
;
enum
ast_module_reload_result
res
=
AST_MODULE_RELOAD_NOT_FOUND
;
int
i
;
int
i
;
size_t
name_baselen
=
name
?
resource_name_baselen
(
name
)
:
0
;
/* If we aren't fully booted, we just pretend we reloaded but we queue this
/* If we aren't fully booted, we just pretend we reloaded but we queue this
up to run once we are booted up. */
up to run once we are booted up. */
...
@@ -991,8 +996,9 @@ enum ast_module_reload_result ast_module_reload(const char *name)
...
@@ -991,8 +996,9 @@ enum ast_module_reload_result ast_module_reload(const char *name)
AST_DLLIST_TRAVERSE
(
&
module_list
,
cur
,
entry
)
{
AST_DLLIST_TRAVERSE
(
&
module_list
,
cur
,
entry
)
{
const
struct
ast_module_info
*
info
=
cur
->
info
;
const
struct
ast_module_info
*
info
=
cur
->
info
;
if
(
name
&&
resource_name_match
(
name
,
cur
->
resource
))
if
(
name
&&
resource_name_match
(
name
,
name_baselen
,
cur
->
resource
))
{
continue
;
continue
;
}
if
(
!
cur
->
flags
.
running
||
cur
->
flags
.
declined
)
{
if
(
!
cur
->
flags
.
running
||
cur
->
flags
.
declined
)
{
if
(
res
==
AST_MODULE_RELOAD_NOT_FOUND
)
{
if
(
res
==
AST_MODULE_RELOAD_NOT_FOUND
)
{
...
@@ -1186,9 +1192,10 @@ AST_LIST_HEAD_NOLOCK(load_order, load_order_entry);
...
@@ -1186,9 +1192,10 @@ AST_LIST_HEAD_NOLOCK(load_order, load_order_entry);
static
struct
load_order_entry
*
add_to_load_order
(
const
char
*
resource
,
struct
load_order
*
load_order
,
int
required
)
static
struct
load_order_entry
*
add_to_load_order
(
const
char
*
resource
,
struct
load_order
*
load_order
,
int
required
)
{
{
struct
load_order_entry
*
order
;
struct
load_order_entry
*
order
;
size_t
resource_baselen
=
resource_name_baselen
(
resource
);
AST_LIST_TRAVERSE
(
load_order
,
order
,
entry
)
{
AST_LIST_TRAVERSE
(
load_order
,
order
,
entry
)
{
if
(
!
resource_name_match
(
order
->
resource
,
resource
))
{
if
(
!
resource_name_match
(
resource
,
resource_baselen
,
order
->
resource
))
{
/* Make sure we have the proper setting for the required field
/* Make sure we have the proper setting for the required field
(we might have both load= and required= lines in modules.conf) */
(we might have both load= and required= lines in modules.conf) */
order
->
required
|=
required
;
order
->
required
|=
required
;
...
@@ -1435,11 +1442,15 @@ int load_modules(unsigned int preload_only)
...
@@ -1435,11 +1442,15 @@ int load_modules(unsigned int preload_only)
/* now scan the config for any modules we are prohibited from loading and
/* now scan the config for any modules we are prohibited from loading and
remove them from the load order */
remove them from the load order */
for
(
v
=
ast_variable_browse
(
cfg
,
"modules"
);
v
;
v
=
v
->
next
)
{
for
(
v
=
ast_variable_browse
(
cfg
,
"modules"
);
v
;
v
=
v
->
next
)
{
if
(
strcasecmp
(
v
->
name
,
"noload"
))
size_t
baselen
;
if
(
strcasecmp
(
v
->
name
,
"noload"
))
{
continue
;
continue
;
}
baselen
=
resource_name_baselen
(
v
->
value
);
AST_LIST_TRAVERSE_SAFE_BEGIN
(
&
load_order
,
order
,
entry
)
{
AST_LIST_TRAVERSE_SAFE_BEGIN
(
&
load_order
,
order
,
entry
)
{
if
(
!
resource_name_match
(
order
->
resource
,
v
->
value
))
{
if
(
!
resource_name_match
(
v
->
value
,
baselen
,
order
->
resource
))
{
AST_LIST_REMOVE_CURRENT
(
entry
);
AST_LIST_REMOVE_CURRENT
(
entry
);
ast_free
(
order
->
resource
);
ast_free
(
order
->
resource
);
ast_free
(
order
);
ast_free
(
order
);
...
...
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