Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
9351cb0a
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9351cb0a
编写于
7月 25, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix reporting of errors against virConnect object in XML apis
上级
cb29913f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
148 addition
and
116 deletion
+148
-116
ChangeLog
ChangeLog
+8
-0
src/domain_conf.c
src/domain_conf.c
+30
-30
src/lxc_conf.c
src/lxc_conf.c
+7
-7
src/network_conf.c
src/network_conf.c
+11
-11
src/storage_conf.c
src/storage_conf.c
+30
-30
src/test.c
src/test.c
+10
-10
src/xml.c
src/xml.c
+34
-19
src/xml.h
src/xml.h
+18
-9
未找到文件。
ChangeLog
浏览文件 @
9351cb0a
Fri Jul 25 15:21:27 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/xml.c, src/xml.h: Take a virConnectPtr object as param
for all methods to allow proper error reporting.
* src/lxc_conf.c, src/domain_conf.c, src/network_conf.c,
src/storage_conf.c, src/test.c: Pass virConnect object
to XML routines
Fri Jul 25 15:03:27 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/xend_internal.c, src/xend_internal.h: Expose the
...
...
src/domain_conf.c
浏览文件 @
9351cb0a
...
...
@@ -1303,7 +1303,7 @@ static int virDomainLifecycleParseXML(virConnectPtr conn,
int
*
val
,
int
defaultVal
)
{
char
*
tmp
=
virXPathString
(
xpath
,
ctxt
);
char
*
tmp
=
virXPathString
(
conn
,
xpath
,
ctxt
);
if
(
tmp
==
NULL
)
{
*
val
=
defaultVal
;
}
else
{
...
...
@@ -1397,7 +1397,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
def
->
id
=
-
1
;
/* Find out what type of QEMU virtualization to use */
if
(
!
(
tmp
=
virXPathString
(
"string(./@type)"
,
ctxt
)))
{
if
(
!
(
tmp
=
virXPathString
(
conn
,
"string(./@type)"
,
ctxt
)))
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"missing domain type attribute"
));
goto
error
;
...
...
@@ -1411,13 +1411,13 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE
(
tmp
);
/* Extract domain name */
if
(
!
(
def
->
name
=
virXPathString
(
"string(./name[1])"
,
ctxt
)))
{
if
(
!
(
def
->
name
=
virXPathString
(
conn
,
"string(./name[1])"
,
ctxt
)))
{
virDomainReportError
(
conn
,
VIR_ERR_NO_NAME
,
NULL
);
goto
error
;
}
/* Extract domain uuid */
tmp
=
virXPathString
(
"string(./uuid[1])"
,
ctxt
);
tmp
=
virXPathString
(
conn
,
"string(./uuid[1])"
,
ctxt
);
if
(
!
tmp
)
{
int
err
;
if
((
err
=
virUUIDGenerate
(
def
->
uuid
)))
{
...
...
@@ -1436,19 +1436,19 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
}
/* Extract domain memory */
if
(
virXPathULong
(
"string(./memory[1])"
,
ctxt
,
&
def
->
maxmem
)
<
0
)
{
if
(
virXPathULong
(
conn
,
"string(./memory[1])"
,
ctxt
,
&
def
->
maxmem
)
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"missing memory element"
));
goto
error
;
}
if
(
virXPathULong
(
"string(./currentMemory[1])"
,
ctxt
,
&
def
->
memory
)
<
0
)
if
(
virXPathULong
(
conn
,
"string(./currentMemory[1])"
,
ctxt
,
&
def
->
memory
)
<
0
)
def
->
memory
=
def
->
maxmem
;
if
(
virXPathULong
(
"string(./vcpu[1])"
,
ctxt
,
&
def
->
vcpus
)
<
0
)
if
(
virXPathULong
(
conn
,
"string(./vcpu[1])"
,
ctxt
,
&
def
->
vcpus
)
<
0
)
def
->
vcpus
=
1
;
tmp
=
virXPathString
(
"string(./vcpu[1]/@cpuset)"
,
ctxt
);
tmp
=
virXPathString
(
conn
,
"string(./vcpu[1]/@cpuset)"
,
ctxt
);
if
(
tmp
)
{
char
*
set
=
tmp
;
def
->
cpumasklen
=
VIR_DOMAIN_CPUMASK_LEN
;
...
...
@@ -1463,7 +1463,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE
(
tmp
);
}
if
((
n
=
virXPathNodeSet
(
"./features/*"
,
ctxt
,
&
nodes
))
>
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./features/*"
,
ctxt
,
&
nodes
))
>
0
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
{
int
val
=
virDomainFeatureTypeFromString
((
const
char
*
)
nodes
[
i
]
->
name
);
if
(
val
<
0
)
{
...
...
@@ -1490,15 +1490,15 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
goto
error
;
tmp
=
virXPathString
(
"string(./clock/@offset)"
,
ctxt
);
tmp
=
virXPathString
(
conn
,
"string(./clock/@offset)"
,
ctxt
);
if
(
tmp
&&
STREQ
(
tmp
,
"localtime"
))
def
->
localtime
=
1
;
VIR_FREE
(
tmp
);
def
->
os
.
bootloader
=
virXPathString
(
"string(./bootloader)"
,
ctxt
);
def
->
os
.
bootloaderArgs
=
virXPathString
(
"string(./bootloader_args)"
,
ctxt
);
def
->
os
.
bootloader
=
virXPathString
(
conn
,
"string(./bootloader)"
,
ctxt
);
def
->
os
.
bootloaderArgs
=
virXPathString
(
conn
,
"string(./bootloader_args)"
,
ctxt
);
def
->
os
.
type
=
virXPathString
(
"string(./os/type[1])"
,
ctxt
);
def
->
os
.
type
=
virXPathString
(
conn
,
"string(./os/type[1])"
,
ctxt
);
if
(
!
def
->
os
.
type
)
{
if
(
def
->
os
.
bootloader
)
{
def
->
os
.
type
=
strdup
(
"xen"
);
...
...
@@ -1532,7 +1532,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
goto
error
;
}
def
->
os
.
arch
=
virXPathString
(
"string(./os/type[1]/@arch)"
,
ctxt
);
def
->
os
.
arch
=
virXPathString
(
conn
,
"string(./os/type[1]/@arch)"
,
ctxt
);
if
(
!
def
->
os
.
arch
)
{
const
char
*
defaultArch
=
virCapabilitiesDefaultGuestArch
(
caps
,
def
->
os
.
type
);
if
(
defaultArch
==
NULL
)
{
...
...
@@ -1547,7 +1547,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
}
}
def
->
os
.
machine
=
virXPathString
(
"string(./os/type[1]/@machine)"
,
ctxt
);
def
->
os
.
machine
=
virXPathString
(
conn
,
"string(./os/type[1]/@machine)"
,
ctxt
);
if
(
!
def
->
os
.
machine
)
{
const
char
*
defaultMachine
=
virCapabilitiesDefaultGuestMachine
(
caps
,
def
->
os
.
type
,
...
...
@@ -1561,14 +1561,14 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
}
if
(
!
def
->
os
.
bootloader
)
{
def
->
os
.
kernel
=
virXPathString
(
"string(./os/kernel[1])"
,
ctxt
);
def
->
os
.
initrd
=
virXPathString
(
"string(./os/initrd[1])"
,
ctxt
);
def
->
os
.
cmdline
=
virXPathString
(
"string(./os/cmdline[1])"
,
ctxt
);
def
->
os
.
root
=
virXPathString
(
"string(./os/root[1])"
,
ctxt
);
def
->
os
.
loader
=
virXPathString
(
"string(./os/loader[1])"
,
ctxt
);
def
->
os
.
kernel
=
virXPathString
(
conn
,
"string(./os/kernel[1])"
,
ctxt
);
def
->
os
.
initrd
=
virXPathString
(
conn
,
"string(./os/initrd[1])"
,
ctxt
);
def
->
os
.
cmdline
=
virXPathString
(
conn
,
"string(./os/cmdline[1])"
,
ctxt
);
def
->
os
.
root
=
virXPathString
(
conn
,
"string(./os/root[1])"
,
ctxt
);
def
->
os
.
loader
=
virXPathString
(
conn
,
"string(./os/loader[1])"
,
ctxt
);
/* analysis of the boot devices */
if
((
n
=
virXPathNodeSet
(
"./os/boot"
,
ctxt
,
&
nodes
))
<
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./os/boot"
,
ctxt
,
&
nodes
))
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot extract boot device"
));
goto
error
;
...
...
@@ -1598,7 +1598,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE
(
nodes
);
}
def
->
emulator
=
virXPathString
(
"string(./devices/emulator[1])"
,
ctxt
);
def
->
emulator
=
virXPathString
(
conn
,
"string(./devices/emulator[1])"
,
ctxt
);
if
(
!
def
->
emulator
)
{
const
char
*
type
=
virDomainVirtTypeToString
(
def
->
virtType
);
if
(
!
type
)
{
...
...
@@ -1622,7 +1622,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
}
/* analysis of the disk devices */
if
((
n
=
virXPathNodeSet
(
"./devices/disk"
,
ctxt
,
&
nodes
))
<
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./devices/disk"
,
ctxt
,
&
nodes
))
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot extract disk devices"
));
goto
error
;
...
...
@@ -1652,7 +1652,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE
(
nodes
);
/* analysis of the network devices */
if
((
n
=
virXPathNodeSet
(
"./devices/interface"
,
ctxt
,
&
nodes
))
<
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./devices/interface"
,
ctxt
,
&
nodes
))
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot extract network devices"
));
goto
error
;
...
...
@@ -1670,7 +1670,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
/* analysis of the character devices */
if
((
n
=
virXPathNodeSet
(
"./devices/parallel"
,
ctxt
,
&
nodes
))
<
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./devices/parallel"
,
ctxt
,
&
nodes
))
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot extract parallel devices"
));
goto
error
;
...
...
@@ -1687,7 +1687,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
}
VIR_FREE
(
nodes
);
if
((
n
=
virXPathNodeSet
(
"./devices/serial"
,
ctxt
,
&
nodes
))
<
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./devices/serial"
,
ctxt
,
&
nodes
))
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot extract serial devices"
));
goto
error
;
...
...
@@ -1709,7 +1709,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
* devices which is the legacy syntax for the same thing
*/
if
(
def
->
serials
==
NULL
)
{
if
((
node
=
virXPathNode
(
"./devices/console[1]"
,
ctxt
))
!=
NULL
)
{
if
((
node
=
virXPathNode
(
conn
,
"./devices/console[1]"
,
ctxt
))
!=
NULL
)
{
virDomainChrDefPtr
chr
=
virDomainChrDefParseXML
(
conn
,
node
);
if
(
!
chr
)
...
...
@@ -1731,7 +1731,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
/* analysis of the input devices */
if
((
n
=
virXPathNodeSet
(
"./devices/input"
,
ctxt
,
&
nodes
))
<
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./devices/input"
,
ctxt
,
&
nodes
))
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot extract input devices"
));
goto
error
;
...
...
@@ -1763,7 +1763,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
VIR_FREE
(
nodes
);
/* analysis of the input devices */
if
((
n
=
virXPathNodeSet
(
"./devices/graphics"
,
ctxt
,
&
nodes
))
<
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./devices/graphics"
,
ctxt
,
&
nodes
))
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot extract graphics devices"
));
goto
error
;
...
...
@@ -1799,7 +1799,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
/* analysis of the sound devices */
if
((
n
=
virXPathNodeSet
(
"./devices/sound"
,
ctxt
,
&
nodes
))
<
0
)
{
if
((
n
=
virXPathNodeSet
(
conn
,
"./devices/sound"
,
ctxt
,
&
nodes
))
<
0
)
{
virDomainReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot extract sound devices"
));
goto
error
;
...
...
src/lxc_conf.c
浏览文件 @
9351cb0a
...
...
@@ -210,7 +210,7 @@ static int lxcParseDomainInterfaces(virConnectPtr conn,
DEBUG0
(
"parsing nets"
);
res
=
virXPathNodeSet
(
"/domain/devices/interface"
,
contextPtr
,
&
list
);
res
=
virXPathNodeSet
(
conn
,
"/domain/devices/interface"
,
contextPtr
,
&
list
);
if
(
res
>
0
)
{
for
(
i
=
0
;
i
<
res
;
++
i
)
{
netDef
=
calloc
(
1
,
sizeof
(
lxc_net_def_t
));
...
...
@@ -338,7 +338,7 @@ static int lxcParseDomainName(virConnectPtr conn, char **name,
{
char
*
res
;
res
=
virXPathString
(
"string(/domain/name[1])"
,
contextPtr
);
res
=
virXPathString
(
conn
,
"string(/domain/name[1])"
,
contextPtr
);
if
(
res
==
NULL
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_NO_NAME
,
NULL
);
return
(
-
1
);
...
...
@@ -353,7 +353,7 @@ static int lxcParseDomainUUID(virConnectPtr conn, unsigned char *uuid,
{
char
*
res
;
res
=
virXPathString
(
"string(/domain/uuid[1])"
,
contextPtr
);
res
=
virXPathString
(
conn
,
"string(/domain/uuid[1])"
,
contextPtr
);
if
(
res
==
NULL
)
{
if
(
virUUIDGenerate
(
uuid
))
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
...
...
@@ -384,7 +384,7 @@ static int lxcParseDomainMounts(virConnectPtr conn,
xmlNodePtr
*
list
;
int
res
;
res
=
virXPathNodeSet
(
"/domain/devices/filesystem"
,
contextPtr
,
&
list
);
res
=
virXPathNodeSet
(
conn
,
"/domain/devices/filesystem"
,
contextPtr
,
&
list
);
if
(
res
>
0
)
{
for
(
i
=
0
;
i
<
res
;
++
i
)
{
if
(
VIR_ALLOC
(
mountObj
)
<
0
)
{
...
...
@@ -422,7 +422,7 @@ static int lxcParseDomainInit(virConnectPtr conn, char** init,
{
char
*
res
;
res
=
virXPathString
(
"string(/domain/os/init[1])"
,
contextPtr
);
res
=
virXPathString
(
conn
,
"string(/domain/os/init[1])"
,
contextPtr
);
if
(
res
==
NULL
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"invalid or missing init element"
));
...
...
@@ -446,7 +446,7 @@ static int lxcParseDomainTty(virConnectPtr conn, char **tty, xmlXPathContextPtr
{
char
*
res
;
res
=
virXPathString
(
"string(/domain/devices/console[1]/@tty)"
,
contextPtr
);
res
=
virXPathString
(
conn
,
"string(/domain/devices/console[1]/@tty)"
,
contextPtr
);
if
(
res
==
NULL
)
{
/* make sure the tty string is empty */
*
tty
=
strdup
(
""
);
...
...
@@ -466,7 +466,7 @@ static int lxcParseDomainMemory(virConnectPtr conn, int* memory, xmlXPathContext
long
res
;
int
rc
;
rc
=
virXPathLong
(
"string(/domain/memory[1])"
,
contextPtr
,
&
res
);
rc
=
virXPathLong
(
conn
,
"string(/domain/memory[1])"
,
contextPtr
,
&
res
);
if
((
rc
==
-
2
)
||
((
rc
==
0
)
&&
(
res
<=
0
)))
{
*
memory
=
-
1
;
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
...
...
src/network_conf.c
浏览文件 @
9351cb0a
...
...
@@ -243,14 +243,14 @@ virNetworkDefParseXML(virConnectPtr conn,
}
/* Extract network name */
def
->
name
=
virXPathString
(
"string(./name[1])"
,
ctxt
);
def
->
name
=
virXPathString
(
conn
,
"string(./name[1])"
,
ctxt
);
if
(
!
def
->
name
)
{
virNetworkReportError
(
conn
,
VIR_ERR_NO_NAME
,
NULL
);
goto
error
;
}
/* Extract network uuid */
tmp
=
virXPathString
(
"string(./uuid[1])"
,
ctxt
);
tmp
=
virXPathString
(
conn
,
"string(./uuid[1])"
,
ctxt
);
if
(
!
tmp
)
{
int
err
;
if
((
err
=
virUUIDGenerate
(
def
->
uuid
)))
{
...
...
@@ -269,16 +269,16 @@ virNetworkDefParseXML(virConnectPtr conn,
}
/* Parse bridge information */
def
->
bridge
=
virXPathString
(
"string(./bridge[1]/@name)"
,
ctxt
);
tmp
=
virXPathString
(
"string(./bridge[1]/@stp)"
,
ctxt
);
def
->
bridge
=
virXPathString
(
conn
,
"string(./bridge[1]/@name)"
,
ctxt
);
tmp
=
virXPathString
(
conn
,
"string(./bridge[1]/@stp)"
,
ctxt
);
def
->
stp
=
(
tmp
&&
STREQ
(
tmp
,
"off"
))
?
0
:
1
;
VIR_FREE
(
tmp
);
if
(
virXPathULong
(
"string(./bridge[1]/@delay)"
,
ctxt
,
&
def
->
delay
)
<
0
)
if
(
virXPathULong
(
conn
,
"string(./bridge[1]/@delay)"
,
ctxt
,
&
def
->
delay
)
<
0
)
def
->
delay
=
0
;
def
->
ipAddress
=
virXPathString
(
"string(./ip[1]/@address)"
,
ctxt
);
def
->
netmask
=
virXPathString
(
"string(./ip[1]/@netmask)"
,
ctxt
);
def
->
ipAddress
=
virXPathString
(
conn
,
"string(./ip[1]/@address)"
,
ctxt
);
def
->
netmask
=
virXPathString
(
conn
,
"string(./ip[1]/@netmask)"
,
ctxt
);
if
(
def
->
ipAddress
&&
def
->
netmask
)
{
/* XXX someday we want IPv6 too, so inet_aton won't work there */
...
...
@@ -307,14 +307,14 @@ virNetworkDefParseXML(virConnectPtr conn,
goto
error
;
}
if
((
dhcp
=
virXPathNode
(
"./ip[1]/dhcp[1]"
,
ctxt
))
&&
if
((
dhcp
=
virXPathNode
(
conn
,
"./ip[1]/dhcp[1]"
,
ctxt
))
&&
virNetworkDHCPRangeDefParseXML
(
conn
,
def
,
dhcp
)
<
0
)
goto
error
;
}
/* IPv4 forwarding setup */
if
(
virXPathBoolean
(
"count(./forward) > 0"
,
ctxt
))
{
if
(
virXPathBoolean
(
conn
,
"count(./forward) > 0"
,
ctxt
))
{
if
(
!
def
->
ipAddress
||
!
def
->
netmask
)
{
virNetworkReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
...
...
@@ -322,7 +322,7 @@ virNetworkDefParseXML(virConnectPtr conn,
goto
error
;
}
tmp
=
virXPathString
(
"string(./forward[1]/@mode)"
,
ctxt
);
tmp
=
virXPathString
(
conn
,
"string(./forward[1]/@mode)"
,
ctxt
);
if
(
tmp
)
{
if
((
def
->
forwardType
=
virNetworkForwardTypeFromString
(
tmp
))
<
0
)
{
virNetworkReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
...
...
@@ -336,7 +336,7 @@ virNetworkDefParseXML(virConnectPtr conn,
}
def
->
forwardDev
=
virXPathString
(
"string(./forward[1]/@dev)"
,
ctxt
);
def
->
forwardDev
=
virXPathString
(
conn
,
"string(./forward[1]/@dev)"
,
ctxt
);
}
else
{
def
->
forwardType
=
VIR_NETWORK_FORWARD_NONE
;
}
...
...
src/storage_conf.c
浏览文件 @
9351cb0a
...
...
@@ -149,14 +149,14 @@ static int
virStoragePoolDefParseAuthChap
(
virConnectPtr
conn
,
xmlXPathContextPtr
ctxt
,
virStoragePoolAuthChapPtr
auth
)
{
auth
->
login
=
virXPathString
(
"string(/pool/source/auth/@login)"
,
ctxt
);
auth
->
login
=
virXPathString
(
conn
,
"string(/pool/source/auth/@login)"
,
ctxt
);
if
(
auth
->
login
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing auth host attribute"
));
return
-
1
;
}
auth
->
passwd
=
virXPathString
(
"string(/pool/source/auth/@passwd)"
,
ctxt
);
auth
->
passwd
=
virXPathString
(
conn
,
"string(/pool/source/auth/@passwd)"
,
ctxt
);
if
(
auth
->
passwd
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing auth passwd attribute"
));
...
...
@@ -174,7 +174,7 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
char
*
mode
;
long
v
;
mode
=
virXPathString
(
"string(/pool/permissions/mode)"
,
ctxt
);
mode
=
virXPathString
(
conn
,
"string(/pool/permissions/mode)"
,
ctxt
);
if
(
!
mode
)
{
perms
->
mode
=
0700
;
}
else
{
...
...
@@ -187,10 +187,10 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
}
}
if
(
virXPathNode
(
"/pool/permissions/owner"
,
ctxt
)
==
NULL
)
{
if
(
virXPathNode
(
conn
,
"/pool/permissions/owner"
,
ctxt
)
==
NULL
)
{
perms
->
uid
=
getuid
();
}
else
{
if
(
virXPathLong
(
"number(/pool/permissions/owner)"
,
ctxt
,
&
v
)
<
0
)
{
if
(
virXPathLong
(
conn
,
"number(/pool/permissions/owner)"
,
ctxt
,
&
v
)
<
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"malformed owner element"
));
return
-
1
;
...
...
@@ -198,10 +198,10 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
perms
->
uid
=
(
int
)
v
;
}
if
(
virXPathNode
(
"/pool/permissions/group"
,
ctxt
)
==
NULL
)
{
if
(
virXPathNode
(
conn
,
"/pool/permissions/group"
,
ctxt
)
==
NULL
)
{
perms
->
uid
=
getgid
();
}
else
{
if
(
virXPathLong
(
"number(/pool/permissions/group)"
,
ctxt
,
&
v
)
<
0
)
{
if
(
virXPathLong
(
conn
,
"number(/pool/permissions/group)"
,
ctxt
,
&
v
)
<
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"malformed group element"
));
return
-
1
;
...
...
@@ -210,7 +210,7 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
}
/* NB, we're ignoring missing labels here - they'll simply inherit */
perms
->
label
=
virXPathString
(
"string(/pool/permissions/label)"
,
ctxt
);
perms
->
label
=
virXPathString
(
conn
,
"string(/pool/permissions/label)"
,
ctxt
);
return
0
;
}
...
...
@@ -248,13 +248,13 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
goto
cleanup
;
}
if
((
ret
->
name
=
virXPathString
(
"string(/pool/name)"
,
ctxt
))
==
NULL
)
{
if
((
ret
->
name
=
virXPathString
(
conn
,
"string(/pool/name)"
,
ctxt
))
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing name element"
));
goto
cleanup
;
}
uuid
=
virXPathString
(
"string(/pool/uuid)"
,
ctxt
);
uuid
=
virXPathString
(
conn
,
"string(/pool/uuid)"
,
ctxt
);
if
(
uuid
==
NULL
)
{
if
(
virUUIDGenerate
(
ret
->
uuid
)
<
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
...
...
@@ -271,7 +271,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
}
if
(
options
->
formatFromString
)
{
char
*
format
=
virXPathString
(
"string(/pool/source/format/@type)"
,
ctxt
);
char
*
format
=
virXPathString
(
conn
,
"string(/pool/source/format/@type)"
,
ctxt
);
if
((
ret
->
source
.
format
=
(
options
->
formatFromString
)(
conn
,
format
))
<
0
)
{
VIR_FREE
(
format
);
goto
cleanup
;
...
...
@@ -280,7 +280,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
}
if
(
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_HOST
)
{
if
((
ret
->
source
.
host
.
name
=
virXPathString
(
"string(/pool/source/host/@name)"
,
ctxt
))
==
NULL
)
{
if
((
ret
->
source
.
host
.
name
=
virXPathString
(
conn
,
"string(/pool/source/host/@name)"
,
ctxt
))
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing source host name"
));
goto
cleanup
;
...
...
@@ -290,7 +290,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
xmlNodePtr
*
nodeset
=
NULL
;
int
nsource
,
i
;
if
((
nsource
=
virXPathNodeSet
(
"/pool/source/device"
,
ctxt
,
&
nodeset
))
<=
0
)
{
if
((
nsource
=
virXPathNodeSet
(
conn
,
"/pool/source/device"
,
ctxt
,
&
nodeset
))
<=
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"cannot extract source devices"
));
goto
cleanup
;
...
...
@@ -314,7 +314,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
ret
->
source
.
ndevice
=
nsource
;
}
if
(
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_DIR
)
{
if
((
ret
->
source
.
dir
=
virXPathString
(
"string(/pool/source/dir/@path)"
,
ctxt
))
==
NULL
)
{
if
((
ret
->
source
.
dir
=
virXPathString
(
conn
,
"string(/pool/source/dir/@path)"
,
ctxt
))
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing source path"
));
goto
cleanup
;
...
...
@@ -322,7 +322,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
}
authType
=
virXPathString
(
"string(/pool/source/auth/@type)"
,
ctxt
);
authType
=
virXPathString
(
conn
,
"string(/pool/source/auth/@type)"
,
ctxt
);
if
(
authType
==
NULL
)
{
ret
->
source
.
authType
=
VIR_STORAGE_POOL_AUTH_NONE
;
}
else
{
...
...
@@ -343,7 +343,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
goto
cleanup
;
}
if
((
ret
->
target
.
path
=
virXPathString
(
"string(/pool/target/path)"
,
ctxt
))
==
NULL
)
{
if
((
ret
->
target
.
path
=
virXPathString
(
conn
,
"string(/pool/target/path)"
,
ctxt
))
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing target path"
));
goto
cleanup
;
...
...
@@ -522,7 +522,7 @@ virStorageVolDefParsePerms(virConnectPtr conn,
char
*
mode
;
long
v
;
mode
=
virXPathString
(
"string(/volume/permissions/mode)"
,
ctxt
);
mode
=
virXPathString
(
conn
,
"string(/volume/permissions/mode)"
,
ctxt
);
if
(
!
mode
)
{
perms
->
mode
=
0600
;
}
else
{
...
...
@@ -535,20 +535,20 @@ virStorageVolDefParsePerms(virConnectPtr conn,
}
}
if
(
virXPathNode
(
"/volume/permissions/owner"
,
ctxt
)
==
NULL
)
{
if
(
virXPathNode
(
conn
,
"/volume/permissions/owner"
,
ctxt
)
==
NULL
)
{
perms
->
uid
=
getuid
();
}
else
{
if
(
virXPathLong
(
"number(/volume/permissions/owner)"
,
ctxt
,
&
v
)
<
0
)
{
if
(
virXPathLong
(
conn
,
"number(/volume/permissions/owner)"
,
ctxt
,
&
v
)
<
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing owner element"
));
return
-
1
;
}
perms
->
uid
=
(
int
)
v
;
}
if
(
virXPathNode
(
"/volume/permissions/group"
,
ctxt
)
==
NULL
)
{
if
(
virXPathNode
(
conn
,
"/volume/permissions/group"
,
ctxt
)
==
NULL
)
{
perms
->
gid
=
getgid
();
}
else
{
if
(
virXPathLong
(
"number(/volume/permissions/group)"
,
ctxt
,
&
v
)
<
0
)
{
if
(
virXPathLong
(
conn
,
"number(/volume/permissions/group)"
,
ctxt
,
&
v
)
<
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing owner element"
));
return
-
1
;
...
...
@@ -557,7 +557,7 @@ virStorageVolDefParsePerms(virConnectPtr conn,
}
/* NB, we're ignoring missing labels here - they'll simply inherit */
perms
->
label
=
virXPathString
(
"string(/volume/permissions/label)"
,
ctxt
);
perms
->
label
=
virXPathString
(
conn
,
"string(/volume/permissions/label)"
,
ctxt
);
return
0
;
}
...
...
@@ -662,7 +662,7 @@ virStorageVolDefParseDoc(virConnectPtr conn,
goto
cleanup
;
}
ret
->
name
=
virXPathString
(
"string(/volume/name)"
,
ctxt
);
ret
->
name
=
virXPathString
(
conn
,
"string(/volume/name)"
,
ctxt
);
if
(
ret
->
name
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing name element"
));
...
...
@@ -670,10 +670,10 @@ virStorageVolDefParseDoc(virConnectPtr conn,
}
/* Auto-generated so deliberately ignore */
/*ret->key = virXPathString("string(/volume/key)", ctxt);*/
/*ret->key = virXPathString(
conn,
"string(/volume/key)", ctxt);*/
capacity
=
virXPathString
(
"string(/volume/capacity)"
,
ctxt
);
unit
=
virXPathString
(
"string(/volume/capacity/@unit)"
,
ctxt
);
capacity
=
virXPathString
(
conn
,
"string(/volume/capacity)"
,
ctxt
);
unit
=
virXPathString
(
conn
,
"string(/volume/capacity/@unit)"
,
ctxt
);
if
(
capacity
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"missing capacity element"
));
...
...
@@ -684,9 +684,9 @@ virStorageVolDefParseDoc(virConnectPtr conn,
VIR_FREE
(
capacity
);
VIR_FREE
(
unit
);
allocation
=
virXPathString
(
"string(/volume/allocation)"
,
ctxt
);
allocation
=
virXPathString
(
conn
,
"string(/volume/allocation)"
,
ctxt
);
if
(
allocation
)
{
unit
=
virXPathString
(
"string(/volume/allocation/@unit)"
,
ctxt
);
unit
=
virXPathString
(
conn
,
"string(/volume/allocation/@unit)"
,
ctxt
);
if
(
virStorageSize
(
conn
,
unit
,
allocation
,
&
ret
->
allocation
)
<
0
)
goto
cleanup
;
VIR_FREE
(
allocation
);
...
...
@@ -695,9 +695,9 @@ virStorageVolDefParseDoc(virConnectPtr conn,
ret
->
allocation
=
ret
->
capacity
;
}
ret
->
target
.
path
=
virXPathString
(
"string(/volume/target/path)"
,
ctxt
);
ret
->
target
.
path
=
virXPathString
(
conn
,
"string(/volume/target/path)"
,
ctxt
);
if
(
options
->
formatFromString
)
{
char
*
format
=
virXPathString
(
"string(/volume/target/format/@type)"
,
ctxt
);
char
*
format
=
virXPathString
(
conn
,
"string(/volume/target/format/@type)"
,
ctxt
);
if
((
ret
->
target
.
format
=
(
options
->
formatFromString
)(
conn
,
format
))
<
0
)
{
VIR_FREE
(
format
);
goto
cleanup
;
...
...
src/test.c
浏览文件 @
9351cb0a
...
...
@@ -362,7 +362,7 @@ static int testOpenFromFile(virConnectPtr conn,
memmove
(
&
privconn
->
nodeInfo
,
&
defaultNodeInfo
,
sizeof
(
defaultNodeInfo
));
nodeInfo
=
&
privconn
->
nodeInfo
;
ret
=
virXPathLong
(
"string(/node/cpu/nodes[1])"
,
ctxt
,
&
l
);
ret
=
virXPathLong
(
conn
,
"string(/node/cpu/nodes[1])"
,
ctxt
,
&
l
);
if
(
ret
==
0
)
{
nodeInfo
->
nodes
=
l
;
}
else
if
(
ret
==
-
2
)
{
...
...
@@ -370,7 +370,7 @@ static int testOpenFromFile(virConnectPtr conn,
goto
error
;
}
ret
=
virXPathLong
(
"string(/node/cpu/sockets[1])"
,
ctxt
,
&
l
);
ret
=
virXPathLong
(
conn
,
"string(/node/cpu/sockets[1])"
,
ctxt
,
&
l
);
if
(
ret
==
0
)
{
nodeInfo
->
sockets
=
l
;
}
else
if
(
ret
==
-
2
)
{
...
...
@@ -378,7 +378,7 @@ static int testOpenFromFile(virConnectPtr conn,
goto
error
;
}
ret
=
virXPathLong
(
"string(/node/cpu/cores[1])"
,
ctxt
,
&
l
);
ret
=
virXPathLong
(
conn
,
"string(/node/cpu/cores[1])"
,
ctxt
,
&
l
);
if
(
ret
==
0
)
{
nodeInfo
->
cores
=
l
;
}
else
if
(
ret
==
-
2
)
{
...
...
@@ -386,7 +386,7 @@ static int testOpenFromFile(virConnectPtr conn,
goto
error
;
}
ret
=
virXPathLong
(
"string(/node/cpu/threads[1])"
,
ctxt
,
&
l
);
ret
=
virXPathLong
(
conn
,
"string(/node/cpu/threads[1])"
,
ctxt
,
&
l
);
if
(
ret
==
0
)
{
nodeInfo
->
threads
=
l
;
}
else
if
(
ret
==
-
2
)
{
...
...
@@ -395,7 +395,7 @@ static int testOpenFromFile(virConnectPtr conn,
}
nodeInfo
->
cpus
=
nodeInfo
->
cores
*
nodeInfo
->
threads
*
nodeInfo
->
sockets
*
nodeInfo
->
nodes
;
ret
=
virXPathLong
(
"string(/node/cpu/active[1])"
,
ctxt
,
&
l
);
ret
=
virXPathLong
(
conn
,
"string(/node/cpu/active[1])"
,
ctxt
,
&
l
);
if
(
ret
==
0
)
{
if
(
l
<
nodeInfo
->
cpus
)
{
nodeInfo
->
cpus
=
l
;
...
...
@@ -404,7 +404,7 @@ static int testOpenFromFile(virConnectPtr conn,
testError
(
NULL
,
NULL
,
NULL
,
VIR_ERR_XML_ERROR
,
_
(
"node active cpu"
));
goto
error
;
}
ret
=
virXPathLong
(
"string(/node/cpu/mhz[1])"
,
ctxt
,
&
l
);
ret
=
virXPathLong
(
conn
,
"string(/node/cpu/mhz[1])"
,
ctxt
,
&
l
);
if
(
ret
==
0
)
{
nodeInfo
->
mhz
=
l
;
}
else
if
(
ret
==
-
2
)
{
...
...
@@ -412,14 +412,14 @@ static int testOpenFromFile(virConnectPtr conn,
goto
error
;
}
str
=
virXPathString
(
"string(/node/cpu/model[1])"
,
ctxt
);
str
=
virXPathString
(
conn
,
"string(/node/cpu/model[1])"
,
ctxt
);
if
(
str
!=
NULL
)
{
strncpy
(
nodeInfo
->
model
,
str
,
sizeof
(
nodeInfo
->
model
)
-
1
);
nodeInfo
->
model
[
sizeof
(
nodeInfo
->
model
)
-
1
]
=
'\0'
;
VIR_FREE
(
str
);
}
ret
=
virXPathLong
(
"string(/node/memory[1])"
,
ctxt
,
&
l
);
ret
=
virXPathLong
(
conn
,
"string(/node/memory[1])"
,
ctxt
,
&
l
);
if
(
ret
==
0
)
{
nodeInfo
->
memory
=
l
;
}
else
if
(
ret
==
-
2
)
{
...
...
@@ -427,7 +427,7 @@ static int testOpenFromFile(virConnectPtr conn,
goto
error
;
}
ret
=
virXPathNodeSet
(
"/node/domain"
,
ctxt
,
&
domains
);
ret
=
virXPathNodeSet
(
conn
,
"/node/domain"
,
ctxt
,
&
domains
);
if
(
ret
<
0
)
{
testError
(
NULL
,
NULL
,
NULL
,
VIR_ERR_XML_ERROR
,
_
(
"node domain list"
));
goto
error
;
...
...
@@ -464,7 +464,7 @@ static int testOpenFromFile(virConnectPtr conn,
if
(
domains
!=
NULL
)
VIR_FREE
(
domains
);
ret
=
virXPathNodeSet
(
"/node/network"
,
ctxt
,
&
networks
);
ret
=
virXPathNodeSet
(
conn
,
"/node/network"
,
ctxt
,
&
networks
);
if
(
ret
<
0
)
{
testError
(
NULL
,
NULL
,
NULL
,
VIR_ERR_XML_ERROR
,
_
(
"node network list"
));
goto
error
;
...
...
src/xml.c
浏览文件 @
9351cb0a
...
...
@@ -22,8 +22,6 @@
#include "buf.h"
#include "util.h"
#include "memory.h"
#include "xend_internal.h"
/* for is_sound_* functions */
/**
* virXMLError:
...
...
@@ -66,14 +64,16 @@ virXMLError(virConnectPtr conn, virErrorNumber error, const char *info,
* if the evaluation failed.
*/
char
*
virXPathString
(
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
)
virXPathString
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
)
{
xmlXPathObjectPtr
obj
;
xmlNodePtr
relnode
;
char
*
ret
;
if
((
ctxt
==
NULL
)
||
(
xpath
==
NULL
))
{
virXMLError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
virXMLError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Invalid parameter to virXPathString()"
),
0
);
return
(
NULL
);
}
...
...
@@ -87,7 +87,7 @@ virXPathString(const char *xpath, xmlXPathContextPtr ctxt)
ret
=
strdup
((
char
*
)
obj
->
stringval
);
xmlXPathFreeObject
(
obj
);
if
(
ret
==
NULL
)
{
virXMLError
(
NULL
,
VIR_ERR_NO_MEMORY
,
_
(
"strdup failed"
),
0
);
virXMLError
(
conn
,
VIR_ERR_NO_MEMORY
,
_
(
"strdup failed"
),
0
);
}
ctxt
->
node
=
relnode
;
return
(
ret
);
...
...
@@ -105,13 +105,16 @@ virXPathString(const char *xpath, xmlXPathContextPtr ctxt)
* or -1 if the evaluation failed.
*/
int
virXPathNumber
(
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
double
*
value
)
virXPathNumber
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
double
*
value
)
{
xmlXPathObjectPtr
obj
;
xmlNodePtr
relnode
;
if
((
ctxt
==
NULL
)
||
(
xpath
==
NULL
)
||
(
value
==
NULL
))
{
virXMLError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
virXMLError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Invalid parameter to virXPathNumber()"
),
0
);
return
(
-
1
);
}
...
...
@@ -143,14 +146,17 @@ virXPathNumber(const char *xpath, xmlXPathContextPtr ctxt, double *value)
* value doesn't have a long format.
*/
int
virXPathLong
(
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
long
*
value
)
virXPathLong
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
long
*
value
)
{
xmlXPathObjectPtr
obj
;
xmlNodePtr
relnode
;
int
ret
=
0
;
if
((
ctxt
==
NULL
)
||
(
xpath
==
NULL
)
||
(
value
==
NULL
))
{
virXMLError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
virXMLError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Invalid parameter to virXPathNumber()"
),
0
);
return
(
-
1
);
}
...
...
@@ -195,14 +201,17 @@ virXPathLong(const char *xpath, xmlXPathContextPtr ctxt, long *value)
* value doesn't have a long format.
*/
int
virXPathULong
(
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
unsigned
long
*
value
)
virXPathULong
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
unsigned
long
*
value
)
{
xmlXPathObjectPtr
obj
;
xmlNodePtr
relnode
;
int
ret
=
0
;
if
((
ctxt
==
NULL
)
||
(
xpath
==
NULL
)
||
(
value
==
NULL
))
{
virXMLError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
virXMLError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Invalid parameter to virXPathNumber()"
),
0
);
return
(
-
1
);
}
...
...
@@ -251,14 +260,16 @@ virXMLPropString(xmlNodePtr node,
* Returns 0 if false, 1 if true, or -1 if the evaluation failed.
*/
int
virXPathBoolean
(
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
)
virXPathBoolean
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
)
{
xmlXPathObjectPtr
obj
;
xmlNodePtr
relnode
;
int
ret
;
if
((
ctxt
==
NULL
)
||
(
xpath
==
NULL
))
{
virXMLError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
virXMLError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Invalid parameter to virXPathBoolean()"
),
0
);
return
(
-
1
);
}
...
...
@@ -287,14 +298,16 @@ virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt)
* Returns a pointer to the node or NULL if the evaluation failed.
*/
xmlNodePtr
virXPathNode
(
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
)
virXPathNode
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
)
{
xmlXPathObjectPtr
obj
;
xmlNodePtr
relnode
;
xmlNodePtr
ret
;
if
((
ctxt
==
NULL
)
||
(
xpath
==
NULL
))
{
virXMLError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
virXMLError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Invalid parameter to virXPathNode()"
),
0
);
return
(
NULL
);
}
...
...
@@ -326,15 +339,17 @@ virXPathNode(const char *xpath, xmlXPathContextPtr ctxt)
* must be freed) or -1 if the evaluation failed.
*/
int
virXPathNodeSet
(
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
xmlNodePtr
**
list
)
virXPathNodeSet
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
xmlNodePtr
**
list
)
{
xmlXPathObjectPtr
obj
;
xmlNodePtr
relnode
;
int
ret
;
if
((
ctxt
==
NULL
)
||
(
xpath
==
NULL
))
{
virXMLError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
virXMLError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Invalid parameter to virXPathNodeSet()"
),
0
);
return
(
-
1
);
}
...
...
@@ -354,7 +369,7 @@ virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt,
ret
=
obj
->
nodesetval
->
nodeNr
;
if
(
list
!=
NULL
&&
ret
)
{
if
(
VIR_ALLOC_N
(
*
list
,
ret
)
<
0
)
{
virXMLError
(
NULL
,
VIR_ERR_NO_MEMORY
,
virXMLError
(
conn
,
VIR_ERR_NO_MEMORY
,
_
(
"allocate string array"
),
ret
*
sizeof
(
**
list
));
ret
=
-
1
;
...
...
src/xml.h
浏览文件 @
9351cb0a
...
...
@@ -11,28 +11,37 @@
#include <libxml/tree.h>
#include <libxml/xpath.h>
int
virXPathBoolean
(
const
char
*
xpath
,
int
virXPathBoolean
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
);
char
*
virXPathString
(
const
char
*
xpath
,
char
*
virXPathString
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
);
int
virXPathNumber
(
const
char
*
xpath
,
int
virXPathNumber
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
double
*
value
);
int
virXPathInt
(
const
char
*
xpath
,
int
virXPathInt
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
int
*
value
);
int
virXPathUInt
(
const
char
*
xpath
,
int
virXPathUInt
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
unsigned
int
*
value
);
int
virXPathLong
(
const
char
*
xpath
,
int
virXPathLong
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
long
*
value
);
int
virXPathULong
(
const
char
*
xpath
,
int
virXPathULong
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
unsigned
long
*
value
);
xmlNodePtr
virXPathNode
(
const
char
*
xpath
,
xmlNodePtr
virXPathNode
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
);
int
virXPathNodeSet
(
const
char
*
xpath
,
int
virXPathNodeSet
(
virConnectPtr
conn
,
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
,
xmlNodePtr
**
list
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录