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

« back to all changes in this revision

Viewing changes to src/mod_proxy.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
 
#include <sys/types.h>
2
 
 
3
 
#include <unistd.h>
4
 
#include <errno.h>
5
 
#include <fcntl.h>
6
 
#include <string.h>
7
 
#include <stdlib.h>
8
 
#include <ctype.h>
9
 
#include <assert.h>
10
 
 
11
1
#include "buffer.h"
12
2
#include "server.h"
13
3
#include "keyvalue.h"
24
14
#include "inet_ntop_cache.h"
25
15
#include "crc32.h"
26
16
 
 
17
#include <sys/types.h>
 
18
 
 
19
#include <unistd.h>
 
20
#include <errno.h>
 
21
#include <fcntl.h>
 
22
#include <string.h>
 
23
#include <stdlib.h>
 
24
#include <ctype.h>
 
25
#include <assert.h>
 
26
 
27
27
#include <stdio.h>
28
28
 
29
29
#ifdef HAVE_SYS_FILIO_H
756
756
 
757
757
        switch(hctx->state) {
758
758
        case PROXY_STATE_INIT:
 
759
#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
759
760
                if (strstr(host->host->ptr,":")) {
760
761
                    if (-1 == (hctx->fd = socket(AF_INET6, SOCK_STREAM, 0))) {
761
762
                        log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed: ", strerror(errno));
762
763
                        return HANDLER_ERROR;
763
764
                    }
764
 
                } else {
 
765
                } else
 
766
#endif
 
767
                {
765
768
                    if (-1 == (hctx->fd = socket(AF_INET, SOCK_STREAM, 0))) {
766
769
                        log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed: ", strerror(errno));
767
770
                        return HANDLER_ERROR;
842
845
 
843
846
                chunkqueue_remove_finished_chunks(hctx->wb);
844
847
 
845
 
                if (-1 == ret) {
846
 
                        if (errno != EAGAIN &&
847
 
                            errno != EINTR) {
848
 
                                log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed:", strerror(errno), errno);
849
 
 
850
 
                                return HANDLER_ERROR;
851
 
                        } else {
852
 
                                fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
853
 
 
854
 
                                return HANDLER_WAIT_FOR_EVENT;
855
 
                        }
 
848
                if (-1 == ret) { /* error on our side */
 
849
                        log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed:", strerror(errno), errno);
 
850
 
 
851
                        return HANDLER_WAIT_FOR_EVENT;
 
852
                } else if (-2 == ret) { /* remote close */
 
853
                        log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed, remote connection close:", strerror(errno), errno);
 
854
 
 
855
                        return HANDLER_WAIT_FOR_EVENT;
856
856
                }
857
857
 
858
858
                if (hctx->wb->bytes_out == hctx->wb->bytes_in) {
1107
1107
 
1108
1108
        /* check if extension matches */
1109
1109
        for (k = 0; k < p->conf.extensions->used; k++) {
 
1110
                data_array *ext = NULL;
1110
1111
                size_t ct_len;
1111
1112
 
1112
 
                extension = (data_array *)p->conf.extensions->data[k];
1113
 
 
1114
 
                if (extension->key->used == 0) continue;
1115
 
 
1116
 
                ct_len = extension->key->used - 1;
 
1113
                ext = (data_array *)p->conf.extensions->data[k];
 
1114
 
 
1115
                if (ext->key->used == 0) continue;
 
1116
 
 
1117
                ct_len = ext->key->used - 1;
1117
1118
 
1118
1119
                if (s_len < ct_len) continue;
1119
1120
 
1120
1121
                /* check extension in the form "/proxy_pattern" */
1121
 
                if (*(extension->key->ptr) == '/') {
1122
 
                        if (strncmp(fn->ptr, extension->key->ptr, ct_len) == 0) {
 
1122
                if (*(ext->key->ptr) == '/') {
 
1123
                        if (strncmp(fn->ptr, ext->key->ptr, ct_len) == 0) {
1123
1124
                                if (s_len > ct_len + 1) {
1124
1125
                                        char *pi_offset;
1125
1126
 
1127
1128
                                                path_info_offset = pi_offset - fn->ptr;
1128
1129
                                        }
1129
1130
                                }
 
1131
                                extension = ext;
1130
1132
                                break;
1131
1133
                        }
1132
 
                } else if (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len)) {
 
1134
                } else if (0 == strncmp(fn->ptr + s_len - ct_len, ext->key->ptr, ct_len)) {
1133
1135
                        /* check extension in the form ".fcg" */
 
1136
                        extension = ext;
1134
1137
                        break;
1135
1138
                }
1136
1139
        }
1137
1140
 
1138
 
        if (k == p->conf.extensions->used) {
 
1141
        if (NULL == extension) {
1139
1142
                return HANDLER_GO_ON;
1140
1143
        }
1141
1144