GPAC
Open Source Multimedia Framework. For more information, check out http://gpac.wp.mines-telecom.fr
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups
downloader.c File Reference
#include <gpac/download.h>
#include <gpac/network.h>
#include <gpac/token.h>
#include <gpac/thread.h>
#include <gpac/list.h>
#include <gpac/base_coding.h>
#include <gpac/tools.h>
#include <gpac/cache.h>
+ Include dependency graph for downloader.c:

Data Structures

struct  gf_user_credentials_struct
 
struct  GF_HTTPHeader
 
struct  GF_PartialDownload
 
struct  GF_DownloadSession
 
struct  GF_DownloadManager
 

Macros

#define SIZE_IN_STREAM   ( 2 << 29 )
 
#define SESSION_RETRY_COUNT   20
 
#define GF_DOWNLOAD_AGENT_NAME   "GPAC/" GPAC_FULL_VERSION
 
#define GF_DOWNLOAD_BUFFER_SIZE   131072
 
#define GF_WAIT_REPLY_SLEEP   20
 

Enumerations

enum  { GF_DOWNLOAD_SESSION_USE_SSL = 1<<10, GF_DOWNLOAD_SESSION_THREAD_DEAD = 1<<11 }
 
enum  REQUEST_TYPE { GET = 0, HEAD = 1, OTHER = 2 }
 

Functions

static void gf_dm_connect (GF_DownloadSession *sess)
 
GF_Err gf_cache_write_to_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess, const char *data, const u32 size)
 Write data to cache Writes data to the cache. A call to gf_cache_open_write_cache should have been issued before calling this function. More...
 
GF_Err gf_cache_close_write_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess, Bool success)
 Close the write file pointer of cache This function also flushes all buffers, so cache will always be consistent after. More...
 
GF_Err gf_cache_open_write_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess)
 Open the write file pointer of cache This function prepares calls for gf_cache_write_to_cache. More...
 
FILE * gf_cache_get_file_pointer (const DownloadedCacheEntry entry)
 Returns write file pointer This function returns the current cache file pointer. More...
 
void gf_cache_set_end_range (DownloadedCacheEntry entry, u64 range_end)
 
Bool gf_cache_is_in_progress (const DownloadedCacheEntry entry)
 
static gf_user_credentials_structgf_find_user_credentials_for_site (GF_DownloadManager *dm, const char *server_name)
 
static GF_Err gf_user_credentials_save_digest (GF_DownloadManager *dm, gf_user_credentials_struct *creds, const char *password)
 Saves the digest for authentication of password and username. More...
 
static GF_Err gf_user_credentials_ask_password (GF_DownloadManager *dm, gf_user_credentials_struct *creds)
 Asks the user for credentials for given site. More...
 
static gf_user_credentials_structgf_user_credentials_register (GF_DownloadManager *dm, const char *server_name, const char *username, const char *password, Bool valid)
 
static Bool gf_dm_is_local (GF_DownloadManager *dm, const char *url)
 
static Bool gf_dm_can_handle_url (GF_DownloadManager *dm, const char *url)
 
DownloadedCacheEntry gf_dm_find_cached_entry_by_url (GF_DownloadSession *sess)
 
DownloadedCacheEntry gf_cache_create_entry (GF_DownloadManager *dm, const char *cache_directory, const char *url, u64 start_range, u64 end_range, Bool mem_storage)
 
s32 gf_cache_remove_session_from_cache_entry (DownloadedCacheEntry entry, GF_DownloadSession *sess)
 
void gf_dm_remove_cache_entry_from_session (GF_DownloadSession *sess)
 
s32 gf_cache_add_session_to_cache_entry (DownloadedCacheEntry entry, 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)
 Marks the cache file to be deleted once the file is not used anymore by any session. More...
 
void gf_dm_delete_cached_file_entry_session (const GF_DownloadSession *sess, const char *url)
 
static void gf_dm_clear_headers (GF_DownloadSession *sess)
 
static void gf_dm_disconnect (GF_DownloadSession *sess, Bool force_close)
 
void gf_dm_sess_del (GF_DownloadSession *sess)
 
void http_do_requests (GF_DownloadSession *sess)
 
static void gf_dm_sess_notify_state (GF_DownloadSession *sess, u32 dnload_status, GF_Err error)
 
static void gf_dm_sess_user_io (GF_DownloadSession *sess, GF_NETIO_Parameter *par)
 
Bool gf_dm_is_thread_dead (GF_DownloadSession *sess)
 is download manager thread dead? More...
 
GF_Err gf_dm_sess_last_error (GF_DownloadSession *sess)
 gets last session error More...
 
void gf_dm_url_info_init (GF_URL_Info *info)
 
void gf_dm_url_info_del (GF_URL_Info *info)
 
static s32 gf_dm_parse_protocol (const char *url, GF_URL_Info *info)
 
GF_Err gf_dm_get_url_info (const char *url, GF_URL_Info *info, const char *baseURL)
 
GF_Err gf_dm_sess_setup_from_url (GF_DownloadSession *sess, const char *url)
 
static u32 gf_dm_session_thread (void *par)
 
GF_DownloadSession * gf_dm_sess_new_simple (GF_DownloadManager *dm, const char *url, u32 dl_flags, gf_dm_user_io user_io, void *usr_cbk, GF_Err *e)
 download session simple constructor More...
 
GF_DownloadSession * gf_dm_sess_new (GF_DownloadManager *dm, const char *url, u32 dl_flags, gf_dm_user_io user_io, void *usr_cbk, GF_Err *e)
 download session constructor More...
 
static GF_Err gf_dm_read_data (GF_DownloadSession *sess, char *data, u32 data_size, u32 *out_read)
 
DownloadedCacheEntry gf_dm_refresh_cache_entry (GF_DownloadSession *sess)
 forces the refresh of a cache entry The entry is still allocated in the session. More...
 
const char * gf_dm_sess_mime_type (GF_DownloadSession *sess)
 get mime type as lower case More...
 
GF_Err gf_dm_sess_set_range (GF_DownloadSession *sess, u64 start_range, u64 end_range, Bool discontinue_cache)
 sets session range More...
 
GF_Err gf_dm_sess_process (GF_DownloadSession *sess)
 fetch session object More...
 
GF_Err gf_dm_sess_process_headers (GF_DownloadSession *sess)
 fetch session object headers More...
 
static Bool gf_dm_needs_to_delete_cache (GF_DownloadManager *dm)
 
GF_DownloadManager * gf_dm_new (GF_Config *cfg)
 download manager constructor More...
 
void gf_dm_set_auth_callback (GF_DownloadManager *dm, Bool(*GetUserPassword)(void *usr_cbk, const char *site_url, char *usr_name, char *password), void *usr_cbk)
 
void gf_dm_del (GF_DownloadManager *dm)
 
static void gf_icy_skip_data (GF_DownloadSession *sess, u32 icy_metaint, const char *data, u32 nbBytes)
 
static u8gf_dm_get_chunk_data (GF_DownloadSession *sess, u8 *body_start, u32 *payload_size, u32 *header_size)
 
static void gf_dm_data_received (GF_DownloadSession *sess, u8 *payload, u32 payload_size, Bool store_in_init, u32 *rewrite_size)
 
GF_Err gf_dm_sess_fetch_data (GF_DownloadSession *sess, char *buffer, u32 buffer_size, u32 *read_size)
 fetches data on session More...
 
GF_Err gf_dm_sess_get_stats (GF_DownloadSession *sess, const char **server, const char **path, u32 *total_size, u32 *bytes_done, u32 *bytes_per_sec, u32 *net_status)
 get statistics More...
 
u64 gf_dm_sess_get_utc_start (GF_DownloadSession *sess)
 get start time More...
 
const char * gf_dm_sess_get_cache_name (GF_DownloadSession *sess)
 get cache file name More...
 
Bool gf_dm_sess_can_be_cached_on_disk (const GF_DownloadSession *sess)
 
void gf_dm_sess_abort (GF_DownloadSession *sess)
 aborts downloading More...
 
void * gf_dm_sess_get_private (GF_DownloadSession *sess)
 gets private data More...
 
void gf_dm_sess_set_private (GF_DownloadSession *sess, void *private_data)
 sets private data More...
 
static u32 http_skip_space (char *val)
 
static char * http_is_header (char *line, char *header_name)
 
static GF_Err http_send_headers (GF_DownloadSession *sess, char *sHTTP)
 
static GF_Err http_parse_remaining_body (GF_DownloadSession *sess, char *sHTTP)
 
static void notify_headers (GF_DownloadSession *sess, char *sHTTP, s32 bytesRead, s32 BodyStart)
 
static GF_Err wait_for_header_and_parse (GF_DownloadSession *sess, char *sHTTP)
 
static void wget_NetIO (void *cbk, GF_NETIO_Parameter *param)
 
GF_Err gf_dm_wget (const char *url, const char *filename, u64 start_range, u64 end_range)
 Same as gf_dm_wget_with_cache, but initializes the GF_DownloadManager by itself. This function is deprecated, please use gf_dm_wget_with_cache instead. More...
 
GF_Err gf_dm_wget_with_cache (GF_DownloadManager *dm, const char *url, const char *filename, u64 start_range, u64 end_range)
 Download a file over the network using a download manager. More...
 
GF_Err gf_dm_get_file_memory (const char *url, char **out_data, u32 *out_size, char **out_mime)
 
const char * gf_dm_sess_get_resource_name (GF_DownloadSession *dnload)
 Get session resource url. More...
 
const char * gf_dm_sess_get_original_resource_name (GF_DownloadSession *dnload)
 Get session original resource url. More...
 
u32 gf_dm_sess_get_status (GF_DownloadSession *dnload)
 fetch session status More...
 
GF_Err gf_dm_sess_reset (GF_DownloadSession *sess)
 Reset session. More...
 
const char * gf_cache_get_cache_filename_range (const GF_DownloadSession *sess, u64 startOffset, u64 endOffset)
 
GF_Err gf_dm_sess_reassign (GF_DownloadSession *sess, u32 flags, gf_dm_user_io user_io, void *cbk)
 
void gf_dm_set_data_rate (GF_DownloadManager *dm, u32 rate_in_bits_per_sec)
 
u32 gf_dm_get_data_rate (GF_DownloadManager *dm)
 
const char * gf_dm_sess_get_header (GF_DownloadSession *sess, const char *name)
 

Data Structure Documentation

struct gf_user_credentials_struct
+ Collaboration diagram for gf_user_credentials_struct:
Data Fields
char site[1024]
char username[50]
char digest[1024]
Bool valid
struct GF_HTTPHeader

the structure used to store an HTTP header

+ Collaboration diagram for GF_HTTPHeader:
Data Fields
char * name
char * value
struct GF_PartialDownload

This structure handles partial downloads

+ Collaboration diagram for GF_PartialDownload:
Data Fields
char * url
u64 startOffset
u64 endOffset
char * filename

Macro Definition Documentation

#define SIZE_IN_STREAM   ( 2 << 29 )
#define SESSION_RETRY_COUNT   20
#define GF_DOWNLOAD_AGENT_NAME   "GPAC/" GPAC_FULL_VERSION
#define GF_DOWNLOAD_BUFFER_SIZE   131072
#define GF_WAIT_REPLY_SLEEP   20

Enumeration Type Documentation

anonymous enum
Enumerator
GF_DOWNLOAD_SESSION_USE_SSL 
GF_DOWNLOAD_SESSION_THREAD_DEAD 
Enumerator
GET 
HEAD 
OTHER 

Function Documentation

static void gf_dm_connect ( GF_DownloadSession *  sess)
static

+ 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 
)
Parameters
entryThe entry to use
sessThe download session
datadata to write
sizenumber of elements to write
Returns
GF_OK is everything went fine, GF_BAD_PARAM if cache has not been opened, GF_IO_ERR if a failure occurs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GF_Err gf_cache_close_write_cache ( const DownloadedCacheEntry  entry,
const GF_DownloadSession *  sess,
Bool  success 
)
Parameters
entryThe entry to use
sessThe download session
success1 if cache write is success, false otherwise
Returns
GF_OK is everything went fine, GF_BAD_PARAM if entry is NULL, GF_IO_ERR if a failure occurs

+ 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 
)
Parameters
entryThe entry to use
sessThe download session
Returns
GF_OK is everything went fine, GF_BAD_PARAM if entry is NULL, GF_IO_ERR if a failure occurs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FILE* gf_cache_get_file_pointer ( const DownloadedCacheEntry  entry)
Parameters
entryThe entry to use
Returns
cache file pointer or NULL

+ 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:

static gf_user_credentials_struct* gf_find_user_credentials_for_site ( GF_DownloadManager *  dm,
const char *  server_name 
)
static

Find a User's credentials for a given site

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static GF_Err gf_user_credentials_save_digest ( GF_DownloadManager *  dm,
gf_user_credentials_struct creds,
const char *  password 
)
static
Parameters
dmThe download manager
credsThe credentials to fill
Returns
GF_OK if info has been filled, GF_BAD_PARAM if creds == NULL or dm == NULL, GF_AUTHENTICATION_FAILURE if user did not filled the info.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static GF_Err gf_user_credentials_ask_password ( GF_DownloadManager *  dm,
gf_user_credentials_struct creds 
)
static
Parameters
dmThe download manager
credsThe credentials to fill
Returns
GF_OK if info has been filled, GF_BAD_PARAM if creds == NULL or dm == NULL, GF_AUTHENTICATION_FAILURE if user did not filled the info.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static gf_user_credentials_struct* gf_user_credentials_register ( GF_DownloadManager *  dm,
const char *  server_name,
const char *  username,
const char *  password,
Bool  valid 
)
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Bool gf_dm_is_local ( GF_DownloadManager *  dm,
const char *  url 
)
static

+ Here is the caller graph for this function:

static Bool gf_dm_can_handle_url ( GF_DownloadManager *  dm,
const char *  url 
)
static

+ Here is the caller graph for this function:

DownloadedCacheEntry gf_dm_find_cached_entry_by_url ( GF_DownloadSession *  sess)

Finds an existing entry in the cache for a given URL

Parameters
sessThe session configured with the URL
Returns
NULL if none found, the DownloadedCacheEntry otherwise

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DownloadedCacheEntry gf_cache_create_entry ( GF_DownloadManager *  dm,
const char *  cache_directory,
const char *  url,
u64  start_range,
u64  end_range,
Bool  mem_storage 
)

Creates a new cache entry

Parameters
dmThe download manager to create this entry
cache_directoryThe path to the directory containing cache files
urlThe full URL
start_rangethe start of the byte range request
end_rangethe end of the byte range request
mem_storageBoolean indicating if the cache data should be stored in memory
Returns
The DownloadedCacheEntry

+ 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 
)

Removes a session for a DownloadedCacheEntry

Parameters
entryThe entry
sessThe session to remove
Returns
the number of sessions left in the cached entry, -1 if one of the parameters is wrong

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gf_dm_remove_cache_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:

s32 gf_cache_add_session_to_cache_entry ( DownloadedCacheEntry  entry,
GF_DownloadSession *  sess 
)

Adds a session to a DownloadedCacheEntry. implemented in cache.c

Parameters
entryThe entry
sessThe session to add
Returns
the number of sessions in the cached entry, -1 if one of the parameters is wrong

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gf_dm_configure_cache ( GF_DownloadSession *  sess)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void gf_dm_clear_headers ( GF_DownloadSession *  sess)
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void gf_dm_disconnect ( GF_DownloadSession *  sess,
Bool  force_close 
)
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void http_do_requests ( GF_DownloadSession *  sess)

Default performing behaviour

Parameters
sessThe session

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void gf_dm_sess_notify_state ( GF_DownloadSession *  sess,
u32  dnload_status,
GF_Err  error 
)
static

+ Here is the caller graph for this function:

static void gf_dm_sess_user_io ( GF_DownloadSession *  sess,
GF_NETIO_Parameter par 
)
static

+ Here is the caller graph for this function:

static s32 gf_dm_parse_protocol ( const char *  url,
GF_URL_Info info 
)
static
Parameters
urlThe url to parse for protocol
infoThe info to fill
Returns
Returns the offset in url of the protocol found -1 if not found

+ Here is the caller graph for this function:

static u32 gf_dm_session_thread ( void *  par)
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static GF_Err gf_dm_read_data ( GF_DownloadSession *  sess,
char *  data,
u32  data_size,
u32 out_read 
)
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Bool gf_dm_needs_to_delete_cache ( GF_DownloadManager *  dm)
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gf_dm_set_auth_callback ( GF_DownloadManager *  dm,
Bool(*)(void *usr_cbk, const char *site_url, char *usr_name, char *password)  GetUserPassword,
void *  usr_cbk 
)
static void gf_icy_skip_data ( GF_DownloadSession *  sess,
u32  icy_metaint,
const char *  data,
u32  nbBytes 
)
static

Skip ICY metadata from SHOUTCAST or ICECAST streams. Data will be skipped and parsed and sent as a GF_NETIO_Parameter to the user_io, so modules interrested by those streams may use the data

Parameters
sessThe GF_DownloadSession
icy_metaintThe number of bytes of data before reaching possible meta data
datalast data received
nbBytesThe number of bytes contained into data

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static u8* gf_dm_get_chunk_data ( GF_DownloadSession *  sess,
u8 body_start,
u32 payload_size,
u32 header_size 
)
static

+ Here is the caller graph for this function:

static void gf_dm_data_received ( GF_DownloadSession *  sess,
u8 payload,
u32  payload_size,
Bool  store_in_init,
u32 rewrite_size 
)
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static u32 http_skip_space ( char *  val)
static

+ Here is the caller graph for this function:

static char* http_is_header ( char *  line,
char *  header_name 
)
static
static GF_Err http_send_headers ( GF_DownloadSession *  sess,
char *  sHTTP 
)
static

Sends the HTTP headers

Parameters
sessThe GF_DownloadSession
sHTTPbuffer containing the request
Returns
GF_OK if everything went fine, the error otherwise

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static GF_Err http_parse_remaining_body ( GF_DownloadSession *  sess,
char *  sHTTP 
)
static

Parse the remaining part of body

Parameters
sessThe session
sHTTPthe data buffer
Returns
The error code if any

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void notify_headers ( GF_DownloadSession *  sess,
char *  sHTTP,
s32  bytesRead,
s32  BodyStart 
)
static

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static GF_Err wait_for_header_and_parse ( GF_DownloadSession *  sess,
char *  sHTTP 
)
static

Waits for the response HEADERS, parse the information... and so on

Parameters
sessThe session
sHTTPthe data buffer

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void wget_NetIO ( void *  cbk,
GF_NETIO_Parameter param 
)
static

NET IO for MPD, we don't need this anymore since mime-type can be given by session

+ Here is the call graph for this function:

+ Here is the caller graph for this function: