~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/url.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2009-04-22 21:39:19 UTC
  • mto: (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090422213919-52m015y6gcpv1m1g
Tags: upstream-0.12.0~svn2018
ImportĀ upstreamĀ versionĀ 0.12.0~svn2018

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
8
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
9
9
    
10
 
    Copyright (C) 2006-2008 Gena Batyan <bgeradz@mediatomb.cc>,
 
10
    Copyright (C) 2006-2009 Gena Batyan <bgeradz@mediatomb.cc>,
11
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
12
12
                            Leonhard Wimmer <leo@mediatomb.cc>
13
13
    
24
24
    version 2 along with MediaTomb; if not, write to the Free Software
25
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
26
26
    
27
 
    $Id: url.cc 1714 2008-03-01 17:33:21Z lww $
 
27
    $Id: url.cc 2010 2009-01-11 19:10:43Z lww $
28
28
*/
29
29
 
30
30
/// \file url.cc
40
40
#include "rexp.h"
41
41
#include "url.h"
42
42
#include "tools.h"
 
43
#include "config_manager.h"
43
44
 
44
45
using namespace zmm;
45
46
 
67
68
    Ref<StringBuffer> buffer(new StringBuffer(buffer_hint));
68
69
 
69
70
    curl_easy_reset(curl_handle);
 
71
    
70
72
    if (verbose)
71
 
        curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
 
73
    {
 
74
        bool logEnabled;
 
75
#ifdef TOMBDEBUG
 
76
        logEnabled = !ConfigManager::isDebugLogging();
 
77
#else
 
78
        logEnabled = ConfigManager::isDebugLogging();
 
79
#endif
 
80
        if (logEnabled)
 
81
            curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
 
82
    }
72
83
 
73
84
    curl_easy_setopt(curl_handle, CURLOPT_URL, URL.c_str());
74
85
    curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, error_buffer);
75
86
 
 
87
    /// \todo it would be a good idea to allow both variants, i.e. retrieve
 
88
    /// the headers and data in one go when needed
76
89
    if (only_header)
77
90
    {
78
 
        curl_easy_setopt(curl_handle, CURLOPT_NOBODY);
 
91
        curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
79
92
        curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, URL::dl);
80
93
        curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, 
81
94
                         (void *)buffer.getPtr());
124
137
    CURLcode res;
125
138
    double cl;
126
139
    char *ct;
 
140
    char *c_url;
127
141
    char error_buffer[CURL_ERROR_SIZE] = {'\0'};
128
142
    String mt;
 
143
    String used_url;
129
144
 
130
145
    if (curl_handle == NULL)
131
146
    {
135
150
            throw _Exception(_("Invalid curl handle!\n"));
136
151
    }
137
152
 
138
 
    Ref<StringBuffer> buffer = download(URL, &retcode, curl_handle, true);
 
153
    Ref<StringBuffer> buffer = download(URL, &retcode, curl_handle, true, true, true);
139
154
    if (retcode != 200)
140
155
    {
141
156
        if (cleanup)
212
227
    else
213
228
        mt = String(ct);
214
229
    
215
 
    log_debug("Extracted content length: %ld\n", cl);
216
 
 
217
 
    Ref<Stat> st(new Stat((off_t)cl, mt));
 
230
    log_debug("Extracted content length: %lld\n", (long long)cl);
 
231
 
 
232
    res = curl_easy_getinfo(curl_handle, CURLINFO_EFFECTIVE_URL, &c_url);
 
233
    if (res != CURLE_OK)
 
234
    {
 
235
        log_error("%s\n", error_buffer);
 
236
        if (cleanup)
 
237
            curl_easy_cleanup(curl_handle);
 
238
        throw _Exception(String(error_buffer));
 
239
    }
 
240
 
 
241
    if (c_url == NULL)
 
242
        used_url = URL;
 
243
    else
 
244
        used_url = String(c_url);
 
245
 
 
246
    Ref<Stat> st(new Stat(used_url, (off_t)cl, mt));
218
247
 
219
248
    if (cleanup)
220
249
        curl_easy_cleanup(curl_handle);