示例#1
0
static int rdpsnd_server_start(RdpsndServerContext* context)
{
	context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpsnd");
	if (!context->priv->ChannelHandle)
		return -1;

	context->priv->rdpsnd_pdu = Stream_New(NULL, 4096);
	if (!context->priv->rdpsnd_pdu)
		goto out_close;

	context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	if (!context->priv->StopEvent)
		goto out_pdu;

	context->priv->Thread = CreateThread(NULL, 0,
			(LPTHREAD_START_ROUTINE) rdpsnd_server_thread, (void*) context, 0, NULL);
	if (!context->priv->Thread)
		goto out_stopEvent;

	return 0;

out_stopEvent:
	CloseHandle(context->priv->StopEvent);
	context->priv->StopEvent = NULL;
out_pdu:
	Stream_Free(context->priv->rdpsnd_pdu, TRUE);
	context->priv->rdpsnd_pdu = NULL;
out_close:
	WTSVirtualChannelClose(context->priv->ChannelHandle);
	context->priv->ChannelHandle = NULL;
	return -1;
}
示例#2
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT encomsp_server_start(EncomspServerContext* context)
{
	context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm,
	                               WTS_CURRENT_SESSION, "encomsp");

	if (!context->priv->ChannelHandle)
		return CHANNEL_RC_BAD_CHANNEL;

	if (!(context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
	{
		WLog_ERR(TAG, "CreateEvent failed!");
		return ERROR_INTERNAL_ERROR;
	}

	if (!(context->priv->Thread = CreateThread(NULL, 0,
	                              (LPTHREAD_START_ROUTINE) encomsp_server_thread, (void*) context, 0, NULL)))
	{
		WLog_ERR(TAG, "CreateThread failed!");
		CloseHandle(context->priv->StopEvent);
		context->priv->StopEvent = NULL;
		return ERROR_INTERNAL_ERROR;
	}

	return CHANNEL_RC_OK;
}
示例#3
0
static int rdpdr_server_start(RdpdrServerContext* context)
{
	context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpdr");

	if (!context->priv->ChannelHandle)
		return -1;

	context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	context->priv->Thread = CreateThread(NULL, 0,
										 (LPTHREAD_START_ROUTINE) rdpdr_server_thread, (void*) context, 0, NULL);
	return 0;
}
示例#4
0
static int rdpsnd_server_start(RdpsndServerContext* context)
{
	void *buffer = NULL;
	DWORD bytesReturned;
	RdpsndServerPrivate *priv = context->priv;

	priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpsnd");
	if (!priv->ChannelHandle)
		return -1;

	if (!WTSVirtualChannelQuery(priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &bytesReturned) || (bytesReturned != sizeof(HANDLE)))
	{
		WLog_ERR(TAG,  "%s: error during WTSVirtualChannelQuery(WTSVirtualEventHandle) or invalid returned size(%d)\n",
				 __FUNCTION__, bytesReturned);

		if (buffer)
			WTSFreeMemory(buffer);
		goto out_close;
	}
	CopyMemory(&priv->channelEvent, buffer, sizeof(HANDLE));
	WTSFreeMemory(buffer);

	priv->rdpsnd_pdu = Stream_New(NULL, 4096);
	if (!priv->rdpsnd_pdu)
		goto out_close;


	if (priv->ownThread)
	{
		context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
		if (!context->priv->StopEvent)
			goto out_pdu;

		context->priv->Thread = CreateThread(NULL, 0,
				(LPTHREAD_START_ROUTINE) rdpsnd_server_thread, (void*) context, 0, NULL);
		if (!context->priv->Thread)
			goto out_stopEvent;
	}

	return 0;

out_stopEvent:
	CloseHandle(context->priv->StopEvent);
	context->priv->StopEvent = NULL;
out_pdu:
	Stream_Free(context->priv->rdpsnd_pdu, TRUE);
	context->priv->rdpsnd_pdu = NULL;
out_close:
	WTSVirtualChannelClose(context->priv->ChannelHandle);
	context->priv->ChannelHandle = NULL;
	return -1;
}
示例#5
0
文件: server.c 项目: dcatonR1/FreeRDP
BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
{
	wMessage message;
	BOOL status = TRUE;
	rdpPeerChannel* channel;
	UINT32 dynvc_caps;
	WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*) hServer;

	if ((vcm->drdynvc_state == DRDYNVC_STATE_NONE) && vcm->client->activated)
	{
		/* Initialize drdynvc channel once and only once. */
		vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
		channel = (rdpPeerChannel*) WTSVirtualChannelOpen((HANDLE) vcm,
		          WTS_CURRENT_SESSION, "drdynvc");

		if (channel)
		{
			ULONG written;
			vcm->drdynvc_channel = channel;
			dynvc_caps = 0x00010050; /* DYNVC_CAPS_VERSION1 (4 bytes) */

			if (!WTSVirtualChannelWrite(channel, (PCHAR) &dynvc_caps, sizeof(dynvc_caps),
			                            &written))
				return FALSE;
		}
	}

	while (MessageQueue_Peek(vcm->queue, &message, TRUE))
	{
		BYTE* buffer;
		UINT32 length;
		UINT16 channelId;
		channelId = (UINT16)(UINT_PTR) message.context;
		buffer = (BYTE*) message.wParam;
		length = (UINT32)(UINT_PTR) message.lParam;

		if (vcm->client->SendChannelData(vcm->client, channelId, buffer,
		                                 length) == FALSE)
		{
			status = FALSE;
		}

		free(buffer);

		if (!status)
			break;
	}

	return status;
}
int TestWtsApiExtraVirtualChannel(int argc, char* argv[])
{
	BOOL bSuccess;
	ULONG length;
	ULONG bytesRead;
	ULONG bytesWritten;
	BYTE buffer[1024];
	HANDLE hVirtualChannel;

	length = sizeof(buffer);

	hVirtualChannel = WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, "sample");

	if (hVirtualChannel == INVALID_HANDLE_VALUE)
	{
		printf("WTSVirtualChannelOpen failed: %d\n", (int) GetLastError());
		return -1;
	}
	printf("WTSVirtualChannelOpen opend");
	bytesWritten = 0;
	bSuccess = WTSVirtualChannelWrite(hVirtualChannel, (PCHAR) buffer, length, &bytesWritten);

	if (!bSuccess)
	{
		printf("WTSVirtualChannelWrite failed: %d\n", (int) GetLastError());
		return -1;
	}
	printf("WTSVirtualChannelWrite written");

	bytesRead = 0;
	bSuccess = WTSVirtualChannelRead(hVirtualChannel, 5000, (PCHAR) buffer, length, &bytesRead);

	if (!bSuccess)
	{
		printf("WTSVirtualChannelRead failed: %d\n", (int) GetLastError());
		return -1;
	}
	printf("WTSVirtualChannelRead read");

	if (!WTSVirtualChannelClose(hVirtualChannel))
	{
		printf("WTSVirtualChannelClose failed\n");
		return -1;
	}

	return 0;
}
示例#7
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT cliprdr_server_open(CliprdrServerContext* context)
{
	void* buffer = NULL;
	DWORD BytesReturned = 0;
	CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;

	cliprdr->ChannelHandle = WTSVirtualChannelOpen(cliprdr->vcm, WTS_CURRENT_SESSION, "cliprdr");

	if (!cliprdr->ChannelHandle)
	{
		WLog_ERR(TAG, "WTSVirtualChannelOpen for cliprdr failed!");
		return ERROR_INTERNAL_ERROR;
	}

	cliprdr->ChannelEvent = NULL;

	if (WTSVirtualChannelQuery(cliprdr->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned))
	{
		if (BytesReturned != sizeof(HANDLE))
		{
			WLog_ERR(TAG, "BytesReturned has not size of HANDLE!");
			return ERROR_INTERNAL_ERROR;
		}
		CopyMemory(&(cliprdr->ChannelEvent), buffer, sizeof(HANDLE));


		WTSFreeMemory(buffer);
	}

	if (!cliprdr->ChannelEvent)
	{
		WLog_ERR(TAG, "WTSVirtualChannelQuery for cliprdr failed!");
		return ERROR_INTERNAL_ERROR;
	}

	return CHANNEL_RC_OK;
}
示例#8
0
BOOL tf_peer_post_connect(freerdp_peer* client)
{
	testPeerContext* context = (testPeerContext*) client->context;

	/**
	 * This callback is called when the entire connection sequence is done, i.e. we've received the
	 * Font List PDU from the client and sent out the Font Map PDU.
	 * The server may start sending graphics output and receiving keyboard/mouse input after this
	 * callback returns.
	 */

	printf("Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname,
			client->settings->OsMajorType, client->settings->OsMinorType);

	if (client->settings->AutoLogonEnabled)
	{
		printf(" and wants to login automatically as %s\\%s",
			client->settings->Domain ? client->settings->Domain : "",
			client->settings->Username);

		/* A real server may perform OS login here if NLA is not executed previously. */
	}
	printf("\n");

	printf("Client requested desktop: %dx%dx%d\n",
		client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth);

#if (SAMPLE_SERVER_USE_CLIENT_RESOLUTION == 1)
	context->rfx_context->width = client->settings->DesktopWidth;
	context->rfx_context->height = client->settings->DesktopHeight;
	printf("Using resolution requested by client.\n");
#else
	client->settings->DesktopWidth = context->rfx_context->width;
	client->settings->DesktopHeight = context->rfx_context->height;
	printf("Resizing client to %dx%d\n", client->settings->DesktopWidth, client->settings->DesktopHeight);
	client->update->DesktopResize(client->update->context);
#endif

	/* A real server should tag the peer as activated here and start sending updates in main loop. */
	test_peer_load_icon(client);

	if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpdbg"))
	{
		context->debug_channel = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpdbg");

		if (context->debug_channel != NULL)
		{
			printf("Open channel rdpdbg.\n");

			context->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

			context->debug_channel_thread = CreateThread(NULL, 0,
					(LPTHREAD_START_ROUTINE) tf_debug_channel_thread_func, (void*) context, 0, NULL);
		}
	}

	if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd"))
	{
		sf_peer_rdpsnd_init(context); /* Audio Output */
	}

	/* Dynamic Virtual Channels */

	sf_peer_audin_init(context); /* Audio Input */

	/* Return FALSE here would stop the execution of the peer main loop. */

	return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
	HANDLE hChannel = NULL;
	PingPayload payload = { 0 };
	ULONG bytesRead=0, bytesWritten=0;
	UINT32 currentSequenceNo = 0;

	hChannel = WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, -1, "JDECHO");
	if (hChannel == NULL)
	{
		Log("Unable to open virtual channel: %i\r\n", GetLastError());
		Log("Are you running inside a remote desktop session?");

		goto End;
	}

	while (true)
	{
		// Send the ping packet across the virtual channel
		payload.SequenceNo = currentSequenceNo++;
		payload.TimeStamp = GetTickCount();

		if (!WTSVirtualChannelWrite(hChannel, (PCHAR)&payload, sizeof(payload), &bytesWritten))
		{
			Log("WTSVirtualChannelWrite failed: %i\t\n", GetLastError());
			goto End;
		}

		if (bytesWritten != sizeof(payload))
		{
			Log("Error: Partial writes are not handled");
			goto End;
		}

		// Wait for the echo channel to send the same packet back
		if (!WTSVirtualChannelRead(hChannel, INFINITE, (PCHAR)&payload, sizeof(payload), &bytesRead))
		{
			Log("WTSVirtualChannelRead failed: %i", GetLastError());
			goto End;
		}

		if (bytesRead != sizeof(payload))
		{
			Log("Error partial reads are not handled");
			goto End;
		}

		// Print statistics
		Log("Got ping reply: %i, %ims", (int)payload.SequenceNo, (int)(GetTickCount()-payload.TimeStamp));

		// Wait for a second before pinging again
		Sleep(1000);
	}

End:

	if (hChannel != NULL)
	{
		WTSVirtualChannelClose(hChannel);
	}
}
示例#10
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT rdpsnd_server_start(RdpsndServerContext* context)
{
	void *buffer = NULL;
	DWORD bytesReturned;
	RdpsndServerPrivate *priv = context->priv;
	UINT error = ERROR_INTERNAL_ERROR;

	priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpsnd");
	if (!priv->ChannelHandle)
	{
		WLog_ERR(TAG, "WTSVirtualChannelOpen failed!");
		return ERROR_INTERNAL_ERROR;
	}

	if (!WTSVirtualChannelQuery(priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &bytesReturned) || (bytesReturned != sizeof(HANDLE)))
	{
		WLog_ERR(TAG,  "error during WTSVirtualChannelQuery(WTSVirtualEventHandle) or invalid returned size(%d)",
				 bytesReturned);

		if (buffer)
			WTSFreeMemory(buffer);
		goto out_close;
	}
	CopyMemory(&priv->channelEvent, buffer, sizeof(HANDLE));
	WTSFreeMemory(buffer);

	priv->rdpsnd_pdu = Stream_New(NULL, 4096);
	if (!priv->rdpsnd_pdu)
	{
		WLog_ERR(TAG, "Stream_New failed!");
		error = CHANNEL_RC_NO_MEMORY;
		goto out_close;
	}

	if (!InitializeCriticalSectionEx(&context->priv->lock, 0, 0))
	{
		WLog_ERR(TAG, "InitializeCriticalSectionEx failed!");
		goto out_pdu;
	}

	if (priv->ownThread)
	{
		context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
		if (!context->priv->StopEvent)
		{
			WLog_ERR(TAG, "CreateEvent failed!");
			goto out_lock;
		}

		context->priv->Thread = CreateThread(NULL, 0,
				(LPTHREAD_START_ROUTINE) rdpsnd_server_thread, (void*) context, 0, NULL);
		if (!context->priv->Thread)
		{
			WLog_ERR(TAG, "CreateThread failed!");
			goto out_stopEvent;
		}

	}

	return CHANNEL_RC_OK;

out_stopEvent:
	CloseHandle(context->priv->StopEvent);
	context->priv->StopEvent = NULL;
out_lock:
	DeleteCriticalSection(&context->priv->lock);
out_pdu:
	Stream_Free(context->priv->rdpsnd_pdu, TRUE);
	context->priv->rdpsnd_pdu = NULL;
out_close:
	WTSVirtualChannelClose(context->priv->ChannelHandle);
	context->priv->ChannelHandle = NULL;
	return error;
}