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
|
};
/* File information */
struct filed_fileinfo {
pthread_mutex_t mutex;
char *path;
int fd;
size_t len;
char *lastmod;
char lastmod_b[64];
char *type;
};
/* Request variables */
struct filed_http_request {
/** Buffers **/
struct filed_fileinfo fileinfo;
char path_b[1010];
char tmpbuf[1010];
/** HTTP Request information **/
char *path; /*** Path being requested ***/
struct {
struct {
int present;
off_t offset; /*** Range start ***/
ssize_t length; /*** Range length ***/
} range;
} headers;
};
/* Global variables */
/** Open File cache **/
struct filed_fileinfo *filed_fileinfo_fdcache;
|
|
|
|
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
|
};
/* File information */
struct filed_fileinfo {
pthread_mutex_t mutex;
char *path;
int fd;
off_t len;
char *lastmod;
char lastmod_b[64];
char *type;
};
/* Request variables */
struct filed_http_request {
/** Buffers **/
struct filed_fileinfo fileinfo;
char path_b[1010];
char tmpbuf[1010];
/** HTTP Request information **/
char *path; /*** Path being requested ***/
struct {
struct {
int present;
off_t offset; /*** Range start ***/
off_t length; /*** Range length ***/
} range;
} headers;
};
/* Global variables */
/** Open File cache **/
struct filed_fileinfo *filed_fileinfo_fdcache;
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
}
/* Process an HTTP request and return the path requested */
static struct filed_http_request *filed_get_http_request(FILE *fp, struct filed_http_request *buffer_st) {
char *method, *path;
char *buffer, *tmpbuffer, *workbuffer, *workbuffer_next;
size_t buffer_len, tmpbuffer_len;
off_t range_start, range_end;
ssize_t range_length;
int range_request;
int i;
range_start = 0;
range_end = 0;
range_request = 0;
range_length = -1;
|
|
<
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
}
/* Process an HTTP request and return the path requested */
static struct filed_http_request *filed_get_http_request(FILE *fp, struct filed_http_request *buffer_st) {
char *method, *path;
char *buffer, *tmpbuffer, *workbuffer, *workbuffer_next;
size_t buffer_len, tmpbuffer_len;
off_t range_start, range_end, range_length;
int range_request;
int i;
range_start = 0;
range_end = 0;
range_request = 0;
range_length = -1;
|
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
fileinfo = filed_open_file(path, &request->fileinfo);
if (fileinfo == NULL) {
filed_error_page(fp, date_current, 404);
filed_log_msg("PROCESS_REPLY_COMPLETE FD=... ERROR=404");
} else {
if (request->headers.range.offset != 0 || request->headers.range.length >= 0) {
if ((size_t) request->headers.range.offset >= fileinfo->len) {
filed_log_msg("PROCESS_REPLY_COMPLETE FD=... ERROR=416");
filed_error_page(fp, date_current, 416);
} else {
if (request->headers.range.length < 0) {
filed_log_msg_debug("Computing length to fit in bounds: fileinfo->len = %llu, request->headers.range.offset = %llu",
(unsigned long long) fileinfo->len,
(unsigned long long) request->headers.range.offset
);
request->headers.range.length = fileinfo->len - request->headers.range.offset;
}
filed_log_msg_debug("Partial request, starting at: %llu and running for %llu bytes", (unsigned long long) request->headers.range.offset, (unsigned long long) request->headers.range.length);
http_code = 206;
}
} else {
if (request->headers.range.present) {
http_code = 206;
} else {
|
|
|
>
>
>
|
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
fileinfo = filed_open_file(path, &request->fileinfo);
if (fileinfo == NULL) {
filed_error_page(fp, date_current, 404);
filed_log_msg("PROCESS_REPLY_COMPLETE FD=... ERROR=404");
} else {
if (request->headers.range.offset != 0 || request->headers.range.length >= 0) {
if (request->headers.range.offset >= fileinfo->len) {
filed_log_msg("PROCESS_REPLY_COMPLETE FD=... ERROR=416");
filed_error_page(fp, date_current, 416);
} else {
if (request->headers.range.length < 0) {
filed_log_msg_debug("Computing length to fit in bounds: fileinfo->len = %llu, request->headers.range.offset = %llu",
(unsigned long long) fileinfo->len,
(unsigned long long) request->headers.range.offset
);
request->headers.range.length = fileinfo->len - request->headers.range.offset;
}
filed_log_msg_debug("Partial request, starting at: %llu and running for %llu bytes",
(unsigned long long) request->headers.range.offset,
(unsigned long long) request->headers.range.length
);
http_code = 206;
}
} else {
if (request->headers.range.present) {
http_code = 206;
} else {
|