{
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
esxPrivate *priv = NULL;
+ esxUtil_ParsedQuery *parsedQuery = NULL;
char hostIpAddress[NI_MAXHOST] = "";
char vCenterIpAddress[NI_MAXHOST] = "";
char *url = NULL;
char *vCenter = NULL;
- int noVerify = 0; // boolean
- int autoAnswer = 0; // boolean
char *username = NULL;
char *password = NULL;
esxVI_String *propertyNameList = NULL;
goto cleanup;
}
+ if (esxUtil_ParseQuery(&parsedQuery, conn->uri) < 0) {
+ goto cleanup;
+ }
+
+ priv->transport = parsedQuery->transport;
+ parsedQuery->transport = NULL;
+
priv->maxVcpus = -1;
priv->supportsVMotion = esxVI_Boolean_Undefined;
priv->supportsLongMode = esxVI_Boolean_Undefined;
- priv->autoAnswer = esxVI_Boolean_False;
+ priv->autoAnswer = parsedQuery->autoAnswer ? esxVI_Boolean_True
+ : esxVI_Boolean_False;
priv->usedCpuTimeCounterId = -1;
- if (esxUtil_ParseQuery(conn->uri, &priv->transport, &vCenter, &noVerify,
- &autoAnswer) < 0) {
- goto cleanup;
- }
-
- if (autoAnswer) {
- priv->autoAnswer = esxVI_Boolean_True;
- }
-
/*
* Set the port dependent on the transport protocol if no port is
* specified. This allows us to rely on the port parameter being
}
}
- if (esxVI_Context_Alloc(&priv->host) < 0) {
- goto cleanup;
- }
-
password = virRequestPassword(auth, username, conn->uri->server);
if (password == NULL) {
goto cleanup;
}
- if (esxVI_Context_Connect(priv->host, url, hostIpAddress, username,
- password, noVerify) < 0) {
+ if (esxVI_Context_Alloc(&priv->host) < 0 ||
+ esxVI_Context_Connect(priv->host, url, hostIpAddress, username,
+ password, parsedQuery->noVerify) < 0) {
goto cleanup;
}
}
if (esxVI_Context_Connect(priv->vCenter, url, vCenterIpAddress,
- username, password, noVerify) < 0) {
+ username, password,
+ parsedQuery->noVerify) < 0) {
goto cleanup;
}
VIR_FREE(priv);
}
+
+ esxUtil_FreeParsedQuery(&parsedQuery);
VIR_FREE(url);
VIR_FREE(vCenter);
VIR_FREE(password);
unsigned long resource ATTRIBUTE_UNUSED)
{
int result = -1;
- char *transport = NULL;
+ esxUtil_ParsedQuery *parsedQuery = NULL;
if (uri_in == NULL) {
- if (esxUtil_ParseQuery(dconn->uri, &transport, NULL, NULL, NULL) < 0) {
+ if (esxUtil_ParseQuery(&parsedQuery, dconn->uri) < 0) {
return -1;
}
- if (virAsprintf(uri_out, "%s://%s:%d/sdk", transport,
+ if (virAsprintf(uri_out, "%s://%s:%d/sdk", parsedQuery->transport,
dconn->uri->server, dconn->uri->port) < 0) {
virReportOOMError();
goto cleanup;
result = 0;
cleanup:
- VIR_FREE(transport);
+ esxUtil_FreeParsedQuery(&parsedQuery);
return result;
}
#define VIR_FROM_THIS VIR_FROM_ESX
+
int
-esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
- int *noVerify, int *autoAnswer)
+esxUtil_ParseQuery(esxUtil_ParsedQuery **parsedQuery, xmlURIPtr uri)
{
int result = -1;
- int i;
struct qparam_set *queryParamSet = NULL;
struct qparam *queryParam = NULL;
+ int i;
+ int noVerify;
+ int autoAnswer;
- if (transport != NULL) {
- *transport = NULL;
- }
-
- if (vCenter != NULL) {
- *vCenter = NULL;
- }
-
- if (noVerify != NULL) {
- *noVerify = 0;
+ if (parsedQuery == NULL || *parsedQuery != NULL) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
}
- if (autoAnswer != NULL) {
- *autoAnswer = 0;
+ if (VIR_ALLOC(*parsedQuery) < 0) {
+ virReportOOMError();
+ return -1;
}
#ifdef HAVE_XMLURI_QUERY_RAW
#endif
if (queryParamSet == NULL) {
- return -1;
+ goto cleanup;
}
for (i = 0; i < queryParamSet->n; i++) {
queryParam = &queryParamSet->p[i];
if (STRCASEEQ(queryParam->name, "transport")) {
- if (transport == NULL) {
- continue;
- }
+ VIR_FREE((*parsedQuery)->transport);
- *transport = strdup(queryParam->value);
+ (*parsedQuery)->transport = strdup(queryParam->value);
- if (*transport == NULL) {
+ if ((*parsedQuery)->transport == NULL) {
virReportOOMError();
goto cleanup;
}
- if (STRNEQ(*transport, "http") && STRNEQ(*transport, "https")) {
+ if (STRNEQ((*parsedQuery)->transport, "http") &&
+ STRNEQ((*parsedQuery)->transport, "https")) {
ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'transport' has unexpected value "
- "'%s' (should be http|https)"), *transport);
+ "'%s' (should be http|https)"),
+ (*parsedQuery)->transport);
goto cleanup;
}
} else if (STRCASEEQ(queryParam->name, "vcenter")) {
- if (vCenter == NULL) {
- continue;
- }
+ VIR_FREE((*parsedQuery)->vCenter);
- *vCenter = strdup(queryParam->value);
+ (*parsedQuery)->vCenter = strdup(queryParam->value);
- if (*vCenter == NULL) {
+ if ((*parsedQuery)->vCenter == NULL) {
virReportOOMError();
goto cleanup;
}
} else if (STRCASEEQ(queryParam->name, "no_verify")) {
- if (noVerify == NULL) {
- continue;
- }
-
- if (virStrToLong_i(queryParam->value, NULL, 10, noVerify) < 0 ||
- (*noVerify != 0 && *noVerify != 1)) {
+ if (virStrToLong_i(queryParam->value, NULL, 10, &noVerify) < 0 ||
+ (noVerify != 0 && noVerify != 1)) {
ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'no_verify' has unexpected value "
"'%s' (should be 0 or 1)"), queryParam->value);
goto cleanup;
}
- } else if (STRCASEEQ(queryParam->name, "auto_answer")) {
- if (autoAnswer == NULL) {
- continue;
- }
- if (virStrToLong_i(queryParam->value, NULL, 10, autoAnswer) < 0 ||
- (*autoAnswer != 0 && *autoAnswer != 1)) {
+ (*parsedQuery)->noVerify = noVerify != 0;
+ } else if (STRCASEEQ(queryParam->name, "auto_answer")) {
+ if (virStrToLong_i(queryParam->value, NULL, 10, &autoAnswer) < 0 ||
+ (autoAnswer != 0 && autoAnswer != 1)) {
ESX_ERROR(VIR_ERR_INVALID_ARG,
_("Query parameter 'auto_answer' has unexpected "
"value '%s' (should be 0 or 1)"), queryParam->value);
goto cleanup;
}
+
+ (*parsedQuery)->autoAnswer = autoAnswer != 0;
} else {
VIR_WARN("Ignoring unexpected query parameter '%s'",
queryParam->name);
}
}
- if (transport != NULL && *transport == NULL) {
- *transport = strdup("https");
+ if ((*parsedQuery)->transport == NULL) {
+ (*parsedQuery)->transport = strdup("https");
- if (*transport == NULL) {
+ if ((*parsedQuery)->transport == NULL) {
virReportOOMError();
goto cleanup;
}
cleanup:
if (result < 0) {
- if (transport != NULL) {
- VIR_FREE(*transport);
- }
-
- if (vCenter != NULL) {
- VIR_FREE(*vCenter);
- }
+ esxUtil_FreeParsedQuery(parsedQuery);
}
if (queryParamSet != NULL) {
+
+void
+esxUtil_FreeParsedQuery(esxUtil_ParsedQuery **parsedQuery)
+{
+ if (parsedQuery == NULL || *parsedQuery == NULL) {
+ return;
+ }
+
+ VIR_FREE((*parsedQuery)->transport);
+ VIR_FREE((*parsedQuery)->vCenter);
+
+ VIR_FREE(*parsedQuery);
+}
+
+
+
int
esxUtil_ParseVirtualMachineIDString(const char *id_string, int *id)
{