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
88cc68d9
Commit
88cc68d9
authored
8 years ago
by
zuul
Committed by
Gerrit Code Review
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge "main/media_cache: Provide an extension on the local file associated with a URI"
parents
c530840d
791b4c9f
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
main/media_cache.c
+31
-11
31 additions, 11 deletions
main/media_cache.c
with
31 additions
and
11 deletions
main/media_cache.c
+
31
−
11
View file @
88cc68d9
...
...
@@ -189,23 +189,31 @@ static void media_cache_item_del_from_astdb(struct ast_bucket_file *bucket_file)
static
void
bucket_file_update_path
(
struct
ast_bucket_file
*
bucket_file
,
const
char
*
preferred_file_name
)
{
if
(
ast_strlen_zero
(
preferred_file_name
))
{
return
;
}
char
*
ext
;
if
(
!
strcmp
(
bucket_file
->
path
,
preferred_file_name
))
{
return
;
}
if
(
!
ast_strlen_zero
(
preferred_file_name
)
&&
strcmp
(
bucket_file
->
path
,
preferred_file_name
))
{
/* Use the preferred file name if available */
rename
(
bucket_file
->
path
,
preferred_file_name
);
ast_copy_string
(
bucket_file
->
path
,
preferred_file_name
,
sizeof
(
bucket_file
->
path
));
}
else
if
(
!
strchr
(
bucket_file
->
path
,
'.'
)
&&
(
ext
=
strrchr
(
ast_sorcery_object_get_id
(
bucket_file
),
'.'
)))
{
/* If we don't have a file extension and were provided one in the URI, use it */
char
new_path
[
PATH_MAX
];
ast_bucket_file_metadata_set
(
bucket_file
,
"ext"
,
ext
);
rename
(
bucket_file
->
path
,
preferred_file_name
);
ast_copy_string
(
bucket_file
->
path
,
preferred_file_name
,
sizeof
(
bucket_file
->
path
));
snprintf
(
new_path
,
sizeof
(
new_path
),
"%s%s"
,
bucket_file
->
path
,
ext
);
rename
(
bucket_file
->
path
,
new_path
);
ast_copy_string
(
bucket_file
->
path
,
new_path
,
sizeof
(
bucket_file
->
path
));
}
}
int
ast_media_cache_retrieve
(
const
char
*
uri
,
const
char
*
preferred_file_name
,
char
*
file_path
,
size_t
len
)
{
struct
ast_bucket_file
*
bucket_file
;
char
*
ext
;
SCOPED_AO2LOCK
(
media_lock
,
media_cache
);
if
(
ast_strlen_zero
(
uri
))
{
...
...
@@ -220,11 +228,18 @@ int ast_media_cache_retrieve(const char *uri, const char *preferred_file_name,
if
(
bucket_file
)
{
if
(
!
ast_bucket_file_is_stale
(
bucket_file
))
{
ast_copy_string
(
file_path
,
bucket_file
->
path
,
len
);
if
((
ext
=
strrchr
(
file_path
,
'.'
)))
{
*
ext
=
'\0'
;
}
ao2_ref
(
bucket_file
,
-
1
);
ast_debug
(
5
,
"Returning media at local file: %s
\n
"
,
file_path
);
return
0
;
}
/* Stale! Drop the ref, as we're going to retrieve it next. */
/* Stale! Remove the item completely, as we're going to replace it next */
ao2_unlink_flags
(
media_cache
,
bucket_file
,
OBJ_NOLOCK
);
ast_bucket_file_delete
(
bucket_file
);
ao2_ref
(
bucket_file
,
-
1
);
}
...
...
@@ -243,9 +258,14 @@ int ast_media_cache_retrieve(const char *uri, const char *preferred_file_name,
bucket_file_update_path
(
bucket_file
,
preferred_file_name
);
media_cache_item_sync_to_astdb
(
bucket_file
);
ast_copy_string
(
file_path
,
bucket_file
->
path
,
len
);
if
((
ext
=
strrchr
(
file_path
,
'.'
)))
{
*
ext
=
'\0'
;
}
ao2_link_flags
(
media_cache
,
bucket_file
,
OBJ_NOLOCK
);
ao2_ref
(
bucket_file
,
-
1
);
ast_debug
(
5
,
"Returning media at local file: %s
\n
"
,
file_path
);
return
0
;
}
...
...
@@ -692,7 +712,7 @@ int ast_media_cache_init(void)
{
ast_register_atexit
(
media_cache_shutdown
);
media_cache
=
ao2_container_alloc_options
(
AO2_ALLOC_OPT_LOCK_
RWLOCK
,
AO2_BUCKETS
,
media_cache
=
ao2_container_alloc_options
(
AO2_ALLOC_OPT_LOCK_
MUTEX
,
AO2_BUCKETS
,
media_cache_hash
,
media_cache_cmp
);
if
(
!
media_cache
)
{
return
-
1
;
...
...
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