| 1 |
#include <Rinternals.h> |
| 2 |
|
| 3 |
|
| 4 |
#define CURL_DISABLE_DEPRECATION 1 |
| 5 |
|
| 6 |
#include <curl/curl.h> |
| 7 |
#include <curl/easy.h> |
| 8 |
#include <string.h> |
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
#define make_string(x) x != NULL ? Rf_mkString(x) : Rf_ScalarString(NA_STRING) |
| 12 |
#define get_string(x) CHAR(STRING_ELT(x, 0)) |
| 13 |
#define len_string(x) Rf_length(STRING_ELT(x, 0)) |
| 14 |
#define assert(x) assert_message(x, NULL) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#if CURL_AT_LEAST_VERSION(7,80,0) |
| 19 |
#define HAS_CURL_PARSER_STRERROR 1 |
| 20 |
#endif |
| 21 |
|
| 22 |
typedef struct { |
| 23 |
unsigned char *buf; |
| 24 |
size_t size; |
| 25 |
} memory; |
| 26 |
|
| 27 |
typedef struct { |
| 28 |
SEXP multiptr; |
| 29 |
SEXP handles; |
| 30 |
CURLM *m; |
| 31 |
} multiref; |
| 32 |
|
| 33 |
typedef struct { |
| 34 |
multiref *mref; |
| 35 |
struct refnode *node; |
| 36 |
memory content; |
| 37 |
SEXP complete; |
| 38 |
SEXP error; |
| 39 |
SEXP data; |
| 40 |
} async; |
| 41 |
|
| 42 |
typedef struct { |
| 43 |
SEXP handleptr; |
| 44 |
CURL *handle; |
| 45 |
struct curl_httppost *form; |
| 46 |
struct curl_slist *headers; |
| 47 |
struct curl_slist *custom; |
| 48 |
char errbuf[CURL_ERROR_SIZE]; |
| 49 |
memory resheaders; |
| 50 |
async async; |
| 51 |
int refCount; |
| 52 |
int locked; |
| 53 |
} reference; |
| 54 |
|
| 55 |
CURL* get_handle(SEXP ptr); |
| 56 |
reference* get_ref(SEXP ptr); |
| 57 |
void raise_libcurl_error(CURLcode res, reference *ref, SEXP error_cb); |
| 58 |
void assert_status(CURLcode res, reference *ref); |
| 59 |
void assert_message(CURLcode res, const char *str); |
| 60 |
void massert(CURLMcode res); |
| 61 |
SEXP slist_to_vec(struct curl_slist *slist); |
| 62 |
struct curl_slist* vec_to_slist(SEXP vec); |
| 63 |
struct curl_httppost* make_form(SEXP form); |
| 64 |
void set_form(reference *ref, struct curl_httppost* newform); |
| 65 |
void reset_resheaders(reference *ref); |
| 66 |
void reset_errbuf(reference *ref); |
| 67 |
void clean_handle(reference *ref); |
| 68 |
size_t push_disk(void* contents, size_t sz, size_t nmemb, FILE *ctx); |
| 69 |
size_t append_buffer(void *contents, size_t sz, size_t nmemb, void *ctx); |
| 70 |
size_t data_callback(void * data, size_t sz, size_t nmemb, SEXP fun); |
| 71 |
CURLcode curl_perform_with_interrupt(CURL *handle); |
| 72 |
int pending_interrupt(void); |
| 73 |
SEXP make_handle_response(reference *ref); |
| 74 |
|
| 75 |
|
| 76 |
SEXP reflist_init(void); |
| 77 |
SEXP reflist_add(SEXP x, SEXP target); |
| 78 |
SEXP reflist_remove(SEXP x, SEXP target); |
| 79 |
|
| 80 |
|
| 81 |
#if defined(__APPLE__) && defined(ENABLE_MACOS_POLYFILL) && !CURL_AT_LEAST_VERSION(7,81,0) |
| 82 |
#include "macos-polyfill.h" |
| 83 |
#endif |