url.h

URL encoding/decoding for lwIP-CE.

Known constraints:

  • No URL parsing (scheme/host/path splitting) — encoding only.

  • Space encodes as %20, not ‘+’ (form encoding is not supported).

Author

Anthony Cagliano

Author

Claude Code

Note

Percent-encoding per RFC 3986. All functions operate on caller-supplied buffers with no heap allocation.

Defines

URL_ERR

Functions

size_t url_encode(char *dst, size_t dst_len, const char *src)

Percent-encode src into dst.

Unreserved characters (A-Z a-z 0-9 - _ . ~) are passed through. All other bytes are encoded as XX.

Parameters:
  • dst – output buffer

  • dst_len – size of dst (including NUL terminator)

  • src – input string (NUL-terminated)

Returns:

number of bytes written to dst (excluding NUL), or URL_ERR if dst is too small.

size_t url_encode_n(char *dst, size_t dst_len, const char *src, size_t src_len)

Percent-encode a binary buffer into dst (same rules as url_encode).

size_t url_decode(char *dst, size_t dst_len, const char *src)

Percent-decode src into dst.

XX sequences are decoded; ‘+’ is left as ‘+’ (not decoded as space).

Parameters:
  • dst – output buffer

  • dst_len – size of dst (including NUL terminator)

  • src – input string (NUL-terminated)

Returns:

number of bytes written to dst (excluding NUL), or URL_ERR if dst is too small or input is malformed.

size_t url_build_query(char *dst, size_t dst_len, const char *const *keys, const char *const *values, size_t count)

Build a query string from key/value pairs into dst.

Encodes all keys and values and joins them with ‘&’. Does NOT include a leading ‘?’.

Parameters:
  • dst – output buffer

  • dst_len – size of dst

  • keys – NULL-terminated array of key strings

  • values – NULL-terminated array of value strings (parallel to keys)

  • count – number of pairs

Returns:

number of bytes written (excluding NUL), or URL_ERR if too small.