summaryrefslogtreecommitdiff
path: root/src/process_url.h
blob: 5b2542c0ed69bed486b6f8d34dd8796768d8f377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef PROCESS_URL_H_
#define PROCESS_URL_H_

#include <curl/curl.h>
#include <curl/system.h>
#include <limits.h>
#include <stdbool.h>

#include "constants.h"
#include "status.h"
#include "utils/utils.h"

#define ERRTOSTRING(err) curl_easy_strerror(err)
#define logerr(X)                                                              \
  _Generic((X), CURLcode: logerr_b, CURLHcode: logerr_h, CURLUcode: logerr_u)(X)

typedef struct curl_conf {
  curl_off_t dlnow_per_thrd[MAX_THREAD];
  curl_off_t dlnow;
  curl_off_t dltotal;
  unsigned char success_thrd;
  unsigned char total_thrd;
  char *URL;
  char *outfn;
  str_array_t partfn;
  FILE *fplist[MAX_THREAD];
  bool need_callback;
} curl_conf_t;

typedef struct thrd_info {
  unsigned char no;
  curl_conf_t *curl_c;
  char range[UCHAR_MAX];
} thrd_info_t;

typedef struct str_data {
  char *string;
  size_t len;
} str_data_t;

typedef str_array_t callback_struct_t;

typedef int (*callback_t)(void *);

void curl_init(char *);

void curl_cleanup(status_t *);

void poll_status(status_t *);

void add_cookie(char **p_cookie);

void set_referer(char *referer);

int get(const char *, char **);

bool get_info(const char *URL, curl_off_t *psize, char **p_content_type,
              char **p_cookie);

void add_url(const char *, const char *, const char *, callback_t,
             callback_struct_t *);

#endif