KHTTP_URLPART(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’… KHTTP_URLPART(3) β€” like, the URL-formatting one

okay so bestie, welcome to KHTTP_URLPART(3) from the Library Functions Manual β€” yes it's section 3, we're in library-functions territory, put your seatbelt on. πŸŽ€

✨ NAME ✨

khttp_urlpart, khttp_urlpartx, khttp_vurlpart, khttp_vurlpartx β€” URL formatting for kcgi. that's the whole vibe. πŸ¦‹

πŸ“š LIBRARY πŸ“š

library β€œlibkcgi” β€” that's where these live, no cap.

🌸 SYNOPSIS 🌸

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

char *
khttp_urlpart(const char *path, const char *suffix, const char *page,
    ...);

char *
khttp_urlpartx(const char *path, const char *suffix, const char *page,
    ...);

char *
khttp_vurlpart(const char *path, const char *suffix, const char *page,
    va_list ap);

char *
khttp_vurlpartx(const char *path, const char *suffix, const char *page,
    va_list ap);

like, four functions, all icons, all doing the same basic thing with slightly different energy. πŸ’…

πŸ”₯ DESCRIPTION πŸ”₯

So what we're doing here is formatting a URL from the components that come after the domain. cute, right? and if you hand over variable arguments, they get appended as query string pairs. it's giving

path/page.suffix
path/page.suffix?key=val...

Now the tea on path: πŸ“

  • if path is NULL, the URL is relative to page.
  • otherwise, path gets followed by a path separator.
  • an empty path means the root directory. yes, empty = root, periodt.

And for suffix: if suffix is NULL or empty, or the corresponding page is NULL or empty, the URL is formatted with no suffix. bye suffix, didn't need you anyway. πŸ‘‹

Here's the part you gotta get right, bestie β€” the variable key-value arguments must be terminated with NULL. not optional. that's the vibe check. ⭐

  • khttp_urlpart() and khttp_vurlpart() take pairs of variable arguments: first is the query string key, second is the value. both are char *. and if a query string value is NULL, it's rendered as an empty string. πŸ’–
  • khttp_urlpartx() and khttp_vurlpartx() take triplets instead. in each group:
    • arg one is a char * giving the key πŸŽ€
    • arg two is an enum kattrx saying what type the third arg is:
      • KATTRX_STRING followed by a char * string (and yeah, a NULL query string value renders as an empty string)
      • KATTRX_INT followed by an int64_t signed integer
      • KATTRX_DOUBLE followed by a double floating-point number
    • and if all the types are KATTRX_STRING, you can shorten the whole invocation to khttp_urlpart(). slay, less typing. πŸ™ˆ

Encoding deets, important: the page, query string keys, and query string values are URL-encoded, but the path and the suffix are not. lowkey crucial, don't forget. πŸ¦‹

⚠️ There are two deprecated forms of these functions: kutil_urlpart() and kutil_urlpartx(). These should no longer be used. like, fr fr, leave them in the past. πŸ’€

πŸ‘‘ RETURN VALUES πŸ‘‘

They return newly-allocated strings that must be freed with free(3), or NULL if allocation fails. so call free(), bestie, don't ghost your memory. 😭

🌈 EXAMPLES 🌈

Okay this is the fun part. πŸ’œ The following creates a relative URL with path, page, suffix, and query string parts:

url = khttp_urlpart("/path", "html", "page",
         "foo", "bar", "baz", "xyzzy", NULL);

This will assign the following URL:

/path/page.html?foo=bar&baz=xyzzy

For typed arguments, the extended form may be used. and heads up: integer and real literals must have the int64_t and double types, respectively. no guessing. ⭐

url = khttp_urlpartx("/path", "html", "page",
         "foo", KATTRX_INT, (int64_t)0, NULL);

This assigns the following:

/path/page.html?foo=0

These may be made relative to the current page by omitting the leading slash or passing NULL for the path component entirely, such as:

url1 = khttp_urlpart("rel/path", "html", "page", NULL);
url2 = khttp_urlpart(NULL, "html", "page", NULL);

These assign the following, respectively:

rel/path/page.html
page.html

Lastly, pages and their suffixes may be omitted entirely:

url3 = khttp_urlpart("", "", "", "foo", "bar", NULL);
url4 = khttp_urlpart(NULL, "", "", "foo", "bar", NULL);

These assign the following:

/?foo=bar
?foo=bar

see? ate. πŸ”₯

🧚 AUTHORS 🧚

Written by Kristaps Dzonsons <kristaps@bsd.lv>. king behavior honestly. πŸ‘‘


and that's the whole page, bestie!! 🫢 this was Debian's rendition, dated $Mdocdate$, and it lives at KHTTP_URLPART(3) β€” go forth and format those URLs, you absolute main character. πŸ’–βœ¨

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