~ubuntu-branches/ubuntu/natty/lighttpd/natty

« back to all changes in this revision

Viewing changes to src/http-header-glue.c

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Krzyżaniak (eloy)
  • Date: 2009-10-30 17:37:29 UTC
  • mto: (6.1.4 squeeze)
  • mto: This revision was merged to the branch mainline in revision 50.
  • Revision ID: james.westby@ubuntu.com-20091030173729-ehmsdiba9nkcd0j7
Tags: upstream-1.4.24
Import upstream version 1.4.24

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define _GNU_SOURCE
2
 
 
3
 
#include <string.h>
4
 
#include <errno.h>
5
 
#include <time.h>
6
 
 
7
1
#include "base.h"
8
2
#include "array.h"
9
3
#include "buffer.h"
11
5
#include "etag.h"
12
6
#include "response.h"
13
7
 
 
8
#include <string.h>
 
9
#include <errno.h>
 
10
 
 
11
#include <time.h>
 
12
 
14
13
/*
15
14
 * This was 'borrowed' from tcpdump.
16
15
 *
104
103
        return response_header_insert(srv, con, key, keylen, value, vallen);
105
104
}
106
105
 
 
106
int response_header_append(server *srv, connection *con, const char *key, size_t keylen, const char *value, size_t vallen) {
 
107
        data_string *ds;
 
108
 
 
109
        UNUSED(srv);
 
110
 
 
111
        /* if there already is a key by this name append the value */
 
112
        if (NULL != (ds = (data_string *)array_get_element(con->response.headers, key))) {
 
113
                buffer_append_string_len(ds->value, CONST_STR_LEN(", "));
 
114
                buffer_append_string_len(ds->value, value, vallen);
 
115
                return 0;
 
116
        }
 
117
 
 
118
        return response_header_insert(srv, con, key, keylen, value, vallen);
 
119
}
 
120
 
107
121
int http_response_redirect_to_directory(server *srv, connection *con) {
108
122
        buffer *o;
109
123
 
259
273
                                        }
260
274
 
261
275
                                        if (0 == strncmp(con->request.http_if_modified_since, mtime->ptr, used_len)) {
262
 
                                                con->http_status = 304;
 
276
                                                if ('\0' == mtime->ptr[used_len]) con->http_status = 304;
263
277
                                                return HANDLER_FINISHED;
264
278
                                        } else {
265
279
                                                char buf[sizeof("Sat, 23 Jul 2005 21:20:01 GMT")];
281
295
                                                strncpy(buf, con->request.http_if_modified_since, used_len);
282
296
                                                buf[used_len] = '\0';
283
297
 
284
 
                                                tm.tm_isdst = 0;
285
298
                                                if (NULL == strptime(buf, "%a, %d %b %Y %H:%M:%S GMT", &tm)) {
286
299
                                                        con->http_status = 412;
287
300
                                                        con->mode = DIRECT;
288
301
                                                        return HANDLER_FINISHED;
289
302
                                                }
 
303
                                                tm.tm_isdst = 0;
290
304
                                                t_header = mktime(&tm);
291
305
 
292
306
                                                strptime(mtime->ptr, "%a, %d %b %Y %H:%M:%S GMT", &tm);
 
307
                                                tm.tm_isdst = 0;
293
308
                                                t_file = mktime(&tm);
294
309
 
295
310
                                                if (t_file > t_header) return HANDLER_GO_ON;
318
333
                }
319
334
 
320
335
                if (0 == strncmp(con->request.http_if_modified_since, mtime->ptr, used_len)) {
321
 
                        con->http_status = 304;
 
336
                        if ('\0' == mtime->ptr[used_len]) con->http_status = 304;
322
337
                        return HANDLER_FINISHED;
323
338
                } else {
324
339
                        char buf[sizeof("Sat, 23 Jul 2005 21:20:01 GMT")];
331
346
                        strncpy(buf, con->request.http_if_modified_since, used_len);
332
347
                        buf[used_len] = '\0';
333
348
 
334
 
                        tm.tm_isdst = 0;
335
349
                        if (NULL == strptime(buf, "%a, %d %b %Y %H:%M:%S GMT", &tm)) {
336
350
                                /**
337
351
                                 * parsing failed, let's get out of here 
338
352
                                 */
339
 
                                log_error_write(srv, __FILE__, __LINE__, "ss",
340
 
                                                "strptime() failed on", buf);
341
353
                                return HANDLER_GO_ON;
342
354
                        }
 
355
                        tm.tm_isdst = 0;
343
356
                        t_header = mktime(&tm);
344
357
 
345
358
                        strptime(mtime->ptr, "%a, %d %b %Y %H:%M:%S GMT", &tm);
 
359
                        tm.tm_isdst = 0;
346
360
                        t_file = mktime(&tm);
347
361
 
348
362
                        if (t_file > t_header) return HANDLER_GO_ON;