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
|
|
|
|
*/
|
2018-07-26 11:29:44 +02:00
|
|
|
|
2019-09-01 01:43:50 +02:00
|
|
|
typedef struct Link Link;
|
2021-09-01 22:29:13 +02:00
|
|
|
typedef struct LinkTable LinkTable;
|
2019-09-01 01:43:50 +02:00
|
|
|
|
2021-09-03 22:39:31 +02:00
|
|
|
#include "cache.h"
|
2021-09-01 22:29:13 +02:00
|
|
|
#include "config.h"
|
2021-09-03 22:39:31 +02:00
|
|
|
#include "network.h"
|
2021-09-03 22:23:52 +02:00
|
|
|
#include "sonic.h"
|
2021-09-03 22:39:31 +02:00
|
|
|
|
2021-09-01 22:29:13 +02:00
|
|
|
#include <curl/curl.h>
|
2019-09-01 01:43:50 +02:00
|
|
|
|
2021-09-01 22:29:13 +02:00
|
|
|
/**
|
|
|
|
* \brief the link type
|
|
|
|
*/
|
2018-07-26 11:29:44 +02:00
|
|
|
typedef enum {
|
2021-08-31 12:18:39 +02:00
|
|
|
LINK_HEAD = 'H',
|
|
|
|
LINK_DIR = 'D',
|
|
|
|
LINK_FILE = 'F',
|
|
|
|
LINK_INVALID = 'I',
|
|
|
|
LINK_UNINITIALISED_FILE = 'U'
|
2018-07-26 11:29:44 +02:00
|
|
|
} LinkType;
|
|
|
|
|
2021-09-02 16:36:53 +02:00
|
|
|
/**
|
|
|
|
* \brief link table type
|
|
|
|
* \details index 0 contains the Link for the base URL
|
|
|
|
*/
|
|
|
|
struct LinkTable {
|
|
|
|
int num;
|
|
|
|
Link **links;
|
|
|
|
};
|
|
|
|
|
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 */
|
2021-08-31 12:18:39 +02:00
|
|
|
char linkname[MAX_FILENAME_LEN + 1];
|
2019-09-01 12:39:47 +02:00
|
|
|
/** \brief The full URL of the file */
|
2021-08-31 12:18:39 +02:00
|
|
|
char f_url[MAX_PATH_LEN + 1];
|
2019-09-01 12:39:47 +02:00
|
|
|
/** \brief The type of the link */
|
2021-08-31 12:18:39 +02:00
|
|
|
LinkType type;
|
2019-09-01 12:39:47 +02:00
|
|
|
/** \brief CURLINFO_CONTENT_LENGTH_DOWNLOAD of the file */
|
2021-08-31 12:18:39 +02:00
|
|
|
size_t content_length;
|
2019-09-01 12:39:47 +02:00
|
|
|
/** \brief The next LinkTable level, if it is a LINK_DIR */
|
2021-08-31 12:18:39 +02:00
|
|
|
LinkTable *next_table;
|
2019-09-01 12:39:47 +02:00
|
|
|
/** \brief CURLINFO_FILETIME obtained from the server */
|
2021-08-31 12:18:39 +02:00
|
|
|
long time;
|
2019-09-01 12:39:47 +02:00
|
|
|
/** \brief The pointer associated with the cache file */
|
2021-08-31 12:18:39 +02:00
|
|
|
Cache *cache_ptr;
|
2021-09-01 22:29:13 +02:00
|
|
|
/** \brief Stores *sonic related data */
|
|
|
|
Sonic sonic;
|
2018-07-26 11:29:44 +02:00
|
|
|
};
|
|
|
|
|
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-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
|
|
|
*/
|
2021-09-03 15:56:11 +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
|
|
|
/**
|
2021-09-02 16:36:53 +02:00
|
|
|
* \brief download a path
|
2019-04-22 13:06:34 +02:00
|
|
|
* \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);
|
|
|
|
|
2021-09-02 16:36:53 +02:00
|
|
|
/**
|
|
|
|
* \brief Download a Link
|
|
|
|
* \return the number of bytes downloaded
|
|
|
|
*/
|
2021-09-03 15:56:11 +02:00
|
|
|
long Link_download(Link *link, char *output_buf, size_t req_size,
|
2021-09-03 13:47:48 +02:00
|
|
|
off_t offset);
|
2021-09-02 16:36:53 +02:00
|
|
|
|
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.
|
|
|
|
*/
|
2021-09-03 15:56:11 +02:00
|
|
|
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
|
2021-09-01 12:56:18 +02:00
|
|
|
* \warning You MUST free the memory field in TransferStruct after use!
|
2019-10-22 01:42:46 +02:00
|
|
|
*/
|
2021-09-03 15:56:11 +02:00
|
|
|
TransferStruct Link_download_full(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
|
|
|
|
*/
|
2021-09-03 15:56:11 +02:00
|
|
|
void LinkTable_free(LinkTable *linktbl);
|
2019-10-22 01:42:46 +02:00
|
|
|
|
2019-10-22 02:13:28 +02:00
|
|
|
/**
|
|
|
|
* \brief print a LinkTable
|
|
|
|
*/
|
2021-09-03 15:56:11 +02:00
|
|
|
void LinkTable_print(LinkTable *linktbl);
|
2019-10-22 02:13:28 +02:00
|
|
|
|
2019-10-23 22:04:25 +02:00
|
|
|
/**
|
|
|
|
* \brief add a Link to a LinkTable
|
|
|
|
*/
|
2021-09-03 15:56:11 +02:00
|
|
|
void LinkTable_add(LinkTable *linktbl, Link *link);
|
2018-07-26 11:29:44 +02:00
|
|
|
#endif
|