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
13450c80
Commit
13450c80
authored
8 years ago
by
Richard Mudgett
Browse files
Options
Downloads
Patches
Plain Diff
res_sorcery_config.c: Cleanup ao2 container usage idioms.
Change-Id: Iad24b335fb121a2bc7f1d048ab7420569edcba5a
parent
d526aa5c
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
res/res_sorcery_config.c
+13
-27
13 additions, 27 deletions
res/res_sorcery_config.c
with
13 additions
and
27 deletions
res/res_sorcery_config.c
+
13
−
27
View file @
13450c80
...
@@ -109,22 +109,6 @@ static void sorcery_config_destructor(void *obj)
...
@@ -109,22 +109,6 @@ static void sorcery_config_destructor(void *obj)
ast_variables_destroy
(
config
->
criteria
);
ast_variables_destroy
(
config
->
criteria
);
}
}
/*! \brief Hashing function for sorcery objects */
static
int
sorcery_config_hash
(
const
void
*
obj
,
const
int
flags
)
{
const
char
*
id
=
obj
;
return
ast_str_hash
(
flags
&
OBJ_KEY
?
id
:
ast_sorcery_object_get_id
(
obj
));
}
/*! \brief Comparator function for sorcery objects */
static
int
sorcery_config_cmp
(
void
*
obj
,
void
*
arg
,
int
flags
)
{
const
char
*
id
=
arg
;
return
!
strcmp
(
ast_sorcery_object_get_id
(
obj
),
flags
&
OBJ_KEY
?
id
:
ast_sorcery_object_get_id
(
arg
))
?
CMP_MATCH
|
CMP_STOP
:
0
;
}
static
int
sorcery_config_fields_cmp
(
void
*
obj
,
void
*
arg
,
int
flags
)
static
int
sorcery_config_fields_cmp
(
void
*
obj
,
void
*
arg
,
int
flags
)
{
{
const
struct
sorcery_config_fields_cmp_params
*
params
=
arg
;
const
struct
sorcery_config_fields_cmp_params
*
params
=
arg
;
...
@@ -145,14 +129,16 @@ static int sorcery_config_fields_cmp(void *obj, void *arg, int flags)
...
@@ -145,14 +129,16 @@ static int sorcery_config_fields_cmp(void *obj, void *arg, int flags)
return
0
;
return
0
;
}
}
/* We want this object */
if
(
params
->
container
)
{
if
(
params
->
container
)
{
/*
* We are putting the found objects into the given container instead
* of the normal container traversal return mechanism.
*/
ao2_link
(
params
->
container
,
obj
);
ao2_link
(
params
->
container
,
obj
);
/* As multiple objects are being returned keep going */
return
0
;
return
0
;
}
else
{
}
else
{
/* Immediately stop and return, we only want a single object */
return
CMP_MATCH
;
return
CMP_MATCH
|
CMP_STOP
;
}
}
}
}
...
@@ -179,7 +165,7 @@ static void *sorcery_config_retrieve_id(const struct ast_sorcery *sorcery, void
...
@@ -179,7 +165,7 @@ static void *sorcery_config_retrieve_id(const struct ast_sorcery *sorcery, void
struct
sorcery_config
*
config
=
data
;
struct
sorcery_config
*
config
=
data
;
RAII_VAR
(
struct
ao2_container
*
,
objects
,
ao2_global_obj_ref
(
config
->
objects
),
ao2_cleanup
);
RAII_VAR
(
struct
ao2_container
*
,
objects
,
ao2_global_obj_ref
(
config
->
objects
),
ao2_cleanup
);
return
objects
?
ao2_find
(
objects
,
id
,
OBJ_KEY
)
:
NULL
;
return
objects
?
ao2_find
(
objects
,
id
,
OBJ_
SEARCH_
KEY
)
:
NULL
;
}
}
static
void
sorcery_config_retrieve_multiple
(
const
struct
ast_sorcery
*
sorcery
,
void
*
data
,
const
char
*
type
,
struct
ao2_container
*
objects
,
const
struct
ast_variable
*
fields
)
static
void
sorcery_config_retrieve_multiple
(
const
struct
ast_sorcery
*
sorcery
,
void
*
data
,
const
char
*
type
,
struct
ao2_container
*
objects
,
const
struct
ast_variable
*
fields
)
...
@@ -196,7 +182,7 @@ static void sorcery_config_retrieve_multiple(const struct ast_sorcery *sorcery,
...
@@ -196,7 +182,7 @@ static void sorcery_config_retrieve_multiple(const struct ast_sorcery *sorcery,
return
;
return
;
}
}
ao2_callback
(
config_objects
,
0
,
sorcery_config_fields_cmp
,
&
params
);
ao2_callback
(
config_objects
,
OBJ_NODATA
|
OBJ_MULTIPLE
,
sorcery_config_fields_cmp
,
&
params
);
}
}
static
void
sorcery_config_retrieve_regex
(
const
struct
ast_sorcery
*
sorcery
,
void
*
data
,
const
char
*
type
,
struct
ao2_container
*
objects
,
const
char
*
regex
)
static
void
sorcery_config_retrieve_regex
(
const
struct
ast_sorcery
*
sorcery
,
void
*
data
,
const
char
*
type
,
struct
ao2_container
*
objects
,
const
char
*
regex
)
...
@@ -218,7 +204,7 @@ static void sorcery_config_retrieve_regex(const struct ast_sorcery *sorcery, voi
...
@@ -218,7 +204,7 @@ static void sorcery_config_retrieve_regex(const struct ast_sorcery *sorcery, voi
return
;
return
;
}
}
ao2_callback
(
config_objects
,
0
,
sorcery_config_fields_cmp
,
&
params
);
ao2_callback
(
config_objects
,
OBJ_NODATA
|
OBJ_MULTIPLE
,
sorcery_config_fields_cmp
,
&
params
);
regfree
(
&
expression
);
regfree
(
&
expression
);
}
}
...
@@ -280,8 +266,9 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
...
@@ -280,8 +266,9 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
ast_debug
(
2
,
"Using bucket size of '%d' for objects of type '%s' from '%s'
\n
"
,
ast_debug
(
2
,
"Using bucket size of '%d' for objects of type '%s' from '%s'
\n
"
,
buckets
,
type
,
config
->
filename
);
buckets
,
type
,
config
->
filename
);
if
(
!
(
objects
=
ao2_container_alloc_options
(
AO2_ALLOC_OPT_LOCK_NOLOCK
,
buckets
,
objects
=
ao2_container_alloc_hash
(
AO2_ALLOC_OPT_LOCK_NOLOCK
,
0
,
buckets
,
sorcery_config_hash
,
sorcery_config_cmp
)))
{
ast_sorcery_object_id_hash
,
NULL
,
ast_sorcery_object_id_compare
);
if
(
!
objects
)
{
ast_log
(
LOG_ERROR
,
"Could not create bucket for new objects from '%s', keeping existing objects
\n
"
,
ast_log
(
LOG_ERROR
,
"Could not create bucket for new objects from '%s', keeping existing objects
\n
"
,
config
->
filename
);
config
->
filename
);
ast_config_destroy
(
cfg
);
ast_config_destroy
(
cfg
);
...
@@ -300,8 +287,7 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
...
@@ -300,8 +287,7 @@ static void sorcery_config_internal_load(void *data, const struct ast_sorcery *s
/* Confirm an object with this id does not already exist in the bucket.
/* Confirm an object with this id does not already exist in the bucket.
* If it exists, however, the configuration is invalid so stop
* If it exists, however, the configuration is invalid so stop
* processing and destroy it. */
* processing and destroy it. */
obj
=
ao2_find
(
objects
,
id
,
OBJ_KEY
);
obj
=
ao2_find
(
objects
,
id
,
OBJ_SEARCH_KEY
);
if
(
obj
)
{
if
(
obj
)
{
ast_log
(
LOG_ERROR
,
"Config file '%s' could not be loaded; configuration contains a duplicate object: '%s' of type '%s'
\n
"
,
ast_log
(
LOG_ERROR
,
"Config file '%s' could not be loaded; configuration contains a duplicate object: '%s' of type '%s'
\n
"
,
config
->
filename
,
id
,
type
);
config
->
filename
,
id
,
type
);
...
...
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