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
7b09d9c5
Commit
7b09d9c5
authored
5 years ago
by
George Joseph
Committed by
Gerrit Code Review
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge "enum.c: Make ast_get_txt() actually do something."
parents
2ff7c9d8
ab63f0cd
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main/enum.c
+70
-19
70 additions, 19 deletions
main/enum.c
with
70 additions
and
19 deletions
main/enum.c
+
70
−
19
View file @
7b09d9c5
...
@@ -942,37 +942,88 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
...
@@ -942,37 +942,88 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
return
ret
;
return
ret
;
}
}
/*! \internal
* \brief Format a phone number as a domain in an ENUM-adjacent way.
*
* Creates a domain name suitable for query by:
*
* 1. Removing non-digits
* 2. Adding a '.' between adjacent digits
* 3. Reversing the string
* 4. Appending the specified suffix (or e164.arpa if none is specified)
*/
static
char
*
format_numeric_domain
(
const
char
*
number
,
const
char
*
suffix
)
{
char
*
buffer
,
*
dst
;
size_t
suffix_length
;
size_t
number_length
=
strlen
(
number
);
const
char
*
src
=
number
+
number_length
-
1
;
if
(
!
suffix
)
{
suffix
=
"e164.arpa"
;
}
suffix_length
=
strlen
(
suffix
);
dst
=
buffer
=
ast_malloc
(
(
number_length
*
2
)
/* We need 2 bytes per input digit */
+
suffix_length
/* ... plus however long the suffix is */
+
1
/* ... plus room for the '.' separator */
+
1
/* ... and room for the \0 byte at the end */
);
if
(
buffer
)
{
while
(
src
>=
number
)
{
if
(
isdigit
(
*
src
))
{
*
dst
++
=
*
src
;
*
dst
++
=
'.'
;
}
src
--
;
}
/* The length arguments below make sure that the \0 byte is copied into
the final string */
if
(
*
suffix
==
'.'
)
{
memcpy
(
dst
,
&
suffix
[
1
],
suffix_length
);
}
else
{
memcpy
(
dst
,
suffix
,
suffix_length
+
1
);
}
}
return
buffer
;
}
int
ast_get_txt
(
struct
ast_channel
*
chan
,
const
char
*
number
,
char
*
txt
,
int
txtlen
,
char
*
suffix
)
int
ast_get_txt
(
struct
ast_channel
*
chan
,
const
char
*
number
,
char
*
txt
,
int
txtlen
,
char
*
suffix
)
{
{
struct
txt_context
context
;
struct
txt_context
context
;
char
tmp
[
259
+
512
];
char
*
domain
;
int
pos
=
strlen
(
number
)
-
1
;
int
ret
;
int
newpos
=
0
;
int
autoservice
=
0
;
int
ret
=
-
1
;
ast_debug
(
4
,
"ast_get_txt: Number = '%s', suffix = '%s'
\n
"
,
number
,
suffix
);
ast_debug
(
4
,
"ast_get_txt: Number = '%s', suffix = '%s'
\n
"
,
number
,
suffix
);
if
(
pos
>
128
)
{
domain
=
format_numeric_domain
(
number
,
suffix
);
pos
=
128
;
if
(
!
domain
)
{
return
-
1
;
}
}
while
(
pos
>=
0
)
{
if
(
chan
)
{
if
(
isdigit
(
number
[
pos
]))
{
/* DNS might take a while, so service the channel while we're blocked */
tmp
[
newpos
++
]
=
number
[
pos
];
autoservice
=
!
ast_autoservice_start
(
chan
);
tmp
[
newpos
++
]
=
'.'
;
}
pos
--
;
}
}
ast_copy_string
(
&
tmp
[
newpos
],
suffix
,
sizeof
(
tmp
)
-
newpos
);
ret
=
ast_search_dns
(
&
context
,
domain
,
C_IN
,
T_TXT
,
txt_callback
);
if
(
ret
>
0
)
{
if
(
ret
<
0
)
{
ast_debug
(
2
,
"No such number found in ENUM: %s (%s)
\n
"
,
tmp
,
strerror
(
errno
));
ret
=
0
;
}
else
{
ast_copy_string
(
txt
,
context
.
txt
,
txtlen
);
ast_copy_string
(
txt
,
context
.
txt
,
txtlen
);
}
else
{
ast_debug
(
2
,
"No such number found in ENUM: %s (%s)
\n
"
,
domain
,
strerror
(
errno
));
}
}
return
ret
;
if
(
autoservice
)
{
ast_autoservice_stop
(
chan
);
}
ast_free
(
domain
);
return
0
;
}
}
/*! \brief Initialize the ENUM support subsystem */
/*! \brief Initialize the ENUM support subsystem */
...
...
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