![]()  | 
  
    libgpac
    
   Documentation of the core library of GPAC 
   | 
  
#include "downloader.h"#include <gpac/network.h>#include <gpac/download.h>#include <gpac/token.h>#include <gpac/thread.h>#include <gpac/list.h>#include <gpac/base_coding.h>#include <gpac/tools.h>#include <gpac/config_file.h>#include <stdio.h>#include <string.h>
 Include dependency graph for downloader_cache.c:Data Structures | |
| struct | __DownloadedCacheEntryStruct | 
| struct | CacheInfo | 
| struct | CacheGather | 
Macros | |
| #define | CHECK_ENTRY if (!entry) { GF_LOG(GF_LOG_WARNING, GF_LOG_CACHE, ("[CACHE] entry is null at " __FILE__ ":%d\n", __LINE__)); return GF_BAD_PARAM; } | 
| #define | _CACHE_HASH_SIZE 20 | 
| #define | _CACHE_MAX_EXTENSION_SIZE 6 | 
Enumerations | |
| enum | CacheValid { CORRUPTED = 1 , DELETED = 1<<1 , IN_PROGRESS = 1<<2 } | 
Functions | |
| Bool | gf_sys_check_process_id (u32 pid) | 
| Checks a process is valid.   | |
| Bool | gf_cache_entry_persistent (const DownloadedCacheEntry entry) | 
| void | gf_cache_entry_set_persistent (const DownloadedCacheEntry entry) | 
| static Bool | cache_cleanup_processes (GF_Config *cfg) | 
| static Bool | gather_cache_files (void *cbck, char *item_name, char *item_path, GF_FileEnumInfo *file_info) | 
| u64 | gf_cache_cleanup (const char *directory, u64 max_size) | 
| void | gf_cache_entry_set_delete_files_when_deleted (const DownloadedCacheEntry entry) | 
| const char * | gf_cache_get_etag_on_server (const DownloadedCacheEntry entry) | 
| const char * | gf_cache_get_mime_type (const DownloadedCacheEntry entry) | 
| GF_Err | gf_cache_set_headers_processed (const DownloadedCacheEntry entry) | 
| Bool | gf_cache_are_headers_processed (const DownloadedCacheEntry entry) | 
| GF_Err | gf_cache_set_etag_on_server (const DownloadedCacheEntry entry, const char *eTag) | 
| GF_Err | gf_cache_set_etag_on_disk (const DownloadedCacheEntry entry, const char *eTag) | 
| GF_Err | gf_cache_set_mime_type (const DownloadedCacheEntry entry, const char *mime_type) | 
| u64 | gf_cache_get_start_range (const DownloadedCacheEntry entry) | 
| u64 | gf_cache_get_end_range (const DownloadedCacheEntry entry) | 
| const char * | gf_cache_get_url (const DownloadedCacheEntry entry) | 
| const char * | gf_cache_get_last_modified_on_server (const DownloadedCacheEntry entry) | 
| GF_Err | gf_cache_set_last_modified_on_server (const DownloadedCacheEntry entry, const char *newLastModified) | 
| GF_Err | gf_cache_set_last_modified_on_disk (const DownloadedCacheEntry entry, const char *newLastModified) | 
| static GF_LockStatus | cache_entry_lock (const char *lockfile) | 
| GF_Err | gf_cache_flush_disk_cache (const DownloadedCacheEntry entry, Bool success) | 
| u32 | gf_cache_get_cache_filesize (const DownloadedCacheEntry entry) | 
| const char * | gf_cache_get_cache_filename (const DownloadedCacheEntry entry) | 
| GF_Err | gf_cache_get_http_headers (const DownloadedCacheEntry entry, const char **etag, const char **last_modif) | 
| static void | gf_cache_check_if_cache_file_is_corrupted (const DownloadedCacheEntry entry, const char *url, GF_Config *cfg) | 
| DownloadedCacheEntry | gf_cache_create_entry (const char *cache_directory, const char *url, u64 start_range, u64 end_range, Bool mem_storage, GF_Mutex *mx) | 
| GF_Err | gf_cache_set_content_length (const DownloadedCacheEntry entry, u32 length) | 
| u32 | gf_cache_get_content_length (const DownloadedCacheEntry entry) | 
| GF_Err | gf_cache_close_write_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess, Bool success) | 
| GF_Err | gf_cache_open_write_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess) | 
| GF_Err | gf_cache_write_to_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess, const char *data, const u32 size, GF_Mutex *mx) | 
| void | gf_cache_delete_entry (const DownloadedCacheEntry entry) | 
| s32 | gf_cache_remove_session_from_cache_entry (DownloadedCacheEntry entry, GF_DownloadSession *sess) | 
| void | gf_cache_set_max_age (const DownloadedCacheEntry entry, u32 max_age, Bool must_revalidate) | 
| static u32 | gf_cache_get_sessions_count_for_cache_entry (const DownloadedCacheEntry entry) | 
| s32 | gf_cache_add_session_to_cache_entry (DownloadedCacheEntry entry, GF_DownloadSession *sess) | 
| void | gf_cache_set_end_range (DownloadedCacheEntry entry, u64 range_end) | 
| Bool | gf_cache_is_in_progress (const DownloadedCacheEntry entry) | 
| Bool | gf_cache_set_mime (const DownloadedCacheEntry entry, const char *mime) | 
| Bool | gf_cache_set_range (const DownloadedCacheEntry entry, u64 size, u64 start_range, u64 end_range) | 
| Bool | gf_cache_set_headers (const DownloadedCacheEntry entry, const char *headers) | 
| char * | gf_cache_get_forced_headers (const DownloadedCacheEntry entry) | 
| void | gf_cache_set_downtime (const DownloadedCacheEntry entry, u32 download_time_ms) | 
| u32 | gf_cache_get_downtime (const DownloadedCacheEntry entry) | 
| u32 | gf_cache_is_done (const DownloadedCacheEntry entry) | 
| const u8 * | gf_cache_get_content (const DownloadedCacheEntry entry, u32 *size, u32 *max_valid_size, Bool *was_modified) | 
| void | gf_cache_release_content (const DownloadedCacheEntry entry) | 
| Bool | gf_cache_is_deleted (const DownloadedCacheEntry entry) | 
| Bool | gf_cache_set_content (const DownloadedCacheEntry entry, GF_Blob *blob, Bool copy, GF_Mutex *mx) | 
| static Bool | gf_cache_entry_can_reuse (const DownloadedCacheEntry entry, Bool skip_revalidate) | 
| Bool | gf_cache_entry_is_shared (const DownloadedCacheEntry entry) | 
| Bool | gf_cache_is_mem (const DownloadedCacheEntry entry) | 
| FILE * | gf_cache_open_read (const DownloadedCacheEntry entry) | 
| static DownloadedCacheEntry | gf_cache_find_entry_by_url (GF_DownloadSession *sess) | 
| void | gf_cache_remove_entry_from_session (GF_DownloadSession *sess) | 
| void | gf_dm_configure_cache (GF_DownloadSession *sess) | 
| void | gf_dm_delete_cached_file_entry (const GF_DownloadManager *dm, const char *url) | 
| GF_EXPORT void | gf_dm_delete_cached_file_entry_session (const GF_DownloadSession *sess, const char *url, Bool force) | 
| GF_EXPORT GF_Err | gf_dm_set_localcache_provider (GF_DownloadManager *dm, Bool(*local_cache_url_provider_cbk)(void *udta, char *url, Bool is_cache_destroy), void *lc_udta) | 
| GF_EXPORT DownloadedCacheEntry | gf_dm_add_cache_entry (GF_DownloadManager *dm, const char *szURL, GF_Blob *blob, u64 start_range, u64 end_range, const char *mime, Bool clone_memory, u32 download_time_ms) | 
| void | gf_dm_sess_reload_cached_headers (GF_DownloadSession *sess) | 
| GF_EXPORT GF_Err | gf_dm_force_headers (GF_DownloadManager *dm, const DownloadedCacheEntry entry, const char *headers) | 
Variables | |
| static const char * | CACHE_SECTION_NAME = "cache" | 
| static const char * | CACHE_SECTION_KEY_URL = "url" | 
| static const char * | CACHE_SECTION_KEY_RANGE = "range" | 
| static const char * | CACHE_SECTION_KEY_ETAG = "ETag" | 
| static const char * | CACHE_SECTION_KEY_MIME_TYPE = "Content-Type" | 
| static const char * | CACHE_SECTION_KEY_CONTENT_SIZE = "Content-Length" | 
| static const char * | CACHE_SECTION_KEY_LAST_MODIFIED = "Last-Modified" | 
| static const char * | CACHE_SECTION_KEY_MAXAGE = "MaxAge" | 
| static const char * | CACHE_SECTION_KEY_MUST_REVALIDATE = "MustRevalidate" | 
| static const char * | CACHE_SECTION_KEY_NOCACHE = "NoCache" | 
| static const char * | CACHE_SECTION_KEY_CREATED = "Created" | 
| static const char * | CACHE_SECTION_KEY_LAST_HIT = "LastHit" | 
| static const char * | CACHE_SECTION_KEY_NUM_HIT = "NumHit" | 
| static const char * | CACHE_SECTION_KEY_INWRITE = "InWrite" | 
| static const char * | CACHE_SECTION_KEY_TODELETE = "ToDelete" | 
| static const char * | CACHE_SECTION_USERS = "users" | 
| static const char * | cache_file_prefix = "gpac_cache_" | 
| static const char * | default_cache_file_suffix = ".dat" | 
| static const char * | cache_file_info_suffix = ".txt" | 
| struct __DownloadedCacheEntryStruct | 
This opaque structure handles the data from the cache
 Collaboration diagram for __DownloadedCacheEntryStruct:| Data Fields | ||
|---|---|---|
| char * | url | |
| char * | hash | |
| char * | cache_filename | |
| char * | cfg_filename | |
| u32 | contentLength | |
| u32 | cacheSize | |
| char * | serverLastModified | |
| char * | diskLastModified | |
| char * | serverETag | |
| char * | diskETag | |
| char * | mimeType | |
| FILE * | writeFilePtr | |
| u32 | written_in_cache | |
| enum CacheValid | flags | |
| const GF_DownloadSession * | write_session | |
| GF_List * | sessions | |
| Bool | discard_on_delete | |
| u64 | max_age | |
| Bool | must_revalidate | |
| Bool | other_in_use | |
| u64 | range_start | |
| u64 | range_end | |
| Bool | continue_file | |
| u32 | previousRangeContentLength | |
| Bool | headers_done | |
| Bool | memory_stored | |
| u32 | mem_allocated | |
| u8 * | mem_storage | |
| GF_Blob | cache_blob | |
| GF_Blob * | external_blob | |
| char * | forced_headers | |
| u32 | downtime | |
| Bool | persistent | |
| struct CacheInfo | 
| struct CacheGather | 
| Data Fields | ||
|---|---|---|
| GF_List * | files | |
| u64 | tot_size | |
| #define CHECK_ENTRY if (!entry) { GF_LOG(GF_LOG_WARNING, GF_LOG_CACHE, ("[CACHE] entry is null at " __FILE__ ":%d\n", __LINE__)); return GF_BAD_PARAM; } | 
| #define _CACHE_HASH_SIZE 20 | 
| #define _CACHE_MAX_EXTENSION_SIZE 6 | 
| enum CacheValid | 
| Bool gf_cache_entry_persistent | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| void gf_cache_entry_set_persistent | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:
      
  | 
  static | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
      
  | 
  static | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
 Here is the call graph for this function:
 Here is the caller graph for this function:| void gf_cache_entry_set_delete_files_when_deleted | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| const char * gf_cache_get_etag_on_server | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| const char * gf_cache_get_mime_type | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| GF_Err gf_cache_set_headers_processed | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| Bool gf_cache_are_headers_processed | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| GF_Err gf_cache_set_etag_on_server | ( | const DownloadedCacheEntry | entry, | 
| const char * | eTag | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| GF_Err gf_cache_set_etag_on_disk | ( | const DownloadedCacheEntry | entry, | 
| const char * | eTag | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| GF_Err gf_cache_set_mime_type | ( | const DownloadedCacheEntry | entry, | 
| const char * | mime_type | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| u64 gf_cache_get_start_range | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| u64 gf_cache_get_end_range | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| const char * gf_cache_get_url | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| const char * gf_cache_get_last_modified_on_server | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| GF_Err gf_cache_set_last_modified_on_server | ( | const DownloadedCacheEntry | entry, | 
| const char * | newLastModified | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| GF_Err gf_cache_set_last_modified_on_disk | ( | const DownloadedCacheEntry | entry, | 
| const char * | newLastModified | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
      
  | 
  static | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
 Here is the call graph for this function:
 Here is the caller graph for this function:| u32 gf_cache_get_cache_filesize | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| const char * gf_cache_get_cache_filename | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| GF_Err gf_cache_get_http_headers | ( | const DownloadedCacheEntry | entry, | 
| const char ** | etag, | ||
| const char ** | last_modif | ||
| ) | 
 Here is the caller graph for this function:
      
  | 
  static | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| DownloadedCacheEntry gf_cache_create_entry | ( | const char * | cache_directory, | 
| const char * | url, | ||
| u64 | start_range, | ||
| u64 | end_range, | ||
| Bool | mem_storage, | ||
| GF_Mutex * | mx | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
 Here is the caller graph for this function:| u32 gf_cache_get_content_length | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| GF_Err gf_cache_close_write_cache | ( | const DownloadedCacheEntry | entry, | 
| const GF_DownloadSession * | sess, | ||
| Bool | success | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| GF_Err gf_cache_open_write_cache | ( | const DownloadedCacheEntry | entry, | 
| const GF_DownloadSession * | sess | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| GF_Err gf_cache_write_to_cache | ( | const DownloadedCacheEntry | entry, | 
| const GF_DownloadSession * | sess, | ||
| const char * | data, | ||
| const u32 | size, | ||
| GF_Mutex * | mx | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| void gf_cache_delete_entry | ( | const DownloadedCacheEntry | entry | ) | 
Cache should have been close before, abornormal situation
 Here is the call graph for this function:
 Here is the caller graph for this function:| s32 gf_cache_remove_session_from_cache_entry | ( | DownloadedCacheEntry | entry, | 
| GF_DownloadSession * | sess | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
 Here is the call graph for this function:
 Here is the caller graph for this function:
      
  | 
  static | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| s32 gf_cache_add_session_to_cache_entry | ( | DownloadedCacheEntry | entry, | 
| GF_DownloadSession * | sess | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| void gf_cache_set_end_range | ( | DownloadedCacheEntry | entry, | 
| u64 | range_end | ||
| ) | 
 Here is the caller graph for this function:| Bool gf_cache_is_in_progress | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| Bool gf_cache_set_mime | ( | const DownloadedCacheEntry | entry, | 
| const char * | mime | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| Bool gf_cache_set_range | ( | const DownloadedCacheEntry | entry, | 
| u64 | size, | ||
| u64 | start_range, | ||
| u64 | end_range | ||
| ) | 
 Here is the caller graph for this function:| Bool gf_cache_set_headers | ( | const DownloadedCacheEntry | entry, | 
| const char * | headers | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| char * gf_cache_get_forced_headers | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| void gf_cache_set_downtime | ( | const DownloadedCacheEntry | entry, | 
| u32 | download_time_ms | ||
| ) | 
 Here is the caller graph for this function:| u32 gf_cache_get_downtime | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| u32 gf_cache_is_done | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| const u8 * gf_cache_get_content | ( | const DownloadedCacheEntry | entry, | 
| u32 * | size, | ||
| u32 * | max_valid_size, | ||
| Bool * | was_modified | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| void gf_cache_release_content | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| Bool gf_cache_is_deleted | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| Bool gf_cache_set_content | ( | const DownloadedCacheEntry | entry, | 
| GF_Blob * | blob, | ||
| Bool | copy, | ||
| GF_Mutex * | mx | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
      
  | 
  static | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| Bool gf_cache_entry_is_shared | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| Bool gf_cache_is_mem | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the caller graph for this function:| FILE * gf_cache_open_read | ( | const DownloadedCacheEntry | entry | ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
      
  | 
  static | 
Finds an existing entry in the cache for a given URL
| sess | The session configured with the URL | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| void gf_cache_remove_entry_from_session | ( | GF_DownloadSession * | sess | ) | 
Removes a cache entry from cache and performs a cleanup if possible. If the cache entry is marked for deletion and has no sessions associated with it, it will be removed (so some modules using a streaming like cache will still work).
 Here is the call graph for this function:
 Here is the caller graph for this function:| void gf_dm_configure_cache | ( | GF_DownloadSession * | sess | ) | 
indicate we can destroy file upon destruction, except if disabled at session level
 Here is the call graph for this function:
 Here is the caller graph for this function:| void gf_dm_delete_cached_file_entry | ( | const GF_DownloadManager * | dm, | 
| const char * | url | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| GF_EXPORT void gf_dm_delete_cached_file_entry_session | ( | const GF_DownloadSession * | sess, | 
| const char * | url, | ||
| Bool | force | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| GF_EXPORT GF_Err gf_dm_set_localcache_provider | ( | GF_DownloadManager * | dm, | 
| Bool(*)(void *udta, char *url, Bool is_cache_destroy) | local_cache_url_provider_cbk, | ||
| void * | lc_udta | ||
| ) | 
 Here is the caller graph for this function:| GF_EXPORT DownloadedCacheEntry gf_dm_add_cache_entry | ( | GF_DownloadManager * | dm, | 
| const char * | szURL, | ||
| GF_Blob * | blob, | ||
| u64 | start_range, | ||
| u64 | end_range, | ||
| const char * | mime, | ||
| Bool | clone_memory, | ||
| u32 | download_time_ms | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| void gf_dm_sess_reload_cached_headers | ( | GF_DownloadSession * | sess | ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:| GF_EXPORT GF_Err gf_dm_force_headers | ( | GF_DownloadManager * | dm, | 
| const DownloadedCacheEntry | entry, | ||
| const char * | headers | ||
| ) | 
 Here is the call graph for this function:
 Here is the caller graph for this function:
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static | 
      
  | 
  static |