/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT printer_free(DEVICE* device) { IRP* irp; PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) device; UINT error; SetEvent(printer_dev->stopEvent); if (WaitForSingleObject(printer_dev->thread, INFINITE) == WAIT_FAILED) { error = GetLastError(); WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error); return error; } while ((irp = (IRP*) InterlockedPopEntrySList(printer_dev->pIrpList)) != NULL) irp->Discard(irp); CloseHandle(printer_dev->thread); CloseHandle(printer_dev->stopEvent); CloseHandle(printer_dev->event); _aligned_free(printer_dev->pIrpList); if (printer_dev->printer) printer_dev->printer->Free(printer_dev->printer); free(printer_dev->device.name); Stream_Free(printer_dev->device.data, TRUE); free(printer_dev); return CHANNEL_RC_OK; }
static void smartcard_free(DEVICE* dev) { IRP* irp; COMPLETIONIDINFO* CompletionIdInfo; SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) dev; SetEvent(smartcard->stopEvent); WaitForSingleObject(smartcard->thread, INFINITE); while ((irp = (IRP*) InterlockedPopEntrySList(smartcard->pIrpList)) != NULL) irp->Discard(irp); _aligned_free(smartcard->pIrpList); /* Begin TS Client defect workaround. */ while ((CompletionIdInfo = (COMPLETIONIDINFO*) list_dequeue(smartcard->CompletionIds)) != NULL) free(CompletionIdInfo); CloseHandle(smartcard->thread); CloseHandle(smartcard->irpEvent); CloseHandle(smartcard->stopEvent); CloseHandle(smartcard->CompletionIdsMutex); Stream_Free(smartcard->device.data, TRUE); list_free(smartcard->CompletionIds); /* End TS Client defect workaround. */ free(dev); }
static void __serial_check_fds(SERIAL_DEVICE* serial) { IRP* irp; IRP* prev; SERIAL_TTY* tty; uint32 result = 0; memset(&serial->tv, 0, sizeof(struct timeval)); tty = serial->tty; /* scan every pending */ irp = list_peek(serial->pending_irps); while (irp) { DEBUG_SVC("MajorFunction %u", irp->MajorFunction); switch (irp->MajorFunction) { case IRP_MJ_READ: if (FD_ISSET(tty->fd, &serial->read_fds)) { irp->IoStatus = STATUS_SUCCESS; serial_process_irp_read(serial, irp); } break; case IRP_MJ_WRITE: if (FD_ISSET(tty->fd, &serial->write_fds)) { irp->IoStatus = STATUS_SUCCESS; serial_process_irp_write(serial, irp); } break; case IRP_MJ_DEVICE_CONTROL: if (serial_tty_get_event(tty, &result)) { DEBUG_SVC("got event result %u", result); irp->IoStatus = STATUS_SUCCESS; stream_write_uint32(irp->output, result); irp->Complete(irp); } break; default: DEBUG_SVC("no request found"); break; } prev = irp; irp = (IRP*)list_next(serial->pending_irps, irp); if (prev->IoStatus == STATUS_SUCCESS) { list_remove(serial->pending_irps, prev); wait_obj_set(serial->in_event); } } }
static void serial_abort_single_io(SERIAL_DEVICE* serial, UINT32 file_id, UINT32 abort_io, UINT32 io_status) { UINT32 major; IRP* irp = NULL; SERIAL_TTY* tty; DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps)); tty = serial->tty; if(!tty) { DEBUG_WARN("tty = %p", tty); return; } switch (abort_io) { case SERIAL_ABORT_IO_NONE: major = 0; break; case SERIAL_ABORT_IO_READ: major = IRP_MJ_READ; break; case SERIAL_ABORT_IO_WRITE: major = IRP_MJ_WRITE; break; default: DEBUG_SVC("unexpected abort_io code %d", abort_io); return; } irp = (IRP*) list_peek(serial->pending_irps); while (irp) { if (irp->FileId != file_id || irp->MajorFunction != major) { irp = (IRP*) list_next(serial->pending_irps, irp); continue; } /* Process a SINGLE FileId and MajorFunction */ list_remove(serial->pending_irps, irp); irp->IoStatus = io_status; Stream_Write_UINT32(irp->output, 0); irp->Complete(irp); break; } DEBUG_SVC("[out] pending size %d", list_size(serial->pending_irps)); }
static void parallel_free(DEVICE* device) { IRP* irp; PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device; DEBUG_SVC("freeing device"); freerdp_thread_stop(parallel->thread); freerdp_thread_free(parallel->thread); while ((irp = (IRP*) InterlockedPopEntrySList(parallel->pIrpList)) != NULL) irp->Discard(irp); _aligned_free(parallel->pIrpList); free(parallel); }
static void parallel_free(DEVICE* device) { IRP* irp; PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device; DEBUG_SVC("freeing device"); freerdp_thread_stop(parallel->thread); freerdp_thread_free(parallel->thread); while ((irp = (IRP*) list_dequeue(parallel->irp_list)) != NULL) irp->Discard(irp); list_free(parallel->irp_list); xfree(parallel); }
static void printer_free(DEVICE* device) { PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) device; IRP* irp; freerdp_thread_stop(printer_dev->thread); freerdp_thread_free(printer_dev->thread); while ((irp = (IRP*) list_dequeue(printer_dev->irp_list)) != NULL) irp->Discard(irp); list_free(printer_dev->irp_list); if (printer_dev->printer) printer_dev->printer->Free(printer_dev->printer); xfree(printer_dev->device.name); xfree(printer_dev); }
static void serial_check_for_events(SERIAL_DEVICE* serial) { IRP* irp = NULL; IRP* prev; UINT32 result = 0; SERIAL_TTY* tty; tty = serial->tty; if(!tty) { DEBUG_WARN("tty = %p", tty); return; } DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps)); irp = (IRP*) list_peek(serial->pending_irps); while (irp) { prev = NULL; if (irp->MajorFunction == IRP_MJ_DEVICE_CONTROL) { if (serial_tty_get_event(tty, &result)) { DEBUG_SVC("got event result %u", result); irp->IoStatus = STATUS_SUCCESS; Stream_Write_UINT32(irp->output, result); irp->Complete(irp); prev = irp; irp = (IRP*) list_next(serial->pending_irps, irp); list_remove(serial->pending_irps, prev); } } if (!prev) irp = (IRP*) list_next(serial->pending_irps, irp); } DEBUG_SVC("[out] pending size %d", list_size(serial->pending_irps)); }
static void printer_free(DEVICE* device) { IRP* irp; PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) device; freerdp_thread_stop(printer_dev->thread); freerdp_thread_free(printer_dev->thread); while ((irp = (IRP*) InterlockedPopEntrySList(printer_dev->pIrpList)) != NULL) irp->Discard(irp); _aligned_free(printer_dev->pIrpList); if (printer_dev->printer) printer_dev->printer->Free(printer_dev->printer); free(printer_dev->device.name); free(printer_dev); }
static void serial_free(DEVICE* device) { SERIAL_DEVICE* serial = (SERIAL_DEVICE*)device; IRP* irp; DEBUG_SVC("freeing device"); freerdp_thread_stop(serial->thread); freerdp_thread_free(serial->thread); while ((irp = (IRP*)list_dequeue(serial->irp_list)) != NULL) irp->Discard(irp); list_free(serial->irp_list); while ((irp = (IRP*)list_dequeue(serial->pending_irps)) != NULL) irp->Discard(irp); list_free(serial->pending_irps); xfree(serial); }
static void drive_free(DEVICE* device) { IRP* irp; DRIVE_FILE* file; DRIVE_DEVICE* disk = (DRIVE_DEVICE*) device; SetEvent(disk->stopEvent); CloseHandle(disk->thread); CloseHandle(disk->irpEvent); while ((irp = (IRP*) InterlockedPopEntrySList(disk->pIrpList)) != NULL) irp->Discard(irp); _aligned_free(disk->pIrpList); while ((file = (DRIVE_FILE*) list_dequeue(disk->files)) != NULL) drive_file_free(file); list_free(disk->files); free(disk); }
static void scard_free(DEVICE* dev) { SCARD_DEVICE* scard = (SCARD_DEVICE*)dev; IRP* irp; COMPLETIONIDINFO* CompletionIdInfo; freerdp_thread_stop(scard->thread); freerdp_thread_free(scard->thread); while ((irp = (IRP*)list_dequeue(scard->irp_list)) != NULL) irp->Discard(irp); list_free(scard->irp_list); /* Begin TS Client defect workaround. */ while ((CompletionIdInfo = (COMPLETIONIDINFO*)list_dequeue(scard->CompletionIds)) != NULL) xfree(CompletionIdInfo); list_free(scard->CompletionIds); /* End TS Client defect workaround. */ xfree(dev); return; }
static void __serial_check_fds(SERIAL_DEVICE* serial) { IRP* irp; IRP* prev; SERIAL_TTY* tty; UINT32 result = 0; BOOL irp_completed = FALSE; ZeroMemory(&serial->tv, sizeof(struct timeval)); tty = serial->tty; if(!tty) { DEBUG_WARN("tty = %p", tty); return; } /* scan every pending */ irp = list_peek(serial->pending_irps); while (irp) { DEBUG_SVC("MajorFunction %u", irp->MajorFunction); switch (irp->MajorFunction) { case IRP_MJ_READ: if (FD_ISSET(tty->fd, &serial->read_fds)) { irp->IoStatus = STATUS_SUCCESS; serial_process_irp_read(serial, irp); irp_completed = TRUE; } break; case IRP_MJ_WRITE: if (FD_ISSET(tty->fd, &serial->write_fds)) { irp->IoStatus = STATUS_SUCCESS; serial_process_irp_write(serial, irp); irp_completed = TRUE; } break; case IRP_MJ_DEVICE_CONTROL: if (serial_tty_get_event(tty, &result)) { DEBUG_SVC("got event result %u", result); irp->IoStatus = STATUS_SUCCESS; Stream_Write_UINT32(irp->output, result); irp->Complete(irp); irp_completed = TRUE; } break; default: DEBUG_SVC("no request found"); break; } prev = irp; irp = (IRP*) list_next(serial->pending_irps, irp); if (irp_completed || (prev->IoStatus == STATUS_SUCCESS)) list_remove(serial->pending_irps, prev); } }
int main(int argc, char** argv) { if (argc<2) { usage: printf("Usage MakeHex IrpFile {OutFile}\n"); return -1; } IRP Irp; char* arg1=*(++argv); if (arg1[0]=='-' && arg1[2]==0) { char s = toupper(arg1[1]); if (s=='H') Irp.m_numberFormat = 1; else if (s=='B') Irp.m_numberFormat = 2; else goto usage; arg1 = *(++argv); if (--argc == 1) goto usage; } if (argc>3) goto usage; FILE *InFile = fopen(arg1, "r"); if (!InFile) { printf("Unable to open \"%s\"\n", arg1); return -1; } if (! Irp.readIrpFile(InFile) ) { printf("IRP file \"%s\" not processed\n"); return -1; } char *OutName; if (argc==3) { OutName = argv[1]; } else { char *tmp = strrchr(arg1, '.'); if (!tmp) { tmp = arg1 + strlen(arg1); } int len = tmp - arg1; OutName = new char [len+5]; memcpy(OutName, arg1, len); strcpy(OutName+len, ".hex"); } FILE *OutFile = fopen(OutName, "w"); if (!OutFile) { printf("Unable to create \"%s\"\n", OutName); return -1; } Irp.writeHex(OutFile); fclose(OutFile); return 0; }