781
*-----------------------------------------------------------------------------
783
* ToolsDaemonTcloSetPrinter --
785
* Set the printer on the guest.
794
*-----------------------------------------------------------------------------
798
ToolsDaemonTcloSetPrinter(RpcInData *data) // IN
800
static char resultBuffer[DEFAULT_RESULT_MSG_MAX_LENGTH];
802
VixError err = VIX_OK;
803
char *printerName = NULL;
804
char *defaultString = NULL;
806
DWORD sysError = ERROR_SUCCESS;
807
Debug(">ToolsDaemonTcloSetPrinter\n");
810
* Parse the arguments
812
printerName = ToolsDaemonTcloGetQuotedString(data->args, &data->args);
813
defaultString = ToolsDaemonTcloGetQuotedString(data->args, &data->args);
816
* Validate the arguments.
818
if ((NULL == printerName) || (NULL == defaultString)) {
819
err = VIX_E_INVALID_ARG;
820
Debug("Failed to get string args\n");
824
if (!StrUtil_StrToInt(&defaultInt, defaultString)) {
825
err = VIX_E_INVALID_ARG;
826
Debug("Failed to convert int arg\n");
830
Debug("Setting printer to: \"%s\", %ssetting as default\n",
831
printerName, (defaultInt != 0) ? "" : "not ");
833
/* Actually set the printer. */
834
if (!Printer_AddConnection(printerName, &sysError)) {
836
Debug("Failed to add printer %s : %d %s\n", printerName, sysError,
837
Err_Errno2String(sysError));
841
/* Set this printer as the default if requested. */
842
if (defaultInt != 0) {
843
if (!Win32U_SetDefaultPrinter(printerName)) {
845
* We couldn't set this printer as default. Oh well. We'll
846
* still report success or failure based purely on whether
847
* the actual printer add succeeded or not.
849
Debug("Unable to set \"%s\" as the default printer\n",
856
* All Foundry tools commands return results that start with a
857
* foundry error and a guest-OS-specific error.
859
Str_Sprintf(resultBuffer, sizeof resultBuffer, "%"FMT64"d %d", err, sysError);
860
RPCIN_SETRETVALS(data, resultBuffer, TRUE);
863
* These were allocated by ToolsDaemonTcloGetQuotedString.
868
Debug("<ToolsDaemonTcloSetPrinter\n");
872
Str_Sprintf(resultBuffer,
875
VIX_E_OP_NOT_SUPPORTED_ON_GUEST,
877
RPCIN_SETRETVALS(data, resultBuffer, TRUE);
1224
*-----------------------------------------------------------------------------
1226
* FoundryToolsDaemon_RegisterSetPrinterCapability --
1228
* Register the Set Printer capability. Sometimes this needs to
1229
* be done separately from the TCLO callback registration, so we
1230
* provide it separately here.
1239
*-----------------------------------------------------------------------------
1243
FoundryToolsDaemon_RegisterSetPrinterCapability(void)
1245
if (!RpcOut_sendOne(NULL, NULL, "tools.capability.printer_set 1")) {
1246
Debug("Unable to register printer set capability\n");
1247
Debug("<FoundryToolsDaemon_RegisterSetPrinterCapability\n");
1256
*-----------------------------------------------------------------------------
1258
* FoundryToolsDaemon_RegisterSetPrinter --
1260
* Register the Set Printer capability and TCLO handler.
1269
*-----------------------------------------------------------------------------
1273
FoundryToolsDaemon_RegisterSetPrinter(RpcIn *in) // IN
1275
/* First, try to load the printer library. */
1276
if (!Printer_Init()) {
1277
Debug("<FoundryToolsDaemon_RegisterSetPrinter\n");
1278
Debug("Unable to load printer library.\n");
1282
/* Register the TCLO handler. */
1283
RpcIn_RegisterCallbackEx(in,
1284
VIX_BACKDOORCOMMAND_SET_GUEST_PRINTER,
1285
ToolsDaemonTcloSetPrinter,
1288
* Inform the VMX that we support setting the guest printer; the UI
1289
* and VMX need to know about this capability in advance (rather than
1290
* simply trying and failing). I've put this here on the theory that
1291
* it's better to have it close to the command that handles the
1292
* actual request than it is to have it near the other capabilities
1293
* registration code, which is in toolsDaemon.c.
1295
* Eventually, Foundry might want to have a unified way of
1296
* registering support for only a subset of the foundry commands in
1299
if (!FoundryToolsDaemon_RegisterSetPrinterCapability()) {
1300
Debug("<FoundryToolsDaemon_RegisterSetPrinter\n");
1309
*-----------------------------------------------------------------------------
1311
* FoundryToolsDaemon_UnregisterSetPrinter --
1313
* Unregister the "Set Printer" capability.
1322
*-----------------------------------------------------------------------------
1326
FoundryToolsDaemon_UnregisterSetPrinter(RpcIn *in) // IN
1329
* RpcIn doesn't have an unregister facility, so all we need to do
1330
* here is unregister the capability.
1334
* Report no longer supporting setting the guest printer.
1336
if (!RpcOut_sendOne(NULL, NULL, "tools.capability.printer_set 0")) {
1337
Debug("<FoundryToolsDaemon_UnregisterSetPrinter\n");
1338
Debug("Unable to unregister printer set capability\n");
1342
/* Cleanup the printer library. */
1343
if (!Printer_Cleanup()) {
1345
* Failed to cleanup, but we still unregistered the command so
1346
* we'll just warn and pretend we succeeded.
1348
Debug("Unable to cleanup printer library\n");
1358
1125
*-----------------------------------------------------------------------------