2018-07-21 03:51:49 +02:00
|
|
|
#ifndef NETWORK_H
|
|
|
|
#define NETWORK_H
|
2018-07-22 12:50:51 +02:00
|
|
|
|
2019-09-01 09:52:18 +02:00
|
|
|
/**
|
|
|
|
* \file network.h
|
|
|
|
* \brief network related functions
|
|
|
|
*/
|
|
|
|
|
2018-07-26 11:29:44 +02:00
|
|
|
#include "link.h"
|
|
|
|
|
2019-04-26 15:14:42 +02:00
|
|
|
typedef enum {
|
|
|
|
HTTP_OK = 200,
|
|
|
|
HTTP_PARTIAL_CONTENT = 206,
|
|
|
|
HTTP_RANGE_NOT_SATISFIABLE = 416,
|
2019-09-04 18:57:15 +02:00
|
|
|
HTTP_TOO_MANY_REQUESTS = 429,
|
|
|
|
HTTP_UNKNOWN_ERROR = 520
|
2019-09-01 09:52:18 +02:00
|
|
|
} HTTPResponseCode;
|
2018-07-26 11:29:44 +02:00
|
|
|
|
2018-07-22 20:30:08 +02:00
|
|
|
typedef enum {
|
2018-07-26 11:29:44 +02:00
|
|
|
FILESTAT = 's',
|
|
|
|
DATA = 'd'
|
|
|
|
} TransferType;
|
|
|
|
|
2019-04-26 15:14:42 +02:00
|
|
|
typedef struct {
|
|
|
|
char *memory;
|
|
|
|
size_t size;
|
|
|
|
} MemoryStruct;
|
|
|
|
|
2018-07-26 11:29:44 +02:00
|
|
|
typedef struct {
|
|
|
|
TransferType type;
|
|
|
|
int transferring;
|
|
|
|
Link *link;
|
|
|
|
} TransferStruct;
|
|
|
|
|
2018-07-30 15:20:04 +02:00
|
|
|
typedef struct {
|
|
|
|
char *username;
|
|
|
|
char *password;
|
2018-07-30 15:55:38 +02:00
|
|
|
char *proxy;
|
|
|
|
char *proxy_user;
|
|
|
|
char *proxy_pass;
|
2018-07-30 15:20:04 +02:00
|
|
|
long max_conns;
|
2019-04-26 12:39:03 +02:00
|
|
|
char *user_agent;
|
2019-04-26 21:37:49 +02:00
|
|
|
int http_429_wait;
|
2019-04-30 09:05:46 +02:00
|
|
|
char *cache_dir;
|
|
|
|
int cache_enabled;
|
2018-07-30 15:20:04 +02:00
|
|
|
} NetworkConfigStruct;
|
|
|
|
|
2019-04-26 21:37:49 +02:00
|
|
|
/** \brief The waiting time after getting HTTP 429 */
|
|
|
|
extern int HTTP_429_WAIT;
|
|
|
|
|
2018-07-30 15:20:04 +02:00
|
|
|
/** \brief CURL configuration */
|
|
|
|
extern NetworkConfigStruct NETWORK_CONFIG;
|
|
|
|
|
2018-07-26 11:29:44 +02:00
|
|
|
/** \brief curl shared interface */
|
2018-07-30 15:20:04 +02:00
|
|
|
extern CURLSH *CURL_SHARE;
|
2018-07-26 11:29:44 +02:00
|
|
|
|
2018-07-26 11:58:51 +02:00
|
|
|
/** \brief perform one transfer cycle */
|
2018-07-26 11:29:44 +02:00
|
|
|
int curl_multi_perform_once();
|
2018-07-22 20:30:08 +02:00
|
|
|
|
2018-07-30 15:20:04 +02:00
|
|
|
/** \brief initialise network config struct */
|
|
|
|
void network_config_init();
|
|
|
|
|
|
|
|
/** \brief initialise the network module */
|
|
|
|
LinkTable *network_init(const char *url);
|
2018-07-21 01:39:51 +02:00
|
|
|
|
2018-07-26 11:58:51 +02:00
|
|
|
/** \brief blocking file transfer */
|
2018-07-26 11:29:44 +02:00
|
|
|
void transfer_blocking(CURL *curl);
|
2018-07-22 20:30:08 +02:00
|
|
|
|
2018-07-26 11:58:51 +02:00
|
|
|
/** \brief non blocking file transfer */
|
2018-07-26 11:29:44 +02:00
|
|
|
void transfer_nonblocking(CURL *curl);
|
2018-07-20 16:38:44 +02:00
|
|
|
|
2018-07-26 11:58:51 +02:00
|
|
|
/** \brief callback function for file transfer */
|
2018-07-26 11:29:44 +02:00
|
|
|
size_t
|
2018-07-30 15:20:04 +02:00
|
|
|
write_memory_callback(void *contents, size_t size, size_t nmemb, void *userp);
|
2018-07-18 17:26:26 +02:00
|
|
|
|
|
|
|
#endif
|