2018-07-26 11:29:44 +02:00
|
|
|
#ifndef LINK_H
|
|
|
|
#define LINK_H
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2019-04-19 15:57:22 +02:00
|
|
|
/** \brief the maximum length of the URL */
|
2018-07-26 11:29:44 +02:00
|
|
|
#define URL_LEN_MAX 2048
|
2019-04-19 15:57:22 +02:00
|
|
|
/** \brief the maximum length of a partial URL (a link) */
|
2019-04-22 14:32:15 +02:00
|
|
|
#define LINKNAME_LEN_MAX 255
|
2018-07-26 11:29:44 +02:00
|
|
|
|
|
|
|
/** \brief the link type */
|
|
|
|
typedef enum {
|
|
|
|
LINK_HEAD = 'H',
|
|
|
|
LINK_DIR = 'D',
|
|
|
|
LINK_FILE = 'F',
|
|
|
|
LINK_INVALID = '\0'
|
|
|
|
} LinkType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief link table type
|
|
|
|
* \details index 0 contains the Link for the base URL
|
|
|
|
*/
|
|
|
|
typedef struct LinkTable LinkTable;
|
|
|
|
|
|
|
|
/** \brief link data type */
|
|
|
|
typedef struct Link Link;
|
|
|
|
|
2019-04-22 13:06:34 +02:00
|
|
|
/**
|
|
|
|
* \brief Link data structure
|
|
|
|
*/
|
2018-07-26 11:29:44 +02:00
|
|
|
struct Link {
|
2019-04-22 14:32:15 +02:00
|
|
|
char linkname[LINKNAME_LEN_MAX]; /**< The link name in the last level of
|
2019-04-23 12:38:08 +02:00
|
|
|
the URL */
|
|
|
|
char f_url[URL_LEN_MAX]; /**< The full URL of the file */
|
2019-04-22 13:06:34 +02:00
|
|
|
LinkType type; /**< The type of the link */
|
|
|
|
size_t content_length; /**< CURLINFO_CONTENT_LENGTH_DOWNLOAD of the file */
|
|
|
|
LinkTable *next_table; /**< The next LinkTable level, if it is a LINK_DIR */
|
2019-04-23 12:38:08 +02:00
|
|
|
long time; /**< CURLINFO_FILETIME obtained from the server */
|
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-04-22 13:06:34 +02:00
|
|
|
/**
|
|
|
|
* \brief set the stats for a file
|
|
|
|
*/
|
2018-07-26 11:29:44 +02:00
|
|
|
void Link_set_stat(Link* this_link, CURL *curl);
|
|
|
|
|
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);
|
|
|
|
|
2018-07-26 11:29:44 +02:00
|
|
|
|
|
|
|
#endif
|