Ejemplo n.º 1
0
/*
 * Consume my share and release my register
 * If we have update event and pleaseHandle flag
 * We need to consume. Anyway we need to clear
 * pleaseHandle flag
 */
void shadow_multiclient_release_subscriber(void* subscriber)
{
	struct rdp_shadow_multiclient_subscriber* s;
	rdpShadowMultiClientEvent* event;

	if (!subscriber)
		return;

	s = (struct rdp_shadow_multiclient_subscriber*)subscriber;
	event = s->ref;

	EnterCriticalSection(&(event->lock));

	WLog_VRB(TAG, "Release Subscriber %p. Drop event %d. %d clients.\n", subscriber, event->eventid, event->consuming);
	(void)_Consume(s, FALSE);
	WLog_VRB(TAG, "Release Subscriber %p. Quit event %d. %d clients.\n", subscriber, event->eventid, event->consuming);

	ArrayList_Remove(event->subscribers, subscriber);

	LeaveCriticalSection(&(event->lock));

	free(subscriber);

	return;
}
Ejemplo n.º 2
0
BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
{
	wStream* s;
	rdpMcs* mcs;
	WTSVirtualChannelManager* vcm;
	rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
	BOOL ret = TRUE;

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

		if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
		{
			if (channel->index < mcs->channelCount)
				mcs->channels[channel->index].handle = NULL;
		}
		else
		{
			ArrayList_Remove(vcm->dynamicVirtualChannels, channel);

			if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
			{
				ULONG written;

				s = Stream_New(NULL, 8);
				if (!s)
				{
					WLog_ERR(TAG, "Stream_New failed!");
					ret = FALSE;
				}
				else
				{
					wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
					ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
					Stream_Free(s, TRUE);
				}

			}
		}

		if (channel->receiveData)
			Stream_Free(channel->receiveData, TRUE);

		if (channel->queue)
		{
			MessageQueue_Free(channel->queue);
			channel->queue = NULL;
		}

		free(channel);
	}

	return ret;
}
Ejemplo n.º 3
0
void freerdp_channels_free(rdpChannels* channels)
{
	MessagePipe_Free(channels->MsgPipe);

	ArrayList_Lock(g_ChannelsList);
	ArrayList_Remove(g_ChannelsList, channels);
	ArrayList_Unlock(g_ChannelsList);

	free(channels);
}
Ejemplo n.º 4
0
static int dvcman_close_channel_iface(IWTSVirtualChannel *pChannel)
{
	DVCMAN_CHANNEL *channel = (DVCMAN_CHANNEL *) pChannel;
	DVCMAN *dvcman = channel->dvcman;
	assert(channel);
	assert(dvcman);
	DEBUG_DVC("id=%d", channel->channel_id);
	ArrayList_Remove(dvcman->channels, channel);
	dvcman_channel_free(channel);
	return 1;
}
Ejemplo n.º 5
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT dvcman_close_channel(IWTSVirtualChannelManager* pChannelMgr,
				 UINT32 ChannelId)
{
	DVCMAN_CHANNEL* channel;
	IWTSVirtualChannel* ichannel;
	DrdynvcClientContext* context;
	DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
	UINT error = CHANNEL_RC_OK;

	channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);

	if (!channel)
	{
		//WLog_ERR(TAG, "ChannelId %d not found!", ChannelId);
		/**
		 * Windows 8 / Windows Server 2012 send close requests for channels that failed to be created.
		 * Do not warn, simply return success here.
		 */
		return CHANNEL_RC_OK;
	}

	if (channel->status == CHANNEL_RC_OK)
	{
		context = dvcman->drdynvc->context;

		IFCALLRET(context->OnChannelDisconnected, error, context, channel->channel_name, channel->pInterface);
		if (error)
		{
			WLog_ERR(TAG, "OnChannelDisconnected returned with error %lu!", error);
			return error;
		}

		WLog_DBG(TAG, "dvcman_close_channel: channel %d closed", ChannelId);

		ichannel = (IWTSVirtualChannel*) channel;

		if ((ichannel->Close) && (error = ichannel->Close(ichannel)))
		{
			WLog_ERR(TAG, "Close failed with eror %lu!", error);
			return error;
		}
	}

	ArrayList_Remove(dvcman->channels, channel);

	return CHANNEL_RC_OK;
}
Ejemplo n.º 6
0
void * HeapList_Allocate(HeapList_T * list)
{
   byte_t ** unused_list;
   byte_t * mem;
   size_t count;

   unused_list = ArrayList_Get(&list->unused_memory, &count, NULL);
   if(count == 0)
   {
      HeapList_CreateNewBlock(list);
      unused_list = ArrayList_Get(&list->unused_memory, &count, NULL);
   }

   mem = unused_list[0];
   ArrayList_Remove(&list->unused_memory, 0);
   list->count ++;

   return mem;
}
Ejemplo n.º 7
0
/**
 * Function description
 *
 * @return 0 on success, otherwise a Win32 error code
 */
static UINT dvcman_close_channel(IWTSVirtualChannelManager* pChannelMgr,
                                 UINT32 ChannelId)
{
	DVCMAN_CHANNEL* channel;
	UINT error = CHANNEL_RC_OK;
	DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
	channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);

	if (!channel)
	{
		//WLog_Print(drdynvc->log, WLOG_ERROR, "ChannelId %"PRIu32" not found!", ChannelId);
		/**
		 * Windows 8 / Windows Server 2012 send close requests for channels that failed to be created.
		 * Do not warn, simply return success here.
		 */
		return CHANNEL_RC_OK;
	}

	ArrayList_Remove(dvcman->channels, channel);
	return error;
}
Ejemplo n.º 8
0
static void winpr_unref_named_pipe(WINPR_NAMED_PIPE* pNamedPipe)
{
	int index;
	NamedPipeServerSocketEntry* baseSocket;

	if (!pNamedPipe)
		return;

	assert(pNamedPipe->name);
	assert(g_NamedPipeServerSockets);
	//WLog_VRB(TAG, "%p (%s)", pNamedPipe, pNamedPipe->name);
	ArrayList_Lock(g_NamedPipeServerSockets);

	for (index = 0; index < ArrayList_Count(g_NamedPipeServerSockets); index++)
	{
		baseSocket = (NamedPipeServerSocketEntry*) ArrayList_GetItem(
						 g_NamedPipeServerSockets, index);
		assert(baseSocket->name);

		if (!strcmp(baseSocket->name, pNamedPipe->name))
		{
			assert(baseSocket->references > 0);
			assert(baseSocket->serverfd != -1);

			if (--baseSocket->references == 0)
			{
				//WLog_DBG(TAG, "removing shared server socked resource");
				//WLog_DBG(TAG, "closing shared serverfd %d", baseSocket->serverfd);
				ArrayList_Remove(g_NamedPipeServerSockets, baseSocket);
				close(baseSocket->serverfd);
				free(baseSocket->name);
				free(baseSocket);
			}

			break;
		}
	}

	ArrayList_Unlock(g_NamedPipeServerSockets);
}
Ejemplo n.º 9
0
void shadow_client_context_free(freerdp_peer* peer, rdpShadowClient* client)
{
	rdpShadowServer* server = client->server;

	ArrayList_Remove(server->clients, (void*) client);

	DeleteCriticalSection(&(client->lock));

	region16_uninit(&(client->invalidRegion));

	WTSCloseServer((HANDLE) client->vcm);

    /* Clear queued messages and free resource */
	MessageQueue_Clear(client->MsgQueue);
	MessageQueue_Free(client->MsgQueue);

	if (client->encoder)
	{
		shadow_encoder_free(client->encoder);
		client->encoder = NULL;
	}
}
Ejemplo n.º 10
0
static void winpr_unref_named_pipe(WINPR_NAMED_PIPE* pNamedPipe)
{
	int index;
	NamedPipeServerSocketEntry *baseSocket;

	if (!pNamedPipe)
		return;

	assert(pNamedPipe->name);
	assert(g_NamedPipeServerSockets);

	//fprintf(stderr, "%s: %p (%s)\n", __FUNCTION__, pNamedPipe, pNamedPipe->name);

	ArrayList_Lock(g_NamedPipeServerSockets);
	for (index = 0; index < ArrayList_Count(g_NamedPipeServerSockets); index++)
	{
		baseSocket = (NamedPipeServerSocketEntry*) ArrayList_GetItem(
				g_NamedPipeServerSockets, index);
		assert(baseSocket->name);
		if (!strcmp(baseSocket->name, pNamedPipe->name))
		{
			assert(baseSocket->references > 0);
			assert(baseSocket->serverfd != -1);
			if (--baseSocket->references == 0)
			{
				//fprintf(stderr, "%s: removing shared server socked resource\n", __FUNCTION__);
				//fprintf(stderr, "%s: closing shared serverfd %d\n", __FUNCTION__, baseSocket->serverfd);
				ArrayList_Remove(g_NamedPipeServerSockets, baseSocket);
				close(baseSocket->serverfd);
				free(baseSocket->name);
				free(baseSocket);
			}
			break;
		}
	}
	ArrayList_Unlock(g_NamedPipeServerSockets);
}
Ejemplo n.º 11
0
void tsmf_stream_free(TSMF_STREAM* stream)
{
	TSMF_PRESENTATION* presentation = stream->presentation;
	ArrayList_Remove(presentation->stream_list, stream);
}
Ejemplo n.º 12
0
void tsmf_presentation_free(TSMF_PRESENTATION* presentation)
{
	ArrayList_Remove(presentation_list, presentation);
}
Ejemplo n.º 13
0
int TestArrayList(int argc, char* argv[])
{
	int index;
	int count;
	size_t val;
	wArrayList* arrayList;
	const int elemsToInsert = 10;

	arrayList = ArrayList_New(TRUE);
	if (!arrayList)
		return -1;

	for (index = 0; index < elemsToInsert; index++)
	{
		if (ArrayList_Add(arrayList, (void*) (size_t) index) < 0)
			return -1;
	}

	count = ArrayList_Count(arrayList);

	printf("ArrayList count: %d\n", count);

	index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);

	printf("ArrayList index: %d\n", index);

	if (index != 6)
		return -1;

	ArrayList_Insert(arrayList, 5, (void*) (size_t) 100);

	index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
	printf("ArrayList index: %d\n", index);

	if (index != 7)
		return -1;

	ArrayList_Remove(arrayList, (void*) (size_t) 100);

	index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
	printf("ArrayList index: %d\n", index);

	if (index != 6)
		return -1;

	for (index = 0; index < elemsToInsert; index++) {
		val = (size_t)ArrayList_GetItem(arrayList, 0);
		ArrayList_RemoveAt(arrayList, 0);
		if (val != index)
		{
			printf("ArrayList: shifted %d entries, expected value %d, got %"PRIdz"\n", index, index, val);
			return -1;
		}
	}

	index = ArrayList_IndexOf(arrayList, (void*) (size_t) elemsToInsert, -1, -1);
	printf("ArrayList index: %d\n", index);
	if (index != -1)
		return -1;

	count = ArrayList_Count(arrayList);
	printf("ArrayList count: %d\n", count);
	if (count != 0)
		return -1;

	ArrayList_Clear(arrayList);
	ArrayList_Free(arrayList);

	return 0;
}
Ejemplo n.º 14
0
static void svc_plugin_remove(rdpSvcPlugin* plugin)
{
	ArrayList_Remove(g_AddinList, (void*) plugin);
}
Ejemplo n.º 15
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));
	if (!channel)
	{
		SetLastError(ERROR_NOT_ENOUGH_MEMORY);
		return NULL;
	}

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

	if (!channel->receiveData)
	{
		WLog_ERR(TAG, "Stream_New failed!");
		goto error_receiveData;
	}

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

	channel->channelId = InterlockedIncrement(&vcm->dvc_channel_id_seq);
	if (ArrayList_Add(vcm->dynamicVirtualChannels, channel) < 0)
		goto error_add;

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

	return channel;

error_create:
	Stream_Free(s, TRUE);
error_s:
	ArrayList_Remove(vcm->dynamicVirtualChannels, channel);
error_add:
	MessageQueue_Free(channel->queue);
error_queue:
	Stream_Free(channel->receiveData, TRUE);
error_receiveData:
	free(channel);
	SetLastError(ERROR_NOT_ENOUGH_MEMORY);
	return NULL;
}