httpdirfs/src/link.h

149 lines
3.1 KiB
C
Raw Normal View History

2018-07-26 11:29:44 +02:00
#ifndef LINK_H
#define LINK_H
/**
* \file link.h
* \brief link related structures and functions
*/
2018-07-26 11:29:44 +02:00
typedef struct Link Link;
typedef struct LinkTable LinkTable;
2021-09-03 22:39:31 +02:00
#include "cache.h"
#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
#include <curl/curl.h>
/**
* \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;
time_t index_time;
2021-09-02 16:36:53 +02:00
Link **links;
};
/**
* \brief Link type data structure
*/
2018-07-26 11:29:44 +02:00
struct Link {
/** \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];
char linkpath[MAX_FILENAME_LEN + 1];
/** \brief The full URL of the file */
2021-08-31 12:18:39 +02:00
char f_url[MAX_PATH_LEN + 1];
/** \brief The type of the link */
2021-08-31 12:18:39 +02:00
LinkType type;
/** \brief CURLINFO_CONTENT_LENGTH_DOWNLOAD of the file */
2021-08-31 12:18:39 +02:00
size_t content_length;
/** \brief The next LinkTable level, if it is a LINK_DIR */
2021-08-31 12:18:39 +02:00
LinkTable *next_table;
/** \brief CURLINFO_FILETIME obtained from the server */
2021-08-31 12:18:39 +02:00
long time;
/** \brief The pointer associated with the cache file */
2021-08-31 12:18:39 +02:00
Cache *cache_ptr;
/** \brief Stores *sonic related data */
Sonic sonic;
2018-07-26 11:29:44 +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
/**
* \brief the offset for calculating partial URL
2019-04-22 14:32:15 +02:00
*/
extern int ROOT_LINK_OFFSET;
2019-04-22 14:32:15 +02:00
/**
* \brief initialise link sub-system.
*/
LinkTable *LinkSystem_init(const char *raw_url);
/**
* \brief Set the stats of a link, after curl multi handle finished querying
*/
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
/**
* \brief create a new LinkTable
*/
2018-07-26 11:29:44 +02:00
LinkTable *LinkTable_new(const char *url);
/**
2021-09-02 16:36:53 +02:00
* \brief download a path
* \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,
off_t offset);
2021-09-02 16:36:53 +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);
/**
* \brief return the link table for the associated path
*/
LinkTable *path_to_Link_LinkTable_new(const char *path);
/**
* \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
/**
* \brief load a link table from the disk.
*/
LinkTable *LinkTable_disk_open(const char *dirn);
/**
* \brief Download a link's content to the memory
* \warning You MUST free the memory field in TransferStruct after use!
*/
2021-09-03 15:56:11 +02:00
TransferStruct Link_download_full(Link *head_link);
/**
* \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);
/**
* \brief print a LinkTable
*/
2021-09-03 15:56:11 +02:00
void LinkTable_print(LinkTable *linktbl);
/**
* \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