iPXE
|
Uniform Resource Identifiers. More...
Go to the source code of this file.
Data Structures | |
struct | uri |
A Uniform Resource Identifier. More... | |
Macros | |
#define | uri_field(uri, field) (&uri->scheme)[field] |
Access URI field. More... | |
#define | URI_FIELD(name) |
Calculate index of a URI field. More... | |
Enumerations | |
enum | uri_fields { URI_SCHEME = URI_FIELD ( scheme ), URI_OPAQUE = URI_FIELD ( opaque ), URI_USER = URI_FIELD ( user ), URI_PASSWORD = URI_FIELD ( password ), URI_HOST = URI_FIELD ( host ), URI_PORT = URI_FIELD ( port ), URI_PATH = URI_FIELD ( path ), URI_EPATH = URI_FIELD ( epath ), URI_EQUERY = URI_FIELD ( equery ), URI_EFRAGMENT = URI_FIELD ( efragment ), URI_FIELDS } |
URI fields. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static int | uri_is_absolute (const struct uri *uri) |
URI is an absolute URI. More... | |
static int | uri_has_opaque (const struct uri *uri) |
URI has an opaque part. More... | |
static int | uri_has_path (const struct uri *uri) |
URI has a path. More... | |
static int | uri_has_absolute_path (const struct uri *uri) |
URI has an absolute path. More... | |
static int | uri_has_relative_path (const struct uri *uri) |
URI has a relative path. More... | |
static struct uri * | uri_get (struct uri *uri) |
Increment URI reference count. More... | |
static void | uri_put (struct uri *uri) |
Decrement URI reference count. More... | |
size_t | uri_decode (const char *encoded, void *buf, size_t len) |
Decode 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... | |
struct uri * | parse_uri (const char *uri_string) |
Parse 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... | |
unsigned int | uri_port (const struct uri *uri, unsigned int default_port) |
Get port from URI. 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... | |
struct uri * | pxe_uri (struct sockaddr *sa_server, const char *filename) |
Construct URI from server address and filename. More... | |
void | churi (struct uri *uri) |
Change working URI. More... | |
Variables | |
struct uri * | cwuri |
Current working URI. More... | |
Uniform Resource Identifiers.
Definition in file uri.h.
#define URI_FIELD | ( | name | ) |
Calculate index of a URI field.
name | URI field name |
field | URI field index |
enum uri_fields |
URI fields.
Enumerator | |
---|---|
URI_SCHEME | |
URI_OPAQUE | |
URI_USER | |
URI_PASSWORD | |
URI_HOST | |
URI_PORT | |
URI_PATH | |
URI_EPATH | |
URI_EQUERY | |
URI_EFRAGMENT | |
URI_FIELDS |
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
inlinestatic |
URI is an absolute URI.
uri | URI |
is_absolute | URI is absolute |
An absolute URI begins with a scheme, e.g. "http:" or "mailto:". Note that this is a separate concept from a URI with an absolute path.
Definition at line 135 of file uri.h.
References NULL, and uri::scheme.
Referenced by netboot(), pxe_uri(), and resolve_uri().
|
inlinestatic |
URI has an opaque part.
uri | URI |
has_opaque | URI has an opaque part |
Definition at line 145 of file uri.h.
References uri::opaque.
|
inlinestatic |
|
inlinestatic |
URI has an absolute path.
uri | URI |
has_absolute_path | URI has an absolute path |
An absolute path begins with a '/'. Note that this is a separate concept from an absolute URI. Note also that a URI may not have a path at all.
Definition at line 169 of file uri.h.
References uri::path.
|
inlinestatic |
URI has a relative path.
uri | URI |
has_relative_path | URI has a relative path |
A relative path begins with something other than a '/'. Note that this is a separate concept from a relative URI. Note also that a URI may not have a path at all.
Definition at line 183 of file uri.h.
References uri::path.
Increment URI reference count.
uri | URI, or NULL |
uri | URI as passed in |
Definition at line 194 of file uri.h.
References ref_get, and uri::refcnt.
Referenced by alloc_sandev(), efi_local_open(), ftp_open(), http_connect(), http_open(), image_exec(), image_set_uri(), peerblk_open(), peermux_filter(), resolve_uri(), tftp_core_open(), and uri_churi_okx().
|
inlinestatic |
Decrement URI reference count.
uri | URI, or NULL |
Definition at line 205 of file uri.h.
References ref_put, and uri::refcnt.
Referenced by churi(), cwuri_fetch_uri(), efi_init_application(), efi_local_free(), efi_pxe_tftp_open(), free_image(), ftp_free(), http_conn_free(), http_free(), http_redirect(), image_exec(), image_set_uri(), imgdownload(), imgdownload_string(), netboot(), peerblk_free(), peerblk_retrieval_open(), peermux_free(), pxe_menu_boot(), pxe_uri(), sanboot_core_exec(), sandev_free(), tftp_apply_settings(), tftp_free(), uri_churi_okx(), uri_dup_okx(), uri_params_okx(), uri_parse_okx(), uri_port_okx(), uri_pxe_okx(), uri_resolve_okx(), xfer_open_uri(), and xfer_open_uri_string().
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().
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().
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().
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().
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().
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 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().
void churi | ( | struct uri * | uri | ) |
Change working URI.
uri | New working URI, or NULL |
Definition at line 45 of file cwuri.c.
References cwuri, NULL, resolve_uri(), and uri_put().
Referenced by efi_init_application(), image_exec(), tftp_apply_settings(), and uri_churi_okx().
struct uri* cwuri |
Current working URI.
Definition at line 38 of file cwuri.c.
Referenced by churi(), cwuri_fetch_uri(), efi_autoexec_network(), image_exec(), imgdownload(), uri_churi_okx(), and xfer_open_uri().