KXML_OPEN(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’… KXML_OPEN(3) β€” like, the kcgixml context opener, bestie

okay so this one lives in the Library Functions Manual and it's from the libkcgixml library ✨ (yes, that's the whole library name, no cap).


🌸 NAME 🌸

kxml_open β€” open a kcgixml context 🫢


πŸŽ€ LIBRARY πŸŽ€

library β€œlibkcgixml”


✨ SYNOPSIS ✨

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
#include <kcgixml.h>

enum kcgi_err
kxml_open(struct kxmlreq *xml, struct kreq *req,
    const char *const *elems, size_t elemsz);

πŸ’– DESCRIPTION πŸ’–

So what this does is it zeroes and initialises a brand-new context req, sitting on top of the underlying kcgi(3) context r β€” and r has to have been allocated with khttp_parse(3) or khttp_fcgi_parse(3), no exceptions bestie πŸ”₯

Lowkey important: you should only call this after khttp_body(3). Like, that's the vibe check and it has to pass.

The context gets initialised with elemsz possible elements, and their names are elems. And here's the thing β€” it's your job (the caller's responsibility, periodt πŸ’…) to make sure those are actually valid XML element names. This function is not gonna hold your hand on that one.

Also 🚨 if kcgi_writer_disable(3) has been called, the process will be killed with an uncatchable signal. Not a vibe. Very much not a vibe. πŸ’€


πŸ¦‹ RETURN VALUES πŸ¦‹

It returns an enum kcgi_err showing the error state, and here's the whole menu:

  • KCGI_OK β€” success! not an error! we love to see it πŸ‘‘
  • KCGI_ENOMEM β€” internal memory allocation failure 😭
  • KCGI_HUP β€” the output connection got terminated. For FastCGI connections, you should release the current connection with khttp_free(3) and reenter the parse loop πŸ”
  • KCGI_FORM β€” the connection is still expecting headers with khttp_head(3). This means khttp_body(3) either didn't return with success or just straight-up wasn't invoked πŸ™ˆ. For FastCGI connections, release the current connection with khttp_free(3) and reenter the parse loop, same drill.
  • KCGI_SYSTEM β€” internal system error while writing to the output stream πŸ’€

🌈 EXAMPLES 🌈

The following outputs a simple XML page πŸŽ‰ It assumes r is a struct kreq pointer. And for brevity β€” because we're keeping it cute and short β€” it does no error checking at all (iconic of it, honestly):

const char *const elems[] =
  { "foo", "bar", "baz" };
khttp_head(r, kresps[KRESP_STATUS],
  "%s", khttps[KHTTP_200]);
khttp_head(r, kresps[KRESP_CONTENT_TYPE],
  "%s", kmimetypes[KMIME_TEXT_XML]);
khttp_body(r);
kxml_open(&req, r, elems, 3);
kxml_push(&req, 0); /* foo */
kxml_puts(&req, "Hello, world");
kxml_close(&req);

🧚 SEE ALSO 🧚


πŸ’œ AUTHORS πŸ’œ

Written by Kristaps Dzonsons <kristaps@bsd.lv> β€” thank you king 🫢


okay that's the whole page, mwah πŸ’‹ this thing is Debian-flavoured, version $Mdocdate$, and it goes by KXML_OPEN(3) if you ever need to find it again. bye bestie, go open some contexts βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • alpine 3.24: kcgi-doc 1.0.1-r0 Β· ISC
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms