Reputation: 145
I'm trying to pass a struct to a callback set with curl_easy_setopt. Here's the struct:
typedef struct gfcontext_t {
int sockfd;
char requested_path[1024];
char path[1024];
} gfcontext_t;
struct gfcontext_t ctx;
I've got these two lines setting up the callback:
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ctx);
and the callback itself looks like this:
size_t write_callback(void *buffer, size_t size, size_t nmemb, void *userp) {
printf("userp: %s\n", userp.requested_path);
}
The machine says "request for member ‘requested_path’ in something not a structure or union." So I guess the struct (ctx) is not being passed correctly. Can anyone point me in the right direction?
Upvotes: 1
Views: 133
Reputation: 394
userp is a pointer. You should type cast it to gfcontext_t *
.
printf("userp: %s\n", ((gfcontext_t *)userp)->requested_path);
Upvotes: 2