7
7
Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
8
8
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
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>
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.
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 $
30
30
/// \file file_request_handler.cc
108
114
// determining which resource to serve
110
116
String s_res_id = dict->get(_(URL_RESOURCE_ID));
117
#ifdef EXTERNAL_TRANSCODING
118
if (string_ok(s_res_id) && (s_res_id != _(URL_VALUE_TRANSCODE_NO_RES_ID)))
120
if (string_ok(s_res_id))
112
122
res_id = s_res_id.toInt();
115
127
String ext = dict->get(_("ext"));
179
#ifdef EXTERNAL_TRANSCODING
180
tr_profile = dict->get(_(URL_PARAM_TRANSCODE_PROFILE_NAME));
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()))
172
189
String protocolInfo = item->getResource(res_id)->getAttributes()->get(_("protocolInfo"));
173
190
if (protocolInfo != nil)
175
Ref<Array<StringBase> > parts = split_string(protocolInfo, ':');
176
mimeType = parts->get(2);
192
mimeType = getMTFromProtocolInfo(protocolInfo);
195
if (!string_ok(mimeType))
180
196
mimeType = _(MIMETYPE_DEFAULT);
183
198
log_debug("setting content length to unknown\n");
184
199
/// \todo we could figure out the content length...
208
#ifdef EXTERNAL_TRANSCODING
209
if (!is_srt && string_ok(tr_profile))
212
Ref<TranscodingProfile> tp = ConfigManager::getInstance()->getTranscodingProfileListOption(CFG_TRANSCODING_PROFILE_LIST)->getByName(tr_profile);
215
throw _Exception(_("Transcoding of file ") + path +
216
" but no profile matching the name " +
217
tr_profile + " found");
219
mimeType = tp->getTargetMimeType();
220
info->file_length = -1;
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
229
if (S_ISREG(statbuf.st_mode))
231
if (string_ok(header))
232
header = header + _("\r\n");
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
241
if (!string_ok(mimeType))
194
242
mimeType = item->getMimeType();
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
200
if (S_ISREG(statbuf.st_mode))
202
if (string_ok(header))
203
header = header + _("\r\n");
205
header = header + _("Accept-Ranges: bytes");
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))
285
324
struct timespec before;
286
325
getTimespecNow(&before);
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
337
376
String s_res_id = dict->get(_(URL_RESOURCE_ID));
377
#ifdef EXTERNAL_TRANSCODING
378
if (string_ok(s_res_id) && (s_res_id != _(URL_VALUE_TRANSCODE_NO_RES_ID)))
380
if (string_ok(s_res_id))
339
382
res_id = s_res_id.toInt();
341
386
String ext = dict->get(_("ext"));
342
387
if (ext == ".srt")
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))
445
throw _Exception(_("Invalid resource ID given!"));
450
throw _Exception(_("Invalid resource ID given!"));
454
info->http_header = NULL;
395
455
// Per default and in case of a bad resource ID, serve the file
398
info->http_header = NULL;
399
457
if ((res_id > 0) && (res_id < item->getResourceCount()))
401
459
// http-get:*:image/jpeg:*
402
460
String protocolInfo = item->getResource(res_id)->getAttributes()->get(_("protocolInfo"));
403
461
if (protocolInfo != nil)
405
Ref<Array<StringBase> > parts = split_string(protocolInfo, ':');
406
mimeType = parts->get(2);
463
mimeType = getMTFromProtocolInfo(protocolInfo);
466
if (!string_ok(mimeType))
410
467
mimeType = _(MIMETYPE_DEFAULT);
413
470
info->content_type = ixmlCloneDOMString(mimeType.c_str());
414
471
info->file_length = -1;
424
mimeType = item->getMimeType();
426
info->file_length = statbuf.st_size;
427
info->content_type = ixmlCloneDOMString(mimeType.c_str());
429
log_debug("Adding content disposition header: %s\n", header.c_str());
480
#ifdef EXTERNAL_TRANSCODING
481
if (!is_srt && string_ok(tr_profile))
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);
491
mimeType = item->getMimeType();
493
info->file_length = statbuf.st_size;
494
info->content_type = ixmlCloneDOMString(mimeType.c_str());
496
log_debug("Adding content disposition header: %s\n",
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
433
if (S_ISREG(statbuf.st_mode))
499
// Accept-Ranges: bytes header, in order to indicate that we support
501
if (S_ISREG(statbuf.st_mode))
503
if (string_ok(header))
504
header = header + _("\r\n");
506
header = header + _("Accept-Ranges: bytes");
435
509
if (string_ok(header))
436
header = header + _("\r\n");
438
header = header + _("Accept-Ranges: bytes");
510
info->http_header = ixmlCloneDOMString(header.c_str());
513
Ref<IOHandler> io_handler(new FileIOHandler(path));
514
io_handler->open(mode);
441
if (string_ok(header))
442
info->http_header = ixmlCloneDOMString(header.c_str());
445
Ref<IOHandler> io_handler(new FileIOHandler(path));
446
io_handler->open(mode);