int cliprdr_client_format_list(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST* formatList) { wStream* s; UINT32 index; int length = 0; int formatNameSize; CLIPRDR_FORMAT* format; cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle; for (index = 0; index < formatList->numFormats; index++) { format = (CLIPRDR_FORMAT*) &(formatList->formats[index]); length += 4; formatNameSize = 2; if (format->formatName) formatNameSize = MultiByteToWideChar(CP_UTF8, 0, format->formatName, -1, NULL, 0) * 2; length += formatNameSize; } s = cliprdr_packet_new(CB_FORMAT_LIST, 0, length); for (index = 0; index < formatList->numFormats; index++) { format = (CLIPRDR_FORMAT*) &(formatList->formats[index]); Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */ if (format->formatName) { int cchWideChar; LPWSTR lpWideCharStr; lpWideCharStr = (LPWSTR) Stream_Pointer(s); cchWideChar = (Stream_Capacity(s) - Stream_GetPosition(s)) / 2; formatNameSize = MultiByteToWideChar(CP_UTF8, 0, format->formatName, -1, lpWideCharStr, cchWideChar) * 2; Stream_Seek(s, formatNameSize); } else { Stream_Write_UINT16(s, 0); } } WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatList: numFormats: %d", formatList->numFormats); cliprdr_packet_send(cliprdr, s); return 0; }
static int remdesk_send_ctl_version_info_pdu(remdeskPlugin* remdesk) { wStream* s; REMDESK_CTL_VERSION_INFO_PDU pdu; remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_VERSIONINFO, 8); pdu.versionMajor = 1; pdu.versionMinor = 2; s = Stream_New(NULL, REMDESK_CHANNEL_CTL_SIZE + pdu.ctlHeader.DataLength); remdesk_write_ctl_header(s, &(pdu.ctlHeader)); Stream_Write_UINT32(s, pdu.versionMajor); /* versionMajor (4 bytes) */ Stream_Write_UINT32(s, pdu.versionMinor); /* versionMinor (4 bytes) */ Stream_SealLength(s); remdesk_virtual_channel_write(remdesk, s); return 1; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT remdesk_write_ctl_header(wStream* s, REMDESK_CTL_HEADER* ctlHeader) { UINT error; if ((error = remdesk_write_channel_header(s, (REMDESK_CHANNEL_HEADER*) ctlHeader))) { WLog_ERR(TAG, "remdesk_write_channel_header failed with error %"PRIu32"!", error); return error; } Stream_Write_UINT32(s, ctlHeader->msgType); /* msgType (4 bytes) */ return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpdr_send_device_list_remove_request(rdpdrPlugin* rdpdr, UINT32 count, UINT32 ids[]) { UINT32 i; wStream* s; s = Stream_New(NULL, count * sizeof(UINT32) + 8); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, RDPDR_CTYP_CORE); Stream_Write_UINT16(s, PAKID_CORE_DEVICELIST_REMOVE); Stream_Write_UINT32(s, count); for (i = 0; i < count; i++) Stream_Write_UINT32(s, ids[i]); Stream_SealLength(s); return rdpdr_send(rdpdr, s); }
void guac_rdpdr_fs_process_query_full_size_info(guac_rdpdr_device* device, wStream* input_stream, int file_id, int completion_id) { guac_rdp_fs_info info = {0}; guac_rdp_fs_get_info((guac_rdp_fs*) device->data, &info); wStream* output_stream = guac_rdpdr_new_io_completion(device, completion_id, STATUS_SUCCESS, 36); guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG, "%s: [file_id=%i]", __func__, file_id); Stream_Write_UINT32(output_stream, 32); Stream_Write_UINT64(output_stream, info.blocks_total); /* TotalAllocationUnits */ Stream_Write_UINT64(output_stream, info.blocks_available); /* CallerAvailableAllocationUnits */ Stream_Write_UINT64(output_stream, info.blocks_available); /* ActualAvailableAllocationUnits */ Stream_Write_UINT32(output_stream, 1); /* SectorsPerAllocationUnit */ Stream_Write_UINT32(output_stream, info.block_size); /* BytesPerSector */ svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream); }
int WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message) { FILE* fp; wStream* s; int MessageLength; int FileNameLength; int FunctionNameLength; int TextStringLength; if (message->Level > log->Level) return 0; fp = appender->FileDescriptor; if (!fp) return -1; FileNameLength = strlen(message->FileName); FunctionNameLength = strlen(message->FunctionName); TextStringLength = strlen(message->TextString); MessageLength = 16 + (4 + FileNameLength + 1) + (4 + FunctionNameLength + 1) + (4 + TextStringLength + 1); s = Stream_New(NULL, MessageLength); Stream_Write_UINT32(s, MessageLength); Stream_Write_UINT32(s, message->Type); Stream_Write_UINT32(s, message->Level); Stream_Write_UINT32(s, message->LineNumber); Stream_Write_UINT32(s, FileNameLength); Stream_Write(s, message->FileName, FileNameLength + 1); Stream_Write_UINT32(s, FunctionNameLength); Stream_Write(s, message->FunctionName, FunctionNameLength + 1); Stream_Write_UINT32(s, TextStringLength); Stream_Write(s, message->TextString, TextStringLength + 1); Stream_SealLength(s); fwrite(Stream_Buffer(s), MessageLength, 1, fp); Stream_Free(s, TRUE); return 1; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_frame_acknowledge_pdu(RDPGFX_CHANNEL_CALLBACK* callback, RDPGFX_FRAME_ACKNOWLEDGE_PDU* pdu) { UINT error; wStream* s; RDPGFX_HEADER header; header.flags = 0; header.cmdId = RDPGFX_CMDID_FRAMEACKNOWLEDGE; header.pduLength = RDPGFX_HEADER_SIZE + 12; WLog_DBG(TAG, "SendFrameAcknowledgePdu: %d", pdu->frameId); s = Stream_New(NULL, header.pduLength); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); return CHANNEL_RC_NO_MEMORY; } if ((error = rdpgfx_write_header(s, &header))) { WLog_ERR(TAG, "rdpgfx_write_header failed with error %lu!", error); return error; } /* RDPGFX_FRAME_ACKNOWLEDGE_PDU */ Stream_Write_UINT32(s, pdu->queueDepth); /* queueDepth (4 bytes) */ Stream_Write_UINT32(s, pdu->frameId); /* frameId (4 bytes) */ Stream_Write_UINT32(s, pdu->totalFramesDecoded); /* totalFramesDecoded (4 bytes) */ error = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s), Stream_Buffer(s), NULL); Stream_Free(s, TRUE); return error; }
static void audin_server_send_formats(audin_server* audin, wStream* s) { int i; UINT32 nAvgBytesPerSec; ULONG written; Stream_SetPosition(s, 0); Stream_Write_UINT8(s, MSG_SNDIN_FORMATS); Stream_Write_UINT32(s, audin->context.num_server_formats); /* NumFormats (4 bytes) */ Stream_Write_UINT32(s, 0); /* cbSizeFormatsPacket (4 bytes), client-to-server only */ for (i = 0; i < audin->context.num_server_formats; i++) { nAvgBytesPerSec = audin->context.server_formats[i].nSamplesPerSec * audin->context.server_formats[i].nChannels * audin->context.server_formats[i].wBitsPerSample / 8; Stream_EnsureRemainingCapacity(s, 18); Stream_Write_UINT16(s, audin->context.server_formats[i].wFormatTag); Stream_Write_UINT16(s, audin->context.server_formats[i].nChannels); Stream_Write_UINT32(s, audin->context.server_formats[i].nSamplesPerSec); Stream_Write_UINT32(s, nAvgBytesPerSec); Stream_Write_UINT16(s, audin->context.server_formats[i].nBlockAlign); Stream_Write_UINT16(s, audin->context.server_formats[i].wBitsPerSample); Stream_Write_UINT16(s, audin->context.server_formats[i].cbSize); if (audin->context.server_formats[i].cbSize) { Stream_EnsureRemainingCapacity(s, audin->context.server_formats[i].cbSize); Stream_Write(s, audin->context.server_formats[i].data, audin->context.server_formats[i].cbSize); } } WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written); }
static void xf_cliprdr_process_dib(clipboardContext* cb, BYTE* data, int size) { wStream* s; UINT16 bpp; UINT32 offset; UINT32 ncolors; /* size should be at least sizeof(BITMAPINFOHEADER) */ if (size < 40) { DEBUG_X11_CLIPRDR("dib size %d too short", size); return; } s = Stream_New(data, size); Stream_Seek(s, 14); Stream_Read_UINT16(s, bpp); Stream_Read_UINT32(s, ncolors); offset = 14 + 40 + (bpp <= 8 ? (ncolors == 0 ? (1 << bpp) : ncolors) * 4 : 0); Stream_Free(s, FALSE); DEBUG_X11_CLIPRDR("offset=%d bpp=%d ncolors=%d", offset, bpp, ncolors); s = Stream_New(NULL, 14 + size); Stream_Write_UINT8(s, 'B'); Stream_Write_UINT8(s, 'M'); Stream_Write_UINT32(s, 14 + size); Stream_Write_UINT32(s, 0); Stream_Write_UINT32(s, offset); Stream_Write(s, data, size); cb->data = Stream_Buffer(s); cb->data_length = Stream_GetPosition(s); Stream_Free(s, FALSE); }
static UINT video_control_send_presentation_response(VideoClientContext *context, TSMM_PRESENTATION_RESPONSE *resp) { BYTE buf[12]; wStream *s; VIDEO_PLUGIN* video = (VIDEO_PLUGIN *)context->handle; IWTSVirtualChannel* channel; UINT ret; s = Stream_New(buf, 12); if (!s) return CHANNEL_RC_NO_MEMORY; Stream_Write_UINT32(s, 12); /* cbSize */ Stream_Write_UINT32(s, TSMM_PACKET_TYPE_PRESENTATION_RESPONSE); /* PacketType */ Stream_Write_UINT8(s, resp->PresentationId); Stream_Zero(s, 3); Stream_SealLength(s); channel = video->control_callback->channel_callback->channel; ret = channel->Write(channel, 12, buf, NULL); Stream_Free(s, FALSE); return ret; }
void cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* s) { int pos; UINT32 dataLen; pos = Stream_GetPosition(s); dataLen = pos - 8; Stream_SetPosition(s, 4); Stream_Write_UINT32(s, dataLen); Stream_SetPosition(s, pos); #ifdef WITH_DEBUG_CLIPRDR WLog_DBG(TAG, "Cliprdr Sending (%d bytes)", dataLen + 8); winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), dataLen + 8); #endif svc_plugin_send((rdpSvcPlugin*) cliprdr, s); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT audin_server_send_version(audin_server* audin, wStream* s) { ULONG written; Stream_Write_UINT8(s, MSG_SNDIN_VERSION); Stream_Write_UINT32(s, 1); /* Version (4 bytes) */ if (!WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); return ERROR_INTERNAL_ERROR; } return CHANNEL_RC_OK; }
void rdp_write_share_data_header(wStream* s, UINT16 length, BYTE type, UINT32 share_id) { length -= RDP_PACKET_HEADER_MAX_LENGTH; length -= RDP_SHARE_CONTROL_HEADER_LENGTH; length -= RDP_SHARE_DATA_HEADER_LENGTH; /* Share Data Header */ Stream_Write_UINT32(s, share_id); /* shareId (4 bytes) */ Stream_Write_UINT8(s, 0); /* pad1 (1 byte) */ Stream_Write_UINT8(s, STREAM_LOW); /* streamId (1 byte) */ Stream_Write_UINT16(s, length); /* uncompressedLength (2 bytes) */ Stream_Write_UINT8(s, type); /* pduType2, Data PDU Type (1 byte) */ Stream_Write_UINT8(s, 0); /* compressedType (1 byte) */ Stream_Write_UINT16(s, 0); /* compressedLength (2 bytes) */ }
BOOL rdp_send_deactivate_all(rdpRdp* rdp) { wStream* s = rdp_send_stream_pdu_init(rdp); BOOL status; if (!s) return FALSE; Stream_Write_UINT32(s, rdp->settings->ShareId); /* shareId (4 bytes) */ Stream_Write_UINT16(s, 1); /* lengthSourceDescriptor (2 bytes) */ Stream_Write_UINT8(s, 0); /* sourceDescriptor (should be 0x00) */ status = rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->userId); Stream_Release(s); return status; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) { UINT32 Length; UINT64 Offset; ssize_t status; BYTE* buffer = NULL; Stream_Read_UINT32(irp->input, Length); Stream_Read_UINT64(irp->input, Offset); buffer = (BYTE*) malloc(Length); if (!buffer) { WLog_ERR(TAG, "malloc failed!"); return CHANNEL_RC_NO_MEMORY; } status = read(parallel->file, buffer, Length); if (status < 0) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; } else { } Stream_Write_UINT32(irp->output, Length); if (Length > 0) { if (!Stream_EnsureRemainingCapacity(irp->output, Length)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); free(buffer); return CHANNEL_RC_NO_MEMORY; } Stream_Write(irp->output, buffer, Length); } free(buffer); return irp->Complete(irp); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT rdpei_send_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s, UINT16 eventId, UINT32 pduLength) { UINT status; Stream_SetPosition(s, 0); Stream_Write_UINT16(s, eventId); /* eventId (2 bytes) */ Stream_Write_UINT32(s, pduLength); /* pduLength (4 bytes) */ Stream_SetPosition(s, Stream_Length(s)); status = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s), Stream_Buffer(s), NULL); #ifdef WITH_DEBUG_RDPEI WLog_DBG(TAG, "rdpei_send_pdu: eventId: %d (%s) length: %d status: %d", eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength, status); #endif return status; }
int cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) { wStream* s; cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle; s = cliprdr_packet_new(CB_UNLOCK_CLIPDATA, 0, 4); Stream_Write_UINT32(s, unlockClipboardData->clipDataId); /* clipDataId (4 bytes) */ WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientUnlockClipboardData: clipDataId: 0x%04X", unlockClipboardData->clipDataId); cliprdr_packet_send(cliprdr, s); return 1; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT cliprdr_server_packet_send(CliprdrServerPrivate* cliprdr, wStream* s) { UINT32 pos; BOOL status; UINT32 dataLen; UINT32 written; pos = Stream_GetPosition(s); dataLen = pos - 8; Stream_SetPosition(s, 4); Stream_Write_UINT32(s, dataLen); Stream_SetPosition(s, pos); status = WTSVirtualChannelWrite(cliprdr->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written); Stream_Free(s, TRUE); return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; }
void guac_rdpdr_process_print_job_create(guac_rdpdr_device* device, wStream* input_stream, int completion_id) { guac_rdpdr_printer_data* printer_data = (guac_rdpdr_printer_data*) device->data; wStream* output_stream = guac_rdpdr_new_io_completion(device, completion_id, STATUS_SUCCESS, 4); /* No bytes received yet */ printer_data->bytes_received = 0; Stream_Write_UINT32(output_stream, 0); /* fileId */ svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream); }
void guac_rdpdr_fs_process_device_control(guac_rdpdr_device* device, wStream* input_stream, int file_id, int completion_id) { wStream* output_stream = guac_rdpdr_new_io_completion(device, completion_id, STATUS_INVALID_PARAMETER, 4); guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG, "%s: [file_id=%i] IGNORED", __func__, file_id); /* No content for now */ Stream_Write_UINT32(output_stream, 0); svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream); }
static void irp_complete(IRP* irp) { int pos; rdpdrPlugin* rdpdr; rdpdr = (rdpdrPlugin*) irp->devman->plugin; pos = (int) Stream_GetPosition(irp->output); Stream_SetPosition(irp->output, RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4); Stream_Write_UINT32(irp->output, irp->IoStatus); /* IoStatus (4 bytes) */ Stream_SetPosition(irp->output, pos); rdpdr_send(rdpdr, irp->output); irp->output = NULL; irp_free(irp); }
void update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* cmd) { Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH); Stream_Write_UINT16(s, CMDTYPE_STREAM_SURFACE_BITS); Stream_Write_UINT16(s, cmd->destLeft); Stream_Write_UINT16(s, cmd->destTop); Stream_Write_UINT16(s, cmd->destRight); Stream_Write_UINT16(s, cmd->destBottom); Stream_Write_UINT8(s, cmd->bpp); Stream_Write_UINT16(s, 0); /* reserved1, reserved2 */ Stream_Write_UINT8(s, cmd->codecID); Stream_Write_UINT16(s, cmd->width); Stream_Write_UINT16(s, cmd->height); Stream_Write_UINT32(s, cmd->bitmapDataLength); }
int cliprdr_client_format_data_request(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) { wStream* s; cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle; formatDataRequest->msgType = CB_FORMAT_DATA_REQUEST; formatDataRequest->msgFlags = 0; formatDataRequest->dataLen = 4; s = cliprdr_packet_new(formatDataRequest->msgType, formatDataRequest->msgFlags, formatDataRequest->dataLen); Stream_Write_UINT32(s, formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */ WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataRequest"); cliprdr_packet_send(cliprdr, s); return 0; }
BOOL rdg_send_tunnel_authorization(rdpRdg* rdg) { int i; wStream* s; BOOL status; WCHAR* clientName = NULL; UINT16 clientNameLen; UINT32 packetSize; clientNameLen = ConvertToUnicode(CP_UTF8, 0, rdg->settings->ClientHostname, -1, &clientName, 0); if (!clientName) return FALSE; packetSize = 12 + clientNameLen * sizeof(WCHAR); s = Stream_New(NULL, packetSize); if (!s) { free(clientName); return FALSE; } Stream_Write_UINT16(s, PKT_TYPE_TUNNEL_AUTH); /* Type (2 bytes) */ Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ Stream_Write_UINT32(s, packetSize); /* PacketLength (4 bytes) */ Stream_Write_UINT16(s, 0); /* FieldsPresent (2 bytes) */ Stream_Write_UINT16(s, clientNameLen * 2); /* Client name string length */ for (i = 0; i < clientNameLen; i++) Stream_Write_UINT16(s, clientName[i]); Stream_SealLength(s); status = rdg_write_packet(rdg, s); Stream_Free(s, TRUE); free(clientName); if (status) { rdg->state = RDG_CLIENT_STATE_TUNNEL_AUTHORIZE; } return status; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_delete_encoding_context_pdu(RdpgfxServerContext* context, RDPGFX_DELETE_ENCODING_CONTEXT_PDU* pdu) { wStream* s = rdpgfx_server_single_packet_new( RDPGFX_CMDID_DELETEENCODINGCONTEXT, 6); if (!s) { WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ Stream_Write_UINT32(s, pdu->codecContextId); /* codecContextId (4 bytes) */ return rdpgfx_server_single_packet_send(context, s); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_reset_graphics_pdu(RdpgfxServerContext* context, RDPGFX_RESET_GRAPHICS_PDU* pdu) { UINT32 index; MONITOR_DEF* monitor; wStream* s; /* Check monitorCount. This ensures total size within 340 bytes) */ if (pdu->monitorCount >= 16) { WLog_ERR(TAG, "Monitor count MUST be less than or equal to 16: %lu", (unsigned long) pdu->monitorCount); return ERROR_INVALID_DATA; } s = rdpgfx_server_single_packet_new( RDPGFX_CMDID_RESETGRAPHICS, RDPGFX_RESET_GRAPHICS_PDU_SIZE - RDPGFX_HEADER_SIZE); if (!s) { WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT32(s, pdu->width); /* width (4 bytes) */ Stream_Write_UINT32(s, pdu->height); /* height (4 bytes) */ Stream_Write_UINT32(s, pdu->monitorCount); /* monitorCount (4 bytes) */ for (index = 0; index < pdu->monitorCount; index++) { monitor = &(pdu->monitorDefArray[index]); Stream_Write_UINT32(s, monitor->left); /* left (4 bytes) */ Stream_Write_UINT32(s, monitor->top); /* top (4 bytes) */ Stream_Write_UINT32(s, monitor->right); /* right (4 bytes) */ Stream_Write_UINT32(s, monitor->bottom); /* bottom (4 bytes) */ Stream_Write_UINT32(s, monitor->flags); /* flags (4 bytes) */ } /* pad (total size must be 340 bytes) */ Stream_SetPosition(s, RDPGFX_RESET_GRAPHICS_PDU_SIZE); return rdpgfx_server_single_packet_send(context, s); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT parallel_process_irp_create(PARALLEL_DEVICE* parallel, IRP* irp) { char* path = NULL; int status; UINT32 PathLength; Stream_Seek(irp->input, 28); /* DesiredAccess(4) AllocationSize(8), FileAttributes(4) */ /* SharedAccess(4) CreateDisposition(4), CreateOptions(4) */ Stream_Read_UINT32(irp->input, PathLength); status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(irp->input), PathLength / 2, &path, 0, NULL, NULL); if (status < 1) if (!(path = (char*) calloc(1, 1))) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } parallel->id = irp->devman->id_sequence++; parallel->file = open(parallel->path, O_RDWR); if (parallel->file < 0) { irp->IoStatus = STATUS_ACCESS_DENIED; parallel->id = 0; } else { /* all read and write operations should be non-blocking */ if (fcntl(parallel->file, F_SETFL, O_NONBLOCK) == -1) { } } Stream_Write_UINT32(irp->output, parallel->id); Stream_Write_UINT8(irp->output, 0); free(path); return irp->Complete(irp); }
static void cliprdr_process_filecontents_response_event(cliprdrPlugin* plugin, RDP_CB_FILECONTENTS_RESPONSE_EVENT* event) { wStream* s; DEBUG_CLIPRDR("Sending file contents response with size = %d", event->size); if (event->size > 0) { s = cliprdr_packet_new(CB_FILECONTENTS_RESPONSE, CB_RESPONSE_OK, event->size + 4); Stream_Write_UINT32(s, event->streamId); Stream_Write(s, event->data, event->size); } else { s = cliprdr_packet_new(CB_FILECONTENTS_RESPONSE, CB_RESPONSE_FAIL, 0); } cliprdr_packet_send(plugin, s); }
BOOL rdp_send_deactivate_all(rdpRdp* rdp) { wStream* s; BOOL status; s = Stream_New(NULL, 1024); rdp_init_stream_pdu(rdp, s); Stream_Write_UINT32(s, rdp->settings->ShareId); /* shareId (4 bytes) */ Stream_Write_UINT16(s, 1); /* lengthSourceDescriptor (2 bytes) */ Stream_Write_UINT8(s, 0); /* sourceDescriptor (should be 0x00) */ status = rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->userId); Stream_Free(s, TRUE); return status; }
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)); }