aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_config_command.c
blob: 26cd26b912a75bfd98d5f7a64e43e2935ef1f400 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include <ngx_config.h>


#if 0

typedef struct ngx_conf_file_t {
    ngx_fd_t  fd;
    char     *name;
    int       line;
    char     *pos;
};

typedef struct ngx_conf_t {
    char             *name;
    ngx_array_t      *args;

    ngx_conf_file_t  *file;
    ngx_log_t        *log;

    void *context;             # ngx_http_conf_t
};

static int argument_number[] = {
    NGX_CONF_NOARGS,
    NGX_CONF_TAKE1,
    NGX_CONF_TAKE2,
    NGX_CONF_TAKE3
};


ngx_conf_parse(cf, container, filename)
{
    create cf;

    *conatiner(cf);

    if (filename) {
        open;
    }

    for ( ;; ) {
        rc = ngx_conf_read_token(cf);

NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE

        if (rc != NGX_OK)
            return rc;

"listen address:port;"
"location /images/ {"

        cmd = ngx_conf_find_token(cf);
        if (cmd == NULL) {
            ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                          "unknown directive \"%s\" in %s:%d",
                          cf->name, cf->file->name, cf->file->line);
            return NGX_ERROR;
        }

        if (cmd->type == NGX_CONF_CONTAINER) {
            ngx_conf_parse(cf, cmd->container, NULL);

        } else if (cmd->type == NGX_CONF_FLAG) {

            if (cf->args->nelts != 1) {
                ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                              "invalid number of arguments "
                              "in directive \"%s\" in %s:%d",
                              cf->name, cf->file->name, cf->file->line);
                return NGX_ERROR;
            }

            if (ngx_strcasecmp(cf->args->elts[0], "on") == 0) {
                flag = 1;

            } else if (ngx_strcasecmp(cf->args->elts[0], "off") == 0) {
                flag = 0;

            } else {
                ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                              "invalid flag in directive \"%s\" in %s:%d",
                              cf->name, cf->file->name, cf->file->line);
                return NGX_ERROR;
            }

            rv = cmd->set(cf, cmd->offset, flag);
            if (rv) {
                 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                               "%s in directive \"%s\" in %s:%d",
                               rv, cf->name, cf->file->name, cf->file->line);
                return NGX_ERROR;
            }

        } else if (cmd->type & argument_number[args->nelts]) {
            rv = cmd->set(cf, cmd->offset, cf->args);
            if (rv) {
                 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                               "%s in directive \"%s\" in %s:%d",
                               rv, cf->name, cf->file->name, cf->file->line);
                return NGX_ERROR;
            }

        } else {
            ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                          "invalid number of arguments "
                          "in directive \"%s\" in %s:%d",
                          cf->name, cf->file->name, cf->file->line);
            return NGX_ERROR;
        }
    }

    if (filename) {
        close;
    }
}    

int ngx_conf_read_token(ngx_conf_t *cf)
{

    need_space = 0;
    last_space = 1;
    len = 0;
    quoted = s_quoted = d_quoted = 0;

    cf->args->nelts = 0;

    for (/* void */ ; cf->pos < cf->end; cf->pos++) {

        ch = *cf->pos;

        if (ch == LF)
            cf->line++;

        if (quoted) {
            quoted = 0;
            continue;
        }

        len++;

        if (ch = '\\') {
            quoted = 1;
            continue;
        }

        if (d_quoted) {

            if (ch == '"') {
                d_qouted = 0;
                need_space = 1;
                last_space = 1;
                continue;
            }

        } else if (s_quoted) {

            if (ch == '\'') {
                s_qouted = 0;
                need_space = 1;
                last_space = 1;
                continue;
            }

        } else {

            if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
                ngx_test_null(word, ngx_push_array(cf->args), NGX_ERRROR);
                ngx_test_null(*word, ngx_palloc(cf->temp_pool, len + 1),
                              NGX_ERROR);

                for (dst = *word, src = cf->start; src < cf->pos; /* void */) {
                    if (*src == '\\')
                        src++;
                    *dst++ = *src++;
                }
                *dst = '\0';

                need_space = 0;
                last_space = 1;
                continue;
            }

            if (need_space) {
                return NGX_ERROR;
            }

            if (ch == ';')
                return NGX_OK;

            if (ch == '{')
                return NGX_OK;

            if (ch == '}')
                return NGX_BLOCK_DONE;

            if (last_space) {
                if (ch == '"') {
                    d_qouted = 1;
                    continue;
                }

                if (ch == '\'') {
                    s_qouted = 1;
                    continue;
                }
            }

            last_space = 0;
        }
    }
}

container
    server
    location
    module
    if

http_conf current server
          current location


ngx_conf_t *ngx_conf_open(char *filename, ngx_log_t *log)
{
    ngx_cf->fd = ngx_open_file(config, NGX_FILE_RDONLY);
    if (ngx_conf->fd == -1) {
        ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
                      "ngx_conf_open: "
                      ngx_open_file_n " %s failed", filename);

        return NULL;
    }

    ngx_conf->name = filename;
    ngx_conf->log = log;
    return ngx_conf;
}

void ngx_conf_close(ngx_conf_t *cf)
{
    if (ngx_close_file(cf->fd) == -1) {
        ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno,
                      ngx_close_file_n " %s failed", cf->name);
    }

    cf->fd = -1;
}






#endif


char *ngx_conf_set_size_slot(char *conf, int offset, char *value)
{
    int size;

    size = atoi(value);
    if (size < 0)
        return "value must be greater or equal to zero";

    *(int *) (conf + offset) = size;
    return NULL;
}

char *ngx_conf_set_time_slot(char *conf, int offset, char *value)
{
    int size;

    size = atoi(value);
    if (size < 0)
        return "value must be greater or equal to zero";

    *(int *) (conf + offset) = size;
    return NULL;
}