~ubuntu-branches/ubuntu/trusty/nzbget/trusty

« back to all changes in this revision

Viewing changes to .pc/fix_fsf_address.patch/Log.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-48qbia23dx6sg8u1
Tags: 11.0+dfsg-0ubuntu1
* 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.

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-2009 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: 339 $
22
 
 * $Date: 2009-06-14 17:57:01 +0200 (Sun, 14 Jun 2009) $
23
 
 *
24
 
 */
25
 
 
26
 
 
27
 
#ifdef HAVE_CONFIG_H
28
 
#include "config.h"
29
 
#endif
30
 
 
31
 
#ifdef WIN32
32
 
#include "win32.h"
33
 
#else
34
 
#include <pthread.h>
35
 
#endif
36
 
 
37
 
#include <stdlib.h>
38
 
#include <string.h>
39
 
#include <sys/stat.h>
40
 
#include <stdarg.h>
41
 
#include <cstdio>
42
 
 
43
 
#include "nzbget.h"
44
 
#include "Options.h"
45
 
#include "Log.h"
46
 
#include "Util.h"
47
 
 
48
 
extern Options* g_pOptions;
49
 
 
50
 
Log::Log()
51
 
{
52
 
        m_Messages.clear();
53
 
        m_iIDGen = 0;
54
 
        m_szLogFilename = NULL;
55
 
#ifdef DEBUG
56
 
        m_bExtraDebug = Util::FileExists("extradebug");
57
 
#endif
58
 
}
59
 
 
60
 
Log::~Log()
61
 
{
62
 
        for (Messages::iterator it = m_Messages.begin(); it != m_Messages.end(); it++)
63
 
        {
64
 
                delete *it;
65
 
        }
66
 
        m_Messages.clear();
67
 
        if (m_szLogFilename)
68
 
        {
69
 
                free(m_szLogFilename);
70
 
        }
71
 
}
72
 
 
73
 
void Log::Filelog(const char* msg, ...)
74
 
{
75
 
        if (m_szLogFilename)
76
 
        {
77
 
                char tmp2[1024];
78
 
 
79
 
                va_list ap;
80
 
                va_start(ap, msg);
81
 
                vsnprintf(tmp2, 1024, msg, ap);
82
 
                tmp2[1024-1] = '\0';
83
 
                va_end(ap);
84
 
 
85
 
                time_t rawtime;
86
 
                time(&rawtime);
87
 
                
88
 
                char szTime[50];
89
 
#ifdef HAVE_CTIME_R_3
90
 
                ctime_r(&rawtime, szTime, 50);
91
 
#else
92
 
                ctime_r(&rawtime, szTime);
93
 
#endif
94
 
                szTime[50-1] = '\0';
95
 
                szTime[strlen(szTime) - 1] = '\0'; // trim LF
96
 
 
97
 
                FILE* file = fopen(m_szLogFilename, "ab+");
98
 
                if (file)
99
 
                {
100
 
#ifdef WIN32
101
 
                        unsigned long iThreadId = GetCurrentThreadId();
102
 
#else
103
 
                        unsigned long iThreadId = (unsigned long)pthread_self();
104
 
#endif
105
 
#ifdef DEBUG
106
 
                        fprintf(file, "%s\t%lu\t%s%s", szTime, iThreadId, tmp2, LINE_ENDING);
107
 
#else
108
 
                        fprintf(file, "%s\t%s%s", szTime, tmp2, LINE_ENDING);
109
 
#endif
110
 
                        fclose(file);
111
 
                }
112
 
                else
113
 
                {
114
 
                        perror(m_szLogFilename);
115
 
                }
116
 
        }
117
 
}
118
 
 
119
 
#ifdef DEBUG
120
 
#undef debug
121
 
#ifdef HAVE_VARIADIC_MACROS
122
 
void debug(const char* szFilename, const char* szFuncname, int iLineNr, const char* msg, ...)
123
 
#else
124
 
void debug(const char* msg, ...)
125
 
#endif
126
 
{
127
 
        char tmp1[1024];
128
 
 
129
 
        va_list ap;
130
 
        va_start(ap, msg);
131
 
        vsnprintf(tmp1, 1024, msg, ap);
132
 
        tmp1[1024-1] = '\0';
133
 
        va_end(ap);
134
 
 
135
 
        char tmp2[1024];
136
 
#ifdef HAVE_VARIADIC_MACROS
137
 
        if (szFuncname)
138
 
        {
139
 
                snprintf(tmp2, 1024, "%s (%s:%i:%s)", tmp1, Util::BaseFileName(szFilename), iLineNr, szFuncname);
140
 
        }
141
 
        else
142
 
        {
143
 
                snprintf(tmp2, 1024, "%s (%s:%i)", tmp1, Util::BaseFileName(szFilename), iLineNr);
144
 
        }
145
 
#else
146
 
        snprintf(tmp2, 1024, "%s", tmp1);
147
 
#endif
148
 
        tmp2[1024-1] = '\0';
149
 
 
150
 
        g_pLog->m_mutexLog.Lock();
151
 
 
152
 
        if (!g_pOptions && g_pLog->m_bExtraDebug)
153
 
        {
154
 
                printf("%s\n", tmp2);
155
 
        }
156
 
 
157
 
        Options::EMessageTarget eMessageTarget = g_pOptions ? g_pOptions->GetDebugTarget() : Options::mtScreen;
158
 
        if (eMessageTarget == Options::mtLog || eMessageTarget == Options::mtBoth)
159
 
        {
160
 
                g_pLog->Filelog("DEBUG\t%s", tmp2);
161
 
        }
162
 
        if (eMessageTarget == Options::mtScreen || eMessageTarget == Options::mtBoth)
163
 
        {
164
 
                g_pLog->AppendMessage(Message::mkDebug, tmp2);
165
 
        }
166
 
 
167
 
        g_pLog->m_mutexLog.Unlock();
168
 
}
169
 
#endif
170
 
 
171
 
void error(const char* msg, ...)
172
 
{
173
 
        char tmp2[1024];
174
 
 
175
 
        va_list ap;
176
 
        va_start(ap, msg);
177
 
        vsnprintf(tmp2, 1024, msg, ap);
178
 
        tmp2[1024-1] = '\0';
179
 
        va_end(ap);
180
 
 
181
 
        g_pLog->m_mutexLog.Lock();
182
 
 
183
 
        Options::EMessageTarget eMessageTarget = g_pOptions ? g_pOptions->GetErrorTarget() : Options::mtBoth;
184
 
        if (eMessageTarget == Options::mtLog || eMessageTarget == Options::mtBoth)
185
 
        {
186
 
                g_pLog->Filelog("ERROR\t%s", tmp2);
187
 
        }
188
 
        if (eMessageTarget == Options::mtScreen || eMessageTarget == Options::mtBoth)
189
 
        {
190
 
                g_pLog->AppendMessage(Message::mkError, tmp2);
191
 
        }
192
 
 
193
 
        g_pLog->m_mutexLog.Unlock();
194
 
}
195
 
 
196
 
void warn(const char* msg, ...)
197
 
{
198
 
        char tmp2[1024];
199
 
 
200
 
        va_list ap;
201
 
        va_start(ap, msg);
202
 
        vsnprintf(tmp2, 1024, msg, ap);
203
 
        tmp2[1024-1] = '\0';
204
 
        va_end(ap);
205
 
 
206
 
        g_pLog->m_mutexLog.Lock();
207
 
 
208
 
        Options::EMessageTarget eMessageTarget = g_pOptions ? g_pOptions->GetWarningTarget() : Options::mtScreen;
209
 
        if (eMessageTarget == Options::mtLog || eMessageTarget == Options::mtBoth)
210
 
        {
211
 
                g_pLog->Filelog("WARNING\t%s", tmp2);
212
 
        }
213
 
        if (eMessageTarget == Options::mtScreen || eMessageTarget == Options::mtBoth)
214
 
        {
215
 
                g_pLog->AppendMessage(Message::mkWarning, tmp2);
216
 
        }
217
 
 
218
 
        g_pLog->m_mutexLog.Unlock();
219
 
}
220
 
 
221
 
void info(const char* msg, ...)
222
 
{
223
 
        char tmp2[1024];
224
 
 
225
 
        va_list ap;
226
 
        va_start(ap, msg);
227
 
        vsnprintf(tmp2, 1024, msg, ap);
228
 
        tmp2[1024-1] = '\0';
229
 
        va_end(ap);
230
 
 
231
 
        g_pLog->m_mutexLog.Lock();
232
 
 
233
 
        Options::EMessageTarget eMessageTarget = g_pOptions ? g_pOptions->GetInfoTarget() : Options::mtScreen;
234
 
        if (eMessageTarget == Options::mtLog || eMessageTarget == Options::mtBoth)
235
 
        {
236
 
                g_pLog->Filelog("INFO\t%s", tmp2);
237
 
        }
238
 
        if (eMessageTarget == Options::mtScreen || eMessageTarget == Options::mtBoth)
239
 
        {
240
 
                g_pLog->AppendMessage(Message::mkInfo, tmp2);
241
 
        }
242
 
 
243
 
        g_pLog->m_mutexLog.Unlock();
244
 
}
245
 
 
246
 
void detail(const char* msg, ...)
247
 
{
248
 
        char tmp2[1024];
249
 
 
250
 
        va_list ap;
251
 
        va_start(ap, msg);
252
 
        vsnprintf(tmp2, 1024, msg, ap);
253
 
        tmp2[1024-1] = '\0';
254
 
        va_end(ap);
255
 
 
256
 
        g_pLog->m_mutexLog.Lock();
257
 
 
258
 
        Options::EMessageTarget eMessageTarget = g_pOptions ? g_pOptions->GetDetailTarget() : Options::mtScreen;
259
 
        if (eMessageTarget == Options::mtLog || eMessageTarget == Options::mtBoth)
260
 
        {
261
 
                g_pLog->Filelog("DETAIL\t%s", tmp2);
262
 
        }
263
 
        if (eMessageTarget == Options::mtScreen || eMessageTarget == Options::mtBoth)
264
 
        {
265
 
                g_pLog->AppendMessage(Message::mkDetail, tmp2);
266
 
        }
267
 
 
268
 
        g_pLog->m_mutexLog.Unlock();
269
 
}
270
 
 
271
 
void abort(const char* msg, ...)
272
 
{
273
 
        char tmp2[1024];
274
 
 
275
 
        va_list ap;
276
 
        va_start(ap, msg);
277
 
        vsnprintf(tmp2, 1024, msg, ap);
278
 
        tmp2[1024-1] = '\0';
279
 
        va_end(ap);
280
 
 
281
 
        g_pLog->m_mutexLog.Lock();
282
 
 
283
 
        printf("\n%s", tmp2);
284
 
 
285
 
        g_pLog->Filelog(tmp2);
286
 
 
287
 
        g_pLog->m_mutexLog.Unlock();
288
 
 
289
 
        exit(-1);
290
 
}
291
 
 
292
 
//************************************************************
293
 
// Message
294
 
 
295
 
Message::Message(unsigned int iID, EKind eKind, time_t tTime, const char* szText)
296
 
{
297
 
        m_iID = iID;
298
 
        m_eKind = eKind;
299
 
        m_tTime = tTime;
300
 
        if (szText)
301
 
        {
302
 
                m_szText = strdup(szText);
303
 
        }
304
 
        else
305
 
        {
306
 
                m_szText = NULL;
307
 
        }
308
 
}
309
 
 
310
 
Message::~ Message()
311
 
{
312
 
        if (m_szText)
313
 
        {
314
 
                free(m_szText);
315
 
        }
316
 
}
317
 
 
318
 
void Log::AppendMessage(Message::EKind eKind, const char * szText)
319
 
{
320
 
        Message* pMessage = new Message(++m_iIDGen, eKind, time(NULL), szText);
321
 
        m_Messages.push_back(pMessage);
322
 
 
323
 
        if (g_pOptions)
324
 
        {
325
 
                while (m_Messages.size() > (unsigned int)g_pOptions->GetLogBufferSize())
326
 
                {
327
 
                        Message* pMessage = m_Messages.front();
328
 
                        delete pMessage;
329
 
                        m_Messages.pop_front();
330
 
                }
331
 
        }
332
 
}
333
 
 
334
 
Log::Messages* Log::LockMessages()
335
 
{
336
 
        m_mutexLog.Lock();
337
 
        return &m_Messages;
338
 
}
339
 
 
340
 
void Log::UnlockMessages()
341
 
{
342
 
        m_mutexLog.Unlock();
343
 
}
344
 
 
345
 
void Log::ResetLog()
346
 
{
347
 
        remove(g_pOptions->GetLogFile());
348
 
}
349
 
 
350
 
/*
351
 
* During intializing stage (when options were not read yet) all messages
352
 
* are saved in screen log, even if they shouldn't (according to options).
353
 
* Method "InitOptions()" check all messages added to screen log during
354
 
* intializing stage and does two things:
355
 
* 1) save the messages to log-file (if they should according to options);
356
 
* 2) delete messages from screen log (if they should not be saved in screen log).
357
 
*/
358
 
void Log::InitOptions()
359
 
{
360
 
        const char* szMessageType[] = { "INFO", "WARNING", "ERROR", "DEBUG", "DETAIL"};
361
 
 
362
 
        if (g_pOptions->GetCreateLog() && g_pOptions->GetLogFile())
363
 
        {
364
 
                m_szLogFilename = strdup(g_pOptions->GetLogFile());
365
 
        }
366
 
 
367
 
        for (unsigned int i = 0; i < m_Messages.size(); )
368
 
        {
369
 
                Message* pMessage = m_Messages.at(i);
370
 
                Options::EMessageTarget eTarget = Options::mtNone;
371
 
                switch (pMessage->GetKind())
372
 
                {
373
 
                        case Message::mkDebug:
374
 
                                eTarget = g_pOptions->GetDebugTarget();
375
 
                                break;
376
 
                        case Message::mkDetail:
377
 
                                eTarget = g_pOptions->GetDetailTarget();
378
 
                                break;
379
 
                        case Message::mkInfo:
380
 
                                eTarget = g_pOptions->GetInfoTarget();
381
 
                                break;
382
 
                        case Message::mkWarning:
383
 
                                eTarget = g_pOptions->GetWarningTarget();
384
 
                                break;
385
 
                        case Message::mkError:
386
 
                                eTarget = g_pOptions->GetErrorTarget();
387
 
                                break;
388
 
                }
389
 
 
390
 
                if (eTarget == Options::mtLog || eTarget == Options::mtBoth)
391
 
                {
392
 
                        Filelog("%s\t%s", szMessageType[pMessage->GetKind()], pMessage->GetText());
393
 
                }
394
 
 
395
 
                if (eTarget == Options::mtLog || eTarget == Options::mtNone)
396
 
                {
397
 
                        delete pMessage;
398
 
                        m_Messages.erase(m_Messages.begin() + i);
399
 
                }
400
 
                else
401
 
                {
402
 
                        i++;
403
 
                }
404
 
        }
405
 
}