curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: CURLOPT_WRITEFUNCTION issues - warning: curl_easy_setopt expects a curl_write_callback argument

From: Timothe Litt <litt_at_acm.org>
Date: Fri, 21 Jan 2022 08:15:14 -0500

I'm confused about what you're trying to do.

outstream is an input parameter.  It will contain whatever you set in
the CURLOPT_WRITEDATA option.

If it's a json structure that's input to your callback, overwriting the
pointer with json_loadb doesn't make sense.

In fact, the value of outstream, now in json isn't used - loadb simply
overwrites it.

Further, your callback may be called many times with pieces of the json
string.  You need to get the entire response before calling json_loadb,
or use another call.

You can use "outstream" as a pointer to a buffer that accumulates the
response, or to a struct with the next write pointer and remaining count
in that buffer, or ...

You need to re-architect this code.


Timothe Litt
ACM Distinguished Engineer
--------------------------
This communication may not represent the ACM or my employer's views,
if any, on the matters discussed.

On 21-Jan-22 07:34, Gavin Henry via curl-library wrote:
> Thanks. Switched it to:
>
> static size_t curl_to_jansson_to_version(void *buffer, size_t size,
> size_t nmemb, void *outstream)
> {
> json_t *json = outstream;
> json = json_loadb(buffer, size * nmemb, 0, NULL);
> assert_non_null(json);
>
> then my CLion moans, but is OK :-)
>
> "The value is never used". I'll leave gcc and clang to sort.

-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-01-21