summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_config.c
blob: 36037c6cf75a041bc9038e897bb4b5e96ee00e04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

#include <ngx_core.h>
#include <ngx_config_command.h>
#include <ngx_http.h>
#include <ngx_http_write_filter.h>
#include <ngx_http_output_filter.h>
#include <ngx_http_index_handler.h>


int ngx_max_module;

/* STUB: gobal srv and loc conf */
void **ngx_srv_conf;
void **ngx_loc_conf;


int ngx_http_config_modules(ngx_pool_t *pool, ngx_http_module_t **modules)
{
    int i;

    for (i = 0; modules[i]; i++) {
        modules[i]->index = i;
    }

    ngx_max_module = i;

    ngx_test_null(ngx_srv_conf,
                  ngx_pcalloc(pool, sizeof(void *) * ngx_max_module),
                  NGX_ERROR);
    ngx_test_null(ngx_loc_conf,
                  ngx_pcalloc(pool, sizeof(void *) * ngx_max_module),
                  NGX_ERROR);

    for (i = 0; modules[i]; i++) {
        if (modules[i]->create_srv_conf)
            ngx_srv_conf[i] = modules[i]->create_srv_conf(pool);

        if (modules[i]->create_loc_conf)
            ngx_loc_conf[i] = modules[i]->create_loc_conf(pool);
    }
}

int ngx_http_init_modules(ngx_pool_t *pool, ngx_http_module_t **modules)
{
    int i;

    for (i = 0; modules[i]; i++) {
        if (modules[i]->init_module)
            modules[i]->init_module(pool);
    }
}

int ngx_http_init_filters(ngx_pool_t *pool, ngx_http_module_t **modules)
{
    int i;
    int (*filter)(ngx_http_request_t *r, ngx_chain_t *ch);

    filter = ngx_http_write_filter;

    for (i = 0; modules[i]; i++) {
        if (modules[i]->init_output_body_filter)
            modules[i]->init_output_body_filter(&filter);
    }
}


/* STUB */
ngx_http_output_filter_set_stub(ngx_pool_t *pool, ngx_http_module_t **modules)
{
    int i;
    ngx_command_t *cmd;

    for (i = 0; modules[i]; i++) {
        if (modules[i] == &ngx_http_output_filter_module) {
            for (cmd = modules[i]->commands; cmd->name; cmd++) {
                if (strcmp(cmd->name, "output_buffer") == 0) {
                    cmd->set(ngx_loc_conf[i], cmd->offset, "32768");
                }
            }
        }
    }
}

ngx_http_write_filter_set_stub(ngx_pool_t *pool, ngx_http_module_t **modules)
{
    int i;
    ngx_command_t *cmd;

    for (i = 0; modules[i]; i++) {
        if (modules[i] == &ngx_http_write_filter_module) {
            for (cmd = modules[i]->commands; cmd->name; cmd++) {
                if (strcmp(cmd->name, "write_buffer") == 0) {
                    cmd->set(ngx_loc_conf[i], cmd->offset, "1500");
                }
            }
        }
    }
}

ngx_http_index_set_stub(ngx_pool_t *pool, ngx_http_module_t **modules)
{
    int i;
    ngx_str_t index;
    ngx_command_t *cmd;

    for (i = 0; modules[i]; i++) {
        if (modules[i] == &ngx_http_index_module) {
            for (cmd = modules[i]->commands; cmd->name; cmd++) {
                if (strcmp(cmd->name, "index") == 0) {
                    index.len = sizeof("index.html") - 1;
                    index.data = "index.html";
                    cmd->set(pool, ngx_loc_conf[i], &index);
                }
            }
        }
    }
}