Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 343:6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 28 May 2004 15:49:23 +0000 |
parents | 4feff829a849 |
children | 199cd29f35a3 |
comparison
equal
deleted
inserted
replaced
342:0ee0642af5f1 | 343:6bdf858bff8c |
---|---|
49 char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) | 49 char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) |
50 { | 50 { |
51 int m, rc, found, valid; | 51 int m, rc, found, valid; |
52 char *rv; | 52 char *rv; |
53 void *conf, **confp; | 53 void *conf, **confp; |
54 ngx_fd_t fd; | |
54 ngx_str_t *name; | 55 ngx_str_t *name; |
55 ngx_fd_t fd; | |
56 ngx_conf_file_t *prev; | 56 ngx_conf_file_t *prev; |
57 ngx_command_t *cmd; | 57 ngx_command_t *cmd; |
58 | 58 |
59 #if (NGX_SUPPRESS_WARN) | 59 #if (NGX_SUPPRESS_WARN) |
60 fd = NGX_INVALID_FILE; | 60 fd = NGX_INVALID_FILE; |
71 ngx_open_file_n " %s failed", filename->data); | 71 ngx_open_file_n " %s failed", filename->data); |
72 return NGX_CONF_ERROR; | 72 return NGX_CONF_ERROR; |
73 } | 73 } |
74 | 74 |
75 prev = cf->conf_file; | 75 prev = cf->conf_file; |
76 ngx_test_null(cf->conf_file, | 76 if (!(cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)))) { |
77 ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)), | 77 return NGX_CONF_ERROR; |
78 NGX_CONF_ERROR); | 78 } |
79 | 79 |
80 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { | 80 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { |
81 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, | 81 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
82 ngx_fd_info_n " %s failed", filename->data); | 82 ngx_fd_info_n " %s failed", filename->data); |
83 } | 83 } |
84 | 84 |
85 ngx_test_null(cf->conf_file->hunk, | 85 if (!(cf->conf_file->buffer = ngx_create_temp_buf(cf->pool, 1024))) { |
86 ngx_create_temp_hunk(cf->pool, 1024), | 86 return NGX_CONF_ERROR; |
87 NGX_CONF_ERROR); | 87 } |
88 | 88 |
89 cf->conf_file->file.fd = fd; | 89 cf->conf_file->file.fd = fd; |
90 cf->conf_file->file.name.len = filename->len; | 90 cf->conf_file->file.name.len = filename->len; |
91 cf->conf_file->file.name.data = filename->data; | 91 cf->conf_file->file.name.data = filename->data; |
92 cf->conf_file->file.offset = 0; | 92 cf->conf_file->file.offset = 0; |
95 } | 95 } |
96 | 96 |
97 for ( ;; ) { | 97 for ( ;; ) { |
98 rc = ngx_conf_read_token(cf); | 98 rc = ngx_conf_read_token(cf); |
99 | 99 |
100 /* ngx_conf_read_token() returns NGX_OK, NGX_ERROR, | 100 /* |
101 NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE */ | 101 * ngx_conf_read_token() returns NGX_OK, NGX_ERROR, |
102 * NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE | |
103 */ | |
102 | 104 |
103 #if 0 | 105 #if 0 |
104 ngx_log_debug(cf->log, "token %d" _ rc); | 106 ngx_log_debug(cf->log, "token %d" _ rc); |
105 #endif | 107 #endif |
106 | 108 |
313 int len; | 315 int len; |
314 int found, need_space, last_space, sharp_comment; | 316 int found, need_space, last_space, sharp_comment; |
315 int quoted, s_quoted, d_quoted; | 317 int quoted, s_quoted, d_quoted; |
316 ssize_t n; | 318 ssize_t n; |
317 ngx_str_t *word; | 319 ngx_str_t *word; |
318 ngx_hunk_t *h; | 320 ngx_buf_t *b; |
319 | 321 |
320 found = 0; | 322 found = 0; |
321 need_space = 0; | 323 need_space = 0; |
322 last_space = 1; | 324 last_space = 1; |
323 sharp_comment = 0; | 325 sharp_comment = 0; |
324 quoted = s_quoted = d_quoted = 0; | 326 quoted = s_quoted = d_quoted = 0; |
325 | 327 |
326 cf->args->nelts = 0; | 328 cf->args->nelts = 0; |
327 h = cf->conf_file->hunk; | 329 b = cf->conf_file->buffer; |
328 start = h->pos; | 330 start = b->pos; |
329 | 331 |
330 #if 0 | 332 #if 0 |
331 ngx_log_debug(cf->log, "TOKEN START"); | 333 ngx_log_debug(cf->log, "TOKEN START"); |
332 #endif | 334 #endif |
333 | 335 |
334 for ( ;; ) { | 336 for ( ;; ) { |
335 | 337 |
336 if (h->pos >= h->last) { | 338 if (b->pos >= b->last) { |
337 if (cf->conf_file->file.offset | 339 if (cf->conf_file->file.offset |
338 >= ngx_file_size(&cf->conf_file->file.info)) { | 340 >= ngx_file_size(&cf->conf_file->file.info)) { |
339 return NGX_CONF_FILE_DONE; | 341 return NGX_CONF_FILE_DONE; |
340 } | 342 } |
341 | 343 |
342 if (h->pos - start) { | 344 if (b->pos - start) { |
343 ngx_memcpy(h->start, start, (size_t) (h->pos - start)); | 345 ngx_memcpy(b->start, start, b->pos - start); |
344 } | 346 } |
345 | 347 |
346 n = ngx_read_file(&cf->conf_file->file, | 348 n = ngx_read_file(&cf->conf_file->file, |
347 h->start + (h->pos - start), | 349 b->start + (b->pos - start), |
348 (size_t) (h->end - (h->start + (h->pos - start))), | 350 b->end - (b->start + (b->pos - start)), |
349 cf->conf_file->file.offset); | 351 cf->conf_file->file.offset); |
350 | 352 |
351 if (n == NGX_ERROR) { | 353 if (n == NGX_ERROR) { |
352 return NGX_ERROR; | 354 return NGX_ERROR; |
353 } | 355 } |
354 | 356 |
355 h->pos = h->start + (h->pos - start); | 357 b->pos = b->start + (b->pos - start); |
356 start = h->start; | 358 start = b->start; |
357 h->last = h->pos + n; | 359 b->last = b->pos + n; |
358 } | 360 } |
359 | 361 |
360 ch = *h->pos++; | 362 ch = *b->pos++; |
361 | 363 |
362 #if 0 | 364 #if 0 |
363 ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ | 365 ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ |
364 last_space _ need_space _ | 366 last_space _ need_space _ |
365 quoted _ s_quoted _ d_quoted _ ch); | 367 quoted _ s_quoted _ d_quoted _ ch); |
404 if (last_space) { | 406 if (last_space) { |
405 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { | 407 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { |
406 continue; | 408 continue; |
407 } | 409 } |
408 | 410 |
409 start = h->pos - 1; | 411 start = b->pos - 1; |
410 | 412 |
411 switch (ch) { | 413 switch (ch) { |
412 | 414 |
413 case ';': | 415 case ';': |
414 case '{': | 416 case '{': |
483 last_space = 1; | 485 last_space = 1; |
484 found = 1; | 486 found = 1; |
485 } | 487 } |
486 | 488 |
487 if (found) { | 489 if (found) { |
488 ngx_test_null(word, ngx_push_array(cf->args), NGX_ERROR); | 490 if (!(word = ngx_push_array(cf->args))) { |
489 ngx_test_null(word->data, | 491 return NGX_ERROR; |
490 ngx_palloc(cf->pool, | 492 } |
491 (size_t) (h->pos - start + 1)), | 493 |
492 NGX_ERROR); | 494 if (!(word->data = ngx_palloc(cf->pool, b->pos - start + 1))) { |
495 return NGX_ERROR; | |
496 } | |
493 | 497 |
494 for (dst = word->data, src = start, len = 0; | 498 for (dst = word->data, src = start, len = 0; |
495 src < h->pos - 1; | 499 src < b->pos - 1; |
496 len++) | 500 len++) |
497 { | 501 { |
498 if (*src == '\\') { | 502 if (*src == '\\') { |
499 switch (src[1]) { | 503 switch (src[1]) { |
500 case '"': | 504 case '"': |
581 return &file[i]; | 585 return &file[i]; |
582 } | 586 } |
583 } | 587 } |
584 } | 588 } |
585 | 589 |
586 ngx_test_null(file, ngx_push_array(&cycle->open_files), NULL); | 590 if (!(file = ngx_push_array(&cycle->open_files))) { |
591 return NULL; | |
592 } | |
593 | |
587 file->fd = NGX_INVALID_FILE; | 594 file->fd = NGX_INVALID_FILE; |
595 | |
588 if (name) { | 596 if (name) { |
589 file->name = *name; | 597 file->name = *name; |
590 } | 598 } |
591 | 599 |
592 return file; | 600 return file; |
915 } | 923 } |
916 | 924 |
917 | 925 |
918 char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data) | 926 char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data) |
919 { | 927 { |
920 ngx_conf_num_bounds_t *bounds = post; | 928 ngx_conf_num_bounds_t *bounds = post; |
921 ngx_int_t *np = data; | 929 ngx_int_t *np = data; |
922 | 930 |
923 if (bounds->high == -1) { | 931 if (bounds->high == -1) { |
924 if (*np >= bounds->low) { | 932 if (*np >= bounds->low) { |
925 return NGX_CONF_OK; | 933 return NGX_CONF_OK; |
926 } | 934 } |