diff options
Diffstat (limited to 'xrdpapi')
-rw-r--r-- | xrdpapi/simple.c | 89 | ||||
-rw-r--r-- | xrdpapi/xrdpapi.c | 14 |
2 files changed, 103 insertions, 0 deletions
diff --git a/xrdpapi/simple.c b/xrdpapi/simple.c new file mode 100644 index 00000000..7c7ff576 --- /dev/null +++ b/xrdpapi/simple.c @@ -0,0 +1,89 @@ + + +// xrdp_chan_test.cpp : Basic test for virtual channel use. + +// These headers are required for the windows terminal services calls. +#include "xrdpapi.h" +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> + +#define DSIZE (1024 * 4) + +int main() +{ + + // Initialize the data for send/receive + char* data; + char* data1; + data = (char*)malloc(DSIZE); + data1 = (char*)malloc(DSIZE); + memset(data, 0xca, DSIZE); + memset(data1, 0, DSIZE); + + // Open the skel channel in current session + + void* channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "skel", 0); + + unsigned int written = 0; + // Write the data to the channel + int ret = WTSVirtualChannelWrite(channel, data, DSIZE, &written); + if (!ret) + { + + 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; + } + + printf("Done!\n"); + + usleep(100000); + return 0; +} diff --git a/xrdpapi/xrdpapi.c b/xrdpapi/xrdpapi.c index 8223c3b2..6c4eced0 100644 --- a/xrdpapi/xrdpapi.c +++ b/xrdpapi/xrdpapi.c @@ -19,6 +19,12 @@ /* do not use os_calls in here */ +#define LOG_LEVEL 1 +#define LLOG(_level, _args) \ + do { if (_level < LOG_LEVEL) { ErrorF _args ; } } while (0) +#define LLOGLN(_level, _args) \ + do { if (_level < LOG_LEVEL) { printf _args ; printf("\n"); } } while (0) + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -152,6 +158,7 @@ send_init(struct wts_obj* wts) memset(initmsg, 0, 64); strncpy(initmsg, wts->name, 8); + LLOGLN(10, ("send_init: sending %s", initmsg)); if (!can_send(wts->fd, 500)) { return 1; @@ -160,6 +167,7 @@ send_init(struct wts_obj* wts) { return 1; } + LLOGLN(10, ("send_init: send ok!")); return 0; } @@ -177,6 +185,7 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, if (SessionId != WTS_CURRENT_SESSION) { + LLOGLN(0, ("WTSVirtualChannelOpenEx: SessionId bad")); return 0; } wts = (struct wts_obj*)malloc(sizeof(struct wts_obj)); @@ -203,6 +212,7 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, 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) @@ -212,6 +222,10 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, } } } + else + { + LLOGLN(0, ("WTSVirtualChannelOpenEx: display is 0")); + } return wts; } |