summaryrefslogtreecommitdiffstats
path: root/xrdpapi/simple.c
blob: 7f309ab8e357d6121670df4b57ef03690744c4b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
 * 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.
 */

/*
 * 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
    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

    //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)
    {

        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;
}