summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2012-09-29 21:02:51 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2012-10-02 23:10:05 +0200
commit3aa68d49c44a7e879138dfdb441c1e135009fb05 (patch)
treebf53ed4b78d4d066a21f5fb015918da7ac9c8bf4
parentab8306e8cad0fa62009248b80990a1d1fabb7f33 (diff)
Forward plugin state to the controller
The purpose of the plugin is to forward value of javascript attributes to the SPICE client. This commit adds some helpers to achieve that, and then calls them to set these values.
-rw-r--r--SPICEConsoleAPI.cpp72
-rw-r--r--SPICEConsoleAPI.h5
2 files changed, 77 insertions, 0 deletions
diff --git a/SPICEConsoleAPI.cpp b/SPICEConsoleAPI.cpp
index 5c3be8a..406a5ab 100644
--- a/SPICEConsoleAPI.cpp
+++ b/SPICEConsoleAPI.cpp
@@ -204,6 +204,32 @@ void SPICEConsoleAPI::connect()
SendInit();
+ SendValue<std::string>(CONTROLLER_HOST, "hostIP");
+ if (port > 0)
+ SendMsg(CONTROLLER_PORT, (uint32_t)port);
+ if (sport > 0)
+ SendMsg(CONTROLLER_SPORT, (uint32_t)sport);
+ /*
+ SendValue(CONTROLLER_FULL_SCREEN,
+ (m_fullscreen == PR_TRUE ? CONTROLLER_SET_FULL_SCREEN : 0) |
+ (m_admin_console == PR_FALSE ? CONTROLLER_AUTO_DISPLAY_RES : 0));
+ */
+ SendValue<bool>(CONTROLLER_ENABLE_SMARTCARD, "Smartcard");
+ SendValue<std::string>(CONTROLLER_PASSWORD, "Password");
+ SendValue<std::string>(CONTROLLER_TLS_CIPHERS, "CipherSuite");
+ SendValue<std::string>(CONTROLLER_SET_TITLE, "Title");
+ SendValue<bool>(CONTROLLER_SEND_CAD, "SendCtrlAltDelete");
+ SendValue<bool>(CONTROLLER_ENABLE_USB_AUTOSHARE, "UsbAutoShare");
+ SendMsg(CONTROLLER_USB_FILTER, m_usb_filter);
+ SendMsg(CONTROLLER_SECURE_CHANNELS, m_SSLChannels);
+ SendMsg(CONTROLLER_CA_FILE, m_trust_store_file);
+ SendValue<std::string>(CONTROLLER_HOST_SUBJECT, "HostSubject");
+ SendValue<std::string>(CONTROLLER_HOTKEYS, "HotKey");
+ //SendValue(CONTROLLER_COLOR_DEPTH, atoi(m_color_depth.c_str()));
+ SendValue<std::string>(CONTROLLER_DISABLE_EFFECTS, "DisableEffects");
+ SendMsg(CONTROLLER_CONNECT);
+ SendMsg(CONTROLLER_SHOW);
+
// set connected status
m_connected_status = -1;
}
@@ -291,6 +317,52 @@ void SPICEConsoleAPI::SendMsg(uint32_t id)
WriteToPipe(&msg, sizeof(msg));
}
+void SPICEConsoleAPI::SendMsg(uint32_t id, uint32_t value)
+{
+ if (!value)
+ return;
+
+ ControllerValue msg = { {id, sizeof(msg)}, value };
+ WriteToPipe(&msg, sizeof(msg));
+}
+
+void SPICEConsoleAPI::SendMsg(uint32_t id, bool value)
+{
+ ControllerValue msg = { {id, sizeof(msg)}, value };
+ WriteToPipe(&msg, sizeof(msg));
+}
+
+void SPICEConsoleAPI::SendMsg(uint32_t id, const std::string &str)
+{
+ if (str.empty())
+ return;
+
+ size_t size = sizeof(ControllerData) + str.size() + 1;
+ ControllerData *msg = static_cast<ControllerData *>(malloc(size));
+ msg->base.id = id;
+ msg->base.size = size;
+ strcpy(reinterpret_cast<char *>(msg->data), str.c_str());
+ WriteToPipe(msg, size);
+ free(msg);
+}
+
+template<typename T> void SPICEConsoleAPI::SendValue(uint32_t id,
+ std::string attributeName)
+{
+ FB::variant variant = getAttribute(attributeName);
+ T value;
+
+ if (variant.empty())
+ return;
+ try {
+ value = variant.cast<T>();
+ } catch (FB::bad_variant_cast &e) {
+ g_warning("Invalid value for %s", attributeName.c_str());
+ return;
+ }
+ SendMsg(id, value);
+}
+
void *SPICEConsoleAPI::ControllerWaitHelper(void *opaque)
{
SPICEConsoleAPI *fake_this = reinterpret_cast<SPICEConsoleAPI *>(opaque);
diff --git a/SPICEConsoleAPI.h b/SPICEConsoleAPI.h
index 33358e5..eb7001e 100644
--- a/SPICEConsoleAPI.h
+++ b/SPICEConsoleAPI.h
@@ -151,6 +151,11 @@ private:
void WriteToPipe(const void *data, uint32_t size);
void SendInit();
void SendMsg(uint32_t id);
+ void SendMsg(uint32_t id, const std::string &str);
+ void SendMsg(uint32_t id, bool value);
+ void SendMsg(uint32_t id, uint32_t value);
+ template<typename T> void SendValue(uint32_t id, std::string attributeName);
+
static void *ControllerWaitHelper(void *opaque);
};