Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
6d06b0d8
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看板
提交
6d06b0d8
编写于
11月 18, 2014
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add virXMLValidateAgainstSchema helper method
Add a helper method that can validate an XML document against an RNG schema
上级
c5b6a4a5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
96 addition
and
0 deletion
+96
-0
include/libvirt/virterror.h
include/libvirt/virterror.h
+1
-0
src/internal.h
src/internal.h
+4
-0
src/libvirt_private.syms
src/libvirt_private.syms
+1
-0
src/util/virerror.c
src/util/virerror.c
+6
-0
src/util/virxml.c
src/util/virxml.c
+79
-0
src/util/virxml.h
src/util/virxml.h
+5
-0
未找到文件。
include/libvirt/virterror.h
浏览文件 @
6d06b0d8
...
...
@@ -304,6 +304,7 @@ typedef enum {
VIR_ERR_STORAGE_VOL_EXIST
=
90
,
/* the storage vol already exists */
VIR_ERR_CPU_INCOMPATIBLE
=
91
,
/* given CPU is incompatible with host
CPU*/
VIR_ERR_XML_INVALID_SCHEMA
=
92
,
/* XML document doens't validate against schema */
}
virErrorNumber
;
/**
...
...
src/internal.h
浏览文件 @
6d06b0d8
...
...
@@ -234,11 +234,15 @@
# define VIR_WARNINGS_NO_CAST_ALIGN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wcast-align\"")
# define VIR_WARNINGS_NO_PRINTF \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=format\"")
# define VIR_WARNINGS_RESET \
_Pragma ("GCC diagnostic pop")
# else
# define VIR_WARNINGS_NO_CAST_ALIGN
# define VIR_WARNINGS_NO_PRINTF
# define VIR_WARNINGS_RESET
# endif
...
...
src/libvirt_private.syms
浏览文件 @
6d06b0d8
...
...
@@ -2252,6 +2252,7 @@ virXMLParseHelper;
virXMLPickShellSafeComment;
virXMLPropString;
virXMLSaveFile;
virXMLValidateAgainstSchema;
virXPathBoolean;
virXPathInt;
virXPathLong;
...
...
src/util/virerror.c
浏览文件 @
6d06b0d8
...
...
@@ -1285,6 +1285,12 @@ virErrorMsg(virErrorNumber error, const char *info)
else
errmsg
=
_
(
"the CPU is incompatible with host CPU: %s"
);
break
;
case
VIR_ERR_XML_INVALID_SCHEMA
:
if
(
info
==
NULL
)
errmsg
=
_
(
"XML document failed to validate against schema"
);
else
errmsg
=
_
(
"XML document failed to validate against schema: %s"
);
break
;
}
return
errmsg
;
}
...
...
src/util/virxml.c
浏览文件 @
6d06b0d8
...
...
@@ -1082,3 +1082,82 @@ virXMLInjectNamespace(xmlNodePtr node,
return
0
;
}
static
void
catchRNGError
(
void
*
ctx
,
const
char
*
msg
,
...)
{
virBufferPtr
buf
=
ctx
;
va_list
args
;
va_start
(
args
,
msg
);
VIR_WARNINGS_NO_PRINTF
;
virBufferVasprintf
(
buf
,
msg
,
args
);
VIR_WARNINGS_RESET
;
va_end
(
args
);
}
static
void
ignoreRNGError
(
void
*
ctx
ATTRIBUTE_UNUSED
,
const
char
*
msg
ATTRIBUTE_UNUSED
,
...)
{}
int
virXMLValidateAgainstSchema
(
const
char
*
schemafile
,
xmlDocPtr
doc
)
{
xmlRelaxNGParserCtxtPtr
rngParser
=
NULL
;
xmlRelaxNGPtr
rng
=
NULL
;
xmlRelaxNGValidCtxtPtr
rngValid
=
NULL
;
virBuffer
buf
=
VIR_BUFFER_INITIALIZER
;
int
ret
=
-
1
;
if
(
!
(
rngParser
=
xmlRelaxNGNewParserCtxt
(
schemafile
)))
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"Unable to create RNG parser for %s"
),
schemafile
);
goto
cleanup
;
}
xmlRelaxNGSetParserErrors
(
rngParser
,
catchRNGError
,
ignoreRNGError
,
&
buf
);
if
(
!
(
rng
=
xmlRelaxNGParse
(
rngParser
)))
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"Unable to parse RNG %s: %s"
),
schemafile
,
virBufferCurrentContent
(
&
buf
));
goto
cleanup
;
}
if
(
!
(
rngValid
=
xmlRelaxNGNewValidCtxt
(
rng
)))
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"Unable to create RNG validation context %s"
),
schemafile
);
goto
cleanup
;
}
xmlRelaxNGSetValidErrors
(
rngValid
,
catchRNGError
,
ignoreRNGError
,
&
buf
);
if
(
xmlRelaxNGValidateDoc
(
rngValid
,
doc
)
!=
0
)
{
virReportError
(
VIR_ERR_XML_INVALID_SCHEMA
,
_
(
"Unable to validate doc against %s
\n
%s"
),
schemafile
,
virBufferCurrentContent
(
&
buf
));
goto
cleanup
;
}
ret
=
0
;
cleanup:
virBufferFreeAndReset
(
&
buf
);
xmlRelaxNGFreeParserCtxt
(
rngParser
);
xmlRelaxNGFreeValidCtxt
(
rngValid
);
xmlRelaxNGFree
(
rng
);
return
ret
;
}
src/util/virxml.h
浏览文件 @
6d06b0d8
...
...
@@ -28,6 +28,7 @@
# include <libxml/parser.h>
# include <libxml/tree.h>
# include <libxml/xpath.h>
# include <libxml/relaxng.h>
int
virXPathBoolean
(
const
char
*
xpath
,
xmlXPathContextPtr
ctxt
);
...
...
@@ -176,4 +177,8 @@ int virXMLInjectNamespace(xmlNodePtr node,
const
char
*
uri
,
const
char
*
key
);
int
virXMLValidateAgainstSchema
(
const
char
*
schemafile
,
xmlDocPtr
xml
);
#endif
/* __VIR_XML_H__ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录