forked from andelf/go-curl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c-callback.c
68 lines (54 loc) · 2.31 KB
/
c-callback.c
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
#include <stdio.h>
#include <string.h>
#include "callback.h"
#include "_cgo_export.h"
/* for OPT_HEADERFUNCTION */
size_t header_function( char *ptr, size_t size, size_t nmemb, void *ctx) {
void *go_header_func = (void *)goGetCurlField((GoUintptr)ctx, "headerFunction");
GoInterface *userdata = (GoInterface *)goGetCurlField((GoUintptr)ctx, "headerData");
if (userdata == NULL) {
return goCallWriteFunctionCallback(go_header_func, ptr, size*nmemb, goNilInterface());
}
return goCallWriteFunctionCallback(go_header_func, ptr, size*nmemb, *userdata);
}
void *return_header_function() {
return (void *)&header_function;
}
/* for OPT_WRITEFUNCTION */
size_t write_function( char *ptr, size_t size, size_t nmemb, void *ctx) {
void *go_write_func = (void *)goGetCurlField((GoUintptr)ctx, "writeFunction");
GoInterface *userdata = (GoInterface *)goGetCurlField((GoUintptr)ctx, "writeData");
if (userdata == NULL) {
return goCallWriteFunctionCallback(go_write_func, ptr, size*nmemb, goNilInterface());
}
return goCallWriteFunctionCallback(go_write_func, ptr, size*nmemb, *userdata);
}
void *return_write_function() {
return (void *)&write_function;
}
/* for OPT_READFUNCTION */
size_t read_function( char *ptr, size_t size, size_t nmemb, void *ctx) {
void *go_read_func = (void *)goGetCurlField((GoUintptr)ctx, "readFunction");
GoInterface *userdata = (GoInterface *)goGetCurlField((GoUintptr)ctx, "readData");
if (userdata == NULL) {
return goCallReadFunctionCallback(go_read_func, ptr, size*nmemb, goNilInterface());
}
return goCallReadFunctionCallback(go_read_func, ptr, size*nmemb, *userdata);
}
void *return_read_function() {
return (void *)&read_function;
}
/* for OPT_PROGRESSFUNCTION */
int progress_function(void *ctx, double dltotal, double dlnow, double ultotal, double ulnow) {
void *go_progress_func = (void *)goGetCurlField((GoUintptr)ctx, "progressFunction");
GoInterface *clientp = (GoInterface *)goGetCurlField((GoUintptr)ctx, "progressData");
if (clientp == NULL) {
return goCallProgressCallback(go_progress_func, goNilInterface(),
dltotal, dlnow, ultotal, ulnow);
}
return goCallProgressCallback(go_progress_func, *clientp,
dltotal, dlnow, ultotal, ulnow);
}
void *return_progress_function() {
return (void *)progress_function;
}