This file is indexed.

/usr/include/dclib-0.3/dclib/cdownloadmanager.h is in libdc-dev 0.3.24~svn3121-1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/***************************************************************************
                          cdownloadmanager.h  -  description
                             -------------------
    begin                : Don Mai 16 2002
    copyright            : (C) 2002-2004 by Mathias Küster
    email                : mathen@users.berlios.de
 ***************************************************************************/

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

#ifndef CDOWNLOADMANAGER_H
#define CDOWNLOADMANAGER_H

/**
  *@author Mathias Küster
  *
  * This handles the queue of files and sources, the list of running
  * transfers, and starting auto searches.
  *
  * The download manager is lacking multi threading, also segment size
  * is fixed, and the number of download slots is not normally limited.
  *
  * Upload bandwith limiting is present, although not present in
  * mainline DC++ at the time of writing this.
  *
  * Calculating the MD5 checksum of the first 10KiB is mostly
  * useless and completely obsolete, but basically very little
  * was ever done to dclib's downloading ability between 0.3.7 and 0.3.22.
  */

#include <dclib/dcos.h>
#include <dclib/core/cmutex.h>
#include <dclib/core/csingleton.h>
#include <dclib/ctransfer.h>

/*
 * eCloseType has moved to here so
 * that cconfig.h does not need to include cdownloadmanager.h
 */
#include <dclib/core/types.h>

#include <dclib/core/cstringlist.h>

#define MAX_FILE_PRIORITY 5

enum eShutdownState {
	essNONE,
	essSHUTDOWN,
	essSHUTDOWNREADY
};

class CUserFileInfo {
public:
	/** */
	CUserFileInfo()
	{
		bMulti = false;
	};
	/** */
	~CUserFileInfo() {};
	/** */
	eTransferWaitState eWaitState;
	/** */
	eTransferFileState eFileState;
	/** */
	CString sLocalFile;
	/** */
	bool bMulti;
};

class CExtraUserSlot {
public:
	/** */
	CExtraUserSlot()
	{
		iSlots = 1;
		bPermanent = false;
	};
	/** */
	~CExtraUserSlot() {};
	/** */
	CString sNick;
	/** */
	CString sHubName;
	/** */
	int iSlots;
	/** */
	bool bPermanent;
};

class DCTransferBanObject {
public:
	/** */
	DCTransferBanObject() {
		m_nRequestCount = 0;
		m_tTime         = 0;
	};
	/** */
	~DCTransferBanObject() {};
	/** */
	CString m_sIP;
	/** */
	unsigned int m_nRequestCount;
	/** */
	time_t m_tTime;
};

class CDownloadManagerInfo : public CDCMessage {
public:
	/** */
	CDownloadManagerInfo() : CDCMessage(DC_MESSAGE_DM_INFO) {
		rate_ul_settings = 0;
		rate_ul_operator = 0;
		rate_ul_user     = 0;
		rate_ul_special  = 0;
		rate_ul_rate_extra = 0;
		rate_dl  = 0;
		slot_max = 0;
		slot_use_settings = 0;
		slot_use_operator = 0;
		slot_use_user     = 0;
		slot_use_special  = 0;
		slot_use_rate_extra = 0;
	};
	/** */
	virtual ~CDownloadManagerInfo() {};
	/** */
	ulonglong Rate() {
		return rate_ul_settings + rate_ul_operator + rate_ul_user + rate_ul_special + rate_ul_rate_extra;
	}
	/** */
	ulonglong rate_ul_settings;
	/** */
	ulonglong rate_ul_operator;
	/** */
	ulonglong rate_ul_user;
	/** */
	ulonglong rate_ul_special;
	/** */
	ulonglong rate_ul_rate_extra;
	/** */
	ulonglong rate_dl;
	/** */
	int slot_max;
	/** the number of normal slots from main config settings used */
	int slot_use_settings;
	/** slot usage for operators (after all other slots used up) */
	int slot_use_operator;
	/** slot usage for users (extra normal slots granted to users, only used if normal slots used up) */
	int slot_use_user;
	/** slot usage for special transfers e.g. minimum filelength (after all normal used up) */
	int slot_use_special;
	/** the number of extra slots that have been given because total upload rate is below a limit */
	int slot_use_rate_extra;

	CDownloadManagerInfo & operator = (const CDownloadManagerInfo & s)
	{
		rate_ul_settings = s.rate_ul_settings;
		rate_ul_operator = s.rate_ul_operator;
		rate_ul_user     = s.rate_ul_user;
		rate_ul_special  = s.rate_ul_special;
		rate_ul_rate_extra = s.rate_ul_rate_extra;
		
		rate_dl  = s.rate_dl;
		slot_max = s.slot_max;
		
		slot_use_settings = s.slot_use_settings;
		slot_use_operator = s.slot_use_operator;
		slot_use_user     = s.slot_use_user;
		slot_use_special  = s.slot_use_special;
		slot_use_rate_extra = s.slot_use_rate_extra;

		return *this;
	};
};

enum eFileManagerStatus {
	efmsNONE=0,
	efmsIDLE,
	efmsCREATESHARELIST,
	efmsCREATESEARCHINDEX,
	efmsCREATEHASHLIST,
	efmsREBUILDLISTS,
	efmsVALIDATELEAVES
};

class CFileManagerInfo : public CDCMessage {
public:
	/** */
	CFileManagerInfo() : CDCMessage(DC_MESSAGE_FM_INFO) {
		m_eFileManagerStatus = efmsNONE;
		m_nProgress = 0;
	};
	/** */
	virtual ~CFileManagerInfo() {};
	/** */
	enum eFileManagerStatus m_eFileManagerStatus;
	/** */
	double m_nProgress;

	CFileManagerInfo & operator = (const CFileManagerInfo & s)
	{
		m_eFileManagerStatus = s.m_eFileManagerStatus;
		m_nProgress          = s.m_nProgress;
		return *this;
	};
};

class CDCMessage;
class CListen;
class CDownloadQueue;
class DCFileChunkObject;
class DCTransferQueueObject;
class DCTransferFileObject;
class DCTransferWait;
class _CCallback0;

class CTransferObject {
public:
	/** */
	CTransferObject() {
		m_pTransfer = 0;
		m_UserDisconnectTimeout = time(0);
	}
	/** */
	~CTransferObject() {
		delete m_pTransfer;
		m_pTransfer = 0;
	}

	/** */
	CTransfer * m_pTransfer;
	/** */
	time_t m_UserDisconnectTimeout;
};

class CDownloadManager : public CSingleton<CDownloadManager> {
public: 
	/** */
	CDownloadManager();
	/** */
	virtual ~CDownloadManager();

	/** load the queue */
	int DLM_LoadQueue();
	/** save the queue */
	int DLM_SaveQueue();
	/** disconnect all transfers for a clean shutdown */
	void DLM_Shutdown();
	/** return the current shutdownstate */
	eShutdownState DLM_ShutdownState() const { return m_eShutdownState; }
	/** add a extra slot to the user */
	void DLM_AddUserSlot( CString nick, CString hubname, int slot, bool permanent = false );
	/** return current used upload slots */
	int DLM_UsedSlots() const { return DownloadManagerInfo.slot_use_settings; }
	/** */
	bool DLM_TransferConnect( CString nick, CString hubname );
	/** */
	bool DLM_TransferClose( ulonglong transferid );
	/** */
	bool DLM_TransferSetRate( ulonglong transferid, ulonglong rate );
	/** */
	bool DLM_TransferGetRate( ulonglong transferid, ulonglong & rate );
	/** */
	CList<CMessageDMTransferObject> * DLM_TransferGetList();

	/** */
	eDirection DLM_TransferDirection( ulonglong transferid );

	/**
	 * For filelists, localpath is abused to set the file/folder to
	 * open the list at (when downloaded from search) and localrootpath
	 * is abused to download a directory.
	 */
	void DLM_QueueAdd( CString nick, CString hubname, CString hubhost,
				CString remotename, CString localname,
				CString localpath, CString localrootpath,
				eltMedium medium, ulonglong size,
				ulonglong startposition,
				ulonglong endposition,
				CString hash,
				bool multi = false );
	/** */
	int DLM_QueueCheck( CString nick, CString hubname, CString hubhost,
				CString remotename, CString localname,
				CString localpath, CString localrootpath,
				eltMedium medium, ulonglong size, CString tth );
	/** change the src-nick/hubname to dst-nick/hubname in the queue */
	bool DLM_QueueEdit( CString srcnick, CString srchubname, CString dstnick, CString dsthubname, CString dsthubhost );
	/** */
	bool DLM_QueuePause( CString nick, CString hubname, CString remotefile, bool pause );
	/** */
	bool DLM_QueueRemove( CString nick, CString hubname, CString remotefile );
	/** */
	bool DLM_QueueRemove( CString localfile );
	/**
	 * 0 = directory removed
	 * 1 = user/hub not found
	 * 2 = no directories queued
	 * 3 = that directory not queued
	 */
	int DLM_QueueRemoveDirectory( CString nick, CString hubname, CString directory );
	/** */
	bool DLM_QueueSetFilePriority( CString nick, CString hubname, CString remotefile, int priority );
	/** */
	bool DLM_QueueGetFileInfo( CString nick, CString hubname, CString hubhost, CString file, CUserFileInfo * UserFileInfo );
	/** */
	DCFileChunkObject * DLM_QueueGetFileChunk( CString file );
	/** */
	bool DLM_QueueUpdateHub( CString nick, CString hubname );
	/** */
	void DLM_QueueGetHub( CString nick, CString hubname, CList<DCHubObject> * list );

	/** */
	bool DLM_AddTransferRequest( CString nick, CString userhost, CString hubname, CString hubhost );
	/** */
	void DLM_AddTransferRequest( CString host, int port, bool crypto, CString hubname, CString hubhost );

	/** */
	bool DLM_GetDownloadManagerInfo( CDownloadManagerInfo * pinfo );
	/** handle search */
	bool DLM_HandleSearch( CMessageSearchResult * MessageSearchResult );

	/** callback function - Called by CManager */
	int Callback();
	/** callback function */
	virtual int DC_DownloadManagerCallBack( CDCMessage * ) { return -1; };

	/**
	 * It's not given to a CCallback it's just directly called by the
	 * listen managers so it can take whatever parameters are necessary.
	 */
	int ListenCallbackHandler( int fd, bool crypto );

protected:
	/** */
	int DM_TransferCallBack( CTransfer * Transfer, CDCMessage * DCMessage );

	/** */
	void SendFileManagerInfo( CFileManagerInfo * info );

private:
	/** */
	friend class CFileManager;

	/** */
	void SendFileInfo( DCTransferQueueObject * TransferObject, DCTransferFileObject * TransferFileItem = 0, bool bRemoveFile = false );
	/** */
	void SendTransferInfo( CTransfer * Transfer, bool remove = false );
	/** */
	void SendSlotInfo( CExtraUserSlot * Object );
	/** */
	void SendLogInfo( CString message, CTransfer * Transfer = 0 );
	/** */
	void SendDownloadManagerInfo( CDownloadManagerInfo * dminfo );
	/** */
	void SendTrafficInfo();

	/** create a messagedmtransferobject from a transfer */
	CMessageDMTransferObject * CreateDMTransferObject( CTransfer * Transfer );
	/** */
	void FileListDone( CTransfer * Transfer, DCTransferFileObject * TransferFileObject );

	/** */
	bool CheckUserSlot( CString nick, CString hubname );
	/** */
	void OptimizeChunks( DCFileChunkObject * FileChunkObject );
	/** */
	bool GetNextChunk( CString file, ulonglong * lstart, ulonglong * lend );
	/** */
	int UpdateChunk( CString file, ulonglong lstart, ulonglong lend, ulonglong lcurrent );
	/** */
	bool GetNewChunkEnd( CString file, ulonglong lstart, ulonglong lend, ulonglong lcurrent, ulonglong * lnstart, ulonglong *lnend );

	/** */
	void UpdateQueueList( time_t ttimeout );
	/** */
	void UpdateTransferList( time_t ttimeout );
	/** */
	void UpdateBanList( time_t ttimeout );

	/** */
	eDirection CheckWaitTransfer( CTransfer * Transfer );
	/** */
	bool UpdateWaitTransfer( CTransfer * Transfer, bool rem = false );
	/** */
	bool ChangeDirection( CTransfer * Transfer );
	/** */
	bool SetNextFile( CTransfer * Transfer );
	/** */
	bool SetDirection( CTransfer * Transfer );
	/** */
	bool SetFile( CTransfer * Transfer );
	/** */
	void UpdateFileState( CTransfer * Transfer, eTransferFileState eState );
	/** */
	bool CheckHash( CTransfer * Transfer );

	/** */
	bool RemoveQueueFile( CString nick, CString hubname, CString remotefile );
	/** */
	bool RemoveQueueFile( CString localfile );

	/** */
	bool InitSearch( time_t ttimeout );
	
	/** */
	ulonglong GetNewID();

	/** */
	eShutdownState m_eShutdownState;

	/** mutex for extra slots list */
	CMutex * m_pExtraSlotsMutex;
	/** */
	CList<CExtraUserSlot> * m_pExtraUserSlotList;

	/** */
	_CCallback0 * m_pCallback;

	/** */
	CDownloadManagerInfo DownloadManagerInfo;
	/** */
	CMutex TransferCallBackMutex;
	/** */
	CMutex LogMutex;
	/** */
	ulonglong m_nID;

	/** */
	time_t m_tDownloadQueueTimeout;
	/** */
	time_t m_tUpdateTransferTimeout;
	/** timeout for a new hubsearch */
	time_t m_tHubSearchTimeout;
	/** timeout for a single search */
	time_t m_tSearchTimeout;
	/**
	 * The last time an additional upload slot was given because
	 * total upload rate was below a limit. This is needed so that
	 * these slots are only given max 1 per minute so that there
	 * is enough time for the new transfer to be included in
	 * the total upload rate.
	 */
	time_t m_tLastRateExtra;
	/**
	 * The time old entries were removed from m_pTransferWaitList.
	 */
	time_t m_tWaitListCleaned;

	/** */
	CDownloadQueue * m_pDownloadQueue;
	/** mutex for transfers list */
	CMutex * m_pTransfersMutex;
	/** */
	CStringList<CTransferObject> * m_pTransferList;
	/** mutex for transfer wait list */
	CMutex * m_pWaitListMutex;
	/** */
	CList<DCTransferWait> * m_pTransferWaitList;
	/** mutex for transfer ban list */
	CMutex * m_pBanListMutex;
	/** */
	CStringList<DCTransferBanObject> * m_pTransferBanList;
	/**
	 * The search result list was never locked/unlocked.
	 */
	CList<CMessageSearchResult> * m_pSearchList;
	/** */
	CList<CDCMessage> * m_pSearchQueryList;
};

#endif