Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
d21342af
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,发现更多精彩内容 >>
提交
d21342af
编写于
2月 19, 2011
作者:
M
Matthias Bolte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
esx: Move CURL handling code to it's own type
上级
802e2df9
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
205 addition
and
176 deletion
+205
-176
src/esx/esx_driver.c
src/esx/esx_driver.c
+2
-2
src/esx/esx_vi.c
src/esx/esx_vi.c
+182
-166
src/esx/esx_vi.h
src/esx/esx_vi.h
+21
-8
未找到文件。
src/esx/esx_driver.c
浏览文件 @
d21342af
...
...
@@ -2639,7 +2639,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
url
=
virBufferContentAndReset
(
&
buffer
);
if
(
esxVI_C
ontext_DownloadFile
(
priv
->
primary
,
url
,
&
vmx
)
<
0
)
{
if
(
esxVI_C
URL_Download
(
priv
->
primary
->
curl
,
url
,
&
vmx
)
<
0
)
{
goto
cleanup
;
}
...
...
@@ -3108,7 +3108,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
/* Upload VMX file */
VIR_DEBUG
(
"Uploading .vmx config, url='%s' vmx='%s'"
,
url
,
vmx
);
if
(
esxVI_C
ontext_UploadFile
(
priv
->
primary
,
url
,
vmx
)
<
0
)
{
if
(
esxVI_C
URL_Upload
(
priv
->
primary
->
curl
,
url
,
vmx
)
<
0
)
{
goto
cleanup
;
}
...
...
src/esx/esx_vi.c
浏览文件 @
d21342af
...
...
@@ -76,42 +76,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* C
ontext
* C
URL
*/
/* esxVI_C
ontext
_Alloc */
ESX_VI__TEMPLATE__ALLOC
(
C
ontext
);
/* esxVI_C
URL
_Alloc */
ESX_VI__TEMPLATE__ALLOC
(
C
URL
)
/* esxVI_C
ontext
_Free */
ESX_VI__TEMPLATE__FREE
(
C
ontext
,
/* esxVI_C
URL
_Free */
ESX_VI__TEMPLATE__FREE
(
C
URL
,
{
VIR_FREE
(
item
->
url
);
VIR_FREE
(
item
->
ipAddress
);
if
(
item
->
curl_handle
!=
NULL
)
{
curl_easy_cleanup
(
item
->
curl_handle
);
if
(
item
->
handle
!=
NULL
)
{
curl_easy_cleanup
(
item
->
handle
);
}
if
(
item
->
curl_
headers
!=
NULL
)
{
curl_slist_free_all
(
item
->
curl_
headers
);
if
(
item
->
headers
!=
NULL
)
{
curl_slist_free_all
(
item
->
headers
);
}
virMutexDestroy
(
&
item
->
curl_lock
);
VIR_FREE
(
item
->
username
);
VIR_FREE
(
item
->
password
);
esxVI_ServiceContent_Free
(
&
item
->
service
);
esxVI_UserSession_Free
(
&
item
->
session
);
esxVI_Datacenter_Free
(
&
item
->
datacenter
);
esxVI_ComputeResource_Free
(
&
item
->
computeResource
);
esxVI_HostSystem_Free
(
&
item
->
hostSystem
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_folderToChildEntity
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_hostSystemToParent
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_hostSystemToVm
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_hostSystemToDatastore
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_computeResourceToHost
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_computeResourceToParentToParent
);
});
virMutexDestroy
(
&
item
->
lock
);
})
static
size_t
esxVI_CURL_ReadString
(
char
*
data
,
size_t
size
,
size_t
nmemb
,
void
*
ptrptr
)
...
...
@@ -218,7 +201,7 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
#endif
static
int
esxVI_CURL_Perform
(
esxVI_C
ontext
*
ctx
,
const
char
*
url
)
esxVI_CURL_Perform
(
esxVI_C
URL
*
curl
,
const
char
*
url
)
{
CURLcode
errorCode
;
long
responseCode
=
0
;
...
...
@@ -226,23 +209,23 @@ esxVI_CURL_Perform(esxVI_Context *ctx, const char *url)
const
char
*
redirectUrl
=
NULL
;
#endif
errorCode
=
curl_easy_perform
(
c
tx
->
curl_
handle
);
errorCode
=
curl_easy_perform
(
c
url
->
handle
);
if
(
errorCode
!=
CURLE_OK
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"curl_easy_perform() returned an error: %s (%d) : %s"
),
curl_easy_strerror
(
errorCode
),
errorCode
,
c
tx
->
curl_
error
);
curl_easy_strerror
(
errorCode
),
errorCode
,
c
url
->
error
);
return
-
1
;
}
errorCode
=
curl_easy_getinfo
(
c
tx
->
curl_
handle
,
CURLINFO_RESPONSE_CODE
,
errorCode
=
curl_easy_getinfo
(
c
url
->
handle
,
CURLINFO_RESPONSE_CODE
,
&
responseCode
);
if
(
errorCode
!=
CURLE_OK
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned an "
"error: %s (%d) : %s"
),
curl_easy_strerror
(
errorCode
),
errorCode
,
c
tx
->
curl_
error
);
errorCode
,
c
url
->
error
);
return
-
1
;
}
...
...
@@ -255,7 +238,7 @@ esxVI_CURL_Perform(esxVI_Context *ctx, const char *url)
if
(
responseCode
==
301
)
{
#if LIBCURL_VERSION_NUM >= 0x071202
/* 7.18.2 */
errorCode
=
curl_easy_getinfo
(
c
tx
->
curl_
handle
,
CURLINFO_REDIRECT_URL
,
errorCode
=
curl_easy_getinfo
(
c
url
->
handle
,
CURLINFO_REDIRECT_URL
,
&
redirectUrl
);
if
(
errorCode
!=
CURLE_OK
)
{
...
...
@@ -263,7 +246,7 @@ esxVI_CURL_Perform(esxVI_Context *ctx, const char *url)
_
(
"curl_easy_getinfo(CURLINFO_REDIRECT_URL) returned "
"an error: %s (%d) : %s"
),
curl_easy_strerror
(
errorCode
),
errorCode
,
c
tx
->
curl_
error
);
errorCode
,
c
url
->
error
);
}
else
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"The server redirects from '%s' to '%s'"
),
url
,
...
...
@@ -281,32 +264,23 @@ esxVI_CURL_Perform(esxVI_Context *ctx, const char *url)
}
int
esxVI_Context_Connect
(
esxVI_Context
*
ctx
,
const
char
*
url
,
const
char
*
ipAddress
,
const
char
*
username
,
const
char
*
password
,
esxUtil_ParsedUri
*
parsedUri
)
esxVI_CURL_Connect
(
esxVI_CURL
*
curl
,
esxUtil_ParsedUri
*
parsedUri
)
{
if
(
ctx
==
NULL
||
url
==
NULL
||
ipAddress
==
NULL
||
username
==
NULL
||
password
==
NULL
||
ctx
->
url
!=
NULL
||
ctx
->
service
!=
NULL
||
ctx
->
curl_handle
!=
NULL
||
ctx
->
curl_headers
!=
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Invalid argument"
));
return
-
1
;
}
if
(
esxVI_String_DeepCopyValue
(
&
ctx
->
url
,
url
)
<
0
||
esxVI_String_DeepCopyValue
(
&
ctx
->
ipAddress
,
ipAddress
)
<
0
)
{
if
(
curl
->
handle
!=
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Invalid call"
));
return
-
1
;
}
c
tx
->
curl_
handle
=
curl_easy_init
();
c
url
->
handle
=
curl_easy_init
();
if
(
c
tx
->
curl_
handle
==
NULL
)
{
if
(
c
url
->
handle
==
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Could not initialize CURL"
));
return
-
1
;
}
c
tx
->
curl_headers
=
curl_slist_append
(
ctx
->
curl_headers
,
"Content-Type: "
"
text/xml; charset=UTF-8"
);
c
url
->
headers
=
curl_slist_append
(
curl
->
headers
,
"Content-Type:
text/xml; charset=UTF-8"
);
/*
* Add a dummy expect header to stop CURL from waiting for a response code
...
...
@@ -316,56 +290,179 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
* 100 (Continue) response and the wait times out resulting in wasting
* approx. 2 sec per POST operation.
*/
ctx
->
curl_headers
=
curl_slist_append
(
ctx
->
curl_headers
,
"Expect: nothing"
);
curl
->
headers
=
curl_slist_append
(
curl
->
headers
,
"Expect: nothing"
);
if
(
c
tx
->
curl_
headers
==
NULL
)
{
if
(
c
url
->
headers
==
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Could not build CURL header list"
));
return
-
1
;
}
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_URL
,
ctx
->
url
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_USERAGENT
,
"libvirt-esx"
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_HEADER
,
0
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_FOLLOWLOCATION
,
0
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_SSL_VERIFYPEER
,
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_USERAGENT
,
"libvirt-esx"
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_HEADER
,
0
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_FOLLOWLOCATION
,
0
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_SSL_VERIFYPEER
,
parsedUri
->
noVerify
?
0
:
1
);
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_SSL_VERIFYHOST
,
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_SSL_VERIFYHOST
,
parsedUri
->
noVerify
?
0
:
2
);
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_COOKIEFILE
,
""
);
curl_easy_setopt
(
c
tx
->
curl_handle
,
CURLOPT_HTTPHEADER
,
ctx
->
curl_
headers
);
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_READFUNCTION
,
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_COOKIEFILE
,
""
);
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_HTTPHEADER
,
curl
->
headers
);
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_READFUNCTION
,
esxVI_CURL_ReadString
);
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_WRITEFUNCTION
,
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_WRITEFUNCTION
,
esxVI_CURL_WriteBuffer
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_ERRORBUFFER
,
ctx
->
curl_error
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_ERRORBUFFER
,
curl
->
error
);
#if ESX_VI__CURL__ENABLE_DEBUG_OUTPUT
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_DEBUGFUNCTION
,
esxVI_CURL_Debug
);
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_VERBOSE
,
1
);
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_DEBUGFUNCTION
,
esxVI_CURL_Debug
);
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_VERBOSE
,
1
);
#endif
if
(
parsedUri
->
proxy
)
{
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_PROXY
,
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_PROXY
,
parsedUri
->
proxy_hostname
);
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_PROXYTYPE
,
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_PROXYTYPE
,
parsedUri
->
proxy_type
);
curl_easy_setopt
(
c
tx
->
curl_
handle
,
CURLOPT_PROXYPORT
,
curl_easy_setopt
(
c
url
->
handle
,
CURLOPT_PROXYPORT
,
parsedUri
->
proxy_port
);
}
if
(
virMutexInit
(
&
c
tx
->
curl_
lock
)
<
0
)
{
if
(
virMutexInit
(
&
c
url
->
lock
)
<
0
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Could not initialize CURL mutex"
));
return
-
1
;
}
ctx
->
username
=
strdup
(
username
);
ctx
->
password
=
strdup
(
password
);
return
0
;
}
int
esxVI_CURL_Download
(
esxVI_CURL
*
curl
,
const
char
*
url
,
char
**
content
)
{
virBuffer
buffer
=
VIR_BUFFER_INITIALIZER
;
int
responseCode
=
0
;
if
(
ctx
->
username
==
NULL
||
ctx
->
password
==
NULL
)
{
if
(
content
==
NULL
||
*
content
!=
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Invalid argument"
));
return
-
1
;
}
virMutexLock
(
&
curl
->
lock
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_WRITEDATA
,
&
buffer
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_UPLOAD
,
0
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_HTTPGET
,
1
);
responseCode
=
esxVI_CURL_Perform
(
curl
,
url
);
virMutexUnlock
(
&
curl
->
lock
);
if
(
responseCode
<
0
)
{
goto
cleanup
;
}
else
if
(
responseCode
!=
200
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"HTTP response code %d for download from '%s'"
),
responseCode
,
url
);
goto
cleanup
;
}
if
(
virBufferError
(
&
buffer
))
{
virReportOOMError
();
goto
cleanup
;
}
*
content
=
virBufferContentAndReset
(
&
buffer
);
cleanup:
if
(
*
content
==
NULL
)
{
virBufferFreeAndReset
(
&
buffer
);
return
-
1
;
}
return
0
;
}
int
esxVI_CURL_Upload
(
esxVI_CURL
*
curl
,
const
char
*
url
,
const
char
*
content
)
{
int
responseCode
=
0
;
if
(
content
==
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Invalid argument"
));
return
-
1
;
}
virMutexLock
(
&
curl
->
lock
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_READDATA
,
&
content
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_UPLOAD
,
1
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_INFILESIZE
,
strlen
(
content
));
responseCode
=
esxVI_CURL_Perform
(
curl
,
url
);
virMutexUnlock
(
&
curl
->
lock
);
if
(
responseCode
<
0
)
{
return
-
1
;
}
else
if
(
responseCode
!=
200
&&
responseCode
!=
201
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"HTTP response code %d for upload to '%s'"
),
responseCode
,
url
);
return
-
1
;
}
return
0
;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Context
*/
/* esxVI_Context_Alloc */
ESX_VI__TEMPLATE__ALLOC
(
Context
)
/* esxVI_Context_Free */
ESX_VI__TEMPLATE__FREE
(
Context
,
{
esxVI_CURL_Free
(
&
item
->
curl
);
VIR_FREE
(
item
->
url
);
VIR_FREE
(
item
->
ipAddress
);
VIR_FREE
(
item
->
username
);
VIR_FREE
(
item
->
password
);
esxVI_ServiceContent_Free
(
&
item
->
service
);
esxVI_UserSession_Free
(
&
item
->
session
);
esxVI_Datacenter_Free
(
&
item
->
datacenter
);
esxVI_ComputeResource_Free
(
&
item
->
computeResource
);
esxVI_HostSystem_Free
(
&
item
->
hostSystem
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_folderToChildEntity
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_hostSystemToParent
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_hostSystemToVm
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_hostSystemToDatastore
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_computeResourceToHost
);
esxVI_SelectionSpec_Free
(
&
item
->
selectSet_computeResourceToParentToParent
);
})
int
esxVI_Context_Connect
(
esxVI_Context
*
ctx
,
const
char
*
url
,
const
char
*
ipAddress
,
const
char
*
username
,
const
char
*
password
,
esxUtil_ParsedUri
*
parsedUri
)
{
if
(
ctx
==
NULL
||
url
==
NULL
||
ipAddress
==
NULL
||
username
==
NULL
||
password
==
NULL
||
ctx
->
url
!=
NULL
||
ctx
->
service
!=
NULL
||
ctx
->
curl
!=
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Invalid argument"
));
return
-
1
;
}
if
(
esxVI_CURL_Alloc
(
&
ctx
->
curl
)
<
0
||
esxVI_CURL_Connect
(
ctx
->
curl
,
parsedUri
)
<
0
||
esxVI_String_DeepCopyValue
(
&
ctx
->
url
,
url
)
<
0
||
esxVI_String_DeepCopyValue
(
&
ctx
->
ipAddress
,
ipAddress
)
<
0
||
esxVI_String_DeepCopyValue
(
&
ctx
->
username
,
username
)
<
0
||
esxVI_String_DeepCopyValue
(
&
ctx
->
password
,
password
)
<
0
)
{
return
-
1
;
}
...
...
@@ -576,87 +673,6 @@ esxVI_Context_LookupObjectsByHostSystemIp(esxVI_Context *ctx,
return
result
;
}
int
esxVI_Context_DownloadFile
(
esxVI_Context
*
ctx
,
const
char
*
url
,
char
**
content
)
{
virBuffer
buffer
=
VIR_BUFFER_INITIALIZER
;
int
responseCode
=
0
;
if
(
content
==
NULL
||
*
content
!=
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Invalid argument"
));
return
-
1
;
}
virMutexLock
(
&
ctx
->
curl_lock
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_WRITEDATA
,
&
buffer
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_UPLOAD
,
0
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_HTTPGET
,
1
);
responseCode
=
esxVI_CURL_Perform
(
ctx
,
url
);
virMutexUnlock
(
&
ctx
->
curl_lock
);
if
(
responseCode
<
0
)
{
goto
cleanup
;
}
else
if
(
responseCode
!=
200
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"HTTP response code %d for download from '%s'"
),
responseCode
,
url
);
goto
cleanup
;
}
if
(
virBufferError
(
&
buffer
))
{
virReportOOMError
();
goto
cleanup
;
}
*
content
=
virBufferContentAndReset
(
&
buffer
);
cleanup:
if
(
*
content
==
NULL
)
{
virBufferFreeAndReset
(
&
buffer
);
return
-
1
;
}
return
0
;
}
int
esxVI_Context_UploadFile
(
esxVI_Context
*
ctx
,
const
char
*
url
,
const
char
*
content
)
{
int
responseCode
=
0
;
if
(
content
==
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Invalid argument"
));
return
-
1
;
}
virMutexLock
(
&
ctx
->
curl_lock
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_READDATA
,
&
content
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_UPLOAD
,
1
);
curl_easy_setopt
(
ctx
->
curl_handle
,
CURLOPT_INFILESIZE
,
strlen
(
content
));
responseCode
=
esxVI_CURL_Perform
(
ctx
,
url
);
virMutexUnlock
(
&
ctx
->
curl_lock
);
if
(
responseCode
<
0
)
{
return
-
1
;
}
else
if
(
responseCode
!=
200
&&
responseCode
!=
201
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"HTTP response code %d for upload to '%s'"
),
responseCode
,
url
);
return
-
1
;
}
return
0
;
}
int
esxVI_Context_Execute
(
esxVI_Context
*
ctx
,
const
char
*
methodName
,
const
char
*
request
,
esxVI_Response
**
response
,
...
...
@@ -678,17 +694,17 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
return
-
1
;
}
virMutexLock
(
&
ctx
->
curl
_
lock
);
virMutexLock
(
&
ctx
->
curl
->
lock
);
curl_easy_setopt
(
ctx
->
curl
_
handle
,
CURLOPT_URL
,
ctx
->
url
);
curl_easy_setopt
(
ctx
->
curl
_
handle
,
CURLOPT_WRITEDATA
,
&
buffer
);
curl_easy_setopt
(
ctx
->
curl
_
handle
,
CURLOPT_UPLOAD
,
0
);
curl_easy_setopt
(
ctx
->
curl
_
handle
,
CURLOPT_POSTFIELDS
,
request
);
curl_easy_setopt
(
ctx
->
curl
_
handle
,
CURLOPT_POSTFIELDSIZE
,
strlen
(
request
));
curl_easy_setopt
(
ctx
->
curl
->
handle
,
CURLOPT_URL
,
ctx
->
url
);
curl_easy_setopt
(
ctx
->
curl
->
handle
,
CURLOPT_WRITEDATA
,
&
buffer
);
curl_easy_setopt
(
ctx
->
curl
->
handle
,
CURLOPT_UPLOAD
,
0
);
curl_easy_setopt
(
ctx
->
curl
->
handle
,
CURLOPT_POSTFIELDS
,
request
);
curl_easy_setopt
(
ctx
->
curl
->
handle
,
CURLOPT_POSTFIELDSIZE
,
strlen
(
request
));
(
*
response
)
->
responseCode
=
esxVI_CURL_Perform
(
ctx
,
ctx
->
url
);
(
*
response
)
->
responseCode
=
esxVI_CURL_Perform
(
ctx
->
curl
,
ctx
->
url
);
virMutexUnlock
(
&
ctx
->
curl
_
lock
);
virMutexUnlock
(
&
ctx
->
curl
->
lock
);
if
((
*
response
)
->
responseCode
<
0
)
{
goto
cleanup
;
...
...
@@ -869,7 +885,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
*/
/* esxVI_Response_Alloc */
ESX_VI__TEMPLATE__ALLOC
(
Response
)
;
ESX_VI__TEMPLATE__ALLOC
(
Response
)
/* esxVI_Response_Free */
ESX_VI__TEMPLATE__FREE
(
Response
,
...
...
@@ -879,7 +895,7 @@ ESX_VI__TEMPLATE__FREE(Response,
if
(
item
->
document
!=
NULL
)
{
xmlFreeDoc
(
item
->
document
);
}
})
;
})
...
...
src/esx/esx_vi.h
浏览文件 @
d21342af
...
...
@@ -82,6 +82,7 @@ typedef enum _esxVI_APIVersion esxVI_APIVersion;
typedef
enum
_esxVI_ProductVersion
esxVI_ProductVersion
;
typedef
enum
_esxVI_Occurrence
esxVI_Occurrence
;
typedef
struct
_esxVI_ParsedHostCpuIdInfo
esxVI_ParsedHostCpuIdInfo
;
typedef
struct
_esxVI_CURL
esxVI_CURL
;
typedef
struct
_esxVI_Context
esxVI_Context
;
typedef
struct
_esxVI_Response
esxVI_Response
;
typedef
struct
_esxVI_Enumeration
esxVI_Enumeration
;
...
...
@@ -141,17 +142,33 @@ struct _esxVI_ParsedHostCpuIdInfo {
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* CURL
*/
struct
_esxVI_CURL
{
CURL
*
handle
;
virMutex
lock
;
struct
curl_slist
*
headers
;
char
error
[
CURL_ERROR_SIZE
];
};
int
esxVI_CURL_Alloc
(
esxVI_CURL
**
curl
);
void
esxVI_CURL_Free
(
esxVI_CURL
**
curl
);
int
esxVI_CURL_Connect
(
esxVI_CURL
*
curl
,
esxUtil_ParsedUri
*
parsedUri
);
int
esxVI_CURL_Download
(
esxVI_CURL
*
curl
,
const
char
*
url
,
char
**
content
);
int
esxVI_CURL_Upload
(
esxVI_CURL
*
curl
,
const
char
*
url
,
const
char
*
content
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Context
*/
struct
_esxVI_Context
{
esxVI_CURL
*
curl
;
char
*
url
;
char
*
ipAddress
;
CURL
*
curl_handle
;
struct
curl_slist
*
curl_headers
;
char
curl_error
[
CURL_ERROR_SIZE
];
virMutex
curl_lock
;
char
*
username
;
char
*
password
;
esxVI_ServiceContent
*
service
;
...
...
@@ -180,10 +197,6 @@ int esxVI_Context_LookupObjectsByPath(esxVI_Context *ctx,
esxUtil_ParsedUri
*
parsedUri
);
int
esxVI_Context_LookupObjectsByHostSystemIp
(
esxVI_Context
*
ctx
,
const
char
*
hostSystemIpAddress
);
int
esxVI_Context_DownloadFile
(
esxVI_Context
*
ctx
,
const
char
*
url
,
char
**
content
);
int
esxVI_Context_UploadFile
(
esxVI_Context
*
ctx
,
const
char
*
url
,
const
char
*
content
);
int
esxVI_Context_Execute
(
esxVI_Context
*
ctx
,
const
char
*
methodName
,
const
char
*
request
,
esxVI_Response
**
response
,
esxVI_Occurrence
occurrence
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录