Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
fd6d06b4
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fd6d06b4
编写于
5月 10, 2006
作者:
K
Karel Zak
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
XML-RPC errors checks
上级
0d8e15fa
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
134 addition
and
57 deletion
+134
-57
ChangeLog
ChangeLog
+5
-0
include/libvirt/virterror.h
include/libvirt/virterror.h
+1
-0
include/virterror.h
include/virterror.h
+1
-0
src/virterror.c
src/virterror.c
+3
-0
src/xml.c
src/xml.c
+0
-8
src/xmlrpc.c
src/xmlrpc.c
+124
-49
未找到文件。
ChangeLog
浏览文件 @
fd6d06b4
Wed May 10 15:50:32 CEST 2006 Karel Zak <kzak@redhat.com>
* src/virterror.c include/virterror.h: added VIR_FROM_RPC
* src/xmlrpc.c: added checks and _virRaiseError()
Wed May 10 13:17:00 CEST 2006 Karel Zak <kzak@redhat.com>
* src/xml.c src/xml.h: added virBufferNew() and virBufferStrcat()
...
...
include/libvirt/virterror.h
浏览文件 @
fd6d06b4
...
...
@@ -44,6 +44,7 @@ typedef enum {
VIR_FROM_SEXPR
,
/* Error in the S-Epression code */
VIR_FROM_XML
,
/* Error in the XML code */
VIR_FROM_DOM
,
/* Error when operating on a domain */
VIR_FROM_RPC
/* Error in the XML-RPC code */
}
virErrorDomain
;
...
...
include/virterror.h
浏览文件 @
fd6d06b4
...
...
@@ -44,6 +44,7 @@ typedef enum {
VIR_FROM_SEXPR
,
/* Error in the S-Epression code */
VIR_FROM_XML
,
/* Error in the XML code */
VIR_FROM_DOM
,
/* Error when operating on a domain */
VIR_FROM_RPC
/* Error in the XML-RPC code */
}
virErrorDomain
;
...
...
src/virterror.c
浏览文件 @
fd6d06b4
...
...
@@ -262,6 +262,9 @@ virDefaultErrorFunc(virErrorPtr err)
case
VIR_FROM_DOM
:
dom
=
"Domain "
;
break
;
case
VIR_FROM_RPC
:
dom
=
"XML-RPC "
;
break
;
}
if
((
err
->
dom
!=
NULL
)
&&
(
err
->
code
!=
VIR_ERR_INVALID_DOMAIN
))
{
domain
=
err
->
dom
->
name
;
...
...
src/xml.c
浏览文件 @
fd6d06b4
...
...
@@ -23,14 +23,6 @@
#include "sexpr.h"
#include "xml.h"
/**
* virXenError:
* @conn: the connection if available
* @error: the error number
* @info: extra information string
*
* Handle an error at the xend daemon interface
*/
static
void
virXMLError
(
virErrorNumber
error
,
const
char
*
info
,
int
value
)
{
...
...
src/xmlrpc.c
浏览文件 @
fd6d06b4
...
...
@@ -9,6 +9,7 @@
*/
#include "xmlrpc.h"
#include "internal.h"
#include <libxml/nanohttp.h>
...
...
@@ -20,8 +21,6 @@
2) xmlRpcValueToSexpr
*/
#define TODO do { } while (0)
static
xmlNodePtr
xmlFirstElement
(
xmlNodePtr
node
);
static
xmlNodePtr
xmlNextElement
(
xmlNodePtr
node
);
...
...
@@ -32,10 +31,25 @@ struct _xmlRpcContext
char
*
faultMessage
;
};
static
void
xmlRpcError
(
virErrorNumber
error
,
const
char
*
info
,
int
value
)
{
const
char
*
errmsg
;
if
(
error
==
VIR_ERR_OK
)
return
;
errmsg
=
__virErrorMsg
(
error
,
info
);
__virRaiseError
(
NULL
,
NULL
,
VIR_FROM_RPC
,
error
,
VIR_ERR_ERROR
,
errmsg
,
info
,
NULL
,
value
,
0
,
errmsg
,
info
,
value
);
}
static
xmlRpcValuePtr
xmlRpcValueNew
(
xmlRpcValueType
type
)
{
xmlRpcValuePtr
ret
=
malloc
(
sizeof
(
*
ret
));
if
(
ret
)
if
(
!
ret
)
xmlRpcError
(
VIR_ERR_NO_MEMORY
,
"allocate value"
,
sizeof
(
*
ret
));
else
ret
->
kind
=
type
;
return
ret
;
}
...
...
@@ -43,8 +57,13 @@ static xmlRpcValuePtr xmlRpcValueNew(xmlRpcValueType type)
static
char
*
xmlGetText
(
xmlNodePtr
node
)
{
for
(
node
=
node
->
children
;
node
;
node
=
node
->
next
)
if
(
node
->
type
==
XML_TEXT_NODE
)
return
strdup
((
const
char
*
)
node
->
content
);
if
(
node
->
type
==
XML_TEXT_NODE
)
{
char
*
x
=
strdup
((
const
char
*
)
node
->
content
);
if
(
!
x
)
xmlRpcError
(
VIR_ERR_NO_MEMORY
,
"copying node content"
,
strlen
((
const
char
*
)
node
->
content
));
return
x
;
}
return
NULL
;
}
...
...
@@ -67,13 +86,15 @@ static xmlNodePtr xmlNextElement(xmlNodePtr node)
static
xmlRpcValuePtr
xmlRpcValueUnmarshalDateTime
(
xmlNodePtr
node
ATTRIBUTE_UNUSED
)
{
/* we don't need this */
TODO
;
TODO
return
NULL
;
}
static
xmlRpcValuePtr
xmlRpcValueUnmarshalString
(
xmlNodePtr
node
)
{
xmlRpcValuePtr
ret
=
xmlRpcValueNew
(
XML_RPC_STRING
);
if
(
ret
)
ret
->
value
.
string
=
xmlGetText
(
node
);
return
ret
;
}
...
...
@@ -81,7 +102,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalString(xmlNodePtr node)
static
xmlRpcValuePtr
xmlRpcValueUnmarshalBase64
(
xmlNodePtr
node
ATTRIBUTE_UNUSED
)
{
/* we don't need this */
TODO
;
TODO
return
NULL
;
}
...
...
@@ -90,10 +111,10 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalInteger(xmlNodePtr node)
xmlRpcValuePtr
ret
=
xmlRpcValueNew
(
XML_RPC_INTEGER
);
char
*
value
=
xmlGetText
(
node
);
if
(
ret
&&
value
)
ret
->
value
.
integer
=
atoi
(
value
);
if
(
value
)
free
(
value
);
return
ret
;
}
...
...
@@ -102,13 +123,14 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalBoolean(xmlNodePtr node)
xmlRpcValuePtr
ret
=
xmlRpcValueNew
(
XML_RPC_BOOLEAN
);
char
*
value
=
xmlGetText
(
node
);
if
(
atoi
(
value
))
if
(
!
ret
)
return
NULL
;
if
(
value
&&
atoi
(
value
))
ret
->
value
.
boolean
=
true
;
else
ret
->
value
.
boolean
=
false
;
if
(
value
)
free
(
value
);
return
ret
;
}
...
...
@@ -117,10 +139,10 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalDouble(xmlNodePtr node)
xmlRpcValuePtr
ret
=
xmlRpcValueNew
(
XML_RPC_DOUBLE
);
char
*
value
=
xmlGetText
(
node
);
if
(
ret
&&
value
)
ret
->
value
.
real
=
atof
(
value
);
if
(
value
)
free
(
value
);
return
ret
;
}
...
...
@@ -130,11 +152,19 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalArray(xmlNodePtr node)
xmlNodePtr
cur
;
int
n_elements
=
0
;
if
(
!
ret
)
return
NULL
;
for
(
cur
=
xmlFirstElement
(
node
);
cur
;
cur
=
xmlNextElement
(
cur
))
n_elements
+=
1
;
ret
->
value
.
array
.
elements
=
malloc
(
n_elements
*
sizeof
(
xmlRpcValue
));
if
(
!
ret
->
value
.
array
.
elements
)
{
xmlRpcError
(
VIR_ERR_NO_MEMORY
,
"allocate value array"
,
n_elements
*
sizeof
(
xmlRpcValue
));
free
(
ret
);
return
NULL
;
}
n_elements
=
0
;
for
(
cur
=
xmlFirstElement
(
node
);
cur
;
cur
=
xmlNextElement
(
cur
))
{
ret
->
value
.
array
.
elements
[
n_elements
]
=
xmlRpcValueUnmarshal
(
cur
);
...
...
@@ -151,6 +181,10 @@ static xmlRpcValueDictElementPtr xmlRpcValueUnmarshalDictElement(xmlNodePtr node
xmlRpcValueDictElementPtr
ret
=
malloc
(
sizeof
(
*
ret
));
xmlNodePtr
cur
;
if
(
!
ret
)
{
xmlRpcError
(
VIR_ERR_NO_MEMORY
,
"allocate dict"
,
sizeof
(
*
ret
));
return
NULL
;
}
memset
(
ret
,
0
,
sizeof
(
*
ret
));
for
(
cur
=
xmlFirstElement
(
node
);
cur
;
cur
=
xmlNextElement
(
cur
))
{
...
...
@@ -159,7 +193,13 @@ static xmlRpcValueDictElementPtr xmlRpcValueUnmarshalDictElement(xmlNodePtr node
}
else
if
(
xmlStrEqual
(
cur
->
name
,
BAD_CAST
"value"
))
{
ret
->
value
=
xmlRpcValueUnmarshal
(
cur
);
}
else
{
/* What? */
xmlRpcError
(
VIR_ERR_XML_ERROR
,
"unexpected dict node"
,
0
);
if
(
ret
->
name
)
free
(
ret
->
name
);
if
(
ret
->
value
)
xmlRpcValueFree
(
ret
->
value
);
free
(
ret
);
return
NULL
;
}
}
...
...
@@ -174,13 +214,20 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalDict(xmlNodePtr node)
xmlRpcValuePtr
ret
=
xmlRpcValueNew
(
XML_RPC_STRUCT
);
xmlNodePtr
cur
;
if
(
!
ret
)
return
NULL
;
ret
->
value
.
dict
.
root
=
root
;
for
(
cur
=
xmlFirstElement
(
node
);
cur
;
cur
=
xmlNextElement
(
cur
))
{
*
elem
=
xmlRpcValueUnmarshalDictElement
(
cur
);
if
(
*
elem
==
NULL
)
{
xmlRpcValueFree
(
ret
);
return
NULL
;
}
elem
=
&
(
*
elem
)
->
next
;
}
ret
->
value
.
dict
.
root
=
root
;
return
ret
;
}
...
...
@@ -218,7 +265,7 @@ xmlRpcValuePtr xmlRpcValueUnmarshal(xmlNodePtr node)
}
else
if
(
xmlStrEqual
(
node
->
name
,
BAD_CAST
"nil"
))
{
ret
=
xmlRpcValueNew
(
XML_RPC_NIL
);
}
else
{
/* bug */
xmlRpcError
(
VIR_ERR_XML_ERROR
,
"unexpected value node"
,
0
);
}
return
ret
;
...
...
@@ -299,11 +346,11 @@ void xmlRpcValueMarshal(xmlRpcValuePtr value, virBufferPtr buf, int indent)
break
;
case
XML_RPC_DATE_TIME
:
/* FIXME */
TODO
;
TODO
break
;
case
XML_RPC_BASE64
:
/* FIXME */
TODO
;
TODO
break
;
case
XML_RPC_STRING
:
virBufferStrcat
(
buf
,
...
...
@@ -344,6 +391,9 @@ virBufferPtr xmlRpcMarshalRequest(const char *request,
xmlRpcValuePtr
xmlRpcUnmarshalResponse
(
xmlNodePtr
node
,
bool
*
is_fault
)
{
if
(
!
node
)
return
NULL
;
if
(
!
xmlStrEqual
(
node
->
name
,
BAD_CAST
"methodResponse"
))
return
NULL
;
...
...
@@ -361,7 +411,6 @@ xmlRpcValuePtr xmlRpcUnmarshalResponse(xmlNodePtr node, bool *is_fault)
return
xmlRpcValueUnmarshal
(
xmlFirstElement
(
node
));
}
else
return
NULL
;
}
static
char
*
xmlRpcCallRaw
(
const
char
*
url
,
const
char
*
request
)
...
...
@@ -378,24 +427,29 @@ static char *xmlRpcCallRaw(const char *url, const char *request)
NULL
,
strlen
(
request
));
if
(
cxt
==
NULL
)
if
(
cxt
==
NULL
)
{
xmlRpcError
(
VIR_ERR_POST_FAILED
,
"send request"
,
0
);
goto
error
;
}
if
(
contentType
&&
strcmp
(
contentType
,
"text/xml"
)
!=
0
)
{
errno
=
EINVAL
;
xmlRpcError
(
VIR_ERR_POST_FAILED
,
"unexpected mime type"
,
0
);
goto
error
;
}
len
=
xmlNanoHTTPContentLength
(
cxt
);
response
=
malloc
(
len
+
1
);
if
(
response
==
NULL
)
if
(
response
==
NULL
)
{
xmlRpcError
(
VIR_ERR_NO_MEMORY
,
"allocate response"
,
len
);
goto
error
;
}
ret
=
xmlNanoHTTPRead
(
cxt
,
response
,
len
);
if
(
ret
!=
len
)
{
errno
=
EINVAL
;
free
(
response
);
response
=
NULL
;
xmlRpcError
(
VIR_ERR_POST_FAILED
,
"read response"
,
0
);
}
response
[
len
]
=
0
;
...
...
@@ -426,8 +480,10 @@ static char **xmlRpcStringArray(xmlRpcValuePtr value)
if
(
value
->
value
.
array
.
elements
[
i
]
->
kind
==
XML_RPC_STRING
)
size
+=
strlen
(
value
->
value
.
array
.
elements
[
i
]
->
value
.
string
)
+
1
;
ptr
=
malloc
(
size
);
if
(
!
(
ptr
=
malloc
(
size
)))
{
xmlRpcError
(
VIR_ERR_NO_MEMORY
,
"allocate string array"
,
size
);
return
NULL
;
}
ret
=
(
char
**
)
ptr
;
ptr
+=
sizeof
(
char
*
)
*
(
value
->
value
.
array
.
n_elements
+
1
);
...
...
@@ -454,28 +510,34 @@ xmlRpcArgvNew(const char *fmt, va_list ap, int *argc)
int
i
;
*
argc
=
strlen
(
fmt
);
argv
=
malloc
(
sizeof
(
*
argv
)
*
*
argc
);
if
(
!
(
argv
=
malloc
(
sizeof
(
*
argv
)
*
*
argc
)))
{
xmlRpcError
(
VIR_ERR_NO_MEMORY
,
"read response"
,
sizeof
(
*
argv
)
*
*
argc
);
return
NULL
;
}
i
=
0
;
for
(
ptr
=
fmt
;
*
ptr
;
ptr
++
)
{
switch
(
*
ptr
)
{
case
'i'
:
argv
[
i
]
=
xmlRpcValueNew
(
XML_RPC_INTEGER
);
if
((
argv
[
i
]
=
xmlRpcValueNew
(
XML_RPC_INTEGER
)))
argv
[
i
]
->
value
.
integer
=
va_arg
(
ap
,
int32_t
);
break
;
case
'f'
:
argv
[
i
]
=
xmlRpcValueNew
(
XML_RPC_DOUBLE
);
if
((
argv
[
i
]
=
xmlRpcValueNew
(
XML_RPC_DOUBLE
)))
argv
[
i
]
->
value
.
real
=
va_arg
(
ap
,
double
);
break
;
case
'b'
:
argv
[
i
]
=
xmlRpcValueNew
(
XML_RPC_BOOLEAN
);
if
((
argv
[
i
]
=
xmlRpcValueNew
(
XML_RPC_BOOLEAN
)))
argv
[
i
]
->
value
.
boolean
=
va_arg
(
ap
,
int
);
break
;
case
's'
:
argv
[
i
]
=
xmlRpcValueNew
(
XML_RPC_STRING
);
if
((
argv
[
i
]
=
xmlRpcValueNew
(
XML_RPC_STRING
)))
argv
[
i
]
->
value
.
string
=
strdup
(
va_arg
(
ap
,
const
char
*
));
break
;
default:
argv
[
i
]
=
NULL
;
break
;
}
if
(
argv
[
i
]
==
NULL
)
{
xmlRpcArgvFree
(
i
,
argv
);
return
NULL
;
}
...
...
@@ -488,6 +550,8 @@ void
xmlRpcArgvFree
(
int
argc
,
xmlRpcValuePtr
*
argv
)
{
int
i
;
if
(
!
argv
)
return
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
xmlRpcValueFree
(
argv
[
i
]);
...
...
@@ -513,7 +577,8 @@ int xmlRpcCall(xmlRpcContextPtr context, const char *method,
if
(
retfmt
&&
*
retfmt
)
retval
=
va_arg
(
ap
,
void
*
);
argv
=
xmlRpcArgvNew
(
fmt
,
ap
,
&
argc
);
if
(
!
(
argv
=
xmlRpcArgvNew
(
fmt
,
ap
,
&
argc
)))
return
-
1
;
va_end
(
ap
);
...
...
@@ -521,10 +586,16 @@ int xmlRpcCall(xmlRpcContextPtr context, const char *method,
xmlRpcArgvFree
(
argc
,
argv
);
if
(
!
buf
)
return
-
1
;
ret
=
xmlRpcCallRaw
(
context
->
uri
,
buf
->
content
);
virBufferFree
(
buf
);
if
(
!
ret
)
return
-
1
;
xml
=
xmlReadDoc
((
const
xmlChar
*
)
ret
,
"response.xml"
,
NULL
,
XML_PARSE_NOENT
|
XML_PARSE_NONET
|
XML_PARSE_NOERROR
|
XML_PARSE_NOWARNING
);
...
...
@@ -532,6 +603,7 @@ int xmlRpcCall(xmlRpcContextPtr context, const char *method,
if
(
xml
==
NULL
)
{
errno
=
EINVAL
;
xmlRpcError
(
VIR_ERR_XML_ERROR
,
"parse server response failed"
,
0
);
return
-
1
;
}
...
...
@@ -572,7 +644,9 @@ int xmlRpcCall(xmlRpcContextPtr context, const char *method,
xmlFreeDoc
(
xml
);
if
(
fault
)
{
/* FIXME we need generic dict routines */
if
(
fault
)
{
/* FIXME we need generic dict routines */
/* FIXME we need faultMessage propagate to libvirt error API */
context
->
faultCode
=
value
->
value
.
dict
.
root
->
value
->
value
.
integer
;
context
->
faultMessage
=
strdup
(
value
->
value
.
dict
.
root
->
next
->
value
->
value
.
string
);
xmlRpcValueFree
(
value
);
...
...
@@ -592,7 +666,8 @@ xmlRpcContextPtr xmlRpcContextNew(const char *uri)
if
(
ret
)
{
ret
->
uri
=
strdup
(
uri
);
ret
->
faultMessage
=
NULL
;
}
}
else
xmlRpcError
(
VIR_ERR_NO_MEMORY
,
"allocate new context"
,
sizeof
(
*
ret
));
return
ret
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录