<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 4 Feb 2016, at 20:16 PM, Jonathon Jongsma <<a href="mailto:jjongsma@redhat.com" class="">jjongsma@redhat.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Thu, 2015-10-29 at 17:26 +0200, Dmitry Fleytman wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">From: Kirill Moizik <<a href="mailto:kirillm@daynix.com" class="">kirillm@daynix.com</a>><br class=""><br class="">Introduce UsbDk API definitions and binding code.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I would appreciate a bit more justification in the commit log about why we're</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">using this approach of dynamically loading and wrapping usbdk rather than</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">linking to a library.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Justification is that spice-gtk should work without UsbDk installed, therefore runtime linkage is needed.</div><div>Iām adding this explanation to the commit message.</div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">Signed-off-by: Kirill Moizik <<a href="mailto:kirillm@daynix.com" class="">kirillm@daynix.com</a>><br class="">---<br class="">src/Makefile.am | 2 +<br class="">src/usbdk_api.c | 187<br class="">++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br class="">src/usbdk_api.h | 34 +++++++++++<br class="">3 files changed, 223 insertions(+)<br class="">create mode 100644 src/usbdk_api.c<br class="">create mode 100644 src/usbdk_api.h<br class=""><br class="">diff --git a/src/Makefile.am b/src/Makefile.am<br class="">index 0c40c48..6f4eb81 100644<br class="">--- a/src/Makefile.am<br class="">+++ b/src/Makefile.am<br class="">@@ -371,6 +371,8 @@ WIN_USB_FILES= \<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>win-usb-clerk.h<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>\<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>win-usb-driver-install.h<span class="Apple-tab-span" style="white-space: pre;"> </span>\<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>win-usb-driver-install.c<span class="Apple-tab-span" style="white-space: pre;"> </span>\<br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span>usbdk_api.h<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>\<br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span>usbdk_api.c<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>\<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>$(NULL)<br class=""><br class="">if OS_WIN32<br class="">diff --git a/src/usbdk_api.c b/src/usbdk_api.c<br class="">new file mode 100644<br class="">index 0000000..c4cb3b1<br class="">--- /dev/null<br class="">+++ b/src/usbdk_api.c<br class="">@@ -0,0 +1,187 @@<br class="">+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */<br class="">+/*<br class="">+ Copyright (C) 2014-2015 Red Hat, Inc.<br class="">+<br class="">+ This library is free software; you can redistribute it and/or<br class="">+ modify it under the terms of the GNU Lesser General Public<br class="">+ License as published by the Free Software Foundation; either<br class="">+ version 2.1 of the License, or (at your option) any later version.<br class="">+<br class="">+ This library is distributed in the hope that it will be useful,<br class="">+ but WITHOUT ANY WARRANTY; without even the implied warranty of<br class="">+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br class="">+ Lesser General Public License for more details.<br class="">+<br class="">+ You should have received a copy of the GNU Lesser General Public<br class="">+ License along with this library; if not, see <<a href="http://www.gnu.org/licenses/" class="">http://www.gnu.org/licenses/</a><br class=""><blockquote type="cite" class="">.<br class=""></blockquote>+<br class="">+ Authors:<br class="">+ Dmitry Fleytman <<a href="mailto:dmitry@daynix.com" class="">dmitry@daynix.com</a>><br class="">+ Kirill Moizik <<a href="mailto:kirill@daynix.com" class="">kirill@daynix.com</a>><br class="">+*/<br class="">+#include <config.h><br class="">+<br class="">+#include <windows.h><br class="">+#include <glib-object.h><br class="">+#include "usbdk_api.h"<br class="">+#include "channel-usbredir-priv.h"<br class="">+<br class="">+#define USB_DK_HIDE_RULE_MATCH_ALL ((ULONG64)(-1))<br class="">+typedef struct tag_USB_DK_HIDE_RULE<br class="">+{<br class="">+ ULONG64 Hide;<br class="">+ ULONG64 Class;<br class="">+ ULONG64 VID;<br class="">+ ULONG64 PID;<br class="">+ ULONG64 BCD;<br class="">+} USB_DK_HIDE_RULE, *PUSB_DK_HIDE_RULE;<br class="">+<br class="">+typedef HANDLE(__cdecl *USBDK_CREATEHIDERHANDLE)(void);<br class="">+typedef BOOL(__cdecl * USBDK_ADDHIDERULE)(HANDLE hider_handle,<br class="">PUSB_DK_HIDE_RULE rule);<br class="">+typedef BOOL(__cdecl *USBDK_CLEARHIDERULES)(HANDLE hider_handle);<br class="">+typedef void(__cdecl *USBDK_CLOSEHIDERHANDLE)(HANDLE hider_handle);<br class="">+<br class="">+struct tag_usbdk_api_wrapper<br class="">+{<br class="">+ HMODULE module;<br class="">+ USBDK_CREATEHIDERHANDLE CreateHandle;<br class="">+ USBDK_ADDHIDERULE AddRule;<br class="">+ USBDK_CLEARHIDERULES ClearRules;<br class="">+ USBDK_CLOSEHIDERHANDLE CloseHiderHandle;<br class="">+};<br class="">+<br class="">+BOOL usbdk_is_driver_installed(void)<br class="">+{<br class="">+ gboolean usbdk_installed = FALSE;<br class="">+ SC_HANDLE managerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);<br class="">+<br class="">+ if (managerHandle) {<br class="">+ SC_HANDLE serviceHandle = OpenService(managerHandle, TEXT("UsbDk"),<br class="">GENERIC_READ);<br class="">+<br class="">+ if (serviceHandle) {<br class="">+ SPICE_DEBUG("UsbDk driver is installed.");<br class="">+ usbdk_installed = TRUE;<br class="">+ CloseServiceHandle(serviceHandle);<br class="">+ }<br class="">+ CloseServiceHandle(managerHandle);<br class="">+ }<br class="">+ return usbdk_installed;<br class="">+}<br class="">+<br class="">+void usbdk_api_unload(usbdk_api_wrapper *usbdk_api)<br class="">+{<br class="">+ if (usbdk_api->module != NULL) {<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Here you dereference usbdk_api</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">+ SPICE_DEBUG("Unloading UsbDk API DLL");<br class="">+ FreeLibrary(usbdk_api->module);<br class="">+ }<br class="">+<br class="">+ if (usbdk_api != NULL) {<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">yet here you check if usbdk_api is non-NULL. If it was NULL, we would have</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">already segfaulted above.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>True. This is broken indeed.</div><div>Fixed, thanks.</div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">+ g_free(usbdk_api);<br class="">+ }<br class="">+}<br class="">+<br class="">+BOOL usbdk_api_load(usbdk_api_wrapper **usbdk_api)<br class="">+{<br class="">+ *usbdk_api = g_new0(usbdk_api_wrapper, 1);<br class="">+<br class="">+ SPICE_DEBUG("Loading UsbDk API DLL");<br class="">+ (*usbdk_api)->module = LoadLibraryA("UsbDkHelper");<br class="">+ if ((*usbdk_api)->module == NULL) {<br class="">+ g_warning("Failed to load UsbDkHelper.dll, error %lu",<br class="">GetLastError());<br class="">+ goto error_unload;<br class="">+ }<br class="">+<br class="">+ (*usbdk_api)->CreateHandle = (USBDK_CREATEHIDERHANDLE)<br class="">+ GetProcAddress((*usbdk_api)->module, "UsbDk_CreateHiderHandle");<br class="">+ if ((*usbdk_api)->CreateHandle == NULL) {<br class="">+ g_warning("Failed to find CreateHandle entry point");<br class="">+ goto error_unload;<br class="">+ }<br class="">+<br class="">+ (*usbdk_api)->AddRule = (USBDK_ADDHIDERULE)<br class="">+ GetProcAddress((*usbdk_api)->module, "UsbDk_AddHideRule");<br class="">+ if ((*usbdk_api)->AddRule == NULL) {<br class="">+ g_warning("Failed to find AddRule entry point");<br class="">+ goto error_unload;<br class="">+ }<br class="">+<br class="">+ (*usbdk_api)->ClearRules = (USBDK_CLEARHIDERULES)<br class="">+ GetProcAddress((*usbdk_api)->module, "UsbDk_ClearHideRules");<br class="">+ if ((*usbdk_api)->ClearRules == NULL) {<br class="">+ g_warning("Failed to find ClearRules entry point");<br class="">+ goto error_unload;<br class="">+ }<br class="">+<br class="">+ (*usbdk_api)->CloseHiderHandle = (USBDK_CLOSEHIDERHANDLE)<br class="">+ GetProcAddress((*usbdk_api)->module, "UsbDk_CloseHiderHandle");<br class="">+ if ((*usbdk_api)->CloseHiderHandle == NULL) {<br class="">+ g_warning("Failed to find CloseHiderHandle entry point");<br class="">+ goto error_unload;<br class="">+ }<br class="">+ return TRUE;<br class="">+<br class="">+error_unload:<br class="">+ usbdk_api_unload(*usbdk_api);<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">This ends up returning a dangling pointer to the caller since *usbdk_api has</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">been freed by usbdk_api_unload(), but is not reset to NULL. Personally, I think</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">this function would be slightly more straightforward if it just returned a</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">usbdk_api_wrapper* variable (NULL on failure) instead of having an output param</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">and a boolean return.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Agree. Changed.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">+ return FALSE;<br class="">+}<br class="">+<br class="">+static uint64_t usbdk_usbredir_field_to_usbdk(int value)<br class="">+{<br class="">+ if (value >= 0)<br class="">+ return value;<br class="">+ else if (value == -1)<br class="">+ return USB_DK_HIDE_RULE_MATCH_ALL;<br class="">+<br class="">+ /* value is < -1 */<br class="">+ g_return_val_if_reached(USB_DK_HIDE_RULE_MATCH_ALL);<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I would suggest something like this instead:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">----</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">if (value >= 0)</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""> return value;</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">g_warn_if_fail(value == -1);</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">return USB_DK_HIDE_RULE_MATCH_ALL;</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">āā</span></div></blockquote><div><br class=""></div><div><br class=""></div><div>This way is better indeed. Changed.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">+}<br class="">+<br class="">+static BOOL usbdk_add_hide_rule(usbdk_api_wrapper *usbdk_api,<br class="">+ HANDLE hider_handle,<br class="">+ PUSB_DK_HIDE_RULE rule)<br class="">+{<br class="">+ return usbdk_api->AddRule(hider_handle, rule);<br class="">+}<br class="">+<br class="">+void usbdk_api_set_hide_rules(usbdk_api_wrapper *usbdk_api, HANDLE<br class="">hider_handle,<br class="">+ gchar *redirect_on_connect)<br class="">+{<br class="">+ struct usbredirfilter_rule *rules;<br class="">+ int r, count;<br class="">+<br class="">+ r = usbredirfilter_string_to_rules(redirect_on_connect, ",", "|",<br class="">+ &rules, &count);<br class="">+ if (r) {<br class="">+ g_warning("auto-connect rules parsing failed with error %d", r);<br class="">+ return;<br class="">+ }<br class="">+<br class="">+ for (int i = 0; i < count; i++) {<br class="">+ USB_DK_HIDE_RULE rule;<br class="">+ rule.Hide = usbdk_usbredir_field_to_usbdk(rules[i].allow);<br class="">+ rule.Class = usbdk_usbredir_field_to_usbdk(rules[i].device_class);<br class="">+ rule.VID = usbdk_usbredir_field_to_usbdk(rules[i].vendor_id);<br class="">+ rule.PID = usbdk_usbredir_field_to_usbdk(rules[i].product_id);<br class="">+ rule.BCD =<br class="">usbdk_usbredir_field_to_usbdk(rules[i].device_version_bcd);<br class="">+ if (usbdk_add_hide_rule(usbdk_api, hider_handle, &rule)) {<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Is this correct? It seems like it should be:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">if (!usbdk_add_hide_rule())</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Or am I reading the code wrong?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Fixed, thanks.</div><div>BTW this did not do any harm except a warning in debug stream.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">+ SPICE_DEBUG("UsbDk add hide rule API failed");<br class="">+ }<br class="">+ }<br class="">+<br class="">+ free(rules);<br class="">+}<br class="">+<br class="">+HANDLE usbdk_create_hider_handle(usbdk_api_wrapper *usbdk_api)<br class="">+{<br class="">+ return usbdk_api->CreateHandle();<br class="">+}<br class="">+<br class="">+BOOL usbdk_clear_hide_rules(usbdk_api_wrapper *usbdk_api, HANDLE<br class="">hider_handle)<br class="">+{<br class="">+ return usbdk_api->ClearRules(hider_handle);<br class="">+}<br class="">+<br class="">+void usbdk_close_hider_handle(usbdk_api_wrapper *usbdk_api, HANDLE<br class="">hider_handle)<br class="">+{<br class="">+ return usbdk_api->CloseHiderHandle(hider_handle);<br class="">+}<br class="">diff --git a/src/usbdk_api.h b/src/usbdk_api.h<br class="">new file mode 100644<br class="">index 0000000..bc0131c<br class="">--- /dev/null<br class="">+++ b/src/usbdk_api.h<br class="">@@ -0,0 +1,34 @@<br class="">+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */<br class="">+/*<br class="">+ Copyright (C) 2014-2015 Red Hat, Inc.<br class="">+<br class="">+ This library is free software; you can redistribute it and/or<br class="">+ modify it under the terms of the GNU Lesser General Public<br class="">+ License as published by the Free Software Foundation; either<br class="">+ version 2.1 of the License, or (at your option) any later version.<br class="">+<br class="">+ This library is distributed in the hope that it will be useful,<br class="">+ but WITHOUT ANY WARRANTY; without even the implied warranty of<br class="">+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br class="">+ Lesser General Public License for more details.<br class="">+<br class="">+ You should have received a copy of the GNU Lesser General Public<br class="">+ License along with this library; if not, see <<a href="http://www.gnu.org/licenses/" class="">http://www.gnu.org/licenses/</a><br class=""><blockquote type="cite" class="">.<br class=""></blockquote>+<br class="">+ Authors:<br class="">+ Dmitry Fleytman <<a href="mailto:dmitry@daynix.com" class="">dmitry@daynix.com</a>><br class="">+ Kirill Moizik <<a href="mailto:kirill@daynix.com" class="">kirill@daynix.com</a>><br class="">+*/<br class="">+#ifndef USBDK_HEADER<br class="">+#define USBDK_HEADER<br class="">+<br class="">+typedef struct tag_usbdk_api_wrapper usbdk_api_wrapper;<br class="">+<br class="">+BOOL usbdk_is_driver_installed(void);<br class="">+HANDLE usbdk_create_hider_handle(usbdk_api_wrapper *usbdk_api);<br class="">+BOOL usbdk_clear_hide_rules(usbdk_api_wrapper *usbdk_api, HANDLE<br class="">hider_handle);<br class="">+void usbdk_close_hider_handle(usbdk_api_wrapper *usbdk_api, HANDLE<br class="">hider_handle);<br class="">+BOOL usbdk_api_load(usbdk_api_wrapper **usbdk_api);<br class="">+void usbdk_api_unload(usbdk_api_wrapper *usbdk_api);<br class="">+void usbdk_api_set_hide_rules(usbdk_api_wrapper *usbdk_api, HANDLE<br class="">hider_handle, gchar *redirect_on_connect);<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Can this declaration be moved up with the other hider-related functions?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Sure. Moved.</div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">+#endif<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Reviewed-by: Jonathon Jongsma <</span><a href="mailto:jjongsma@redhat.com" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">jjongsma@redhat.com</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">></span></div></blockquote></div><br class=""></body></html>