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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
//This file is part of HTTPServer a Miranda IM plugin
//Copyright (C)2002 Kennet Nielsen
//
//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; either
//version 2 of the License, or (at your option) any later version.
//
//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., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "Glob.h"
CLFileShareNode * pclFirstNode = NULL;
mir_cs csFileShareListAccess;
/////////////////////////////////////////////////////////////////////
// Member Function : CLShareUser
// Type : Private / Public / Protected
// Parameters : None
// Returns :
// Description :
//
// References : -
// Remarks : -
// Created : 030918, 18 september 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
CLShareUser::CLShareUser(HANDLE hCon, in_addr stAdd) {
hConnection = hCon;
stAddr = stAdd;
pclNext = NULL;
dwTotalSize = 0;
dwCurrentDL = 0;
dwSpeed = 0;
}
/////////////////////////////////////////////////////////////////////
// Member Function : ~CLShareUser
// Type : Private / Public / Protected
// Parameters : None
// Returns :
// Description :
//
// References : -
// Remarks : -
// Created : 031124, 24 november 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
CLShareUser::~CLShareUser() {
if (hConnection) {
CloseSocket();
Netlib_CloseHandle(hConnection);
}
}
/////////////////////////////////////////////////////////////////////
// Member Function : CloseSend
// Type : Private / Public / Protected
// Parameters : None
// Returns : void
// Description :
//
// References : -
// Remarks : -
// Created : 031124, 24 november 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
void CLShareUser::CloseSocket() {
SOCKET s = CallService(MS_NETLIB_GETSOCKET, (WPARAM) hConnection, 0);
if (s != INVALID_SOCKET) {
shutdown(s, SD_SEND);
int nBytesRead;
do {
char szBuf[100];
nBytesRead = Netlib_Recv(hConnection, szBuf, sizeof(szBuf), 0);
} while (nBytesRead && nBytesRead != SOCKET_ERROR);
//shutdown( s, SD_RECEIVE );
}
}
/////////////////////////////////////////////////////////////////////
// Member Function : dwGetDownloadSpeed
// Type : Private / Public / Protected
// Parameters : None
// Returns : DWORD
// Description :
//
// References : -
// Remarks : -
// Created : 030918, 18 september 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
DWORD CLShareUser::dwGetDownloadSpeed() {
return dwSpeed;
}
/////////////////////////////////////////////////////////////////////
// Member Function : CLFileShareNode
// Type : Private / Public / Protected
// Parameters : NULL - ?
// Returns :
// Description :
//
// References : -
// Remarks : -
// Created : 030826, 26 august 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
CLFileShareNode::CLFileShareNode(char * pszSrvPath, char * pszRealPath) {
memset(&st, 0, sizeof(STFileShareInfo));
st.lStructSize = sizeof(STFileShareInfo);
pclNext = NULL;
pclCurrentUsers = NULL;
bSetPaths(pszSrvPath, pszRealPath);
}
/////////////////////////////////////////////////////////////////////
// Member Function : CLFileShareNode
// Type : Global
// Parameters : pstInfo - ?
// Returns :
// Description :
//
// References : -
// Remarks : -
// Created : 030829, 29 august 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
CLFileShareNode::CLFileShareNode(STFileShareInfo * pstInfo) {
memset(&st, 0, sizeof(STFileShareInfo));
st.lStructSize = sizeof(STFileShareInfo);
pclNext = NULL;
pclCurrentUsers = NULL;
bSetInfo(pstInfo);
}
/////////////////////////////////////////////////////////////////////
// Member Function : ~CLFileShareNode
// Type : Private / Public / Protected
// Parameters : None
// Returns :
// Description :
//
// References : -
// Remarks : -
// Created : 030826, 26 august 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
CLFileShareNode::~CLFileShareNode() {
delete [] st.pszSrvPath;
delete [] st.pszRealPath;
CLShareUser * pclCur = pclCurrentUsers;
while (pclCur) {
CLShareUser * pclNext = pclCur->pclNext;
delete pclCur;
pclCur = pclNext;
}
}
/////////////////////////////////////////////////////////////////////
// Member Function : bSetPaths
// Type : Private / Public / Protected
// Parameters : pszSrvPath - ?
// pszRealPath - ?
// Returns : Returns true if
// Description :
//
// References : -
// Remarks : -
// Created : 030829, 29 august 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
bool CLFileShareNode::bSetPaths(char * pszSrvPath, char * pszRealPath) {
/* This might be a problem !!
if( nDownloadsInProgress > 0 )
return false;
*/
if (!pszSrvPath || !pszRealPath)
return false;
delete [] st.pszSrvPath;
delete [] st.pszRealPath;
st.dwMaxSrvPath = (int)mir_strlen(pszSrvPath) + 1;
st.pszSrvPath = new char[ st.dwMaxSrvPath ];
strcpy(st.pszSrvPath, pszSrvPath);
int nRealLen = (int)mir_strlen(pszRealPath);
if (nRealLen <= 2 || !(pszRealPath[1] == ':' ||
(pszRealPath[0] == '\\' && pszRealPath[1] == '\\'))) {
// Relative path
// we will prepend plugin path to avoid problems
st.dwMaxRealPath = nPluginPathLen + nRealLen + 1;
st.pszRealPath = new char[ st.dwMaxRealPath ];
strcpy(st.pszRealPath, szPluginPath);
pszOrigRealPath = &st.pszRealPath[nPluginPathLen];
} else {
st.dwMaxRealPath = nRealLen + 1;
st.pszRealPath = new char[ st.dwMaxRealPath ];
pszOrigRealPath = st.pszRealPath;
}
strcpy(pszOrigRealPath, pszRealPath);
return true;
}
/////////////////////////////////////////////////////////////////////
// Member Function : bSetInfo
// Type : Private / Public / Protected
// Parameters : pstInfo - ?
// Returns : Returns true if
// Description :
//
// References : -
// Remarks : -
// Created : 030829, 29 august 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
bool CLFileShareNode::bSetInfo(STFileShareInfo * pstInfo) {
if (! bSetPaths(pstInfo->pszSrvPath, pstInfo->pszRealPath))
return false;
if (pstInfo->nMaxDownloads < -1)
return false;
st.dwAllowedIP = pstInfo->dwAllowedIP;
st.dwAllowedMask = pstInfo->dwAllowedMask;
st.nMaxDownloads = pstInfo->nMaxDownloads;
st.dwOptions = pstInfo->dwOptions;
return true;
}
/*
/////////////////////////////////////////////////////////////////////
// Member Function : bAddHttpUser
// Type : Private / Public / Protected
// Parameters : hConnection - ?
// stAddr - ?
// Returns : Returns true if
// Description :
//
// References : -
// Remarks : -
// Created : 030902, 02 september 2003
// Developer : KN, Houdini
/////////////////////////////////////////////////////////////////////
CLHttpUser * CLFileShareNode::pclAddHttpUser( HANDLE hConnection, in_addr stAddr )
{
CLHttpUser * pclCur = pclCurrentUsers;
while( pclCur )
{
if( pclCur->hConnection == hConnection )
{
return NULL;
}
pclCur = pclCur->pclNext;
}
pclCurrentUsers = new CLHttpUser( hConnection, stAddr, pclCurrentUsers );
UpdateStatisticsView();
return pclCurrentUsers;
}
*/
bool CLFileShareNode::bAddUser(CLShareUser * pclUser) {
// deny access
if (bIsOnline || !bLimitOnlyWhenOnline) {
int nConnectionCount = 0;
int nUserConnectionCount = 0;
// iterate through all shares
CLFileShareNode * pclShare = pclFirstNode;
while (pclShare) {
// iterate through its users
CLShareUser * pclCur = pclShare->pclCurrentUsers;
while (pclCur) {
//mir_strcmp(pclCur->szCurrentDLSrvPath, pclUser->szCurrentDLSrvPath) == 0) // same file
if (memcmp(&pclCur->stAddr, &pclUser->stAddr, sizeof(in_addr)) == 0) // same IP
nUserConnectionCount++;
nConnectionCount++;
pclCur = pclCur->pclNext;
}
pclShare = pclShare->pclNext;
}
if (nMaxConnectionsTotal >= 0)
if (nConnectionCount + 1 > nMaxConnectionsTotal)
return false;
if (nMaxConnectionsPerUser >= 0)
if (nUserConnectionCount + 1 > nMaxConnectionsPerUser)
return false;
}
pclUser->pclNext = pclCurrentUsers;
pclCurrentUsers = pclUser;
UpdateStatisticsView();
return true;
}
/////////////////////////////////////////////////////////////////////
// Member Function : bRemoveUser
// Type : Private / Public / Protected
// Parameters : pclUser - ?
// Returns : Returns true if
// Description :
//
// References : -
// Remarks : -
// Created : 030918, 18 september 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
bool CLFileShareNode::bRemoveUser(CLShareUser * pclUser) {
CLShareUser **pclPrev = &pclCurrentUsers;
CLShareUser * pclCur = pclCurrentUsers;
while (pclCur) {
if (pclCur == pclUser) {
*pclPrev = pclCur->pclNext;
UpdateStatisticsView();
return true;
}
pclPrev = &pclCur->pclNext;
pclCur = pclCur->pclNext;
}
return false;
}
/////////////////////////////////////////////////////////////////////
// Member Function : CloseAllTransfers
// Type : Private / Public / Protected
// Parameters : None
// Returns : void
// Description :
//
// References : -
// Remarks : -
// Created : 030902, 02 september 2003
// Developer : KN
/////////////////////////////////////////////////////////////////////
void CLFileShareNode::CloseAllTransfers() {
CLShareUser * pclCur = pclCurrentUsers;
while (pclCur) {
pclCur->CloseSocket();
pclCur = pclCur->pclNext;
}
}
|