Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ option_a (const char *arg, const char *format, int blocksize,
/* Remote storage. */
drv->type = drv_uri;
drv->uri.path = uri.path;
drv->uri.query = uri.query;
drv->uri.protocol = uri.protocol;
drv->uri.server = uri.server;
drv->uri.username = uri.username;
Expand Down Expand Up @@ -179,6 +180,11 @@ add_drives_handle (guestfs_h *g, struct drv *drv, size_t drive_index)
ad_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_SECRET_BITMASK;
ad_optargs.secret = drv->uri.password;
}
if (drv->uri.query) {
ad_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_QUERY_BITMASK;
ad_optargs.query = drv->uri.query;
}

#ifdef GUESTFS_ADD_DRIVE_OPTS_BLOCKSIZE_BITMASK
if (drv->uri.blocksize) {
ad_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_BLOCKSIZE_BITMASK;
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct drv {
} a;
struct {
char *path; /* disk path */
char *query; /* query string */
char *protocol; /* protocol (eg. "nbd") */
char **server; /* server(s) - can be NULL */
char *username; /* username - can be NULL */
Expand Down
27 changes: 20 additions & 7 deletions options/uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@
#include "uri.h"

static int is_uri (const char *arg);
static int parse (const char *arg, char **path_ret, char **protocol_ret, char ***server_ret, char **username_ret, char **password_ret);
static int parse (const char *arg, char **path_ret, char **query_ret, char **protocol_ret, char ***server_ret, char **username_ret, char **password_ret);
static char *query_get (xmlURIPtr uri, const char *search_name);
static int make_server (xmlURIPtr uri, const char *socket, char ***ret);

int
parse_uri (const char *arg, struct uri *uri_ret)
{
char *path = NULL;
char *query = NULL;
char *protocol = NULL;
char **server = NULL;
char *username = NULL;
char *password = NULL;

/* Does it look like a URI? */
if (is_uri (arg)) {
if (parse (arg, &path, &protocol, &server, &username, &password) == -1)
if (parse (arg, &path, &query, &protocol, &server, &username, &password) == -1)
return -1;
}
else {
Expand All @@ -75,6 +76,7 @@ parse_uri (const char *arg, struct uri *uri_ret)
}

uri_ret->path = path;
uri_ret->query = query;
uri_ret->protocol = protocol;
uri_ret->server = server;
uri_ret->username = username;
Expand Down Expand Up @@ -107,7 +109,7 @@ is_uri (const char *arg)
}

static int
parse (const char *arg, char **path_ret, char **protocol_ret,
parse (const char *arg, char **path_ret, char **query_ret, char **protocol_ret,
char ***server_ret, char **username_ret, char **password_ret)
{
CLEANUP_XMLFREEURI xmlURIPtr uri = NULL;
Expand Down Expand Up @@ -193,16 +195,16 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
* exportname expected will be "pool/disk". Here, uri->path will be
* "/pool/disk" so we have to knock off the leading '/' character.
*/
path = uri->path;
if (path && path[0] == '/' &&
char *tmpPath = uri->path;
if (tmpPath && tmpPath[0] == '/' &&
(STREQ (uri->scheme, "gluster") ||
STREQ (uri->scheme, "iscsi") ||
STRPREFIX (uri->scheme, "nbd") ||
STREQ (uri->scheme, "rbd") ||
STREQ (uri->scheme, "sheepdog")))
path++;
tmpPath++;

*path_ret = strdup (path ? path : "");
*path_ret = strdup (tmpPath ? tmpPath : "");
if (*path_ret == NULL) {
perror ("strdup: path");
free (*protocol_ret);
Expand All @@ -212,6 +214,17 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
return -1;
}

*query_ret = strdup(uri->query_raw ? uri->query_raw : "");
if (*query_ret == NULL) {
perror ("strdup: query");
free (*protocol_ret);
guestfs_int_free_string_list (*server_ret);
free (*username_ret);
free (*password_ret);
free (*path_ret);
return -1;
}

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions options/uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

struct uri {
char *path; /* disk path */
char *query; /* query string */
char *protocol; /* protocol (eg. "file", "nbd") */
char **server; /* server(s) - can be NULL */
char *username; /* username - can be NULL */
Expand Down