Changeset 1465

Show
Ignore:
Timestamp:
12/12/2006 10:13:38 PM (22 months ago)
Author:
jakabosky
Message:

converted mod_proxy_backend_xxx's into loadable modules.
added backend scgi
rewrote http-chunked and fastcgi decoding
added support for X-LIGHTTPD-send-tempfile

Location:
trunk
Files:
3 added
2 removed
33 modified

Legend:

Unmodified
Added
Removed
  • trunk/configure.in

    r1457 r1465  
    564564 
    565565 
    566 do_build="mod_cgi mod_fastcgi mod_proxy mod_evhost mod_simple_vhost mod_access mod_alias mod_setenv mod_usertrack mod_auth mod_status mod_accesslog mod_rrdtool mod_secdownload mod_expire mod_compress mod_dirlisting mod_indexfiles mod_userdir mod_webdav mod_staticfile mod_scgi mod_flv_streaming"  
     566do_build="mod_proxy_core mod_proxy_backend_http mod_proxy_backend_fastcgi mod_proxy_backend_scgi mod_evhost mod_simple_vhost mod_access mod_alias mod_setenv mod_usertrack mod_auth mod_status mod_accesslog mod_rrdtool mod_secdownload mod_expire mod_compress mod_dirlisting mod_indexfiles mod_userdir mod_webdav mod_staticfile mod_flv_streaming"  
    567567 
    568568plugins="mod_rewrite mod_redirect mod_ssi mod_trigger_b4_dl" 
  • trunk/src/Makefile.am

    r1457 r1465  
    5353      stat_cache.c plugin.c joblist.c etag.c array.c \ 
    5454      data_string.c data_count.c data_array.c \ 
    55       data_integer.c md5.c data_fastcgi.c \ 
     55      data_integer.c md5.c \ 
    5656      fdevent_select.c fdevent_linux_rtsig.c \ 
    5757      fdevent_poll.c fdevent_linux_sysepoll.c \ 
     
    137137mod_sql_vhost_core_la_LIBADD = $(common_libadd) 
    138138 
    139 #lib_LTLIBRARIES += mod_cgi.la 
    140 #mod_cgi_la_SOURCES = mod_cgi.c  
    141 #mod_cgi_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
    142 #mod_cgi_la_LIBADD = $(common_libadd) 
    143  
    144 #lib_LTLIBRARIES += mod_scgi.la 
    145 #mod_scgi_la_SOURCES = mod_scgi.c  
    146 #mod_scgi_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
    147 #mod_scgi_la_LIBADD = $(common_libadd) 
    148  
    149139lib_LTLIBRARIES += mod_staticfile.la 
    150140mod_staticfile_la_SOURCES = mod_staticfile.c  
     
    187177mod_usertrack_la_LIBADD = $(common_libadd) 
    188178 
    189 #lib_LTLIBRARIES += mod_proxy.la 
    190 #mod_proxy_la_SOURCES = mod_proxy.c 
    191 #mod_proxy_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
    192 #mod_proxy_la_LIBADD = $(common_libadd) 
    193  
    194179lib_LTLIBRARIES += mod_proxy_core.la 
    195180mod_proxy_core_la_SOURCES = mod_proxy_core.c mod_proxy_core_pool.c \ 
    196181                            mod_proxy_core_backend.c mod_proxy_core_address.c \ 
    197182                            mod_proxy_core_backlog.c mod_proxy_core_rewrites.c \ 
    198                             mod_proxy_backend_http.c mod_proxy_backend_fastcgi.c 
     183                            mod_proxy_core_protocol.c 
    199184mod_proxy_core_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
    200185mod_proxy_core_la_LIBADD = $(common_libadd) $(PCRE_LIB) 
     186 
     187lib_LTLIBRARIES += mod_proxy_backend_http.la 
     188mod_proxy_backend_http_la_SOURCES = mod_proxy_backend_http.c 
     189mod_proxy_backend_http_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
     190mod_proxy_backend_http_la_LIBADD = $(common_libadd) $(PCRE_LIB) 
     191 
     192lib_LTLIBRARIES += mod_proxy_backend_fastcgi.la 
     193mod_proxy_backend_fastcgi_la_SOURCES = mod_proxy_backend_fastcgi.c 
     194mod_proxy_backend_fastcgi_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
     195mod_proxy_backend_fastcgi_la_LIBADD = $(common_libadd) $(PCRE_LIB) 
     196 
     197lib_LTLIBRARIES += mod_proxy_backend_scgi.la 
     198mod_proxy_backend_scgi_la_SOURCES = mod_proxy_backend_scgi.c 
     199mod_proxy_backend_scgi_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
     200mod_proxy_backend_scgi_la_LIBADD = $(common_libadd) $(PCRE_LIB) 
    201201 
    202202 
     
    231231mod_simple_vhost_la_LIBADD = $(common_libadd) 
    232232                 
    233 #lib_LTLIBRARIES += mod_fastcgi.la 
    234 #mod_fastcgi_la_SOURCES = mod_fastcgi.c 
    235 #mod_fastcgi_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined 
    236 #mod_fastcgi_la_LIBADD = $(common_libadd) 
    237  
    238233lib_LTLIBRARIES += mod_access.la 
    239234mod_access_la_SOURCES = mod_access.c 
     
    292287      mod_proxy_core_pool.h \ 
    293288      mod_proxy_core_rewrites.h \ 
    294       mod_proxy_backend_http.h \ 
    295       mod_proxy_backend_fastcgi.h \ 
    296289      status_counter.h \ 
    297290      http_req.h \ 
  • trunk/src/array-static.h

    r1349 r1465  
    2424        } 
    2525         
    26 #define FOREACH(array, element, func) \ 
    27 do { size_t _i; for (_i = 0; _i < array->used; _i++) { void *element = array->ptr[_i]; func; } } while(0); 
     26#define FOREACH(array, type, element, func) \ 
     27do { size_t _i; for (_i = 0; _i < array->used; _i++) { type *element = array->ptr[_i]; func; } } while(0); 
    2828 
    2929#define STRUCT_INIT(type, var) \ 
     
    3131        var = calloc(1, sizeof(*var)) 
    3232 
     33#define ARRAY_STATIC_FREE(array, type, element, func) \ 
     34        FOREACH(array, type, element, func); \ 
     35        if(array->ptr) free(array->ptr); \ 
     36        array->ptr = NULL; 
     37 
    3338#endif 
  • trunk/src/array.c

    r1349 r1465  
    145145 
    146146        return ds; 
     147} 
     148 
     149void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len) { 
     150        data_string *ds_dst; 
     151 
     152        if (NULL != (ds_dst = (data_string *)array_get_element(hdrs, key))) { 
     153                buffer_copy_string_len(ds_dst->value, value, val_len); 
     154                return; 
     155        } 
     156 
     157        if (NULL == (ds_dst = (data_string *)array_get_unused_element(hdrs, TYPE_STRING))) { 
     158                ds_dst = data_string_init(); 
     159        } 
     160 
     161        buffer_copy_string_len(ds_dst->key, key, key_len); 
     162        buffer_copy_string_len(ds_dst->value, value, val_len); 
     163        array_insert_unique(hdrs, (data_unset *)ds_dst); 
     164} 
     165 
     166void array_append_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len) { 
     167        data_string *ds_dst; 
     168 
     169        if (NULL == (ds_dst = (data_string *)array_get_unused_element(hdrs, TYPE_STRING))) { 
     170                ds_dst = data_string_init(); 
     171        } 
     172 
     173        buffer_copy_string_len(ds_dst->key, key, key_len); 
     174        buffer_copy_string_len(ds_dst->value, value, val_len); 
     175        array_insert_unique(hdrs, (data_unset *)ds_dst); 
    147176} 
    148177 
  • trunk/src/array.h

    r1349 r1465  
    135135data_integer *data_integer_init(void); 
    136136 
    137 typedef struct { 
    138         DATA_UNSET; 
    139  
    140         buffer *host; 
    141  
    142         unsigned short port; 
    143  
    144         time_t disable_ts; 
    145         int is_disabled; 
    146         size_t balance; 
    147  
    148         int usage; /* fair-balancing needs the no. of connections active on this host */ 
    149         int last_used_ndx; /* round robin */ 
    150 } data_fastcgi; 
    151  
    152 data_fastcgi *data_fastcgi_init(void); 
    153  
    154137array *array_init(void); 
    155138array *array_init_array(array *a); 
     
    161144data_unset *array_get_unused_element(array *a, data_type_t t); 
    162145data_unset *array_get_element(array *a, const char *key); 
     146void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len); 
     147void array_append_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len); 
    163148data_unset *array_replace(array *a, data_unset *du); 
    164149int array_strcasecmp(const char *a, size_t a_len, const char *b, size_t b_len); 
  • trunk/src/base.h

    r1462 r1465  
    560560        connections *conns; 
    561561        connections *joblist; 
     562        connections *joblist_prev; 
    562563        connections *fdwaitqueue; 
    563564 
  • trunk/src/buffer.c

    r1445 r1465  
    11271127        if (!bp) return; 
    11281128 
    1129         FOREACH(bp, b, buffer_free(b)); 
     1129        ARRAY_STATIC_FREE(bp, buffer, b, buffer_free(b)); 
    11301130 
    11311131        free(bp); 
  • trunk/src/chunk.c

    r1437 r1465  
    241241} 
    242242 
    243  
     243/* 
     244 * copy/steal max_len bytes from chunk chain.  return total bytes copied/stolen. 
     245 * 
     246 */ 
     247int chunkqueue_steal_chunks_len(chunkqueue *cq, chunk *c, size_t max_len) { 
     248        size_t total = 0; 
     249        off_t we_have = 0, we_want = 0; 
     250        buffer *b; 
     251 
     252        if (!cq || !c) return 0; 
     253 
     254        /* copy/steal chunks */ 
     255        for (; c && max_len > 0; c = c->next) { 
     256                /* skip empty chunks */ 
     257                if (c->mem->used == 0) continue; 
     258 
     259                we_have = c->mem->used - c->offset - 1; 
     260                if (we_have == 0) continue; 
     261 
     262                we_want = we_have < max_len ? we_have : max_len; 
     263 
     264                if (c->offset == 0 && we_have == we_want) { 
     265                        /* steal whole chunk */ 
     266                        chunkqueue_steal_chunk(cq, c); 
     267                } else { 
     268                        /* copy unused data from chunk */ 
     269                        b = chunkqueue_get_append_buffer(cq); 
     270                        buffer_copy_string_len(b, c->mem->ptr + c->offset, we_want); 
     271                        c->offset += we_want; 
     272                } 
     273                total += we_want; 
     274                max_len -= we_want; 
     275        } 
     276        return total; 
     277} 
     278 
     279int chunkqueue_skip(chunkqueue *cq, off_t skip) { 
     280        size_t total = 0; 
     281        off_t we_have = 0, we_want = 0; 
     282        chunk *c; 
     283 
     284        if (!cq) return 0; 
     285 
     286        /* consume chunks */ 
     287        for (c = cq->first; c && skip > 0; c = c->next) { 
     288                /* skip empty chunks */ 
     289                if (c->mem->used == 0) continue; 
     290 
     291                we_have = c->mem->used - c->offset - 1; 
     292                if (we_have == 0) continue; 
     293 
     294                we_want = we_have < skip ? we_have : skip; 
     295 
     296                c->offset += we_want; 
     297                total += we_want; 
     298                skip -= we_want; 
     299        } 
     300        return total; 
     301} 
     302  
    244303int chunkqueue_append_buffer(chunkqueue *cq, buffer *mem) { 
    245304        chunk *c; 
  • trunk/src/chunk.h

    r1437 r1465  
    6767int chunkqueue_steal_tempfile(chunkqueue *cq, chunk *in); 
    6868int chunkqueue_steal_chunk(chunkqueue *cq, chunk *c);  
     69int chunkqueue_steal_chunks_len(chunkqueue *cq, chunk *c, size_t max_len);  
     70int chunkqueue_skip(chunkqueue *cq, off_t skip); 
    6971void chunkqueue_remove_empty_last_chunk(chunkqueue *cq); 
    7072 
  • trunk/src/connections.c

    r1449 r1465  
    965965        buffer_append_string(b, "\r\n"); 
    966966        chunkqueue_append_buffer(cq, b); 
     967        len = b->used - 1; 
    967968 
    968969        buffer_free(b); 
    969970 
    970         return 0; 
     971        return len; 
    971972} 
    972973 
     
    978979        chunk *c; 
    979980        int is_chunked; 
    980  
     981        int we_have = 0; 
     982 
     983        /* no more data to encode. */ 
     984        if (out->is_closed) return 0; 
    981985        /**/ 
    982986 
     
    989993                                if (c->mem->used == 0) continue; 
    990994 
    991                                 http_chunk_append_len(out, c->mem->used - 1); 
     995                                we_have = c->mem->used - c->offset - 1; 
     996                                in->bytes_out += we_have; 
     997                                if(we_have == 0) continue; 
     998                                we_have += http_chunk_append_len(out, we_have); 
    992999                                chunkqueue_append_buffer(out, c->mem); 
    9931000                                c->offset = c->mem->used - 1; 
     
    9961003                                if (c->file.length == 0) continue; 
    9971004 
    998                                 http_chunk_append_len(out, c->file.length); 
    999                                 chunkqueue_append_file(out, c->file.name, c->file.start, c->file.length); 
     1005                                we_have = c->file.length; 
     1006                                in->bytes_out += we_have; 
     1007                                we_have += http_chunk_append_len(out, c->file.length); 
     1008                                if(c->file.is_temp) { 
     1009                                        chunkqueue_steal_tempfile(out, c); 
     1010                                } else { 
     1011                                        chunkqueue_append_file(out, c->file.name, c->file.start, c->file.length); 
     1012                                } 
    10001013 
    10011014                                c->offset = c->file.length; 
    10021015                                break; 
     1016                        case UNUSED_CHUNK: 
     1017                                break; 
    10031018                        } 
    10041019                        chunkqueue_append_mem(out, "\r\n", 2 + 1); 
    1005                 } 
    1006                 if (in->is_closed) chunkqueue_append_mem(out, "0\r\n\r\n", 5 + 1); 
     1020                        we_have += 2; 
     1021                        out->bytes_in += we_have; 
     1022                } 
     1023                if (in->is_closed) { 
     1024                        chunkqueue_append_mem(out, "0\r\n\r\n", 5 + 1); 
     1025                        out->bytes_in += 5; 
     1026                } 
    10071027        } else { 
    10081028                for (c = in->first; c; c = c->next) { 
     
    10111031                                if (c->mem->used == 0) continue; 
    10121032 
     1033                                we_have = c->mem->used - c->offset - 1; 
     1034                                in->bytes_out += we_have; 
     1035                                if(we_have == 0) continue; 
    10131036                                if (c->offset == 0) { 
    10141037                                        chunkqueue_steal_chunk(out, c); 
     
    10211044                                if (c->file.length == 0) continue; 
    10221045 
    1023                                 chunkqueue_append_file(out, c->file.name, c->file.start, c->file.length); 
     1046                                we_have = c->file.length; 
     1047                                in->bytes_out += we_have; 
     1048                                if(c->file.is_temp) { 
     1049                                        chunkqueue_steal_tempfile(out, c); 
     1050                                } else { 
     1051                                        chunkqueue_append_file(out, c->file.name, c->file.start, c->file.length); 
     1052                                } 
    10241053 
    10251054                                c->offset = c->file.length; 
    10261055                                break; 
    1027                         } 
     1056                        case UNUSED_CHUNK: 
     1057                                break; 
     1058                        } 
     1059                        in->bytes_out += we_have; 
     1060                        out->bytes_in += we_have; 
    10281061                } 
    10291062        } 
     
    10311064        chunkqueue_remove_finished_chunks(in); 
    10321065 
     1066        if (in->is_closed) { 
     1067                /* mark the output queue as finished. */ 
     1068                out->is_closed = 1; 
     1069        } 
    10331070        return 0; 
    10341071} 
     
    12221259 
    12231260                                        connection_set_state(srv, con, CON_STATE_HANDLE_REQUEST_HEADER); 
     1261 
     1262                                        /* need to reset condition cache since request uri changed. */ 
     1263                                        config_cond_cache_reset(srv, con); 
    12241264 
    12251265                                        done = -1; 
     
    13531393                        case NETWORK_STATUS_SUCCESS: 
    13541394                                /* we send everything from the chunkqueue and the chunkqueue-sender signaled it is finished */ 
    1355                                 if (con->send->is_closed) { 
     1395                                if (con->send_raw->is_closed) { 
    13561396                                        if (con->http_status == 100) { 
    13571397                                                /* send out the 100 Continue header and handle the request as normal afterwards */ 
     
    13621402                                                connection_set_state(srv, con, CON_STATE_RESPONSE_END); 
    13631403                                        } 
     1404                                } else { 
     1405                                        /* still have data to send in send_raw queue */ 
     1406                                        fdevent_event_add(srv->ev, con->sock, FDEVENT_OUT); 
     1407                                        return HANDLER_WAIT_FOR_EVENT; 
    13641408                                } 
    13651409                                break; 
     
    13781422                                return HANDLER_WAIT_FOR_EVENT; 
    13791423                        case NETWORK_STATUS_INTERRUPTED: 
     1424                        case NETWORK_STATUS_UNSET: 
    13801425                                break; 
    13811426                        } 
  • trunk/src/fdevent_freebsd_kqueue.c

    r1349 r1465  
    118118        size_t ndx; 
    119119 
    120         for (ndx = 0; ndx < ev->used; ndx++) { 
     120        for (ndx = 0; ndx < event_count; ndx++) { 
    121121                int events = 0, e; 
    122122 
  • trunk/src/http_resp.c

    r1446 r1465  
    206206        int last_token_id = 0; 
    207207 
     208        if(!cq->first) return PARSE_NEED_MORE; 
    208209        t.cq = cq; 
    209210        t.c = cq->first; 
     
    251252        http_resp_parserFree(pParser, free); 
    252253 
     254                if (!buffer_is_empty(context.errmsg)) { 
     255                        TRACE("parsing failed: %s", BUF_STR(context.errmsg)); 
     256                } 
    253257        if (context.ok == 0) { 
    254258                /* we are missing the some tokens */ 
     
    266270                for (c = cq->first; c != t.c; c = c->next) { 
    267271                        c->offset = c->mem->used - 1; 
     272                        cq->bytes_out += c->mem->used - 1; 
    268273                } 
    269274 
    270275                c->offset = t.offset; 
     276                cq->bytes_out += t.offset; 
    271277 
    272278                ret = PARSE_SUCCESS; 
  • trunk/src/http_resp_parser.y

    r1439 r1465  
    4040        resp->status = strtol(ds->value->ptr, &err, 10); 
    4141    
    42         if (*err != '\0' && *err != ' ') { 
     42        if (*err != '\0' && *err != ' ' && *err != '\r') { 
    4343            buffer_copy_string(ctx->errmsg, "expected a number: "); 
    4444            buffer_append_string_buffer(ctx->errmsg, ds->value); 
  • trunk/src/joblist.c

    r1349 r1465  
    88int joblist_append(server *srv, connection *con) { 
    99        if (con->in_joblist) return 0; 
     10        con->in_joblist = 1; 
    1011 
    1112        if (srv->joblist->size == 0) { 
  • trunk/src/mod_auth.c

    r1349 r1465  
    193193        /* search auth-directives for path */ 
    194194        for (k = 0; k < p->conf.auth_require->used; k++) { 
    195                 buffer *req = p->conf.auth_require->data[k]->key; 
    196  
    197                 if (req->used == 0) continue; 
    198                 if (con->uri.path->used < req->used) continue; 
     195                buffer *auth_path = p->conf.auth_require->data[k]->key; 
     196 
     197                if (auth_path->used == 0) continue; 
     198                if (con->uri.path->used < auth_path->used) continue; 
    199199 
    200200                /* if we have a case-insensitive FS we have to lower-case the URI here too */ 
    201201 
    202202                if (con->conf.force_lowercase_filenames) { 
    203                         if (0 == strncasecmp(con->uri.path->ptr, req->ptr, req->used - 1)) { 
     203                        if (0 == strncasecmp(con->uri.path->ptr, auth_path->ptr, auth_path->used - 1)) { 
    204204                                auth_required = 1; 
    205205                                break; 
    206206                        } 
    207207                } else { 
    208                         if (0 == strncmp(con->uri.path->ptr, req->ptr, req->used - 1)) { 
     208                        if (0 == strncmp(con->uri.path->ptr, auth_path->ptr, auth_path->used - 1)) { 
    209209                                auth_required = 1; 
    210210                                break; 
  • trunk/src/mod_indexfile.c

    r1460 r1465  
    1010 
    1111#include "plugin.h" 
     12 
     13#include "configfile.h" 
    1214 
    1315#include "stat_cache.h" 
  • trunk/src/mod_proxy_backend_fastcgi.c

    r1418 r1465  
    55#include "inet_ntop_cache.h" 
    66#include "mod_proxy_core.h" 
     7#include "mod_proxy_core_protocol.h" 
    78#include "buffer.h" 
    89#include "log.h" 
    910#include "fastcgi.h" 
    10  
     11#include "array.h" 
     12 
     13#define CORE_PLUGIN "mod_proxy_core" 
     14 
     15typedef struct { 
     16        PLUGIN_DATA; 
     17 
     18        proxy_protocol *protocol; 
     19} protocol_plugin_data; 
    1120 
    1221/**  
     
    2029#endif 
    2130