int freerds_server_message_enqueue(rdsBackend* backend, RDS_MSG_COMMON* msg) { void* dup = NULL; dup = freerds_server_message_copy(msg); LinkedList_AddLast(((rdsBackendConnector *)backend)->ServerList, (void*) dup); return 0; }
int TestLinkedList(int argc, char* argv[]) { int count; int number; wLinkedList* list; list = LinkedList_New(); LinkedList_AddFirst(list, (void*) (size_t) 1); LinkedList_AddLast(list, (void*) (size_t) 2); LinkedList_AddLast(list, (void*) (size_t) 3); count = LinkedList_Count(list); if (count != 3) { printf("LinkedList_Count: expected %d, actual: %d\n", 3, count); return -1; } LinkedList_Enumerator_Reset(list); while (LinkedList_Enumerator_MoveNext(list)) { number = (int) (size_t) LinkedList_Enumerator_Current(list); printf("\t%d\n", number); } printf("\n"); printf("LinkedList First: %d Last: %d\n", (int) (size_t) LinkedList_First(list), (int) (size_t) LinkedList_Last(list)); LinkedList_RemoveFirst(list); LinkedList_RemoveLast(list); count = LinkedList_Count(list); if (count != 1) { printf("LinkedList_Count: expected %d, actual: %d\n", 1, count); return -1; } LinkedList_Enumerator_Reset(list); while (LinkedList_Enumerator_MoveNext(list)) { number = (int) (size_t) LinkedList_Enumerator_Current(list); printf("\t%d\n", number); } printf("\n"); printf("LinkedList First: %d Last: %d\n", (int) (size_t) LinkedList_First(list), (int) (size_t) LinkedList_Last(list)); LinkedList_RemoveFirst(list); LinkedList_RemoveLast(list); count = LinkedList_Count(list); if (count != 0) { printf("LinkedList_Count: expected %d, actual: %d\n", 0, count); return -1; } LinkedList_AddFirst(list, (void*) (size_t) 4); LinkedList_AddLast(list, (void*) (size_t) 5); LinkedList_AddLast(list, (void*) (size_t) 6); count = LinkedList_Count(list); if (count != 3) { printf("LinkedList_Count: expected %d, actual: %d\n", 3, count); return -1; } LinkedList_Enumerator_Reset(list); while (LinkedList_Enumerator_MoveNext(list)) { number = (int) (size_t) LinkedList_Enumerator_Current(list); printf("\t%d\n", number); } printf("\n"); printf("LinkedList First: %d Last: %d\n", (int) (size_t) LinkedList_First(list), (int) (size_t) LinkedList_Last(list)); LinkedList_Remove(list, (void*) (size_t) 5); LinkedList_Enumerator_Reset(list); while (LinkedList_Enumerator_MoveNext(list)) { number = (int) (size_t) LinkedList_Enumerator_Current(list); printf("\t%d\n", number); } printf("\n"); printf("LinkedList First: %d Last: %d\n", (int) (size_t) LinkedList_First(list), (int) (size_t) LinkedList_Last(list)); LinkedList_Free(list); /* Test enumerator robustness */ /* enumerator on an empty list */ list = LinkedList_New(); LinkedList_Enumerator_Reset(list); while (LinkedList_Enumerator_MoveNext(list)) { number = (int) (size_t) LinkedList_Enumerator_Current(list); printf("\t%d\n", number); } printf("\n"); LinkedList_Free(list); /* Use an enumerator without reset */ list = LinkedList_New(); LinkedList_AddFirst(list, (void*) (size_t) 4); LinkedList_AddLast(list, (void*) (size_t) 5); LinkedList_AddLast(list, (void*) (size_t) 6); while (LinkedList_Enumerator_MoveNext(list)) { number = (int) (size_t) LinkedList_Enumerator_Current(list); printf("\t%d\n", number); } printf("\n"); LinkedList_Free(list); return 0; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { SMARTCARD_DEVICE* smartcard = NULL; size_t length; UINT error = CHANNEL_RC_NO_MEMORY; if (!sSmartcard) { wObject* obj; 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->names = LinkedList_New(); smartcard->rdpcontext = pEntryPoints->rdpcontext; length = strlen(smartcard->device.name); smartcard->device.data = Stream_New(NULL, length + 1); if (!smartcard->device.data || !smartcard->names) { WLog_ERR(TAG, "Stream_New failed!"); goto fail; } Stream_Write(smartcard->device.data, "SCARD", 6); smartcard->IrpQueue = MessageQueue_New(NULL); if (!smartcard->IrpQueue) { WLog_ERR(TAG, "MessageQueue_New failed!"); goto fail; } smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1); if (!smartcard->CompletedIrpQueue) { WLog_ERR(TAG, "Queue_New failed!"); goto fail; } smartcard->rgSCardContextList = ListDictionary_New(TRUE); if (!smartcard->rgSCardContextList) { WLog_ERR(TAG, "ListDictionary_New failed!"); goto fail; } obj = ListDictionary_ValueObject(smartcard->rgSCardContextList); obj->fnObjectFree = smartcard_context_free; smartcard->rgOutstandingMessages = ListDictionary_New(TRUE); if (!smartcard->rgOutstandingMessages) { WLog_ERR(TAG, "ListDictionary_New failed!"); goto fail; } if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, &smartcard->device))) { WLog_ERR(TAG, "RegisterDevice failed!"); goto fail; } smartcard->thread = CreateThread(NULL, 0, smartcard_thread_func, smartcard, CREATE_SUSPENDED, NULL); if (!smartcard->thread) { WLog_ERR(TAG, "ListDictionary_New failed!"); error = ERROR_INTERNAL_ERROR; goto fail; } ResumeThread(smartcard->thread); } else smartcard = sSmartcard; if (pEntryPoints->device->Name) LinkedList_AddLast(smartcard->names, pEntryPoints->device->Name); sSmartcard = smartcard; return CHANNEL_RC_OK; fail: smartcard_free_(smartcard); return error; }