Ejemplo n.º 1
0
/**
 * Duplicate URI
 *
 * @v uri		URI
 * @ret uri		Duplicate URI
 *
 * Creates a modifiable copy of a URI.
 */
struct uri * uri_dup ( struct uri *uri ) {
	size_t len = ( unparse_uri ( NULL, 0, uri ) + 1 );
	char buf[len];

	unparse_uri ( buf, len, uri );
	return parse_uri ( buf );
}
Ejemplo n.º 2
0
/**
 * Fetch an image
 *
 * @v uri_string	URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
 * @v name		Name for image, or NULL
 * @v register_image	Image registration routine
 * @ret rc		Return status code
 */
int imgfetch ( struct image *image, const char *uri_string,
	       int ( * image_register ) ( struct image *image ) ) {
	char uri_string_redacted[ strlen ( uri_string ) + 3 /* "***" */
				  + 1 /* NUL */ ];
	struct uri *uri;
	const char *password;
	int rc;

	if ( ! ( uri = parse_uri ( uri_string ) ) )
		return -ENOMEM;

	image_set_uri ( image, uri );

	/* Redact password portion of URI, if necessary */
	password = uri->password;
	if ( password )
		uri->password = "******";
	unparse_uri ( uri_string_redacted, sizeof ( uri_string_redacted ),
		      uri, URI_ALL );
	uri->password = password;

	if ( ( rc = create_downloader ( &monojob, image, image_register,
					LOCATION_URI, uri ) ) == 0 )
		rc = monojob_wait ( uri_string_redacted );

	uri_put ( uri );
	return rc;
}
Ejemplo n.º 3
0
static int test_parse_unparse ( const char *uri_string ) {
	char buf[URI_MAX_LEN];
	size_t len;
	struct uri *uri = NULL;
	int rc;

	/* Parse and unparse URI */
	uri = parse_uri ( uri_string );
	if ( ! uri ) {
		rc = -ENOMEM;
		goto done;
	}
	len = unparse_uri ( buf, sizeof ( buf ), uri, URI_ALL );

	/* Compare result */
	if ( strcmp ( buf, uri_string ) != 0 ) {
		printf ( "Unparse of \"%s\" produced \"%s\"\n",
			 uri_string, buf );
		rc = -EINVAL;
		goto done;
	}

	rc = 0;

 done:
	uri_put ( uri );
	if ( rc ) {
		printf ( "URI parse-unparse of \"%s\" failed: %s\n",
			 uri_string, strerror ( rc ) );
	}
	return rc;
}
Ejemplo n.º 4
0
static int test_resolve ( const char *base_uri_string,
			  const char *relative_uri_string,
			  const char *resolved_uri_string ) {
	struct uri *base_uri = NULL;
	struct uri *relative_uri = NULL;
	struct uri *resolved_uri = NULL;
	char buf[URI_MAX_LEN];
	size_t len;
	int rc;

	/* Parse URIs */
	base_uri = parse_uri ( base_uri_string );
	if ( ! base_uri ) {
		rc = -ENOMEM;
		goto done;
	}
	relative_uri = parse_uri ( relative_uri_string );
	if ( ! relative_uri ) {
		rc = -ENOMEM;
		goto done;
	}

	/* Resolve URI */
	resolved_uri = resolve_uri ( base_uri, relative_uri );
	if ( ! resolved_uri ) {
		rc = -ENOMEM;
		goto done;
	}

	/* Compare result */
	len = unparse_uri ( buf, sizeof ( buf ), resolved_uri, URI_ALL );
	if ( strcmp ( buf, resolved_uri_string ) != 0 ) {
		printf ( "Resolution of \"%s\"+\"%s\" produced \"%s\"\n",
			 base_uri_string, relative_uri_string, buf );
		rc = -EINVAL;
		goto done;
	}

	rc = 0;

 done:
	uri_put ( base_uri );
	uri_put ( relative_uri );
	uri_put ( resolved_uri );
	if ( rc ) {
		printf ( "URI resolution of \"%s\"+\"%s\" failed: %s\n",
			 base_uri_string, relative_uri_string,
			 strerror ( rc ) );
	}
	return rc;
}