gnurl_formget(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… gnurl_formget(3) β€” the libgnurl manual page, bestie edition πŸŽ€

okay so this is the gnurl_formget(3) page from the libgnurl Manual and honestly? it's a whole vibe. it's about turning a form you already built into a serialized blob. let's get into it ✨


🌸 NAME 🌸

curl_formget β€” serialize a previously built multipart/formdata HTTP POST chain πŸ’Œ

like, it takes your cute lil form chain and turns it into actual bytes. no cap.


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

int curl_formget(struct curl_httppost * form, void *userp,
                  curl_formget_callback append );

that's the whole thing. three args, one int back. slay 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so curl_formget() is literally the function you use to serialize data that you previously built/appended with curl_formadd(3). it's giving "cleanup crew for your formpost" energy.

it accepts a void pointer as its second argument, named userp, which gets passed as the first argument to the curl_formget_callback function. so like, you hand it a pointer, it hands that pointer right back to your callback. iykyk πŸ’«

typedef size_t (*curl_formget_callback)(void *userp, const char *buf,
size_t len);

the curl_formget_callback will be executed for each part of the HTTP POST chain. one callback per part, every time. πŸ‘‘

⚠️ bestie listen β€” the character buffer passed to the callback must not be freed. do not touch it. do not free() it. the callback should return the buffer length passed to it on success, and that's it. that's the whole job. πŸ’€

and here's the messy part πŸ™ˆ: if the CURLFORM_STREAM option is used in the formpost, it will prevent curl_formget(3) from working until you've performed the actual HTTP request β€” because only then will libcurl get the actual read callback to use! literally not me finding that out the hard way 😭 so like, do the request first, then serialize. periodt.


πŸ’– RETURN VALUE πŸ’–

  • 0 β€” everything was ok, we're so back 🌈
  • non-zero β€” an error occurred, we're so not back πŸ’€

that's it. that's the whole vibe check.


πŸŽ€ EXAMPLE πŸŽ€

here's the example, written out exactly, because i would never do you dirty like that 🫢

        size_t print_httppost_callback(void *arg, const char *buf, size_t len)
        {
          fwrite(buf, len, 1, stdout);
          (*(size_t *) arg) += len;
          return len;
        }

        size_t print_httppost(struct curl_httppost *post)
        {
          size_t total_size = 0;
          if(curl_formget(post, &total_size, print_httppost_callback)) {
            return (size_t) -1;
          }
          return total_size;
        }

the callback fwrites the buffer, bumps the running total through that void *arg (which is really a size_t *, sneaky but iconic), and returns len. then print_httppost calls curl_formget with &total_size, and returns (size_t) -1 if it fails. main character error handling fr fr πŸ”₯


🧚 AVAILABILITY 🧚

  • this function was added in libcurl 7.15.5 ⭐
  • the form API is deprecated in libcurl 7.56.0 πŸ’€

so like, it exists, but it's on the deprecated list. use it knowing that, bestie. no surprises. 🌸


🌈 SEE ALSO 🌈

go read those too, they're the supporting cast πŸ’œ


and that's the page!! this one's from libcurl 7.15.5, dated 20 June 2006, and it lives at gnurl_formget(3) in the libgnurl manual. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from