From: VMware, Inc <> Date: Tue, 19 Oct 2010 18:54:15 +0000 (-0700) Subject: Cleanup rpcin interface. X-Git-Tag: 2010.10.18-313025~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1bcc7dd4d669072a160bc58c60e6866c724b209;p=thirdparty%2Fopen-vm-tools.git Cleanup rpcin interface. Now that vmware-user is gone, there's no code left that needs to work both with the old RpcIn interface and the new RpcChannel interface. So we can do some cleanup: (i) remove the new-style callbacks from the old-style RpcIn interface. The spots in the old code that used the new API were reverted to use the old API. So now code using the old RpcIn interface directly is stuck with the old API. (ii) Remove the RpcInRet type, which was used by VIX code when it needed to compile both in vmtoolsd and vmware-user. That type was added in change 946632. (iii) Remove some debug logging that was ifdef'd out anyway, and didn't make sense in this day and age of mostly binary RPCs. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/rpcin.h b/open-vm-tools/lib/include/rpcin.h index 9579eadd4..0d749c294 100644 --- a/open-vm-tools/lib/include/rpcin.h +++ b/open-vm-tools/lib/include/rpcin.h @@ -31,19 +31,13 @@ extern "C" { #endif -#if defined(VMTOOLS_USE_GLIB) -# include - typedef gboolean RpcInRet; -#else -# include "dbllnklst.h" - typedef Bool RpcInRet; -#endif - typedef void RpcIn_ErrorFunc(void *clientData, char const *status); typedef struct RpcIn RpcIn; -#if defined(VMTOOLS_USE_GLIB) +#if defined(VMTOOLS_USE_GLIB) /* { */ + +#include "vmware/tools/guestrpc.h" RpcIn *RpcIn_Construct(GMainContext *mainCtx, RpcIn_Callback dispatch, @@ -52,42 +46,21 @@ RpcIn *RpcIn_Construct(GMainContext *mainCtx, Bool RpcIn_start(RpcIn *in, unsigned int delay, RpcIn_ErrorFunc *errorFunc, void *errorData); -#else - -/* Data passed to new-style RpcIn callbacks. */ -typedef struct RpcInData { - /* Data from the host's RPC request. */ - const char *name; - const char *args; - size_t argsSize; - /* Data to be returned to the host. */ - char *result; - size_t resultLen; - Bool freeResult; - /* Client data. */ - void *appCtx; - void *clientData; -} RpcInData; - - -/* - * Type for RpcIn callbacks. The callback function is responsible for - * allocating memory for the result string. - */ -typedef RpcInRet (*RpcIn_Callback)(RpcInData *data); +#else /* } { */ +#include "dbllnklst.h" /* * Type for old RpcIn callbacks. Don't use this anymore - this is here * for backwards compatibility. */ typedef Bool -(*RpcIn_CallbackOld)(char const **result, // OUT - size_t *resultLen, // OUT - const char *name, // IN - const char *args, // IN - size_t argsSize, // IN - void *clientData); // IN +(*RpcIn_Callback)(char const **result, // OUT + size_t *resultLen, // OUT + const char *name, // IN + const char *args, // IN + size_t argsSize, // IN + void *clientData); // IN RpcIn *RpcIn_Construct(DblLnkLst_Links *eventQueue); @@ -100,21 +73,14 @@ Bool RpcIn_start(RpcIn *in, unsigned int delay, * Use RpcIn_RegisterCallbackEx() instead. */ void RpcIn_RegisterCallback(RpcIn *in, const char *name, - RpcIn_CallbackOld callback, void *clientData); + RpcIn_Callback callback, void *clientData); -void RpcIn_RegisterCallbackEx(RpcIn *in, const char *name, - RpcIn_Callback callback, void *clientData); void RpcIn_UnregisterCallback(RpcIn *in, const char *name); -/* Helper macro for porting old callbacks that currently use RpcIn_SetRetVals. */ -#define RPCIN_SETRETVALS(data, val, retVal) \ - RpcIn_SetRetVals((char const **) &(data)->result, &(data)->resultLen, \ - (val), (retVal)) - unsigned int RpcIn_SetRetVals(char const **result, size_t *resultLen, const char *resultVal, Bool retVal); -#endif +#endif /* } */ void RpcIn_Destruct(RpcIn *in); Bool RpcIn_stop(RpcIn *in); diff --git a/open-vm-tools/lib/rpcIn/rpcin.c b/open-vm-tools/lib/rpcIn/rpcin.c index 588e7c9aa..853931e96 100644 --- a/open-vm-tools/lib/rpcIn/rpcin.c +++ b/open-vm-tools/lib/rpcIn/rpcin.c @@ -72,21 +72,11 @@ static DblLnkLst_Links *gTimerEventQueue; * The RpcIn object */ -typedef enum { - RPCIN_CB_OLD, - RPCIN_CB_NEW -} RpcInCallbackType; - - /* The list of TCLO command callbacks we support */ typedef struct RpcInCallbackList { const char *name; size_t length; /* Length of name so we don't have to strlen a lot */ - RpcInCallbackType type; - union { - RpcIn_CallbackOld oldCb; - RpcIn_Callback newCb; - } callback; + RpcIn_Callback callback; struct RpcInCallbackList *next; void *clientData; } RpcInCallbackList; @@ -151,9 +141,14 @@ struct RpcIn { */ static Bool -RpcInPingCallback(RpcInData *data) // IN +RpcInPingCallback(char const **result, // OUT + size_t *resultLen, // OUT + const char *name, // IN + const char *args, // IN + size_t argsSize, // IN + void *clientData) // IN { - return RPCIN_SETRETVALS(data, "", TRUE); + return RpcIn_SetRetVals(result, resultLen, "", TRUE); } @@ -201,7 +196,7 @@ RpcIn_Construct(DblLnkLst_Links *eventQueue) *----------------------------------------------------------------------------- */ -RpcInCallbackList * +static RpcInCallbackList * RpcInLookupCallback(RpcIn *in, // IN const char *name) // IN { @@ -244,7 +239,7 @@ RpcInLookupCallback(RpcIn *in, // IN void RpcIn_RegisterCallback(RpcIn *in, // IN const char *name, // IN - RpcIn_CallbackOld cb, // IN + RpcIn_Callback cb, // IN void *clientData) // IN { RpcInCallbackList *p; @@ -261,56 +256,7 @@ RpcIn_RegisterCallback(RpcIn *in, // IN p->length = strlen(name); p->name = strdup(name); - p->type = RPCIN_CB_OLD; - p->callback.oldCb = cb; - p->clientData = clientData; - - p->next = in->callbacks; - - in->callbacks = p; -} - - -/* - *----------------------------------------------------------------------------- - * - * RpcIn_RegisterCallbackEx -- - * - * Register a callback to happen when a TCLO message is - * received. When a TCLO message beginning with 'name' is - * sent, the callback will be called with an instance of - * "RpcInData" with the information from the request. - * - * Results: - * None - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ -void -RpcIn_RegisterCallbackEx(RpcIn *in, // IN - const char *name, // IN - RpcIn_Callback cb, // IN - void *clientData) // IN -{ - RpcInCallbackList *p; - - Debug("Registering callback '%s'\n", name); - - ASSERT(in); - ASSERT(name); - ASSERT(cb); - ASSERT(RpcInLookupCallback(in, name) == NULL); // not there yet - - p = (RpcInCallbackList *) malloc(sizeof(RpcInCallbackList)); - ASSERT_NOT_IMPLEMENTED(p); - - p->length = strlen(name); - p->name = strdup(name); - p->type = RPCIN_CB_NEW; - p->callback.newCb = cb; + p->callback = cb; p->clientData = clientData; p->next = in->callbacks; @@ -645,25 +591,9 @@ RpcInLoop(void *clientData) // IN free(cmd); if (cb) { result = NULL; - if (cb->type == RPCIN_CB_OLD) { - status = cb->callback.oldCb((char const **) &result, &resultLen, cb->name, - reply + cb->length, repLen - cb->length, - cb->clientData); - } else { - RpcInData data = { cb->name, - reply + cb->length, - repLen - cb->length, - NULL, - 0, - FALSE, - NULL, - cb->clientData }; - status = cb->callback.newCb(&data); - result = data.result; - resultLen = data.resultLen; - freeResult = data.freeResult; - } - + status = cb->callback((char const **) &result, &resultLen, cb->name, + reply + cb->length, repLen - cb->length, + cb->clientData); ASSERT(result); } else { status = FALSE; @@ -698,14 +628,6 @@ RpcInLoop(void *clientData) // IN free(result); } -#if 0 /* Costly in non-debug cases --hpreg */ - if (strlen(reply) <= 128) { - Debug("Tclo: Done executing '%s'; result='%s'\n", reply, result); - } else { - Debug("Tclo: reply string too long to display\n"); - } -#endif - /* * Run the event pump (in case VMware sends a long sequence of RPCs and * perfoms a time-consuming job) and continue to loop immediately @@ -844,10 +766,10 @@ RpcIn_start(RpcIn *in, // IN #if !defined(VMTOOLS_USE_GLIB) /* Register the 'reset' handler */ if (resetCallback) { - RpcIn_RegisterCallbackEx(in, "reset", resetCallback, resetClientData); + RpcIn_RegisterCallback(in, "reset", resetCallback, resetClientData); } - RpcIn_RegisterCallbackEx(in, "ping", RpcInPingCallback, NULL); + RpcIn_RegisterCallback(in, "ping", RpcInPingCallback, NULL); #endif return TRUE; diff --git a/open-vm-tools/services/plugins/vix/foundryToolsDaemon.c b/open-vm-tools/services/plugins/vix/foundryToolsDaemon.c index 5128ad404..1724884f1 100644 --- a/open-vm-tools/services/plugins/vix/foundryToolsDaemon.c +++ b/open-vm-tools/services/plugins/vix/foundryToolsDaemon.c @@ -113,18 +113,18 @@ static VixError ToolsDaemonTcloGetEncodedQuotedString(const char *args, const char **endOfArg, char **result); -RpcInRet ToolsDaemonTcloReceiveVixCommand(RpcInData *data); +gboolean ToolsDaemonTcloReceiveVixCommand(RpcInData *data); static HgfsServerMgrData gFoundryHgfsBkdrConn; -RpcInRet ToolsDaemonHgfsImpersonated(RpcInData *data); +gboolean ToolsDaemonHgfsImpersonated(RpcInData *data); #if defined(linux) || defined(_WIN32) -RpcInRet ToolsDaemonTcloSyncDriverFreeze(RpcInData *data); +gboolean ToolsDaemonTcloSyncDriverFreeze(RpcInData *data); -RpcInRet ToolsDaemonTcloSyncDriverThaw(RpcInData *data); +gboolean ToolsDaemonTcloSyncDriverThaw(RpcInData *data); #endif -RpcInRet ToolsDaemonTcloMountHGFS(RpcInData *data); +gboolean ToolsDaemonTcloMountHGFS(RpcInData *data); void ToolsDaemonTcloReportProgramCompleted(const char *requestName, VixError err, @@ -159,7 +159,7 @@ static Bool thisProcessRunsAsRoot = FALSE; *----------------------------------------------------------------------------- */ -RpcInRet +gboolean FoundryToolsDaemonRunProgram(RpcInData *data) // IN { VixError err = VIX_OK; @@ -280,7 +280,7 @@ abort: *----------------------------------------------------------------------------- */ -RpcInRet +gboolean FoundryToolsDaemonGetToolsProperties(RpcInData *data) // IN { VixError err = VIX_OK; @@ -363,7 +363,7 @@ abort: *----------------------------------------------------------------------------- */ -RpcInRet +gboolean ToolsDaemonTcloCheckUserAccount(RpcInData *data) // IN { VixError err = VIX_OK; @@ -602,7 +602,7 @@ abort: */ #if defined(linux) || defined(_WIN32) -RpcInRet +gboolean ToolsDaemonTcloSyncDriverFreeze(RpcInData *data) { static char resultBuffer[DEFAULT_RESULT_MSG_MAX_LENGTH]; @@ -748,7 +748,7 @@ exit: */ #if defined(linux) || defined(_WIN32) -RpcInRet +gboolean ToolsDaemonTcloSyncDriverThaw(RpcInData *data) // IN { static char resultBuffer[DEFAULT_RESULT_MSG_MAX_LENGTH]; @@ -801,7 +801,7 @@ ToolsDaemonTcloSyncDriverThaw(RpcInData *data) // IN *----------------------------------------------------------------------------- */ -RpcInRet +gboolean ToolsDaemonTcloMountHGFS(RpcInData *data) // IN { VixError err = VIX_OK; @@ -900,7 +900,7 @@ ToolsDaemonTcloMountHGFS(RpcInData *data) // IN *----------------------------------------------------------------------------- */ -RpcInRet +gboolean ToolsDaemonHgfsImpersonated(RpcInData *data) // IN { VixError err; @@ -1127,7 +1127,7 @@ ToolsDaemonTcloReportProgramCompleted(const char *requestName, // IN *----------------------------------------------------------------------------- */ -RpcInRet +gboolean ToolsDaemonTcloReceiveVixCommand(RpcInData *data) // IN { VixError err = VIX_OK; diff --git a/open-vm-tools/services/plugins/vix/vixPluginInt.h b/open-vm-tools/services/plugins/vix/vixPluginInt.h index ebe7e16ae..5479246a2 100644 --- a/open-vm-tools/services/plugins/vix/vixPluginInt.h +++ b/open-vm-tools/services/plugins/vix/vixPluginInt.h @@ -31,29 +31,29 @@ #include "vmware/tools/plugin.h" #include "rpcin.h" -RpcInRet +gboolean ToolsDaemonTcloCheckUserAccount(RpcInData *data); -RpcInRet +gboolean FoundryToolsDaemonGetToolsProperties(RpcInData *data); -RpcInRet +gboolean ToolsDaemonHgfsImpersonated(RpcInData *data); -RpcInRet +gboolean ToolsDaemonTcloMountHGFS(RpcInData *data); -RpcInRet +gboolean ToolsDaemonTcloReceiveVixCommand(RpcInData *data); -RpcInRet +gboolean FoundryToolsDaemonRunProgram(RpcInData *data); #if defined(linux) || defined(_WIN32) -RpcInRet +gboolean ToolsDaemonTcloSyncDriverFreeze(RpcInData *data); -RpcInRet +gboolean ToolsDaemonTcloSyncDriverThaw(RpcInData *data); #endif diff --git a/open-vm-tools/toolbox/toolbox-gtk.c b/open-vm-tools/toolbox/toolbox-gtk.c index cf8fb8bbb..e9afa903e 100644 --- a/open-vm-tools/toolbox/toolbox-gtk.c +++ b/open-vm-tools/toolbox/toolbox-gtk.c @@ -127,7 +127,9 @@ static gint ToolsMain_CheckF1Help(GtkWidget *widget, GdkEventKey *event, static GtkWidget* ToolsMain_Create(void); -static Bool RpcInResetCB(RpcInData *data); +static Bool RpcInResetCB(char const **result, size_t *resultLen, + const char *name, const char *args, + size_t argsSize, void *clientData); static Bool RpcInSetOptionCB(char const **result, size_t *resultLen, const char *name, const char *args, size_t argsSize, void *clientData); @@ -746,11 +748,16 @@ ToolsMain_Create(void) */ static Bool -RpcInResetCB(RpcInData *data) // IN/OUT +RpcInResetCB(char const **result, // OUT + size_t *resultLen, // OUT + const char *name, // IN + const char *args, // IN + size_t argsSize, // IN + void *clientData) // IN { Debug("----------toolbox: Received 'reset' from vmware\n"); - return RPCIN_SETRETVALS(data, "ATR " TOOLS_CTLPANEL_NAME, TRUE); + return RpcIn_SetRetVals(result, resultLen, "ATR " TOOLS_CTLPANEL_NAME, TRUE); }