FreeRDP/channels/rdpdr/client/devman.c

195 lines
4.5 KiB
C
Raw Normal View History

2011-08-04 19:22:58 +04:00
/**
2012-10-09 05:00:07 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
2011-08-04 19:22:58 +04:00
*
* Copyright 2010-2011 Vic Lee
2012-10-09 05:00:07 +04:00
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
2015-06-03 14:38:47 +03:00
* Copyright 2015 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
* Copyright 2016 Armin Novak <armin.novak@gmail.com>
2011-08-04 19:22:58 +04:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
2011-08-04 19:22:58 +04:00
#include "config.h"
#endif
2011-08-04 19:22:58 +04:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <winpr/stream.h>
2011-08-04 19:22:58 +04:00
#include <freerdp/types.h>
#include <freerdp/addin.h>
#include <freerdp/client/channels.h>
#include <freerdp/channels/log.h>
2011-08-04 19:22:58 +04:00
2012-10-09 05:00:07 +04:00
#include "rdpdr_main.h"
2011-08-04 19:22:58 +04:00
#include "devman.h"
void devman_device_free(DEVICE* device)
{
if (!device)
return;
IFCALL(device->Free, device);
}
DEVMAN* devman_new(rdpdrPlugin* rdpdr)
2011-08-04 19:22:58 +04:00
{
DEVMAN* devman;
if (!rdpdr)
return NULL;
devman = (DEVMAN*) calloc(1, sizeof(DEVMAN));
2015-06-03 14:38:47 +03:00
2015-05-20 20:19:50 +03:00
if (!devman)
2015-06-03 14:38:47 +03:00
{
WLog_INFO(TAG, "calloc failed!");
2015-05-20 20:19:50 +03:00
return NULL;
2015-06-03 14:38:47 +03:00
}
devman->plugin = (void*) rdpdr;
2011-08-04 19:22:58 +04:00
devman->id_sequence = 1;
devman->devices = ListDictionary_New(TRUE);
if (!devman->devices)
{
2015-06-03 14:38:47 +03:00
WLog_INFO(TAG, "ListDictionary_New failed!");
2015-08-28 12:06:26 +03:00
free(devman);
return NULL;
}
2015-06-03 14:38:47 +03:00
ListDictionary_ValueObject(devman->devices)->fnObjectFree =
(OBJECT_FREE_FN) devman_device_free;
2011-08-05 19:19:43 +04:00
return devman;
2011-08-04 19:22:58 +04:00
}
void devman_free(DEVMAN* devman)
{
ListDictionary_Free(devman->devices);
free(devman);
2011-08-04 19:22:58 +04:00
}
2014-02-14 11:09:55 +04:00
void devman_unregister_device(DEVMAN* devman, void* key)
{
DEVICE* device;
if (!devman || !key)
return;
device = (DEVICE*) ListDictionary_Remove(devman->devices, key);
2014-02-14 11:09:55 +04:00
if (device)
devman_device_free(device);
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT devman_register_device(DEVMAN* devman, DEVICE* device)
2011-08-04 19:22:58 +04:00
{
void* key = NULL;
if (!devman || !device)
return ERROR_INVALID_PARAMETER;
2011-08-04 19:22:58 +04:00
device->id = devman->id_sequence++;
key = (void*) (size_t) device->id;
2015-06-03 14:38:47 +03:00
if (!ListDictionary_Add(devman->devices, key, device))
{
WLog_INFO(TAG, "ListDictionary_Add failed!");
return ERROR_INTERNAL_ERROR;
}
return CHANNEL_RC_OK;
}
DEVICE* devman_get_device_by_id(DEVMAN* devman, UINT32 id)
{
DEVICE* device = NULL;
void* key = (void*) (size_t) id;
if (!devman)
return NULL;
device = (DEVICE*) ListDictionary_GetItemValue(devman->devices, key);
return device;
2011-08-04 19:22:58 +04:00
}
static char DRIVE_SERVICE_NAME[] = "drive";
static char PRINTER_SERVICE_NAME[] = "printer";
static char SMARTCARD_SERVICE_NAME[] = "smartcard";
static char SERIAL_SERVICE_NAME[] = "serial";
static char PARALLEL_SERVICE_NAME[] = "parallel";
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
UINT devman_load_device_service(DEVMAN* devman, RDPDR_DEVICE* device, rdpContext* rdpcontext)
2011-08-04 19:22:58 +04:00
{
char* ServiceName = NULL;
2011-08-04 19:22:58 +04:00
DEVICE_SERVICE_ENTRY_POINTS ep;
PDEVICE_SERVICE_ENTRY entry = NULL;
2011-08-04 19:22:58 +04:00
if (!devman || !device || !rdpcontext)
return ERROR_INVALID_PARAMETER;
if (device->Type == RDPDR_DTYP_FILESYSTEM)
ServiceName = DRIVE_SERVICE_NAME;
else if (device->Type == RDPDR_DTYP_PRINT)
ServiceName = PRINTER_SERVICE_NAME;
else if (device->Type == RDPDR_DTYP_SMARTCARD)
ServiceName = SMARTCARD_SERVICE_NAME;
else if (device->Type == RDPDR_DTYP_SERIAL)
ServiceName = SERIAL_SERVICE_NAME;
else if (device->Type == RDPDR_DTYP_PARALLEL)
ServiceName = PARALLEL_SERVICE_NAME;
if (!ServiceName)
2015-06-03 14:38:47 +03:00
{
WLog_INFO(TAG, "ServiceName %s did not match!", ServiceName);
return ERROR_INVALID_NAME;
}
if (device->Name)
WLog_INFO(TAG, "Loading device service %s [%s] (static)", ServiceName, device->Name);
else
WLog_INFO(TAG, "Loading device service %s (static)", ServiceName);
entry = (PDEVICE_SERVICE_ENTRY) freerdp_load_channel_addin_entry(ServiceName, NULL, "DeviceServiceEntry", 0);
2012-02-10 05:04:27 +04:00
if (!entry)
2015-06-03 14:38:47 +03:00
{
WLog_INFO(TAG, "freerdp_load_channel_addin_entry failed!");
return ERROR_INTERNAL_ERROR;
}
2011-08-04 19:22:58 +04:00
ep.devman = devman;
ep.RegisterDevice = devman_register_device;
ep.device = device;
ep.rdpcontext = rdpcontext;
2011-08-04 19:22:58 +04:00
return entry(&ep);
2011-08-04 19:22:58 +04:00
}