KHTTP_URLPART(3)
π 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
pathisNULL, the URL is relative topage. - otherwise,
pathgets followed by a path separator. - an empty
pathmeans 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()andkhttp_vurlpart()take pairs of variable arguments: first is the query string key, second is the value. both arechar *. and if a query string value isNULL, it's rendered as an empty string. πkhttp_urlpartx()andkhttp_vurlpartx()take triplets instead. in each group:- arg one is a
char *giving the key π - arg two is an
enum kattrxsaying what type the third arg is:KATTRX_STRINGfollowed by achar *string (and yeah, aNULLquery string value renders as an empty string)KATTRX_INTfollowed by anint64_tsigned integerKATTRX_DOUBLEfollowed by adoublefloating-point number
- and if all the types are
KATTRX_STRING, you can shorten the whole invocation tokhttp_urlpart(). slay, less typing. π
- arg one is a
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()andkutil_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
- Copyright (c) 2014, 2017, 2020 Kristaps Dzonsons <kristaps@bsd.lv>
- Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms