diff src/core/ngx_config_file.c @ 32:d45effe5854c

nginx-0.0.1-2002-12-19-10:08:55 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 19 Dec 2002 07:08:55 +0000
parents src/core/ngx_config_command.c@d7908993fdeb
children 79c1fce18e71
line wrap: on
line diff
copy from src/core/ngx_config_command.c
copy to src/core/ngx_config_file.c
--- a/src/core/ngx_config_command.c
+++ b/src/core/ngx_config_file.c
@@ -1,54 +1,67 @@
 
 #include <ngx_config.h>
 
-
-#if 0
-
-typedef struct ngx_conf_file_t {
-    ngx_fd_t  fd;
-    char     *name;
-    int       line;
-    char     *pos;
-};
+#include <ngx_core.h>
 
-typedef struct ngx_conf_t {
-    char             *name;
-    ngx_array_t      *args;
+#include <ngx_config_file.h>
 
-    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_TAKE2
 };
 
+#if 0
 
-ngx_conf_parse(cf, container, filename)
+int ngx_conf_parse(ngx_conf_t *cf, char *filename)
 {
-    create cf;
-
-    *conatiner(cf);
+    int    rc;
+    char  *error;
+    ngx_fd_t  fd;
+    ngx_conf_file_t  *prev;
 
     if (filename) {
-        open;
+
+        fd = ngx_open_file(filename, NGX_FILE_RDONLY);
+        if (fd == NGX_INVALID_FILE) {
+            ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
+                          "ngx_conf_open: "
+                          ngx_open_file_n " %s failed", filename);
+            return NGX_ERROR;
+        }
+
+        prev = cf->file;
+        ngx_test_null(cf->file, ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)),
+                      NGX_ERROR);
+
+        cf->file->fd = fd;
+        cf->file->name = filename;
+        cf->file->line = 1;
+        cf->file->pos = 0;
     }
 
     for ( ;; ) {
         rc = ngx_conf_read_token(cf);
 
-NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE
+        /* ??? NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */
 
-        if (rc != NGX_OK)
+        if (rc != NGX_OK) {
             return rc;
+        }
 
-"listen address:port;"
-"location /images/ {"
+        /* ????
+           "listen address:port;"
+           "location /images/ {" */
+
+        if (cf->handler) {
+
+            if (*(cf->handler)(cf) == NGX_ERROR) {
+                return NGX_ERROR;
+            }
+
+            continue;
+        }
 
         cmd = ngx_conf_find_token(cf);
         if (cmd == NULL) {
@@ -58,6 +71,18 @@ NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, N
             return NGX_ERROR;
         }
 
+        if (cmd->type & argument_number[cf->args->nelts]) {
+            error = cmd->set(cf, cmd->offset, cf->args);
+
+            if (error) {
+                 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+                               "%s in directive \"%s\" in %s:%d",
+                               error, cf->name, cf->file->name, cf->file->line);
+                return NGX_ERROR;
+            }
+        }
+
+#if 0
         if (cmd->type == NGX_CONF_CONTAINER) {
             ngx_conf_parse(cf, cmd->container, NULL);
 
@@ -109,14 +134,30 @@ NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, N
             return NGX_ERROR;
         }
     }
+#endif
 
     if (filename) {
-        close;
+        cf->file = prev;
+
+        if (ngx_close_file(fd) == NGX_FILE_ERROR) {
+            ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno,
+                          ngx_close_file_n " %s failed", cf->name);
+            return NGX_ERROR;
+        }
     }
+
+    return NGX_OK;
 }    
 
+#endif
+
+#if 0
+
 int ngx_conf_read_token(ngx_conf_t *cf)
 {
+    char        *start, ch, *src, *dst;
+    int          n, need_space, last_space, len, quoted, s_quoted, d_quoted;
+    ngx_hunk_t  *h;
 
     need_space = 0;
     last_space = 1;
@@ -124,13 +165,35 @@ int ngx_conf_read_token(ngx_conf_t *cf)
     quoted = s_quoted = d_quoted = 0;
 
     cf->args->nelts = 0;
+    h = cf->conf_file->hunk;
 
-    for (/* void */ ; cf->pos < cf->end; cf->pos++) {
+    for (start = h->pos.mem; /* end_of_file */ ; h->pos.mem++) {
+
+        if (h->pos.mem >= h->last.mem) {
+            if (h->pos.mem - start) {
+                ngx_memcpy(h->start, start, h->pos.mem - start);
+            }
+
+            n = ngx_read_file(cf->conf_file->file,
+                              h->start + (h->pos.mem - start),
+                              h->end - (h->start + (h->pos.mem - start)),
+                              cf->conf_file->file.offset);
 
-        ch = *cf->pos;
+            if (n == NGX_ERROR) {
+                return NGX_ERROR;
+            }
 
-        if (ch == LF)
-            cf->line++;
+            cf->conf_file.file.offset += n;
+            h->pos.mem = h->start + (h->pos.mem - start);
+            start = h->start;
+            h->last.mem = h->pos.mem + n;
+        }
+
+        ch = *h->pos.mem;
+
+        if (ch == LF) {
+            cf->conf_file->line++;
+        }
 
         if (quoted) {
             quoted = 0;
@@ -139,6 +202,15 @@ int ngx_conf_read_token(ngx_conf_t *cf)
 
         len++;
 
+        if (last_space) {
+            start = h->pos.mem;
+
+            if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
+                start++;
+                continue;
+            }
+        }
+
         if (ch = '\\') {
             quoted = 1;
             continue;
@@ -147,7 +219,7 @@ int ngx_conf_read_token(ngx_conf_t *cf)
         if (d_quoted) {
 
             if (ch == '"') {
-                d_qouted = 0;
+                d_quoted = 0;
                 need_space = 1;
                 last_space = 1;
                 continue;
@@ -156,7 +228,7 @@ int ngx_conf_read_token(ngx_conf_t *cf)
         } else if (s_quoted) {
 
             if (ch == '\'') {
-                s_qouted = 0;
+                s_quoted = 0;
                 need_space = 1;
                 last_space = 1;
                 continue;
@@ -165,11 +237,12 @@ int ngx_conf_read_token(ngx_conf_t *cf)
         } 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_test_null(word, ngx_push_array(cf->args), NGX_ERROR);
+                ngx_test_null(word->data, ngx_palloc(cf->temp_pool, len + 1),
                               NGX_ERROR);
+                word->len = len;
 
-                for (dst = *word, src = cf->start; src < cf->pos; /* void */) {
+                for (dst = word->data, src = start; src < h->pos; /* void */) {
                     if (*src == '\\')
                         src++;
                     *dst++ = *src++;
@@ -185,23 +258,26 @@ int ngx_conf_read_token(ngx_conf_t *cf)
                 return NGX_ERROR;
             }
 
-            if (ch == ';')
+            if (ch == ';') {
                 return NGX_OK;
+            }
 
-            if (ch == '{')
+            if (ch == '{') {
                 return NGX_OK;
+            }
 
-            if (ch == '}')
+            if (ch == '}') {
                 return NGX_BLOCK_DONE;
+            }
 
             if (last_space) {
                 if (ch == '"') {
-                    d_qouted = 1;
+                    d_quoted = 1;
                     continue;
                 }
 
                 if (ch == '\'') {
-                    s_qouted = 1;
+                    s_quoted = 1;
                     continue;
                 }
             }
@@ -211,50 +287,8 @@ int ngx_conf_read_token(ngx_conf_t *cf)
     }
 }
 
-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;