示例#1
0
文件: rdpdraw.c 项目: piccolo/xrdp
void
rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion)
{
    RegionRec reg;
    RegionRec clip;
    int dx;
    int dy;
    int i;
    int j;
    int num_clip_rects;
    int num_reg_rects;
    BoxRec box1;
    BoxRec box2;

    LLOGLN(10, ("in rdpCopyWindow"));
    RegionInit(&reg, NullBox, 0);
    RegionCopy(&reg, pOldRegion);
    g_pScreen->CopyWindow = g_rdpScreen.CopyWindow;
    g_pScreen->CopyWindow(pWin, ptOldOrg, pOldRegion);
    RegionInit(&clip, NullBox, 0);
    RegionCopy(&clip, &pWin->borderClip);
    dx = pWin->drawable.x - ptOldOrg.x;
    dy = pWin->drawable.y - ptOldOrg.y;

    if (g_do_dirty_ons)
    {
        LLOGLN(0, ("rdpCopyWindow: gettig dirty TODO"));
        //draw_item_add_srcblt_region
    }
    else
    {
        rdpup_begin_update();
        num_clip_rects = REGION_NUM_RECTS(&clip);
        num_reg_rects = REGION_NUM_RECTS(&reg);

        /* should maybe sort the rects instead of checking dy < 0 */
        /* If we can depend on the rects going from top to bottom, left
           to right we are ok */
        if (dy < 0 || (dy == 0 && dx < 0))
        {
            for (j = 0; j < num_clip_rects; j++)
            {
                box1 = REGION_RECTS(&clip)[j];
                rdpup_set_clip(box1.x1, box1.y1, box1.x2 - box1.x1, box1.y2 - box1.y1);

                for (i = 0; i < num_reg_rects; i++)
                {
                    box2 = REGION_RECTS(&reg)[i];
                    rdpup_screen_blt(box2.x1 + dx, box2.y1 + dy, box2.x2 - box2.x1,
                                     box2.y2 - box2.y1, box2.x1, box2.y1);
                }
            }
        }
        else
        {
            for (j = num_clip_rects - 1; j >= 0; j--)
            {
                box1 = REGION_RECTS(&clip)[j];
                rdpup_set_clip(box1.x1, box1.y1, box1.x2 - box1.x1, box1.y2 - box1.y1);

                for (i = num_reg_rects - 1; i >= 0; i--)
                {
                    box2 = REGION_RECTS(&reg)[i];
                    rdpup_screen_blt(box2.x1 + dx, box2.y1 + dy, box2.x2 - box2.x1,
                                     box2.y2 - box2.y1, box2.x1, box2.y1);
                }
            }
        }

        rdpup_reset_clip();
        rdpup_end_update();
    }

    RegionUninit(&reg);
    RegionUninit(&clip);
    g_pScreen->CopyWindow = rdpCopyWindow;
}
示例#2
0
PCSC_API LONG
SCardTransmit(SCARDHANDLE hCard, const SCARD_IO_REQUEST *pioSendPci,
              LPCBYTE pbSendBuffer, DWORD cbSendLength,
              SCARD_IO_REQUEST *pioRecvPci, LPBYTE pbRecvBuffer,
              LPDWORD pcbRecvLength)
{
    char *msg;
    int bytes;
    int code;
    int offset;
    int status;
    int extra_len;
    int got_recv_pci;

    LLOGLN(10, ("SCardTransmit:"));
    if (g_sck == -1)
    {
        LLOGLN(0, ("SCardTransmit: error, not connected"));
        return SCARD_F_INTERNAL_ERROR;
    }

    LLOGLN(10, ("  hCard 0x%8.8x", (int)hCard));
    LLOGLN(10, ("  cbSendLength %d", (int)cbSendLength));
    LLOGLN(10, ("  cbRecvLength %d", (int)*pcbRecvLength));
    LLOGLN(10, ("  pioSendPci->dwProtocol %d", (int)(pioSendPci->dwProtocol)));
    LLOGLN(10, ("  pioSendPci->cbPciLength %d", (int)(pioSendPci->cbPciLength)));
    LLOGLN(10, ("  pioRecvPci %p", pioRecvPci));
    if (pioRecvPci != 0)
    {
        LLOGLN(10, ("    pioRecvPci->dwProtocol %d", (int)(pioRecvPci->dwProtocol)));
        LLOGLN(10, ("    pioRecvPci->cbPciLength %d", (int)(pioRecvPci->cbPciLength)));
    }
    msg = (char *) malloc(8192);
    offset = 0;
    SET_UINT32(msg, offset, hCard);
    offset += 4;
    SET_UINT32(msg, offset, pioSendPci->dwProtocol);
    offset += 4;
/*  SET_UINT32(msg, offset, pioSendPci->cbPciLength); */
    SET_UINT32(msg, offset, 8);
    offset += 4;
/*  extra_len = pioSendPci->cbPciLength - 8;  */
    extra_len = 0;
    SET_UINT32(msg, offset, extra_len);
    offset += 4;
    memcpy(msg + offset, pioSendPci + 1, extra_len);
    offset += extra_len;
    SET_UINT32(msg, offset, cbSendLength);
    offset += 4;
    memcpy(msg + offset, pbSendBuffer, cbSendLength);
    offset += cbSendLength;
    // TODO figure out why recv pci does not work
    if (1 || (pioRecvPci == 0) || (pioRecvPci->cbPciLength < 8))
    {
        got_recv_pci = 0;
        SET_UINT32(msg, offset, 0); /* dwProtocol */
        offset += 4;
        SET_UINT32(msg, offset, 0); /* cbPciLength */
        offset += 4;
        SET_UINT32(msg, offset, 0); /* extra_len */
        offset += 4;
    }
    else
    {
        got_recv_pci = 1;
        SET_UINT32(msg, offset, pioRecvPci->dwProtocol);
        offset += 4;
        SET_UINT32(msg, offset, pioRecvPci->cbPciLength);
        offset += 4;
        extra_len = pioRecvPci->cbPciLength - 8;
        SET_UINT32(msg, offset, extra_len);
        offset += 4;
        memcpy(msg + offset, pioRecvPci + 1, extra_len);
        offset += extra_len;
    }
    SET_UINT32(msg, offset, *pcbRecvLength);
    offset += 4;
    if (send_message(SCARD_TRANSMIT, msg, offset) != 0)
    {
        LLOGLN(0, ("SCardTransmit: error, send_message"));
        free(msg);
        return SCARD_F_INTERNAL_ERROR;
    }
    bytes = 8192;
    code = SCARD_TRANSMIT;
    if (get_message(&code, msg, &bytes) != 0)
    {
        LLOGLN(0, ("SCardTransmit: error, get_message"));
        free(msg);
        return SCARD_F_INTERNAL_ERROR;
    }
    if (code != SCARD_TRANSMIT)
    {
        LLOGLN(0, ("SCardTransmit: error, bad code"));
        free(msg);
        return SCARD_F_INTERNAL_ERROR;
    }
    offset = 0;
    if (got_recv_pci == 0)
    {
        offset += 8;
        extra_len = GET_UINT32(msg, offset);
        offset += 4;
        offset += extra_len;
    }
    else
    {
        pioRecvPci->dwProtocol = GET_UINT32(msg, offset);
        offset += 4;
        pioRecvPci->cbPciLength = GET_UINT32(msg, offset);
        offset += 4;
        extra_len = GET_UINT32(msg, offset);
        offset += 4;
        offset += extra_len;
    }
    *pcbRecvLength = GET_UINT32(msg, offset);
    offset += 4;
    LLOGLN(10, ("  cbRecvLength %d", (int)*pcbRecvLength));
    memcpy(pbRecvBuffer, msg + offset, *pcbRecvLength);
    LHEXDUMP(10, (pbRecvBuffer, *pcbRecvLength));
    offset += *pcbRecvLength;
    status = GET_UINT32(msg, offset);
    free(msg);
    return status;
}
示例#3
0
static int
connect_to_chansrv(void)
{
    int bytes;
    int dis;
    int error;
    char *xrdp_session;
    char *xrdp_display;
    char *home_str;
    struct sockaddr_un saddr;
    struct sockaddr *psaddr;

    if (g_sck != -1)
    {
        /* already connected */
        return 0;
    }
    xrdp_session = getenv("XRDP_SESSION");
    if (xrdp_session == NULL)
    {
        /* XRDP_SESSION must be set */
        LLOGLN(0, ("connect_to_chansrv: error, not xrdp session"));
        return 1;
    }
    xrdp_display = getenv("DISPLAY");
    if (xrdp_display == NULL)
    {
        /* DISPLAY must be set */
        LLOGLN(0, ("connect_to_chansrv: error, display not set"));
        return 1;
    }
    home_str = getenv("HOME");
    if (home_str == NULL)
    {
        /* HOME must be set */
        LLOGLN(0, ("connect_to_chansrv: error, home not set"));
        return 1;
    }
    dis = get_display_num_from_display(xrdp_display);
    if (dis < 10)
    {
        /* DISPLAY must be > 9 */
        LLOGLN(0, ("connect_to_chansrv: error, display not > 9 %d", dis));
        return 1;
    }
    g_sck = socket(PF_LOCAL, SOCK_STREAM, 0);
    if (g_sck == -1)
    {
        LLOGLN(0, ("connect_to_chansrv: error, socket failed"));
        return 1;
    }
    memset(&saddr, 0, sizeof(struct sockaddr_un));
    saddr.sun_family = AF_UNIX;
    bytes = sizeof(saddr.sun_path);
    snprintf(saddr.sun_path, bytes, "%s/.pcsc%d/pcscd.comm", home_str, dis);
    saddr.sun_path[bytes - 1] = 0;
    LLOGLN(10, ("connect_to_chansrv: connecting to %s", saddr.sun_path));
    psaddr = (struct sockaddr *) &saddr;
    bytes = sizeof(struct sockaddr_un);
    error = connect(g_sck, psaddr, bytes);
    if (error == 0)
    {
    }
    else
    {
        perror("connect_to_chansrv");
        close(g_sck);
        g_sck = -1;
        LLOGLN(0, ("connect_to_chansrv: error, open %s", saddr.sun_path));
        return 1;
    }
    return 0;
}
示例#4
0
static BOOL tsmf_ffmpeg_decode_audio(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, UINT32 extensions)
{
	TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
	int len;
	int frame_size;
	UINT32 src_size;
	const BYTE* src;
	BYTE* dst;
	int dst_offset;

#if 0
	LLOGLN(0, ("tsmf_ffmpeg_decode_audio: data_size %d", data_size));
	int i;
	for (i = 0; i < data_size; i++)
	{
		LLOG(0, ("%02X ", data[i]));
		if (i % 16 == 15)
			LLOG(0, ("\n"));
	}
	LLOG(0, ("\n"));
#endif

	if (mdecoder->decoded_size_max == 0)
		mdecoder->decoded_size_max = AVCODEC_MAX_AUDIO_FRAME_SIZE + 16;
	mdecoder->decoded_data = malloc(mdecoder->decoded_size_max);
	ZeroMemory(mdecoder->decoded_data, mdecoder->decoded_size_max);
	/* align the memory for SSE2 needs */
	dst = (BYTE*) (((uintptr_t) mdecoder->decoded_data + 15) & ~ 0x0F);
	dst_offset = dst - mdecoder->decoded_data;
	src = data;
	src_size = data_size;

	while (src_size > 0)
	{
		/* Ensure enough space for decoding */
		if (mdecoder->decoded_size_max - mdecoder->decoded_size < AVCODEC_MAX_AUDIO_FRAME_SIZE)
		{
			mdecoder->decoded_size_max = mdecoder->decoded_size_max * 2 + 16;
			mdecoder->decoded_data = realloc(mdecoder->decoded_data, mdecoder->decoded_size_max);
			dst = (BYTE*) (((uintptr_t)mdecoder->decoded_data + 15) & ~ 0x0F);
			if (dst - mdecoder->decoded_data != dst_offset)
			{
				/* re-align the memory if the alignment has changed after realloc */
				memmove(dst, mdecoder->decoded_data + dst_offset, mdecoder->decoded_size);
				dst_offset = dst - mdecoder->decoded_data;
			}
			dst += mdecoder->decoded_size;
		}
		
		frame_size = mdecoder->decoded_size_max - mdecoder->decoded_size;
#if LIBAVCODEC_VERSION_MAJOR < 52 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR <= 20)
		len = avcodec_decode_audio2(mdecoder->codec_context,
			(int16_t*) dst, &frame_size, src, src_size);
#else
		{
			AVFrame* decoded_frame = avcodec_alloc_frame();
			int got_frame = 0;
			AVPacket pkt;
			av_init_packet(&pkt);
			pkt.data = (BYTE*) src;
			pkt.size = src_size;
			len = avcodec_decode_audio4(mdecoder->codec_context, decoded_frame, &got_frame, &pkt);
			
			if (len >= 0 && got_frame)
			{
				frame_size = av_samples_get_buffer_size(NULL, mdecoder->codec_context->channels,
					decoded_frame->nb_samples, mdecoder->codec_context->sample_fmt, 1);
				memcpy(dst, decoded_frame->data[0], frame_size);
			}
			
			av_free(decoded_frame);
		}
#endif
		if (len <= 0 || frame_size <= 0)
		{
			DEBUG_WARN("error decoding");
			break;
		}

		src += len;
		src_size -= len;
		mdecoder->decoded_size += frame_size;
		dst += frame_size;
	}

	if (mdecoder->decoded_size == 0)
	{
		free(mdecoder->decoded_data);
		mdecoder->decoded_data = NULL;
	}
	else if (dst_offset)
	{
		/* move the aligned decoded data to original place */
		memmove(mdecoder->decoded_data, mdecoder->decoded_data + dst_offset, mdecoder->decoded_size);
	}

	DEBUG_DVC("data_size %d decoded_size %d",
		data_size, mdecoder->decoded_size);

	return TRUE;
}
示例#5
0
RegionPtr
rdpCopyPlane(DrawablePtr pSrc, DrawablePtr pDst,
             GCPtr pGC, int srcx, int srcy, int w, int h,
             int dstx, int dsty, unsigned long bitPlane)
{
    RegionPtr rv;
    RegionRec clip_reg;
    RegionRec box_reg;
    RegionRec reg1;
    RegionRec reg2;
    int cd;
    int num_clips;
    int j;
    int got_id;
    int dirty_type;
    int post_process;
    int reset_surface;
    BoxRec box;
    BoxPtr pbox;
    struct image_data id;
    WindowPtr pDstWnd;
    PixmapPtr pDstPixmap;
    rdpPixmapRec *pDstPriv;
    rdpPixmapRec *pDirtyPriv;

    LLOGLN(10, ("rdpCopyPlane:"));

    /* do original call */
    rv = rdpCopyPlaneOrg(pSrc, pDst, pGC, srcx, srcy, w, h,
                         dstx, dsty, bitPlane);

    dirty_type = 0;
    pDirtyPriv = 0;
    post_process = 0;
    reset_surface = 0;
    got_id = 0;

    if (pDst->type == DRAWABLE_PIXMAP)
    {
        pDstPixmap = (PixmapPtr)pDst;
        pDstPriv = GETPIXPRIV(pDstPixmap);

        if (xrdp_is_os(pDstPixmap, pDstPriv))
        {
            post_process = 1;

            if (g_do_dirty_os)
            {
                LLOGLN(10, ("rdpCopyPlane: gettig dirty"));
                pDstPriv->is_dirty = 1;
                pDirtyPriv = pDstPriv;
                dirty_type = RDI_IMGLL;
            }
            else
            {
                rdpup_switch_os_surface(pDstPriv->rdpindex);
                reset_surface = 1;
                rdpup_get_pixmap_image_rect(pDstPixmap, &id);
                got_id = 1;
            }
        }
    }
    else
    {
        if (pDst->type == DRAWABLE_WINDOW)
        {
            pDstWnd = (WindowPtr)pDst;

            if (pDstWnd->viewable)
            {
                post_process = 1;

                if (g_do_dirty_ons)
                {
                    LLOGLN(0, ("rdpCopyPlane: gettig dirty"));
                    g_screenPriv.is_dirty = 1;
                    pDirtyPriv = &g_screenPriv;
                    dirty_type = RDI_IMGLL;
                }
                else
                {
                    rdpup_get_screen_image_rect(&id);
                    got_id = 1;
                }
            }
        }
    }

    if (!post_process)
    {
        return rv;
    }

    RegionInit(&clip_reg, NullBox, 0);
    cd = rdp_get_clip(&clip_reg, pDst, pGC);

    if (cd == 1)
    {
        if (dirty_type != 0)
        {
            box.x1 = pDst->x + dstx;
            box.y1 = pDst->y + dsty;
            box.x2 = box.x1 + w;
            box.y2 = box.y1 + h;
            RegionInit(&reg1, &box, 0);
            draw_item_add_img_region(pDirtyPriv, &reg1, GXcopy, dirty_type);
            RegionUninit(&reg1);
        }
        else if (got_id)
        {
            rdpup_begin_update();
            rdpup_send_area(&id, pDst->x + dstx, pDst->y + dsty, w, h);
            rdpup_end_update();
        }
    }
    else if (cd == 2)
    {
        num_clips = REGION_NUM_RECTS(&clip_reg);

        if (num_clips > 0)
        {
            if (dirty_type != 0)
            {
                box.x1 = pDst->x + dstx;
                box.y1 = pDst->y + dsty;
                box.x2 = box.x1 + w;
                box.y2 = box.y1 + h;
                RegionInit(&reg1, &box, 0);
                RegionInit(&reg2, NullBox, 0);
                RegionCopy(&reg2, &clip_reg);
                RegionIntersect(&reg1, &reg1, &reg2);
                draw_item_add_img_region(pDirtyPriv, &reg1, GXcopy, dirty_type);
                RegionUninit(&reg1);
                RegionUninit(&reg2);
            }
            else if (got_id)
            {
                rdpup_begin_update();
                box.x1 = pDst->x + dstx;
                box.y1 = pDst->y + dsty;
                box.x2 = box.x1 + w;
                box.y2 = box.y1 + h;
                RegionInit(&box_reg, &box, 0);
                RegionIntersect(&clip_reg, &clip_reg, &box_reg);
                num_clips = REGION_NUM_RECTS(&clip_reg);

                if (num_clips < 10)
                {
                    for (j = num_clips - 1; j >= 0; j--)
                    {
                        box = REGION_RECTS(&clip_reg)[j];
                        rdpup_send_area(&id, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
                    }
                }
                else
                {
                    pbox = RegionExtents(&clip_reg);
                    rdpup_send_area(&id, pbox->x1, pbox->y1, pbox->x2 - pbox->x1,
                                    pbox->y2 - pbox->y1);
                }

                RegionUninit(&box_reg);
                rdpup_end_update();
            }
        }
    }

    RegionUninit(&clip_reg);

    if (reset_surface)
    {
        rdpup_switch_os_surface(-1);
    }

    return rv;
}
示例#6
0
static int
rdpsnd_pulse_set_format(rdpsndDevicePlugin * devplugin, char * snd_format, int size)
{
	struct pulse_device_data * pulse_data;
	pa_sample_spec sample_spec = { 0 };
	int nChannels;
	int wBitsPerSample;
	int nSamplesPerSec;
	int wFormatTag;
	int nBlockAlign;

	pulse_data = (struct pulse_device_data *) devplugin->device_data;
	if (!pulse_data->context)
		return 1;
	wFormatTag = GET_UINT16(snd_format, 0);
	nChannels = GET_UINT16(snd_format, 2);
	nSamplesPerSec = GET_UINT32(snd_format, 4);
	nBlockAlign = GET_UINT16(snd_format, 12);
	wBitsPerSample = GET_UINT16(snd_format, 14);
	LLOGLN(0, ("rdpsnd_pulse_set_format: wFormatTag=%d nChannels=%d "
		"nSamplesPerSec=%d wBitsPerSample=%d nBlockAlign=%d",
		wFormatTag, nChannels, nSamplesPerSec, wBitsPerSample, nBlockAlign));

	sample_spec.rate = nSamplesPerSec;
	sample_spec.channels = nChannels;
	switch (wFormatTag)
	{
		case 1: /* PCM */
			switch (wBitsPerSample)
			{
				case 8:
					sample_spec.format = PA_SAMPLE_U8;
					break;
				case 16:
					sample_spec.format = PA_SAMPLE_S16LE;
					break;
			}
			break;

		case 6: /* A-LAW */
			sample_spec.format = PA_SAMPLE_ALAW;
			break;

		case 7: /* U-LAW */
			sample_spec.format = PA_SAMPLE_ULAW;
			break;

		case 0x11: /* IMA ADPCM */
			sample_spec.format = PA_SAMPLE_S16LE;
			break;
	}

	pulse_data->sample_spec = sample_spec;
	pulse_data->format = wFormatTag;
	pulse_data->block_size = nBlockAlign;

	if (pulse_data->stream)
	{
		pa_threaded_mainloop_lock(pulse_data->mainloop);
		pa_stream_disconnect(pulse_data->stream);
		pa_stream_unref(pulse_data->stream);
		pulse_data->stream = NULL;
		pa_threaded_mainloop_unlock(pulse_data->mainloop);
	}
	rdpsnd_pulse_open(devplugin);

	return 0;
}
示例#7
0
int
FreeRDPRdpsndDeviceEntry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)
{
	rdpsndDevicePlugin * devplugin;
	struct pulse_device_data * pulse_data;
	RD_PLUGIN_DATA * data;
	int i;

	devplugin = pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->plugin);
	if (devplugin == NULL)
	{
		LLOGLN(0, ("rdpsnd_pulse: unable to register device."));
		return 1;
	}

	devplugin->open = rdpsnd_pulse_open;
	devplugin->format_supported = rdpsnd_pulse_format_supported;
	devplugin->set_format = rdpsnd_pulse_set_format;
	devplugin->set_volume = rdpsnd_pulse_set_volume;
	devplugin->play = rdpsnd_pulse_play;
	devplugin->close = rdpsnd_pulse_close;
	devplugin->free = rdpsnd_pulse_free;

	pulse_data = (struct pulse_device_data *) malloc(sizeof(struct pulse_device_data));
	memset(pulse_data, 0, sizeof(struct pulse_device_data));

	data = (RD_PLUGIN_DATA *) pEntryPoints->data;
	if (data && strcmp(data->data[0], "pulse") == 0)
	{
		for (i = 1; i < 4 && data->data[i]; i++)
		{
			if (i > 1)
			{
				strncat(pulse_data->device_name, ":",
					sizeof(pulse_data->device_name) - strlen(pulse_data->device_name));
			}
			strncat(pulse_data->device_name, (char*)data->data[i],
				sizeof(pulse_data->device_name) - strlen(pulse_data->device_name));
		}
	}
	pulse_data->pDecodeImaAdpcm = pEntryPoints->pDecodeImaAdpcm;
	devplugin->device_data = pulse_data;

	pulse_data->mainloop = pa_threaded_mainloop_new();
	if (!pulse_data->mainloop)
	{
		LLOGLN(0, ("rdpsnd_pulse: pa_threaded_mainloop_new failed"));
		rdpsnd_pulse_free(devplugin);
		return 1;
	}
	pulse_data->context = pa_context_new(pa_threaded_mainloop_get_api(pulse_data->mainloop), "freerdp");
	if (!pulse_data->context)
	{
		LLOGLN(0, ("rdpsnd_pulse: pa_context_new failed"));
		rdpsnd_pulse_free(devplugin);
		return 1;
	}
	pa_context_set_state_callback(pulse_data->context, rdpsnd_pulse_context_state_callback, devplugin);
	if (rdpsnd_pulse_connect(devplugin))
	{
		LLOGLN(0, ("rdpsnd_pulse: rdpsnd_pulse_connect failed"));
		rdpsnd_pulse_free(devplugin);
		return 1;
	}

	LLOGLN(0, ("rdpsnd_pulse: pulse device '%s' registered.", pulse_data->device_name));

	return 0;
}
示例#8
0
static uint32
disk_query_info(IRP * irp)
{
	FILE_INFO *finfo;
	uint32 status;
	int size;
	char * buf;
	struct stat file_stat;

	LLOGLN(10, ("disk_query_info: class=%d id=%d", irp->infoClass, irp->fileID));
	finfo = disk_get_file_info(irp->dev, irp->fileID);
	if (finfo == NULL)
	{
		LLOGLN(0, ("disk_query_info: invalid file id"));
		return RD_STATUS_INVALID_HANDLE;
	}

	size = 256;
	buf = malloc(size);
	memset(buf, 0, size);

	status = RD_STATUS_SUCCESS;

	if (stat(finfo->fullpath, &file_stat) != 0)
	{
		return RD_STATUS_NO_SUCH_FILE;
	}

	switch (irp->infoClass)
	{
		case FileBasicInformation:
			SET_UINT64(buf, 0, get_rdp_filetime(file_stat.st_ctime < file_stat.st_mtime ?
				file_stat.st_ctime : file_stat.st_mtime)); /* CreationTime */
			SET_UINT64(buf, 8, get_rdp_filetime(file_stat.st_atime)); /* LastAccessTime */
			SET_UINT64(buf, 16, get_rdp_filetime(file_stat.st_mtime)); /* LastWriteTime */
			SET_UINT64(buf, 24, get_rdp_filetime(file_stat.st_ctime)); /* ChangeTime */
			SET_UINT32(buf, 32, finfo->file_attr); /* FileAttributes */
			size = 36;
			break;

		case FileStandardInformation:
			SET_UINT64(buf, 0, file_stat.st_size); /* AllocationSize */
			SET_UINT64(buf, 8, file_stat.st_size); /* EndOfFile */
			SET_UINT32(buf, 16, file_stat.st_nlink); /* NumberOfLinks */
			SET_UINT8(buf, 20, finfo->delete_pending); /* DeletePending */
			SET_UINT8(buf, 21, finfo->is_dir); /* Directory */
			size = 22;
			break;

		case FileAttributeTagInformation:
			SET_UINT32(buf, 0, finfo->file_attr); /* FileAttributes */
			SET_UINT32(buf, 4, 0);	/* ReparseTag */
			size = 8;
			break;

		default:
			LLOGLN(0, ("disk_query_info: invalid info class"));
			size = 0;
			status = RD_STATUS_NOT_SUPPORTED;
			break;
	}

	irp->outputBuffer = buf;
	irp->outputBufferLength = size;

	return status;
}
示例#9
0
static uint32
disk_set_info(IRP * irp)
{
	FILE_INFO *finfo;
	uint32 status;
	uint64 len;
	char * buf;
	char * fullpath;
	struct stat file_stat;
	struct utimbuf tvs;
	int mode;
	uint32 attr;
	time_t t;
	UNICONV * uniconv;

	LLOGLN(10, ("disk_set_info: class=%d id=%d", irp->infoClass, irp->fileID));
	finfo = disk_get_file_info(irp->dev, irp->fileID);
	if (finfo == NULL)
	{
		LLOGLN(0, ("disk_set_info: invalid file id"));
		return RD_STATUS_INVALID_HANDLE;
	}

	status = RD_STATUS_SUCCESS;

	switch (irp->infoClass)
	{
		case FileBasicInformation:
			if (stat(finfo->fullpath, &file_stat) != 0)
				return get_error_status();

			/* Change file time */
			tvs.actime = file_stat.st_atime;
			tvs.modtime = file_stat.st_mtime;
			t = get_system_filetime(GET_UINT64(irp->inputBuffer, 8)); /* LastAccessTime */
			if (t > 0)
				tvs.actime = t;
			t = get_system_filetime(GET_UINT64(irp->inputBuffer, 16)); /* LastWriteTime */
			if (t > 0)
				tvs.modtime = t;
			utime(finfo->fullpath, &tvs);

			/* Change read-only flag */
			attr = GET_UINT32(irp->inputBuffer, 32);
			if (attr == 0)
				break;
			mode = file_stat.st_mode;
			if (attr & FILE_ATTRIBUTE_READONLY)
				mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
			else
				mode |= S_IWUSR;
			mode &= 0777;
			chmod(finfo->fullpath, mode);
			break;

		case FileEndOfFileInformation:
		case FileAllocationInformation:
			len = GET_UINT64(irp->inputBuffer, 0);
			set_file_size(finfo->file, len);
			break;

		case FileDispositionInformation:
			/* Delete on close */
			finfo->delete_pending = 1;
			break;

		case FileRenameInformation:
			//replaceIfExists = GET_UINT8(irp->inputBuffer, 0); /* ReplaceIfExists */
			//rootDirectory = GET_UINT8(irp->inputBuffer, 1); /* RootDirectory */
			len = GET_UINT32(irp->inputBuffer, 2);
			uniconv = freerdp_uniconv_new();
			buf = freerdp_uniconv_in(uniconv, (unsigned char*) (irp->inputBuffer + 6), len);
			freerdp_uniconv_free(uniconv);
			fullpath = disk_get_fullpath(irp->dev, buf);
			xfree(buf);
			LLOGLN(10, ("disk_set_info: rename %s to %s", finfo->fullpath, fullpath));
			if (rename(finfo->fullpath, fullpath) == 0)
			{
				free(finfo->fullpath);
				finfo->fullpath = fullpath;
			}
			else
			{
				free(fullpath);
				return get_error_status();
			}
			break;

		default:
			LLOGLN(0, ("disk_set_info: invalid info class"));
			status = RD_STATUS_NOT_SUPPORTED;
			break;
	}

	return status;
}
示例#10
0
static uint32
disk_control(IRP * irp)
{
	LLOGLN(10, ("disk_control: id=%d io=%X", irp->fileID, irp->ioControlCode));
	return RD_STATUS_SUCCESS;
}
示例#11
0
static uint32
disk_query_volume_info(IRP * irp)
{
	FILE_INFO * finfo;
	struct STATFS_T stat_fs;
	uint32 status;
	int size;
	char * buf;
	size_t len;
	UNICONV * uniconv;
	char * s;

	LLOGLN(10, ("disk_query_volume_info: class=%d id=%d", irp->infoClass, irp->fileID));
	finfo = disk_get_file_info(irp->dev, irp->fileID);
	if (finfo == NULL)
	{
		LLOGLN(0, ("disk_query_volume_info: invalid file id"));
		return RD_STATUS_INVALID_HANDLE;
	}
	if (STATFS_FN(finfo->fullpath, &stat_fs) != 0)
	{
		LLOGLN(0, ("disk_query_volume_info: statfs failed"));
		return RD_STATUS_ACCESS_DENIED;
	}

	size = 0;
	buf = NULL;
	status = RD_STATUS_SUCCESS;
	uniconv = freerdp_uniconv_new();

	switch (irp->infoClass)
	{
		case FileFsVolumeInformation:
			buf = malloc(256);
			memset(buf, 0, 256);
			SET_UINT64(buf, 0, 0); /* VolumeCreationTime */
			SET_UINT32(buf, 8, 0); /* VolumeSerialNumber */
			s = freerdp_uniconv_out(uniconv, "FREERDP", &len);
			memcpy(buf + 17, s, len);
			xfree(s);
			SET_UINT32(buf, 12, len); /* VolumeLabelLength */
			SET_UINT8(buf, 16, 0);	/* SupportsObjects */
			size = 17 + len;
			break;

		case FileFsSizeInformation:
			size = 24;
			buf = malloc(size);
			memset(buf, 0, size);
			SET_UINT64(buf, 0, stat_fs.f_blocks); /* TotalAllocationUnits */
			SET_UINT64(buf, 8, stat_fs.f_bfree); /* AvailableAllocationUnits */
			SET_UINT32(buf, 16, stat_fs.f_bsize / 0x200); /* SectorsPerAllocationUnit */
			SET_UINT32(buf, 20, 0x200); /* BytesPerSector */
			break;

		case FileFsAttributeInformation:
			buf = malloc(256);
			memset(buf, 0, 256);
			SET_UINT32(buf, 0, FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK); /* FileSystemAttributes */
			SET_UINT32(buf, 4, F_NAMELEN(stat_fs)); /* MaximumComponentNameLength */
			s = freerdp_uniconv_out(uniconv, "FREERDP", &len);
			memcpy(buf + 17, s, len);
			xfree(s);
			SET_UINT32(buf, 8, len); /* FileSystemNameLength */
			size = 12 + len;
			break;

		case FileFsFullSizeInformation:
			size = 32;
			buf = malloc(size);
			memset(buf, 0, size);
			SET_UINT64(buf, 0, stat_fs.f_blocks); /* TotalAllocationUnits */
			SET_UINT64(buf, 8, stat_fs.f_bfree); /* CallerAvailableAllocationUnits */
			SET_UINT64(buf, 16, stat_fs.f_bfree); /* ActualAvailableAllocationUnits */
			SET_UINT32(buf, 24, stat_fs.f_bsize / 0x200); /* SectorsPerAllocationUnit */
			SET_UINT32(buf, 28, 0x200); /* BytesPerSector */
			break;

		case FileFsDeviceInformation:
			size = 8;
			buf = malloc(size);
			memset(buf, 0, size);
			SET_UINT32(buf, 0, FILE_DEVICE_DISK); /* DeviceType */
			SET_UINT32(buf, 4, 0); /* BytesPerSector */
			break;

		default:
			LLOGLN(0, ("disk_query_volume_info: invalid info class"));
			status = RD_STATUS_NOT_SUPPORTED;
			break;
	}

	freerdp_uniconv_free(uniconv);

	irp->outputBuffer = buf;
	irp->outputBufferLength = size;

	return status;
}
示例#12
0
static uint32
disk_remove_dir(const char * path)
{
	DIR * dir;
	struct dirent * pdirent;
	struct stat file_stat;
	char * p;
	uint32 ret = RD_STATUS_SUCCESS;

	dir = opendir(path);
	if (dir == NULL)
		return get_error_status();

	pdirent = readdir(dir);
	while (pdirent)
	{
		if (strcmp(pdirent->d_name, ".") == 0 || strcmp(pdirent->d_name, "..") == 0)
		{
			pdirent = readdir(dir);
			continue;
		}

		p = malloc(strlen(path) + strlen(pdirent->d_name) + 2);
		sprintf(p, "%s/%s", path, pdirent->d_name);
		if (stat(p, &file_stat) != 0)
		{
			LLOGLN(0, ("disk_remove_dir: stat %s failed (%i)\n", p, errno));
			ret = get_error_status();
		}
		else if (S_ISDIR(file_stat.st_mode))
		{
			ret = disk_remove_dir(p);
		}
		else
		{
			if (unlink(p) < 0)
			{
				LLOGLN(0, ("disk_remove_dir: unlink %s failed (%i)\n", p, errno));
				ret = get_error_status();
			}
		}
		free(p);

		if (ret != RD_STATUS_SUCCESS)
			break;

		pdirent = readdir(dir);
	}

	closedir(dir);
	if (ret == RD_STATUS_SUCCESS)
	{
		if (rmdir(path) < 0)
		{
			LLOGLN(0, ("disk_remove_dir: rmdir %s failed (%i)\n", path, errno));
			ret = get_error_status();
		}
	}

	return ret;
}
示例#13
0
static tbool tsmf_ffmpeg_decode_audio(ITSMFDecoder* decoder, const uint8* data, uint32 data_size, uint32 extensions)
{
	TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
	int len;
	int frame_size;
	uint32 src_size;
	const uint8* src;
	uint8* dst;
	int dst_offset;

#if 0
	LLOGLN(0, ("tsmf_ffmpeg_decode_audio: data_size %d", data_size));
	int i;
	for (i = 0; i < data_size; i++)
	{
		LLOG(0, ("%02X ", data[i]));
		if (i % 16 == 15)
			LLOG(0, ("\n"));
	}
	LLOG(0, ("\n"));
#endif

	if (mdecoder->decoded_size_max == 0)
		mdecoder->decoded_size_max = AVCODEC_MAX_AUDIO_FRAME_SIZE + 16;
	mdecoder->decoded_data = xzalloc(mdecoder->decoded_size_max);
	/* align the memory for SSE2 needs */
	dst = (uint8*) (((uintptr_t)mdecoder->decoded_data + 15) & ~ 0x0F);
	dst_offset = dst - mdecoder->decoded_data;
	src = data;
	src_size = data_size;

	while (src_size > 0)
	{
		/* Ensure enough space for decoding */
		if (mdecoder->decoded_size_max - mdecoder->decoded_size < AVCODEC_MAX_AUDIO_FRAME_SIZE)
		{
			mdecoder->decoded_size_max = mdecoder->decoded_size_max * 2 + 16;
			mdecoder->decoded_data = xrealloc(mdecoder->decoded_data, mdecoder->decoded_size_max);
			dst = (uint8*) (((uintptr_t)mdecoder->decoded_data + 15) & ~ 0x0F);
			if (dst - mdecoder->decoded_data != dst_offset)
			{
				/* re-align the memory if the alignment has changed after realloc */
				memmove(dst, mdecoder->decoded_data + dst_offset, mdecoder->decoded_size);
				dst_offset = dst - mdecoder->decoded_data;
			}
			dst += mdecoder->decoded_size;
		}
		frame_size = mdecoder->decoded_size_max - mdecoder->decoded_size;
#if LIBAVCODEC_VERSION_MAJOR < 52 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR <= 20)
		len = avcodec_decode_audio2(mdecoder->codec_context,
			(int16_t*) dst, &frame_size,
			src, src_size);
#else
		{
			AVPacket pkt;
			av_init_packet(&pkt);
			pkt.data = (uint8*) src;
			pkt.size = src_size;
			len = avcodec_decode_audio3(mdecoder->codec_context,
				(int16_t*) dst, &frame_size, &pkt);
		}
#endif
		if (len <= 0 || frame_size <= 0)
		{
			DEBUG_WARN("error decoding");
			break;
		}
		src += len;
		src_size -= len;
		mdecoder->decoded_size += frame_size;
		dst += frame_size;
	}

	if (mdecoder->decoded_size == 0)
	{
		xfree(mdecoder->decoded_data);
		mdecoder->decoded_data = NULL;
	}
	else if (dst_offset)
	{
		/* move the aligned decoded data to original place */
		memmove(mdecoder->decoded_data, mdecoder->decoded_data + dst_offset, mdecoder->decoded_size);
	}

	DEBUG_DVC("data_size %d decoded_size %d",
		data_size, mdecoder->decoded_size);

	return true;
}
示例#14
0
void
rdpPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc* parcs)
{
  RegionRec clip_reg;
  RegionPtr tmpRegion;
  int cd;
  int lw;
  int extra;
  int i;
  int num_clips;
  int got_id;
  xRectangle* rects;
  BoxRec box;
  struct image_data id;
  WindowPtr pDstWnd;
  PixmapPtr pDstPixmap;
  rdpPixmapRec* pDstPriv;

  LLOGLN(10, ("rdpPolyArc:"));

  rects = 0;
  if (narcs > 0)
  {
    rects = (xRectangle*)g_malloc(narcs * sizeof(xRectangle), 0);
    lw = pGC->lineWidth;
    if (lw == 0)
    {
      lw = 1;
    }
    extra = lw / 2;
    for (i = 0; i < narcs; i++)
    {
      rects[i].x = (parcs[i].x - extra) + pDrawable->x;
      rects[i].y = (parcs[i].y - extra) + pDrawable->y;
      rects[i].width = parcs[i].width + lw;
      rects[i].height = parcs[i].height + lw;
    }
  }

  /* do original call */
  rdpPolyArcOrg(pDrawable, pGC, narcs, parcs);

  got_id = 0;
  if (pDrawable->type == DRAWABLE_PIXMAP)
  {
    pDstPixmap = (PixmapPtr)pDrawable;
    pDstPriv = GETPIXPRIV(pDstPixmap);
    if (XRDP_IS_OS(pDstPriv))
    {
      rdpup_switch_os_surface(pDstPriv->rdpindex);
      rdpup_get_pixmap_image_rect(pDstPixmap, &id);
      got_id = 1;
    }
  }
  else
  {
    if (pDrawable->type == DRAWABLE_WINDOW)
    {
      pDstWnd = (WindowPtr)pDrawable;
      if (pDstWnd->viewable)
      {
        rdpup_get_screen_image_rect(&id);
        got_id = 1;
      }
    }
  }
  if (!got_id)
  {
    g_free(rects);
    return;
  }

  RegionInit(&clip_reg, NullBox, 0);
  cd = rdp_get_clip(&clip_reg, pDrawable, pGC);
  if (cd == 1)
  {
    if (rects != 0)
    {
      tmpRegion = RegionFromRects(narcs, rects, CT_NONE);
      num_clips = REGION_NUM_RECTS(tmpRegion);
      if (num_clips > 0)
      {
        rdpup_begin_update();
        for (i = num_clips - 1; i >= 0; i--)
        {
          box = REGION_RECTS(tmpRegion)[i];
          rdpup_send_area(&id, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
        }
        rdpup_end_update();
      }
      RegionDestroy(tmpRegion);
    }
  }
  else if (cd == 2)
  {
    if (rects != 0)
    {
      tmpRegion = RegionFromRects(narcs, rects, CT_NONE);
      RegionIntersect(tmpRegion, tmpRegion, &clip_reg);
      num_clips = REGION_NUM_RECTS(tmpRegion);
      if (num_clips > 0)
      {
        rdpup_begin_update();
        for (i = num_clips - 1; i >= 0; i--)
        {
          box = REGION_RECTS(tmpRegion)[i];
          rdpup_send_area(&id, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
        }
        rdpup_end_update();
      }
      RegionDestroy(tmpRegion);
    }
  }
  RegionUninit(&clip_reg);
  g_free(rects);
  rdpup_switch_os_surface(-1);
}
示例#15
0
文件: libxrdp.c 项目: PKRoma/xrdp
int EXPORT_CC
libxrdp_send_bitmap(struct xrdp_session *session, int width, int height,
                    int bpp, char *data, int x, int y, int cx, int cy)
{
    int line_bytes = 0;
    int i = 0;
    int j = 0;
    int k;
    int total_lines = 0;
    int lines_sending = 0;
    int Bpp = 0;
    int e = 0;
    int bufsize = 0;
    int total_bufsize = 0;
    int num_updates = 0;
    int line_pad_bytes;
    int server_line_bytes;
    char *p_num_updates = (char *)NULL;
    char *p = (char *)NULL;
    char *q = (char *)NULL;
    struct stream *s = (struct stream *)NULL;
    struct stream *temp_s = (struct stream *)NULL;
    tui32 pixel;

    LLOGLN(10, ("libxrdp_send_bitmap: sending bitmap"));
    Bpp = (bpp + 7) / 8;
    e = (4 - width) & 3;
    switch (bpp)
    {
        case 15:
        case 16:
            server_line_bytes = width * 2;
            break;
        case 24:
        case 32:
            server_line_bytes = width * 4;
            break;
        default: /* 8 bpp */
            server_line_bytes = width;
            break;
    }
    line_bytes = width * Bpp;
    line_pad_bytes = line_bytes + e * Bpp;

    LLOGLN(10, ("libxrdp_send_bitmap: bpp %d Bpp %d line_bytes %d "
           "server_line_bytes %d", bpp, Bpp, line_bytes, server_line_bytes));
    make_stream(s);
    init_stream(s, MAX_BITMAP_BUF_SIZE);

    if (session->client_info->use_bitmap_comp)
    {
        LLOGLN(10, ("libxrdp_send_bitmap: compression"));
        make_stream(temp_s);
        init_stream(temp_s, 65536);
        i = 0;

        if (cy <= height)
        {
            i = cy;
        }

        while (i > 0)
        {
            LLOGLN(10, ("libxrdp_send_bitmap: i %d", i));

            total_bufsize = 0;
            num_updates = 0;
            xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s);
            out_uint16_le(s, RDP_UPDATE_BITMAP);
            p_num_updates = s->p;
            out_uint8s(s, 2); /* num_updates set later */

            do
            {
                if (session->client_info->op1)
                {
                    s_push_layer(s, channel_hdr, 18);
                }
                else
                {
                    s_push_layer(s, channel_hdr, 26);
                }

                p = s->p;

                if (bpp > 24)
                {
                    LLOGLN(10, ("libxrdp_send_bitmap: 32 bpp"));
                    lines_sending = xrdp_bitmap32_compress(data, width, height,
                                                           s, 32,
                                   (MAX_BITMAP_BUF_SIZE - 100) - total_bufsize,
                                                           i - 1, temp_s, e, 0x10);
                    LLOGLN(10, ("libxrdp_send_bitmap: i %d lines_sending %d",
                           i, lines_sending));
                }
                else
                {
                    lines_sending = xrdp_bitmap_compress(data, width, height,
                                                         s, bpp,
                                 (MAX_BITMAP_BUF_SIZE - 100) - total_bufsize,
                                                         i - 1, temp_s, e);
                    LLOGLN(10, ("libxrdp_send_bitmap: i %d lines_sending %d",
                           i, lines_sending));
                }

                if (lines_sending == 0)
                {
                    break;
                }

                num_updates++;
                bufsize = s->p - p;
                total_bufsize += bufsize;
                i = i - lines_sending;
                s_mark_end(s);
                s_pop_layer(s, channel_hdr);
                out_uint16_le(s, x); /* left */
                out_uint16_le(s, y + i); /* top */
                out_uint16_le(s, (x + cx) - 1); /* right */
                out_uint16_le(s, (y + i + lines_sending) - 1); /* bottom */
                out_uint16_le(s, width + e); /* width */
                out_uint16_le(s, lines_sending); /* height */
                out_uint16_le(s, bpp); /* bpp */

                if (session->client_info->op1)
                {
                    out_uint16_le(s, 0x401); /* compress */
                    out_uint16_le(s, bufsize); /* compressed size */
                    j = (width + e) * Bpp;
                    j = j * lines_sending;
                    total_bufsize += 18; /* bytes since pop layer */
                }
                else
                {
                    out_uint16_le(s, 0x1); /* compress */
                    out_uint16_le(s, bufsize + 8);
                    out_uint8s(s, 2); /* pad */
                    out_uint16_le(s, bufsize); /* compressed size */
                    j = (width + e) * Bpp;
                    out_uint16_le(s, j); /* line size */
                    j = j * lines_sending;
                    out_uint16_le(s, j); /* final size */
                    total_bufsize += 26; /* bytes since pop layer */
                }

                LLOGLN(10, ("libxrdp_send_bitmap: decompressed pixels %d "
                       "decompressed bytes %d compressed bytes %d",
                       lines_sending * (width + e),
                       line_pad_bytes * lines_sending, bufsize));

                if (j > MAX_BITMAP_BUF_SIZE)
                {
                    LLOGLN(0, ("libxrdp_send_bitmap: error, decompressed "
                           "size too big: %d bytes", j));
                }

                if (bufsize > MAX_BITMAP_BUF_SIZE)
                {
                    LLOGLN(0, ("libxrdp_send_bitmap: error, compressed size "
                           "too big: %d bytes", bufsize));
                }

                s->p = s->end;
            }
            while (total_bufsize < MAX_BITMAP_BUF_SIZE && i > 0);

            LLOGLN(10, ("libxrdp_send_bitmap: num_updates %d total_bufsize %d",
                   num_updates, total_bufsize));

            p_num_updates[0] = num_updates;
            p_num_updates[1] = num_updates >> 8;
            xrdp_rdp_send_data((struct xrdp_rdp *)session->rdp, s,
                               RDP_DATA_PDU_UPDATE);

            if (total_bufsize > MAX_BITMAP_BUF_SIZE)
            {
                LLOGLN(0, ("libxrdp_send_bitmap: error, total compressed "
                       "size too big: %d bytes", total_bufsize));
            }
        }

        free_stream(temp_s);
    }
示例#16
0
static uint32
disk_query_directory(IRP * irp, uint8 initialQuery, const char * path)
{
	DISK_DEVICE_INFO * info;
	FILE_INFO * finfo;
	char * p;
	uint32 status;
	char * buf;
	int size;
	size_t len;
	struct dirent * pdirent;
	struct stat file_stat;
	uint32 attr;
	UNICONV * uniconv;

	LLOGLN(10, ("disk_query_directory: class=%d id=%d init=%d path=%s", irp->infoClass, irp->fileID,
		initialQuery, path));
	finfo = disk_get_file_info(irp->dev, irp->fileID);
	if (finfo == NULL || finfo->dir == NULL)
	{
		LLOGLN(0, ("disk_query_directory: invalid file id"));
		return RD_STATUS_INVALID_HANDLE;
	}
	info = (DISK_DEVICE_INFO *) irp->dev->info;

	if (initialQuery)
	{
		if (finfo->pattern)
			free(finfo->pattern);
		p = strrchr(path, '\\');
		p = (p ? p + 1 : (char *)path);
		finfo->pattern = malloc(strlen(p) + 1);
		strcpy(finfo->pattern, p);
		rewinddir(finfo->dir);
	}

	status = RD_STATUS_SUCCESS;
	buf = NULL;
	size = 0;

	pdirent = readdir(finfo->dir);
	while (pdirent && finfo->pattern[0] && fnmatch(finfo->pattern, pdirent->d_name, 0) != 0)
		pdirent = readdir(finfo->dir);
	if (pdirent == NULL)
	{
		return RD_STATUS_NO_MORE_FILES;
	}

	memset(&file_stat, 0, sizeof(struct stat));
	p = malloc(strlen(finfo->fullpath) + strlen(pdirent->d_name) + 2);
	sprintf(p, "%s/%s", finfo->fullpath, pdirent->d_name);
	if (stat(p, &file_stat) != 0)
	{
		LLOGLN(0, ("disk_query_directory: stat %s failed (%i)\n", p, errno));
	}
	free(p);

	attr = get_file_attribute(pdirent->d_name, &file_stat);
	uniconv = freerdp_uniconv_new();

	switch (irp->infoClass)
	{
		case FileBothDirectoryInformation:
			size = 93 + strlen(pdirent->d_name) * 2;
			buf = malloc(size);
			memset(buf, 0, size);

			SET_UINT32(buf, 0, 0); /* NextEntryOffset */
			SET_UINT32(buf, 4, 0); /* FileIndex */
			SET_UINT64(buf, 8, get_rdp_filetime(file_stat.st_ctime < file_stat.st_mtime ?
				file_stat.st_ctime : file_stat.st_mtime)); /* CreationTime */
			SET_UINT64(buf, 16, get_rdp_filetime(file_stat.st_atime)); /* LastAccessTime */
			SET_UINT64(buf, 24, get_rdp_filetime(file_stat.st_mtime)); /* LastWriteTime */
			SET_UINT64(buf, 32, get_rdp_filetime(file_stat.st_ctime)); /* ChangeTime */
			SET_UINT64(buf, 40, file_stat.st_size); /* EndOfFile */
			SET_UINT64(buf, 48, file_stat.st_size); /* AllocationSize */
			SET_UINT32(buf, 56, attr); /* FileAttributes */
			SET_UINT32(buf, 64, 0); /* EaSize */
			SET_UINT8(buf, 68, 0); /* ShortNameLength */
			/* [MS-FSCC] has one byte padding here but RDP does not! */
			//SET_UINT8(buf, 69, 0); /* Reserved */
			/* ShortName 24  bytes */
			p = freerdp_uniconv_out(uniconv, pdirent->d_name, &len);
			memcpy(buf + 93, p, len);
			xfree(p);
			SET_UINT32(buf, 60, len); /* FileNameLength */
			size = 93 + len;
			break;

		case FileFullDirectoryInformation:
			size = 68 + strlen(pdirent->d_name) * 2;
			buf = malloc(size);
			memset(buf, 0, size);

			SET_UINT32(buf, 0, 0); /* NextEntryOffset */
			SET_UINT32(buf, 4, 0); /* FileIndex */
			SET_UINT64(buf, 8, get_rdp_filetime(file_stat.st_ctime < file_stat.st_mtime ?
				file_stat.st_ctime : file_stat.st_mtime)); /* CreationTime */
			SET_UINT64(buf, 16, get_rdp_filetime(file_stat.st_atime)); /* LastAccessTime */
			SET_UINT64(buf, 24, get_rdp_filetime(file_stat.st_mtime)); /* LastWriteTime */
			SET_UINT64(buf, 32, get_rdp_filetime(file_stat.st_ctime)); /* ChangeTime */
			SET_UINT64(buf, 40, file_stat.st_size); /* EndOfFile */
			SET_UINT64(buf, 48, file_stat.st_size); /* AllocationSize */
			SET_UINT32(buf, 56, attr); /* FileAttributes */
			SET_UINT32(buf, 64, 0); /* EaSize */
			p = freerdp_uniconv_out(uniconv, pdirent->d_name, &len);
			memcpy(buf + 68, p, len);
			xfree(p);
			SET_UINT32(buf, 60, len); /* FileNameLength */
			size = 68 + len;
			break;

		case FileNamesInformation:
			size = 12 + strlen(pdirent->d_name) * 2;
			buf = malloc(size);
			memset(buf, 0, size);

			SET_UINT32(buf, 0, 0); /* NextEntryOffset */
			SET_UINT32(buf, 4, 0); /* FileIndex */
			p = freerdp_uniconv_out(uniconv, pdirent->d_name, &len);
			memcpy(buf + 12, p, len);
			xfree(p);
			SET_UINT32(buf, 8, len); /* FileNameLength */
			size = 12 + len;
			break;

		case FileDirectoryInformation:
			size = 64 + strlen(pdirent->d_name) * 2;
			buf = malloc(size);
			memset(buf, 0, size);

			SET_UINT32(buf, 0, 0); /* NextEntryOffset */
			SET_UINT32(buf, 4, 0); /* FileIndex */
			SET_UINT64(buf, 8, get_rdp_filetime(file_stat.st_ctime < file_stat.st_mtime ?
				file_stat.st_ctime : file_stat.st_mtime)); /* CreationTime */
			SET_UINT64(buf, 16, get_rdp_filetime(file_stat.st_atime)); /* LastAccessTime */
			SET_UINT64(buf, 24, get_rdp_filetime(file_stat.st_mtime)); /* LastWriteTime */
			SET_UINT64(buf, 32, get_rdp_filetime(file_stat.st_ctime)); /* ChangeTime */
			SET_UINT64(buf, 40, file_stat.st_size); /* EndOfFile */
			SET_UINT64(buf, 48, file_stat.st_size); /* AllocationSize */
			SET_UINT32(buf, 56, attr); /* FileAttributes */
			p = freerdp_uniconv_out(uniconv, pdirent->d_name, &len);
			memcpy(buf + 64, p, len);
			xfree(p);
			SET_UINT32(buf, 60, len); /* FileNameLength */
			size = 64 + len;
			break;

		default:
			LLOGLN(0, ("disk_query_directory: invalid info class %d", irp->infoClass));
			status = RD_STATUS_NOT_SUPPORTED;
			break;
	}

	freerdp_uniconv_free(uniconv);

	irp->outputBuffer = buf;
	irp->outputBufferLength = size;

	return status;
}
示例#17
0
static int
rdpsnd_pulse_open(rdpsndDevicePlugin * devplugin)
{
	struct pulse_device_data * pulse_data;
	pa_stream_state_t state;
	pa_buffer_attr buffer_attr = { 0 };

	pulse_data = (struct pulse_device_data *) devplugin->device_data;
	if (!pulse_data->context)
		return 1;
	/* Since rdpsnd_main calls set_format() after open(), but we need the
	   format spec to open the stream, we will defer the open request if
	   initial set_format request is not yet received */
	if (!pulse_data->sample_spec.rate || pulse_data->stream)
		return 0;
	LLOGLN(10, ("rdpsnd_pulse_open:"));
	pa_threaded_mainloop_lock(pulse_data->mainloop);
	pulse_data->stream = pa_stream_new(pulse_data->context, "freerdp",
		&pulse_data->sample_spec, NULL);
	if (!pulse_data->stream)
	{
		pa_threaded_mainloop_unlock(pulse_data->mainloop);
		LLOGLN(0, ("rdpsnd_pulse_open: pa_stream_new failed (%d)",
			pa_context_errno(pulse_data->context)));
		return 1;
	}
	pa_stream_set_state_callback(pulse_data->stream,
		rdpsnd_pulse_stream_state_callback, devplugin);
	pa_stream_set_write_callback(pulse_data->stream,
		rdpsnd_pulse_stream_request_callback, devplugin);
	buffer_attr.maxlength = (uint32_t) -1;
	buffer_attr.tlength = (uint32_t) -1;//pa_usec_to_bytes(2000000, &pulse_data->sample_spec);
	buffer_attr.prebuf = (uint32_t) -1;
	buffer_attr.minreq = (uint32_t) -1;
	buffer_attr.fragsize = (uint32_t) -1;
	if (pa_stream_connect_playback(pulse_data->stream,
		pulse_data->device_name[0] ? pulse_data->device_name : NULL,
		&buffer_attr, 0, NULL, NULL) < 0)
	{
		pa_threaded_mainloop_unlock(pulse_data->mainloop);
		LLOGLN(0, ("rdpsnd_pulse_open: pa_stream_connect_playback failed (%d)",
			pa_context_errno(pulse_data->context)));
		return 1;
	}

	for (;;)
	{
		state = pa_stream_get_state(pulse_data->stream);
		if (state == PA_STREAM_READY)
			break;
        if (!PA_STREAM_IS_GOOD(state))
		{
			LLOGLN(0, ("rdpsnd_pulse_open: bad stream state (%d)",
				pa_context_errno(pulse_data->context)));
			break;
		}
		pa_threaded_mainloop_wait(pulse_data->mainloop);
	}
	pa_threaded_mainloop_unlock(pulse_data->mainloop);
	if (state == PA_STREAM_READY)
	{
		memset(&pulse_data->adpcm, 0, sizeof(rdpsndDspAdpcm));
		LLOGLN(0, ("rdpsnd_pulse_open: connected"));
		return 0;
	}
	else
	{
		rdpsnd_pulse_close(devplugin);
		return 1;
	}
}
示例#18
0
static int
thread_process_message(rdpdbgPlugin * plugin, char * data, int data_size)
{
	LLOGLN(10, ("rdpdbg: thread_process_message: size=%d", data_size));
	return 0;
}
示例#19
0
static int
rdpsnd_pulse_set_volume(rdpsndDevicePlugin * devplugin, uint32 value)
{
	LLOGLN(0, ("rdpsnd_pulse_set_volume: %8.8x", value));
	return 0;
}
示例#20
0
RegionPtr rdpCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
		int srcx, int srcy, int w, int h, int dstx, int dsty, unsigned long bitPlane)
{
	RegionPtr rv;
	RegionRec clip_reg;
	RegionRec box_reg;
	int cd;
	int num_clips;
	int j;
	int post_process;
	BoxRec box;
	BoxPtr pbox;
	WindowPtr pDstWnd;
	PixmapPtr pDstPixmap;
	rdpPixmapRec *pDstPriv;

	LLOGLN(10, ("rdpCopyPlane:"));

	/* do original call */
	rv = rdpCopyPlaneOrg(pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty, bitPlane);

	post_process = 0;

	if (pDst->type == DRAWABLE_PIXMAP)
	{
		pDstPixmap = (PixmapPtr) pDst;
		pDstPriv = GETPIXPRIV(pDstPixmap);
	}
	else
	{
		if (pDst->type == DRAWABLE_WINDOW)
		{
			pDstWnd = (WindowPtr) pDst;

			if (pDstWnd->viewable)
			{
				post_process = 1;
			}
		}
	}

	if (!post_process)
		return rv;

	RegionInit(&clip_reg, NullBox, 0);
	cd = rdp_get_clip(&clip_reg, pDst, pGC);

	if (cd == 1)
	{
		rdp_send_area_update(pDst->x + dstx, pDst->y + dsty, w, h);
	}
	else if (cd == 2)
	{
		num_clips = REGION_NUM_RECTS(&clip_reg);

		if (num_clips > 0)
		{
			box.x1 = pDst->x + dstx;
			box.y1 = pDst->y + dsty;
			box.x2 = box.x1 + w;
			box.y2 = box.y1 + h;
			RegionInit(&box_reg, &box, 0);
			RegionIntersect(&clip_reg, &clip_reg, &box_reg);
			num_clips = REGION_NUM_RECTS(&clip_reg);

			if (num_clips < 10)
			{
				for (j = num_clips - 1; j >= 0; j--)
				{
					box = REGION_RECTS(&clip_reg)[j];
					rdp_send_area_update(box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
				}
			}
			else
			{
				pbox = RegionExtents(&clip_reg);
				rdp_send_area_update(pbox->x1, pbox->y1, pbox->x2 - pbox->x1, pbox->y2 - pbox->y1);
			}

			RegionUninit(&box_reg);
		}
	}

	RegionUninit(&clip_reg);

	return rv;
}
示例#21
0
/* tested with pGC->lineWidth = 0, 1, 2, 4 and opcodes 3 and 6 */
void
rdpPolyRectangle(DrawablePtr pDrawable, GCPtr pGC, int nrects,
                 xRectangle *rects)
{
    RegionRec clip_reg;
    RegionPtr fill_reg;
    int num_clips;
    int cd;
    int lw;
    int i;
    int j;
    int up;
    int down;
    int got_id;
    int dirty_type;
    int post_process;
    int reset_surface;
    xRectangle *regRects;
    xRectangle *r;
    xRectangle *rect1;
    BoxRec box;
    struct image_data id;

    WindowPtr pDstWnd;
    PixmapPtr pDstPixmap;
    rdpPixmapRec *pDstPriv;
    rdpPixmapRec *pDirtyPriv;

    LLOGLN(10, ("rdpPolyRectangle:"));

    /* make a copy of rects */
    rect1 = (xRectangle *)g_malloc(sizeof(xRectangle) * nrects, 0);

    for (i = 0; i < nrects; i++)
    {
        rect1[i] = rects[i];
    }

    /* do original call */
    rdpPolyRectangleOrg(pDrawable, pGC, nrects, rects);

    dirty_type = 0;
    pDirtyPriv = 0;
    post_process = 0;
    reset_surface = 0;
    got_id = 0;

    if (pDrawable->type == DRAWABLE_PIXMAP)
    {
        pDstPixmap = (PixmapPtr)pDrawable;
        pDstPriv = GETPIXPRIV(pDstPixmap);

        if (xrdp_is_os(pDstPixmap, pDstPriv))
        {
            post_process = 1;

            if (g_do_dirty_os)
            {
                LLOGLN(10, ("rdpPolyRectangle: gettig dirty"));
                pDstPriv->is_dirty = 1;
                pDirtyPriv = pDstPriv;
                dirty_type = RDI_IMGLL;
            }
            else
            {
                rdpup_switch_os_surface(pDstPriv->rdpindex);
                reset_surface = 1;
                rdpup_get_pixmap_image_rect(pDstPixmap, &id);
                got_id = 1;
            }
        }
    }
    else
    {
        if (pDrawable->type == DRAWABLE_WINDOW)
        {
            pDstWnd = (WindowPtr)pDrawable;

            if (pDstWnd->viewable)
            {
                post_process = 1;

                if (g_do_dirty_ons)
                {
                    LLOGLN(0, ("rdpPolyRectangle: gettig dirty"));
                    g_screenPriv.is_dirty = 1;
                    pDirtyPriv = &g_screenPriv;
                    dirty_type = RDI_IMGLL;
                }
                else
                {
                    rdpup_get_screen_image_rect(&id);
                    got_id = 1;
                }
            }
        }
    }

    if (!post_process)
    {
        g_free(rect1);
        return;
    }

    RegionInit(&clip_reg, NullBox, 0);
    cd = rdp_get_clip(&clip_reg, pDrawable, pGC);
    regRects = 0;

    if ((cd != 0) && (nrects > 0))
    {
        regRects = (xRectangle *)g_malloc(nrects * 4 * sizeof(xRectangle), 0);
        lw = pGC->lineWidth;

        if (lw < 1)
        {
            lw = 1;
        }

        up = lw / 2;
        down = 1 + (lw - 1) / 2;

        for (i = 0; i < nrects; i++)
        {
            r = regRects + i * 4;
            r->x = (rect1[i].x + pDrawable->x) - up;
            r->y = (rect1[i].y + pDrawable->y) - up;
            r->width = rect1[i].width + up + down;
            r->height = lw;
            r++;
            r->x = (rect1[i].x + pDrawable->x) - up;
            r->y = (rect1[i].y + pDrawable->y) + down;
            r->width = lw;
            r->height = MAX(rect1[i].height - (up + down), 0);
            r++;
            r->x = ((rect1[i].x + rect1[i].width) + pDrawable->x) - up;
            r->y = (rect1[i].y + pDrawable->y) + down;
            r->width = lw;
            r->height = MAX(rect1[i].height - (up + down), 0);
            r++;
            r->x = (rect1[i].x + pDrawable->x) - up;
            r->y = ((rect1[i].y + rect1[i].height) + pDrawable->y) - up;
            r->width = rect1[i].width + up + down;
            r->height = lw;
        }
    }

    if (cd == 1)
    {
        if (regRects != 0)
        {
            if (dirty_type != 0)
            {
                fill_reg = RegionFromRects(nrects * 4, regRects, CT_NONE);

                if (pGC->lineStyle == LineSolid)
                {
                    draw_item_add_fill_region(pDirtyPriv, fill_reg, pGC->fgPixel,
                                              pGC->alu);
                }
                else
                {
                    draw_item_add_img_region(pDirtyPriv, fill_reg, GXcopy, dirty_type);
                }

                RegionDestroy(fill_reg);
            }
            else if (got_id)
            {
                rdpup_begin_update();

                if (pGC->lineStyle == LineSolid)
                {
                    rdpup_set_fgcolor(pGC->fgPixel);
                    rdpup_set_opcode(pGC->alu);

                    for (i = 0; i < nrects * 4; i++)
                    {
                        r = regRects + i;
                        rdpup_fill_rect(r->x, r->y, r->width, r->height);
                    }

                    rdpup_set_opcode(GXcopy);
                }
                else
                {
                    for (i = 0; i < nrects * 4; i++)
                    {
                        r = regRects + i;
                        rdpup_send_area(&id, r->x, r->y, r->width, r->height);
                    }
                }

                rdpup_end_update();
            }
        }
    }
    else if (cd == 2)
    {
        if (regRects != 0)
        {
            fill_reg = RegionFromRects(nrects * 4, regRects, CT_NONE);
            RegionIntersect(&clip_reg, &clip_reg, fill_reg);
            num_clips = REGION_NUM_RECTS(&clip_reg);

            if (num_clips > 0)
            {
                if (dirty_type != 0)
                {
                    if (pGC->lineStyle == LineSolid)
                    {
                        draw_item_add_fill_region(pDirtyPriv, &clip_reg, pGC->fgPixel,
                                                  pGC->alu);
                    }
                    else
                    {
                        draw_item_add_img_region(pDirtyPriv, &clip_reg, GXcopy, dirty_type);
                    }
                }
                else if (got_id)
                {
                    rdpup_begin_update();

                    if (pGC->lineStyle == LineSolid)
                    {
                        rdpup_set_fgcolor(pGC->fgPixel);
                        rdpup_set_opcode(pGC->alu);

                        for (j = num_clips - 1; j >= 0; j--)
                        {
                            box = REGION_RECTS(&clip_reg)[j];
                            rdpup_fill_rect(box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
                        }

                        rdpup_set_opcode(GXcopy);
                    }
                    else
                    {
                        for (j = num_clips - 1; j >= 0; j--)
                        {
                            box = REGION_RECTS(&clip_reg)[j];
                            rdpup_send_area(&id, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
                        }
                    }

                    rdpup_end_update();
                }
            }

            RegionDestroy(fill_reg);
        }
    }

    RegionUninit(&clip_reg);
    g_free(regRects);
    g_free(rect1);

    if (reset_surface)
    {
        rdpup_switch_os_surface(-1);
    }
}
示例#22
0
static int
audin_process_formats(IWTSVirtualChannelCallback * pChannelCallback,
	char * data, uint32 data_size)
{
	AUDIN_CHANNEL_CALLBACK * callback = (AUDIN_CHANNEL_CALLBACK *) pChannelCallback;
	uint32 NumFormats;
	uint32 i;
	int size;
	int out_size;
	char * ldata;
	char * out_data;
	char * lout_formats;
	int out_format_count;
	int error;

	NumFormats = GET_UINT32(data, 0);
	if ((NumFormats < 1) || (NumFormats > 1000))
	{
		LLOGLN(0, ("audin_process_formats: bad NumFormats %d",
			NumFormats));
		return 1;
	}
	/* Ignore cbSizeFormatsPacket */

	size = sizeof(char *) * (NumFormats + 1);
	callback->formats_data = (char **) malloc(size);
	memset(callback->formats_data, 0, size);

	out_size = data_size + 1;
	out_data = (char *) malloc(out_size);
	memset(out_data, 0, out_size);

	lout_formats = out_data + 9;
	/* remainder is sndFormats (variable) */
	ldata = data + 8;
	out_format_count = 0;
	for (i = 0; i < NumFormats; i++)
	{
		size = 18 + GET_UINT16(ldata, 16);
		if (wave_in_format_supported(callback->device_data, ldata, size))
		{
			/* Store the agreed format in the corresponding index */
			callback->formats_data[out_format_count] = (char *) malloc(size);
			memcpy(callback->formats_data[out_format_count], ldata, size);
			/* Put the format to output buffer */
			memcpy(lout_formats, ldata, size);
			lout_formats += size;
			out_format_count++;
		}
		ldata += size;
	}
	callback->formats_count = out_format_count;

	audin_send_incoming_data_pdu(pChannelCallback);

	/* cbSizeFormatsPacket: the size of the entire PDU minus the size of ExtraData */
	size = lout_formats - out_data;	
	SET_UINT8(out_data, 0, MSG_SNDIN_FORMATS);
	SET_UINT32(out_data, 1, out_format_count);
	SET_UINT32(out_data, 5, size);
	error = callback->channel->Write(callback->channel, size, out_data, NULL);
	free(out_data);

	return error;
}
示例#23
0
void rdpPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment *pSegs)
{
	RegionRec clip_reg;
	int cd;
	int i;
	int j;
	int got_id;
	int dirty_type;
	int post_process;
	int reset_surface;
	xSegment *segs;
	BoxRec box;
	struct image_data id;
	WindowPtr pDstWnd;
	PixmapPtr pDstPixmap;
	rdpPixmapRec *pDstPriv;
	rdpPixmapRec *pDirtyPriv;

	LLOGLN(10, ("rdpPolySegment:"));
	LLOGLN(10, ("  nseg %d", nseg));

	segs = 0;

	if (nseg) /* get the rects */
	{
		segs = (xSegment *)g_malloc(nseg * sizeof(xSegment), 0);

		for (i = 0; i < nseg; i++)
		{
			segs[i].x1 = pSegs[i].x1 + pDrawable->x;
			segs[i].y1 = pSegs[i].y1 + pDrawable->y;
			segs[i].x2 = pSegs[i].x2 + pDrawable->x;
			segs[i].y2 = pSegs[i].y2 + pDrawable->y;
		}
	}

	/* do original call */
	rdpPolySegmentOrg(pDrawable, pGC, nseg, pSegs);

	dirty_type = 0;
	pDirtyPriv = 0;
	post_process = 0;
	reset_surface = 0;
	got_id = 0;

	if (pDrawable->type == DRAWABLE_PIXMAP)
	{
		pDstPixmap = (PixmapPtr)pDrawable;
		pDstPriv = GETPIXPRIV(pDstPixmap);

		if (xrdp_is_os(pDstPixmap, pDstPriv))
		{
			post_process = 1;

			if (g_do_dirty_os)
			{
				LLOGLN(10, ("rdpPolySegment: gettig dirty"));
				pDstPriv->is_dirty = 1;
				pDirtyPriv = pDstPriv;
				dirty_type = RDI_IMGLL;
			}
			else
			{
				rdpup_switch_os_surface(pDstPriv->rdpindex);
				reset_surface = 1;
				rdpup_get_pixmap_image_rect(pDstPixmap, &id);
				got_id = 1;
			}
		}
	}
	else
	{
		if (pDrawable->type == DRAWABLE_WINDOW)
		{
			pDstWnd = (WindowPtr)pDrawable;

			if (pDstWnd->viewable)
			{
				post_process = 1;

				if (g_do_dirty_ons)
				{
					LLOGLN(0, ("rdpPolySegment: gettig dirty"));
					g_screenPriv.is_dirty = 1;
					pDirtyPriv = &g_screenPriv;
					dirty_type = RDI_IMGLL;
				}
				else
				{
					rdpup_get_screen_image_rect(&id);
					got_id = 1;
				}
			}
		}
	}

	if (!post_process)
	{
		g_free(segs);
		return;
	}

	RegionInit(&clip_reg, NullBox, 0);
	cd = rdp_get_clip(&clip_reg, pDrawable, pGC);
	LLOGLN(10, ("rdpPolySegment: cd %d", cd));

	if (cd == 1) /* no clip */
	{
		if (segs != 0)
		{
			if (dirty_type != 0)
			{
				RegionUninit(&clip_reg);
				RegionInit(&clip_reg, NullBox, 0);
				RegionAroundSegs(&clip_reg, segs, nseg);
				draw_item_add_line_region(pDirtyPriv, &clip_reg, pGC->fgPixel,
						pGC->alu, pGC->lineWidth, segs, nseg, 1);
			}
			else if (got_id)
			{
				rdpup_begin_update();
				rdpup_set_fgcolor(pGC->fgPixel);
				rdpup_set_opcode(pGC->alu);
				rdpup_set_pen(0, pGC->lineWidth);

				for (i = 0; i < nseg; i++)
				{
					rdpup_draw_line(segs[i].x1, segs[i].y1, segs[i].x2, segs[i].y2);
				}

				rdpup_set_opcode(GXcopy);
				rdpup_end_update();
			}
		}
	}
	else if (cd == 2) /* clip */
	{
		if (segs != 0)
		{
			if (dirty_type != 0)
			{
				draw_item_add_line_region(pDirtyPriv, &clip_reg, pGC->fgPixel,
						pGC->alu, pGC->lineWidth, segs, nseg, 1);
			}
			else if (got_id)
			{
				rdpup_begin_update();
				rdpup_set_fgcolor(pGC->fgPixel);
				rdpup_set_opcode(pGC->alu);
				rdpup_set_pen(0, pGC->lineWidth);

				for (j = REGION_NUM_RECTS(&clip_reg) - 1; j >= 0; j--)
				{
					box = REGION_RECTS(&clip_reg)[j];
					rdpup_set_clip(box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);

					for (i = 0; i < nseg; i++)
					{
						rdpup_draw_line(segs[i].x1, segs[i].y1, segs[i].x2, segs[i].y2);
						LLOGLN(10, ("  %d %d %d %d", segs[i].x1, segs[i].y1,
								segs[i].x2, segs[i].y2));
					}
				}

				rdpup_reset_clip();
				rdpup_set_opcode(GXcopy);
				rdpup_end_update();
			}
		}
	}

	g_free(segs);
	RegionUninit(&clip_reg);

	if (reset_surface)
	{
		rdpup_switch_os_surface(-1);
	}
}
示例#24
0
static int 
clipboard_get_file(char* file, int bytes)
{
    int sindex;
    int pindex;
    int flags;
    char full_fn[256]; /* /etc/xrdp/xrdp.ini */
    char filename[256]; /* xrdp.ini */
    char pathname[256]; /* /etc/xrdp */
    struct cb_file_info *cfi;

    /* x-special/gnome-copied-files */
    if ((g_strncmp(file, "copy", 4) == 0) && (bytes == 4))
    {
        return 0;
    }
    if ((g_strncmp(file, "cut", 3) == 0) && (bytes == 3))
    {
        return 0;
    }
    sindex = 0;
    flags = CB_FILE_ATTRIBUTE_ARCHIVE;
    /* text/uri-list */
    /* x-special/gnome-copied-files */
    if (g_strncmp(file, "file://", 7) == 0)
    {
        sindex = 7;
    }
    pindex = bytes;
    while (pindex > sindex)
    {
        if (file[pindex] == '/')
        {
            break;
        }
        pindex--;
    }
    g_memset(pathname, 0, 256);
    g_memset(filename, 0, 256);
    g_memcpy(pathname, file + sindex, pindex - sindex);
    if (pathname[0] == 0)
    {
        pathname[0] = '/';
    }
    g_memcpy(filename, file + pindex + 1, (bytes - 1) - pindex);
    /* this should replace %20 with space */
    clipboard_check_file(filename);
    g_snprintf(full_fn, 255, "%s/%s", pathname, filename);
    if (g_directory_exist(full_fn))
    {
        LLOGLN(0, ("clipboard_get_file: file [%s] is a directory, "
                   "not supported", full_fn));
        flags |= CB_FILE_ATTRIBUTE_DIRECTORY;
        return 1;
    }
    if (!g_file_exist(full_fn))
    {
        LLOGLN(0, ("clipboard_get_file: file [%s] does not exist",
                   full_fn));
        return 1;
    }
    else
    {
        cfi = (struct cb_file_info*)g_malloc(sizeof(struct cb_file_info), 1);
        list_add_item(g_files_list, (tintptr)cfi);
        g_strcpy(cfi->filename, filename);
        g_strcpy(cfi->pathname, pathname);
        cfi->size = g_file_get_size(full_fn);
        cfi->flags = flags;
        cfi->time = (g_time1() + CB_EPOCH_DIFF) * 10000000LL;
        LLOGLN(10, ("ok filename [%s] pathname [%s] size [%d]",
                    cfi->filename, cfi->pathname, cfi->size));
    }
    return 0;
}
示例#25
0
void
rdpPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrectFill,
                xRectangle* prectInit)
{
  int j;
  int cd;
  int num_clips;
  RegionRec clip_reg;
  RegionPtr fill_reg;
  BoxRec box;

  int got_id;
  struct image_data id;
  WindowPtr pDstWnd;
  PixmapPtr pDstPixmap;
  rdpPixmapRec* pDstPriv;

  LLOGLN(10, ("rdpPolyFillRect:"));

  /* make a copy of rects */
  fill_reg = RegionFromRects(nrectFill, prectInit, CT_NONE);

  /* do original call */
  rdpPolyFillRectOrg(pDrawable, pGC, nrectFill, prectInit);

  got_id = 0;
  if (pDrawable->type == DRAWABLE_PIXMAP)
  {
    pDstPixmap = (PixmapPtr)pDrawable;
    pDstPriv = GETPIXPRIV(pDstPixmap);
    if (XRDP_IS_OS(pDstPriv))
    {
      rdpup_switch_os_surface(pDstPriv->rdpindex);
      rdpup_get_pixmap_image_rect(pDstPixmap, &id);
      got_id = 1;
    }
  }
  else
  {
    if (pDrawable->type == DRAWABLE_WINDOW)
    {
      pDstWnd = (WindowPtr)pDrawable;
      if (pDstWnd->viewable)
      {
        rdpup_get_screen_image_rect(&id);
        got_id = 1;
      }
    }
  }
  if (!got_id)
  {
    RegionDestroy(fill_reg);
    return;
  }
  RegionTranslate(fill_reg, pDrawable->x, pDrawable->y);
  RegionInit(&clip_reg, NullBox, 0);
  cd = rdp_get_clip(&clip_reg, pDrawable, pGC);
  if (cd == 1) /* no clip */
  {
    rdpup_begin_update();
    if (pGC->fillStyle == 0 && /* solid fill */
        (pGC->alu == GXclear ||
         pGC->alu == GXset ||
         pGC->alu == GXinvert ||
         pGC->alu == GXnoop ||
         pGC->alu == GXand ||
         pGC->alu == GXcopy /*||
         pGC->alu == GXxor*/)) /* todo, why dosen't xor work? */
    {
      rdpup_set_fgcolor(pGC->fgPixel);
      rdpup_set_opcode(pGC->alu);
      for (j = REGION_NUM_RECTS(fill_reg) - 1; j >= 0; j--)
      {
        box = REGION_RECTS(fill_reg)[j];
        rdpup_fill_rect(box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
      }
      rdpup_set_opcode(GXcopy);
    }
    else /* non solid fill */
    {
      for (j = REGION_NUM_RECTS(fill_reg) - 1; j >= 0; j--)
      {
        box = REGION_RECTS(fill_reg)[j];
        rdpup_send_area(&id, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
      }
    }
    rdpup_end_update();
  }
  else if (cd == 2) /* clip */
  {
    RegionIntersect(&clip_reg, &clip_reg, fill_reg);
    num_clips = REGION_NUM_RECTS(&clip_reg);
    if (num_clips > 0)
    {
      rdpup_begin_update();
      if (pGC->fillStyle == 0 && /* solid fill */
          (pGC->alu == GXclear ||
           pGC->alu == GXset ||
           pGC->alu == GXinvert ||
           pGC->alu == GXnoop ||
           pGC->alu == GXand ||
           pGC->alu == GXcopy /*||
           pGC->alu == GXxor*/)) /* todo, why dosen't xor work? */
      {
        rdpup_set_fgcolor(pGC->fgPixel);
        rdpup_set_opcode(pGC->alu);
        for (j = num_clips - 1; j >= 0; j--)
        {
          box = REGION_RECTS(&clip_reg)[j];
          rdpup_fill_rect(box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
        }
        rdpup_set_opcode(GXcopy);
      }
      else /* non solid fill */
      {
        for (j = num_clips - 1; j >= 0; j--)
        {
          box = REGION_RECTS(&clip_reg)[j];
          rdpup_send_area(&id, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
        }
      }
      rdpup_end_update();
    }
  }
  RegionUninit(&clip_reg);
  RegionDestroy(fill_reg);
  rdpup_switch_os_surface(-1);
}
示例#26
0
/* response to client asking for clipboard contents that is file list */
int 
clipboard_send_data_response_for_file(char *data, int data_size)
{
    struct stream *s;
    int size;
    int rv;
    int bytes_after_header;
    int cItems;
    int flags;
    int index;
    tui32 ui32;
    char fn[256];
    struct cb_file_info *cfi;

    LLOGLN(10, ("clipboard_send_data_response_for_file: data_size %d",
                data_size));
    //g_hexdump(data, data_size);
    if (g_files_list == 0)
    {
        g_files_list = list_create();
        g_files_list->auto_free = 1;
    }
    list_clear(g_files_list);
    clipboard_get_files(data, data_size);
    cItems = g_files_list->count;
    bytes_after_header = cItems * 592 + 4;
    make_stream(s);
    init_stream(s, 64 + bytes_after_header);
    out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */
    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
    out_uint32_le(s, bytes_after_header);
    out_uint32_le(s, cItems);
    for (index = 0; index < cItems; index++)
    {
        cfi = (struct cb_file_info *)list_get_item(g_files_list, index);
        flags = CB_FD_ATTRIBUTES | CB_FD_FILESIZE | CB_FD_WRITESTIME | CB_FD_PROGRESSUI;
        out_uint32_le(s, flags);
        out_uint8s(s, 32); /* reserved1 */
        flags = cfi->flags;
        out_uint32_le(s, flags);
        out_uint8s(s, 16); /* reserved2 */
        /* file time */
        /* 100-nanoseconds intervals since 1 January 1601 */
        //out_uint32_le(s, 0x2c305d08); /* 25 October 2009, 21:17 */
        //out_uint32_le(s, 0x01ca55f3);
        ui32 = cfi->time & 0xffffffff;
        out_uint32_le(s, ui32);
        ui32 = cfi->time >> 32;
        out_uint32_le(s, ui32);
        /* file size */
        out_uint32_le(s, 0);
        out_uint32_le(s, cfi->size);
        g_snprintf(fn, 255, "%s", cfi->filename);
        clipboard_out_unicode(s, fn, 256);
        out_uint8s(s, 8); /* pad */
    }
    out_uint32_le(s, 0);
    s_mark_end(s);
    size = (int)(s->end - s->data);
    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
    free_stream(s);
    return rv;
}
示例#27
0
PCSC_API LONG
SCardListReaders(SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders,
                 LPDWORD pcchReaders)
{
    char* msg;
    char* reader_names;
    int reader_names_index;
    int code;
    int bytes;
    int num_readers;
    int status;
    int offset;
    int index;
    int bytes_groups;
    int val;
    int llen;
    char reader[100];

    LLOGLN(10, ("SCardListReaders:"));
    LLOGLN(10, ("SCardListReaders: mszGroups %s", mszGroups));
    LLOGLN(10, ("SCardListReaders: *pcchReaders %d", (int)*pcchReaders));
    if (g_sck == -1)
    {
        LLOGLN(0, ("SCardListReaders: error, not connected"));
        return SCARD_F_INTERNAL_ERROR;
    }
    if ((mszGroups == NULL) && (mszReaders == NULL))
    {
        *pcchReaders = 0;
    }
    msg = (char *) malloc(8192);
    offset = 0;
    SET_UINT32(msg, offset, hContext);
    offset += 4;
    bytes_groups = 0;
    if (mszGroups != 0)
    {
        bytes_groups = strlen(mszGroups);
    }
    SET_UINT32(msg, offset, bytes_groups);
    offset += 4;
    memcpy(msg + offset, mszGroups, bytes_groups);
    offset += bytes_groups;
    val = *pcchReaders;
    SET_UINT32(msg, offset, val);
    offset += 4;
    if (send_message(SCARD_LIST_READERS, msg, offset) != 0)
    {
        LLOGLN(0, ("SCardListReaders: error, send_message"));
        free(msg);
        return SCARD_F_INTERNAL_ERROR;
    }
    bytes = 8192;
    code = SCARD_LIST_READERS;
    if (get_message(&code, msg, &bytes) != 0)
    {
        LLOGLN(0, ("SCardListReaders: error, get_message"));
        free(msg);
        return SCARD_F_INTERNAL_ERROR;
    }
    if (code != SCARD_LIST_READERS)
    {
        LLOGLN(0, ("SCardListReaders: error, bad code"));
        free(msg);
        return SCARD_F_INTERNAL_ERROR;
    }
    offset = 0;
    llen = GET_UINT32(msg, offset);
    offset += 4;
    num_readers = GET_UINT32(msg, offset);
    offset += 4;
    LLOGLN(10, ("SCardListReaders: mszReaders %p pcchReaders %p num_readers %d",
           mszReaders, pcchReaders, num_readers));
    reader_names = (char *) malloc(8192);
    reader_names_index = 0;
    for (index = 0; index < num_readers; index++)
    {
        memcpy(reader, msg + offset, 100);
        bytes = strlen(reader);
        memcpy(reader_names + reader_names_index, reader, bytes);
        reader_names_index += bytes;
        reader_names[reader_names_index] = 0;
        reader_names_index++;
        offset += 100;
        LLOGLN(10, ("SCardListReaders: readername %s", reader));
    }
    reader_names[reader_names_index] = 0;
    reader_names_index++;
    status = GET_UINT32(msg, offset);
    LLOGLN(10, ("SCardListReaders: status 0x%8.8x", status));
    offset += 4;
    if (mszReaders == 0)
    {
        reader_names_index = llen / 2;
    }
    if (pcchReaders != 0)
    {
        *pcchReaders = reader_names_index;
    }
    if (mszReaders != 0)
    {
        memcpy(mszReaders, reader_names, reader_names_index);
    }
    free(msg);
    free(reader_names);
    return status;
}
示例#28
0
文件: libxrdp.c 项目: PKRoma/xrdp
int EXPORT_CC
libxrdp_send_palette(struct xrdp_session *session, int *palette)
{
    int rv;
    int i = 0;
    int color = 0;
    struct stream *s = (struct stream *)NULL;

    if (session->client_info->bpp > 8)
    {
        return 0;
    }

    DEBUG(("libxrdp_send_palette sending palette"));

    /* clear orders */
    libxrdp_orders_force_send(session);
    make_stream(s);
    init_stream(s, 8192);

    if (session->client_info->use_fast_path & 1) /* fastpath output supported */
    {
        LLOGLN(10, ("libxrdp_send_palette: fastpath"));
        if (xrdp_rdp_init_fastpath((struct xrdp_rdp *)session->rdp, s) != 0)
        {
            free_stream(s);
            return 1;
        }
    }
    else {
        LLOGLN(10, ("libxrdp_send_palette: slowpath"));
        xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s);
    }

    /* TS_UPDATE_PALETTE_DATA */
    out_uint16_le(s, RDP_UPDATE_PALETTE);
    out_uint16_le(s, 0);
    out_uint16_le(s, 256); /* # of colors */
    out_uint16_le(s, 0);

    for (i = 0; i < 256; i++)
    {
        color = palette[i];
        out_uint8(s, color >> 16);
        out_uint8(s, color >> 8);
        out_uint8(s, color);
    }

    s_mark_end(s);
    if (session->client_info->use_fast_path & 1) /* fastpath output supported */
    {
       if (xrdp_rdp_send_fastpath((struct xrdp_rdp *)session->rdp, s,
                                   FASTPATH_UPDATETYPE_PALETTE) != 0)
       {
           free_stream(s);
           return 1;
       }
    }
    else
    {
       xrdp_rdp_send_data((struct xrdp_rdp *)session->rdp, s,
                           RDP_DATA_PDU_UPDATE);
    }
    free_stream(s);

    /* send the orders palette too */
    rv = libxrdp_orders_init(session);
    if (rv == 0)
    {
        rv = libxrdp_orders_send_palette(session, palette, 0);
    }
    if (rv == 0)
    {
        rv = libxrdp_orders_send(session);
    }
    return rv;
}
示例#29
0
static int
get_message(int *code, char *data, int *bytes)
{
    char header[8];
    int max_bytes;
    int error;
    int recv_rv;
    int max;
    int lcode;
    struct timeval time;
    fd_set rd_set;

    LLOGLN(10, ("get_message:"));
    max = g_sck + 1;
    while (1)
    {
        LLOGLN(10, ("get_message: loop"));
        time.tv_sec = 1;
        time.tv_usec = 0;
        FD_ZERO(&rd_set);
        FD_SET(((unsigned int)g_sck), &rd_set);
        error = select(max, &rd_set, 0, 0, &time);
        if (error == 1)
        {
            pthread_mutex_lock(&g_mutex);
            time.tv_sec = 0;
            time.tv_usec = 0;
            FD_ZERO(&rd_set);
            FD_SET(((unsigned int)g_sck), &rd_set);
            error = select(max, &rd_set, 0, 0, &time);
            if (error == 1)
            {
                /* just take a look at the next message */
                recv_rv = recv(g_sck, header, 8, MSG_PEEK);
                if (recv_rv == 8)
                {
                    lcode = GET_UINT32(header, 4);
                    if (lcode == *code)
                    {
                        /* still have mutex lock */
                        break;
                    }
                    else
                    {
                        LLOGLN(10, ("get_message: lcode %d *code %d",
                               lcode, *code));
                    }
                }
                else if (recv_rv == 0)
                {
                    pthread_mutex_unlock(&g_mutex);
                    LLOGLN(0, ("get_message: recv_rv 0, disconnect"));
                    return 1;
                }
                else
                {
                    LLOGLN(10, ("get_message: recv_rv %d", recv_rv));
                }
            }
            else
            {
                LLOGLN(10, ("get_message: select return %d", error));
            }
            pthread_mutex_unlock(&g_mutex);
            usleep(1000);
        }
    }

    if (recv(g_sck, header, 8, 0) != 8)
    {
        pthread_mutex_unlock(&g_mutex);
        return 1;
    }
    max_bytes = *bytes;
    *bytes = GET_UINT32(header, 0);
    *code = GET_UINT32(header, 4);
    if (*bytes > max_bytes)
    {
        pthread_mutex_unlock(&g_mutex);
        return 1;
    }
    if (recv(g_sck, data, *bytes, 0) != *bytes)
    {
        pthread_mutex_unlock(&g_mutex);
        return 1;
    }
    pthread_mutex_unlock(&g_mutex);
    return 0;
}
示例#30
0
文件: rdpdraw.c 项目: piccolo/xrdp
int
draw_item_pack(PixmapPtr pix, rdpPixmapRec *priv)
{
    struct rdp_draw_item *di;
    struct rdp_draw_item *di_prev;

#if 1

    /* look for repeating draw types */
    if (priv->draw_item_head != 0)
    {
        if (priv->draw_item_head->next != 0)
        {
            di_prev = priv->draw_item_head;
            di = priv->draw_item_head->next;

            while (di != 0)
            {
                if ((di_prev->type == RDI_IMGLL) && (di->type == RDI_IMGLL))
                {
                    LLOGLN(10, ("draw_item_pack: packing RDI_IMGLL"));
                    RegionUnion(di_prev->reg, di_prev->reg, di->reg);
                    draw_item_remove(priv, di);
                    di = di_prev->next;
                }
                else if ((di_prev->type == RDI_IMGLY) && (di->type == RDI_IMGLY))
                {
                    LLOGLN(10, ("draw_item_pack: packing RDI_IMGLY"));
                    RegionUnion(di_prev->reg, di_prev->reg, di->reg);
                    draw_item_remove(priv, di);
                    di = di_prev->next;
                }
                else
                {
                    di_prev = di;
                    di = di_prev->next;
                }
            }
        }
    }

#endif
#if 1

    /* subtract regions */
    if (priv->draw_item_tail != 0)
    {
        if (priv->draw_item_tail->prev != 0)
        {
            di = priv->draw_item_tail;

            while (di->prev != 0)
            {
                /* skip subtract flag
                 * draw items like line can't be used to clear(subtract) previous
                 * draw items since they are not opaque
                 * eg they can not be the 'S' in 'D = M - S'
                 * the region for line draw items is the clip region */
                if ((di->flags & 1) == 0)
                {
                    di_prev = di->prev;

                    while (di_prev != 0)
                    {
                        /* D = M - S */
                        RegionSubtract(di_prev->reg, di_prev->reg, di->reg);
                        di_prev = di_prev->prev;
                    }
                }

                di = di->prev;
            }
        }
    }

#endif
#if 1
    /* remove draw items with empty regions */
    di = priv->draw_item_head;
    di_prev = 0;

    while (di != 0)
    {
        if (!RegionNotEmpty(di->reg))
        {
            LLOGLN(10, ("draw_item_pack: removing empty item type %d", di->type));
            draw_item_remove(priv, di);
            di = di_prev == 0 ? priv->draw_item_head : di_prev->next;
        }
        else
        {
            di_prev = di;
            di = di->next;
        }
    }

#endif
    return 0;
}