summaryrefslogtreecommitdiffstats
path: root/tcutils/utils.h
blob: f0512dc0fedcce5119fa5873ea6189504c257f94 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef UTILS_H
#define UTILS_H

#include <QDebug>
#include <QListWidgetItem>
#include <QMessageBox>
#include <QStatusBar>
#include <xrdpapi.h>

/*
 * stream definition and macros to access them;
 * all definitions default to little endian
 */

typedef struct stream
{
    char* data;    /* holds stream data           */
    char* pos;     /* current read/write position */
    int   size;    /* number of bytes in data     */
} STREAM;

#define qstream_new(_s, _size)                 \
do                                             \
{                                              \
    (_s).data = (char *) malloc(_size);        \
    (_s).pos = (_s).data;                      \
    (_s).size = (_size);                       \
}                                              \
while (0)

#define qstream_new_zero(_s, _size)            \
do                                             \
{                                              \
    (_s).data = (char *) calloc((_size), 1);   \
    (_s).pos = (_s).data;                      \
    (_s).size = (_size);                       \
}                                              \
while (0)

#define qstream_free(_s)              \
do                                    \
{                                     \
    if ((_s)->data)                   \
        free((_s)->data);             \
}                                     \
while (0)

#define qstream_set_pos(_s, _p)       \
do                                    \
{                                     \
    (_s)->pos = (_s)->data + (_p);    \
}                                     \
while (0)

#define qstream_inc_pos(_s, _v)       \
do                                    \
{                                     \
    (_s)->pos += (_v);                \
}                                     \
while (0)

#define qstream_rd_u8(_s, _v)                \
do                                           \
{                                            \
    (_v) = *((unsigned char *) ((_s)->pos)); \
    (_s)->pos++;                             \
}                                            \
while (0)

#define qstream_rd_u16(_s, _v)                        \
do                                                    \
{                                                     \
    (_v) = (unsigned short)                           \
    (                                                 \
        (*((unsigned char *) ((_s)->pos + 0)) << 0) | \
        (*((unsigned char *) ((_s)->pos + 1)) << 8)   \
    );                                                \
    (_s)->pos += 2;                                   \
} while (0)

#define qstream_rd_u32(_s, _v)                          \
do                                                      \
{                                                       \
    (_v) = (unsigned int)                               \
    (                                                   \
        (*((unsigned char *) ((_s)->pos + 0)) << 0)  |  \
        (*((unsigned char *) ((_s)->pos + 1)) << 8)  |  \
        (*((unsigned char *) ((_s)->pos + 2)) << 16) |  \
        (*((unsigned char *) ((_s)->pos + 3)) << 24)    \
    );                                                  \
    (_s)->pos += 4;                                     \
} while (0)

#define qstream_wr_u8(_s, _v)                           \
do                                                      \
{                                                       \
    *((_s)->pos) = (unsigned char) (_v);                \
    (_s)->pos++;                                        \
} while (0)

#define qstream_wr_u16(_s, _v)                          \
do                                                      \
{                                                       \
    *((_s)->pos) = (unsigned char) ((_v) >> 0);         \
    (_s)->pos++;                                        \
    *((_s)->pos) = (unsigned char) ((_v) >> 8);         \
    (_s)->pos++;                                        \
} while (0)

#define qstream_wr_u32(_s, _v)                          \
do                                                      \
{                                                       \
  *((_s)->pos) = (unsigned char) ((_v) >> 0);           \
  (_s)->pos++;                                          \
  *((_s)->pos) = (unsigned char) ((_v) >> 8);           \
  (_s)->pos++;                                          \
  *((_s)->pos) = (unsigned char) ((_v) >> 16);          \
  (_s)->pos++;                                          \
  *((_s)->pos) = (unsigned char) ((_v) >> 24);          \
  (_s)->pos++;                                          \
} while (0)

/* list of commands we support; this list should match the one in */
/* NeutrinoRDP channels/tcutils/tcutils_main.h                    */
enum TCU_COMMANDS
{
    TCU_CMD_GET_MOUNT_LIST = 1,
    TCU_CMD_UNMOUNT_DEVICE
};

/* umount error codes */
enum TCU_UMOUNT_ERROR
{
    UMOUNT_SUCCESS = 0,
    UMOUNT_BUSY,
    UMOUNT_NOT_MOUNTED,
    UMOUNT_OP_NOT_PERMITTED,
    UMOUNT_PERMISSION_DENIED,
    UMOUNT_UNKNOWN
};

class Utils
{
public:
    Utils();
    static int getMountList(void *wtsChannel, QList<QListWidgetItem *> *itemList);
    static int unmountDevice(void *wtsChannel, QString device, QStatusBar *statusBar);
};

#endif // UTILS_H