KXML_POP(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’… KXML_POP(3) β€” kxml_pop

okay so bestie, welcome to kxml_pop(3), part of the β€œlibkcgixml” library ✨ (yes that's LIBRARY, and yes she's an icon). This is the little function that closes out an element scope for kcgixml, and honestly? she's a closer. literally.


✨ SYNOPSIS ✨

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

enum kcgi_err
kxml_pop(struct kxmlreq *req);

like, that's the whole vibe. one function, one job, no cap πŸŽ€


🌸 DESCRIPTION 🌸

So kxml_pop closes exactly one element scope of req β€” the request you already set up with kxml_open(3). That's it. That's the whole function. main character energy in its purest form πŸ’…

where do those scopes come from, you ask? they get opened by kxml_push(3) or kxml_pushattrs(3). so every push needs its pop, bestie. it's giving matching accessories. πŸŽ€

⚠️ ngl, it is literally an error to pop from an empty scope stack. no scopes open? no pop for you. don't do it. 🫢

πŸ¦‹ RETURN VALUES πŸ¦‹

she returns an enum kcgi_err, which is just the error state. here's the whole cast of characters:

  • KCGI_OK β€” success! not an error, just vibes πŸ’–
  • KCGI_ENOMEM β€” internal memory allocation failure. the malloc said no 😭
  • KCGI_HUP β€” the output connection has been terminated. for FastCGI connections, you should release the current connection with khttp_free(3) and reenter the parse loop. (yeah. do that. 🫑)
  • KCGI_FORM β€” the connection is still expecting headers via khttp_head(3). this one's telling you that khttp_body(3) didn't return with success, or was never invoked at all. for FastCGI connections, release the current connection with khttp_free(3) and reenter the parse loop. (same drill, different error πŸ’€)
  • KCGI_SYSTEM β€” internal system error writing to the output stream. the stream is not having it πŸ™ˆ
  • KCGI_WRITER β€” there are no open scopes to pop. literally nothing to close. this is the empty-stack situation from up there ⬆️

πŸ”₯ EXAMPLES πŸ”₯

okay so this example outputs a simple XML page, and it assumes r is a struct kreq pointer. for brevity, it does not do any error checking (iconic of it, honestly, but don't copy that part into prod 😭).

      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_pop(&req);
      kxml_push(&req, 1, "baz", "xyzzy"); /* bar */
      kxml_puts(&req, "Hello, world");
      kxml_pop(&req);
      kxml_close(&req);

see how every kxml_push gets its matching kxml_pop? balance. harmony. friendship. πŸ’œ


πŸŽ€ SEE ALSO πŸŽ€

like obviously go read the parent page, bestie, iykyk 🌈


πŸ‘‘ AUTHORS πŸ‘‘

Written by Kristaps Dzonsons <kristaps@bsd.lv>. we stan. 🫢


okay and for the sign-off: this page came from the Debian fam, dated $Mdocdate$, and it's KXML_POP(3) through and through. periodt. πŸ’…βœ¨

πŸ“¦ 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