diff options
| author | Michael Brown | 2007-06-12 00:54:51 +0200 |
|---|---|---|
| committer | Michael Brown | 2007-06-12 00:54:51 +0200 |
| commit | 15dae1e04240f8135e2f04ef6297db8e9f32f496 (patch) | |
| tree | 5dab229dc91b526802c7f85b34f0382739202fbd /src/core | |
| parent | Remove unused headers. (diff) | |
| download | ipxe-15dae1e04240f8135e2f04ef6297db8e9f32f496.tar.gz ipxe-15dae1e04240f8135e2f04ef6297db8e9f32f496.tar.xz ipxe-15dae1e04240f8135e2f04ef6297db8e9f32f496.zip | |
Add concept of "current working URI".
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/cwuri.c | 42 | ||||
| -rw-r--r-- | src/core/uri.c | 21 |
2 files changed, 58 insertions, 5 deletions
diff --git a/src/core/cwuri.c b/src/core/cwuri.c new file mode 100644 index 000000000..cf5e90f8d --- /dev/null +++ b/src/core/cwuri.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stddef.h> +#include <gpxe/uri.h> + +/** @file + * + * Current working URI + * + * Somewhat analogous to the current working directory in a POSIX + * system. + */ + +/** Current working URI */ +struct uri *cwuri = NULL; + +/** + * Change working URI + * + * @v uri New working URI + */ +void churi ( struct uri *uri ) { + if ( cwuri ) + uri_put ( cwuri ); + cwuri = uri_get ( uri ); +} diff --git a/src/core/uri.c b/src/core/uri.c index a793c4577..8cb855a6b 100644 --- a/src/core/uri.c +++ b/src/core/uri.c @@ -35,6 +35,8 @@ * @v uri URI */ static void dump_uri ( struct uri *uri ) { + if ( ! uri ) + return; if ( uri->scheme ) DBG ( " scheme \"%s\"", uri->scheme ); if ( uri->opaque ) @@ -174,12 +176,14 @@ struct uri * parse_uri ( const char *uri_string ) { /** * Get port from URI * - * @v uri URI + * @v uri URI, or NULL * @v default_port Default port to use if none specified in URI * @ret port Port */ unsigned int uri_port ( struct uri *uri, unsigned int default_port ) { - return ( uri->port ? strtoul ( uri->port, NULL, 0 ) : default_port ); + if ( ( ! uri ) || ( ! uri->port ) ) + return default_port; + return ( strtoul ( uri->port, NULL, 0 ) ); } /** @@ -187,7 +191,7 @@ unsigned int uri_port ( struct uri *uri, unsigned int default_port ) { * * @v buf Buffer to fill with URI string * @v size Size of buffer - * @v uri URI to write into buffer + * @v uri URI to write into buffer, or NULL * @ret len Length of URI string */ int unparse_uri ( char *buf, size_t size, struct uri *uri ) { @@ -197,6 +201,13 @@ int unparse_uri ( char *buf, size_t size, struct uri *uri ) { dump_uri ( uri ); DBG ( "\n" ); + /* Special-case NULL URI */ + if ( ! uri ) { + if ( size ) + buf[0] = '\0'; + return 0; + } + /* Special-case opaque URIs */ if ( uri->opaque ) { return ssnprintf ( ( buf + used ), ( size - used ), @@ -332,7 +343,7 @@ char * resolve_path ( const char *base_path, /** * Resolve base+relative URI * - * @v base_uri Base URI + * @v base_uri Base URI, or NULL * @v relative_uri Relative URI * @ret resolved_uri Resolved URI * @@ -347,7 +358,7 @@ struct uri * resolve_uri ( struct uri *base_uri, struct uri *new_uri; /* If relative URI is absolute, just re-use it */ - if ( uri_is_absolute ( relative_uri ) ) + if ( uri_is_absolute ( relative_uri ) || ( ! base_uri ) ) return uri_get ( relative_uri ); /* Mangle URI */ |
