资源简介
A toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes). Libvert support:xen ,qemu,kvm,etcs...
代码片段和文件信息
/*
* dispatch.h: RPC message dispatching infrastructure
*
* Copyright (C) 2007 2008 2009 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not write to the Free Software
* Foundation Inc. 59 Temple Place Suite 330 Boston MA 02111-1307 USA
*
* Author: Richard W.M. Jones
* Author: Daniel P. Berrange
*/
#include
#include “dispatch.h“
#include “remote.h“
#include “memory.h“
/* Convert a libvirt virError object into wire format */
static void
remoteDispatchCopyError (remote_error *rerr
virErrorPtr verr)
{
rerr->code = verr->code;
rerr->domain = verr->domain;
rerr->message = verr->message ? malloc(sizeof(char*)) : NULL;
if (rerr->message) *rerr->message = strdup(verr->message);
rerr->level = verr->level;
rerr->str1 = verr->str1 ? malloc(sizeof(char*)) : NULL;
if (rerr->str1) *rerr->str1 = strdup(verr->str1);
rerr->str2 = verr->str2 ? malloc(sizeof(char*)) : NULL;
if (rerr->str2) *rerr->str2 = strdup(verr->str2);
rerr->str3 = verr->str3 ? malloc(sizeof(char*)) : NULL;
if (rerr->str3) *rerr->str3 = strdup(verr->str3);
rerr->int1 = verr->int1;
rerr->int2 = verr->int2;
}
/* A set of helpers for sending back errors to client
in various ways .... */
static void
remoteDispatchStringError (remote_error *rerr
int code const char *msg)
{
virError verr;
memset(&verr 0 sizeof verr);
/* Construct the dummy libvirt virError. */
verr.code = code;
verr.domain = VIR_FROM_REMOTE;
verr.message = (char *)msg;
verr.level = VIR_ERR_ERROR;
verr.str1 = (char *)msg;
remoteDispatchCopyError(rerr &verr);
}
void remoteDispatchAuthError (remote_error *rerr)
{
remoteDispatchStringError (rerr VIR_ERR_AUTH_FAILED “authentication failed“);
}
void remoteDispatchFormatError (remote_error *rerr
const char *fmt ...)
{
va_list args;
char msgbuf[1024];
char *msg = msgbuf;
va_start (args fmt);
vsnprintf (msgbuf sizeof msgbuf fmt args);
va_end (args);
remoteDispatchStringError (rerr VIR_ERR_RPC msg);
}
void remoteDispatchGenericError (remote_error *rerr)
{
remoteDispatchStringError(rerr
VIR_ERR_INTERNAL_ERROR
“library function returned err
评论
共有 条评论