iPXE
|
Uniform Resource Identifiers. More...
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <ctype.h>
#include <ipxe/vsprintf.h>
#include <ipxe/params.h>
#include <ipxe/tcpip.h>
#include <ipxe/uri.h>
Go to the source code of this file.
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
size_t | uri_decode (const char *encoded, void *buf, size_t len) |
Decode URI field. More... | |
static void | uri_decode_inplace (char *encoded) |
Decode URI field in-place. More... | |
static int | uri_character_escaped (char c, unsigned int field) |
Check if character should be escaped within a URI field. More... | |
size_t | uri_encode (unsigned int field, const void *raw, size_t raw_len, char *buf, ssize_t len) |
Encode URI field. More... | |
size_t | uri_encode_string (unsigned int field, const char *string, char *buf, ssize_t len) |
Encode URI field string. More... | |
static void | uri_dump (const struct uri *uri) |
Dump URI for debugging. More... | |
static void | uri_free (struct refcnt *refcnt) |
Free URI. More... | |
struct uri * | parse_uri (const char *uri_string) |
Parse URI. More... | |
unsigned int | uri_port (const struct uri *uri, unsigned int default_port) |
Get port from URI. More... | |
size_t | format_uri (const struct uri *uri, char *buf, size_t len) |
Format URI. More... | |
char * | format_uri_alloc (const struct uri *uri) |
Format URI. More... | |
static size_t | uri_copy_fields (const struct uri *src, struct uri *dest) |
Copy URI fields. More... | |
struct uri * | uri_dup (const struct uri *uri) |
Duplicate URI. More... | |
char * | resolve_path (const char *base_path, const char *relative_path) |
Resolve base+relative path. More... | |
struct uri * | resolve_uri (const struct uri *base_uri, struct uri *relative_uri) |
Resolve base+relative URI. More... | |
static struct uri * | tftp_uri (struct sockaddr *sa_server, const char *filename) |
Construct TFTP URI from server address and filename. More... | |
struct uri * | pxe_uri (struct sockaddr *sa_server, const char *filename) |
Construct URI from server address and filename. More... | |
Uniform Resource Identifiers.
Definition in file uri.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
Decode URI field.
encoded | Encoded field |
buf | Data buffer |
len | Length |
len | Length of data |
URI decoding can never increase the length of a string; we can therefore safely decode in place.
Definition at line 53 of file uri.c.
References c, count, len, out, snprintf(), and strtoul().
Referenced by parse_uristring_setting(), and uri_decode_inplace().
|
static |
Decode URI field in-place.
encoded | Encoded field, or NULL |
Definition at line 84 of file uri.c.
References len, strlen(), and uri_decode().
Referenced by parse_uri(), and resolve_uri().
|
static |
Check if character should be escaped within a URI field.
c | Character |
field | URI field index |
escaped | Character should be escaped |
Definition at line 106 of file uri.c.
References c, isprint(), strchr(), URI_EPATH, URI_HOST, URI_OPAQUE, URI_PASSWORD, URI_PATH, URI_PORT, URI_SCHEME, and URI_USER.
Referenced by uri_encode().
Encode URI field.
field | URI field index |
raw | Raw data |
raw_len | Length of raw data |
buf | Buffer |
len | Length of buffer |
len | Length of encoded string (excluding NUL) |
Definition at line 200 of file uri.c.
References c, len, raw, raw_len, ssnprintf(), and uri_character_escaped().
Referenced by format_uristring_setting(), ocsp_uri_string(), and uri_encode_string().
Encode URI field string.
field | URI field index |
string | String |
buf | Buffer |
len | Length of buffer |
len | Length of encoded string (excluding NUL) |
Definition at line 235 of file uri.c.
References len, strlen(), and uri_encode().
Referenced by format_uri(), and http_form_params().
|
static |
Dump URI for debugging.
uri | URI |
Definition at line 246 of file uri.c.
References DBGC, uri::efragment, uri::epath, uri::equery, uri::host, parameters::name, uri::opaque, uri::params, uri::password, uri::path, uri::port, uri::scheme, and uri::user.
Referenced by format_uri(), parse_uri(), and uri_dup().
|
static |
Free URI.
refcnt | Reference count |
Definition at line 279 of file uri.c.
References container_of, free, and uri::params.
Referenced by parse_uri(), and uri_dup().
struct uri* parse_uri | ( | const char * | uri_string | ) |
Parse URI.
uri_string | URI as a string |
uri | URI |
Splits a URI into its component parts. The return URI structure is dynamically allocated and must eventually be freed by calling uri_put().
Definition at line 296 of file uri.c.
References DBGC, done, uri::efragment, uri::epath, uri::equery, find_parameters(), uri::host, isalpha(), memcpy(), memmove(), NULL, uri::opaque, uri::params, uri::password, uri::path, uri::port, raw, raw_len, ref_init, uri::refcnt, uri::scheme, strchr(), strcpy(), strlen(), strncmp(), strrchr(), strstr(), tmp, uri_decode_inplace(), uri_dump(), URI_EPATH, uri_field, uri_free(), uri::user, and zalloc().
Referenced by cwuri_fetch_uri(), efi_path_uri(), fetch_root_path(), http_redirect(), imgdownload_string(), peerblk_retrieval_uri(), pxe_uri(), sanboot_core_exec(), tftp_apply_settings(), uri_churi_okx(), uri_params_okx(), uri_parse_okx(), uri_port_okx(), uri_resolve_okx(), and xfer_open_uri_string().
unsigned int uri_port | ( | const struct uri * | uri, |
unsigned int | default_port | ||
) |
Get port from URI.
uri | URI, or NULL |
default_port | Default port to use if none specified in URI |
port | Port |
Definition at line 455 of file uri.c.
References NULL, uri::port, and strtoul().
Referenced by ftp_open(), http_connect(), slam_open(), tcp_open_uri(), tftp_core_open(), udp_open_uri(), and uri_port_okx().
Format URI.
uri | URI |
buf | Buffer to fill with URI string |
size | Size of buffer |
len | Length of URI string |
Definition at line 471 of file uri.c.
References DBGC, uri::epath, uri::host, len, NULL, prefix, ssnprintf(), uri_dump(), URI_EFRAGMENT, uri_encode_string(), URI_EQUERY, uri_field, URI_FIELDS, URI_HOST, URI_PASSWORD, URI_PATH, URI_PORT, URI_SCHEME, and uri::user.
Referenced by efi_uri_path(), format_uri_alloc(), http_open(), multiboot_add_cmdline(), uri_format_okx(), and uri_pxe_okx().
char* format_uri_alloc | ( | const struct uri * | uri | ) |
Format URI.
uri | URI |
string | URI string, or NULL on failure |
The caller is responsible for eventually freeing the allocated memory.
Definition at line 540 of file uri.c.
References format_uri(), len, malloc(), NULL, and string.
Referenced by cwuri_fetch_uri(), imgdownload(), uri_churi_okx(), uri_format_okx(), and uri_resolve_okx().
Copy URI fields.
src | Source URI |
dest | Destination URI, or NULL to calculate length |
len | Length of raw URI |
Definition at line 558 of file uri.c.
References dest, len, memcpy(), out, src, strlen(), uri_field, and URI_FIELDS.
Referenced by uri_dup().
Duplicate URI.
uri | URI |
uri | Duplicate URI |
Creates a modifiable copy of a URI.
Definition at line 594 of file uri.c.
References DBGC, len, NULL, uri::params, ref_init, uri::refcnt, uri_copy_fields(), uri_dump(), uri_free(), and zalloc().
Referenced by resolve_uri(), tftp_uri(), uri_dup_okx(), and uri_params_okx().
char* resolve_path | ( | const char * | base_path, |
const char * | relative_path | ||
) |
Resolve base+relative path.
base_uri | Base path |
relative_uri | Relative path |
resolved_uri | Resolved path, or NULL on failure |
Takes a base path (e.g. "/var/lib/tftpboot/vmlinuz" and a relative path (e.g. "initrd.gz") and produces a new path (e.g. "/var/lib/tftpboot/initrd.gz"). Note that any non-directory portion of the base path will automatically be stripped; this matches the semantics used when resolving the path component of URIs.
Definition at line 632 of file uri.c.
References asprintf(), dirname(), free, NULL, strdup(), and strlen().
Referenced by efi_local_open_path(), resolve_uri(), and uri_resolve_path_okx().
Resolve base+relative URI.
base_uri | Base URI, or NULL |
relative_uri | Relative URI |
resolved_uri | Resolved URI, or NULL on failure |
Takes a base URI (e.g. "http://ipxe.org/kernels/vmlinuz" and a relative URI (e.g. "../initrds/initrd.gz") and produces a new URI (e.g. "http://ipxe.org/initrds/initrd.gz").
Definition at line 694 of file uri.c.
References uri::efragment, uri::epath, uri::equery, free, memcpy(), NULL, uri::params, uri::path, resolve_path(), strdup(), uri_decode_inplace(), uri_dup(), uri_get(), and uri_is_absolute().
Referenced by churi(), cwuri_fetch_uri(), http_redirect(), imgdownload(), uri_resolve_okx(), and xfer_open_uri().
Construct TFTP URI from server address and filename.
sa_server | Server address |
filename | Filename |
uri | URI, or NULL on failure |
Definition at line 753 of file uri.c.
References asprintf(), free, memset(), ntohs, NULL, uri::path, snprintf(), sock_ntoa(), sockaddr_tcpip::st_port, tmp, and uri_dup().
Referenced by pxe_uri().
Construct URI from server address and filename.
sa_server | Server address |
filename | Filename |
uri | URI, or NULL on failure |
PXE TFTP filenames specified via the DHCP next-server field often contain characters such as ':' or '#' which would confuse the generic URI parser. We provide a mechanism for directly constructing a TFTP URI from the next-server and filename.
Definition at line 808 of file uri.c.
References NULL, uri::opaque, parse_uri(), tftp_uri(), uri_is_absolute(), and uri_put().
Referenced by efi_pxe_tftp_open(), fetch_next_server_and_filename(), pxe_tftp_open(), and uri_pxe_okx().