/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT read_touch_frame(RdpeiServerContext *context, wStream *s, RDPINPUT_TOUCH_FRAME *frame) { int i; RDPINPUT_CONTACT_DATA *contact; UINT error; if (!rdpei_read_2byte_unsigned(s, &frame->contactCount) || !rdpei_read_8byte_unsigned(s, &frame->frameOffset)) { WLog_ERR(TAG, "rdpei_read_ failed!"); return ERROR_INTERNAL_ERROR; } frame->contacts = contact = calloc(frame->contactCount, sizeof(RDPINPUT_CONTACT_DATA)); if (!frame->contacts) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } for (i = 0; i < frame->contactCount; i++, contact++) { if ((error = read_touch_contact_data(context, s, contact))) { WLog_ERR(TAG, "read_touch_contact_data failed with error %lu!", error); frame->contactCount = i; touch_frame_reset(frame); return error; } } return CHANNEL_RC_OK; }
static int read_touch_event(RdpeiServerContext *context, wStream *s) { UINT32 frameCount; int i, ret; RDPINPUT_TOUCH_EVENT *event = &context->priv->touchEvent; RDPINPUT_TOUCH_FRAME *frame; ret = -1; if (!rdpei_read_4byte_unsigned(s, &event->encodeTime) || !rdpei_read_2byte_unsigned(s, &frameCount)) return -1; event->frameCount = frameCount; event->frames = frame = calloc(event->frameCount, sizeof(RDPINPUT_TOUCH_FRAME)); if (!event->frames) return -1; for (i = 0; i < frameCount; i++, frame++) { if (read_touch_frame(context, s, frame) < 0) { event->frameCount = i; goto out_cleanup; } } if (context->onTouchEvent) context->onTouchEvent(context, event); ret = 0; out_cleanup: touch_event_reset(event); return ret; }
static int read_touch_frame(RdpeiServerContext *context, wStream *s, RDPINPUT_TOUCH_FRAME *frame) { int i; RDPINPUT_CONTACT_DATA *contact; if (!rdpei_read_2byte_unsigned(s, &frame->contactCount) || !rdpei_read_8byte_unsigned(s, &frame->frameOffset)) return -1; frame->contacts = contact = calloc(frame->contactCount, sizeof(RDPINPUT_CONTACT_DATA)); if (!frame->contacts) return -1; for (i = 0; i < frame->contactCount; i++, contact++) { if (read_touch_contact_data(context, s, contact) < 0) { frame->contactCount = i; goto out_cleanup; } } return 0; out_cleanup: touch_frame_reset(frame); return -1; }
static int read_touch_contact_data(RdpeiServerContext *context, wStream *s, RDPINPUT_CONTACT_DATA *contactData) { if (Stream_GetRemainingLength(s) < 1) return -1; Stream_Read_UINT8(s, contactData->contactId); if (!rdpei_read_2byte_unsigned(s, &contactData->fieldsPresent) || !rdpei_read_4byte_signed(s, &contactData->x) || !rdpei_read_4byte_signed(s, &contactData->y) || !rdpei_read_4byte_unsigned(s, &contactData->contactFlags)) return -1; if (contactData->fieldsPresent & CONTACT_DATA_CONTACTRECT_PRESENT) { if (!rdpei_read_2byte_signed(s, &contactData->contactRectLeft) || !rdpei_read_2byte_signed(s, &contactData->contactRectTop) || !rdpei_read_2byte_signed(s, &contactData->contactRectRight) || !rdpei_read_2byte_signed(s, &contactData->contactRectBottom)) return -1; } if ((contactData->fieldsPresent & CONTACT_DATA_ORIENTATION_PRESENT) && !rdpei_read_4byte_unsigned(s, &contactData->orientation)) return -1; if ((contactData->fieldsPresent & CONTACT_DATA_PRESSURE_PRESENT) && !rdpei_read_4byte_unsigned(s, &contactData->pressure)) return -1; return 0; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT read_touch_contact_data(RdpeiServerContext *context, wStream *s, RDPINPUT_CONTACT_DATA *contactData) { if (Stream_GetRemainingLength(s) < 1) { WLog_ERR(TAG, "Not enought data!"); return ERROR_INVALID_DATA; } Stream_Read_UINT8(s, contactData->contactId); if (!rdpei_read_2byte_unsigned(s, &contactData->fieldsPresent) || !rdpei_read_4byte_signed(s, &contactData->x) || !rdpei_read_4byte_signed(s, &contactData->y) || !rdpei_read_4byte_unsigned(s, &contactData->contactFlags)) { WLog_ERR(TAG, "rdpei_read_ failed!"); return ERROR_INTERNAL_ERROR; } if (contactData->fieldsPresent & CONTACT_DATA_CONTACTRECT_PRESENT) { if (!rdpei_read_2byte_signed(s, &contactData->contactRectLeft) || !rdpei_read_2byte_signed(s, &contactData->contactRectTop) || !rdpei_read_2byte_signed(s, &contactData->contactRectRight) || !rdpei_read_2byte_signed(s, &contactData->contactRectBottom)) { WLog_ERR(TAG, "rdpei_read_ failed!"); return ERROR_INTERNAL_ERROR; } } if ((contactData->fieldsPresent & CONTACT_DATA_ORIENTATION_PRESENT) && !rdpei_read_4byte_unsigned(s, &contactData->orientation)) { WLog_ERR(TAG, "rdpei_read_ failed!"); return ERROR_INTERNAL_ERROR; } if ((contactData->fieldsPresent & CONTACT_DATA_PRESSURE_PRESENT) && !rdpei_read_4byte_unsigned(s, &contactData->pressure)) { WLog_ERR(TAG, "rdpei_read_ failed!"); return ERROR_INTERNAL_ERROR; } return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT read_touch_event(RdpeiServerContext *context, wStream *s) { UINT32 frameCount; int i; RDPINPUT_TOUCH_EVENT *event = &context->priv->touchEvent; RDPINPUT_TOUCH_FRAME *frame; UINT error = CHANNEL_RC_OK; if (!rdpei_read_4byte_unsigned(s, &event->encodeTime) || !rdpei_read_2byte_unsigned(s, &frameCount)) { WLog_ERR(TAG, "rdpei_read_ failed!"); return ERROR_INTERNAL_ERROR; } event->frameCount = frameCount; event->frames = frame = calloc(event->frameCount, sizeof(RDPINPUT_TOUCH_FRAME)); if (!event->frames) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } for (i = 0; i < frameCount; i++, frame++) { if ((error = read_touch_frame(context, s, frame))) { WLog_ERR(TAG, "read_touch_contact_data failed with error %lu!", error); event->frameCount = i; goto out_cleanup; } } IFCALLRET(context->onTouchEvent, error, context, event); if (error) WLog_ERR(TAG, "context->onTouchEvent failed with error %lu", error); out_cleanup: touch_event_reset(event); return error; }