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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Manuel Mausz (manuel@mausz.at)
* Christian Raschko (c.raschko@netcore.at)
*/
//Header guard
#ifndef TSQUERY_H
#define TSQUERY_H
//Libraries
#include <wx/wx.h>
#include <wx/socket.h>
#include <wx/xml2.h>
#include "tsheaders.h"
//! TSQuery
/*! TSQuery
*/
class TSQueryThread : public wxThread
{
DECLARE_CLASS(TSQueryThread)
public:
/*! thread execution starts here
* \return Returns ExitCode.
*/
virtual ExitCode Entry();
/*! and stops here
*/
virtual void OnExit();
/*! Default CTor, Initializes the object.
* Creates all necessary member objects.
*/
TSQueryThread(TSClient *client);
/*! Default DTor.
*/
~TSQueryThread();
/*! Sets the password for incomming connections.
* \param str Password string.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool SetPassword(wxString const &str);
/*! Sets the allowed Addresses.
* You can use either an IP or an URL, seperate with ','
* \param str Server address string.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool SetAllowedAddresses(wxString const &str);
/*! Start thread.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool Start();
/*! Stop thread.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool Stop();
/*! Sets the server address.
* You can use either an IP or an URL.
* \param str Server address string.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool SetServerAddress(wxString const &str);
/*! Sets the connection port.
* \param port Connection port.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool SetPort(wxUint16 const &port);
/*! Listen for incomming connections.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool Accept();
/*! Dumps object.
* \param ostrm Stream to write.
*/
void Dump(wxOutputStream &ostrm) const;
/*! Gets the server Address.
* \return Returns the current password.
*/
wxString const &GetServerAddress() const
{
return m_ServerAddress;
}
/*! Gets the password for incomming connections.
* \return Returns the current password.
*/
wxString const &GetPassword() const
{
return m_Password;
}
/*! Gets the allowed addresses for incomming connections.
* \return Returns the allowed addresses.
*/
wxString const &GetAllowedAddresses() const
{
return m_AllowedAddresses;
}
/*! Gets the port for incomming connections.
* \return Returns the current port.
*/
wxUint16 const &GetPort() const
{
return m_Port;
}
/*! Gets the LastError message, call this method
* to get more information for an error.
* \return LastError message.
*/
wxString const &GetLastError() const
{
return m_LastError;
}
private:
bool CmdGetStatus(wxSocketBase *sock);
bool CmdGetChannels(wxSocketBase *sock);
bool CmdGetUsers(wxSocketBase *sock);
bool CmdCreateChannel(wxSocketBase *sock);
bool CmdDeleteChannel(wxSocketBase *sock);
bool CmdModifyChannel(wxSocketBase *sock);
bool CmdMoveUser(wxSocketBase *sock);
bool CmdKickUser(wxSocketBase *sock);
bool CmdKill(wxSocketBase *sock);
bool SendDOM(wxSocketBase *sock);
bool ProcessCommand(wxSocketBase *sock);
bool SendError(wxString const &cmd, wxString const &str, wxSocketBase *sock);
bool IsIPAllowed(wxString const &str);
bool IsValidFormat();
wxString GetNodeValue(wxXml2Node &pElemRoot, wxString const &str);
//Sets the LastError message.
void SetLastError(wxString const &str)
{
m_LastError = str;
}
//Members
wxString m_LastError;
wxString m_AllowedAddresses;
wxString m_Password;
wxSocketServer *m_pSocket;
wxIPV4address m_ServerAddr;
TSClient *m_pClient;
wxXml2Document m_pXml;
wxUint16 m_Port;
wxString m_ServerAddress;
};
#endif
|