Exemplo n.º 1
0
wMessagePipe* MessagePipe_New()
{
	wMessagePipe* pipe = NULL;

	pipe = (wMessagePipe*) malloc(sizeof(wMessagePipe));

	if (pipe)
	{
		pipe->In = MessageQueue_New();
		pipe->Out = MessageQueue_New();
	}

	return pipe;
}
Exemplo n.º 2
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT rail_virtual_channel_event_connected(railPlugin* rail, LPVOID pData,
        UINT32 dataLength)
{
	UINT status;
	status = rail->channelEntryPoints.pVirtualChannelOpenEx(rail->InitHandle,
	         &rail->OpenHandle, rail->channelDef.name, rail_virtual_channel_open_event_ex);

	if (status != CHANNEL_RC_OK)
	{
		WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08"PRIX32"]",
		         WTSErrorToString(status), status);
		return status;
	}

	rail->queue = MessageQueue_New(NULL);

	if (!rail->queue)
	{
		WLog_ERR(TAG, "MessageQueue_New failed!");
		return CHANNEL_RC_NO_MEMORY;
	}

	if (!(rail->thread = CreateThread(NULL, 0,
	                                  (LPTHREAD_START_ROUTINE) rail_virtual_channel_client_thread, (void*) rail, 0,
	                                  NULL)))
	{
		WLog_ERR(TAG, "CreateThread failed!");
		MessageQueue_Free(rail->queue);
		rail->queue = NULL;
		return ERROR_INTERNAL_ERROR;
	}

	return CHANNEL_RC_OK;
}
Exemplo n.º 3
0
rdpChannels* freerdp_channels_new(freerdp* instance)
{
	rdpChannels* channels;
	channels = (rdpChannels*) calloc(1, sizeof(rdpChannels));

	if (!channels)
		return NULL;

	if (!InitializeCriticalSectionAndSpinCount(&channels->channelsLock, 4000))
		goto error;

	channels->instance = instance;
	channels->queue = MessageQueue_New(NULL);

	if (!channels->queue)
		goto error;

	channels->openHandles = HashTable_New(TRUE);

	if (!channels->openHandles)
		goto error;

	return channels;
error:
	freerdp_channels_free(channels);
	return NULL;
}
Exemplo n.º 4
0
int TestMessageQueue(int argc, char* argv[])
{
	HANDLE thread;
	wMessageQueue* queue;

	if (!(queue = MessageQueue_New(NULL)))
	{
		printf("failed to create message queue\n");
		return 1;
	}

	if (!(thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_queue_consumer_thread, (void*) queue, 0, NULL)))
	{
		printf("failed to create thread\n");
		MessageQueue_Free(queue);
		return 1;
	}

	if (!MessageQueue_Post(queue, NULL, 123, NULL, NULL) ||
			!MessageQueue_Post(queue, NULL, 456, NULL, NULL) ||
			!MessageQueue_Post(queue, NULL, 789, NULL, NULL) ||
			!MessageQueue_PostQuit(queue, 0) ||
			WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0)
		return -1;

	MessageQueue_Free(queue);
	CloseHandle(thread);

	return 0;
}
Exemplo n.º 5
0
SMARTCARD_CONTEXT* smartcard_context_new(SMARTCARD_DEVICE* smartcard, SCARDCONTEXT hContext)
{
	SMARTCARD_CONTEXT* pContext;

	pContext = (SMARTCARD_CONTEXT*) calloc(1, sizeof(SMARTCARD_CONTEXT));
	if (!pContext)
		return pContext;

	pContext->smartcard = smartcard;
	pContext->hContext = hContext;

	pContext->IrpQueue = MessageQueue_New(NULL);
	if (!pContext->IrpQueue)
		goto error_irpqueue;

	pContext->thread = CreateThread(NULL, 0,
			(LPTHREAD_START_ROUTINE) smartcard_context_thread,
			pContext, 0, NULL);
	if (!pContext->thread)
		goto error_thread;
	return pContext;

error_thread:
	MessageQueue_Free(pContext->IrpQueue);
error_irpqueue:
	free(pContext);
	return NULL;
}
Exemplo n.º 6
0
static void rail_virtual_channel_event_connected(railPlugin* rail, LPVOID pData, UINT32 dataLength)
{
    UINT32 status;

    status = rail->channelEntryPoints.pVirtualChannelOpen(rail->InitHandle,
             &rail->OpenHandle, rail->channelDef.name, rail_virtual_channel_open_event);

    if (!rail_add_open_handle_data(rail->OpenHandle, rail))
    {
        WLog_ERR(TAG,  "%s: unable to register open handle", __FUNCTION__);
        return;
    }

    if (status != CHANNEL_RC_OK)
    {
        WLog_ERR(TAG,  "pVirtualChannelOpen failed with %s [%08X]",
                 WTSErrorToString(status), status);
        return;
    }

    rail->queue = MessageQueue_New(NULL);
    if (!rail->queue)
    {
        WLog_ERR(TAG, "%s: unable to create a message queue", __FUNCTION__);
        return;
    }

    rail->thread = CreateThread(NULL, 0,
                                (LPTHREAD_START_ROUTINE) rail_virtual_channel_client_thread, (void*) rail, 0, NULL);
}
Exemplo n.º 7
0
rdpChannels* freerdp_channels_new(void)
{
	rdpChannels* channels;

	channels = (rdpChannels*) calloc(1, sizeof(rdpChannels));
	if (!channels)
		return NULL;

	channels->queue = MessageQueue_New(NULL);
	if (!channels->queue)
		goto error_queue;

	if (!g_OpenHandles)
	{
		g_OpenHandles = HashTable_New(TRUE);
		if (!g_OpenHandles)
			goto error_open_handles;

		if (!InitializeCriticalSectionAndSpinCount(&g_channels_lock, 4000))
			goto error_open_handles;
	}

	return channels;

error_open_handles:
	MessageQueue_Free(channels->queue);
error_queue:
	free(channels);
	return NULL;
}
Exemplo n.º 8
0
rdpUpdate* update_new(rdpRdp* rdp)
{
	const wObject cb = { NULL, NULL, NULL,  update_free_queued_message, NULL };
	rdpUpdate* update;

	update = (rdpUpdate*) malloc(sizeof(rdpUpdate));

	if (update)
	{
		OFFSCREEN_DELETE_LIST* deleteList;

		ZeroMemory(update, sizeof(rdpUpdate));

		WLog_Init();
		update->log = WLog_Get("com.freerdp.core.update");

		update->bitmap_update.count = 64;
		update->bitmap_update.rectangles = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * update->bitmap_update.count);
		ZeroMemory(update->bitmap_update.rectangles, sizeof(BITMAP_DATA) * update->bitmap_update.count);

		update->pointer = (rdpPointerUpdate*) malloc(sizeof(rdpPointerUpdate));
		ZeroMemory(update->pointer, sizeof(rdpPointerUpdate));

		update->primary = (rdpPrimaryUpdate*) malloc(sizeof(rdpPrimaryUpdate));
		ZeroMemory(update->primary, sizeof(rdpPrimaryUpdate));

		update->secondary = (rdpSecondaryUpdate*) malloc(sizeof(rdpSecondaryUpdate));
		ZeroMemory(update->secondary, sizeof(rdpSecondaryUpdate));

		update->altsec = (rdpAltSecUpdate*) malloc(sizeof(rdpAltSecUpdate));
		ZeroMemory(update->altsec, sizeof(rdpAltSecUpdate));

		update->window = (rdpWindowUpdate*) malloc(sizeof(rdpWindowUpdate));
		ZeroMemory(update->window, sizeof(rdpWindowUpdate));

		deleteList = &(update->altsec->create_offscreen_bitmap.deleteList);
		deleteList->sIndices = 64;
		deleteList->indices = malloc(deleteList->sIndices * 2);
		deleteList->cIndices = 0;

		update->SuppressOutput = update_send_suppress_output;

		update->initialState = TRUE;

		update->queue = MessageQueue_New(&cb);
	}

	return update;
}
Exemplo n.º 9
0
void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path)
{
	int i, length;
	DRIVE_DEVICE* drive;

#ifdef WIN32
	/*
	 * We cannot enter paths like c:\ because : is an arg separator
	 * thus, paths are entered as c+\ and the + is substituted here
	 */
	if (path[1] == '+')
	{
		if ((path[0]>='a' && path[0]<='z') || (path[0]>='A' && path[0]<='Z'))
		{
			path[1] = ':';
		}
	}
#endif

	if (name[0] && path[0])
	{
		drive = (DRIVE_DEVICE*) malloc(sizeof(DRIVE_DEVICE));
		ZeroMemory(drive, sizeof(DRIVE_DEVICE));

		drive->device.type = RDPDR_DTYP_FILESYSTEM;
		drive->device.name = name;
		drive->device.IRPRequest = drive_irp_request;
		drive->device.Free = drive_free;

		length = (int) strlen(name);
		drive->device.data = Stream_New(NULL, length + 1);

		for (i = 0; i <= length; i++)
			Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]);

		drive->path = path;

		drive->files = ListDictionary_New(TRUE);
		ListDictionary_ValueObject(drive->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free;

		drive->IrpQueue = MessageQueue_New(NULL);
		drive->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL);

		pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) drive);

		ResumeThread(drive->thread);
	}
}
Exemplo n.º 10
0
rdpInput* input_new(rdpRdp* rdp)
{
	const wObject cb = { NULL, NULL, NULL, input_free_queued_message, NULL };
	rdpInput* input;

	input = (rdpInput*) malloc(sizeof(rdpInput));

	if (input != NULL)
	{
		ZeroMemory(input, sizeof(rdpInput));

		input->queue = MessageQueue_New(&cb);
	}

	return input;
}
Exemplo n.º 11
0
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
{
	char* name;
	char* path;
	int i, length;
	RDPDR_PARALLEL* device;
	PARALLEL_DEVICE* parallel;

	device = (RDPDR_PARALLEL*) pEntryPoints->device;
	name = device->Name;
	path = device->Path;

	if (!name || (name[0] == '*'))
	{
		/* TODO: implement auto detection of parallel ports */
		return 0;
	}

	if (name[0] && path[0])
	{
		parallel = (PARALLEL_DEVICE*) calloc(1, sizeof(PARALLEL_DEVICE));

		if (!parallel)
			return -1;

		parallel->device.type = RDPDR_DTYP_PARALLEL;
		parallel->device.name = name;
		parallel->device.IRPRequest = parallel_irp_request;
		parallel->device.Free = parallel_free;

		length = strlen(name);
		parallel->device.data = Stream_New(NULL, length + 1);

		for (i = 0; i <= length; i++)
			Stream_Write_UINT8(parallel->device.data, name[i] < 0 ? '_' : name[i]);

		parallel->path = path;

		parallel->queue = MessageQueue_New(NULL);

		pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) parallel);

		parallel->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) parallel_thread_func, (void*) parallel, 0, NULL);
	}

	return 0;
}
Exemplo n.º 12
0
int freerds_message_server_connector_init(rdsBackendConnector* backend)
{
	rdsBackendConnector* connector = (rdsBackendConnector *)backend;
	connector->ServerProxy = (rdsServerInterface*) malloc(sizeof(rdsServerInterface));

	//mod->ServerProxy = NULL; /* disable */

	if (connector->ServerProxy)
	{
		CopyMemory(connector->ServerProxy, connector->server, sizeof(rdsServerInterface));

		connector->server->BeginUpdate = freerds_message_server_begin_update;
		connector->server->EndUpdate = freerds_message_server_end_update;
		connector->server->Beep = freerds_message_server_beep;
		connector->server->IsTerminated = freerds_message_server_is_terminated;
		connector->server->OpaqueRect = freerds_message_server_opaque_rect;
		connector->server->ScreenBlt = freerds_message_server_screen_blt;
		connector->server->PaintRect = freerds_message_server_paint_rect;
		connector->server->PatBlt = freerds_message_server_patblt;
		connector->server->DstBlt = freerds_message_server_dstblt;
		connector->server->SetPointer = freerds_message_server_set_pointer;
		connector->server->SetSystemPointer = freerds_message_server_set_system_pointer;
		connector->server->SetPalette = freerds_message_server_set_palette;
		connector->server->SetClippingRegion = freerds_message_server_set_clipping_region;
		connector->server->LineTo = freerds_message_server_line_to;
		connector->server->CacheGlyph = freerds_message_server_cache_glyph;
		connector->server->GlyphIndex = freerds_message_glyph_index;
		connector->server->SharedFramebuffer = freerds_message_server_shared_framebuffer;
		connector->server->Reset = freerds_message_server_reset;
		connector->server->CreateOffscreenSurface = freerds_message_server_create_offscreen_surface;
		connector->server->SwitchOffscreenSurface = freerds_message_server_switch_offscreen_surface;
		connector->server->DeleteOffscreenSurface = freerds_message_server_delete_offscreen_surface;
		connector->server->PaintOffscreenSurface = freerds_message_server_paint_offscreen_surface;
		connector->server->WindowNewUpdate = freerds_message_server_window_new_update;
		connector->server->WindowDelete = freerds_message_server_window_delete;
	}

	connector->fps = 10;
	connector->MaxFps = 30;

	connector->ServerList = LinkedList_New();
	connector->ServerQueue = MessageQueue_New(NULL);

	return 0;
}
Exemplo n.º 13
0
rdpInput* input_new(rdpRdp* rdp)
{
	const wObject cb = { NULL, NULL, NULL, input_free_queued_message, NULL };
	rdpInput* input;

	input = (rdpInput*) calloc(1, sizeof(rdpInput));
	if (!input)
		return NULL;

	input->queue = MessageQueue_New(&cb);
	if (!input->queue)
	{
		free(input);
		return NULL;
	}

	return input;
}
Exemplo n.º 14
0
rdsConnection* freerds_connection_create(freerdp_peer* client)
{
	rdsConnection* xfp;

	client->ContextSize = sizeof(rdsConnection);
	client->ContextNew = (psPeerContextNew) freerds_peer_context_new;
	client->ContextFree = (psPeerContextFree) freerds_peer_context_free;
	freerdp_peer_context_new(client);

	xfp = (rdsConnection*) client->context;

	xfp->TermEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	xfp->notifications = MessageQueue_New(NULL);

	xfp->Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) freerds_connection_main_thread, client, 0, NULL);

	return xfp;
}
Exemplo n.º 15
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT remdesk_virtual_channel_event_connected(remdeskPlugin* remdesk, LPVOID pData, UINT32 dataLength)
{
	UINT32 status;
	UINT error;

	status = remdesk->channelEntryPoints.pVirtualChannelOpen(remdesk->InitHandle,
		&remdesk->OpenHandle, remdesk->channelDef.name, remdesk_virtual_channel_open_event);

	if (status != CHANNEL_RC_OK)
	{
		WLog_ERR(TAG,  "pVirtualChannelOpen failed with %s [%08X]",
				 WTSErrorToString(status), status);
		return status;
	}

	if ((error = remdesk_add_open_handle_data(remdesk->OpenHandle, remdesk)))
	{
		WLog_ERR(TAG, "remdesk_add_open_handle_data failed with error %lu", error);
		return error;
	}

	remdesk->queue = MessageQueue_New(NULL);
	if (!remdesk->queue)
	{
		WLog_ERR(TAG, "MessageQueue_New failed!");
		error = CHANNEL_RC_NO_MEMORY;
		goto error_out;
	}

	remdesk->thread = CreateThread(NULL, 0,
			(LPTHREAD_START_ROUTINE) remdesk_virtual_channel_client_thread, (void*) remdesk, 0, NULL);
	if (!remdesk->thread)
	{
		WLog_ERR(TAG, "CreateThread failed");
		error = ERROR_INTERNAL_ERROR;
		goto error_out;
	}
	return CHANNEL_RC_OK;
error_out:
	remdesk_remove_open_handle_data(remdesk->OpenHandle);
	MessageQueue_Free(remdesk->queue);
	remdesk->queue = NULL;
	return error;
}
Exemplo n.º 16
0
HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
{
	rdpContext* context;
	freerdp_peer* client;
	WTSVirtualChannelManager* vcm;
	HANDLE hServer = INVALID_HANDLE_VALUE;

	context = (rdpContext*) pServerName;

	if (!context)
		return INVALID_HANDLE_VALUE;

	client = context->peer;

	if (!client)
		return INVALID_HANDLE_VALUE;

	vcm = (WTSVirtualChannelManager*) calloc(1, sizeof(WTSVirtualChannelManager));

	if (vcm)
	{
		vcm->client = client;
		vcm->rdp = context->rdp;

		vcm->SessionId = g_SessionId++;

		if (!g_ServerHandles)
			g_ServerHandles = HashTable_New(TRUE);

		HashTable_Add(g_ServerHandles, (void*) (UINT_PTR) vcm->SessionId, (void*) vcm);

		vcm->queue = MessageQueue_New(NULL);

		vcm->dvc_channel_id_seq = 1;
		vcm->dynamicVirtualChannels = ArrayList_New(TRUE);

		client->ReceiveChannelData = WTSReceiveChannelData;

		hServer = (HANDLE) vcm;
	}

	return hServer;
}
Exemplo n.º 17
0
rdpChannels* freerdp_channels_new(void)
{
	rdpChannels* channels;

	channels = (rdpChannels*) calloc(1, sizeof(rdpChannels));

	if (!channels)
		return NULL;

	channels->queue = MessageQueue_New(NULL);

	if (!g_OpenHandles)
	{
		g_OpenHandles = HashTable_New(TRUE);
		InitializeCriticalSectionAndSpinCount(&g_channels_lock, 4000);
	}

	return channels;
}
Exemplo n.º 18
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT remdesk_virtual_channel_event_connected(remdeskPlugin* remdesk,
        LPVOID pData, UINT32 dataLength)
{
	UINT32 status;
	UINT error;
	status = remdesk->channelEntryPoints.pVirtualChannelOpenEx(remdesk->InitHandle,
	         &remdesk->OpenHandle, remdesk->channelDef.name,
	         remdesk_virtual_channel_open_event_ex);

	if (status != CHANNEL_RC_OK)
	{
		WLog_ERR(TAG,  "pVirtualChannelOpenEx failed with %s [%08"PRIX32"]",
		         WTSErrorToString(status), status);
		return status;
	}

	remdesk->queue = MessageQueue_New(NULL);

	if (!remdesk->queue)
	{
		WLog_ERR(TAG, "MessageQueue_New failed!");
		error = CHANNEL_RC_NO_MEMORY;
		goto error_out;
	}

	remdesk->thread = CreateThread(NULL, 0,
	                               remdesk_virtual_channel_client_thread, (void*) remdesk,
	                               0, NULL);

	if (!remdesk->thread)
	{
		WLog_ERR(TAG, "CreateThread failed");
		error = ERROR_INTERNAL_ERROR;
		goto error_out;
	}

	return CHANNEL_RC_OK;
error_out:
	MessageQueue_Free(remdesk->queue);
	remdesk->queue = NULL;
	return error;
}
Exemplo n.º 19
0
int TestMessageQueue(int argc, char* argv[])
{
	HANDLE thread;
	wMessageQueue* queue;

	queue = MessageQueue_New(NULL);

	thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) message_queue_consumer_thread, (void*) queue, 0, NULL);

	MessageQueue_Post(queue, NULL, 123, NULL, NULL);
	MessageQueue_Post(queue, NULL, 456, NULL, NULL);
	MessageQueue_Post(queue, NULL, 789, NULL, NULL);
	MessageQueue_PostQuit(queue, 0);

	WaitForSingleObject(thread, INFINITE);

	MessageQueue_Free(queue);

	return 0;
}
Exemplo n.º 20
0
static void remdesk_virtual_channel_event_connected(remdeskPlugin* remdesk, LPVOID pData, UINT32 dataLength)
{
    UINT32 status;

    status = remdesk->channelEntryPoints.pVirtualChannelOpen(remdesk->InitHandle,
             &remdesk->OpenHandle, remdesk->channelDef.name, remdesk_virtual_channel_open_event);

    remdesk_add_open_handle_data(remdesk->OpenHandle, remdesk);

    if (status != CHANNEL_RC_OK)
    {
        WLog_ERR(TAG,  "pVirtualChannelOpen failed with %s [%08X]",
                 WTSErrorToString(status), status);
        return;
    }

    remdesk->queue = MessageQueue_New(NULL);

    remdesk->thread = CreateThread(NULL, 0,
                                   (LPTHREAD_START_ROUTINE) remdesk_virtual_channel_client_thread, (void*) remdesk, 0, NULL);
}
Exemplo n.º 21
0
SMARTCARD_CONTEXT* smartcard_context_new(SMARTCARD_DEVICE* smartcard,
        SCARDCONTEXT hContext)
{
	SMARTCARD_CONTEXT* pContext;
	pContext = (SMARTCARD_CONTEXT*) calloc(1, sizeof(SMARTCARD_CONTEXT));

	if (!pContext)
	{
		WLog_ERR(TAG, "calloc failed!");
		return pContext;
	}

	pContext->smartcard = smartcard;
	pContext->hContext = hContext;
	pContext->IrpQueue = MessageQueue_New(NULL);

	if (!pContext->IrpQueue)
	{
		WLog_ERR(TAG, "MessageQueue_New failed!");
		goto error_irpqueue;
	}

	pContext->thread = CreateThread(NULL, 0,
	                                smartcard_context_thread,
	                                pContext, 0, NULL);

	if (!pContext->thread)
	{
		WLog_ERR(TAG, "CreateThread failed!");
		goto error_thread;
	}

	return pContext;
error_thread:
	MessageQueue_Free(pContext->IrpQueue);
error_irpqueue:
	free(pContext);
	return NULL;
}
Exemplo n.º 22
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr, LPVOID pData, UINT32 dataLength)
{
	UINT32 status;
	UINT error;

	status = cliprdr->channelEntryPoints.pVirtualChannelOpen(cliprdr->InitHandle,
		&cliprdr->OpenHandle, cliprdr->channelDef.name, cliprdr_virtual_channel_open_event);

	if (status != CHANNEL_RC_OK)
	{
		WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
				 WTSErrorToString(status), status);
		return status;
	}

	if ((error = cliprdr_add_open_handle_data(cliprdr->OpenHandle, cliprdr)))
	{
		WLog_ERR(TAG, "cliprdr_add_open_handle_data failed with error %lu", error);
		return error;
	}

	cliprdr->queue = MessageQueue_New(NULL);
	if (!cliprdr->queue)
	{
		WLog_ERR(TAG, "MessageQueue_New failed!");
		return ERROR_NOT_ENOUGH_MEMORY;
	}

	if (!(cliprdr->thread = CreateThread(NULL, 0,
			(LPTHREAD_START_ROUTINE) cliprdr_virtual_channel_client_thread, (void*) cliprdr, 0, NULL)))
	{
		WLog_ERR(TAG, "CreateThread failed!");
		MessageQueue_Free(cliprdr->queue);
		cliprdr->queue = NULL;
		return ERROR_INTERNAL_ERROR;
	}
	return CHANNEL_RC_OK;
}
Exemplo n.º 23
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT encomsp_virtual_channel_event_connected(encomspPlugin* encomsp, LPVOID pData, UINT32 dataLength)
{
	UINT32 status;
	UINT error;

	status = encomsp->channelEntryPoints.pVirtualChannelOpen(encomsp->InitHandle,
		&encomsp->OpenHandle, encomsp->channelDef.name, encomsp_virtual_channel_open_event);

	if (status != CHANNEL_RC_OK)
	{
		WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
				 WTSErrorToString(status), status);
		return status;
	}

	if ((error = encomsp_add_open_handle_data(encomsp->OpenHandle, encomsp)))
	{
		WLog_ERR(TAG, "encomsp_process_receive failed with error %lu!", error);
		return status;
	}

	encomsp->queue = MessageQueue_New(NULL);
	if (!encomsp->queue)
	{
		WLog_ERR(TAG, "MessageQueue_New failed!");
		return CHANNEL_RC_NO_MEMORY;
	}

	if (!(encomsp->thread = CreateThread(NULL, 0,
			(LPTHREAD_START_ROUTINE) encomsp_virtual_channel_client_thread, (void*) encomsp, 0, NULL)))
	{
		WLog_ERR(TAG, "CreateThread failed!");
		MessageQueue_Free(encomsp->queue);
		return ERROR_INTERNAL_ERROR;
	}
	return CHANNEL_RC_OK;
}
Exemplo n.º 24
0
HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
{
	UINT32 index;
	wStream* s;
	rdpMcs* mcs;
	BOOL joined = FALSE;
	freerdp_peer* client;
	rdpPeerChannel* channel;
	ULONG written;
	WTSVirtualChannelManager* vcm;

	if (SessionId == WTS_CURRENT_SESSION)
		return NULL;

	vcm = (WTSVirtualChannelManager*) HashTable_GetItemValue(g_ServerHandles, (void*) (UINT_PTR) SessionId);

	if (!vcm)
		return NULL;

	if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
	{
		return FreeRDP_WTSVirtualChannelOpen((HANDLE) vcm, SessionId, pVirtualName);
	}

	client = vcm->client;
	mcs = client->context->rdp->mcs;

	for (index = 0; index < mcs->channelCount; index++)
	{
		if (mcs->channels[index].joined && (strncmp(mcs->channels[index].Name, "drdynvc", 7) == 0))
		{
			joined = TRUE;
			break;
		}
	}

	if (!joined)
	{
		SetLastError(ERROR_NOT_FOUND);
		return NULL;
	}

	if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
	{
		SetLastError(ERROR_NOT_READY);
		return NULL;
	}

	channel = (rdpPeerChannel*) calloc(1, sizeof(rdpPeerChannel));

	channel->vcm = vcm;
	channel->client = client;
	channel->channelType = RDP_PEER_CHANNEL_TYPE_DVC;
	channel->receiveData = Stream_New(NULL, client->settings->VirtualChannelChunkSize);
	channel->queue = MessageQueue_New(NULL);

	channel->channelId = vcm->dvc_channel_id_seq++;
	ArrayList_Add(vcm->dynamicVirtualChannels, channel);

	s = Stream_New(NULL, 64);
	wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName);
	WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
	Stream_Free(s, TRUE);

	return channel;
}
Exemplo n.º 25
0
HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
{
	int length;
	UINT32 index;
	rdpMcs* mcs;
	BOOL joined = FALSE;
	freerdp_peer* client;
	rdpPeerChannel* channel;
	WTSVirtualChannelManager* vcm;
	HANDLE hChannelHandle = NULL;

	vcm = (WTSVirtualChannelManager*) hServer;

	if (!vcm)
		return NULL;

	client = vcm->client;
	mcs = client->context->rdp->mcs;

	length = strlen(pVirtualName);

	if (length > 8)
	{
		SetLastError(ERROR_NOT_FOUND);
		return NULL;
	}

	for (index = 0; index < mcs->channelCount; index++)
	{
		if (mcs->channels[index].joined && (strncmp(mcs->channels[index].Name, pVirtualName, length) == 0))
		{
			joined = TRUE;
			break;
		}
	}

	if (!joined)
	{
		SetLastError(ERROR_NOT_FOUND);
		return NULL;
	}

	channel = (rdpPeerChannel*) mcs->channels[index].handle;

	if (!channel)
	{
		channel = (rdpPeerChannel*) calloc(1, sizeof(rdpPeerChannel));

		channel->vcm = vcm;
		channel->client = client;
		channel->channelId = mcs->channels[index].ChannelId;
		channel->index = index;
		channel->channelType = RDP_PEER_CHANNEL_TYPE_SVC;
		channel->receiveData = Stream_New(NULL, client->settings->VirtualChannelChunkSize);
		channel->queue = MessageQueue_New(NULL);

		mcs->channels[index].handle = channel;
	}

	hChannelHandle = (HANDLE) channel;

	return hChannelHandle;
}
Exemplo n.º 26
0
BOOL shadow_client_context_new(freerdp_peer* peer, rdpShadowClient* client)
{
	rdpSettings* settings;
	rdpShadowServer* server;
	const wObject cb = { NULL, NULL, NULL, shadow_client_free_queued_message, NULL };

	server = (rdpShadowServer*) peer->ContextExtra;
	client->server = server;
	client->subsystem = server->subsystem;

	settings = peer->settings;

	settings->ColorDepth = 32;
	settings->NSCodec = TRUE;
	settings->RemoteFxCodec = TRUE;
	settings->BitmapCacheV3Enabled = TRUE;
	settings->FrameMarkerCommandEnabled = TRUE;
	settings->SurfaceFrameMarkerEnabled = TRUE;
	settings->SupportGraphicsPipeline = FALSE;

	settings->DrawAllowSkipAlpha = TRUE;
	settings->DrawAllowColorSubsampling = TRUE;
	settings->DrawAllowDynamicColorFidelity = TRUE;

	settings->CompressionLevel = PACKET_COMPR_TYPE_RDP6;

	settings->RdpSecurity = TRUE;
	settings->TlsSecurity = TRUE;
	settings->NlaSecurity = FALSE;

	if (!(settings->CertificateFile = _strdup(server->CertificateFile)))
		goto fail_cert_file;
	if (!(settings->PrivateKeyFile = _strdup(server->PrivateKeyFile)))
		goto fail_privkey_file;
	if (!(settings->RdpKeyFile = _strdup(settings->PrivateKeyFile)))
		goto fail_rdpkey_file;


	if (server->ipcSocket)
	{
		settings->LyncRdpMode = TRUE;
		settings->CompressionEnabled = FALSE;
	}

	client->inLobby = TRUE;
	client->mayView = server->mayView;
	client->mayInteract = server->mayInteract;

	if (!InitializeCriticalSectionAndSpinCount(&(client->lock), 4000))
		goto fail_client_lock;

	region16_init(&(client->invalidRegion));

	client->vcm = WTSOpenServerA((LPSTR) peer->context);
	if (!client->vcm || client->vcm == INVALID_HANDLE_VALUE)
		goto fail_open_server;

	if (!(client->MsgQueue = MessageQueue_New(&cb)))
		goto fail_message_queue;

	if (!(client->encoder = shadow_encoder_new(client)))
		goto fail_encoder_new;

	if (ArrayList_Add(server->clients, (void*) client) >= 0)
		return TRUE;

	shadow_encoder_free(client->encoder);
	client->encoder = NULL;
fail_encoder_new:
	MessageQueue_Free(client->MsgQueue);
	client->MsgQueue = NULL;
fail_message_queue:
	WTSCloseServer((HANDLE) client->vcm);
	client->vcm = NULL;
fail_open_server:
	DeleteCriticalSection(&(client->lock));
fail_client_lock:
	free(settings->RdpKeyFile);
	settings->RdpKeyFile = NULL;
fail_rdpkey_file:
	free(settings->PrivateKeyFile);
	settings->PrivateKeyFile = NULL;
fail_privkey_file:
	free(settings->CertificateFile);
	settings->CertificateFile = NULL;
fail_cert_file:

	return FALSE;
}
Exemplo n.º 27
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
{
	char* name;
	char* path;
	char* driver;
	RDPDR_SERIAL* device;
#if defined __linux__ && !defined ANDROID
	int i, len;
	SERIAL_DEVICE* serial;
#endif /* __linux__ */
	UINT error = CHANNEL_RC_OK;
	device = (RDPDR_SERIAL*) pEntryPoints->device;
	name = device->Name;
	path = device->Path;
	driver = device->Driver;

	if (!name || (name[0] == '*'))
	{
		/* TODO: implement auto detection of serial ports */
		return CHANNEL_RC_OK;
	}

	if ((name && name[0]) && (path && path[0]))
	{
		wLog* log;
		WLog_Init();
		log = WLog_Get("com.freerdp.channel.serial.client");
		WLog_Print(log, WLOG_DEBUG, "initializing");
#ifndef __linux__ /* to be removed */
		WLog_Print(log, WLOG_WARN,
		           "Serial ports redirection not supported on this platform.");
		return CHANNEL_RC_INITIALIZATION_ERROR;
#else /* __linux __ */
		WLog_Print(log, WLOG_DEBUG, "Defining %s as %s", name, path);

		if (!DefineCommDevice(name /* eg: COM1 */, path /* eg: /dev/ttyS0 */))
		{
			WLog_ERR(TAG, "DefineCommDevice failed!");
			return ERROR_INTERNAL_ERROR;
		}

		serial = (SERIAL_DEVICE*) calloc(1, sizeof(SERIAL_DEVICE));

		if (!serial)
		{
			WLog_ERR(TAG, "calloc failed!");
			return CHANNEL_RC_NO_MEMORY;
		}

		serial->log = log;
		serial->device.type = RDPDR_DTYP_SERIAL;
		serial->device.name = name;
		serial->device.IRPRequest = serial_irp_request;
		serial->device.Free = serial_free;
		serial->rdpcontext = pEntryPoints->rdpcontext;
		len = strlen(name);
		serial->device.data = Stream_New(NULL, len + 1);

		if (!serial->device.data)
		{
			WLog_ERR(TAG, "calloc failed!");
			error = CHANNEL_RC_NO_MEMORY;
			goto error_out;
		}

		for (i = 0; i <= len; i++)
			Stream_Write_UINT8(serial->device.data, name[i] < 0 ? '_' : name[i]);

		if (driver != NULL)
		{
			if (_stricmp(driver, "Serial") == 0)
				serial->ServerSerialDriverId = SerialDriverSerialSys;
			else if (_stricmp(driver, "SerCx") == 0)
				serial->ServerSerialDriverId = SerialDriverSerCxSys;
			else if (_stricmp(driver, "SerCx2") == 0)
				serial->ServerSerialDriverId = SerialDriverSerCx2Sys;
			else
			{
				assert(FALSE);
				WLog_Print(serial->log, WLOG_DEBUG,
				           "Unknown server's serial driver: %s. SerCx2 will be used", driver);
				serial->ServerSerialDriverId = SerialDriverSerialSys;
			}
		}
		else
		{
			/* default driver */
			serial->ServerSerialDriverId = SerialDriverSerialSys;
		}

		if (device->Permissive != NULL)
		{
			if (_stricmp(device->Permissive, "permissive") == 0)
			{
				serial->permissive = TRUE;
			}
			else
			{
				WLog_Print(serial->log, WLOG_DEBUG, "Unknown flag: %s", device->Permissive);
				assert(FALSE);
			}
		}

		WLog_Print(serial->log, WLOG_DEBUG, "Server's serial driver: %s (id: %d)",
		           driver, serial->ServerSerialDriverId);
		/* TODO: implement auto detection of the server's serial driver */
		serial->MainIrpQueue = MessageQueue_New(NULL);

		if (!serial->MainIrpQueue)
		{
			WLog_ERR(TAG, "MessageQueue_New failed!");
			error = CHANNEL_RC_NO_MEMORY;
			goto error_out;
		}

		/* IrpThreads content only modified by create_irp_thread() */
		serial->IrpThreads = ListDictionary_New(FALSE);

		if (!serial->IrpThreads)
		{
			WLog_ERR(TAG, "ListDictionary_New failed!");
			error = CHANNEL_RC_NO_MEMORY;
			goto error_out;
		}

		serial->IrpThreadToBeTerminatedCount = 0;
		InitializeCriticalSection(&serial->TerminatingIrpThreadsLock);

		if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman,
		             (DEVICE*) serial)))
		{
			WLog_ERR(TAG, "EntryPoints->RegisterDevice failed with error %"PRIu32"!", error);
			goto error_out;
		}

		if (!(serial->MainThread = CreateThread(NULL,
		                                        0,
		                                        (LPTHREAD_START_ROUTINE) serial_thread_func,
		                                        (void*) serial,
		                                        0,
		                                        NULL)))
		{
			WLog_ERR(TAG, "CreateThread failed!");
			error = ERROR_INTERNAL_ERROR;
			goto error_out;
		}

#endif /* __linux __ */
	}

	return error;
error_out:
#ifdef __linux__ /* to be removed */
	ListDictionary_Free(serial->IrpThreads);
	MessageQueue_Free(serial->MainIrpQueue);
	Stream_Free(serial->device.data, TRUE);
	free(serial);
#endif /* __linux __ */
	return error;
}
Exemplo n.º 28
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
UINT drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints,
                               char* name, char* path)
{
	int i, length;
	DRIVE_DEVICE* drive;
	UINT error;
#ifdef WIN32

	/*
	 * We cannot enter paths like c:\ because : is an arg separator
	 * thus, paths are entered as c+\ and the + is substituted here
	 */
	if (path[1] == '+')
	{
		if ((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z'))
		{
			path[1] = ':';
		}
	}

#endif

	if (name[0] && path[0])
	{
		drive = (DRIVE_DEVICE*) calloc(1, sizeof(DRIVE_DEVICE));

		if (!drive)
		{
			WLog_ERR(TAG, "calloc failed!");
			return CHANNEL_RC_NO_MEMORY;
		}

		drive->device.type = RDPDR_DTYP_FILESYSTEM;
		drive->device.name = name;
		drive->device.IRPRequest = drive_irp_request;
		drive->device.Free = drive_free;
		drive->rdpcontext = pEntryPoints->rdpcontext;
		length = (int) strlen(name);
		drive->device.data = Stream_New(NULL, length + 1);

		if (!drive->device.data)
		{
			WLog_ERR(TAG, "Stream_New failed!");
			error = CHANNEL_RC_NO_MEMORY;
			goto out_error;
		}

		for (i = 0; i <= length; i++)
			Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]);

		drive->path = path;
		drive->files = ListDictionary_New(TRUE);

		if (!drive->files)
		{
			WLog_ERR(TAG, "ListDictionary_New failed!");
			error = CHANNEL_RC_NO_MEMORY;
			goto out_error;
		}

		ListDictionary_ValueObject(drive->files)->fnObjectFree =
		    (OBJECT_FREE_FN) drive_file_free;
		drive->IrpQueue = MessageQueue_New(NULL);

		if (!drive->IrpQueue)
		{
			WLog_ERR(TAG, "ListDictionary_New failed!");
			error = CHANNEL_RC_NO_MEMORY;
			goto out_error;
		}

		if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman,
		             (DEVICE*) drive)))
		{
			WLog_ERR(TAG, "RegisterDevice failed with error %u!", error);
			goto out_error;
		}

		if (!(drive->thread = CreateThread(NULL, 0,
		                                   (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL)))
		{
			WLog_ERR(TAG, "CreateThread failed!");
			goto out_error;
		}

		ResumeThread(drive->thread);
	}

	return CHANNEL_RC_OK;
out_error:
	MessageQueue_Free(drive->IrpQueue);
	ListDictionary_Free(drive->files);
	free(drive);
	return error;
}
Exemplo n.º 29
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
{
	char* name;
	char* path;
	int i;
	size_t length;
	RDPDR_PARALLEL* device;
	PARALLEL_DEVICE* parallel;
	UINT error;

	device = (RDPDR_PARALLEL*) pEntryPoints->device;
	name = device->Name;
	path = device->Path;

	if (!name || (name[0] == '*'))
	{
		/* TODO: implement auto detection of parallel ports */
		return CHANNEL_RC_OK;
	}

	if (name[0] && path[0])
	{
		parallel = (PARALLEL_DEVICE*) calloc(1, sizeof(PARALLEL_DEVICE));
		if (!parallel)
		{
			WLog_ERR(TAG, "calloc failed!");
			return CHANNEL_RC_NO_MEMORY;
		}

		parallel->device.type = RDPDR_DTYP_PARALLEL;
		parallel->device.name = name;
		parallel->device.IRPRequest = parallel_irp_request;
		parallel->device.Free = parallel_free;
		parallel->rdpcontext = pEntryPoints->rdpcontext;

		length = strlen(name);
		parallel->device.data = Stream_New(NULL, length + 1);
		if (!parallel->device.data)
		{
			WLog_ERR(TAG, "Stream_New failed!");
			error = CHANNEL_RC_NO_MEMORY;
			goto error_out;
		}

		for (i = 0; i <= length; i++)
			Stream_Write_UINT8(parallel->device.data, name[i] < 0 ? '_' : name[i]);

		parallel->path = path;

		parallel->queue = MessageQueue_New(NULL);
		if (!parallel->queue)
		{
			WLog_ERR(TAG, "MessageQueue_New failed!");
			error = CHANNEL_RC_NO_MEMORY;
			goto error_out;
		}

		if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) parallel)))
		{
			WLog_ERR(TAG, "RegisterDevice failed with error %lu!", error);
			goto error_out;
		}


		if (!(parallel->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) parallel_thread_func, (void*) parallel, 0, NULL)))
		{
			WLog_ERR(TAG, "CreateThread failed!");
			error = ERROR_INTERNAL_ERROR;
			goto error_out;
		}
	}

	return CHANNEL_RC_OK;
error_out:
	MessageQueue_Free(parallel->queue);
	Stream_Free(parallel->device.data, TRUE);
	free(parallel);
	return error;
}
Exemplo n.º 30
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
{
	char* name;
	char* path;
	size_t length;
	int ck;
	RDPDR_SMARTCARD* device;
	SMARTCARD_DEVICE* smartcard;
	UINT error = CHANNEL_RC_NO_MEMORY;

	device = (RDPDR_SMARTCARD*) pEntryPoints->device;

	name = device->Name;
	path = device->Path;

	smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE));
	if (!smartcard)
	{
		WLog_ERR(TAG, "calloc failed!");
		return CHANNEL_RC_NO_MEMORY;
	}

	smartcard->device.type = RDPDR_DTYP_SMARTCARD;
	smartcard->device.name = "SCARD";
	smartcard->device.IRPRequest = smartcard_irp_request;
	smartcard->device.Init = smartcard_init;
	smartcard->device.Free = smartcard_free;
	smartcard->rdpcontext = pEntryPoints->rdpcontext;

	length = strlen(smartcard->device.name);
	smartcard->device.data = Stream_New(NULL, length + 1);
	if (!smartcard->device.data)
	{
		WLog_ERR(TAG, "Stream_New failed!");
		goto error_device_data;
	}

	Stream_Write(smartcard->device.data, "SCARD", 6);

	smartcard->name = NULL;
	smartcard->path = NULL;

	if (path)
	{
		smartcard->path = path;
		smartcard->name = name;
	}
	else if (name)
	{
		if (1 == sscanf(name, "%d", &ck))
			smartcard->path = name;
		else
			smartcard->name = name;
	}

	smartcard->IrpQueue = MessageQueue_New(NULL);
	if (!smartcard->IrpQueue)
	{
		WLog_ERR(TAG, "MessageQueue_New failed!");
		goto error_irp_queue;
	}


	smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1);
	if (!smartcard->CompletedIrpQueue)
	{
		WLog_ERR(TAG, "Queue_New failed!");
		goto error_completed_irp_queue;
	}

	smartcard->rgSCardContextList = ListDictionary_New(TRUE);
	if (!smartcard->rgSCardContextList)
	{
		WLog_ERR(TAG, "ListDictionary_New failed!");
		goto error_context_list;
	}

	ListDictionary_ValueObject(smartcard->rgSCardContextList)->fnObjectFree =
			(OBJECT_FREE_FN) smartcard_context_free;

	smartcard->rgOutstandingMessages = ListDictionary_New(TRUE);
	if (!smartcard->rgOutstandingMessages)
	{
		WLog_ERR(TAG, "ListDictionary_New failed!");
		goto error_outstanding_messages;
	}

	if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard)))
	{
		WLog_ERR(TAG, "RegisterDevice failed!");
		goto error_outstanding_messages;
	}


	smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func,
			smartcard, CREATE_SUSPENDED, NULL);
	if (!smartcard->thread)
	{
		WLog_ERR(TAG, "ListDictionary_New failed!");
		error = ERROR_INTERNAL_ERROR;
		goto error_thread;
	}

	ResumeThread(smartcard->thread);

	return CHANNEL_RC_OK;

error_thread:
	ListDictionary_Free(smartcard->rgOutstandingMessages);
error_outstanding_messages:
	ListDictionary_Free(smartcard->rgSCardContextList);
error_context_list:
	Queue_Free(smartcard->CompletedIrpQueue);
error_completed_irp_queue:
	MessageQueue_Free(smartcard->IrpQueue);
error_irp_queue:
	Stream_Free(smartcard->device.data, TRUE);
error_device_data:
	free(smartcard);
	return error;
}