2018-07-26 11:29:44 +02:00
|
|
|
#ifndef LINK_H
|
|
|
|
#define LINK_H
|
|
|
|
|
2019-09-01 09:52:18 +02:00
|
|
|
/**
|
|
|
|
* \file link.h
|
|
|
|
* \brief link related structures and functions
|
|
|
|
*/
|
2021-08-22 01:51:37 +02:00
|
|
|
#include "config.h"
|
2019-04-26 08:39:45 +02:00
|
|
|
#include "util.h"
|
|
|
|
#include <curl/curl.h>
|
2018-07-26 11:29:44 +02:00
|
|
|
|
2019-09-01 01:43:50 +02:00
|
|
|
/** \brief Link type */
|
|
|
|
typedef struct Link Link;
|
|
|
|
|
|
|
|
#include "cache.h"
|
|
|
|
|
2018-07-26 11:29:44 +02:00
|
|
|
/** \brief the link type */
|
|
|
|
typedef enum {
|
|
|
|
LINK_HEAD = 'H',
|
|
|
|
LINK_DIR = 'D',
|
|
|
|
LINK_FILE = 'F',
|
2019-09-03 23:11:23 +02:00
|
|
|
LINK_INVALID = 'I',
|
|
|
|
LINK_UNINITIALISED_FILE = 'U'
|
2018-07-26 11:29:44 +02:00
|
|
|
} LinkType;
|
|
|
|
|
2019-10-22 01:42:46 +02:00
|
|
|
/** \brief for storing downloaded data in memory */
|
|
|
|
typedef struct {
|
2019-10-22 21:26:21 +02:00
|
|
|
char *data;
|
2019-10-22 01:42:46 +02:00
|
|
|
size_t size;
|
2019-10-22 21:26:21 +02:00
|
|
|
} DataStruct;
|
2019-10-22 01:42:46 +02:00
|
|
|
|
|
|
|
/** \brief specify the type of data transfer */
|
|
|
|
typedef enum {
|
|
|
|
FILESTAT = 's',
|
|
|
|
DATA = 'd'
|
|
|
|
} TransferType;
|
|
|
|
|
|
|
|
/** \brief for storing the link being transferred, and metadata */
|
|
|
|
typedef struct {
|
|
|
|
TransferType type;
|
|
|
|
int transferring;
|
|
|
|
Link *link;
|
|
|
|
} TransferStruct;
|
|
|
|
|
2018-07-26 11:29:44 +02:00
|
|
|
/**
|
|
|
|
* \brief link table type
|
|
|
|
* \details index 0 contains the Link for the base URL
|
|
|
|
*/
|
|
|
|
typedef struct LinkTable LinkTable;
|
|
|
|
|
2019-04-22 13:06:34 +02:00
|
|
|
/**
|
2019-09-01 01:43:50 +02:00
|
|
|
* \brief Link type data structure
|
2019-04-22 13:06:34 +02:00
|
|
|
*/
|
2018-07-26 11:29:44 +02:00
|
|
|
struct Link {
|
2019-09-01 12:39:47 +02:00
|
|
|
/** \brief The link name in the last level of the URL */
|
|
|
|
char linkname[MAX_FILENAME_LEN+1];
|
|
|
|
/** \brief The full URL of the file */
|
|
|
|
char f_url[MAX_PATH_LEN+1];
|
|
|
|
/** \brief The type of the link */
|
|
|
|
LinkType type;
|
|
|
|
/** \brief CURLINFO_CONTENT_LENGTH_DOWNLOAD of the file */
|
|
|
|
size_t content_length;
|
|
|
|
/** \brief The next LinkTable level, if it is a LINK_DIR */
|
|
|
|
LinkTable *next_table;
|
|
|
|
/** \brief CURLINFO_FILETIME obtained from the server */
|
|
|
|
long time;
|
|
|
|
/** \brief How many times associated cache has been opened */
|
|
|
|
int cache_opened;
|
|
|
|
/** \brief The pointer associated with the cache file */
|
|
|
|
Cache *cache_ptr;
|
2019-10-21 04:28:57 +02:00
|
|
|
/**
|
2019-10-27 22:21:30 +01:00
|
|
|
* \brief Sonic id field
|
|
|
|
* \details This is used to store the followings:
|
|
|
|
* - Arist ID
|
|
|
|
* - Album ID
|
|
|
|
* - Song ID
|
|
|
|
* - Sub-directory ID (in the XML response, this is the ID on the "child"
|
|
|
|
* element)
|
2019-10-21 04:28:57 +02:00
|
|
|
*/
|
2019-10-28 02:09:55 +01:00
|
|
|
char *sonic_id;
|
2019-10-24 01:44:18 +02:00
|
|
|
/**
|
2019-10-27 22:21:30 +01:00
|
|
|
* \brief Sonic directory depth
|
|
|
|
* \details This is used exclusively in ID3 mode to store the depth of the
|
|
|
|
* current directory.
|
2019-10-24 01:44:18 +02:00
|
|
|
*/
|
2019-10-27 22:21:30 +01:00
|
|
|
int sonic_depth;
|
2018-07-26 11:29:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LinkTable {
|
|
|
|
int num;
|
|
|
|
Link **links;
|
|
|
|
};
|
|
|
|
|
2019-04-22 13:06:34 +02:00
|
|
|
/**
|
|
|
|
* \brief root link table
|
|
|
|
*/
|
2018-07-26 11:29:44 +02:00
|
|
|
extern LinkTable *ROOT_LINK_TBL;
|
|
|
|
|
2019-04-22 14:32:15 +02:00
|
|
|
/**
|
2019-04-22 16:26:25 +02:00
|
|
|
* \brief the offset for calculating partial URL
|
2019-04-22 14:32:15 +02:00
|
|
|
*/
|
2019-04-22 16:26:25 +02:00
|
|
|
extern int ROOT_LINK_OFFSET;
|
2019-04-22 14:32:15 +02:00
|
|
|
|
2019-08-31 22:21:28 +02:00
|
|
|
/**
|
|
|
|
* \brief initialise link sub-system.
|
|
|
|
*/
|
2019-10-27 22:21:30 +01:00
|
|
|
LinkTable *LinkSystem_init(const char *raw_url);
|
2019-08-31 22:21:28 +02:00
|
|
|
|
2019-04-26 15:14:42 +02:00
|
|
|
/**
|
2019-09-01 09:52:18 +02:00
|
|
|
* \brief Add a link to the curl multi bundle for querying stats
|
2019-04-26 15:14:42 +02:00
|
|
|
*/
|
2019-09-03 23:11:23 +02:00
|
|
|
void Link_req_file_stat(Link *this_link);
|
2019-04-26 15:14:42 +02:00
|
|
|
|
2019-04-22 13:06:34 +02:00
|
|
|
/**
|
2019-09-01 09:52:18 +02:00
|
|
|
* \brief Set the stats of a link, after curl multi handle finished querying
|
2019-04-22 13:06:34 +02:00
|
|
|
*/
|
2019-09-03 23:11:23 +02:00
|
|
|
void Link_set_file_stat(Link* this_link, CURL *curl);
|
2018-07-26 11:29:44 +02:00
|
|
|
|
2019-04-22 13:06:34 +02:00
|
|
|
/**
|
|
|
|
* \brief create a new LinkTable
|
|
|
|
*/
|
2018-07-26 11:29:44 +02:00
|
|
|
LinkTable *LinkTable_new(const char *url);
|
|
|
|
|
2019-04-22 13:06:34 +02:00
|
|
|
/**
|
|
|
|
* \brief download a link
|
|
|
|
* \return the number of bytes downloaded
|
2018-07-26 11:29:44 +02:00
|
|
|
*/
|
|
|
|
long path_download(const char *path, char *output_buf, size_t size,
|
|
|
|
off_t offset);
|
|
|
|
|
2019-04-22 13:06:34 +02:00
|
|
|
/**
|
|
|
|
* \brief find the link associated with a path
|
|
|
|
*/
|
2018-07-26 11:29:44 +02:00
|
|
|
Link *path_to_Link(const char *path);
|
|
|
|
|
2019-04-22 13:06:34 +02:00
|
|
|
/**
|
|
|
|
* \brief return the link table for the associated path
|
|
|
|
*/
|
|
|
|
LinkTable *path_to_Link_LinkTable_new(const char *path);
|
|
|
|
|
2019-04-26 08:39:45 +02:00
|
|
|
/**
|
|
|
|
* \brief dump a link table to the disk.
|
|
|
|
*/
|
|
|
|
int LinkTable_disk_save(LinkTable *linktbl, const char *dirn);
|
2018-07-26 11:29:44 +02:00
|
|
|
|
2019-04-26 08:39:45 +02:00
|
|
|
/**
|
|
|
|
* \brief load a link table from the disk.
|
|
|
|
*/
|
|
|
|
LinkTable *LinkTable_disk_open(const char *dirn);
|
2019-10-22 01:42:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Download a link's content to the memory
|
2019-10-22 21:26:21 +02:00
|
|
|
* \warning You MUST free the memory field in DataStruct after use!
|
2019-10-22 01:42:46 +02:00
|
|
|
*/
|
2019-10-22 21:26:21 +02:00
|
|
|
DataStruct Link_to_DataStruct(Link *head_link);
|
2019-10-22 01:42:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Allocate a LinkTable
|
|
|
|
* \note This does not fill in the LinkTable.
|
|
|
|
*/
|
|
|
|
LinkTable *LinkTable_alloc(const char *url);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief free a LinkTable
|
|
|
|
*/
|
|
|
|
void LinkTable_free(LinkTable *linktbl);
|
|
|
|
|
2019-10-22 02:13:28 +02:00
|
|
|
/**
|
|
|
|
* \brief print a LinkTable
|
|
|
|
*/
|
|
|
|
void LinkTable_print(LinkTable *linktbl);
|
|
|
|
|
2019-10-23 22:04:25 +02:00
|
|
|
/**
|
|
|
|
* \brief add a Link to a LinkTable
|
|
|
|
*/
|
|
|
|
void LinkTable_add(LinkTable *linktbl, Link *link);
|
2018-07-26 11:29:44 +02:00
|
|
|
#endif
|