Getting strings of predictable length from vz SDK is still
not convinient. We don't need length feedback from sdk
function but still need to allocate and set length variable
just to be able to call the function. Let's introduce another
macro that generates suitable wrapper in this case.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/vz/vz_sdk.c | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 443f753..1200b0d 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -225,12 +225,24 @@ FUN ## _Alloc(PRL_HANDLE handle) \
return NULL; \
}
+#define PRLSDK_GENERATE_STRING_GETTER_FIXED(FUN) \
+static PRL_RESULT \
+FUN ## _Fixed(PRL_HANDLE handle, char *buf, size_t size) \
+{ \
+ PRL_UINT32 buflen = size; \
+ \
+ return FUN(handle, buf, &buflen); \
+}
+
PRLSDK_GENERATE_STRING_GETTER(PrlResult_GetParamAsString)
+PRLSDK_GENERATE_STRING_GETTER_FIXED(PrlEvent_GetIssuerId)
+
PRLSDK_GENERATE_STRING_GETTER(PrlVmCfg_GetName)
PRLSDK_GENERATE_STRING_GETTER(PrlVmCfg_GetVNCHostName)
PRLSDK_GENERATE_STRING_GETTER(PrlVmCfg_GetCpuMask)
PRLSDK_GENERATE_STRING_GETTER(PrlVmCfg_GetHomePath)
+PRLSDK_GENERATE_STRING_GETTER_FIXED(PrlVmCfg_GetUuid)
PRLSDK_GENERATE_STRING_GETTER(PrlVmDev_GetFriendlyName)
PRLSDK_GENERATE_STRING_GETTER(PrlVmDev_GetImagePath)
@@ -239,6 +251,8 @@ PRLSDK_GENERATE_STRING_GETTER(PrlVmDevHd_GetMountPoint)
PRLSDK_GENERATE_STRING_GETTER(PrlVmDevNet_GetHostInterfaceName)
PRLSDK_GENERATE_STRING_GETTER(PrlVmDevNet_GetVirtualNetworkId)
+PRLSDK_GENERATE_STRING_GETTER_FIXED(PrlVmDevNet_GetMacAddressCanonical)
+PRLSDK_GENERATE_STRING_GETTER_FIXED(PrlVmDevNet_GetMacAddress)
int
prlsdkInit(void)
@@ -381,15 +395,13 @@ prlsdkGetDomainIds(PRL_HANDLE sdkdom,
unsigned char *uuid)
{
char uuidstr[VIR_UUID_STRING_BUFLEN + 2];
- PRL_UINT32 len;
PRL_RESULT pret;
if (name && !(*name = PrlVmCfg_GetName_Alloc(sdkdom)))
goto error;
if (uuid) {
- len = sizeof(uuidstr);
- pret = PrlVmCfg_GetUuid(sdkdom, uuidstr, &len);
+ pret = PrlVmCfg_GetUuid_Fixed(sdkdom, uuidstr, sizeof(uuidstr));
prlsdkCheckRetGoto(pret, error);
if (prlsdkUUIDParse(uuidstr, uuid) < 0) {
@@ -720,7 +732,6 @@ static int
prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt)
{
char macstr[VIR_MAC_STRING_BUFLEN];
- PRL_UINT32 buflen;
PRL_UINT32 netAdapterIndex;
PRL_UINT32 emulatedType;
PRL_RESULT pret;
@@ -748,8 +759,8 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool
isCt)
return 0;
}
- buflen = ARRAY_CARDINALITY(macstr);
- pret = PrlVmDevNet_GetMacAddressCanonical(netAdapter, macstr, &buflen);
+ pret = PrlVmDevNet_GetMacAddressCanonical_Fixed(netAdapter, macstr,
+ sizeof(macstr));
prlsdkCheckRetGoto(pret, cleanup);
if (virMacAddrParse(macstr, &net->mac) < 0)
@@ -1628,7 +1639,6 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
PRL_HANDLE_TYPE handleType;
char uuidstr[VIR_UUID_STRING_BUFLEN + 2];
unsigned char uuid[VIR_UUID_BUFLEN];
- PRL_UINT32 bufsize = ARRAY_CARDINALITY(uuidstr);
PRL_EVENT_TYPE prlEventType;
pret = PrlHandle_GetType(prlEvent, &handleType);
@@ -1641,7 +1651,7 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
if (privconn == NULL)
goto cleanup;
- pret = PrlEvent_GetIssuerId(prlEvent, uuidstr, &bufsize);
+ pret = PrlEvent_GetIssuerId_Fixed(prlEvent, uuidstr, sizeof(uuidstr));
prlsdkCheckRetGoto(pret, cleanup);
pret = PrlEvent_GetType(prlEvent, &prlEventType);
@@ -2863,7 +2873,6 @@ prlsdkFindNetByMAC(PRL_HANDLE sdkdom, virMacAddrPtr mac)
PRL_UINT32 adaptersCount;
PRL_UINT32 i;
PRL_HANDLE adapter = PRL_INVALID_HANDLE;
- PRL_UINT32 len;
char adapterMac[PRL_MAC_STRING_BUFNAME];
char expectedMac[PRL_MAC_STRING_BUFNAME];
@@ -2876,12 +2885,11 @@ prlsdkFindNetByMAC(PRL_HANDLE sdkdom, virMacAddrPtr mac)
pret = PrlVmCfg_GetNetAdapter(sdkdom, i, &adapter);
prlsdkCheckRetGoto(pret, cleanup);
- len = sizeof(adapterMac);
- memset(adapterMac, 0, sizeof(adapterMac));
- pret = PrlVmDevNet_GetMacAddress(adapter, adapterMac, &len);
+ pret = PrlVmDevNet_GetMacAddress_Fixed(adapter, adapterMac,
+ sizeof(adapterMac));
prlsdkCheckRetGoto(pret, cleanup);
- if (memcmp(adapterMac, expectedMac, PRL_MAC_STRING_BUFNAME) == 0)
+ if (STREQ(adapterMac, expectedMac))
return adapter;
PrlHandle_Free(adapter);
--
1.8.3.1