forked from Kitura/CCurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shim.h
79 lines (62 loc) · 2.85 KB
/
shim.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Copyright IBM Corporation 2016
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef CurlHelpers_h
#define CurlHelpers_h
#import <curl/curl.h>
#define CURL_TRUE 1
#define CURL_FALSE 0
extern inline CURLcode curlHelperSetOptBool(CURL *curl, CURLoption option, int yesNo) {
return curl_easy_setopt(curl, option, yesNo == CURL_TRUE ? 1L : 0L);
}
// set options list - CURLOPT_HTTPHEADER, CURLOPT_HTTP200ALIASES, CURLOPT_QUOTE, CURLOPT_TELNETOPTIONS, CURLOPT_MAIL_RCPT, etc.
extern inline CURLcode curlHelperSetOptList(CURL *curl, CURLoption option, struct curl_slist *list) {
return curl_easy_setopt(curl, option, list);
}
__attribute__((deprecated("curlHelperSetOptHeaders has been deprecated please use curlHelperSetOptList(curl, CURLOPT_HTTPHEADER, headers) instead")))
extern inline CURLcode curlHelperSetOptHeaders(CURL *curl, struct curl_slist *headers) {
return curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
}
extern inline CURLcode curlHelperSetOptInt(CURL *curl, CURLoption option, long data) {
return curl_easy_setopt(curl, option, data);
}
// const keyword is used so that Swift strings can be passed
extern inline CURLcode curlHelperSetOptString(CURL *curl, CURLoption option, const char *data) {
return curl_easy_setopt(curl, option, data);
}
extern inline CURLcode curlHelperSetOptReadFunc(CURL *curl, void *userData, size_t (*read_cb) (char *buffer, size_t size, size_t nitems, void *userdata)) {
CURLcode rc = curl_easy_setopt(curl, CURLOPT_READDATA, userData);
if (rc == CURLE_OK) {
rc = curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
}
return rc;
}
extern inline CURLcode curlHelperSetOptWriteFunc(CURL *curl, void *userData, size_t (*write_cb) (char *ptr, size_t size, size_t nmemb, void *userdata)) {
CURLcode rc = curl_easy_setopt(curl, CURLOPT_HEADER, 1);
if (rc == CURLE_OK) {
rc = curl_easy_setopt(curl, CURLOPT_WRITEDATA, userData);
if (rc == CURLE_OK) {
rc = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
}
}
return rc;
}
extern inline CURLcode curlHelperGetInfoCString(CURL *curl, CURLINFO info, char **data) {
return curl_easy_getinfo(curl, info, data);
}
extern inline CURLcode curlHelperGetInfoLong(CURL *curl, CURLINFO info, long *data) {
return curl_easy_getinfo(curl, info, data);
}
#endif /* CurlHelpers_h */