int xf_event_action_script_init(xfContext* xfc) { int exitCode; char* xevent; FILE* actionScript; char buffer[1024] = { 0 }; char command[1024] = { 0 }; xfc->xevents = ArrayList_New(TRUE); ArrayList_Object(xfc->xevents)->fnObjectFree = free; sprintf_s(command, sizeof(command), "%s xevent", xfc->actionScript); actionScript = popen(command, "r"); if (actionScript < 0) return -1; while (fgets(buffer, sizeof(buffer), actionScript) != NULL) { strtok(buffer, "\n"); xevent = _strdup(buffer); ArrayList_Add(xfc->xevents, xevent); } exitCode = pclose(actionScript); return 1; }
static BOOL InitWinPRPipeModule() { if (g_NamedPipeServerSockets) return TRUE; g_NamedPipeServerSockets = ArrayList_New(FALSE); return g_NamedPipeServerSockets != NULL; }
BOOL InitializeWindowClasses() { if (g_WindowClasses) return TRUE; g_WindowClasses = ArrayList_New(TRUE); return g_WindowClasses != NULL; }
static BOOL InitializeThreadpool(PTP_POOL pool) { int index; HANDLE thread; if (pool->Threads) return TRUE; pool->Minimum = 0; pool->Maximum = 500; if (!(pool->PendingQueue = Queue_New(TRUE, -1, -1))) goto fail_queue_new; if (!(pool->WorkComplete = CountdownEvent_New(0))) goto fail_countdown_event; if (!(pool->TerminateEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) goto fail_terminate_event; if (!(pool->Threads = ArrayList_New(TRUE))) goto fail_thread_array; pool->Threads->object.fnObjectFree = threads_close; for (index = 0; index < 4; index++) { if (!(thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) thread_pool_work_func, (void*) pool, 0, NULL))) { goto fail_create_threads; } if (ArrayList_Add(pool->Threads, thread) < 0) goto fail_create_threads; } return TRUE; fail_create_threads: SetEvent(pool->TerminateEvent); ArrayList_Free(pool->Threads); pool->Threads = NULL; fail_thread_array: CloseHandle(pool->TerminateEvent); pool->TerminateEvent = NULL; fail_terminate_event: CountdownEvent_Free(pool->WorkComplete); pool->WorkComplete = NULL; fail_countdown_event: Queue_Free(pool->PendingQueue); pool->WorkComplete = NULL; fail_queue_new: return FALSE; }
/** * this is called shortly after the application starts and * before any other function in the file * called only from main thread */ int freerdp_channels_global_init(void) { if (!g_ChannelsList) { g_ChannelsList = ArrayList_New(TRUE); InitializeCriticalSectionAndSpinCount(&g_channels_lock, 4000); } return 0; }
/** * this is called shortly after the application starts and * before any other function in the file * called only from main thread */ int freerdp_channels_global_init(void) { g_open_handle_sequence = 1; g_mutex_init = CreateMutex(NULL, FALSE, NULL); if (!g_ChannelsList) g_ChannelsList = ArrayList_New(TRUE); return 0; }
BOOL xf_keyboard_action_script_init(xfContext* xfc) { FILE* keyScript; char* keyCombination; char buffer[1024] = { 0 }; char command[1024] = { 0 }; if (xfc->actionScript) { free(xfc->actionScript); xfc->actionScript = NULL; } if (PathFileExistsA("/usr/share/freerdp/action.sh")) xfc->actionScript = _strdup("/usr/share/freerdp/action.sh"); if (!xfc->actionScript) return FALSE; xfc->keyCombinations = ArrayList_New(TRUE); if (!xfc->keyCombinations) return FALSE; ArrayList_Object(xfc->keyCombinations)->fnObjectFree = free; sprintf_s(command, sizeof(command), "%s key", xfc->actionScript); keyScript = popen(command, "r"); if (!keyScript) { free(xfc->actionScript); xfc->actionScript = NULL; return FALSE; } while (fgets(buffer, sizeof(buffer), keyScript) != NULL) { strtok(buffer, "\n"); keyCombination = _strdup(buffer); if (!keyCombination || ArrayList_Add(xfc->keyCombinations, keyCombination) < 0) { ArrayList_Free(xfc->keyCombinations); free(xfc->actionScript); xfc->actionScript = NULL; pclose(keyScript); return FALSE; } } pclose(keyScript); return xf_event_action_script_init(xfc); }
static void _HandleCreatorsInit() { assert(_HandleCreators == NULL); _HandleCreators = ArrayList_New(TRUE); if (!_HandleCreators) return; /* * Register all file handle creators. */ ArrayList_Add(_HandleCreators, GetNamedPipeClientHandleCreator()); #if defined __linux__ && !defined ANDROID ArrayList_Add(_HandleCreators, GetCommHandleCreator()); #endif /* __linux__ && !defined ANDROID */ }
IWTSVirtualChannelManager* dvcman_new(drdynvcPlugin* plugin) { DVCMAN* dvcman; dvcman = (DVCMAN*) calloc(1, sizeof(DVCMAN)); dvcman->iface.CreateListener = dvcman_create_listener; dvcman->iface.PushEvent = dvcman_push_event; dvcman->iface.FindChannelById = dvcman_find_channel_by_id; dvcman->iface.GetChannelId = dvcman_get_channel_id; dvcman->drdynvc = plugin; dvcman->channels = ArrayList_New(TRUE); dvcman->pool = StreamPool_New(TRUE, 10); return (IWTSVirtualChannelManager*) dvcman; }
void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints) { /** * The channel manager will guarantee only one thread can call * VirtualChannelInit at a time. So this should be safe. */ CopyMemory(&plugin->channel_entry_points, pEntryPoints, pEntryPoints->cbSize); if (!g_AddinList) g_AddinList = ArrayList_New(TRUE); ArrayList_Add(g_AddinList, (void*) plugin); plugin->channel_entry_points.pVirtualChannelInit(&plugin->init_handle, &plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, svc_plugin_init_event); }
void tsmf_media_init(void) { #ifndef _WIN32 struct sigaction sigtrap; sigtrap.sa_handler = tsmf_signal_handler; sigemptyset(&sigtrap.sa_mask); sigtrap.sa_flags = 0; sigaction(SIGINT, &sigtrap, 0); sigaction(SIGUSR1, &sigtrap, 0); #endif if (!presentation_list) { presentation_list = ArrayList_New(TRUE); ArrayList_Object(presentation_list)->fnObjectFree = (OBJECT_FREE_FN) _tsmf_presentation_free; } }
rdpShadowMultiClientEvent* shadow_multiclient_new() { rdpShadowMultiClientEvent* event = (rdpShadowMultiClientEvent*) calloc(1, sizeof(rdpShadowMultiClientEvent)); if (!event) goto out_error; event->event = CreateEvent(NULL, TRUE, FALSE, NULL); if (!event->event) goto out_free; event->barrierEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!event->barrierEvent) goto out_free_event; event->doneEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!event->doneEvent) goto out_free_barrierEvent; event->subscribers = ArrayList_New(TRUE); if (!event->subscribers) goto out_free_doneEvent; if (!InitializeCriticalSectionAndSpinCount(&(event->lock), 4000)) goto out_free_subscribers; event->consuming = 0; event->waiting = 0; event->eventid = 0; SetEvent(event->doneEvent); return event; out_free_subscribers: ArrayList_Free(event->subscribers); out_free_doneEvent: CloseHandle(event->doneEvent); out_free_barrierEvent: CloseHandle(event->barrierEvent); out_free_event: CloseHandle(event->event); out_free: free(event); out_error: return (rdpShadowMultiClientEvent *)NULL; }
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; }
IWTSVirtualChannelManager *dvcman_new(drdynvcPlugin *plugin) { DVCMAN *dvcman; dvcman = (DVCMAN *) calloc(1,sizeof(DVCMAN)); if (!dvcman) { DEBUG_WARN("calloc failed %s (%d)!", strerror(errno), errno); return NULL; } dvcman->iface.CreateListener = dvcman_create_listener; dvcman->iface.PushEvent = dvcman_push_event; dvcman->iface.FindChannelById = dvcman_find_channel_by_id; dvcman->iface.GetChannelId = dvcman_get_channel_id; dvcman->drdynvc = plugin; dvcman->channels = ArrayList_New(TRUE); return (IWTSVirtualChannelManager *) dvcman; }
TSMF_PRESENTATION *tsmf_presentation_new(const BYTE *guid, IWTSVirtualChannelCallback *pChannelCallback) { TSMF_PRESENTATION *presentation; assert(guid); assert(pChannelCallback); presentation = (TSMF_PRESENTATION *) calloc(1, sizeof(TSMF_PRESENTATION)); if (!presentation) { CLOG_ERR("calloc failed"); return NULL; } CopyMemory(presentation->presentation_id, guid, GUID_SIZE); presentation->channel_callback = pChannelCallback; presentation->volume = 5000; /* 50% */ presentation->stream_list = ArrayList_New(TRUE); ArrayList_Object(presentation->stream_list)->fnObjectFree = (OBJECT_FREE_FN) _tsmf_stream_free; ArrayList_Add(presentation_list, presentation); return presentation; }
int rpc_client_new(rdpRpc* rpc) { RpcClient* client = NULL; client = (RpcClient*) malloc(sizeof(RpcClient)); if (client) { client->Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) rpc_client_thread, rpc, CREATE_SUSPENDED, NULL); client->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); client->PduSentEvent = CreateEvent(NULL, TRUE, FALSE, NULL); client->SendQueue = Queue_New(TRUE, -1, -1); Queue_Object(client->SendQueue)->fnObjectFree = (OBJECT_FREE_FN) rpc_pdu_free; client->pdu = NULL; client->ReceivePool = Queue_New(TRUE, -1, -1); client->ReceiveQueue = Queue_New(TRUE, -1, -1); Queue_Object(client->ReceivePool)->fnObjectFree = (OBJECT_FREE_FN) rpc_pdu_free; Queue_Object(client->ReceiveQueue)->fnObjectFree = (OBJECT_FREE_FN) rpc_pdu_free; client->RecvFrag = NULL; client->FragmentPool = Queue_New(TRUE, -1, -1); client->FragmentQueue = Queue_New(TRUE, -1, -1); Queue_Object(client->FragmentPool)->fnObjectFree = (OBJECT_FREE_FN) rpc_fragment_free; Queue_Object(client->FragmentQueue)->fnObjectFree = (OBJECT_FREE_FN) rpc_fragment_free; client->ClientCallList = ArrayList_New(TRUE); ArrayList_Object(client->ClientCallList)->fnObjectFree = (OBJECT_FREE_FN) rpc_client_call_free; } rpc->client = client; return 0; }
TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid, IWTSVirtualChannelCallback* pChannelCallback) { TSMF_PRESENTATION* presentation; if (!guid || !pChannelCallback) return NULL; presentation = (TSMF_PRESENTATION*) calloc(1, sizeof(TSMF_PRESENTATION)); if (!presentation) { WLog_ERR(TAG, "calloc failed"); return NULL; } CopyMemory(presentation->presentation_id, guid, GUID_SIZE); presentation->channel_callback = pChannelCallback; presentation->volume = 5000; /* 50% */ presentation->muted = 0; if (!(presentation->stream_list = ArrayList_New(TRUE))) goto error_stream_list; ArrayList_Object(presentation->stream_list)->fnObjectFree = (OBJECT_FREE_FN) _tsmf_stream_free; if (ArrayList_Add(presentation_list, presentation) < 0) goto error_add; return presentation; error_add: ArrayList_Free(presentation->stream_list); error_stream_list: free(presentation); return NULL; }
static IWTSVirtualChannelManager* dvcman_new(drdynvcPlugin* plugin) { DVCMAN* dvcman; dvcman = (DVCMAN*) calloc(1, sizeof(DVCMAN)); if (!dvcman) { WLog_Print(plugin->log, WLOG_ERROR, "calloc failed!"); return NULL; } dvcman->iface.CreateListener = dvcman_create_listener; dvcman->iface.FindChannelById = dvcman_find_channel_by_id; dvcman->iface.GetChannelId = dvcman_get_channel_id; dvcman->drdynvc = plugin; dvcman->channels = ArrayList_New(TRUE); if (!dvcman->channels) { WLog_Print(plugin->log, WLOG_ERROR, "ArrayList_New failed!"); free(dvcman); return NULL; } dvcman->channels->object.fnObjectFree = dvcman_channel_free; dvcman->pool = StreamPool_New(TRUE, 10); if (!dvcman->pool) { WLog_Print(plugin->log, WLOG_ERROR, "StreamPool_New failed!"); ArrayList_Free(dvcman->channels); free(dvcman); return NULL; } return (IWTSVirtualChannelManager*) dvcman; }
rdpRpc* rpc_new(rdpTransport* transport) { rdpRpc* rpc = (rdpRpc*) malloc(sizeof(rdpRpc)); if (rpc != NULL) { ZeroMemory(rpc, sizeof(rdpRpc)); rpc->State = RPC_CLIENT_STATE_INITIAL; rpc->transport = transport; rpc->settings = transport->settings; rpc->SendSeqNum = 0; rpc->ntlm = ntlm_new(); rpc->NtlmHttpIn = ntlm_http_new(); rpc->NtlmHttpOut = ntlm_http_new(); rpc_ntlm_http_init_channel(rpc, rpc->NtlmHttpIn, TSG_CHANNEL_IN); rpc_ntlm_http_init_channel(rpc, rpc->NtlmHttpOut, TSG_CHANNEL_OUT); rpc->PipeCallId = 0; rpc->StubCallId = 0; rpc->StubFragCount = 0; rpc->rpc_vers = 5; rpc->rpc_vers_minor = 0; /* little-endian data representation */ rpc->packed_drep[0] = 0x10; rpc->packed_drep[1] = 0x00; rpc->packed_drep[2] = 0x00; rpc->packed_drep[3] = 0x00; rpc->max_xmit_frag = 0x0FF8; rpc->max_recv_frag = 0x0FF8; rpc->ReceiveWindow = 0x00010000; rpc->ChannelLifetime = 0x40000000; rpc->ChannelLifetimeSet = 0; rpc->KeepAliveInterval = 300000; rpc->CurrentKeepAliveInterval = rpc->KeepAliveInterval; rpc->CurrentKeepAliveTime = 0; rpc->VirtualConnection = rpc_client_virtual_connection_new(rpc); rpc->VirtualConnectionCookieTable = ArrayList_New(TRUE); rpc->CallId = 2; rpc_client_new(rpc); rpc->client->SynchronousSend = TRUE; rpc->client->SynchronousReceive = TRUE; } return rpc; }
int rpc_client_new(rdpRpc* rpc) { RpcClient* client; client = (RpcClient*) calloc(1, sizeof(RpcClient)); rpc->client = client; if (!client) return -1; client->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!client->StopEvent) return -1; client->PduSentEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!client->PduSentEvent) return -1; client->SendQueue = Queue_New(TRUE, -1, -1); if (!client->SendQueue) return -1; Queue_Object(client->SendQueue)->fnObjectFree = (OBJECT_FREE_FN) rpc_pdu_free; client->pdu = NULL; client->ReceivePool = Queue_New(TRUE, -1, -1); if (!client->ReceivePool) return -1; Queue_Object(client->ReceivePool)->fnObjectFree = (OBJECT_FREE_FN) rpc_pdu_free; client->ReceiveQueue = Queue_New(TRUE, -1, -1); if (!client->ReceiveQueue) return -1; Queue_Object(client->ReceiveQueue)->fnObjectFree = (OBJECT_FREE_FN) rpc_pdu_free; client->RecvFrag = NULL; client->FragmentPool = Queue_New(TRUE, -1, -1); if (!client->FragmentPool) return -1; Queue_Object(client->FragmentPool)->fnObjectFree = (OBJECT_FREE_FN) rpc_fragment_free; client->FragmentQueue = Queue_New(TRUE, -1, -1); if (!client->FragmentQueue) return -1; Queue_Object(client->FragmentQueue)->fnObjectFree = (OBJECT_FREE_FN) rpc_fragment_free; client->ClientCallList = ArrayList_New(TRUE); if (!client->ClientCallList) return -1; ArrayList_Object(client->ClientCallList)->fnObjectFree = (OBJECT_FREE_FN) rpc_client_call_free; return 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; }
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) { SetLastError(ERROR_INVALID_DATA); return INVALID_HANDLE_VALUE; } vcm = (WTSVirtualChannelManager*) calloc(1, sizeof(WTSVirtualChannelManager)); if (!vcm) goto error_vcm_alloc; vcm->client = client; vcm->rdp = context->rdp; vcm->SessionId = g_SessionId++; if (!g_ServerHandles) { g_ServerHandles = HashTable_New(TRUE); if (!g_ServerHandles) goto error_free; } if (HashTable_Add(g_ServerHandles, (void*) (UINT_PTR) vcm->SessionId, (void*) vcm) < 0) goto error_free; vcm->queue = MessageQueue_New(NULL); if (!vcm->queue) goto error_queue; vcm->dvc_channel_id_seq = 0; vcm->dynamicVirtualChannels = ArrayList_New(TRUE); if (!vcm->dynamicVirtualChannels) goto error_dynamicVirtualChannels; client->ReceiveChannelData = WTSReceiveChannelData; hServer = (HANDLE) vcm; return hServer; error_dynamicVirtualChannels: MessageQueue_Free(vcm->queue); error_queue: HashTable_Remove(g_ServerHandles, (void*) (UINT_PTR) vcm->SessionId); error_free: free(vcm); error_vcm_alloc: SetLastError(ERROR_NOT_ENOUGH_MEMORY); return INVALID_HANDLE_VALUE; }