Refactor the code to use virTypedParamList which simplifies cleanup.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
if (conn->driver->connectSetIdentity != NULL) {
g_autoptr(virIdentity) ident = NULL;
- g_autoptr(virTypedParamList) paramlist = NULL;
- virTypedParameterPtr identparams = NULL;
- int nidentparams = 0;
+ g_autoptr(virTypedParamList) identparams = NULL;
VIR_DEBUG("Attempting to delegate current identity");
if (!(ident = virIdentityGetCurrent()))
goto error;
- if (virIdentityGetParameters(ident, &identparams, &nidentparams) < 0)
+ if (!(identparams = virIdentityGetParameters(ident)))
goto error;
- paramlist = virTypedParamListFromParams(&identparams, nidentparams);
-
- if (virConnectSetIdentity(conn, paramlist->par, paramlist->npar, 0) < 0)
+ if (virConnectSetIdentity(conn, identparams->par, identparams->npar, 0) < 0)
goto error;
}
}
bool preserveIdentity,
virConnectPtr *conn)
{
- virTypedParameterPtr params = NULL;
- int nparams = 0;
+ g_autoptr(virTypedParamList) identparams = NULL;
int ret = -1;
VIR_DEBUG("Getting secondary uri=%s readonly=%d preserveIdent=%d conn=%p",
if (!(ident = virIdentityGetCurrent()))
return -1;
- if (virIdentityGetParameters(ident, ¶ms, &nparams) < 0)
+ if (!(identparams = virIdentityGetParameters(ident)))
goto error;
}
VIR_DEBUG("Opened driver %p", *conn);
if (preserveIdentity) {
- if (virConnectSetIdentity(*conn, params, nparams, 0) < 0)
+ if (virConnectSetIdentity(*conn, identparams->par, identparams->npar, 0) < 0)
goto error;
VIR_DEBUG("Forwarded current identity to secondary driver");
ret = 0;
cleanup:
- virTypedParamsFree(params, nparams);
return ret;
error:
}
-int virIdentityGetParameters(virIdentity *ident,
- virTypedParameterPtr *params,
- int *nparams)
+virTypedParamList *virIdentityGetParameters(virIdentity *ident)
{
- *params = NULL;
- *nparams = 0;
+ virTypedParameter *tmp = NULL;
- if (virTypedParamsCopy(params, ident->params, ident->nparams) < 0)
- return -1;
-
- *nparams = ident->nparams;
+ if (virTypedParamsCopy(&tmp, ident->params, ident->nparams) < 0)
+ return NULL;
- return 0;
+ return virTypedParamListFromParams(&tmp, ident->nparams);
}
#include "internal.h"
#include <glib-object.h>
+#include "virtypedparam.h"
#define VIR_TYPE_IDENTITY vir_identity_get_type()
G_DECLARE_FINAL_TYPE(virIdentity, vir_identity, VIR, IDENTITY, GObject);
virTypedParameterPtr params,
int nparams);
-int virIdentityGetParameters(virIdentity *ident,
- virTypedParameterPtr *params,
- int *nparams);
+virTypedParamList *virIdentityGetParameters(virIdentity *ident);