Changeset 148
- Timestamp:
- 02/18/06 20:12:06 (3 years ago)
- Files:
-
- fastphoto/trunk/src/cgi.c (modified) (3 diffs)
- fastphoto/trunk/src/fastphoto.h (modified) (1 diff)
- fastphoto/trunk/src/header.c (modified) (1 diff)
- fastphoto/trunk/src/header.h (modified) (1 diff)
- fastphoto/trunk/src/httpdate.c (modified) (2 diffs)
- fastphoto/trunk/src/httpdate.h (modified) (1 diff)
- fastphoto/trunk/src/main.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fastphoto/trunk/src/cgi.c
r147 r148 8 8 #include "cache.h" 9 9 #include "header.h" 10 #include "httpdate.h" 10 11 #include "photo.h" 11 12 … … 77 78 char * path_translated; 78 79 char * query_string; 80 char * if_modified_since; 81 time_t since_time; 79 82 80 83 gateway_interface = getenv ("GATEWAY_INTERFACE"); … … 83 86 } 84 87 88 httpdate_init (); 89 85 90 path_info = getenv ("PATH_INFO"); 86 91 path_translated = getenv ("PATH_TRANSLATED"); 87 92 query_string = getenv ("QUERY_STRING"); 93 if_modified_since = getenv ("HTTP_IF_MODIFIED_SINCE"); 88 94 89 95 photo_init (¶ms->in, path_translated); 96 97 if (if_modified_since != NULL) { 98 int len; 99 100 fprintf (stderr, "If-Modified-Since: %s\n", if_modified_since); 101 102 len = strlen (if_modified_since) + 1; 103 since_time = httpdate_parse (if_modified_since, len); 104 105 if (params->in.mtime <= since_time) { 106 return HTTP_NOT_MODIFIED; 107 } 108 } 90 109 91 110 parse_query (params, query_string); fastphoto/trunk/src/fastphoto.h
r147 r148 8 8 9 9 #define FASTPHOTO_DEFAULT_CACHEDIR "/var/cache/fastphoto" 10 11 #define HTTP_NOT_MODIFIED 304 10 12 11 13 typedef struct fastphoto_s fastphoto_t; fastphoto/trunk/src/header.c
r143 r148 16 16 httpdate_snprint (buf, 30, mtime); 17 17 return printf ("Last-Modified: %s\n", buf); 18 } 19 20 int 21 header_not_modified (void) 22 { 23 fprintf (stderr, "304 Not Modified\n"); 24 return printf ("Status: 304 Not Modified\n"); 18 25 } 19 26 fastphoto/trunk/src/header.h
r140 r148 5 5 int header_content_length (int len); 6 6 int header_last_modified (time_t mtime); 7 int header_not_modified (void); 7 8 int header_end (void); 8 9 fastphoto/trunk/src/httpdate.c
r146 r148 11 11 static char * months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 12 12 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 13 14 void 15 httpdate_init (void) 16 { 17 tzset(); 18 } 13 19 14 20 int … … 55 61 d.tm_year -= 1900; 56 62 63 d.tm_sec -= timezone; 64 57 65 return mktime (&d); 58 66 } fastphoto/trunk/src/httpdate.h
r144 r148 4 4 #include <time.h> 5 5 6 void httpdate_init (void); 6 7 int httpdate_snprint (char * buf, int n, time_t mtime); 7 8 time_t httpdate_parse (char * s, int n); fastphoto/trunk/src/main.c
r147 r148 148 148 149 149 memset (¶ms, 0, sizeof (fastphoto_t)); 150 151 cgi = cgi_init(¶ms); 150 152 151 if (cgi_init(¶ms)) { 152 cgi = 1; 153 if (cgi == 1) { 153 154 header_content_type_jpeg (); 155 } else if (cgi == HTTP_NOT_MODIFIED) { 156 header_not_modified(); 157 header_end(); 158 goto cleanup; 154 159 } else { 155 160 err = cmd_init(¶ms, argc, argv); … … 178 183 } 179 184 185 cleanup: 186 180 187 if (params.data) free (params.data); 181 188
