2018-07-26 11:29:44 +02:00
|
|
|
#ifndef LINK_H
|
|
|
|
#define LINK_H
|
|
|
|
|
2019-04-26 08:39:45 +02:00
|
|
|
#include "util.h"
|
2018-07-26 11:29:44 +02:00
|
|
|
|
2019-04-26 08:39:45 +02:00
|
|
|
#include <curl/curl.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-04-26 20:30:39 +02:00
|
|
|
LINK_INVALID = 'I'
|
2018-07-26 11:29:44 +02:00
|
|
|
} 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-26 08:39:45 +02:00
|
|
|
char linkname[MAX_FILENAME_LEN]; /**< The link name in the last level of
|
2019-04-23 12:38:08 +02:00
|
|
|
the URL */
|
2019-04-26 08:39:45 +02:00
|
|
|
char f_url[MAX_PATH_LEN]; /**< 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-26 15:14:42 +02:00
|
|
|
/**
|
|
|
|
* \brief
|
|
|
|
*/
|
|
|
|
void Link_get_stat(Link *this_link);
|
|
|
|
|
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);
|
|
|
|
|
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);
|
2018-07-26 11:29:44 +02:00
|
|
|
#endif
|