Hi Timothe,

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

It seems I am too as I have fully understood the callback.

> 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.

No, it doesn't now. What I'm trying to do is save the result of this,
then pull out the "version" and compare it to the PACKAGE_VERSION of
SentryPeer in my test suite. So if it was in bash or on the CLI:

curl -H "Content-Type: application/json" http://127.0.0.1:8082/health-check
{
  "status": "OK",
  "message": "Hello from SentryPeer!",
  "version": "0.0.6"
}


> 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.

It's my misunderstanding of where to put json_loadb(). It's not
supposed to be done in the callback, but filling up a json buffer in
there and processing wherever I've set CURLOPT_WRITEDATA, correct?

As the callback, as you say, may not parse all of the above json in
one go or be given it from the API endpoint.

My goal is to be able save/process the returned JSON and pull out the
version string to do:

json_t *sentrypeer_version_json = json_object_get(json, "version");
assert_string_equal(json_string_value(sentrypeer_version_json),
PACKAGE_VERSION);

Thanks.
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html

Reply via email to