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

« back to all changes in this revision

Viewing changes to WebDownloader.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2014-12-25 12:58:06 UTC
  • mfrom: (1.2.1) (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141225125806-vnzgajhm7mju9933
Tags: 14.1+dfsg-1
* New Upstream release (Closes: #768863)
* debian/patches:
  - Remove 0010_unnecessary_gcryptdep.patch, included upstream
  - Refresh remaining patches
* debian/control:
  - Remove no longer needed build-depends on libpar2-dev and libsigc++-dev
* debian/nzbget.conf
  - Update sample configuration file to include new options introduced by
    new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  This file is part of nzbget
3
 
 *
4
 
 *  Copyright (C) 2012-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
 
 *
20
 
 * $Revision: 677 $
21
 
 * $Date: 2013-05-14 22:20:52 +0200 (Tue, 14 May 2013) $
22
 
 *
23
 
 */
24
 
 
25
 
 
26
 
#ifdef HAVE_CONFIG_H
27
 
#include "config.h"
28
 
#endif
29
 
 
30
 
#ifdef WIN32
31
 
#include "win32.h"
32
 
#endif
33
 
 
34
 
#include <stdlib.h>
35
 
#include <string.h>
36
 
#include <stdio.h>
37
 
#ifdef WIN32
38
 
#include <direct.h>
39
 
#else
40
 
#include <unistd.h>
41
 
#include <sys/time.h>
42
 
#endif
43
 
#include <sys/stat.h>
44
 
#include <errno.h>
45
 
 
46
 
#include "nzbget.h"
47
 
#include "WebDownloader.h"
48
 
#include "Log.h"
49
 
#include "Options.h"
50
 
#include "Util.h"
51
 
 
52
 
extern Options* g_pOptions;
53
 
 
54
 
WebDownloader::WebDownloader()
55
 
{
56
 
        debug("Creating WebDownloader");
57
 
 
58
 
        m_szURL = NULL;
59
 
        m_szOutputFilename      = NULL;
60
 
        m_pConnection = NULL;
61
 
        m_szInfoName = NULL;
62
 
        m_bConfirmedLength = false;
63
 
        m_eStatus = adUndefined;
64
 
        m_szOriginalFilename = NULL;
65
 
        SetLastUpdateTimeNow();
66
 
}
67
 
 
68
 
WebDownloader::~WebDownloader()
69
 
{
70
 
        debug("Destroying WebDownloader");
71
 
 
72
 
        if (m_szURL)
73
 
        {
74
 
                free(m_szURL);
75
 
        }
76
 
        if (m_szInfoName)
77
 
        {
78
 
                free(m_szInfoName);
79
 
        }
80
 
        if (m_szOutputFilename)
81
 
        {
82
 
                free(m_szOutputFilename);
83
 
        }
84
 
        if (m_szOriginalFilename)
85
 
        {
86
 
                free(m_szOriginalFilename);
87
 
        }
88
 
}
89
 
 
90
 
void WebDownloader::SetOutputFilename(const char* v)
91
 
{
92
 
        m_szOutputFilename = strdup(v);
93
 
}
94
 
 
95
 
void WebDownloader::SetInfoName(const char* v)
96
 
{
97
 
        m_szInfoName = strdup(v);
98
 
}
99
 
 
100
 
void WebDownloader::SetURL(const char * szURL)
101
 
{
102
 
        m_szURL = strdup(szURL);
103
 
}
104
 
 
105
 
void WebDownloader::SetStatus(EStatus eStatus)
106
 
{
107
 
        m_eStatus = eStatus;
108
 
        Notify(NULL);
109
 
}
110
 
 
111
 
void WebDownloader::Run()
112
 
{
113
 
        debug("Entering WebDownloader-loop");
114
 
 
115
 
        SetStatus(adRunning);
116
 
 
117
 
        int iRemainedDownloadRetries = g_pOptions->GetRetries() > 0 ? g_pOptions->GetRetries() : 1;
118
 
        int iRemainedConnectRetries = iRemainedDownloadRetries > 10 ? iRemainedDownloadRetries : 10;
119
 
 
120
 
        EStatus Status = adFailed;
121
 
 
122
 
        while (!IsStopped() && iRemainedDownloadRetries > 0 && iRemainedConnectRetries > 0)
123
 
        {
124
 
                SetLastUpdateTimeNow();
125
 
 
126
 
                Status = Download();
127
 
 
128
 
                if ((((Status == adFailed) && (iRemainedDownloadRetries > 1)) ||
129
 
                        ((Status == adConnectError) && (iRemainedConnectRetries > 1)))
130
 
                        && !IsStopped() && !(g_pOptions->GetPauseDownload() || g_pOptions->GetPauseDownload2()))
131
 
                {
132
 
                        detail("Waiting %i sec to retry", g_pOptions->GetRetryInterval());
133
 
                        int msec = 0;
134
 
                        while (!IsStopped() && (msec < g_pOptions->GetRetryInterval() * 1000) && 
135
 
                                !(g_pOptions->GetPauseDownload() || g_pOptions->GetPauseDownload2()))
136
 
                        {
137
 
                                usleep(100 * 1000);
138
 
                                msec += 100;
139
 
                        }
140
 
                }
141
 
 
142
 
                if (IsStopped() || g_pOptions->GetPauseDownload() || g_pOptions->GetPauseDownload2())
143
 
                {
144
 
                        Status = adRetry;
145
 
                        break;
146
 
                }
147
 
 
148
 
                if (Status == adFinished || Status == adFatalError || Status == adNotFound)
149
 
                {
150
 
                        break;
151
 
                }
152
 
 
153
 
                if (Status != adConnectError)
154
 
                {
155
 
                        iRemainedDownloadRetries--;
156
 
                }
157
 
                else
158
 
                {
159
 
                        iRemainedConnectRetries--;
160
 
                }
161
 
        }
162
 
 
163
 
        if (Status != adFinished && Status != adRetry)
164
 
        {
165
 
                Status = adFailed;
166
 
        }
167
 
 
168
 
        if (Status == adFailed)
169
 
        {
170
 
                if (IsStopped())
171
 
                {
172
 
                        detail("Download %s cancelled", m_szInfoName);
173
 
                }
174
 
                else
175
 
                {
176
 
                        error("Download %s failed", m_szInfoName);
177
 
                }
178
 
        }
179
 
 
180
 
        if (Status == adFinished)
181
 
        {
182
 
                detail("Download %s completed", m_szInfoName);
183
 
        }
184
 
 
185
 
        SetStatus(Status);
186
 
 
187
 
        debug("Exiting WebDownloader-loop");
188
 
}
189
 
 
190
 
WebDownloader::EStatus WebDownloader::Download()
191
 
{
192
 
        EStatus Status = adRunning;
193
 
 
194
 
        URL url(m_szURL);
195
 
 
196
 
        Status = CreateConnection(&url);
197
 
        if (Status != adRunning)
198
 
        {
199
 
                return Status;
200
 
        }
201
 
 
202
 
        m_pConnection->SetSuppressErrors(false);
203
 
 
204
 
        // connection
205
 
        bool bConnected = m_pConnection->Connect();
206
 
        if (!bConnected || IsStopped())
207
 
        {
208
 
                FreeConnection();
209
 
                return adConnectError;
210
 
        }
211
 
 
212
 
        // Okay, we got a Connection. Now start downloading.
213
 
        detail("Downloading %s", m_szInfoName);
214
 
 
215
 
        SendHeaders(&url);
216
 
 
217
 
        Status = DownloadHeaders();
218
 
 
219
 
        if (Status == adRunning)
220
 
        {
221
 
                Status = DownloadBody();
222
 
        }
223
 
 
224
 
        if (IsStopped())
225
 
        {
226
 
                Status = adFailed;
227
 
        }
228
 
 
229
 
        FreeConnection();
230
 
 
231
 
        if (Status != adFinished)
232
 
        {
233
 
                // Download failed, delete broken output file
234
 
                remove(m_szOutputFilename);
235
 
        }
236
 
 
237
 
        return Status;
238
 
}
239
 
 
240
 
 
241
 
WebDownloader::EStatus WebDownloader::CreateConnection(URL *pUrl)
242
 
{
243
 
        if (!pUrl->IsValid())
244
 
        {
245
 
                error("URL is not valid: %s", pUrl->GetAddress());
246
 
                return adFatalError;
247
 
        }
248
 
 
249
 
        int iPort = pUrl->GetPort();
250
 
        if (iPort == 0 && !strcasecmp(pUrl->GetProtocol(), "http"))
251
 
        {
252
 
                iPort = 80;
253
 
        }
254
 
        if (iPort == 0 && !strcasecmp(pUrl->GetProtocol(), "https"))
255
 
        {
256
 
                iPort = 443;
257
 
        }
258
 
 
259
 
        if (strcasecmp(pUrl->GetProtocol(), "http") && strcasecmp(pUrl->GetProtocol(), "https"))
260
 
        {
261
 
                error("Unsupported protocol in URL: %s", pUrl->GetAddress());
262
 
                return adFatalError;
263
 
        }
264
 
 
265
 
#ifdef DISABLE_TLS
266
 
        if (!strcasecmp(pUrl->GetProtocol(), "https"))
267
 
        {
268
 
                error("Program was compiled without TLS/SSL-support. Cannot download using https protocol. URL: %s", pUrl->GetAddress());
269
 
                return adFatalError;
270
 
        }
271
 
#endif
272
 
 
273
 
        bool bTLS = !strcasecmp(pUrl->GetProtocol(), "https");
274
 
 
275
 
        m_pConnection = new Connection(pUrl->GetHost(), iPort, bTLS);
276
 
 
277
 
        return adRunning;
278
 
}
279
 
 
280
 
void WebDownloader::SendHeaders(URL *pUrl)
281
 
{
282
 
        char tmp[1024];
283
 
 
284
 
        // retrieve file
285
 
        snprintf(tmp, 1024, "GET %s HTTP/1.0\r\n", pUrl->GetResource());
286
 
        tmp[1024-1] = '\0';
287
 
        m_pConnection->WriteLine(tmp);
288
 
 
289
 
        snprintf(tmp, 1024, "User-Agent: nzbget/%s\r\n", Util::VersionRevision());
290
 
        tmp[1024-1] = '\0';
291
 
        m_pConnection->WriteLine(tmp);
292
 
 
293
 
        snprintf(tmp, 1024, "Host: %s\r\n", pUrl->GetHost());
294
 
        tmp[1024-1] = '\0';
295
 
        m_pConnection->WriteLine(tmp);
296
 
 
297
 
        m_pConnection->WriteLine("Accept: */*\r\n");
298
 
#ifndef DISABLE_GZIP
299
 
        m_pConnection->WriteLine("Accept-Encoding: gzip\r\n");
300
 
#endif
301
 
        m_pConnection->WriteLine("Connection: close\r\n");
302
 
        m_pConnection->WriteLine("\r\n");
303
 
}
304
 
 
305
 
WebDownloader::EStatus WebDownloader::DownloadHeaders()
306
 
{
307
 
        EStatus Status = adRunning;
308
 
 
309
 
        m_bConfirmedLength = false;
310
 
        const int LineBufSize = 1024*10;
311
 
        char* szLineBuf = (char*)malloc(LineBufSize);
312
 
        m_iContentLen = -1;
313
 
        bool bFirstLine = true;
314
 
        m_bGZip = false;
315
 
 
316
 
        // Headers
317
 
        while (!IsStopped())
318
 
        {
319
 
                SetLastUpdateTimeNow();
320
 
 
321
 
                int iLen = 0;
322
 
                char* line = m_pConnection->ReadLine(szLineBuf, LineBufSize, &iLen);
323
 
 
324
 
                if (bFirstLine)
325
 
                {
326
 
                        Status = CheckResponse(szLineBuf);
327
 
                        if (Status != adRunning)
328
 
                        {
329
 
                                break;
330
 
                        }
331
 
                        bFirstLine = false;
332
 
                }
333
 
 
334
 
                // Have we encountered a timeout?
335
 
                if (!line)
336
 
                {
337
 
                        if (!IsStopped())
338
 
                        {
339
 
                                warn("URL %s failed: Unexpected end of file", m_szInfoName);
340
 
                        }
341
 
                        Status = adFailed;
342
 
                        break;
343
 
                }
344
 
 
345
 
                debug("Header: %s", line);
346
 
 
347
 
                // detect body of response
348
 
                if (*line == '\r' || *line == '\n')
349
 
                {
350
 
                        if (m_iContentLen == -1 && !m_bGZip)
351
 
                        {
352
 
                                warn("URL %s: Content-Length is not submitted by server, cannot verify whether the file is complete", m_szInfoName);
353
 
                        }
354
 
                        break;
355
 
                }
356
 
 
357
 
                ProcessHeader(line);
358
 
        }
359
 
 
360
 
        free(szLineBuf);
361
 
 
362
 
        return Status;
363
 
}
364
 
 
365
 
WebDownloader::EStatus WebDownloader::DownloadBody()
366
 
{
367
 
        EStatus Status = adRunning;
368
 
 
369
 
        m_pOutFile = NULL;
370
 
        bool bEnd = false;
371
 
        const int LineBufSize = 1024*10;
372
 
        char* szLineBuf = (char*)malloc(LineBufSize);
373
 
        int iWrittenLen = 0;
374
 
 
375
 
#ifndef DISABLE_GZIP
376
 
        m_pGUnzipStream = NULL;
377
 
        if (m_bGZip)
378
 
        {
379
 
                m_pGUnzipStream = new GUnzipStream(1024*10);
380
 
        }
381
 
#endif
382
 
 
383
 
        // Body
384
 
        while (!IsStopped())
385
 
        {
386
 
                SetLastUpdateTimeNow();
387
 
 
388
 
                char* szBuffer;
389
 
                int iLen;
390
 
                m_pConnection->ReadBuffer(&szBuffer, &iLen);
391
 
                if (iLen == 0)
392
 
                {
393
 
                        iLen = m_pConnection->TryRecv(szLineBuf, LineBufSize);
394
 
                        szBuffer = szLineBuf;
395
 
                }
396
 
 
397
 
                // Have we encountered a timeout?
398
 
                if (iLen <= 0)
399
 
                {
400
 
                        if (m_iContentLen == -1)
401
 
                        {
402
 
                                bEnd = true;
403
 
                                break;
404
 
                        }
405
 
 
406
 
                        if (!IsStopped())
407
 
                        {
408
 
                                warn("URL %s failed: Unexpected end of file", m_szInfoName);
409
 
                        }
410
 
                        Status = adFailed;
411
 
                        break;
412
 
                }
413
 
 
414
 
                // write to output file
415
 
                if (!Write(szBuffer, iLen))
416
 
                {
417
 
                        Status = adFatalError;
418
 
                        break;
419
 
                }
420
 
                iWrittenLen += iLen;
421
 
 
422
 
                //detect end of file
423
 
                if (iWrittenLen == m_iContentLen || (m_iContentLen == -1 && m_bGZip && m_bConfirmedLength))
424
 
                {
425
 
                        bEnd = true;
426
 
                        break;
427
 
                }
428
 
        }
429
 
 
430
 
        free(szLineBuf);
431
 
 
432
 
#ifndef DISABLE_GZIP
433
 
        if (m_pGUnzipStream)
434
 
        {
435
 
                delete m_pGUnzipStream;
436
 
        }
437
 
#endif
438
 
 
439
 
        if (m_pOutFile)
440
 
        {
441
 
                fclose(m_pOutFile);
442
 
        }
443
 
 
444
 
        if (!bEnd && Status == adRunning && !IsStopped())
445
 
        {
446
 
                warn("URL %s failed: file incomplete", m_szInfoName);
447
 
                Status = adFailed;
448
 
        }
449
 
 
450
 
        if (bEnd)
451
 
        {
452
 
                Status = adFinished;
453
 
        }
454
 
 
455
 
        return Status;
456
 
}
457
 
 
458
 
WebDownloader::EStatus WebDownloader::CheckResponse(const char* szResponse)
459
 
{
460
 
        if (!szResponse)
461
 
        {
462
 
                if (!IsStopped())
463
 
                {
464
 
                        warn("URL %s: Connection closed by remote host", m_szInfoName);
465
 
                }
466
 
                return adConnectError;
467
 
        }
468
 
 
469
 
        const char* szHTTPResponse = strchr(szResponse, ' ');
470
 
        if (strncmp(szResponse, "HTTP", 4) || !szHTTPResponse)
471
 
        {
472
 
                warn("URL %s failed: %s", m_szInfoName, szResponse);
473
 
                return adFailed;
474
 
        }
475
 
 
476
 
        szHTTPResponse++;
477
 
 
478
 
        if (!strncmp(szHTTPResponse, "400", 3) || !strncmp(szHTTPResponse, "499", 3))
479
 
        {
480
 
                warn("URL %s failed: %s", m_szInfoName, szHTTPResponse);
481
 
                return adConnectError;
482
 
        }
483
 
        else if (!strncmp(szHTTPResponse, "404", 3))
484
 
        {
485
 
                warn("URL %s failed: %s", m_szInfoName, szHTTPResponse);
486
 
                return adNotFound;
487
 
        }
488
 
        else if (!strncmp(szHTTPResponse, "200", 3))
489
 
        {
490
 
                // OK
491
 
                return adRunning;
492
 
        }
493
 
        else 
494
 
        {
495
 
                // unknown error, no special handling
496
 
                warn("URL %s failed: %s", m_szInfoName, szResponse);
497
 
                return adFailed;
498
 
        }
499
 
}
500
 
 
501
 
void WebDownloader::ProcessHeader(const char* szLine)
502
 
{
503
 
        if (!strncmp(szLine, "Content-Length: ", 16))
504
 
        {
505
 
                m_iContentLen = atoi(szLine + 16);
506
 
                m_bConfirmedLength = true;
507
 
        }
508
 
 
509
 
        if (!strncmp(szLine, "Content-Encoding: gzip", 22))
510
 
        {
511
 
                m_bGZip = true;
512
 
        }
513
 
 
514
 
        if (!strncmp(szLine, "Content-Disposition: ", 21))
515
 
        {
516
 
                ParseFilename(szLine);
517
 
        }
518
 
}
519
 
 
520
 
void WebDownloader::ParseFilename(const char* szContentDisposition)
521
 
{
522
 
        // Examples:
523
 
        // Content-Disposition: attachment; filename="fname.ext"
524
 
        // Content-Disposition: attachement;filename=fname.ext
525
 
        // Content-Disposition: attachement;filename=fname.ext;
526
 
        const char *p = strstr(szContentDisposition, "filename");
527
 
        if (!p)
528
 
        {
529
 
                return;
530
 
        }
531
 
 
532
 
        p = strchr(p, '=');
533
 
        if (!p)
534
 
        {
535
 
                return;
536
 
        }
537
 
 
538
 
        p++;
539
 
 
540
 
        while (*p == ' ') p++;
541
 
 
542
 
        char fname[1024];
543
 
        strncpy(fname, p, 1024);
544
 
        fname[1024-1] = '\0';
545
 
 
546
 
        char *pe = fname + strlen(fname) - 1;
547
 
        while ((*pe == ' ' || *pe == '\n' || *pe == '\r' || *pe == ';') && pe > fname) {
548
 
                *pe = '\0';
549
 
                pe--;
550
 
        }
551
 
 
552
 
        WebUtil::HttpUnquote(fname);
553
 
 
554
 
        if (m_szOriginalFilename)
555
 
        {
556
 
                free(m_szOriginalFilename);
557
 
        }
558
 
        m_szOriginalFilename = strdup(Util::BaseFileName(fname));
559
 
 
560
 
        debug("OriginalFilename: %s", m_szOriginalFilename);
561
 
}
562
 
 
563
 
bool WebDownloader::Write(void* pBuffer, int iLen)
564
 
{
565
 
        if (!m_pOutFile && !PrepareFile())
566
 
        {
567
 
                return false;
568
 
        }
569
 
 
570
 
#ifndef DISABLE_GZIP
571
 
        if (m_bGZip)
572
 
        {
573
 
                m_pGUnzipStream->Write(pBuffer, iLen);
574
 
                const void *pOutBuf;
575
 
                int iOutLen = 1;
576
 
                while (iOutLen > 0)
577
 
                {
578
 
                        GUnzipStream::EStatus eGZStatus = m_pGUnzipStream->Read(&pOutBuf, &iOutLen);
579
 
 
580
 
                        if (eGZStatus == GUnzipStream::zlError)
581
 
                        {
582
 
                                error("URL %s: GUnzip failed", m_szInfoName);
583
 
                                return false;
584
 
                        }
585
 
 
586
 
                        if (iOutLen > 0 && fwrite(pOutBuf, 1, iOutLen, m_pOutFile) <= 0)
587
 
                        {
588
 
                                return false;
589
 
                        }
590
 
 
591
 
                        if (eGZStatus == GUnzipStream::zlFinished)
592
 
                        {
593
 
                                m_bConfirmedLength = true;
594
 
                                return true;
595
 
                        }
596
 
                }
597
 
                return true;
598
 
        }
599
 
        else
600
 
#endif
601
 
 
602
 
        return fwrite(pBuffer, 1, iLen, m_pOutFile) > 0;
603
 
}
604
 
 
605
 
bool WebDownloader::PrepareFile()
606
 
{
607
 
        // prepare file for writing
608
 
 
609
 
        const char* szFilename = m_szOutputFilename;
610
 
        m_pOutFile = fopen(szFilename, "wb");
611
 
        if (!m_pOutFile)
612
 
        {
613
 
                error("Could not %s file %s", "create", szFilename);
614
 
                return false;
615
 
        }
616
 
        if (g_pOptions->GetWriteBufferSize() > 0)
617
 
        {
618
 
                setvbuf(m_pOutFile, (char *)NULL, _IOFBF, g_pOptions->GetWriteBufferSize());
619
 
        }
620
 
 
621
 
        return true;
622
 
}
623
 
 
624
 
void WebDownloader::LogDebugInfo()
625
 
{
626
 
        char szTime[50];
627
 
#ifdef HAVE_CTIME_R_3
628
 
                ctime_r(&m_tLastUpdateTime, szTime, 50);
629
 
#else
630
 
                ctime_r(&m_tLastUpdateTime, szTime);
631
 
#endif
632
 
 
633
 
        debug("      Web-Download: status=%i, LastUpdateTime=%s, filename=%s", m_eStatus, szTime, Util::BaseFileName(m_szOutputFilename));
634
 
}
635
 
 
636
 
void WebDownloader::Stop()
637
 
{
638
 
        debug("Trying to stop WebDownloader");
639
 
        Thread::Stop();
640
 
        m_mutexConnection.Lock();
641
 
        if (m_pConnection)
642
 
        {
643
 
                m_pConnection->SetSuppressErrors(true);
644
 
                m_pConnection->Cancel();
645
 
        }
646
 
        m_mutexConnection.Unlock();
647
 
        debug("WebDownloader stopped successfully");
648
 
}
649
 
 
650
 
bool WebDownloader::Terminate()
651
 
{
652
 
        Connection* pConnection = m_pConnection;
653
 
        bool terminated = Kill();
654
 
        if (terminated && pConnection)
655
 
        {
656
 
                debug("Terminating connection");
657
 
                pConnection->SetSuppressErrors(true);
658
 
                pConnection->Cancel();
659
 
                pConnection->Disconnect();
660
 
                delete pConnection;
661
 
        }
662
 
        return terminated;
663
 
}
664
 
 
665
 
void WebDownloader::FreeConnection()
666
 
{
667
 
        if (m_pConnection)                                                      
668
 
        {
669
 
                debug("Releasing connection");
670
 
                m_mutexConnection.Lock();
671
 
                if (m_pConnection->GetStatus() == Connection::csCancelled)
672
 
                {
673
 
                        m_pConnection->Disconnect();
674
 
                }
675
 
                delete m_pConnection;
676
 
                m_pConnection = NULL;
677
 
                m_mutexConnection.Unlock();
678
 
        }
679
 
}