2018-07-21 03:51:49 +02:00
|
|
|
#ifndef NETWORK_H
|
|
|
|
#define NETWORK_H
|
2018-07-22 12:50:51 +02:00
|
|
|
|
|
|
|
#include "data.h"
|
2018-07-18 17:26:26 +02:00
|
|
|
|
2018-07-22 20:30:08 +02:00
|
|
|
#include <curl/curl.h>
|
2018-07-18 17:26:26 +02:00
|
|
|
#include <gumbo.h>
|
|
|
|
|
2018-07-22 20:30:08 +02:00
|
|
|
#define URL_LEN_MAX 2048
|
|
|
|
#define LINK_LEN_MAX 255
|
2018-07-24 03:40:53 +02:00
|
|
|
|
|
|
|
#ifndef HTTPDIRFS_SINGLE
|
|
|
|
# define CURL_MULTI_MAX_CONNECTION 10
|
|
|
|
#endif
|
2018-07-22 20:30:08 +02:00
|
|
|
|
|
|
|
/** \brief the link type */
|
|
|
|
typedef enum {
|
|
|
|
LINK_HEAD = 'H',
|
|
|
|
LINK_DIR = 'D',
|
|
|
|
LINK_FILE = 'F',
|
2018-07-23 18:36:36 +02:00
|
|
|
LINK_INVALID = '\0'
|
2018-07-22 20:30:08 +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;
|
|
|
|
|
|
|
|
|
|
|
|
struct Link {
|
|
|
|
char p_url[LINK_LEN_MAX];
|
|
|
|
char f_url[URL_LEN_MAX];
|
|
|
|
LinkType type;
|
|
|
|
size_t content_length;
|
|
|
|
LinkTable *next_table;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LinkTable {
|
|
|
|
int num;
|
|
|
|
Link **links;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief root link table */
|
|
|
|
extern LinkTable *ROOT_LINK_TBL;
|
|
|
|
|
2018-07-21 01:39:51 +02:00
|
|
|
/** \brief Initialise the network module */
|
2018-07-22 12:50:51 +02:00
|
|
|
void network_init(const char *url);
|
2018-07-21 01:39:51 +02:00
|
|
|
|
2018-07-22 14:35:11 +02:00
|
|
|
/**
|
|
|
|
* \brief download a link */
|
|
|
|
/* \return the number of bytes downloaded
|
|
|
|
*/
|
2018-07-23 02:27:03 +02:00
|
|
|
long Link_download(const char *path, char *output_buf, size_t size,
|
|
|
|
off_t offset);
|
2018-07-22 20:30:08 +02:00
|
|
|
|
|
|
|
/** \brief create a new LinkTable */
|
|
|
|
LinkTable *LinkTable_new(const char *url);
|
2018-07-20 16:38:44 +02:00
|
|
|
|
2018-07-20 03:09:51 +02:00
|
|
|
/** \brief print a LinkTable */
|
|
|
|
void LinkTable_print(LinkTable *linktbl);
|
|
|
|
|
2018-07-22 12:50:51 +02:00
|
|
|
/** \brief find the link associated with a path */
|
2018-07-22 14:35:11 +02:00
|
|
|
Link *path_to_Link(const char *path);
|
2018-07-18 17:26:26 +02:00
|
|
|
|
|
|
|
#endif
|