NetSurf
Functions
url.c File Reference

Implementation of URI percent escaping. More...

#include <ctype.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include "utils/ascii.h"
#include "utils/config.h"
#include "utils/log.h"
#include "utils/url.h"
Include dependency graph for url.c:

Go to the source code of this file.

Functions

static char xdigit_to_hex (char c)
 Convert a hex digit to a hex value. More...
 
nserror url_unescape (const char *str, size_t length, size_t *length_out, char **result_out)
 Convert an escaped string to plain. More...
 
nserror url_escape (const char *unescaped, bool sptoplus, const char *escexceptions, char **result)
 Escape a string suitable for inclusion in an URL. More...
 

Detailed Description

Implementation of URI percent escaping.

Percent encoding of URI is subject to RFC3986 however this is not implementing URI behaviour purely the percent encoding so only the unreserved set is not encoded and arbitrary binary data may be unescaped.

Note
Earlier RFC (2396, 1738 and 1630) list the tilde ~ character as special so its handling is ambiguious

Definition in file url.c.

Function Documentation

◆ url_escape()

nserror url_escape ( const char *  unescaped,
bool  sptoplus,
const char *  escexceptions,
char **  result 
)

Escape a string suitable for inclusion in an URL.

Parameters
[in]unescapedthe unescaped string
[in]sptoplustrue iff spaces should be converted to +
[in]escexceptionsNULL or a string of characters to be excluded from escaping.
[out]resultReturns pointer to buffer to escaped string. Returned string is '\0' terminated.
Returns
NSERROR_OK on success

Definition at line 131 of file url.c.

References NSERROR_BAD_PARAMETER, NSERROR_NOMEM, NSERROR_OK, and result.

Referenced by atari_path_to_nsurl(), form_url_encode(), make_search_nsurl(), posix_path_to_nsurl(), and ro_path_to_nsurl().

Here is the caller graph for this function:

◆ url_unescape()

nserror url_unescape ( const char *  str,
size_t  length,
size_t *  length_out,
char **  result_out 
)

Convert an escaped string to plain.

Parameters
[in]strString to unescape.
[in]lengthLength of string or 0 to use strlen.
[out]length_outIff non-NULL, value updated to length of returned result_out string (excluding trailing '\0'`).
[out]result_outReturns unescaped string, owned by caller. Must be freed with free(). Returned string has trailing '\0'.
Returns
NSERROR_OK on success

Definition at line 67 of file url.c.

References ascii_is_hex(), NSERROR_BAD_PARAMETER, NSERROR_NOMEM, NSERROR_OK, result, and xdigit_to_hex().

Referenced by amiga_nsurl_to_path(), atari_nsurl_to_path(), download_ro_filetype(), fetch_data_process(), posix_nsurl_to_path(), ro_nsurl_to_path(), url_to_path(), and windows_nsurl_to_path().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xdigit_to_hex()

static char xdigit_to_hex ( char  c)
inlinestatic

Convert a hex digit to a hex value.

Must be called with valid hex char, results undefined otherwise.

Parameters
[in]ccharacter to convert to value
Returns
the value of c

Definition at line 54 of file url.c.

Referenced by url_unescape().

Here is the caller graph for this function: