o moved from GNU General Public License to Apache License, Version 2.0
o applied new coding standards to all .c files o moved some files around
This commit is contained in:
+97
-72
@@ -1,6 +1,24 @@
|
||||
/**
|
||||
* xrdp: A Remote Desktop Protocol server.
|
||||
*
|
||||
* Copyright (C) Jay Sorg 2004-2012
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
// xrdp_chan_test.cpp : Basic test for virtual channel use.
|
||||
/*
|
||||
* Basic test for virtual channel use
|
||||
*/
|
||||
|
||||
// These headers are required for the windows terminal services calls.
|
||||
#include "xrdpapi.h"
|
||||
@@ -15,80 +33,87 @@
|
||||
int main()
|
||||
{
|
||||
|
||||
// Initialize the data for send/receive
|
||||
void* hFile;
|
||||
char* data;
|
||||
char* data1;
|
||||
data = (char*)malloc(DSIZE);
|
||||
data1 = (char*)malloc(DSIZE);
|
||||
int ret;
|
||||
void* vcFileHandlePtr = NULL;
|
||||
memset(data, 0xca, DSIZE);
|
||||
memset(data1, 0, DSIZE);
|
||||
unsigned int written = 0;
|
||||
// Initialize the data for send/receive
|
||||
void *hFile;
|
||||
char *data;
|
||||
char *data1;
|
||||
data = (char *)malloc(DSIZE);
|
||||
data1 = (char *)malloc(DSIZE);
|
||||
int ret;
|
||||
void *vcFileHandlePtr = NULL;
|
||||
memset(data, 0xca, DSIZE);
|
||||
memset(data1, 0, DSIZE);
|
||||
unsigned int written = 0;
|
||||
|
||||
// Open the skel channel in current session
|
||||
// Open the skel channel in current session
|
||||
|
||||
//void* channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "skel", 0);
|
||||
void* channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "TSMF", WTS_CHANNEL_OPTION_DYNAMIC);
|
||||
ret = WTSVirtualChannelQuery(channel, WTSVirtualFileHandle, vcFileHandlePtr, &written);
|
||||
//void* channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "skel", 0);
|
||||
void *channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "TSMF", WTS_CHANNEL_OPTION_DYNAMIC);
|
||||
ret = WTSVirtualChannelQuery(channel, WTSVirtualFileHandle, vcFileHandlePtr, &written);
|
||||
|
||||
// Write the data to the channel
|
||||
ret = WTSVirtualChannelWrite(channel, data, DSIZE, &written);
|
||||
if (!ret)
|
||||
{
|
||||
// Write the data to the channel
|
||||
ret = WTSVirtualChannelWrite(channel, data, DSIZE, &written);
|
||||
|
||||
long err = errno;
|
||||
printf("error 1 0x%8.8x\n", err);
|
||||
usleep(100000);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Sent bytes!\n");
|
||||
}
|
||||
if (written != DSIZE)
|
||||
{
|
||||
long err = errno;
|
||||
printf("error 2 0x%8.8x\n", err);
|
||||
usleep(100000);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Read bytes!\n");
|
||||
}
|
||||
ret = WTSVirtualChannelRead(channel, 100, data1, DSIZE, &written);
|
||||
if (!ret)
|
||||
{
|
||||
long err = errno;
|
||||
printf("error 3 0x%8.8x\n", err);
|
||||
usleep(100000);
|
||||
return 1;
|
||||
}
|
||||
if (written != DSIZE)
|
||||
{
|
||||
long err = errno;
|
||||
printf("error 4 0x%8.8x\n", err);
|
||||
usleep(100000);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Read bytes!\n");
|
||||
}
|
||||
ret = WTSVirtualChannelClose(channel);
|
||||
if (memcmp(data, data1, DSIZE) == 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("error data no match\n");
|
||||
return 1;
|
||||
}
|
||||
if (!ret)
|
||||
{
|
||||
|
||||
printf("Done!\n");
|
||||
long err = errno;
|
||||
printf("error 1 0x%8.8x\n", err);
|
||||
usleep(100000);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Sent bytes!\n");
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
return 0;
|
||||
if (written != DSIZE)
|
||||
{
|
||||
long err = errno;
|
||||
printf("error 2 0x%8.8x\n", err);
|
||||
usleep(100000);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Read bytes!\n");
|
||||
}
|
||||
|
||||
ret = WTSVirtualChannelRead(channel, 100, data1, DSIZE, &written);
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
long err = errno;
|
||||
printf("error 3 0x%8.8x\n", err);
|
||||
usleep(100000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (written != DSIZE)
|
||||
{
|
||||
long err = errno;
|
||||
printf("error 4 0x%8.8x\n", err);
|
||||
usleep(100000);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Read bytes!\n");
|
||||
}
|
||||
|
||||
ret = WTSVirtualChannelClose(channel);
|
||||
|
||||
if (memcmp(data, data1, DSIZE) == 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("error data no match\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Done!\n");
|
||||
|
||||
usleep(100000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+298
-260
@@ -21,9 +21,9 @@
|
||||
|
||||
#define LOG_LEVEL 1
|
||||
#define LLOG(_level, _args) \
|
||||
do { if (_level < LOG_LEVEL) { ErrorF _args ; } } while (0)
|
||||
do { if (_level < LOG_LEVEL) { ErrorF _args ; } } while (0)
|
||||
#define LLOGLN(_level, _args) \
|
||||
do { if (_level < LOG_LEVEL) { printf _args ; printf("\n"); } } while (0)
|
||||
do { if (_level < LOG_LEVEL) { printf _args ; printf("\n"); } } while (0)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -40,344 +40,382 @@
|
||||
|
||||
struct wts_obj
|
||||
{
|
||||
int fd;
|
||||
int status;
|
||||
char name[8];
|
||||
char dname[128];
|
||||
int display_num;
|
||||
int flags;
|
||||
int fd;
|
||||
int status;
|
||||
char name[8];
|
||||
char dname[128];
|
||||
int display_num;
|
||||
int flags;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
static int
|
||||
get_display_num_from_display(char* display_text)
|
||||
get_display_num_from_display(char *display_text)
|
||||
{
|
||||
int index;
|
||||
int mode;
|
||||
int host_index;
|
||||
int disp_index;
|
||||
int scre_index;
|
||||
char host[256];
|
||||
char disp[256];
|
||||
char scre[256];
|
||||
int index;
|
||||
int mode;
|
||||
int host_index;
|
||||
int disp_index;
|
||||
int scre_index;
|
||||
char host[256];
|
||||
char disp[256];
|
||||
char scre[256];
|
||||
|
||||
index = 0;
|
||||
host_index = 0;
|
||||
disp_index = 0;
|
||||
scre_index = 0;
|
||||
mode = 0;
|
||||
while (display_text[index] != 0)
|
||||
{
|
||||
if (display_text[index] == ':')
|
||||
index = 0;
|
||||
host_index = 0;
|
||||
disp_index = 0;
|
||||
scre_index = 0;
|
||||
mode = 0;
|
||||
|
||||
while (display_text[index] != 0)
|
||||
{
|
||||
mode = 1;
|
||||
if (display_text[index] == ':')
|
||||
{
|
||||
mode = 1;
|
||||
}
|
||||
else if (display_text[index] == '.')
|
||||
{
|
||||
mode = 2;
|
||||
}
|
||||
else if (mode == 0)
|
||||
{
|
||||
host[host_index] = display_text[index];
|
||||
host_index++;
|
||||
}
|
||||
else if (mode == 1)
|
||||
{
|
||||
disp[disp_index] = display_text[index];
|
||||
disp_index++;
|
||||
}
|
||||
else if (mode == 2)
|
||||
{
|
||||
scre[scre_index] = display_text[index];
|
||||
scre_index++;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
else if (display_text[index] == '.')
|
||||
{
|
||||
mode = 2;
|
||||
}
|
||||
else if (mode == 0)
|
||||
{
|
||||
host[host_index] = display_text[index];
|
||||
host_index++;
|
||||
}
|
||||
else if (mode == 1)
|
||||
{
|
||||
disp[disp_index] = display_text[index];
|
||||
disp_index++;
|
||||
}
|
||||
else if (mode == 2)
|
||||
{
|
||||
scre[scre_index] = display_text[index];
|
||||
scre_index++;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
host[host_index] = 0;
|
||||
disp[disp_index] = 0;
|
||||
scre[scre_index] = 0;
|
||||
return atoi(disp);
|
||||
|
||||
host[host_index] = 0;
|
||||
disp[disp_index] = 0;
|
||||
scre[scre_index] = 0;
|
||||
return atoi(disp);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void*
|
||||
WTSVirtualChannelOpen(void* hServer, unsigned int SessionId,
|
||||
const char* pVirtualName)
|
||||
void *
|
||||
WTSVirtualChannelOpen(void *hServer, unsigned int SessionId,
|
||||
const char *pVirtualName)
|
||||
{
|
||||
if (hServer != WTS_CURRENT_SERVER_HANDLE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return WTSVirtualChannelOpenEx(SessionId, pVirtualName, 0);
|
||||
if (hServer != WTS_CURRENT_SERVER_HANDLE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return WTSVirtualChannelOpenEx(SessionId, pVirtualName, 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
static int
|
||||
can_send(int sck, int millis)
|
||||
{
|
||||
struct timeval time;
|
||||
fd_set wfds;
|
||||
int select_rv;
|
||||
struct timeval time;
|
||||
fd_set wfds;
|
||||
int select_rv;
|
||||
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(sck, &wfds);
|
||||
time.tv_sec = millis / 1000;
|
||||
time.tv_usec = (millis * 1000) % 1000000;
|
||||
select_rv = select(sck + 1, 0, &wfds, 0, &time);
|
||||
if (select_rv > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(sck, &wfds);
|
||||
time.tv_sec = millis / 1000;
|
||||
time.tv_usec = (millis * 1000) % 1000000;
|
||||
select_rv = select(sck + 1, 0, &wfds, 0, &time);
|
||||
|
||||
if (select_rv > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
static int
|
||||
can_recv(int sck, int millis)
|
||||
{
|
||||
struct timeval time;
|
||||
fd_set rfds;
|
||||
int select_rv;
|
||||
struct timeval time;
|
||||
fd_set rfds;
|
||||
int select_rv;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(sck, &rfds);
|
||||
time.tv_sec = millis / 1000;
|
||||
time.tv_usec = (millis * 1000) % 1000000;
|
||||
select_rv = select(sck + 1, &rfds, 0, 0, &time);
|
||||
if (select_rv > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(sck, &rfds);
|
||||
time.tv_sec = millis / 1000;
|
||||
time.tv_usec = (millis * 1000) % 1000000;
|
||||
select_rv = select(sck + 1, &rfds, 0, 0, &time);
|
||||
|
||||
if (select_rv > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
static int
|
||||
send_init(struct wts_obj* wts)
|
||||
send_init(struct wts_obj *wts)
|
||||
{
|
||||
char initmsg[64];
|
||||
char initmsg[64];
|
||||
|
||||
memset(initmsg, 0, 64);
|
||||
strncpy(initmsg, wts->name, 8);
|
||||
initmsg[16] = (wts->flags >> 0) & 0xff;
|
||||
initmsg[17] = (wts->flags >> 8) & 0xff;
|
||||
initmsg[18] = (wts->flags >> 16) & 0xff;
|
||||
initmsg[19] = (wts->flags >> 24) & 0xff;
|
||||
LLOGLN(10, ("send_init: sending %s", initmsg));
|
||||
if (!can_send(wts->fd, 500))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (send(wts->fd, initmsg, 64, 0) != 64)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
LLOGLN(10, ("send_init: send ok!"));
|
||||
return 0;
|
||||
memset(initmsg, 0, 64);
|
||||
strncpy(initmsg, wts->name, 8);
|
||||
initmsg[16] = (wts->flags >> 0) & 0xff;
|
||||
initmsg[17] = (wts->flags >> 8) & 0xff;
|
||||
initmsg[18] = (wts->flags >> 16) & 0xff;
|
||||
initmsg[19] = (wts->flags >> 24) & 0xff;
|
||||
LLOGLN(10, ("send_init: sending %s", initmsg));
|
||||
|
||||
if (!can_send(wts->fd, 500))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (send(wts->fd, initmsg, 64, 0) != 64)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
LLOGLN(10, ("send_init: send ok!"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void*
|
||||
void *
|
||||
WTSVirtualChannelOpenEx(unsigned int SessionId,
|
||||
const char* pVirtualName,
|
||||
const char *pVirtualName,
|
||||
unsigned int flags)
|
||||
{
|
||||
struct wts_obj* wts;
|
||||
char* display_text;
|
||||
struct sockaddr_un s;
|
||||
int bytes;
|
||||
unsigned long llong;
|
||||
struct wts_obj *wts;
|
||||
char *display_text;
|
||||
struct sockaddr_un s;
|
||||
int bytes;
|
||||
unsigned long llong;
|
||||
|
||||
if (SessionId != WTS_CURRENT_SESSION)
|
||||
{
|
||||
LLOGLN(0, ("WTSVirtualChannelOpenEx: SessionId bad"));
|
||||
return 0;
|
||||
}
|
||||
wts = (struct wts_obj*)malloc(sizeof(struct wts_obj));
|
||||
memset(wts, 0, sizeof(struct wts_obj));
|
||||
wts->fd = -1;
|
||||
wts->flags = flags;
|
||||
display_text = getenv("DISPLAY");
|
||||
if (display_text != 0)
|
||||
{
|
||||
wts->display_num = get_display_num_from_display(display_text);
|
||||
}
|
||||
if (wts->display_num > 0)
|
||||
{
|
||||
wts->fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
/* set non blocking */
|
||||
llong = fcntl(wts->fd, F_GETFL);
|
||||
llong = llong | O_NONBLOCK;
|
||||
fcntl(wts->fd, F_SETFL, llong);
|
||||
/* connect to session chansrv */
|
||||
memset(&s, 0, sizeof(struct sockaddr_un));
|
||||
s.sun_family = AF_UNIX;
|
||||
bytes = sizeof(s.sun_path);
|
||||
snprintf(s.sun_path, bytes - 1, "/tmp/.xrdp/xrdpapi_%d", wts->display_num);
|
||||
s.sun_path[bytes - 1] = 0;
|
||||
bytes = sizeof(struct sockaddr_un);
|
||||
if (connect(wts->fd, (struct sockaddr*)&s, bytes) == 0)
|
||||
if (SessionId != WTS_CURRENT_SESSION)
|
||||
{
|
||||
LLOGLN(10, ("WTSVirtualChannelOpenEx: connected ok, name %s", pVirtualName));
|
||||
strncpy(wts->name, pVirtualName, 8);
|
||||
/* wait for connection to complete and send init */
|
||||
if (send_init(wts) == 0)
|
||||
{
|
||||
/* all ok */
|
||||
wts->status = 1;
|
||||
}
|
||||
LLOGLN(0, ("WTSVirtualChannelOpenEx: SessionId bad"));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LLOGLN(0, ("WTSVirtualChannelOpenEx: display is 0"));
|
||||
}
|
||||
return wts;
|
||||
|
||||
wts = (struct wts_obj *)malloc(sizeof(struct wts_obj));
|
||||
memset(wts, 0, sizeof(struct wts_obj));
|
||||
wts->fd = -1;
|
||||
wts->flags = flags;
|
||||
display_text = getenv("DISPLAY");
|
||||
|
||||
if (display_text != 0)
|
||||
{
|
||||
wts->display_num = get_display_num_from_display(display_text);
|
||||
}
|
||||
|
||||
if (wts->display_num > 0)
|
||||
{
|
||||
wts->fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
/* set non blocking */
|
||||
llong = fcntl(wts->fd, F_GETFL);
|
||||
llong = llong | O_NONBLOCK;
|
||||
fcntl(wts->fd, F_SETFL, llong);
|
||||
/* connect to session chansrv */
|
||||
memset(&s, 0, sizeof(struct sockaddr_un));
|
||||
s.sun_family = AF_UNIX;
|
||||
bytes = sizeof(s.sun_path);
|
||||
snprintf(s.sun_path, bytes - 1, "/tmp/.xrdp/xrdpapi_%d", wts->display_num);
|
||||
s.sun_path[bytes - 1] = 0;
|
||||
bytes = sizeof(struct sockaddr_un);
|
||||
|
||||
if (connect(wts->fd, (struct sockaddr *)&s, bytes) == 0)
|
||||
{
|
||||
LLOGLN(10, ("WTSVirtualChannelOpenEx: connected ok, name %s", pVirtualName));
|
||||
strncpy(wts->name, pVirtualName, 8);
|
||||
|
||||
/* wait for connection to complete and send init */
|
||||
if (send_init(wts) == 0)
|
||||
{
|
||||
/* all ok */
|
||||
wts->status = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LLOGLN(0, ("WTSVirtualChannelOpenEx: display is 0"));
|
||||
}
|
||||
|
||||
return wts;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
WTSVirtualChannelWrite(void* hChannelHandle, const char* Buffer,
|
||||
unsigned int Length, unsigned int* pBytesWritten)
|
||||
WTSVirtualChannelWrite(void *hChannelHandle, const char *Buffer,
|
||||
unsigned int Length, unsigned int *pBytesWritten)
|
||||
{
|
||||
struct wts_obj* wts;
|
||||
int error;
|
||||
int lerrno;
|
||||
struct wts_obj *wts;
|
||||
int error;
|
||||
int lerrno;
|
||||
|
||||
wts = (struct wts_obj*)hChannelHandle;
|
||||
if (wts == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (wts->status != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (can_send(wts->fd, 0))
|
||||
{
|
||||
error = send(wts->fd, Buffer, Length, 0);
|
||||
if (error == -1)
|
||||
wts = (struct wts_obj *)hChannelHandle;
|
||||
|
||||
if (wts == 0)
|
||||
{
|
||||
lerrno = errno;
|
||||
if ((lerrno == EWOULDBLOCK) || (lerrno == EAGAIN) ||
|
||||
(lerrno == EINPROGRESS))
|
||||
{
|
||||
*pBytesWritten = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
else if (error == 0)
|
||||
|
||||
if (wts->status != 1)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
else if (error > 0)
|
||||
|
||||
if (can_send(wts->fd, 0))
|
||||
{
|
||||
*pBytesWritten = error;
|
||||
return 1;
|
||||
error = send(wts->fd, Buffer, Length, 0);
|
||||
|
||||
if (error == -1)
|
||||
{
|
||||
lerrno = errno;
|
||||
|
||||
if ((lerrno == EWOULDBLOCK) || (lerrno == EAGAIN) ||
|
||||
(lerrno == EINPROGRESS))
|
||||
{
|
||||
*pBytesWritten = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (error == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (error > 0)
|
||||
{
|
||||
*pBytesWritten = error;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*pBytesWritten = 0;
|
||||
return 1;
|
||||
|
||||
*pBytesWritten = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
WTSVirtualChannelRead(void* hChannelHandle, unsigned int TimeOut,
|
||||
char* Buffer, unsigned int BufferSize,
|
||||
unsigned int* pBytesRead)
|
||||
WTSVirtualChannelRead(void *hChannelHandle, unsigned int TimeOut,
|
||||
char *Buffer, unsigned int BufferSize,
|
||||
unsigned int *pBytesRead)
|
||||
{
|
||||
struct wts_obj* wts;
|
||||
int error;
|
||||
int lerrno;
|
||||
struct wts_obj *wts;
|
||||
int error;
|
||||
int lerrno;
|
||||
|
||||
wts = (struct wts_obj*)hChannelHandle;
|
||||
if (wts == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (wts->status != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (can_recv(wts->fd, TimeOut))
|
||||
{
|
||||
error = recv(wts->fd, Buffer, BufferSize, 0);
|
||||
if (error == -1)
|
||||
wts = (struct wts_obj *)hChannelHandle;
|
||||
|
||||
if (wts == 0)
|
||||
{
|
||||
lerrno = errno;
|
||||
if ((lerrno == EWOULDBLOCK) || (lerrno == EAGAIN) ||
|
||||
(lerrno == EINPROGRESS))
|
||||
{
|
||||
*pBytesRead = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
else if (error == 0)
|
||||
|
||||
if (wts->status != 1)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
else if (error > 0)
|
||||
|
||||
if (can_recv(wts->fd, TimeOut))
|
||||
{
|
||||
*pBytesRead = error;
|
||||
return 1;
|
||||
error = recv(wts->fd, Buffer, BufferSize, 0);
|
||||
|
||||
if (error == -1)
|
||||
{
|
||||
lerrno = errno;
|
||||
|
||||
if ((lerrno == EWOULDBLOCK) || (lerrno == EAGAIN) ||
|
||||
(lerrno == EINPROGRESS))
|
||||
{
|
||||
*pBytesRead = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (error == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (error > 0)
|
||||
{
|
||||
*pBytesRead = error;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*pBytesRead = 0;
|
||||
return 1;
|
||||
|
||||
*pBytesRead = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
WTSVirtualChannelClose(void* hChannelHandle)
|
||||
WTSVirtualChannelClose(void *hChannelHandle)
|
||||
{
|
||||
struct wts_obj* wts;
|
||||
struct wts_obj *wts;
|
||||
|
||||
wts = (struct wts_obj*)hChannelHandle;
|
||||
if (wts == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (wts->fd != -1)
|
||||
{
|
||||
close(wts->fd);
|
||||
}
|
||||
free(wts);
|
||||
return 1;
|
||||
wts = (struct wts_obj *)hChannelHandle;
|
||||
|
||||
if (wts == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (wts->fd != -1)
|
||||
{
|
||||
close(wts->fd);
|
||||
}
|
||||
|
||||
free(wts);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
WTSVirtualChannelQuery(void* hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
|
||||
void** ppBuffer, unsigned int* pBytesReturned)
|
||||
WTSVirtualChannelQuery(void *hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
|
||||
void **ppBuffer, unsigned int *pBytesReturned)
|
||||
{
|
||||
struct wts_obj* wts;
|
||||
struct wts_obj *wts;
|
||||
|
||||
wts = (struct wts_obj*)hChannelHandle;
|
||||
if (wts == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (wts->status != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (WtsVirtualClass == WTSVirtualFileHandle)
|
||||
{
|
||||
*pBytesReturned = 4;
|
||||
*ppBuffer = malloc(4);
|
||||
memcpy(*ppBuffer, &(wts->fd), 4);
|
||||
}
|
||||
return 1;
|
||||
wts = (struct wts_obj *)hChannelHandle;
|
||||
|
||||
if (wts == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (wts->status != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (WtsVirtualClass == WTSVirtualFileHandle)
|
||||
{
|
||||
*pBytesReturned = 4;
|
||||
*ppBuffer = malloc(4);
|
||||
memcpy(*ppBuffer, &(wts->fd), 4);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void
|
||||
WTSFreeMemory(void* pMemory)
|
||||
WTSFreeMemory(void *pMemory)
|
||||
{
|
||||
if (pMemory != 0)
|
||||
{
|
||||
free(pMemory);
|
||||
}
|
||||
if (pMemory != 0)
|
||||
{
|
||||
free(pMemory);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -16,10 +16,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
xrdpapi header, do not use os_calls.h, arch.h or any xrdp internal headers
|
||||
this file is included in 3rd party apps
|
||||
*/
|
||||
* xrdpapi header, do not use os_calls.h, arch.h or any xrdp internal headers
|
||||
* this file is included in 3rd party apps
|
||||
*/
|
||||
|
||||
#if !defined(XRDPAPI_H_)
|
||||
#define XRDPAPI_H_
|
||||
|
||||
Reference in New Issue
Block a user