forked from NadiaSama/FG.video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fgvideo_letv_handler.c
70 lines (56 loc) · 1.47 KB
/
fgvideo_letv_handler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (C) NadiaF0rever
* Copyright (C) Beijing Datafrog Technology Co., Ltd.
*/
#include "fgvideo_common_handler.h"
#include "fgvideo_letv_handler.h"
static ngx_int_t letv_handler(ngx_http_request_t *r, ngx_str_t * \
file_name, ngx_open_file_info_t *of, ngx_chain_t **out);
ngx_int_t
fgvideo_letv_ts_handler(ngx_http_request_t *r)
{
return fgvideo_common_handler(r, letv_handler);
}
ngx_int_t
fgvideo_letv_letv_handler(ngx_http_request_t *r)
{
return fgvideo_common_handler(r, letv_handler);
}
static ngx_int_t
letv_handler(ngx_http_request_t *r, ngx_str_t *file_name, \
ngx_open_file_info_t *of, ngx_chain_t **out)
{
ngx_str_t value;
off_t start, end;
start = 0;
end = of->size;
if(r->args.len == 0){
goto done;
}
#define LETV_RSTART "rstart"
if(ngx_http_arg(r, (u_char *)LETV_RSTART, sizeof(LETV_RSTART) - 1, &value \
) == NGX_OK){
start = ngx_atoof(value.data, value.len);
if(start == NGX_ERROR || start >= of->size){
return NGX_HTTP_BAD_REQUEST;
}
}
#define LETV_REND "rend"
if(ngx_http_arg(r, (u_char *)LETV_REND, sizeof(LETV_REND) - 1, &value) \
== NGX_OK){
end = ngx_atoof(value.data, value.len);
if(end == NGX_ERROR || end >= of->size){
return NGX_HTTP_BAD_REQUEST;
}
}
if(start >= end){
return NGX_HTTP_BAD_REQUEST;
}
done:
if(fgvideo_range_response(r, file_name, of, start, (end - start), out) \
!= NGX_OK){
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT;
return NGX_OK;
}