@@ -4,6 +4,10 @@ import "C"
44
55/*
66#cgo pkg-config: libusbredirhost libusbredirparser-0.5 libusb-1.0 glib-2.0 gio-2.0
7+
8+ #define G_LOG_DOMAIN "usbredirect"
9+ #define G_LOG_USE_STRUCTURED
10+
711#include <usbredirhost.h>
812#include <usbredirparser.h>
913#include <usbredirproto.h>
@@ -62,16 +66,33 @@ typedef struct {
6266
6367static bool
6468by_bus(device *device) {
65- return device != NULL && device.bus > && device.device_number > 0;
69+ return device != NULL && device->bus > 0 && device->device_number > 0;
70+ }
71+
72+ static bool
73+ validate_device_from_config(usbredir_config *config)
74+ {
75+ bool by_bus_flag = config->device.bus > 0 && config->device.device_number > 0;
76+ if (by_bus_flag) {
77+ return config->device.bus > 0 && config->device.device_number > 0;
78+ }
79+
80+ if (config->device.vendor <= 0 || config->device.vendor > 0xffff ||
81+ config->device.product < 0 || config->device.product > 0xffff) {
82+ return false;
83+ }
84+
85+ return true;
6686}
87+
6788static bool
6889is_valid_config(usbredir_config *config) {
69- if (!config || !config->addr) {
90+ if (!config || !config->net_settings. addr) {
7091 return false;
7192 }
7293
7394 if (!validate_device_from_config(config)) {
74- return fail ;
95+ return false ;
7596 }
7697
7798 return true;
@@ -81,7 +102,7 @@ static redirect *
81102new_redirect(usbredir_config *config)
82103{
83104 redirect *self = NULL;
84- if !is_valid_config(config) {
105+ if ( !is_valid_config(config) ) {
85106 return self;
86107 }
87108
@@ -95,21 +116,6 @@ new_redirect(usbredir_config *config)
95116 return self;
96117}
97118
98- static bool
99- validate_device_from_config(usbredir_config *config)
100- {
101- if (config->by_bus) {
102- return config->bus > 0 && config->device_number > 0;
103- }
104-
105- if (config->vendor <= 0 || config->vendor > 0xffff ||
106- config->product < 0 || config->product > 0xffff) {
107- return false;
108- }
109-
110- return true;
111- }
112-
113119static gpointer
114120thread_handle_libusb_events(gpointer user_data)
115121{
@@ -395,7 +401,7 @@ can_claim_usb_device(libusb_device *dev, libusb_device_handle **handle)
395401 for (i = 0; i < config->bNumInterfaces; i++) {
396402 int interface_num = config->interface[i].altsetting[0].bInterfaceNumber;
397403#if LIBUSBX_API_VERSION < 0x01000102
398- ret = libusb_detach_kernel_driver(handle, interface_num);
404+ ret = libusb_detach_kernel_driver(* handle, interface_num);
399405 if (ret != 0 && ret != LIBUSB_ERROR_NOT_FOUND
400406 && ret != LIBUSB_ERROR_NOT_SUPPORTED) {
401407 g_error("failed to detach driver from interface %d: %s",
@@ -596,7 +602,7 @@ int usbredir_run(usbredir_config *config)
596602 socket_service = g_socket_service_new();
597603 GInetAddress *iaddr = g_inet_address_new_from_string(self->net_settings.addr);
598604 if (iaddr == NULL) {
599- g_warning("Failed to parse IP: %s", self->addr);
605+ g_warning("Failed to parse IP: %s", self->net_settings. addr);
600606 goto end;
601607 }
602608
@@ -617,7 +623,7 @@ int usbredir_run(usbredir_config *config)
617623
618624 g_signal_connect(socket_service,
619625 "incoming", G_CALLBACK(connection_incoming_cb),
620- state );
626+ self );
621627 }
622628
623629 self->main_loop = g_main_loop_new(NULL, FALSE);
@@ -702,7 +708,7 @@ func Run(ctx context.Context, config Config) error {
702708 },
703709 verbosity : C .int (config .Verbosity ),
704710 }
705- defer C .free (unsafe .Pointer (cConfig .addr ))
711+ defer C .free (unsafe .Pointer (cConfig .net_settings . addr ))
706712
707713 done := make (chan error , 1 )
708714 go func () {
0 commit comments