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
062857ec
Commit
062857ec
authored
9 years ago
by
zuul
Committed by
Gerrit Code Review
9 years ago
Browse files
Options
Downloads
Plain Diff
Merge "res_pjsip_config_wizard: Add command to export primitive objects"
parents
def3fb46
4f08e9fb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGES
+6
-0
6 additions, 0 deletions
CHANGES
res/res_pjsip_config_wizard.c
+108
-3
108 additions, 3 deletions
res/res_pjsip_config_wizard.c
with
114 additions
and
3 deletions
CHANGES
+
6
−
0
View file @
062857ec
...
...
@@ -210,6 +210,12 @@ Queue
--- Functionality changes from Asterisk 13.7.0 to Asterisk 13.8.0 ------------
------------------------------------------------------------------------------
res_pjsip_config_wizard
------------------
* A new command (pjsip export config_wizard primitives) has been added that
will export all the pjsip objects it created to the console or a file
suitable for reuse in a pjsip.conf file.
app_confbridge
------------------
* Added CONFBRIDGE_INFO(muted,) for querying the muted conference state.
...
...
This diff is collapsed.
Click to expand it.
res/res_pjsip_config_wizard.c
+
108
−
3
View file @
062857ec
...
...
@@ -45,6 +45,7 @@ ASTERISK_REGISTER_FILE()
#include
<pjsip.h>
#include
"asterisk/astobj2.h"
#include
"asterisk/cli.h"
#include
"asterisk/res_pjsip.h"
#include
"asterisk/module.h"
#include
"asterisk/pbx.h"
...
...
@@ -276,7 +277,7 @@ struct object_type_wizard {
struct
ast_config
*
last_config
;
char
object_type
[];
};
static
AST_VECTOR
(
object_type_wizards
,
struct
object_type_wizard
*
)
object_type_wizards
;
static
AST_VECTOR
_RW
(
object_type_wizards
,
struct
object_type_wizard
*
)
object_type_wizards
;
/*! \brief Callbacks for vector deletes */
#define NOT_EQUALS(a, b) (a != b)
...
...
@@ -304,12 +305,15 @@ static struct object_type_wizard *find_wizard(const char *object_type)
{
int
idx
;
AST_VECTOR_RW_RDLOCK
(
&
object_type_wizards
);
for
(
idx
=
0
;
idx
<
AST_VECTOR_SIZE
(
&
object_type_wizards
);
idx
++
)
{
struct
object_type_wizard
*
otw
=
AST_VECTOR_GET
(
&
object_type_wizards
,
idx
);
if
(
!
strcmp
(
otw
->
object_type
,
object_type
))
{
AST_VECTOR_RW_UNLOCK
(
&
object_type_wizards
);
return
otw
;
}
}
AST_VECTOR_RW_UNLOCK
(
&
object_type_wizards
);
return
NULL
;
}
...
...
@@ -1137,7 +1141,9 @@ static void wizard_mapped_observer(const char *name, struct ast_sorcery *sorcery
otw
->
wizard_data
=
wizard_data
;
otw
->
last_config
=
NULL
;
strcpy
(
otw
->
object_type
,
object_type
);
/* Safe */
AST_VECTOR_RW_WRLOCK
(
&
object_type_wizards
);
AST_VECTOR_APPEND
(
&
object_type_wizards
,
otw
);
AST_VECTOR_RW_UNLOCK
(
&
object_type_wizards
);
ast_debug
(
1
,
"Wizard mapped for object_type '%s'
\n
"
,
object_type
);
}
}
...
...
@@ -1177,19 +1183,118 @@ static void instance_destroying_observer(const char *name, struct ast_sorcery *s
ast_module_unref
(
ast_module_info
->
self
);
}
static
char
*
handle_export_primitives
(
struct
ast_cli_entry
*
e
,
int
cmd
,
struct
ast_cli_args
*
a
)
{
struct
ast_sorcery
*
sorcery
;
int
idx
;
FILE
*
f
=
NULL
;
const
char
*
fn
=
NULL
;
switch
(
cmd
)
{
case
CLI_INIT
:
e
->
command
=
"pjsip export config_wizard primitives [to]"
;
e
->
usage
=
"Usage: pjsip export config_wizard primitives [ to <filename ]
\n
"
" Export the config_wizard objects as pjsip primitives to
\n
"
" the console or to <filename>
\n
"
;
return
NULL
;
case
CLI_GENERATE
:
return
NULL
;
}
if
(
a
->
argc
>
5
)
{
char
date
[
256
]
=
""
;
time_t
t
;
fn
=
a
->
argv
[
5
];
time
(
&
t
);
ast_copy_string
(
date
,
ctime
(
&
t
),
sizeof
(
date
));
f
=
fopen
(
fn
,
"w"
);
if
(
!
f
)
{
ast_log
(
LOG_ERROR
,
"Unable to write %s (%s)
\n
"
,
fn
,
strerror
(
errno
));
return
CLI_FAILURE
;
}
fprintf
(
f
,
";!
\n
"
);
fprintf
(
f
,
";! Automatically generated configuration file
\n
"
);
fprintf
(
f
,
";! Filename: %s
\n
"
,
fn
);
fprintf
(
f
,
";! Generator: %s
\n
"
,
"'pjsip export config_wizard primitives'"
);
fprintf
(
f
,
";! Creation Date: %s"
,
date
);
fprintf
(
f
,
";!
\n
"
);
}
sorcery
=
ast_sip_get_sorcery
();
AST_VECTOR_RW_RDLOCK
(
&
object_type_wizards
);
for
(
idx
=
0
;
idx
<
AST_VECTOR_SIZE
(
&
object_type_wizards
);
idx
++
)
{
struct
object_type_wizard
*
otw
=
AST_VECTOR_GET
(
&
object_type_wizards
,
idx
);
struct
ao2_container
*
container
;
struct
ao2_iterator
i
;
void
*
o
;
container
=
ast_sorcery_retrieve_by_fields
(
sorcery
,
otw
->
object_type
,
AST_RETRIEVE_FLAG_MULTIPLE
,
NULL
);
if
(
!
container
)
{
continue
;
}
i
=
ao2_iterator_init
(
container
,
0
);
while
((
o
=
ao2_iterator_next
(
&
i
)))
{
struct
ast_variable
*
vars
;
struct
ast_variable
*
v
;
vars
=
ast_sorcery_objectset_create
(
sorcery
,
o
);
if
(
vars
&&
ast_variable_find_in_list
(
vars
,
"@pjsip_wizard"
))
{
if
(
f
)
{
fprintf
(
f
,
"
\n
[%s]
\n
type = %s
\n
"
,
ast_sorcery_object_get_id
(
o
),
otw
->
object_type
);
}
else
{
ast_cli
(
a
->
fd
,
"
\n
[%s]
\n
type = %s
\n
"
,
ast_sorcery_object_get_id
(
o
),
otw
->
object_type
);
}
for
(
v
=
vars
;
v
;
v
=
v
->
next
)
{
if
(
!
ast_strlen_zero
(
v
->
value
))
{
if
(
f
)
{
fprintf
(
f
,
"%s = %s
\n
"
,
v
->
name
,
v
->
value
);
}
else
{
ast_cli
(
a
->
fd
,
"%s = %s
\n
"
,
v
->
name
,
v
->
value
);
}
}
}
}
ast_variables_destroy
(
vars
);
ao2_ref
(
o
,
-
1
);
}
ao2_iterator_destroy
(
&
i
);
ao2_cleanup
(
container
);
}
AST_VECTOR_RW_UNLOCK
(
&
object_type_wizards
);
if
(
f
)
{
fclose
(
f
);
ast_cli
(
a
->
fd
,
"Wrote configuration to %s
\n
"
,
fn
);
}
return
CLI_SUCCESS
;
}
static
struct
ast_cli_entry
config_wizard_cli
[]
=
{
AST_CLI_DEFINE
(
handle_export_primitives
,
"Export config wizard primitives"
),
};
static
int
load_module
(
void
)
{
AST_VECTOR_INIT
(
&
object_type_wizards
,
12
);
AST_VECTOR_
RW_
INIT
(
&
object_type_wizards
,
12
);
ast_sorcery_global_observer_add
(
&
global_observer
);
ast_cli_register_multiple
(
config_wizard_cli
,
ARRAY_LEN
(
config_wizard_cli
));
return
AST_MODULE_LOAD_SUCCESS
;
}
static
int
unload_module
(
void
)
{
ast_cli_unregister_multiple
(
config_wizard_cli
,
ARRAY_LEN
(
config_wizard_cli
));
ast_sorcery_global_observer_remove
(
&
global_observer
);
AST_VECTOR_REMOVE_CMP_UNORDERED
(
&
object_type_wizards
,
NULL
,
NOT_EQUALS
,
OTW_DELETE_CB
);
AST_VECTOR_FREE
(
&
object_type_wizards
);
AST_VECTOR_
RW_
FREE
(
&
object_type_wizards
);
return
0
;
}
...
...
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