This file is indexed.

/usr/include/eiskaltdcpp/dcpp/QueueManager.h is in libeiskaltdcpp-dev 2.2.9-3.

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
/*
 * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#pragma once

#include "TimerManager.h"
#include "CriticalSection.h"
#include "Exception.h"
#include "User.h"
#include "File.h"
#include "QueueItem.h"
#include "Singleton.h"
#include "DirectoryListing.h"
#include "MerkleTree.h"
#include "QueueManagerListener.h"
#include "SearchManagerListener.h"
#include "ClientManagerListener.h"

namespace dcpp {

STANDARD_EXCEPTION(QueueException);

class UserConnection;

class DirectoryItem {
public:
    typedef DirectoryItem* Ptr;
    typedef unordered_multimap<UserPtr, Ptr, User::Hash> DirectoryMap;
    typedef DirectoryMap::iterator DirectoryIter;
    typedef pair<DirectoryIter, DirectoryIter> DirectoryPair;

    typedef vector<Ptr> List;
    typedef List::iterator Iter;

    DirectoryItem() : priority(QueueItem::DEFAULT) { }
    DirectoryItem(const UserPtr& aUser, const string& aName, const string& aTarget,
        QueueItem::Priority p) : name(aName), target(aTarget), priority(p), user(aUser) { }
    ~DirectoryItem() { }

    UserPtr& getUser() { return user; }
    void setUser(const UserPtr& aUser) { user = aUser; }

    GETSET(string, name, Name);
    GETSET(string, target, Target);
    GETSET(QueueItem::Priority, priority, Priority);
private:
    UserPtr user;
};

class ConnectionQueueItem;
class QueueLoader;

class QueueManager : public Singleton<QueueManager>, public Speaker<QueueManagerListener>, private TimerManagerListener,
    private SearchManagerListener, private ClientManagerListener
{
public:
    //NOTE: freedcpp
    void add(const string& aTarget, int64_t aSize, const TTHValue& root);

    /** Add a file to the queue. */
    void add(const string& aTarget, int64_t aSize, const TTHValue& root, const HintedUser& aUser,
    int aFlags = 0, bool addBad = true);
    /** Add a user's filelist to the queue. */
    void addList(const HintedUser& HintedUser, int aFlags, const string& aInitialDir = Util::emptyString);
    /** Readd a source that was removed */
    void readd(const string& target, const HintedUser& aUser);
    /** Add a directory to the queue (downloads filelist and matches the directory). */
    void addDirectory(const string& aDir, const HintedUser& aUser, const string& aTarget,
            QueueItem::Priority p = QueueItem::DEFAULT) noexcept;

    int matchListing(const DirectoryListing& dl) noexcept;
    void matchAllListings();

    bool getTTH(const string& name, TTHValue& tth) noexcept;

    int64_t getSize(const string& target) noexcept;
    int64_t getPos(const string& target) noexcept;

    /** Move the target location of a queued item. Running items are silently ignored */
    void move(const string& aSource, const string& aTarget) noexcept;

    void remove(const string& aTarget) noexcept;
    void removeSource(const string& aTarget, const UserPtr& aUser, int reason, bool removeConn = true) noexcept;
    void removeSource(const UserPtr& aUser, int reason) noexcept;

    void recheck(const string& aTarget);

    void setPriority(const string& aTarget, QueueItem::Priority p) noexcept;

    void getTargets(const TTHValue& tth, StringList& sl);
    QueueItem::StringMap& lockQueue() noexcept { cs.lock(); return fileQueue.getQueue(); } ;
    void unlockQueue() noexcept { cs.unlock(); }

    Download* getDownload(UserConnection& aSource, bool supportsTrees) noexcept;
    void putDownload(Download* aDownload, bool finished) noexcept;
    void setFile(Download* download);

    int64_t getQueued(const UserPtr& aUser) const;

    /** @return The highest priority download the user has, PAUSED may also mean no downloads */
    QueueItem::Priority hasDownload(const UserPtr& aUser) noexcept;

    bool getQueueInfo(const UserPtr& aUser, string& aTarget, int64_t& aSize, int& aFlags) noexcept;

    int countOnlineSources(const string& aTarget);

    void loadQueue() noexcept;
    void saveQueue(bool force = false) noexcept;

    void noDeleteFileList(const string& path);

    bool handlePartialSearch(const TTHValue& tth, PartsInfo& _outPartsInfo);
    bool handlePartialResult(const UserPtr& aUser, const string& hubHint, const TTHValue& tth, const QueueItem::PartialSource& partialSource, PartsInfo& outPartialInfo);

    bool isChunkDownloaded(const TTHValue& tth, int64_t startPos, int64_t& bytes, string& tempTarget, int64_t& size) {
        Lock l(cs);
        QueueItem::List ql;
        fileQueue.find(ql, tth);

        if(ql.empty()) return false;

        QueueItem* qi = ql.front();

        tempTarget = qi->getTempTarget();
        size = qi->getSize();

        return qi->isChunkDownloaded(startPos, bytes);
    }

    GETSET(uint64_t, lastSave, LastSave);
    GETSET(string, queueFile, QueueFile);
private:
    enum { MOVER_LIMIT = 10*1024*1024 };
    class FileMover : public Thread {
    public:
        FileMover() : active(false) { }
        virtual ~FileMover() { join(); }

        void moveFile(const string& source, const string& target);
        virtual int run();
    private:
        typedef pair<string, string> FilePair;
        typedef vector<FilePair> FileList;
        typedef FileList::iterator FileIter;

        bool active;

        FileList files;
        CriticalSection cs;
    } mover;

    typedef vector<pair<QueueItem::SourceConstIter, const QueueItem*> > PFSSourceList;

    class Rechecker : public Thread {
        struct DummyOutputStream : OutputStream {
            virtual size_t write(const void*, size_t n) { return n; }
            virtual size_t flush() { return 0; }
        };

    public:
        explicit Rechecker(QueueManager* qm_) : qm(qm_), active(false) { }
        virtual ~Rechecker() { join(); }

        void add(const string& file);
        virtual int run();

    private:
        QueueManager* qm;
        bool active;

        StringList files;
        CriticalSection cs;
    } rechecker;

    /** All queue items by target */
    class FileQueue {
    public:
        FileQueue() : lastInsert(queue.end()) { }
        ~FileQueue() {
            for(QueueItem::StringIter i = queue.begin(); i != queue.end(); ++i)
                delete i->second;
        }
        void add(QueueItem* qi);
        QueueItem* add(const string& aTarget, int64_t aSize, int aFlags, QueueItem::Priority p,
            const string& aTempTarget, time_t aAdded, const TTHValue& root);

        QueueItem* find(const string& target);
        void find(QueueItem::List& sl, int64_t aSize, const string& ext);
        void find(QueueItem::List& ql, const TTHValue& tth);
        // find some PFS sources to exchange parts info
        void findPFSSources(PFSSourceList&);
        bool exists(const TTHValue& tth) const;

#ifdef WITH_DHT
        // return a PFS tth to DHT publish
        TTHValue* findPFSPubTTH();
#endif

        QueueItem* findAutoSearch(StringList& recent);
        size_t getSize() { return queue.size(); }
        QueueItem::StringMap& getQueue() { return queue; }
        void move(QueueItem* qi, const string& aTarget);
        void remove(QueueItem* qi);
    private:
        QueueItem::StringMap queue;
        /** A hint where to insert an item... */
        QueueItem::StringIter lastInsert;
    };

    /** All queue items indexed by user (this is a cache for the FileQueue really...) */
    class UserQueue {
    public:
        void add(QueueItem* qi);
        void add(QueueItem* qi, const UserPtr& aUser);
        QueueItem* getNext(const UserPtr& aUser, QueueItem::Priority minPrio = QueueItem::LOWEST, int64_t wantedSize = 0,int64_t lastSpeed =0 ,bool allowRemove = true);
        QueueItem* getRunning(const UserPtr& aUser);
        void addDownload(QueueItem* qi, Download* d);
        void removeDownload(QueueItem* qi, const UserPtr& d);
        QueueItem::UserListMap& getList(int p) { return userQueue[p]; }
        void remove(QueueItem* qi, bool removeRunning = true);
        void remove(QueueItem* qi, const UserPtr& aUser, bool removeRunning = true);
        void setPriority(QueueItem* qi, QueueItem::Priority p);

        QueueItem::UserMap& getRunning() { return running; }
        bool isRunning(const UserPtr& aUser) const {
            return (running.find(aUser) != running.end());
        }
        int64_t getQueued(const UserPtr& aUser) const;
    private:
        /** QueueItems by priority and user (this is where the download order is determined) */
        QueueItem::UserListMap userQueue[QueueItem::LAST];
        /** Currently running downloads, a QueueItem is always either here or in the userQueue */
        QueueItem::UserMap running;
    };

    friend class QueueLoader;
    friend class Singleton<QueueManager>;

    QueueManager();
    virtual ~QueueManager();

    mutable CriticalSection cs;

    /** QueueItems by target */
    FileQueue fileQueue;
    /** QueueItems by user */
    UserQueue userQueue;
    /** Directories queued for downloading */
    DirectoryItem::DirectoryMap directories;
    /** Recent searches list, to avoid searching for the same thing too often */
    StringList recent;
    /** The queue needs to be saved */
    bool dirty;
    /** Next search */
    uint64_t nextSearch;
    /** File lists not to delete */
    StringList protectedFileLists;
    /** Sanity check for the target filename */
    static string checkTarget(const string& aTarget, bool checkExsistence);
    /** Add a source to an existing queue item */
    bool addSource(QueueItem* qi, const HintedUser& aUser, Flags::MaskType addBad);

    void processList(const string& name, const HintedUser& user, int flags);

    void load(const SimpleXML& aXml);
    void moveFile(const string& source, const string& target);
    static void moveFile_(const string& source, const string& target);
    void moveStuckFile(QueueItem* qi);
    void rechecked(QueueItem* qi);

    void setDirty();

    string getListPath(const HintedUser& user);

    bool checkSfv(QueueItem* qi, Download* d);
    uint32_t calcCrc32(const string& file);

    void logFinishedDownload(QueueItem* qi, Download* d, bool crcError);

    // TimerManagerListener
    virtual void on(TimerManagerListener::Second, uint64_t aTick) noexcept;
    virtual void on(TimerManagerListener::Minute, uint64_t aTick) noexcept;

    // SearchManagerListener
    virtual void on(SearchManagerListener::SR, const SearchResultPtr&) noexcept;

    // ClientManagerListener
    virtual void on(ClientManagerListener::UserConnected, const UserPtr& aUser) noexcept;
    virtual void on(ClientManagerListener::UserDisconnected, const UserPtr& aUser) noexcept;
};

} // namespace dcpp