- Timestamp:
- Sep 16, 2024, 9:42:19 PM (2 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile
r25 r32 23 23 24 24 format: 25 clang-format --verbose -i `find ./Server ./Common ./Module -name "*.c" -or -name "*.h"`25 clang-format --verbose -i `find ./Server ./Common ./Module "(" -name "*.c" -or -name "*.h" ")" -and -not -name "strptime.*"` 26 26 27 27 clean: -
trunk/README
r1 r32 1 1 Simple HTTP daemon 2 3 Put under public domain, except Server/strptime.{c,h}. -
trunk/Server/Makefile
r17 r32 6 6 .SUFFIXES: .c .o 7 7 8 OBJS = version.o main.o config.o server.o ssl.o http.o module.o 8 OBJS = version.o main.o config.o server.o ssl.o http.o module.o strptime.o 9 9 10 10 all: tewi$(EXEC) -
trunk/Server/server.c
r31 r32 16 16 #include <stdarg.h> 17 17 #include <sys/stat.h> 18 #include <time.h> 18 19 19 20 #include <cm_string.h> … … 24 25 #include <winsock2.h> 25 26 #include <process.h> 27 28 #include "strptime.h" 26 29 #else 27 30 #include <sys/select.h> … … 170 173 "</html>\n" 171 174 172 void _tw_process_page(SSL* ssl, int sock, const char* status, const char* type, FILE* f, const unsigned char* doc, size_t size, char** headers ) {175 void _tw_process_page(SSL* ssl, int sock, const char* status, const char* type, FILE* f, const unsigned char* doc, size_t size, char** headers, time_t mtime, time_t cmtime) { 173 176 char construct[512]; 177 if(mtime != 0 && cmtime != 0 && mtime <= cmtime) { 178 status = "304 Not Modified"; 179 type = NULL; 180 size = 0; 181 headers = NULL; 182 f = NULL; 183 doc = NULL; 184 } 174 185 sprintf(construct, "%llu", (unsigned long long)size); 175 186 tw_write(ssl, sock, "HTTP/1.1 ", 9); … … 188 199 tw_write(ssl, sock, construct, strlen(construct)); 189 200 tw_write(ssl, sock, "\r\n", 2); 201 if(mtime != 0) { 202 struct tm* tm = gmtime(&mtime); 203 char date[513]; 204 strftime(date, 512, "%a, %d %b %Y %H:%M:%S GMT", tm); 205 tw_write(ssl, sock, "Last-Modified: ", 5 + 8 + 2); 206 tw_write(ssl, sock, date, strlen(date)); 207 tw_write(ssl, sock, "\r\n", 2); 208 } 190 209 } 191 210 int i; … … 215 234 } 216 235 217 void tw_process_page(SSL* ssl, int sock, const char* status, const char* type, FILE* f, const unsigned char* doc, size_t size ) { _tw_process_page(ssl, sock, status, type, f, doc, size, NULL); }236 void tw_process_page(SSL* ssl, int sock, const char* status, const char* type, FILE* f, const unsigned char* doc, size_t size, time_t mtime, time_t cmtime) { _tw_process_page(ssl, sock, status, type, f, doc, size, NULL, mtime, cmtime); } 218 237 219 238 const char* tw_http_status(int code) { … … 258 277 void tw_http_error(SSL* ssl, int sock, int error, char* name, int port) { 259 278 char* str = tw_http_default_error(error, name, port); 260 tw_process_page(ssl, sock, tw_http_status(error), "text/html", NULL, str, strlen(str) );279 tw_process_page(ssl, sock, tw_http_status(error), "text/html", NULL, str, strlen(str), 0, 0); 261 280 free(str); 262 281 } … … 389 408 char* vhost = cm_strdup(config.hostname); 390 409 int i; 410 time_t cmtime = 0; 391 411 for(i = 0; req.headers[i] != NULL; i += 2) { 392 412 if(cm_strcaseequ(req.headers[i], "Host")) { 393 413 free(vhost); 394 vhost = req.headers[i + 1]; 395 break; 414 vhost = cm_strdup(req.headers[i + 1]); 415 } else if(cm_strcaseequ(req.headers[i], "If-Modified-Since")) { 416 struct tm tm; 417 strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm); 418 #ifdef __MINGW32__ 419 cmtime = _mkgmtime(&tm); 420 #else 421 cmtime = timegm(&tm); 422 #endif 396 423 } 397 424 } … … 435 462 if(req.path[strlen(req.path) - 1] != '/') { 436 463 char* headers[3] = {"Location", cm_strcat(req.path, "/"), NULL}; 437 _tw_process_page(s, sock, tw_http_status(308), NULL, NULL, NULL, 0, headers );464 _tw_process_page(s, sock, tw_http_status(308), NULL, NULL, NULL, 0, headers, 0, 0); 438 465 free(headers[1]); 439 466 } else { … … 458 485 stat(p, &st); 459 486 char* mime = tw_get_mime(ext, vhost_entry); 460 tw_process_page(s, sock, tw_http_status(200), mime, f, NULL, st.st_size );487 tw_process_page(s, sock, tw_http_status(200), mime, f, NULL, st.st_size, 0, 0); 461 488 fclose(f); 462 489 free(p); … … 572 599 addstring(&str, " </body>\n"); 573 600 addstring(&str, "</html>\n"); 574 tw_process_page(s, sock, tw_http_status(200), "text/html", NULL, str, strlen(str) );601 tw_process_page(s, sock, tw_http_status(200), "text/html", NULL, str, strlen(str), 0, 0); 575 602 free(str); 576 603 } … … 589 616 if(ext != NULL) free(ext); 590 617 FILE* f = fopen(path, "rb"); 591 tw_process_page(s, sock, tw_http_status(200), mime, f, NULL, st.st_size );618 tw_process_page(s, sock, tw_http_status(200), mime, f, NULL, st.st_size, st.st_mtime, cmtime); 592 619 fclose(f); 593 620 } … … 599 626 free(vhost); 600 627 free(host); 628 tw_free_request(&req); 601 629 } else if(ret == -1) { 602 630 } else { -
trunk/Server/tw_http.h
r20 r32 23 23 #ifdef SOURCE 24 24 #include <openssl/ssl.h> 25 void tw_free_request(struct tw_http_request* req); 25 26 int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req); 26 27 #endif -
trunk/example.conf
r30 r32 4 4 #LoadModule /home/nishi/SVN/tewi/trunk/Module/mod_example.so 5 5 6 Listen 80 7 ListenSSL 4436 Listen 8080 7 #ListenSSL 443 8 8 9 9 SSLKey key.pem
Note:
See TracChangeset
for help on using the changeset viewer.