~vanvugt/+junk/mediatomb

« back to all changes in this revision

Viewing changes to src/file_request_handler.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-03-02 13:09:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080302130916-zlljdze3kt7vuq4b
Tags: 0.11.0-1
* New upstream release.
* Include message about which inotify headers will be used when enabling
  inotify runtime support.
* Fixed error with use of INTERFACE in init script. Also removed use of -m
  option.
* Including new config.xml options.
* Added more build dependencies for new upstream release.
* Removed build dependency of libid3-dev, taglib is now preferred.
* mediatomb.xpm and manpage.xml is now included in orig tarball.
* inotify patch is not needed anymore.
* md5 patch has been committed upstream and is no longer needed. Also removed
  README.Debian.
* TwinHelix PNG fix is now used. Removed from TODO.
* Adding dependency of iceweasel for mediatomb package.
* Updated copyright file.
* Updated watch file.
* Updated rules file for proper configure options.

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-2007 Gena Batyan <bgeradz@mediatomb.cc>,
 
10
    Copyright (C) 2006-2008 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: file_request_handler.cc 1358 2007-06-14 18:26:19Z jin_eld $
 
27
    $Id: file_request_handler.cc 1698 2008-02-23 20:48:30Z lww $
28
28
*/
29
29
 
30
30
/// \file file_request_handler.cc
51
51
#include "file_request_handler.h"
52
52
#include "metadata_handler.h"
53
53
#include "tools.h"
 
54
#ifdef EXTERNAL_TRANSCODING
 
55
    #include "transcoding/transcode_dispatcher.h"
 
56
#endif
54
57
 
55
58
using namespace zmm;
56
59
using namespace mxml;
65
68
 
66
69
    String mimeType;
67
70
    int objectID;
 
71
#ifdef EXTERNAL_TRANSCODING
 
72
    String tr_profile;
 
73
#endif
68
74
 
69
75
    struct stat statbuf;
70
76
    int ret = 0;
100
106
    {
101
107
        throw _Exception(_("get_info: object is not an item"));
102
108
    }
103
 
   
 
109
     
104
110
    Ref<CdsItem> item = RefCast(obj, CdsItem);
105
111
 
106
112
    String path = item->getLocation();
108
114
    // determining which resource to serve 
109
115
    int res_id = 0;
110
116
    String s_res_id = dict->get(_(URL_RESOURCE_ID));
111
 
    if (s_res_id != nil)
 
117
#ifdef EXTERNAL_TRANSCODING
 
118
    if (string_ok(s_res_id) && (s_res_id != _(URL_VALUE_TRANSCODE_NO_RES_ID)))
 
119
#else
 
120
    if (string_ok(s_res_id))
 
121
#endif
112
122
        res_id = s_res_id.toInt();
 
123
    else
 
124
        res_id = -1;
113
125
 
114
126
 
115
127
    String ext = dict->get(_("ext"));
164
176
        }
165
177
    }
166
178
 
 
179
#ifdef EXTERNAL_TRANSCODING
 
180
    tr_profile = dict->get(_(URL_PARAM_TRANSCODE_PROFILE_NAME));
 
181
#endif
 
182
 
167
183
    info->http_header = NULL;
 
184
    // for transcoded resourecs res_id will always be negative
168
185
    log_debug("fetching resource id %d\n", res_id);
169
186
    if ((res_id > 0) && (res_id < item->getResourceCount()))
170
187
    {
172
189
        String protocolInfo = item->getResource(res_id)->getAttributes()->get(_("protocolInfo"));
173
190
        if (protocolInfo != nil)
174
191
        {
175
 
            Ref<Array<StringBase> > parts = split_string(protocolInfo, ':');
176
 
            mimeType = parts->get(2);
 
192
            mimeType = getMTFromProtocolInfo(protocolInfo);
177
193
        }
178
 
        else
179
 
        {
 
194
 
 
195
        if (!string_ok(mimeType))
180
196
            mimeType = _(MIMETYPE_DEFAULT);
181
 
        }
182
197
      
183
198
        log_debug("setting content length to unknown\n");
184
199
        /// \todo we could figure out the content length...
190
205
    }
191
206
    else
192
207
    {
193
 
        if (mimeType == nil)
 
208
#ifdef EXTERNAL_TRANSCODING
 
209
        if (!is_srt && string_ok(tr_profile))
 
210
        {
 
211
 
 
212
            Ref<TranscodingProfile> tp = ConfigManager::getInstance()->getTranscodingProfileListOption(CFG_TRANSCODING_PROFILE_LIST)->getByName(tr_profile);
 
213
 
 
214
            if (tp == nil)
 
215
                throw _Exception(_("Transcoding of file ") + path +
 
216
                                 " but no profile matching the name " +
 
217
                                 tr_profile + " found");
 
218
 
 
219
            mimeType = tp->getTargetMimeType();
 
220
            info->file_length = -1;
 
221
        }
 
222
        else
 
223
#endif
 
224
        {
 
225
            info->file_length = statbuf.st_size;
 
226
            // if we are dealing with a regular file we should add the
 
227
            // Accept-Ranges: bytes header, in order to indicate that we support
 
228
            // seeking
 
229
            if (S_ISREG(statbuf.st_mode))
 
230
            {
 
231
                if (string_ok(header))
 
232
                    header = header + _("\r\n");
 
233
 
 
234
                header = header + _("Accept-Ranges: bytes");
 
235
                /// \todo turned out that we are not always allowed to add this
 
236
                /// header, since chunked encoding may be active and we do not
 
237
                /// know that here
 
238
            }
 
239
        }
 
240
 
 
241
        if (!string_ok(mimeType))
194
242
            mimeType = item->getMimeType();
195
243
 
196
 
        info->file_length = statbuf.st_size;
197
 
        // if we are dealing with a regular file we should add the
198
 
        // Accept-Ranges: bytes header, in order to indicate that we support
199
 
        // seeking
200
 
        if (S_ISREG(statbuf.st_mode))
201
 
        {
202
 
            if (string_ok(header))
203
 
                header = header + _("\r\n");
204
 
 
205
 
            header = header + _("Accept-Ranges: bytes");
206
 
        }
207
 
 
208
244
        //log_debug("sizeof off_t %d, statbuf.st_size %d\n", sizeof(off_t), sizeof(statbuf.st_size));
209
245
        //log_debug("get_info: file_length: " OFF_T_SPRINTF "\n", statbuf.st_size);
210
246
        if (string_ok(header))
228
264
    String mimeType;
229
265
    int ret;
230
266
    bool is_srt = false;
 
267
#ifdef EXTERNAL_TRANSCODING
 
268
    String tr_profile;
 
269
#endif
231
270
 
232
271
    log_debug("start\n");
233
272
    struct stat statbuf;
285
324
            struct timespec before;
286
325
            getTimespecNow(&before);
287
326
#endif
288
 
            output = run_process(action, _("run"), input);
 
327
            output = run_simple_process(action, _("run"), input);
289
328
#ifdef LOG_TOMBDEBUG
290
329
            long delta = getDeltaMillis(&before);
291
330
            log_debug("script executed in %ld milliseconds\n", delta);
335
374
    // determining which resource to serve 
336
375
    int res_id = 0;
337
376
    String s_res_id = dict->get(_(URL_RESOURCE_ID));
338
 
    if (s_res_id != nil)
 
377
#ifdef EXTERNAL_TRANSCODING
 
378
    if (string_ok(s_res_id) && (s_res_id != _(URL_VALUE_TRANSCODE_NO_RES_ID)))
 
379
#else
 
380
    if (string_ok(s_res_id))
 
381
#endif
339
382
        res_id = s_res_id.toInt();
 
383
    else
 
384
        res_id = -1;
340
385
 
341
386
    String ext = dict->get(_("ext"));
342
387
    if (ext == ".srt")
392
437
        }
393
438
    }
394
439
    log_debug("fetching resource id %d\n", res_id);
 
440
#ifdef EXTERNAL_TRANSCODING
 
441
    tr_profile = dict->get(_(URL_PARAM_TRANSCODE_PROFILE_NAME));
 
442
    if (string_ok(tr_profile))
 
443
    {
 
444
        if (res_id != (-1))
 
445
            throw _Exception(_("Invalid resource ID given!"));
 
446
    }
 
447
    else
 
448
    {
 
449
        if (res_id == -1)
 
450
            throw _Exception(_("Invalid resource ID given!"));
 
451
    }
 
452
#endif
 
453
 
 
454
    info->http_header = NULL;
395
455
    // Per default and in case of a bad resource ID, serve the file
396
456
    // itself
397
 
 
398
 
    info->http_header = NULL;
399
457
    if ((res_id > 0) && (res_id < item->getResourceCount()))
400
458
    {
401
459
        // http-get:*:image/jpeg:*
402
460
        String protocolInfo = item->getResource(res_id)->getAttributes()->get(_("protocolInfo"));
403
461
        if (protocolInfo != nil)
404
462
        {
405
 
            Ref<Array<StringBase> > parts = split_string(protocolInfo, ':');
406
 
            mimeType = parts->get(2);
 
463
            mimeType = getMTFromProtocolInfo(protocolInfo);
407
464
        }
408
 
        else
409
 
        {
 
465
 
 
466
        if (!string_ok(mimeType))
410
467
            mimeType = _(MIMETYPE_DEFAULT);
411
 
        }
 
468
 
412
469
 
413
470
        info->content_type = ixmlCloneDOMString(mimeType.c_str());
414
471
        info->file_length = -1;
420
477
    }
421
478
    else
422
479
    {
423
 
        if (mimeType == nil)
424
 
            mimeType = item->getMimeType();
425
 
 
426
 
        info->file_length = statbuf.st_size;
427
 
        info->content_type = ixmlCloneDOMString(mimeType.c_str());
428
 
 
429
 
        log_debug("Adding content disposition header: %s\n", header.c_str());
 
480
#ifdef EXTERNAL_TRANSCODING
 
481
        if (!is_srt && string_ok(tr_profile))
 
482
        {
 
483
            Ref<TranscodeDispatcher> tr_d(new TranscodeDispatcher());
 
484
            Ref<TranscodingProfile> tp = ConfigManager::getInstance()->getTranscodingProfileListOption(CFG_TRANSCODING_PROFILE_LIST)->getByName(tr_profile);
 
485
            return tr_d->open(tp, path, item->getObjectType(), info);
 
486
        }
 
487
        else
 
488
#endif
 
489
        {
 
490
            if (mimeType == nil)
 
491
                mimeType = item->getMimeType();
 
492
 
 
493
            info->file_length = statbuf.st_size;
 
494
            info->content_type = ixmlCloneDOMString(mimeType.c_str());
 
495
 
 
496
            log_debug("Adding content disposition header: %s\n", 
 
497
                    header.c_str());
430
498
            // if we are dealing with a regular file we should add the
431
 
        // Accept-Ranges: bytes header, in order to indicate that we support
432
 
        // seeking
433
 
        if (S_ISREG(statbuf.st_mode))
434
 
        {
 
499
            // Accept-Ranges: bytes header, in order to indicate that we support
 
500
            // seeking
 
501
            if (S_ISREG(statbuf.st_mode))
 
502
            {
 
503
                if (string_ok(header))
 
504
                    header = header + _("\r\n");
 
505
 
 
506
                header = header + _("Accept-Ranges: bytes");
 
507
            }
 
508
 
435
509
            if (string_ok(header))
436
 
                header = header + _("\r\n");
437
 
 
438
 
            header = header + _("Accept-Ranges: bytes");
 
510
                info->http_header = ixmlCloneDOMString(header.c_str());
 
511
 
 
512
 
 
513
            Ref<IOHandler> io_handler(new FileIOHandler(path));
 
514
            io_handler->open(mode);
 
515
            return io_handler;
439
516
        }
440
 
 
441
 
        if (string_ok(header))
442
 
             info->http_header = ixmlCloneDOMString(header.c_str());
443
 
 
444
 
 
445
 
        Ref<IOHandler> io_handler(new FileIOHandler(path));
446
 
        io_handler->open(mode);
447
 
        return io_handler;
448
517
    }
449
518
}