const char *uristr)
{
virURIPtr uri = NULL;
+ const char *path = NULL;
char **scheme = NULL;
int ret = -1;
/* XXX We currently don't support auth, so don't bother parsing it */
- /* possibly skip the leading slash */
- if (uri->path &&
- VIR_STRDUP(src->path,
- *uri->path == '/' ? uri->path + 1 : uri->path) < 0)
+ /* uri->path is NULL if the URI does not contain slash after host:
+ * transport://host:port */
+ if (uri->path)
+ path = uri->path;
+ else
+ path = "";
+
+ /* possibly skip the leading slash */
+ if (path[0] == '/')
+ path++;
+
+ /* NBD allows empty export name (path) */
+ if (src->protocol == VIR_STORAGE_NET_PROTOCOL_NBD &&
+ path[0] == '\0')
+ path = NULL;
+
+ if (VIR_STRDUP(src->path, path) < 0)
goto cleanup;
if (src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER) {
/* type VIR_STORAGE_TYPE_BLOCK is not tested since it parses back to 'file' */
/* type VIR_STORAGE_TYPE_DIR it is a 'format' driver in qemu */
+ TEST_JSON_FORMAT_NET("<source protocol='http' name=''>\n"
+ " <host name='example.com' port='80'/>\n"
+ "</source>\n");
TEST_JSON_FORMAT_NET("<source protocol='http' name='file'>\n"
" <host name='example.com' port='80'/>\n"
"</source>\n");
TEST_BACKING_PARSE("path", "<source file='path'/>\n");
TEST_BACKING_PARSE("://", NULL);
+ TEST_BACKING_PARSE("http://example.com",
+ "<source protocol='http' name=''>\n"
+ " <host name='example.com' port='80'/>\n"
+ "</source>\n");
+ TEST_BACKING_PARSE("http://example.com/",
+ "<source protocol='http' name=''>\n"
+ " <host name='example.com' port='80'/>\n"
+ "</source>\n");
TEST_BACKING_PARSE("http://example.com/file",
"<source protocol='http' name='file'>\n"
" <host name='example.com' port='80'/>\n"
"<source protocol='nbd' name='blah'>\n"
" <host name='example.org' port='6000'/>\n"
"</source>\n");
+ TEST_BACKING_PARSE("nbd://example.org:1234",
+ "<source protocol='nbd'>\n"
+ " <host name='example.org' port='1234'/>\n"
+ "</source>\n");
+ TEST_BACKING_PARSE("nbd://example.org:1234/",
+ "<source protocol='nbd'>\n"
+ " <host name='example.org' port='1234'/>\n"
+ "</source>\n");
+ TEST_BACKING_PARSE("nbd://example.org:1234/exportname",
+ "<source protocol='nbd' name='exportname'>\n"
+ " <host name='example.org' port='1234'/>\n"
+ "</source>\n");
#ifdef WITH_YAJL
TEST_BACKING_PARSE("json:", NULL);