Overview
Comment: | Added vhost support |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
3298334221905511f3e91d731834f546 |
User & Date: | rkeene on 2014-02-18 03:47:37 |
Other Links: | manifest | tags |
Context
2014-02-18
| ||
05:16 | More logging optimizations check-in: 937df4b0c8 user: rkeene tags: trunk | |
03:47 | Added vhost support check-in: 3298334221 user: rkeene tags: trunk | |
03:45 | Fixed call to wrong function for finding end of HTTP path check-in: 773268af3c user: rkeene tags: trunk | |
Changes
Modified filed.1 from [5b3db65898] to [5afcb460b6].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | + | .PU .TH FILED 1 "12 Feb 14" "filed 1.7" .SH NAME filed \- serve files over HTTP .SH SYNOPSIS .ll +10 .B filed .RB [{ \-h | \-\-help }] .RB [{ \-d | \-\-daemon }] .RB [{ \-v | \-\-version }] .RB [{ \-V | \-\-vhost }] .RB [{ \-b | \-\-bind } .IR address ] .RB [{ \-p | \-\-port } .IR port ] .RB [{ \-t | \-\-threads } .IR count ] .RB [{ \-c | \-\-cache } |
︙ | |||
42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | + + + + + | .TP .B -v (or --version) Instructs .B filed to print out its version number and then exit. .TP .B -V (or --vhost) instructs filed to prepend all requests with their HTTP Host header. .TP .B -b (or --bind) Specifies the address to listen for incoming HTTP requests on. .TP .B -p (or --port) |
︙ |
Modified filed.c from [91c2968a74] to [4157b8b146].
︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | + + + + + + | /* Default values */ #define PORT 80 #define THREAD_COUNT 5 #define BIND_ADDR "::" #define CACHE_SIZE 8209 #define LOG_FILE "-" /* Configuration options that work threads need to be aware of */ struct filed_options { int vhosts_enabled; }; /* Arguments for worker threads */ struct filed_worker_thread_args { int fd; struct filed_options options; }; /* Arguments for logging threads */ struct filed_logging_thread_args { FILE *fp; }; |
︙ | |||
55 56 57 58 59 60 61 | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | - + + + + + + | char etag[64]; }; /* Request variables */ struct filed_http_request { /** Buffers **/ struct filed_fileinfo fileinfo; |
︙ | |||
623 624 625 626 627 628 629 | 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | - + + + + | pthread_mutex_unlock(&cache->mutex); return(buffer); } /* Process an HTTP request and return the path requested */ |
︙ | |||
658 659 660 661 662 663 664 | 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | - + | *buffer = '\0'; buffer++; path = buffer; /* Terminate path component */ |
︙ | |||
709 710 711 712 713 714 715 716 717 718 719 720 721 722 | 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | + + + + + + + + + + + + + + | workbuffer++; if (*workbuffer != '\r' && *workbuffer != '\n') { range_end = strtoull(workbuffer, &workbuffer_next, 10); } } } } else if (strncasecmp(buffer, "Host: ", 5) == 0) { buffer_st->headers.host.present = 1; workbuffer = strpbrk(buffer + 5, "\r\n:"); if (workbuffer != NULL) { *workbuffer = '\0'; } workbuffer = buffer + 5; while (*workbuffer == ' ') { workbuffer++; } strcpy(buffer_st->headers.host.host, workbuffer); } if (memcmp(buffer, "\r\n", 2) == 0) { break; } } |
︙ | |||
735 736 737 738 739 740 741 742 743 744 745 746 747 748 | 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 | + + + + + + + + + + + + + + + + + + + | ); } /* Fill up structure to return */ buffer_st->headers.range.present = range_request; buffer_st->headers.range.offset = range_start; buffer_st->headers.range.length = range_length; /* If vhosts are enabled, compute new path */ if (options->vhosts_enabled) { if (buffer_st->headers.host.present == 1) { buffer = buffer_st->tmpbuf; buffer_len = sizeof(buffer_st->tmpbuf); snprintf_ret = snprintf(buffer, buffer_len, "/%s%s%s", buffer_st->headers.host.host, buffer_st->path[0] == '/' ? "" : "/", buffer_st->path ); if (snprintf_ret >= 0) { if (((unsigned int) snprintf_ret) < buffer_len) { strcpy(buffer_st->path, buffer); } } } } return(buffer_st); } /* Return an error page */ static void filed_error_page(FILE *fp, const char *date_current, int error_number, int method) { char *error_string = "<html><head><title>ERROR</title></head><body>Unable to process request</body></html>"; |
︙ | |||
760 761 762 763 764 765 766 | 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | - + - + | fprintf(fp, "%s", error_string); } return; } /* Handle a single request from a client */ |
︙ | |||
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 | 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | + + | } /* Handle incoming connections */ static void *filed_worker_thread(void *arg_v) { struct filed_worker_thread_args *arg; struct filed_http_request request; struct filed_log_entry *log, local_dummy_log; struct filed_options *options; struct sockaddr_in6 addr; socklen_t addrlen; int failure_count = 0, max_failure_count = FILED_MAX_FAILURE_COUNT; int master_fd, fd; /* Read arguments */ arg = arg_v; master_fd = arg->fd; options = &arg->options; while (1) { /* Failure loop prevention */ if (failure_count > max_failure_count) { break; } |
︙ | |||
1009 1010 1011 1012 1013 1014 1015 | 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 | - + - + + | } log->port = addr.sin6_port; /* Reset failure count*/ failure_count = 0; /* Handle socket */ |
︙ | |||
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 | + + + + | } fprintf(output, "Usage: filed [<options>]\n"); fprintf(output, " Options:\n"); fprintf(output, " -h, --help\n"); fprintf(output, " -d, --daemon\n"); fprintf(output, " -v, --version\n"); fprintf(output, " -V, --vhost\n"); fprintf(output, " -b <address>, --bind <address>\n"); fprintf(output, " -p <port>, --port <port>\n"); fprintf(output, " -t <count>, --threads <count>\n"); fprintf(output, " -c <entries>, --cache <entries>\n"); fprintf(output, " -l <file>, --log <file>\n"); fprintf(output, " -u <user>, --user <user>\n"); fprintf(output, " -r <directory>, --root <directory>\n"); if (long_help) { fprintf(output, "\n"); fprintf(output, " Usage:\n"); fprintf(output, " -h (or --help) prints this usage information.\n"); fprintf(output, "\n"); fprintf(output, " -d (or --daemon) instructs filed to become a daemon after initializing\n"); fprintf(output, " the listening TCP socket and log files.\n"); fprintf(output, "\n"); fprintf(output, " -v (or --version) instructs filed print out the version number and exit.\n"); fprintf(output, "\n"); fprintf(output, " -V (or --vhost) instructs filed to prepend all requests with their HTTP\n"); fprintf(output, " Host header.\n"); fprintf(output, "\n"); fprintf(output, " -b (or --bind) specifies the address to listen for incoming HTTP\n"); fprintf(output, " requests on. The default value is \"%s\".\n", BIND_ADDR); fprintf(output, "\n"); fprintf(output, " -p (or --port) specifies the TCP port number to listen for incoming HTTP\n"); fprintf(output, " requests on. The default is %u.\n", (unsigned int) PORT); fprintf(output, "\n"); |
︙ | |||
1222 1223 1224 1225 1226 1227 1228 | 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 | - + + + + + - - + + + | close(fd_out); return(0); } /* Run process */ int main(int argc, char **argv) { |
︙ | |||
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 | + + + + | newroot = strdup(optarg); break; case 'l': log_file = strdup(optarg); break; case 'd': daemon_enabled = 1; break; case 'V': thread_options.vhosts_enabled = 1; break; case 'v': printf("filed version %s\n", FILED_VERSION); return(0); case '?': case ':': |
︙ | |||
1363 1364 1365 1366 1367 1368 1369 | 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 | - + | if (init_ret != 0) { perror("filed_logging_thread_init"); return(4); } /* Create worker threads */ |
︙ |