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
43305a0d
Commit
43305a0d
authored
7 years ago
by
Joshua Colp
Committed by
Gerrit Code Review
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge "res_pjsip.c: Fix ident_to_str() and refactor ident_handler()."
parents
92ff6c65
a7bbb18e
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_pjsip/pjsip_configuration.c
+78
-25
78 additions, 25 deletions
res/res_pjsip/pjsip_configuration.c
with
78 additions
and
25 deletions
res/res_pjsip/pjsip_configuration.c
+
78
−
25
View file @
43305a0d
...
@@ -572,12 +572,63 @@ static int outbound_auths_to_str(const void *obj, const intptr_t *args, char **b
...
@@ -572,12 +572,63 @@ static int outbound_auths_to_str(const void *obj, const intptr_t *args, char **b
return
ast_sip_auths_to_str
(
&
endpoint
->
outbound_auths
,
buf
);
return
ast_sip_auths_to_str
(
&
endpoint
->
outbound_auths
,
buf
);
}
}
/*!
* \internal
* \brief Convert identify_by method to string.
*
* \param method Method value to convert to string
*
* \return String representation.
*/
static
const
char
*
sip_endpoint_identifier_type2str
(
enum
ast_sip_endpoint_identifier_type
method
)
{
const
char
*
str
=
"<unknown>"
;
switch
(
method
)
{
case
AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME
:
str
=
"username"
;
break
;
case
AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME
:
str
=
"auth_username"
;
break
;
case
AST_SIP_ENDPOINT_IDENTIFY_BY_IP
:
str
=
"ip"
;
break
;
}
return
str
;
}
/*!
* \internal
* \brief Convert string to an endpoint identifier token.
*
* \param str String to convert
*
* \retval enum ast_sip_endpoint_identifier_type token value on success.
* \retval -1 on failure.
*/
static
int
sip_endpoint_identifier_str2type
(
const
char
*
str
)
{
int
method
;
if
(
!
strcasecmp
(
str
,
"username"
))
{
method
=
AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME
;
}
else
if
(
!
strcasecmp
(
str
,
"auth_username"
))
{
method
=
AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME
;
}
else
if
(
!
strcasecmp
(
str
,
"ip"
))
{
method
=
AST_SIP_ENDPOINT_IDENTIFY_BY_IP
;
}
else
{
method
=
-
1
;
}
return
method
;
}
static
int
ident_handler
(
const
struct
aco_option
*
opt
,
struct
ast_variable
*
var
,
void
*
obj
)
static
int
ident_handler
(
const
struct
aco_option
*
opt
,
struct
ast_variable
*
var
,
void
*
obj
)
{
{
struct
ast_sip_endpoint
*
endpoint
=
obj
;
struct
ast_sip_endpoint
*
endpoint
=
obj
;
char
*
idents
=
ast_strdupa
(
var
->
value
);
char
*
idents
=
ast_strdupa
(
var
->
value
);
char
*
val
;
char
*
val
;
enum
ast_sip_endpoint_identifier_type
method
;
int
method
;
/*
/*
* If there's already something in the vector when we get here,
* If there's already something in the vector when we get here,
...
@@ -593,13 +644,8 @@ static int ident_handler(const struct aco_option *opt, struct ast_variable *var,
...
@@ -593,13 +644,8 @@ static int ident_handler(const struct aco_option *opt, struct ast_variable *var,
continue
;
continue
;
}
}
if
(
!
strcasecmp
(
val
,
"username"
))
{
method
=
sip_endpoint_identifier_str2type
(
val
);
method
=
AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME
;
if
(
method
==
-
1
)
{
}
else
if
(
!
strcasecmp
(
val
,
"auth_username"
))
{
method
=
AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME
;
}
else
if
(
!
strcasecmp
(
val
,
"ip"
))
{
method
=
AST_SIP_ENDPOINT_IDENTIFY_BY_IP
;
}
else
{
ast_log
(
LOG_ERROR
,
"Unrecognized identification method %s specified for endpoint %s
\n
"
,
ast_log
(
LOG_ERROR
,
"Unrecognized identification method %s specified for endpoint %s
\n
"
,
val
,
ast_sorcery_object_get_id
(
endpoint
));
val
,
ast_sorcery_object_get_id
(
endpoint
));
AST_VECTOR_RESET
(
&
endpoint
->
ident_method_order
,
AST_VECTOR_ELEM_CLEANUP_NOOP
);
AST_VECTOR_RESET
(
&
endpoint
->
ident_method_order
,
AST_VECTOR_ELEM_CLEANUP_NOOP
);
...
@@ -622,34 +668,41 @@ static int ident_to_str(const void *obj, const intptr_t *args, char **buf)
...
@@ -622,34 +668,41 @@ static int ident_to_str(const void *obj, const intptr_t *args, char **buf)
{
{
const
struct
ast_sip_endpoint
*
endpoint
=
obj
;
const
struct
ast_sip_endpoint
*
endpoint
=
obj
;
int
methods
;
int
methods
;
char
*
method
;
int
idx
;
int
i
;
int
buf_used
=
0
;
int
j
=
0
;
int
buf_size
=
MAX_OBJECT_FIELD
;
methods
=
AST_VECTOR_SIZE
(
&
endpoint
->
ident_method_order
);
methods
=
AST_VECTOR_SIZE
(
&
endpoint
->
ident_method_order
);
if
(
!
methods
)
{
if
(
!
methods
)
{
return
0
;
return
0
;
}
}
if
(
!
(
*
buf
=
ast_calloc
(
MAX_OBJECT_FIELD
,
sizeof
(
char
))))
{
*
buf
=
ast_malloc
(
buf_size
);
if
(
!*
buf
)
{
return
-
1
;
return
-
1
;
}
}
for
(
i
=
0
;
i
<
methods
;
i
++
)
{
for
(
idx
=
0
;
idx
<
methods
;
++
idx
)
{
switch
(
AST_VECTOR_GET
(
&
endpoint
->
ident_method_order
,
i
))
{
enum
ast_sip_endpoint_identifier_type
method
;
case
AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME
:
const
char
*
method_str
;
method
=
"username"
;
break
;
method
=
AST_VECTOR_GET
(
&
endpoint
->
ident_method_order
,
idx
);
case
AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME
:
method_str
=
sip_endpoint_identifier_type2str
(
method
);
method
=
"auth_username"
;
break
;
/* Should never have an "<unknown>" method string */
case
AST_SIP_ENDPOINT_IDENTIFY_BY_IP
:
ast_assert
(
strcmp
(
method_str
,
"<unknown>"
));
method
=
"ip"
;
if
(
!
strcmp
(
method_str
,
"<unknown>"
))
{
break
;
default:
continue
;
continue
;
}
}
j
=
sprintf
(
*
buf
+
j
,
"%s%s"
,
method
,
i
<
methods
-
1
?
","
:
""
);
buf_used
+=
snprintf
(
*
buf
+
buf_used
,
buf_size
-
buf_used
,
"%s%s"
,
method_str
,
idx
<
methods
-
1
?
","
:
""
);
if
(
buf_size
<=
buf_used
)
{
/* Need more room than available, truncating. */
*
(
*
buf
+
(
buf_size
-
1
))
=
'\0'
;
ast_log
(
LOG_WARNING
,
"Truncated identify_by string: %s
\n
"
,
*
buf
);
break
;
}
}
}
return
0
;
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