~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to .pc/fix_fsf_address.patch/DownloadInfo.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2013-07-18 14:50:28 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130718145028-qhxse81w1sj5w424
Tags: 11.0+dfsg-1
* New upstream release (Closes: #701896)
* Repackage original tarball to remove copies of jquery and twitter-
  bootstrap
* debian/watch: Update for new versioning scheme
* debian/patches: Remove all old patches, add one patch:
  - dont-embed-libraries.patch: Don't install embedded jquery and bootstrap 
    libraries
* debian/combat: Upgrade to debhelper combat 9
* debian/control:
  - Fix Vcs-Git field
  - Adjust debhelper version for combat level 9
  - Add jquery and bootstrap to depends for integrated webserver
  - Add python to recommends for post-processing scripts
  - Bump build-depends on libpar2-dev to support the cancel function
* debian/links:
  - Use the system jquery and bootstrap libraries
* debian/rules:
  - Add get-orig-source target to build modified upstream tarball
* Adjust sample nzbget.conf:
  - Only listen to 127.0.0.1 instead of 0.0.0.0
  - Use nzbget.conf as template for webui configuration
* Adjust sample nzbgetd init file:
  - Point to correct location of nzbget binary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  This file is part of nzbget
3
 
 *
4
 
 *  Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
5
 
 *  Copyright (C) 2007-2010 Andrei Prygounkov <hugbug@users.sourceforge.net>
6
 
 *
7
 
 *  This program is free software; you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation; either version 2 of the License, or
10
 
 *  (at your option) any later version.
11
 
 *
12
 
 *  This program is distributed in the hope that it will be useful,
13
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 *  GNU General Public License for more details.
16
 
 *
17
 
 *  You should have received a copy of the GNU General Public License
18
 
 *  along with this program; if not, write to the Free Software
19
 
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
 
 *
21
 
 * $Revision: 378 $
22
 
 * $Date: 2010-01-29 10:34:44 +0100 (Fri, 29 Jan 2010) $
23
 
 *
24
 
 */
25
 
 
26
 
 
27
 
#ifdef HAVE_CONFIG_H
28
 
#include <config.h>
29
 
#endif
30
 
 
31
 
#ifdef WIN32
32
 
#include "win32.h"
33
 
#endif
34
 
 
35
 
#include <stdlib.h>
36
 
#include <string.h>
37
 
#include <cctype>
38
 
#include <cstdio>
39
 
#include <sys/stat.h>
40
 
 
41
 
#include "nzbget.h"
42
 
#include "DownloadInfo.h"
43
 
#include "Options.h"
44
 
#include "Log.h"
45
 
#include "Util.h"
46
 
 
47
 
extern Options* g_pOptions;
48
 
 
49
 
int FileInfo::m_iIDGen = 0;
50
 
int NZBInfo::m_iIDGen = 0;
51
 
int PostInfo::m_iIDGen = 0;
52
 
 
53
 
NZBParameter::NZBParameter(const char* szName)
54
 
{
55
 
        m_szName = strdup(szName);
56
 
        m_szValue = NULL;
57
 
}
58
 
 
59
 
NZBParameter::~NZBParameter()
60
 
{
61
 
        if (m_szName)
62
 
        {
63
 
                free(m_szName);
64
 
        }
65
 
        if (m_szValue)
66
 
        {
67
 
                free(m_szValue);
68
 
        }
69
 
}
70
 
 
71
 
void NZBParameter::SetValue(const char* szValue)
72
 
{
73
 
        if (m_szValue)
74
 
        {
75
 
                free(m_szValue);
76
 
        }
77
 
        m_szValue = strdup(szValue);
78
 
}
79
 
 
80
 
 
81
 
void NZBParameterList::SetParameter(const char* szName, const char* szValue)
82
 
{
83
 
        NZBParameter* pParameter = NULL;
84
 
        bool bDelete = !szValue || !*szValue;
85
 
 
86
 
        for (iterator it = begin(); it != end(); it++)
87
 
        {
88
 
                NZBParameter* pLookupParameter = *it;
89
 
                if (!strcmp(pLookupParameter->GetName(), szName))
90
 
                {
91
 
                        if (bDelete)
92
 
                        {
93
 
                                delete pLookupParameter;
94
 
                                erase(it);
95
 
                                return;
96
 
                        }
97
 
                        pParameter = pLookupParameter;
98
 
                        break;
99
 
                }
100
 
        }
101
 
 
102
 
        if (bDelete)
103
 
        {
104
 
                return;
105
 
        }
106
 
 
107
 
        if (!pParameter)
108
 
        {
109
 
                pParameter = new NZBParameter(szName);
110
 
                push_back(pParameter);
111
 
        }
112
 
 
113
 
        pParameter->SetValue(szValue);
114
 
}
115
 
 
116
 
 
117
 
NZBInfo::NZBInfo()
118
 
{
119
 
        debug("Creating NZBInfo");
120
 
 
121
 
        m_szFilename = NULL;
122
 
        m_szDestDir = NULL;
123
 
        m_szCategory = strdup("");
124
 
        m_iFileCount = 0;
125
 
        m_iParkedFileCount = 0;
126
 
        m_lSize = 0;
127
 
        m_iRefCount = 0;
128
 
        m_bPostProcess = false;
129
 
        m_eParStatus = prNone;
130
 
        m_eScriptStatus = srNone;
131
 
        m_bDeleted = false;
132
 
        m_bParCleanup = false;
133
 
        m_bCleanupDisk = false;
134
 
        m_szQueuedFilename = strdup("");
135
 
        m_tHistoryTime = 0;
136
 
        m_Owner = NULL;
137
 
        m_Messages.clear();
138
 
        m_iIDMessageGen = 0;
139
 
        m_iIDGen++;
140
 
        m_iID = m_iIDGen;
141
 
}
142
 
 
143
 
NZBInfo::~NZBInfo()
144
 
{
145
 
        debug("Destroying NZBInfo");
146
 
 
147
 
        if (m_szFilename)
148
 
        {
149
 
                free(m_szFilename);
150
 
        }
151
 
        if (m_szDestDir)
152
 
        {
153
 
                free(m_szDestDir);
154
 
        }
155
 
        if (m_szCategory)
156
 
        {
157
 
                free(m_szCategory);
158
 
        }
159
 
        if (m_szQueuedFilename)
160
 
        {
161
 
                free(m_szQueuedFilename);
162
 
        }
163
 
 
164
 
        ClearCompletedFiles();
165
 
 
166
 
        for (NZBParameterList::iterator it = m_ppParameters.begin(); it != m_ppParameters.end(); it++)
167
 
        {
168
 
                delete *it;
169
 
        }
170
 
        m_ppParameters.clear();
171
 
 
172
 
        for (Messages::iterator it = m_Messages.begin(); it != m_Messages.end(); it++)
173
 
        {
174
 
                delete *it;
175
 
        }
176
 
        m_Messages.clear();
177
 
 
178
 
        if (m_Owner)
179
 
        {
180
 
                m_Owner->Remove(this);
181
 
        }
182
 
}
183
 
 
184
 
void NZBInfo::AddReference()
185
 
{
186
 
        m_iRefCount++;
187
 
}
188
 
 
189
 
void NZBInfo::Release()
190
 
{
191
 
        m_iRefCount--;
192
 
        if (m_iRefCount <= 0)
193
 
        {
194
 
                delete this;
195
 
        }
196
 
}
197
 
 
198
 
void NZBInfo::ClearCompletedFiles()
199
 
{
200
 
        for (Files::iterator it = m_completedFiles.begin(); it != m_completedFiles.end(); it++)
201
 
        {
202
 
                free(*it);
203
 
        }
204
 
        m_completedFiles.clear();
205
 
}
206
 
 
207
 
void NZBInfo::SetDestDir(const char* szDestDir)
208
 
{
209
 
        if (m_szDestDir)
210
 
        {
211
 
                free(m_szDestDir);
212
 
        }
213
 
        m_szDestDir = strdup(szDestDir);
214
 
}
215
 
 
216
 
void NZBInfo::SetFilename(const char * szFilename)
217
 
{
218
 
        if (m_szFilename)
219
 
        {
220
 
                free(m_szFilename);
221
 
        }
222
 
        m_szFilename = strdup(szFilename);
223
 
}
224
 
 
225
 
void NZBInfo::SetCategory(const char* szCategory)
226
 
{
227
 
        if (m_szCategory)
228
 
        {
229
 
                free(m_szCategory);
230
 
        }
231
 
        m_szCategory = strdup(szCategory);
232
 
}
233
 
 
234
 
void NZBInfo::SetQueuedFilename(const char * szQueuedFilename)
235
 
{
236
 
        if (m_szQueuedFilename)
237
 
        {
238
 
                free(m_szQueuedFilename);
239
 
        }
240
 
        m_szQueuedFilename = strdup(szQueuedFilename);
241
 
}
242
 
 
243
 
void NZBInfo::GetNiceNZBName(char* szBuffer, int iSize)
244
 
{
245
 
        MakeNiceNZBName(m_szFilename, szBuffer, iSize);
246
 
}
247
 
 
248
 
void NZBInfo::MakeNiceNZBName(const char * szNZBFilename, char * szBuffer, int iSize)
249
 
{
250
 
        char postname[1024];
251
 
        const char* szBaseName = Util::BaseFileName(szNZBFilename);
252
 
 
253
 
        // if .nzb file has a certain structure, try to strip out certain elements
254
 
        if (sscanf(szBaseName, "msgid_%*d_%1023s", postname) == 1)
255
 
        {
256
 
                // OK, using stripped name
257
 
        }
258
 
        else
259
 
        {
260
 
                // using complete filename
261
 
                strncpy(postname, szBaseName, 1024);
262
 
                postname[1024-1] = '\0';
263
 
        }
264
 
 
265
 
        // wipe out ".nzb"
266
 
        if (char* p = strrchr(postname, '.')) *p = '\0';
267
 
 
268
 
        Util::MakeValidFilename(postname, '_', false);
269
 
 
270
 
        // if the resulting name is empty, use basename without cleaning up "msgid_"
271
 
        if (strlen(postname) == 0)
272
 
        {
273
 
                // using complete filename
274
 
                strncpy(postname, szBaseName, 1024);
275
 
                postname[1024-1] = '\0';
276
 
 
277
 
                // wipe out ".nzb"
278
 
                if (char* p = strrchr(postname, '.')) *p = '\0';
279
 
 
280
 
                Util::MakeValidFilename(postname, '_', false);
281
 
 
282
 
                // if the resulting name is STILL empty, use "noname"
283
 
                if (strlen(postname) == 0)
284
 
                {
285
 
                        strncpy(postname, "noname", 1024);
286
 
                }
287
 
        }
288
 
 
289
 
        strncpy(szBuffer, postname, iSize);
290
 
        szBuffer[iSize-1] = '\0';
291
 
}
292
 
 
293
 
void NZBInfo::BuildDestDirName()
294
 
{
295
 
        char szBuffer[1024];
296
 
        char szCategory[1024];
297
 
        bool bHasCategory = m_szCategory && m_szCategory[0] != '\0';
298
 
        if (g_pOptions->GetAppendCategoryDir() && bHasCategory)
299
 
        {
300
 
                strncpy(szCategory, m_szCategory, 1024);
301
 
                szCategory[1024 - 1] = '\0';
302
 
                Util::MakeValidFilename(szCategory, '_', true);
303
 
        }
304
 
 
305
 
        if (g_pOptions->GetAppendNZBDir())
306
 
        {
307
 
                char szNiceNZBName[1024];
308
 
                GetNiceNZBName(szNiceNZBName, 1024);
309
 
                if (g_pOptions->GetAppendCategoryDir() && bHasCategory)
310
 
                {
311
 
                        snprintf(szBuffer, 1024, "%s%s%c%s", g_pOptions->GetDestDir(), szCategory, PATH_SEPARATOR, szNiceNZBName);
312
 
                }
313
 
                else
314
 
                {
315
 
                        snprintf(szBuffer, 1024, "%s%s", g_pOptions->GetDestDir(), szNiceNZBName);
316
 
                }
317
 
                szBuffer[1024-1] = '\0';
318
 
        }
319
 
        else
320
 
        {
321
 
                if (g_pOptions->GetAppendCategoryDir() && bHasCategory)
322
 
                {
323
 
                        snprintf(szBuffer, 1024, "%s%s", g_pOptions->GetDestDir(), szCategory);
324
 
                }
325
 
                else
326
 
                {
327
 
                        strncpy(szBuffer, g_pOptions->GetDestDir(), 1024);
328
 
                }
329
 
                szBuffer[1024-1] = '\0'; // trim the last slash, always returned by GetDestDir()
330
 
        }
331
 
 
332
 
        SetDestDir(szBuffer);
333
 
}
334
 
 
335
 
void NZBInfo::SetParameter(const char* szName, const char* szValue)
336
 
{
337
 
        m_ppParameters.SetParameter(szName, szValue);
338
 
}
339
 
 
340
 
NZBInfo::Messages* NZBInfo::LockMessages()
341
 
{
342
 
        m_mutexLog.Lock();
343
 
        return &m_Messages;
344
 
}
345
 
 
346
 
void NZBInfo::UnlockMessages()
347
 
{
348
 
        m_mutexLog.Unlock();
349
 
}
350
 
 
351
 
void NZBInfo::AppendMessage(Message::EKind eKind, time_t tTime, const char * szText)
352
 
{
353
 
        if (tTime == 0)
354
 
        {
355
 
                tTime = time(NULL);
356
 
        }
357
 
 
358
 
        Message* pMessage = new Message(++m_iIDMessageGen, eKind, tTime, szText);
359
 
 
360
 
        m_mutexLog.Lock();
361
 
        m_Messages.push_back(pMessage);
362
 
        m_mutexLog.Unlock();
363
 
}
364
 
 
365
 
void NZBInfoList::Add(NZBInfo* pNZBInfo)
366
 
{
367
 
        pNZBInfo->m_Owner = this;
368
 
        push_back(pNZBInfo);
369
 
}
370
 
 
371
 
void NZBInfoList::Remove(NZBInfo* pNZBInfo)
372
 
{
373
 
        for (iterator it = begin(); it != end(); it++)
374
 
        {
375
 
                NZBInfo* pNZBInfo2 = *it;
376
 
                if (pNZBInfo2 == pNZBInfo)
377
 
                {
378
 
                        erase(it);
379
 
                        break;
380
 
                }
381
 
        }
382
 
}
383
 
 
384
 
void NZBInfoList::ReleaseAll()
385
 
{
386
 
        int i = 0;
387
 
        for (iterator it = begin(); it != end(); )
388
 
        {
389
 
                NZBInfo* pNZBInfo = *it;
390
 
                bool bObjDeleted = pNZBInfo->m_iRefCount == 1;
391
 
                pNZBInfo->Release();
392
 
                if (bObjDeleted)
393
 
                {
394
 
                        it = begin() + i;
395
 
                }
396
 
                else
397
 
                {
398
 
                        it++;
399
 
                        i++;
400
 
                }
401
 
        }
402
 
}
403
 
 
404
 
ArticleInfo::ArticleInfo()
405
 
{
406
 
        //debug("Creating ArticleInfo");
407
 
        m_szMessageID           = NULL;
408
 
        m_iSize                         = 0;
409
 
        m_eStatus                       = aiUndefined;
410
 
        m_szResultFilename      = NULL;
411
 
}
412
 
 
413
 
ArticleInfo::~ ArticleInfo()
414
 
{
415
 
        //debug("Destroying ArticleInfo");
416
 
 
417
 
        if (m_szMessageID)
418
 
        {
419
 
                free(m_szMessageID);
420
 
        }
421
 
        if (m_szResultFilename)
422
 
        {
423
 
                free(m_szResultFilename);
424
 
        }
425
 
}
426
 
 
427
 
void ArticleInfo::SetMessageID(const char * szMessageID)
428
 
{
429
 
        m_szMessageID = strdup(szMessageID);
430
 
}
431
 
 
432
 
void ArticleInfo::SetResultFilename(const char * v)
433
 
{
434
 
        if (m_szResultFilename)
435
 
        {
436
 
                free(m_szResultFilename);
437
 
        }
438
 
        m_szResultFilename = strdup(v);
439
 
}
440
 
 
441
 
 
442
 
FileInfo::FileInfo()
443
 
{
444
 
        debug("Creating FileInfo");
445
 
 
446
 
        m_Articles.clear();
447
 
        m_Groups.clear();
448
 
        m_szSubject = NULL;
449
 
        m_szFilename = NULL;
450
 
        m_bFilenameConfirmed = false;
451
 
        m_lSize = 0;
452
 
        m_lRemainingSize = 0;
453
 
        m_tTime = 0;
454
 
        m_bPaused = false;
455
 
        m_bDeleted = false;
456
 
        m_iCompleted = 0;
457
 
        m_bOutputInitialized = false;
458
 
        m_pNZBInfo = NULL;
459
 
        m_iIDGen++;
460
 
        m_iID = m_iIDGen;
461
 
}
462
 
 
463
 
FileInfo::~ FileInfo()
464
 
{
465
 
        debug("Destroying FileInfo");
466
 
 
467
 
        if (m_szSubject)
468
 
        {
469
 
                free(m_szSubject);
470
 
        }
471
 
        if (m_szFilename)
472
 
        {
473
 
                free(m_szFilename);
474
 
        }
475
 
 
476
 
        for (Groups::iterator it = m_Groups.begin(); it != m_Groups.end() ;it++)
477
 
        {
478
 
                free(*it);
479
 
        }
480
 
        m_Groups.clear();
481
 
 
482
 
        ClearArticles();
483
 
 
484
 
        if (m_pNZBInfo)
485
 
        {
486
 
                m_pNZBInfo->Release();
487
 
        }
488
 
}
489
 
 
490
 
void FileInfo::ClearArticles()
491
 
{
492
 
        for (Articles::iterator it = m_Articles.begin(); it != m_Articles.end() ;it++)
493
 
        {
494
 
                delete *it;
495
 
        }
496
 
        m_Articles.clear();
497
 
}
498
 
 
499
 
void FileInfo::SetID(int s)
500
 
{
501
 
        m_iID = s;
502
 
        if (m_iIDGen < m_iID)
503
 
        {
504
 
                m_iIDGen = m_iID;
505
 
        }
506
 
}
507
 
 
508
 
void FileInfo::SetNZBInfo(NZBInfo* pNZBInfo)
509
 
{
510
 
        if (m_pNZBInfo)
511
 
        {
512
 
                m_pNZBInfo->Release();
513
 
        }
514
 
        m_pNZBInfo = pNZBInfo;
515
 
        m_pNZBInfo->AddReference();
516
 
}
517
 
 
518
 
void FileInfo::SetSubject(const char* szSubject)
519
 
{
520
 
        m_szSubject = strdup(szSubject);
521
 
}
522
 
 
523
 
void FileInfo::SetFilename(const char* szFilename)
524
 
{
525
 
        if (m_szFilename)
526
 
        {
527
 
                free(m_szFilename);
528
 
        }
529
 
        m_szFilename = strdup(szFilename);
530
 
}
531
 
 
532
 
void FileInfo::MakeValidFilename()
533
 
{
534
 
        Util::MakeValidFilename(m_szFilename, '_', false);
535
 
}
536
 
 
537
 
void FileInfo::LockOutputFile()
538
 
{
539
 
        m_mutexOutputFile.Lock();
540
 
}
541
 
 
542
 
void FileInfo::UnlockOutputFile()
543
 
{
544
 
        m_mutexOutputFile.Unlock();
545
 
}
546
 
 
547
 
bool FileInfo::IsDupe(const char* szFilename)
548
 
{
549
 
        char fileName[1024];
550
 
        snprintf(fileName, 1024, "%s%c%s", m_pNZBInfo->GetDestDir(), (int)PATH_SEPARATOR, szFilename);
551
 
        fileName[1024-1] = '\0';
552
 
        if (Util::FileExists(fileName))
553
 
        {
554
 
                return true;
555
 
        }
556
 
        snprintf(fileName, 1024, "%s%c%s_broken", m_pNZBInfo->GetDestDir(), (int)PATH_SEPARATOR, szFilename);
557
 
        fileName[1024-1] = '\0';
558
 
        if (Util::FileExists(fileName))
559
 
        {
560
 
                return true;
561
 
        }
562
 
 
563
 
        return false;
564
 
}
565
 
 
566
 
GroupInfo::GroupInfo()
567
 
{
568
 
        m_iFirstID = 0;
569
 
        m_iLastID = 0;
570
 
        m_iRemainingFileCount = 0;
571
 
        m_iPausedFileCount = 0;
572
 
        m_lRemainingSize = 0;
573
 
        m_lPausedSize = 0;
574
 
        m_iRemainingParCount = 0;
575
 
        m_tMinTime = 0;
576
 
        m_tMaxTime = 0;
577
 
}
578
 
 
579
 
GroupInfo::~GroupInfo()
580
 
{
581
 
        if (m_pNZBInfo)
582
 
        {
583
 
                m_pNZBInfo->Release();
584
 
        }
585
 
}
586
 
 
587
 
PostInfo::PostInfo()
588
 
{
589
 
        debug("Creating PostInfo");
590
 
 
591
 
        m_pNZBInfo = NULL;
592
 
        m_szParFilename = NULL;
593
 
        m_szInfoName = NULL;
594
 
        m_bWorking = false;
595
 
        m_bDeleted = false;
596
 
        m_bParCheck = false;
597
 
        m_eParStatus = psNone;
598
 
        m_eRequestParCheck = rpNone;
599
 
        m_eScriptStatus = srNone;
600
 
        m_szProgressLabel = strdup("");
601
 
        m_iFileProgress = 0;
602
 
        m_iStageProgress = 0;
603
 
        m_tStartTime = 0;
604
 
        m_tStageTime = 0;
605
 
        m_eStage = ptQueued;
606
 
        m_pScriptThread = NULL;
607
 
        m_Messages.clear();
608
 
        m_iIDMessageGen = 0;
609
 
        m_iIDGen++;
610
 
        m_iID = m_iIDGen;
611
 
}
612
 
 
613
 
PostInfo::~ PostInfo()
614
 
{
615
 
        debug("Destroying PostInfo");
616
 
 
617
 
        if (m_szParFilename)
618
 
        {
619
 
                free(m_szParFilename);
620
 
        }
621
 
        if (m_szInfoName)
622
 
        {
623
 
                free(m_szInfoName);
624
 
        }
625
 
        if (m_szProgressLabel)
626
 
        {
627
 
                free(m_szProgressLabel);
628
 
        }
629
 
 
630
 
        for (Messages::iterator it = m_Messages.begin(); it != m_Messages.end(); it++)
631
 
        {
632
 
                delete *it;
633
 
        }
634
 
        m_Messages.clear();
635
 
 
636
 
        if (m_pNZBInfo)
637
 
        {
638
 
                m_pNZBInfo->Release();
639
 
        }
640
 
}
641
 
 
642
 
void PostInfo::SetNZBInfo(NZBInfo* pNZBInfo)
643
 
{
644
 
        if (m_pNZBInfo)
645
 
        {
646
 
                m_pNZBInfo->Release();
647
 
        }
648
 
        m_pNZBInfo = pNZBInfo;
649
 
        m_pNZBInfo->AddReference();
650
 
}
651
 
 
652
 
void PostInfo::SetParFilename(const char* szParFilename)
653
 
{
654
 
        m_szParFilename = strdup(szParFilename);
655
 
}
656
 
 
657
 
void PostInfo::SetInfoName(const char* szInfoName)
658
 
{
659
 
        m_szInfoName = strdup(szInfoName);
660
 
}
661
 
 
662
 
void PostInfo::SetProgressLabel(const char* szProgressLabel)
663
 
{
664
 
        if (m_szProgressLabel)
665
 
        {
666
 
                free(m_szProgressLabel);
667
 
        }
668
 
        m_szProgressLabel = strdup(szProgressLabel);
669
 
}
670
 
 
671
 
PostInfo::Messages* PostInfo::LockMessages()
672
 
{
673
 
        m_mutexLog.Lock();
674
 
        return &m_Messages;
675
 
}
676
 
 
677
 
void PostInfo::UnlockMessages()
678
 
{
679
 
        m_mutexLog.Unlock();
680
 
}
681
 
 
682
 
void PostInfo::AppendMessage(Message::EKind eKind, const char * szText)
683
 
{
684
 
        Message* pMessage = new Message(++m_iIDMessageGen, eKind, time(NULL), szText);
685
 
 
686
 
        m_mutexLog.Lock();
687
 
        m_Messages.push_back(pMessage);
688
 
 
689
 
        while (m_Messages.size() > (unsigned int)g_pOptions->GetLogBufferSize())
690
 
        {
691
 
                Message* pMessage = m_Messages.front();
692
 
                delete pMessage;
693
 
                m_Messages.pop_front();
694
 
        }
695
 
        m_mutexLog.Unlock();
696
 
}
697
 
 
698
 
void DownloadQueue::BuildGroups(GroupQueue* pGroupQueue)
699
 
{
700
 
        for (FileQueue::iterator it = GetFileQueue()->begin(); it != GetFileQueue()->end(); it++)
701
 
    {
702
 
        FileInfo* pFileInfo = *it;
703
 
                GroupInfo* pGroupInfo = NULL;
704
 
                for (GroupQueue::iterator itg = pGroupQueue->begin(); itg != pGroupQueue->end(); itg++)
705
 
                {
706
 
                        GroupInfo* pGroupInfo1 = *itg;
707
 
                        if (pGroupInfo1->GetNZBInfo() == pFileInfo->GetNZBInfo())
708
 
                        {
709
 
                                pGroupInfo = pGroupInfo1;
710
 
                                break;
711
 
                        }
712
 
                }
713
 
                if (!pGroupInfo)
714
 
                {
715
 
                        pGroupInfo = new GroupInfo();
716
 
                        pGroupInfo->m_pNZBInfo = pFileInfo->GetNZBInfo();
717
 
                        pGroupInfo->m_pNZBInfo->AddReference();
718
 
                        pGroupInfo->m_iFirstID = pFileInfo->GetID();
719
 
                        pGroupInfo->m_iLastID = pFileInfo->GetID();
720
 
                        pGroupInfo->m_tMinTime = pFileInfo->GetTime();
721
 
                        pGroupInfo->m_tMaxTime = pFileInfo->GetTime();
722
 
                        pGroupQueue->push_back(pGroupInfo);
723
 
                }
724
 
                if (pFileInfo->GetID() < pGroupInfo->GetFirstID())
725
 
                {
726
 
                        pGroupInfo->m_iFirstID = pFileInfo->GetID();
727
 
                }
728
 
                if (pFileInfo->GetID() > pGroupInfo->GetLastID())
729
 
                {
730
 
                        pGroupInfo->m_iLastID = pFileInfo->GetID();
731
 
                }
732
 
                if (pFileInfo->GetTime() > 0)
733
 
                {
734
 
                        if (pFileInfo->GetTime() < pGroupInfo->GetMinTime())
735
 
                        {
736
 
                                pGroupInfo->m_tMinTime = pFileInfo->GetTime();
737
 
                        }
738
 
                        if (pFileInfo->GetTime() > pGroupInfo->GetMaxTime())
739
 
                        {
740
 
                                pGroupInfo->m_tMaxTime = pFileInfo->GetTime();
741
 
                        }
742
 
                }
743
 
                pGroupInfo->m_iRemainingFileCount++;
744
 
                pGroupInfo->m_lRemainingSize += pFileInfo->GetRemainingSize();
745
 
                if (pFileInfo->GetPaused())
746
 
                {
747
 
                        pGroupInfo->m_lPausedSize += pFileInfo->GetRemainingSize();
748
 
                        pGroupInfo->m_iPausedFileCount++;
749
 
                }
750
 
 
751
 
                char szLoFileName[1024];
752
 
                strncpy(szLoFileName, pFileInfo->GetFilename(), 1024);
753
 
                szLoFileName[1024-1] = '\0';
754
 
                for (char* p = szLoFileName; *p; p++) *p = tolower(*p); // convert string to lowercase
755
 
                if (strstr(szLoFileName, ".par2"))
756
 
                {
757
 
                        pGroupInfo->m_iRemainingParCount++;
758
 
                }
759
 
        }
760
 
}